xref: /onnv-gate/usr/src/lib/nsswitch/files/common/gethostent6.c (revision 2830:5228d1267a01)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*2830Sdjl  * Common Development and Distribution License (the "License").
6*2830Sdjl  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*2830Sdjl  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  *
25*2830Sdjl  * files/gethostent6.c -- "files" backend for nsswitch "hosts" database
260Sstevel@tonic-gate  */
270Sstevel@tonic-gate 
280Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
290Sstevel@tonic-gate 
300Sstevel@tonic-gate #include <netdb.h>
310Sstevel@tonic-gate #include "files_common.h"
320Sstevel@tonic-gate #include <string.h>
330Sstevel@tonic-gate #include <strings.h>
340Sstevel@tonic-gate #include <stddef.h>
350Sstevel@tonic-gate #include <stdlib.h>
360Sstevel@tonic-gate #include <sys/types.h>
370Sstevel@tonic-gate #include <sys/socket.h>
380Sstevel@tonic-gate #include <netinet/in.h>
390Sstevel@tonic-gate #include <arpa/nameser.h>
400Sstevel@tonic-gate #include <ctype.h>
410Sstevel@tonic-gate 
420Sstevel@tonic-gate extern nss_status_t __nss_files_XY_hostbyname();
430Sstevel@tonic-gate extern int __nss_files_2herrno();
44*2830Sdjl extern int __nss_files_check_addr(int, nss_XbyY_args_t *, const char *, int);
450Sstevel@tonic-gate 
460Sstevel@tonic-gate static nss_status_t
getbyname(be,a)470Sstevel@tonic-gate getbyname(be, a)
480Sstevel@tonic-gate 	files_backend_ptr_t	be;
490Sstevel@tonic-gate 	void			*a;
500Sstevel@tonic-gate {
510Sstevel@tonic-gate 	nss_XbyY_args_t		*argp = (nss_XbyY_args_t *)a;
520Sstevel@tonic-gate 	nss_status_t		res;
530Sstevel@tonic-gate 
540Sstevel@tonic-gate 	res = __nss_files_XY_hostbyname(be, argp, argp->key.ipnode.name,
550Sstevel@tonic-gate 							AF_INET6);
560Sstevel@tonic-gate 	if (res != NSS_SUCCESS)
570Sstevel@tonic-gate 		argp->h_errno = __nss_files_2herrno(res);
580Sstevel@tonic-gate 	return (res);
590Sstevel@tonic-gate }
600Sstevel@tonic-gate 
61*2830Sdjl static int
check_addr(nss_XbyY_args_t * argp,const char * line,int linelen)62*2830Sdjl check_addr(nss_XbyY_args_t *argp, const char *line, int linelen)
63*2830Sdjl {
64*2830Sdjl 	return (__nss_files_check_addr(AF_INET6, argp, line, linelen));
65*2830Sdjl }
660Sstevel@tonic-gate 
670Sstevel@tonic-gate static nss_status_t
getbyaddr(be,a)680Sstevel@tonic-gate getbyaddr(be, a)
690Sstevel@tonic-gate 	files_backend_ptr_t	be;
700Sstevel@tonic-gate 	void			*a;
710Sstevel@tonic-gate {
720Sstevel@tonic-gate 	nss_XbyY_args_t		*argp	= (nss_XbyY_args_t *)a;
730Sstevel@tonic-gate 	nss_status_t		res;
740Sstevel@tonic-gate 
750Sstevel@tonic-gate 
76*2830Sdjl 	res = _nss_files_XY_all(be, argp, 1, 0, check_addr);
770Sstevel@tonic-gate 	if (res != NSS_SUCCESS)
780Sstevel@tonic-gate 		argp->h_errno = __nss_files_2herrno(res);
790Sstevel@tonic-gate 	return (res);
800Sstevel@tonic-gate }
810Sstevel@tonic-gate 
820Sstevel@tonic-gate static files_backend_op_t ipnodes_ops[] = {
830Sstevel@tonic-gate 	_nss_files_destr,
840Sstevel@tonic-gate 	_nss_files_endent,
850Sstevel@tonic-gate 	_nss_files_setent,
860Sstevel@tonic-gate 	_nss_files_getent_netdb,
870Sstevel@tonic-gate 	getbyname,
880Sstevel@tonic-gate 	getbyaddr,
890Sstevel@tonic-gate };
900Sstevel@tonic-gate 
910Sstevel@tonic-gate /*ARGSUSED*/
920Sstevel@tonic-gate nss_backend_t *
_nss_files_ipnodes_constr(dummy1,dummy2,dummy3)930Sstevel@tonic-gate _nss_files_ipnodes_constr(dummy1, dummy2, dummy3)
940Sstevel@tonic-gate 	const char	*dummy1, *dummy2, *dummy3;
950Sstevel@tonic-gate {
960Sstevel@tonic-gate 	return (_nss_files_constr(ipnodes_ops,
970Sstevel@tonic-gate 				sizeof (ipnodes_ops) / sizeof (ipnodes_ops[0]),
980Sstevel@tonic-gate 				_PATH_IPNODES,
990Sstevel@tonic-gate 				NSS_LINELEN_HOSTS,
1000Sstevel@tonic-gate 				NULL));
1010Sstevel@tonic-gate }
102