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