1 /* Copyright (c) 1997-2013 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, see
17 <http://www.gnu.org/licenses/>. */
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 searchXYX (char *str
, const char *what
)
35 assert (strlen (what
) == 6);
36 assert (strncmp (str
, what
, 6) == 0);
37 str
+= 6; /* Points to the begin of the parameters. */
40 while (str
[i
] != '\0' && str
[i
] != ':')
42 if (i
== 0) /* only "<WHAT>=" ? */
45 return strndup (str
, i
);
50 searchgroup (char *str
)
52 return searchXYX (str
, "group=");
57 searchowner (char *str
)
59 return searchXYX (str
, "owner=");
66 char buf
[strlen (str
) + 1];
71 dptr
= strstr (str
, "ttl=");
72 if (dptr
== NULL
) /* should (could) not happen */
75 dptr
+= 4; /* points to the begin of the new ttl */
77 while (dptr
[i
] != '\0' && dptr
[i
] != ':')
79 if (i
== 0) /* only "ttl=" ? */
82 strncpy (buf
, dptr
, i
);
87 cptr
= strchr (dptr
, 'd');
92 time
+= atoi (dptr
) * 60 * 60 * 24;
96 cptr
= strchr (dptr
, 'h');
101 time
+= atoi (dptr
) * 60 * 60;
105 cptr
= strchr (dptr
, 'm');
110 time
+= atoi (dptr
) * 60;
114 cptr
= strchr (dptr
, 's');
124 searchaccess (char *str
, unsigned int access
)
126 char buf
[strlen (str
) + 1];
128 unsigned int result
= access
;
132 cptr
= strstr (str
, "access=");
136 cptr
+= 7; /* points to the begin of the access string */
138 while (cptr
[i
] != '\0' && cptr
[i
] != ':')
140 if (i
== 0) /* only "access=" ? */
143 strncpy (buf
, cptr
, i
);
148 if (*cptr
== ',') /* Fix for stupid Solaris scripts */
150 while (*cptr
!= '\0')
170 cptr
++; /* Remove "-" from beginning */
171 while (*cptr
!= '\0' && *cptr
!= ',')
177 result
= result
& ~(NIS_READ_ACC
<< 24);
179 result
= result
& ~(NIS_READ_ACC
<< 16);
181 result
= result
& ~(NIS_READ_ACC
<< 8);
183 result
= result
& ~(NIS_READ_ACC
);
187 result
= result
& ~(NIS_MODIFY_ACC
<< 24);
189 result
= result
& ~(NIS_MODIFY_ACC
<< 16);
191 result
= result
& ~(NIS_MODIFY_ACC
<< 8);
193 result
= result
& ~(NIS_MODIFY_ACC
);
197 result
= result
& ~(NIS_CREATE_ACC
<< 24);
199 result
= result
& ~(NIS_CREATE_ACC
<< 16);
201 result
= result
& ~(NIS_CREATE_ACC
<< 8);
203 result
= result
& ~(NIS_CREATE_ACC
);
207 result
= result
& ~(NIS_DESTROY_ACC
<< 24);
209 result
= result
& ~(NIS_DESTROY_ACC
<< 16);
211 result
= result
& ~(NIS_DESTROY_ACC
<< 8);
213 result
= result
& ~(NIS_DESTROY_ACC
);
223 cptr
++; /* Remove "+" from beginning */
224 while (*cptr
!= '\0' && *cptr
!= ',')
230 result
= result
| (NIS_READ_ACC
<< 24);
232 result
= result
| (NIS_READ_ACC
<< 16);
234 result
= result
| (NIS_READ_ACC
<< 8);
236 result
= result
| (NIS_READ_ACC
);
240 result
= result
| (NIS_MODIFY_ACC
<< 24);
242 result
= result
| (NIS_MODIFY_ACC
<< 16);
244 result
= result
| (NIS_MODIFY_ACC
<< 8);
246 result
= result
| (NIS_MODIFY_ACC
);
250 result
= result
| (NIS_CREATE_ACC
<< 24);
252 result
= result
| (NIS_CREATE_ACC
<< 16);
254 result
= result
| (NIS_CREATE_ACC
<< 8);
256 result
= result
| (NIS_CREATE_ACC
);
260 result
= result
| (NIS_DESTROY_ACC
<< 24);
262 result
= result
| (NIS_DESTROY_ACC
<< 16);
264 result
= result
| (NIS_DESTROY_ACC
<< 8);
266 result
= result
| (NIS_DESTROY_ACC
);
276 cptr
++; /* Remove "=" from beginning */
279 result
= result
& ~((NIS_READ_ACC
+ NIS_MODIFY_ACC
+
280 NIS_CREATE_ACC
+ NIS_DESTROY_ACC
) << 24);
283 result
= result
& ~((NIS_READ_ACC
+ NIS_MODIFY_ACC
+
284 NIS_CREATE_ACC
+ NIS_DESTROY_ACC
) << 16);
286 result
= result
& ~((NIS_READ_ACC
+ NIS_MODIFY_ACC
+
287 NIS_CREATE_ACC
+ NIS_DESTROY_ACC
) << 8);
289 result
= result
& ~(NIS_READ_ACC
+ NIS_MODIFY_ACC
+
290 NIS_CREATE_ACC
+ NIS_DESTROY_ACC
);
291 while (*cptr
!= '\0' && *cptr
!= ',')
297 result
= result
| (NIS_READ_ACC
<< 24);
299 result
= result
| (NIS_READ_ACC
<< 16);
301 result
= result
| (NIS_READ_ACC
<< 8);
303 result
= result
| (NIS_READ_ACC
);
307 result
= result
| (NIS_MODIFY_ACC
<< 24);
309 result
= result
| (NIS_MODIFY_ACC
<< 16);
311 result
= result
| (NIS_MODIFY_ACC
<< 8);
313 result
= result
| (NIS_MODIFY_ACC
);
317 result
= result
| (NIS_CREATE_ACC
<< 24);
319 result
= result
| (NIS_CREATE_ACC
<< 16);
321 result
= result
| (NIS_CREATE_ACC
<< 8);
323 result
= result
| (NIS_CREATE_ACC
);
327 result
= result
| (NIS_DESTROY_ACC
<< 24);
329 result
= result
| (NIS_DESTROY_ACC
<< 16);
331 result
= result
| (NIS_DESTROY_ACC
<< 8);
333 result
= result
| (NIS_DESTROY_ACC
);
336 return result
= (~0U);
343 return result
= (~0U);
354 __nis_default_owner (char *defaults
)
356 char *default_owner
= NULL
;
358 char *cptr
= defaults
;
360 cptr
= getenv ("NIS_DEFAULTS");
364 char *dptr
= strstr (cptr
, "owner=");
367 char *p
= searchowner (dptr
);
370 default_owner
= strdupa (p
);
375 return strdup (default_owner
?: nis_local_principal ());
377 libnsl_hidden_def (__nis_default_owner
)
381 __nis_default_group (char *defaults
)
383 char *default_group
= NULL
;
385 char *cptr
= defaults
;
387 cptr
= getenv ("NIS_DEFAULTS");
391 char *dptr
= strstr (cptr
, "group=");
394 char *p
= searchgroup (dptr
);
397 default_group
= strdupa (p
);
402 return strdup (default_group
?: nis_local_group ());
404 libnsl_hidden_def (__nis_default_group
)
408 __nis_default_ttl (char *defaults
)
412 if (defaults
!= NULL
)
414 dptr
= strstr (defaults
, "ttl=");
416 return searchttl (defaults
);
419 cptr
= getenv ("NIS_DEFAULTS");
423 dptr
= strstr (cptr
, "ttl=");
427 return searchttl (cptr
);
430 /* Default access rights are ----rmcdr---r---, but we could change
431 this with the NIS_DEFAULTS variable. */
433 __nis_default_access (char *param
, unsigned int defaults
)
439 result
= 0 | OWNER_DEFAULT
| GROUP_DEFAULT
| WORLD_DEFAULT
;
443 if (param
!= NULL
&& strstr (param
, "access=") != NULL
)
444 result
= searchaccess (param
, result
);
447 cptr
= getenv ("NIS_DEFAULTS");
448 if (cptr
!= NULL
&& strstr (cptr
, "access=") != NULL
)
449 result
= searchaccess (cptr
, result
);
454 libnsl_hidden_def (__nis_default_access
)