]>
sourceware.org Git - glibc.git/blob - nis/nis_names.c
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
);
109 req
.ns_name
= (char *)name
;
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
;
166 char *p1
, *p2
, *p3
, *p4
;
167 char buf1
[strlen (name
) + 20];
168 char buf4
[strlen (name
) + 20];
170 res
= calloc (1, sizeof (nis_result
));
172 req
.ns_name
= (char *)name
;
174 req
.ns_object
.ns_object_len
= 1;
175 req
.ns_object
.ns_object_val
= nis_clone_object (obj
, NULL
);
177 p1
= req
.ns_object
.ns_object_val
[0].zo_name
;
178 req
.ns_object
.ns_object_val
[0].zo_name
=
179 nis_name_of_r (name
, buf1
, sizeof (buf1
));
181 p2
= req
.ns_object
.ns_object_val
[0].zo_owner
;
182 if (p2
== NULL
|| strlen (p2
) == 0)
183 req
.ns_object
.ns_object_val
[0].zo_owner
= nis_local_principal ();
185 p3
= req
.ns_object
.ns_object_val
[0].zo_group
;
186 if (p3
== NULL
|| strlen (p3
) == 0)
187 req
.ns_object
.ns_object_val
[0].zo_group
= nis_local_group ();
189 p4
= req
.ns_object
.ns_object_val
[0].zo_domain
;
190 req
.ns_object
.ns_object_val
[0].zo_domain
=
191 nis_domain_of_r (name
, buf4
, sizeof (buf4
));
193 if ((status
= __do_niscall (NULL
, 0, NIS_ADD
, (xdrproc_t
) xdr_ns_request
,
194 (caddr_t
) &req
, (xdrproc_t
) xdr_nis_result
,
195 (caddr_t
) res
, 0)) != RPC_SUCCESS
)
196 res
->status
= status
;
198 req
.ns_object
.ns_object_val
[0].zo_name
= p1
;
199 req
.ns_object
.ns_object_val
[0].zo_owner
= p2
;
200 req
.ns_object
.ns_object_val
[0].zo_group
= p3
;
201 req
.ns_object
.ns_object_val
[0].zo_domain
= p4
;
203 nis_destroy_object (req
.ns_object
.ns_object_val
);
209 nis_remove (const_nis_name name
, const nis_object
*obj
)
213 struct ns_request req
;
215 res
= calloc (1, sizeof (nis_result
));
217 req
.ns_name
= (char *)name
;
221 req
.ns_object
.ns_object_len
= 1;
222 req
.ns_object
.ns_object_val
= nis_clone_object (obj
, NULL
);
226 req
.ns_object
.ns_object_len
= 0;
227 req
.ns_object
.ns_object_val
= NULL
;
230 if ((status
= __do_niscall (NULL
, 0, NIS_REMOVE
, (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
);
241 nis_modify (const_nis_name name
, const nis_object
*obj
)
245 struct ns_request req
;
247 res
= calloc (1, sizeof (nis_result
));
249 req
.ns_name
= (char *)name
;
251 req
.ns_object
.ns_object_len
= 1;
252 req
.ns_object
.ns_object_val
= nis_clone_object (obj
, NULL
);
254 if ((status
= __do_niscall (NULL
, 0, NIS_MODIFY
, (xdrproc_t
) xdr_ns_request
,
255 (caddr_t
) & req
, (xdrproc_t
) xdr_nis_result
,
256 (caddr_t
) res
, 0)) != RPC_SUCCESS
)
257 res
->status
= status
;
259 nis_destroy_object (req
.ns_object
.ns_object_val
);
This page took 0.051179 seconds and 5 git commands to generate.