aboutsummaryrefslogtreecommitdiff
path: root/loginutils/addgroup.c
diff options
context:
space:
mode:
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 $ */