Add point for gconv-modules db.
[glibc.git] / nis / nis_lookup.c
blob6a2198ac2147eb2744dfcc28d62d9260e2862933
1 /* Copyright (C) 1997, 1998 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>
22 #include "nis_xdr.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));
38 if (res == NULL)
39 return NULL;
41 if (flags & EXPAND_NAME)
43 names = nis_getnames (name);
44 if (names == NULL)
46 NIS_RES_STATUS (res) = NIS_NAMEUNREACHABLE;
47 return res;
50 else
52 names = namebuf;
53 names[0] = (nis_name)name;
56 req.ns_name = names[0];
57 while (!done)
59 req.ns_object.ns_object_len = 0;
60 req.ns_object.ns_object_val = NULL;
61 memset (res, '\0', sizeof (nis_result));
63 status = __do_niscall (req.ns_name, NIS_LOOKUP,
64 (xdrproc_t) _xdr_ns_request,
65 (caddr_t) & req,
66 (xdrproc_t) _xdr_nis_result,
67 (caddr_t) res, flags, NULL);
68 if (status != NIS_SUCCESS)
69 NIS_RES_STATUS (res) = status;
71 switch (NIS_RES_STATUS (res))
73 case NIS_PARTIAL:
74 case NIS_SUCCESS:
75 case NIS_S_SUCCESS:
76 if (__type_of(NIS_RES_OBJECT (res)) == NIS_LINK_OBJ &&
77 flags & FOLLOW_LINKS) /* We are following links */
79 /* if we hit the link limit, bail */
80 if (count_links > NIS_MAXLINKS)
82 NIS_RES_STATUS (res) = NIS_LINKNAMEERROR;
83 ++done;
84 break;
86 if (count_links)
87 free (req.ns_name);
88 ++count_links;
89 req.ns_name = strdup (NIS_RES_OBJECT (res)->LI_data.li_name);
90 nis_freeresult (res);
91 res = calloc (1, sizeof (nis_result));
92 if (res == NULL)
93 return NULL;
95 else
96 ++done;
97 break;
98 case NIS_CBRESULTS:
99 /* The callback is handled in __do_niscall2 */
100 ++done;
101 break;
102 case NIS_UNAVAIL:
103 /* NIS+ is not installed, or all servers are down */
104 ++done;
105 break;
106 default:
107 /* Try the next domainname if we don't follow a link */
108 if (count_links)
110 free (req.ns_name);
111 NIS_RES_STATUS (res) = NIS_LINKNAMEERROR;
112 ++done;
113 break;
115 ++name_nr;
116 if (names[name_nr] == NULL)
118 ++done;
119 break;
121 req.ns_name = names[name_nr];
122 break;
126 if (names != namebuf)
127 nis_freenames (names);
129 return res;