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>
26 #include <rpcsvc/nislib.h>
28 #define DEFAULT_TTL 43200
31 ** Some functions for parsing the -D param and NIS_DEFAULTS Environ
34 searchgroup (char *str
)
36 static char default_group
[NIS_MAXNAMELEN
];
40 cptr
= strstr (str
, "group=");
44 cptr
+= 6; /* points to the begin of the group string */
46 while (cptr
[i
] != '\0' && cptr
[i
] != ':')
48 if (i
== 0) /* only "group=" ? */
51 strncpy (default_group
, cptr
, i
);
57 searchowner (char *str
)
59 static char default_owner
[NIS_MAXNAMELEN
];
63 cptr
= strstr (str
, "owner=");
67 cptr
+= 6; /* points to the begin of the owner string */
69 while (cptr
[i
] != '\0' && cptr
[i
] != ':')
71 if (i
== 0) /* only "owner=" ? */
74 strncpy (default_owner
, cptr
, i
);
87 dptr
= strstr (str
, "ttl=");
88 if (dptr
== NULL
) /* should (could) not happen */
91 dptr
+= 4; /* points to the begin of the new ttl */
93 while (dptr
[i
] != '\0' && dptr
[i
] != ':')
95 if (i
== 0) /* only "ttl=" ? */
98 strncpy (buf
, dptr
, i
);
102 cptr
= strchr (dptr
, 'd');
107 time
+= atoi (dptr
) * 60 * 60 * 24;
111 cptr
= strchr (dptr
, 'h');
116 time
+= atoi (dptr
) * 60 * 60;
120 cptr
= strchr (dptr
, 'm');
125 time
+= atoi (dptr
) * 60;
129 cptr
= strchr (dptr
, 's');
139 searchaccess (char *str
, u_long access
)
141 static char buf
[NIS_MAXNAMELEN
];
147 cptr
= strstr (str
, "access=");
151 cptr
+= 7; /* points to the begin of the access string */
153 while (cptr
[i
] != '\0' && cptr
[i
] != ':')
155 if (i
== 0) /* only "access=" ? */
158 strncpy (buf
, cptr
, i
);
160 result
= n
= o
= g
= w
= 0;
162 while (*cptr
!= '\0')
182 cptr
++; /* Remove "=" from beginning */
183 while (*cptr
!= '\0' && *cptr
!= ',')
189 result
= result
& ~(NIS_READ_ACC
<< 24);
191 result
= result
& ~(NIS_READ_ACC
<< 16);
193 result
= result
& ~(NIS_READ_ACC
<< 8);
195 result
= result
& ~(NIS_READ_ACC
);
199 result
= result
& ~(NIS_MODIFY_ACC
<< 24);
201 result
= result
& ~(NIS_MODIFY_ACC
<< 16);
203 result
= result
& ~(NIS_MODIFY_ACC
<< 8);
205 result
= result
& ~(NIS_MODIFY_ACC
);
209 result
= result
& ~(NIS_CREATE_ACC
<< 24);
211 result
= result
& ~(NIS_CREATE_ACC
<< 16);
213 result
= result
& ~(NIS_CREATE_ACC
<< 8);
215 result
= result
& ~(NIS_CREATE_ACC
);
219 result
= result
& ~(NIS_DESTROY_ACC
<< 24);
221 result
= result
& ~(NIS_DESTROY_ACC
<< 16);
223 result
= result
& ~(NIS_DESTROY_ACC
<< 8);
225 result
= result
& ~(NIS_DESTROY_ACC
);
228 fprintf (stderr
, "Parse error in \"%s\"\n", buf
);
235 cptr
++; /* Remove "=" from beginning */
236 while (*cptr
!= '\0' && *cptr
!= ',')
242 result
= result
| (NIS_READ_ACC
<< 24);
244 result
= result
| (NIS_READ_ACC
<< 16);
246 result
= result
| (NIS_READ_ACC
<< 8);
248 result
= result
| (NIS_READ_ACC
);
252 result
= result
| (NIS_MODIFY_ACC
<< 24);
254 result
= result
| (NIS_MODIFY_ACC
<< 16);
256 result
= result
| (NIS_MODIFY_ACC
<< 8);
258 result
= result
| (NIS_MODIFY_ACC
);
262 result
= result
| (NIS_CREATE_ACC
<< 24);
264 result
= result
| (NIS_CREATE_ACC
<< 16);
266 result
= result
| (NIS_CREATE_ACC
<< 8);
268 result
= result
| (NIS_CREATE_ACC
);
272 result
= result
| (NIS_DESTROY_ACC
<< 24);
274 result
= result
| (NIS_DESTROY_ACC
<< 16);
276 result
= result
| (NIS_DESTROY_ACC
<< 8);
278 result
= result
| (NIS_DESTROY_ACC
);
281 fprintf (stderr
, "Parse error in \"%s\"\n", buf
);
288 cptr
++; /* Remove "=" from beginning */
291 result
= result
& ~((NIS_READ_ACC
+ NIS_MODIFY_ACC
+
292 NIS_CREATE_ACC
+ NIS_DESTROY_ACC
) << 24);
295 result
= result
& ~((NIS_READ_ACC
+ NIS_MODIFY_ACC
+
296 NIS_CREATE_ACC
+ NIS_DESTROY_ACC
) << 16);
298 result
= result
& ~((NIS_READ_ACC
+ NIS_MODIFY_ACC
+
299 NIS_CREATE_ACC
+ NIS_DESTROY_ACC
) << 8);
301 result
= result
& ~(NIS_READ_ACC
+ NIS_MODIFY_ACC
+
302 NIS_CREATE_ACC
+ NIS_DESTROY_ACC
);
303 while (*cptr
!= '\0' && *cptr
!= ',')
309 result
= result
| (NIS_READ_ACC
<< 24);
311 result
= result
| (NIS_READ_ACC
<< 16);
313 result
= result
| (NIS_READ_ACC
<< 8);
315 result
= result
| (NIS_READ_ACC
);
319 result
= result
| (NIS_MODIFY_ACC
<< 24);
321 result
= result
| (NIS_MODIFY_ACC
<< 16);
323 result
= result
| (NIS_MODIFY_ACC
<< 8);
325 result
= result
| (NIS_MODIFY_ACC
);
329 result
= result
| (NIS_CREATE_ACC
<< 24);
331 result
= result
| (NIS_CREATE_ACC
<< 16);
333 result
= result
| (NIS_CREATE_ACC
<< 8);
335 result
= result
| (NIS_CREATE_ACC
);
339 result
= result
| (NIS_DESTROY_ACC
<< 24);
341 result
= result
| (NIS_DESTROY_ACC
<< 16);
343 result
= result
| (NIS_DESTROY_ACC
<< 8);
345 result
= result
| (NIS_DESTROY_ACC
);
348 fprintf (stderr
, "Parse error in \"%s\"\n", buf
);
355 fprintf (stderr
, "Parse error in \"%s\"\n", buf
);
365 __nis_default_owner (char *defaults
)
367 static char default_owner
[NIS_MAXNAMELEN
];
370 strcpy (default_owner
, nis_local_principal ());
372 if (defaults
!= NULL
)
374 dptr
= strstr (defaults
, "owner=");
376 strcpy (default_owner
, searchowner (defaults
));
380 cptr
= getenv ("NIS_DEFAULTS");
383 dptr
= strstr (cptr
, "owner=");
385 strcpy (default_owner
, searchowner (cptr
));
389 return default_owner
;
393 __nis_default_group (char *defaults
)
395 static char default_group
[NIS_MAXNAMELEN
];
398 strcpy (default_group
, nis_local_group ());
400 if (defaults
!= NULL
)
402 dptr
= strstr (defaults
, "group=");
404 strcpy (default_group
, searchgroup (defaults
));
408 cptr
= getenv ("NIS_DEFAULTS");
411 dptr
= strstr (cptr
, "group=");
413 strcpy (default_group
, searchgroup (cptr
));
417 return default_group
;
421 __nis_default_ttl (char *defaults
)
425 if (defaults
!= NULL
)
427 dptr
= strstr (defaults
, "ttl=");
429 return searchttl (defaults
);
432 cptr
= getenv ("NIS_DEFAULTS");
436 dptr
= strstr (cptr
, "ttl=");
440 return searchttl (cptr
);
443 /* Default access rights are ----rmcdr---r---, but we could change
444 this with the NIS_DEFAULTS variable. */
446 __nis_default_access (char *param
, u_long defaults
)
452 result
= 0 | OWNER_DEFAULT
| GROUP_DEFAULT
| WORLD_DEFAULT
;
456 if (param
!= NULL
&& strstr (param
, "access=") != NULL
)
457 result
= searchaccess (param
, result
);
460 cptr
= getenv ("NIS_DEFAULTS");
461 if (cptr
!= NULL
&& strstr (cptr
, "access=") != NULL
)
462 result
= searchaccess (getenv ("NIS_DEFAULTS"), result
);