* nis/nis_table.c (nis_list): Avoid clearing res twice before
[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 (!val)
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   int errcode;
184
185   if (res == NULL)
186     return NULL;
187
188   if (name == NULL)
189     {
190       errcode = NIS_BADNAME;
191     err_out:
192       memset (res, '\0', sizeof (nis_result));
193       NIS_RES_STATUS (res) = NIS_BADNAME;
194       return res;
195     }
196
197   if ((ibreq = __create_ib_request (name, flags)) == NULL)
198     {
199       errcode = 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           errcode = 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           errcode = 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 (status != NIS_SUCCESS)
249         {
250           NIS_RES_STATUS (res) = status;
251           goto fail2;
252         }
253
254       while (__nisbind_connect (&bptr) != NIS_SUCCESS)
255         if (__nisbind_next (&bptr) != NIS_SUCCESS)
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 (clnt_status != RPC_SUCCESS)
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 (count_links > NIS_MAXLINKS)
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 (count_links)
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   size_t namelen = strlen (name);
528   char buf1[namelen + 20];
529   char buf4[namelen + 20];
530
531   ib_request *ibreq = __create_ib_request (name, flags);
532   if (ibreq == NULL)
533     {
534       NIS_RES_STATUS (res) = NIS_BADNAME;
535       return res;
536     }
537
538   nis_object obj;
539   memcpy (&obj, obj2, sizeof (nis_object));
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 (status  != NIS_SUCCESS)
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   if (( ibreq =__create_ib_request (name, flags)) == NULL)
591     {
592       NIS_RES_STATUS (res) = NIS_BADNAME;
593       return res;
594     }
595
596   memcpy (&obj, obj2, sizeof (nis_object));
597
598   if (obj.zo_name == NULL || strlen (obj.zo_name) == 0)
599     obj.zo_name = nis_leaf_of_r (name, buf1, sizeof (buf1));
600
601   if (obj.zo_owner == NULL || strlen (obj.zo_owner) == 0)
602     obj.zo_owner = nis_local_principal ();
603
604   if (obj.zo_group == NULL || strlen (obj.zo_group) == 0)
605     obj.zo_group = nis_local_group ();
606
607   obj.zo_domain = nis_domain_of_r (name, buf4, sizeof (buf4));
608
609   ibreq->ibr_obj.ibr_obj_val = nis_clone_object (&obj, NULL);
610   if (ibreq->ibr_obj.ibr_obj_val == NULL)
611     {
612       nis_free_request (ibreq);
613       NIS_RES_STATUS (res) = NIS_NOMEMORY;
614       return res;
615     }
616   ibreq->ibr_obj.ibr_obj_len = 1;
617
618   if ((status = __do_niscall (ibreq->ibr_name, NIS_IBMODIFY,
619                               (xdrproc_t) _xdr_ib_request,
620                               (caddr_t) ibreq, (xdrproc_t) _xdr_nis_result,
621                               (caddr_t) res, 0, NULL)) != NIS_SUCCESS)
622     NIS_RES_STATUS (res) = status;
623
624   nis_free_request (ibreq);
625
626   return res;
627 }
628
629 nis_result *
630 nis_remove_entry (const_nis_name name, const nis_object *obj,
631                   unsigned int flags)
632 {
633   nis_result *res;
634   ib_request *ibreq;
635   nis_error status;
636
637   res = calloc (1, sizeof (nis_result));
638   if (res == NULL)
639     return NULL;
640
641   if (name == NULL)
642     {
643       NIS_RES_STATUS (res) = NIS_BADNAME;
644       return res;
645     }
646
647   if ((ibreq =__create_ib_request (name, flags)) == NULL)
648     {
649       NIS_RES_STATUS (res) = NIS_BADNAME;
650       return res;
651     }
652
653   if (obj != NULL)
654     {
655       ibreq->ibr_obj.ibr_obj_val = nis_clone_object (obj, NULL);
656       if (ibreq->ibr_obj.ibr_obj_val == NULL)
657         {
658           nis_free_request (ibreq);
659           NIS_RES_STATUS (res) = NIS_NOMEMORY;
660           return res;
661         }
662       ibreq->ibr_obj.ibr_obj_len = 1;
663     }
664
665   if ((status = __do_niscall (ibreq->ibr_name, NIS_IBREMOVE,
666                               (xdrproc_t) _xdr_ib_request,
667                               (caddr_t) ibreq, (xdrproc_t) _xdr_nis_result,
668                               (caddr_t) res, 0, NULL)) != NIS_SUCCESS)
669     NIS_RES_STATUS (res) = status;
670
671   nis_free_request (ibreq);
672
673   return res;
674 }
675
676 nis_result *
677 nis_first_entry (const_nis_name name)
678 {
679   nis_result *res;
680   ib_request *ibreq;
681   nis_error status;
682
683   res = calloc (1, sizeof (nis_result));
684   if (res == NULL)
685     return NULL;
686
687   if (name == NULL)
688     {
689       NIS_RES_STATUS (res) = NIS_BADNAME;
690       return res;
691     }
692
693   ibreq = __create_ib_request (name, 0);
694   if (ibreq == NULL)
695     {
696       NIS_RES_STATUS (res) = NIS_BADNAME;
697       return res;
698     }
699
700   status = __do_niscall (ibreq->ibr_name, NIS_IBFIRST,
701                          (xdrproc_t) _xdr_ib_request,
702                          (caddr_t) ibreq, (xdrproc_t) _xdr_nis_result,
703                          (caddr_t) res, 0, NULL);
704
705   if (status != NIS_SUCCESS)
706     NIS_RES_STATUS (res) = status;
707
708   nis_free_request (ibreq);
709
710   return res;
711 }
712
713 nis_result *
714 nis_next_entry (const_nis_name name, const netobj *cookie)
715 {
716   nis_result *res;
717   ib_request *ibreq;
718   nis_error status;
719
720   res = calloc (1, sizeof (nis_result));
721   if (res == NULL)
722     return NULL;
723
724   if (name == NULL)
725     {
726       NIS_RES_STATUS (res) = NIS_BADNAME;
727       return res;
728     }
729
730   ibreq = __create_ib_request (name, 0);
731   if (ibreq == NULL)
732     {
733       NIS_RES_STATUS (res) = NIS_BADNAME;
734       return res;
735     }
736
737   if (cookie != NULL)
738     {
739       ibreq->ibr_cookie.n_bytes = cookie->n_bytes;
740       ibreq->ibr_cookie.n_len = cookie->n_len;
741     }
742
743   status = __do_niscall (ibreq->ibr_name, NIS_IBNEXT,
744                          (xdrproc_t) _xdr_ib_request,
745                          (caddr_t) ibreq, (xdrproc_t) _xdr_nis_result,
746                          (caddr_t) res, 0, NULL);
747
748   if (status != NIS_SUCCESS)
749     NIS_RES_STATUS (res) = status;
750
751   if (cookie != NULL)
752     {
753       /* Don't give cookie free, it is not from us */
754       ibreq->ibr_cookie.n_bytes = NULL;
755       ibreq->ibr_cookie.n_len = 0;
756     }
757
758   nis_free_request (ibreq);
759
760   return res;
761 }