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