aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2006-09-23 16:34:39 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2006-09-23 16:34:39 +0000
commit01a74f96492e9e9995b7fcb54013d00a840a3d5f (patch)
tree6ae8edcc3735c70b79e0c0cc824894fbb9c797e9
parentc290563319b61c8230deca52ab625d8dc335e2d3 (diff)
downloadbusybox-w32-01a74f96492e9e9995b7fcb54013d00a840a3d5f.tar.gz
busybox-w32-01a74f96492e9e9995b7fcb54013d00a840a3d5f.tar.bz2
busybox-w32-01a74f96492e9e9995b7fcb54013d00a840a3d5f.zip
applets.c: fix indentation
-rw-r--r--applets/applets.c128
1 files changed, 64 insertions, 64 deletions
diff --git a/applets/applets.c b/applets/applets.c
index 39dcfb0f8..e992998d6 100644
--- a/applets/applets.c
+++ b/applets/applets.c
@@ -50,33 +50,33 @@ const size_t NUM_APPLETS = (sizeof (applets) / sizeof (struct BB_applet) - 1);
50/* applets [] is const, so we have to define this "override" structure */ 50/* applets [] is const, so we have to define this "override" structure */
51static struct BB_suid_config 51static struct BB_suid_config
52{ 52{
53 struct BB_applet *m_applet; 53 struct BB_applet *m_applet;
54 54
55 uid_t m_uid; 55 uid_t m_uid;
56 gid_t m_gid; 56 gid_t m_gid;
57 mode_t m_mode; 57 mode_t m_mode;
58 58
59 struct BB_suid_config *m_next; 59 struct BB_suid_config *m_next;
60} *suid_config; 60} *suid_config;
61 61
62static int suid_cfg_readable; 62static int suid_cfg_readable;
63 63
64/* check if u is member of group g */ 64/* check if u is member of group g */
65static int ingroup (uid_t u, gid_t g) 65static int ingroup(uid_t u, gid_t g)
66{ 66{
67 struct group *grp = getgrgid (g); 67 struct group *grp = getgrgid(g);
68 68
69 if (grp) { 69 if (grp) {
70 char **mem; 70 char **mem;
71 71
72 for (mem = grp->gr_mem; *mem; mem++) { 72 for (mem = grp->gr_mem; *mem; mem++) {
73 struct passwd *pwd = getpwnam (*mem); 73 struct passwd *pwd = getpwnam(*mem);
74 74
75 if (pwd && (pwd->pw_uid == u)) 75 if (pwd && (pwd->pw_uid == u))
76 return 1; 76 return 1;
77 }
77 } 78 }
78 } 79 return 0;
79 return 0;
80} 80}
81 81
82/* This should probably be a libbb routine. In that case, 82/* This should probably be a libbb routine. In that case,
@@ -320,58 +320,58 @@ static void parse_config_file(void)
320#ifdef CONFIG_FEATURE_SUID 320#ifdef CONFIG_FEATURE_SUID
321static void check_suid (struct BB_applet *applet) 321static void check_suid (struct BB_applet *applet)
322{ 322{
323 uid_t ruid = getuid (); /* real [ug]id */ 323 uid_t ruid = getuid (); /* real [ug]id */
324 uid_t rgid = getgid (); 324 uid_t rgid = getgid ();
325 325
326#ifdef CONFIG_FEATURE_SUID_CONFIG 326#ifdef CONFIG_FEATURE_SUID_CONFIG
327 if (suid_cfg_readable) { 327 if (suid_cfg_readable) {
328 struct BB_suid_config *sct; 328 struct BB_suid_config *sct;
329
330 for (sct = suid_config; sct; sct = sct->m_next) {
331 if (sct->m_applet == applet)
332 break;
333 }
334 if (sct) {
335 mode_t m = sct->m_mode;
336 329
337 if (sct->m_uid == ruid) /* same uid */ 330 for (sct = suid_config; sct; sct = sct->m_next) {
338 m >>= 6; 331 if (sct->m_applet == applet)
339 else if ((sct->m_gid == rgid) || ingroup (ruid, sct->m_gid)) /* same group / in group */ 332 break;
340 m >>= 3; 333 }
341 334 if (sct) {
342 if (!(m & S_IXOTH)) /* is x bit not set ? */ 335 mode_t m = sct->m_mode;
343 bb_error_msg_and_die ("You have no permission to run this applet!"); 336
344 337 if (sct->m_uid == ruid) /* same uid */
345 if ((sct->m_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) { /* *both* have to be set for sgid */ 338 m >>= 6;
346 xsetgid(sct->m_gid); 339 else if ((sct->m_gid == rgid) || ingroup (ruid, sct->m_gid)) /* same group / in group */
347 } else xsetgid(rgid); /* no sgid -> drop */ 340 m >>= 3;
348 341
349 if (sct->m_mode & S_ISUID) xsetuid(sct->m_uid); 342 if (!(m & S_IXOTH)) /* is x bit not set ? */
350 else xsetuid(ruid); /* no suid -> drop */ 343 bb_error_msg_and_die ("You have no permission to run this applet!");
344
345 if ((sct->m_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) { /* *both* have to be set for sgid */
346 xsetgid(sct->m_gid);
347 } else xsetgid(rgid); /* no sgid -> drop */
348
349 if (sct->m_mode & S_ISUID) xsetuid(sct->m_uid);
350 else xsetuid(ruid); /* no suid -> drop */
351 } else {
352 /* default: drop all privileges */
353 xsetgid(rgid);
354 xsetuid(ruid);
355 }
356 return;
351 } else { 357 } else {
352 /* default: drop all privileges */
353 xsetgid(rgid);
354 xsetuid(ruid);
355 }
356 return;
357 } else {
358#ifndef CONFIG_FEATURE_SUID_CONFIG_QUIET 358#ifndef CONFIG_FEATURE_SUID_CONFIG_QUIET
359 static int onetime = 0; 359 static int onetime = 0;
360 360
361 if (!onetime) { 361 if (!onetime) {
362 onetime = 1; 362 onetime = 1;
363 fprintf (stderr, "Using fallback suid method\n"); 363 fprintf (stderr, "Using fallback suid method\n");
364 } 364 }
365#endif 365#endif
366 } 366 }
367#endif 367#endif
368 368
369 if (applet->need_suid == _BB_SUID_ALWAYS) { 369 if (applet->need_suid == _BB_SUID_ALWAYS) {
370 if (geteuid()) bb_error_msg_and_die("Applet requires root privileges!"); 370 if (geteuid()) bb_error_msg_and_die("Applet requires root privileges!");
371 } else if (applet->need_suid == _BB_SUID_NEVER) { 371 } else if (applet->need_suid == _BB_SUID_NEVER) {
372 xsetgid(rgid); /* drop all privileges */ 372 xsetgid(rgid); /* drop all privileges */
373 xsetuid(ruid); 373 xsetuid(ruid);
374 } 374 }
375} 375}
376#else 376#else
377#define check_suid(x) 377#define check_suid(x)
@@ -426,7 +426,7 @@ static const char *unpack_usage_messages(void)
426#define unpack_usage_messages() usage_messages 426#define unpack_usage_messages() usage_messages
427#endif /* ENABLE_FEATURE_COMPRESS_USAGE */ 427#endif /* ENABLE_FEATURE_COMPRESS_USAGE */
428 428
429void bb_show_usage (void) 429void bb_show_usage(void)
430{ 430{
431 if (ENABLE_SHOW_USAGE) { 431 if (ENABLE_SHOW_USAGE) {
432 const char *format_string; 432 const char *format_string;
@@ -443,22 +443,22 @@ void bb_show_usage (void)
443 applet_using->name, usage_string); 443 applet_using->name, usage_string);
444 } 444 }
445 445
446 exit (bb_default_error_retval); 446 exit (bb_default_error_retval);
447} 447}
448 448
449static int applet_name_compare(const void *name, const void *vapplet) 449static int applet_name_compare(const void *name, const void *vapplet)
450{ 450{
451 const struct BB_applet *applet = vapplet; 451 const struct BB_applet *applet = vapplet;
452 452
453 return strcmp(name, applet->name); 453 return strcmp(name, applet->name);
454} 454}
455 455
456extern const size_t NUM_APPLETS; 456extern const size_t NUM_APPLETS;
457 457
458struct BB_applet *find_applet_by_name(const char *name) 458struct BB_applet *find_applet_by_name(const char *name)
459{ 459{
460 return bsearch(name, applets, NUM_APPLETS, sizeof(struct BB_applet), 460 return bsearch(name, applets, NUM_APPLETS, sizeof(struct BB_applet),
461 applet_name_compare); 461 applet_name_compare);
462} 462}
463 463
464void run_applet_by_name(const char *name, int argc, char **argv) 464void run_applet_by_name(const char *name, int argc, char **argv)