openbmc/build/tmp/deploy/sdk/witherspoon-2019-08-08/sysroots/armv6-openbmc-linux-gnueabi/usr/src/debug/shadow/4.6-r0/shadow-4.6/src/newusers.c
static int add_passwd(struct passwd* pwd, const char* password)
{
    const struct spwd* sp;
    struct spwd spent;
    char* cp;

#ifndef USE_PAM
    void* crypt_arg = NULL;
    if (crypt_method != NULL)
    {
#ifdef USE_SHA_CRYPT
        if (sflg)
        {
            crypt_arg = &sha_rounds;
        }
#endif /* USE_SHA_CRYPT */
    }

    /*
     * In the case of regular password files, this is real easy - pwd
     * points to the entry in the password file. Shadow files are
     * harder since there are zillions of things to do ...
     */
    if (!is_shadow)
    {
        return update_passwd(pwd, password);
    }
#endif /* USE_PAM */

    /*
     * Do the first and easiest shadow file case. The user already
     * exists in the shadow password file.
     */
    sp = spw_locate(pwd->pw_name);
#ifndef USE_PAM
    if (NULL != sp)
    {
        spent = *sp;
        if ((NULL != crypt_method) && (0 == strcmp(crypt_method, "NONE")))
        {
            spent.sp_pwdp = (char*)password;
        }
        else
        {
            const char* salt = crypt_make_salt(crypt_method, crypt_arg);
            cp = pw_encrypt(password, salt);
            if (NULL == cp)
            {
                fprintf(stderr,
                        _("%s: failed to crypt password with salt '%s': %s\n"),
                        Prog, salt, strerror(errno));
                return 1;
            }
            spent.sp_pwdp = cp;
        }
        spent.sp_lstchg = (long)gettime() / SCALE;
        if (0 == spent.sp_lstchg)
        {
            /* Better disable aging than requiring a password
             * change */
            spent.sp_lstchg = -1;
        }
        return (spw_update(&spent) == 0);
    }

    /*
     * Pick the next easiest case - the user has an encrypted password
     * which isn't equal to "x". The password was set to "x" earlier
     * when the entry was created, so this user would have to have had
     * the password set someplace else.
     */
    if (strcmp(pwd->pw_passwd, "x") != 0)
    {
        return update_passwd(pwd, password);
    }
#else  /* USE_PAM */
    /*
     * If there is already a shadow entry, do not touch it.
     * If there is already a passwd entry with a password, do not
     * touch it.
     * The password will be updated later for all users using PAM.
     */
    if ((NULL != sp) || (strcmp(pwd->pw_passwd, "x") != 0))
    {
        return 0;
    }
#endif /* USE_PAM */

    /*
     * Now the really hard case - I need to create an entirely new
     * shadow password file entry.
     */
    spent.sp_namp = pwd->pw_name;
#ifndef USE_PAM
    if ((crypt_method != NULL) && (0 == strcmp(crypt_method, "NONE")))
    {
        spent.sp_pwdp = (char*)password;
    }
    else
    {
        const char* salt = crypt_make_salt(crypt_method, crypt_arg);
        cp = pw_encrypt(password, salt);
        if (NULL == cp)
        {
            fprintf(stderr,
                    _("%s: failed to crypt password with salt '%s': %s\n"),
                    Prog, salt, strerror(errno));
            return 1;
        }
        spent.sp_pwdp = cp;
    }
#else
    /*
     * Lock the password.
     * The password will be updated later for all users using PAM.
     */
    spent.sp_pwdp = "!";
#endif
    spent.sp_lstchg = (long)gettime() / SCALE;
    if (0 == spent.sp_lstchg)
    {
        /* Better disable aging than requiring a password change */
        spent.sp_lstchg = -1;
    }
    spent.sp_min = getdef_num("PASS_MIN_DAYS", 0);
    /* 10000 is infinity this week */
    spent.sp_max = getdef_num("PASS_MAX_DAYS", 10000);
    spent.sp_warn = getdef_num("PASS_WARN_AGE", -1);
    spent.sp_inact = -1;
    spent.sp_expire = -1;
    spent.sp_flag = SHADOW_SP_FLAG_UNSET;

    return (spw_update(&spent) == 0);
}
/*
 * add_passwd - add or update the encrypted password
 */
