Ignore:
Timestamp:
Dec 20, 2016, 4:07:32 PM (7 years ago)
Author:
Bruno Cornec
Message:

New 3?3 banch for incorporation of latest busybox 1.25. Changing minor version to handle potential incompatibilities.

Location:
branches/3.3
Files:
1 edited
1 copied

Legend:

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

    r3232 r3621  
    66 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
    77 */
    8 #include "libbb.h"
     8//config:config CHPASSWD
     9//config:   bool "chpasswd"
     10//config:   default y
     11//config:   help
     12//config:     Reads a file of user name and password pairs from standard input
     13//config:     and uses this information to update a group of existing users.
     14//config:
     15//config:config FEATURE_DEFAULT_PASSWD_ALGO
     16//config:   string "Default password encryption method (passwd -a, cryptpw -m parameter)"
     17//config:   default "des"
     18//config:   depends on PASSWD || CRYPTPW
     19//config:   help
     20//config:     Possible choices are "d[es]", "m[d5]", "s[ha256]" or "sha512".
     21
     22//applet:IF_CHPASSWD(APPLET(chpasswd, BB_DIR_USR_SBIN, BB_SUID_DROP))
     23
     24//kbuild:lib-$(CONFIG_CHPASSWD) += chpasswd.o
    925
    1026//usage:#define chpasswd_trivial_usage
    11 //usage:    IF_LONG_OPTS("[--md5|--encrypted]") IF_NOT_LONG_OPTS("[-m|-e]")
     27//usage:    IF_LONG_OPTS("[--md5|--encrypted|--crypt-method]") IF_NOT_LONG_OPTS("[-m|-e|-c]")
    1228//usage:#define chpasswd_full_usage "\n\n"
    1329//usage:       "Read user:password from stdin and update /etc/passwd\n"
    1430//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"
     31//usage:     "\n    -e,--encrypted      Supplied passwords are in encrypted form"
     32//usage:     "\n    -m,--md5        Use MD5 encryption instead of DES"
     33//usage:     "\n    -c,--crypt-method   Use the specified method to encrypt the passwords"
    1734//usage:    )
    1835//usage:    IF_NOT_LONG_OPTS(
    1936//usage:     "\n    -e  Supplied passwords are in encrypted form"
    2037//usage:     "\n    -m  Use MD5 encryption instead of DES"
     38//usage:     "\n    -c  Use the specified method to encrypt the passwords"
    2139//usage:    )
    2240
    23 //TODO: implement -c ALGO
     41#include "libbb.h"
    2442
    2543#if ENABLE_LONG_OPTS
    2644static const char chpasswd_longopts[] ALIGN1 =
    27     "encrypted\0" No_argument "e"
    28     "md5\0"       No_argument "m"
     45    "encrypted\0"    No_argument       "e"
     46    "md5\0"          No_argument       "m"
     47    "crypt-method\0" Required_argument "c"
    2948    ;
    3049#endif
     
    3756{
    3857    char *name;
     58    const char *algo = CONFIG_FEATURE_DEFAULT_PASSWD_ALGO;
    3959    int opt;
    4060
     
    4262        bb_error_msg_and_die(bb_msg_perm_denied_are_you_root);
    4363
    44     opt_complementary = "m--e:e--m";
     64    opt_complementary = "m--ec:e--mc:c--em";
    4565    IF_LONG_OPTS(applet_long_options = chpasswd_longopts;)
    46     opt = getopt32(argv, "em");
     66    opt = getopt32(argv, "emc:", &algo);
    4767
    4868    while ((name = xmalloc_fgetline(stdin)) != NULL) {
     
    6080        free_me = NULL;
    6181        if (!(opt & OPT_ENC)) {
    62             char salt[sizeof("$N$XXXXXXXX")];
     82            char salt[MAX_PW_SALT_LEN];
    6383
    64             crypt_make_salt(salt, 1);
    6584            if (opt & OPT_MD5) {
    66                 salt[0] = '$';
    67                 salt[1] = '1';
    68                 salt[2] = '$';
    69                 crypt_make_salt(salt + 3, 4);
     85                /* Force MD5 if the -m flag is set */
     86                algo = "md5";
    7087            }
     88
     89            crypt_make_pw_salt(salt, algo);
    7190            free_me = pass = pw_encrypt(pass, salt, 0);
    7291        }
     
    87106            bb_error_msg_and_die("an error occurred updating password for %s", name);
    88107        if (rc)
    89             bb_info_msg("Password for '%s' changed", name);
     108            bb_error_msg("password for '%s' changed", name);
    90109        logmode = LOGMODE_STDIO;
    91110        free(name);
Note: See TracChangeset for help on using the changeset viewer.