Update.
[glibc.git] / nis / nis_intern.c
blob91522a63120079752cc3e4f1bfd9a4ec78974612
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. */
20 #include <string.h>
21 #include <rpcsvc/nis.h>
22 #include <rpcsvc/nislib.h>
23 #include "nis_intern.h"
25 /* Nearly the same as nis_getnames, but nis_getnames stopped
26 when 2 points left */
27 nis_name *
28 __nis_expandname (const char *name)
30 nis_name *getnames = NULL;
31 char local_domain[NIS_MAXNAMELEN + 1];
32 char *path, *cp;
33 int count, pos;
35 strncpy (local_domain, nis_local_directory (), NIS_MAXNAMELEN);
36 local_domain[NIS_MAXNAMELEN] = '\0';
38 count = 1;
39 if ((getnames = malloc ((count + 1) * sizeof (char *))) == NULL)
40 return NULL;
42 /* Do we have a fully qualified NIS+ name ? If yes, give it back */
43 if (name[strlen (name) - 1] == '.')
45 if ((getnames[0] = strdup (name)) == NULL)
47 free (getnames);
48 return NULL;
50 getnames[1] = NULL;
52 return getnames;
55 /* Get the search path, where we have to search "name" */
56 path = getenv ("NIS_PATH");
57 if (path == NULL)
58 path = strdupa ("$");
59 else
60 path = strdupa (path);
62 pos = 0;
64 cp = strtok (path, ":");
65 while (cp)
67 if (strcmp (cp, "$") == 0)
69 char *cptr = local_domain;
70 char *tmp;
72 while (*cptr != '\0')
74 if (pos >= count)
76 count += 5;
77 getnames = realloc (getnames, (count + 1) * sizeof (char *));
79 tmp = malloc (strlen (cptr) + strlen (local_domain) +
80 strlen (name) + 2);
81 if (tmp == NULL)
82 return NULL;
84 getnames[pos] = tmp;
85 tmp = stpcpy (tmp, name);
86 if (*cptr != '.')
87 *tmp++ = '.';
88 stpcpy (tmp, cptr);
90 ++pos;
92 ++cptr;
93 while ((*cptr != '\0') && (*cptr != '.'))
94 ++cptr;
96 if ((*cptr == '.') && (cptr[1] != '\0'))
97 ++cptr;
100 else
102 char *tmp;
104 if (cp[strlen (cp) - 1] == '$')
106 tmp = malloc (strlen (cp) + strlen (local_domain) +
107 strlen (name) + 2);
108 if (tmp == NULL)
109 return NULL;
111 getnames[pos] = tmp;
112 tmp = stpcpy (tmp, name);
113 *tmp++ = '.';
114 tmp = stpcpy (tmp, cp);
115 --tmp;
116 if (tmp[- 1] != '.')
117 *tmp++ = '.';
118 stpcpy (tmp, local_domain);
120 else
122 tmp = malloc (strlen (cp) + strlen (name) + 2);
123 if (tmp == NULL)
124 return NULL;
126 tmp = stpcpy (tmp, name);
127 *tmp++ = '.';
128 stpcpy (tmp, cp);
131 if (pos > count)
133 count += 5;
134 getnames = realloc (getnames, (count + 1) * sizeof (char *));
136 getnames[pos] = tmp;
137 pos++;
139 cp = strtok (NULL, ":");
142 getnames[pos] = NULL;
144 return getnames;
147 fd_result *
148 __nis_finddirectoy (const_nis_name name)
150 fd_args args;
151 nis_error status;
152 fd_result *res;
154 args.dir_name = (char *) name;
155 args.requester = nis_local_principal ();
157 res = calloc (1, sizeof (fd_result));
158 if (res == NULL)
159 return NULL;
161 if ((status = __do_niscall (NULL, 0, NIS_FINDDIRECTORY,
162 (xdrproc_t) xdr_fd_args,
163 (caddr_t) &args,
164 (xdrproc_t) xdr_fd_result,
165 (caddr_t) res, 0)) != RPC_SUCCESS)
166 res->status = status;
168 return res;