Don't define __libc_have_rt_sigs here.
[glibc/history.git] / nis / nis_lookup.c
blobcbc64c34a490b3ab892dcd712e3199185f175a70
1 /* Copyright (C) 1997 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Thorsten Kukuk <kukuk@uni-paderborn.de>, 1997.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
20 #include <string.h>
21 #include <rpcsvc/nis.h>
23 #include "nis_intern.h"
25 nis_result *
26 nis_lookup (const_nis_name name, const u_long flags)
28 nis_result *res;
29 struct ns_request req;
30 nis_name *names;
31 nis_error status;
32 int count_links = 0; /* We will follow only 16 links in the deep */
33 int done = 0;
34 int name_nr = 0;
35 nis_name namebuf[2] = {NULL, NULL};
37 res = calloc (1, sizeof (nis_result));
39 if (flags & EXPAND_NAME)
41 names = nis_getnames (name);
42 if (names == NULL)
44 res->status = NIS_NAMEUNREACHABLE;
45 return res;
48 else
50 names = namebuf;
51 names[0] = (nis_name) name;
54 req.ns_name = names[0];
55 while (!done)
57 req.ns_object.ns_object_len = 0;
58 req.ns_object.ns_object_val = NULL;
59 memset (res, '\0', sizeof (nis_result));
61 status = __do_niscall (req.ns_name, NIS_LOOKUP,
62 (xdrproc_t) xdr_ns_request,
63 (caddr_t) & req,
64 (xdrproc_t) xdr_nis_result,
65 (caddr_t) res, flags, NULL);
66 if (status != NIS_SUCCESS)
67 res->status = status;
69 switch (res->status)
71 case NIS_PARTIAL:
72 case NIS_SUCCESS:
73 case NIS_S_SUCCESS:
74 if (__type_of(NIS_RES_OBJECT (res)) == NIS_LINK_OBJ &&
75 flags & FOLLOW_LINKS) /* We are following links */
77 /* if we hit the link limit, bail */
78 if (count_links > NIS_MAXLINKS)
80 res->status = NIS_LINKNAMEERROR;
81 ++done;
82 break;
84 if (count_links)
85 free (req.ns_name);
86 ++count_links;
87 req.ns_name = strdup (NIS_RES_OBJECT (res)->LI_data.li_name);
88 nis_freeresult (res);
89 res = calloc (1, sizeof (nis_result));
91 else
92 ++done;
93 break;
94 case NIS_CBRESULTS:
95 /* The callback is handled in __do_niscall2 */
96 ++done;
97 break;
98 case NIS_UNAVAIL:
99 /* NIS+ is not installed, or all servers are down */
100 ++done;
101 break;
102 default:
103 /* Try the next domainname if we don't follow a link */
104 if (count_links)
106 free (req.ns_name);
107 res->status = NIS_LINKNAMEERROR;
108 ++done;
109 break;
111 ++name_nr;
112 if (names[name_nr] == NULL)
114 ++done;
115 break;
117 req.ns_name = names[name_nr];
118 break;
122 if (names != namebuf)
123 nis_freenames (names);
125 return res;