1 /* rpc.c - rpc lookup routines */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2008-2013 The OpenLDAP Foundation.
6 * Portions Copyright 2008 by Howard Chu, Symas Corp.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted only as authorized by the OpenLDAP
13 * A copy of this license is available in the file LICENSE in the
14 * top-level directory of the distribution or, alternatively, at
15 * <http://www.OpenLDAP.org/license.html>.
18 * This code references portions of the nss-ldapd package
19 * written by Arthur de Jong. The nss-ldapd code was forked
20 * from the nss-ldap library written by Luke Howard.
25 /* ( nisSchema.2.5 NAME 'oncRpc' SUP top STRUCTURAL
26 * DESC 'Abstraction of an Open Network Computing (ONC)
27 * [RFC1057] Remote Procedure Call (RPC) binding.
28 * This class maps an ONC RPC number to a name.
29 * The distinguished value of the cn attribute denotes
30 * the RPC service's canonical name'
31 * MUST ( cn $ oncRpcNumber )
35 /* the basic search filter for searches */
36 static struct berval rpc_filter = BER_BVC("(objectClass=oncRpc)");
38 /* the attributes to request with searches */
39 static struct berval rpc_keys[] = {
41 BER_BVC("oncRpcNumber"),
52 /* write a single rpc entry to the stream */
53 static int write_rpc(nssov_rpc_cbp *cbp,Entry *entry)
55 int32_t tmpint32,tmp2int32,tmp3int32;
56 int i,numname,dupname,number;
57 struct berval name,*names;
61 /* get the most canonical name */
62 nssov_find_rdnval( &entry->e_nname, cbp->mi->mi_attrs[0].an_desc, &name );
63 /* get the other names for the rpc */
64 a = attr_find( entry->e_attrs, cbp->mi->mi_attrs[0].an_desc );
65 if ( !a || !a->a_vals )
67 Debug(LDAP_DEBUG_ANY,"rpc entry %s does not contain %s value\n",
68 entry->e_name.bv_val, cbp->mi->mi_attrs[0].an_desc->ad_cname.bv_val, 0 );
72 numname = a->a_numvals;
73 /* if the name is not yet found, get the first entry from names */
74 if (BER_BVISNULL(&name)) {
79 for (i=0; i<numname; i++) {
80 if ( bvmatch(&name, &a->a_nvals[i])) {
86 /* get the rpc number */
87 a = attr_find( entry->e_attrs, cbp->mi->mi_attrs[1].an_desc );
88 if ( !a || !a->a_vals )
90 Debug(LDAP_DEBUG_ANY,"rpc entry %s does not contain %s value\n",
91 entry->e_name.bv_val, cbp->mi->mi_attrs[1].an_desc->ad_cname.bv_val, 0 );
93 } else if ( a->a_numvals > 1 ) {
94 Debug(LDAP_DEBUG_ANY,"rpc entry %s contains multiple %s values\n",
95 entry->e_name.bv_val, cbp->mi->mi_attrs[1].an_desc->ad_cname.bv_val, 0 );
97 number=(int)strtol(a->a_vals[0].bv_val,&tmp,0);
100 Debug(LDAP_DEBUG_ANY,"rpc entry %s contains non-numeric %s value\n",
101 entry->e_name.bv_val, cbp->mi->mi_attrs[1].an_desc->ad_cname.bv_val, 0 );
104 /* write the entry */
105 WRITE_INT32(cbp->fp,NSLCD_RESULT_BEGIN);
106 WRITE_BERVAL(cbp->fp,&name);
107 if ( dupname >= 0 ) {
108 WRITE_INT32(cbp->fp,numname-1);
110 WRITE_INT32(cbp->fp,numname);
112 for (i=0;i<numname;i++) {
113 if (i == dupname) continue;
114 WRITE_BERVAL(cbp->fp,&names[i]);
116 WRITE_INT32(cbp->fp,number);
125 struct berval filter = {sizeof(fbuf)};
126 filter.bv_val = fbuf;
127 BER_BVZERO(&cbp.numb);
128 READ_STRING(fp,cbp.buf);
129 cbp.name.bv_len = tmpint32;
130 cbp.name.bv_val = cbp.buf;,
131 Debug(LDAP_DEBUG_TRACE,"nssov_rpc_byname(%s)\n",cbp.name.bv_val,0,0);,
132 NSLCD_ACTION_RPC_BYNAME,
133 nssov_filter_byname(cbp.mi,0,&cbp.name,&filter)
140 struct berval filter = {sizeof(fbuf)};
141 filter.bv_val = fbuf;
142 READ_INT32(fp,number);
143 cbp.numb.bv_val = cbp.buf;
144 cbp.numb.bv_len = snprintf(cbp.buf,sizeof(cbp.buf),"%d",number);
145 BER_BVZERO(&cbp.name);,
146 Debug(LDAP_DEBUG_TRACE,"nssov_rpc_bynumber(%s)\n",cbp.numb.bv_val,0,0);,
147 NSLCD_ACTION_RPC_BYNUMBER,
148 nssov_filter_byid(cbp.mi,1,&cbp.numb,&filter)
153 struct berval filter;
154 /* no parameters to read */,
155 Debug(LDAP_DEBUG_TRACE,"nssov_rpc_all()\n",0,0,0);,
156 NSLCD_ACTION_RPC_ALL,
157 (filter=cbp.mi->mi_filter,0)