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. */
21 #include <rpcsvc/nis.h>
22 #include <rpcsvc/nislib.h>
24 #include "nis_intern.h"
27 nis_lookup (const_nis_name name
, const u_long flags
)
30 struct ns_request req
;
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 */
37 res
= calloc (1, sizeof (nis_result
));
39 if (flags
& EXPAND_NAME
)
41 names
= __nis_expandname (name
);
44 res
->status
= NIS_NAMEUNREACHABLE
;
49 while (names
[i
] != NULL
&& (i
== 0 || res
->status
> 1))
51 req
.ns_name
= names
[i
];
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
,
62 (xdrproc_t
) xdr_nis_result
,
63 (caddr_t
) res
, flags
)) != RPC_SUCCESS
)
66 nis_freenames (names
);
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
))
79 if ((flags
& FOLLOW_LINKS
) == FOLLOW_LINKS
)
81 if (count_links
== 16)
83 res
->status
= NIS_LINKNAMEERROR
;
89 req
.ns_name
= res
->objects
.objects_val
->LI_data
.li_name
;
93 res
->status
= NIS_NOTSEARCHABLE
;
100 if (res
->status
== NIS_NOT_ME
)
101 res
->status
= NIS_NOSUCHNAME
;
104 nis_freenames (names
);
108 req
.ns_name
= (char *)name
;
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
,
119 (xdrproc_t
) xdr_nis_result
,
120 (caddr_t
) res
, flags
)) != RPC_SUCCESS
)
122 res
->status
= status
;
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
))
135 if ((flags
& FOLLOW_LINKS
) == FOLLOW_LINKS
)
137 if (count_links
== 16)
139 res
->status
= NIS_LINKNAMEERROR
;
145 req
.ns_name
= res
->objects
.objects_val
->LI_data
.li_name
;
149 res
->status
= NIS_NOTSEARCHABLE
;