1 /* Copyright (c) 1997, 1998, 1999, 2000 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, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21 #include <rpcsvc/nis.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 (__builtin_expect (serv
== NULL
, 0))
45 for (i
= 0; i
< NIS_RES_OBJECT (res
)->DI_data
.do_servers
.do_servers_len
;
49 &NIS_RES_OBJECT (res
)->DI_data
.do_servers
.do_servers_val
[i
];
50 serv
[i
] = calloc (1, sizeof (nis_server
));
51 if (__builtin_expect (serv
[i
] == NULL
, 0))
54 if (server
->name
!= NULL
)
56 serv
[i
]->name
= strdup (server
->name
);
57 if (__builtin_expect (serv
[i
]->name
== NULL
, 0))
61 serv
[i
]->ep
.ep_len
= server
->ep
.ep_len
;
62 if (serv
[i
]->ep
.ep_len
> 0)
67 malloc (server
->ep
.ep_len
* sizeof (endpoint
));
68 if (__builtin_expect (serv
[i
]->ep
.ep_val
== NULL
, 0))
71 for (j
= 0; j
< serv
[i
]->ep
.ep_len
; ++j
)
73 if (server
->ep
.ep_val
[j
].uaddr
)
74 serv
[i
]->ep
.ep_val
[j
].uaddr
=
75 strdup (server
->ep
.ep_val
[j
].uaddr
);
77 serv
[i
]->ep
.ep_val
[j
].uaddr
= NULL
;
78 if (server
->ep
.ep_val
[j
].family
)
79 serv
[i
]->ep
.ep_val
[j
].family
=
80 strdup (server
->ep
.ep_val
[j
].family
);
82 serv
[i
]->ep
.ep_val
[j
].family
= NULL
;
83 if (server
->ep
.ep_val
[j
].proto
)
84 serv
[i
]->ep
.ep_val
[j
].proto
=
85 strdup (server
->ep
.ep_val
[j
].proto
);
87 serv
[i
]->ep
.ep_val
[j
].proto
= NULL
;
91 serv
[i
]->ep
.ep_val
= NULL
;
92 serv
[i
]->key_type
= server
->key_type
;
93 serv
[i
]->pkey
.n_len
= server
->pkey
.n_len
;
94 if (server
->pkey
.n_len
> 0)
96 serv
[i
]->pkey
.n_bytes
= malloc (server
->pkey
.n_len
);
97 if (__builtin_expect (serv
[i
]->pkey
.n_bytes
== NULL
, 0))
99 memcpy (serv
[i
]->pkey
.n_bytes
, server
->pkey
.n_bytes
,
103 serv
[i
]->pkey
.n_bytes
= NULL
;
109 serv
= malloc (sizeof (nis_server
*));
110 if (__builtin_expect (serv
!= NULL
, 0))
115 nis_freeresult (res
);
121 nis_freeservlist (nis_server
**serv
)
129 while (serv
[i
] != NULL
)
131 xdr_free ((xdrproc_t
)_xdr_nis_server
, (char *)serv
[i
]);