Ignore:
Timestamp:
Jan 1, 2014, 12:47:38 AM (7 years ago)
Author:
Bruno Cornec
Message:
  • Update mindi-busybox to 1.21.1
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3.2/mindi-busybox/loginutils/chpasswd.c

    r2725 r3232  
    77 */
    88#include "libbb.h"
     9
     10//usage:#define chpasswd_trivial_usage
     11//usage:    IF_LONG_OPTS("[--md5|--encrypted]") IF_NOT_LONG_OPTS("[-m|-e]")
     12//usage:#define chpasswd_full_usage "\n\n"
     13//usage:       "Read user:password from stdin and update /etc/passwd\n"
     14//usage:    IF_LONG_OPTS(
     15//usage:     "\n    -e,--encrypted  Supplied passwords are in encrypted form"
     16//usage:     "\n    -m,--md5    Use MD5 encryption instead of DES"
     17//usage:    )
     18//usage:    IF_NOT_LONG_OPTS(
     19//usage:     "\n    -e  Supplied passwords are in encrypted form"
     20//usage:     "\n    -m  Use MD5 encryption instead of DES"
     21//usage:    )
     22
     23//TODO: implement -c ALGO
    924
    1025#if ENABLE_LONG_OPTS
     
    2136int chpasswd_main(int argc UNUSED_PARAM, char **argv)
    2237{
    23     char *name, *pass;
    24     char salt[sizeof("$N$XXXXXXXX")];
    25     int opt, rc;
    26     int rnd = rnd; /* we *want* it to be non-initialized! */
     38    char *name;
     39    int opt;
    2740
    28     if (getuid())
     41    if (getuid() != 0)
    2942        bb_error_msg_and_die(bb_msg_perm_denied_are_you_root);
    3043
     
    3447
    3548    while ((name = xmalloc_fgetline(stdin)) != NULL) {
     49        char *free_me;
     50        char *pass;
     51        int rc;
     52
    3653        pass = strchr(name, ':');
    3754        if (!pass)
     
    4158        xuname2uid(name); /* dies if there is no such user */
    4259
     60        free_me = NULL;
    4361        if (!(opt & OPT_ENC)) {
    44             rnd = crypt_make_salt(salt, 1, rnd);
     62            char salt[sizeof("$N$XXXXXXXX")];
     63
     64            crypt_make_salt(salt, 1);
    4565            if (opt & OPT_MD5) {
    46                 strcpy(salt, "$1$");
    47                 rnd = crypt_make_salt(salt + 3, 4, rnd);
     66                salt[0] = '$';
     67                salt[1] = '1';
     68                salt[2] = '$';
     69                crypt_make_salt(salt + 3, 4);
    4870            }
    49             pass = pw_encrypt(pass, salt, 0);
     71            free_me = pass = pw_encrypt(pass, salt, 0);
    5072        }
    5173
     
    5476#if ENABLE_FEATURE_SHADOWPASSWDS
    5577        rc = update_passwd(bb_path_shadow_file, name, pass, NULL);
    56         if (rc == 0) /* no lines updated, no errors detected */
     78        if (rc > 0) /* password in /etc/shadow was updated */
     79            pass = (char*)"x";
     80        if (rc >= 0)
     81            /* 0 = /etc/shadow missing (not an error), >0 = passwd changed in /etc/shadow */
    5782#endif
    5883            rc = update_passwd(bb_path_passwd_file, name, pass, NULL);
     
    6590        logmode = LOGMODE_STDIO;
    6691        free(name);
    67         if (!(opt & OPT_ENC))
    68             free(pass);
     92        free(free_me);
    6993    }
    7094    return EXIT_SUCCESS;
Note: See TracChangeset for help on using the changeset viewer.