aboutsummaryrefslogtreecommitdiff
path: root/loginutils/addgroup.c
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2003-06-20 09:01:58 +0000
committerEric Andersen <andersen@codepoet.org>2003-06-20 09:01:58 +0000
commit8876fb2f59a0b515b3121d5894933eef88ce566a (patch)
treef67de9320202043aca8ded20fb80d668c3b0c2d8 /loginutils/addgroup.c
parentdfce3536ace2bcd38bdd3731841998ce344d786e (diff)
downloadbusybox-w32-8876fb2f59a0b515b3121d5894933eef88ce566a.tar.gz
busybox-w32-8876fb2f59a0b515b3121d5894933eef88ce566a.tar.bz2
busybox-w32-8876fb2f59a0b515b3121d5894933eef88ce566a.zip
last_patch89 from vodz:
Manuel, I rewrite bb_getopt_ulflags() function for more universal usage. My version support now: - options with arguments (optional arg as GNU extension also) - complementaly and/or incomplementaly and/or incongruously and/or list options - long_opt (all applets may have long option, add supporting is trivial) This realisation full compatibile from your version. Code size grow 480 bytes, but only coreutils/* over compensate this size after using new function. Last patch reduced over 800 bytes and not full applied to all. "mkdir" and "mv" applets have long_opt now for demonstrate trivial addition support long_opt with usage new bb_getopt_ulflags(). Complementaly and/or incomplementaly and/or incongruously and/or list options logic is not trivial, but new "cut" and "grep" applets using this logic for examples with full demostrating. New "grep" applet reduced over 300 bytes. Mark, Also. I removed bug from "grep" applet. $ echo a b | busybox grep -e a b a b a b But right is printing one only. --w vodz
Diffstat (limited to 'loginutils/addgroup.c')
-rw-r--r--loginutils/addgroup.c31
1 files changed, 14 insertions, 17 deletions
diff --git a/loginutils/addgroup.c b/loginutils/addgroup.c
index 2e8188dec..af1cd7a83 100644
--- a/loginutils/addgroup.c
+++ b/loginutils/addgroup.c
@@ -122,6 +122,17 @@ static int addgroup(const char *filename, char *group, gid_t gid, const char *us
122 return 0; 122 return 0;
123} 123}
124 124
125#ifndef CONFIG_ADDUSER
126static inline void if_i_am_not_root(void)
127{
128 if (geteuid()) {
129 bb_error_msg_and_die( "Only root may add a user or group to the system.");
130 }
131}
132#else
133extern void if_i_am_not_root(void);
134#endif
135
125/* 136/*
126 * addgroup will take a login_name as its first parameter. 137 * addgroup will take a login_name as its first parameter.
127 * 138 *
@@ -131,21 +142,13 @@ static int addgroup(const char *filename, char *group, gid_t gid, const char *us
131 * ________________________________________________________________________ */ 142 * ________________________________________________________________________ */
132int addgroup_main(int argc, char **argv) 143int addgroup_main(int argc, char **argv)
133{ 144{
134 int opt;
135 char *group; 145 char *group;
136 char *user; 146 char *user;
137 gid_t gid = 0; 147 gid_t gid = 0;
138 148
139 /* get remaining args */ 149 /* get remaining args */
140 while ((opt = getopt (argc, argv, "g:")) != -1) { 150 if(bb_getopt_ulflags(argc, argv, "g:", &group)) {
141 switch (opt) { 151 gid = strtol(group, NULL, 10);
142 case 'g':
143 gid = strtol(optarg, NULL, 10);
144 break;
145 default:
146 bb_show_usage();
147 break;
148 }
149 } 152 }
150 153
151 if (optind < argc) { 154 if (optind < argc) {
@@ -161,14 +164,8 @@ int addgroup_main(int argc, char **argv)
161 } else { 164 } else {
162 user = ""; 165 user = "";
163 } 166 }
164 167 if_i_am_not_root();
165 if (geteuid() != 0) {
166 bb_error_msg_and_die
167 ("Only root may add a group to the system.");
168 }
169 168
170 /* werk */ 169 /* werk */
171 return addgroup(bb_path_group_file, group, gid, user); 170 return addgroup(bb_path_group_file, group, gid, user);
172} 171}
173
174/* $Id: addgroup.c,v 1.10 2003/03/19 09:12:20 mjn3 Exp $ */