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  *	nis/ether_addr.c -- "nis" backend for nsswitch "ethers" database
26  */
27 
28 /*
29  * All routines necessary to deal with the ethers NIS maps.  The maps
30  * contain mapping between 48 bit ethernet addresses and their corresponding
31  * hosts name.  The addresses have an ascii representation of the form
32  * "x:x:x:x:x:x" where x is a hex number between 0x00 and 0xff;  the
33  * bytes are always in network order.
34  */
35 
36 #include <stdio.h>
37 #include <sys/types.h>
38 #include <sys/socket.h>
39 #include <net/if.h>
40 #include <netinet/in.h>
41 #include <net/if_arp.h>
42 #include <netinet/if_ether.h>
43 #include <nss_dbdefs.h>
44 #include "nis_common.h"
45 
46 static nss_status_t
47 getbyhost(be, a)
48 	nis_backend_ptr_t	be;
49 	void			*a;
50 {
51 	nss_XbyY_args_t		*argp = (nss_XbyY_args_t *)a;
52 
53 	return (_nss_nis_lookup(be, argp, 0, "ethers.byname",
54 		argp->key.name, 0));
55 }
56 
57 static nss_status_t
58 getbyether(be, a)
59 	nis_backend_ptr_t	be;
60 	void			*a;
61 {
62 	nss_XbyY_args_t		*argp = (nss_XbyY_args_t *)a;
63 	char	etherstr[18];
64 	uchar_t	*e = argp->key.ether;
65 
66 	(void) snprintf(etherstr, 18, "%x:%x:%x:%x:%x:%x",
67 		*e, *(e + 1), *(e + 2), *(e + 3), *(e + 4), *(e + 5));
68 	return (_nss_nis_lookup(be, argp, 0, "ethers.byaddr", etherstr, 0));
69 }
70 
71 static nis_backend_op_t ethers_ops[] = {
72 	_nss_nis_destr,
73 	getbyhost,
74 	getbyether
75 };
76 
77 /*ARGSUSED*/
78 nss_backend_t *
79 _nss_nis_ethers_constr(dummy1, dummy2, dummy3)
80 	const char	*dummy1, *dummy2, *dummy3;
81 {
82 	return (_nss_nis_constr(ethers_ops,
83 			sizeof (ethers_ops) / sizeof (ethers_ops[0]),
84 			"ethers.byaddr"));
85 }
86