]>
Commit | Line | Data |
---|---|---|
843ede44 | 1 | /* Copyright (c) 1997, 1998, 1999 Free Software Foundation, Inc. |
51702635 UD |
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 <string.h> | |
21 | #include <rpcsvc/nis.h> | |
91eee4dd UD |
22 | |
23 | #include "nis_xdr.h" | |
51702635 UD |
24 | #include "nis_intern.h" |
25 | ||
26 | nis_server ** | |
27 | nis_getservlist (const_nis_name dir) | |
28 | { | |
29 | nis_result *res; | |
30 | nis_server **serv; | |
31 | ||
32 | res = nis_lookup (dir, FOLLOW_LINKS); | |
33 | ||
32abdb71 | 34 | if (res != NULL && NIS_RES_STATUS (res) == NIS_SUCCESS) |
51702635 UD |
35 | { |
36 | unsigned long i; | |
37 | nis_server *server; | |
38 | ||
dfd2257a | 39 | serv = |
843ede44 | 40 | malloc (sizeof (nis_server *) * |
dfd2257a | 41 | (NIS_RES_OBJECT (res)->DI_data.do_servers.do_servers_len + 1)); |
51702635 UD |
42 | if (serv == NULL) |
43 | return NULL; | |
32abdb71 | 44 | |
dfd2257a UD |
45 | for (i = 0; i < NIS_RES_OBJECT (res)->DI_data.do_servers.do_servers_len; |
46 | ++i) | |
51702635 UD |
47 | { |
48 | server = | |
dfd2257a | 49 | &NIS_RES_OBJECT (res)->DI_data.do_servers.do_servers_val[i]; |
714a562f | 50 | serv[i] = calloc (1, sizeof (nis_server)); |
51702635 | 51 | if (server->name != NULL) |
32abdb71 UD |
52 | { |
53 | serv[i]->name = strdup (server->name); | |
54 | if (serv[i]->name == NULL) | |
55 | return NULL; | |
56 | } | |
51702635 UD |
57 | |
58 | serv[i]->ep.ep_len = server->ep.ep_len; | |
59 | if (serv[i]->ep.ep_len > 0) | |
60 | { | |
843ede44 | 61 | unsigned long int j; |
51702635 UD |
62 | |
63 | serv[i]->ep.ep_val = | |
64 | malloc (server->ep.ep_len * sizeof (endpoint)); | |
843ede44 UD |
65 | if (serv[i]->ep.ep_val == NULL) |
66 | return NULL; | |
67 | ||
51702635 UD |
68 | for (j = 0; j < serv[i]->ep.ep_len; ++j) |
69 | { | |
70 | if (server->ep.ep_val[j].uaddr) | |
71 | serv[i]->ep.ep_val[j].uaddr = | |
72 | strdup (server->ep.ep_val[j].uaddr); | |
73 | else | |
74 | serv[i]->ep.ep_val[j].uaddr = NULL; | |
75 | if (server->ep.ep_val[j].family) | |
76 | serv[i]->ep.ep_val[j].family = | |
77 | strdup (server->ep.ep_val[j].family); | |
78 | else | |
79 | serv[i]->ep.ep_val[j].family = NULL; | |
80 | if (server->ep.ep_val[j].proto) | |
81 | serv[i]->ep.ep_val[j].proto = | |
82 | strdup (server->ep.ep_val[j].proto); | |
83 | else | |
84 | serv[i]->ep.ep_val[j].proto = NULL; | |
85 | } | |
86 | } | |
87 | else | |
88 | serv[i]->ep.ep_val = NULL; | |
89 | serv[i]->key_type = server->key_type; | |
90 | serv[i]->pkey.n_len = server->pkey.n_len; | |
91 | if (server->pkey.n_len > 0) | |
92 | { | |
93 | serv[i]->pkey.n_bytes = | |
94 | malloc (server->pkey.n_len); | |
95 | if (serv[i]->pkey.n_bytes == NULL) | |
96 | return NULL; | |
97 | memcpy (serv[i]->pkey.n_bytes, server->pkey.n_bytes, | |
98 | server->pkey.n_len); | |
99 | } | |
100 | else | |
101 | serv[i]->pkey.n_bytes = NULL; | |
102 | } | |
843ede44 | 103 | serv[i] = NULL; |
51702635 UD |
104 | } |
105 | else | |
106 | { | |
107 | serv = malloc (sizeof (nis_server *)); | |
108 | if (serv != NULL) | |
109 | serv[0] = NULL; | |
110 | } | |
32abdb71 UD |
111 | |
112 | if (res != NULL) | |
113 | nis_freeresult (res); | |
114 | ||
51702635 UD |
115 | return serv; |
116 | } | |
117 | ||
118 | void | |
119 | nis_freeservlist (nis_server **serv) | |
120 | { | |
121 | int i; | |
122 | ||
123 | if (serv == NULL) | |
124 | return; | |
125 | ||
126 | i = 0; | |
127 | while (serv[i] != NULL) | |
714a562f | 128 | { |
91eee4dd | 129 | xdr_free ((xdrproc_t)_xdr_nis_server, (char *)serv[i]); |
714a562f UD |
130 | free (serv[i]); |
131 | ++i; | |
132 | } | |
51702635 UD |
133 | free (serv); |
134 | } |