diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-07-27 11:20:10 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-07-27 11:20:10 +0000 |
commit | 3734b946bfef55c8f63d367422da5c7aa7b972db (patch) | |
tree | 1bdd3e14523002dc8276d167b17f900e40fa6dff /loginutils | |
parent | 661f6fad77b672a5f6648b01275eb9ff19c59139 (diff) | |
download | busybox-w32-3734b946bfef55c8f63d367422da5c7aa7b972db.tar.gz busybox-w32-3734b946bfef55c8f63d367422da5c7aa7b972db.tar.bz2 busybox-w32-3734b946bfef55c8f63d367422da5c7aa7b972db.zip |
bb_getpwuid, bb_getgrgid: change order of arguments to more intuitive one;
comment thoroughly when they die and when they dont.
Diffstat (limited to 'loginutils')
-rw-r--r-- | loginutils/passwd.c | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/loginutils/passwd.c b/loginutils/passwd.c index cd98d4101..a293ee926 100644 --- a/loginutils/passwd.c +++ b/loginutils/passwd.c | |||
@@ -51,13 +51,13 @@ static char* new_password(const struct passwd *pw, uid_t myuid, int algo) | |||
51 | goto err_ret; | 51 | goto err_ret; |
52 | } | 52 | } |
53 | 53 | ||
54 | /*memset(salt, 0, sizeof(salt)); - why?*/ | ||
55 | crypt_make_salt(salt, 1, 0); /* des */ | 54 | crypt_make_salt(salt, 1, 0); /* des */ |
56 | if (algo) { /* MD5 */ | 55 | if (algo) { /* MD5 */ |
57 | strcpy(salt, "$1$"); | 56 | strcpy(salt, "$1$"); |
58 | crypt_make_salt(salt + 3, 4, 0); | 57 | crypt_make_salt(salt + 3, 4, 0); |
59 | } | 58 | } |
60 | ret = xstrdup(pw_encrypt(newp, salt)); /* returns ptr to static */ | 59 | /* pw_encrypt returns ptr to static */ |
60 | ret = xstrdup(pw_encrypt(newp, salt)); | ||
61 | /* whee, success! */ | 61 | /* whee, success! */ |
62 | 62 | ||
63 | err_ret: | 63 | err_ret: |
@@ -80,7 +80,7 @@ int passwd_main(int argc, char **argv) | |||
80 | OPT_delete = 0x8, /* -d - delete password */ | 80 | OPT_delete = 0x8, /* -d - delete password */ |
81 | OPT_lud = 0xe, | 81 | OPT_lud = 0xe, |
82 | STATE_ALGO_md5 = 0x10, | 82 | STATE_ALGO_md5 = 0x10, |
83 | /*STATE_ALGO_des = 0x20, not needed yet */ | 83 | //STATE_ALGO_des = 0x20, not needed yet |
84 | }; | 84 | }; |
85 | unsigned opt; | 85 | unsigned opt; |
86 | int rc; | 86 | int rc; |
@@ -104,7 +104,7 @@ int passwd_main(int argc, char **argv) | |||
104 | logmode = LOGMODE_BOTH; | 104 | logmode = LOGMODE_BOTH; |
105 | openlog(applet_name, LOG_NOWAIT, LOG_AUTH); | 105 | openlog(applet_name, LOG_NOWAIT, LOG_AUTH); |
106 | opt = getopt32(argc, argv, "a:lud", &opt_a); | 106 | opt = getopt32(argc, argv, "a:lud", &opt_a); |
107 | argc -= optind; | 107 | //argc -= optind; |
108 | argv += optind; | 108 | argv += optind; |
109 | 109 | ||
110 | if (strcasecmp(opt_a, "des") != 0) /* -a */ | 110 | if (strcasecmp(opt_a, "des") != 0) /* -a */ |
@@ -112,11 +112,13 @@ int passwd_main(int argc, char **argv) | |||
112 | //else | 112 | //else |
113 | // opt |= STATE_ALGO_des; | 113 | // opt |= STATE_ALGO_des; |
114 | myuid = getuid(); | 114 | myuid = getuid(); |
115 | if ((opt & OPT_lud) && (!argc || myuid)) | 115 | /* -l, -u, -d require root priv and username argument */ |
116 | if ((opt & OPT_lud) && (myuid || !argv[0])) | ||
116 | bb_show_usage(); | 117 | bb_show_usage(); |
117 | 118 | ||
118 | myname = xstrdup(bb_getpwuid(NULL, myuid, -1)); | 119 | /* Will complain and die if username not found */ |
119 | name = argc ? argv[0] : myname; | 120 | myname = xstrdup(bb_getpwuid(NULL, -1, myuid)); |
121 | name = argv[0] ? argv[0] : myname; | ||
120 | 122 | ||
121 | pw = getpwnam(name); | 123 | pw = getpwnam(name); |
122 | if (!pw) bb_error_msg_and_die("unknown user %s", name); | 124 | if (!pw) bb_error_msg_and_die("unknown user %s", name); |
@@ -158,9 +160,12 @@ int passwd_main(int argc, char **argv) | |||
158 | newp = xasprintf("!%s", pw->pw_passwd); | 160 | newp = xasprintf("!%s", pw->pw_passwd); |
159 | } else if (opt & OPT_unlock) { | 161 | } else if (opt & OPT_unlock) { |
160 | if (c) goto skip; /* not '!' */ | 162 | if (c) goto skip; /* not '!' */ |
163 | /* pw->pw_passwd pints to static storage, | ||
164 | * strdup'ing to avoid nasty surprizes */ | ||
161 | newp = xstrdup(&pw->pw_passwd[1]); | 165 | newp = xstrdup(&pw->pw_passwd[1]); |
162 | } else if (opt & OPT_delete) { | 166 | } else if (opt & OPT_delete) { |
163 | newp = xstrdup(""); | 167 | //newp = xstrdup(""); |
168 | newp = (char*)""; | ||
164 | } | 169 | } |
165 | 170 | ||
166 | rlimit_fsize.rlim_cur = rlimit_fsize.rlim_max = 512L * 30000; | 171 | rlimit_fsize.rlim_cur = rlimit_fsize.rlim_max = 512L * 30000; |
@@ -177,8 +182,8 @@ int passwd_main(int argc, char **argv) | |||
177 | filename); | 182 | filename); |
178 | bb_info_msg("Password for %s changed by %s", name, myname); | 183 | bb_info_msg("Password for %s changed by %s", name, myname); |
179 | 184 | ||
180 | if (ENABLE_FEATURE_CLEAN_UP) free(newp); | 185 | //if (ENABLE_FEATURE_CLEAN_UP) free(newp); |
181 | skip: | 186 | skip: |
182 | if (!newp) { | 187 | if (!newp) { |
183 | bb_error_msg_and_die("password for %s is already %slocked", | 188 | bb_error_msg_and_die("password for %s is already %slocked", |
184 | name, (opt & OPT_unlock) ? "un" : ""); | 189 | name, (opt & OPT_unlock) ? "un" : ""); |