diff options
-rw-r--r-- | loginutils/chpasswd.c | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/loginutils/chpasswd.c b/loginutils/chpasswd.c index 652e4f127..4b3602e7a 100644 --- a/loginutils/chpasswd.c +++ b/loginutils/chpasswd.c | |||
@@ -24,18 +24,20 @@ | |||
24 | //kbuild:lib-$(CONFIG_CHPASSWD) += chpasswd.o | 24 | //kbuild:lib-$(CONFIG_CHPASSWD) += chpasswd.o |
25 | 25 | ||
26 | //usage:#define chpasswd_trivial_usage | 26 | //usage:#define chpasswd_trivial_usage |
27 | //usage: IF_LONG_OPTS("[--md5|--encrypted|--crypt-method]") IF_NOT_LONG_OPTS("[-m|-e|-c]") | 27 | //usage: IF_LONG_OPTS("[--md5|--encrypted|--crypt-method|--root]") IF_NOT_LONG_OPTS("[-m|-e|-c|-R]") |
28 | //usage:#define chpasswd_full_usage "\n\n" | 28 | //usage:#define chpasswd_full_usage "\n\n" |
29 | //usage: "Read user:password from stdin and update /etc/passwd\n" | 29 | //usage: "Read user:password from stdin and update /etc/passwd\n" |
30 | //usage: IF_LONG_OPTS( | 30 | //usage: IF_LONG_OPTS( |
31 | //usage: "\n -e,--encrypted Supplied passwords are in encrypted form" | 31 | //usage: "\n -e,--encrypted Supplied passwords are in encrypted form" |
32 | //usage: "\n -m,--md5 Eencrypt using md5, not des" | 32 | //usage: "\n -m,--md5 Encrypt using md5, not des" |
33 | //usage: "\n -c,--crypt-method ALG "CRYPT_METHODS_HELP_STR | 33 | //usage: "\n -c,--crypt-method ALG "CRYPT_METHODS_HELP_STR |
34 | //usage: "\n -R,--root DIR Directory to chroot into" | ||
34 | //usage: ) | 35 | //usage: ) |
35 | //usage: IF_NOT_LONG_OPTS( | 36 | //usage: IF_NOT_LONG_OPTS( |
36 | //usage: "\n -e Supplied passwords are in encrypted form" | 37 | //usage: "\n -e Supplied passwords are in encrypted form" |
37 | //usage: "\n -m Eencrypt using md5, not des" | 38 | //usage: "\n -m Encrypt using md5, not des" |
38 | //usage: "\n -c ALG "CRYPT_METHODS_HELP_STR | 39 | //usage: "\n -c ALG "CRYPT_METHODS_HELP_STR |
40 | //usage: "\n -R DIR Directory to chroot into" | ||
39 | //usage: ) | 41 | //usage: ) |
40 | 42 | ||
41 | #include "libbb.h" | 43 | #include "libbb.h" |
@@ -45,6 +47,7 @@ static const char chpasswd_longopts[] ALIGN1 = | |||
45 | "encrypted\0" No_argument "e" | 47 | "encrypted\0" No_argument "e" |
46 | "md5\0" No_argument "m" | 48 | "md5\0" No_argument "m" |
47 | "crypt-method\0" Required_argument "c" | 49 | "crypt-method\0" Required_argument "c" |
50 | "root\0" Required_argument "R" | ||
48 | ; | 51 | ; |
49 | #endif | 52 | #endif |
50 | 53 | ||
@@ -56,16 +59,21 @@ int chpasswd_main(int argc UNUSED_PARAM, char **argv) | |||
56 | { | 59 | { |
57 | char *name; | 60 | char *name; |
58 | const char *algo = CONFIG_FEATURE_DEFAULT_PASSWD_ALGO; | 61 | const char *algo = CONFIG_FEATURE_DEFAULT_PASSWD_ALGO; |
62 | const char *root = NULL; | ||
59 | int opt; | 63 | int opt; |
60 | 64 | ||
61 | if (getuid() != 0) | 65 | if (getuid() != 0) |
62 | bb_error_msg_and_die(bb_msg_perm_denied_are_you_root); | 66 | bb_error_msg_and_die(bb_msg_perm_denied_are_you_root); |
63 | 67 | ||
64 | opt = getopt32long(argv, "^" "emc:" "\0" "m--ec:e--mc:c--em", | 68 | opt = getopt32long(argv, "^" "emc:R:" "\0" "m--ec:e--mc:c--em", |
65 | chpasswd_longopts, | 69 | chpasswd_longopts, |
66 | &algo | 70 | &algo, &root |
67 | ); | 71 | ); |
68 | 72 | ||
73 | if (root) { | ||
74 | xchroot(root); | ||
75 | } | ||
76 | |||
69 | while ((name = xmalloc_fgetline(stdin)) != NULL) { | 77 | while ((name = xmalloc_fgetline(stdin)) != NULL) { |
70 | char *free_me; | 78 | char *free_me; |
71 | char *pass; | 79 | char *pass; |