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_unix/support.c
int _set_ctrl(pam_handle_t* pamh, int flags, int* remember, int* rounds,
              int* pass_min_len, int argc, const char** argv)
{
    unsigned int ctrl;
    char* val;
    int j;

    D(("called."));

    ctrl = UNIX_DEFAULTS; /* the default selection of options */

    /* set some flags manually */

    if (getuid() == 0 && !(flags & PAM_CHANGE_EXPIRED_AUTHTOK))
    {
        D(("IAMROOT"));
        set(UNIX__IAMROOT, ctrl);
    }
    if (flags & PAM_UPDATE_AUTHTOK)
    {
        D(("UPDATE_AUTHTOK"));
        set(UNIX__UPDATE, ctrl);
    }
    if (flags & PAM_PRELIM_CHECK)
    {
        D(("PRELIM_CHECK"));
        set(UNIX__PRELIM, ctrl);
    }
    if (flags & PAM_SILENT)
    {
        D(("SILENT"));
        set(UNIX__QUIET, ctrl);
    }

    /* preset encryption method with value from /etc/login.defs */
    val = search_key("ENCRYPT_METHOD", LOGIN_DEFS);
    if (val)
    {
        for (j = 0; j < UNIX_CTRLS_; ++j)
        {
            if (unix_args[j].token && unix_args[j].is_hash_algo &&
                !strncasecmp(val, unix_args[j].token,
                             strlen(unix_args[j].token)))
            {
                break;
            }
        }
        if (j >= UNIX_CTRLS_)
        {
            pam_syslog(pamh, LOG_WARNING,
                       "unrecognized ENCRYPT_METHOD value [%s]", val);
        }
        else
        {
            ctrl &= unix_args[j].mask; /* for turning things off */
            ctrl |= unix_args[j].flag; /* for turning things on  */
        }
        free(val);

        /* read number of rounds for crypt algo */
        if (rounds &&
            (on(UNIX_SHA256_PASS, ctrl) || on(UNIX_SHA512_PASS, ctrl)))
        {
            val = search_key("SHA_CRYPT_MAX_ROUNDS", LOGIN_DEFS);

            if (val)
            {
                *rounds = strtol(val, NULL, 10);
                free(val);
            }
        }
    }

    /* now parse the arguments to this module */

    for (; argc-- > 0; ++argv)
    {
        int sl;

        D(("pam_unix arg: %s", *argv));

        for (j = 0; j < UNIX_CTRLS_; ++j)
        {
            if (unix_args[j].token)
            {
                sl = strlen(unix_args[j].token);
                if (unix_args[j].token[sl - 1] == '=')
                {
                    /* exclude argument from comparison */
                    if (!strncmp(*argv, unix_args[j].token, sl))
                        break;
                }
                else
                {
                    /* compare full strings */
                    if (!strcmp(*argv, unix_args[j].token))
                        break;
                }
            }
        }

        if (j >= UNIX_CTRLS_)
        {
            pam_syslog(pamh, LOG_ERR, "unrecognized option [%s]", *argv);
        }
        else
        {
            /* special cases */
            if (j == UNIX_REMEMBER_PASSWD)
            {
                if (remember == NULL)
                {
                    pam_syslog(
                        pamh, LOG_ERR,
                        "option remember not allowed for this module type");
                    continue;
                }
                *remember = strtol(*argv + 9, NULL, 10);
                if ((*remember == INT_MIN) || (*remember == INT_MAX))
                    *remember = -1;
                if (*remember > 400)
                    *remember = 400;
            }
            else if (j == UNIX_MIN_PASS_LEN)
            {
                if (pass_min_len == NULL)
                {
                    pam_syslog(
                        pamh, LOG_ERR,
                        "option minlen not allowed for this module type");
                    continue;
                }
                *pass_min_len = atoi(*argv + 7);
            }
            else if (j == UNIX_ALGO_ROUNDS)
            {
                if (rounds == NULL)
                {
                    pam_syslog(
                        pamh, LOG_ERR,
                        "option rounds not allowed for this module type");
                    continue;
                }
                *rounds = strtol(*argv + 7, NULL, 10);
            }

            ctrl &= unix_args[j].mask; /* for turning things off */
            ctrl |= unix_args[j].flag; /* for turning things on  */
        }
    }

    if (UNIX_DES_CRYPT(ctrl) && pass_min_len && *pass_min_len > 8)
    {
        pam_syslog(pamh, LOG_NOTICE, "Password minlen reset to 8 characters");
        *pass_min_len = 8;
    }

    if (flags & PAM_DISALLOW_NULL_AUTHTOK)
    {
        D(("DISALLOW_NULL_AUTHTOK"));
        set(UNIX__NONULL, ctrl);
    }

    /* Set default rounds for blowfish */
    if (on(UNIX_BLOWFISH_PASS, ctrl) && off(UNIX_ALGO_ROUNDS, ctrl) &&
        rounds != NULL)
    {
        *rounds = 5;
        set(UNIX_ALGO_ROUNDS, ctrl);
    }

    /* Enforce sane "rounds" values */
    if (on(UNIX_ALGO_ROUNDS, ctrl))
    {
        if (on(UNIX_BLOWFISH_PASS, ctrl))
        {
            if (*rounds < 4 || *rounds > 31)
                *rounds = 5;
        }
        else if (on(UNIX_SHA256_PASS, ctrl) || on(UNIX_SHA512_PASS, ctrl))
        {
            if ((*rounds < 1000) || (*rounds == INT_MAX))
                /* don't care about bogus values */
                unset(UNIX_ALGO_ROUNDS, ctrl);
            if (*rounds >= 10000000)
                *rounds = 9999999;
        }
    }

    /* auditing is a more sensitive version of debug */

    if (on(UNIX_AUDIT, ctrl))
    {
        set(UNIX_DEBUG, ctrl);
    }
    /* return the set of flags */

    D(("done."));
    return ctrl;
}
/*
 * set the control flags for the UNIX module.
 */
