1 /* Copyright (c) 1997-2018 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1997.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
24 #include <sys/types.h>
26 #include <rpcsvc/nis.h>
27 #include <shlib-compat.h>
29 #define DEFAULT_TTL 43200
32 ** Some functions for parsing the -D param and NIS_DEFAULTS Environ
35 searchXYX (char *str
, const char *what
)
37 assert (strlen (what
) == 6);
38 assert (strncmp (str
, what
, 6) == 0);
39 str
+= 6; /* Points to the begin of the parameters. */
42 while (str
[i
] != '\0' && str
[i
] != ':')
44 if (i
== 0) /* only "<WHAT>=" ? */
47 return strndup (str
, i
);
52 searchgroup (char *str
)
54 return searchXYX (str
, "group=");
59 searchowner (char *str
)
61 return searchXYX (str
, "owner=");
68 char buf
[strlen (str
) + 1];
73 dptr
= strstr (str
, "ttl=");
74 if (dptr
== NULL
) /* should (could) not happen */
77 dptr
+= 4; /* points to the begin of the new ttl */
79 while (dptr
[i
] != '\0' && dptr
[i
] != ':')
81 if (i
== 0) /* only "ttl=" ? */
84 strncpy (buf
, dptr
, i
);
89 cptr
= strchr (dptr
, 'd');
94 time
+= atoi (dptr
) * 60 * 60 * 24;
98 cptr
= strchr (dptr
, 'h');
103 time
+= atoi (dptr
) * 60 * 60;
107 cptr
= strchr (dptr
, 'm');
112 time
+= atoi (dptr
) * 60;
116 cptr
= strchr (dptr
, 's');
126 searchaccess (char *str
, unsigned int access
)
128 char buf
[strlen (str
) + 1];
130 unsigned int result
= access
;
134 cptr
= strstr (str
, "access=");
138 cptr
+= 7; /* points to the begin of the access string */
140 while (cptr
[i
] != '\0' && cptr
[i
] != ':')
142 if (i
== 0) /* only "access=" ? */
145 strncpy (buf
, cptr
, i
);
150 if (*cptr
== ',') /* Fix for stupid Solaris scripts */
152 while (*cptr
!= '\0')
172 cptr
++; /* Remove "-" from beginning */
173 while (*cptr
!= '\0' && *cptr
!= ',')
179 result
= result
& ~(NIS_READ_ACC
<< 24);
181 result
= result
& ~(NIS_READ_ACC
<< 16);
183 result
= result
& ~(NIS_READ_ACC
<< 8);
185 result
= result
& ~(NIS_READ_ACC
);
189 result
= result
& ~(NIS_MODIFY_ACC
<< 24);
191 result
= result
& ~(NIS_MODIFY_ACC
<< 16);
193 result
= result
& ~(NIS_MODIFY_ACC
<< 8);
195 result
= result
& ~(NIS_MODIFY_ACC
);
199 result
= result
& ~(NIS_CREATE_ACC
<< 24);
201 result
= result
& ~(NIS_CREATE_ACC
<< 16);
203 result
= result
& ~(NIS_CREATE_ACC
<< 8);
205 result
= result
& ~(NIS_CREATE_ACC
);
209 result
= result
& ~(NIS_DESTROY_ACC
<< 24);
211 result
= result
& ~(NIS_DESTROY_ACC
<< 16);
213 result
= result
& ~(NIS_DESTROY_ACC
<< 8);
215 result
= result
& ~(NIS_DESTROY_ACC
);
225 cptr
++; /* Remove "+" from beginning */
226 while (*cptr
!= '\0' && *cptr
!= ',')
232 result
= result
| (NIS_READ_ACC
<< 24);
234 result
= result
| (NIS_READ_ACC
<< 16);
236 result
= result
| (NIS_READ_ACC
<< 8);
238 result
= result
| (NIS_READ_ACC
);
242 result
= result
| (NIS_MODIFY_ACC
<< 24);
244 result
= result
| (NIS_MODIFY_ACC
<< 16);
246 result
= result
| (NIS_MODIFY_ACC
<< 8);
248 result
= result
| (NIS_MODIFY_ACC
);
252 result
= result
| (NIS_CREATE_ACC
<< 24);
254 result
= result
| (NIS_CREATE_ACC
<< 16);
256 result
= result
| (NIS_CREATE_ACC
<< 8);
258 result
= result
| (NIS_CREATE_ACC
);
262 result
= result
| (NIS_DESTROY_ACC
<< 24);
264 result
= result
| (NIS_DESTROY_ACC
<< 16);
266 result
= result
| (NIS_DESTROY_ACC
<< 8);
268 result
= result
| (NIS_DESTROY_ACC
);
278 cptr
++; /* Remove "=" from beginning */
281 result
= result
& ~((NIS_READ_ACC
+ NIS_MODIFY_ACC
+
282 NIS_CREATE_ACC
+ NIS_DESTROY_ACC
) << 24);
285 result
= result
& ~((NIS_READ_ACC
+ NIS_MODIFY_ACC
+
286 NIS_CREATE_ACC
+ NIS_DESTROY_ACC
) << 16);
288 result
= result
& ~((NIS_READ_ACC
+ NIS_MODIFY_ACC
+
289 NIS_CREATE_ACC
+ NIS_DESTROY_ACC
) << 8);
291 result
= result
& ~(NIS_READ_ACC
+ NIS_MODIFY_ACC
+
292 NIS_CREATE_ACC
+ NIS_DESTROY_ACC
);
293 while (*cptr
!= '\0' && *cptr
!= ',')
299 result
= result
| (NIS_READ_ACC
<< 24);
301 result
= result
| (NIS_READ_ACC
<< 16);
303 result
= result
| (NIS_READ_ACC
<< 8);
305 result
= result
| (NIS_READ_ACC
);
309 result
= result
| (NIS_MODIFY_ACC
<< 24);
311 result
= result
| (NIS_MODIFY_ACC
<< 16);
313 result
= result
| (NIS_MODIFY_ACC
<< 8);
315 result
= result
| (NIS_MODIFY_ACC
);
319 result
= result
| (NIS_CREATE_ACC
<< 24);
321 result
= result
| (NIS_CREATE_ACC
<< 16);
323 result
= result
| (NIS_CREATE_ACC
<< 8);
325 result
= result
| (NIS_CREATE_ACC
);
329 result
= result
| (NIS_DESTROY_ACC
<< 24);
331 result
= result
| (NIS_DESTROY_ACC
<< 16);
333 result
= result
| (NIS_DESTROY_ACC
<< 8);
335 result
= result
| (NIS_DESTROY_ACC
);
338 return result
= (~0U);
345 return result
= (~0U);
356 __nis_default_owner (char *defaults
)
358 char *default_owner
= NULL
;
360 char *cptr
= defaults
;
362 cptr
= getenv ("NIS_DEFAULTS");
366 char *dptr
= strstr (cptr
, "owner=");
369 char *p
= searchowner (dptr
);
372 default_owner
= strdupa (p
);
377 return strdup (default_owner
?: nis_local_principal ());
379 libnsl_hidden_nolink_def (__nis_default_owner
, GLIBC_2_1
)
383 __nis_default_group (char *defaults
)
385 char *default_group
= NULL
;
387 char *cptr
= defaults
;
389 cptr
= getenv ("NIS_DEFAULTS");
393 char *dptr
= strstr (cptr
, "group=");
396 char *p
= searchgroup (dptr
);
399 default_group
= strdupa (p
);
404 return strdup (default_group
?: nis_local_group ());
406 libnsl_hidden_nolink_def (__nis_default_group
, GLIBC_2_1
)
410 __nis_default_ttl (char *defaults
)
414 if (defaults
!= NULL
)
416 dptr
= strstr (defaults
, "ttl=");
418 return searchttl (defaults
);
421 cptr
= getenv ("NIS_DEFAULTS");
425 dptr
= strstr (cptr
, "ttl=");
429 return searchttl (cptr
);
431 libnsl_hidden_nolink_def (__nis_default_ttl
, GLIBC_2_1
)
433 /* Default access rights are ----rmcdr---r---, but we could change
434 this with the NIS_DEFAULTS variable. */
436 __nis_default_access (char *param
, unsigned int defaults
)
442 result
= 0 | OWNER_DEFAULT
| GROUP_DEFAULT
| WORLD_DEFAULT
;
446 if (param
!= NULL
&& strstr (param
, "access=") != NULL
)
447 result
= searchaccess (param
, result
);
450 cptr
= getenv ("NIS_DEFAULTS");
451 if (cptr
!= NULL
&& strstr (cptr
, "access=") != NULL
)
452 result
= searchaccess (cptr
, result
);
457 libnsl_hidden_nolink_def (__nis_default_access
, GLIBC_2_1
)