diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-03-13 13:01:14 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-03-13 13:01:14 +0000 |
commit | 5df955fce2fbdc5b2acc365a120327ff943403da (patch) | |
tree | 41763239e81807259b7532aeef540ebc4804ce3d /loginutils/addgroup.c | |
parent | c9c893d4f59418c50c8eb42bd80390026e123dd8 (diff) | |
download | busybox-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/addgroup.c')
-rw-r--r-- | loginutils/addgroup.c | 45 |
1 files changed, 24 insertions, 21 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 */ |
16 | static int group_study(struct group *g) | 16 | static 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 | * ________________________________________________________________________ */ | ||
87 | int addgroup_main(int argc, char **argv); | 91 | int addgroup_main(int argc, char **argv); |
88 | int addgroup_main(int argc, char **argv) | 92 | int 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 | } |