2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License (the "License").
2N/A * You may not use this file except in compliance with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A/*
2N/A * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
2N/A * Use is subject to license terms.
2N/A */
2N/A
2N/A#pragma ident "%Z%%M% %I% %E% SMI"
2N/A
2N/A#include <secdb.h>
2N/A#include "ldap_common.h"
2N/A#include <bsm/libbsm.h>
2N/A
2N/A
2N/A/* audit_user attributes */
2N/A#define _AU_NAME "uid"
2N/A#define _AU_ALWAYS "SolarisAuditAlways"
2N/A#define _AU_NEVER "SolarisAuditNever"
2N/A#define _AU_GETAUUSERNAME "(&(objectClass=SolarisAuditUser)(uid=%s))"
2N/A#define _AU_GETAUUSERNAME_SSD "(&(%%s)(uid=%s))"
2N/A
2N/A
2N/Astatic const char *auuser_attrs[] = {
2N/A _AU_NAME,
2N/A _AU_ALWAYS,
2N/A _AU_NEVER,
2N/A (char *)NULL
2N/A};
2N/A/*
2N/A * _nss_ldap_au2str is the data marshaling method for the audit_user
2N/A * system call getauusernam, getauusernam_r, getauuserent and getauuserent_r.
2N/A * This method is called after a successful search has been performed.
2N/A * This method will parse the search results into the file format.
2N/A * e.g.
2N/A *
2N/A * root:lo:no
2N/A *
2N/A */
2N/Astatic int
2N/A_nss_ldap_au2str(ldap_backend_ptr be, nss_XbyY_args_t *argp)
2N/A{
2N/A int nss_result;
2N/A int buflen = 0;
2N/A unsigned long len = 0L;
2N/A char *buffer = NULL;
2N/A ns_ldap_result_t *result = be->result;
2N/A char **name, **al, **ne, *al_str, *ne_str;
2N/A
2N/A if (result == NULL)
2N/A return (NSS_STR_PARSE_PARSE);
2N/A
2N/A buflen = argp->buf.buflen;
2N/A nss_result = NSS_STR_PARSE_SUCCESS;
2N/A (void) memset(argp->buf.buffer, 0, buflen);
2N/A
2N/A name = __ns_ldap_getAttr(result->entry, _AU_NAME);
2N/A if (name == NULL || name[0] == NULL ||
2N/A (strlen(name[0]) < 1)) {
2N/A nss_result = NSS_STR_PARSE_PARSE;
2N/A goto result_au2str;
2N/A }
2N/A al = __ns_ldap_getAttr(result->entry, _AU_ALWAYS);
2N/A if (al == NULL || al[0] == NULL || (strlen(al[0]) < 1))
2N/A al_str = _NO_VALUE;
2N/A else
2N/A al_str = al[0];
2N/A
2N/A ne = __ns_ldap_getAttr(result->entry, _AU_NEVER);
2N/A if (ne == NULL || ne[0] == NULL || (strlen(ne[0]) < 1))
2N/A ne_str = _NO_VALUE;
2N/A else
2N/A ne_str = ne[0];
2N/A
2N/A /* 3 = 2 ':' + 1 '\0' */
2N/A len = strlen(name[0]) + strlen(al_str) + strlen(ne_str) + 3;
2N/A if (len > buflen) {
2N/A nss_result = NSS_STR_PARSE_ERANGE;
2N/A goto result_au2str;
2N/A }
2N/A
2N/A if (argp->buf.result != NULL) {
2N/A if ((be->buffer = calloc(1, len)) == NULL) {
2N/A nss_result = NSS_STR_PARSE_PARSE;
2N/A goto result_au2str;
2N/A }
2N/A buffer = be->buffer;
2N/A } else
2N/A buffer = argp->buf.buffer;
2N/A (void) snprintf(buffer, len, "%s:%s:%s",
2N/A name[0], al_str, ne_str);
2N/A /* The front end marshaller doesn't need the trailing null */
2N/A if (argp->buf.result != NULL)
2N/A be->buflen = strlen(be->buffer);
2N/A
2N/Aresult_au2str:
2N/A (void) __ns_ldap_freeResult(&be->result);
2N/A return ((int)nss_result);
2N/A}
2N/A
2N/A
2N/Astatic nss_status_t
2N/Agetbyname(ldap_backend_ptr be, void *a)
2N/A{
2N/A char searchfilter[SEARCHFILTERLEN];
2N/A char userdata[SEARCHFILTERLEN];
2N/A char name[SEARCHFILTERLEN];
2N/A nss_XbyY_args_t *argp = (nss_XbyY_args_t *)a;
2N/A int ret;
2N/A
2N/A if (_ldap_filter_name(name, argp->key.name, sizeof (name)) != 0)
2N/A return ((nss_status_t)NSS_NOTFOUND);
2N/A
2N/A ret = snprintf(searchfilter, sizeof (searchfilter),
2N/A _AU_GETAUUSERNAME, name);
2N/A
2N/A if (ret >= sizeof (searchfilter) || ret < 0)
2N/A return ((nss_status_t)NSS_NOTFOUND);
2N/A
2N/A ret = snprintf(userdata, sizeof (userdata),
2N/A _AU_GETAUUSERNAME_SSD, name);
2N/A
2N/A if (ret >= sizeof (userdata) || ret < 0)
2N/A return ((nss_status_t)NSS_NOTFOUND);
2N/A
2N/A return (_nss_ldap_lookup(be, argp, _AUUSER, searchfilter, NULL,
2N/A _merge_SSD_filter, userdata));
2N/A}
2N/A
2N/A
2N/Astatic ldap_backend_op_t auuser_ops[] = {
2N/A _nss_ldap_destr,
2N/A _nss_ldap_endent,
2N/A _nss_ldap_setent,
2N/A _nss_ldap_getent,
2N/A getbyname
2N/A};
2N/A
2N/A
2N/A/*ARGSUSED0*/
2N/Anss_backend_t *
2N/A_nss_ldap_audit_user_constr(const char *dummy1,
2N/A const char *dummy2,
2N/A const char *dummy3,
2N/A const char *dummy4,
2N/A const char *dummy5)
2N/A{
2N/A return ((nss_backend_t *)_nss_ldap_constr(auuser_ops,
2N/A sizeof (auuser_ops)/sizeof (auuser_ops[0]), _AUUSER,
2N/A auuser_attrs, _nss_ldap_au2str));
2N/A}