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
5*2830Sdjl * Common Development and Distribution License (the "License").
6*2830Sdjl * 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*2830Sdjl * Copyright 2006 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 <ctype.h>
290Sstevel@tonic-gate #include <netdb.h>
300Sstevel@tonic-gate #include "ns_internal.h"
310Sstevel@tonic-gate #include "ldap_common.h"
320Sstevel@tonic-gate
330Sstevel@tonic-gate /* services attributes filters */
340Sstevel@tonic-gate #define _S_NAME "cn"
350Sstevel@tonic-gate #define _S_PORT "ipserviceport"
360Sstevel@tonic-gate #define _S_PROTOCOL "ipserviceprotocol"
370Sstevel@tonic-gate #define _F_GETSERVBYNAME "(&(objectClass=ipService)(cn=%s))"
380Sstevel@tonic-gate #define _F_GETSERVBYNAME_SSD "(&(%%s)(cn=%s))"
390Sstevel@tonic-gate #define _F_GETSERVBYNAMEPROTO \
400Sstevel@tonic-gate "(&(objectClass=ipService)(cn=%s)(ipServiceProtocol=%s))"
410Sstevel@tonic-gate #define _F_GETSERVBYNAMEPROTO_SSD \
420Sstevel@tonic-gate "(&(%%s)(cn=%s)(ipServiceProtocol=%s))"
430Sstevel@tonic-gate #define _F_GETSERVBYPORT "(&(objectClass=ipService)(ipServicePort=%ld))"
440Sstevel@tonic-gate #define _F_GETSERVBYPORT_SSD "(&(%%s)(ipServicePort=%ld))"
450Sstevel@tonic-gate #define _F_GETSERVBYPORTPROTO \
460Sstevel@tonic-gate "(&(objectClass=ipService)(ipServicePort=%ld)(ipServiceProtocol=%s))"
470Sstevel@tonic-gate #define _F_GETSERVBYPORTPROTO_SSD \
480Sstevel@tonic-gate "(&(%%s)(ipServicePort=%ld)(ipServiceProtocol=%s))"
490Sstevel@tonic-gate
500Sstevel@tonic-gate typedef struct _nss_services_cookie {
510Sstevel@tonic-gate int index; /* index of ipserviceprotocol */
520Sstevel@tonic-gate char *cname; /* canonical name, don't free it */
530Sstevel@tonic-gate ns_ldap_result_t *result;
540Sstevel@tonic-gate } _nss_services_cookie_t;
550Sstevel@tonic-gate
560Sstevel@tonic-gate static const char *services_attrs[] = {
570Sstevel@tonic-gate _S_NAME,
580Sstevel@tonic-gate _S_PORT,
590Sstevel@tonic-gate _S_PROTOCOL,
600Sstevel@tonic-gate (char *)NULL
610Sstevel@tonic-gate };
620Sstevel@tonic-gate
630Sstevel@tonic-gate void
_nss_services_cookie_free(void ** ckP)640Sstevel@tonic-gate _nss_services_cookie_free(void **ckP) {
650Sstevel@tonic-gate _nss_services_cookie_t **cookieP = (_nss_services_cookie_t **)ckP;
660Sstevel@tonic-gate if (cookieP && *cookieP) {
670Sstevel@tonic-gate if ((*cookieP)->result)
680Sstevel@tonic-gate (void) __ns_ldap_freeResult(&(*cookieP)->result);
690Sstevel@tonic-gate free(*cookieP);
700Sstevel@tonic-gate *cookieP = NULL;
710Sstevel@tonic-gate }
720Sstevel@tonic-gate }
730Sstevel@tonic-gate
740Sstevel@tonic-gate static _nss_services_cookie_t *
_nss_services_cookie_new(ns_ldap_result_t * result,int index,char * cname)750Sstevel@tonic-gate _nss_services_cookie_new(ns_ldap_result_t *result, int index, char *cname) {
760Sstevel@tonic-gate
770Sstevel@tonic-gate _nss_services_cookie_t *cookie;
780Sstevel@tonic-gate
790Sstevel@tonic-gate if ((cookie = calloc(1, sizeof (*cookie))) == NULL)
800Sstevel@tonic-gate return (NULL);
810Sstevel@tonic-gate
820Sstevel@tonic-gate /*
830Sstevel@tonic-gate * result has been allocated either by __ns_ldap_firstEntry
840Sstevel@tonic-gate * or __ns_ldap_nextEntry.
850Sstevel@tonic-gate */
860Sstevel@tonic-gate cookie->result = result;
870Sstevel@tonic-gate
880Sstevel@tonic-gate cookie->index = index;
890Sstevel@tonic-gate cookie->cname = cname;
900Sstevel@tonic-gate
910Sstevel@tonic-gate return (cookie);
920Sstevel@tonic-gate }
930Sstevel@tonic-gate /*
94*2830Sdjl * _nss_ldap_services2str is the data marshaling method for the services
950Sstevel@tonic-gate * getXbyY * (e.g., getbyname(), getbyport(), getent()) backend processes.
960Sstevel@tonic-gate * This method is called after a successful ldap search has been performed.
97*2830Sdjl * This method will parse the ldap search values into the file format.
98*2830Sdjl * e.g.
99*2830Sdjl *
100*2830Sdjl * nfsd 2049/udp nfs
101*2830Sdjl * nfsd 2049/tcp nfs
1020Sstevel@tonic-gate *
1030Sstevel@tonic-gate * In section 5.5 of RFC 2307, it specifies that a "services" LDAP entry
1040Sstevel@tonic-gate * containing multiple ipserviceprotocol values should be able to be mapped
1050Sstevel@tonic-gate * to multiple "services" entities. Code has been added to support
1060Sstevel@tonic-gate * this one to many mapping feature.
1070Sstevel@tonic-gate */
1080Sstevel@tonic-gate
1090Sstevel@tonic-gate static int
_nss_ldap_services2str(ldap_backend_ptr be,nss_XbyY_args_t * argp)110*2830Sdjl _nss_ldap_services2str(ldap_backend_ptr be, nss_XbyY_args_t *argp)
1110Sstevel@tonic-gate {
112*2830Sdjl uint_t i, k;
1130Sstevel@tonic-gate int nss_result;
114*2830Sdjl int buflen = 0, len;
115*2830Sdjl char **ipport, *cname = NULL, *protoval = NULL;
116*2830Sdjl char *buffer = NULL;
1170Sstevel@tonic-gate ns_ldap_result_t *result;
118*2830Sdjl ns_ldap_attr_t *names = NULL, *protocol = NULL;
1190Sstevel@tonic-gate _nss_services_cookie_t *cookie = (_nss_services_cookie_t *)
1200Sstevel@tonic-gate be->services_cookie;
1210Sstevel@tonic-gate
1220Sstevel@tonic-gate if (cookie) {
1230Sstevel@tonic-gate /*
1240Sstevel@tonic-gate * getservent_r with multiple protocol values and the entry
1250Sstevel@tonic-gate * is enumerated 2nd time or beyond
1260Sstevel@tonic-gate */
1270Sstevel@tonic-gate result = cookie->result;
1280Sstevel@tonic-gate cname = cookie->cname;
1290Sstevel@tonic-gate } else {
1300Sstevel@tonic-gate /*
1310Sstevel@tonic-gate * getservbyname_r, getservbyport_r or
1320Sstevel@tonic-gate * getservent_r with single protocol value or multiple values
1330Sstevel@tonic-gate * and the entry is enumerated 1st time
1340Sstevel@tonic-gate */
1350Sstevel@tonic-gate result = be->result;
1360Sstevel@tonic-gate }
137*2830Sdjl if (result == NULL) {
138*2830Sdjl nss_result = NSS_STR_PARSE_PARSE;
139*2830Sdjl goto result_srvs2str;
140*2830Sdjl }
1410Sstevel@tonic-gate
142*2830Sdjl buflen = argp->buf.buflen;
143*2830Sdjl if (argp->buf.result != NULL) {
144*2830Sdjl if ((be->buffer = calloc(1, buflen)) == NULL) {
145*2830Sdjl nss_result = NSS_STR_PARSE_PARSE;
146*2830Sdjl goto result_srvs2str;
147*2830Sdjl }
148*2830Sdjl buffer = be->buffer;
149*2830Sdjl } else
150*2830Sdjl buffer = argp->buf.buffer;
151*2830Sdjl
152*2830Sdjl
153*2830Sdjl nss_result = NSS_STR_PARSE_SUCCESS;
1540Sstevel@tonic-gate (void) memset(argp->buf.buffer, 0, buflen);
1550Sstevel@tonic-gate
156*2830Sdjl /* Get services names */
157*2830Sdjl names = __ns_ldap_getAttrStruct(result->entry, _S_NAME);
158*2830Sdjl if (names == NULL || names->attrvalue == NULL) {
159*2830Sdjl nss_result = NSS_STR_PARSE_PARSE;
160*2830Sdjl goto result_srvs2str;
161*2830Sdjl }
162*2830Sdjl /* Get canonical services name */
163*2830Sdjl if (cname == NULL) {
164*2830Sdjl cname = __s_api_get_canonical_name(result->entry, names, 1);
165*2830Sdjl if (cname == NULL || (len = strlen(cname)) < 1) {
166*2830Sdjl nss_result = NSS_STR_PARSE_PARSE;
167*2830Sdjl goto result_srvs2str;
168*2830Sdjl }
169*2830Sdjl }
170*2830Sdjl /* Get port */
171*2830Sdjl ipport = __ns_ldap_getAttr(result->entry, _S_PORT);
172*2830Sdjl if (ipport == NULL || ipport[0] == NULL ||
173*2830Sdjl (len = strlen(cname)) < 1) {
174*2830Sdjl nss_result = NSS_STR_PARSE_PARSE;
175*2830Sdjl goto result_srvs2str;
1760Sstevel@tonic-gate }
177*2830Sdjl /* Set services name and port and '/' */
178*2830Sdjl len = snprintf(buffer, buflen, "%s %s/", cname, ipport[0]);
179*2830Sdjl TEST_AND_ADJUST(len, buffer, buflen, result_srvs2str);
180*2830Sdjl
181*2830Sdjl /* Get protocol */
182*2830Sdjl protocol = __ns_ldap_getAttrStruct(result->entry, _S_PROTOCOL);
183*2830Sdjl if (protocol == NULL || protocol->attrvalue == NULL) {
184*2830Sdjl nss_result = NSS_STR_PARSE_PARSE;
185*2830Sdjl goto result_srvs2str;
186*2830Sdjl }
1870Sstevel@tonic-gate
188*2830Sdjl if (cookie) {
189*2830Sdjl /*
190*2830Sdjl * getservent_r
191*2830Sdjl * Get current value then increment index
192*2830Sdjl */
193*2830Sdjl protoval = protocol->attrvalue[cookie->index++];
194*2830Sdjl } else if (protocol->value_count > 1 && be->setcalled == 0 &&
195*2830Sdjl argp->key.serv.proto) {
196*2830Sdjl /*
197*2830Sdjl * getserverbyname_r and getservbyport_r
198*2830Sdjl *
199*2830Sdjl * If there are more than one value and
200*2830Sdjl * it needs to match protocol too,
201*2830Sdjl * iterate each value to find matching one.
202*2830Sdjl */
203*2830Sdjl for (k = 0; k < protocol->value_count; k++) {
204*2830Sdjl if (protocol->attrvalue[k] == NULL) {
205*2830Sdjl nss_result = NSS_STR_PARSE_PARSE;
206*2830Sdjl goto result_srvs2str;
207*2830Sdjl }
208*2830Sdjl if (strcmp(protocol->attrvalue[k],
209*2830Sdjl argp->key.serv.proto) == 0) {
210*2830Sdjl protoval = protocol->attrvalue[k];
211*2830Sdjl break;
2120Sstevel@tonic-gate }
2130Sstevel@tonic-gate }
214*2830Sdjl } else {
215*2830Sdjl /*
216*2830Sdjl * 1. getserverbyname_r and getservbyport_r
217*2830Sdjl *
218*2830Sdjl * It does not need to match protocol or
219*2830Sdjl * ipserviceprotocol has single value,
220*2830Sdjl * return the first one.
221*2830Sdjl *
222*2830Sdjl * 2. getservent_r with single ipserviceprotocol value
223*2830Sdjl * or multiple values and the entry is
224*2830Sdjl * enumerated 1st time, return the first one.
225*2830Sdjl *
226*2830Sdjl */
227*2830Sdjl protoval = protocol->attrvalue[0];
228*2830Sdjl }
2290Sstevel@tonic-gate
230*2830Sdjl if (protoval == NULL || (len = strlen(protoval)) < 1) {
231*2830Sdjl nss_result = NSS_STR_PARSE_PARSE;
232*2830Sdjl goto result_srvs2str;
233*2830Sdjl }
234*2830Sdjl
235*2830Sdjl /* Set protocol */
236*2830Sdjl len = snprintf(buffer, buflen, "%s", protoval);
237*2830Sdjl TEST_AND_ADJUST(len, buffer, buflen, result_srvs2str);
2380Sstevel@tonic-gate
239*2830Sdjl /* Append aliases */
240*2830Sdjl for (i = 0; i < names->value_count; i++) {
241*2830Sdjl if (names->attrvalue[i] == NULL) {
242*2830Sdjl nss_result = NSS_STR_PARSE_PARSE;
243*2830Sdjl goto result_srvs2str;
244*2830Sdjl }
245*2830Sdjl /* Skip the canonical name */
246*2830Sdjl if (strcmp(cname, names->attrvalue[i]) != 0) {
247*2830Sdjl len = snprintf(buffer, buflen, " %s",
248*2830Sdjl names->attrvalue[i]);
249*2830Sdjl TEST_AND_ADJUST(len, buffer, buflen, result_srvs2str);
2500Sstevel@tonic-gate }
2510Sstevel@tonic-gate }
2520Sstevel@tonic-gate
253*2830Sdjl
2540Sstevel@tonic-gate if (be->enumcookie != NULL && cookie == NULL &&
2550Sstevel@tonic-gate protocol->value_count > 1) {
2560Sstevel@tonic-gate /*
2570Sstevel@tonic-gate * getservent_r with multiple ipserviceprotocol values
2580Sstevel@tonic-gate * and the entry is enumerated 1st time
2590Sstevel@tonic-gate *
2600Sstevel@tonic-gate * Create cookie and save result in the cookie
2610Sstevel@tonic-gate * "attrvalue[0]" of ipserviceprotocol is returned,
2620Sstevel@tonic-gate * so it starts with index 1. Also save the canonical name.
2630Sstevel@tonic-gate */
2640Sstevel@tonic-gate be->services_cookie =
2650Sstevel@tonic-gate (void *)_nss_services_cookie_new(be->result, 1, cname);
2660Sstevel@tonic-gate if (be->services_cookie == NULL) {
2670Sstevel@tonic-gate nss_result = NSS_STR_PARSE_PARSE;
268*2830Sdjl goto result_srvs2str;
2690Sstevel@tonic-gate }
2700Sstevel@tonic-gate
2710Sstevel@tonic-gate /* reset be->result so it won't get freed later */
2720Sstevel@tonic-gate be->result = NULL;
2730Sstevel@tonic-gate }
2740Sstevel@tonic-gate
275*2830Sdjl /* The front end marshaller doesn't need to copy trailing nulls */
276*2830Sdjl if (argp->buf.result != NULL)
277*2830Sdjl be->buflen = strlen(be->buffer);
2780Sstevel@tonic-gate
279*2830Sdjl result_srvs2str:
2800Sstevel@tonic-gate if (cookie) {
2810Sstevel@tonic-gate /*
2820Sstevel@tonic-gate * getservent_r with multiple ipserviceprotocol values and
2830Sstevel@tonic-gate * the entry is enumerated 2nd time or beyond
2840Sstevel@tonic-gate */
2850Sstevel@tonic-gate if (nss_result != NSS_STR_PARSE_SUCCESS ||
2860Sstevel@tonic-gate cookie->index >= protocol->value_count) {
2870Sstevel@tonic-gate /*
2880Sstevel@tonic-gate * If it's an error case or it has iterated all
2890Sstevel@tonic-gate * ipservicesprotocol value(s) then free cookie and
2900Sstevel@tonic-gate * set it to NULL
2910Sstevel@tonic-gate *
2920Sstevel@tonic-gate */
2930Sstevel@tonic-gate _nss_services_cookie_free(
2940Sstevel@tonic-gate (void **)&be->services_cookie);
2950Sstevel@tonic-gate }
2960Sstevel@tonic-gate } else {
2970Sstevel@tonic-gate /*
2980Sstevel@tonic-gate * getservbyname_r, getservbyport_r, or
2990Sstevel@tonic-gate * getservent_r with single value or can't create cookie
3000Sstevel@tonic-gate */
3010Sstevel@tonic-gate (void) __ns_ldap_freeResult(&be->result);
3020Sstevel@tonic-gate }
303*2830Sdjl return (nss_result);
3040Sstevel@tonic-gate }
3050Sstevel@tonic-gate
3060Sstevel@tonic-gate /*
3070Sstevel@tonic-gate * getbyname gets struct servent values by service name. This
3080Sstevel@tonic-gate * function constructs an ldap search filter using the service
3090Sstevel@tonic-gate * name invocation parameter and the getservbyname search filter
3100Sstevel@tonic-gate * defined. Once the filter is constructed, we search for a matching
3110Sstevel@tonic-gate * entry and marshal the data results into *serv = (struct servent *)
3120Sstevel@tonic-gate * argp->buf.result. The function _nss_ldap_services2ent performs
3130Sstevel@tonic-gate * the data marshaling.
3140Sstevel@tonic-gate */
3150Sstevel@tonic-gate
3160Sstevel@tonic-gate static nss_status_t
getbyname(ldap_backend_ptr be,void * a)3170Sstevel@tonic-gate getbyname(ldap_backend_ptr be, void *a)
3180Sstevel@tonic-gate {
3190Sstevel@tonic-gate nss_XbyY_args_t *argp = (nss_XbyY_args_t *)a;
3200Sstevel@tonic-gate const char *proto = argp->key.serv.proto;
3210Sstevel@tonic-gate char searchfilter[SEARCHFILTERLEN];
3220Sstevel@tonic-gate char userdata[SEARCHFILTERLEN];
3230Sstevel@tonic-gate char name[SEARCHFILTERLEN];
3240Sstevel@tonic-gate char protocol[SEARCHFILTERLEN];
3250Sstevel@tonic-gate int ret;
3260Sstevel@tonic-gate
3270Sstevel@tonic-gate if (_ldap_filter_name(name, argp->key.serv.serv.name, sizeof (name))
3280Sstevel@tonic-gate != 0)
3290Sstevel@tonic-gate return ((nss_status_t)NSS_NOTFOUND);
3300Sstevel@tonic-gate
3310Sstevel@tonic-gate if (proto == NULL) {
3320Sstevel@tonic-gate ret = snprintf(searchfilter, sizeof (searchfilter),
3330Sstevel@tonic-gate _F_GETSERVBYNAME, name);
3340Sstevel@tonic-gate if (ret >= sizeof (searchfilter) || ret < 0)
3350Sstevel@tonic-gate return ((nss_status_t)NSS_NOTFOUND);
3360Sstevel@tonic-gate
3370Sstevel@tonic-gate ret = snprintf(userdata, sizeof (userdata),
3380Sstevel@tonic-gate _F_GETSERVBYNAME_SSD, name);
3390Sstevel@tonic-gate if (ret >= sizeof (userdata) || ret < 0)
3400Sstevel@tonic-gate return ((nss_status_t)NSS_NOTFOUND);
3410Sstevel@tonic-gate } else {
3420Sstevel@tonic-gate if (_ldap_filter_name(protocol, proto, sizeof (protocol)) != 0)
3430Sstevel@tonic-gate return ((nss_status_t)NSS_NOTFOUND);
3440Sstevel@tonic-gate
3450Sstevel@tonic-gate ret = snprintf(searchfilter, sizeof (searchfilter),
3460Sstevel@tonic-gate _F_GETSERVBYNAMEPROTO, name, protocol);
3470Sstevel@tonic-gate if (ret >= sizeof (searchfilter) || ret < 0)
3480Sstevel@tonic-gate return ((nss_status_t)NSS_NOTFOUND);
3490Sstevel@tonic-gate
3500Sstevel@tonic-gate ret = snprintf(userdata, sizeof (userdata),
3510Sstevel@tonic-gate _F_GETSERVBYNAMEPROTO_SSD, name, protocol);
3520Sstevel@tonic-gate if (ret >= sizeof (userdata) || ret < 0)
3530Sstevel@tonic-gate return ((nss_status_t)NSS_NOTFOUND);
3540Sstevel@tonic-gate }
3550Sstevel@tonic-gate
3560Sstevel@tonic-gate return ((nss_status_t)_nss_ldap_lookup(be, argp,
3570Sstevel@tonic-gate _SERVICES, searchfilter, NULL,
3580Sstevel@tonic-gate _merge_SSD_filter, userdata));
3590Sstevel@tonic-gate }
3600Sstevel@tonic-gate
3610Sstevel@tonic-gate
3620Sstevel@tonic-gate /*
3630Sstevel@tonic-gate * getbyport gets struct servent values by service port. This
3640Sstevel@tonic-gate * function constructs an ldap search filter using the service
3650Sstevel@tonic-gate * name invocation parameter and the getservbyport search filter
3660Sstevel@tonic-gate * defined. Once the filter is constructed, we search for a matching
3670Sstevel@tonic-gate * entry and marshal the data results into *serv = (struct servent *)
3680Sstevel@tonic-gate * argp->buf.result. The function _nss_ldap_services2ent performs
3690Sstevel@tonic-gate * the data marshaling.
3700Sstevel@tonic-gate */
3710Sstevel@tonic-gate
3720Sstevel@tonic-gate static nss_status_t
getbyport(ldap_backend_ptr be,void * a)3730Sstevel@tonic-gate getbyport(ldap_backend_ptr be, void *a)
3740Sstevel@tonic-gate {
3750Sstevel@tonic-gate nss_XbyY_args_t *argp = (nss_XbyY_args_t *)a;
3760Sstevel@tonic-gate const char *proto = argp->key.serv.proto;
3770Sstevel@tonic-gate char portstr[12];
3780Sstevel@tonic-gate char searchfilter[SEARCHFILTERLEN];
3790Sstevel@tonic-gate char userdata[SEARCHFILTERLEN];
3800Sstevel@tonic-gate char protocol[SEARCHFILTERLEN];
3810Sstevel@tonic-gate int ret;
3820Sstevel@tonic-gate
3830Sstevel@tonic-gate ret = snprintf(portstr, sizeof (portstr), " %d",
3840Sstevel@tonic-gate ntohs((ushort_t)argp->key.serv.serv.port));
3850Sstevel@tonic-gate if (ret >= sizeof (portstr) || ret < 0)
3860Sstevel@tonic-gate return ((nss_status_t)NSS_NOTFOUND);
3870Sstevel@tonic-gate
3880Sstevel@tonic-gate if (proto == NULL) {
3890Sstevel@tonic-gate ret = snprintf(searchfilter, sizeof (searchfilter),
3900Sstevel@tonic-gate _F_GETSERVBYPORT, strtol(portstr, (char **)NULL, 10));
3910Sstevel@tonic-gate if (ret >= sizeof (searchfilter) || ret < 0)
3920Sstevel@tonic-gate return ((nss_status_t)NSS_NOTFOUND);
3930Sstevel@tonic-gate
3940Sstevel@tonic-gate ret = snprintf(userdata, sizeof (userdata),
3950Sstevel@tonic-gate _F_GETSERVBYPORT_SSD, strtol(portstr, (char **)NULL, 10));
3960Sstevel@tonic-gate if (ret >= sizeof (userdata) || ret < 0)
3970Sstevel@tonic-gate return ((nss_status_t)NSS_NOTFOUND);
3980Sstevel@tonic-gate } else {
3990Sstevel@tonic-gate if (_ldap_filter_name(protocol, proto, sizeof (protocol)) != 0)
4000Sstevel@tonic-gate return ((nss_status_t)NSS_NOTFOUND);
4010Sstevel@tonic-gate
4020Sstevel@tonic-gate ret = snprintf(searchfilter, sizeof (searchfilter),
4030Sstevel@tonic-gate _F_GETSERVBYPORTPROTO,
4040Sstevel@tonic-gate strtol(portstr, (char **)NULL, 10), protocol);
4050Sstevel@tonic-gate if (ret >= sizeof (searchfilter) || ret < 0)
4060Sstevel@tonic-gate return ((nss_status_t)NSS_NOTFOUND);
4070Sstevel@tonic-gate
4080Sstevel@tonic-gate ret = snprintf(userdata, sizeof (userdata),
4090Sstevel@tonic-gate _F_GETSERVBYPORTPROTO_SSD,
4100Sstevel@tonic-gate strtol(portstr, (char **)NULL, 10), protocol);
4110Sstevel@tonic-gate if (ret >= sizeof (userdata) || ret < 0)
4120Sstevel@tonic-gate return ((nss_status_t)NSS_NOTFOUND);
4130Sstevel@tonic-gate }
4140Sstevel@tonic-gate
4150Sstevel@tonic-gate return ((nss_status_t)_nss_ldap_lookup(be, argp,
4160Sstevel@tonic-gate _SERVICES, searchfilter, NULL,
4170Sstevel@tonic-gate _merge_SSD_filter, userdata));
4180Sstevel@tonic-gate }
4190Sstevel@tonic-gate
4200Sstevel@tonic-gate static ldap_backend_op_t serv_ops[] = {
4210Sstevel@tonic-gate _nss_ldap_destr,
4220Sstevel@tonic-gate _nss_ldap_endent,
4230Sstevel@tonic-gate _nss_ldap_setent,
4240Sstevel@tonic-gate _nss_ldap_getent,
4250Sstevel@tonic-gate getbyname,
4260Sstevel@tonic-gate getbyport
4270Sstevel@tonic-gate };
4280Sstevel@tonic-gate
4290Sstevel@tonic-gate
4300Sstevel@tonic-gate /*
4310Sstevel@tonic-gate * _nss_ldap_services_constr is where life begins. This function calls
4320Sstevel@tonic-gate * the generic ldap constructor function to define and build the
4330Sstevel@tonic-gate * abstract data types required to support ldap operations.
4340Sstevel@tonic-gate */
4350Sstevel@tonic-gate
4360Sstevel@tonic-gate /*ARGSUSED0*/
4370Sstevel@tonic-gate nss_backend_t *
_nss_ldap_services_constr(const char * dummy1,const char * dummy2,const char * dummy3)4380Sstevel@tonic-gate _nss_ldap_services_constr(const char *dummy1, const char *dummy2,
4390Sstevel@tonic-gate const char *dummy3)
4400Sstevel@tonic-gate {
4410Sstevel@tonic-gate
4420Sstevel@tonic-gate return ((nss_backend_t *)_nss_ldap_constr(serv_ops,
4430Sstevel@tonic-gate sizeof (serv_ops)/sizeof (serv_ops[0]), _SERVICES,
444*2830Sdjl services_attrs, _nss_ldap_services2str));
4450Sstevel@tonic-gate }
446