diff options
author | Bernhard Reutner-Fischer <rep.dot.nop@gmail.com> | 2008-07-21 14:41:33 +0000 |
---|---|---|
committer | Bernhard Reutner-Fischer <rep.dot.nop@gmail.com> | 2008-07-21 14:41:33 +0000 |
commit | d73cbd31a295ac757e59f129f162d9cd69440224 (patch) | |
tree | 53d9c4cff7223be124698ec8cc3ccba4bded52eb | |
parent | a53de7f7c2cd3ac46b26642aafb1a573a096a80d (diff) | |
download | busybox-w32-d73cbd31a295ac757e59f129f162d9cd69440224.tar.gz busybox-w32-d73cbd31a295ac757e59f129f162d9cd69440224.tar.bz2 busybox-w32-d73cbd31a295ac757e59f129f162d9cd69440224.zip |
- first pass to unify/cleanup uid handling (-236b)
This needs further love, alot of love.. Tito?
-rw-r--r-- | coreutils/install.c | 4 | ||||
-rw-r--r-- | include/libbb.h | 2 | ||||
-rw-r--r-- | libbb/bb_pwd.c | 2 | ||||
-rw-r--r-- | libpwdgrp/uidgid_get.c | 8 | ||||
-rw-r--r-- | loginutils/passwd.c | 5 | ||||
-rw-r--r-- | loginutils/vlock.c | 2 | ||||
-rw-r--r-- | miscutils/crontab.c | 4 | ||||
-rw-r--r-- | networking/httpd.c | 4 | ||||
-rw-r--r-- | networking/libiproute/libnetlink.c | 2 | ||||
-rw-r--r-- | networking/tcpudp.c | 7 | ||||
-rw-r--r-- | networking/tftp.c | 2 | ||||
-rw-r--r-- | procps/renice.c | 2 | ||||
-rw-r--r-- | runit/chpst.c | 8 |
13 files changed, 26 insertions, 26 deletions
diff --git a/coreutils/install.c b/coreutils/install.c index c5d7a0cc5..c7ddbb214 100644 --- a/coreutils/install.c +++ b/coreutils/install.c | |||
@@ -170,7 +170,7 @@ int install_main(int argc, char **argv) | |||
170 | 170 | ||
171 | /* Set the file mode */ | 171 | /* Set the file mode */ |
172 | if ((flags & OPT_MODE) && chmod(dest, mode) == -1) { | 172 | if ((flags & OPT_MODE) && chmod(dest, mode) == -1) { |
173 | bb_perror_msg("cannot change permissions of %s", dest); | 173 | bb_perror_msg("can't change %s of %s", "permissions", dest); |
174 | ret = EXIT_FAILURE; | 174 | ret = EXIT_FAILURE; |
175 | } | 175 | } |
176 | #if ENABLE_SELINUX | 176 | #if ENABLE_SELINUX |
@@ -181,7 +181,7 @@ int install_main(int argc, char **argv) | |||
181 | if ((flags & (OPT_OWNER|OPT_GROUP)) | 181 | if ((flags & (OPT_OWNER|OPT_GROUP)) |
182 | && lchown(dest, uid, gid) == -1 | 182 | && lchown(dest, uid, gid) == -1 |
183 | ) { | 183 | ) { |
184 | bb_perror_msg("cannot change ownership of %s", dest); | 184 | bb_perror_msg("can't change %s of %s", "ownership", dest); |
185 | ret = EXIT_FAILURE; | 185 | ret = EXIT_FAILURE; |
186 | } | 186 | } |
187 | if (flags & OPT_STRIP) { | 187 | if (flags & OPT_STRIP) { |
diff --git a/include/libbb.h b/include/libbb.h index 4e4e37911..4b2a839a5 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -691,6 +691,8 @@ struct bb_uidgid_t { | |||
691 | }; | 691 | }; |
692 | /* always sets uid and gid */ | 692 | /* always sets uid and gid */ |
693 | int get_uidgid(struct bb_uidgid_t*, const char*, int numeric_ok) FAST_FUNC; | 693 | int get_uidgid(struct bb_uidgid_t*, const char*, int numeric_ok) FAST_FUNC; |
694 | /* always sets uid and gid, allows numeric; exits on failure */ | ||
695 | void xget_uidgid(struct bb_uidgid_t*, const char*) FAST_FUNC; | ||
694 | /* chown-like handling of "user[:[group]" */ | 696 | /* chown-like handling of "user[:[group]" */ |
695 | void parse_chown_usergroup_or_die(struct bb_uidgid_t *u, char *user_group) FAST_FUNC; | 697 | void parse_chown_usergroup_or_die(struct bb_uidgid_t *u, char *user_group) FAST_FUNC; |
696 | /* bb_getpwuid, bb_getgrgid: | 698 | /* bb_getpwuid, bb_getgrgid: |
diff --git a/libbb/bb_pwd.c b/libbb/bb_pwd.c index b03dc8399..65eb69200 100644 --- a/libbb/bb_pwd.c +++ b/libbb/bb_pwd.c | |||
@@ -82,7 +82,7 @@ long FAST_FUNC xuname2uid(const char *name) | |||
82 | 82 | ||
83 | myuser = getpwnam(name); | 83 | myuser = getpwnam(name); |
84 | if (myuser == NULL) | 84 | if (myuser == NULL) |
85 | bb_error_msg_and_die("unknown user name: %s", name); | 85 | bb_error_msg_and_die("unknown user %s", name); |
86 | 86 | ||
87 | return myuser->pw_uid; | 87 | return myuser->pw_uid; |
88 | } | 88 | } |
diff --git a/libpwdgrp/uidgid_get.c b/libpwdgrp/uidgid_get.c index 88f4e2545..dc7cc6614 100644 --- a/libpwdgrp/uidgid_get.c +++ b/libpwdgrp/uidgid_get.c | |||
@@ -76,6 +76,11 @@ int FAST_FUNC get_uidgid(struct bb_uidgid_t *u, const char *ug, int numeric_ok) | |||
76 | } | 76 | } |
77 | return 1; | 77 | return 1; |
78 | } | 78 | } |
79 | void FAST_FUNC xget_uidgid(struct bb_uidgid_t *u, const char *ug) | ||
80 | { | ||
81 | if (!get_uidgid(u, ug, 1)) | ||
82 | bb_error_msg_and_die("unknown user/group %s", ug); | ||
83 | } | ||
79 | 84 | ||
80 | /* chown-like: | 85 | /* chown-like: |
81 | * "user" sets uid only, | 86 | * "user" sets uid only, |
@@ -106,8 +111,7 @@ void FAST_FUNC parse_chown_usergroup_or_die(struct bb_uidgid_t *u, char *user_gr | |||
106 | } else { | 111 | } else { |
107 | if (!group[1]) /* "user:" */ | 112 | if (!group[1]) /* "user:" */ |
108 | *group = '\0'; | 113 | *group = '\0'; |
109 | if (!get_uidgid(u, user_group, 1)) | 114 | xget_uidgid(u, user_group); |
110 | bb_error_msg_and_die("unknown user/group %s", user_group); | ||
111 | } | 115 | } |
112 | } | 116 | } |
113 | 117 | ||
diff --git a/loginutils/passwd.c b/loginutils/passwd.c index 84e5aeb6d..99fb76eca 100644 --- a/loginutils/passwd.c +++ b/loginutils/passwd.c | |||
@@ -27,7 +27,7 @@ static char* new_password(const struct passwd *pw, uid_t myuid, int algo) | |||
27 | goto err_ret; | 27 | goto err_ret; |
28 | encrypted = pw_encrypt(orig, pw->pw_passwd, 1); /* returns malloced str */ | 28 | encrypted = pw_encrypt(orig, pw->pw_passwd, 1); /* returns malloced str */ |
29 | if (strcmp(encrypted, pw->pw_passwd) != 0) { | 29 | if (strcmp(encrypted, pw->pw_passwd) != 0) { |
30 | syslog(LOG_WARNING, "incorrect password for '%s'", | 30 | syslog(LOG_WARNING, "incorrect password for %s", |
31 | pw->pw_name); | 31 | pw->pw_name); |
32 | bb_do_delay(FAIL_DELAY); | 32 | bb_do_delay(FAIL_DELAY); |
33 | puts("Incorrect password"); | 33 | puts("Incorrect password"); |
@@ -119,7 +119,8 @@ int passwd_main(int argc UNUSED_PARAM, char **argv) | |||
119 | name = argv[0] ? argv[0] : myname; | 119 | name = argv[0] ? argv[0] : myname; |
120 | 120 | ||
121 | pw = getpwnam(name); | 121 | pw = getpwnam(name); |
122 | if (!pw) bb_error_msg_and_die("unknown user %s", name); | 122 | if (!pw) |
123 | bb_error_msg_and_die("unknown user %s", name); | ||
123 | if (myuid && pw->pw_uid != myuid) { | 124 | if (myuid && pw->pw_uid != myuid) { |
124 | /* LOGMODE_BOTH */ | 125 | /* LOGMODE_BOTH */ |
125 | bb_error_msg_and_die("%s can't change password for %s", myname, name); | 126 | bb_error_msg_and_die("%s can't change password for %s", myname, name); |
diff --git a/loginutils/vlock.c b/loginutils/vlock.c index 442272a05..42ef44732 100644 --- a/loginutils/vlock.c +++ b/loginutils/vlock.c | |||
@@ -40,7 +40,7 @@ int vlock_main(int argc UNUSED_PARAM, char **argv) | |||
40 | struct vt_mode ovtm; | 40 | struct vt_mode ovtm; |
41 | uid_t uid; | 41 | uid_t uid; |
42 | struct passwd *pw; | 42 | struct passwd *pw; |
43 | 43 | /* XXX: xgetpwuid */ | |
44 | uid = getuid(); | 44 | uid = getuid(); |
45 | pw = getpwuid(uid); | 45 | pw = getpwuid(uid); |
46 | if (pw == NULL) | 46 | if (pw == NULL) |
diff --git a/miscutils/crontab.c b/miscutils/crontab.c index 64ea4e616..f8662babb 100644 --- a/miscutils/crontab.c +++ b/miscutils/crontab.c | |||
@@ -129,11 +129,11 @@ int crontab_main(int argc UNUSED_PARAM, char **argv) | |||
129 | if (!pas) | 129 | if (!pas) |
130 | bb_error_msg_and_die("user %s is not known", user_name); | 130 | bb_error_msg_and_die("user %s is not known", user_name); |
131 | } else { | 131 | } else { |
132 | /* XXX: xgetpwuid */ | ||
132 | uid_t my_uid = getuid(); | 133 | uid_t my_uid = getuid(); |
133 | pas = getpwuid(my_uid); | 134 | pas = getpwuid(my_uid); |
134 | if (!pas) | 135 | if (!pas) |
135 | bb_perror_msg_and_die("no user record for UID %u", | 136 | bb_perror_msg_and_die("unknown uid %d", (int)my_uid); |
136 | (unsigned)my_uid); | ||
137 | } | 137 | } |
138 | 138 | ||
139 | #define user_name DONT_USE_ME_BEYOND_THIS_POINT | 139 | #define user_name DONT_USE_ME_BEYOND_THIS_POINT |
diff --git a/networking/httpd.c b/networking/httpd.c index f7e044d27..8c4242e44 100644 --- a/networking/httpd.c +++ b/networking/httpd.c | |||
@@ -2351,9 +2351,7 @@ int httpd_main(int argc UNUSED_PARAM, char **argv) | |||
2351 | #endif | 2351 | #endif |
2352 | #if ENABLE_FEATURE_HTTPD_SETUID | 2352 | #if ENABLE_FEATURE_HTTPD_SETUID |
2353 | if (opt & OPT_SETUID) { | 2353 | if (opt & OPT_SETUID) { |
2354 | if (!get_uidgid(&ugid, s_ugid, 1)) | 2354 | xget_uidgid(&ugid, s_ugid); |
2355 | bb_error_msg_and_die("unknown user[:group] " | ||
2356 | "name '%s'", s_ugid); | ||
2357 | } | 2355 | } |
2358 | #endif | 2356 | #endif |
2359 | 2357 | ||
diff --git a/networking/libiproute/libnetlink.c b/networking/libiproute/libnetlink.c index 6b599d91c..01454fbf5 100644 --- a/networking/libiproute/libnetlink.c +++ b/networking/libiproute/libnetlink.c | |||
@@ -37,7 +37,7 @@ int FAST_FUNC xrtnl_open(struct rtnl_handle *rth/*, unsigned subscriptions*/) | |||
37 | xbind(rth->fd, (struct sockaddr*)&rth->local, sizeof(rth->local)); | 37 | xbind(rth->fd, (struct sockaddr*)&rth->local, sizeof(rth->local)); |
38 | addr_len = sizeof(rth->local); | 38 | addr_len = sizeof(rth->local); |
39 | if (getsockname(rth->fd, (struct sockaddr*)&rth->local, &addr_len) < 0) | 39 | if (getsockname(rth->fd, (struct sockaddr*)&rth->local, &addr_len) < 0) |
40 | bb_perror_msg_and_die("cannot getsockname"); | 40 | bb_perror_msg_and_die("getsockname"); |
41 | if (addr_len != sizeof(rth->local)) | 41 | if (addr_len != sizeof(rth->local)) |
42 | bb_error_msg_and_die("wrong address length %d", addr_len); | 42 | bb_error_msg_and_die("wrong address length %d", addr_len); |
43 | if (rth->local.nl_family != AF_NETLINK) | 43 | if (rth->local.nl_family != AF_NETLINK) |
diff --git a/networking/tcpudp.c b/networking/tcpudp.c index 29408c5be..d6731198c 100644 --- a/networking/tcpudp.c +++ b/networking/tcpudp.c | |||
@@ -216,8 +216,7 @@ int tcpudpsvd_main(int argc UNUSED_PARAM, char **argv) | |||
216 | if (max_per_host > cmax) | 216 | if (max_per_host > cmax) |
217 | max_per_host = cmax; | 217 | max_per_host = cmax; |
218 | if (option_mask32 & OPT_u) { | 218 | if (option_mask32 & OPT_u) { |
219 | if (!get_uidgid(&ugid, user, 1)) | 219 | xget_uidgid(&ugid, user); |
220 | bb_error_msg_and_die("unknown user/group: %s", user); | ||
221 | } | 220 | } |
222 | #ifdef SSLSVD | 221 | #ifdef SSLSVD |
223 | if (option_mask32 & OPT_U) ssluser = optarg; | 222 | if (option_mask32 & OPT_U) ssluser = optarg; |
@@ -245,9 +244,9 @@ int tcpudpsvd_main(int argc UNUSED_PARAM, char **argv) | |||
245 | if (option_mask32 & OPT_u) | 244 | if (option_mask32 & OPT_u) |
246 | if (!uidgid_get(&sslugid, ssluser, 1)) { | 245 | if (!uidgid_get(&sslugid, ssluser, 1)) { |
247 | if (errno) { | 246 | if (errno) { |
248 | bb_perror_msg_and_die("fatal: cannot get user/group: %s", ssluser); | 247 | bb_perror_msg_and_die("can't get user/group: %s", ssluser); |
249 | } | 248 | } |
250 | bb_error_msg_and_die("unknown user/group '%s'", ssluser); | 249 | bb_error_msg_and_die("unknown user/group %s", ssluser); |
251 | } | 250 | } |
252 | if (!cert) cert = "./cert.pem"; | 251 | if (!cert) cert = "./cert.pem"; |
253 | if (!key) key = cert; | 252 | if (!key) key = cert; |
diff --git a/networking/tftp.c b/networking/tftp.c index d09a6eba5..07d672dcb 100644 --- a/networking/tftp.c +++ b/networking/tftp.c | |||
@@ -225,7 +225,7 @@ static int tftp_protocol( | |||
225 | if (user_opt) { | 225 | if (user_opt) { |
226 | struct passwd *pw = getpwnam(user_opt); | 226 | struct passwd *pw = getpwnam(user_opt); |
227 | if (!pw) | 227 | if (!pw) |
228 | bb_error_msg_and_die("unknown user '%s'", user_opt); | 228 | bb_error_msg_and_die("unknown user %s", user_opt); |
229 | change_identity(pw); /* initgroups, setgid, setuid */ | 229 | change_identity(pw); /* initgroups, setgid, setuid */ |
230 | } | 230 | } |
231 | } | 231 | } |
diff --git a/procps/renice.c b/procps/renice.c index 4c309e9d1..ea5fc703e 100644 --- a/procps/renice.c +++ b/procps/renice.c | |||
@@ -84,7 +84,7 @@ int renice_main(int argc UNUSED_PARAM, char **argv) | |||
84 | struct passwd *p; | 84 | struct passwd *p; |
85 | p = getpwnam(arg); | 85 | p = getpwnam(arg); |
86 | if (!p) { | 86 | if (!p) { |
87 | bb_error_msg("unknown user: %s", arg); | 87 | bb_error_msg("unknown user %s", arg); |
88 | goto HAD_ERROR; | 88 | goto HAD_ERROR; |
89 | } | 89 | } |
90 | who = p->pw_uid; | 90 | who = p->pw_uid; |
diff --git a/runit/chpst.c b/runit/chpst.c index 899a4eef0..3c841ddbb 100644 --- a/runit/chpst.c +++ b/runit/chpst.c | |||
@@ -81,9 +81,7 @@ static void suidgid(char *user) | |||
81 | { | 81 | { |
82 | struct bb_uidgid_t ugid; | 82 | struct bb_uidgid_t ugid; |
83 | 83 | ||
84 | if (!get_uidgid(&ugid, user, 1)) { | 84 | xget_uidgid(&ugid, user); |
85 | bb_error_msg_and_die("unknown user/group: %s", user); | ||
86 | } | ||
87 | if (setgroups(1, &ugid.gid) == -1) | 85 | if (setgroups(1, &ugid.gid) == -1) |
88 | bb_perror_msg_and_die("setgroups"); | 86 | bb_perror_msg_and_die("setgroups"); |
89 | xsetgid(ugid.gid); | 87 | xsetgid(ugid.gid); |
@@ -94,9 +92,7 @@ static void euidgid(char *user) | |||
94 | { | 92 | { |
95 | struct bb_uidgid_t ugid; | 93 | struct bb_uidgid_t ugid; |
96 | 94 | ||
97 | if (!get_uidgid(&ugid, user, 1)) { | 95 | xget_uidgid(&ugid, user); |
98 | bb_error_msg_and_die("unknown user/group: %s", user); | ||
99 | } | ||
100 | xsetenv("GID", utoa(ugid.gid)); | 96 | xsetenv("GID", utoa(ugid.gid)); |
101 | xsetenv("UID", utoa(ugid.uid)); | 97 | xsetenv("UID", utoa(ugid.uid)); |
102 | } | 98 | } |