Update.
[glibc.git] / nis / nis_lookup.c
blob6f5b12b2857522754d38cf22c1007c27dfda1c65
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>
22 #include <rpcsvc/nislib.h>
24 #include "nis_intern.h"
26 nis_result *
27 nis_lookup (const_nis_name name, const u_long flags)
29 nis_result *res;
30 struct ns_request req;
31 nis_name *names;
32 nis_error status;
33 int is_link = 1; /* We should go at least once in the while loop */
34 int count_links = 0; /* We will follow only 16 links in the deep */
35 int i;
37 res = calloc (1, sizeof (nis_result));
39 if (flags & EXPAND_NAME)
41 names = __nis_expandname (name);
42 if (names == NULL)
44 res->status = NIS_NAMEUNREACHABLE;
45 return res;
48 i = 0;
49 while (names[i] != NULL && (i == 0 || res->status > 1))
51 req.ns_name = names[i];
53 while (is_link)
55 req.ns_object.ns_object_len = 0;
56 req.ns_object.ns_object_val = NULL;
57 memset (res, '\0', sizeof (nis_result));
59 if ((status = __do_niscall (req.ns_name, NIS_LOOKUP,
60 (xdrproc_t) xdr_ns_request,
61 (caddr_t) & req,
62 (xdrproc_t) xdr_nis_result,
63 (caddr_t) res, flags)) != RPC_SUCCESS)
65 res->status = status;
66 nis_freenames (names);
67 return res;
70 if ((res->status == NIS_SUCCESS || res->status == NIS_S_SUCCESS)
71 && (res->objects.objects_len > 0 &&
72 res->objects.objects_val->zo_data.zo_type == LINK_OBJ))
73 is_link = 1;
74 else
75 is_link = 0;
77 if (is_link)
79 if ((flags & FOLLOW_LINKS) == FOLLOW_LINKS)
81 if (count_links == 16)
83 res->status = NIS_LINKNAMEERROR;
84 return res;
86 else
87 ++count_links;
89 req.ns_name = res->objects.objects_val->LI_data.li_name;
91 else
93 res->status = NIS_NOTSEARCHABLE;
94 return res;
99 ++i;
100 if (res->status == NIS_NOT_ME)
101 res->status = NIS_NOSUCHNAME;
104 nis_freenames (names);
106 else
108 req.ns_name = (char *)name;
110 while (is_link)
112 req.ns_object.ns_object_len = 0;
113 req.ns_object.ns_object_val = NULL;
114 memset (res, '\0', sizeof (nis_result));
116 if ((status = __do_niscall (req.ns_name, NIS_LOOKUP,
117 (xdrproc_t) xdr_ns_request,
118 (caddr_t) &req,
119 (xdrproc_t) xdr_nis_result,
120 (caddr_t) res, flags)) != RPC_SUCCESS)
122 res->status = status;
123 return res;
126 if ((res->status == NIS_SUCCESS || res->status == NIS_S_SUCCESS) &&
127 (res->objects.objects_len > 0 &&
128 res->objects.objects_val->zo_data.zo_type == LINK_OBJ))
129 is_link = 1;
130 else
131 is_link = 0;
133 if (is_link)
135 if ((flags & FOLLOW_LINKS) == FOLLOW_LINKS)
137 if (count_links == 16)
139 res->status = NIS_LINKNAMEERROR;
140 return res;
142 else
143 ++count_links;
145 req.ns_name = res->objects.objects_val->LI_data.li_name;
147 else
149 res->status = NIS_NOTSEARCHABLE;
150 return res;
156 return res;