set the control flags for the UNIX module.
set the control flags for the UNIX module .
int _set_ctrl(pam_handle_t* pamh, int flags, int* remember, int* rounds,
              int* pass_min_len, int argc, const char** argv)
{
    unsigned int ctrl;
    char* val;
    int j;
    D(("called."));
    ctrl = UNIX_DEFAULTS; 
    if (getuid() == 0 && !(flags & PAM_CHANGE_EXPIRED_AUTHTOK))
    {
        D(("IAMROOT"));
        set(UNIX__IAMROOT, ctrl);
    }
    if (flags & PAM_UPDATE_AUTHTOK)
    {
        D(("UPDATE_AUTHTOK"));
        set(UNIX__UPDATE, ctrl);
    }
    if (flags & PAM_PRELIM_CHECK)
    {
        D(("PRELIM_CHECK"));
        set(UNIX__PRELIM, ctrl);
    }
    if (flags & PAM_SILENT)
    {
        D(("SILENT"));
        set(UNIX__QUIET, ctrl);
    }
    val = search_key("ENCRYPT_METHOD", LOGIN_DEFS);
    if (val)
    {
        for (j = 0; j < UNIX_CTRLS_; ++j)
        {
            if (unix_args[j].token && unix_args[j].is_hash_algo &&
                !strncasecmp(val, unix_args[j].token,
                             strlen(unix_args[j].token)))
            {
                break;
            }
        }
        if (j >= UNIX_CTRLS_)
        {
            pam_syslog(pamh, LOG_WARNING,
                       "unrecognized ENCRYPT_METHOD value [%s]", val);
        }
        else
        {
            ctrl &= unix_args[j].mask; 
            ctrl |= unix_args[j].flag; 
        }
        free(val);
        if (rounds &&
            (on(UNIX_SHA256_PASS, ctrl) || on(UNIX_SHA512_PASS, ctrl)))
        {
            val = search_key("SHA_CRYPT_MAX_ROUNDS", LOGIN_DEFS);
            if (val)
            {
                *rounds = strtol(val, NULL, 10);
                free(val);
            }
        }
    }
    for (; argc-- > 0; ++argv)
    {
        int sl;
        D(("pam_unix arg: %s", *argv));
        for (j = 0; j < UNIX_CTRLS_; ++j)
        {
            if (unix_args[j].token)
            {
                sl = strlen(unix_args[j].token);
                if (unix_args[j].token[sl - 1] == '=')
                {
                    if (!strncmp(*argv, unix_args[j].token, sl))
                        break;
                }
                else
                {
                    if (!strcmp(*argv, unix_args[j].token))
                        break;
                }
            }
        }
        if (j >= UNIX_CTRLS_)
        {
            pam_syslog(pamh, LOG_ERR, "unrecognized option [%s]", *argv);
        }
        else
        {
            if (j == UNIX_REMEMBER_PASSWD)
            {
                if (remember == NULL)
                {
                    pam_syslog(
                        pamh, LOG_ERR,
                        "option remember not allowed for this module type");
                    continue;
                }
                *remember = strtol(*argv + 9, NULL, 10);
                if ((*remember == INT_MIN) || (*remember == INT_MAX))
                    *remember = -1;
                if (*remember > 400)
                    *remember = 400;
            }
            else if (j == UNIX_MIN_PASS_LEN)
            {
                if (pass_min_len == NULL)
                {
                    pam_syslog(
                        pamh, LOG_ERR,
                        "option minlen not allowed for this module type");
                    continue;
                }
                *pass_min_len = atoi(*argv + 7);
            }
            else if (j == UNIX_ALGO_ROUNDS)
            {
                if (rounds == NULL)
                {
                    pam_syslog(
                        pamh, LOG_ERR,
                        "option rounds not allowed for this module type");
                    continue;
                }
                *rounds = strtol(*argv + 7, NULL, 10);
            }
            ctrl &= unix_args[j].mask; 
            ctrl |= unix_args[j].flag; 
        }
    }
    if (UNIX_DES_CRYPT(ctrl) && pass_min_len && *pass_min_len > 8)
    {
        pam_syslog(pamh, LOG_NOTICE, "Password minlen reset to 8 characters");
        *pass_min_len = 8;
    }
    if (flags & PAM_DISALLOW_NULL_AUTHTOK)
    {
        D(("DISALLOW_NULL_AUTHTOK"));
        set(UNIX__NONULL, ctrl);
    }
    if (on(UNIX_BLOWFISH_PASS, ctrl) && off(UNIX_ALGO_ROUNDS, ctrl) &&
        rounds != NULL)
    {
        *rounds = 5;
        set(UNIX_ALGO_ROUNDS, ctrl);
    }
    if (on(UNIX_ALGO_ROUNDS, ctrl))
    {
        if (on(UNIX_BLOWFISH_PASS, ctrl))
        {
            if (*rounds < 4 || *rounds > 31)
                *rounds = 5;
        }
        else if (on(UNIX_SHA256_PASS, ctrl) || on(UNIX_SHA512_PASS, ctrl))
        {
            if ((*rounds < 1000) || (*rounds == INT_MAX))
                unset(UNIX_ALGO_ROUNDS, ctrl);
            if (*rounds >= 10000000)
                *rounds = 9999999;
        }
    }
    if (on(UNIX_AUDIT, ctrl))
    {
        set(UNIX_DEBUG, ctrl);
    }
    D(("done."));
    return ctrl;
}
int _set_ctrl ( pam_handle_t * pamh , int flags , int * remember , int * rounds , int * pass_min_len , int argc , const char * * argv ) { unsigned int ctrl ; char * val ; int j ; D ( ( " " ) ) ; ctrl = UNIX_DEFAULTS ; if ( getuid ( ) == 0 && ! ( flags & PAM_CHANGE_EXPIRED_AUTHTOK ) ) { D ( ( " " ) ) ; set ( UNIX__IAMROOT , ctrl ) ; } if ( flags & PAM_UPDATE_AUTHTOK ) { D ( ( " " ) ) ; set ( UNIX__UPDATE , ctrl ) ; } if ( flags & PAM_PRELIM_CHECK ) { D ( ( " " ) ) ; set ( UNIX__PRELIM , ctrl ) ; } if ( flags & PAM_SILENT ) { D ( ( " " ) ) ; set ( UNIX__QUIET , ctrl ) ; } val = search_key ( " " , LOGIN_DEFS ) ; if ( val ) { for ( j = 0 ; j < UNIX_CTRLS_ ; ++ j ) { if ( unix_args [ j ] . token && unix_args [ j ] . is_hash_algo && ! strncasecmp ( val , unix_args [ j ] . token , strlen ( unix_args [ j ] . token ) ) ) { break ; } } if ( j >= UNIX_CTRLS_ ) { pam_syslog ( pamh , LOG_WARNING , " " , val ) ; } else { ctrl &= unix_args [ j ] . mask ; ctrl |= unix_args [ j ] . flag ; } free ( val ) ; if ( rounds && ( on ( UNIX_SHA256_PASS , ctrl ) || on ( UNIX_SHA512_PASS , ctrl ) ) ) { val = search_key ( " " , LOGIN_DEFS ) ; if ( val ) { * rounds = strtol ( val , NULL , 10 ) ; free ( val ) ; } } } for ( ; argc -- > 0 ; ++ argv ) { int sl ; D ( ( " " , * argv ) ) ; for ( j = 0 ; j < UNIX_CTRLS_ ; ++ j ) { if ( unix_args [ j ] . token ) { sl = strlen ( unix_args [ j ] . token ) ; if ( unix_args [ j ] . token [ sl - 1 ] == ' ' ) { if ( ! strncmp ( * argv , unix_args [ j ] . token , sl ) ) break ; } else { if ( ! strcmp ( * argv , unix_args [ j ] . token ) ) break ; } } } if ( j >= UNIX_CTRLS_ ) { pam_syslog ( pamh , LOG_ERR , " " , * argv ) ; } else { if ( j == UNIX_REMEMBER_PASSWD ) { if ( remember == NULL ) { pam_syslog ( pamh , LOG_ERR , " " ) ; continue ; } * remember = strtol ( * argv + 9 , NULL , 10 ) ; if ( ( * remember == INT_MIN ) || ( * remember == INT_MAX ) ) * remember = -1 ; if ( * remember > 400 ) * remember = 400 ; } else if ( j == UNIX_MIN_PASS_LEN ) { if ( pass_min_len == NULL ) { pam_syslog ( pamh , LOG_ERR , " " ) ; continue ; } * pass_min_len = atoi ( * argv + 7 ) ; } else if ( j == UNIX_ALGO_ROUNDS ) { if ( rounds == NULL ) { pam_syslog ( pamh , LOG_ERR , " " ) ; continue ; } * rounds = strtol ( * argv + 7 , NULL , 10 ) ; } ctrl &= unix_args [ j ] . mask ; ctrl |= unix_args [ j ] . flag ; } } if ( UNIX_DES_CRYPT ( ctrl ) && pass_min_len && * pass_min_len > 8 ) { pam_syslog ( pamh , LOG_NOTICE , " " ) ; * pass_min_len = 8 ; } if ( flags & PAM_DISALLOW_NULL_AUTHTOK ) { D ( ( " " ) ) ; set ( UNIX__NONULL , ctrl ) ; } if ( on ( UNIX_BLOWFISH_PASS , ctrl ) && off ( UNIX_ALGO_ROUNDS , ctrl ) && rounds != NULL ) { * rounds = 5 ; set ( UNIX_ALGO_ROUNDS , ctrl ) ; } if ( on ( UNIX_ALGO_ROUNDS , ctrl ) ) { if ( on ( UNIX_BLOWFISH_PASS , ctrl ) ) { if ( * rounds < 4 || * rounds > 31 ) * rounds = 5 ; } else if ( on ( UNIX_SHA256_PASS , ctrl ) || on ( UNIX_SHA512_PASS , ctrl ) ) { if ( ( * rounds < 1000 ) || ( * rounds == INT_MAX ) ) unset ( UNIX_ALGO_ROUNDS , ctrl ) ; if ( * rounds >= 10000000 ) * rounds = 9999999 ; } } if ( on ( UNIX_AUDIT , ctrl ) ) { set ( UNIX_DEBUG , ctrl ) ; } D ( ( " " ) ) ; return ctrl ; }
set the control flags for the UNIX module.
set the control flags for the UNIX module .
/* the default selection of options */ /* set some flags manually */ /* preset encryption method with value from /etc/login.defs */ /* for turning things off */ /* for turning things on  */ /* read number of rounds for crypt algo */ /* now parse the arguments to this module */ /* exclude argument from comparison */ /* compare full strings */ /* special cases */ /* for turning things off */ /* for turning things on  */ /* Set default rounds for blowfish */ /* Enforce sane "rounds" values */ /* don't care about bogus values */ /* auditing is a more sensitive version of debug */ /* return the set of flags */