]> sourceware.org Git - glibc.git/blob - nis/nis_names.c
Update.
[glibc.git] / nis / nis_names.c
1 /* Copyright (C) 1997 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Thorsten Kukuk <kukuk@uni-paderborn.de>, 1997.
4
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.
9
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.
14
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. */
19
20 #include <string.h>
21 #include <rpc/rpc.h>
22 #include <rpcsvc/nis.h>
23 #include <rpcsvc/nislib.h>
24
25 #include "nis_intern.h"
26
27 nis_result *
28 nis_lookup (const_nis_name name, const u_long flags)
29 {
30 nis_result *res;
31 struct ns_request req;
32 nis_name *names;
33 nis_error status;
34 int is_link = 1; /* We should go at least once in the while loop */
35 int count_links = 0; /* We will follow only 16 links in the deep */
36 int i;
37
38 res = calloc (1, sizeof (nis_result));
39
40 if (flags & EXPAND_NAME)
41 {
42 names = __nis_expandname (name);
43 if (names == NULL)
44 {
45 res->status = NIS_NAMEUNREACHABLE;
46 return res;
47 }
48
49 i = 0;
50 while (names[i] != NULL && (i == 0 || res->status > 1))
51 {
52 req.ns_name = names[i];
53
54 while (is_link)
55 {
56 req.ns_object.ns_object_len = 0;
57 req.ns_object.ns_object_val = NULL;
58 memset (res, '\0', sizeof (nis_result));
59
60 if ((status = __do_niscall (NULL, 0, NIS_LOOKUP,
61 (xdrproc_t) xdr_ns_request,
62 (caddr_t) & req,
63 (xdrproc_t) xdr_nis_result,
64 (caddr_t) res, flags)) != RPC_SUCCESS)
65 {
66 res->status = status;
67 nis_freenames (names);
68 return res;
69 }
70
71 if ((res->status == NIS_SUCCESS || res->status == NIS_S_SUCCESS)
72 && (res->objects.objects_len > 0 &&
73 res->objects.objects_val->zo_data.zo_type == LINK_OBJ))
74 is_link = 1;
75 else
76 is_link = 0;
77
78 if (is_link)
79 {
80 if ((flags & FOLLOW_LINKS) == FOLLOW_LINKS)
81 {
82 if (count_links == 16)
83 {
84 res->status = NIS_LINKNAMEERROR;
85 return res;
86 }
87 else
88 ++count_links;
89
90 req.ns_name = res->objects.objects_val->LI_data.li_name;
91 }
92 else
93 {
94 res->status = NIS_NOTSEARCHABLE;
95 return res;
96 }
97 }
98 }
99
100 ++i;
101 if (res->status == NIS_NOT_ME)
102 res->status = NIS_NOSUCHNAME;
103 }
104
105 nis_freenames (names);
106 }
107 else
108 {
109 req.ns_name = (char *)name;
110
111 while (is_link)
112 {
113 req.ns_object.ns_object_len = 0;
114 req.ns_object.ns_object_val = NULL;
115 memset (res, '\0', sizeof (nis_result));
116
117 if ((status = __do_niscall (NULL, 0, NIS_LOOKUP,
118 (xdrproc_t) xdr_ns_request,
119 (caddr_t) &req,
120 (xdrproc_t) xdr_nis_result,
121 (caddr_t) res, flags)) != RPC_SUCCESS)
122 {
123 res->status = status;
124 return res;
125 }
126
127 if ((res->status == NIS_SUCCESS || res->status == NIS_S_SUCCESS) &&
128 (res->objects.objects_len > 0 &&
129 res->objects.objects_val->zo_data.zo_type == LINK_OBJ))
130 is_link = 1;
131 else
132 is_link = 0;
133
134 if (is_link)
135 {
136 if ((flags & FOLLOW_LINKS) == FOLLOW_LINKS)
137 {
138 if (count_links == 16)
139 {
140 res->status = NIS_LINKNAMEERROR;
141 return res;
142 }
143 else
144 ++count_links;
145
146 req.ns_name = res->objects.objects_val->LI_data.li_name;
147 }
148 else
149 {
150 res->status = NIS_NOTSEARCHABLE;
151 return res;
152 }
153 }
154 }
155 }
156
157 return res;
158 }
159
160 nis_result *
161 nis_add (const_nis_name name, const nis_object *obj)
162 {
163 nis_result *res;
164 nis_error status;
165 struct ns_request req;
166 char *p1, *p2, *p3, *p4;
167 char buf1 [strlen (name) + 20];
168 char buf4 [strlen (name) + 20];
169
170 res = calloc (1, sizeof (nis_result));
171
172 req.ns_name = (char *)name;
173
174 req.ns_object.ns_object_len = 1;
175 req.ns_object.ns_object_val = nis_clone_object (obj, NULL);
176
177 p1 = req.ns_object.ns_object_val[0].zo_name;
178 req.ns_object.ns_object_val[0].zo_name =
179 nis_name_of_r (name, buf1, sizeof (buf1));
180
181 p2 = req.ns_object.ns_object_val[0].zo_owner;
182 if (p2 == NULL || strlen (p2) == 0)
183 req.ns_object.ns_object_val[0].zo_owner = nis_local_principal ();
184
185 p3 = req.ns_object.ns_object_val[0].zo_group;
186 if (p3 == NULL || strlen (p3) == 0)
187 req.ns_object.ns_object_val[0].zo_group = nis_local_group ();
188
189 p4 = req.ns_object.ns_object_val[0].zo_domain;
190 req.ns_object.ns_object_val[0].zo_domain =
191 nis_domain_of_r (name, buf4, sizeof (buf4));
192
193 if ((status = __do_niscall (NULL, 0, NIS_ADD, (xdrproc_t) xdr_ns_request,
194 (caddr_t) &req, (xdrproc_t) xdr_nis_result,
195 (caddr_t) res, 0)) != RPC_SUCCESS)
196 res->status = status;
197
198 req.ns_object.ns_object_val[0].zo_name = p1;
199 req.ns_object.ns_object_val[0].zo_owner = p2;
200 req.ns_object.ns_object_val[0].zo_group = p3;
201 req.ns_object.ns_object_val[0].zo_domain = p4;
202
203 nis_destroy_object (req.ns_object.ns_object_val);
204
205 return res;
206 }
207
208 nis_result *
209 nis_remove (const_nis_name name, const nis_object *obj)
210 {
211 nis_result *res;
212 nis_error status;
213 struct ns_request req;
214
215 res = calloc (1, sizeof (nis_result));
216
217 req.ns_name = (char *)name;
218
219 if (obj != NULL)
220 {
221 req.ns_object.ns_object_len = 1;
222 req.ns_object.ns_object_val = nis_clone_object (obj, NULL);
223 }
224 else
225 {
226 req.ns_object.ns_object_len = 0;
227 req.ns_object.ns_object_val = NULL;
228 }
229
230 if ((status = __do_niscall (NULL, 0, NIS_REMOVE, (xdrproc_t) xdr_ns_request,
231 (caddr_t) & req, (xdrproc_t) xdr_nis_result,
232 (caddr_t) res, 0)) != RPC_SUCCESS)
233 res->status = status;
234
235 nis_destroy_object (req.ns_object.ns_object_val);
236
237 return res;
238 }
239
240 nis_result *
241 nis_modify (const_nis_name name, const nis_object *obj)
242 {
243 nis_result *res;
244 nis_error status;
245 struct ns_request req;
246
247 res = calloc (1, sizeof (nis_result));
248
249 req.ns_name = (char *)name;
250
251 req.ns_object.ns_object_len = 1;
252 req.ns_object.ns_object_val = nis_clone_object (obj, NULL);
253
254 if ((status = __do_niscall (NULL, 0, NIS_MODIFY, (xdrproc_t) xdr_ns_request,
255 (caddr_t) & req, (xdrproc_t) xdr_nis_result,
256 (caddr_t) res, 0)) != RPC_SUCCESS)
257 res->status = status;
258
259 nis_destroy_object (req.ns_object.ns_object_val);
260
261 return res;
262 }
This page took 0.051179 seconds and 5 git commands to generate.