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. */
22 #include <rpcsvc/nis.h>
23 #include <rpcsvc/nislib.h>
25 #include "nis_intern.h"
28 nis_lookup (const nis_name name
, const u_long flags
)
31 struct ns_request req
;
34 int is_link
= 1; /* We should go at least once in the while loop */
35 int count_links
= 0; /* We will follow only 16 links in the deep */
38 res
= calloc (1, sizeof (nis_result
));
40 if (flags
& EXPAND_NAME
)
42 names
= __nis_expandname (name
);
45 res
->status
= NIS_NAMEUNREACHABLE
;
50 while (names
[i
] != NULL
&& (i
== 0 || res
->status
> 1))
52 req
.ns_name
= names
[i
];
56 req
.ns_object
.ns_object_len
= 0;
57 req
.ns_object
.ns_object_val
= NULL
;
58 memset (res
, '\0', sizeof (nis_result
));
60 if ((status
= __do_niscall (NULL
, 0, NIS_LOOKUP
,
61 (xdrproc_t
) xdr_ns_request
,
63 (xdrproc_t
) xdr_nis_result
,
64 (caddr_t
) res
, flags
)) != RPC_SUCCESS
)
67 nis_freenames (names
);
71 if ((res
->status
== NIS_SUCCESS
|| res
->status
== NIS_S_SUCCESS
)
72 && (res
->objects
.objects_len
> 0 &&
73 res
->objects
.objects_val
->zo_data
.zo_type
== LINK_OBJ
))
80 if ((flags
& FOLLOW_LINKS
) == FOLLOW_LINKS
)
82 if (count_links
== 16)
84 res
->status
= NIS_LINKNAMEERROR
;
90 req
.ns_name
= res
->objects
.objects_val
->LI_data
.li_name
;
94 res
->status
= NIS_NOTSEARCHABLE
;
101 if (res
->status
== NIS_NOT_ME
)
102 res
->status
= NIS_NOSUCHNAME
;
105 nis_freenames (names
);
113 req
.ns_object
.ns_object_len
= 0;
114 req
.ns_object
.ns_object_val
= NULL
;
115 memset (res
, '\0', sizeof (nis_result
));
117 if ((status
= __do_niscall (NULL
, 0, NIS_LOOKUP
,
118 (xdrproc_t
) xdr_ns_request
,
120 (xdrproc_t
) xdr_nis_result
,
121 (caddr_t
) res
, flags
)) != RPC_SUCCESS
)
123 res
->status
= status
;
127 if ((res
->status
== NIS_SUCCESS
|| res
->status
== NIS_S_SUCCESS
) &&
128 (res
->objects
.objects_len
> 0 &&
129 res
->objects
.objects_val
->zo_data
.zo_type
== LINK_OBJ
))
136 if ((flags
& FOLLOW_LINKS
) == FOLLOW_LINKS
)
138 if (count_links
== 16)
140 res
->status
= NIS_LINKNAMEERROR
;
146 req
.ns_name
= res
->objects
.objects_val
->LI_data
.li_name
;
150 res
->status
= NIS_NOTSEARCHABLE
;
161 nis_add (const nis_name name
, const nis_object
*obj
)
165 struct ns_request req
;
167 res
= calloc (1, sizeof (nis_result
));
171 req
.ns_object
.ns_object_len
= 1;
172 req
.ns_object
.ns_object_val
= nis_clone_object (obj
, NULL
);
174 if ((status
= __do_niscall (NULL
, 0, NIS_ADD
, (xdrproc_t
) xdr_ns_request
,
175 (caddr_t
) & req
, (xdrproc_t
) xdr_nis_result
,
176 (caddr_t
) res
, 0)) != RPC_SUCCESS
)
177 res
->status
= status
;
179 nis_destroy_object (req
.ns_object
.ns_object_val
);
185 nis_remove (const nis_name name
, const nis_object
*obj
)
189 struct ns_request req
;
191 res
= calloc (1, sizeof (nis_result
));
197 req
.ns_object
.ns_object_len
= 1;
198 req
.ns_object
.ns_object_val
= nis_clone_object (obj
, NULL
);
202 req
.ns_object
.ns_object_len
= 0;
203 req
.ns_object
.ns_object_val
= NULL
;
206 if ((status
= __do_niscall (NULL
, 0, NIS_REMOVE
, (xdrproc_t
) xdr_ns_request
,
207 (caddr_t
) & req
, (xdrproc_t
) xdr_nis_result
,
208 (caddr_t
) res
, 0)) != RPC_SUCCESS
)
209 res
->status
= status
;
211 nis_destroy_object (req
.ns_object
.ns_object_val
);
217 nis_modify (const nis_name name
, const nis_object
*obj
)
221 struct ns_request req
;
223 res
= calloc (1, sizeof (nis_result
));
227 req
.ns_object
.ns_object_len
= 1;
228 req
.ns_object
.ns_object_val
= nis_clone_object (obj
, NULL
);
230 if ((status
= __do_niscall (NULL
, 0, NIS_MODIFY
, (xdrproc_t
) xdr_ns_request
,
231 (caddr_t
) & req
, (xdrproc_t
) xdr_nis_result
,
232 (caddr_t
) res
, 0)) != RPC_SUCCESS
)
233 res
->status
= status
;
235 nis_destroy_object (req
.ns_object
.ns_object_val
);