Changeset 3232 in MondoRescue for branches/3.2/mindi-busybox/coreutils/id.c
- Timestamp:
- Jan 1, 2014, 12:47:38 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3.2/mindi-busybox/coreutils/id.c
r2725 r3232 15 15 * Added -G option Tito Ragusa (C) 2008 for SUSv3. 16 16 */ 17 18 //config:config ID 19 //config: bool "id" 20 //config: default y 21 //config: help 22 //config: id displays the current user and group ID names. 23 24 //config:config GROUPS 25 //config: bool "groups" 26 //config: default y 27 //config: help 28 //config: Print the group names associated with current user id. 29 30 //kbuild:lib-$(CONFIG_GROUPS) += id.o 31 //kbuild:lib-$(CONFIG_ID) += id.o 32 33 //applet:IF_GROUPS(APPLET_NOEXEC(groups, id, BB_DIR_USR_BIN, BB_SUID_DROP, groups)) 34 //applet:IF_ID( APPLET_NOEXEC(id, id, BB_DIR_USR_BIN, BB_SUID_DROP, id )) 35 36 //usage:#define id_trivial_usage 37 //usage: "[OPTIONS] [USER]" 38 //usage:#define id_full_usage "\n\n" 39 //usage: "Print information about USER or the current user\n" 40 //usage: IF_SELINUX( 41 //usage: "\n -Z Security context" 42 //usage: ) 43 //usage: "\n -u User ID" 44 //usage: "\n -g Group ID" 45 //usage: "\n -G Supplementary group IDs" 46 //usage: "\n -n Print names instead of numbers" 47 //usage: "\n -r Print real ID instead of effective ID" 48 //usage: 49 //usage:#define id_example_usage 50 //usage: "$ id\n" 51 //usage: "uid=1000(andersen) gid=1000(andersen)\n" 52 53 //usage:#define groups_trivial_usage 54 //usage: "[USER]" 55 //usage:#define groups_full_usage "\n\n" 56 //usage: "Print the group memberships of USER or for the current process" 57 //usage: 58 //usage:#define groups_example_usage 59 //usage: "$ groups\n" 60 //usage: "andersen lp dialout cdrom floppy\n" 17 61 18 62 #include "libbb.h" … … 74 118 /* On error set *n < 0 and return >= 0 75 119 * If *n is too small, update it and return < 0 76 * 120 * (ok to trash groups[] in both cases) 77 121 * Otherwise fill in groups[] and return >= 0 78 122 */ … … 88 132 /* I guess *n < 0 might indicate error. Anyway, 89 133 * malloc'ing -1 bytes won't be good, so: */ 90 //if (*n < 0) 91 // return 0; 92 //return m; 93 //commented out here, happens below anyway 94 } else { 95 /* On error -1 is returned, which ends up in *n */ 96 int nn = getgroups(*n, groups); 97 /* 0: nn <= *n, groups[] was big enough; -1 otherwise */ 98 m = - (nn > *n); 99 *n = nn; 100 } 101 if (*n < 0) 102 return 0; /* error, don't return < 0! */ 103 return m; 134 if (*n < 0) 135 return 0; 136 return m; 137 } 138 139 *n = getgroups(*n, groups); 140 if (*n >= 0) 141 return *n; 142 /* Error */ 143 if (errno == EINVAL) /* *n is too small? */ 144 *n = getgroups(0, groups); /* get needed *n */ 145 /* if *n >= 0, return -1 (got new *n), else return 0 (error): */ 146 return -(*n >= 0); 104 147 } 105 148 … … 119 162 security_context_t scontext = NULL; 120 163 #endif 121 /* Don't allow -n -r -nr -ug -rug -nug -rnug -uZ -gZ -GZ*/ 122 /* Don't allow more than one username */ 123 opt_complementary = "?1:u--g:g--u:G--u:u--G:g--G:G--g:r?ugG:n?ugG" 124 IF_SELINUX(":u--Z:Z--u:g--Z:Z--g:G--Z:Z--G"); 125 opt = getopt32(argv, "rnugG" IF_SELINUX("Z")); 164 165 if (ENABLE_GROUPS && (!ENABLE_ID || applet_name[0] == 'g')) { 166 /* TODO: coreutils groups prepend "USER : " prefix, 167 * and accept many usernames. Example: 168 * # groups root root 169 * root : root 170 * root : root 171 */ 172 opt = option_mask32 = getopt32(argv, "") | JUST_ALL_GROUPS | NAME_NOT_NUMBER; 173 } else { 174 /* Don't allow -n -r -nr -ug -rug -nug -rnug -uZ -gZ -GZ*/ 175 /* Don't allow more than one username */ 176 opt_complementary = "?1:u--g:g--u:G--u:u--G:g--G:G--g:r?ugG:n?ugG" 177 IF_SELINUX(":u--Z:Z--u:g--Z:Z--g:G--Z:Z--G"); 178 opt = getopt32(argv, "rnugG" IF_SELINUX("Z")); 179 } 126 180 127 181 username = argv[optind]; … … 160 214 * to not run get_groups() twice. That might be slow 161 215 * ("user database in remote SQL server" case) */ 162 groups = xmalloc(64 * sizeof(g id_t));216 groups = xmalloc(64 * sizeof(groups[0])); 163 217 n = 64; 164 218 if (get_groups(username, rgid, groups, &n) < 0) { 165 219 /* Need bigger buffer after all */ 166 groups = xrealloc(groups, n * sizeof(g id_t));220 groups = xrealloc(groups, n * sizeof(groups[0])); 167 221 get_groups(username, rgid, groups, &n); 168 222 } … … 177 231 } 178 232 } else if (n < 0) { /* error in get_groups() */ 179 if ( !ENABLE_DESKTOP)233 if (ENABLE_DESKTOP) 180 234 bb_error_msg_and_die("can't get groups"); 181 else 182 return EXIT_FAILURE; 235 return EXIT_FAILURE; 183 236 } 184 237 if (ENABLE_FEATURE_CLEAN_UP)
Note:
See TracChangeset
for help on using the changeset viewer.