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