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 login_access(pam_handle_t* pamh, struct login_info* item)
{
    FILE* fp;
    char line[BUFSIZ];
    char* perm;  /* becomes permission field */
    char* users; /* becomes list of login names */
    char* froms; /* becomes list of terminals or hosts */
    int match = NO;
    int nonall_match = NO;
    int end;
    int lineno = 0; /* for diagnostics */
    char* sptr;

    if (item->debug)
        pam_syslog(pamh, LOG_DEBUG, "login_access: user=%s, from=%s, file=%s",
                   item->user->pw_name, item->from, item->config_file);

    /*
     * Process the table one line at a time and stop at the first match.
     * Blank lines and lines that begin with a '#' character are ignored.
     * Non-comment lines are broken at the ':' character. All fields are
     * mandatory. The first field should be a "+" or "-" character. A
     * non-existing table means no access control.
     */

    if ((fp = fopen(item->config_file, "r")) != NULL)
    {
        while (!match && fgets(line, sizeof(line), fp))
        {
            lineno++;
            if (line[end = strlen(line) - 1] != '\n')
            {
                pam_syslog(pamh, LOG_ERR,
                           "%s: line %d: missing newline or line too long",
                           item->config_file, lineno);
                continue;
            }
            if (line[0] == '#')
                continue; /* comment line */
            while (end > 0 && isspace(line[end - 1]))
                end--;
            line[end] = 0;    /* strip trailing whitespace */
            if (line[0] == 0) /* skip blank lines */
                continue;

            /* Allow field seperator in last field of froms */
            if (!(perm = strtok_r(line, item->fs, &sptr)) ||
                !(users = strtok_r(NULL, item->fs, &sptr)) ||
                !(froms = strtok_r(NULL, "\n", &sptr)))
            {
                pam_syslog(pamh, LOG_ERR, "%s: line %d: bad field count",
                           item->config_file, lineno);
                continue;
            }
            if (perm[0] != '+' && perm[0] != '-')
            {
                pam_syslog(pamh, LOG_ERR, "%s: line %d: bad first field",
                           item->config_file, lineno);
                continue;
            }
            if (item->debug)
                pam_syslog(pamh, LOG_DEBUG, "line %d: %s : %s : %s", lineno,
                           perm, users, froms);
            match = list_match(pamh, users, NULL, item, user_match);
            if (item->debug)
                pam_syslog(pamh, LOG_DEBUG, "user_match=%d, \"%s\"", match,
                           item->user->pw_name);
            if (match)
            {
                match = list_match(pamh, froms, NULL, item, from_match);
                if (!match && perm[0] == '+')
                {
                    nonall_match = YES;
                }
                if (item->debug)
                    pam_syslog(pamh, LOG_DEBUG, "from_match=%d, \"%s\"", match,
                               item->from);
            }
        }
        (void)fclose(fp);
    }
    else if (errno == ENOENT)
    {
        /* This is no error.  */
        pam_syslog(pamh, LOG_WARNING, "warning: cannot open %s: %m",
                   item->config_file);
    }
    else
    {
        pam_syslog(pamh, LOG_ERR, "cannot open %s: %m", item->config_file);
        return NO;
    }
#ifdef HAVE_LIBAUDIT
    if (!item->noaudit &&
        (match == YES || (match == ALL && nonall_match == YES)) &&
        line[0] == '-')
    {
        pam_modutil_audit_write(pamh, AUDIT_ANOM_LOGIN_LOCATION, "pam_access",
                                0);
    }
#endif
    if (match == NO)
        return NOMATCH;
    if (line[0] == '+')
        return YES;
    return NO;
}
/* login_access - match username/group and host/tty with access control file */
match username/group and host/tty with access control file
match username / group and host / tty with access control file
static int login_access(pam_handle_t* pamh, struct login_info* item)
{
    FILE* fp;
    char line[BUFSIZ];
    char* perm;  
    char* users; 
    char* froms; 
    int match = NO;
    int nonall_match = NO;
    int end;
    int lineno = 0; 
    char* sptr;
    if (item->debug)
        pam_syslog(pamh, LOG_DEBUG, "login_access: user=%s, from=%s, file=%s",
                   item->user->pw_name, item->from, item->config_file);
    if ((fp = fopen(item->config_file, "r")) != NULL)
    {
        while (!match && fgets(line, sizeof(line), fp))
        {
            lineno++;
            if (line[end = strlen(line) - 1] != '\n')
            {
                pam_syslog(pamh, LOG_ERR,
                           "%s: line %d: missing newline or line too long",
                           item->config_file, lineno);
                continue;
            }
            if (line[0] == '#')
                continue; 
            while (end > 0 && isspace(line[end - 1]))
                end--;
            line[end] = 0;    
            if (line[0] == 0) 
                continue;
            if (!(perm = strtok_r(line, item->fs, &sptr)) ||
                !(users = strtok_r(NULL, item->fs, &sptr)) ||
                !(froms = strtok_r(NULL, "\n", &sptr)))
            {
                pam_syslog(pamh, LOG_ERR, "%s: line %d: bad field count",
                           item->config_file, lineno);
                continue;
            }
            if (perm[0] != '+' && perm[0] != '-')
            {
                pam_syslog(pamh, LOG_ERR, "%s: line %d: bad first field",
                           item->config_file, lineno);
                continue;
            }
            if (item->debug)
                pam_syslog(pamh, LOG_DEBUG, "line %d: %s : %s : %s", lineno,
                           perm, users, froms);
            match = list_match(pamh, users, NULL, item, user_match);
            if (item->debug)
                pam_syslog(pamh, LOG_DEBUG, "user_match=%d, \"%s\"", match,
                           item->user->pw_name);
            if (match)
            {
                match = list_match(pamh, froms, NULL, item, from_match);
                if (!match && perm[0] == '+')
                {
                    nonall_match = YES;
                }
                if (item->debug)
                    pam_syslog(pamh, LOG_DEBUG, "from_match=%d, \"%s\"", match,
                               item->from);
            }
        }
        (void)fclose(fp);
    }
    else if (errno == ENOENT)
    {
        pam_syslog(pamh, LOG_WARNING, "warning: cannot open %s: %m",
                   item->config_file);
    }
    else
    {
        pam_syslog(pamh, LOG_ERR, "cannot open %s: %m", item->config_file);
        return NO;
    }
#ifdef HAVE_LIBAUDIT
    if (!item->noaudit &&
        (match == YES || (match == ALL && nonall_match == YES)) &&
        line[0] == '-')
    {
        pam_modutil_audit_write(pamh, AUDIT_ANOM_LOGIN_LOCATION, "pam_access",
                                0);
    }
#endif
    if (match == NO)
        return NOMATCH;
    if (line[0] == '+')
        return YES;
    return NO;
}
static int login_access ( pam_handle_t * pamh , struct login_info * item ) { FILE * fp ; char line [ BUFSIZ ] ; char * perm ; char * users ; char * froms ; int match = NO ; int nonall_match = NO ; int end ; int lineno = 0 ; char * sptr ; if ( item -> debug ) pam_syslog ( pamh , LOG_DEBUG , " " , item -> user -> pw_name , item -> from , item -> config_file ) ; if ( ( fp = fopen ( item -> config_file , " " ) ) != NULL ) { while ( ! match && fgets ( line , sizeof ( line ) , fp ) ) { lineno ++ ; if ( line [ end = strlen ( line ) - 1 ] != ' \n ' ) { pam_syslog ( pamh , LOG_ERR , " " , item -> config_file , lineno ) ; continue ; } if ( line [ 0 ] == ' ' ) continue ; while ( end > 0 && isspace ( line [ end - 1 ] ) ) end -- ; line [ end ] = 0 ; if ( line [ 0 ] == 0 ) continue ; if ( ! ( perm = strtok_r ( line , item -> fs , & sptr ) ) || ! ( users = strtok_r ( NULL , item -> fs , & sptr ) ) || ! ( froms = strtok_r ( NULL , " \n " , & sptr ) ) ) { pam_syslog ( pamh , LOG_ERR , " " , item -> config_file , lineno ) ; continue ; } if ( perm [ 0 ] != ' ' && perm [ 0 ] != ' ' ) { pam_syslog ( pamh , LOG_ERR , " " , item -> config_file , lineno ) ; continue ; } if ( item -> debug ) pam_syslog ( pamh , LOG_DEBUG , " " , lineno , perm , users , froms ) ; match = list_match ( pamh , users , NULL , item , user_match ) ; if ( item -> debug ) pam_syslog ( pamh , LOG_DEBUG , " \" \" " , match , item -> user -> pw_name ) ; if ( match ) { match = list_match ( pamh , froms , NULL , item , from_match ) ; if ( ! match && perm [ 0 ] == ' ' ) { nonall_match = YES ; } if ( item -> debug ) pam_syslog ( pamh , LOG_DEBUG , " \" \" " , match , item -> from ) ; } } ( void ) fclose ( fp ) ; } else if ( errno == ENOENT ) { pam_syslog ( pamh , LOG_WARNING , " " , item -> config_file ) ; } else { pam_syslog ( pamh , LOG_ERR , " " , item -> config_file ) ; return NO ; } #ifdef HAVE_LIBAUDIT if ( ! item -> noaudit && ( match == YES || ( match == ALL && nonall_match == YES ) ) && line [ 0 ] == ' ' ) { pam_modutil_audit_write ( pamh , AUDIT_ANOM_LOGIN_LOCATION , " " , 0 ) ; } #endif if ( match == NO ) return NOMATCH ; if ( line [ 0 ] == ' ' ) return YES ; return NO ; }
login_access - match username/group and host/tty with access control file
login_access - match username / group and host / tty with access control file
/* becomes permission field */ /* becomes list of login names */ /* becomes list of terminals or hosts */ /* for diagnostics */ /*
     * Process the table one line at a time and stop at the first match.
     * Blank lines and lines that begin with a '#' character are ignored.
     * Non-comment lines are broken at the ':' character. All fields are
     * mandatory. The first field should be a "+" or "-" character. A
     * non-existing table means no access control.
     */ /* comment line */ /* strip trailing whitespace */ /* skip blank lines */ /* Allow field seperator in last field of froms */ /* This is no error.  */