Mercurial > hg > octave-lojdl > gnulib-hg
annotate lib/userspec.c @ 4560:ff249a314eac
Accept `.' as a separator only in pre-POSIX-200112 mode.
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Sat, 16 Aug 2003 06:25:29 +0000 |
parents | fcd34d3861a4 |
children | ce37d22a271f |
rev | line source |
---|---|
5 | 1 /* userspec.c -- Parse a user and group string. |
4156
99ea86c79f44
Make it possibly to simply write: #include <alloca.h>.
Bruno Haible <bruno@clisp.org>
parents:
3966
diff
changeset
|
2 Copyright (C) 1989-1992, 1997-1998, 2000, 2002-2003 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 | |
4156
99ea86c79f44
Make it possibly to simply write: #include <alloca.h>.
Bruno Haible <bruno@clisp.org>
parents:
3966
diff
changeset
|
24 #include <alloca.h> |
230 | 25 |
5 | 26 #include <stdio.h> |
27 #include <sys/types.h> | |
28 #include <pwd.h> | |
29 #include <grp.h> | |
30 | |
2854 | 31 #if HAVE_SYS_PARAM_H |
32 # include <sys/param.h> | |
33 #endif | |
34 | |
4333 | 35 #include <limits.h> |
2854 | 36 |
966 | 37 #if HAVE_STRING_H |
432
a56993d69333
(parse_user_spec): Use strchr, not index.
Jim Meyering <jim@meyering.net>
parents:
316
diff
changeset
|
38 # include <string.h> |
5 | 39 #else |
432
a56993d69333
(parse_user_spec): Use strchr, not index.
Jim Meyering <jim@meyering.net>
parents:
316
diff
changeset
|
40 # include <strings.h> |
a56993d69333
(parse_user_spec): Use strchr, not index.
Jim Meyering <jim@meyering.net>
parents:
316
diff
changeset
|
41 # ifndef strchr |
a56993d69333
(parse_user_spec): Use strchr, not index.
Jim Meyering <jim@meyering.net>
parents:
316
diff
changeset
|
42 # define strchr index |
a56993d69333
(parse_user_spec): Use strchr, not index.
Jim Meyering <jim@meyering.net>
parents:
316
diff
changeset
|
43 # endif |
5 | 44 #endif |
45 | |
966 | 46 #if STDC_HEADERS |
432
a56993d69333
(parse_user_spec): Use strchr, not index.
Jim Meyering <jim@meyering.net>
parents:
316
diff
changeset
|
47 # include <stdlib.h> |
5 | 48 #endif |
49 | |
966 | 50 #if HAVE_UNISTD_H |
432
a56993d69333
(parse_user_spec): Use strchr, not index.
Jim Meyering <jim@meyering.net>
parents:
316
diff
changeset
|
51 # include <unistd.h> |
5 | 52 #endif |
53 | |
4560
ff249a314eac
Accept `.' as a separator only in pre-POSIX-200112 mode.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4333
diff
changeset
|
54 #include "posixver.h" |
2810
aff553209434
(same_name): Invoke xalloc_die instead of printing our own message.
Jim Meyering <jim@meyering.net>
parents:
2284
diff
changeset
|
55 #include "xalloc.h" |
2854 | 56 #include "xstrtol.h" |
2810
aff553209434
(same_name): Invoke xalloc_die instead of printing our own message.
Jim Meyering <jim@meyering.net>
parents:
2284
diff
changeset
|
57 |
3966
22d3032f0239
Include gettext.h instead of <libintl.h> with #ifdefs.
Bruno Haible <bruno@clisp.org>
parents:
3700
diff
changeset
|
58 #include "gettext.h" |
22d3032f0239
Include gettext.h instead of <libintl.h> with #ifdefs.
Bruno Haible <bruno@clisp.org>
parents:
3700
diff
changeset
|
59 #define _(msgid) gettext (msgid) |
22d3032f0239
Include gettext.h instead of <libintl.h> with #ifdefs.
Bruno Haible <bruno@clisp.org>
parents:
3700
diff
changeset
|
60 #define N_(msgid) msgid |
2273 | 61 |
5 | 62 #ifndef _POSIX_VERSION |
63 struct passwd *getpwnam (); | |
64 struct group *getgrnam (); | |
65 struct group *getgrgid (); | |
66 #endif | |
67 | |
499
62aa0b766a11
[HAVE_ENDGRENT]: Define away endgrent.
Jim Meyering <jim@meyering.net>
parents:
475
diff
changeset
|
68 #ifndef HAVE_ENDGRENT |
62aa0b766a11
[HAVE_ENDGRENT]: Define away endgrent.
Jim Meyering <jim@meyering.net>
parents:
475
diff
changeset
|
69 # define endgrent() ((void) 0) |
62aa0b766a11
[HAVE_ENDGRENT]: Define away endgrent.
Jim Meyering <jim@meyering.net>
parents:
475
diff
changeset
|
70 #endif |
62aa0b766a11
[HAVE_ENDGRENT]: Define away endgrent.
Jim Meyering <jim@meyering.net>
parents:
475
diff
changeset
|
71 |
62aa0b766a11
[HAVE_ENDGRENT]: Define away endgrent.
Jim Meyering <jim@meyering.net>
parents:
475
diff
changeset
|
72 #ifndef HAVE_ENDPWENT |
62aa0b766a11
[HAVE_ENDGRENT]: Define away endgrent.
Jim Meyering <jim@meyering.net>
parents:
475
diff
changeset
|
73 # define endpwent() ((void) 0) |
5 | 74 #endif |
75 | |
2854 | 76 /* The extra casts work around common compiler bugs. */ |
77 #define TYPE_SIGNED(t) (! ((t) 0 < (t) -1)) | |
78 /* The outer cast is needed to work around a bug in Cray C 5.0.3.0. | |
79 It is necessary at least when t == time_t. */ | |
80 #define TYPE_MINIMUM(t) ((t) (TYPE_SIGNED (t) \ | |
81 ? ~ (t) 0 << (sizeof (t) * CHAR_BIT - 1) : (t) 0)) | |
82 #define TYPE_MAXIMUM(t) ((t) (~ (t) 0 - TYPE_MINIMUM (t))) | |
83 | |
84 #ifndef UID_T_MAX | |
85 # define UID_T_MAX TYPE_MAXIMUM (uid_t) | |
86 #endif | |
87 | |
88 #ifndef GID_T_MAX | |
89 # define GID_T_MAX TYPE_MAXIMUM (gid_t) | |
90 #endif | |
91 | |
92 /* MAXUID may come from limits.h or sys/params.h. */ | |
93 #ifndef MAXUID | |
94 # define MAXUID UID_T_MAX | |
95 #endif | |
96 #ifndef MAXGID | |
97 # define MAXGID GID_T_MAX | |
98 #endif | |
99 | |
230 | 100 /* Perform the equivalent of the statement `dest = strdup (src);', |
101 but obtaining storage via alloca instead of from the heap. */ | |
102 | |
103 #define V_STRDUP(dest, src) \ | |
104 do \ | |
105 { \ | |
106 int _len = strlen ((src)); \ | |
107 (dest) = (char *) alloca (_len + 1); \ | |
108 strcpy (dest, src); \ | |
109 } \ | |
110 while (0) | |
111 | |
2271 | 112 /* ISDIGIT differs from isdigit, as follows: |
113 - Its arg may be any int or unsigned int; it need not be an unsigned char. | |
114 - It's guaranteed to evaluate its argument exactly once. | |
115 - It's typically faster. | |
3699 | 116 POSIX says that only '0' through '9' are digits. Prefer ISDIGIT to |
117 ISDIGIT_LOCALE unless it's important to use the locale's definition | |
118 of `digit' even when the host does not conform to POSIX. */ | |
2271 | 119 #define ISDIGIT(c) ((unsigned) (c) - '0' <= 9) |
5 | 120 |
1347
e7dc6e5a3be5
Don't declare strdup if it's defined as a macro.
Jim Meyering <jim@meyering.net>
parents:
1278
diff
changeset
|
121 #ifndef strdup |
5 | 122 char *strdup (); |
1347
e7dc6e5a3be5
Don't declare strdup if it's defined as a macro.
Jim Meyering <jim@meyering.net>
parents:
1278
diff
changeset
|
123 #endif |
194 | 124 |
125 /* Return nonzero if STR represents an unsigned decimal integer, | |
126 otherwise return 0. */ | |
127 | |
128 static int | |
1557 | 129 is_number (const char *str) |
194 | 130 { |
131 for (; *str; str++) | |
2271 | 132 if (!ISDIGIT (*str)) |
194 | 133 return 0; |
134 return 1; | |
135 } | |
5 | 136 |
137 /* Extract from NAME, which has the form "[user][:.][group]", | |
138 a USERNAME, UID U, GROUPNAME, and GID G. | |
139 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
|
140 If the group is omitted but the ":" separator is given, |
5 | 141 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
|
142 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
|
143 any `.'s. If there is no `:', but there is a `.', then first look |
3049 | 144 up the entire SPEC_ARG as a login name. If that look-up fails, then |
145 try again interpreting the `.' as a separator. | |
5 | 146 |
147 USERNAME and GROUPNAME will be in newly malloc'd memory. | |
148 Either one might be NULL instead, indicating that it was not | |
149 given and the corresponding numeric ID was left unchanged. | |
150 | |
151 Return NULL if successful, a static error message string if not. */ | |
152 | |
194 | 153 const char * |
1580 | 154 parse_user_spec (const char *spec_arg, uid_t *uid, gid_t *gid, |
155 char **username_arg, char **groupname_arg) | |
5 | 156 { |
2273 | 157 static const char *E_invalid_user = N_("invalid user"); |
158 static const char *E_invalid_group = N_("invalid group"); | |
159 static const char *E_bad_spec = | |
160 N_("cannot get the login group of a numeric UID"); | |
161 static const char *E_cannot_omit_both = | |
162 N_("cannot omit both user and group"); | |
163 | |
194 | 164 const char *error_msg; |
165 char *spec; /* A copy we can write on. */ | |
5 | 166 struct passwd *pwd; |
167 struct group *grp; | |
194 | 168 char *g, *u, *separator; |
230 | 169 char *groupname; |
2284
ce1bca7b77d5
(parse_user_spec): If there is no `:' but there is a `.',
Jim Meyering <jim@meyering.net>
parents:
2273
diff
changeset
|
170 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
|
171 char *dot = NULL; |
5 | 172 |
194 | 173 error_msg = NULL; |
230 | 174 *username_arg = *groupname_arg = NULL; |
175 groupname = NULL; | |
5 | 176 |
231 | 177 V_STRDUP (spec, spec_arg); |
194 | 178 |
2284
ce1bca7b77d5
(parse_user_spec): If there is no `:' but there is a `.',
Jim Meyering <jim@meyering.net>
parents:
2273
diff
changeset
|
179 /* 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
|
180 separator = strchr (spec, ':'); |
2273 | 181 |
2284
ce1bca7b77d5
(parse_user_spec): If there is no `:' but there is a `.',
Jim Meyering <jim@meyering.net>
parents:
2273
diff
changeset
|
182 /* If there is no colon, then see if there's a `.'. */ |
4560
ff249a314eac
Accept `.' as a separator only in pre-POSIX-200112 mode.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4333
diff
changeset
|
183 if (separator == NULL && posix2_version () < 200112) |
2284
ce1bca7b77d5
(parse_user_spec): If there is no `:' but there is a `.',
Jim Meyering <jim@meyering.net>
parents:
2273
diff
changeset
|
184 { |
ce1bca7b77d5
(parse_user_spec): If there is no `:' but there is a `.',
Jim Meyering <jim@meyering.net>
parents:
2273
diff
changeset
|
185 dot = strchr (spec, '.'); |
ce1bca7b77d5
(parse_user_spec): If there is no `:' but there is a `.',
Jim Meyering <jim@meyering.net>
parents:
2273
diff
changeset
|
186 /* 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
|
187 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
|
188 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
|
189 as a separator. */ |
ce1bca7b77d5
(parse_user_spec): If there is no `:' but there is a `.',
Jim Meyering <jim@meyering.net>
parents:
2273
diff
changeset
|
190 /* 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
|
191 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
|
192 if (dot) |
ce1bca7b77d5
(parse_user_spec): If there is no `:' but there is a `.',
Jim Meyering <jim@meyering.net>
parents:
2273
diff
changeset
|
193 maybe_retry = 1; |
ce1bca7b77d5
(parse_user_spec): If there is no `:' but there is a `.',
Jim Meyering <jim@meyering.net>
parents:
2273
diff
changeset
|
194 } |
ce1bca7b77d5
(parse_user_spec): If there is no `:' but there is a `.',
Jim Meyering <jim@meyering.net>
parents:
2273
diff
changeset
|
195 |
ce1bca7b77d5
(parse_user_spec): If there is no `:' but there is a `.',
Jim Meyering <jim@meyering.net>
parents:
2273
diff
changeset
|
196 retry: |
194 | 197 |
198 /* Replace separator with a NUL. */ | |
199 if (separator != NULL) | |
200 *separator = '\0'; | |
201 | |
202 /* Set U and G to non-zero length strings corresponding to user and | |
203 group specifiers or to NULL. */ | |
204 u = (*spec == '\0' ? NULL : spec); | |
205 | |
206 g = (separator == NULL || *(separator + 1) == '\0' | |
207 ? NULL | |
208 : separator + 1); | |
209 | |
210 if (u == NULL && g == NULL) | |
2273 | 211 return _(E_cannot_omit_both); |
194 | 212 |
1260
7aff74949325
(parse_user_spec) [__DJGPP__]: Make function know
Jim Meyering <jim@meyering.net>
parents:
966
diff
changeset
|
213 #ifdef __DJGPP__ |
7aff74949325
(parse_user_spec) [__DJGPP__]: Make function know
Jim Meyering <jim@meyering.net>
parents:
966
diff
changeset
|
214 /* 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
|
215 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
|
216 if (u && !is_number (u)) |
7aff74949325
(parse_user_spec) [__DJGPP__]: Make function know
Jim Meyering <jim@meyering.net>
parents:
966
diff
changeset
|
217 setenv ("USER", u, 1); |
7aff74949325
(parse_user_spec) [__DJGPP__]: Make function know
Jim Meyering <jim@meyering.net>
parents:
966
diff
changeset
|
218 if (g && !is_number (g)) |
7aff74949325
(parse_user_spec) [__DJGPP__]: Make function know
Jim Meyering <jim@meyering.net>
parents:
966
diff
changeset
|
219 setenv ("GROUP", g, 1); |
7aff74949325
(parse_user_spec) [__DJGPP__]: Make function know
Jim Meyering <jim@meyering.net>
parents:
966
diff
changeset
|
220 #endif |
7aff74949325
(parse_user_spec) [__DJGPP__]: Make function know
Jim Meyering <jim@meyering.net>
parents:
966
diff
changeset
|
221 |
194 | 222 if (u != NULL) |
5 | 223 { |
194 | 224 pwd = getpwnam (u); |
225 if (pwd == NULL) | |
5 | 226 { |
194 | 227 |
475
7e3e0dd559c7
(isnumber): Rename to is_number.
Jim Meyering <jim@meyering.net>
parents:
432
diff
changeset
|
228 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
|
229 error_msg = E_invalid_user; |
5 | 230 else |
194 | 231 { |
232 int use_login_group; | |
233 use_login_group = (separator != NULL && g == NULL); | |
234 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
|
235 error_msg = E_bad_spec; |
194 | 236 else |
2272
9d6da67904b5
add FIXME comments for use of atoi
Jim Meyering <jim@meyering.net>
parents:
2271
diff
changeset
|
237 { |
2854 | 238 unsigned long int tmp_long; |
239 if (xstrtoul (u, NULL, 0, &tmp_long, NULL) != LONGINT_OK | |
240 || tmp_long > MAXUID) | |
241 return _(E_invalid_user); | |
242 *uid = tmp_long; | |
2272
9d6da67904b5
add FIXME comments for use of atoi
Jim Meyering <jim@meyering.net>
parents:
2271
diff
changeset
|
243 } |
194 | 244 } |
5 | 245 } |
246 else | |
247 { | |
194 | 248 *uid = pwd->pw_uid; |
249 if (g == NULL && separator != NULL) | |
5 | 250 { |
194 | 251 /* A separator was given, but a group was not specified, |
252 so get the login group. */ | |
253 *gid = pwd->pw_gid; | |
254 grp = getgrgid (pwd->pw_gid); | |
255 if (grp == NULL) | |
256 { | |
257 /* This is enough room to hold the unsigned decimal | |
258 representation of any 32-bit quantity and the trailing | |
259 zero byte. */ | |
260 char uint_buf[21]; | |
261 sprintf (uint_buf, "%u", (unsigned) (pwd->pw_gid)); | |
230 | 262 V_STRDUP (groupname, uint_buf); |
194 | 263 } |
264 else | |
265 { | |
230 | 266 V_STRDUP (groupname, grp->gr_name); |
194 | 267 } |
268 endgrent (); | |
5 | 269 } |
194 | 270 } |
271 endpwent (); | |
5 | 272 } |
273 | |
195 | 274 if (g != NULL && error_msg == NULL) |
194 | 275 { |
276 /* Explicit group. */ | |
277 grp = getgrnam (g); | |
278 if (grp == NULL) | |
279 { | |
475
7e3e0dd559c7
(isnumber): Rename to is_number.
Jim Meyering <jim@meyering.net>
parents:
432
diff
changeset
|
280 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
|
281 error_msg = E_invalid_group; |
194 | 282 else |
2272
9d6da67904b5
add FIXME comments for use of atoi
Jim Meyering <jim@meyering.net>
parents:
2271
diff
changeset
|
283 { |
2854 | 284 unsigned long int tmp_long; |
3050
aaaab011fac4
This bug had a serious impact on chown: `chown N:M FILE' (for integer
Jim Meyering <jim@meyering.net>
parents:
3049
diff
changeset
|
285 if (xstrtoul (g, NULL, 0, &tmp_long, NULL) != LONGINT_OK |
2854 | 286 || tmp_long > MAXGID) |
287 return _(E_invalid_group); | |
288 *gid = tmp_long; | |
2272
9d6da67904b5
add FIXME comments for use of atoi
Jim Meyering <jim@meyering.net>
parents:
2271
diff
changeset
|
289 } |
194 | 290 } |
291 else | |
292 *gid = grp->gr_gid; | |
293 endgrent (); /* Save a file descriptor. */ | |
5 | 294 |
194 | 295 if (error_msg == NULL) |
230 | 296 V_STRDUP (groupname, g); |
5 | 297 } |
194 | 298 |
230 | 299 if (error_msg == NULL) |
5 | 300 { |
230 | 301 if (u != NULL) |
302 { | |
303 *username_arg = strdup (u); | |
304 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
|
305 error_msg = xalloc_msg_memory_exhausted; |
230 | 306 } |
307 | |
308 if (groupname != NULL && error_msg == NULL) | |
5 | 309 { |
230 | 310 *groupname_arg = strdup (groupname); |
311 if (*groupname_arg == NULL) | |
312 { | |
313 if (*username_arg != NULL) | |
314 { | |
315 free (*username_arg); | |
316 *username_arg = NULL; | |
317 } | |
2810
aff553209434
(same_name): Invoke xalloc_die instead of printing our own message.
Jim Meyering <jim@meyering.net>
parents:
2284
diff
changeset
|
318 error_msg = xalloc_msg_memory_exhausted; |
230 | 319 } |
5 | 320 } |
321 } | |
194 | 322 |
2284
ce1bca7b77d5
(parse_user_spec): If there is no `:' but there is a `.',
Jim Meyering <jim@meyering.net>
parents:
2273
diff
changeset
|
323 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
|
324 { |
ce1bca7b77d5
(parse_user_spec): If there is no `:' but there is a `.',
Jim Meyering <jim@meyering.net>
parents:
2273
diff
changeset
|
325 maybe_retry = 0; |
ce1bca7b77d5
(parse_user_spec): If there is no `:' but there is a `.',
Jim Meyering <jim@meyering.net>
parents:
2273
diff
changeset
|
326 separator = dot; |
ce1bca7b77d5
(parse_user_spec): If there is no `:' but there is a `.',
Jim Meyering <jim@meyering.net>
parents:
2273
diff
changeset
|
327 error_msg = NULL; |
ce1bca7b77d5
(parse_user_spec): If there is no `:' but there is a `.',
Jim Meyering <jim@meyering.net>
parents:
2273
diff
changeset
|
328 goto retry; |
ce1bca7b77d5
(parse_user_spec): If there is no `:' but there is a `.',
Jim Meyering <jim@meyering.net>
parents:
2273
diff
changeset
|
329 } |
ce1bca7b77d5
(parse_user_spec): If there is no `:' but there is a `.',
Jim Meyering <jim@meyering.net>
parents:
2273
diff
changeset
|
330 |
2810
aff553209434
(same_name): Invoke xalloc_die instead of printing our own message.
Jim Meyering <jim@meyering.net>
parents:
2284
diff
changeset
|
331 return _(error_msg); |
5 | 332 } |
333 | |
232
0d9395790eb7
(main): Change #ifdef TESTING to TEST.
Jim Meyering <jim@meyering.net>
parents:
231
diff
changeset
|
334 #ifdef TEST |
194 | 335 |
966 | 336 # define NULL_CHECK(s) ((s) == NULL ? "(null)" : (s)) |
194 | 337 |
338 int | |
339 main (int argc, char **argv) | |
340 { | |
341 int i; | |
342 | |
343 for (i = 1; i < argc; i++) | |
344 { | |
345 const char *e; | |
346 char *username, *groupname; | |
347 uid_t uid; | |
348 gid_t gid; | |
349 char *tmp; | |
5 | 350 |
194 | 351 tmp = strdup (argv[i]); |
352 e = parse_user_spec (tmp, &uid, &gid, &username, &groupname); | |
353 free (tmp); | |
354 printf ("%s: %u %u %s %s %s\n", | |
355 argv[i], | |
356 (unsigned int) uid, | |
357 (unsigned int) gid, | |
358 NULL_CHECK (username), | |
359 NULL_CHECK (groupname), | |
360 NULL_CHECK (e)); | |
361 } | |
362 | |
363 exit (0); | |
5 | 364 } |
194 | 365 |
366 #endif |