1 /* Copyright (c) 1997, 1998, 2004, 2006 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, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
24 #include <sys/types.h>
26 #include <rpcsvc/nis.h>
28 #define DEFAULT_TTL 43200
31 ** Some functions for parsing the -D param and NIS_DEFAULTS Environ
34 searchXYX (char *str
, const char *what
)
36 assert (strlen (what
) == 6);
37 assert (strncmp (str
, what
, 6) == 0);
38 str
+= 6; /* Points to the begin of the parameters. */
41 while (str
[i
] != '\0' && str
[i
] != ':')
43 if (i
== 0) /* only "<WHAT>=" ? */
46 return strndup (str
, i
);
51 searchgroup (char *str
)
53 return searchXYX (str
, "group=");
58 searchowner (char *str
)
60 return searchXYX (str
, "owner=");
67 char buf
[strlen (str
) + 1];
72 dptr
= strstr (str
, "ttl=");
73 if (dptr
== NULL
) /* should (could) not happen */
76 dptr
+= 4; /* points to the begin of the new ttl */
78 while (dptr
[i
] != '\0' && dptr
[i
] != ':')
80 if (i
== 0) /* only "ttl=" ? */
83 strncpy (buf
, dptr
, i
);
88 cptr
= strchr (dptr
, 'd');
93 time
+= atoi (dptr
) * 60 * 60 * 24;
97 cptr
= strchr (dptr
, 'h');
102 time
+= atoi (dptr
) * 60 * 60;
106 cptr
= strchr (dptr
, 'm');
111 time
+= atoi (dptr
) * 60;
115 cptr
= strchr (dptr
, 's');
125 searchaccess (char *str
, unsigned int access
)
127 char buf
[strlen (str
) + 1];
129 unsigned int result
= access
;
133 cptr
= strstr (str
, "access=");
137 cptr
+= 7; /* points to the begin of the access string */
139 while (cptr
[i
] != '\0' && cptr
[i
] != ':')
141 if (i
== 0) /* only "access=" ? */
144 strncpy (buf
, cptr
, i
);
149 if (*cptr
== ',') /* Fix for stupid Solaris scripts */
151 while (*cptr
!= '\0')
171 cptr
++; /* Remove "-" from beginning */
172 while (*cptr
!= '\0' && *cptr
!= ',')
178 result
= result
& ~(NIS_READ_ACC
<< 24);
180 result
= result
& ~(NIS_READ_ACC
<< 16);
182 result
= result
& ~(NIS_READ_ACC
<< 8);
184 result
= result
& ~(NIS_READ_ACC
);
188 result
= result
& ~(NIS_MODIFY_ACC
<< 24);
190 result
= result
& ~(NIS_MODIFY_ACC
<< 16);
192 result
= result
& ~(NIS_MODIFY_ACC
<< 8);
194 result
= result
& ~(NIS_MODIFY_ACC
);
198 result
= result
& ~(NIS_CREATE_ACC
<< 24);
200 result
= result
& ~(NIS_CREATE_ACC
<< 16);
202 result
= result
& ~(NIS_CREATE_ACC
<< 8);
204 result
= result
& ~(NIS_CREATE_ACC
);
208 result
= result
& ~(NIS_DESTROY_ACC
<< 24);
210 result
= result
& ~(NIS_DESTROY_ACC
<< 16);
212 result
= result
& ~(NIS_DESTROY_ACC
<< 8);
214 result
= result
& ~(NIS_DESTROY_ACC
);
224 cptr
++; /* Remove "+" from beginning */
225 while (*cptr
!= '\0' && *cptr
!= ',')
231 result
= result
| (NIS_READ_ACC
<< 24);
233 result
= result
| (NIS_READ_ACC
<< 16);
235 result
= result
| (NIS_READ_ACC
<< 8);
237 result
= result
| (NIS_READ_ACC
);
241 result
= result
| (NIS_MODIFY_ACC
<< 24);
243 result
= result
| (NIS_MODIFY_ACC
<< 16);
245 result
= result
| (NIS_MODIFY_ACC
<< 8);
247 result
= result
| (NIS_MODIFY_ACC
);
251 result
= result
| (NIS_CREATE_ACC
<< 24);
253 result
= result
| (NIS_CREATE_ACC
<< 16);
255 result
= result
| (NIS_CREATE_ACC
<< 8);
257 result
= result
| (NIS_CREATE_ACC
);
261 result
= result
| (NIS_DESTROY_ACC
<< 24);
263 result
= result
| (NIS_DESTROY_ACC
<< 16);
265 result
= result
| (NIS_DESTROY_ACC
<< 8);
267 result
= result
| (NIS_DESTROY_ACC
);
277 cptr
++; /* Remove "=" from beginning */
280 result
= result
& ~((NIS_READ_ACC
+ NIS_MODIFY_ACC
+
281 NIS_CREATE_ACC
+ NIS_DESTROY_ACC
) << 24);
284 result
= result
& ~((NIS_READ_ACC
+ NIS_MODIFY_ACC
+
285 NIS_CREATE_ACC
+ NIS_DESTROY_ACC
) << 16);
287 result
= result
& ~((NIS_READ_ACC
+ NIS_MODIFY_ACC
+
288 NIS_CREATE_ACC
+ NIS_DESTROY_ACC
) << 8);
290 result
= result
& ~(NIS_READ_ACC
+ NIS_MODIFY_ACC
+
291 NIS_CREATE_ACC
+ NIS_DESTROY_ACC
);
292 while (*cptr
!= '\0' && *cptr
!= ',')
298 result
= result
| (NIS_READ_ACC
<< 24);
300 result
= result
| (NIS_READ_ACC
<< 16);
302 result
= result
| (NIS_READ_ACC
<< 8);
304 result
= result
| (NIS_READ_ACC
);
308 result
= result
| (NIS_MODIFY_ACC
<< 24);
310 result
= result
| (NIS_MODIFY_ACC
<< 16);
312 result
= result
| (NIS_MODIFY_ACC
<< 8);
314 result
= result
| (NIS_MODIFY_ACC
);
318 result
= result
| (NIS_CREATE_ACC
<< 24);
320 result
= result
| (NIS_CREATE_ACC
<< 16);
322 result
= result
| (NIS_CREATE_ACC
<< 8);
324 result
= result
| (NIS_CREATE_ACC
);
328 result
= result
| (NIS_DESTROY_ACC
<< 24);
330 result
= result
| (NIS_DESTROY_ACC
<< 16);
332 result
= result
| (NIS_DESTROY_ACC
<< 8);
334 result
= result
| (NIS_DESTROY_ACC
);
337 return result
= (~0U);
344 return result
= (~0U);
355 __nis_default_owner (char *defaults
)
357 char *default_owner
= NULL
;
359 char *cptr
= defaults
;
361 cptr
= getenv ("NIS_DEFAULTS");
365 char *dptr
= strstr (cptr
, "owner=");
368 char *p
= searchowner (dptr
);
371 default_owner
= strdupa (p
);
376 return strdup (default_owner
?: nis_local_principal ());
378 libnsl_hidden_def (__nis_default_owner
)
382 __nis_default_group (char *defaults
)
384 char *default_group
= NULL
;
386 char *cptr
= defaults
;
388 cptr
= getenv ("NIS_DEFAULTS");
392 char *dptr
= strstr (cptr
, "group=");
395 char *p
= searchgroup (dptr
);
398 default_group
= strdupa (p
);
403 return strdup (default_group
?: nis_local_group ());
405 libnsl_hidden_def (__nis_default_group
)
409 __nis_default_ttl (char *defaults
)
413 if (defaults
!= NULL
)
415 dptr
= strstr (defaults
, "ttl=");
417 return searchttl (defaults
);
420 cptr
= getenv ("NIS_DEFAULTS");
424 dptr
= strstr (cptr
, "ttl=");
428 return searchttl (cptr
);
431 /* Default access rights are ----rmcdr---r---, but we could change
432 this with the NIS_DEFAULTS variable. */
434 __nis_default_access (char *param
, unsigned int defaults
)
440 result
= 0 | OWNER_DEFAULT
| GROUP_DEFAULT
| WORLD_DEFAULT
;
444 if (param
!= NULL
&& strstr (param
, "access=") != NULL
)
445 result
= searchaccess (param
, result
);
448 cptr
= getenv ("NIS_DEFAULTS");
449 if (cptr
!= NULL
&& strstr (cptr
, "access=") != NULL
)
450 result
= searchaccess (cptr
, result
);
455 libnsl_hidden_def (__nis_default_access
)