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. */
24 #include <libc-lock.h>
25 #include <rpc/netdb.h>
26 #include <rpcsvc/nis.h>
27 #include <rpcsvc/nislib.h>
29 #include "nss-nisplus.h"
31 __libc_lock_define_initialized (static, lock
)
33 static nis_result
*result
= NULL
;
34 static nis_name
*names
= NULL
;
36 #define ENTNAME rpcent
37 #define DATABASE "rpc"
38 #define TRAILING_LIST_MEMBER r_aliases
39 #define TRAILING_LIST_SEPARATOR_P isspace
40 #include "../../nss/nss_files/files-parse.c"
43 STRING_FIELD (result
->r_name
, isspace
, 1);
44 INT_FIELD (result
->r_number
, isspace
, 1, 10,);
47 #define NISENTRYVAL(idx,col,res) \
48 ((res)->objects.objects_val[(idx)].zo_data.objdata_u.en_data.en_cols.en_cols_val[(col)].ec_value.ec_value_val)
50 #define NISENTRYLEN(idx,col,res) \
51 ((res)->objects.objects_val[(idx)].zo_data.objdata_u.en_data.en_cols.en_cols_val[(col)].ec_value.ec_value_len)
54 _nss_nisplus_parse_rpcent (nis_result
*result
, struct rpcent
*rpc
,
55 char *buffer
, size_t buflen
)
58 size_t room_left
= buflen
;
60 struct parser_data
*data
= (void *) buffer
;
65 if ((result
->status
!= NIS_SUCCESS
&& result
->status
!= NIS_S_SUCCESS
) ||
66 result
->objects
.objects_val
[0].zo_data
.zo_type
!= ENTRY_OBJ
||
67 strcmp(result
->objects
.objects_val
[0].zo_data
.objdata_u
.en_data
.en_type
,
69 result
->objects
.objects_val
[0].zo_data
.objdata_u
.en_data
.en_cols
.en_cols_len
< 3)
72 memset (p
, '\0', room_left
);
74 /* Generate the rpc entry format and use the normal parser */
75 if (NISENTRYLEN (0, 0, result
) +1 > room_left
)
80 strncpy (p
, NISENTRYVAL (0, 0, result
), NISENTRYLEN (0, 0, result
));
81 room_left
-= (NISENTRYLEN (0, 0, result
) +1);
83 if (NISENTRYLEN (0, 2, result
) +1 > room_left
)
89 strncat (p
, NISENTRYVAL (0, 2, result
), NISENTRYLEN (0, 2, result
));
90 room_left
-= (NISENTRYLEN (0, 2, result
) + 1);
91 /* + 1: We overwrite the last \0 */
93 for (i
= 0; i
< result
->objects
.objects_len
; i
++)
94 /* XXX should we start with i = 0 or with i = 1 ? */
96 if (NISENTRYLEN (i
, 1, result
) +1 > room_left
)
102 strncat (p
, NISENTRYVAL (i
, 1, result
), NISENTRYLEN (i
, 1, result
));
103 room_left
-= (NISENTRYLEN (i
, 1, result
) + 1);
106 return _nss_files_parse_rpcent (p
, rpc
, data
, buflen
);
110 _nss_nisplus_setrpcent (void)
112 __libc_lock_lock (lock
);
115 nis_freeresult (result
);
119 nis_freenames (names
);
123 __libc_lock_unlock (lock
);
125 return NSS_STATUS_SUCCESS
;
129 _nss_nisplus_endrpcent (void)
131 __libc_lock_lock (lock
);
134 nis_freeresult (result
);
138 nis_freenames (names
);
142 __libc_lock_unlock (lock
);
144 return NSS_STATUS_SUCCESS
;
147 static enum nss_status
148 internal_nisplus_getrpcent_r (struct rpcent
*rpc
, char *buffer
,
153 /* Get the next entry until we found a correct one. */
158 names
= nis_getnames ("rpc.org_dir");
159 if (names
== NULL
|| names
[0] == NULL
)
160 return NSS_STATUS_UNAVAIL
;
162 result
= nis_first_entry(names
[0]);
163 if (niserr2nss (result
->status
) != NSS_STATUS_SUCCESS
)
164 return niserr2nss (result
->status
);
170 res
= nis_next_entry (names
[0], &result
->cookie
);
171 nis_freeresult (result
);
173 if (niserr2nss (result
->status
) != NSS_STATUS_SUCCESS
)
174 return niserr2nss (result
->status
);
177 parse_res
= _nss_nisplus_parse_rpcent (result
, rpc
, buffer
, buflen
);
178 } while (!parse_res
);
180 return NSS_STATUS_SUCCESS
;
184 _nss_nisplus_getrpcent_r (struct rpcent
*result
, char *buffer
,
189 __libc_lock_lock (lock
);
191 status
= internal_nisplus_getrpcent_r (result
, buffer
, buflen
);
193 __libc_lock_unlock (lock
);
199 _nss_nisplus_getrpcbyname_r (const char *name
, struct rpcent
*rpc
,
200 char *buffer
, size_t buflen
)
205 return NSS_STATUS_NOTFOUND
;
209 char buf
[strlen (name
) + 255];
211 /* Search at first in the alias list, and use the correct name
212 for the next search */
213 sprintf (buf
, "[name=%s],rpc.org_dir", name
);
214 result
= nis_list (buf
, EXPAND_NAME
, NULL
, NULL
);
216 /* If we do not find it, try it as original name. But if the
217 database is correct, we should find it in the first case, too */
218 if ((result
->status
!= NIS_SUCCESS
&&
219 result
->status
!= NIS_S_SUCCESS
) ||
220 result
->objects
.objects_val
[0].zo_data
.zo_type
!= ENTRY_OBJ
||
221 strcmp (result
->objects
.objects_val
[0].zo_data
.objdata_u
.en_data
.en_type
,
223 result
->objects
.objects_val
[0].zo_data
.objdata_u
.en_data
.en_cols
.en_cols_len
< 3)
224 sprintf (buf
, "[cname=%s],rpc.org_dir", name
);
226 sprintf (buf
, "[cname=%s],rpc.org_dir", NISENTRYVAL(0, 0, result
));
228 nis_freeresult (result
);
229 result
= nis_list(buf
, EXPAND_NAME
, NULL
, NULL
);
231 if (niserr2nss (result
->status
) != NSS_STATUS_SUCCESS
)
233 enum nss_status status
= niserr2nss (result
->status
);
235 nis_freeresult (result
);
239 parse_res
= _nss_nisplus_parse_rpcent (result
, rpc
, buffer
, buflen
);
241 nis_freeresult (result
);
244 return NSS_STATUS_SUCCESS
;
246 if (!parse_res
&& errno
== ERANGE
)
247 return NSS_STATUS_TRYAGAIN
;
249 return NSS_STATUS_NOTFOUND
;
254 _nss_nisplus_getrpcbynumber_r (const int number
, struct rpcent
*rpc
,
255 char *buffer
, size_t buflen
)
261 snprintf (buf
, sizeof (buf
), "[number=%d],rpc.org_dir", number
);
263 result
= nis_list(buf
, EXPAND_NAME
, NULL
, NULL
);
265 if (niserr2nss (result
->status
) != NSS_STATUS_SUCCESS
)
267 enum nss_status status
= niserr2nss (result
->status
);
269 nis_freeresult (result
);
273 parse_res
= _nss_nisplus_parse_rpcent (result
, rpc
, buffer
, buflen
);
275 nis_freeresult (result
);
278 return NSS_STATUS_SUCCESS
;
280 if (!parse_res
&& errno
== ERANGE
)
281 return NSS_STATUS_TRYAGAIN
;
283 return NSS_STATUS_NOTFOUND
;