]> git.ipfire.org Git - thirdparty/glibc.git/blame - nis/nis_free.c
Update.
[thirdparty/glibc.git] / nis / nis_free.c
CommitLineData
e61abf83
UD
1/* Copyright (c) 1997 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1997.
4
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.
9
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.
14
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. */
19
20#include <rpcsvc/nis.h>
21#include <rpcsvc/nislib.h>
22
23void
24nis_free_attr (nis_attr *obj)
25{
26 if (obj == NULL)
27 return;
28
29 if (obj->zattr_ndx)
30 {
31 free (obj->zattr_ndx);
32 obj->zattr_ndx = NULL;
33 }
34
35 if (obj->zattr_val.zattr_val_val)
36 {
37 free (obj->zattr_val.zattr_val_val);
38 obj->zattr_val.zattr_val_val = NULL;
39 obj->zattr_val.zattr_val_len = 0;
40 }
41}
42
43void
44nis_free_request (ib_request *ibreq)
45{
46 unsigned int i;
47
48 for (i = 0; i < ibreq->ibr_srch.ibr_srch_len; ++i)
49 {
50 nis_free_attr (&(ibreq->ibr_srch.ibr_srch_val)[i]);
51 ibreq->ibr_srch.ibr_srch_val = NULL;
52 ibreq->ibr_srch.ibr_srch_len = 0;
53 }
54
55 if (ibreq->ibr_name)
56 {
57 free (ibreq->ibr_name);
58 ibreq->ibr_name = NULL;
59 }
60
61 if (ibreq->ibr_cookie.n_bytes)
62 {
63 free (ibreq->ibr_cookie.n_bytes);
64 ibreq->ibr_cookie.n_bytes = NULL;
65 ibreq->ibr_cookie.n_len = 0;
66 }
67}
68
69void
5ae9d168 70nis_free_endpoints (endpoint *ep, unsigned int len)
e61abf83
UD
71{
72 int i;
73
74 if (ep == NULL)
75 return;
76
77 for (i = 0; i < len; ++i)
78 {
79 if (ep[i].uaddr)
80 {
81 free (ep[i].uaddr);
82 ep[i].uaddr = NULL;
83 }
84 if (ep[i].family)
85 {
86 free (ep[i].family);
87 ep[i].family = NULL;
88 }
89 if (ep[i].proto)
90 {
91 free (ep[i].proto);
92 ep[i].proto = NULL;
93 }
94 }
95}
96
97void
5ae9d168 98nis_free_servers (nis_server *obj, unsigned int len)
e61abf83
UD
99{
100 int i;
101
102 if (obj == NULL)
103 return;
104
105 for (i = 0; i < len; i++)
106 {
107 if (obj[i].name)
108 {
109 free (obj[i].name);
110 obj[i].name = NULL;
111 }
112 if (obj[i].ep.ep_len > 0)
113 {
114 nis_free_endpoints (obj[i].ep.ep_val, obj[i].ep.ep_len);
115 free (obj[i].ep.ep_val);
116 obj[i].ep.ep_val = NULL;
117 obj[i].ep.ep_len = 0;
118 }
119 if (obj[i].pkey.n_bytes && obj[i].pkey.n_len > 0)
120 {
121 free (obj[i].pkey.n_bytes);
122 obj[i].pkey.n_bytes = NULL;
123 obj[i].pkey.n_len = 0;
124 }
125 }
126}
127
128void
129nis_free_directory (directory_obj *obj)
130{
131 if (obj == NULL)
132 return;
133 if (obj->do_name)
134 {
135 free (obj->do_name);
136 obj->do_name = NULL;
137 }
138 if (obj->do_servers.do_servers_len > 0)
139 {
140 nis_free_servers (obj->do_servers.do_servers_val,
141 obj->do_servers.do_servers_len);
142 free (obj->do_servers.do_servers_val);
143 obj->do_servers.do_servers_val = NULL;
144 obj->do_servers.do_servers_len = 0;
145 }
146 if (obj->do_armask.do_armask_len > 0)
147 {
148 free (obj->do_armask.do_armask_val);
149 obj->do_armask.do_armask_val = NULL;
150 obj->do_armask.do_armask_len = 0;
151 }
152}
153
154void
155nis_free_group (group_obj *obj)
156{
157 unsigned int i;
158
159 if (obj->gr_members.gr_members_len > 0)
160 {
161 for (i = 0; i < obj->gr_members.gr_members_len; ++i)
162 if (obj->gr_members.gr_members_val[i])
163 free (obj->gr_members.gr_members_val[i]);
164 free (obj->gr_members.gr_members_val);
165 obj->gr_members.gr_members_val = NULL;
166 obj->gr_members.gr_members_len = 0;
167 }
168}
169
170void
171nis_free_table (table_obj *obj)
172{
173 if (obj == NULL)
174 return;
175
176 if (obj->ta_type)
177 {
178 free (obj->ta_type);
179 obj->ta_type = NULL;
180 }
181
182 if (obj->ta_cols.ta_cols_val)
183 {
184 unsigned int i;
185
186 for (i = 0; i < obj->ta_cols.ta_cols_len; ++i)
187 if (obj->ta_cols.ta_cols_val[i].tc_name)
188 free (obj->ta_cols.ta_cols_val[i].tc_name);
189 free (obj->ta_cols.ta_cols_val);
190 obj->ta_cols.ta_cols_val = NULL;
191 obj->ta_cols.ta_cols_len = 0;
192 }
193
194 if (obj->ta_path)
195 {
196 free (obj->ta_path);
197 obj->ta_path = NULL;
198 }
199}
200
201void
202nis_free_entry (entry_obj *obj)
203{
204 if (obj == NULL)
205 return;
206
207 if (obj->en_type)
208 {
209 free (obj->en_type);
210 obj->en_type = 0;
211 }
212
213 if (obj->en_cols.en_cols_val)
214 {
215 unsigned int i;
216
217 for (i = 0; i < obj->en_cols.en_cols_len; ++i)
218 if (obj->en_cols.en_cols_val[i].ec_value.ec_value_val)
219 free (obj->en_cols.en_cols_val[i].ec_value.ec_value_val);
220 free (obj->en_cols.en_cols_val);
221 obj->en_cols.en_cols_val = NULL;
222 obj->en_cols.en_cols_len = 0;
223 }
224}
225
226void
227nis_free_link (link_obj *obj)
228{
229 if (obj == NULL)
230 return;
231
232 if (obj->li_attrs.li_attrs_val)
233 {
234 unsigned int i;
235
236 for (i = 0; i < obj->li_attrs.li_attrs_len; ++i)
237 {
238 if (obj->li_attrs.li_attrs_val[i].zattr_ndx)
239 free (obj->li_attrs.li_attrs_val[i].zattr_ndx);
240 if (obj->li_attrs.li_attrs_val[i].zattr_val.zattr_val_val)
241 free (obj->li_attrs.li_attrs_val[i].zattr_val.zattr_val_val);
242 }
243 free (obj->li_attrs.li_attrs_val);
244 obj->li_attrs.li_attrs_val = NULL;
245 obj->li_attrs.li_attrs_len = 0;
246 }
247
248 if (obj->li_name)
249 {
250 free (obj->li_name);
251 obj->li_name = NULL;
252 }
253}
254
255void
256nis_free_object (nis_object *obj)
257{
258
259 if (obj == NULL)
260 return;
261
262 if (obj->zo_name)
263 {
264 free (obj->zo_name);
265 obj->zo_name = NULL;
266 }
267 if (obj->zo_owner)
268 {
269 free (obj->zo_owner);
270 obj->zo_owner = NULL;
271 }
272 if (obj->zo_group)
273 {
274 free (obj->zo_group);
275 obj->zo_group = NULL;
276 }
277 if (obj->zo_domain)
278 {
279 free (obj->zo_domain);
280 obj->zo_domain = NULL;
281 }
282 switch (obj->zo_data.zo_type)
283 {
284 case BOGUS_OBJ:
285 break;
286 case NO_OBJ:
287 break;
288 case DIRECTORY_OBJ:
289 nis_free_directory (&obj->zo_data.objdata_u.di_data);
290 break;
291 case GROUP_OBJ:
292 nis_free_group (&obj->zo_data.objdata_u.gr_data);
293 break;
294 case TABLE_OBJ:
295 nis_free_table (&obj->zo_data.objdata_u.ta_data);
296 break;
297 case ENTRY_OBJ:
298 nis_free_entry (&obj->zo_data.objdata_u.en_data);
299 break;
300 case LINK_OBJ:
301 nis_free_link (&obj->zo_data.objdata_u.li_data);
302 break;
303 case PRIVATE_OBJ:
304 if (obj->zo_data.objdata_u.po_data.po_data_val)
305 {
306 free (obj->zo_data.objdata_u.po_data.po_data_val);
307 obj->zo_data.objdata_u.po_data.po_data_val = NULL;
308 }
309 break;
310 default:
311 break;
312 }
313 obj->zo_data.zo_type = NO_OBJ;
314}
315
316void
317nis_freeresult (nis_result *res)
318{
319 unsigned int i;
320
321 if (res == NULL)
322 return;
323
324 for (i = 0; i < res->objects.objects_len; i++)
325 nis_free_object (&(res->objects.objects_val)[i]);
326
327 if (res->objects.objects_val != NULL)
328 free (res->objects.objects_val);
329
330 if (res->cookie.n_bytes != NULL && res->cookie.n_len > 0)
331 free (res->cookie.n_bytes);
332
333 free (res);
334}