1 /* host.c - host 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.6 NAME 'ipHost' SUP top AUXILIARY
26 * DESC 'Abstraction of a host, an IP device. The distinguished
27 * value of the cn attribute denotes the host's canonical
28 * name. Device SHOULD be used as a structural class'
29 * MUST ( cn $ ipHostNumber )
30 * MAY ( l $ description $ manager ) )
33 /* the basic search filter for searches */
34 static struct berval host_filter = BER_BVC("(objectClass=ipHost)");
36 /* the attributes to request with searches */
37 static struct berval host_keys[] = {
39 BER_BVC("ipHostNumber"),
50 /* write a single host entry to the stream */
51 static int write_host(nssov_host_cbp *cbp,Entry *entry)
53 int32_t tmpint32,tmp2int32,tmp3int32;
54 int numaddr,i,numname,dupname;
55 struct berval name,*names,*addrs;
58 /* get the most canonical name */
59 nssov_find_rdnval( &entry->e_nname, cbp->mi->mi_attrs[0].an_desc, &name );
60 /* get the other names for the host */
61 a = attr_find( entry->e_attrs, cbp->mi->mi_attrs[0].an_desc );
62 if ( !a || !a->a_vals )
64 Debug(LDAP_DEBUG_ANY,"host entry %s does not contain %s value\n",
65 entry->e_name.bv_val, cbp->mi->mi_attrs[0].an_desc->ad_cname.bv_val, 0 );
69 numname = a->a_numvals;
70 /* if the name is not yet found, get the first entry from names */
71 if (BER_BVISNULL(&name)) {
76 for (i=0; i<numname; i++) {
77 if ( bvmatch(&name, &a->a_nvals[i])) {
83 /* get the addresses */
84 a = attr_find( entry->e_attrs, cbp->mi->mi_attrs[1].an_desc );
85 if ( !a || !a->a_vals )
87 Debug(LDAP_DEBUG_ANY,"host entry %s does not contain %s value\n",
88 entry->e_name.bv_val, cbp->mi->mi_attrs[1].an_desc->ad_cname.bv_val, 0 );
92 numaddr = a->a_numvals;
94 WRITE_INT32(cbp->fp,NSLCD_RESULT_BEGIN);
95 WRITE_BERVAL(cbp->fp,&name);
97 WRITE_INT32(cbp->fp,numname-1);
99 WRITE_INT32(cbp->fp,numname);
101 for (i=0;i<numname;i++) {
102 if (i == dupname) continue;
103 WRITE_BERVAL(cbp->fp,&names[i]);
105 WRITE_INT32(cbp->fp,numaddr);
106 for (i=0;i<numaddr;i++)
108 WRITE_ADDRESS(cbp->fp,&addrs[i]);
118 struct berval filter = {sizeof(fbuf)};
119 filter.bv_val = fbuf;
120 BER_BVZERO(&cbp.addr);
121 READ_STRING(fp,cbp.buf);
122 cbp.name.bv_len = tmpint32;
123 cbp.name.bv_val = cbp.buf;,
124 Debug(LDAP_DEBUG_TRACE,"nssov_host_byname(%s)\n",cbp.name.bv_val,0,0);,
125 NSLCD_ACTION_HOST_BYNAME,
126 nssov_filter_byname(cbp.mi,0,&cbp.name,&filter)
133 int len=sizeof(addr);
135 struct berval filter = {sizeof(fbuf)};
136 filter.bv_val = fbuf;
137 BER_BVZERO(&cbp.name);
138 READ_ADDRESS(fp,addr,len,af);
139 /* translate the address to a string */
140 if (inet_ntop(af,addr,cbp.buf,sizeof(cbp.buf))==NULL)
142 Debug(LDAP_DEBUG_ANY,"nssov: unable to convert address to string\n",0,0,0);
145 cbp.addr.bv_val = cbp.buf;
146 cbp.addr.bv_len = strlen(cbp.buf);,
147 Debug(LDAP_DEBUG_TRACE,"nssov_host_byaddr(%s)\n",cbp.addr.bv_val,0,0);,
148 NSLCD_ACTION_HOST_BYADDR,
149 nssov_filter_byid(cbp.mi,1,&cbp.addr,&filter)
154 struct berval filter;
155 /* no parameters to read */
156 BER_BVZERO(&cbp.name);
157 BER_BVZERO(&cbp.addr);,
158 Debug(LDAP_DEBUG_TRACE,"nssov_host_all()\n",0,0,0);,
159 NSLCD_ACTION_HOST_ALL,
160 (filter=cbp.mi->mi_filter,0)