From 4e30c67fa0eb0ddd9f68f783ee44806c4495cd82 Mon Sep 17 00:00:00 2001 From: Jon Kolb Date: Tue, 31 Jul 2018 21:30:24 -0400 Subject: Add chroot support to chpasswd function old new delta .rodata 170689 170724 +35 packed_usage 32850 32876 +26 chpasswd_main 411 436 +25 chpasswd_longopts 34 41 +7 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 4/0 up/down: 93/0) Total: 93 bytes Signed-off-by: Jon Kolb Signed-off-by: Denys Vlasenko --- loginutils/chpasswd.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'loginutils') 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 @@ //kbuild:lib-$(CONFIG_CHPASSWD) += chpasswd.o //usage:#define chpasswd_trivial_usage -//usage: IF_LONG_OPTS("[--md5|--encrypted|--crypt-method]") IF_NOT_LONG_OPTS("[-m|-e|-c]") +//usage: IF_LONG_OPTS("[--md5|--encrypted|--crypt-method|--root]") IF_NOT_LONG_OPTS("[-m|-e|-c|-R]") //usage:#define chpasswd_full_usage "\n\n" //usage: "Read user:password from stdin and update /etc/passwd\n" //usage: IF_LONG_OPTS( //usage: "\n -e,--encrypted Supplied passwords are in encrypted form" -//usage: "\n -m,--md5 Eencrypt using md5, not des" +//usage: "\n -m,--md5 Encrypt using md5, not des" //usage: "\n -c,--crypt-method ALG "CRYPT_METHODS_HELP_STR +//usage: "\n -R,--root DIR Directory to chroot into" //usage: ) //usage: IF_NOT_LONG_OPTS( //usage: "\n -e Supplied passwords are in encrypted form" -//usage: "\n -m Eencrypt using md5, not des" +//usage: "\n -m Encrypt using md5, not des" //usage: "\n -c ALG "CRYPT_METHODS_HELP_STR +//usage: "\n -R DIR Directory to chroot into" //usage: ) #include "libbb.h" @@ -45,6 +47,7 @@ static const char chpasswd_longopts[] ALIGN1 = "encrypted\0" No_argument "e" "md5\0" No_argument "m" "crypt-method\0" Required_argument "c" + "root\0" Required_argument "R" ; #endif @@ -56,16 +59,21 @@ int chpasswd_main(int argc UNUSED_PARAM, char **argv) { char *name; const char *algo = CONFIG_FEATURE_DEFAULT_PASSWD_ALGO; + const char *root = NULL; int opt; if (getuid() != 0) bb_error_msg_and_die(bb_msg_perm_denied_are_you_root); - opt = getopt32long(argv, "^" "emc:" "\0" "m--ec:e--mc:c--em", + opt = getopt32long(argv, "^" "emc:R:" "\0" "m--ec:e--mc:c--em", chpasswd_longopts, - &algo + &algo, &root ); + if (root) { + xchroot(root); + } + while ((name = xmalloc_fgetline(stdin)) != NULL) { char *free_me; char *pass; -- cgit v1.2.3