update from main archive 970619
[glibc/history.git] / nis / nis_getservlist.c
blobb30b70b584f38f7a02f300f3fe146c6d9117582e
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.
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>
22 #include <rpcsvc/nislib.h>
23 #include "nis_intern.h"
25 nis_server **
26 nis_getservlist (const_nis_name dir)
28 nis_result *res;
29 nis_server **serv;
31 res = nis_lookup (dir, FOLLOW_LINKS);
33 if (res->status == NIS_SUCCESS || res->status == NIS_S_SUCCESS)
35 unsigned long i;
36 nis_server *server;
38 serv = calloc (1, sizeof (nis_server *) *
39 (res->objects.objects_val->DI_data.do_servers.do_servers_len + 1));
40 if (serv == NULL)
41 return NULL;
42 for (i = 0; i < res->objects.objects_val->DI_data.do_servers.do_servers_len; ++i)
44 server =
45 &res->objects.objects_val->DI_data.do_servers.do_servers_val[i];
46 serv[i] = calloc (1, sizeof (nis_server));
47 if (server->name != NULL)
48 serv[i]->name = strdup (server->name);
50 serv[i]->ep.ep_len = server->ep.ep_len;
51 if (serv[i]->ep.ep_len > 0)
53 unsigned long j;
55 serv[i]->ep.ep_val =
56 malloc (server->ep.ep_len * sizeof (endpoint));
57 for (j = 0; j < serv[i]->ep.ep_len; ++j)
59 if (server->ep.ep_val[j].uaddr)
60 serv[i]->ep.ep_val[j].uaddr =
61 strdup (server->ep.ep_val[j].uaddr);
62 else
63 serv[i]->ep.ep_val[j].uaddr = NULL;
64 if (server->ep.ep_val[j].family)
65 serv[i]->ep.ep_val[j].family =
66 strdup (server->ep.ep_val[j].family);
67 else
68 serv[i]->ep.ep_val[j].family = NULL;
69 if (server->ep.ep_val[j].proto)
70 serv[i]->ep.ep_val[j].proto =
71 strdup (server->ep.ep_val[j].proto);
72 else
73 serv[i]->ep.ep_val[j].proto = NULL;
76 else
77 serv[i]->ep.ep_val = NULL;
78 serv[i]->key_type = server->key_type;
79 serv[i]->pkey.n_len = server->pkey.n_len;
80 if (server->pkey.n_len > 0)
82 serv[i]->pkey.n_bytes =
83 malloc (server->pkey.n_len);
84 if (serv[i]->pkey.n_bytes == NULL)
85 return NULL;
86 memcpy (serv[i]->pkey.n_bytes, server->pkey.n_bytes,
87 server->pkey.n_len);
89 else
90 serv[i]->pkey.n_bytes = NULL;
93 else
95 serv = malloc (sizeof (nis_server *));
96 if (serv != NULL)
97 serv[0] = NULL;
99 return serv;
102 void
103 nis_freeservlist (nis_server **serv)
105 int i;
107 if (serv == NULL)
108 return;
110 i = 0;
111 while (serv[i] != NULL)
113 nis_free_servers (serv[i], 1);
114 free (serv[i]);
115 ++i;
117 free (serv);