17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5cb5caa98Sdjl * Common Development and Distribution License (the "License"). 6cb5caa98Sdjl * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 22*01ef659dSJoep Vesseur * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate #include <stdlib.h> 277c478bd9Sstevel@tonic-gate #include <string.h> 287c478bd9Sstevel@tonic-gate #include <sys/types.h> 297c478bd9Sstevel@tonic-gate #include <exec_attr.h> 307c478bd9Sstevel@tonic-gate #include <rpcsvc/ypclnt.h> 317c478bd9Sstevel@tonic-gate #include <rpcsvc/yp_prot.h> 327c478bd9Sstevel@tonic-gate #include "nis_common.h" 337c478bd9Sstevel@tonic-gate 347c478bd9Sstevel@tonic-gate 357c478bd9Sstevel@tonic-gate /* extern from nis_common.c */ 367c478bd9Sstevel@tonic-gate extern void massage_netdb(const char **, int *); 377c478bd9Sstevel@tonic-gate /* externs from libnsl */ 387c478bd9Sstevel@tonic-gate extern int _doexeclist(nss_XbyY_args_t *); 397c478bd9Sstevel@tonic-gate extern char *_exec_wild_id(char *, const char *); 407c478bd9Sstevel@tonic-gate extern void _exec_cleanup(nss_status_t, nss_XbyY_args_t *); 41cb5caa98Sdjl extern char *_strtok_escape(char *, char *, char **); 427c478bd9Sstevel@tonic-gate 437c478bd9Sstevel@tonic-gate typedef struct __exec_nis_args { 447c478bd9Sstevel@tonic-gate int *yp_status; 457c478bd9Sstevel@tonic-gate nss_XbyY_args_t *argp; 467c478bd9Sstevel@tonic-gate } _exec_nis_args; 477c478bd9Sstevel@tonic-gate 487c478bd9Sstevel@tonic-gate 497c478bd9Sstevel@tonic-gate /* 507c478bd9Sstevel@tonic-gate * check_match: returns 1 if - matching entry found and no more entries needed, 517c478bd9Sstevel@tonic-gate * or, entry cannot be found because of error; 527c478bd9Sstevel@tonic-gate * returns 0 if - no matching entry found, or, 537c478bd9Sstevel@tonic-gate * matching entry found and next match needed. 547c478bd9Sstevel@tonic-gate */ 557c478bd9Sstevel@tonic-gate static int 567c478bd9Sstevel@tonic-gate check_match(nss_XbyY_args_t *argp, int check_policy) 577c478bd9Sstevel@tonic-gate { 587c478bd9Sstevel@tonic-gate execstr_t *exec = (execstr_t *)(argp->returnval); 597c478bd9Sstevel@tonic-gate _priv_execattr *_priv_exec = (_priv_execattr *)(argp->key.attrp); 607c478bd9Sstevel@tonic-gate const char *name = _priv_exec->name; 617c478bd9Sstevel@tonic-gate const char *type = _priv_exec->type; 627c478bd9Sstevel@tonic-gate const char *id = _priv_exec->id; 637c478bd9Sstevel@tonic-gate const char *policy = _priv_exec->policy; 647c478bd9Sstevel@tonic-gate 657c478bd9Sstevel@tonic-gate if (name && id) { 667c478bd9Sstevel@tonic-gate /* 677c478bd9Sstevel@tonic-gate * NSS_DBOP_EXECATTR_BYNAMEID searched for name and id in 687c478bd9Sstevel@tonic-gate * _exec_nis_lookup already. 697c478bd9Sstevel@tonic-gate * If we're talking to pre-Solaris9 nis servers, check policy, 707c478bd9Sstevel@tonic-gate * as policy was not a searchable column then. 717c478bd9Sstevel@tonic-gate */ 727c478bd9Sstevel@tonic-gate if ((check_policy && policy && 737c478bd9Sstevel@tonic-gate (strcmp(policy, exec->policy) != 0)) || 747c478bd9Sstevel@tonic-gate (type && (strcmp(type, exec->type) != 0))) { 757c478bd9Sstevel@tonic-gate return (0); 767c478bd9Sstevel@tonic-gate } 777c478bd9Sstevel@tonic-gate } else if ((policy && exec->policy && 787c478bd9Sstevel@tonic-gate (strcmp(policy, exec->policy) != 0)) || 797c478bd9Sstevel@tonic-gate (name && exec->name && (strcmp(name, exec->name) != 0)) || 807c478bd9Sstevel@tonic-gate (type && exec->type && (strcmp(type, exec->type) != 0)) || 817c478bd9Sstevel@tonic-gate (id && exec->id && (strcmp(id, exec->id) != 0))) { 827c478bd9Sstevel@tonic-gate return (0); 837c478bd9Sstevel@tonic-gate } 847c478bd9Sstevel@tonic-gate 857c478bd9Sstevel@tonic-gate return (1); 867c478bd9Sstevel@tonic-gate } 877c478bd9Sstevel@tonic-gate 88cb5caa98Sdjl /* 89cb5caa98Sdjl * check_match_strbuf: set up the data needed by check_match() 90cb5caa98Sdjl * and call it to match exec_attr data in strbuf and argp->key.attrp 91cb5caa98Sdjl */ 92cb5caa98Sdjl static int 93cb5caa98Sdjl check_match_strbuf(nss_XbyY_args_t *argp, char *strbuf, int check_policy) 94cb5caa98Sdjl { 95cb5caa98Sdjl char *last = NULL; 96cb5caa98Sdjl char *sep = KV_TOKEN_DELIMIT; 97cb5caa98Sdjl execstr_t exec; 98cb5caa98Sdjl execstr_t *execp = &exec; 99cb5caa98Sdjl void *sp; 100cb5caa98Sdjl int rc; 101cb5caa98Sdjl 102cb5caa98Sdjl /* 103cb5caa98Sdjl * Remove newline that yp_match puts at the 104cb5caa98Sdjl * end of the entry it retrieves from the map. 105cb5caa98Sdjl */ 106cb5caa98Sdjl if (strbuf[argp->returnlen] == '\n') { 107cb5caa98Sdjl strbuf[argp->returnlen] = '\0'; 108cb5caa98Sdjl } 109cb5caa98Sdjl 110cb5caa98Sdjl execp->name = _strtok_escape(strbuf, sep, &last); 111cb5caa98Sdjl execp->policy = _strtok_escape(NULL, sep, &last); 112cb5caa98Sdjl execp->type = _strtok_escape(NULL, sep, &last); 113cb5caa98Sdjl execp->res1 = _strtok_escape(NULL, sep, &last); 114cb5caa98Sdjl execp->res2 = _strtok_escape(NULL, sep, &last); 115cb5caa98Sdjl execp->id = _strtok_escape(NULL, sep, &last); 116cb5caa98Sdjl 117cb5caa98Sdjl sp = argp->returnval; 118cb5caa98Sdjl argp->returnval = execp; 119cb5caa98Sdjl rc = check_match(argp, check_policy); 120cb5caa98Sdjl argp->returnval = sp; 121cb5caa98Sdjl free(strbuf); 122cb5caa98Sdjl 123cb5caa98Sdjl return (rc); 124cb5caa98Sdjl } 1257c478bd9Sstevel@tonic-gate 1267c478bd9Sstevel@tonic-gate static nss_status_t 1277c478bd9Sstevel@tonic-gate _exec_nis_parse(const char *instr, 1287c478bd9Sstevel@tonic-gate int instr_len, 1297c478bd9Sstevel@tonic-gate nss_XbyY_args_t *argp, 1307c478bd9Sstevel@tonic-gate int check_policy) 1317c478bd9Sstevel@tonic-gate { 1327c478bd9Sstevel@tonic-gate int parse_stat; 1337c478bd9Sstevel@tonic-gate nss_status_t res; 1347c478bd9Sstevel@tonic-gate _priv_execattr *_priv_exec = (_priv_execattr *)(argp->key.attrp); 135cb5caa98Sdjl char *strbuf; 136cb5caa98Sdjl int check_matched; 1377c478bd9Sstevel@tonic-gate 138cb5caa98Sdjl argp->returnval = NULL; 139cb5caa98Sdjl argp->returnlen = 0; 1407c478bd9Sstevel@tonic-gate parse_stat = (*argp->str2ent)(instr, instr_len, argp->buf.result, 1417c478bd9Sstevel@tonic-gate argp->buf.buffer, argp->buf.buflen); 1427c478bd9Sstevel@tonic-gate switch (parse_stat) { 1437c478bd9Sstevel@tonic-gate case NSS_STR_PARSE_SUCCESS: 144cb5caa98Sdjl argp->returnlen = instr_len; 145cb5caa98Sdjl /* if exec_attr file format requested */ 146cb5caa98Sdjl if (argp->buf.result == NULL) { 147cb5caa98Sdjl argp->returnval = argp->buf.buffer; 148cb5caa98Sdjl if ((strbuf = strdup(instr)) == NULL) 149cb5caa98Sdjl res = NSS_UNAVAIL; 150cb5caa98Sdjl check_matched = check_match_strbuf(argp, 151cb5caa98Sdjl strbuf, check_policy); 152cb5caa98Sdjl } else { 1537c478bd9Sstevel@tonic-gate argp->returnval = argp->buf.result; 154cb5caa98Sdjl check_matched = check_match(argp, check_policy); 155cb5caa98Sdjl } 156cb5caa98Sdjl if (check_matched) { 1577c478bd9Sstevel@tonic-gate res = NSS_SUCCESS; 158*01ef659dSJoep Vesseur if (IS_GET_ALL(_priv_exec->search_flag)) { 1597c478bd9Sstevel@tonic-gate if (_doexeclist(argp) == 0) { 1607c478bd9Sstevel@tonic-gate res = NSS_UNAVAIL; 1617c478bd9Sstevel@tonic-gate } 1627c478bd9Sstevel@tonic-gate } 1637c478bd9Sstevel@tonic-gate } else { 1647c478bd9Sstevel@tonic-gate res = NSS_NOTFOUND; 1657c478bd9Sstevel@tonic-gate } 1667c478bd9Sstevel@tonic-gate break; 1677c478bd9Sstevel@tonic-gate case NSS_STR_PARSE_ERANGE: 1687c478bd9Sstevel@tonic-gate argp->erange = 1; 1697c478bd9Sstevel@tonic-gate res = NSS_NOTFOUND; 1707c478bd9Sstevel@tonic-gate break; 1717c478bd9Sstevel@tonic-gate default: 1727c478bd9Sstevel@tonic-gate res = NSS_UNAVAIL; 1737c478bd9Sstevel@tonic-gate break; 1747c478bd9Sstevel@tonic-gate } 1757c478bd9Sstevel@tonic-gate 1767c478bd9Sstevel@tonic-gate return (res); 1777c478bd9Sstevel@tonic-gate } 1787c478bd9Sstevel@tonic-gate 1797c478bd9Sstevel@tonic-gate /* 1807c478bd9Sstevel@tonic-gate * This is the callback for yp_all. It returns 0 to indicate that it wants to 1817c478bd9Sstevel@tonic-gate * be called again for further key-value pairs, or returns non-zero to stop the 1827c478bd9Sstevel@tonic-gate * flow of key-value pairs. If it returns a non-zero value, it is not called 1837c478bd9Sstevel@tonic-gate * again. The functional value of yp_all is then 0. 1847c478bd9Sstevel@tonic-gate */ 185cb5caa98Sdjl /*ARGSUSED*/ 1867c478bd9Sstevel@tonic-gate static int 1877c478bd9Sstevel@tonic-gate _exec_nis_cb(int instatus, 1887c478bd9Sstevel@tonic-gate char *inkey, 1897c478bd9Sstevel@tonic-gate int inkeylen, 1907c478bd9Sstevel@tonic-gate char *inval, 1917c478bd9Sstevel@tonic-gate int invallen, 1927c478bd9Sstevel@tonic-gate void *indata) 1937c478bd9Sstevel@tonic-gate { 1947c478bd9Sstevel@tonic-gate int check_policy = 1; /* always check policy for yp_all */ 1957c478bd9Sstevel@tonic-gate int stop_cb; 1967c478bd9Sstevel@tonic-gate const char *filter; 1977c478bd9Sstevel@tonic-gate nss_status_t res; 1987c478bd9Sstevel@tonic-gate _exec_nis_args *eargp = (_exec_nis_args *)indata; 1997c478bd9Sstevel@tonic-gate nss_XbyY_args_t *argp = eargp->argp; 2007c478bd9Sstevel@tonic-gate _priv_execattr *_priv_exec = (_priv_execattr *)(argp->key.attrp); 2017c478bd9Sstevel@tonic-gate 2027c478bd9Sstevel@tonic-gate if (instatus != YP_TRUE) { 203bf1f3d92Ssdussud /* 204bf1f3d92Ssdussud * If we have no more data to look at, we want to 205bf1f3d92Ssdussud * keep yp_status from previous key/value pair 206bf1f3d92Ssdussud * that we processed. 207bf1f3d92Ssdussud * If this is the 1st time we enter this callback, 208bf1f3d92Ssdussud * yp_status is already set to YPERR_YPERR 209bf1f3d92Ssdussud * (see _exec_nis_lookup() for when this callback 210bf1f3d92Ssdussud * and arguments are set initially). 211bf1f3d92Ssdussud */ 212bf1f3d92Ssdussud if (instatus != YP_NOMORE) { 2137c478bd9Sstevel@tonic-gate *(eargp->yp_status) = YPERR_YPERR; 214bf1f3d92Ssdussud } 2157c478bd9Sstevel@tonic-gate return (0); /* yp_all may decide otherwise... */ 2167c478bd9Sstevel@tonic-gate } 2177c478bd9Sstevel@tonic-gate 2187c478bd9Sstevel@tonic-gate filter = (_priv_exec->name) ? _priv_exec->name : _priv_exec->id; 2197c478bd9Sstevel@tonic-gate 2207c478bd9Sstevel@tonic-gate /* 2217c478bd9Sstevel@tonic-gate * yp_all does not null terminate the entry it retrieves from the 2227c478bd9Sstevel@tonic-gate * map, unlike yp_match. so we do it explicitly here. 2237c478bd9Sstevel@tonic-gate */ 2247c478bd9Sstevel@tonic-gate inval[invallen] = '\0'; 2257c478bd9Sstevel@tonic-gate 2267c478bd9Sstevel@tonic-gate /* 2277c478bd9Sstevel@tonic-gate * Optimization: if the entry doesn't contain the filter string then 2287c478bd9Sstevel@tonic-gate * it can't be the entry we want, so don't bother looking more closely 2297c478bd9Sstevel@tonic-gate * at it. 2307c478bd9Sstevel@tonic-gate */ 2317c478bd9Sstevel@tonic-gate if ((_priv_exec->policy && 2327c478bd9Sstevel@tonic-gate (strstr(inval, _priv_exec->policy) == NULL)) || 2337c478bd9Sstevel@tonic-gate (strstr(inval, filter) == NULL)) { 2347c478bd9Sstevel@tonic-gate *(eargp->yp_status) = YPERR_KEY; 2357c478bd9Sstevel@tonic-gate return (0); 2367c478bd9Sstevel@tonic-gate } 2377c478bd9Sstevel@tonic-gate 2387c478bd9Sstevel@tonic-gate res = _exec_nis_parse(inval, invallen, argp, check_policy); 2397c478bd9Sstevel@tonic-gate 2407c478bd9Sstevel@tonic-gate switch (res) { 2417c478bd9Sstevel@tonic-gate case NSS_SUCCESS: 2427c478bd9Sstevel@tonic-gate *(eargp->yp_status) = 0; 243*01ef659dSJoep Vesseur stop_cb = IS_GET_ONE(_priv_exec->search_flag); 2447c478bd9Sstevel@tonic-gate break; 2457c478bd9Sstevel@tonic-gate case NSS_UNAVAIL: 2467c478bd9Sstevel@tonic-gate *(eargp->yp_status) = YPERR_KEY; 2477c478bd9Sstevel@tonic-gate stop_cb = 1; 2487c478bd9Sstevel@tonic-gate break; 2497c478bd9Sstevel@tonic-gate default: 2507c478bd9Sstevel@tonic-gate *(eargp->yp_status) = YPERR_YPERR; 2517c478bd9Sstevel@tonic-gate stop_cb = 0; 2527c478bd9Sstevel@tonic-gate break; 2537c478bd9Sstevel@tonic-gate } 2547c478bd9Sstevel@tonic-gate 2557c478bd9Sstevel@tonic-gate return (stop_cb); 2567c478bd9Sstevel@tonic-gate } 2577c478bd9Sstevel@tonic-gate 2587c478bd9Sstevel@tonic-gate static nss_status_t 2597c478bd9Sstevel@tonic-gate _exec_nis_lookup(nis_backend_ptr_t be, nss_XbyY_args_t *argp, int getby_flag) 2607c478bd9Sstevel@tonic-gate { 2617c478bd9Sstevel@tonic-gate int ypstatus; 2627c478bd9Sstevel@tonic-gate nss_status_t res = NSS_SUCCESS; 2637c478bd9Sstevel@tonic-gate nss_status_t ypres; 2647c478bd9Sstevel@tonic-gate _priv_execattr *_priv_exec = (_priv_execattr *)(argp->key.attrp); 2657c478bd9Sstevel@tonic-gate 2667c478bd9Sstevel@tonic-gate if (getby_flag == NSS_DBOP_EXECATTR_BYNAMEID) { 2677c478bd9Sstevel@tonic-gate int check_policy = 0; 2687c478bd9Sstevel@tonic-gate int vallen; 2697c478bd9Sstevel@tonic-gate char *val; 2707c478bd9Sstevel@tonic-gate char key[MAX_INPUT]; 2717c478bd9Sstevel@tonic-gate 2727c478bd9Sstevel@tonic-gate /* 2737c478bd9Sstevel@tonic-gate * Try using policy as part of search key. If that fails, 2747c478bd9Sstevel@tonic-gate * (it will, in case of pre-Solaris9 nis server where policy 2757c478bd9Sstevel@tonic-gate * was not searchable), try again without using policy. 2767c478bd9Sstevel@tonic-gate */ 2777c478bd9Sstevel@tonic-gate if (snprintf(key, MAX_INPUT, "%s%s%s%s%s", _priv_exec->name, 2787c478bd9Sstevel@tonic-gate KV_TOKEN_DELIMIT, _priv_exec->policy, KV_TOKEN_DELIMIT, 2797c478bd9Sstevel@tonic-gate _priv_exec->id) >= MAX_INPUT) 2807c478bd9Sstevel@tonic-gate return (NSS_NOTFOUND); 2817c478bd9Sstevel@tonic-gate do { 2827c478bd9Sstevel@tonic-gate ypres = _nss_nis_ypmatch(be->domain, NIS_MAP_EXECATTR, 2837c478bd9Sstevel@tonic-gate key, &val, &vallen, &ypstatus); 2847c478bd9Sstevel@tonic-gate if ((check_policy == 0) && (ypstatus == YPERR_KEY)) { 2857c478bd9Sstevel@tonic-gate (void) snprintf(key, MAX_INPUT, "%s%s%s", 2867c478bd9Sstevel@tonic-gate _priv_exec->name, KV_TOKEN_DELIMIT, 2877c478bd9Sstevel@tonic-gate _priv_exec->id); 2887c478bd9Sstevel@tonic-gate check_policy = 1; 2897c478bd9Sstevel@tonic-gate continue; 2907c478bd9Sstevel@tonic-gate } else if (ypres != NSS_SUCCESS) { 2917c478bd9Sstevel@tonic-gate res = ypres; 2927c478bd9Sstevel@tonic-gate break; 2937c478bd9Sstevel@tonic-gate } else { 294458d6ca5Smichen char *val_save = val; 295458d6ca5Smichen 2967c478bd9Sstevel@tonic-gate massage_netdb((const char **)&val, &vallen); 2977c478bd9Sstevel@tonic-gate res = _exec_nis_parse((const char *)val, 2987c478bd9Sstevel@tonic-gate vallen, argp, check_policy); 299458d6ca5Smichen free(val_save); 3007c478bd9Sstevel@tonic-gate break; 3017c478bd9Sstevel@tonic-gate } 3027c478bd9Sstevel@tonic-gate } while (res == NSS_SUCCESS); 3037c478bd9Sstevel@tonic-gate } else { 3047c478bd9Sstevel@tonic-gate int ypstat = YPERR_YPERR; 3057c478bd9Sstevel@tonic-gate struct ypall_callback cback; 3067c478bd9Sstevel@tonic-gate _exec_nis_args eargs; 3077c478bd9Sstevel@tonic-gate 3087c478bd9Sstevel@tonic-gate eargs.yp_status = &ypstat; 3097c478bd9Sstevel@tonic-gate eargs.argp = argp; 3107c478bd9Sstevel@tonic-gate 3117c478bd9Sstevel@tonic-gate cback.foreach = _exec_nis_cb; 3127c478bd9Sstevel@tonic-gate cback.data = (void *)&eargs; 3137c478bd9Sstevel@tonic-gate 3147c478bd9Sstevel@tonic-gate /* 3157c478bd9Sstevel@tonic-gate * Instead of calling yp_all() doing hard lookup, we use 3167c478bd9Sstevel@tonic-gate * the alternative function, __yp_all_cflookup(), to 3177c478bd9Sstevel@tonic-gate * perform soft lookup when binding to nis servers with 3187c478bd9Sstevel@tonic-gate * time-out control. Other than that, these two functions 3197c478bd9Sstevel@tonic-gate * do exactly the same thing. 3207c478bd9Sstevel@tonic-gate */ 3217c478bd9Sstevel@tonic-gate ypstatus = __yp_all_cflookup((char *)(be->domain), 3227c478bd9Sstevel@tonic-gate (char *)(be->enum_map), &cback, 0); 3237c478bd9Sstevel@tonic-gate 3247c478bd9Sstevel@tonic-gate /* 3257c478bd9Sstevel@tonic-gate * For GET_ALL, check if we found anything at all. 3267c478bd9Sstevel@tonic-gate */ 3277c478bd9Sstevel@tonic-gate if (_priv_exec->head_exec != NULL) 3287c478bd9Sstevel@tonic-gate return (NSS_SUCCESS); 3297c478bd9Sstevel@tonic-gate 3307c478bd9Sstevel@tonic-gate switch (ypstat) { 3317c478bd9Sstevel@tonic-gate case 0: 3327c478bd9Sstevel@tonic-gate res = NSS_SUCCESS; 3337c478bd9Sstevel@tonic-gate break; 3347c478bd9Sstevel@tonic-gate case YPERR_BUSY: 3357c478bd9Sstevel@tonic-gate res = NSS_TRYAGAIN; 3367c478bd9Sstevel@tonic-gate break; 337bf1f3d92Ssdussud case YPERR_KEY: 338bf1f3d92Ssdussud /* 339bf1f3d92Ssdussud * If no such key, return NSS_NOTFOUND 340bf1f3d92Ssdussud * as this looks more relevant; it will 341bf1f3d92Ssdussud * also help libnsl to try with another 342bf1f3d92Ssdussud * policy (see _getexecprof()). 343bf1f3d92Ssdussud */ 344bf1f3d92Ssdussud res = NSS_NOTFOUND; 345bf1f3d92Ssdussud break; 3467c478bd9Sstevel@tonic-gate default: 3477c478bd9Sstevel@tonic-gate res = NSS_UNAVAIL; 3487c478bd9Sstevel@tonic-gate break; 3497c478bd9Sstevel@tonic-gate } 3507c478bd9Sstevel@tonic-gate 3517c478bd9Sstevel@tonic-gate } 3527c478bd9Sstevel@tonic-gate 3537c478bd9Sstevel@tonic-gate return (res); 3547c478bd9Sstevel@tonic-gate } 3557c478bd9Sstevel@tonic-gate 3567c478bd9Sstevel@tonic-gate /* 3577c478bd9Sstevel@tonic-gate * If search for exact match for id failed, get_wild checks if we have 3587c478bd9Sstevel@tonic-gate * a wild-card entry for that id. 3597c478bd9Sstevel@tonic-gate */ 3607c478bd9Sstevel@tonic-gate static nss_status_t 3617c478bd9Sstevel@tonic-gate get_wild(nis_backend_ptr_t be, nss_XbyY_args_t *argp, int getby_flag) 3627c478bd9Sstevel@tonic-gate { 363458d6ca5Smichen const char *orig_id; 3647c478bd9Sstevel@tonic-gate char *old_id = NULL; 3657c478bd9Sstevel@tonic-gate char *wild_id = NULL; 3667c478bd9Sstevel@tonic-gate nss_status_t res = NSS_NOTFOUND; 3677c478bd9Sstevel@tonic-gate _priv_execattr *_priv_exec = (_priv_execattr *)(argp->key.attrp); 3687c478bd9Sstevel@tonic-gate 369458d6ca5Smichen orig_id = _priv_exec->id; 3707c478bd9Sstevel@tonic-gate old_id = strdup(_priv_exec->id); 3717c478bd9Sstevel@tonic-gate wild_id = old_id; 3727c478bd9Sstevel@tonic-gate while ((wild_id = _exec_wild_id(wild_id, _priv_exec->type)) != NULL) { 3737c478bd9Sstevel@tonic-gate _priv_exec->id = wild_id; 3747c478bd9Sstevel@tonic-gate res = _exec_nis_lookup(be, argp, getby_flag); 3757c478bd9Sstevel@tonic-gate if (res == NSS_SUCCESS) 3767c478bd9Sstevel@tonic-gate break; 3777c478bd9Sstevel@tonic-gate } 3787c478bd9Sstevel@tonic-gate _priv_exec->id = orig_id; 3797c478bd9Sstevel@tonic-gate if (old_id) 3807c478bd9Sstevel@tonic-gate free(old_id); 3817c478bd9Sstevel@tonic-gate 3827c478bd9Sstevel@tonic-gate return (res); 3837c478bd9Sstevel@tonic-gate } 3847c478bd9Sstevel@tonic-gate 3857c478bd9Sstevel@tonic-gate 3867c478bd9Sstevel@tonic-gate static nss_status_t 3877c478bd9Sstevel@tonic-gate getbynam(nis_backend_ptr_t be, void *a) 3887c478bd9Sstevel@tonic-gate { 3897c478bd9Sstevel@tonic-gate nss_status_t res; 3907c478bd9Sstevel@tonic-gate nss_XbyY_args_t *argp = (nss_XbyY_args_t *)a; 3917c478bd9Sstevel@tonic-gate 3927c478bd9Sstevel@tonic-gate res = _exec_nis_lookup(be, argp, NSS_DBOP_EXECATTR_BYNAME); 3937c478bd9Sstevel@tonic-gate 3947c478bd9Sstevel@tonic-gate _exec_cleanup(res, argp); 3957c478bd9Sstevel@tonic-gate 3967c478bd9Sstevel@tonic-gate return (res); 3977c478bd9Sstevel@tonic-gate } 3987c478bd9Sstevel@tonic-gate 3997c478bd9Sstevel@tonic-gate static nss_status_t 4007c478bd9Sstevel@tonic-gate getbyid(nis_backend_ptr_t be, void *a) 4017c478bd9Sstevel@tonic-gate { 4027c478bd9Sstevel@tonic-gate nss_status_t res; 4037c478bd9Sstevel@tonic-gate nss_XbyY_args_t *argp = (nss_XbyY_args_t *)a; 404cb5caa98Sdjl /*LINTED*/ 4057c478bd9Sstevel@tonic-gate _priv_execattr *_priv_exec = (_priv_execattr *)(argp->key.attrp); 4067c478bd9Sstevel@tonic-gate 4077c478bd9Sstevel@tonic-gate res = _exec_nis_lookup(be, argp, NSS_DBOP_EXECATTR_BYID); 4087c478bd9Sstevel@tonic-gate 4097c478bd9Sstevel@tonic-gate if (res != NSS_SUCCESS) 4107c478bd9Sstevel@tonic-gate res = get_wild(be, argp, NSS_DBOP_EXECATTR_BYID); 4117c478bd9Sstevel@tonic-gate 4127c478bd9Sstevel@tonic-gate _exec_cleanup(res, argp); 4137c478bd9Sstevel@tonic-gate 4147c478bd9Sstevel@tonic-gate return (res); 4157c478bd9Sstevel@tonic-gate } 4167c478bd9Sstevel@tonic-gate 4177c478bd9Sstevel@tonic-gate 4187c478bd9Sstevel@tonic-gate static nss_status_t 4197c478bd9Sstevel@tonic-gate getbynameid(nis_backend_ptr_t be, void *a) 4207c478bd9Sstevel@tonic-gate { 4217c478bd9Sstevel@tonic-gate nss_status_t res; 4227c478bd9Sstevel@tonic-gate nss_XbyY_args_t *argp = (nss_XbyY_args_t *)a; 423cb5caa98Sdjl /*LINTED*/ 4247c478bd9Sstevel@tonic-gate _priv_execattr *_priv_exec = (_priv_execattr *)(argp->key.attrp); 4257c478bd9Sstevel@tonic-gate 4267c478bd9Sstevel@tonic-gate res = _exec_nis_lookup(be, argp, NSS_DBOP_EXECATTR_BYNAMEID); 4277c478bd9Sstevel@tonic-gate 4287c478bd9Sstevel@tonic-gate if (res != NSS_SUCCESS) 4297c478bd9Sstevel@tonic-gate res = get_wild(be, argp, NSS_DBOP_EXECATTR_BYNAMEID); 4307c478bd9Sstevel@tonic-gate 4317c478bd9Sstevel@tonic-gate _exec_cleanup(res, argp); 4327c478bd9Sstevel@tonic-gate 4337c478bd9Sstevel@tonic-gate return (res); 4347c478bd9Sstevel@tonic-gate } 4357c478bd9Sstevel@tonic-gate 4367c478bd9Sstevel@tonic-gate 4377c478bd9Sstevel@tonic-gate static nis_backend_op_t execattr_ops[] = { 4387c478bd9Sstevel@tonic-gate _nss_nis_destr, 4397c478bd9Sstevel@tonic-gate _nss_nis_endent, 4407c478bd9Sstevel@tonic-gate _nss_nis_setent, 4417c478bd9Sstevel@tonic-gate _nss_nis_getent_netdb, 4427c478bd9Sstevel@tonic-gate getbynam, 4437c478bd9Sstevel@tonic-gate getbyid, 4447c478bd9Sstevel@tonic-gate getbynameid 4457c478bd9Sstevel@tonic-gate }; 4467c478bd9Sstevel@tonic-gate 447cb5caa98Sdjl /*ARGSUSED*/ 4487c478bd9Sstevel@tonic-gate nss_backend_t * 4497c478bd9Sstevel@tonic-gate _nss_nis_exec_attr_constr(const char *dummy1, 4507c478bd9Sstevel@tonic-gate const char *dummy2, 4517c478bd9Sstevel@tonic-gate const char *dummy3, 4527c478bd9Sstevel@tonic-gate const char *dummy4, 4537c478bd9Sstevel@tonic-gate const char *dummy5, 4547c478bd9Sstevel@tonic-gate const char *dummy6, 4557c478bd9Sstevel@tonic-gate const char *dummy7) 4567c478bd9Sstevel@tonic-gate { 4577c478bd9Sstevel@tonic-gate return (_nss_nis_constr(execattr_ops, 4587c478bd9Sstevel@tonic-gate sizeof (execattr_ops)/sizeof (execattr_ops[0]), 4597c478bd9Sstevel@tonic-gate NIS_MAP_EXECATTR)); 4607c478bd9Sstevel@tonic-gate } 461