add or update the encrypted password
add or update the encrypted password
static int add_passwd(struct passwd* pwd, const char* password)
{
    const struct spwd* sp;
    struct spwd spent;
    char* cp;
#ifndef USE_PAM
    void* crypt_arg = NULL;
    if (crypt_method != NULL)
    {
#ifdef USE_SHA_CRYPT
        if (sflg)
        {
            crypt_arg = &sha_rounds;
        }
#endif 
    }
    if (!is_shadow)
    {
        return update_passwd(pwd, password);
    }
#endif 
    sp = spw_locate(pwd->pw_name);
#ifndef USE_PAM
    if (NULL != sp)
    {
        spent = *sp;
        if ((NULL != crypt_method) && (0 == strcmp(crypt_method, "NONE")))
        {
            spent.sp_pwdp = (char*)password;
        }
        else
        {
            const char* salt = crypt_make_salt(crypt_method, crypt_arg);
            cp = pw_encrypt(password, salt);
            if (NULL == cp)
            {
                fprintf(stderr,
                        _("%s: failed to crypt password with salt '%s': %s\n"),
                        Prog, salt, strerror(errno));
                return 1;
            }
            spent.sp_pwdp = cp;
        }
        spent.sp_lstchg = (long)gettime() / SCALE;
        if (0 == spent.sp_lstchg)
        {
            spent.sp_lstchg = -1;
        }
        return (spw_update(&spent) == 0);
    }
    if (strcmp(pwd->pw_passwd, "x") != 0)
    {
        return update_passwd(pwd, password);
    }
#else  
    if ((NULL != sp) || (strcmp(pwd->pw_passwd, "x") != 0))
    {
        return 0;
    }
#endif 
    spent.sp_namp = pwd->pw_name;
#ifndef USE_PAM
    if ((crypt_method != NULL) && (0 == strcmp(crypt_method, "NONE")))
    {
        spent.sp_pwdp = (char*)password;
    }
    else
    {
        const char* salt = crypt_make_salt(crypt_method, crypt_arg);
        cp = pw_encrypt(password, salt);
        if (NULL == cp)
        {
            fprintf(stderr,
                    _("%s: failed to crypt password with salt '%s': %s\n"),
                    Prog, salt, strerror(errno));
            return 1;
        }
        spent.sp_pwdp = cp;
    }
#else
    spent.sp_pwdp = "!";
#endif
    spent.sp_lstchg = (long)gettime() / SCALE;
    if (0 == spent.sp_lstchg)
    {
        spent.sp_lstchg = -1;
    }
    spent.sp_min = getdef_num("PASS_MIN_DAYS", 0);
    spent.sp_max = getdef_num("PASS_MAX_DAYS", 10000);
    spent.sp_warn = getdef_num("PASS_WARN_AGE", -1);
    spent.sp_inact = -1;
    spent.sp_expire = -1;
    spent.sp_flag = SHADOW_SP_FLAG_UNSET;
    return (spw_update(&spent) == 0);
}
static int add_passwd ( struct passwd * pwd , const char * password ) { const struct spwd * sp ; struct spwd spent ; char * cp ; #ifndef USE_PAM void * crypt_arg = NULL ; if ( crypt_method != NULL ) { #ifdef USE_SHA_CRYPT if ( sflg ) { crypt_arg = & sha_rounds ; } #endif } if ( ! is_shadow ) { return update_passwd ( pwd , password ) ; } #endif sp = spw_locate ( pwd -> pw_name ) ; #ifndef USE_PAM if ( NULL != sp ) { spent = * sp ; if ( ( NULL != crypt_method ) && ( 0 == strcmp ( crypt_method , " " ) ) ) { spent . sp_pwdp = ( char * ) password ; } else { const char * salt = crypt_make_salt ( crypt_method , crypt_arg ) ; cp = pw_encrypt ( password , salt ) ; if ( NULL == cp ) { fprintf ( stderr , _ ( " \n " ) , Prog , salt , strerror ( errno ) ) ; return 1 ; } spent . sp_pwdp = cp ; } spent . sp_lstchg = ( long ) gettime ( ) / SCALE ; if ( 0 == spent . sp_lstchg ) { spent . sp_lstchg = -1 ; } return ( spw_update ( & spent ) == 0 ) ; } if ( strcmp ( pwd -> pw_passwd , " " ) != 0 ) { return update_passwd ( pwd , password ) ; } #else if ( ( NULL != sp ) || ( strcmp ( pwd -> pw_passwd , " " ) != 0 ) ) { return 0 ; } #endif spent . sp_namp = pwd -> pw_name ; #ifndef USE_PAM if ( ( crypt_method != NULL ) && ( 0 == strcmp ( crypt_method , " " ) ) ) { spent . sp_pwdp = ( char * ) password ; } else { const char * salt = crypt_make_salt ( crypt_method , crypt_arg ) ; cp = pw_encrypt ( password , salt ) ; if ( NULL == cp ) { fprintf ( stderr , _ ( " \n " ) , Prog , salt , strerror ( errno ) ) ; return 1 ; } spent . sp_pwdp = cp ; } #else spent . sp_pwdp = " " ; #endif spent . sp_lstchg = ( long ) gettime ( ) / SCALE ; if ( 0 == spent . sp_lstchg ) { spent . sp_lstchg = -1 ; } spent . sp_min = getdef_num ( " " , 0 ) ; spent . sp_max = getdef_num ( " " , 10000 ) ; spent . sp_warn = getdef_num ( " " , -1 ) ; spent . sp_inact = -1 ; spent . sp_expire = -1 ; spent . sp_flag = SHADOW_SP_FLAG_UNSET ; return ( spw_update ( & spent ) == 0 ) ; }
add_passwd - add or update the encrypted password
add_passwd - add or update the encrypted password
/* USE_SHA_CRYPT */ /*
     * In the case of regular password files, this is real easy - pwd
     * points to the entry in the password file. Shadow files are
     * harder since there are zillions of things to do ...
     */ /* USE_PAM */ /*
     * Do the first and easiest shadow file case. The user already
     * exists in the shadow password file.
     */ /* Better disable aging than requiring a password
             * change */ /*
     * Pick the next easiest case - the user has an encrypted password
     * which isn't equal to "x". The password was set to "x" earlier
     * when the entry was created, so this user would have to have had
     * the password set someplace else.
     */ /* USE_PAM */ /*
     * If there is already a shadow entry, do not touch it.
     * If there is already a passwd entry with a password, do not
     * touch it.
     * The password will be updated later for all users using PAM.
     */ /* USE_PAM */ /*
     * Now the really hard case - I need to create an entirely new
     * shadow password file entry.
     */ /*
     * Lock the password.
     * The password will be updated later for all users using PAM.
     */ /* Better disable aging than requiring a password change */ /* 10000 is infinity this week */