aboutsummaryrefslogtreecommitdiff
path: root/loginutils/adduser.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-03-13 13:01:14 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-03-13 13:01:14 +0000
commit5df955fce2fbdc5b2acc365a120327ff943403da (patch)
tree41763239e81807259b7532aeef540ebc4804ce3d /loginutils/adduser.c
parentc9c893d4f59418c50c8eb42bd80390026e123dd8 (diff)
downloadbusybox-w32-5df955fce2fbdc5b2acc365a120327ff943403da.tar.gz
busybox-w32-5df955fce2fbdc5b2acc365a120327ff943403da.tar.bz2
busybox-w32-5df955fce2fbdc5b2acc365a120327ff943403da.zip
Do not fail password check if shadow password does not exist -
fall back to ordinary one Reduced usage of functions returning datain static buffers. (mostly passwd/group/shadow related): function old new delta correct_password 143 193 +50 sulogin_main 490 533 +43 adduser_main 732 774 +42 passwd_main 1875 1915 +40 addgroup_main 330 365 +35 bb_internal_getspnam 38 - -38 bb_internal_fgetpwent 38 - -38 bb_internal_fgetgrent 38 - -38 static.resultbuf 168 88 -80 static.buffer 1872 1104 -768 ------------------------------------------------------------------------------ (add/remove: 0/3 grow/shrink: 5/2 up/down: 210/-962) Total: -752 bytes
Diffstat (limited to 'loginutils/adduser.c')
-rw-r--r--loginutils/adduser.c35
1 files changed, 18 insertions, 17 deletions
diff --git a/loginutils/adduser.c b/loginutils/adduser.c
index e0cdd1ced..4c03790d8 100644
--- a/loginutils/adduser.c
+++ b/loginutils/adduser.c
@@ -10,19 +10,21 @@
10 10
11#include "busybox.h" 11#include "busybox.h"
12 12
13#define DONT_SET_PASS (1 << 4) 13#define OPT_DONT_SET_PASS (1 << 4)
14#define DONT_MAKE_HOME (1 << 6) 14#define OPT_DONT_MAKE_HOME (1 << 6)
15 15
16 16
17/* remix */ 17/* remix */
18/* EDR recoded such that the uid may be passed in *p */ 18/* EDR recoded such that the uid may be passed in *p */
19static int passwd_study(const char *filename, struct passwd *p) 19static int passwd_study(const char *filename, struct passwd *p)
20{ 20{
21 struct passwd *pw; 21 enum { min = 500, max = 65000 };
22 FILE *passwd; 22 FILE *passwd;
23 23 /* We are using reentrant fgetpwent_r() in order to avoid
24 const int min = 500; 24 * pulling in static buffers from libc (think static build here) */
25 const int max = 65000; 25 char buffer[256];
26 struct passwd pw;
27 struct passwd *result;
26 28
27 passwd = xfopen(filename, "r"); 29 passwd = xfopen(filename, "r");
28 30
@@ -34,14 +36,14 @@ static int passwd_study(const char *filename, struct passwd *p)
34 * make sure login isn't taken; 36 * make sure login isn't taken;
35 * find free uid and gid; 37 * find free uid and gid;
36 */ 38 */
37 while ((pw = fgetpwent(passwd))) { 39 while (!fgetpwent_r(passwd, &pw, buffer, sizeof(buffer), &result)) {
38 if (strcmp(pw->pw_name, p->pw_name) == 0) { 40 if (strcmp(pw.pw_name, p->pw_name) == 0) {
39 /* return 0; */ 41 /* return 0; */
40 return 1; 42 return 1;
41 } 43 }
42 if ((pw->pw_uid >= p->pw_uid) && (pw->pw_uid < max) 44 if ((pw.pw_uid >= p->pw_uid) && (pw.pw_uid < max)
43 && (pw->pw_uid >= min)) { 45 && (pw.pw_uid >= min)) {
44 p->pw_uid = pw->pw_uid + 1; 46 p->pw_uid = pw.pw_uid + 1;
45 } 47 }
46 } 48 }
47 49
@@ -85,7 +87,7 @@ static void passwd_wrapper(const char *login)
85} 87}
86 88
87/* putpwent(3) remix */ 89/* putpwent(3) remix */
88static int adduser(struct passwd *p, unsigned long flags) 90static int adduser(struct passwd *p)
89{ 91{
90 FILE *file; 92 FILE *file;
91 int addgroup = !p->pw_gid; 93 int addgroup = !p->pw_gid;
@@ -130,7 +132,7 @@ static int adduser(struct passwd *p, unsigned long flags)
130 /* Clear the umask for this process so it doesn't 132 /* Clear the umask for this process so it doesn't
131 * * screw up the permissions on the mkdir and chown. */ 133 * * screw up the permissions on the mkdir and chown. */
132 umask(0); 134 umask(0);
133 if (!(flags & DONT_MAKE_HOME)) { 135 if (!(option_mask32 & OPT_DONT_MAKE_HOME)) {
134 /* Set the owner and group so it is owned by the new user, 136 /* Set the owner and group so it is owned by the new user,
135 then fix up the permissions to 2755. Can't do it before 137 then fix up the permissions to 2755. Can't do it before
136 since chown will clear the setgid bit */ 138 since chown will clear the setgid bit */
@@ -141,7 +143,7 @@ static int adduser(struct passwd *p, unsigned long flags)
141 } 143 }
142 } 144 }
143 145
144 if (!(flags & DONT_SET_PASS)) { 146 if (!(option_mask32 & OPT_DONT_SET_PASS)) {
145 /* interactively set passwd */ 147 /* interactively set passwd */
146 passwd_wrapper(p->pw_name); 148 passwd_wrapper(p->pw_name);
147 } 149 }
@@ -163,7 +165,6 @@ int adduser_main(int argc, char **argv)
163{ 165{
164 struct passwd pw; 166 struct passwd pw;
165 const char *usegroup = NULL; 167 const char *usegroup = NULL;
166 unsigned long flags;
167 168
168 /* got root? */ 169 /* got root? */
169 if (geteuid()) { 170 if (geteuid()) {
@@ -176,7 +177,7 @@ int adduser_main(int argc, char **argv)
176 177
177 /* check for min, max and missing args and exit on error */ 178 /* check for min, max and missing args and exit on error */
178 opt_complementary = "-1:?1:?"; 179 opt_complementary = "-1:?1:?";
179 flags = getopt32(argc, argv, "h:g:s:G:DSH", &pw.pw_dir, &pw.pw_gecos, &pw.pw_shell, &usegroup); 180 getopt32(argc, argv, "h:g:s:G:DSH", &pw.pw_dir, &pw.pw_gecos, &pw.pw_shell, &usegroup);
180 181
181 /* create string for $HOME if not specified already */ 182 /* create string for $HOME if not specified already */
182 if (!pw.pw_dir) { 183 if (!pw.pw_dir) {
@@ -191,5 +192,5 @@ int adduser_main(int argc, char **argv)
191 pw.pw_gid = usegroup ? xgroup2gid(usegroup) : 0; /* exits on failure */ 192 pw.pw_gid = usegroup ? xgroup2gid(usegroup) : 0; /* exits on failure */
192 193
193 /* grand finale */ 194 /* grand finale */
194 return adduser(&pw, flags); 195 return adduser(&pw);
195} 196}