1 /* host.c - host 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.6 NAME 'ipHost' SUP top AUXILIARY
24 * DESC 'Abstraction of a host, an IP device. The distinguished
25 * value of the cn attribute denotes the host's canonical
26 * name. Device SHOULD be used as a structural class'
27 * MUST ( cn $ ipHostNumber )
28 * MAY ( l $ description $ manager ) )
31 /* the basic search filter for searches */
32 static struct berval host_filter = BER_BVC("(objectClass=ipHost)");
34 /* the attributes to request with searches */
35 static struct berval host_keys[] = {
37 BER_BVC("ipHostNumber"),
48 /* write a single host entry to the stream */
49 static int write_host(nssov_host_cbp *cbp,Entry *entry)
51 int32_t tmpint32,tmp2int32,tmp3int32;
52 int numaddr,i,numname,dupname;
53 struct berval name,*names,*addrs;
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 host */
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,"host entry %s does not contain %s value",
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 addresses */
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,"host entry %s does not contain %s value",
86 entry->e_name.bv_val, cbp->mi->mi_attrs[1].an_desc->ad_cname.bv_val, 0 );
90 numaddr = a->a_numvals;
92 WRITE_INT32(cbp->fp,NSLCD_RESULT_SUCCESS);
93 WRITE_BERVAL(cbp->fp,&name);
95 WRITE_INT32(cbp->fp,numname-1);
97 WRITE_INT32(cbp->fp,numname);
99 for (i=0;i<numname;i++) {
100 if (i == dupname) continue;
101 WRITE_BERVAL(cbp->fp,&names[i]);
103 WRITE_INT32(cbp->fp,numaddr);
104 for (i=0;i<numaddr;i++)
106 WRITE_ADDRESS(cbp->fp,&addrs[i]);
116 struct berval filter = {sizeof(fbuf)};
117 filter.bv_val = fbuf;
118 BER_BVZERO(&cbp.addr);
119 READ_STRING_BUF2(fp,cbp.buf,sizeof(cbp.buf));
120 cbp.name.bv_len = tmpint32;
121 cbp.name.bv_val = cbp.buf;,
122 Debug(LDAP_DEBUG_TRACE,"nssov_host_byname(%s)",cbp.name.bv_val,0,0);,
123 NSLCD_ACTION_HOST_BYNAME,
124 nssov_filter_byname(cbp.mi,0,&cbp.name,&filter)
131 int len=sizeof(addr);
133 struct berval filter = {sizeof(fbuf)};
134 filter.bv_val = fbuf;
135 BER_BVZERO(&cbp.name);
136 READ_ADDRESS(fp,addr,len,af);
137 /* translate the address to a string */
138 if (inet_ntop(af,addr,cbp.buf,sizeof(cbp.buf))==NULL)
140 Debug(LDAP_DEBUG_ANY,"nssov: unable to convert address to string",0,0,0);
143 cbp.addr.bv_val = cbp.buf;
144 cbp.addr.bv_len = strlen(cbp.buf);,
145 Debug(LDAP_DEBUG_TRACE,"nssov_host_byaddr(%s)",cbp.addr.bv_val,0,0);,
146 NSLCD_ACTION_HOST_BYADDR,
147 nssov_filter_byid(cbp.mi,1,&cbp.addr,&filter)
152 struct berval filter;
153 /* no parameters to read */
154 BER_BVZERO(&cbp.name);
155 BER_BVZERO(&cbp.addr);,
156 Debug(LDAP_DEBUG_TRACE,"nssov_host_all()",0,0,0);,
157 NSLCD_ACTION_HOST_ALL,
158 (filter=cbp.mi->mi_filter,0)