Back to index

openldap  2.4.31
protocol.c
Go to the documentation of this file.
00001 /* protocol.c - network protocol 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  * Portions 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 /*
00018 /* ACKNOWLEDGEMENTS:
00019  * This code references portions of the nss-ldapd package
00020  * written by Arthur de Jong. The nss-ldapd code was forked
00021  * from the nss-ldap library written by Luke Howard.
00022  */
00023 
00024 #include "nssov.h"
00025 
00026 /* ( nisSchema.2.4 NAME 'ipProtocol' SUP top STRUCTURAL
00027  *   DESC 'Abstraction of an IP protocol. Maps a protocol number
00028  *         to one or more names. The distinguished value of the cn
00029  *         attribute denotes the protocol's canonical name'
00030  *   MUST ( cn $ ipProtocolNumber )
00031  *    MAY description )
00032  */
00033 
00034 /* the basic search filter for searches */
00035 static struct berval protocol_filter = BER_BVC("(objectClass=ipProtocol)");
00036 
00037 /* the attributes used in searches */
00038 static struct berval protocol_keys[] = {
00039        BER_BVC("cn"),
00040        BER_BVC("ipProtocolNumber"),
00041        BER_BVNULL
00042 };
00043 
00044 NSSOV_INIT(protocol)
00045 
00046 NSSOV_CBPRIV(protocol,
00047        char buf[256];
00048        struct berval name;
00049        struct berval numb;);
00050 
00051 static int write_protocol(nssov_protocol_cbp *cbp,Entry *entry)
00052 {
00053        int32_t tmpint32,tmp2int32,tmp3int32;
00054        int i,numname,dupname,proto;
00055        struct berval name,*names;
00056        Attribute *a;
00057        char *tmp;
00058 
00059        /* get the most canonical name */
00060        nssov_find_rdnval( &entry->e_nname, cbp->mi->mi_attrs[0].an_desc, &name );
00061        /* get the other names for the protocol */
00062        a = attr_find( entry->e_attrs, cbp->mi->mi_attrs[0].an_desc );
00063        if ( !a || !a->a_vals )
00064        {
00065               Debug(LDAP_DEBUG_ANY,"protocol entry %s does not contain %s value\n",
00066                      entry->e_name.bv_val, cbp->mi->mi_attrs[0].an_desc->ad_cname.bv_val, 0 );
00067               return 0;
00068        }
00069        names = a->a_vals;
00070        numname = a->a_numvals;
00071        /* if the name is not yet found, get the first entry from names */
00072        if (BER_BVISNULL(&name)) {
00073               name=names[0];
00074               dupname = 0;
00075        } else {
00076               dupname = -1;
00077               for (i=0; i<numname; i++) {
00078                      if ( bvmatch(&name, &a->a_nvals[i])) {
00079                             dupname = i;
00080                             break;
00081                      }
00082               }
00083        }
00084        /* get the protocol number */
00085        a = attr_find( entry->e_attrs, cbp->mi->mi_attrs[1].an_desc );
00086        if ( !a || !a->a_vals )
00087        {
00088               Debug(LDAP_DEBUG_ANY,"protocol entry %s does not contain %s value\n",
00089                      entry->e_name.bv_val, cbp->mi->mi_attrs[1].an_desc->ad_cname.bv_val, 0 );
00090               return 0;
00091        } else if ( a->a_numvals > 1 ) {
00092               Debug(LDAP_DEBUG_ANY,"protocol entry %s contains multiple %s values\n",
00093                      entry->e_name.bv_val, cbp->mi->mi_attrs[1].an_desc->ad_cname.bv_val, 0 );
00094        }
00095        proto=(int)strtol(a->a_vals[0].bv_val,&tmp,0);
00096        if (*tmp)
00097        {
00098               Debug(LDAP_DEBUG_ANY,"protocol entry %s contains non-numeric %s value\n",
00099                      entry->e_name.bv_val, cbp->mi->mi_attrs[1].an_desc->ad_cname.bv_val, 0 );
00100               return 0;
00101        }
00102        /* write the entry */
00103        WRITE_INT32(cbp->fp,NSLCD_RESULT_BEGIN);
00104        WRITE_BERVAL(cbp->fp,&name);
00105        if ( dupname >= 0 ) {
00106               WRITE_INT32(cbp->fp,numname-1);
00107        } else {
00108               WRITE_INT32(cbp->fp,numname);
00109        }
00110        for (i=0;i<numname;i++) {
00111               if (i == dupname) continue;
00112               WRITE_BERVAL(cbp->fp,&names[i]);
00113        }
00114        WRITE_INT32(cbp->fp,proto);
00115        return 0;
00116 }
00117 
00118 NSSOV_CB(protocol)
00119 
00120 NSSOV_HANDLE(
00121        protocol,byname,
00122        char fbuf[1024];
00123        struct berval filter = {sizeof(fbuf)};
00124        filter.bv_val = fbuf;
00125        BER_BVZERO(&cbp.numb);
00126        READ_STRING(fp,cbp.buf);
00127        cbp.name.bv_len = tmpint32;
00128        cbp.name.bv_val = cbp.buf;,
00129        Debug(LDAP_DEBUG_TRACE,"nssov_protocol_byname(%s)\n",cbp.name.bv_val,0,0);,
00130        NSLCD_ACTION_PROTOCOL_BYNAME,
00131        nssov_filter_byname(cbp.mi,0,&cbp.name,&filter)
00132 )
00133 
00134 NSSOV_HANDLE(
00135        protocol,bynumber,
00136        int protocol;
00137        char fbuf[1024];
00138        struct berval filter = {sizeof(fbuf)};
00139        filter.bv_val = fbuf;
00140        READ_INT32(fp,protocol);
00141        cbp.numb.bv_val = cbp.buf;
00142        cbp.numb.bv_len = snprintf(cbp.buf,sizeof(cbp.buf),"%d",protocol);
00143        BER_BVZERO(&cbp.name);,
00144        Debug(LDAP_DEBUG_TRACE,"nssov_protocol_bynumber(%s)\n",cbp.numb.bv_val,0,0);,
00145        NSLCD_ACTION_PROTOCOL_BYNUMBER,
00146        nssov_filter_byid(cbp.mi,1,&cbp.numb,&filter)
00147 )
00148 
00149 NSSOV_HANDLE(
00150        protocol,all,
00151        struct berval filter;
00152        /* no parameters to read */,
00153        Debug(LDAP_DEBUG_TRACE,"nssov_protocol_all()\n",0,0,0);,
00154        NSLCD_ACTION_PROTOCOL_ALL,
00155        (filter=cbp.mi->mi_filter,0)
00156 )