1 /* Copyright (c) 1997, 1998 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
23 #include <sys/types.h>
25 #include <rpcsvc/nis.h>
27 #define DEFAULT_TTL 43200
30 ** Some functions for parsing the -D param and NIS_DEFAULTS Environ
33 searchgroup (char *str
)
38 cptr
= strstr (str
, "group=");
42 cptr
+= 6; /* points to the begin of the group string */
44 while (cptr
[i
] != '\0' && cptr
[i
] != ':')
46 if (i
== 0) /* only "group=" ? */
49 return strndup (cptr
, i
);
53 searchowner (char *str
)
58 cptr
= strstr (str
, "owner=");
62 cptr
+= 6; /* points to the begin of the owner string */
64 while (cptr
[i
] != '\0' && cptr
[i
] != ':')
66 if (i
== 0) /* only "owner=" ? */
69 return strndup (cptr
, i
);
75 char buf
[strlen (str
) + 1];
80 dptr
= strstr (str
, "ttl=");
81 if (dptr
== NULL
) /* should (could) not happen */
84 dptr
+= 4; /* points to the begin of the new ttl */
86 while (dptr
[i
] != '\0' && dptr
[i
] != ':')
88 if (i
== 0) /* only "ttl=" ? */
91 strncpy (buf
, dptr
, i
);
96 cptr
= strchr (dptr
, 'd');
101 time
+= atoi (dptr
) * 60 * 60 * 24;
105 cptr
= strchr (dptr
, 'h');
110 time
+= atoi (dptr
) * 60 * 60;
114 cptr
= strchr (dptr
, 'm');
119 time
+= atoi (dptr
) * 60;
123 cptr
= strchr (dptr
, 's');
133 searchaccess (char *str
, unsigned int access
)
135 char buf
[strlen (str
) + 1];
137 unsigned int result
= access
;
141 cptr
= strstr (str
, "access=");
145 cptr
+= 7; /* points to the begin of the access string */
147 while (cptr
[i
] != '\0' && cptr
[i
] != ':')
149 if (i
== 0) /* only "access=" ? */
152 strncpy (buf
, cptr
, i
);
157 if (*cptr
== ',') /* Fix for stupid Solaris scripts */
159 while (*cptr
!= '\0')
179 cptr
++; /* Remove "-" from beginning */
180 while (*cptr
!= '\0' && *cptr
!= ',')
186 result
= result
& ~(NIS_READ_ACC
<< 24);
188 result
= result
& ~(NIS_READ_ACC
<< 16);
190 result
= result
& ~(NIS_READ_ACC
<< 8);
192 result
= result
& ~(NIS_READ_ACC
);
196 result
= result
& ~(NIS_MODIFY_ACC
<< 24);
198 result
= result
& ~(NIS_MODIFY_ACC
<< 16);
200 result
= result
& ~(NIS_MODIFY_ACC
<< 8);
202 result
= result
& ~(NIS_MODIFY_ACC
);
206 result
= result
& ~(NIS_CREATE_ACC
<< 24);
208 result
= result
& ~(NIS_CREATE_ACC
<< 16);
210 result
= result
& ~(NIS_CREATE_ACC
<< 8);
212 result
= result
& ~(NIS_CREATE_ACC
);
216 result
= result
& ~(NIS_DESTROY_ACC
<< 24);
218 result
= result
& ~(NIS_DESTROY_ACC
<< 16);
220 result
= result
& ~(NIS_DESTROY_ACC
<< 8);
222 result
= result
& ~(NIS_DESTROY_ACC
);
232 cptr
++; /* Remove "+" from beginning */
233 while (*cptr
!= '\0' && *cptr
!= ',')
239 result
= result
| (NIS_READ_ACC
<< 24);
241 result
= result
| (NIS_READ_ACC
<< 16);
243 result
= result
| (NIS_READ_ACC
<< 8);
245 result
= result
| (NIS_READ_ACC
);
249 result
= result
| (NIS_MODIFY_ACC
<< 24);
251 result
= result
| (NIS_MODIFY_ACC
<< 16);
253 result
= result
| (NIS_MODIFY_ACC
<< 8);
255 result
= result
| (NIS_MODIFY_ACC
);
259 result
= result
| (NIS_CREATE_ACC
<< 24);
261 result
= result
| (NIS_CREATE_ACC
<< 16);
263 result
= result
| (NIS_CREATE_ACC
<< 8);
265 result
= result
| (NIS_CREATE_ACC
);
269 result
= result
| (NIS_DESTROY_ACC
<< 24);
271 result
= result
| (NIS_DESTROY_ACC
<< 16);
273 result
= result
| (NIS_DESTROY_ACC
<< 8);
275 result
= result
| (NIS_DESTROY_ACC
);
285 cptr
++; /* Remove "=" from beginning */
288 result
= result
& ~((NIS_READ_ACC
+ NIS_MODIFY_ACC
+
289 NIS_CREATE_ACC
+ NIS_DESTROY_ACC
) << 24);
292 result
= result
& ~((NIS_READ_ACC
+ NIS_MODIFY_ACC
+
293 NIS_CREATE_ACC
+ NIS_DESTROY_ACC
) << 16);
295 result
= result
& ~((NIS_READ_ACC
+ NIS_MODIFY_ACC
+
296 NIS_CREATE_ACC
+ NIS_DESTROY_ACC
) << 8);
298 result
= result
& ~(NIS_READ_ACC
+ NIS_MODIFY_ACC
+
299 NIS_CREATE_ACC
+ NIS_DESTROY_ACC
);
300 while (*cptr
!= '\0' && *cptr
!= ',')
306 result
= result
| (NIS_READ_ACC
<< 24);
308 result
= result
| (NIS_READ_ACC
<< 16);
310 result
= result
| (NIS_READ_ACC
<< 8);
312 result
= result
| (NIS_READ_ACC
);
316 result
= result
| (NIS_MODIFY_ACC
<< 24);
318 result
= result
| (NIS_MODIFY_ACC
<< 16);
320 result
= result
| (NIS_MODIFY_ACC
<< 8);
322 result
= result
| (NIS_MODIFY_ACC
);
326 result
= result
| (NIS_CREATE_ACC
<< 24);
328 result
= result
| (NIS_CREATE_ACC
<< 16);
330 result
= result
| (NIS_CREATE_ACC
<< 8);
332 result
= result
| (NIS_CREATE_ACC
);
336 result
= result
| (NIS_DESTROY_ACC
<< 24);
338 result
= result
| (NIS_DESTROY_ACC
<< 16);
340 result
= result
| (NIS_DESTROY_ACC
<< 8);
342 result
= result
| (NIS_DESTROY_ACC
);
345 return result
= (~0U);
352 return result
= (~0U);
362 __nis_default_owner (char *defaults
)
364 char default_owner
[NIS_MAXNAMELEN
+ 1];
367 strcpy (default_owner
, nis_local_principal ());
369 if (defaults
!= NULL
)
371 dptr
= strstr (defaults
, "owner=");
374 char *p
= searchowner (defaults
);
375 if (strlen (p
) <= NIS_MAXNAMELEN
)
376 strcpy (default_owner
, p
);
382 cptr
= getenv ("NIS_DEFAULTS");
385 dptr
= strstr (cptr
, "owner=");
388 char *p
= searchowner (cptr
);
389 if (strlen (p
) <= NIS_MAXNAMELEN
)
390 strcpy (default_owner
, p
);
396 return strdup (default_owner
);
400 __nis_default_group (char *defaults
)
402 char default_group
[NIS_MAXNAMELEN
+ 1];
405 strcpy (default_group
, nis_local_group ());
407 if (defaults
!= NULL
)
409 dptr
= strstr (defaults
, "group=");
412 char *p
= searchgroup (defaults
);
414 if (strlen (p
) <= NIS_MAXNAMELEN
)
415 strcpy (default_group
, p
);
421 cptr
= getenv ("NIS_DEFAULTS");
424 dptr
= strstr (cptr
, "group=");
427 char *p
= searchgroup (cptr
);
429 if (strlen (p
) <= NIS_MAXNAMELEN
)
430 strcpy (default_group
, p
);
436 return strdup (default_group
);
440 __nis_default_ttl (char *defaults
)
444 if (defaults
!= NULL
)
446 dptr
= strstr (defaults
, "ttl=");
448 return searchttl (defaults
);
451 cptr
= getenv ("NIS_DEFAULTS");
455 dptr
= strstr (cptr
, "ttl=");
459 return searchttl (cptr
);
462 /* Default access rights are ----rmcdr---r---, but we could change
463 this with the NIS_DEFAULTS variable. */
465 __nis_default_access (char *param
, unsigned int defaults
)
471 result
= 0 | OWNER_DEFAULT
| GROUP_DEFAULT
| WORLD_DEFAULT
;
475 if (param
!= NULL
&& strstr (param
, "access=") != NULL
)
476 result
= searchaccess (param
, result
);
479 cptr
= getenv ("NIS_DEFAULTS");
480 if (cptr
!= NULL
&& strstr (cptr
, "access=") != NULL
)
481 result
= searchaccess (getenv ("NIS_DEFAULTS"), result
);