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 return strncpy (default_group
, cptr
, i
);
55 searchowner (char *str
)
57 static char default_owner
[NIS_MAXNAMELEN
];
61 cptr
= strstr (str
, "owner=");
65 cptr
+= 6; /* points to the begin of the owner string */
67 while (cptr
[i
] != '\0' && cptr
[i
] != ':')
69 if (i
== 0) /* only "owner=" ? */
72 return strncpy (default_owner
, cptr
, i
);
83 dptr
= strstr (str
, "ttl=");
84 if (dptr
== NULL
) /* should (could) not happen */
87 dptr
+= 4; /* points to the begin of the new ttl */
89 while (dptr
[i
] != '\0' && dptr
[i
] != ':')
91 if (i
== 0) /* only "ttl=" ? */
94 strncpy (buf
, dptr
, i
);
98 cptr
= strchr (dptr
, 'd');
103 time
+= atoi (dptr
) * 60 * 60 * 24;
107 cptr
= strchr (dptr
, 'h');
112 time
+= atoi (dptr
) * 60 * 60;
116 cptr
= strchr (dptr
, 'm');
121 time
+= atoi (dptr
) * 60;
125 cptr
= strchr (dptr
, 's');
135 searchaccess (char *str
, u_long access
)
137 static char buf
[NIS_MAXNAMELEN
];
143 cptr
= strstr (str
, "access=");
147 cptr
+= 7; /* points to the begin of the access string */
149 while (cptr
[i
] != '\0' && cptr
[i
] != ':')
151 if (i
== 0) /* only "access=" ? */
154 strncpy (buf
, cptr
, i
);
156 result
= n
= o
= g
= w
= 0;
158 while (*cptr
!= '\0')
178 cptr
++; /* Remove "=" from beginning */
179 while (*cptr
!= '\0' && *cptr
!= ',')
185 result
= result
& ~(NIS_READ_ACC
<< 24);
187 result
= result
& ~(NIS_READ_ACC
<< 16);
189 result
= result
& ~(NIS_READ_ACC
<< 8);
191 result
= result
& ~(NIS_READ_ACC
);
195 result
= result
& ~(NIS_MODIFY_ACC
<< 24);
197 result
= result
& ~(NIS_MODIFY_ACC
<< 16);
199 result
= result
& ~(NIS_MODIFY_ACC
<< 8);
201 result
= result
& ~(NIS_MODIFY_ACC
);
205 result
= result
& ~(NIS_CREATE_ACC
<< 24);
207 result
= result
& ~(NIS_CREATE_ACC
<< 16);
209 result
= result
& ~(NIS_CREATE_ACC
<< 8);
211 result
= result
& ~(NIS_CREATE_ACC
);
215 result
= result
& ~(NIS_DESTROY_ACC
<< 24);
217 result
= result
& ~(NIS_DESTROY_ACC
<< 16);
219 result
= result
& ~(NIS_DESTROY_ACC
<< 8);
221 result
= result
& ~(NIS_DESTROY_ACC
);
224 fprintf (stderr
, "Parse error in \"%s\"\n", buf
);
231 cptr
++; /* Remove "=" from beginning */
232 while (*cptr
!= '\0' && *cptr
!= ',')
238 result
= result
| (NIS_READ_ACC
<< 24);
240 result
= result
| (NIS_READ_ACC
<< 16);
242 result
= result
| (NIS_READ_ACC
<< 8);
244 result
= result
| (NIS_READ_ACC
);
248 result
= result
| (NIS_MODIFY_ACC
<< 24);
250 result
= result
| (NIS_MODIFY_ACC
<< 16);
252 result
= result
| (NIS_MODIFY_ACC
<< 8);
254 result
= result
| (NIS_MODIFY_ACC
);
258 result
= result
| (NIS_CREATE_ACC
<< 24);
260 result
= result
| (NIS_CREATE_ACC
<< 16);
262 result
= result
| (NIS_CREATE_ACC
<< 8);
264 result
= result
| (NIS_CREATE_ACC
);
268 result
= result
| (NIS_DESTROY_ACC
<< 24);
270 result
= result
| (NIS_DESTROY_ACC
<< 16);
272 result
= result
| (NIS_DESTROY_ACC
<< 8);
274 result
= result
| (NIS_DESTROY_ACC
);
277 fprintf (stderr
, "Parse error in \"%s\"\n", buf
);
284 cptr
++; /* Remove "=" from beginning */
287 result
= result
& ~((NIS_READ_ACC
+ NIS_MODIFY_ACC
+
288 NIS_CREATE_ACC
+ NIS_DESTROY_ACC
) << 24);
291 result
= result
& ~((NIS_READ_ACC
+ NIS_MODIFY_ACC
+
292 NIS_CREATE_ACC
+ NIS_DESTROY_ACC
) << 16);
294 result
= result
& ~((NIS_READ_ACC
+ NIS_MODIFY_ACC
+
295 NIS_CREATE_ACC
+ NIS_DESTROY_ACC
) << 8);
297 result
= result
& ~(NIS_READ_ACC
+ NIS_MODIFY_ACC
+
298 NIS_CREATE_ACC
+ NIS_DESTROY_ACC
);
299 while (*cptr
!= '\0' && *cptr
!= ',')
305 result
= result
| (NIS_READ_ACC
<< 24);
307 result
= result
| (NIS_READ_ACC
<< 16);
309 result
= result
| (NIS_READ_ACC
<< 8);
311 result
= result
| (NIS_READ_ACC
);
315 result
= result
| (NIS_MODIFY_ACC
<< 24);
317 result
= result
| (NIS_MODIFY_ACC
<< 16);
319 result
= result
| (NIS_MODIFY_ACC
<< 8);
321 result
= result
| (NIS_MODIFY_ACC
);
325 result
= result
| (NIS_CREATE_ACC
<< 24);
327 result
= result
| (NIS_CREATE_ACC
<< 16);
329 result
= result
| (NIS_CREATE_ACC
<< 8);
331 result
= result
| (NIS_CREATE_ACC
);
335 result
= result
| (NIS_DESTROY_ACC
<< 24);
337 result
= result
| (NIS_DESTROY_ACC
<< 16);
339 result
= result
| (NIS_DESTROY_ACC
<< 8);
341 result
= result
| (NIS_DESTROY_ACC
);
344 fprintf (stderr
, "Parse error in \"%s\"\n", buf
);
351 fprintf (stderr
, "Parse error in \"%s\"\n", buf
);
361 __nis_default_owner (char *defaults
)
363 static char default_owner
[NIS_MAXNAMELEN
];
366 strcpy (default_owner
, nis_local_principal ());
368 if (defaults
!= NULL
)
370 dptr
= strstr (defaults
, "owner=");
372 strcpy (default_owner
, searchowner (defaults
));
376 cptr
= getenv ("NIS_DEFAULTS");
379 dptr
= strstr (cptr
, "owner=");
381 strcpy (default_owner
, searchowner (cptr
));
385 return default_owner
;
389 __nis_default_group (char *defaults
)
391 static char default_group
[NIS_MAXNAMELEN
];
394 strcpy (default_group
, nis_local_group ());
396 if (defaults
!= NULL
)
398 dptr
= strstr (defaults
, "group=");
400 strcpy (default_group
, searchgroup (defaults
));
404 cptr
= getenv ("NIS_DEFAULTS");
407 dptr
= strstr (cptr
, "group=");
409 strcpy (default_group
, searchgroup (cptr
));
413 return default_group
;
417 __nis_default_ttl (char *defaults
)
421 if (defaults
!= NULL
)
423 dptr
= strstr (defaults
, "ttl=");
425 return searchttl (defaults
);
428 cptr
= getenv ("NIS_DEFAULTS");
432 dptr
= strstr (cptr
, "ttl=");
436 return searchttl (cptr
);
439 /* Default access rights are ----rmcdr---r---, but we could change
440 this with the NIS_DEFAULTS variable. */
442 __nis_default_access (char *param
, u_long defaults
)
448 result
= 0 | OWNER_DEFAULT
| GROUP_DEFAULT
| WORLD_DEFAULT
;
452 if (param
!= NULL
&& strstr (param
, "access=") != NULL
)
453 result
= searchaccess (param
, result
);
456 cptr
= getenv ("NIS_DEFAULTS");
457 if (cptr
!= NULL
&& strstr (cptr
, "access=") != NULL
)
458 result
= searchaccess (getenv ("NIS_DEFAULTS"), result
);