aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2009-07-19 23:07:13 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2009-07-19 23:07:13 +0200
commitd6513cff17245c3922452ee8aa99151c8533bace (patch)
treec5b18f98bc54459b9b4778562c9cdf926d347c31
parent3ed181b7ac8e696cd28caf003ae9dcbeebc03757 (diff)
downloadbusybox-w32-d6513cff17245c3922452ee8aa99151c8533bace.tar.gz
busybox-w32-d6513cff17245c3922452ee8aa99151c8533bace.tar.bz2
busybox-w32-d6513cff17245c3922452ee8aa99151c8533bace.zip
tcpsvd,udpsvd: fix uid/gid printing when run with -u
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--networking/tcpudp.c46
1 files changed, 23 insertions, 23 deletions
diff --git a/networking/tcpudp.c b/networking/tcpudp.c
index a5be192fb..98a2aa8c0 100644
--- a/networking/tcpudp.c
+++ b/networking/tcpudp.c
@@ -184,6 +184,7 @@ int tcpudpsvd_main(int argc UNUSED_PARAM, char **argv)
184 int sock; 184 int sock;
185 int conn; 185 int conn;
186 unsigned backlog = 20; 186 unsigned backlog = 20;
187 unsigned opts;
187 188
188 INIT_G(); 189 INIT_G();
189 190
@@ -192,18 +193,18 @@ int tcpudpsvd_main(int argc UNUSED_PARAM, char **argv)
192 /* 3+ args, -i at most once, -p implies -h, -v is counter, -b N, -c N */ 193 /* 3+ args, -i at most once, -p implies -h, -v is counter, -b N, -c N */
193 opt_complementary = "-3:i--i:ph:vv:b+:c+"; 194 opt_complementary = "-3:i--i:ph:vv:b+:c+";
194#ifdef SSLSVD 195#ifdef SSLSVD
195 getopt32(argv, "+c:C:i:x:u:l:Eb:hpt:vU:/:Z:K:", 196 opts = getopt32(argv, "+c:C:i:x:u:l:Eb:hpt:vU:/:Z:K:",
196 &cmax, &str_C, &instructs, &instructs, &user, &preset_local_hostname, 197 &cmax, &str_C, &instructs, &instructs, &user, &preset_local_hostname,
197 &backlog, &str_t, &ssluser, &root, &cert, &key, &verbose 198 &backlog, &str_t, &ssluser, &root, &cert, &key, &verbose
198 ); 199 );
199#else 200#else
200 /* "+": stop on first non-option */ 201 /* "+": stop on first non-option */
201 getopt32(argv, "+c:C:i:x:u:l:Eb:hpt:v", 202 opts = getopt32(argv, "+c:C:i:x:u:l:Eb:hpt:v",
202 &cmax, &str_C, &instructs, &instructs, &user, &preset_local_hostname, 203 &cmax, &str_C, &instructs, &instructs, &user, &preset_local_hostname,
203 &backlog, &str_t, &verbose 204 &backlog, &str_t, &verbose
204 ); 205 );
205#endif 206#endif
206 if (option_mask32 & OPT_C) { /* -C n[:message] */ 207 if (opts & OPT_C) { /* -C n[:message] */
207 max_per_host = bb_strtou(str_C, &str_C, 10); 208 max_per_host = bb_strtou(str_C, &str_C, 10);
208 if (str_C[0]) { 209 if (str_C[0]) {
209 if (str_C[0] != ':') 210 if (str_C[0] != ':')
@@ -214,14 +215,14 @@ int tcpudpsvd_main(int argc UNUSED_PARAM, char **argv)
214 } 215 }
215 if (max_per_host > cmax) 216 if (max_per_host > cmax)
216 max_per_host = cmax; 217 max_per_host = cmax;
217 if (option_mask32 & OPT_u) { 218 if (opts & OPT_u) {
218 xget_uidgid(&ugid, user); 219 xget_uidgid(&ugid, user);
219 } 220 }
220#ifdef SSLSVD 221#ifdef SSLSVD
221 if (option_mask32 & OPT_U) ssluser = optarg; 222 if (opts & OPT_U) ssluser = optarg;
222 if (option_mask32 & OPT_slash) root = optarg; 223 if (opts & OPT_slash) root = optarg;
223 if (option_mask32 & OPT_Z) cert = optarg; 224 if (opts & OPT_Z) cert = optarg;
224 if (option_mask32 & OPT_K) key = optarg; 225 if (opts & OPT_K) key = optarg;
225#endif 226#endif
226 argv += optind; 227 argv += optind;
227 if (!argv[0][0] || LONE_CHAR(argv[0], '0')) 228 if (!argv[0][0] || LONE_CHAR(argv[0], '0'))
@@ -236,11 +237,11 @@ int tcpudpsvd_main(int argc UNUSED_PARAM, char **argv)
236#ifdef SSLSVD 237#ifdef SSLSVD
237 sslser = user; 238 sslser = user;
238 client = 0; 239 client = 0;
239 if ((getuid() == 0) && !(option_mask32 & OPT_u)) { 240 if ((getuid() == 0) && !(opts & OPT_u)) {
240 xfunc_exitcode = 100; 241 xfunc_exitcode = 100;
241 bb_error_msg_and_die("-U ssluser must be set when running as root"); 242 bb_error_msg_and_die("-U ssluser must be set when running as root");
242 } 243 }
243 if (option_mask32 & OPT_u) 244 if (opts & OPT_u)
244 if (!uidgid_get(&sslugid, ssluser, 1)) { 245 if (!uidgid_get(&sslugid, ssluser, 1)) {
245 if (errno) { 246 if (errno) {
246 bb_perror_msg_and_die("can't get user/group: %s", ssluser); 247 bb_perror_msg_and_die("can't get user/group: %s", ssluser);
@@ -285,7 +286,7 @@ int tcpudpsvd_main(int argc UNUSED_PARAM, char **argv)
285 /* ndelay_off(sock); - it is the default I think? */ 286 /* ndelay_off(sock); - it is the default I think? */
286 287
287#ifndef SSLSVD 288#ifndef SSLSVD
288 if (option_mask32 & OPT_u) { 289 if (opts & OPT_u) {
289 /* drop permissions */ 290 /* drop permissions */
290 xsetgid(ugid.gid); 291 xsetgid(ugid.gid);
291 xsetuid(ugid.uid); 292 xsetuid(ugid.uid);
@@ -294,13 +295,12 @@ int tcpudpsvd_main(int argc UNUSED_PARAM, char **argv)
294 295
295 if (verbose) { 296 if (verbose) {
296 char *addr = xmalloc_sockaddr2dotted(&lsa->u.sa); 297 char *addr = xmalloc_sockaddr2dotted(&lsa->u.sa);
297 bb_error_msg("listening on %s, starting", addr); 298 if (opts & OPT_u)
298 free(addr); 299 bb_error_msg("listening on %s, starting, uid %u, gid %u", addr,
299#ifndef SSLSVD
300 if (option_mask32 & OPT_u)
301 printf(", uid %u, gid %u",
302 (unsigned)ugid.uid, (unsigned)ugid.gid); 300 (unsigned)ugid.uid, (unsigned)ugid.gid);
303#endif 301 else
302 bb_error_msg("listening on %s, starting", addr);
303 free(addr);
304 } 304 }
305 305
306 /* Main accept() loop */ 306 /* Main accept() loop */
@@ -419,10 +419,10 @@ int tcpudpsvd_main(int argc UNUSED_PARAM, char **argv)
419 char *free_me1 = NULL; 419 char *free_me1 = NULL;
420 char *free_me2 = NULL; 420 char *free_me2 = NULL;
421 421
422 if (verbose || !(option_mask32 & OPT_E)) { 422 if (verbose || !(opts & OPT_E)) {
423 if (!max_per_host) /* remote_addr is not yet known */ 423 if (!max_per_host) /* remote_addr is not yet known */
424 free_me0 = remote_addr = xmalloc_sockaddr2dotted(&remote.u.sa); 424 free_me0 = remote_addr = xmalloc_sockaddr2dotted(&remote.u.sa);
425 if (option_mask32 & OPT_h) { 425 if (opts & OPT_h) {
426 free_me1 = remote_hostname = xmalloc_sockaddr2host_noport(&remote.u.sa); 426 free_me1 = remote_hostname = xmalloc_sockaddr2host_noport(&remote.u.sa);
427 if (!remote_hostname) { 427 if (!remote_hostname) {
428 bb_error_msg("cannot look up hostname for %s", remote_addr); 428 bb_error_msg("cannot look up hostname for %s", remote_addr);
@@ -436,7 +436,7 @@ int tcpudpsvd_main(int argc UNUSED_PARAM, char **argv)
436 getsockname(0, &local.u.sa, &local.len); 436 getsockname(0, &local.u.sa, &local.len);
437 /* else: for UDP it is done earlier by parent */ 437 /* else: for UDP it is done earlier by parent */
438 local_addr = xmalloc_sockaddr2dotted(&local.u.sa); 438 local_addr = xmalloc_sockaddr2dotted(&local.u.sa);
439 if (option_mask32 & OPT_h) { 439 if (opts & OPT_h) {
440 local_hostname = preset_local_hostname; 440 local_hostname = preset_local_hostname;
441 if (!local_hostname) { 441 if (!local_hostname) {
442 free_me2 = local_hostname = xmalloc_sockaddr2host_noport(&local.u.sa); 442 free_me2 = local_hostname = xmalloc_sockaddr2host_noport(&local.u.sa);
@@ -453,7 +453,7 @@ int tcpudpsvd_main(int argc UNUSED_PARAM, char **argv)
453 remote_addr, 453 remote_addr,
454 cur_per_host, max_per_host); 454 cur_per_host, max_per_host);
455 } 455 }
456 bb_error_msg((option_mask32 & OPT_h) 456 bb_error_msg((opts & OPT_h)
457 ? "start %u %s-%s (%s-%s)" 457 ? "start %u %s-%s (%s-%s)"
458 : "start %u %s-%s", 458 : "start %u %s-%s",
459 pid, 459 pid,
@@ -461,7 +461,7 @@ int tcpudpsvd_main(int argc UNUSED_PARAM, char **argv)
461 local_hostname, remote_hostname); 461 local_hostname, remote_hostname);
462 } 462 }
463 463
464 if (!(option_mask32 & OPT_E)) { 464 if (!(opts & OPT_E)) {
465 /* setup ucspi env */ 465 /* setup ucspi env */
466 const char *proto = tcp ? "TCP" : "UDP"; 466 const char *proto = tcp ? "TCP" : "UDP";
467 467
@@ -477,7 +477,7 @@ int tcpudpsvd_main(int argc UNUSED_PARAM, char **argv)
477 xsetenv_plain("PROTO", proto); 477 xsetenv_plain("PROTO", proto);
478 xsetenv_proto(proto, "LOCALADDR", local_addr); 478 xsetenv_proto(proto, "LOCALADDR", local_addr);
479 xsetenv_proto(proto, "REMOTEADDR", remote_addr); 479 xsetenv_proto(proto, "REMOTEADDR", remote_addr);
480 if (option_mask32 & OPT_h) { 480 if (opts & OPT_h) {
481 xsetenv_proto(proto, "LOCALHOST", local_hostname); 481 xsetenv_proto(proto, "LOCALHOST", local_hostname);
482 xsetenv_proto(proto, "REMOTEHOST", remote_hostname); 482 xsetenv_proto(proto, "REMOTEHOST", remote_hostname);
483 } 483 }