openbmc/build/tmp/deploy/sdk/witherspoon-2019-08-08/sysroots/armv6-openbmc-linux-gnueabi/usr/src/debug/nss-pam-ldapd/0.9.8-r0/nss-pam-ldapd-0.9.8/nslcd/common.c
char* sid2search(const char* sid)
{
    const char* tmpsid = sid;
    char *res, *tmp;
    int i = 0;
    unsigned long int l;
    /* check the beginning of the string */
    if (strncasecmp(sid, "S-", 2) != 0)
    {
        log_log(LOG_ERR, "error in SID %s", sid);
        exit(EXIT_FAILURE);
    }
    /* count the number of dashes in the sid */
    while (tmpsid != NULL)
    {
        i++;
        tmpsid = strchr(tmpsid + 1, '-');
    }
    i -= 2; /* number of security ids plus one because we add the uid later */
    /* allocate memory */
    res = malloc(3 + 3 + 6 * 3 + i * 4 * 3 + 1);
    if (res == NULL)
    {
        log_log(LOG_CRIT, "malloc() failed to allocate memory");
        exit(1);
    }
    /* build the first part */
    l = strtoul(sid + 2, &tmp, 10);
    sprintf(res, "\\%02x\\%02x", (unsigned int)l & 0xff, (unsigned int)i);
    /* build authority part (we only handle 32 of the 48 bits) */
    l = strtoul(tmp + 1, &tmp, 10);
    sprintf(res + strlen(res), "\\00\\00\\%02x\\%02x\\%02x\\%02x",
            (unsigned int)((l >> 24) & 0xff), (unsigned int)((l >> 16) & 0xff),
            (unsigned int)((l >> 8) & 0xff), (unsigned int)(l & 0xff));
    /* go over the rest of the bits */
    while (*tmp != '\0')
    {
        l = strtoul(tmp + 1, &tmp, 10);
        sprintf(res + strlen(res), "\\%02x\\%02x\\%02x\\%02x",
                (unsigned int)(l & 0xff), (unsigned int)((l >> 8) & 0xff),
                (unsigned int)((l >> 16) & 0xff),
                (unsigned int)((l >> 24) & 0xff));
    }
    return res;
}
/* convert the provided string representation of a sid
   (e.g. S-1-5-21-1936905831-823966427-12391542-23578)
   to a format that can be used to search the objectSid property with */
convert the provided string representation of a sid

to a format that can be used to search the objectSid property with
convert the provided string representation of a sid to a format that can be used to search the objectSid property with
char* sid2search(const char* sid)
{
    const char* tmpsid = sid;
    char *res, *tmp;
    int i = 0;
    unsigned long int l;
    if (strncasecmp(sid, "S-", 2) != 0)
    {
        log_log(LOG_ERR, "error in SID %s", sid);
        exit(EXIT_FAILURE);
    }
    while (tmpsid != NULL)
    {
        i++;
        tmpsid = strchr(tmpsid + 1, '-');
    }
    i -= 2; 
    res = malloc(3 + 3 + 6 * 3 + i * 4 * 3 + 1);
    if (res == NULL)
    {
        log_log(LOG_CRIT, "malloc() failed to allocate memory");
        exit(1);
    }
    l = strtoul(sid + 2, &tmp, 10);
    sprintf(res, "\\%02x\\%02x", (unsigned int)l & 0xff, (unsigned int)i);
    l = strtoul(tmp + 1, &tmp, 10);
    sprintf(res + strlen(res), "\\00\\00\\%02x\\%02x\\%02x\\%02x",
            (unsigned int)((l >> 24) & 0xff), (unsigned int)((l >> 16) & 0xff),
            (unsigned int)((l >> 8) & 0xff), (unsigned int)(l & 0xff));
    while (*tmp != '\0')
    {
        l = strtoul(tmp + 1, &tmp, 10);
        sprintf(res + strlen(res), "\\%02x\\%02x\\%02x\\%02x",
                (unsigned int)(l & 0xff), (unsigned int)((l >> 8) & 0xff),
                (unsigned int)((l >> 16) & 0xff),
                (unsigned int)((l >> 24) & 0xff));
    }
    return res;
}
char * sid2search ( const char * sid ) { const char * tmpsid = sid ; char * res , * tmp ; int i = 0 ; unsigned long int l ; if ( strncasecmp ( sid , " " , 2 ) != 0 ) { log_log ( LOG_ERR , " " , sid ) ; exit ( EXIT_FAILURE ) ; } while ( tmpsid != NULL ) { i ++ ; tmpsid = strchr ( tmpsid + 1 , ' ' ) ; } i -= 2 ; res = malloc ( 3 + 3 + 6 * 3 + i * 4 * 3 + 1 ) ; if ( res == NULL ) { log_log ( LOG_CRIT , " " ) ; exit ( 1 ) ; } l = strtoul ( sid + 2 , & tmp , 10 ) ; sprintf ( res , " \\ \\ " , ( unsigned int ) l & 0xff , ( unsigned int ) i ) ; l = strtoul ( tmp + 1 , & tmp , 10 ) ; sprintf ( res + strlen ( res ) , " \\ \\ \\ \\ \\ \\ " , ( unsigned int ) ( ( l >> 24 ) & 0xff ) , ( unsigned int ) ( ( l >> 16 ) & 0xff ) , ( unsigned int ) ( ( l >> 8 ) & 0xff ) , ( unsigned int ) ( l & 0xff ) ) ; while ( * tmp != ' \0 ' ) { l = strtoul ( tmp + 1 , & tmp , 10 ) ; sprintf ( res + strlen ( res ) , " \\ \\ \\ \\ " , ( unsigned int ) ( l & 0xff ) , ( unsigned int ) ( ( l >> 8 ) & 0xff ) , ( unsigned int ) ( ( l >> 16 ) & 0xff ) , ( unsigned int ) ( ( l >> 24 ) & 0xff ) ) ; } return res ; }
convert the provided string representation of a sid
(e.g.
convert the provided string representation of a sid ( e . g .
/* check the beginning of the string */ /* count the number of dashes in the sid */ /* number of security ids plus one because we add the uid later */ /* allocate memory */ /* build the first part */ /* build authority part (we only handle 32 of the 48 bits) */ /* go over the rest of the bits */