1 /* Copyright (c) 1997 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 Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 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 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
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
);
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
);
95 cptr
= strchr (dptr
, 'd');
100 time
+= atoi (dptr
) * 60 * 60 * 24;
104 cptr
= strchr (dptr
, 'h');
109 time
+= atoi (dptr
) * 60 * 60;
113 cptr
= strchr (dptr
, 'm');
118 time
+= atoi (dptr
) * 60;
122 cptr
= strchr (dptr
, 's');
132 searchaccess (char *str
, u_long access
)
134 char buf
[NIS_MAXNAMELEN
];
136 u_long result
= access
;
140 cptr
= strstr (str
, "access=");
144 cptr
+= 7; /* points to the begin of the access string */
146 while (cptr
[i
] != '\0' && cptr
[i
] != ':')
148 if (i
== 0) /* only "access=" ? */
151 strncpy (buf
, cptr
, i
);
155 while (*cptr
!= '\0')
175 cptr
++; /* Remove "=" from beginning */
176 while (*cptr
!= '\0' && *cptr
!= ',')
182 result
= result
& ~(NIS_READ_ACC
<< 24);
184 result
= result
& ~(NIS_READ_ACC
<< 16);
186 result
= result
& ~(NIS_READ_ACC
<< 8);
188 result
= result
& ~(NIS_READ_ACC
);
192 result
= result
& ~(NIS_MODIFY_ACC
<< 24);
194 result
= result
& ~(NIS_MODIFY_ACC
<< 16);
196 result
= result
& ~(NIS_MODIFY_ACC
<< 8);
198 result
= result
& ~(NIS_MODIFY_ACC
);
202 result
= result
& ~(NIS_CREATE_ACC
<< 24);
204 result
= result
& ~(NIS_CREATE_ACC
<< 16);
206 result
= result
& ~(NIS_CREATE_ACC
<< 8);
208 result
= result
& ~(NIS_CREATE_ACC
);
212 result
= result
& ~(NIS_DESTROY_ACC
<< 24);
214 result
= result
& ~(NIS_DESTROY_ACC
<< 16);
216 result
= result
& ~(NIS_DESTROY_ACC
<< 8);
218 result
= result
& ~(NIS_DESTROY_ACC
);
228 cptr
++; /* Remove "=" from beginning */
229 while (*cptr
!= '\0' && *cptr
!= ',')
235 result
= result
| (NIS_READ_ACC
<< 24);
237 result
= result
| (NIS_READ_ACC
<< 16);
239 result
= result
| (NIS_READ_ACC
<< 8);
241 result
= result
| (NIS_READ_ACC
);
245 result
= result
| (NIS_MODIFY_ACC
<< 24);
247 result
= result
| (NIS_MODIFY_ACC
<< 16);
249 result
= result
| (NIS_MODIFY_ACC
<< 8);
251 result
= result
| (NIS_MODIFY_ACC
);
255 result
= result
| (NIS_CREATE_ACC
<< 24);
257 result
= result
| (NIS_CREATE_ACC
<< 16);
259 result
= result
| (NIS_CREATE_ACC
<< 8);
261 result
= result
| (NIS_CREATE_ACC
);
265 result
= result
| (NIS_DESTROY_ACC
<< 24);
267 result
= result
| (NIS_DESTROY_ACC
<< 16);
269 result
= result
| (NIS_DESTROY_ACC
<< 8);
271 result
= result
| (NIS_DESTROY_ACC
);
281 cptr
++; /* Remove "=" from beginning */
284 result
= result
& ~((NIS_READ_ACC
+ NIS_MODIFY_ACC
+
285 NIS_CREATE_ACC
+ NIS_DESTROY_ACC
) << 24);
288 result
= result
& ~((NIS_READ_ACC
+ NIS_MODIFY_ACC
+
289 NIS_CREATE_ACC
+ NIS_DESTROY_ACC
) << 16);
291 result
= result
& ~((NIS_READ_ACC
+ NIS_MODIFY_ACC
+
292 NIS_CREATE_ACC
+ NIS_DESTROY_ACC
) << 8);
294 result
= result
& ~(NIS_READ_ACC
+ NIS_MODIFY_ACC
+
295 NIS_CREATE_ACC
+ NIS_DESTROY_ACC
);
296 while (*cptr
!= '\0' && *cptr
!= ',')
302 result
= result
| (NIS_READ_ACC
<< 24);
304 result
= result
| (NIS_READ_ACC
<< 16);
306 result
= result
| (NIS_READ_ACC
<< 8);
308 result
= result
| (NIS_READ_ACC
);
312 result
= result
| (NIS_MODIFY_ACC
<< 24);
314 result
= result
| (NIS_MODIFY_ACC
<< 16);
316 result
= result
| (NIS_MODIFY_ACC
<< 8);
318 result
= result
| (NIS_MODIFY_ACC
);
322 result
= result
| (NIS_CREATE_ACC
<< 24);
324 result
= result
| (NIS_CREATE_ACC
<< 16);
326 result
= result
| (NIS_CREATE_ACC
<< 8);
328 result
= result
| (NIS_CREATE_ACC
);
332 result
= result
| (NIS_DESTROY_ACC
<< 24);
334 result
= result
| (NIS_DESTROY_ACC
<< 16);
336 result
= result
| (NIS_DESTROY_ACC
<< 8);
338 result
= result
| (NIS_DESTROY_ACC
);
341 return result
= ULONG_MAX
;
348 return result
= ULONG_MAX
;
357 __nis_default_owner (char *defaults
)
359 char default_owner
[NIS_MAXNAMELEN
];
362 strcpy (default_owner
, nis_local_principal ());
364 if (defaults
!= NULL
)
366 dptr
= strstr (defaults
, "owner=");
369 char *p
= searchowner (defaults
);
370 strcpy (default_owner
, p
);
376 cptr
= getenv ("NIS_DEFAULTS");
379 dptr
= strstr (cptr
, "owner=");
382 char *p
= searchowner (cptr
);
383 strcpy (default_owner
, p
);
389 return strdup (default_owner
);
393 __nis_default_group (char *defaults
)
395 char default_group
[NIS_MAXNAMELEN
];
398 strcpy (default_group
, nis_local_group ());
400 if (defaults
!= NULL
)
402 dptr
= strstr (defaults
, "group=");
405 char *p
= searchgroup (defaults
);
406 strcpy (default_group
, p
);
412 cptr
= getenv ("NIS_DEFAULTS");
415 dptr
= strstr (cptr
, "group=");
418 char *p
= searchgroup (cptr
);
419 strcpy (default_group
, p
);
425 return strdup (default_group
);
429 __nis_default_ttl (char *defaults
)
433 if (defaults
!= NULL
)
435 dptr
= strstr (defaults
, "ttl=");
437 return searchttl (defaults
);
440 cptr
= getenv ("NIS_DEFAULTS");
444 dptr
= strstr (cptr
, "ttl=");
448 return searchttl (cptr
);
451 /* Default access rights are ----rmcdr---r---, but we could change
452 this with the NIS_DEFAULTS variable. */
454 __nis_default_access (char *param
, u_long defaults
)
460 result
= 0 | OWNER_DEFAULT
| GROUP_DEFAULT
| WORLD_DEFAULT
;
464 if (param
!= NULL
&& strstr (param
, "access=") != NULL
)
465 result
= searchaccess (param
, result
);
468 cptr
= getenv ("NIS_DEFAULTS");
469 if (cptr
!= NULL
&& strstr (cptr
, "access=") != NULL
)
470 result
= searchaccess (getenv ("NIS_DEFAULTS"), result
);