1 /* protocol.c - network protocol 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>.
19 * This code references portions of the nss-ldapd package
20 * written by Arthur de Jong. The nss-ldapd code was forked
21 * from the nss-ldap library written by Luke Howard.
26 /* ( nisSchema.2.4 NAME 'ipProtocol' SUP top STRUCTURAL
27 * DESC 'Abstraction of an IP protocol. Maps a protocol number
28 * to one or more names. The distinguished value of the cn
29 * attribute denotes the protocol's canonical name'
30 * MUST ( cn $ ipProtocolNumber )
34 /* the basic search filter for searches */
35 static struct berval protocol_filter = BER_BVC("(objectClass=ipProtocol)");
37 /* the attributes used in searches */
38 static struct berval protocol_keys[] = {
40 BER_BVC("ipProtocolNumber"),
46 NSSOV_CBPRIV(protocol,
51 static int write_protocol(nssov_protocol_cbp *cbp,Entry *entry)
53 int32_t tmpint32,tmp2int32,tmp3int32;
54 int i,numname,dupname,proto;
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 protocol */
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,"protocol entry %s does not contain %s value\n",
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 ( bvmatch(&name, &a->a_nvals[i])) {
84 /* get the protocol 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,"protocol entry %s does not contain %s value\n",
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,"protocol entry %s contains multiple %s values\n",
93 entry->e_name.bv_val, cbp->mi->mi_attrs[1].an_desc->ad_cname.bv_val, 0 );
95 proto=(int)strtol(a->a_vals[0].bv_val,&tmp,0);
98 Debug(LDAP_DEBUG_ANY,"protocol entry %s contains non-numeric %s value\n",
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_BEGIN);
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,proto);
123 struct berval filter = {sizeof(fbuf)};
124 filter.bv_val = fbuf;
125 BER_BVZERO(&cbp.numb);
126 READ_STRING(fp,cbp.buf);
127 cbp.name.bv_len = tmpint32;
128 cbp.name.bv_val = cbp.buf;,
129 Debug(LDAP_DEBUG_TRACE,"nssov_protocol_byname(%s)\n",cbp.name.bv_val,0,0);,
130 NSLCD_ACTION_PROTOCOL_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,protocol);
141 cbp.numb.bv_val = cbp.buf;
142 cbp.numb.bv_len = snprintf(cbp.buf,sizeof(cbp.buf),"%d",protocol);
143 BER_BVZERO(&cbp.name);,
144 Debug(LDAP_DEBUG_TRACE,"nssov_protocol_bynumber(%s)\n",cbp.numb.bv_val,0,0);,
145 NSLCD_ACTION_PROTOCOL_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_protocol_all()\n",0,0,0);,
154 NSLCD_ACTION_PROTOCOL_ALL,
155 (filter=cbp.mi->mi_filter,0)