aboutsummaryrefslogtreecommitdiff
path: root/loginutils
diff options
context:
space:
mode:
authorvda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277>2007-03-13 13:01:14 +0000
committervda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277>2007-03-13 13:01:14 +0000
commitbf07ea7cef9740b0f10121a8e39965d4f7c7f0e2 (patch)
tree41763239e81807259b7532aeef540ebc4804ce3d /loginutils
parent35284053c70e23ba1f7cf6484194dafe0cef6258 (diff)
downloadbusybox-w32-bf07ea7cef9740b0f10121a8e39965d4f7c7f0e2.tar.gz
busybox-w32-bf07ea7cef9740b0f10121a8e39965d4f7c7f0e2.tar.bz2
busybox-w32-bf07ea7cef9740b0f10121a8e39965d4f7c7f0e2.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 git-svn-id: svn://busybox.net/trunk/busybox@18085 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'loginutils')
-rw-r--r--loginutils/addgroup.c45
-rw-r--r--loginutils/adduser.c35
-rw-r--r--loginutils/passwd.c26
-rw-r--r--loginutils/sulogin.c15
4 files changed, 66 insertions, 55 deletions
diff --git a/loginutils/addgroup.c b/loginutils/addgroup.c
index 768d2c061..78250a418 100644
--- a/loginutils/addgroup.c
+++ b/loginutils/addgroup.c
@@ -15,35 +15,37 @@
15 * return 1 on failure */ 15 * return 1 on failure */
16static int group_study(struct group *g) 16static int group_study(struct group *g)
17{ 17{
18 enum { max = 65000 };
18 FILE *etc_group; 19 FILE *etc_group;
19 gid_t desired; 20 gid_t desired;
20 21 /* Using _r function to avoid static buffers pulled in */
21 struct group *grp; 22 char buffer[256];
22 const int max = 65000; 23 struct group grp;
24 struct group *result;
23 25
24 etc_group = xfopen(bb_path_group_file, "r"); 26 etc_group = xfopen(bb_path_group_file, "r");
25 27
26 /* make sure gr_name isn't taken, make sure gid is kosher */ 28 /* make sure gr_name isn't taken, make sure gid is kosher */
27 desired = g->gr_gid; 29 desired = g->gr_gid;
28 while ((grp = fgetgrent(etc_group))) { 30 while (!fgetgrent_r(etc_group, &grp, buffer, sizeof(buffer), &result)) {
29 if ((strcmp(grp->gr_name, g->gr_name)) == 0) { 31 if ((strcmp(grp.gr_name, g->gr_name)) == 0) {
30 bb_error_msg_and_die("%s: group already in use", g->gr_name); 32 bb_error_msg_and_die("%s: group already in use", g->gr_name);
31 } 33 }
32 if ((desired) && grp->gr_gid == desired) { 34 if ((desired) && grp.gr_gid == desired) {
33 bb_error_msg_and_die("%d: gid already in use", 35 bb_error_msg_and_die("%d: gid already in use",
34 desired); 36 desired);
35 } 37 }
36 if ((grp->gr_gid > g->gr_gid) && (grp->gr_gid < max)) { 38 if ((grp.gr_gid > g->gr_gid) && (grp.gr_gid < max)) {
37 g->gr_gid = grp->gr_gid; 39 g->gr_gid = grp.gr_gid;
38 } 40 }
39 } 41 }
40 fclose(etc_group); 42 if (ENABLE_FEATURE_CLEAN_UP)
43 fclose(etc_group);
41 44
42 /* gid */ 45 /* gid */
46 g->gr_gid++;
43 if (desired) { 47 if (desired) {
44 g->gr_gid = desired; 48 g->gr_gid = desired;
45 } else {
46 g->gr_gid++;
47 } 49 }
48 /* return 1; */ 50 /* return 1; */
49 return 0; 51 return 0;
@@ -65,12 +67,16 @@ static int addgroup(char *group, gid_t gid, const char *user)
65 file = xfopen(bb_path_group_file, "a"); 67 file = xfopen(bb_path_group_file, "a");
66 /* group:passwd:gid:userlist */ 68 /* group:passwd:gid:userlist */
67 fprintf(file, "%s:%s:%d:%s\n", group, "x", gr.gr_gid, user); 69 fprintf(file, "%s:%s:%d:%s\n", group, "x", gr.gr_gid, user);
68 fclose(file); 70 if (ENABLE_FEATURE_CLEAN_UP)
71 fclose(file);
69 72
70#if ENABLE_FEATURE_SHADOWPASSWDS 73#if ENABLE_FEATURE_SHADOWPASSWDS
71 file = xfopen(bb_path_gshadow_file, "a"); 74 file = fopen_or_warn(bb_path_gshadow_file, "a");
72 fprintf(file, "%s:!::\n", group); 75 if (file) {
73 fclose(file); 76 fprintf(file, "%s:!::\n", group);
77 if (ENABLE_FEATURE_CLEAN_UP)
78 fclose(file);
79 }
74#endif 80#endif
75 81
76 /* return 1; */ 82 /* return 1; */
@@ -80,10 +86,8 @@ static int addgroup(char *group, gid_t gid, const char *user)
80/* 86/*
81 * addgroup will take a login_name as its first parameter. 87 * addgroup will take a login_name as its first parameter.
82 * 88 *
83 * gid 89 * gid can be customized via command-line parameters.
84 * 90 */
85 * can be customized via command-line parameters.
86 * ________________________________________________________________________ */
87int addgroup_main(int argc, char **argv); 91int addgroup_main(int argc, char **argv);
88int addgroup_main(int argc, char **argv) 92int addgroup_main(int argc, char **argv)
89{ 93{
@@ -103,6 +107,5 @@ int addgroup_main(int argc, char **argv)
103 bb_error_msg_and_die(bb_msg_perm_denied_are_you_root); 107 bb_error_msg_and_die(bb_msg_perm_denied_are_you_root);
104 } 108 }
105 109
106 /* werk */ 110 return addgroup(argv[0], gid, argv[1] ? argv[1] : "");
107 return addgroup(argv[0], gid, (argv[1]) ? argv[1] : "");
108} 111}
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}
diff --git a/loginutils/passwd.c b/loginutils/passwd.c
index 4531e63a6..b937ce45e 100644
--- a/loginutils/passwd.c
+++ b/loginutils/passwd.c
@@ -252,6 +252,13 @@ int passwd_main(int argc, char **argv)
252 struct rlimit rlimit_fsize; 252 struct rlimit rlimit_fsize;
253 char c; 253 char c;
254 254
255#if ENABLE_FEATURE_SHADOWPASSWDS
256 /* Using _r function to avoid pulling in static buffers */
257 struct spwd spw;
258 struct spwd *result;
259 char buffer[256];
260#endif
261
255 logmode = LOGMODE_BOTH; 262 logmode = LOGMODE_BOTH;
256 openlog(applet_name, LOG_NOWAIT, LOG_AUTH); 263 openlog(applet_name, LOG_NOWAIT, LOG_AUTH);
257 opt = getopt32(argc, argv, "a:lud", &opt_a); 264 opt = getopt32(argc, argv, "a:lud", &opt_a);
@@ -278,17 +285,14 @@ int passwd_main(int argc, char **argv)
278 285
279 filename = bb_path_passwd_file; 286 filename = bb_path_passwd_file;
280#if ENABLE_FEATURE_SHADOWPASSWDS 287#if ENABLE_FEATURE_SHADOWPASSWDS
281 { 288 if (getspnam_r(pw->pw_name, &spw, buffer, sizeof(buffer), &result)) {
282 struct spwd *sp = getspnam(name); 289 /* LOGMODE_BOTH */
283 if (!sp) { 290 bb_error_msg("no record of %s in %s, using %s",
284 /* LOGMODE_BOTH */ 291 name, bb_path_shadow_file,
285 bb_error_msg("no record of %s in %s, using %s", 292 bb_path_passwd_file);
286 name, bb_path_shadow_file, 293 } else {
287 bb_path_passwd_file); 294 filename = bb_path_shadow_file;
288 } else { 295 pw->pw_passwd = spw.sp_pwdp;
289 filename = bb_path_shadow_file;
290 pw->pw_passwd = sp->sp_pwdp;
291 }
292 } 296 }
293#endif 297#endif
294 298
diff --git a/loginutils/sulogin.c b/loginutils/sulogin.c
index 8e3095c87..38503f7b1 100644
--- a/loginutils/sulogin.c
+++ b/loginutils/sulogin.c
@@ -43,6 +43,12 @@ int sulogin_main(int argc, char **argv)
43 const char * const *p; 43 const char * const *p;
44 struct passwd *pwd; 44 struct passwd *pwd;
45 const char *shell; 45 const char *shell;
46#if ENABLE_FEATURE_SHADOWPASSWDS
47 /* Using _r function to avoid pulling in static buffers */
48 char buffer[256];
49 struct spwd spw;
50 struct spwd *result;
51#endif
46 52
47 logmode = LOGMODE_BOTH; 53 logmode = LOGMODE_BOTH;
48 openlog(applet_name, 0, LOG_AUTH); 54 openlog(applet_name, 0, LOG_AUTH);
@@ -76,13 +82,10 @@ int sulogin_main(int argc, char **argv)
76 } 82 }
77 83
78#if ENABLE_FEATURE_SHADOWPASSWDS 84#if ENABLE_FEATURE_SHADOWPASSWDS
79 { 85 if (getspnam_r(pwd->pw_name, &spw, buffer, sizeof(buffer), &result)) {
80 struct spwd *spwd = getspnam(pwd->pw_name); 86 goto auth_error;
81 if (!spwd) {
82 goto auth_error;
83 }
84 pwd->pw_passwd = spwd->sp_pwdp;
85 } 87 }
88 pwd->pw_passwd = spw.sp_pwdp;
86#endif 89#endif
87 90
88 while (1) { 91 while (1) {