]>
git.ipfire.org Git - thirdparty/glibc.git/blob - nis/nss_nis/nis-ethers.c
8c446209ad5f3fc44b7bec08bef90412b2094822
1 /* Copyright (C) 1996-2000, 2001 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Thorsten Kukuk <kukuk@suse.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 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
24 #include <bits/libc-lock.h>
25 #include <rpcsvc/yp.h>
26 #include <rpcsvc/ypclnt.h>
27 #include <netinet/ether.h>
28 #include <netinet/if_ether.h>
32 /* Protect global state against multiple changers */
33 __libc_lock_define_initialized (static, lock
)
35 /* Get the declaration of the parser function. */
36 #define ENTNAME etherent
37 #define STRUCTURE etherent
39 #include <nss/nss_files/files-parse.c>
44 struct response
*next
;
47 static struct response
*start
;
48 static struct response
*next
;
51 saveit (int instatus
, char *inkey
, int inkeylen
, char *inval
,
52 int invallen
, char *indata
)
54 if (instatus
!= YP_TRUE
)
57 if (inkey
&& inkeylen
> 0 && inval
&& invallen
> 0)
61 start
= malloc (sizeof (struct response
));
68 next
->next
= malloc (sizeof (struct response
));
69 if (next
->next
== NULL
)
74 next
->val
= malloc (invallen
+ 1);
75 if (next
->val
== NULL
)
77 strncpy (next
->val
, inval
, invallen
);
78 next
->val
[invallen
] = '\0';
84 static enum nss_status
85 internal_nis_setetherent (void)
88 struct ypall_callback ypcb
;
89 enum nss_status status
;
91 yp_get_default_domain (&domainname
);
95 if (start
->val
!= NULL
)
103 ypcb
.foreach
= saveit
;
105 status
= yperr2nss (yp_all (domainname
, "ethers.byname", &ypcb
));
112 _nss_nis_setetherent (int stayopen
)
114 enum nss_status result
;
116 __libc_lock_lock (lock
);
118 result
= internal_nis_setetherent ();
120 __libc_lock_unlock (lock
);
126 _nss_nis_endetherent (void)
128 __libc_lock_lock (lock
);
130 while (start
!= NULL
)
132 if (start
->val
!= NULL
)
141 __libc_lock_unlock (lock
);
143 return NSS_STATUS_SUCCESS
;
146 static enum nss_status
147 internal_nis_getetherent_r (struct etherent
*eth
, char *buffer
, size_t buflen
,
150 struct parser_data
*data
= (void *) buffer
;
154 internal_nis_setetherent ();
156 /* Get the next entry until we found a correct one. */
164 return NSS_STATUS_NOTFOUND
;
166 p
= strncpy (buffer
, next
->val
, buflen
);
171 parse_res
= _nss_files_parse_etherent (p
, eth
, data
, buflen
, errnop
);
173 return NSS_STATUS_TRYAGAIN
;
178 return NSS_STATUS_SUCCESS
;
182 _nss_nis_getetherent_r (struct etherent
*result
, char *buffer
, size_t buflen
,
187 __libc_lock_lock (lock
);
189 status
= internal_nis_getetherent_r (result
, buffer
, buflen
, errnop
);
191 __libc_lock_unlock (lock
);
197 _nss_nis_gethostton_r (const char *name
, struct etherent
*eth
,
198 char *buffer
, size_t buflen
, int *errnop
)
200 struct parser_data
*data
= (void *) buffer
;
201 enum nss_status retval
;
202 char *domain
, *result
, *p
;
208 return NSS_STATUS_UNAVAIL
;
211 if (yp_get_default_domain (&domain
))
212 return NSS_STATUS_UNAVAIL
;
214 retval
= yperr2nss (yp_match (domain
, "ethers.byname", name
,
215 strlen (name
), &result
, &len
));
217 if (retval
!= NSS_STATUS_SUCCESS
)
219 if (retval
== NSS_STATUS_NOTFOUND
)
221 else if (retval
== NSS_STATUS_TRYAGAIN
)
226 if ((size_t) (len
+ 1) > buflen
)
230 return NSS_STATUS_TRYAGAIN
;
233 p
= strncpy (buffer
, result
, len
);
239 parse_res
= _nss_files_parse_etherent (p
, eth
, data
, buflen
, errnop
);
243 return NSS_STATUS_TRYAGAIN
;
247 return NSS_STATUS_NOTFOUND
;
250 return NSS_STATUS_SUCCESS
;
254 _nss_nis_getntohost_r (const struct ether_addr
*addr
, struct etherent
*eth
,
255 char *buffer
, size_t buflen
, int *errnop
)
257 struct parser_data
*data
= (void *) buffer
;
258 enum nss_status retval
;
259 char *domain
, *result
, *p
;
260 int len
, nlen
, parse_res
;
266 return NSS_STATUS_UNAVAIL
;
269 if (yp_get_default_domain (&domain
))
270 return NSS_STATUS_UNAVAIL
;
272 nlen
= sprintf (buf
, "%x:%x:%x:%x:%x:%x",
273 (int) addr
->ether_addr_octet
[0],
274 (int) addr
->ether_addr_octet
[1],
275 (int) addr
->ether_addr_octet
[2],
276 (int) addr
->ether_addr_octet
[3],
277 (int) addr
->ether_addr_octet
[4],
278 (int) addr
->ether_addr_octet
[5]);
280 retval
= yperr2nss (yp_match (domain
, "ethers.byaddr", buf
,
281 nlen
, &result
, &len
));
283 if (retval
!= NSS_STATUS_SUCCESS
)
285 if (retval
== NSS_STATUS_TRYAGAIN
)
290 if ((size_t) (len
+ 1) > buflen
)
294 return NSS_STATUS_TRYAGAIN
;
297 p
= strncpy (buffer
, result
, len
);
303 parse_res
= _nss_files_parse_etherent (p
, eth
, data
, buflen
, errnop
);
307 return NSS_STATUS_TRYAGAIN
;
311 return NSS_STATUS_NOTFOUND
;
314 return NSS_STATUS_SUCCESS
;