1 /* ether.c - ethernet address lookup routines */
4 * Copyright 2008 by Howard Chu, Symas Corp.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted only as authorized by the OpenLDAP
11 * A copy of this license is available in the file LICENSE in the
12 * top-level directory of the distribution or, alternatively, at
13 * <http://www.OpenLDAP.org/license.html>.
16 * This code references portions of the nss-ldapd package
17 * written by Arthur de Jong. The nss-ldapd code was forked
18 * from the nss-ldap library written by Luke Howard.
24 uint8_t ether_addr_octet[6];
27 /* ( nisSchema.2.11 NAME 'ieee802Device' SUP top AUXILIARY
28 * DESC 'A device with a MAC address; device SHOULD be
29 * used as a structural class'
33 /* the basic search filter for searches */
34 static struct berval ether_filter = BER_BVC("(objectClass=ieee802Device)");
36 /* the attributes to request with searches */
37 static struct berval ether_keys[] = {
39 BER_BVC("macAddress"),
50 #define WRITE_ETHER(fp,addr) \
52 sscanf(addr.bv_val,"%02x:%02x:%02x:%02x:%02x:%02x", \
53 &ao[0], &ao[1], &ao[2], &ao[3], &ao[4], &ao[5] );\
54 tmpaddr.ether_addr_octet[0] = ao[0]; \
55 tmpaddr.ether_addr_octet[1] = ao[1]; \
56 tmpaddr.ether_addr_octet[2] = ao[2]; \
57 tmpaddr.ether_addr_octet[3] = ao[3]; \
58 tmpaddr.ether_addr_octet[4] = ao[4]; \
59 tmpaddr.ether_addr_octet[5] = ao[5]; } \
60 WRITE_TYPE(fp,tmpaddr,uint8_t[6]);
62 static int write_ether(nssov_ether_cbp *cbp,Entry *entry)
65 struct ether_addr tmpaddr;
66 struct berval tmparr[2], empty;
67 struct berval *names,*ethers;
71 /* get the name of the ether entry */
72 if (BER_BVISNULL(&cbp->name))
74 a = attr_find(entry->e_attrs, cbp->mi->mi_attrs[0].an_desc);
77 Debug(LDAP_DEBUG_ANY,"ether entry %s does not contain %s value",
78 entry->e_name.bv_val,cbp->mi->mi_attrs[0].an_desc->ad_cname.bv_val,0 );
87 BER_BVZERO(&names[1]);
89 /* get the addresses */
90 if (BER_BVISNULL(&cbp->addr))
92 a = attr_find(entry->e_attrs, cbp->mi->mi_attrs[1].an_desc);
95 Debug(LDAP_DEBUG_ANY,"ether entry %s does not contain %s value",
96 entry->e_name.bv_val,cbp->mi->mi_attrs[1].an_desc->ad_cname.bv_val,0 );
100 /* TODO: move parsing of addresses up here */
106 BER_BVZERO(ðers[1]);
108 /* write entries for all names and addresses */
109 for (i=0;!BER_BVISNULL(&names[i]);i++)
110 for (j=0;!BER_BVISNULL(ðers[j]);j++)
112 WRITE_INT32(cbp->fp,NSLCD_RESULT_SUCCESS);
113 WRITE_BERVAL(cbp->fp,&names[i]);
114 WRITE_ETHER(cbp->fp,ethers[j]);
124 struct berval filter = {sizeof(fbuf)};
125 filter.bv_val = fbuf;
126 BER_BVZERO(&cbp.addr);
127 READ_STRING_BUF2(fp,cbp.buf,sizeof(cbp.buf));
128 cbp.name.bv_len = tmpint32;
129 cbp.name.bv_val = cbp.buf;,
130 Debug(LDAP_DEBUG_TRACE,"nssov_ether_byname(%s)",cbp.name.bv_val,0,0);,
131 NSLCD_ACTION_ETHER_BYNAME,
132 nssov_filter_byname(cbp.mi,0,&cbp.name,&filter)
137 struct ether_addr addr;
139 struct berval filter = {sizeof(fbuf)};
140 filter.bv_val = fbuf;
141 BER_BVZERO(&cbp.name);
142 READ_TYPE(fp,addr,uint8_t[6]);
143 cbp.addr.bv_len = snprintf(cbp.buf,sizeof(cbp.buf), "%x:%x:%x:%x:%x:%x",
144 addr.ether_addr_octet[0],
145 addr.ether_addr_octet[1],
146 addr.ether_addr_octet[2],
147 addr.ether_addr_octet[3],
148 addr.ether_addr_octet[4],
149 addr.ether_addr_octet[5]);
150 cbp.addr.bv_val = cbp.buf;,
151 Debug(LDAP_DEBUG_TRACE,"nssov_ether_byether(%s)",cbp.addr.bv_val,0,0);,
152 NSLCD_ACTION_ETHER_BYETHER,
153 nssov_filter_byid(cbp.mi,1,&cbp.addr,&filter)
158 struct berval filter;
159 /* no parameters to read */
160 BER_BVZERO(&cbp.name);
161 BER_BVZERO(&cbp.addr);,
162 Debug(LDAP_DEBUG_TRACE,"nssov_ether_all()",0,0,0);,
163 NSLCD_ACTION_ETHER_ALL,
164 (filter=cbp.mi->mi_filter,0)