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>
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
));
39 if (flags
& EXPAND_NAME
)
41 names
= nis_getnames (name
);
44 res
->status
= NIS_NAMEUNREACHABLE
;
51 names
[0] = (nis_name
) name
;
54 req
.ns_name
= names
[0];
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
,
64 (xdrproc_t
) xdr_nis_result
,
65 (caddr_t
) res
, flags
, NULL
);
66 if (status
!= NIS_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
;
87 req
.ns_name
= strdup (NIS_RES_OBJECT (res
)->LI_data
.li_name
);
89 res
= calloc (1, sizeof (nis_result
));
95 /* The callback is handled in __do_niscall2 */
99 /* NIS+ is not installed, or all servers are down */
103 /* Try the next domainname if we don't follow a link */
107 res
->status
= NIS_LINKNAMEERROR
;
112 if (names
[name_nr
] == NULL
)
117 req
.ns_name
= names
[name_nr
];
122 if (names
!= namebuf
)
123 nis_freenames (names
);