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