openbmc/build/tmp/deploy/sdk/witherspoon-2019-08-08/sysroots/armv6-openbmc-linux-gnueabi/usr/src/debug/glibc/2.29-r0/git/nss/nss_compat/compat-grp.c
static enum nss_status internal_getgrgid_r(gid_t gid, struct group* result,
                                           ent_t* ent, char* buffer,
                                           size_t buflen, int* errnop)
{
    struct parser_data* data = (void*)buffer;
    while (1)
    {
        fpos_t pos;
        int parse_res = 0;
        char* p;

        do
        {
            /* We need at least 3 characters for one line.  */
            if (__glibc_unlikely(buflen < 3))
            {
            erange:
                *errnop = ERANGE;
                return NSS_STATUS_TRYAGAIN;
            }

            fgetpos(ent->stream, &pos);
            buffer[buflen - 1] = '\xff';
            p = fgets_unlocked(buffer, buflen, ent->stream);
            if (p == NULL && feof_unlocked(ent->stream))
                return NSS_STATUS_NOTFOUND;

            if (p == NULL || __builtin_expect(buffer[buflen - 1] != '\xff', 0))
            {
            erange_reset:
                fsetpos(ent->stream, &pos);
                goto erange;
            }

            /* Terminate the line for any case.  */
            buffer[buflen - 1] = '\0';

            /* Skip leading blanks.  */
            while (isspace(*p))
                ++p;
        } while (*p == '\0' ||
                 *p == '#' || /* Ignore empty and comment lines. */
                 /* Parse the line.  If it is invalid, loop to
                    get the next line of the file to parse.  */
                 !(parse_res = _nss_files_parse_grent(p, result, data, buflen,
                                                      errnop)));

        if (__glibc_unlikely(parse_res == -1))
            /* The parser ran out of space.  */
            goto erange_reset;

        /* This is a real entry.  */
        if (result->gr_name[0] != '+' && result->gr_name[0] != '-')
        {
            if (result->gr_gid == gid)
                return NSS_STATUS_SUCCESS;
            else
                continue;
        }

        /* -group */
        if (result->gr_name[0] == '-' && result->gr_name[1] != '\0')
        {
            blacklist_store_name(&result->gr_name[1], ent);
            continue;
        }

        /* +group */
        if (result->gr_name[0] == '+' && result->gr_name[1] != '\0')
        {
            /* Yes, no +1, see the memcpy call below.  */
            size_t len = strlen(result->gr_name);
            char buf[len];
            enum nss_status status;

            /* Store the group in the blacklist for the "+" at the end of
               /etc/group */
            memcpy(buf, &result->gr_name[1], len);
            status = getgrnam_plusgroup(&result->gr_name[1], result, ent,
                                        buffer, buflen, errnop);
            blacklist_store_name(buf, ent);
            if (status == NSS_STATUS_SUCCESS && result->gr_gid == gid)
                break;
            else
                continue;
        }
        /* +:... */
        if (result->gr_name[0] == '+' && result->gr_name[1] == '\0')
        {
            if (!nss_getgrgid_r)
                return NSS_STATUS_UNAVAIL;

            enum nss_status status =
                nss_getgrgid_r(gid, result, buffer, buflen, errnop);
            if (status == NSS_STATUS_RETURN) /* We couldn't parse the entry */
                return NSS_STATUS_NOTFOUND;
            else
                return status;
        }
    }

    return NSS_STATUS_SUCCESS;
}
/* Searches in /etc/group and the NIS/NIS+ map for a special group id */
Searches in /etc/group and the NIS/NIS+ map for a special group id
Searches in / etc / group and the NIS / NIS + map for a special group id
static enum nss_status internal_getgrgid_r(gid_t gid, struct group* result,
                                           ent_t* ent, char* buffer,
                                           size_t buflen, int* errnop)
{
    struct parser_data* data = (void*)buffer;
    while (1)
    {
        fpos_t pos;
        int parse_res = 0;
        char* p;
        do
        {
            if (__glibc_unlikely(buflen < 3))
            {
            erange:
                *errnop = ERANGE;
                return NSS_STATUS_TRYAGAIN;
            }
            fgetpos(ent->stream, &pos);
            buffer[buflen - 1] = '\xff';
            p = fgets_unlocked(buffer, buflen, ent->stream);
            if (p == NULL && feof_unlocked(ent->stream))
                return NSS_STATUS_NOTFOUND;
            if (p == NULL || __builtin_expect(buffer[buflen - 1] != '\xff', 0))
            {
            erange_reset:
                fsetpos(ent->stream, &pos);
                goto erange;
            }
            buffer[buflen - 1] = '\0';
            while (isspace(*p))
                ++p;
        } while (*p == '\0' ||
                 *p == '#' || 
                 !(parse_res = _nss_files_parse_grent(p, result, data, buflen,
                                                      errnop)));
        if (__glibc_unlikely(parse_res == -1))
            goto erange_reset;
        if (result->gr_name[0] != '+' && result->gr_name[0] != '-')
        {
            if (result->gr_gid == gid)
                return NSS_STATUS_SUCCESS;
            else
                continue;
        }
        if (result->gr_name[0] == '-' && result->gr_name[1] != '\0')
        {
            blacklist_store_name(&result->gr_name[1], ent);
            continue;
        }
        if (result->gr_name[0] == '+' && result->gr_name[1] != '\0')
        {
            size_t len = strlen(result->gr_name);
            char buf[len];
            enum nss_status status;
            memcpy(buf, &result->gr_name[1], len);
            status = getgrnam_plusgroup(&result->gr_name[1], result, ent,
                                        buffer, buflen, errnop);
            blacklist_store_name(buf, ent);
            if (status == NSS_STATUS_SUCCESS && result->gr_gid == gid)
                break;
            else
                continue;
        }
        if (result->gr_name[0] == '+' && result->gr_name[1] == '\0')
        {
            if (!nss_getgrgid_r)
                return NSS_STATUS_UNAVAIL;
            enum nss_status status =
                nss_getgrgid_r(gid, result, buffer, buflen, errnop);
            if (status == NSS_STATUS_RETURN) 
                return NSS_STATUS_NOTFOUND;
            else
                return status;
        }
    }
    return NSS_STATUS_SUCCESS;
}
static enum nss_status internal_getgrgid_r ( gid_t gid , struct group * result , ent_t * ent , char * buffer , size_t buflen , int * errnop ) { struct parser_data * data = ( void * ) buffer ; while ( 1 ) { fpos_t pos ; int parse_res = 0 ; char * p ; do { if ( __glibc_unlikely ( buflen < 3 ) ) { erange : * errnop = ERANGE ; return NSS_STATUS_TRYAGAIN ; } fgetpos ( ent -> stream , & pos ) ; buffer [ buflen - 1 ] = ' \xff ' ; p = fgets_unlocked ( buffer , buflen , ent -> stream ) ; if ( p == NULL && feof_unlocked ( ent -> stream ) ) return NSS_STATUS_NOTFOUND ; if ( p == NULL || __builtin_expect ( buffer [ buflen - 1 ] != ' \xff ' , 0 ) ) { erange_reset : fsetpos ( ent -> stream , & pos ) ; goto erange ; } buffer [ buflen - 1 ] = ' \0 ' ; while ( isspace ( * p ) ) ++ p ; } while ( * p == ' \0 ' || * p == ' ' || ! ( parse_res = _nss_files_parse_grent ( p , result , data , buflen , errnop ) ) ) ; if ( __glibc_unlikely ( parse_res == -1 ) ) goto erange_reset ; if ( result -> gr_name [ 0 ] != ' ' && result -> gr_name [ 0 ] != ' ' ) { if ( result -> gr_gid == gid ) return NSS_STATUS_SUCCESS ; else continue ; } if ( result -> gr_name [ 0 ] == ' ' && result -> gr_name [ 1 ] != ' \0 ' ) { blacklist_store_name ( & result -> gr_name [ 1 ] , ent ) ; continue ; } if ( result -> gr_name [ 0 ] == ' ' && result -> gr_name [ 1 ] != ' \0 ' ) { size_t len = strlen ( result -> gr_name ) ; char buf [ len ] ; enum nss_status status ; memcpy ( buf , & result -> gr_name [ 1 ] , len ) ; status = getgrnam_plusgroup ( & result -> gr_name [ 1 ] , result , ent , buffer , buflen , errnop ) ; blacklist_store_name ( buf , ent ) ; if ( status == NSS_STATUS_SUCCESS && result -> gr_gid == gid ) break ; else continue ; } if ( result -> gr_name [ 0 ] == ' ' && result -> gr_name [ 1 ] == ' \0 ' ) { if ( ! nss_getgrgid_r ) return NSS_STATUS_UNAVAIL ; enum nss_status status = nss_getgrgid_r ( gid , result , buffer , buflen , errnop ) ; if ( status == NSS_STATUS_RETURN ) return NSS_STATUS_NOTFOUND ; else return status ; } } return NSS_STATUS_SUCCESS ; }
Searches in /etc/group and the NIS/NIS+ map for a special group id
Searches in / etc / group and the NIS / NIS + map for a special group id
/* We need at least 3 characters for one line.  */ /* Terminate the line for any case.  */ /* Skip leading blanks.  */ /* Ignore empty and comment lines. */ /* Parse the line.  If it is invalid, loop to
                    get the next line of the file to parse.  */ /* The parser ran out of space.  */ /* This is a real entry.  */ /* -group */ /* +group */ /* Yes, no +1, see the memcpy call below.  */ /* Store the group in the blacklist for the "+" at the end of
               /etc/group */ /* +:... */ /* We couldn't parse the entry */