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 <prof_attr.h> 31*0Sstevel@tonic-gate #include "ldap_common.h" 32*0Sstevel@tonic-gate 33*0Sstevel@tonic-gate 34*0Sstevel@tonic-gate /* prof_attr attributes filters */ 35*0Sstevel@tonic-gate #define _PROF_NAME "cn" 36*0Sstevel@tonic-gate #define _PROF_RES1 "SolarisAttrReserved1" 37*0Sstevel@tonic-gate #define _PROF_RES2 "SolarisAttrReserved2" 38*0Sstevel@tonic-gate #define _PROF_DESC "SolarisAttrLongDesc" 39*0Sstevel@tonic-gate #define _PROF_ATTRS "SolarisAttrKeyValue" 40*0Sstevel@tonic-gate #define _PROF_GETPROFNAME "(&(objectClass=SolarisProfAttr)(cn=%s))" 41*0Sstevel@tonic-gate #define _PROF_GETPROFNAME_SSD "(&(%%s)(cn=%s))" 42*0Sstevel@tonic-gate 43*0Sstevel@tonic-gate static const char *prof_attrs[] = { 44*0Sstevel@tonic-gate _PROF_NAME, 45*0Sstevel@tonic-gate _PROF_RES1, 46*0Sstevel@tonic-gate _PROF_RES2, 47*0Sstevel@tonic-gate _PROF_DESC, 48*0Sstevel@tonic-gate _PROF_ATTRS, 49*0Sstevel@tonic-gate (char *)NULL 50*0Sstevel@tonic-gate }; 51*0Sstevel@tonic-gate 52*0Sstevel@tonic-gate 53*0Sstevel@tonic-gate static int 54*0Sstevel@tonic-gate _nss_ldap_prof2ent(ldap_backend_ptr be, nss_XbyY_args_t *argp) 55*0Sstevel@tonic-gate { 56*0Sstevel@tonic-gate int i, nss_result; 57*0Sstevel@tonic-gate int buflen = (int)0; 58*0Sstevel@tonic-gate unsigned long len = 0L; 59*0Sstevel@tonic-gate char *nullstring = (char *)NULL; 60*0Sstevel@tonic-gate char *buffer = (char *)NULL; 61*0Sstevel@tonic-gate char *ceiling = (char *)NULL; 62*0Sstevel@tonic-gate profstr_t *prof = (profstr_t *)NULL; 63*0Sstevel@tonic-gate ns_ldap_attr_t *attrptr; 64*0Sstevel@tonic-gate ns_ldap_result_t *result = be->result; 65*0Sstevel@tonic-gate 66*0Sstevel@tonic-gate buffer = argp->buf.buffer; 67*0Sstevel@tonic-gate buflen = (size_t)argp->buf.buflen; 68*0Sstevel@tonic-gate if (!argp->buf.result) { 69*0Sstevel@tonic-gate nss_result = (int)NSS_STR_PARSE_ERANGE; 70*0Sstevel@tonic-gate goto result_prof2ent; 71*0Sstevel@tonic-gate } 72*0Sstevel@tonic-gate prof = (profstr_t *)(argp->buf.result); 73*0Sstevel@tonic-gate ceiling = buffer + buflen; 74*0Sstevel@tonic-gate prof->name = (char *)NULL; 75*0Sstevel@tonic-gate prof->res1 = (char *)NULL; 76*0Sstevel@tonic-gate prof->res2 = (char *)NULL; 77*0Sstevel@tonic-gate prof->desc = (char *)NULL; 78*0Sstevel@tonic-gate prof->attr = (char *)NULL; 79*0Sstevel@tonic-gate nss_result = (int)NSS_STR_PARSE_SUCCESS; 80*0Sstevel@tonic-gate (void) memset(argp->buf.buffer, 0, buflen); 81*0Sstevel@tonic-gate 82*0Sstevel@tonic-gate attrptr = getattr(result, 0); 83*0Sstevel@tonic-gate if (attrptr == NULL) { 84*0Sstevel@tonic-gate nss_result = (int)NSS_STR_PARSE_PARSE; 85*0Sstevel@tonic-gate goto result_prof2ent; 86*0Sstevel@tonic-gate } 87*0Sstevel@tonic-gate 88*0Sstevel@tonic-gate for (i = 0; i < result->entry->attr_count; i++) { 89*0Sstevel@tonic-gate attrptr = getattr(result, i); 90*0Sstevel@tonic-gate if (attrptr == NULL) { 91*0Sstevel@tonic-gate nss_result = (int)NSS_STR_PARSE_PARSE; 92*0Sstevel@tonic-gate goto result_prof2ent; 93*0Sstevel@tonic-gate } 94*0Sstevel@tonic-gate if (strcasecmp(attrptr->attrname, _PROF_NAME) == 0) { 95*0Sstevel@tonic-gate if ((attrptr->attrvalue[0] == NULL) || 96*0Sstevel@tonic-gate (len = strlen(attrptr->attrvalue[0])) < 1) { 97*0Sstevel@tonic-gate nss_result = (int)NSS_STR_PARSE_PARSE; 98*0Sstevel@tonic-gate goto result_prof2ent; 99*0Sstevel@tonic-gate } 100*0Sstevel@tonic-gate prof->name = buffer; 101*0Sstevel@tonic-gate buffer += len + 1; 102*0Sstevel@tonic-gate if (buffer >= ceiling) { 103*0Sstevel@tonic-gate nss_result = (int)NSS_STR_PARSE_ERANGE; 104*0Sstevel@tonic-gate goto result_prof2ent; 105*0Sstevel@tonic-gate } 106*0Sstevel@tonic-gate (void) strcpy(prof->name, attrptr->attrvalue[0]); 107*0Sstevel@tonic-gate continue; 108*0Sstevel@tonic-gate } 109*0Sstevel@tonic-gate if (strcasecmp(attrptr->attrname, _PROF_RES1) == 0) { 110*0Sstevel@tonic-gate if ((attrptr->attrvalue[0] == NULL) || 111*0Sstevel@tonic-gate (len = strlen(attrptr->attrvalue[0])) < 1) { 112*0Sstevel@tonic-gate prof->res1 = nullstring; 113*0Sstevel@tonic-gate } else { 114*0Sstevel@tonic-gate prof->res1 = buffer; 115*0Sstevel@tonic-gate buffer += len + 1; 116*0Sstevel@tonic-gate if (buffer >= ceiling) { 117*0Sstevel@tonic-gate nss_result = (int)NSS_STR_PARSE_ERANGE; 118*0Sstevel@tonic-gate goto result_prof2ent; 119*0Sstevel@tonic-gate } 120*0Sstevel@tonic-gate (void) strcpy(prof->res1, 121*0Sstevel@tonic-gate attrptr->attrvalue[0]); 122*0Sstevel@tonic-gate } 123*0Sstevel@tonic-gate continue; 124*0Sstevel@tonic-gate } 125*0Sstevel@tonic-gate if (strcasecmp(attrptr->attrname, _PROF_RES2) == 0) { 126*0Sstevel@tonic-gate if ((attrptr->attrvalue[0] == NULL) || 127*0Sstevel@tonic-gate (len = strlen(attrptr->attrvalue[0])) < 1) { 128*0Sstevel@tonic-gate prof->res2 = nullstring; 129*0Sstevel@tonic-gate } else { 130*0Sstevel@tonic-gate prof->res2 = buffer; 131*0Sstevel@tonic-gate buffer += len + 1; 132*0Sstevel@tonic-gate if (buffer >= ceiling) { 133*0Sstevel@tonic-gate nss_result = (int)NSS_STR_PARSE_ERANGE; 134*0Sstevel@tonic-gate goto result_prof2ent; 135*0Sstevel@tonic-gate } 136*0Sstevel@tonic-gate (void) strcpy(prof->res2, 137*0Sstevel@tonic-gate attrptr->attrvalue[0]); 138*0Sstevel@tonic-gate } 139*0Sstevel@tonic-gate continue; 140*0Sstevel@tonic-gate } 141*0Sstevel@tonic-gate if (strcasecmp(attrptr->attrname, _PROF_DESC) == 0) { 142*0Sstevel@tonic-gate if ((attrptr->attrvalue[0] == NULL) || 143*0Sstevel@tonic-gate (len = strlen(attrptr->attrvalue[0])) < 1) { 144*0Sstevel@tonic-gate prof->desc = nullstring; 145*0Sstevel@tonic-gate } else { 146*0Sstevel@tonic-gate prof->desc = buffer; 147*0Sstevel@tonic-gate buffer += len + 1; 148*0Sstevel@tonic-gate if (buffer >= ceiling) { 149*0Sstevel@tonic-gate nss_result = (int)NSS_STR_PARSE_ERANGE; 150*0Sstevel@tonic-gate goto result_prof2ent; 151*0Sstevel@tonic-gate } 152*0Sstevel@tonic-gate (void) strcpy(prof->desc, 153*0Sstevel@tonic-gate attrptr->attrvalue[0]); 154*0Sstevel@tonic-gate } 155*0Sstevel@tonic-gate continue; 156*0Sstevel@tonic-gate } 157*0Sstevel@tonic-gate if (strcasecmp(attrptr->attrname, _PROF_ATTRS) == 0) { 158*0Sstevel@tonic-gate if ((attrptr->attrvalue[0] == NULL) || 159*0Sstevel@tonic-gate (len = strlen(attrptr->attrvalue[0])) < 1) { 160*0Sstevel@tonic-gate prof->attr = nullstring; 161*0Sstevel@tonic-gate } else { 162*0Sstevel@tonic-gate prof->attr = buffer; 163*0Sstevel@tonic-gate buffer += len + 1; 164*0Sstevel@tonic-gate if (buffer >= ceiling) { 165*0Sstevel@tonic-gate nss_result = (int)NSS_STR_PARSE_ERANGE; 166*0Sstevel@tonic-gate goto result_prof2ent; 167*0Sstevel@tonic-gate } 168*0Sstevel@tonic-gate (void) strcpy(prof->attr, 169*0Sstevel@tonic-gate attrptr->attrvalue[0]); 170*0Sstevel@tonic-gate } 171*0Sstevel@tonic-gate continue; 172*0Sstevel@tonic-gate } 173*0Sstevel@tonic-gate } 174*0Sstevel@tonic-gate 175*0Sstevel@tonic-gate #ifdef DEBUG 176*0Sstevel@tonic-gate (void) fprintf(stdout, "\n[getprofattr.c: _nss_ldap_prof2ent]\n"); 177*0Sstevel@tonic-gate (void) fprintf(stdout, " prof-name: [%s]\n", prof->name); 178*0Sstevel@tonic-gate if (prof->res1 != (char *)NULL) { 179*0Sstevel@tonic-gate (void) fprintf(stdout, " res1: [%s]\n", prof->res1); 180*0Sstevel@tonic-gate } 181*0Sstevel@tonic-gate if (prof->res2 != (char *)NULL) { 182*0Sstevel@tonic-gate (void) fprintf(stdout, " res2: [%s]\n", prof->res2); 183*0Sstevel@tonic-gate } 184*0Sstevel@tonic-gate if (prof->desc != (char *)NULL) { 185*0Sstevel@tonic-gate (void) fprintf(stdout, " desc: [%s]\n", prof->desc); 186*0Sstevel@tonic-gate } 187*0Sstevel@tonic-gate if (prof->attr != (char *)NULL) { 188*0Sstevel@tonic-gate (void) fprintf(stdout, " attr: [%s]\n", prof->attr); 189*0Sstevel@tonic-gate } 190*0Sstevel@tonic-gate #endif /* DEBUG */ 191*0Sstevel@tonic-gate 192*0Sstevel@tonic-gate result_prof2ent: 193*0Sstevel@tonic-gate (void) __ns_ldap_freeResult(&be->result); 194*0Sstevel@tonic-gate return ((int)nss_result); 195*0Sstevel@tonic-gate } 196*0Sstevel@tonic-gate 197*0Sstevel@tonic-gate 198*0Sstevel@tonic-gate static nss_status_t 199*0Sstevel@tonic-gate getbyname(ldap_backend_ptr be, void *a) 200*0Sstevel@tonic-gate { 201*0Sstevel@tonic-gate char searchfilter[SEARCHFILTERLEN]; 202*0Sstevel@tonic-gate char userdata[SEARCHFILTERLEN]; 203*0Sstevel@tonic-gate char name[SEARCHFILTERLEN]; 204*0Sstevel@tonic-gate int ret; 205*0Sstevel@tonic-gate nss_XbyY_args_t *argp = (nss_XbyY_args_t *)a; 206*0Sstevel@tonic-gate 207*0Sstevel@tonic-gate #ifdef DEBUG 208*0Sstevel@tonic-gate (void) fprintf(stdout, "\n[getprofattr.c: getbyname]\n"); 209*0Sstevel@tonic-gate #endif /* DEBUG */ 210*0Sstevel@tonic-gate 211*0Sstevel@tonic-gate if (_ldap_filter_name(name, argp->key.name, sizeof (name)) != 0) 212*0Sstevel@tonic-gate return ((nss_status_t)NSS_NOTFOUND); 213*0Sstevel@tonic-gate 214*0Sstevel@tonic-gate ret = snprintf(searchfilter, sizeof (searchfilter), 215*0Sstevel@tonic-gate _PROF_GETPROFNAME, name); 216*0Sstevel@tonic-gate if (ret < 0 || ret >= sizeof (searchfilter)) 217*0Sstevel@tonic-gate return ((nss_status_t)NSS_NOTFOUND); 218*0Sstevel@tonic-gate 219*0Sstevel@tonic-gate ret = snprintf(userdata, sizeof (userdata), 220*0Sstevel@tonic-gate _PROF_GETPROFNAME_SSD, name); 221*0Sstevel@tonic-gate if (ret < 0 || ret >= sizeof (userdata)) 222*0Sstevel@tonic-gate return ((nss_status_t)NSS_NOTFOUND); 223*0Sstevel@tonic-gate 224*0Sstevel@tonic-gate return (_nss_ldap_lookup(be, argp, 225*0Sstevel@tonic-gate _PROFATTR, searchfilter, NULL, _merge_SSD_filter, userdata)); 226*0Sstevel@tonic-gate } 227*0Sstevel@tonic-gate 228*0Sstevel@tonic-gate 229*0Sstevel@tonic-gate static ldap_backend_op_t profattr_ops[] = { 230*0Sstevel@tonic-gate _nss_ldap_destr, 231*0Sstevel@tonic-gate _nss_ldap_endent, 232*0Sstevel@tonic-gate _nss_ldap_setent, 233*0Sstevel@tonic-gate _nss_ldap_getent, 234*0Sstevel@tonic-gate getbyname 235*0Sstevel@tonic-gate }; 236*0Sstevel@tonic-gate 237*0Sstevel@tonic-gate 238*0Sstevel@tonic-gate /*ARGSUSED0*/ 239*0Sstevel@tonic-gate nss_backend_t * 240*0Sstevel@tonic-gate _nss_ldap_prof_attr_constr(const char *dummy1, 241*0Sstevel@tonic-gate const char *dummy2, 242*0Sstevel@tonic-gate const char *dummy3, 243*0Sstevel@tonic-gate const char *dummy4, 244*0Sstevel@tonic-gate const char *dummy5) 245*0Sstevel@tonic-gate { 246*0Sstevel@tonic-gate #ifdef DEBUG 247*0Sstevel@tonic-gate (void) fprintf(stdout, 248*0Sstevel@tonic-gate "\n[getprofattr.c: _nss_ldap_prof_attr_constr]\n"); 249*0Sstevel@tonic-gate #endif 250*0Sstevel@tonic-gate return ((nss_backend_t *)_nss_ldap_constr(profattr_ops, 251*0Sstevel@tonic-gate sizeof (profattr_ops)/sizeof (profattr_ops[0]), _PROFATTR, 252*0Sstevel@tonic-gate prof_attrs, _nss_ldap_prof2ent)); 253*0Sstevel@tonic-gate } 254