]> git.ipfire.org Git - thirdparty/glibc.git/blame - nis/nis_table.c
Fix http: URL in 'configure'
[thirdparty/glibc.git] / nis / nis_table.c
CommitLineData
04277e02 1/* Copyright (c) 1997-2019 Free Software Foundation, Inc.
e61abf83 2 This file is part of the GNU C Library.
3d8fa13a 3 Contributed by Thorsten Kukuk <kukuk@suse.de>, 1997.
e61abf83
UD
4
5 The GNU C Library is free software; you can redistribute it and/or
41bdb6e2
AJ
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.
e61abf83
UD
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
41bdb6e2 13 Lesser General Public License for more details.
e61abf83 14
41bdb6e2 15 You should have received a copy of the GNU Lesser General Public
59ba27a6 16 License along with the GNU C Library; if not, see
5a82c748 17 <https://www.gnu.org/licenses/>. */
e61abf83 18
a17fa610 19#include <assert.h>
e61abf83
UD
20#include <string.h>
21#include <rpcsvc/nis.h>
9090848d 22#include <libc-diag.h>
82f43dd2 23#include <shlib-compat.h>
91eee4dd
UD
24
25#include "nis_xdr.h"
e61abf83 26#include "nis_intern.h"
a17fa610 27#include "libnsl.h"
e61abf83 28
d6db1d53 29
a17fa610
UD
30struct ib_request *
31__create_ib_request (const_nis_name name, unsigned int flags)
e61abf83 32{
3218d55b 33 struct ib_request *ibreq = calloc (1, sizeof (struct ib_request));
d6db1d53 34 nis_attr *search_val = NULL;
8112cc70 35 size_t search_len = 0;
d6db1d53 36 size_t size = 0;
e61abf83 37
3d8fa13a
UD
38 if (ibreq == NULL)
39 return NULL;
40
d6db1d53 41 ibreq->ibr_flags = flags;
e61abf83 42
3218d55b 43 char *cptr = strdupa (name);
e61abf83
UD
44
45 /* Not of "[key=value,key=value,...],foo.." format? */
46 if (cptr[0] != '[')
0292b0dd
UD
47 {
48 ibreq->ibr_name = strdup (cptr);
49 if (ibreq->ibr_name == NULL)
50 {
51 free (ibreq);
52 return NULL;
53 }
54 return ibreq;
55 }
e61abf83 56
d6db1d53
UD
57 /* "[key=value,...],foo" format */
58 ibreq->ibr_name = strchr (cptr, ']');
59 if (ibreq->ibr_name == NULL || ibreq->ibr_name[1] != ',')
3d8fa13a 60 {
3218d55b
UD
61 /* The object has not really been built yet so we use free. */
62 free (ibreq);
3d8fa13a
UD
63 return NULL;
64 }
e61abf83 65
9be31a51 66 /* Check if we have an entry of "[key=value,],bar". If, remove the "," */
d6db1d53
UD
67 if (ibreq->ibr_name[-1] == ',')
68 ibreq->ibr_name[-1] = '\0';
69 else
70 ibreq->ibr_name[0] = '\0';
71 ibreq->ibr_name += 2;
72 ibreq->ibr_name = strdup (ibreq->ibr_name);
32abdb71 73 if (ibreq->ibr_name == NULL)
9be31a51
UD
74 {
75 free_null:
76 while (search_len-- > 0)
77 {
78 free (search_val[search_len].zattr_ndx);
79 free (search_val[search_len].zattr_val.zattr_val_val);
80 }
81 free (search_val);
82 nis_free_request (ibreq);
83 return NULL;
84 }
e61abf83 85
d6db1d53 86 ++cptr; /* Remove "[" */
e61abf83 87
d6db1d53 88 while (cptr != NULL && cptr[0] != '\0')
e61abf83 89 {
d6db1d53
UD
90 char *key = cptr;
91 char *val = strchr (cptr, '=');
92
93 cptr = strchr (key, ',');
94 if (cptr != NULL)
95 *cptr++ = '\0';
e61abf83 96
a1ffb40e 97 if (__glibc_unlikely (val == NULL))
e61abf83 98 {
d6db1d53
UD
99 nis_free_request (ibreq);
100 return NULL;
e61abf83 101 }
d6db1d53 102 *val++ = '\0';
fff04b32 103 if (search_len + 1 >= size)
ab26144e
UD
104 {
105 size += 1;
458901c6
UD
106 nis_attr *newp = realloc (search_val, size * sizeof (nis_attr));
107 if (newp == NULL)
9be31a51 108 goto free_null;
458901c6 109 search_val = newp;
e61abf83 110 }
d6db1d53 111 search_val[search_len].zattr_ndx = strdup (key);
fff04b32 112 if (search_val[search_len].zattr_ndx == NULL)
9be31a51 113 goto free_null;
32abdb71 114
d6db1d53
UD
115 search_val[search_len].zattr_val.zattr_val_len = strlen (val) + 1;
116 search_val[search_len].zattr_val.zattr_val_val = strdup (val);
117 if (search_val[search_len].zattr_val.zattr_val_val == NULL)
9be31a51
UD
118 {
119 free (search_val[search_len].zattr_ndx);
120 goto free_null;
121 }
32abdb71 122
d6db1d53 123 ++search_len;
e61abf83 124 }
e61abf83 125
d6db1d53
UD
126 ibreq->ibr_srch.ibr_srch_val = search_val;
127 ibreq->ibr_srch.ibr_srch_len = search_len;
e61abf83
UD
128
129 return ibreq;
130}
1e4d83f6 131libnsl_hidden_nolink_def (__create_ib_request, GLIBC_PRIVATE)
e61abf83 132
3218d55b 133static const struct timeval RPCTIMEOUT = {10, 0};
e852e889
UD
134
135static char *
3e4370cf 136get_tablepath (char *name, dir_binding *bptr)
e852e889
UD
137{
138 enum clnt_stat result;
3218d55b 139 nis_result res;
e852e889
UD
140 struct ns_request req;
141
3218d55b 142 memset (&res, '\0', sizeof (res));
e852e889
UD
143
144 req.ns_name = name;
145 req.ns_object.ns_object_len = 0;
146 req.ns_object.ns_object_val = NULL;
147
148 result = clnt_call (bptr->clnt, NIS_LOOKUP, (xdrproc_t) _xdr_ns_request,
149 (caddr_t) &req, (xdrproc_t) _xdr_nis_result,
3218d55b 150 (caddr_t) &res, RPCTIMEOUT);
e852e889 151
d00002ed 152 const char *cptr;
3218d55b
UD
153 if (result == RPC_SUCCESS && NIS_RES_STATUS (&res) == NIS_SUCCESS
154 && __type_of (NIS_RES_OBJECT (&res)) == NIS_TABLE_OBJ)
155 cptr = NIS_RES_OBJECT (&res)->TA_data.ta_path;
e852e889 156 else
3218d55b
UD
157 cptr = "";
158
3e4370cf
UD
159 char *str = strdup (cptr);
160
161 if (result == RPC_SUCCESS)
162 xdr_free ((xdrproc_t) _xdr_nis_result, (char *) &res);
163
164 return str;
e852e889
UD
165}
166
a17fa610
UD
167
168nis_error
169__follow_path (char **tablepath, char **tableptr, struct ib_request *ibreq,
170 dir_binding *bptr)
171{
172 if (*tablepath == NULL)
173 {
174 *tablepath = get_tablepath (ibreq->ibr_name, bptr);
175 if (*tablepath == NULL)
176 return NIS_NOMEMORY;
177
178 *tableptr = *tablepath;
179 }
2a9feb92
CM
180
181 /* Since tableptr is only set here, and it's set when tablepath is NULL,
182 which it is initially defined as, we know it will always be set here. */
183 DIAG_PUSH_NEEDS_COMMENT;
184 DIAG_IGNORE_NEEDS_COMMENT (4.7, "-Wmaybe-uninitialized");
185
a17fa610
UD
186 if (*tableptr == NULL)
187 return NIS_NOTFOUND;
188
189 char *newname = strsep (tableptr, ":");
190 if (newname[0] == '\0')
191 return NIS_NOTFOUND;
192
2a9feb92
CM
193 DIAG_POP_NEEDS_COMMENT;
194
a17fa610
UD
195 newname = strdup (newname);
196 if (newname == NULL)
197 return NIS_NOMEMORY;
198
199 free (ibreq->ibr_name);
200 ibreq->ibr_name = newname;
201
202 return NIS_SUCCESS;
203}
1e4d83f6 204libnsl_hidden_nolink_def (__follow_path, GLIBC_PRIVATE)
a17fa610
UD
205
206
e61abf83 207nis_result *
a1129917 208nis_list (const_nis_name name, unsigned int flags,
c131718c 209 int (*callback) (const_nis_name name,
e61abf83
UD
210 const nis_object *object,
211 const void *userdata),
212 const void *userdata)
213{
f2d5cf50 214 nis_result *res = malloc (sizeof (nis_result));
d6db1d53 215 ib_request *ibreq;
2d7da676 216 int status;
e852e889 217 enum clnt_stat clnt_status;
650425ce 218 int count_links = 0; /* We will only follow NIS_MAXLINKS links! */
2d7da676
UD
219 int done = 0;
220 nis_name *names;
221 nis_name namebuf[2] = {NULL, NULL};
222 int name_nr = 0;
650425ce 223 nis_cb *cb = NULL;
07683f84
UD
224 char *tableptr;
225 char *tablepath = NULL;
e852e889 226 int first_try = 0; /* Do we try the old binding at first ? */
68361572 227 nis_result *allres = NULL;
e61abf83 228
91eee4dd
UD
229 if (res == NULL)
230 return NULL;
e61abf83 231
d6db1d53
UD
232 if (name == NULL)
233 {
fff04b32 234 status = NIS_BADNAME;
f2d5cf50 235 err_out:
68361572 236 nis_freeresult (allres);
f2d5cf50 237 memset (res, '\0', sizeof (nis_result));
fff04b32 238 NIS_RES_STATUS (res) = status;
d6db1d53
UD
239 return res;
240 }
241
a17fa610 242 ibreq = __create_ib_request (name, flags);
fff04b32 243 if (ibreq == NULL)
e61abf83 244 {
fff04b32 245 status = NIS_BADNAME;
f2d5cf50 246 goto err_out;
e61abf83
UD
247 }
248
901956a5
UD
249 if ((flags & EXPAND_NAME)
250 && ibreq->ibr_name[strlen (ibreq->ibr_name) - 1] != '.')
e61abf83 251 {
dfd2257a
UD
252 names = nis_getnames (ibreq->ibr_name);
253 free (ibreq->ibr_name);
254 ibreq->ibr_name = NULL;
2d7da676 255 if (names == NULL)
e61abf83 256 {
3d8fa13a 257 nis_free_request (ibreq);
fff04b32 258 status = NIS_BADNAME;
f2d5cf50 259 goto err_out;
e61abf83 260 }
dfd2257a 261 ibreq->ibr_name = strdup (names[name_nr]);
901956a5
UD
262 if (ibreq->ibr_name == NULL)
263 {
07683f84 264 nis_freenames (names);
901956a5 265 nis_free_request (ibreq);
fff04b32 266 status = NIS_NOMEMORY;
f2d5cf50 267 goto err_out;
901956a5 268 }
2d7da676
UD
269 }
270 else
650425ce
UD
271 {
272 names = namebuf;
dfd2257a 273 names[name_nr] = ibreq->ibr_name;
650425ce 274 }
e61abf83 275
650425ce
UD
276 cb = NULL;
277
e852e889 278 while (!done)
2d7da676 279 {
e852e889
UD
280 dir_binding bptr;
281 directory_obj *dir = NULL;
650425ce 282
e852e889 283 memset (res, '\0', sizeof (nis_result));
650425ce 284
bd1ebae0 285 status = __nisfind_server (ibreq->ibr_name,
697d37b1
JJ
286 ibreq->ibr_srch.ibr_srch_val != NULL,
287 &dir, &bptr, flags & ~MASTER_ONLY);
e852e889 288 if (status != NIS_SUCCESS)
07683f84 289 {
ab26144e
UD
290 NIS_RES_STATUS (res) = status;
291 goto fail3;
07683f84 292 }
a334319f 293
e852e889 294 while (__nisbind_connect (&bptr) != NIS_SUCCESS)
a1ffb40e 295 if (__glibc_unlikely (__nisbind_next (&bptr) != NIS_SUCCESS))
e852e889 296 {
e852e889 297 NIS_RES_STATUS (res) = NIS_NAMEUNREACHABLE;
07683f84 298 goto fail;
e852e889 299 }
6f0ee462 300
650425ce
UD
301 if (callback != NULL)
302 {
a17fa610 303 assert (cb == NULL);
650425ce 304 cb = __nis_create_callback (callback, userdata, flags);
dfd2257a
UD
305 ibreq->ibr_cbhost.ibr_cbhost_len = 1;
306 ibreq->ibr_cbhost.ibr_cbhost_val = cb->serv;
e852e889 307 }
650425ce 308
e852e889
UD
309 again:
310 clnt_status = clnt_call (bptr.clnt, NIS_IBLIST,
311 (xdrproc_t) _xdr_ib_request, (caddr_t) ibreq,
312 (xdrproc_t) _xdr_nis_result,
313 (caddr_t) res, RPCTIMEOUT);
314
a1ffb40e 315 if (__glibc_unlikely (clnt_status != RPC_SUCCESS))
e852e889
UD
316 NIS_RES_STATUS (res) = NIS_RPCERROR;
317 else
318 switch (NIS_RES_STATUS (res))
319 { /* start switch */
320 case NIS_PARTIAL:
321 case NIS_SUCCESS:
322 case NIS_S_SUCCESS:
707c7499
UD
323 if (__type_of (NIS_RES_OBJECT (res)) == NIS_LINK_OBJ
324 && (flags & FOLLOW_LINKS)) /* We are following links. */
e852e889
UD
325 {
326 free (ibreq->ibr_name);
3d8fa13a 327 ibreq->ibr_name = NULL;
e852e889 328 /* If we hit the link limit, bail. */
a1ffb40e 329 if (__glibc_unlikely (count_links > NIS_MAXLINKS))
e852e889
UD
330 {
331 NIS_RES_STATUS (res) = NIS_LINKNAMEERROR;
332 ++done;
333 break;
334 }
335 ++count_links;
336 ibreq->ibr_name =
337 strdup (NIS_RES_OBJECT (res)->LI_data.li_name);
901956a5
UD
338 if (ibreq->ibr_name == NULL)
339 {
a334319f 340 NIS_RES_STATUS (res) = NIS_NOMEMORY;
07683f84
UD
341 fail:
342 __nisbind_destroy (&bptr);
07683f84
UD
343 nis_free_directory (dir);
344 fail3:
345 free (tablepath);
346 if (cb)
347 {
348 __nis_destroy_callback (cb);
349 ibreq->ibr_cbhost.ibr_cbhost_len = 0;
350 ibreq->ibr_cbhost.ibr_cbhost_val = NULL;
351 }
352 if (names != namebuf)
353 nis_freenames (names);
354 nis_free_request (ibreq);
68361572 355 nis_freeresult (allres);
901956a5
UD
356 return res;
357 }
e852e889
UD
358 if (NIS_RES_OBJECT (res)->LI_data.li_attrs.li_attrs_len)
359 if (ibreq->ibr_srch.ibr_srch_len == 0)
650425ce 360 {
e852e889
UD
361 ibreq->ibr_srch.ibr_srch_len =
362 NIS_RES_OBJECT (res)->LI_data.li_attrs.li_attrs_len;
363 ibreq->ibr_srch.ibr_srch_val =
364 NIS_RES_OBJECT (res)->LI_data.li_attrs.li_attrs_val;
650425ce 365 }
56a5719e
UD
366 /* The following is a non-obvious optimization. A
367 nis_freeresult call would call xdr_free as the
368 following code. But it also would unnecessarily
369 free the result structure. We avoid this here
370 along with the necessary tests. */
56a5719e
UD
371 xdr_free ((xdrproc_t) _xdr_nis_result, (char *)res);
372 memset (res, '\0', sizeof (*res));
e852e889
UD
373 first_try = 1; /* Try at first the old binding */
374 goto again;
375 }
707c7499
UD
376 else if ((flags & FOLLOW_PATH)
377 && NIS_RES_STATUS (res) == NIS_PARTIAL)
e852e889 378 {
ab26144e
UD
379 enum nis_error err = __follow_path (&tablepath, &tableptr,
380 ibreq, &bptr);
381 if (err != NIS_SUCCESS)
e852e889 382 {
ab26144e
UD
383 if (err == NIS_NOMEMORY)
384 NIS_RES_STATUS (res) = err;
a334319f 385 ++done;
e852e889
UD
386 }
387 else
388 {
707c7499
UD
389 /* The following is a non-obvious optimization. A
390 nis_freeresult call would call xdr_free as the
391 following code. But it also would unnecessarily
392 free the result structure. We avoid this here
393 along with the necessary tests. */
a17fa610 394 xdr_free ((xdrproc_t) _xdr_nis_result, (char *) res);
707c7499 395 memset (res, '\0', sizeof (*res));
a334319f
UD
396 first_try = 1;
397 goto again;
e852e889
UD
398 }
399 }
68361572
UD
400 else if ((flags & (FOLLOW_PATH | ALL_RESULTS))
401 == (FOLLOW_PATH | ALL_RESULTS))
402 {
403 if (allres == NULL)
404 {
405 allres = res;
406 res = malloc (sizeof (nis_result));
407 if (res == NULL)
408 {
409 res = allres;
410 allres = NULL;
411 NIS_RES_STATUS (res) = NIS_NOMEMORY;
412 goto fail;
413 }
414 NIS_RES_STATUS (res) = NIS_RES_STATUS (allres);
415 }
416 else
417 {
418 nis_object *objects_val
419 = realloc (NIS_RES_OBJECT (allres),
420 (NIS_RES_NUMOBJ (allres)
421 + NIS_RES_NUMOBJ (res))
422 * sizeof (nis_object));
423 if (objects_val == NULL)
424 {
425 NIS_RES_STATUS (res) = NIS_NOMEMORY;
426 goto fail;
427 }
428 NIS_RES_OBJECT (allres) = objects_val;
429 memcpy (NIS_RES_OBJECT (allres) + NIS_RES_NUMOBJ (allres),
430 NIS_RES_OBJECT (res),
431 NIS_RES_NUMOBJ (res) * sizeof (nis_object));
432 NIS_RES_NUMOBJ (allres) += NIS_RES_NUMOBJ (res);
433 NIS_RES_NUMOBJ (res) = 0;
434 free (NIS_RES_OBJECT (res));
435 NIS_RES_OBJECT (res) = NULL;
436 NIS_RES_STATUS (allres) = NIS_RES_STATUS (res);
437 xdr_free ((xdrproc_t) _xdr_nis_result, (char *) res);
438 }
ab26144e
UD
439 enum nis_error err = __follow_path (&tablepath, &tableptr,
440 ibreq, &bptr);
441 if (err != NIS_SUCCESS)
68361572 442 {
4df92d57
UD
443 /* Prepare for the nis_freeresult call. */
444 memset (res, '\0', sizeof (*res));
445
ab26144e
UD
446 if (err == NIS_NOMEMORY)
447 NIS_RES_STATUS (allres) = err;
68361572
UD
448 ++done;
449 }
450 }
e852e889 451 else
2d7da676 452 ++done;
e852e889
UD
453 break;
454 case NIS_CBRESULTS:
455 if (cb != NULL)
456 {
457 __nis_do_callback (&bptr, &res->cookie, cb);
458 NIS_RES_STATUS (res) = cb->result;
459
460 if (!(flags & ALL_RESULTS))
650425ce 461 ++done;
e852e889
UD
462 else
463 {
ab26144e 464 enum nis_error err
a17fa610 465 = __follow_path (&tablepath, &tableptr, ibreq, &bptr);
ab26144e 466 if (err != NIS_SUCCESS)
0008163a 467 {
ab26144e
UD
468 if (err == NIS_NOMEMORY)
469 NIS_RES_STATUS (res) = err;
0008163a
UD
470 ++done;
471 }
e852e889
UD
472 }
473 }
474 break;
475 case NIS_SYSTEMERROR:
476 case NIS_NOSUCHNAME:
477 case NIS_NOT_ME:
478 /* If we had first tried the old binding, do nothing, but
479 get a new binding */
480 if (!first_try)
481 {
482 if (__nisbind_next (&bptr) != NIS_SUCCESS)
483 {
484 ++done;
485 break; /* No more servers to search */
486 }
487 while (__nisbind_connect (&bptr) != NIS_SUCCESS)
488 {
489 if (__nisbind_next (&bptr) != NIS_SUCCESS)
490 {
491 ++done;
492 break; /* No more servers to search */
493 }
494 }
495 goto again;
496 }
497 break;
498 default:
499 if (!first_try)
500 {
501 /* Try the next domainname if we don't follow a link. */
901956a5
UD
502 free (ibreq->ibr_name);
503 ibreq->ibr_name = NULL;
a1ffb40e 504 if (__glibc_unlikely (count_links))
e852e889 505 {
e852e889
UD
506 NIS_RES_STATUS (res) = NIS_LINKNAMEERROR;
507 ++done;
508 break;
509 }
510 ++name_nr;
511 if (names[name_nr] == NULL)
512 {
513 ++done;
514 break;
515 }
901956a5
UD
516 ibreq->ibr_name = strdup (names[name_nr]);
517 if (ibreq->ibr_name == NULL)
518 {
901956a5 519 NIS_RES_STATUS (res) = NIS_NOMEMORY;
07683f84 520 goto fail;
901956a5 521 }
e852e889
UD
522 first_try = 1; /* Try old binding at first */
523 goto again;
524 }
525 break;
526 }
527 first_try = 0;
528
529 if (cb)
530 {
531 __nis_destroy_callback (cb);
532 ibreq->ibr_cbhost.ibr_cbhost_len = 0;
533 ibreq->ibr_cbhost.ibr_cbhost_val = NULL;
07683f84 534 cb = NULL;
e61abf83 535 }
e852e889
UD
536
537 __nisbind_destroy (&bptr);
538 nis_free_directory (dir);
539 }
e61abf83 540
07683f84
UD
541 free (tablepath);
542
2d7da676
UD
543 if (names != namebuf)
544 nis_freenames (names);
545
dfd2257a 546 nis_free_request (ibreq);
e61abf83 547
68361572
UD
548 if (allres)
549 {
550 nis_freeresult (res);
551 return allres;
552 }
553
e61abf83
UD
554 return res;
555}
1e4d83f6 556libnsl_hidden_nolink_def (nis_list, GLIBC_2_1)
e61abf83
UD
557
558nis_result *
a1129917 559nis_add_entry (const_nis_name name, const nis_object *obj2, unsigned int flags)
e61abf83 560{
0292b0dd 561 nis_result *res = calloc (1, sizeof (nis_result));
91eee4dd
UD
562 if (res == NULL)
563 return NULL;
564
d6db1d53 565 if (name == NULL)
91eee4dd 566 {
d6db1d53 567 NIS_RES_STATUS (res) = NIS_BADNAME;
91eee4dd
UD
568 return res;
569 }
e61abf83 570
a17fa610 571 ib_request *ibreq = __create_ib_request (name, flags);
0292b0dd 572 if (ibreq == NULL)
e61abf83 573 {
91eee4dd 574 NIS_RES_STATUS (res) = NIS_BADNAME;
e61abf83
UD
575 return res;
576 }
577
0292b0dd 578 nis_object obj;
91eee4dd 579 memcpy (&obj, obj2, sizeof (nis_object));
e61abf83 580
fff04b32
UD
581 size_t namelen = strlen (name);
582 char buf1[namelen + 20];
583 char buf4[namelen + 20];
584
91eee4dd
UD
585 if (obj.zo_name == NULL || strlen (obj.zo_name) == 0)
586 obj.zo_name = nis_leaf_of_r (name, buf1, sizeof (buf1));
ce37fa88 587
91eee4dd
UD
588 if (obj.zo_owner == NULL || strlen (obj.zo_owner) == 0)
589 obj.zo_owner = nis_local_principal ();
ce37fa88 590
91eee4dd
UD
591 if (obj.zo_group == NULL || strlen (obj.zo_group) == 0)
592 obj.zo_group = nis_local_group ();
ce37fa88 593
91eee4dd
UD
594 obj.zo_domain = nis_domain_of_r (name, buf4, sizeof (buf4));
595
596 ibreq->ibr_obj.ibr_obj_val = nis_clone_object (&obj, NULL);
597 if (ibreq->ibr_obj.ibr_obj_val == NULL)
598 {
3d8fa13a 599 nis_free_request (ibreq);
91eee4dd
UD
600 NIS_RES_STATUS (res) = NIS_NOMEMORY;
601 return res;
602 }
603 ibreq->ibr_obj.ibr_obj_len = 1;
ce37fa88 604
0292b0dd
UD
605 nis_error status = __do_niscall (ibreq->ibr_name, NIS_IBADD,
606 (xdrproc_t) _xdr_ib_request,
607 (caddr_t) ibreq,
608 (xdrproc_t) _xdr_nis_result,
609 (caddr_t) res, 0, NULL);
a1ffb40e 610 if (__glibc_unlikely (status != NIS_SUCCESS))
91eee4dd 611 NIS_RES_STATUS (res) = status;
ce37fa88 612
dfd2257a 613 nis_free_request (ibreq);
e61abf83
UD
614
615 return res;
616}
1e4d83f6 617libnsl_hidden_nolink_def (nis_add_entry, GLIBC_2_1)
e61abf83
UD
618
619nis_result *
a1129917
UD
620nis_modify_entry (const_nis_name name, const nis_object *obj2,
621 unsigned int flags)
e61abf83 622{
91eee4dd 623 nis_object obj;
e61abf83 624 nis_result *res;
e61abf83 625 nis_error status;
d6db1d53
UD
626 ib_request *ibreq;
627 size_t namelen = strlen (name);
628 char buf1[namelen + 20];
629 char buf4[namelen + 20];
e61abf83
UD
630
631 res = calloc (1, sizeof (nis_result));
d6db1d53
UD
632 if (res == NULL)
633 return NULL;
e61abf83 634
a17fa610 635 ibreq = __create_ib_request (name, flags);
fff04b32 636 if (ibreq == NULL)
e61abf83 637 {
91eee4dd 638 NIS_RES_STATUS (res) = NIS_BADNAME;
e61abf83
UD
639 return res;
640 }
641
91eee4dd 642 memcpy (&obj, obj2, sizeof (nis_object));
e61abf83 643
91eee4dd
UD
644 if (obj.zo_name == NULL || strlen (obj.zo_name) == 0)
645 obj.zo_name = nis_leaf_of_r (name, buf1, sizeof (buf1));
ce37fa88 646
91eee4dd
UD
647 if (obj.zo_owner == NULL || strlen (obj.zo_owner) == 0)
648 obj.zo_owner = nis_local_principal ();
ce37fa88 649
91eee4dd
UD
650 if (obj.zo_group == NULL || strlen (obj.zo_group) == 0)
651 obj.zo_group = nis_local_group ();
ce37fa88 652
91eee4dd
UD
653 obj.zo_domain = nis_domain_of_r (name, buf4, sizeof (buf4));
654
655 ibreq->ibr_obj.ibr_obj_val = nis_clone_object (&obj, NULL);
656 if (ibreq->ibr_obj.ibr_obj_val == NULL)
657 {
3d8fa13a 658 nis_free_request (ibreq);
91eee4dd
UD
659 NIS_RES_STATUS (res) = NIS_NOMEMORY;
660 return res;
661 }
662 ibreq->ibr_obj.ibr_obj_len = 1;
ce37fa88 663
fff04b32
UD
664 status = __do_niscall (ibreq->ibr_name, NIS_IBMODIFY,
665 (xdrproc_t) _xdr_ib_request,
666 (caddr_t) ibreq, (xdrproc_t) _xdr_nis_result,
667 (caddr_t) res, 0, NULL);
a1ffb40e 668 if (__glibc_unlikely (status != NIS_SUCCESS))
91eee4dd 669 NIS_RES_STATUS (res) = status;
ce37fa88 670
dfd2257a 671 nis_free_request (ibreq);
e61abf83
UD
672
673 return res;
674}
1e4d83f6 675libnsl_hidden_nolink_def (nis_modify_entry, GLIBC_2_1)
e61abf83
UD
676
677nis_result *
c131718c 678nis_remove_entry (const_nis_name name, const nis_object *obj,
a1129917 679 unsigned int flags)
e61abf83
UD
680{
681 nis_result *res;
d6db1d53 682 ib_request *ibreq;
e61abf83
UD
683 nis_error status;
684
685 res = calloc (1, sizeof (nis_result));
91eee4dd
UD
686 if (res == NULL)
687 return NULL;
688
d6db1d53 689 if (name == NULL)
91eee4dd 690 {
d6db1d53 691 NIS_RES_STATUS (res) = NIS_BADNAME;
91eee4dd
UD
692 return res;
693 }
e61abf83 694
a17fa610 695 ibreq = __create_ib_request (name, flags);
fff04b32 696 if (ibreq == NULL)
e61abf83 697 {
91eee4dd 698 NIS_RES_STATUS (res) = NIS_BADNAME;
e61abf83
UD
699 return res;
700 }
701
e61abf83
UD
702 if (obj != NULL)
703 {
dfd2257a 704 ibreq->ibr_obj.ibr_obj_val = nis_clone_object (obj, NULL);
91eee4dd
UD
705 if (ibreq->ibr_obj.ibr_obj_val == NULL)
706 {
3d8fa13a 707 nis_free_request (ibreq);
91eee4dd
UD
708 NIS_RES_STATUS (res) = NIS_NOMEMORY;
709 return res;
710 }
dfd2257a 711 ibreq->ibr_obj.ibr_obj_len = 1;
e61abf83
UD
712 }
713
dfd2257a 714 if ((status = __do_niscall (ibreq->ibr_name, NIS_IBREMOVE,
91eee4dd
UD
715 (xdrproc_t) _xdr_ib_request,
716 (caddr_t) ibreq, (xdrproc_t) _xdr_nis_result,
650425ce 717 (caddr_t) res, 0, NULL)) != NIS_SUCCESS)
91eee4dd 718 NIS_RES_STATUS (res) = status;
e61abf83 719
dfd2257a 720 nis_free_request (ibreq);
e61abf83
UD
721
722 return res;
723}
1e4d83f6 724libnsl_hidden_nolink_def (nis_remove_entry, GLIBC_2_1)
e61abf83
UD
725
726nis_result *
c131718c 727nis_first_entry (const_nis_name name)
e61abf83
UD
728{
729 nis_result *res;
d6db1d53 730 ib_request *ibreq;
e61abf83
UD
731 nis_error status;
732
733 res = calloc (1, sizeof (nis_result));
91eee4dd
UD
734 if (res == NULL)
735 return NULL;
736
d6db1d53 737 if (name == NULL)
91eee4dd 738 {
d6db1d53 739 NIS_RES_STATUS (res) = NIS_BADNAME;
91eee4dd
UD
740 return res;
741 }
e61abf83 742
a17fa610 743 ibreq = __create_ib_request (name, 0);
32abdb71 744 if (ibreq == NULL)
e61abf83 745 {
91eee4dd 746 NIS_RES_STATUS (res) = NIS_BADNAME;
e61abf83
UD
747 return res;
748 }
749
32abdb71
UD
750 status = __do_niscall (ibreq->ibr_name, NIS_IBFIRST,
751 (xdrproc_t) _xdr_ib_request,
752 (caddr_t) ibreq, (xdrproc_t) _xdr_nis_result,
753 (caddr_t) res, 0, NULL);
754
a1ffb40e 755 if (__glibc_unlikely (status != NIS_SUCCESS))
91eee4dd 756 NIS_RES_STATUS (res) = status;
e61abf83 757
dfd2257a 758 nis_free_request (ibreq);
e61abf83
UD
759
760 return res;
761}
1e4d83f6 762libnsl_hidden_nolink_def (nis_first_entry, GLIBC_2_1)
e61abf83
UD
763
764nis_result *
c131718c 765nis_next_entry (const_nis_name name, const netobj *cookie)
e61abf83
UD
766{
767 nis_result *res;
d6db1d53 768 ib_request *ibreq;
e61abf83
UD
769 nis_error status;
770
771 res = calloc (1, sizeof (nis_result));
91eee4dd
UD
772 if (res == NULL)
773 return NULL;
774
d6db1d53 775 if (name == NULL)
91eee4dd 776 {
d6db1d53 777 NIS_RES_STATUS (res) = NIS_BADNAME;
91eee4dd
UD
778 return res;
779 }
e61abf83 780
a17fa610 781 ibreq = __create_ib_request (name, 0);
32abdb71 782 if (ibreq == NULL)
e61abf83 783 {
91eee4dd 784 NIS_RES_STATUS (res) = NIS_BADNAME;
e61abf83
UD
785 return res;
786 }
787
788 if (cookie != NULL)
789 {
d6db1d53 790 ibreq->ibr_cookie.n_bytes = cookie->n_bytes;
dfd2257a 791 ibreq->ibr_cookie.n_len = cookie->n_len;
e61abf83
UD
792 }
793
32abdb71
UD
794 status = __do_niscall (ibreq->ibr_name, NIS_IBNEXT,
795 (xdrproc_t) _xdr_ib_request,
796 (caddr_t) ibreq, (xdrproc_t) _xdr_nis_result,
797 (caddr_t) res, 0, NULL);
798
a1ffb40e 799 if (__glibc_unlikely (status != NIS_SUCCESS))
91eee4dd 800 NIS_RES_STATUS (res) = status;
e61abf83 801
d6db1d53
UD
802 if (cookie != NULL)
803 {
804 /* Don't give cookie free, it is not from us */
805 ibreq->ibr_cookie.n_bytes = NULL;
806 ibreq->ibr_cookie.n_len = 0;
807 }
808
dfd2257a 809 nis_free_request (ibreq);
e61abf83
UD
810
811 return res;
812}
1e4d83f6 813libnsl_hidden_nolink_def (nis_next_entry, GLIBC_2_1)