1 /* Copyright (C) 1996 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1996.
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 <rpcsvc/yp.h>
26 #include <rpcsvc/ypclnt.h>
27 #include <netinet/if_ether.h>
31 /* Protect global state against multiple changers */
32 __libc_lock_define_initialized (static, lock
)
37 struct ether_addr e_addr
;
40 static bool_t new_start
= 1;
41 static char *oldkey
= NULL
;
42 static int oldkeylen
= 0;
45 _nss_nis_setetherent (void)
47 __libc_lock_lock (lock
);
57 __libc_lock_unlock (lock
);
59 return NSS_STATUS_SUCCESS
;
63 _nss_nis_endetherent (void)
65 __libc_lock_lock (lock
);
75 __libc_lock_unlock (lock
);
77 return NSS_STATUS_SUCCESS
;
80 static enum nss_status
81 internal_nis_getetherent_r (struct ether
*eth
, char *buffer
, size_t buflen
)
83 char *domain
, *result
, *outkey
;
84 int len
, keylen
, parse_res
;
86 if (yp_get_default_domain (&domain
))
87 return NSS_STATUS_UNAVAIL
;
89 /* Get the next entry until we found a correct one. */
92 enum nss_status retval
;
96 retval
= yperr2nss (yp_first (domain
, "ethers.byaddr",
97 &outkey
, &keylen
, &result
, &len
));
99 retval
= yperr2nss ( yp_next (domain
, "ethers.byaddr",
101 &outkey
, &keylen
, &result
, &len
));
103 if (retval
!= NSS_STATUS_SUCCESS
)
105 if (retval
== NSS_STATUS_TRYAGAIN
)
106 __set_errno (EAGAIN
);
110 if ((size_t) (len
+ 1) > buflen
)
113 __set_errno (ERANGE
);
114 return NSS_STATUS_TRYAGAIN
;
117 p
= strncpy (buffer
, result
, len
);
123 parse_res
= _nss_files_parse_etherent (p
, eth
, buffer
, buflen
);
124 if (!parse_res
&& errno
== ERANGE
)
125 return NSS_STATUS_TRYAGAIN
;
134 return NSS_STATUS_SUCCESS
;
138 _nss_nis_getetherent_r (struct ether
*result
, char *buffer
, size_t buflen
)
142 __libc_lock_lock (lock
);
144 status
= internal_nis_getetherent_r (result
, buffer
, buflen
);
146 __libc_lock_unlock (lock
);
152 _nss_nis_getethernam_r (const char *name
, struct ether
*eth
,
153 char *buffer
, size_t buflen
)
155 enum nss_status retval
;
156 char *domain
, *result
, *p
;
161 __set_errno (EINVAL
);
162 return NSS_STATUS_UNAVAIL
;
165 if (yp_get_default_domain (&domain
))
166 return NSS_STATUS_UNAVAIL
;
168 retval
= yperr2nss (yp_match (domain
, "ethers.byname", name
,
169 strlen (name
), &result
, &len
));
171 if (retval
!= NSS_STATUS_SUCCESS
)
173 if (retval
== NSS_STATUS_TRYAGAIN
)
174 __set_errno (EAGAIN
);
178 if ((size_t) (len
+ 1) > buflen
)
181 __set_errno (ERANGE
);
182 return NSS_STATUS_TRYAGAIN
;
185 p
= strncpy (buffer
, result
, len
);
191 parse_res
= _nss_files_parse_etherent (p
, eth
, buffer
, buflen
);
196 return NSS_STATUS_TRYAGAIN
;
198 return NSS_STATUS_NOTFOUND
;
201 return NSS_STATUS_SUCCESS
;
205 _nss_nis_getetherbyaddr_r (struct ether_addr
*addr
, struct ether
*eth
,
206 char *buffer
, size_t buflen
)
208 enum nss_status retval
;
209 char *domain
, *result
, *p
;
210 int len
, nlen
, parse_res
;
215 __set_errno (EINVAL
);
216 return NSS_STATUS_UNAVAIL
;
219 if (yp_get_default_domain (&domain
))
220 return NSS_STATUS_UNAVAIL
;
222 nlen
= sprintf (buf
, "%x:%x:%x:%x:%x:%x",
223 (int) addr
->ether_addr_octet
[0],
224 (int) addr
->ether_addr_octet
[1],
225 (int) addr
->ether_addr_octet
[2],
226 (int) addr
->ether_addr_octet
[3],
227 (int) addr
->ether_addr_octet
[4],
228 (int) addr
->ether_addr_octet
[5]);
230 retval
= yperr2nss (yp_match (domain
, "ethers.byaddr", buf
,
231 nlen
, &result
, &len
));
233 if (retval
!= NSS_STATUS_SUCCESS
)
235 if (retval
== NSS_STATUS_TRYAGAIN
)
236 __set_errno (EAGAIN
);
240 if ((size_t) (len
+ 1) > buflen
)
243 __set_errno (ERANGE
);
244 return NSS_STATUS_TRYAGAIN
;
247 p
= strncpy (buffer
, result
, len
);
253 parse_res
= _nss_files_parse_etherent (p
, eth
, buffer
, buflen
);
258 return NSS_STATUS_TRYAGAIN
;
260 return NSS_STATUS_NOTFOUND
;
263 return NSS_STATUS_SUCCESS
;