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. */
21 #include <rpcsvc/nis.h>
23 #include "nis_intern.h"
26 nis_lookup (const_nis_name name
, const u_long flags
)
29 struct ns_request req
;
32 int count_links
= 0; /* We will follow only 16 links in the deep */
35 nis_name namebuf
[2] = {NULL
, NULL
};
37 res
= calloc (1, sizeof (nis_result
));
41 if (flags
& EXPAND_NAME
)
43 names
= nis_getnames (name
);
46 NIS_RES_STATUS (res
) = NIS_NAMEUNREACHABLE
;
53 names
[0] = (nis_name
)name
;
56 req
.ns_name
= names
[0];
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
,
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
))
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
;
89 req
.ns_name
= strdup (NIS_RES_OBJECT (res
)->LI_data
.li_name
);
91 res
= calloc (1, sizeof (nis_result
));
99 /* The callback is handled in __do_niscall2 */
103 /* NIS+ is not installed, or all servers are down */
107 /* Try the next domainname if we don't follow a link */
111 NIS_RES_STATUS (res
) = NIS_LINKNAMEERROR
;
116 if (names
[name_nr
] == NULL
)
121 req
.ns_name
= names
[name_nr
];
126 if (names
!= namebuf
)
127 nis_freenames (names
);