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 "ldap_common.h"
307c478bd9Sstevel@tonic-gate #include <bsm/libbsm.h>
317c478bd9Sstevel@tonic-gate
327c478bd9Sstevel@tonic-gate
337c478bd9Sstevel@tonic-gate /* audit_user attributes */
347c478bd9Sstevel@tonic-gate #define _AU_NAME "uid"
357c478bd9Sstevel@tonic-gate #define _AU_ALWAYS "SolarisAuditAlways"
367c478bd9Sstevel@tonic-gate #define _AU_NEVER "SolarisAuditNever"
377c478bd9Sstevel@tonic-gate #define _AU_GETAUUSERNAME "(&(objectClass=SolarisAuditUser)(uid=%s))"
387c478bd9Sstevel@tonic-gate #define _AU_GETAUUSERNAME_SSD "(&(%%s)(uid=%s))"
397c478bd9Sstevel@tonic-gate
407c478bd9Sstevel@tonic-gate
417c478bd9Sstevel@tonic-gate static const char *auuser_attrs[] = {
427c478bd9Sstevel@tonic-gate _AU_NAME,
437c478bd9Sstevel@tonic-gate _AU_ALWAYS,
447c478bd9Sstevel@tonic-gate _AU_NEVER,
457c478bd9Sstevel@tonic-gate (char *)NULL
467c478bd9Sstevel@tonic-gate };
47*cb5caa98Sdjl /*
48*cb5caa98Sdjl * _nss_ldap_au2str is the data marshaling method for the audit_user
49*cb5caa98Sdjl * system call getauusernam, getauusernam_r, getauuserent and getauuserent_r.
50*cb5caa98Sdjl * This method is called after a successful search has been performed.
51*cb5caa98Sdjl * This method will parse the search results into the file format.
52*cb5caa98Sdjl * e.g.
53*cb5caa98Sdjl *
54*cb5caa98Sdjl * root:lo:no
55*cb5caa98Sdjl *
56*cb5caa98Sdjl */
577c478bd9Sstevel@tonic-gate static int
_nss_ldap_au2str(ldap_backend_ptr be,nss_XbyY_args_t * argp)58*cb5caa98Sdjl _nss_ldap_au2str(ldap_backend_ptr be, nss_XbyY_args_t *argp)
597c478bd9Sstevel@tonic-gate {
60*cb5caa98Sdjl int nss_result;
61*cb5caa98Sdjl int buflen = 0;
627c478bd9Sstevel@tonic-gate unsigned long len = 0L;
63*cb5caa98Sdjl char *buffer = NULL;
647c478bd9Sstevel@tonic-gate ns_ldap_result_t *result = be->result;
65*cb5caa98Sdjl char **name, **al, **ne, *al_str, *ne_str;
667c478bd9Sstevel@tonic-gate
67*cb5caa98Sdjl if (result == NULL)
68*cb5caa98Sdjl return (NSS_STR_PARSE_PARSE);
69*cb5caa98Sdjl
70*cb5caa98Sdjl buflen = argp->buf.buflen;
71*cb5caa98Sdjl nss_result = NSS_STR_PARSE_SUCCESS;
727c478bd9Sstevel@tonic-gate (void) memset(argp->buf.buffer, 0, buflen);
737c478bd9Sstevel@tonic-gate
74*cb5caa98Sdjl name = __ns_ldap_getAttr(result->entry, _AU_NAME);
75*cb5caa98Sdjl if (name == NULL || name[0] == NULL ||
76*cb5caa98Sdjl (strlen(name[0]) < 1)) {
77*cb5caa98Sdjl nss_result = NSS_STR_PARSE_PARSE;
78*cb5caa98Sdjl goto result_au2str;
797c478bd9Sstevel@tonic-gate }
80*cb5caa98Sdjl al = __ns_ldap_getAttr(result->entry, _AU_ALWAYS);
81*cb5caa98Sdjl if (al == NULL || al[0] == NULL || (strlen(al[0]) < 1))
82*cb5caa98Sdjl al_str = _NO_VALUE;
83*cb5caa98Sdjl else
84*cb5caa98Sdjl al_str = al[0];
85*cb5caa98Sdjl
86*cb5caa98Sdjl ne = __ns_ldap_getAttr(result->entry, _AU_NEVER);
87*cb5caa98Sdjl if (ne == NULL || ne[0] == NULL || (strlen(ne[0]) < 1))
88*cb5caa98Sdjl ne_str = _NO_VALUE;
89*cb5caa98Sdjl else
90*cb5caa98Sdjl ne_str = ne[0];
91*cb5caa98Sdjl
92*cb5caa98Sdjl /* 3 = 2 ':' + 1 '\0' */
93*cb5caa98Sdjl len = strlen(name[0]) + strlen(al_str) + strlen(ne_str) + 3;
94*cb5caa98Sdjl if (len > buflen) {
95*cb5caa98Sdjl nss_result = NSS_STR_PARSE_ERANGE;
96*cb5caa98Sdjl goto result_au2str;
977c478bd9Sstevel@tonic-gate }
987c478bd9Sstevel@tonic-gate
99*cb5caa98Sdjl if (argp->buf.result != NULL) {
100*cb5caa98Sdjl if ((be->buffer = calloc(1, len)) == NULL) {
101*cb5caa98Sdjl nss_result = NSS_STR_PARSE_PARSE;
102*cb5caa98Sdjl goto result_au2str;
1037c478bd9Sstevel@tonic-gate }
104*cb5caa98Sdjl buffer = be->buffer;
105*cb5caa98Sdjl } else
106*cb5caa98Sdjl buffer = argp->buf.buffer;
107*cb5caa98Sdjl (void) snprintf(buffer, len, "%s:%s:%s",
108*cb5caa98Sdjl name[0], al_str, ne_str);
109*cb5caa98Sdjl /* The front end marshaller doesn't need the trailing null */
110*cb5caa98Sdjl if (argp->buf.result != NULL)
111*cb5caa98Sdjl be->buflen = strlen(be->buffer);
1127c478bd9Sstevel@tonic-gate
113*cb5caa98Sdjl result_au2str:
1147c478bd9Sstevel@tonic-gate (void) __ns_ldap_freeResult(&be->result);
1157c478bd9Sstevel@tonic-gate return ((int)nss_result);
1167c478bd9Sstevel@tonic-gate }
1177c478bd9Sstevel@tonic-gate
1187c478bd9Sstevel@tonic-gate
1197c478bd9Sstevel@tonic-gate static nss_status_t
getbyname(ldap_backend_ptr be,void * a)1207c478bd9Sstevel@tonic-gate getbyname(ldap_backend_ptr be, void *a)
1217c478bd9Sstevel@tonic-gate {
1227c478bd9Sstevel@tonic-gate char searchfilter[SEARCHFILTERLEN];
1237c478bd9Sstevel@tonic-gate char userdata[SEARCHFILTERLEN];
1247c478bd9Sstevel@tonic-gate char name[SEARCHFILTERLEN];
1257c478bd9Sstevel@tonic-gate nss_XbyY_args_t *argp = (nss_XbyY_args_t *)a;
1267c478bd9Sstevel@tonic-gate int ret;
1277c478bd9Sstevel@tonic-gate
1287c478bd9Sstevel@tonic-gate if (_ldap_filter_name(name, argp->key.name, sizeof (name)) != 0)
1297c478bd9Sstevel@tonic-gate return ((nss_status_t)NSS_NOTFOUND);
1307c478bd9Sstevel@tonic-gate
1317c478bd9Sstevel@tonic-gate ret = snprintf(searchfilter, sizeof (searchfilter),
1327c478bd9Sstevel@tonic-gate _AU_GETAUUSERNAME, name);
1337c478bd9Sstevel@tonic-gate
1347c478bd9Sstevel@tonic-gate if (ret >= sizeof (searchfilter) || ret < 0)
1357c478bd9Sstevel@tonic-gate return ((nss_status_t)NSS_NOTFOUND);
1367c478bd9Sstevel@tonic-gate
1377c478bd9Sstevel@tonic-gate ret = snprintf(userdata, sizeof (userdata),
1387c478bd9Sstevel@tonic-gate _AU_GETAUUSERNAME_SSD, name);
1397c478bd9Sstevel@tonic-gate
1407c478bd9Sstevel@tonic-gate if (ret >= sizeof (userdata) || ret < 0)
1417c478bd9Sstevel@tonic-gate return ((nss_status_t)NSS_NOTFOUND);
1427c478bd9Sstevel@tonic-gate
1437c478bd9Sstevel@tonic-gate return (_nss_ldap_lookup(be, argp, _AUUSER, searchfilter, NULL,
1447c478bd9Sstevel@tonic-gate _merge_SSD_filter, userdata));
1457c478bd9Sstevel@tonic-gate }
1467c478bd9Sstevel@tonic-gate
1477c478bd9Sstevel@tonic-gate
1487c478bd9Sstevel@tonic-gate static ldap_backend_op_t auuser_ops[] = {
1497c478bd9Sstevel@tonic-gate _nss_ldap_destr,
1507c478bd9Sstevel@tonic-gate _nss_ldap_endent,
1517c478bd9Sstevel@tonic-gate _nss_ldap_setent,
1527c478bd9Sstevel@tonic-gate _nss_ldap_getent,
1537c478bd9Sstevel@tonic-gate getbyname
1547c478bd9Sstevel@tonic-gate };
1557c478bd9Sstevel@tonic-gate
1567c478bd9Sstevel@tonic-gate
1577c478bd9Sstevel@tonic-gate /*ARGSUSED0*/
1587c478bd9Sstevel@tonic-gate nss_backend_t *
_nss_ldap_audit_user_constr(const char * dummy1,const char * dummy2,const char * dummy3,const char * dummy4,const char * dummy5)1597c478bd9Sstevel@tonic-gate _nss_ldap_audit_user_constr(const char *dummy1,
1607c478bd9Sstevel@tonic-gate const char *dummy2,
1617c478bd9Sstevel@tonic-gate const char *dummy3,
1627c478bd9Sstevel@tonic-gate const char *dummy4,
1637c478bd9Sstevel@tonic-gate const char *dummy5)
1647c478bd9Sstevel@tonic-gate {
1657c478bd9Sstevel@tonic-gate return ((nss_backend_t *)_nss_ldap_constr(auuser_ops,
1667c478bd9Sstevel@tonic-gate sizeof (auuser_ops)/sizeof (auuser_ops[0]), _AUUSER,
167*cb5caa98Sdjl auuser_attrs, _nss_ldap_au2str));
1687c478bd9Sstevel@tonic-gate }
169