Back to index

openldap  2.4.31
ether.c
Go to the documentation of this file.
00001 /* ether.c - ethernet address lookup routines */
00002 /* $OpenLDAP$ */
00003 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
00004  *
00005  * Copyright 2008-2012 The OpenLDAP Foundation.
00006  * Copyright 2008 by Howard Chu, Symas Corp.
00007  * All rights reserved.
00008  *
00009  * Redistribution and use in source and binary forms, with or without
00010  * modification, are permitted only as authorized by the OpenLDAP
00011  * Public License.
00012  *
00013  * A copy of this license is available in the file LICENSE in the
00014  * top-level directory of the distribution or, alternatively, at
00015  * <http://www.OpenLDAP.org/license.html>.
00016  */
00017 /* ACKNOWLEDGEMENTS:
00018  * This code references portions of the nss-ldapd package
00019  * written by Arthur de Jong. The nss-ldapd code was forked
00020  * from the nss-ldap library written by Luke Howard.
00021  */
00022 
00023 #include "nssov.h"
00024 
00025 struct ether_addr {
00026   uint8_t ether_addr_octet[6];
00027 };
00028 
00029 /* ( nisSchema.2.11 NAME 'ieee802Device' SUP top AUXILIARY
00030  *   DESC 'A device with a MAC address; device SHOULD be
00031  *         used as a structural class'
00032  *   MAY macAddress )
00033  */
00034 
00035 /* the basic search filter for searches */
00036 static struct berval ether_filter = BER_BVC("(objectClass=ieee802Device)");
00037 
00038 /* the attributes to request with searches */
00039 static struct berval ether_keys[] = {
00040        BER_BVC("cn"),
00041        BER_BVC("macAddress"),
00042        BER_BVNULL
00043 };
00044 
00045 NSSOV_INIT(ether)
00046 
00047 NSSOV_CBPRIV(ether,
00048        char buf[256];
00049        struct berval name;
00050        struct berval addr;);
00051 
00052 #define WRITE_ETHER(fp,addr) \
00053   {int ao[6]; \
00054   sscanf(addr.bv_val,"%02x:%02x:%02x:%02x:%02x:%02x", \
00055        &ao[0], &ao[1], &ao[2], &ao[3], &ao[4], &ao[5] );\
00056        tmpaddr.ether_addr_octet[0] = ao[0]; \
00057        tmpaddr.ether_addr_octet[1] = ao[1]; \
00058        tmpaddr.ether_addr_octet[2] = ao[2]; \
00059        tmpaddr.ether_addr_octet[3] = ao[3]; \
00060        tmpaddr.ether_addr_octet[4] = ao[4]; \
00061        tmpaddr.ether_addr_octet[5] = ao[5]; } \
00062   WRITE_TYPE(fp,tmpaddr,uint8_t[6]);
00063 
00064 static int write_ether(nssov_ether_cbp *cbp,Entry *entry)
00065 {
00066        int32_t tmpint32;
00067        struct ether_addr tmpaddr;
00068        struct berval tmparr[2], empty;
00069        struct berval *names,*ethers;
00070        Attribute *a;
00071        int i,j;
00072 
00073        /* get the name of the ether entry */
00074        if (BER_BVISNULL(&cbp->name))
00075        {
00076               a = attr_find(entry->e_attrs, cbp->mi->mi_attrs[0].an_desc);
00077               if ( !a )
00078               {
00079                      Debug(LDAP_DEBUG_ANY,"ether entry %s does not contain %s value\n",
00080                                                  entry->e_name.bv_val,cbp->mi->mi_attrs[0].an_desc->ad_cname.bv_val,0 );
00081                      return 0;
00082               }
00083               names = a->a_vals;
00084        }
00085        else
00086        {
00087               names=tmparr;
00088               names[0]=cbp->name;
00089               BER_BVZERO(&names[1]);
00090        }
00091        /* get the addresses */
00092        if (BER_BVISNULL(&cbp->addr))
00093        {
00094               a = attr_find(entry->e_attrs, cbp->mi->mi_attrs[1].an_desc);
00095               if ( !a )
00096               {
00097                      Debug(LDAP_DEBUG_ANY,"ether entry %s does not contain %s value\n",
00098                                                  entry->e_name.bv_val,cbp->mi->mi_attrs[1].an_desc->ad_cname.bv_val,0 );
00099                      return 0;
00100               }
00101               ethers = a->a_vals;
00102               /* TODO: move parsing of addresses up here */
00103        }
00104        else
00105        {
00106               ethers=tmparr;
00107               ethers[0]=cbp->addr;
00108               BER_BVZERO(&ethers[1]);
00109        }
00110        /* write entries for all names and addresses */
00111        for (i=0;!BER_BVISNULL(&names[i]);i++)
00112               for (j=0;!BER_BVISNULL(&ethers[j]);j++)
00113               {
00114                      WRITE_INT32(cbp->fp,NSLCD_RESULT_BEGIN);
00115                      WRITE_BERVAL(cbp->fp,&names[i]);
00116                      WRITE_ETHER(cbp->fp,ethers[j]);
00117               }
00118        return 0;
00119 }
00120 
00121 NSSOV_CB(ether)
00122 
00123 NSSOV_HANDLE(
00124        ether,byname,
00125        char fbuf[1024];
00126        struct berval filter = {sizeof(fbuf)};
00127        filter.bv_val = fbuf;
00128        BER_BVZERO(&cbp.addr);
00129        READ_STRING(fp,cbp.buf);
00130        cbp.name.bv_len = tmpint32;
00131        cbp.name.bv_val = cbp.buf;,
00132        Debug(LDAP_DEBUG_TRACE,"nssov_ether_byname(%s)\n",cbp.name.bv_val,0,0);,
00133        NSLCD_ACTION_ETHER_BYNAME,
00134        nssov_filter_byname(cbp.mi,0,&cbp.name,&filter)
00135 )
00136 
00137 NSSOV_HANDLE(
00138        ether,byether,
00139        struct ether_addr addr;
00140        char fbuf[1024];
00141        struct berval filter = {sizeof(fbuf)};
00142        filter.bv_val = fbuf;
00143        BER_BVZERO(&cbp.name);
00144        READ_TYPE(fp,addr,uint8_t[6]);
00145        cbp.addr.bv_len = snprintf(cbp.buf,sizeof(cbp.buf), "%x:%x:%x:%x:%x:%x",
00146               addr.ether_addr_octet[0],
00147               addr.ether_addr_octet[1],
00148               addr.ether_addr_octet[2],
00149               addr.ether_addr_octet[3],
00150               addr.ether_addr_octet[4],
00151               addr.ether_addr_octet[5]);
00152        cbp.addr.bv_val = cbp.buf;,
00153        Debug(LDAP_DEBUG_TRACE,"nssov_ether_byether(%s)\n",cbp.addr.bv_val,0,0);,
00154        NSLCD_ACTION_ETHER_BYETHER,
00155        nssov_filter_byid(cbp.mi,1,&cbp.addr,&filter)
00156 )
00157 
00158 NSSOV_HANDLE(
00159        ether,all,
00160        struct berval filter;
00161        /* no parameters to read */
00162        BER_BVZERO(&cbp.name);
00163        BER_BVZERO(&cbp.addr);,
00164        Debug(LDAP_DEBUG_TRACE,"nssov_ether_all()\n",0,0,0);,
00165        NSLCD_ACTION_ETHER_ALL,
00166        (filter=cbp.mi->mi_filter,0)
00167 )