10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
52830Sdjl * Common Development and Distribution License (the "License").
62830Sdjl * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
210Sstevel@tonic-gate /*
22*5361Schinlong * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
230Sstevel@tonic-gate * Use is subject to license terms.
240Sstevel@tonic-gate */
250Sstevel@tonic-gate
260Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
270Sstevel@tonic-gate
280Sstevel@tonic-gate #include <netdb.h>
290Sstevel@tonic-gate #include <arpa/inet.h>
300Sstevel@tonic-gate #include <netinet/in.h>
310Sstevel@tonic-gate #include <sys/socket.h>
320Sstevel@tonic-gate #include <syslog.h>
330Sstevel@tonic-gate #include <sys/systeminfo.h>
340Sstevel@tonic-gate #include "ns_internal.h"
350Sstevel@tonic-gate #include "ldap_common.h"
360Sstevel@tonic-gate
370Sstevel@tonic-gate /* host attributes filters */
380Sstevel@tonic-gate #define _H_DN "dn"
390Sstevel@tonic-gate #define _H_NAME "cn"
400Sstevel@tonic-gate #define _H_ADDR "iphostnumber"
410Sstevel@tonic-gate #define _F_GETHOSTBYNAME "(&(objectClass=ipHost)(cn=%s))"
420Sstevel@tonic-gate #define _F_GETHOSTBYNAME_SSD "(&(%%s)(cn=%s))"
430Sstevel@tonic-gate #define _F_GETHOSTDOTTEDBYNAME "(&(objectClass=ipHost)(|(cn=%s)(cn=%s)))"
440Sstevel@tonic-gate #define _F_GETHOSTDOTTEDBYNAME_SSD "(&(%%s)(|(cn=%s)(cn=%s)))"
450Sstevel@tonic-gate #define _F_GETHOSTBYADDR "(&(objectClass=ipHost)(ipHostNumber=%s))"
460Sstevel@tonic-gate #define _F_GETHOSTBYADDR_SSD "(&(%%s)(ipHostNumber=%s))"
470Sstevel@tonic-gate
480Sstevel@tonic-gate static const char *hosts_attrs[] = {
490Sstevel@tonic-gate _H_NAME,
500Sstevel@tonic-gate _H_ADDR,
510Sstevel@tonic-gate (char *)NULL
520Sstevel@tonic-gate };
530Sstevel@tonic-gate
540Sstevel@tonic-gate /*
552830Sdjl * _nss_ldap_hosts2str is the data marshaling method for the hosts getXbyY
562830Sdjl * system call gethostbyname() and gethostbyaddr.
572830Sdjl * This method is called after a successful search has been performed.
582830Sdjl * This method will parse the search results into the file format.
592830Sdjl * e.g.
602830Sdjl *
612830Sdjl * 9.9.9.9 jurassic jurassic1 jurassic2
622830Sdjl * 10.10.10.10 puppy
632830Sdjl *
640Sstevel@tonic-gate */
652830Sdjl int
_nss_ldap_hosts2str_int(int af,ldap_backend_ptr be,nss_XbyY_args_t * argp)662830Sdjl _nss_ldap_hosts2str_int(int af, ldap_backend_ptr be, nss_XbyY_args_t *argp)
670Sstevel@tonic-gate {
682830Sdjl uint_t i;
690Sstevel@tonic-gate int nss_result;
702830Sdjl int buflen, buflen1, buflen2, len;
712830Sdjl int firstimedn = 1, first_entry;
722830Sdjl int validaddress = 0, copy_cname;
732830Sdjl char *cname = NULL, *h_name = NULL;
742830Sdjl char *buffer = NULL;
752830Sdjl char *name;
760Sstevel@tonic-gate ns_ldap_result_t *result = be->result;
772830Sdjl ns_ldap_attr_t *names;
780Sstevel@tonic-gate ns_ldap_entry_t *entry;
792830Sdjl char **ips = NULL, **dns = NULL;
802830Sdjl char *first_host = NULL, *other_hosts = NULL;
812830Sdjl char *buf1, *buf2;
822830Sdjl
832830Sdjl if (result == NULL)
842830Sdjl return (NSS_STR_PARSE_PARSE);
852830Sdjl buflen = buflen1 = buflen2 = argp->buf.buflen;
860Sstevel@tonic-gate
872830Sdjl if (argp->buf.result != NULL) {
882830Sdjl if ((be->buffer = calloc(1, buflen)) == NULL) {
892830Sdjl nss_result = NSS_STR_PARSE_PARSE;
902830Sdjl goto result_host2str;
912830Sdjl }
922830Sdjl buffer = be->buffer;
932830Sdjl } else
942830Sdjl buffer = argp->buf.buffer;
952830Sdjl if ((first_host = calloc(1, buflen1)) == NULL) {
962830Sdjl nss_result = NSS_STR_PARSE_PARSE;
972830Sdjl goto result_host2str;
980Sstevel@tonic-gate }
992830Sdjl if ((other_hosts = calloc(1, buflen2)) == NULL) {
1002830Sdjl nss_result = NSS_STR_PARSE_PARSE;
1012830Sdjl goto result_host2str;
1020Sstevel@tonic-gate }
1030Sstevel@tonic-gate
1042830Sdjl nss_result = NSS_STR_PARSE_SUCCESS;
1052830Sdjl (void) memset(argp->buf.buffer, 0, buflen);
1062830Sdjl /*
1072830Sdjl * Multiple lines return will be sepereated by newlines
1082830Sdjl * Single line return or last line does not have newline
1092830Sdjl * e.g.
1102830Sdjl *
1112830Sdjl * 8.8.8.8 hostname
1122830Sdjl *
1132830Sdjl * or the search for hostname h1 returns 3 entries
1142830Sdjl *
1152830Sdjl * 9.9.9.9 h1
1162830Sdjl * 10.10.10.10 h1 xx
1172830Sdjl * 20.20.20.20 h1 yyy
1182830Sdjl *
1192830Sdjl * str2hostent expects all name/aliases in the first entry
1202830Sdjl * so the string is organized as
1212830Sdjl *
1222830Sdjl * "9.9.9.9 h1 xx yy\n10.10.10.10 \n20.20.20.20 "
1232830Sdjl *
1242830Sdjl * Use first_host to hold "9.9.9.9 h1 xx yy" and other_hosts to hold
1252830Sdjl * "\n10.10.10.10 \n20.20.20.20 "
1262830Sdjl *
1272830Sdjl */
1282830Sdjl buf1 = first_host;
1292830Sdjl buf2 = other_hosts;
1302830Sdjl first_entry = 1;
1310Sstevel@tonic-gate for (entry = result->entry; entry != NULL; entry = entry->next) {
132*5361Schinlong if (firstimedn) {
133*5361Schinlong dns = __ns_ldap_getAttr(entry, _H_DN);
134*5361Schinlong if (dns == NULL || dns[0] == NULL || strlen(dns[0])
135*5361Schinlong < 1) {
136*5361Schinlong nss_result = NSS_STR_PARSE_PARSE;
137*5361Schinlong goto result_host2str;
138*5361Schinlong }
139*5361Schinlong /* get domain name associated with this dn */
140*5361Schinlong be->toglue = _get_domain_name(dns[0]);
141*5361Schinlong firstimedn = 0;
142*5361Schinlong }
143*5361Schinlong
144*5361Schinlong /* Get IP */
145*5361Schinlong ips = __ns_ldap_getAttr(entry, _H_ADDR);
146*5361Schinlong if (ips == NULL || ips[0] == NULL || strlen(ips[0]) < 1) {
147*5361Schinlong nss_result = NSS_STR_PARSE_PARSE;
148*5361Schinlong goto result_host2str;
149*5361Schinlong }
150*5361Schinlong /* Skip IPV6 address in AF_INET mode */
151*5361Schinlong if (af == AF_INET &&
152*5361Schinlong (inet_addr(_strip_quotes(ips[0])) == (in_addr_t)-1))
153*5361Schinlong continue;
154*5361Schinlong
155*5361Schinlong /* A valid address for either af mode */
156*5361Schinlong validaddress++;
157*5361Schinlong
158*5361Schinlong if (first_entry) {
159*5361Schinlong len = snprintf(buf1, buflen1, "%s", ips[0]);
160*5361Schinlong TEST_AND_ADJUST(len, buf1, buflen1, result_host2str);
161*5361Schinlong } else {
162*5361Schinlong len = snprintf(buf2, buflen2, "\n%s ", ips[0]);
163*5361Schinlong TEST_AND_ADJUST(len, buf2, buflen2, result_host2str);
164*5361Schinlong }
165*5361Schinlong
166*5361Schinlong /* Get host names */
167*5361Schinlong names = __ns_ldap_getAttrStruct(entry, _H_NAME);
168*5361Schinlong if (names == NULL || names->attrvalue == NULL) {
169*5361Schinlong nss_result = NSS_STR_PARSE_PARSE;
170*5361Schinlong goto result_host2str;
171*5361Schinlong }
172*5361Schinlong
173*5361Schinlong /* Get canonical name of each entry */
174*5361Schinlong cname = __s_api_get_canonical_name(entry, names, 1);
175*5361Schinlong if (cname == NULL || strlen(cname) < 1) {
1762830Sdjl nss_result = NSS_STR_PARSE_PARSE;
1772830Sdjl goto result_host2str;
178*5361Schinlong }
1792830Sdjl
180*5361Schinlong /* Filter cname that's identical to h_name */
181*5361Schinlong if (first_entry) {
182*5361Schinlong h_name = cname;
183*5361Schinlong first_entry = 0;
184*5361Schinlong copy_cname = 1;
185*5361Schinlong } else if (strcasecmp(cname, h_name) != 0) {
186*5361Schinlong copy_cname = 1;
187*5361Schinlong } else
188*5361Schinlong copy_cname = 0;
1892830Sdjl
190*5361Schinlong if (copy_cname) {
191*5361Schinlong /* Use the canonical name as the host name */
192*5361Schinlong if (be->toglue == NULL || DOTTEDSUBDOMAIN(cname))
193*5361Schinlong len = snprintf(buf1, buflen1, " %s", cname);
194*5361Schinlong else
195*5361Schinlong /* append domain name */
196*5361Schinlong len = snprintf(buf1, buflen1, " %s.%s", cname,
197*5361Schinlong be->toglue);
1982830Sdjl
199*5361Schinlong TEST_AND_ADJUST(len, buf1, buflen1, result_host2str);
200*5361Schinlong }
2012830Sdjl
202*5361Schinlong /* Append aliases */
203*5361Schinlong for (i = 0; i < names->value_count; i++) {
204*5361Schinlong name = names->attrvalue[i];
205*5361Schinlong if (name == NULL) {
206*5361Schinlong nss_result = NSS_STR_PARSE_PARSE;
207*5361Schinlong goto result_host2str;
208*5361Schinlong }
209*5361Schinlong /* Skip the canonical name and h_name */
210*5361Schinlong if (strcasecmp(name, cname) != 0 &&
211*5361Schinlong strcasecmp(name, h_name) != 0) {
212*5361Schinlong if (be->toglue == NULL || DOTTEDSUBDOMAIN(name))
213*5361Schinlong len = snprintf(buf1, buflen1, " %s",
214*5361Schinlong name);
215*5361Schinlong else
216*5361Schinlong /* append domain name */
217*5361Schinlong len = snprintf(buf1, buflen1, " %s.%s",
218*5361Schinlong name, be->toglue);
219*5361Schinlong TEST_AND_ADJUST(len, buf1, buflen1,
220*5361Schinlong result_host2str);
221*5361Schinlong }
2220Sstevel@tonic-gate }
2230Sstevel@tonic-gate }
2240Sstevel@tonic-gate
2250Sstevel@tonic-gate if (validaddress == 0) {
2262830Sdjl /*
2272830Sdjl * For AF_INET mode, it found an IPv6 address and skipped it.
2282830Sdjl */
229*5361Schinlong nss_result = NSS_STR_PARSE_NO_ADDR;
230*5361Schinlong goto result_host2str;
2310Sstevel@tonic-gate }
2322830Sdjl /* Combine 2 strings */
2332830Sdjl len = snprintf(buffer, buflen, "%s%s", first_host, other_hosts);
2342830Sdjl TEST_AND_ADJUST(len, buffer, buflen, result_host2str);
2352830Sdjl
2362830Sdjl /* The front end marshaller doesn't need to copy trailing nulls */
2372830Sdjl if (argp->buf.result != NULL)
2382830Sdjl be->buflen = strlen(be->buffer);
2390Sstevel@tonic-gate
2402830Sdjl result_host2str:
2412830Sdjl if (first_host)
2422830Sdjl free(first_host);
2432830Sdjl if (other_hosts)
2442830Sdjl free(other_hosts);
2453178Schinlong if (be->toglue) {
2463178Schinlong free(be->toglue);
2473178Schinlong be->toglue = NULL;
2483178Schinlong }
2490Sstevel@tonic-gate (void) __ns_ldap_freeResult(&be->result);
2502830Sdjl return (nss_result);
2510Sstevel@tonic-gate }
2520Sstevel@tonic-gate
2532830Sdjl static int
_nss_ldap_hosts2str(ldap_backend_ptr be,nss_XbyY_args_t * argp)2542830Sdjl _nss_ldap_hosts2str(ldap_backend_ptr be, nss_XbyY_args_t *argp) {
2552830Sdjl return (_nss_ldap_hosts2str_int(AF_INET, be, argp));
2562830Sdjl }
2570Sstevel@tonic-gate
2580Sstevel@tonic-gate /*
2590Sstevel@tonic-gate * getbyname gets a struct hostent by hostname. This function constructs
2600Sstevel@tonic-gate * an ldap search filter using the name invocation parameter and the
2610Sstevel@tonic-gate * gethostbyname search filter defined. Once the filter is constructed,
2620Sstevel@tonic-gate * we search for a matching entry and marshal the data results into
2630Sstevel@tonic-gate * struct hostent for the frontend process. Host name searches will be
2640Sstevel@tonic-gate * on fully qualified host names (foo.bar.sun.com)
2650Sstevel@tonic-gate */
2660Sstevel@tonic-gate
2670Sstevel@tonic-gate static nss_status_t
getbyname(ldap_backend_ptr be,void * a)2680Sstevel@tonic-gate getbyname(ldap_backend_ptr be, void *a)
2690Sstevel@tonic-gate {
2700Sstevel@tonic-gate char hostname[3 * MAXHOSTNAMELEN];
2710Sstevel@tonic-gate char realdomain[BUFSIZ];
2720Sstevel@tonic-gate nss_XbyY_args_t *argp = (nss_XbyY_args_t *)a;
2730Sstevel@tonic-gate nss_status_t lstat;
2740Sstevel@tonic-gate char searchfilter[SEARCHFILTERLEN];
2750Sstevel@tonic-gate char userdata[SEARCHFILTERLEN];
2760Sstevel@tonic-gate int rc;
2770Sstevel@tonic-gate
2780Sstevel@tonic-gate if (_ldap_filter_name(hostname, argp->key.name, sizeof (hostname)) != 0)
2790Sstevel@tonic-gate return ((nss_status_t)NSS_NOTFOUND);
2800Sstevel@tonic-gate
2810Sstevel@tonic-gate rc = snprintf(searchfilter, sizeof (searchfilter), _F_GETHOSTBYNAME,
2820Sstevel@tonic-gate hostname);
2830Sstevel@tonic-gate if (rc >= sizeof (searchfilter) || rc < 0)
2840Sstevel@tonic-gate return ((nss_status_t)NSS_NOTFOUND);
2850Sstevel@tonic-gate
2860Sstevel@tonic-gate rc = snprintf(userdata, sizeof (userdata), _F_GETHOSTBYNAME_SSD,
2870Sstevel@tonic-gate hostname);
2880Sstevel@tonic-gate if (rc >= sizeof (userdata) || rc < 0)
2890Sstevel@tonic-gate return ((nss_status_t)NSS_NOTFOUND);
2900Sstevel@tonic-gate
2910Sstevel@tonic-gate /* get the domain we are in */
2920Sstevel@tonic-gate rc = sysinfo(SI_SRPC_DOMAIN, realdomain, BUFSIZ);
2930Sstevel@tonic-gate if (rc <= 0)
2940Sstevel@tonic-gate return ((nss_status_t)NSS_NOTFOUND);
2950Sstevel@tonic-gate
2960Sstevel@tonic-gate /* Is this a request for a host.domain */
2970Sstevel@tonic-gate if (DOTTEDSUBDOMAIN(hostname)) {
2980Sstevel@tonic-gate char host[MAXHOSTNAMELEN];
2990Sstevel@tonic-gate char domain[MAXHOSTNAMELEN];
3000Sstevel@tonic-gate char hname[3 * MAXHOSTNAMELEN];
3010Sstevel@tonic-gate
3020Sstevel@tonic-gate /* separate host and domain. this function */
3030Sstevel@tonic-gate /* will munge hname, so use argp->keyname */
3040Sstevel@tonic-gate /* from here on for original string */
3050Sstevel@tonic-gate
3060Sstevel@tonic-gate (void) strcpy(hname, hostname);
3070Sstevel@tonic-gate
3080Sstevel@tonic-gate if (chophostdomain(hname, host, domain) == -1) {
3090Sstevel@tonic-gate return ((nss_status_t)NSS_NOTFOUND);
3100Sstevel@tonic-gate }
3110Sstevel@tonic-gate
3120Sstevel@tonic-gate /* if domain is a proper subset of realdomain */
3130Sstevel@tonic-gate /* ie. domain = "eng" and realdomain */
3140Sstevel@tonic-gate /* = "eng.wiz.com", we try to lookup both" */
3150Sstevel@tonic-gate /* host.domain and host */
3160Sstevel@tonic-gate
3170Sstevel@tonic-gate if (propersubdomain(realdomain, domain) == 1) {
3180Sstevel@tonic-gate /* yes, it is a proper domain */
3190Sstevel@tonic-gate rc = snprintf(searchfilter, sizeof (searchfilter),
3200Sstevel@tonic-gate _F_GETHOSTDOTTEDBYNAME, hostname, host);
3210Sstevel@tonic-gate if (rc >= sizeof (searchfilter) || rc < 0)
3220Sstevel@tonic-gate return ((nss_status_t)NSS_NOTFOUND);
3230Sstevel@tonic-gate
3240Sstevel@tonic-gate rc = snprintf(userdata, sizeof (userdata),
3250Sstevel@tonic-gate _F_GETHOSTDOTTEDBYNAME_SSD, hostname, host);
3260Sstevel@tonic-gate if (rc >= sizeof (userdata) || rc < 0)
3270Sstevel@tonic-gate return ((nss_status_t)NSS_NOTFOUND);
3280Sstevel@tonic-gate } else {
3290Sstevel@tonic-gate /* it is not a proper domain, so only try to look up */
3300Sstevel@tonic-gate /* host.domain */
3310Sstevel@tonic-gate rc = snprintf(searchfilter, sizeof (searchfilter),
3320Sstevel@tonic-gate _F_GETHOSTBYNAME, hostname);
3330Sstevel@tonic-gate if (rc >= sizeof (searchfilter) || rc < 0)
3340Sstevel@tonic-gate return ((nss_status_t)NSS_NOTFOUND);
3350Sstevel@tonic-gate
3360Sstevel@tonic-gate rc = snprintf(userdata, sizeof (userdata),
3370Sstevel@tonic-gate _F_GETHOSTBYNAME_SSD, hostname);
3380Sstevel@tonic-gate if (rc >= sizeof (userdata) || rc < 0)
3390Sstevel@tonic-gate return ((nss_status_t)NSS_NOTFOUND);
3400Sstevel@tonic-gate }
3410Sstevel@tonic-gate } else {
3420Sstevel@tonic-gate rc = snprintf(searchfilter, sizeof (searchfilter),
3430Sstevel@tonic-gate _F_GETHOSTBYNAME, hostname);
3440Sstevel@tonic-gate if (rc >= sizeof (searchfilter) || rc < 0)
3450Sstevel@tonic-gate return ((nss_status_t)NSS_NOTFOUND);
3460Sstevel@tonic-gate
3470Sstevel@tonic-gate rc = snprintf(userdata, sizeof (userdata),
3480Sstevel@tonic-gate _F_GETHOSTBYNAME_SSD, hostname);
3490Sstevel@tonic-gate if (rc >= sizeof (userdata) || rc < 0)
3500Sstevel@tonic-gate return ((nss_status_t)NSS_NOTFOUND);
3510Sstevel@tonic-gate }
352*5361Schinlong lstat = (nss_status_t)_nss_ldap_lookup(be, argp, _HOSTS, searchfilter,
353*5361Schinlong NULL, _merge_SSD_filter, userdata);
3540Sstevel@tonic-gate if (lstat == (nss_status_t)NS_LDAP_SUCCESS)
3550Sstevel@tonic-gate return ((nss_status_t)NSS_SUCCESS);
3560Sstevel@tonic-gate
3570Sstevel@tonic-gate argp->h_errno = __nss2herrno(lstat);
3580Sstevel@tonic-gate return ((nss_status_t)lstat);
3590Sstevel@tonic-gate }
3600Sstevel@tonic-gate
3610Sstevel@tonic-gate
3620Sstevel@tonic-gate /*
3630Sstevel@tonic-gate * getbyaddr gets a struct hostent by host address. This function
3640Sstevel@tonic-gate * constructs an ldap search filter using the host address invocation
3650Sstevel@tonic-gate * parameter and the gethostbyaddr search filter defined. Once the
3660Sstevel@tonic-gate * filter is constructed, we search for a matching entry and marshal
3670Sstevel@tonic-gate * the data results into struct hostent for the frontend process.
3680Sstevel@tonic-gate *
3690Sstevel@tonic-gate * extern char *inet_ntoa_r() not an advertised function from libnsl.
3700Sstevel@tonic-gate * There is no man page and no prototype.
3710Sstevel@tonic-gate */
3720Sstevel@tonic-gate
3730Sstevel@tonic-gate static nss_status_t
getbyaddr(ldap_backend_ptr be,void * a)3740Sstevel@tonic-gate getbyaddr(ldap_backend_ptr be, void *a)
3750Sstevel@tonic-gate {
3760Sstevel@tonic-gate nss_XbyY_args_t *argp = (nss_XbyY_args_t *)a;
3770Sstevel@tonic-gate struct in_addr addr;
3780Sstevel@tonic-gate char buf[18];
3790Sstevel@tonic-gate nss_status_t lstat;
3800Sstevel@tonic-gate extern char *inet_ntoa_r();
3810Sstevel@tonic-gate char searchfilter[SEARCHFILTERLEN];
3820Sstevel@tonic-gate char userdata[SEARCHFILTERLEN];
3830Sstevel@tonic-gate int ret;
3840Sstevel@tonic-gate
3850Sstevel@tonic-gate argp->h_errno = 0;
3860Sstevel@tonic-gate if ((argp->key.hostaddr.type != AF_INET) ||
3870Sstevel@tonic-gate (argp->key.hostaddr.len != sizeof (addr)))
3880Sstevel@tonic-gate return (NSS_NOTFOUND);
3890Sstevel@tonic-gate
3900Sstevel@tonic-gate (void) memcpy(&addr, argp->key.hostaddr.addr, sizeof (addr));
3910Sstevel@tonic-gate (void) inet_ntoa_r(addr, buf);
3920Sstevel@tonic-gate
3930Sstevel@tonic-gate ret = snprintf(searchfilter, sizeof (searchfilter), _F_GETHOSTBYADDR,
3940Sstevel@tonic-gate buf);
3950Sstevel@tonic-gate if (ret >= sizeof (searchfilter) || ret < 0)
3960Sstevel@tonic-gate return ((nss_status_t)NSS_NOTFOUND);
3970Sstevel@tonic-gate
3980Sstevel@tonic-gate ret = snprintf(userdata, sizeof (userdata), _F_GETHOSTBYADDR_SSD, buf);
3990Sstevel@tonic-gate if (ret >= sizeof (userdata) || ret < 0)
4000Sstevel@tonic-gate return ((nss_status_t)NSS_NOTFOUND);
4010Sstevel@tonic-gate
402*5361Schinlong lstat = (nss_status_t)_nss_ldap_lookup(be, argp, _HOSTS, searchfilter,
403*5361Schinlong NULL, _merge_SSD_filter, userdata);
4040Sstevel@tonic-gate if (lstat == (nss_status_t)NS_LDAP_SUCCESS)
4050Sstevel@tonic-gate return ((nss_status_t)NSS_SUCCESS);
4060Sstevel@tonic-gate
4070Sstevel@tonic-gate argp->h_errno = __nss2herrno(lstat);
4080Sstevel@tonic-gate return ((nss_status_t)lstat);
4090Sstevel@tonic-gate }
4100Sstevel@tonic-gate
4110Sstevel@tonic-gate static ldap_backend_op_t hosts_ops[] = {
4120Sstevel@tonic-gate _nss_ldap_destr,
4130Sstevel@tonic-gate _nss_ldap_endent,
4140Sstevel@tonic-gate _nss_ldap_setent,
4150Sstevel@tonic-gate _nss_ldap_getent,
4160Sstevel@tonic-gate getbyname,
4170Sstevel@tonic-gate getbyaddr
4180Sstevel@tonic-gate };
4190Sstevel@tonic-gate
4200Sstevel@tonic-gate
4210Sstevel@tonic-gate /*
4220Sstevel@tonic-gate * _nss_ldap_hosts_constr is where life begins. This function calls the generic
4230Sstevel@tonic-gate * ldap constructor function to define and build the abstract data types
4240Sstevel@tonic-gate * required to support ldap operations.
4250Sstevel@tonic-gate */
4260Sstevel@tonic-gate
4270Sstevel@tonic-gate /*ARGSUSED0*/
4280Sstevel@tonic-gate nss_backend_t *
_nss_ldap_hosts_constr(const char * dummy1,const char * dummy2,const char * dummy3)4290Sstevel@tonic-gate _nss_ldap_hosts_constr(const char *dummy1, const char *dummy2,
4300Sstevel@tonic-gate const char *dummy3)
4310Sstevel@tonic-gate {
4320Sstevel@tonic-gate
4330Sstevel@tonic-gate return ((nss_backend_t *)_nss_ldap_constr(hosts_ops,
434*5361Schinlong sizeof (hosts_ops)/sizeof (hosts_ops[0]), _HOSTS,
435*5361Schinlong hosts_attrs, _nss_ldap_hosts2str));
4360Sstevel@tonic-gate }
437