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. */
22 #include <rpcsvc/nis.h>
23 #include <rpcsvc/nislib.h>
26 nis_leaf_of (const_nis_name name)
28 static char result[NIS_MAXNAMELEN + 1];
30 return nis_leaf_of_r (name, result, NIS_MAXNAMELEN);
34 nis_leaf_of_r (const_nis_name name, char *buffer, size_t buflen)
40 while (name[i] != '.' && name[i] != '\0')
51 if ((size_t)i >= buflen)
56 strncpy (buffer, name, i);
64 nis_name_of (const_nis_name name)
66 static char result[NIS_MAXNAMELEN + 1];
68 return nis_name_of_r (name, result, NIS_MAXNAMELEN);
72 nis_name_of_r (const_nis_name name, char *buffer, size_t buflen)
77 local_domain = nis_local_directory ();
79 diff = strlen (name) - strlen (local_domain);
83 if (strcmp (&name[diff], local_domain) != 0)
86 if ((size_t) diff >= buflen)
91 memcpy (buffer, name, diff - 1);
92 buffer[diff - 1] = '\0';
101 count_dots (const_nis_name str)
106 for (i = 0; i < strlen (str); ++i)
114 nis_getnames (const_nis_name name)
116 nis_name *getnames = NULL;
117 char local_domain[NIS_MAXNAMELEN + 1];
119 int count, pos, have_point;
121 strncpy (local_domain, nis_local_directory (), NIS_MAXNAMELEN);
122 local_domain[NIS_MAXNAMELEN] = '\0';
125 if ((getnames = malloc ((count + 1) * sizeof (char *))) == NULL)
128 /* Do we have a fully qualified NIS+ name ? If yes, give it back */
129 if (name[strlen (name) - 1] == '.')
131 if ((getnames[0] = strdup (name)) == NULL)
141 /* Get the search path, where we have to search "name" */
142 path = getenv ("NIS_PATH");
144 path = strdupa ("$");
146 path = strdupa (path);
148 have_point = (strchr (name, '.') != NULL);
152 cp = strtok (path, ":");
155 if (strcmp (cp, "$") == 0)
157 char *cptr = local_domain;
160 while ((have_point && *cptr != '\0') || (count_dots (cptr) >= 2))
165 getnames = realloc (getnames, (count + 1) * sizeof (char *));
167 tmp = malloc (strlen (cptr) + strlen (local_domain) +
173 tmp = stpcpy (tmp, name);
182 while (*cptr != '.' && *cptr != '\0')
184 if (cptr[0] != '\0' && cptr[1] != '\0')
185 /* If we have only ".", don't remove the "." */
193 if (cp[strlen (cp) - 1] == '$')
197 tmp = malloc (strlen (cp) + strlen (local_domain) +
202 p = stpcpy (tmp, name);
208 stpcpy (p, local_domain);
214 tmp = malloc (strlen (cp) + strlen (name) + 2);
218 p = stpcpy (tmp, name);
226 getnames = realloc (getnames, (count + 1) * sizeof (char *));
227 if (getnames == NULL)
233 cp = strtok (NULL, ":");
236 getnames[pos] = NULL;
242 nis_freenames (nis_name *names)
246 while (names[i] != NULL)
256 nis_dir_cmp (const_nis_name n1, const_nis_name n2)
265 if (strcmp (n1, n2) == 0)
268 return NOT_SEQUENTIAL;
273 if (n2[len2 - len1 - 1] != '.')
274 return NOT_SEQUENTIAL;
275 else if (strcmp (&n2[len2 - len1], n1) == 0)
278 return NOT_SEQUENTIAL;
282 if (n1[len1 - len2 - 1] != '.')
283 return NOT_SEQUENTIAL;
284 else if (strcmp (&n1[len1 - len2], n2) == 0)
287 return NOT_SEQUENTIAL;
293 nis_destroy_object (nis_object *obj)
295 nis_free_object (obj);