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. 23*2830Sdjl * Use is subject to license terms. 240Sstevel@tonic-gate * 25*2830Sdjl * nis/ether_addr.c -- "nis" backend for nsswitch "ethers" database 260Sstevel@tonic-gate */ 270Sstevel@tonic-gate 280Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 290Sstevel@tonic-gate 300Sstevel@tonic-gate /* 310Sstevel@tonic-gate * All routines necessary to deal with the ethers NIS maps. The maps 320Sstevel@tonic-gate * contain mapping between 48 bit ethernet addresses and their corresponding 330Sstevel@tonic-gate * hosts name. The addresses have an ascii representation of the form 340Sstevel@tonic-gate * "x:x:x:x:x:x" where x is a hex number between 0x00 and 0xff; the 350Sstevel@tonic-gate * bytes are always in network order. 360Sstevel@tonic-gate */ 370Sstevel@tonic-gate 380Sstevel@tonic-gate #include <stdio.h> 390Sstevel@tonic-gate #include <sys/types.h> 400Sstevel@tonic-gate #include <sys/socket.h> 410Sstevel@tonic-gate #include <net/if.h> 420Sstevel@tonic-gate #include <netinet/in.h> 430Sstevel@tonic-gate #include <net/if_arp.h> 440Sstevel@tonic-gate #include <netinet/if_ether.h> 450Sstevel@tonic-gate #include <nss_dbdefs.h> 460Sstevel@tonic-gate #include "nis_common.h" 470Sstevel@tonic-gate 480Sstevel@tonic-gate static nss_status_t 490Sstevel@tonic-gate getbyhost(be, a) 500Sstevel@tonic-gate nis_backend_ptr_t be; 510Sstevel@tonic-gate void *a; 520Sstevel@tonic-gate { 53*2830Sdjl nss_XbyY_args_t *argp = (nss_XbyY_args_t *)a; 540Sstevel@tonic-gate 550Sstevel@tonic-gate return (_nss_nis_lookup(be, argp, 0, "ethers.byname", 560Sstevel@tonic-gate argp->key.name, 0)); 570Sstevel@tonic-gate } 580Sstevel@tonic-gate 590Sstevel@tonic-gate static nss_status_t 600Sstevel@tonic-gate getbyether(be, a) 610Sstevel@tonic-gate nis_backend_ptr_t be; 620Sstevel@tonic-gate void *a; 630Sstevel@tonic-gate { 64*2830Sdjl nss_XbyY_args_t *argp = (nss_XbyY_args_t *)a; 650Sstevel@tonic-gate char etherstr[18]; 66*2830Sdjl uchar_t *e = argp->key.ether; 670Sstevel@tonic-gate 68*2830Sdjl (void) snprintf(etherstr, 18, "%x:%x:%x:%x:%x:%x", 690Sstevel@tonic-gate *e, *(e + 1), *(e + 2), *(e + 3), *(e + 4), *(e + 5)); 700Sstevel@tonic-gate return (_nss_nis_lookup(be, argp, 0, "ethers.byaddr", etherstr, 0)); 710Sstevel@tonic-gate } 720Sstevel@tonic-gate 730Sstevel@tonic-gate static nis_backend_op_t ethers_ops[] = { 740Sstevel@tonic-gate _nss_nis_destr, 750Sstevel@tonic-gate getbyhost, 760Sstevel@tonic-gate getbyether 770Sstevel@tonic-gate }; 780Sstevel@tonic-gate 790Sstevel@tonic-gate /*ARGSUSED*/ 800Sstevel@tonic-gate nss_backend_t * 810Sstevel@tonic-gate _nss_nis_ethers_constr(dummy1, dummy2, dummy3) 820Sstevel@tonic-gate const char *dummy1, *dummy2, *dummy3; 830Sstevel@tonic-gate { 840Sstevel@tonic-gate return (_nss_nis_constr(ethers_ops, 850Sstevel@tonic-gate sizeof (ethers_ops) / sizeof (ethers_ops[0]), 860Sstevel@tonic-gate "ethers.byaddr")); 870Sstevel@tonic-gate } 88