1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  *
25  * files/gethostent6.c -- "files" backend for nsswitch "hosts" database
26  */
27 
28 #include <netdb.h>
29 #include "files_common.h"
30 #include <string.h>
31 #include <strings.h>
32 #include <stddef.h>
33 #include <stdlib.h>
34 #include <sys/types.h>
35 #include <sys/socket.h>
36 #include <netinet/in.h>
37 #include <arpa/nameser.h>
38 #include <ctype.h>
39 
40 extern nss_status_t __nss_files_XY_hostbyname();
41 extern int __nss_files_2herrno();
42 extern int __nss_files_check_addr(int, nss_XbyY_args_t *, const char *, int);
43 
44 static nss_status_t
getbyname(be,a)45 getbyname(be, a)
46 	files_backend_ptr_t	be;
47 	void			*a;
48 {
49 	nss_XbyY_args_t		*argp = (nss_XbyY_args_t *)a;
50 	nss_status_t		res;
51 
52 	res = __nss_files_XY_hostbyname(be, argp, argp->key.ipnode.name,
53 							AF_INET6);
54 	if (res != NSS_SUCCESS)
55 		argp->h_errno = __nss_files_2herrno(res);
56 	return (res);
57 }
58 
59 static int
check_addr(nss_XbyY_args_t * argp,const char * line,int linelen)60 check_addr(nss_XbyY_args_t *argp, const char *line, int linelen)
61 {
62 	return (__nss_files_check_addr(AF_INET6, argp, line, linelen));
63 }
64 
65 static nss_status_t
getbyaddr(be,a)66 getbyaddr(be, a)
67 	files_backend_ptr_t	be;
68 	void			*a;
69 {
70 	nss_XbyY_args_t		*argp	= (nss_XbyY_args_t *)a;
71 	nss_status_t		res;
72 
73 
74 	res = _nss_files_XY_all(be, argp, 1, 0, check_addr);
75 	if (res != NSS_SUCCESS)
76 		argp->h_errno = __nss_files_2herrno(res);
77 	return (res);
78 }
79 
80 static files_backend_op_t ipnodes_ops[] = {
81 	_nss_files_destr,
82 	_nss_files_endent,
83 	_nss_files_setent,
84 	_nss_files_getent_netdb,
85 	getbyname,
86 	getbyaddr,
87 };
88 
89 /*ARGSUSED*/
90 nss_backend_t *
_nss_files_ipnodes_constr(dummy1,dummy2,dummy3)91 _nss_files_ipnodes_constr(dummy1, dummy2, dummy3)
92 	const char	*dummy1, *dummy2, *dummy3;
93 {
94 	return (_nss_files_constr(ipnodes_ops,
95 				sizeof (ipnodes_ops) / sizeof (ipnodes_ops[0]),
96 				_PATH_IPNODES,
97 				NSS_LINELEN_HOSTS,
98 				NULL));
99 }
100