summaryrefslogtreecommitdiff
path: root/usr/src/lib/nsswitch/nisplus/common/ether_addr.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr/src/lib/nsswitch/nisplus/common/ether_addr.c')
-rw-r--r--usr/src/lib/nsswitch/nisplus/common/ether_addr.c104
1 files changed, 39 insertions, 65 deletions
diff --git a/usr/src/lib/nsswitch/nisplus/common/ether_addr.c b/usr/src/lib/nsswitch/nisplus/common/ether_addr.c
index 3d0fbb25e1..346188c4b4 100644
--- a/usr/src/lib/nsswitch/nisplus/common/ether_addr.c
+++ b/usr/src/lib/nsswitch/nisplus/common/ether_addr.c
@@ -2,9 +2,8 @@
* 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.
+ * 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
* or http://www.opensolaris.org/os/licensing.
@@ -20,12 +19,16 @@
* CDDL HEADER END
*/
/*
- * nisplus/ether_addr.c -- "nisplus" backend for nsswitch "ethers" database
- *
- * Copyright 1988-1992,2002 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
+/*
+ * nisplus/ether_addr.c
+ *
+ * nisplus backend for nsswitch "ethers" database
+ */
+
#pragma ident "%Z%%M% %I% %E% SMI"
/*
@@ -36,6 +39,7 @@
* bytes are always in network order.
*/
+#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <net/if.h>
@@ -67,43 +71,30 @@ getbyether(be, a)
char etherstr[18];
uchar_t *e = argp->key.ether;
- (void) sprintf(etherstr, "%x:%x:%x:%x:%x:%x",
+ (void) snprintf(etherstr, 18, "%x:%x:%x:%x:%x:%x",
*e, *(e + 1), *(e + 2), *(e + 3), *(e + 4), *(e + 5));
return (_nss_nisplus_lookup(be, argp, ETHER_TAG_ADDR,
etherstr));
}
/*
- * Place the resulting struct ether_addr from the nis_object structure into
- * argp->buf.result only if argp->buf.result is initialized (not NULL).
- * I.e. 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.
+ * Convert the ethers nisplus object into files format
*
* Returns NSS_STR_PARSE_{SUCCESS, ERANGE, PARSE}
*/
/*ARGSUSED*/
static int
-nis_object2ent(nobj, obj, argp)
- int nobj;
- nis_object *obj;
- nss_XbyY_args_t *argp;
+nis_object2str(nobj, obj, be, argp)
+ int nobj;
+ nis_object *obj;
+ nisplus_backend_ptr_t be;
+ nss_XbyY_args_t *argp;
{
- uchar_t *ether = (uchar_t *)argp->buf.result;
- char *host = argp->buf.buffer;
- char *val;
- struct entry_col *ecol;
- int len;
+ char *addr, *name;
+ int addrlen, namelen;
+ struct entry_col *ecol;
/*
- * 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.
- *
* If we got more than one nis_object, we just ignore it.
* Although it should never have happened.
*
@@ -118,46 +109,29 @@ nis_object2ent(nobj, obj, argp)
}
ecol = obj->EN_data.en_cols.en_cols_val;
- /*
- * get ether addr
- *
- * ether_hostton
- */
- if (ether) {
- int i;
- unsigned int t[6];
-
- EC_SET(ecol, ETHER_NDX_ADDR, len, val);
- if (len < 2)
- return (NSS_STR_PARSE_PARSE);
- i = sscanf(val, "%x:%x:%x:%x:%x:%x",
- &t[0], &t[1], &t[2], &t[3], &t[4], &t[5]);
- if (i != ETHERADDRL)
- return (NSS_STR_PARSE_PARSE);
- for (i = 0; i < ETHERADDRL; i++)
- *(ether + i) = (uchar_t)t[i];
+ /* addr */
+ __NISPLUS_GETCOL_OR_RETURN(ecol, ETHER_NDX_ADDR, addrlen, addr);
+
+ /* name */
+ __NISPLUS_GETCOL_OR_RETURN(ecol, ETHER_NDX_NAME, namelen, name);
+
+ /* skip comment */
/*
- * get hostname
+ * can't use argp->buf.result == NULL test to determine if
+ * the caller is nscd or not.
*
- * ether_ntohost
+ * exclude trailing null from length
*/
- } else if (host) {
- EC_SET(ecol, ETHER_NDX_NAME, len, val);
- if (len < 2)
- return (NSS_STR_PARSE_PARSE);
- /*
- * 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.
- */
- if (len > MAXHOSTNAMELEN)
- return (NSS_STR_PARSE_ERANGE);
- strcpy(host, val);
- }
+ be->buflen = addrlen + namelen + 1;
+ if ((be->buffer = calloc(1, be->buflen + 1)) == NULL)
+ return (NSS_STR_PARSE_PARSE);
+ (void) snprintf(be->buffer, be->buflen + 1, "%s %s", addr, name);
+#ifdef DEBUG
+ (void) fprintf(stdout, "ethers [%s]\n", be->buffer);
+ (void) fflush(stdout);
+#endif /* DEBUG */
return (NSS_STR_PARSE_SUCCESS);
}
@@ -174,5 +148,5 @@ _nss_nisplus_ethers_constr(dummy1, dummy2, dummy3)
{
return (_nss_nisplus_constr(ethers_ops,
sizeof (ethers_ops) / sizeof (ethers_ops[0]),
- ETHER_TBLNAME, nis_object2ent));
+ ETHER_TBLNAME, nis_object2str));
}