1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * CDDL HEADER START 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*0Sstevel@tonic-gate * with the License. 8*0Sstevel@tonic-gate * 9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*0Sstevel@tonic-gate * See the License for the specific language governing permissions 12*0Sstevel@tonic-gate * and limitations under the License. 13*0Sstevel@tonic-gate * 14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*0Sstevel@tonic-gate * 20*0Sstevel@tonic-gate * CDDL HEADER END 21*0Sstevel@tonic-gate */ 22*0Sstevel@tonic-gate /* 23*0Sstevel@tonic-gate * Copyright 2003 Sun Microsystems, Inc. All rights reserved. 24*0Sstevel@tonic-gate * Use is subject to license terms. 25*0Sstevel@tonic-gate */ 26*0Sstevel@tonic-gate 27*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 28*0Sstevel@tonic-gate 29*0Sstevel@tonic-gate #include <secdb.h> 30*0Sstevel@tonic-gate #include <exec_attr.h> 31*0Sstevel@tonic-gate #include "ldap_common.h" 32*0Sstevel@tonic-gate 33*0Sstevel@tonic-gate 34*0Sstevel@tonic-gate /* exec_attr attributes filters */ 35*0Sstevel@tonic-gate #define ISWILD(x) (x == NULL) ? "*" : x 36*0Sstevel@tonic-gate #define _EXEC_NAME "cn" 37*0Sstevel@tonic-gate #define _EXEC_POLICY "SolarisKernelSecurityPolicy" 38*0Sstevel@tonic-gate #define _EXEC_TYPE "SolarisProfileType" 39*0Sstevel@tonic-gate #define _EXEC_RES1 "SolarisAttrRes1" 40*0Sstevel@tonic-gate #define _EXEC_RES2 "SolarisAttrRes2" 41*0Sstevel@tonic-gate #define _EXEC_ID "SolarisProfileId" 42*0Sstevel@tonic-gate #define _EXEC_ATTRS "SolarisAttrKeyValue" 43*0Sstevel@tonic-gate #define _EXEC_GETEXECNAME "(&(objectClass=SolarisExecAttr)(cn=%s)"\ 44*0Sstevel@tonic-gate "(SolarisKernelSecurityPolicy=%s)"\ 45*0Sstevel@tonic-gate "(SolarisProfileType=%s))" 46*0Sstevel@tonic-gate #define _EXEC_GETEXECNAME_SSD "(&(%%s)(cn=%s)"\ 47*0Sstevel@tonic-gate "(SolarisKernelSecurityPolicy=%s)"\ 48*0Sstevel@tonic-gate "(SolarisProfileType=%s))" 49*0Sstevel@tonic-gate #define _EXEC_GETEXECID "(&(objectClass=SolarisExecAttr)"\ 50*0Sstevel@tonic-gate "(SolarisProfileId=%s)"\ 51*0Sstevel@tonic-gate "(SolarisKernelSecurityPolicy=%s)"\ 52*0Sstevel@tonic-gate "(SolarisProfileType=%s))" 53*0Sstevel@tonic-gate #define _EXEC_GETEXECID_SSD "(&(%%s)"\ 54*0Sstevel@tonic-gate "(SolarisProfileId=%s)"\ 55*0Sstevel@tonic-gate "(SolarisKernelSecurityPolicy=%s)"\ 56*0Sstevel@tonic-gate "(SolarisProfileType=%s))" 57*0Sstevel@tonic-gate #define _EXEC_GETEXECNAMEID "(&(objectClass=SolarisExecAttr)(cn=%s)"\ 58*0Sstevel@tonic-gate "(SolarisProfileId=%s)"\ 59*0Sstevel@tonic-gate "(SolarisKernelSecurityPolicy=%s)"\ 60*0Sstevel@tonic-gate "(SolarisProfileType=%s))" 61*0Sstevel@tonic-gate #define _EXEC_GETEXECNAMEID_SSD "(&(%%s)(cn=%s)"\ 62*0Sstevel@tonic-gate "(SolarisProfileId=%s)"\ 63*0Sstevel@tonic-gate "(SolarisKernelSecurityPolicy=%s)"\ 64*0Sstevel@tonic-gate "(SolarisProfileType=%s))" 65*0Sstevel@tonic-gate 66*0Sstevel@tonic-gate 67*0Sstevel@tonic-gate /* from libnsl */ 68*0Sstevel@tonic-gate extern int _doexeclist(nss_XbyY_args_t *); 69*0Sstevel@tonic-gate extern char *_exec_wild_id(char *, const char *); 70*0Sstevel@tonic-gate extern void _exec_cleanup(nss_status_t, nss_XbyY_args_t *); 71*0Sstevel@tonic-gate 72*0Sstevel@tonic-gate 73*0Sstevel@tonic-gate static const char *exec_attrs[] = { 74*0Sstevel@tonic-gate _EXEC_NAME, 75*0Sstevel@tonic-gate _EXEC_POLICY, 76*0Sstevel@tonic-gate _EXEC_TYPE, 77*0Sstevel@tonic-gate _EXEC_RES1, 78*0Sstevel@tonic-gate _EXEC_RES2, 79*0Sstevel@tonic-gate _EXEC_ID, 80*0Sstevel@tonic-gate _EXEC_ATTRS, 81*0Sstevel@tonic-gate (char *)NULL 82*0Sstevel@tonic-gate }; 83*0Sstevel@tonic-gate 84*0Sstevel@tonic-gate 85*0Sstevel@tonic-gate #ifdef DEBUG 86*0Sstevel@tonic-gate static void 87*0Sstevel@tonic-gate _print_execstr(execstr_t *exec) 88*0Sstevel@tonic-gate { 89*0Sstevel@tonic-gate 90*0Sstevel@tonic-gate (void) fprintf(stdout, " exec-name: [%s]\n", exec->name); 91*0Sstevel@tonic-gate if (exec->policy != (char *)NULL) { 92*0Sstevel@tonic-gate (void) fprintf(stdout, " policy: [%s]\n", exec->policy); 93*0Sstevel@tonic-gate } 94*0Sstevel@tonic-gate if (exec->type != (char *)NULL) { 95*0Sstevel@tonic-gate (void) fprintf(stdout, " type: [%s]\n", exec->type); 96*0Sstevel@tonic-gate } 97*0Sstevel@tonic-gate if (exec->res1 != (char *)NULL) { 98*0Sstevel@tonic-gate (void) fprintf(stdout, " res1: [%s]\n", exec->res1); 99*0Sstevel@tonic-gate } 100*0Sstevel@tonic-gate if (exec->res2 != (char *)NULL) { 101*0Sstevel@tonic-gate (void) fprintf(stdout, " res2: [%s]\n", exec->res2); 102*0Sstevel@tonic-gate } 103*0Sstevel@tonic-gate if (exec->id != (char *)NULL) { 104*0Sstevel@tonic-gate (void) fprintf(stdout, " id: [%s]\n", exec->id); 105*0Sstevel@tonic-gate } 106*0Sstevel@tonic-gate if (exec->attr != (char *)NULL) { 107*0Sstevel@tonic-gate (void) fprintf(stdout, " attr: [%s]\n", exec->attr); 108*0Sstevel@tonic-gate } 109*0Sstevel@tonic-gate if (exec->next != (execstr_t *)NULL) { 110*0Sstevel@tonic-gate (void) fprintf(stdout, " next: [%s]\n", exec->next->name); 111*0Sstevel@tonic-gate (void) fprintf(stdout, "\n"); 112*0Sstevel@tonic-gate _print_execstr(exec->next); 113*0Sstevel@tonic-gate } 114*0Sstevel@tonic-gate } 115*0Sstevel@tonic-gate #endif /* DEBUG */ 116*0Sstevel@tonic-gate 117*0Sstevel@tonic-gate 118*0Sstevel@tonic-gate static int 119*0Sstevel@tonic-gate _exec_ldap_exec2ent(ns_ldap_entry_t *entry, nss_XbyY_args_t *argp) 120*0Sstevel@tonic-gate { 121*0Sstevel@tonic-gate 122*0Sstevel@tonic-gate int i; 123*0Sstevel@tonic-gate unsigned long len = 0L; 124*0Sstevel@tonic-gate int buflen = (int)0; 125*0Sstevel@tonic-gate char *nullstring = (char *)NULL; 126*0Sstevel@tonic-gate char *buffer = (char *)NULL; 127*0Sstevel@tonic-gate char *ceiling = (char *)NULL; 128*0Sstevel@tonic-gate execstr_t *exec = (execstr_t *)NULL; 129*0Sstevel@tonic-gate ns_ldap_attr_t *attrptr; 130*0Sstevel@tonic-gate 131*0Sstevel@tonic-gate buffer = argp->buf.buffer; 132*0Sstevel@tonic-gate buflen = (size_t)argp->buf.buflen; 133*0Sstevel@tonic-gate (void) memset(argp->buf.buffer, 0, buflen); 134*0Sstevel@tonic-gate exec = (execstr_t *)(argp->buf.result); 135*0Sstevel@tonic-gate ceiling = buffer + buflen; 136*0Sstevel@tonic-gate exec->name = (char *)NULL; 137*0Sstevel@tonic-gate exec->policy = (char *)NULL; 138*0Sstevel@tonic-gate exec->type = (char *)NULL; 139*0Sstevel@tonic-gate exec->res1 = (char *)NULL; 140*0Sstevel@tonic-gate exec->res2 = (char *)NULL; 141*0Sstevel@tonic-gate exec->id = (char *)NULL; 142*0Sstevel@tonic-gate exec->attr = (char *)NULL; 143*0Sstevel@tonic-gate 144*0Sstevel@tonic-gate for (i = 0; i < entry->attr_count; i++) { 145*0Sstevel@tonic-gate attrptr = entry->attr_pair[i]; 146*0Sstevel@tonic-gate if (attrptr == NULL) { 147*0Sstevel@tonic-gate return ((int)NSS_STR_PARSE_PARSE); 148*0Sstevel@tonic-gate } 149*0Sstevel@tonic-gate if (strcasecmp(attrptr->attrname, _EXEC_NAME) == 0) { 150*0Sstevel@tonic-gate if ((attrptr->attrvalue[0] == NULL) || 151*0Sstevel@tonic-gate (len = strlen(attrptr->attrvalue[0])) < 1) { 152*0Sstevel@tonic-gate return ((int)NSS_STR_PARSE_PARSE); 153*0Sstevel@tonic-gate } 154*0Sstevel@tonic-gate exec->name = buffer; 155*0Sstevel@tonic-gate buffer += len + 1; 156*0Sstevel@tonic-gate if (buffer >= ceiling) { 157*0Sstevel@tonic-gate return ((int)NSS_STR_PARSE_ERANGE); 158*0Sstevel@tonic-gate } 159*0Sstevel@tonic-gate (void) strcpy(exec->name, attrptr->attrvalue[0]); 160*0Sstevel@tonic-gate continue; 161*0Sstevel@tonic-gate } 162*0Sstevel@tonic-gate if (strcasecmp(attrptr->attrname, _EXEC_POLICY) == 0) { 163*0Sstevel@tonic-gate if ((attrptr->attrvalue[0] == NULL) || 164*0Sstevel@tonic-gate (len = strlen(attrptr->attrvalue[0])) < 1) { 165*0Sstevel@tonic-gate exec->policy = nullstring; 166*0Sstevel@tonic-gate } else { 167*0Sstevel@tonic-gate exec->policy = buffer; 168*0Sstevel@tonic-gate buffer += len + 1; 169*0Sstevel@tonic-gate if (buffer >= ceiling) { 170*0Sstevel@tonic-gate return ((int)NSS_STR_PARSE_ERANGE); 171*0Sstevel@tonic-gate } 172*0Sstevel@tonic-gate (void) strcpy(exec->policy, 173*0Sstevel@tonic-gate attrptr->attrvalue[0]); 174*0Sstevel@tonic-gate } 175*0Sstevel@tonic-gate continue; 176*0Sstevel@tonic-gate } 177*0Sstevel@tonic-gate if (strcasecmp(attrptr->attrname, _EXEC_TYPE) == 0) { 178*0Sstevel@tonic-gate if ((attrptr->attrvalue[0] == NULL) || 179*0Sstevel@tonic-gate (len = strlen(attrptr->attrvalue[0])) < 1) { 180*0Sstevel@tonic-gate exec->type = nullstring; 181*0Sstevel@tonic-gate } else { 182*0Sstevel@tonic-gate exec->type = buffer; 183*0Sstevel@tonic-gate buffer += len + 1; 184*0Sstevel@tonic-gate if (buffer >= ceiling) { 185*0Sstevel@tonic-gate return ((int)NSS_STR_PARSE_ERANGE); 186*0Sstevel@tonic-gate } 187*0Sstevel@tonic-gate (void) strcpy(exec->type, 188*0Sstevel@tonic-gate attrptr->attrvalue[0]); 189*0Sstevel@tonic-gate } 190*0Sstevel@tonic-gate continue; 191*0Sstevel@tonic-gate } 192*0Sstevel@tonic-gate if (strcasecmp(attrptr->attrname, _EXEC_RES1) == 0) { 193*0Sstevel@tonic-gate if ((attrptr->attrvalue[0] == NULL) || 194*0Sstevel@tonic-gate (len = strlen(attrptr->attrvalue[0])) < 1) { 195*0Sstevel@tonic-gate exec->res1 = nullstring; 196*0Sstevel@tonic-gate } else { 197*0Sstevel@tonic-gate exec->res1 = buffer; 198*0Sstevel@tonic-gate buffer += len + 1; 199*0Sstevel@tonic-gate if (buffer >= ceiling) { 200*0Sstevel@tonic-gate return ((int)NSS_STR_PARSE_ERANGE); 201*0Sstevel@tonic-gate } 202*0Sstevel@tonic-gate (void) strcpy(exec->res1, 203*0Sstevel@tonic-gate attrptr->attrvalue[0]); 204*0Sstevel@tonic-gate } 205*0Sstevel@tonic-gate continue; 206*0Sstevel@tonic-gate } 207*0Sstevel@tonic-gate if (strcasecmp(attrptr->attrname, _EXEC_RES2) == 0) { 208*0Sstevel@tonic-gate if ((attrptr->attrvalue[0] == NULL) || 209*0Sstevel@tonic-gate (len = strlen(attrptr->attrvalue[0])) < 1) { 210*0Sstevel@tonic-gate exec->res2 = nullstring; 211*0Sstevel@tonic-gate } else { 212*0Sstevel@tonic-gate exec->res2 = buffer; 213*0Sstevel@tonic-gate buffer += len + 1; 214*0Sstevel@tonic-gate if (buffer >= ceiling) { 215*0Sstevel@tonic-gate return ((int)NSS_STR_PARSE_ERANGE); 216*0Sstevel@tonic-gate } 217*0Sstevel@tonic-gate (void) strcpy(exec->res2, 218*0Sstevel@tonic-gate attrptr->attrvalue[0]); 219*0Sstevel@tonic-gate } 220*0Sstevel@tonic-gate continue; 221*0Sstevel@tonic-gate } 222*0Sstevel@tonic-gate if (strcasecmp(attrptr->attrname, _EXEC_ID) == 0) { 223*0Sstevel@tonic-gate if ((attrptr->attrvalue[0] == NULL) || 224*0Sstevel@tonic-gate (len = strlen(attrptr->attrvalue[0])) < 1) { 225*0Sstevel@tonic-gate exec->id = nullstring; 226*0Sstevel@tonic-gate } else { 227*0Sstevel@tonic-gate exec->id = buffer; 228*0Sstevel@tonic-gate buffer += len + 1; 229*0Sstevel@tonic-gate if (buffer >= ceiling) { 230*0Sstevel@tonic-gate return ((int)NSS_STR_PARSE_ERANGE); 231*0Sstevel@tonic-gate } 232*0Sstevel@tonic-gate (void) strcpy(exec->id, attrptr->attrvalue[0]); 233*0Sstevel@tonic-gate } 234*0Sstevel@tonic-gate continue; 235*0Sstevel@tonic-gate } 236*0Sstevel@tonic-gate if (strcasecmp(attrptr->attrname, _EXEC_ATTRS) == 0) { 237*0Sstevel@tonic-gate if ((attrptr->attrvalue[0] == NULL) || 238*0Sstevel@tonic-gate (len = strlen(attrptr->attrvalue[0])) < 1) { 239*0Sstevel@tonic-gate exec->attr = nullstring; 240*0Sstevel@tonic-gate } else { 241*0Sstevel@tonic-gate exec->attr = buffer; 242*0Sstevel@tonic-gate buffer += len + 1; 243*0Sstevel@tonic-gate if (buffer >= ceiling) { 244*0Sstevel@tonic-gate return ((int)NSS_STR_PARSE_ERANGE); 245*0Sstevel@tonic-gate } 246*0Sstevel@tonic-gate (void) strcpy(exec->attr, 247*0Sstevel@tonic-gate attrptr->attrvalue[0]); 248*0Sstevel@tonic-gate } 249*0Sstevel@tonic-gate continue; 250*0Sstevel@tonic-gate } 251*0Sstevel@tonic-gate } 252*0Sstevel@tonic-gate 253*0Sstevel@tonic-gate exec->next = (execstr_t *)NULL; 254*0Sstevel@tonic-gate 255*0Sstevel@tonic-gate #ifdef DEBUG 256*0Sstevel@tonic-gate (void) fprintf(stdout, "\n[getexecattr.c: _exec_ldap_exec2ent]\n"); 257*0Sstevel@tonic-gate _print_execstr(exec); 258*0Sstevel@tonic-gate #endif /* DEBUG */ 259*0Sstevel@tonic-gate 260*0Sstevel@tonic-gate return ((int)NSS_STR_PARSE_SUCCESS); 261*0Sstevel@tonic-gate } 262*0Sstevel@tonic-gate 263*0Sstevel@tonic-gate 264*0Sstevel@tonic-gate /* 265*0Sstevel@tonic-gate * place the results from ldap object structure into argp->buf.result 266*0Sstevel@tonic-gate * returns NSS_STR_PARSE_{SUCCESS, ERANGE, PARSE} 267*0Sstevel@tonic-gate */ 268*0Sstevel@tonic-gate static int 269*0Sstevel@tonic-gate _nss_ldap_exec2ent(ldap_backend_ptr be, nss_XbyY_args_t *argp) 270*0Sstevel@tonic-gate { 271*0Sstevel@tonic-gate int status = (int)NSS_STR_PARSE_SUCCESS; 272*0Sstevel@tonic-gate ns_ldap_entry_t *entry; 273*0Sstevel@tonic-gate ns_ldap_result_t *result = be->result; 274*0Sstevel@tonic-gate 275*0Sstevel@tonic-gate if (!argp->buf.result) { 276*0Sstevel@tonic-gate status = (int)NSS_STR_PARSE_ERANGE; 277*0Sstevel@tonic-gate goto result_exec2ent; 278*0Sstevel@tonic-gate } 279*0Sstevel@tonic-gate 280*0Sstevel@tonic-gate for (entry = result->entry; entry != NULL; entry = entry->next) { 281*0Sstevel@tonic-gate status = _exec_ldap_exec2ent(entry, argp); 282*0Sstevel@tonic-gate if (status != NSS_STR_PARSE_SUCCESS) { 283*0Sstevel@tonic-gate goto result_exec2ent; 284*0Sstevel@tonic-gate } 285*0Sstevel@tonic-gate } 286*0Sstevel@tonic-gate 287*0Sstevel@tonic-gate result_exec2ent: 288*0Sstevel@tonic-gate (void) __ns_ldap_freeResult(&be->result); 289*0Sstevel@tonic-gate return (status); 290*0Sstevel@tonic-gate } 291*0Sstevel@tonic-gate 292*0Sstevel@tonic-gate 293*0Sstevel@tonic-gate static nss_status_t 294*0Sstevel@tonic-gate _exec_process_val(ldap_backend_ptr be, nss_XbyY_args_t *argp) 295*0Sstevel@tonic-gate { 296*0Sstevel@tonic-gate int status; 297*0Sstevel@tonic-gate nss_status_t nss_stat = NSS_UNAVAIL; 298*0Sstevel@tonic-gate ns_ldap_attr_t *attrptr; 299*0Sstevel@tonic-gate ns_ldap_entry_t *entry; 300*0Sstevel@tonic-gate ns_ldap_result_t *result = be->result; 301*0Sstevel@tonic-gate _priv_execattr *_priv_exec = (_priv_execattr *)(argp->key.attrp); 302*0Sstevel@tonic-gate 303*0Sstevel@tonic-gate #ifdef DEBUG 304*0Sstevel@tonic-gate (void) fprintf(stdout, "\n[getexecattr.c: _exec_process_val]\n"); 305*0Sstevel@tonic-gate #endif /* DEBUG */ 306*0Sstevel@tonic-gate 307*0Sstevel@tonic-gate argp->returnval = NULL; 308*0Sstevel@tonic-gate attrptr = getattr(result, 0); 309*0Sstevel@tonic-gate if (attrptr == NULL) { 310*0Sstevel@tonic-gate (void) __ns_ldap_freeResult(&be->result); 311*0Sstevel@tonic-gate return (nss_stat); 312*0Sstevel@tonic-gate } 313*0Sstevel@tonic-gate for (entry = result->entry; entry != NULL; entry = entry->next) { 314*0Sstevel@tonic-gate status = _exec_ldap_exec2ent(entry, argp); 315*0Sstevel@tonic-gate switch (status) { 316*0Sstevel@tonic-gate case NSS_STR_PARSE_SUCCESS: 317*0Sstevel@tonic-gate argp->returnval = argp->buf.result; 318*0Sstevel@tonic-gate nss_stat = NSS_SUCCESS; 319*0Sstevel@tonic-gate if (_priv_exec->search_flag == GET_ALL) { 320*0Sstevel@tonic-gate if (_doexeclist(argp) == 0) { 321*0Sstevel@tonic-gate nss_stat = NSS_UNAVAIL; 322*0Sstevel@tonic-gate } 323*0Sstevel@tonic-gate } 324*0Sstevel@tonic-gate break; 325*0Sstevel@tonic-gate case NSS_STR_PARSE_ERANGE: 326*0Sstevel@tonic-gate argp->erange = 1; 327*0Sstevel@tonic-gate nss_stat = NSS_NOTFOUND; 328*0Sstevel@tonic-gate break; 329*0Sstevel@tonic-gate case NSS_STR_PARSE_PARSE: 330*0Sstevel@tonic-gate nss_stat = NSS_NOTFOUND; 331*0Sstevel@tonic-gate break; 332*0Sstevel@tonic-gate default: 333*0Sstevel@tonic-gate nss_stat = NSS_UNAVAIL; 334*0Sstevel@tonic-gate break; 335*0Sstevel@tonic-gate } 336*0Sstevel@tonic-gate 337*0Sstevel@tonic-gate if ((_priv_exec->search_flag == GET_ONE) || 338*0Sstevel@tonic-gate (nss_stat != NSS_SUCCESS)) { 339*0Sstevel@tonic-gate break; 340*0Sstevel@tonic-gate } 341*0Sstevel@tonic-gate } 342*0Sstevel@tonic-gate 343*0Sstevel@tonic-gate return (nss_stat); 344*0Sstevel@tonic-gate } 345*0Sstevel@tonic-gate 346*0Sstevel@tonic-gate 347*0Sstevel@tonic-gate /* 348*0Sstevel@tonic-gate * Check if we have either an exact match or a wild-card entry for that id. 349*0Sstevel@tonic-gate */ 350*0Sstevel@tonic-gate static nss_status_t 351*0Sstevel@tonic-gate get_wild(ldap_backend_ptr be, nss_XbyY_args_t *argp, int getby_flag) 352*0Sstevel@tonic-gate { 353*0Sstevel@tonic-gate char *dup_id = NULL; 354*0Sstevel@tonic-gate char *wild_id; 355*0Sstevel@tonic-gate char searchfilter[SEARCHFILTERLEN]; 356*0Sstevel@tonic-gate char userdata[SEARCHFILTERLEN]; 357*0Sstevel@tonic-gate char name[SEARCHFILTERLEN]; 358*0Sstevel@tonic-gate char id[SEARCHFILTERLEN]; 359*0Sstevel@tonic-gate int ret; 360*0Sstevel@tonic-gate nss_status_t nss_stat = NSS_NOTFOUND; 361*0Sstevel@tonic-gate _priv_execattr *_priv_exec = (_priv_execattr *)(argp->key.attrp); 362*0Sstevel@tonic-gate const char *policy = _priv_exec->policy; 363*0Sstevel@tonic-gate const char *type = _priv_exec->type; 364*0Sstevel@tonic-gate 365*0Sstevel@tonic-gate if (strpbrk(policy, "*()\\") != NULL || 366*0Sstevel@tonic-gate type != NULL && strpbrk(type, "*()\\") != NULL) 367*0Sstevel@tonic-gate return ((nss_status_t)NSS_NOTFOUND); 368*0Sstevel@tonic-gate 369*0Sstevel@tonic-gate if (_priv_exec->id != NULL) 370*0Sstevel@tonic-gate dup_id = strdup(_priv_exec->id); 371*0Sstevel@tonic-gate 372*0Sstevel@tonic-gate switch (getby_flag) { 373*0Sstevel@tonic-gate case NSS_DBOP_EXECATTR_BYNAMEID: 374*0Sstevel@tonic-gate if (_ldap_filter_name(name, _priv_exec->name, 375*0Sstevel@tonic-gate sizeof (name)) != 0) 376*0Sstevel@tonic-gate goto go_out; 377*0Sstevel@tonic-gate break; 378*0Sstevel@tonic-gate } 379*0Sstevel@tonic-gate 380*0Sstevel@tonic-gate wild_id = dup_id; 381*0Sstevel@tonic-gate do { 382*0Sstevel@tonic-gate if (wild_id != NULL) { 383*0Sstevel@tonic-gate if (_ldap_filter_name(id, wild_id, sizeof (id)) != 0) 384*0Sstevel@tonic-gate goto go_out; 385*0Sstevel@tonic-gate } else 386*0Sstevel@tonic-gate (void) strlcpy(id, "*", sizeof (id)); 387*0Sstevel@tonic-gate 388*0Sstevel@tonic-gate switch (getby_flag) { 389*0Sstevel@tonic-gate case NSS_DBOP_EXECATTR_BYID: 390*0Sstevel@tonic-gate ret = snprintf(searchfilter, sizeof (searchfilter), 391*0Sstevel@tonic-gate _EXEC_GETEXECID, id, policy, ISWILD(type)); 392*0Sstevel@tonic-gate if (ret >= sizeof (searchfilter) || ret < 0) 393*0Sstevel@tonic-gate goto go_out; 394*0Sstevel@tonic-gate ret = snprintf(userdata, sizeof (userdata), 395*0Sstevel@tonic-gate _EXEC_GETEXECID_SSD, id, policy, ISWILD(type)); 396*0Sstevel@tonic-gate if (ret >= sizeof (userdata) || ret < 0) 397*0Sstevel@tonic-gate goto go_out; 398*0Sstevel@tonic-gate break; 399*0Sstevel@tonic-gate 400*0Sstevel@tonic-gate case NSS_DBOP_EXECATTR_BYNAMEID: 401*0Sstevel@tonic-gate ret = snprintf(searchfilter, sizeof (searchfilter), 402*0Sstevel@tonic-gate _EXEC_GETEXECNAMEID, name, id, 403*0Sstevel@tonic-gate policy, ISWILD(type)); 404*0Sstevel@tonic-gate if (ret >= sizeof (searchfilter) || ret < 0) 405*0Sstevel@tonic-gate goto go_out; 406*0Sstevel@tonic-gate ret = snprintf(userdata, sizeof (userdata), 407*0Sstevel@tonic-gate _EXEC_GETEXECNAMEID_SSD, name, id, 408*0Sstevel@tonic-gate policy, ISWILD(type)); 409*0Sstevel@tonic-gate if (ret >= sizeof (userdata) || ret < 0) 410*0Sstevel@tonic-gate goto go_out; 411*0Sstevel@tonic-gate break; 412*0Sstevel@tonic-gate 413*0Sstevel@tonic-gate default: 414*0Sstevel@tonic-gate goto go_out; 415*0Sstevel@tonic-gate } 416*0Sstevel@tonic-gate nss_stat = _nss_ldap_nocb_lookup(be, argp, _EXECATTR, 417*0Sstevel@tonic-gate searchfilter, NULL, _merge_SSD_filter, userdata); 418*0Sstevel@tonic-gate if (nss_stat == NSS_SUCCESS) 419*0Sstevel@tonic-gate break; 420*0Sstevel@tonic-gate } while ((wild_id = _exec_wild_id(wild_id, type)) != NULL); 421*0Sstevel@tonic-gate 422*0Sstevel@tonic-gate go_out: 423*0Sstevel@tonic-gate free(dup_id); 424*0Sstevel@tonic-gate 425*0Sstevel@tonic-gate return (nss_stat); 426*0Sstevel@tonic-gate } 427*0Sstevel@tonic-gate 428*0Sstevel@tonic-gate static nss_status_t 429*0Sstevel@tonic-gate getbynam(ldap_backend_ptr be, void *a) 430*0Sstevel@tonic-gate { 431*0Sstevel@tonic-gate char searchfilter[SEARCHFILTERLEN]; 432*0Sstevel@tonic-gate char userdata[SEARCHFILTERLEN]; 433*0Sstevel@tonic-gate char name[SEARCHFILTERLEN]; 434*0Sstevel@tonic-gate int ret; 435*0Sstevel@tonic-gate nss_status_t nss_stat; 436*0Sstevel@tonic-gate nss_XbyY_args_t *argp = (nss_XbyY_args_t *)a; 437*0Sstevel@tonic-gate _priv_execattr *_priv_exec = (_priv_execattr *)(argp->key.attrp); 438*0Sstevel@tonic-gate const char *policy = _priv_exec->policy; 439*0Sstevel@tonic-gate const char *type = _priv_exec->type; 440*0Sstevel@tonic-gate 441*0Sstevel@tonic-gate #ifdef DEBUG 442*0Sstevel@tonic-gate (void) fprintf(stdout, "\n[getexecattr.c: getbyname]\n"); 443*0Sstevel@tonic-gate #endif /* DEBUG */ 444*0Sstevel@tonic-gate 445*0Sstevel@tonic-gate if (strpbrk(policy, "*()\\") != NULL || 446*0Sstevel@tonic-gate type != NULL && strpbrk(type, "*()\\") != NULL || 447*0Sstevel@tonic-gate _ldap_filter_name(name, _priv_exec->name, sizeof (name)) != 0) 448*0Sstevel@tonic-gate return ((nss_status_t)NSS_NOTFOUND); 449*0Sstevel@tonic-gate ret = snprintf(searchfilter, sizeof (searchfilter), 450*0Sstevel@tonic-gate _EXEC_GETEXECNAME, name, policy, ISWILD(type)); 451*0Sstevel@tonic-gate if (ret >= sizeof (searchfilter) || ret < 0) 452*0Sstevel@tonic-gate return ((nss_status_t)NSS_NOTFOUND); 453*0Sstevel@tonic-gate ret = snprintf(userdata, sizeof (userdata), 454*0Sstevel@tonic-gate _EXEC_GETEXECNAME_SSD, name, policy, ISWILD(type)); 455*0Sstevel@tonic-gate if (ret >= sizeof (userdata) || ret < 0) 456*0Sstevel@tonic-gate return ((nss_status_t)NSS_NOTFOUND); 457*0Sstevel@tonic-gate 458*0Sstevel@tonic-gate nss_stat = _nss_ldap_nocb_lookup(be, argp, _EXECATTR, 459*0Sstevel@tonic-gate searchfilter, NULL, _merge_SSD_filter, userdata); 460*0Sstevel@tonic-gate 461*0Sstevel@tonic-gate if (nss_stat == NSS_SUCCESS) 462*0Sstevel@tonic-gate nss_stat = _exec_process_val(be, argp); 463*0Sstevel@tonic-gate 464*0Sstevel@tonic-gate _exec_cleanup(nss_stat, argp); 465*0Sstevel@tonic-gate 466*0Sstevel@tonic-gate return (nss_stat); 467*0Sstevel@tonic-gate } 468*0Sstevel@tonic-gate 469*0Sstevel@tonic-gate 470*0Sstevel@tonic-gate static nss_status_t 471*0Sstevel@tonic-gate getbyid(ldap_backend_ptr be, void *a) 472*0Sstevel@tonic-gate { 473*0Sstevel@tonic-gate nss_status_t nss_stat; 474*0Sstevel@tonic-gate nss_XbyY_args_t *argp = (nss_XbyY_args_t *)a; 475*0Sstevel@tonic-gate 476*0Sstevel@tonic-gate #ifdef DEBUG 477*0Sstevel@tonic-gate (void) fprintf(stdout, "\n[getexecattr.c: getbyid]\n"); 478*0Sstevel@tonic-gate #endif /* DEBUG */ 479*0Sstevel@tonic-gate 480*0Sstevel@tonic-gate nss_stat = get_wild(be, argp, NSS_DBOP_EXECATTR_BYID); 481*0Sstevel@tonic-gate 482*0Sstevel@tonic-gate if (nss_stat == NSS_SUCCESS) 483*0Sstevel@tonic-gate nss_stat = _exec_process_val(be, argp); 484*0Sstevel@tonic-gate 485*0Sstevel@tonic-gate _exec_cleanup(nss_stat, argp); 486*0Sstevel@tonic-gate 487*0Sstevel@tonic-gate return (nss_stat); 488*0Sstevel@tonic-gate } 489*0Sstevel@tonic-gate 490*0Sstevel@tonic-gate 491*0Sstevel@tonic-gate static nss_status_t 492*0Sstevel@tonic-gate getbynameid(ldap_backend_ptr be, void *a) 493*0Sstevel@tonic-gate { 494*0Sstevel@tonic-gate nss_status_t nss_stat; 495*0Sstevel@tonic-gate nss_XbyY_args_t *argp = (nss_XbyY_args_t *)a; 496*0Sstevel@tonic-gate 497*0Sstevel@tonic-gate #ifdef DEBUG 498*0Sstevel@tonic-gate (void) fprintf(stdout, "\n[getexecattr.c: getbynameid]\n"); 499*0Sstevel@tonic-gate #endif /* DEBUG */ 500*0Sstevel@tonic-gate 501*0Sstevel@tonic-gate nss_stat = get_wild(be, argp, NSS_DBOP_EXECATTR_BYNAMEID); 502*0Sstevel@tonic-gate 503*0Sstevel@tonic-gate if (nss_stat == NSS_SUCCESS) 504*0Sstevel@tonic-gate nss_stat = _exec_process_val(be, argp); 505*0Sstevel@tonic-gate 506*0Sstevel@tonic-gate _exec_cleanup(nss_stat, argp); 507*0Sstevel@tonic-gate 508*0Sstevel@tonic-gate return (nss_stat); 509*0Sstevel@tonic-gate } 510*0Sstevel@tonic-gate 511*0Sstevel@tonic-gate 512*0Sstevel@tonic-gate static ldap_backend_op_t execattr_ops[] = { 513*0Sstevel@tonic-gate _nss_ldap_destr, 514*0Sstevel@tonic-gate _nss_ldap_endent, 515*0Sstevel@tonic-gate _nss_ldap_setent, 516*0Sstevel@tonic-gate _nss_ldap_getent, 517*0Sstevel@tonic-gate getbynam, 518*0Sstevel@tonic-gate getbyid, 519*0Sstevel@tonic-gate getbynameid 520*0Sstevel@tonic-gate }; 521*0Sstevel@tonic-gate 522*0Sstevel@tonic-gate 523*0Sstevel@tonic-gate /*ARGSUSED0*/ 524*0Sstevel@tonic-gate nss_backend_t * 525*0Sstevel@tonic-gate _nss_ldap_exec_attr_constr(const char *dummy1, 526*0Sstevel@tonic-gate const char *dummy2, 527*0Sstevel@tonic-gate const char *dummy3, 528*0Sstevel@tonic-gate const char *dummy4, 529*0Sstevel@tonic-gate const char *dummy5, 530*0Sstevel@tonic-gate const char *dummy6, 531*0Sstevel@tonic-gate const char *dummy7) 532*0Sstevel@tonic-gate { 533*0Sstevel@tonic-gate #ifdef DEBUG 534*0Sstevel@tonic-gate (void) fprintf(stdout, 535*0Sstevel@tonic-gate "\n[getexecattr.c: _nss_ldap_exec_attr_constr]\n"); 536*0Sstevel@tonic-gate #endif 537*0Sstevel@tonic-gate return ((nss_backend_t *)_nss_ldap_constr(execattr_ops, 538*0Sstevel@tonic-gate sizeof (execattr_ops)/sizeof (execattr_ops[0]), _EXECATTR, 539*0Sstevel@tonic-gate exec_attrs, _nss_ldap_exec2ent)); 540*0Sstevel@tonic-gate } 541