1 /* Copyright (c) 1997-2014 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 Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the 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 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
20 #include <rpcsvc/nis.h>
23 #include "nis_intern.h"
26 nis_getservlist (const_nis_name dir
)
31 res
= nis_lookup (dir
, FOLLOW_LINKS
);
33 if (res
!= NULL
&& NIS_RES_STATUS (res
) == NIS_SUCCESS
)
39 malloc (sizeof (nis_server
*) *
40 (NIS_RES_OBJECT (res
)->DI_data
.do_servers
.do_servers_len
+ 1));
41 if (__glibc_unlikely (serv
== NULL
))
47 for (i
= 0; i
< NIS_RES_OBJECT (res
)->DI_data
.do_servers
.do_servers_len
;
51 &NIS_RES_OBJECT (res
)->DI_data
.do_servers
.do_servers_val
[i
];
52 serv
[i
] = calloc (1, sizeof (nis_server
));
53 if (__glibc_unlikely (serv
[i
] == NULL
))
58 free (serv
[i
]->pkey
.n_bytes
);
59 if (serv
[i
]->ep
.ep_val
!= NULL
)
62 for (j
= 0; j
< serv
[i
]->ep
.ep_len
; ++j
)
64 free (serv
[i
]->ep
.ep_val
[j
].proto
);
65 free (serv
[i
]->ep
.ep_val
[j
].family
);
66 free (serv
[i
]->ep
.ep_val
[j
].uaddr
);
68 free (serv
[i
]->ep
.ep_val
);
81 if (server
->name
!= NULL
)
83 serv
[i
]->name
= strdup (server
->name
);
84 if (__glibc_unlikely (serv
[i
]->name
== NULL
))
91 serv
[i
]->ep
.ep_len
= server
->ep
.ep_len
;
92 if (serv
[i
]->ep
.ep_len
> 0)
97 malloc (server
->ep
.ep_len
* sizeof (endpoint
));
98 if (__glibc_unlikely (serv
[i
]->ep
.ep_val
== NULL
))
104 for (j
= 0; j
< serv
[i
]->ep
.ep_len
; ++j
)
106 if (server
->ep
.ep_val
[j
].uaddr
)
107 serv
[i
]->ep
.ep_val
[j
].uaddr
=
108 strdup (server
->ep
.ep_val
[j
].uaddr
);
110 serv
[i
]->ep
.ep_val
[j
].uaddr
= NULL
;
111 if (server
->ep
.ep_val
[j
].family
)
112 serv
[i
]->ep
.ep_val
[j
].family
=
113 strdup (server
->ep
.ep_val
[j
].family
);
115 serv
[i
]->ep
.ep_val
[j
].family
= NULL
;
116 if (server
->ep
.ep_val
[j
].proto
)
117 serv
[i
]->ep
.ep_val
[j
].proto
=
118 strdup (server
->ep
.ep_val
[j
].proto
);
120 serv
[i
]->ep
.ep_val
[j
].proto
= NULL
;
124 serv
[i
]->key_type
= server
->key_type
;
125 serv
[i
]->pkey
.n_len
= server
->pkey
.n_len
;
126 if (server
->pkey
.n_len
> 0)
128 serv
[i
]->pkey
.n_bytes
= malloc (server
->pkey
.n_len
);
129 if (__glibc_unlikely (serv
[i
]->pkey
.n_bytes
== NULL
))
134 memcpy (serv
[i
]->pkey
.n_bytes
, server
->pkey
.n_bytes
,
142 serv
= malloc (sizeof (nis_server
*));
143 if (__glibc_unlikely (serv
!= NULL
))
147 nis_freeresult (res
);
153 nis_freeservlist (nis_server
**serv
)
161 while (serv
[i
] != NULL
)
163 xdr_free ((xdrproc_t
)_xdr_nis_server
, (char *)serv
[i
]);