Mercurial > hg > octave-nkf > gnulib-hg
annotate lib/userspec.c @ 2810:aff553209434
(same_name): Invoke xalloc_die instead of printing our own message.
(parse_user_spec):
Don't translate a message until just before returning,
to avoid unnecessary translation.
author | Jim Meyering <jim@meyering.net> |
---|---|
date | Mon, 07 Aug 2000 16:56:29 +0000 |
parents | ce1bca7b77d5 |
children | 658f210cdd89 |
rev | line source |
---|---|
5 | 1 /* userspec.c -- Parse a user and group string. |
2271 | 2 Copyright (C) 1989-1992, 1997, 1998, 2000 Free Software Foundation, Inc. |
5 | 3 |
4 This program is free software; you can redistribute it and/or modify | |
5 it under the terms of the GNU General Public License as published by | |
6 the Free Software Foundation; either version 2, or (at your option) | |
7 any later version. | |
8 | |
9 This program is distributed in the hope that it will be useful, | |
10 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 GNU General Public License for more details. | |
13 | |
14 You should have received a copy of the GNU General Public License | |
650
b4ef1c1a0171
update FSF address in copyright
Jim Meyering <jim@meyering.net>
parents:
499
diff
changeset
|
15 along with this program; if not, write to the Free Software Foundation, |
b4ef1c1a0171
update FSF address in copyright
Jim Meyering <jim@meyering.net>
parents:
499
diff
changeset
|
16 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
5 | 17 |
18 /* Written by David MacKenzie <djm@gnu.ai.mit.edu>. */ | |
966 | 19 |
20 #if HAVE_CONFIG_H | |
21 # include <config.h> | |
105 | 22 #endif |
23 | |
231 | 24 #ifdef __GNUC__ |
432
a56993d69333
(parse_user_spec): Use strchr, not index.
Jim Meyering <jim@meyering.net>
parents:
316
diff
changeset
|
25 # define alloca __builtin_alloca |
231 | 26 #else |
1278
9ad625a30b7d
Use #if, not #ifdef with HAVE_ macros
Jim Meyering <jim@meyering.net>
parents:
1260
diff
changeset
|
27 # if HAVE_ALLOCA_H |
432
a56993d69333
(parse_user_spec): Use strchr, not index.
Jim Meyering <jim@meyering.net>
parents:
316
diff
changeset
|
28 # include <alloca.h> |
a56993d69333
(parse_user_spec): Use strchr, not index.
Jim Meyering <jim@meyering.net>
parents:
316
diff
changeset
|
29 # else |
a56993d69333
(parse_user_spec): Use strchr, not index.
Jim Meyering <jim@meyering.net>
parents:
316
diff
changeset
|
30 # ifdef _AIX |
966 | 31 # pragma alloca |
432
a56993d69333
(parse_user_spec): Use strchr, not index.
Jim Meyering <jim@meyering.net>
parents:
316
diff
changeset
|
32 # else |
231 | 33 char *alloca (); |
432
a56993d69333
(parse_user_spec): Use strchr, not index.
Jim Meyering <jim@meyering.net>
parents:
316
diff
changeset
|
34 # endif |
a56993d69333
(parse_user_spec): Use strchr, not index.
Jim Meyering <jim@meyering.net>
parents:
316
diff
changeset
|
35 # endif |
231 | 36 #endif |
230 | 37 |
5 | 38 #include <stdio.h> |
39 #include <sys/types.h> | |
40 #include <pwd.h> | |
41 #include <grp.h> | |
42 | |
966 | 43 #if HAVE_STRING_H |
432
a56993d69333
(parse_user_spec): Use strchr, not index.
Jim Meyering <jim@meyering.net>
parents:
316
diff
changeset
|
44 # include <string.h> |
5 | 45 #else |
432
a56993d69333
(parse_user_spec): Use strchr, not index.
Jim Meyering <jim@meyering.net>
parents:
316
diff
changeset
|
46 # include <strings.h> |
a56993d69333
(parse_user_spec): Use strchr, not index.
Jim Meyering <jim@meyering.net>
parents:
316
diff
changeset
|
47 # ifndef strchr |
a56993d69333
(parse_user_spec): Use strchr, not index.
Jim Meyering <jim@meyering.net>
parents:
316
diff
changeset
|
48 # define strchr index |
a56993d69333
(parse_user_spec): Use strchr, not index.
Jim Meyering <jim@meyering.net>
parents:
316
diff
changeset
|
49 # endif |
5 | 50 #endif |
51 | |
966 | 52 #if STDC_HEADERS |
432
a56993d69333
(parse_user_spec): Use strchr, not index.
Jim Meyering <jim@meyering.net>
parents:
316
diff
changeset
|
53 # include <stdlib.h> |
5 | 54 #endif |
55 | |
966 | 56 #if HAVE_UNISTD_H |
432
a56993d69333
(parse_user_spec): Use strchr, not index.
Jim Meyering <jim@meyering.net>
parents:
316
diff
changeset
|
57 # include <unistd.h> |
5 | 58 #endif |
59 | |
2810
aff553209434
(same_name): Invoke xalloc_die instead of printing our own message.
Jim Meyering <jim@meyering.net>
parents:
2284
diff
changeset
|
60 #include "xalloc.h" |
aff553209434
(same_name): Invoke xalloc_die instead of printing our own message.
Jim Meyering <jim@meyering.net>
parents:
2284
diff
changeset
|
61 |
2273 | 62 #if ENABLE_NLS |
63 # include <libintl.h> | |
64 # define _(Text) gettext (Text) | |
65 #else | |
66 # define _(Text) Text | |
67 #endif | |
68 #define N_(Text) Text | |
69 | |
5 | 70 #ifndef _POSIX_VERSION |
71 struct passwd *getpwnam (); | |
72 struct group *getgrnam (); | |
73 struct group *getgrgid (); | |
74 #endif | |
75 | |
499
62aa0b766a11
[HAVE_ENDGRENT]: Define away endgrent.
Jim Meyering <jim@meyering.net>
parents:
475
diff
changeset
|
76 #ifndef HAVE_ENDGRENT |
62aa0b766a11
[HAVE_ENDGRENT]: Define away endgrent.
Jim Meyering <jim@meyering.net>
parents:
475
diff
changeset
|
77 # define endgrent() ((void) 0) |
62aa0b766a11
[HAVE_ENDGRENT]: Define away endgrent.
Jim Meyering <jim@meyering.net>
parents:
475
diff
changeset
|
78 #endif |
62aa0b766a11
[HAVE_ENDGRENT]: Define away endgrent.
Jim Meyering <jim@meyering.net>
parents:
475
diff
changeset
|
79 |
62aa0b766a11
[HAVE_ENDGRENT]: Define away endgrent.
Jim Meyering <jim@meyering.net>
parents:
475
diff
changeset
|
80 #ifndef HAVE_ENDPWENT |
62aa0b766a11
[HAVE_ENDGRENT]: Define away endgrent.
Jim Meyering <jim@meyering.net>
parents:
475
diff
changeset
|
81 # define endpwent() ((void) 0) |
5 | 82 #endif |
83 | |
230 | 84 /* Perform the equivalent of the statement `dest = strdup (src);', |
85 but obtaining storage via alloca instead of from the heap. */ | |
86 | |
87 #define V_STRDUP(dest, src) \ | |
88 do \ | |
89 { \ | |
90 int _len = strlen ((src)); \ | |
91 (dest) = (char *) alloca (_len + 1); \ | |
92 strcpy (dest, src); \ | |
93 } \ | |
94 while (0) | |
95 | |
2271 | 96 /* ISDIGIT differs from isdigit, as follows: |
97 - Its arg may be any int or unsigned int; it need not be an unsigned char. | |
98 - It's guaranteed to evaluate its argument exactly once. | |
99 - It's typically faster. | |
100 Posix 1003.2-1992 section 2.5.2.1 page 50 lines 1556-1558 says that | |
101 only '0' through '9' are digits. Prefer ISDIGIT to isdigit unless | |
102 it's important to use the locale's definition of `digit' even when the | |
103 host does not conform to Posix. */ | |
104 #define ISDIGIT(c) ((unsigned) (c) - '0' <= 9) | |
5 | 105 |
1347
e7dc6e5a3be5
Don't declare strdup if it's defined as a macro.
Jim Meyering <jim@meyering.net>
parents:
1278
diff
changeset
|
106 #ifndef strdup |
5 | 107 char *strdup (); |
1347
e7dc6e5a3be5
Don't declare strdup if it's defined as a macro.
Jim Meyering <jim@meyering.net>
parents:
1278
diff
changeset
|
108 #endif |
194 | 109 |
110 /* Return nonzero if STR represents an unsigned decimal integer, | |
111 otherwise return 0. */ | |
112 | |
113 static int | |
1557 | 114 is_number (const char *str) |
194 | 115 { |
116 for (; *str; str++) | |
2271 | 117 if (!ISDIGIT (*str)) |
194 | 118 return 0; |
119 return 1; | |
120 } | |
5 | 121 |
122 /* Extract from NAME, which has the form "[user][:.][group]", | |
123 a USERNAME, UID U, GROUPNAME, and GID G. | |
124 Either user or group, or both, must be present. | |
2284
ce1bca7b77d5
(parse_user_spec): If there is no `:' but there is a `.',
Jim Meyering <jim@meyering.net>
parents:
2273
diff
changeset
|
125 If the group is omitted but the ":" separator is given, |
5 | 126 use the given user's login group. |
2284
ce1bca7b77d5
(parse_user_spec): If there is no `:' but there is a `.',
Jim Meyering <jim@meyering.net>
parents:
2273
diff
changeset
|
127 If SPEC_ARG contains a `:', then use that as the separator, ignoring |
ce1bca7b77d5
(parse_user_spec): If there is no `:' but there is a `.',
Jim Meyering <jim@meyering.net>
parents:
2273
diff
changeset
|
128 any `.'s. If there is no `:', but there is a `.', then first look |
ce1bca7b77d5
(parse_user_spec): If there is no `:' but there is a `.',
Jim Meyering <jim@meyering.net>
parents:
2273
diff
changeset
|
129 up SPEC_ARG as a login name. If that look-up fails, then try again |
ce1bca7b77d5
(parse_user_spec): If there is no `:' but there is a `.',
Jim Meyering <jim@meyering.net>
parents:
2273
diff
changeset
|
130 interpreting the `.' as a separator. |
5 | 131 |
132 USERNAME and GROUPNAME will be in newly malloc'd memory. | |
133 Either one might be NULL instead, indicating that it was not | |
134 given and the corresponding numeric ID was left unchanged. | |
135 | |
136 Return NULL if successful, a static error message string if not. */ | |
137 | |
194 | 138 const char * |
1580 | 139 parse_user_spec (const char *spec_arg, uid_t *uid, gid_t *gid, |
140 char **username_arg, char **groupname_arg) | |
5 | 141 { |
2273 | 142 static const char *E_invalid_user = N_("invalid user"); |
143 static const char *E_invalid_group = N_("invalid group"); | |
144 static const char *E_bad_spec = | |
145 N_("cannot get the login group of a numeric UID"); | |
146 static const char *E_cannot_omit_both = | |
147 N_("cannot omit both user and group"); | |
148 | |
194 | 149 const char *error_msg; |
150 char *spec; /* A copy we can write on. */ | |
5 | 151 struct passwd *pwd; |
152 struct group *grp; | |
194 | 153 char *g, *u, *separator; |
230 | 154 char *groupname; |
2284
ce1bca7b77d5
(parse_user_spec): If there is no `:' but there is a `.',
Jim Meyering <jim@meyering.net>
parents:
2273
diff
changeset
|
155 int maybe_retry = 0; |
ce1bca7b77d5
(parse_user_spec): If there is no `:' but there is a `.',
Jim Meyering <jim@meyering.net>
parents:
2273
diff
changeset
|
156 char *dot = NULL; |
5 | 157 |
194 | 158 error_msg = NULL; |
230 | 159 *username_arg = *groupname_arg = NULL; |
160 groupname = NULL; | |
5 | 161 |
231 | 162 V_STRDUP (spec, spec_arg); |
194 | 163 |
2284
ce1bca7b77d5
(parse_user_spec): If there is no `:' but there is a `.',
Jim Meyering <jim@meyering.net>
parents:
2273
diff
changeset
|
164 /* Find the POSIX `:' separator if there is one. */ |
432
a56993d69333
(parse_user_spec): Use strchr, not index.
Jim Meyering <jim@meyering.net>
parents:
316
diff
changeset
|
165 separator = strchr (spec, ':'); |
2273 | 166 |
2284
ce1bca7b77d5
(parse_user_spec): If there is no `:' but there is a `.',
Jim Meyering <jim@meyering.net>
parents:
2273
diff
changeset
|
167 /* If there is no colon, then see if there's a `.'. */ |
194 | 168 if (separator == NULL) |
2284
ce1bca7b77d5
(parse_user_spec): If there is no `:' but there is a `.',
Jim Meyering <jim@meyering.net>
parents:
2273
diff
changeset
|
169 { |
ce1bca7b77d5
(parse_user_spec): If there is no `:' but there is a `.',
Jim Meyering <jim@meyering.net>
parents:
2273
diff
changeset
|
170 dot = strchr (spec, '.'); |
ce1bca7b77d5
(parse_user_spec): If there is no `:' but there is a `.',
Jim Meyering <jim@meyering.net>
parents:
2273
diff
changeset
|
171 /* If there's no colon but there is a `.', then first look up the |
ce1bca7b77d5
(parse_user_spec): If there is no `:' but there is a `.',
Jim Meyering <jim@meyering.net>
parents:
2273
diff
changeset
|
172 whole spec, in case it's an OWNER name that includes a dot. |
ce1bca7b77d5
(parse_user_spec): If there is no `:' but there is a `.',
Jim Meyering <jim@meyering.net>
parents:
2273
diff
changeset
|
173 If that fails, then we'll try again, but interpreting the `.' |
ce1bca7b77d5
(parse_user_spec): If there is no `:' but there is a `.',
Jim Meyering <jim@meyering.net>
parents:
2273
diff
changeset
|
174 as a separator. */ |
ce1bca7b77d5
(parse_user_spec): If there is no `:' but there is a `.',
Jim Meyering <jim@meyering.net>
parents:
2273
diff
changeset
|
175 /* FIXME: accepting `.' as the separator is contrary to POSIX. |
ce1bca7b77d5
(parse_user_spec): If there is no `:' but there is a `.',
Jim Meyering <jim@meyering.net>
parents:
2273
diff
changeset
|
176 someday we should drop support for this. */ |
ce1bca7b77d5
(parse_user_spec): If there is no `:' but there is a `.',
Jim Meyering <jim@meyering.net>
parents:
2273
diff
changeset
|
177 if (dot) |
ce1bca7b77d5
(parse_user_spec): If there is no `:' but there is a `.',
Jim Meyering <jim@meyering.net>
parents:
2273
diff
changeset
|
178 maybe_retry = 1; |
ce1bca7b77d5
(parse_user_spec): If there is no `:' but there is a `.',
Jim Meyering <jim@meyering.net>
parents:
2273
diff
changeset
|
179 } |
ce1bca7b77d5
(parse_user_spec): If there is no `:' but there is a `.',
Jim Meyering <jim@meyering.net>
parents:
2273
diff
changeset
|
180 |
ce1bca7b77d5
(parse_user_spec): If there is no `:' but there is a `.',
Jim Meyering <jim@meyering.net>
parents:
2273
diff
changeset
|
181 retry: |
194 | 182 |
183 /* Replace separator with a NUL. */ | |
184 if (separator != NULL) | |
185 *separator = '\0'; | |
186 | |
187 /* Set U and G to non-zero length strings corresponding to user and | |
188 group specifiers or to NULL. */ | |
189 u = (*spec == '\0' ? NULL : spec); | |
190 | |
191 g = (separator == NULL || *(separator + 1) == '\0' | |
192 ? NULL | |
193 : separator + 1); | |
194 | |
195 if (u == NULL && g == NULL) | |
2273 | 196 return _(E_cannot_omit_both); |
194 | 197 |
1260
7aff74949325
(parse_user_spec) [__DJGPP__]: Make function know
Jim Meyering <jim@meyering.net>
parents:
966
diff
changeset
|
198 #ifdef __DJGPP__ |
7aff74949325
(parse_user_spec) [__DJGPP__]: Make function know
Jim Meyering <jim@meyering.net>
parents:
966
diff
changeset
|
199 /* Pretend that we are the user U whose group is G. This makes |
7aff74949325
(parse_user_spec) [__DJGPP__]: Make function know
Jim Meyering <jim@meyering.net>
parents:
966
diff
changeset
|
200 pwd and grp functions ``know'' about the UID and GID of these. */ |
7aff74949325
(parse_user_spec) [__DJGPP__]: Make function know
Jim Meyering <jim@meyering.net>
parents:
966
diff
changeset
|
201 if (u && !is_number (u)) |
7aff74949325
(parse_user_spec) [__DJGPP__]: Make function know
Jim Meyering <jim@meyering.net>
parents:
966
diff
changeset
|
202 setenv ("USER", u, 1); |
7aff74949325
(parse_user_spec) [__DJGPP__]: Make function know
Jim Meyering <jim@meyering.net>
parents:
966
diff
changeset
|
203 if (g && !is_number (g)) |
7aff74949325
(parse_user_spec) [__DJGPP__]: Make function know
Jim Meyering <jim@meyering.net>
parents:
966
diff
changeset
|
204 setenv ("GROUP", g, 1); |
7aff74949325
(parse_user_spec) [__DJGPP__]: Make function know
Jim Meyering <jim@meyering.net>
parents:
966
diff
changeset
|
205 #endif |
7aff74949325
(parse_user_spec) [__DJGPP__]: Make function know
Jim Meyering <jim@meyering.net>
parents:
966
diff
changeset
|
206 |
194 | 207 if (u != NULL) |
5 | 208 { |
194 | 209 pwd = getpwnam (u); |
210 if (pwd == NULL) | |
5 | 211 { |
194 | 212 |
475
7e3e0dd559c7
(isnumber): Rename to is_number.
Jim Meyering <jim@meyering.net>
parents:
432
diff
changeset
|
213 if (!is_number (u)) |
2810
aff553209434
(same_name): Invoke xalloc_die instead of printing our own message.
Jim Meyering <jim@meyering.net>
parents:
2284
diff
changeset
|
214 error_msg = E_invalid_user; |
5 | 215 else |
194 | 216 { |
217 int use_login_group; | |
218 use_login_group = (separator != NULL && g == NULL); | |
219 if (use_login_group) | |
2810
aff553209434
(same_name): Invoke xalloc_die instead of printing our own message.
Jim Meyering <jim@meyering.net>
parents:
2284
diff
changeset
|
220 error_msg = E_bad_spec; |
194 | 221 else |
2272
9d6da67904b5
add FIXME comments for use of atoi
Jim Meyering <jim@meyering.net>
parents:
2271
diff
changeset
|
222 { |
9d6da67904b5
add FIXME comments for use of atoi
Jim Meyering <jim@meyering.net>
parents:
2271
diff
changeset
|
223 /* FIXME: don't use atoi! */ |
9d6da67904b5
add FIXME comments for use of atoi
Jim Meyering <jim@meyering.net>
parents:
2271
diff
changeset
|
224 *uid = atoi (u); |
9d6da67904b5
add FIXME comments for use of atoi
Jim Meyering <jim@meyering.net>
parents:
2271
diff
changeset
|
225 } |
194 | 226 } |
5 | 227 } |
228 else | |
229 { | |
194 | 230 *uid = pwd->pw_uid; |
231 if (g == NULL && separator != NULL) | |
5 | 232 { |
194 | 233 /* A separator was given, but a group was not specified, |
234 so get the login group. */ | |
235 *gid = pwd->pw_gid; | |
236 grp = getgrgid (pwd->pw_gid); | |
237 if (grp == NULL) | |
238 { | |
239 /* This is enough room to hold the unsigned decimal | |
240 representation of any 32-bit quantity and the trailing | |
241 zero byte. */ | |
242 char uint_buf[21]; | |
243 sprintf (uint_buf, "%u", (unsigned) (pwd->pw_gid)); | |
230 | 244 V_STRDUP (groupname, uint_buf); |
194 | 245 } |
246 else | |
247 { | |
230 | 248 V_STRDUP (groupname, grp->gr_name); |
194 | 249 } |
250 endgrent (); | |
5 | 251 } |
194 | 252 } |
253 endpwent (); | |
5 | 254 } |
255 | |
195 | 256 if (g != NULL && error_msg == NULL) |
194 | 257 { |
258 /* Explicit group. */ | |
259 grp = getgrnam (g); | |
260 if (grp == NULL) | |
261 { | |
475
7e3e0dd559c7
(isnumber): Rename to is_number.
Jim Meyering <jim@meyering.net>
parents:
432
diff
changeset
|
262 if (!is_number (g)) |
2810
aff553209434
(same_name): Invoke xalloc_die instead of printing our own message.
Jim Meyering <jim@meyering.net>
parents:
2284
diff
changeset
|
263 error_msg = E_invalid_group; |
194 | 264 else |
2272
9d6da67904b5
add FIXME comments for use of atoi
Jim Meyering <jim@meyering.net>
parents:
2271
diff
changeset
|
265 { |
9d6da67904b5
add FIXME comments for use of atoi
Jim Meyering <jim@meyering.net>
parents:
2271
diff
changeset
|
266 /* FIXME: don't use atoi! */ |
9d6da67904b5
add FIXME comments for use of atoi
Jim Meyering <jim@meyering.net>
parents:
2271
diff
changeset
|
267 *gid = atoi (g); |
9d6da67904b5
add FIXME comments for use of atoi
Jim Meyering <jim@meyering.net>
parents:
2271
diff
changeset
|
268 } |
194 | 269 } |
270 else | |
271 *gid = grp->gr_gid; | |
272 endgrent (); /* Save a file descriptor. */ | |
5 | 273 |
194 | 274 if (error_msg == NULL) |
230 | 275 V_STRDUP (groupname, g); |
5 | 276 } |
194 | 277 |
230 | 278 if (error_msg == NULL) |
5 | 279 { |
230 | 280 if (u != NULL) |
281 { | |
282 *username_arg = strdup (u); | |
283 if (*username_arg == NULL) | |
2810
aff553209434
(same_name): Invoke xalloc_die instead of printing our own message.
Jim Meyering <jim@meyering.net>
parents:
2284
diff
changeset
|
284 error_msg = xalloc_msg_memory_exhausted; |
230 | 285 } |
286 | |
287 if (groupname != NULL && error_msg == NULL) | |
5 | 288 { |
230 | 289 *groupname_arg = strdup (groupname); |
290 if (*groupname_arg == NULL) | |
291 { | |
292 if (*username_arg != NULL) | |
293 { | |
294 free (*username_arg); | |
295 *username_arg = NULL; | |
296 } | |
2810
aff553209434
(same_name): Invoke xalloc_die instead of printing our own message.
Jim Meyering <jim@meyering.net>
parents:
2284
diff
changeset
|
297 error_msg = xalloc_msg_memory_exhausted; |
230 | 298 } |
5 | 299 } |
300 } | |
194 | 301 |
2284
ce1bca7b77d5
(parse_user_spec): If there is no `:' but there is a `.',
Jim Meyering <jim@meyering.net>
parents:
2273
diff
changeset
|
302 if (error_msg && maybe_retry) |
ce1bca7b77d5
(parse_user_spec): If there is no `:' but there is a `.',
Jim Meyering <jim@meyering.net>
parents:
2273
diff
changeset
|
303 { |
ce1bca7b77d5
(parse_user_spec): If there is no `:' but there is a `.',
Jim Meyering <jim@meyering.net>
parents:
2273
diff
changeset
|
304 maybe_retry = 0; |
ce1bca7b77d5
(parse_user_spec): If there is no `:' but there is a `.',
Jim Meyering <jim@meyering.net>
parents:
2273
diff
changeset
|
305 separator = dot; |
ce1bca7b77d5
(parse_user_spec): If there is no `:' but there is a `.',
Jim Meyering <jim@meyering.net>
parents:
2273
diff
changeset
|
306 error_msg = NULL; |
ce1bca7b77d5
(parse_user_spec): If there is no `:' but there is a `.',
Jim Meyering <jim@meyering.net>
parents:
2273
diff
changeset
|
307 goto retry; |
ce1bca7b77d5
(parse_user_spec): If there is no `:' but there is a `.',
Jim Meyering <jim@meyering.net>
parents:
2273
diff
changeset
|
308 } |
ce1bca7b77d5
(parse_user_spec): If there is no `:' but there is a `.',
Jim Meyering <jim@meyering.net>
parents:
2273
diff
changeset
|
309 |
2810
aff553209434
(same_name): Invoke xalloc_die instead of printing our own message.
Jim Meyering <jim@meyering.net>
parents:
2284
diff
changeset
|
310 return _(error_msg); |
5 | 311 } |
312 | |
232
0d9395790eb7
(main): Change #ifdef TESTING to TEST.
Jim Meyering <jim@meyering.net>
parents:
231
diff
changeset
|
313 #ifdef TEST |
194 | 314 |
966 | 315 # define NULL_CHECK(s) ((s) == NULL ? "(null)" : (s)) |
194 | 316 |
317 int | |
318 main (int argc, char **argv) | |
319 { | |
320 int i; | |
321 | |
322 for (i = 1; i < argc; i++) | |
323 { | |
324 const char *e; | |
325 char *username, *groupname; | |
326 uid_t uid; | |
327 gid_t gid; | |
328 char *tmp; | |
5 | 329 |
194 | 330 tmp = strdup (argv[i]); |
331 e = parse_user_spec (tmp, &uid, &gid, &username, &groupname); | |
332 free (tmp); | |
333 printf ("%s: %u %u %s %s %s\n", | |
334 argv[i], | |
335 (unsigned int) uid, | |
336 (unsigned int) gid, | |
337 NULL_CHECK (username), | |
338 NULL_CHECK (groupname), | |
339 NULL_CHECK (e)); | |
340 } | |
341 | |
342 exit (0); | |
5 | 343 } |
194 | 344 |
345 #endif |