Update.
[glibc.git] / nis / nis_getservlist.c
blobf88c156f898e3f9b930152ed6c4dfb9a4fe76318
1 /* Copyright (c) 1997, 1998 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.
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. */
20 #include <string.h>
21 #include <rpcsvc/nis.h>
23 #include "nis_xdr.h"
24 #include "nis_intern.h"
26 nis_server **
27 nis_getservlist (const_nis_name dir)
29 nis_result *res;
30 nis_server **serv;
32 res = nis_lookup (dir, FOLLOW_LINKS);
34 if (NIS_RES_STATUS (res) == NIS_SUCCESS)
36 unsigned long i;
37 nis_server *server;
39 serv =
40 calloc (1, sizeof (nis_server *) *
41 (NIS_RES_OBJECT (res)->DI_data.do_servers.do_servers_len + 1));
42 if (serv == NULL)
43 return NULL;
44 for (i = 0; i < NIS_RES_OBJECT (res)->DI_data.do_servers.do_servers_len;
45 ++i)
47 server =
48 &NIS_RES_OBJECT (res)->DI_data.do_servers.do_servers_val[i];
49 serv[i] = calloc (1, sizeof (nis_server));
50 if (server->name != NULL)
51 serv[i]->name = strdup (server->name);
53 serv[i]->ep.ep_len = server->ep.ep_len;
54 if (serv[i]->ep.ep_len > 0)
56 unsigned long j;
58 serv[i]->ep.ep_val =
59 malloc (server->ep.ep_len * sizeof (endpoint));
60 for (j = 0; j < serv[i]->ep.ep_len; ++j)
62 if (server->ep.ep_val[j].uaddr)
63 serv[i]->ep.ep_val[j].uaddr =
64 strdup (server->ep.ep_val[j].uaddr);
65 else
66 serv[i]->ep.ep_val[j].uaddr = NULL;
67 if (server->ep.ep_val[j].family)
68 serv[i]->ep.ep_val[j].family =
69 strdup (server->ep.ep_val[j].family);
70 else
71 serv[i]->ep.ep_val[j].family = NULL;
72 if (server->ep.ep_val[j].proto)
73 serv[i]->ep.ep_val[j].proto =
74 strdup (server->ep.ep_val[j].proto);
75 else
76 serv[i]->ep.ep_val[j].proto = NULL;
79 else
80 serv[i]->ep.ep_val = NULL;
81 serv[i]->key_type = server->key_type;
82 serv[i]->pkey.n_len = server->pkey.n_len;
83 if (server->pkey.n_len > 0)
85 serv[i]->pkey.n_bytes =
86 malloc (server->pkey.n_len);
87 if (serv[i]->pkey.n_bytes == NULL)
88 return NULL;
89 memcpy (serv[i]->pkey.n_bytes, server->pkey.n_bytes,
90 server->pkey.n_len);
92 else
93 serv[i]->pkey.n_bytes = NULL;
96 else
98 serv = malloc (sizeof (nis_server *));
99 if (serv != NULL)
100 serv[0] = NULL;
102 return serv;
105 void
106 nis_freeservlist (nis_server **serv)
108 int i;
110 if (serv == NULL)
111 return;
113 i = 0;
114 while (serv[i] != NULL)
116 xdr_free ((xdrproc_t)_xdr_nis_server, (char *)serv[i]);
117 free (serv[i]);
118 ++i;
120 free (serv);