[git commit] Add chroot support to chpasswd
Denys Vlasenko
vda.linux at googlemail.com
Wed Aug 1 13:33:41 UTC 2018
commit: https://git.busybox.net/busybox/commit/?id=4e30c67fa0eb0ddd9f68f783ee44806c4495cd82
branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master
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 <kolbyjack at gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
loginutils/chpasswd.c | 18 +++++++++++++-----
1 file 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 @@
//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;
More information about the busybox-cvs
mailing list