1 /* rpc.c - rpc lookup routines */
4 * Copyright 2008 by Howard Chu, Symas Corp.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted only as authorized by the OpenLDAP
11 * A copy of this license is available in the file LICENSE in the
12 * top-level directory of the distribution or, alternatively, at
13 * <http://www.OpenLDAP.org/license.html>.
16 * This code references portions of the nss-ldapd package
17 * written by Arthur de Jong. The nss-ldapd code was forked
18 * from the nss-ldap library written by Luke Howard.
23 /* ( nisSchema.2.5 NAME 'oncRpc' SUP top STRUCTURAL
24 * DESC 'Abstraction of an Open Network Computing (ONC)
25 * [RFC1057] Remote Procedure Call (RPC) binding.
26 * This class maps an ONC RPC number to a name.
27 * The distinguished value of the cn attribute denotes
28 * the RPC service's canonical name'
29 * MUST ( cn $ oncRpcNumber )
33 /* the basic search filter for searches */
34 static struct berval rpc_filter = BER_BVC("(objectClass=oncRpc)");
36 /* the attributes to request with searches */
37 static struct berval rpc_keys[] = {
39 BER_BVC("oncRpcNumber"),
50 /* write a single rpc entry to the stream */
51 static int write_rpc(nssov_rpc_cbp *cbp,Entry *entry)
53 int32_t tmpint32,tmp2int32,tmp3int32;
54 int i,numname,dupname,number;
55 struct berval name,*names;
59 /* get the most canonical name */
60 nssov_find_rdnval( &entry->e_nname, cbp->mi->mi_attrs[0].an_desc, &name );
61 /* get the other names for the rpc */
62 a = attr_find( entry->e_attrs, cbp->mi->mi_attrs[0].an_desc );
63 if ( !a || !a->a_vals )
65 Debug(LDAP_DEBUG_ANY,"rpc entry %s does not contain %s value",
66 entry->e_name.bv_val, cbp->mi->mi_attrs[0].an_desc->ad_cname.bv_val, 0 );
70 numname = a->a_numvals;
71 /* if the name is not yet found, get the first entry from names */
72 if (BER_BVISNULL(&name)) {
77 for (i=0; i<numname; i++) {
78 if ( ber_bvmatch(&name, &a->a_nvals[i])) {
84 /* get the rpc number */
85 a = attr_find( entry->e_attrs, cbp->mi->mi_attrs[1].an_desc );
86 if ( !a || !a->a_vals )
88 Debug(LDAP_DEBUG_ANY,"rpc entry %s does not contain %s value",
89 entry->e_name.bv_val, cbp->mi->mi_attrs[1].an_desc->ad_cname.bv_val, 0 );
91 } else if ( a->a_numvals > 1 ) {
92 Debug(LDAP_DEBUG_ANY,"rpc entry %s contains multiple %s values",
93 entry->e_name.bv_val, cbp->mi->mi_attrs[1].an_desc->ad_cname.bv_val, 0 );
95 number=(int)strtol(a->a_vals[0].bv_val,&tmp,0);
98 Debug(LDAP_DEBUG_ANY,"rpc entry %s contains non-numeric %s value",
99 entry->e_name.bv_val, cbp->mi->mi_attrs[1].an_desc->ad_cname.bv_val, 0 );
102 /* write the entry */
103 WRITE_INT32(cbp->fp,NSLCD_RESULT_SUCCESS);
104 WRITE_BERVAL(cbp->fp,&name);
105 if ( dupname >= 0 ) {
106 WRITE_INT32(cbp->fp,numname-1);
108 WRITE_INT32(cbp->fp,numname);
110 for (i=0;i<numname;i++) {
111 if (i == dupname) continue;
112 WRITE_BERVAL(cbp->fp,&names[i]);
114 WRITE_INT32(cbp->fp,number);
123 struct berval filter = {sizeof(fbuf)};
124 filter.bv_val = fbuf;
125 BER_BVZERO(&cbp.numb);
126 READ_STRING_BUF2(fp,cbp.buf,sizeof(cbp.buf));
127 cbp.name.bv_len = tmpint32;
128 cbp.name.bv_val = cbp.buf;,
129 Debug(LDAP_DEBUG_TRACE,"nssov_rpc_byname(%s)",cbp.name.bv_val,0,0);,
130 NSLCD_ACTION_RPC_BYNAME,
131 nssov_filter_byname(cbp.mi,0,&cbp.name,&filter)
138 struct berval filter = {sizeof(fbuf)};
139 filter.bv_val = fbuf;
140 READ_INT32(fp,number);
141 cbp.numb.bv_val = cbp.buf;
142 cbp.numb.bv_len = snprintf(cbp.buf,sizeof(cbp.buf),"%d",number);
143 BER_BVZERO(&cbp.name);,
144 Debug(LDAP_DEBUG_TRACE,"nssov_rpc_bynumber(%d)",cbp.numb.bv_val,0,0);,
145 NSLCD_ACTION_RPC_BYNUMBER,
146 nssov_filter_byid(cbp.mi,1,&cbp.numb,&filter)
151 struct berval filter;
152 /* no parameters to read */,
153 Debug(LDAP_DEBUG_TRACE,"nssov_rpc_all()",0,0,0);,
154 NSLCD_ACTION_RPC_ALL,
155 (filter=cbp.mi->mi_filter,0)