/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
* Copyright (c) 2014, Joyent, Inc. All rights reserved.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* University Copyright- Copyright (c) 1982, 1986, 1988
* The Regents of the University of California
* All Rights Reserved
*
* University Acknowledgment- Portions of this document are derived from
* software developed by the University of California, Berkeley, and its
* contributors.
*/
/*
* All routines necessary to deal the "ethers" database. The sources
* contain mappings between 48 bit ethernet addresses and corresponding
* hosts names. The addresses have an ascii representation of the form
* "x:x:x:x:x:x" where x is a hex number between 0x00 and 0xff; the
* bytes are always in network order.
*/
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
#include <thread.h>
#include <pthread.h>
#include <netinet/if_ether.h>
#include <nss_dbdefs.h>
int str2ether(const char *, int, void *, char *, int);
static DEFINE_NSS_DB_ROOT(db_root);
void
{
p->name = NSS_DBNAM_ETHERS;
}
/*
* Given a host's name, this routine finds the corresponding 48 bit
* ethernet address based on the "ethers" policy in /etc/nsswitch.conf.
* Returns zero if successful, non-zero otherwise.
*/
int
const char *host, /* function input */
struct ether_addr *e /* function output */
)
{
/*
* let the backend do the allocation to store stuff for parsing.
*/
(void) NSS_XbyY_FINI(&arg);
}
/*
* Given a 48 bit ethernet address, it finds the corresponding hostname
* ethernet address based on the "ethers" policy in /etc/nsswitch.conf.
* Returns zero if successful, non-zero otherwise.
*/
int
char *host, /* function output */
const struct ether_addr *e /* function input */
)
{
/*
* let the backend do the allocation to store stuff for parsing.
*/
/* memcpy(host, ether_res.host, strlen(ether_res.host)); */
(void) NSS_XbyY_FINI(&arg);
}
/*
* Parses a line from "ethers" database into its components. The line has
* the form 8:0:20:1:17:c8 krypton
* where the first part is a 48 bit ethernet address and the second is
* the corresponding hosts name.
* Returns zero if successful, non-zero otherwise.
*/
int
const char *s, /* the string to be parsed */
struct ether_addr *e, /* ethernet address struct to be filled in */
char *hostname /* hosts name to be set */
)
{
int i;
uint_t t[6];
i = sscanf(s, " %x:%x:%x:%x:%x:%x %s",
if (i != 7) {
return (7 - i);
}
for (i = 0; i < 6; i++)
e->ether_addr_octet[i] = (uchar_t)t[i];
return (0);
}
/*
* Parses a line from "ethers" database into its components.
* Useful for the vile purposes of the backends that
* expect a str2ether() format.
*
* This function, after parsing the instr line, will
* place the resulting struct ether_addr in b->buf.result only if
* b->buf.result is initialized (not NULL). I.e. it always happens
* for "files" backend (that needs to parse input line and
* then do a match for the ether key) and happens for "nis"
* backend only if the call was ether_hostton.
*
* Also, it will place the resulting hostname into b->buf.buffer
* only if b->buf.buffer is initialized. I.e. it always happens
* for "files" backend (that needs to parse input line and
* then do a match for the host key) and happens for "nis"
* backend only if the call was ether_ntohost.
*
* Cannot use the sscanf() technique for parsing because instr
* is a read-only, not necessarily null-terminated, buffer.
*
* Return values: 0 = success, 1 = parse error, 2 = erange ...
* The structure pointer passed in is a structure in the caller's space
* wherein the field pointers would be set to areas in the buffer if
* need be. instring and buffer should be separate areas.
*/
((x) >= 'a' && (x) <= 'z') || ((x) >= 'A' && (x) <= 'Z'))
/* ARGSUSED */
int
{
ptrdiff_t i;
p = instr;
/* skip beginning whitespace, if any */
p++;
if (ether) { /* parse ether */
for (i = 0; i < 6; i++) {
int j = 0, n = 0;
start = p;
/* don't worry about overflow here */
j++;
p++;
}
if (*p != ':' && i < 5) {
return (NSS_STR_PARSE_PARSE);
} else {
p++;
}
}
} else { /* skip ether */
p++;
}
if (host) { /* parse host */
p++;
start = p;
p++;
if ((i = (p - start)) < MAXHOSTNAMELEN) {
host[i] = '\0';
} else
return (NSS_STR_PARSE_ERANGE); /* failure */
}
return (NSS_STR_PARSE_SUCCESS);
}
typedef struct {
} eabuf_t;
static eabuf_t *
ea_buf(void)
{
if (thr_main())
return (&ea_main);
return (NULL);
}
return (eabuf);
}
/*
* Converts a 48 bit ethernet number to its string representation using a user
* defined buffer.
*/
char *
{
return (buf);
}
/*
* Converts a 48 bit ethernet number to its string representation using a
* per-thread buffer.
*/
char *
{
return (NULL);
}
/*
* Converts an ethernet address representation back into its 48 bits using a
* user defined buffer.
*/
struct ether_addr *
{
int i;
uint_t t[6];
i = sscanf(s, " %x:%x:%x:%x:%x:%x",
&t[0], &t[1], &t[2], &t[3], &t[4], &t[5]);
if (i != 6)
return (NULL);
for (i = 0; i < 6; i++)
e->ether_addr_octet[i] = (uchar_t)t[i];
return (e);
}
/*
* Converts an ethernet address representation back into its 48 bits using a
* per-thread buffer.
*/
struct ether_addr *
ether_aton(const char *s)
{
return (NULL);
}