1 /* Copyright (c) 1997-2019 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 <https://www.gnu.org/licenses/>. */
20 #include <rpcsvc/nis.h>
21 #include <shlib-compat.h>
24 #include "nis_intern.h"
27 nis_getservlist (const_nis_name dir
)
32 res
= nis_lookup (dir
, FOLLOW_LINKS
);
34 if (res
!= NULL
&& NIS_RES_STATUS (res
) == NIS_SUCCESS
)
40 malloc (sizeof (nis_server
*) *
41 (NIS_RES_OBJECT (res
)->DI_data
.do_servers
.do_servers_len
+ 1));
42 if (__glibc_unlikely (serv
== NULL
))
48 for (i
= 0; i
< NIS_RES_OBJECT (res
)->DI_data
.do_servers
.do_servers_len
;
52 &NIS_RES_OBJECT (res
)->DI_data
.do_servers
.do_servers_val
[i
];
53 serv
[i
] = calloc (1, sizeof (nis_server
));
54 if (__glibc_unlikely (serv
[i
] == NULL
))
59 free (serv
[i
]->pkey
.n_bytes
);
60 if (serv
[i
]->ep
.ep_val
!= NULL
)
63 for (j
= 0; j
< serv
[i
]->ep
.ep_len
; ++j
)
65 free (serv
[i
]->ep
.ep_val
[j
].proto
);
66 free (serv
[i
]->ep
.ep_val
[j
].family
);
67 free (serv
[i
]->ep
.ep_val
[j
].uaddr
);
69 free (serv
[i
]->ep
.ep_val
);
82 if (server
->name
!= NULL
)
84 serv
[i
]->name
= strdup (server
->name
);
85 if (__glibc_unlikely (serv
[i
]->name
== NULL
))
92 serv
[i
]->ep
.ep_len
= server
->ep
.ep_len
;
93 if (serv
[i
]->ep
.ep_len
> 0)
98 malloc (server
->ep
.ep_len
* sizeof (endpoint
));
99 if (__glibc_unlikely (serv
[i
]->ep
.ep_val
== NULL
))
105 for (j
= 0; j
< serv
[i
]->ep
.ep_len
; ++j
)
107 if (server
->ep
.ep_val
[j
].uaddr
)
108 serv
[i
]->ep
.ep_val
[j
].uaddr
=
109 strdup (server
->ep
.ep_val
[j
].uaddr
);
111 serv
[i
]->ep
.ep_val
[j
].uaddr
= NULL
;
112 if (server
->ep
.ep_val
[j
].family
)
113 serv
[i
]->ep
.ep_val
[j
].family
=
114 strdup (server
->ep
.ep_val
[j
].family
);
116 serv
[i
]->ep
.ep_val
[j
].family
= NULL
;
117 if (server
->ep
.ep_val
[j
].proto
)
118 serv
[i
]->ep
.ep_val
[j
].proto
=
119 strdup (server
->ep
.ep_val
[j
].proto
);
121 serv
[i
]->ep
.ep_val
[j
].proto
= NULL
;
125 serv
[i
]->key_type
= server
->key_type
;
126 serv
[i
]->pkey
.n_len
= server
->pkey
.n_len
;
127 if (server
->pkey
.n_len
> 0)
129 serv
[i
]->pkey
.n_bytes
= malloc (server
->pkey
.n_len
);
130 if (__glibc_unlikely (serv
[i
]->pkey
.n_bytes
== NULL
))
135 memcpy (serv
[i
]->pkey
.n_bytes
, server
->pkey
.n_bytes
,
143 serv
= malloc (sizeof (nis_server
*));
144 if (__glibc_unlikely (serv
!= NULL
))
148 nis_freeresult (res
);
152 libnsl_hidden_nolink_def (nis_getservlist
, GLIBC_2_1
)
155 nis_freeservlist (nis_server
**serv
)
163 while (serv
[i
] != NULL
)
165 xdr_free ((xdrproc_t
)_xdr_nis_server
, (char *)serv
[i
]);
171 libnsl_hidden_nolink_def (nis_freeservlist
, GLIBC_2_1
)