openbmc/build/tmp/deploy/sdk/witherspoon-2019-08-08/sysroots/armv6-openbmc-linux-gnueabi/usr/src/debug/libpam/1.3.1-r0/Linux-PAM-1.3.1/modules/pam_access/pam_access.c
static int user_match(pam_handle_t* pamh, char* tok, struct login_info* item)
{
    char* string = item->user->pw_name;
    struct login_info fake_item;
    char* at;
    int rv;

    if (item->debug)
        pam_syslog(pamh, LOG_DEBUG, "user_match: tok=%s, item=%s", tok, string);

    /*
     * If a token has the magic value "ALL" the match always succeeds.
     * Otherwise, return YES if the token fully matches the username, if the
     * token is a group that contains the username, or if the token is the
     * name of the user's primary group.
     */

    /* Try to split on a pattern (@*[^@]+)(@+.*) */
    for (at = tok; *at == '@'; ++at)
        ;

    if (tok[0] == '(' && tok[strlen(tok) - 1] == ')')
    {
        return (group_match(pamh, tok, string, item->debug));
    }
    else if ((at = strchr(at, '@')) != NULL)
    {
        /* split user@host pattern */
        if (item->hostname == NULL)
            return NO;
        memcpy(&fake_item, item, sizeof(fake_item));
        fake_item.from = item->hostname;
        fake_item.gai_rv = 0;
        fake_item.res = NULL;
        fake_item.from_remote_host = 1; /* hostname should be resolvable */
        *at = 0;
        if (!user_match(pamh, tok, item))
            return NO;
        rv = from_match(pamh, at + 1, &fake_item);
        if (fake_item.gai_rv == 0 && fake_item.res)
            freeaddrinfo(fake_item.res);
        return rv;
    }
    else if (tok[0] == '@')
    { /* netgroup */
        const char* hostname = NULL;
        if (tok[1] == '@')
        { /* add hostname to netgroup match */
            if (item->hostname == NULL)
                return NO;
            ++tok;
            hostname = item->hostname;
        }
        return (netgroup_match(pamh, tok + 1, hostname, string, item->debug));
    }
    else if ((rv = string_match(pamh, tok, string, item->debug)) !=
             NO) /* ALL or exact match */
        return rv;
    else if (item->only_new_group_syntax == NO &&
             pam_modutil_user_in_group_nam_nam(pamh, item->user->pw_name, tok))
        /* try group membership */
        return YES;

    return NO;
}
/* user_match - match a username against one token */
match a username against one token
match a username against one token
static int user_match(pam_handle_t* pamh, char* tok, struct login_info* item)
{
    char* string = item->user->pw_name;
    struct login_info fake_item;
    char* at;
    int rv;
    if (item->debug)
        pam_syslog(pamh, LOG_DEBUG, "user_match: tok=%s, item=%s", tok, string);
    for (at = tok; *at == '@'; ++at)
        ;
    if (tok[0] == '(' && tok[strlen(tok) - 1] == ')')
    {
        return (group_match(pamh, tok, string, item->debug));
    }
    else if ((at = strchr(at, '@')) != NULL)
    {
        if (item->hostname == NULL)
            return NO;
        memcpy(&fake_item, item, sizeof(fake_item));
        fake_item.from = item->hostname;
        fake_item.gai_rv = 0;
        fake_item.res = NULL;
        fake_item.from_remote_host = 1; 
        *at = 0;
        if (!user_match(pamh, tok, item))
            return NO;
        rv = from_match(pamh, at + 1, &fake_item);
        if (fake_item.gai_rv == 0 && fake_item.res)
            freeaddrinfo(fake_item.res);
        return rv;
    }
    else if (tok[0] == '@')
    { 
        const char* hostname = NULL;
        if (tok[1] == '@')
        { 
            if (item->hostname == NULL)
                return NO;
            ++tok;
            hostname = item->hostname;
        }
        return (netgroup_match(pamh, tok + 1, hostname, string, item->debug));
    }
    else if ((rv = string_match(pamh, tok, string, item->debug)) !=
             NO) 
        return rv;
    else if (item->only_new_group_syntax == NO &&
             pam_modutil_user_in_group_nam_nam(pamh, item->user->pw_name, tok))
        return YES;
    return NO;
}
static int user_match ( pam_handle_t * pamh , char * tok , struct login_info * item ) { char * string = item -> user -> pw_name ; struct login_info fake_item ; char * at ; int rv ; if ( item -> debug ) pam_syslog ( pamh , LOG_DEBUG , " " , tok , string ) ; for ( at = tok ; * at == ' ' ; ++ at ) ; if ( tok [ 0 ] == ' ' && tok [ strlen ( tok ) - 1 ] == ' ' ) { return ( group_match ( pamh , tok , string , item -> debug ) ) ; } else if ( ( at = strchr ( at , ' ' ) ) != NULL ) { if ( item -> hostname == NULL ) return NO ; memcpy ( & fake_item , item , sizeof ( fake_item ) ) ; fake_item . from = item -> hostname ; fake_item . gai_rv = 0 ; fake_item . res = NULL ; fake_item . from_remote_host = 1 ; * at = 0 ; if ( ! user_match ( pamh , tok , item ) ) return NO ; rv = from_match ( pamh , at + 1 , & fake_item ) ; if ( fake_item . gai_rv == 0 && fake_item . res ) freeaddrinfo ( fake_item . res ) ; return rv ; } else if ( tok [ 0 ] == ' ' ) { const char * hostname = NULL ; if ( tok [ 1 ] == ' ' ) { if ( item -> hostname == NULL ) return NO ; ++ tok ; hostname = item -> hostname ; } return ( netgroup_match ( pamh , tok + 1 , hostname , string , item -> debug ) ) ; } else if ( ( rv = string_match ( pamh , tok , string , item -> debug ) ) != NO ) return rv ; else if ( item -> only_new_group_syntax == NO && pam_modutil_user_in_group_nam_nam ( pamh , item -> user -> pw_name , tok ) ) return YES ; return NO ; }
user_match - match a username against one token
user_match - match a username against one token
/*
     * If a token has the magic value "ALL" the match always succeeds.
     * Otherwise, return YES if the token fully matches the username, if the
     * token is a group that contains the username, or if the token is the
     * name of the user's primary group.
     */ /* Try to split on a pattern (@*[^@]+)(@+.*) */ /* split user@host pattern */ /* hostname should be resolvable */ /* netgroup */ /* add hostname to netgroup match */ /* ALL or exact match */ /* try group membership */