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 (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
2N/A */
2N/A
2N/A#include <secdb.h>
2N/A#include <prof_attr.h>
2N/A#include "ldap_common.h"
2N/A
2N/A
2N/A/* prof_attr attributes filters */
2N/A#define _PROF_NAME "cn"
2N/A#define _PROF_RES1 "SolarisAttrReserved1"
2N/A#define _PROF_RES2 "SolarisAttrReserved2"
2N/A#define _PROF_DESC "SolarisAttrLongDesc"
2N/A#define _PROF_ATTRS "SolarisAttrKeyValue"
2N/A/* Negate an exec_attr attribute to exclude exec_attr entries */
2N/A#define _PROF_GETPROFNAME \
2N/A"(&(objectClass=SolarisProfAttr)(!(SolarisKernelSecurityPolicy=*))(cn=%s))"
2N/A#define _PROF_GETPROFNAME_SSD "(&(%%s)(cn=%s))"
2N/A
2N/Astatic const char *prof_attrs[] = {
2N/A _PROF_NAME,
2N/A _PROF_RES1,
2N/A _PROF_RES2,
2N/A _PROF_DESC,
2N/A _PROF_ATTRS,
2N/A (char *)NULL
2N/A};
2N/A/*
2N/A * _nss_ldap_prof2str is the data marshaling method for the prof_attr
2N/A * system call getprofattr, getprofnam and getproflist.
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 * All:::Execute any command as the user or role:help=RtAll.html
2N/A *
2N/A */
2N/Astatic int
2N/A_nss_ldap_prof2str(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, **res1, **res2, **des, **attr;
2N/A char *res1_str, *res2_str, *des_str, *attr_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, _PROF_NAME);
2N/A if (name == NULL || name[0] == NULL || *name[0] == '\0') {
2N/A nss_result = NSS_STR_PARSE_PARSE;
2N/A goto result_prof2str;
2N/A }
2N/A res1 = __ns_ldap_getAttr(result->entry, _PROF_RES1);
2N/A if (res1 == NULL || res1[0] == NULL || *res1[0] == '\0')
2N/A res1_str = _NO_VALUE;
2N/A else
2N/A res1_str = res1[0];
2N/A
2N/A res2 = __ns_ldap_getAttr(result->entry, _PROF_RES2);
2N/A if (res2 == NULL || res2[0] == NULL || *res2[0] == '\0')
2N/A res2_str = _NO_VALUE;
2N/A else
2N/A res2_str = res2[0];
2N/A
2N/A des = __ns_ldap_getAttr(result->entry, _PROF_DESC);
2N/A if (des == NULL || des[0] == NULL || *des[0] == '\0')
2N/A des_str = _NO_VALUE;
2N/A else
2N/A des_str = des[0];
2N/A
2N/A attr = __ns_ldap_getAttr(result->entry, _PROF_ATTRS);
2N/A if (attr == NULL || attr[0] == NULL || *attr[0] == '\0')
2N/A attr_str = _NO_VALUE;
2N/A else
2N/A attr_str = attr[0];
2N/A /* 5 = 4 ':' + 1 '\0' */
2N/A len = strlen(name[0]) + strlen(res1_str) + strlen(res2_str) +
2N/A strlen(des_str) + strlen(attr_str) + 6;
2N/A if (len > buflen) {
2N/A nss_result = NSS_STR_PARSE_ERANGE;
2N/A goto result_prof2str;
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_prof2str;
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:%s:%s",
2N/A name[0], res1_str, res2_str, des_str, attr_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_prof2str:
2N/A (void) __ns_ldap_freeResult(&be->result);
2N/A return (nss_result);
2N/A}
2N/A
2N/Aextern nss_status_t __get_default_prof(const char *, nss_XbyY_args_t *);
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 int ret;
2N/A nss_XbyY_args_t *argp = (nss_XbyY_args_t *)a;
2N/A
2N/A if (argp->key.name != NULL && *argp->key.name == '/' &&
2N/A __get_default_prof(argp->key.name, argp) == NSS_SUCCESS) {
2N/A return (NSS_SUCCESS);
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 _PROF_GETPROFNAME, name);
2N/A if (ret < 0 || ret >= sizeof (searchfilter))
2N/A return ((nss_status_t)NSS_NOTFOUND);
2N/A
2N/A ret = snprintf(userdata, sizeof (userdata),
2N/A _PROF_GETPROFNAME_SSD, name);
2N/A if (ret < 0 || ret >= sizeof (userdata))
2N/A return ((nss_status_t)NSS_NOTFOUND);
2N/A
2N/A return (_nss_ldap_lookup(be, argp,
2N/A _PROFATTR, searchfilter, NULL, _merge_SSD_filter, userdata));
2N/A}
2N/A
2N/A
2N/Astatic ldap_backend_op_t profattr_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_prof_attr_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(profattr_ops,
2N/A sizeof (profattr_ops)/sizeof (profattr_ops[0]), _PROFATTR,
2N/A prof_attrs, _nss_ldap_prof2str));
2N/A}