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 <secdb.h> 277c478bd9Sstevel@tonic-gate #include <exec_attr.h> 287c478bd9Sstevel@tonic-gate #include "ldap_common.h" 297c478bd9Sstevel@tonic-gate 307c478bd9Sstevel@tonic-gate 317c478bd9Sstevel@tonic-gate /* exec_attr attributes filters */ 327c478bd9Sstevel@tonic-gate #define ISWILD(x) (x == NULL) ? "*" : x 337c478bd9Sstevel@tonic-gate #define _EXEC_NAME "cn" 347c478bd9Sstevel@tonic-gate #define _EXEC_POLICY "SolarisKernelSecurityPolicy" 357c478bd9Sstevel@tonic-gate #define _EXEC_TYPE "SolarisProfileType" 367c478bd9Sstevel@tonic-gate #define _EXEC_RES1 "SolarisAttrRes1" 377c478bd9Sstevel@tonic-gate #define _EXEC_RES2 "SolarisAttrRes2" 387c478bd9Sstevel@tonic-gate #define _EXEC_ID "SolarisProfileId" 397c478bd9Sstevel@tonic-gate #define _EXEC_ATTRS "SolarisAttrKeyValue" 407c478bd9Sstevel@tonic-gate #define _EXEC_GETEXECNAME "(&(objectClass=SolarisExecAttr)(cn=%s)"\ 417c478bd9Sstevel@tonic-gate "(SolarisKernelSecurityPolicy=%s)"\ 427c478bd9Sstevel@tonic-gate "(SolarisProfileType=%s))" 437c478bd9Sstevel@tonic-gate #define _EXEC_GETEXECNAME_SSD "(&(%%s)(cn=%s)"\ 447c478bd9Sstevel@tonic-gate "(SolarisKernelSecurityPolicy=%s)"\ 457c478bd9Sstevel@tonic-gate "(SolarisProfileType=%s))" 467c478bd9Sstevel@tonic-gate #define _EXEC_GETEXECID "(&(objectClass=SolarisExecAttr)"\ 477c478bd9Sstevel@tonic-gate "(SolarisProfileId=%s)"\ 487c478bd9Sstevel@tonic-gate "(SolarisKernelSecurityPolicy=%s)"\ 497c478bd9Sstevel@tonic-gate "(SolarisProfileType=%s))" 507c478bd9Sstevel@tonic-gate #define _EXEC_GETEXECID_SSD "(&(%%s)"\ 517c478bd9Sstevel@tonic-gate "(SolarisProfileId=%s)"\ 527c478bd9Sstevel@tonic-gate "(SolarisKernelSecurityPolicy=%s)"\ 537c478bd9Sstevel@tonic-gate "(SolarisProfileType=%s))" 547c478bd9Sstevel@tonic-gate #define _EXEC_GETEXECNAMEID "(&(objectClass=SolarisExecAttr)(cn=%s)"\ 557c478bd9Sstevel@tonic-gate "(SolarisProfileId=%s)"\ 567c478bd9Sstevel@tonic-gate "(SolarisKernelSecurityPolicy=%s)"\ 577c478bd9Sstevel@tonic-gate "(SolarisProfileType=%s))" 587c478bd9Sstevel@tonic-gate #define _EXEC_GETEXECNAMEID_SSD "(&(%%s)(cn=%s)"\ 597c478bd9Sstevel@tonic-gate "(SolarisProfileId=%s)"\ 607c478bd9Sstevel@tonic-gate "(SolarisKernelSecurityPolicy=%s)"\ 617c478bd9Sstevel@tonic-gate "(SolarisProfileType=%s))" 627c478bd9Sstevel@tonic-gate 637c478bd9Sstevel@tonic-gate 647c478bd9Sstevel@tonic-gate /* from libnsl */ 657c478bd9Sstevel@tonic-gate extern int _doexeclist(nss_XbyY_args_t *); 667c478bd9Sstevel@tonic-gate extern char *_exec_wild_id(char *, const char *); 677c478bd9Sstevel@tonic-gate extern void _exec_cleanup(nss_status_t, nss_XbyY_args_t *); 687c478bd9Sstevel@tonic-gate 697c478bd9Sstevel@tonic-gate 707c478bd9Sstevel@tonic-gate static const char *exec_attrs[] = { 717c478bd9Sstevel@tonic-gate _EXEC_NAME, 727c478bd9Sstevel@tonic-gate _EXEC_POLICY, 737c478bd9Sstevel@tonic-gate _EXEC_TYPE, 747c478bd9Sstevel@tonic-gate _EXEC_RES1, 757c478bd9Sstevel@tonic-gate _EXEC_RES2, 767c478bd9Sstevel@tonic-gate _EXEC_ID, 777c478bd9Sstevel@tonic-gate _EXEC_ATTRS, 787c478bd9Sstevel@tonic-gate (char *)NULL 797c478bd9Sstevel@tonic-gate }; 807c478bd9Sstevel@tonic-gate 817c478bd9Sstevel@tonic-gate 827c478bd9Sstevel@tonic-gate #ifdef DEBUG 837c478bd9Sstevel@tonic-gate static void 847c478bd9Sstevel@tonic-gate _print_execstr(execstr_t *exec) 857c478bd9Sstevel@tonic-gate { 867c478bd9Sstevel@tonic-gate 877c478bd9Sstevel@tonic-gate (void) fprintf(stdout, " exec-name: [%s]\n", exec->name); 887c478bd9Sstevel@tonic-gate if (exec->policy != (char *)NULL) { 897c478bd9Sstevel@tonic-gate (void) fprintf(stdout, " policy: [%s]\n", exec->policy); 907c478bd9Sstevel@tonic-gate } 917c478bd9Sstevel@tonic-gate if (exec->type != (char *)NULL) { 927c478bd9Sstevel@tonic-gate (void) fprintf(stdout, " type: [%s]\n", exec->type); 937c478bd9Sstevel@tonic-gate } 947c478bd9Sstevel@tonic-gate if (exec->res1 != (char *)NULL) { 957c478bd9Sstevel@tonic-gate (void) fprintf(stdout, " res1: [%s]\n", exec->res1); 967c478bd9Sstevel@tonic-gate } 977c478bd9Sstevel@tonic-gate if (exec->res2 != (char *)NULL) { 987c478bd9Sstevel@tonic-gate (void) fprintf(stdout, " res2: [%s]\n", exec->res2); 997c478bd9Sstevel@tonic-gate } 1007c478bd9Sstevel@tonic-gate if (exec->id != (char *)NULL) { 1017c478bd9Sstevel@tonic-gate (void) fprintf(stdout, " id: [%s]\n", exec->id); 1027c478bd9Sstevel@tonic-gate } 1037c478bd9Sstevel@tonic-gate if (exec->attr != (char *)NULL) { 1047c478bd9Sstevel@tonic-gate (void) fprintf(stdout, " attr: [%s]\n", exec->attr); 1057c478bd9Sstevel@tonic-gate } 1067c478bd9Sstevel@tonic-gate if (exec->next != (execstr_t *)NULL) { 1077c478bd9Sstevel@tonic-gate (void) fprintf(stdout, " next: [%s]\n", exec->next->name); 1087c478bd9Sstevel@tonic-gate (void) fprintf(stdout, "\n"); 1097c478bd9Sstevel@tonic-gate _print_execstr(exec->next); 1107c478bd9Sstevel@tonic-gate } 1117c478bd9Sstevel@tonic-gate } 1127c478bd9Sstevel@tonic-gate #endif /* DEBUG */ 1137c478bd9Sstevel@tonic-gate 1147c478bd9Sstevel@tonic-gate 1157c478bd9Sstevel@tonic-gate static int 1167c478bd9Sstevel@tonic-gate _exec_ldap_exec2ent(ns_ldap_entry_t *entry, nss_XbyY_args_t *argp) 1177c478bd9Sstevel@tonic-gate { 1187c478bd9Sstevel@tonic-gate 1197c478bd9Sstevel@tonic-gate int i; 1207c478bd9Sstevel@tonic-gate unsigned long len = 0L; 1217c478bd9Sstevel@tonic-gate int buflen = (int)0; 1227c478bd9Sstevel@tonic-gate char *nullstring = (char *)NULL; 1237c478bd9Sstevel@tonic-gate char *buffer = (char *)NULL; 1247c478bd9Sstevel@tonic-gate char *ceiling = (char *)NULL; 1257c478bd9Sstevel@tonic-gate execstr_t *exec = (execstr_t *)NULL; 1267c478bd9Sstevel@tonic-gate ns_ldap_attr_t *attrptr; 1277c478bd9Sstevel@tonic-gate 1287c478bd9Sstevel@tonic-gate buffer = argp->buf.buffer; 1297c478bd9Sstevel@tonic-gate buflen = (size_t)argp->buf.buflen; 1307c478bd9Sstevel@tonic-gate (void) memset(argp->buf.buffer, 0, buflen); 1317c478bd9Sstevel@tonic-gate exec = (execstr_t *)(argp->buf.result); 1327c478bd9Sstevel@tonic-gate ceiling = buffer + buflen; 1337c478bd9Sstevel@tonic-gate exec->name = (char *)NULL; 1347c478bd9Sstevel@tonic-gate exec->policy = (char *)NULL; 1357c478bd9Sstevel@tonic-gate exec->type = (char *)NULL; 1367c478bd9Sstevel@tonic-gate exec->res1 = (char *)NULL; 1377c478bd9Sstevel@tonic-gate exec->res2 = (char *)NULL; 1387c478bd9Sstevel@tonic-gate exec->id = (char *)NULL; 1397c478bd9Sstevel@tonic-gate exec->attr = (char *)NULL; 1407c478bd9Sstevel@tonic-gate 1417c478bd9Sstevel@tonic-gate for (i = 0; i < entry->attr_count; i++) { 1427c478bd9Sstevel@tonic-gate attrptr = entry->attr_pair[i]; 1437c478bd9Sstevel@tonic-gate if (attrptr == NULL) { 1447c478bd9Sstevel@tonic-gate return ((int)NSS_STR_PARSE_PARSE); 1457c478bd9Sstevel@tonic-gate } 1467c478bd9Sstevel@tonic-gate if (strcasecmp(attrptr->attrname, _EXEC_NAME) == 0) { 1477c478bd9Sstevel@tonic-gate if ((attrptr->attrvalue[0] == NULL) || 1487c478bd9Sstevel@tonic-gate (len = strlen(attrptr->attrvalue[0])) < 1) { 1497c478bd9Sstevel@tonic-gate return ((int)NSS_STR_PARSE_PARSE); 1507c478bd9Sstevel@tonic-gate } 1517c478bd9Sstevel@tonic-gate exec->name = buffer; 1527c478bd9Sstevel@tonic-gate buffer += len + 1; 1537c478bd9Sstevel@tonic-gate if (buffer >= ceiling) { 1547c478bd9Sstevel@tonic-gate return ((int)NSS_STR_PARSE_ERANGE); 1557c478bd9Sstevel@tonic-gate } 1567c478bd9Sstevel@tonic-gate (void) strcpy(exec->name, attrptr->attrvalue[0]); 1577c478bd9Sstevel@tonic-gate continue; 1587c478bd9Sstevel@tonic-gate } 1597c478bd9Sstevel@tonic-gate if (strcasecmp(attrptr->attrname, _EXEC_POLICY) == 0) { 1607c478bd9Sstevel@tonic-gate if ((attrptr->attrvalue[0] == NULL) || 1617c478bd9Sstevel@tonic-gate (len = strlen(attrptr->attrvalue[0])) < 1) { 1627c478bd9Sstevel@tonic-gate exec->policy = nullstring; 1637c478bd9Sstevel@tonic-gate } else { 1647c478bd9Sstevel@tonic-gate exec->policy = buffer; 1657c478bd9Sstevel@tonic-gate buffer += len + 1; 1667c478bd9Sstevel@tonic-gate if (buffer >= ceiling) { 1677c478bd9Sstevel@tonic-gate return ((int)NSS_STR_PARSE_ERANGE); 1687c478bd9Sstevel@tonic-gate } 1697c478bd9Sstevel@tonic-gate (void) strcpy(exec->policy, 1707c478bd9Sstevel@tonic-gate attrptr->attrvalue[0]); 1717c478bd9Sstevel@tonic-gate } 1727c478bd9Sstevel@tonic-gate continue; 1737c478bd9Sstevel@tonic-gate } 1747c478bd9Sstevel@tonic-gate if (strcasecmp(attrptr->attrname, _EXEC_TYPE) == 0) { 1757c478bd9Sstevel@tonic-gate if ((attrptr->attrvalue[0] == NULL) || 1767c478bd9Sstevel@tonic-gate (len = strlen(attrptr->attrvalue[0])) < 1) { 1777c478bd9Sstevel@tonic-gate exec->type = nullstring; 1787c478bd9Sstevel@tonic-gate } else { 1797c478bd9Sstevel@tonic-gate exec->type = buffer; 1807c478bd9Sstevel@tonic-gate buffer += len + 1; 1817c478bd9Sstevel@tonic-gate if (buffer >= ceiling) { 1827c478bd9Sstevel@tonic-gate return ((int)NSS_STR_PARSE_ERANGE); 1837c478bd9Sstevel@tonic-gate } 1847c478bd9Sstevel@tonic-gate (void) strcpy(exec->type, 1857c478bd9Sstevel@tonic-gate attrptr->attrvalue[0]); 1867c478bd9Sstevel@tonic-gate } 1877c478bd9Sstevel@tonic-gate continue; 1887c478bd9Sstevel@tonic-gate } 1897c478bd9Sstevel@tonic-gate if (strcasecmp(attrptr->attrname, _EXEC_RES1) == 0) { 1907c478bd9Sstevel@tonic-gate if ((attrptr->attrvalue[0] == NULL) || 1917c478bd9Sstevel@tonic-gate (len = strlen(attrptr->attrvalue[0])) < 1) { 1927c478bd9Sstevel@tonic-gate exec->res1 = nullstring; 1937c478bd9Sstevel@tonic-gate } else { 1947c478bd9Sstevel@tonic-gate exec->res1 = buffer; 1957c478bd9Sstevel@tonic-gate buffer += len + 1; 1967c478bd9Sstevel@tonic-gate if (buffer >= ceiling) { 1977c478bd9Sstevel@tonic-gate return ((int)NSS_STR_PARSE_ERANGE); 1987c478bd9Sstevel@tonic-gate } 1997c478bd9Sstevel@tonic-gate (void) strcpy(exec->res1, 2007c478bd9Sstevel@tonic-gate attrptr->attrvalue[0]); 2017c478bd9Sstevel@tonic-gate } 2027c478bd9Sstevel@tonic-gate continue; 2037c478bd9Sstevel@tonic-gate } 2047c478bd9Sstevel@tonic-gate if (strcasecmp(attrptr->attrname, _EXEC_RES2) == 0) { 2057c478bd9Sstevel@tonic-gate if ((attrptr->attrvalue[0] == NULL) || 2067c478bd9Sstevel@tonic-gate (len = strlen(attrptr->attrvalue[0])) < 1) { 2077c478bd9Sstevel@tonic-gate exec->res2 = nullstring; 2087c478bd9Sstevel@tonic-gate } else { 2097c478bd9Sstevel@tonic-gate exec->res2 = buffer; 2107c478bd9Sstevel@tonic-gate buffer += len + 1; 2117c478bd9Sstevel@tonic-gate if (buffer >= ceiling) { 2127c478bd9Sstevel@tonic-gate return ((int)NSS_STR_PARSE_ERANGE); 2137c478bd9Sstevel@tonic-gate } 2147c478bd9Sstevel@tonic-gate (void) strcpy(exec->res2, 2157c478bd9Sstevel@tonic-gate attrptr->attrvalue[0]); 2167c478bd9Sstevel@tonic-gate } 2177c478bd9Sstevel@tonic-gate continue; 2187c478bd9Sstevel@tonic-gate } 2197c478bd9Sstevel@tonic-gate if (strcasecmp(attrptr->attrname, _EXEC_ID) == 0) { 2207c478bd9Sstevel@tonic-gate if ((attrptr->attrvalue[0] == NULL) || 2217c478bd9Sstevel@tonic-gate (len = strlen(attrptr->attrvalue[0])) < 1) { 2227c478bd9Sstevel@tonic-gate exec->id = nullstring; 2237c478bd9Sstevel@tonic-gate } else { 2247c478bd9Sstevel@tonic-gate exec->id = buffer; 2257c478bd9Sstevel@tonic-gate buffer += len + 1; 2267c478bd9Sstevel@tonic-gate if (buffer >= ceiling) { 2277c478bd9Sstevel@tonic-gate return ((int)NSS_STR_PARSE_ERANGE); 2287c478bd9Sstevel@tonic-gate } 2297c478bd9Sstevel@tonic-gate (void) strcpy(exec->id, attrptr->attrvalue[0]); 2307c478bd9Sstevel@tonic-gate } 2317c478bd9Sstevel@tonic-gate continue; 2327c478bd9Sstevel@tonic-gate } 2337c478bd9Sstevel@tonic-gate if (strcasecmp(attrptr->attrname, _EXEC_ATTRS) == 0) { 2347c478bd9Sstevel@tonic-gate if ((attrptr->attrvalue[0] == NULL) || 2357c478bd9Sstevel@tonic-gate (len = strlen(attrptr->attrvalue[0])) < 1) { 2367c478bd9Sstevel@tonic-gate exec->attr = nullstring; 2377c478bd9Sstevel@tonic-gate } else { 2387c478bd9Sstevel@tonic-gate exec->attr = buffer; 2397c478bd9Sstevel@tonic-gate buffer += len + 1; 2407c478bd9Sstevel@tonic-gate if (buffer >= ceiling) { 2417c478bd9Sstevel@tonic-gate return ((int)NSS_STR_PARSE_ERANGE); 2427c478bd9Sstevel@tonic-gate } 2437c478bd9Sstevel@tonic-gate (void) strcpy(exec->attr, 2447c478bd9Sstevel@tonic-gate attrptr->attrvalue[0]); 2457c478bd9Sstevel@tonic-gate } 2467c478bd9Sstevel@tonic-gate continue; 2477c478bd9Sstevel@tonic-gate } 2487c478bd9Sstevel@tonic-gate } 2497c478bd9Sstevel@tonic-gate 2507c478bd9Sstevel@tonic-gate exec->next = (execstr_t *)NULL; 2517c478bd9Sstevel@tonic-gate 2527c478bd9Sstevel@tonic-gate #ifdef DEBUG 2537c478bd9Sstevel@tonic-gate (void) fprintf(stdout, "\n[getexecattr.c: _exec_ldap_exec2ent]\n"); 2547c478bd9Sstevel@tonic-gate _print_execstr(exec); 2557c478bd9Sstevel@tonic-gate #endif /* DEBUG */ 2567c478bd9Sstevel@tonic-gate 2577c478bd9Sstevel@tonic-gate return ((int)NSS_STR_PARSE_SUCCESS); 2587c478bd9Sstevel@tonic-gate } 2597c478bd9Sstevel@tonic-gate 2607c478bd9Sstevel@tonic-gate 2617c478bd9Sstevel@tonic-gate /* 262cb5caa98Sdjl * place the results from ldap object structure into the file format 2637c478bd9Sstevel@tonic-gate * returns NSS_STR_PARSE_{SUCCESS, ERANGE, PARSE} 2647c478bd9Sstevel@tonic-gate */ 2657c478bd9Sstevel@tonic-gate static int 266cb5caa98Sdjl _nss_ldap_exec2str(ldap_backend_ptr be, nss_XbyY_args_t *argp) 2677c478bd9Sstevel@tonic-gate { 268cb5caa98Sdjl int status = NSS_STR_PARSE_SUCCESS; 2697c478bd9Sstevel@tonic-gate ns_ldap_result_t *result = be->result; 270cb5caa98Sdjl int len; 271cb5caa98Sdjl char *buffer, **name, **policy, **type; 272cb5caa98Sdjl char **res1, **res2, **id, **attr; 273cb5caa98Sdjl char *policy_str, *type_str, *res1_str, *res2_str; 274cb5caa98Sdjl char *id_str, *attr_str; 2757c478bd9Sstevel@tonic-gate 276cb5caa98Sdjl if (result == NULL) 277cb5caa98Sdjl return (NSS_STR_PARSE_PARSE); 278cb5caa98Sdjl 279cb5caa98Sdjl (void) memset(argp->buf.buffer, 0, argp->buf.buflen); 280cb5caa98Sdjl 281cb5caa98Sdjl name = __ns_ldap_getAttr(result->entry, _EXEC_NAME); 282cb5caa98Sdjl if (name == NULL || name[0] == NULL || 283cb5caa98Sdjl (strlen(name[0]) < 1)) { 284cb5caa98Sdjl status = NSS_STR_PARSE_PARSE; 285cb5caa98Sdjl goto result_exec2str; 2867c478bd9Sstevel@tonic-gate } 2877c478bd9Sstevel@tonic-gate 288cb5caa98Sdjl policy = __ns_ldap_getAttr(result->entry, _EXEC_POLICY); 2897c478bd9Sstevel@tonic-gate 290cb5caa98Sdjl if (policy == NULL || policy[0] == NULL) 291cb5caa98Sdjl policy_str = _NO_VALUE; 292cb5caa98Sdjl else 293cb5caa98Sdjl policy_str = policy[0]; 294cb5caa98Sdjl 295cb5caa98Sdjl type = __ns_ldap_getAttr(result->entry, _EXEC_TYPE); 296cb5caa98Sdjl if (type == NULL || type[0] == NULL) 297cb5caa98Sdjl type_str = _NO_VALUE; 298cb5caa98Sdjl else 299cb5caa98Sdjl type_str = type[0]; 300cb5caa98Sdjl 301cb5caa98Sdjl res1 = __ns_ldap_getAttr(result->entry, _EXEC_RES1); 302cb5caa98Sdjl if (res1 == NULL || res1[0] == NULL) 303cb5caa98Sdjl res1_str = _NO_VALUE; 304cb5caa98Sdjl else 305cb5caa98Sdjl res1_str = res1[0]; 306cb5caa98Sdjl 307cb5caa98Sdjl res2 = __ns_ldap_getAttr(result->entry, _EXEC_RES2); 308cb5caa98Sdjl if (res2 == NULL || res2[0] == NULL) 309cb5caa98Sdjl res2_str = _NO_VALUE; 310cb5caa98Sdjl else 311cb5caa98Sdjl res2_str = res2[0]; 312cb5caa98Sdjl 313cb5caa98Sdjl id = __ns_ldap_getAttr(result->entry, _EXEC_ID); 314cb5caa98Sdjl if (id == NULL || id[0] == NULL) 315cb5caa98Sdjl id_str = _NO_VALUE; 316cb5caa98Sdjl else 317cb5caa98Sdjl id_str = id[0]; 318cb5caa98Sdjl 319cb5caa98Sdjl attr = __ns_ldap_getAttr(result->entry, _EXEC_ATTRS); 320cb5caa98Sdjl if (attr == NULL || attr[0] == NULL) 321cb5caa98Sdjl attr_str = _NO_VALUE; 322cb5caa98Sdjl else 323cb5caa98Sdjl attr_str = attr[0]; 324cb5caa98Sdjl 325cb5caa98Sdjl /* 7 = 6 ':' + 1 '\0' */ 326cb5caa98Sdjl len = strlen(name[0]) + strlen(policy_str) + strlen(type_str) + 327cb5caa98Sdjl strlen(res1_str) + strlen(res2_str) + strlen(id_str) + 328cb5caa98Sdjl strlen(attr_str) + 7; 329cb5caa98Sdjl 330cb5caa98Sdjl if (len > argp->buf.buflen) { 331cb5caa98Sdjl status = NSS_STR_PARSE_ERANGE; 332cb5caa98Sdjl goto result_exec2str; 333cb5caa98Sdjl } 334cb5caa98Sdjl if (argp->buf.result != NULL) { 335cb5caa98Sdjl if ((be->buffer = calloc(1, len)) == NULL) { 336cb5caa98Sdjl status = NSS_STR_PARSE_PARSE; 337cb5caa98Sdjl goto result_exec2str; 338cb5caa98Sdjl } 339cb5caa98Sdjl buffer = be->buffer; 340cb5caa98Sdjl } else 341cb5caa98Sdjl buffer = argp->buf.buffer; 342cb5caa98Sdjl 343cb5caa98Sdjl (void) snprintf(buffer, len, "%s:%s:%s:%s:%s:%s:%s", 344cb5caa98Sdjl name[0], policy_str, type_str, res1_str, 345cb5caa98Sdjl res2_str, id_str, attr_str); 346cb5caa98Sdjl /* The front end marshaller does not need the trailing null */ 347cb5caa98Sdjl if (argp->buf.result != NULL) 348cb5caa98Sdjl be->buflen = strlen(buffer); 349cb5caa98Sdjl result_exec2str: 3507c478bd9Sstevel@tonic-gate (void) __ns_ldap_freeResult(&be->result); 3517c478bd9Sstevel@tonic-gate return (status); 3527c478bd9Sstevel@tonic-gate } 3537c478bd9Sstevel@tonic-gate 3547c478bd9Sstevel@tonic-gate 3557c478bd9Sstevel@tonic-gate static nss_status_t 3567c478bd9Sstevel@tonic-gate _exec_process_val(ldap_backend_ptr be, nss_XbyY_args_t *argp) 3577c478bd9Sstevel@tonic-gate { 3587c478bd9Sstevel@tonic-gate int status; 3597c478bd9Sstevel@tonic-gate nss_status_t nss_stat = NSS_UNAVAIL; 3607c478bd9Sstevel@tonic-gate ns_ldap_attr_t *attrptr; 3617c478bd9Sstevel@tonic-gate ns_ldap_entry_t *entry; 3627c478bd9Sstevel@tonic-gate ns_ldap_result_t *result = be->result; 3637c478bd9Sstevel@tonic-gate _priv_execattr *_priv_exec = (_priv_execattr *)(argp->key.attrp); 3647c478bd9Sstevel@tonic-gate 3657c478bd9Sstevel@tonic-gate argp->returnval = NULL; 3667c478bd9Sstevel@tonic-gate attrptr = getattr(result, 0); 3677c478bd9Sstevel@tonic-gate if (attrptr == NULL) { 3687c478bd9Sstevel@tonic-gate (void) __ns_ldap_freeResult(&be->result); 3697c478bd9Sstevel@tonic-gate return (nss_stat); 3707c478bd9Sstevel@tonic-gate } 3717c478bd9Sstevel@tonic-gate for (entry = result->entry; entry != NULL; entry = entry->next) { 3727c478bd9Sstevel@tonic-gate status = _exec_ldap_exec2ent(entry, argp); 3737c478bd9Sstevel@tonic-gate switch (status) { 3747c478bd9Sstevel@tonic-gate case NSS_STR_PARSE_SUCCESS: 3757c478bd9Sstevel@tonic-gate argp->returnval = argp->buf.result; 3767c478bd9Sstevel@tonic-gate nss_stat = NSS_SUCCESS; 377*01ef659dSJoep Vesseur if (IS_GET_ALL(_priv_exec->search_flag)) { 3787c478bd9Sstevel@tonic-gate if (_doexeclist(argp) == 0) { 3797c478bd9Sstevel@tonic-gate nss_stat = NSS_UNAVAIL; 3807c478bd9Sstevel@tonic-gate } 3817c478bd9Sstevel@tonic-gate } 3827c478bd9Sstevel@tonic-gate break; 3837c478bd9Sstevel@tonic-gate case NSS_STR_PARSE_ERANGE: 3847c478bd9Sstevel@tonic-gate argp->erange = 1; 3857c478bd9Sstevel@tonic-gate nss_stat = NSS_NOTFOUND; 3867c478bd9Sstevel@tonic-gate break; 3877c478bd9Sstevel@tonic-gate case NSS_STR_PARSE_PARSE: 3887c478bd9Sstevel@tonic-gate nss_stat = NSS_NOTFOUND; 3897c478bd9Sstevel@tonic-gate break; 3907c478bd9Sstevel@tonic-gate default: 3917c478bd9Sstevel@tonic-gate nss_stat = NSS_UNAVAIL; 3927c478bd9Sstevel@tonic-gate break; 3937c478bd9Sstevel@tonic-gate } 3947c478bd9Sstevel@tonic-gate 395*01ef659dSJoep Vesseur if (IS_GET_ONE(_priv_exec->search_flag) || 3967c478bd9Sstevel@tonic-gate (nss_stat != NSS_SUCCESS)) { 3977c478bd9Sstevel@tonic-gate break; 3987c478bd9Sstevel@tonic-gate } 3997c478bd9Sstevel@tonic-gate } 4007c478bd9Sstevel@tonic-gate 4017c478bd9Sstevel@tonic-gate return (nss_stat); 4027c478bd9Sstevel@tonic-gate } 4037c478bd9Sstevel@tonic-gate 4047c478bd9Sstevel@tonic-gate 4057c478bd9Sstevel@tonic-gate /* 4067c478bd9Sstevel@tonic-gate * Check if we have either an exact match or a wild-card entry for that id. 4077c478bd9Sstevel@tonic-gate */ 4087c478bd9Sstevel@tonic-gate static nss_status_t 4097c478bd9Sstevel@tonic-gate get_wild(ldap_backend_ptr be, nss_XbyY_args_t *argp, int getby_flag) 4107c478bd9Sstevel@tonic-gate { 4117c478bd9Sstevel@tonic-gate char *dup_id = NULL; 4127c478bd9Sstevel@tonic-gate char *wild_id; 4137c478bd9Sstevel@tonic-gate char searchfilter[SEARCHFILTERLEN]; 4147c478bd9Sstevel@tonic-gate char userdata[SEARCHFILTERLEN]; 4157c478bd9Sstevel@tonic-gate char name[SEARCHFILTERLEN]; 4167c478bd9Sstevel@tonic-gate char id[SEARCHFILTERLEN]; 4177c478bd9Sstevel@tonic-gate int ret; 4187c478bd9Sstevel@tonic-gate nss_status_t nss_stat = NSS_NOTFOUND; 4197c478bd9Sstevel@tonic-gate _priv_execattr *_priv_exec = (_priv_execattr *)(argp->key.attrp); 4207c478bd9Sstevel@tonic-gate const char *policy = _priv_exec->policy; 4217c478bd9Sstevel@tonic-gate const char *type = _priv_exec->type; 4227c478bd9Sstevel@tonic-gate 4237c478bd9Sstevel@tonic-gate if (strpbrk(policy, "*()\\") != NULL || 4247c478bd9Sstevel@tonic-gate type != NULL && strpbrk(type, "*()\\") != NULL) 4257c478bd9Sstevel@tonic-gate return ((nss_status_t)NSS_NOTFOUND); 4267c478bd9Sstevel@tonic-gate 4277c478bd9Sstevel@tonic-gate if (_priv_exec->id != NULL) 4287c478bd9Sstevel@tonic-gate dup_id = strdup(_priv_exec->id); 4297c478bd9Sstevel@tonic-gate 4307c478bd9Sstevel@tonic-gate switch (getby_flag) { 4317c478bd9Sstevel@tonic-gate case NSS_DBOP_EXECATTR_BYNAMEID: 4327c478bd9Sstevel@tonic-gate if (_ldap_filter_name(name, _priv_exec->name, 4337c478bd9Sstevel@tonic-gate sizeof (name)) != 0) 4347c478bd9Sstevel@tonic-gate goto go_out; 4357c478bd9Sstevel@tonic-gate break; 4367c478bd9Sstevel@tonic-gate } 4377c478bd9Sstevel@tonic-gate 4387c478bd9Sstevel@tonic-gate wild_id = dup_id; 4397c478bd9Sstevel@tonic-gate do { 4407c478bd9Sstevel@tonic-gate if (wild_id != NULL) { 4417c478bd9Sstevel@tonic-gate if (_ldap_filter_name(id, wild_id, sizeof (id)) != 0) 4427c478bd9Sstevel@tonic-gate goto go_out; 4437c478bd9Sstevel@tonic-gate } else 4447c478bd9Sstevel@tonic-gate (void) strlcpy(id, "*", sizeof (id)); 4457c478bd9Sstevel@tonic-gate 4467c478bd9Sstevel@tonic-gate switch (getby_flag) { 4477c478bd9Sstevel@tonic-gate case NSS_DBOP_EXECATTR_BYID: 4487c478bd9Sstevel@tonic-gate ret = snprintf(searchfilter, sizeof (searchfilter), 4497c478bd9Sstevel@tonic-gate _EXEC_GETEXECID, id, policy, ISWILD(type)); 4507c478bd9Sstevel@tonic-gate if (ret >= sizeof (searchfilter) || ret < 0) 4517c478bd9Sstevel@tonic-gate goto go_out; 4527c478bd9Sstevel@tonic-gate ret = snprintf(userdata, sizeof (userdata), 4537c478bd9Sstevel@tonic-gate _EXEC_GETEXECID_SSD, id, policy, ISWILD(type)); 4547c478bd9Sstevel@tonic-gate if (ret >= sizeof (userdata) || ret < 0) 4557c478bd9Sstevel@tonic-gate goto go_out; 4567c478bd9Sstevel@tonic-gate break; 4577c478bd9Sstevel@tonic-gate 4587c478bd9Sstevel@tonic-gate case NSS_DBOP_EXECATTR_BYNAMEID: 4597c478bd9Sstevel@tonic-gate ret = snprintf(searchfilter, sizeof (searchfilter), 4607c478bd9Sstevel@tonic-gate _EXEC_GETEXECNAMEID, name, id, 4617c478bd9Sstevel@tonic-gate policy, ISWILD(type)); 4627c478bd9Sstevel@tonic-gate if (ret >= sizeof (searchfilter) || ret < 0) 4637c478bd9Sstevel@tonic-gate goto go_out; 4647c478bd9Sstevel@tonic-gate ret = snprintf(userdata, sizeof (userdata), 4657c478bd9Sstevel@tonic-gate _EXEC_GETEXECNAMEID_SSD, name, id, 4667c478bd9Sstevel@tonic-gate policy, ISWILD(type)); 4677c478bd9Sstevel@tonic-gate if (ret >= sizeof (userdata) || ret < 0) 4687c478bd9Sstevel@tonic-gate goto go_out; 4697c478bd9Sstevel@tonic-gate break; 4707c478bd9Sstevel@tonic-gate 4717c478bd9Sstevel@tonic-gate default: 4727c478bd9Sstevel@tonic-gate goto go_out; 4737c478bd9Sstevel@tonic-gate } 4747c478bd9Sstevel@tonic-gate nss_stat = _nss_ldap_nocb_lookup(be, argp, _EXECATTR, 4757c478bd9Sstevel@tonic-gate searchfilter, NULL, _merge_SSD_filter, userdata); 4767c478bd9Sstevel@tonic-gate if (nss_stat == NSS_SUCCESS) 4777c478bd9Sstevel@tonic-gate break; 4787c478bd9Sstevel@tonic-gate } while ((wild_id = _exec_wild_id(wild_id, type)) != NULL); 4797c478bd9Sstevel@tonic-gate 4807c478bd9Sstevel@tonic-gate go_out: 4817c478bd9Sstevel@tonic-gate free(dup_id); 4827c478bd9Sstevel@tonic-gate 4837c478bd9Sstevel@tonic-gate return (nss_stat); 4847c478bd9Sstevel@tonic-gate } 4857c478bd9Sstevel@tonic-gate 4867c478bd9Sstevel@tonic-gate static nss_status_t 487cb5caa98Sdjl exec_attr_process_val(ldap_backend_ptr be, nss_XbyY_args_t *argp) { 488cb5caa98Sdjl 489cb5caa98Sdjl _priv_execattr *_priv_exec = (_priv_execattr *)(argp->key.attrp); 490cb5caa98Sdjl int stat, nss_stat = NSS_SUCCESS; 491cb5caa98Sdjl 492*01ef659dSJoep Vesseur if (IS_GET_ONE(_priv_exec->search_flag)) { 493cb5caa98Sdjl /* ns_ldap_entry_t -> file format */ 494cb5caa98Sdjl stat = (*be->ldapobj2str)(be, argp); 495cb5caa98Sdjl 496cb5caa98Sdjl if (stat == NSS_STR_PARSE_SUCCESS) { 497cb5caa98Sdjl if (argp->buf.result != NULL) { 498cb5caa98Sdjl /* file format -> execstr_t */ 499cb5caa98Sdjl stat = (*argp->str2ent)(be->buffer, 500cb5caa98Sdjl be->buflen, 501cb5caa98Sdjl argp->buf.result, 502cb5caa98Sdjl argp->buf.buffer, 503cb5caa98Sdjl argp->buf.buflen); 504cb5caa98Sdjl if (stat == NSS_STR_PARSE_SUCCESS) { 505cb5caa98Sdjl argp->returnval = argp->buf.result; 506cb5caa98Sdjl argp->returnlen = 1; /* irrelevant */ 507cb5caa98Sdjl nss_stat = NSS_SUCCESS; 508cb5caa98Sdjl } else { 509cb5caa98Sdjl argp->returnval = NULL; 510cb5caa98Sdjl argp->returnlen = 0; 511cb5caa98Sdjl nss_stat = NSS_NOTFOUND; 512cb5caa98Sdjl } 513cb5caa98Sdjl } else { 514cb5caa98Sdjl /* return file format in argp->buf.buffer */ 515cb5caa98Sdjl argp->returnval = argp->buf.buffer; 516cb5caa98Sdjl argp->returnlen = strlen(argp->buf.buffer); 517cb5caa98Sdjl nss_stat = NSS_SUCCESS; 518cb5caa98Sdjl } 519cb5caa98Sdjl } else { 520cb5caa98Sdjl argp->returnval = NULL; 521cb5caa98Sdjl argp->returnlen = 0; 522cb5caa98Sdjl nss_stat = NSS_NOTFOUND; 523cb5caa98Sdjl } 524cb5caa98Sdjl } else { 525cb5caa98Sdjl /* GET_ALL */ 526cb5caa98Sdjl nss_stat = _exec_process_val(be, argp); 527cb5caa98Sdjl _exec_cleanup(nss_stat, argp); 528cb5caa98Sdjl } 529cb5caa98Sdjl 530cb5caa98Sdjl return (nss_stat); 531cb5caa98Sdjl 532cb5caa98Sdjl } 533cb5caa98Sdjl 534cb5caa98Sdjl static nss_status_t 5357c478bd9Sstevel@tonic-gate getbynam(ldap_backend_ptr be, void *a) 5367c478bd9Sstevel@tonic-gate { 5377c478bd9Sstevel@tonic-gate char searchfilter[SEARCHFILTERLEN]; 5387c478bd9Sstevel@tonic-gate char userdata[SEARCHFILTERLEN]; 5397c478bd9Sstevel@tonic-gate char name[SEARCHFILTERLEN]; 5407c478bd9Sstevel@tonic-gate int ret; 5417c478bd9Sstevel@tonic-gate nss_status_t nss_stat; 5427c478bd9Sstevel@tonic-gate nss_XbyY_args_t *argp = (nss_XbyY_args_t *)a; 5437c478bd9Sstevel@tonic-gate _priv_execattr *_priv_exec = (_priv_execattr *)(argp->key.attrp); 5447c478bd9Sstevel@tonic-gate const char *policy = _priv_exec->policy; 5457c478bd9Sstevel@tonic-gate const char *type = _priv_exec->type; 5467c478bd9Sstevel@tonic-gate 5477c478bd9Sstevel@tonic-gate if (strpbrk(policy, "*()\\") != NULL || 5487c478bd9Sstevel@tonic-gate type != NULL && strpbrk(type, "*()\\") != NULL || 5497c478bd9Sstevel@tonic-gate _ldap_filter_name(name, _priv_exec->name, sizeof (name)) != 0) 5507c478bd9Sstevel@tonic-gate return ((nss_status_t)NSS_NOTFOUND); 5517c478bd9Sstevel@tonic-gate ret = snprintf(searchfilter, sizeof (searchfilter), 5527c478bd9Sstevel@tonic-gate _EXEC_GETEXECNAME, name, policy, ISWILD(type)); 5537c478bd9Sstevel@tonic-gate if (ret >= sizeof (searchfilter) || ret < 0) 5547c478bd9Sstevel@tonic-gate return ((nss_status_t)NSS_NOTFOUND); 5557c478bd9Sstevel@tonic-gate ret = snprintf(userdata, sizeof (userdata), 5567c478bd9Sstevel@tonic-gate _EXEC_GETEXECNAME_SSD, name, policy, ISWILD(type)); 5577c478bd9Sstevel@tonic-gate if (ret >= sizeof (userdata) || ret < 0) 5587c478bd9Sstevel@tonic-gate return ((nss_status_t)NSS_NOTFOUND); 5597c478bd9Sstevel@tonic-gate 5607c478bd9Sstevel@tonic-gate nss_stat = _nss_ldap_nocb_lookup(be, argp, _EXECATTR, 5617c478bd9Sstevel@tonic-gate searchfilter, NULL, _merge_SSD_filter, userdata); 5627c478bd9Sstevel@tonic-gate 5637c478bd9Sstevel@tonic-gate if (nss_stat == NSS_SUCCESS) 564cb5caa98Sdjl nss_stat = exec_attr_process_val(be, argp); 5657c478bd9Sstevel@tonic-gate 5667c478bd9Sstevel@tonic-gate return (nss_stat); 5677c478bd9Sstevel@tonic-gate } 5687c478bd9Sstevel@tonic-gate 5697c478bd9Sstevel@tonic-gate static nss_status_t 5707c478bd9Sstevel@tonic-gate getbyid(ldap_backend_ptr be, void *a) 5717c478bd9Sstevel@tonic-gate { 572cb5caa98Sdjl nss_status_t nss_stat = NSS_SUCCESS; 5737c478bd9Sstevel@tonic-gate nss_XbyY_args_t *argp = (nss_XbyY_args_t *)a; 5747c478bd9Sstevel@tonic-gate 5757c478bd9Sstevel@tonic-gate nss_stat = get_wild(be, argp, NSS_DBOP_EXECATTR_BYID); 5767c478bd9Sstevel@tonic-gate 5777c478bd9Sstevel@tonic-gate if (nss_stat == NSS_SUCCESS) 578cb5caa98Sdjl nss_stat = exec_attr_process_val(be, argp); 5797c478bd9Sstevel@tonic-gate 5807c478bd9Sstevel@tonic-gate return (nss_stat); 5817c478bd9Sstevel@tonic-gate } 5827c478bd9Sstevel@tonic-gate 5837c478bd9Sstevel@tonic-gate 5847c478bd9Sstevel@tonic-gate static nss_status_t 5857c478bd9Sstevel@tonic-gate getbynameid(ldap_backend_ptr be, void *a) 5867c478bd9Sstevel@tonic-gate { 5877c478bd9Sstevel@tonic-gate nss_status_t nss_stat; 5887c478bd9Sstevel@tonic-gate nss_XbyY_args_t *argp = (nss_XbyY_args_t *)a; 5897c478bd9Sstevel@tonic-gate 5907c478bd9Sstevel@tonic-gate nss_stat = get_wild(be, argp, NSS_DBOP_EXECATTR_BYNAMEID); 5917c478bd9Sstevel@tonic-gate 5927c478bd9Sstevel@tonic-gate if (nss_stat == NSS_SUCCESS) 593cb5caa98Sdjl nss_stat = exec_attr_process_val(be, argp); 5947c478bd9Sstevel@tonic-gate 5957c478bd9Sstevel@tonic-gate return (nss_stat); 5967c478bd9Sstevel@tonic-gate } 5977c478bd9Sstevel@tonic-gate 5987c478bd9Sstevel@tonic-gate 5997c478bd9Sstevel@tonic-gate static ldap_backend_op_t execattr_ops[] = { 6007c478bd9Sstevel@tonic-gate _nss_ldap_destr, 6017c478bd9Sstevel@tonic-gate _nss_ldap_endent, 6027c478bd9Sstevel@tonic-gate _nss_ldap_setent, 6037c478bd9Sstevel@tonic-gate _nss_ldap_getent, 6047c478bd9Sstevel@tonic-gate getbynam, 6057c478bd9Sstevel@tonic-gate getbyid, 6067c478bd9Sstevel@tonic-gate getbynameid 6077c478bd9Sstevel@tonic-gate }; 6087c478bd9Sstevel@tonic-gate 6097c478bd9Sstevel@tonic-gate 6107c478bd9Sstevel@tonic-gate /*ARGSUSED0*/ 6117c478bd9Sstevel@tonic-gate nss_backend_t * 6127c478bd9Sstevel@tonic-gate _nss_ldap_exec_attr_constr(const char *dummy1, 6137c478bd9Sstevel@tonic-gate const char *dummy2, 6147c478bd9Sstevel@tonic-gate const char *dummy3, 6157c478bd9Sstevel@tonic-gate const char *dummy4, 6167c478bd9Sstevel@tonic-gate const char *dummy5, 6177c478bd9Sstevel@tonic-gate const char *dummy6, 6187c478bd9Sstevel@tonic-gate const char *dummy7) 6197c478bd9Sstevel@tonic-gate { 6207c478bd9Sstevel@tonic-gate #ifdef DEBUG 6217c478bd9Sstevel@tonic-gate (void) fprintf(stdout, 6227c478bd9Sstevel@tonic-gate "\n[getexecattr.c: _nss_ldap_exec_attr_constr]\n"); 6237c478bd9Sstevel@tonic-gate #endif 6247c478bd9Sstevel@tonic-gate return ((nss_backend_t *)_nss_ldap_constr(execattr_ops, 6257c478bd9Sstevel@tonic-gate sizeof (execattr_ops)/sizeof (execattr_ops[0]), _EXECATTR, 626cb5caa98Sdjl exec_attrs, _nss_ldap_exec2str)); 6277c478bd9Sstevel@tonic-gate } 628