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 <secdb.h> 290Sstevel@tonic-gate #include <auth_attr.h> 300Sstevel@tonic-gate #include "ldap_common.h" 310Sstevel@tonic-gate 320Sstevel@tonic-gate 330Sstevel@tonic-gate /* auth_attr attributes filters */ 340Sstevel@tonic-gate #define _AUTH_NAME "cn" 350Sstevel@tonic-gate #define _AUTH_RES1 "SolarisAttrReserved1" 360Sstevel@tonic-gate #define _AUTH_RES2 "SolarisAttrReserved2" 370Sstevel@tonic-gate #define _AUTH_SHORTDES "SolarisAttrShortDesc" 380Sstevel@tonic-gate #define _AUTH_LONGDES "SolarisAttrLongDesc" 390Sstevel@tonic-gate #define _AUTH_ATTRS "SolarisAttrKeyValue" 400Sstevel@tonic-gate #define _AUTH_GETAUTHNAME "(&(objectClass=SolarisAuthAttr)(cn=%s))" 410Sstevel@tonic-gate #define _AUTH_GETAUTHNAME_SSD "(&(%%s)(cn=%s))" 420Sstevel@tonic-gate 430Sstevel@tonic-gate 440Sstevel@tonic-gate static const char *auth_attrs[] = { 450Sstevel@tonic-gate _AUTH_NAME, 460Sstevel@tonic-gate _AUTH_RES1, 470Sstevel@tonic-gate _AUTH_RES2, 480Sstevel@tonic-gate _AUTH_SHORTDES, 490Sstevel@tonic-gate _AUTH_LONGDES, 500Sstevel@tonic-gate _AUTH_ATTRS, 510Sstevel@tonic-gate (char *)NULL 520Sstevel@tonic-gate }; 53*2830Sdjl /* 54*2830Sdjl * _nss_ldap_auth2str is the data marshaling method for the auth_attr 55*2830Sdjl * system call getauthattr and getauthnam. 56*2830Sdjl * This method is called after a successful search has been performed. 57*2830Sdjl * This method will parse the search results into the file format. 58*2830Sdjl * e.g. 59*2830Sdjl * 60*2830Sdjl * solaris.:::All Solaris Authorizations::help=AllSolAuthsHeader.html 61*2830Sdjl * 62*2830Sdjl */ 630Sstevel@tonic-gate static int 64*2830Sdjl _nss_ldap_auth2str(ldap_backend_ptr be, nss_XbyY_args_t *argp) 650Sstevel@tonic-gate { 66*2830Sdjl int nss_result; 67*2830Sdjl int buflen = 0; 680Sstevel@tonic-gate unsigned long len = 0L; 69*2830Sdjl char *buffer = NULL; 700Sstevel@tonic-gate ns_ldap_result_t *result = be->result; 71*2830Sdjl char **name, **res1, **res2, **sdes, **ldes, **attr; 72*2830Sdjl char *res1_str, *res2_str, *sdes_str, *ldes_str; 73*2830Sdjl char *attr_str; 740Sstevel@tonic-gate 75*2830Sdjl if (result == NULL) 76*2830Sdjl return (NSS_STR_PARSE_PARSE); 77*2830Sdjl 78*2830Sdjl buflen = argp->buf.buflen; 79*2830Sdjl nss_result = NSS_STR_PARSE_SUCCESS; 800Sstevel@tonic-gate (void) memset(argp->buf.buffer, 0, buflen); 810Sstevel@tonic-gate 82*2830Sdjl name = __ns_ldap_getAttr(result->entry, _AUTH_NAME); 83*2830Sdjl if (name == NULL || name[0] == NULL || 84*2830Sdjl (strlen(name[0]) < 1)) { 85*2830Sdjl nss_result = NSS_STR_PARSE_PARSE; 86*2830Sdjl goto result_auth2str; 87*2830Sdjl } 88*2830Sdjl res1 = __ns_ldap_getAttr(result->entry, _AUTH_RES1); 89*2830Sdjl if (res1 == NULL || res1[0] == NULL || (strlen(res1[0]) < 1)) 90*2830Sdjl res1_str = _NO_VALUE; 91*2830Sdjl else 92*2830Sdjl res1_str = res1[0]; 93*2830Sdjl 94*2830Sdjl res2 = __ns_ldap_getAttr(result->entry, _AUTH_RES2); 95*2830Sdjl if (res2 == NULL || res2[0] == NULL || (strlen(res2[0]) < 1)) 96*2830Sdjl res2_str = _NO_VALUE; 97*2830Sdjl else 98*2830Sdjl res2_str = res2[0]; 99*2830Sdjl 100*2830Sdjl sdes = __ns_ldap_getAttr(result->entry, _AUTH_SHORTDES); 101*2830Sdjl if (sdes == NULL || sdes[0] == NULL || (strlen(sdes[0]) < 1)) 102*2830Sdjl sdes_str = _NO_VALUE; 103*2830Sdjl else 104*2830Sdjl sdes_str = sdes[0]; 105*2830Sdjl 106*2830Sdjl ldes = __ns_ldap_getAttr(result->entry, _AUTH_LONGDES); 107*2830Sdjl if (ldes == NULL || ldes[0] == NULL || (strlen(ldes[0]) < 1)) 108*2830Sdjl ldes_str = _NO_VALUE; 109*2830Sdjl else 110*2830Sdjl ldes_str = ldes[0]; 111*2830Sdjl 112*2830Sdjl attr = __ns_ldap_getAttr(result->entry, _AUTH_ATTRS); 113*2830Sdjl if (attr == NULL || attr[0] == NULL || (strlen(attr[0]) < 1)) 114*2830Sdjl attr_str = _NO_VALUE; 115*2830Sdjl else 116*2830Sdjl attr_str = attr[0]; 117*2830Sdjl /* 6 = 5 ':' + 1 '\0' */ 118*2830Sdjl len = strlen(name[0]) + strlen(res1_str) + strlen(res2_str) + 119*2830Sdjl strlen(sdes_str) + strlen(ldes_str) + strlen(attr_str) + 6; 120*2830Sdjl if (len > buflen) { 121*2830Sdjl nss_result = NSS_STR_PARSE_ERANGE; 122*2830Sdjl goto result_auth2str; 1230Sstevel@tonic-gate } 1240Sstevel@tonic-gate 125*2830Sdjl if (argp->buf.result != NULL) { 126*2830Sdjl if ((be->buffer = calloc(1, len)) == NULL) { 127*2830Sdjl nss_result = NSS_STR_PARSE_PARSE; 128*2830Sdjl goto result_auth2str; 1290Sstevel@tonic-gate } 130*2830Sdjl buffer = be->buffer; 131*2830Sdjl } else 132*2830Sdjl buffer = argp->buf.buffer; 133*2830Sdjl (void) snprintf(buffer, len, "%s:%s:%s:%s:%s:%s", 134*2830Sdjl name[0], res1_str, res2_str, sdes_str, 135*2830Sdjl ldes_str, attr_str); 136*2830Sdjl /* The front end marshaller doesn't need the trailing null */ 137*2830Sdjl if (argp->buf.result != NULL) 138*2830Sdjl be->buflen = strlen(be->buffer); 1390Sstevel@tonic-gate 140*2830Sdjl result_auth2str: 1410Sstevel@tonic-gate (void) __ns_ldap_freeResult(&be->result); 1420Sstevel@tonic-gate return ((int)nss_result); 1430Sstevel@tonic-gate } 1440Sstevel@tonic-gate 1450Sstevel@tonic-gate 1460Sstevel@tonic-gate static nss_status_t 1470Sstevel@tonic-gate getbyname(ldap_backend_ptr be, void *a) 1480Sstevel@tonic-gate { 1490Sstevel@tonic-gate nss_XbyY_args_t *argp = (nss_XbyY_args_t *)a; 1500Sstevel@tonic-gate char searchfilter[SEARCHFILTERLEN]; 1510Sstevel@tonic-gate char userdata[SEARCHFILTERLEN]; 1520Sstevel@tonic-gate char name[SEARCHFILTERLEN]; 1530Sstevel@tonic-gate int ret; 1540Sstevel@tonic-gate 1550Sstevel@tonic-gate if (_ldap_filter_name(name, argp->key.name, sizeof (name)) != 0) 1560Sstevel@tonic-gate return ((nss_status_t)NSS_NOTFOUND); 1570Sstevel@tonic-gate 1580Sstevel@tonic-gate ret = snprintf(searchfilter, SEARCHFILTERLEN, 1590Sstevel@tonic-gate _AUTH_GETAUTHNAME, name); 1600Sstevel@tonic-gate if (ret >= sizeof (searchfilter) || ret < 0) 1610Sstevel@tonic-gate return ((nss_status_t)NSS_NOTFOUND); 1620Sstevel@tonic-gate 1630Sstevel@tonic-gate ret = snprintf(userdata, sizeof (userdata), 1640Sstevel@tonic-gate _AUTH_GETAUTHNAME_SSD, name); 1650Sstevel@tonic-gate if (ret >= sizeof (userdata) || ret < 0) 1660Sstevel@tonic-gate return ((nss_status_t)NSS_NOTFOUND); 1670Sstevel@tonic-gate 1680Sstevel@tonic-gate return ((nss_status_t)_nss_ldap_lookup(be, argp, 1690Sstevel@tonic-gate _AUTHATTR, searchfilter, NULL, _merge_SSD_filter, userdata)); 1700Sstevel@tonic-gate } 1710Sstevel@tonic-gate 1720Sstevel@tonic-gate 1730Sstevel@tonic-gate static ldap_backend_op_t authattr_ops[] = { 1740Sstevel@tonic-gate _nss_ldap_destr, 1750Sstevel@tonic-gate _nss_ldap_endent, 1760Sstevel@tonic-gate _nss_ldap_setent, 1770Sstevel@tonic-gate _nss_ldap_getent, 1780Sstevel@tonic-gate getbyname 1790Sstevel@tonic-gate }; 1800Sstevel@tonic-gate 1810Sstevel@tonic-gate 1820Sstevel@tonic-gate /*ARGSUSED0*/ 1830Sstevel@tonic-gate nss_backend_t * 1840Sstevel@tonic-gate _nss_ldap_auth_attr_constr(const char *dummy1, 1850Sstevel@tonic-gate const char *dummy2, 1860Sstevel@tonic-gate const char *dummy3, 1870Sstevel@tonic-gate const char *dummy4, 1880Sstevel@tonic-gate const char *dummy5) 1890Sstevel@tonic-gate { 1900Sstevel@tonic-gate return ((nss_backend_t *)_nss_ldap_constr(authattr_ops, 1910Sstevel@tonic-gate sizeof (authattr_ops)/sizeof (authattr_ops[0]), _AUTHATTR, 192*2830Sdjl auth_attrs, _nss_ldap_auth2str)); 1930Sstevel@tonic-gate } 194