Back to index

openldap  2.4.31
rpc.c
Go to the documentation of this file.
00001 /* rpc.c - rpc 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 /* 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 /* ( nisSchema.2.5 NAME 'oncRpc' SUP top STRUCTURAL
00026  *      DESC 'Abstraction of an Open Network Computing (ONC)
00027  *                           [RFC1057] Remote Procedure Call (RPC) binding.
00028  *                           This class maps an ONC RPC number to a name.
00029  *                           The distinguished value of the cn attribute denotes
00030  *                           the RPC service's canonical name'
00031  *      MUST ( cn $ oncRpcNumber )
00032  *      MAY description )
00033  */
00034 
00035 /* the basic search filter for searches */
00036 static struct berval rpc_filter = BER_BVC("(objectClass=oncRpc)");
00037 
00038 /* the attributes to request with searches */
00039 static struct berval rpc_keys[] = {
00040        BER_BVC("cn"),
00041        BER_BVC("oncRpcNumber"),
00042        BER_BVNULL
00043 };
00044 
00045 NSSOV_INIT(rpc)
00046 
00047 NSSOV_CBPRIV(rpc,
00048        char buf[256];
00049        struct berval name;
00050        struct berval numb;);
00051 
00052 /* write a single rpc entry to the stream */
00053 static int write_rpc(nssov_rpc_cbp *cbp,Entry *entry)
00054 {
00055        int32_t tmpint32,tmp2int32,tmp3int32;
00056        int i,numname,dupname,number;
00057        struct berval name,*names;
00058        Attribute *a;
00059        char *tmp;
00060 
00061        /* get the most canonical name */
00062        nssov_find_rdnval( &entry->e_nname, cbp->mi->mi_attrs[0].an_desc, &name );
00063        /* get the other names for the rpc */
00064        a = attr_find( entry->e_attrs, cbp->mi->mi_attrs[0].an_desc );
00065        if ( !a || !a->a_vals )
00066        {
00067               Debug(LDAP_DEBUG_ANY,"rpc entry %s does not contain %s value\n",
00068                      entry->e_name.bv_val, cbp->mi->mi_attrs[0].an_desc->ad_cname.bv_val, 0 );
00069               return 0;
00070        }
00071        names = a->a_vals;
00072        numname = a->a_numvals;
00073        /* if the name is not yet found, get the first entry from names */
00074        if (BER_BVISNULL(&name)) {
00075               name=names[0];
00076               dupname = 0;
00077        } else {
00078               dupname = -1;
00079               for (i=0; i<numname; i++) {
00080                      if ( bvmatch(&name, &a->a_nvals[i])) {
00081                             dupname = i;
00082                             break;
00083                      }
00084               }
00085        }
00086        /* get the rpc number */
00087        a = attr_find( entry->e_attrs, cbp->mi->mi_attrs[1].an_desc );
00088        if ( !a || !a->a_vals )
00089        {
00090               Debug(LDAP_DEBUG_ANY,"rpc entry %s does not contain %s value\n",
00091                      entry->e_name.bv_val, cbp->mi->mi_attrs[1].an_desc->ad_cname.bv_val, 0 );
00092               return 0;
00093        } else if ( a->a_numvals > 1 ) {
00094               Debug(LDAP_DEBUG_ANY,"rpc entry %s contains multiple %s values\n",
00095                      entry->e_name.bv_val, cbp->mi->mi_attrs[1].an_desc->ad_cname.bv_val, 0 );
00096        }
00097        number=(int)strtol(a->a_vals[0].bv_val,&tmp,0);
00098        if (*tmp)
00099        {
00100               Debug(LDAP_DEBUG_ANY,"rpc entry %s contains non-numeric %s value\n",
00101                      entry->e_name.bv_val, cbp->mi->mi_attrs[1].an_desc->ad_cname.bv_val, 0 );
00102               return 0;
00103        }
00104        /* write the entry */
00105        WRITE_INT32(cbp->fp,NSLCD_RESULT_BEGIN);
00106        WRITE_BERVAL(cbp->fp,&name);
00107        if ( dupname >= 0 ) {
00108               WRITE_INT32(cbp->fp,numname-1);
00109        } else {
00110               WRITE_INT32(cbp->fp,numname);
00111        }
00112        for (i=0;i<numname;i++) {
00113               if (i == dupname) continue;
00114               WRITE_BERVAL(cbp->fp,&names[i]);
00115        }
00116        WRITE_INT32(cbp->fp,number);
00117        return 0;
00118 }
00119 
00120 NSSOV_CB(rpc)
00121 
00122 NSSOV_HANDLE(
00123        rpc,byname,
00124        char fbuf[1024];
00125     struct berval filter = {sizeof(fbuf)};
00126     filter.bv_val = fbuf;
00127     BER_BVZERO(&cbp.numb);
00128     READ_STRING(fp,cbp.buf);
00129     cbp.name.bv_len = tmpint32;
00130     cbp.name.bv_val = cbp.buf;,
00131        Debug(LDAP_DEBUG_TRACE,"nssov_rpc_byname(%s)\n",cbp.name.bv_val,0,0);,
00132        NSLCD_ACTION_RPC_BYNAME,
00133        nssov_filter_byname(cbp.mi,0,&cbp.name,&filter)
00134 )
00135 
00136 NSSOV_HANDLE(
00137        rpc,bynumber,
00138        int number;
00139        char fbuf[1024];
00140     struct berval filter = {sizeof(fbuf)};
00141     filter.bv_val = fbuf;
00142        READ_INT32(fp,number);
00143        cbp.numb.bv_val = cbp.buf;
00144        cbp.numb.bv_len = snprintf(cbp.buf,sizeof(cbp.buf),"%d",number);
00145        BER_BVZERO(&cbp.name);,
00146        Debug(LDAP_DEBUG_TRACE,"nssov_rpc_bynumber(%s)\n",cbp.numb.bv_val,0,0);,
00147        NSLCD_ACTION_RPC_BYNUMBER,
00148        nssov_filter_byid(cbp.mi,1,&cbp.numb,&filter)
00149 )
00150 
00151 NSSOV_HANDLE(
00152        rpc,all,
00153        struct berval filter;
00154        /* no parameters to read */,
00155        Debug(LDAP_DEBUG_TRACE,"nssov_rpc_all()\n",0,0,0);,
00156        NSLCD_ACTION_RPC_ALL,
00157        (filter=cbp.mi->mi_filter,0)
00158 )