xref: /titanic_52/usr/src/lib/nsswitch/files/common/netmasks.c (revision 06e46062ef4f5f4b687cbafb4518fb123fe23920)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  *	files/netmasks.c -- "files" backend for nsswitch "netmasks" database
24  *
25  *	Copyright (c) 1996 Sun Microsystems Inc
26  *	All Rights Reserved.
27  */
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 /*
32  * All routines necessary to deal with the file /etc/inet/netmasks.  The file
33  * contains mappings from 32 bit network internet addresses to their
34  * corresponding 32 bit mask internet addresses. The addresses are in dotted
35  * internet address form.
36  */
37 
38 #include "files_common.h"
39 #include <string.h>
40 #include <sys/types.h>
41 #include <sys/socket.h>
42 #include <net/if.h>
43 #include <netinet/in.h>
44 #include <arpa/inet.h>
45 #include <nss_dbdefs.h>
46 
47 /*
48  * Validate 'files' netmasks entry. The comparison objects are in IPv4
49  * internet address format.
50  */
51 static int
52 check_addr(args)
53 	nss_XbyY_args_t		*args;
54 {
55 	struct in_addr tmp;
56 
57 	tmp.s_addr = inet_addr(args->key.name);
58 	return (memcmp(args->buf.buffer, (char *)&tmp,
59 	    sizeof (struct in_addr)) == 0);
60 }
61 
62 static nss_status_t
63 getbynet(be, a)
64 	files_backend_ptr_t	be;
65 	void			*a;
66 {
67 	nss_XbyY_args_t		*argp = (nss_XbyY_args_t *) a;
68 	nss_status_t		res;
69 	char			tmpbuf[NSS_LINELEN_NETMASKS];
70 
71 	argp->buf.buffer = tmpbuf;
72 	argp->buf.buflen = NSS_LINELEN_NETMASKS;
73 	res = _nss_files_XY_all(be, argp, 0, argp->key.name, check_addr);
74 	argp->buf.buffer = NULL;
75 	argp->buf.buflen = 0;
76 
77 	return (res);
78 }
79 
80 static files_backend_op_t netmasks_ops[] = {
81 	_nss_files_destr,
82 	getbynet
83 };
84 
85 /*ARGSUSED*/
86 nss_backend_t *
87 _nss_files_netmasks_constr(dummy1, dummy2, dummy3)
88 	const char	*dummy1, *dummy2, *dummy3;
89 {
90 	return (_nss_files_constr(netmasks_ops,
91 	    sizeof (netmasks_ops) / sizeof (netmasks_ops[0]),
92 	    _PATH_NETMASKS, NSS_LINELEN_NETMASKS, NULL));
93 }
94