1 /* protocol.c - network protocol 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.4 NAME 'ipProtocol' SUP top STRUCTURAL
24 * DESC 'Abstraction of an IP protocol. Maps a protocol number
25 * to one or more names. The distinguished value of the cn
26 * attribute denotes the protocol's canonical name'
27 * MUST ( cn $ ipProtocolNumber )
31 /* the basic search filter for searches */
32 static struct berval protocol_filter = BER_BVC("(objectClass=ipProtocol)");
34 /* the attributes used in searches */
35 static struct berval protocol_keys[] = {
37 BER_BVC("ipProtocolNumber"),
43 NSSOV_CBPRIV(protocol,
48 static int write_protocol(nssov_protocol_cbp *cbp,Entry *entry)
50 int32_t tmpint32,tmp2int32,tmp3int32;
51 int i,numname,dupname,proto;
52 struct berval name,*names;
56 /* get the most canonical name */
57 nssov_find_rdnval( &entry->e_nname, cbp->mi->mi_attrs[0].an_desc, &name );
58 /* get the other names for the protocol */
59 a = attr_find( entry->e_attrs, cbp->mi->mi_attrs[0].an_desc );
60 if ( !a || !a->a_vals )
62 Debug(LDAP_DEBUG_ANY,"protocol entry %s does not contain %s value\n",
63 entry->e_name.bv_val, cbp->mi->mi_attrs[0].an_desc->ad_cname.bv_val, 0 );
67 numname = a->a_numvals;
68 /* if the name is not yet found, get the first entry from names */
69 if (BER_BVISNULL(&name)) {
74 for (i=0; i<numname; i++) {
75 if ( ber_bvmatch(&name, &a->a_nvals[i])) {
81 /* get the protocol number */
82 a = attr_find( entry->e_attrs, cbp->mi->mi_attrs[1].an_desc );
83 if ( !a || !a->a_vals )
85 Debug(LDAP_DEBUG_ANY,"protocol entry %s does not contain %s value\n",
86 entry->e_name.bv_val, cbp->mi->mi_attrs[1].an_desc->ad_cname.bv_val, 0 );
88 } else if ( a->a_numvals > 1 ) {
89 Debug(LDAP_DEBUG_ANY,"protocol entry %s contains multiple %s values\n",
90 entry->e_name.bv_val, cbp->mi->mi_attrs[1].an_desc->ad_cname.bv_val, 0 );
92 proto=(int)strtol(a->a_vals[0].bv_val,&tmp,0);
95 Debug(LDAP_DEBUG_ANY,"protocol entry %s contains non-numeric %s value\n",
96 entry->e_name.bv_val, cbp->mi->mi_attrs[1].an_desc->ad_cname.bv_val, 0 );
100 WRITE_INT32(cbp->fp,NSLCD_RESULT_SUCCESS);
101 WRITE_BERVAL(cbp->fp,&name);
102 if ( dupname >= 0 ) {
103 WRITE_INT32(cbp->fp,numname-1);
105 WRITE_INT32(cbp->fp,numname);
107 for (i=0;i<numname;i++) {
108 if (i == dupname) continue;
109 WRITE_BERVAL(cbp->fp,&names[i]);
111 WRITE_INT32(cbp->fp,proto);
120 struct berval filter = {sizeof(fbuf)};
121 filter.bv_val = fbuf;
122 BER_BVZERO(&cbp.numb);
123 READ_STRING_BUF2(fp,cbp.buf,sizeof(cbp.buf));
124 cbp.name.bv_len = tmpint32;
125 cbp.name.bv_val = cbp.buf;,
126 Debug(LDAP_DEBUG_TRACE,"nssov_protocol_byname(%s)\n",cbp.name.bv_val,0,0);,
127 NSLCD_ACTION_PROTOCOL_BYNAME,
128 nssov_filter_byname(cbp.mi,0,&cbp.name,&filter)
135 struct berval filter = {sizeof(fbuf)};
136 filter.bv_val = fbuf;
137 READ_INT32(fp,protocol);
138 cbp.numb.bv_val = cbp.buf;
139 cbp.numb.bv_len = snprintf(cbp.buf,sizeof(cbp.buf),"%d",protocol);
140 BER_BVZERO(&cbp.name);,
141 Debug(LDAP_DEBUG_TRACE,"nssov_protocol_bynumber(%s)\n",cbp.numb.bv_val,0,0);,
142 NSLCD_ACTION_PROTOCOL_BYNUMBER,
143 nssov_filter_byid(cbp.mi,1,&cbp.numb,&filter)
148 struct berval filter;
149 /* no parameters to read */,
150 Debug(LDAP_DEBUG_TRACE,"nssov_protocol_all()\n",0,0,0);,
151 NSLCD_ACTION_PROTOCOL_ALL,
152 (filter=cbp.mi->mi_filter,0)