Changeset 2725 in MondoRescue for branches/2.2.9/mindi-busybox/coreutils/chown.c
- Timestamp:
- Feb 25, 2011, 9:26:54 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2.9/mindi-busybox/coreutils/chown.c
r1765 r2725 5 5 * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org> 6 6 * 7 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.7 * Licensed under GPLv2 or later, see file LICENSE in this source tree. 8 8 */ 9 9 10 10 /* BB_AUDIT SUSv3 defects - none? */ 11 /* BB_AUDIT GNU defects - unsupported long options. */12 11 /* http://www.opengroup.org/onlinepubs/007904975/utilities/chown.html */ 13 12 … … 17 16 18 17 19 #define OPT_STR ("Rh" USE_DESKTOP("vcfLHP"))18 #define OPT_STR ("Rh" IF_DESKTOP("vcfLHP")) 20 19 #define BIT_RECURSE 1 21 #define OPT_RECURSE (opt ion_mask32& 1)22 #define OPT_NODEREF (opt ion_mask32& 2)23 #define OPT_VERBOSE ( USE_DESKTOP(option_mask32 & 0x04) SKIP_DESKTOP(0))24 #define OPT_CHANGED ( USE_DESKTOP(option_mask32 & 0x08) SKIP_DESKTOP(0))25 #define OPT_QUIET ( USE_DESKTOP(option_mask32 & 0x10) SKIP_DESKTOP(0))20 #define OPT_RECURSE (opt & 1) 21 #define OPT_NODEREF (opt & 2) 22 #define OPT_VERBOSE (IF_DESKTOP(opt & 0x04) IF_NOT_DESKTOP(0)) 23 #define OPT_CHANGED (IF_DESKTOP(opt & 0x08) IF_NOT_DESKTOP(0)) 24 #define OPT_QUIET (IF_DESKTOP(opt & 0x10) IF_NOT_DESKTOP(0)) 26 25 /* POSIX options 27 26 * -L traverse every symbolic link to a directory encountered … … 33 32 /* -L */ 34 33 #define BIT_TRAVERSE 0x20 35 #define OPT_TRAVERSE ( USE_DESKTOP(option_mask32 & BIT_TRAVERSE) SKIP_DESKTOP(0))34 #define OPT_TRAVERSE (IF_DESKTOP(opt & BIT_TRAVERSE) IF_NOT_DESKTOP(0)) 36 35 /* -H or -L */ 37 36 #define BIT_TRAVERSE_TOP (0x20|0x40) 38 #define OPT_TRAVERSE_TOP (USE_DESKTOP(option_mask32 & BIT_TRAVERSE_TOP) SKIP_DESKTOP(0)) 37 #define OPT_TRAVERSE_TOP (IF_DESKTOP(opt & BIT_TRAVERSE_TOP) IF_NOT_DESKTOP(0)) 38 39 #if ENABLE_FEATURE_CHOWN_LONG_OPTIONS 40 static const char chown_longopts[] ALIGN1 = 41 "recursive\0" No_argument "R" 42 "dereference\0" No_argument "\xff" 43 "no-dereference\0" No_argument "h" 44 # if ENABLE_DESKTOP 45 "changes\0" No_argument "c" 46 "silent\0" No_argument "f" 47 "quiet\0" No_argument "f" 48 "verbose\0" No_argument "v" 49 # endif 50 ; 51 #endif 39 52 40 53 typedef int (*chown_fptr)(const char *, uid_t, gid_t); 41 54 42 static struct bb_uidgid_t ugid = { -1, -1 }; 55 struct param_t { 56 struct bb_uidgid_t ugid; 57 chown_fptr chown_func; 58 }; 43 59 44 static int fileAction(const char *fileName, struct stat *statbuf,45 void * cf, int depth)60 static int FAST_FUNC fileAction(const char *fileName, struct stat *statbuf, 61 void *vparam, int depth UNUSED_PARAM) 46 62 { 47 uid_t u = (ugid.uid == (uid_t)-1) ? statbuf->st_uid : ugid.uid; 48 gid_t g = (ugid.gid == (gid_t)-1) ? statbuf->st_gid : ugid.gid; 63 #define param (*(struct param_t*)vparam) 64 #define opt option_mask32 65 uid_t u = (param.ugid.uid == (uid_t)-1L) ? statbuf->st_uid : param.ugid.uid; 66 gid_t g = (param.ugid.gid == (gid_t)-1L) ? statbuf->st_gid : param.ugid.gid; 49 67 50 if ( !((chown_fptr)cf)(fileName, u, g)) {68 if (param.chown_func(fileName, u, g) == 0) { 51 69 if (OPT_VERBOSE 52 70 || (OPT_CHANGED && (statbuf->st_uid != u || statbuf->st_gid != g)) … … 58 76 } 59 77 if (!OPT_QUIET) 60 bb_ perror_msg("%s", fileName); /* A filename can have % in it... */78 bb_simple_perror_msg(fileName); 61 79 return FALSE; 80 #undef opt 81 #undef param 62 82 } 63 83 64 int chown_main(int argc, char **argv); 65 int chown_main(int argc, char **argv) 84 int chown_main(int argc UNUSED_PARAM, char **argv) 66 85 { 67 86 int retval = EXIT_SUCCESS; 68 int flags;69 chown_fptr chown_func;87 int opt, flags; 88 struct param_t param; 70 89 90 /* Just -1 might not work: uid_t may be unsigned long */ 91 param.ugid.uid = -1L; 92 param.ugid.gid = -1L; 93 94 #if ENABLE_FEATURE_CHOWN_LONG_OPTIONS 95 applet_long_options = chown_longopts; 96 #endif 71 97 opt_complementary = "-2"; 72 getopt32(argv, OPT_STR);98 opt = getopt32(argv, OPT_STR); 73 99 argv += optind; 74 100 75 101 /* This matches coreutils behavior (almost - see below) */ 76 chown_func = chown;102 param.chown_func = chown; 77 103 if (OPT_NODEREF 78 104 /* || (OPT_RECURSE && !OPT_TRAVERSE_TOP): */ 79 USE_DESKTOP( || (option_mask32& (BIT_RECURSE|BIT_TRAVERSE_TOP)) == BIT_RECURSE)105 IF_DESKTOP( || (opt & (BIT_RECURSE|BIT_TRAVERSE_TOP)) == BIT_RECURSE) 80 106 ) { 81 chown_func = lchown;107 param.chown_func = lchown; 82 108 } 83 109 … … 90 116 flags |= ACTION_FOLLOWLINKS; /* follow links if -L */ 91 117 92 parse_chown_usergroup_or_die(& ugid, argv[0]);118 parse_chown_usergroup_or_die(¶m.ugid, argv[0]); 93 119 94 120 /* Ok, ready to do the deed now */ 95 argv++; 96 do { 121 while (*++argv) { 97 122 if (!recursive_action(*argv, 98 123 flags, /* flags */ 99 124 fileAction, /* file action */ 100 125 fileAction, /* dir action */ 101 chown_func,/* user data */126 ¶m, /* user data */ 102 127 0) /* depth */ 103 128 ) { 104 129 retval = EXIT_FAILURE; 105 130 } 106 } while (*++argv);131 } 107 132 108 133 return retval;
Note:
See TracChangeset
for help on using the changeset viewer.