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 5*cb5caa98Sdjl * Common Development and Distribution License (the "License"). 6*cb5caa98Sdjl * 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*cb5caa98Sdjl * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 277c478bd9Sstevel@tonic-gate 287c478bd9Sstevel@tonic-gate #include <secdb.h> 297c478bd9Sstevel@tonic-gate #include <auth_attr.h> 307c478bd9Sstevel@tonic-gate #include "ldap_common.h" 317c478bd9Sstevel@tonic-gate 327c478bd9Sstevel@tonic-gate 337c478bd9Sstevel@tonic-gate /* auth_attr attributes filters */ 347c478bd9Sstevel@tonic-gate #define _AUTH_NAME "cn" 357c478bd9Sstevel@tonic-gate #define _AUTH_RES1 "SolarisAttrReserved1" 367c478bd9Sstevel@tonic-gate #define _AUTH_RES2 "SolarisAttrReserved2" 377c478bd9Sstevel@tonic-gate #define _AUTH_SHORTDES "SolarisAttrShortDesc" 387c478bd9Sstevel@tonic-gate #define _AUTH_LONGDES "SolarisAttrLongDesc" 397c478bd9Sstevel@tonic-gate #define _AUTH_ATTRS "SolarisAttrKeyValue" 407c478bd9Sstevel@tonic-gate #define _AUTH_GETAUTHNAME "(&(objectClass=SolarisAuthAttr)(cn=%s))" 417c478bd9Sstevel@tonic-gate #define _AUTH_GETAUTHNAME_SSD "(&(%%s)(cn=%s))" 427c478bd9Sstevel@tonic-gate 437c478bd9Sstevel@tonic-gate 447c478bd9Sstevel@tonic-gate static const char *auth_attrs[] = { 457c478bd9Sstevel@tonic-gate _AUTH_NAME, 467c478bd9Sstevel@tonic-gate _AUTH_RES1, 477c478bd9Sstevel@tonic-gate _AUTH_RES2, 487c478bd9Sstevel@tonic-gate _AUTH_SHORTDES, 497c478bd9Sstevel@tonic-gate _AUTH_LONGDES, 507c478bd9Sstevel@tonic-gate _AUTH_ATTRS, 517c478bd9Sstevel@tonic-gate (char *)NULL 527c478bd9Sstevel@tonic-gate }; 53*cb5caa98Sdjl /* 54*cb5caa98Sdjl * _nss_ldap_auth2str is the data marshaling method for the auth_attr 55*cb5caa98Sdjl * system call getauthattr and getauthnam. 56*cb5caa98Sdjl * This method is called after a successful search has been performed. 57*cb5caa98Sdjl * This method will parse the search results into the file format. 58*cb5caa98Sdjl * e.g. 59*cb5caa98Sdjl * 60*cb5caa98Sdjl * solaris.:::All Solaris Authorizations::help=AllSolAuthsHeader.html 61*cb5caa98Sdjl * 62*cb5caa98Sdjl */ 637c478bd9Sstevel@tonic-gate static int 64*cb5caa98Sdjl _nss_ldap_auth2str(ldap_backend_ptr be, nss_XbyY_args_t *argp) 657c478bd9Sstevel@tonic-gate { 66*cb5caa98Sdjl int nss_result; 67*cb5caa98Sdjl int buflen = 0; 687c478bd9Sstevel@tonic-gate unsigned long len = 0L; 69*cb5caa98Sdjl char *buffer = NULL; 707c478bd9Sstevel@tonic-gate ns_ldap_result_t *result = be->result; 71*cb5caa98Sdjl char **name, **res1, **res2, **sdes, **ldes, **attr; 72*cb5caa98Sdjl char *res1_str, *res2_str, *sdes_str, *ldes_str; 73*cb5caa98Sdjl char *attr_str; 747c478bd9Sstevel@tonic-gate 75*cb5caa98Sdjl if (result == NULL) 76*cb5caa98Sdjl return (NSS_STR_PARSE_PARSE); 77*cb5caa98Sdjl 78*cb5caa98Sdjl buflen = argp->buf.buflen; 79*cb5caa98Sdjl nss_result = NSS_STR_PARSE_SUCCESS; 807c478bd9Sstevel@tonic-gate (void) memset(argp->buf.buffer, 0, buflen); 817c478bd9Sstevel@tonic-gate 82*cb5caa98Sdjl name = __ns_ldap_getAttr(result->entry, _AUTH_NAME); 83*cb5caa98Sdjl if (name == NULL || name[0] == NULL || 84*cb5caa98Sdjl (strlen(name[0]) < 1)) { 85*cb5caa98Sdjl nss_result = NSS_STR_PARSE_PARSE; 86*cb5caa98Sdjl goto result_auth2str; 87*cb5caa98Sdjl } 88*cb5caa98Sdjl res1 = __ns_ldap_getAttr(result->entry, _AUTH_RES1); 89*cb5caa98Sdjl if (res1 == NULL || res1[0] == NULL || (strlen(res1[0]) < 1)) 90*cb5caa98Sdjl res1_str = _NO_VALUE; 91*cb5caa98Sdjl else 92*cb5caa98Sdjl res1_str = res1[0]; 93*cb5caa98Sdjl 94*cb5caa98Sdjl res2 = __ns_ldap_getAttr(result->entry, _AUTH_RES2); 95*cb5caa98Sdjl if (res2 == NULL || res2[0] == NULL || (strlen(res2[0]) < 1)) 96*cb5caa98Sdjl res2_str = _NO_VALUE; 97*cb5caa98Sdjl else 98*cb5caa98Sdjl res2_str = res2[0]; 99*cb5caa98Sdjl 100*cb5caa98Sdjl sdes = __ns_ldap_getAttr(result->entry, _AUTH_SHORTDES); 101*cb5caa98Sdjl if (sdes == NULL || sdes[0] == NULL || (strlen(sdes[0]) < 1)) 102*cb5caa98Sdjl sdes_str = _NO_VALUE; 103*cb5caa98Sdjl else 104*cb5caa98Sdjl sdes_str = sdes[0]; 105*cb5caa98Sdjl 106*cb5caa98Sdjl ldes = __ns_ldap_getAttr(result->entry, _AUTH_LONGDES); 107*cb5caa98Sdjl if (ldes == NULL || ldes[0] == NULL || (strlen(ldes[0]) < 1)) 108*cb5caa98Sdjl ldes_str = _NO_VALUE; 109*cb5caa98Sdjl else 110*cb5caa98Sdjl ldes_str = ldes[0]; 111*cb5caa98Sdjl 112*cb5caa98Sdjl attr = __ns_ldap_getAttr(result->entry, _AUTH_ATTRS); 113*cb5caa98Sdjl if (attr == NULL || attr[0] == NULL || (strlen(attr[0]) < 1)) 114*cb5caa98Sdjl attr_str = _NO_VALUE; 115*cb5caa98Sdjl else 116*cb5caa98Sdjl attr_str = attr[0]; 117*cb5caa98Sdjl /* 6 = 5 ':' + 1 '\0' */ 118*cb5caa98Sdjl len = strlen(name[0]) + strlen(res1_str) + strlen(res2_str) + 119*cb5caa98Sdjl strlen(sdes_str) + strlen(ldes_str) + strlen(attr_str) + 6; 120*cb5caa98Sdjl if (len > buflen) { 121*cb5caa98Sdjl nss_result = NSS_STR_PARSE_ERANGE; 122*cb5caa98Sdjl goto result_auth2str; 1237c478bd9Sstevel@tonic-gate } 1247c478bd9Sstevel@tonic-gate 125*cb5caa98Sdjl if (argp->buf.result != NULL) { 126*cb5caa98Sdjl if ((be->buffer = calloc(1, len)) == NULL) { 127*cb5caa98Sdjl nss_result = NSS_STR_PARSE_PARSE; 128*cb5caa98Sdjl goto result_auth2str; 1297c478bd9Sstevel@tonic-gate } 130*cb5caa98Sdjl buffer = be->buffer; 131*cb5caa98Sdjl } else 132*cb5caa98Sdjl buffer = argp->buf.buffer; 133*cb5caa98Sdjl (void) snprintf(buffer, len, "%s:%s:%s:%s:%s:%s", 134*cb5caa98Sdjl name[0], res1_str, res2_str, sdes_str, 135*cb5caa98Sdjl ldes_str, attr_str); 136*cb5caa98Sdjl /* The front end marshaller doesn't need the trailing null */ 137*cb5caa98Sdjl if (argp->buf.result != NULL) 138*cb5caa98Sdjl be->buflen = strlen(be->buffer); 1397c478bd9Sstevel@tonic-gate 140*cb5caa98Sdjl result_auth2str: 1417c478bd9Sstevel@tonic-gate (void) __ns_ldap_freeResult(&be->result); 1427c478bd9Sstevel@tonic-gate return ((int)nss_result); 1437c478bd9Sstevel@tonic-gate } 1447c478bd9Sstevel@tonic-gate 1457c478bd9Sstevel@tonic-gate 1467c478bd9Sstevel@tonic-gate static nss_status_t 1477c478bd9Sstevel@tonic-gate getbyname(ldap_backend_ptr be, void *a) 1487c478bd9Sstevel@tonic-gate { 1497c478bd9Sstevel@tonic-gate nss_XbyY_args_t *argp = (nss_XbyY_args_t *)a; 1507c478bd9Sstevel@tonic-gate char searchfilter[SEARCHFILTERLEN]; 1517c478bd9Sstevel@tonic-gate char userdata[SEARCHFILTERLEN]; 1527c478bd9Sstevel@tonic-gate char name[SEARCHFILTERLEN]; 1537c478bd9Sstevel@tonic-gate int ret; 1547c478bd9Sstevel@tonic-gate 1557c478bd9Sstevel@tonic-gate if (_ldap_filter_name(name, argp->key.name, sizeof (name)) != 0) 1567c478bd9Sstevel@tonic-gate return ((nss_status_t)NSS_NOTFOUND); 1577c478bd9Sstevel@tonic-gate 1587c478bd9Sstevel@tonic-gate ret = snprintf(searchfilter, SEARCHFILTERLEN, 1597c478bd9Sstevel@tonic-gate _AUTH_GETAUTHNAME, name); 1607c478bd9Sstevel@tonic-gate if (ret >= sizeof (searchfilter) || ret < 0) 1617c478bd9Sstevel@tonic-gate return ((nss_status_t)NSS_NOTFOUND); 1627c478bd9Sstevel@tonic-gate 1637c478bd9Sstevel@tonic-gate ret = snprintf(userdata, sizeof (userdata), 1647c478bd9Sstevel@tonic-gate _AUTH_GETAUTHNAME_SSD, name); 1657c478bd9Sstevel@tonic-gate if (ret >= sizeof (userdata) || ret < 0) 1667c478bd9Sstevel@tonic-gate return ((nss_status_t)NSS_NOTFOUND); 1677c478bd9Sstevel@tonic-gate 1687c478bd9Sstevel@tonic-gate return ((nss_status_t)_nss_ldap_lookup(be, argp, 1697c478bd9Sstevel@tonic-gate _AUTHATTR, searchfilter, NULL, _merge_SSD_filter, userdata)); 1707c478bd9Sstevel@tonic-gate } 1717c478bd9Sstevel@tonic-gate 1727c478bd9Sstevel@tonic-gate 1737c478bd9Sstevel@tonic-gate static ldap_backend_op_t authattr_ops[] = { 1747c478bd9Sstevel@tonic-gate _nss_ldap_destr, 1757c478bd9Sstevel@tonic-gate _nss_ldap_endent, 1767c478bd9Sstevel@tonic-gate _nss_ldap_setent, 1777c478bd9Sstevel@tonic-gate _nss_ldap_getent, 1787c478bd9Sstevel@tonic-gate getbyname 1797c478bd9Sstevel@tonic-gate }; 1807c478bd9Sstevel@tonic-gate 1817c478bd9Sstevel@tonic-gate 1827c478bd9Sstevel@tonic-gate /*ARGSUSED0*/ 1837c478bd9Sstevel@tonic-gate nss_backend_t * 1847c478bd9Sstevel@tonic-gate _nss_ldap_auth_attr_constr(const char *dummy1, 1857c478bd9Sstevel@tonic-gate const char *dummy2, 1867c478bd9Sstevel@tonic-gate const char *dummy3, 1877c478bd9Sstevel@tonic-gate const char *dummy4, 1887c478bd9Sstevel@tonic-gate const char *dummy5) 1897c478bd9Sstevel@tonic-gate { 1907c478bd9Sstevel@tonic-gate return ((nss_backend_t *)_nss_ldap_constr(authattr_ops, 1917c478bd9Sstevel@tonic-gate sizeof (authattr_ops)/sizeof (authattr_ops[0]), _AUTHATTR, 192*cb5caa98Sdjl auth_attrs, _nss_ldap_auth2str)); 1937c478bd9Sstevel@tonic-gate } 194