getether.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (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 2003 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <netinet/if_ether.h>
#include "ldap_common.h"
/* ether attributes filters */
#define _E_HOSTNAME "cn"
#define _E_MACADDRESS "macaddress"
#define _F_GETETHERBYHOST "(&(objectClass=ieee802Device)(cn=%s))"
#define _F_GETETHERBYHOST_SSD "(&(%%s)(cn=%s))"
#define _F_GETETHERBYETHER "(&(objectClass=ieee802Device)(macAddress=%s))"
#define _F_GETETHERBYETHER_SSD "(&(%%s)(macAddress=%s))"
static const char *ethers_attrs[] = {
(char *)NULL
};
/*
* _nss_ldap_ethers2ent is the data marshaling method for the ethers
* getXbyY * (e.g., getbyhost(), getbyether()) backend processes. This
* method is called after a successful ldap search has been performed.
* This method will parse the ldap search values into uchar_t *ether
* = argp->buf.buffer which the frontend process expects. Three error
* conditions are expected and returned to nsswitch.
*
* Place the resulting struct ether_addr from the ldap query into
* argp->buf.result only if argp->buf.result is initialized (not NULL).
* e.g., it happens for the call ether_hostton.
*
* Place the resulting hostname into argp->buf.buffer only if
* argp->buf.buffer is initialized. I.e. it happens for the call
* ether_ntohost.
*
* argp->buf.buflen does not make sense for ethers. It is always set
* to 0 by the frontend. The caller only passes a hostname pointer in
* case of ether_ntohost, that is assumed to be big enough. For
* ether_hostton, the struct ether_addr passed is a fixed size.
*
* The interface does not let the caller specify how long is the buffer
* pointed by host. We make a safe assumption that the callers will
* always give MAXHOSTNAMELEN. In any case, it is the only finite number
* we can lay our hands on in case of runaway strings, memory corruption etc.
*/
static int
{
int i, ip;
int nss_result;
int buflen = (int)0;
unsigned int t[ETHERADDRL];
unsigned long len = 0L;
hostflag = 1;
}
etherflag = 1;
}
nss_result = (int)NSS_STR_PARSE_SUCCESS;
nss_result = (int)NSS_STR_PARSE_PARSE;
goto result_ea2ent;
}
nss_result = (int)NSS_STR_PARSE_PARSE;
goto result_ea2ent;
}
if (hostflag) {
nss_result = (int)NSS_STR_PARSE_PARSE;
goto result_ea2ent;
}
if (len > MAXHOSTNAMELEN) {
nss_result = (int)NSS_STR_PARSE_ERANGE;
goto result_ea2ent;
}
continue;
}
}
if (etherflag) {
nss_result = (int)NSS_STR_PARSE_PARSE;
goto result_ea2ent;
}
"%x:%x:%x:%x:%x:%x", &t[0], &t[1],
&t[2], &t[3], &t[4], &t[5]);
if (ip != ETHERADDRL) {
nss_result = (int)NSS_STR_PARSE_PARSE;
goto result_ea2ent;
}
continue;
}
}
}
#ifdef DEBUG
" ether_addr: [%x:%x:%x:%x:%x:%x]\n",
ether->ether_addr_octet[0],
#endif /* DEBUG */
return ((int)nss_result);
}
/*
* getbyhost gets an ethernet address by hostname. This function
* constructs an ldap search filter using the hostname invocation
* parameter and the getetherbyhost search filter defined. Once
* the filter is constructed, we search for a matching entry and
* marshal the data results into uchar_t *ether for the frontend
* process. The function _nss_ldap_ethers2ent performs the data
* marshaling.
*
* RFC 2307, An Approach for Using LDAP as a Network Information Service,
* indicates that dn's be fully qualified. Host name searches will be on
* fully qualified host names (e.g., foo.bar.sun.com).
*/
static nss_status_t
{
char searchfilter[SEARCHFILTERLEN];
char userdata[SEARCHFILTERLEN];
int ret;
return ((nss_status_t)NSS_NOTFOUND);
return ((nss_status_t)NSS_NOTFOUND);
return ((nss_status_t)NSS_NOTFOUND);
}
/*
* getbyether gets an ethernet address by ethernet address. This
* function constructs an ldap search filter using the ASCII
* ethernet address invocation parameter and the getetherbyether
* search filter defined. Once the filter is constructed, we
* search for a matching entry and marshal the data results into
* uchar_t *ether for the frontend process. The function
* _nss_ldap_ethers2ent performs the data marshaling.
*/
static nss_status_t
{
char etherstr[18];
char searchfilter[SEARCHFILTERLEN];
char userdata[SEARCHFILTERLEN];
int ret;
*e, *(e + 1), *(e + 2), *(e + 3), *(e + 4), *(e + 5));
return ((nss_status_t)NSS_NOTFOUND);
return ((nss_status_t)NSS_NOTFOUND);
return ((nss_status_t)NSS_NOTFOUND);
}
static ldap_backend_op_t ethers_ops[] = {
};
/*
* _nss_ldap_ethers_constr is where life begins. This function calls the
* generic ldap constructor function to define and build the abstract
* data types required to support ldap operations.
*/
/*ARGSUSED0*/
const char *dummy3)
{
}