1 /* $NetBSD: rpc.c,v 1.1.1.4 2014/05/28 09:58:28 tron Exp $ */ 2 3 /* rpc.c - rpc lookup routines */ 4 /* $OpenLDAP$ */ 5 /* This work is part of OpenLDAP Software <http://www.openldap.org/>. 6 * 7 * Copyright 2008-2014 The OpenLDAP Foundation. 8 * Portions Copyright 2008 by Howard Chu, Symas Corp. 9 * All rights reserved. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted only as authorized by the OpenLDAP 13 * Public License. 14 * 15 * A copy of this license is available in the file LICENSE in the 16 * top-level directory of the distribution or, alternatively, at 17 * <http://www.OpenLDAP.org/license.html>. 18 */ 19 /* ACKNOWLEDGEMENTS: 20 * This code references portions of the nss-ldapd package 21 * written by Arthur de Jong. The nss-ldapd code was forked 22 * from the nss-ldap library written by Luke Howard. 23 */ 24 25 #include "nssov.h" 26 27 /* ( nisSchema.2.5 NAME 'oncRpc' SUP top STRUCTURAL 28 * DESC 'Abstraction of an Open Network Computing (ONC) 29 * [RFC1057] Remote Procedure Call (RPC) binding. 30 * This class maps an ONC RPC number to a name. 31 * The distinguished value of the cn attribute denotes 32 * the RPC service's canonical name' 33 * MUST ( cn $ oncRpcNumber ) 34 * MAY description ) 35 */ 36 37 /* the basic search filter for searches */ 38 static struct berval rpc_filter = BER_BVC("(objectClass=oncRpc)"); 39 40 /* the attributes to request with searches */ 41 static struct berval rpc_keys[] = { 42 BER_BVC("cn"), 43 BER_BVC("oncRpcNumber"), 44 BER_BVNULL 45 }; 46 47 NSSOV_INIT(rpc) 48 49 NSSOV_CBPRIV(rpc, 50 char buf[256]; 51 struct berval name; 52 struct berval numb;); 53 54 /* write a single rpc entry to the stream */ 55 static int write_rpc(nssov_rpc_cbp *cbp,Entry *entry) 56 { 57 int32_t tmpint32,tmp2int32,tmp3int32; 58 int i,numname,dupname,number; 59 struct berval name,*names; 60 Attribute *a; 61 char *tmp; 62 63 /* get the most canonical name */ 64 nssov_find_rdnval( &entry->e_nname, cbp->mi->mi_attrs[0].an_desc, &name ); 65 /* get the other names for the rpc */ 66 a = attr_find( entry->e_attrs, cbp->mi->mi_attrs[0].an_desc ); 67 if ( !a || !a->a_vals ) 68 { 69 Debug(LDAP_DEBUG_ANY,"rpc entry %s does not contain %s value\n", 70 entry->e_name.bv_val, cbp->mi->mi_attrs[0].an_desc->ad_cname.bv_val, 0 ); 71 return 0; 72 } 73 names = a->a_vals; 74 numname = a->a_numvals; 75 /* if the name is not yet found, get the first entry from names */ 76 if (BER_BVISNULL(&name)) { 77 name=names[0]; 78 dupname = 0; 79 } else { 80 dupname = -1; 81 for (i=0; i<numname; i++) { 82 if ( bvmatch(&name, &a->a_nvals[i])) { 83 dupname = i; 84 break; 85 } 86 } 87 } 88 /* get the rpc number */ 89 a = attr_find( entry->e_attrs, cbp->mi->mi_attrs[1].an_desc ); 90 if ( !a || !a->a_vals ) 91 { 92 Debug(LDAP_DEBUG_ANY,"rpc entry %s does not contain %s value\n", 93 entry->e_name.bv_val, cbp->mi->mi_attrs[1].an_desc->ad_cname.bv_val, 0 ); 94 return 0; 95 } else if ( a->a_numvals > 1 ) { 96 Debug(LDAP_DEBUG_ANY,"rpc entry %s contains multiple %s values\n", 97 entry->e_name.bv_val, cbp->mi->mi_attrs[1].an_desc->ad_cname.bv_val, 0 ); 98 } 99 number=(int)strtol(a->a_vals[0].bv_val,&tmp,0); 100 if (*tmp) 101 { 102 Debug(LDAP_DEBUG_ANY,"rpc entry %s contains non-numeric %s value\n", 103 entry->e_name.bv_val, cbp->mi->mi_attrs[1].an_desc->ad_cname.bv_val, 0 ); 104 return 0; 105 } 106 /* write the entry */ 107 WRITE_INT32(cbp->fp,NSLCD_RESULT_BEGIN); 108 WRITE_BERVAL(cbp->fp,&name); 109 if ( dupname >= 0 ) { 110 WRITE_INT32(cbp->fp,numname-1); 111 } else { 112 WRITE_INT32(cbp->fp,numname); 113 } 114 for (i=0;i<numname;i++) { 115 if (i == dupname) continue; 116 WRITE_BERVAL(cbp->fp,&names[i]); 117 } 118 WRITE_INT32(cbp->fp,number); 119 return 0; 120 } 121 122 NSSOV_CB(rpc) 123 124 NSSOV_HANDLE( 125 rpc,byname, 126 char fbuf[1024]; 127 struct berval filter = {sizeof(fbuf)}; 128 filter.bv_val = fbuf; 129 BER_BVZERO(&cbp.numb); 130 READ_STRING(fp,cbp.buf); 131 cbp.name.bv_len = tmpint32; 132 cbp.name.bv_val = cbp.buf;, 133 Debug(LDAP_DEBUG_TRACE,"nssov_rpc_byname(%s)\n",cbp.name.bv_val,0,0);, 134 NSLCD_ACTION_RPC_BYNAME, 135 nssov_filter_byname(cbp.mi,0,&cbp.name,&filter) 136 ) 137 138 NSSOV_HANDLE( 139 rpc,bynumber, 140 int number; 141 char fbuf[1024]; 142 struct berval filter = {sizeof(fbuf)}; 143 filter.bv_val = fbuf; 144 READ_INT32(fp,number); 145 cbp.numb.bv_val = cbp.buf; 146 cbp.numb.bv_len = snprintf(cbp.buf,sizeof(cbp.buf),"%d",number); 147 BER_BVZERO(&cbp.name);, 148 Debug(LDAP_DEBUG_TRACE,"nssov_rpc_bynumber(%s)\n",cbp.numb.bv_val,0,0);, 149 NSLCD_ACTION_RPC_BYNUMBER, 150 nssov_filter_byid(cbp.mi,1,&cbp.numb,&filter) 151 ) 152 153 NSSOV_HANDLE( 154 rpc,all, 155 struct berval filter; 156 /* no parameters to read */, 157 Debug(LDAP_DEBUG_TRACE,"nssov_rpc_all()\n",0,0,0);, 158 NSLCD_ACTION_RPC_ALL, 159 (filter=cbp.mi->mi_filter,0) 160 ) 161