xref: /titanic_50/usr/src/lib/nsswitch/files/common/gethostent6.c (revision b3700b074e637f8c6991b70754c88a2cfffb246b)
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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
29 
30 #include <netdb.h>
31 #include "files_common.h"
32 #include <string.h>
33 #include <strings.h>
34 #include <stddef.h>
35 #include <stdlib.h>
36 #include <sys/types.h>
37 #include <sys/socket.h>
38 #include <netinet/in.h>
39 #include <arpa/nameser.h>
40 #include <ctype.h>
41 
42 extern nss_status_t __nss_files_XY_hostbyname();
43 extern int __nss_files_2herrno();
44 extern int __nss_files_check_addr(int, nss_XbyY_args_t *, const char *, int);
45 
46 static nss_status_t
47 getbyname(be, a)
48 	files_backend_ptr_t	be;
49 	void			*a;
50 {
51 	nss_XbyY_args_t		*argp = (nss_XbyY_args_t *)a;
52 	nss_status_t		res;
53 
54 	res = __nss_files_XY_hostbyname(be, argp, argp->key.ipnode.name,
55 							AF_INET6);
56 	if (res != NSS_SUCCESS)
57 		argp->h_errno = __nss_files_2herrno(res);
58 	return (res);
59 }
60 
61 static int
62 check_addr(nss_XbyY_args_t *argp, const char *line, int linelen)
63 {
64 	return (__nss_files_check_addr(AF_INET6, argp, line, linelen));
65 }
66 
67 static nss_status_t
68 getbyaddr(be, a)
69 	files_backend_ptr_t	be;
70 	void			*a;
71 {
72 	nss_XbyY_args_t		*argp	= (nss_XbyY_args_t *)a;
73 	nss_status_t		res;
74 
75 
76 	res = _nss_files_XY_all(be, argp, 1, 0, check_addr);
77 	if (res != NSS_SUCCESS)
78 		argp->h_errno = __nss_files_2herrno(res);
79 	return (res);
80 }
81 
82 static files_backend_op_t ipnodes_ops[] = {
83 	_nss_files_destr,
84 	_nss_files_endent,
85 	_nss_files_setent,
86 	_nss_files_getent_netdb,
87 	getbyname,
88 	getbyaddr,
89 };
90 
91 /*ARGSUSED*/
92 nss_backend_t *
93 _nss_files_ipnodes_constr(dummy1, dummy2, dummy3)
94 	const char	*dummy1, *dummy2, *dummy3;
95 {
96 	return (_nss_files_constr(ipnodes_ops,
97 				sizeof (ipnodes_ops) / sizeof (ipnodes_ops[0]),
98 				_PATH_IPNODES,
99 				NSS_LINELEN_HOSTS,
100 				NULL));
101 }
102