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 <user_attr.h>
2N/A#include "ldap_common.h"
2N/A
2N/A
2N/A/* user_attr attributes filters */
2N/A#define _USER_NAME "uid"
2N/A#define _USER_QUALIFIER "SolarisUserQualifier"
2N/A#define _USER_RES1 "SolarisAttrReserved1"
2N/A#define _USER_RES2 "SolarisAttrReserved2"
2N/A#define _USER_ATTRS "SolarisAttrKeyValue"
2N/A#define _USER_GETUSERNAME \
2N/A "(&(objectClass=SolarisUserAttr)(uid=%s))"
2N/A#define _USER_GETUSERNAME_SSD "(&(%%s)(uid=%s))"
2N/A
2N/A
2N/Astatic const char *user_attrs[] = {
2N/A _USER_NAME,
2N/A _USER_QUALIFIER,
2N/A _USER_RES1,
2N/A _USER_RES2,
2N/A _USER_ATTRS,
2N/A (char *)NULL
2N/A};
2N/A/*
2N/A * _nss_ldap_user2str is the data marshaling method for the user_attr
2N/A * system call getuserattr, getusernam and getuseruid.
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 * adm::::profiles=Log Management
2N/A *
2N/A */
2N/Astatic int
2N/A_nss_ldap_user2str(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, **qu, **attr;
2N/A char *res1_str, *res2_str, *qu_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, _USER_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_user2str;
2N/A }
2N/A
2N/A qu = __ns_ldap_getAttr(result->entry, _USER_QUALIFIER);
2N/A if (qu == NULL || qu[0] == NULL || (strlen(qu[0]) < 1))
2N/A qu_str = _NO_VALUE;
2N/A else
2N/A qu_str = qu[0];
2N/A
2N/A res1 = __ns_ldap_getAttr(result->entry, _USER_RES2);
2N/A if (res1 == NULL || res1[0] == NULL || (strlen(res1[0]) < 1))
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, _USER_RES2);
2N/A if (res2 == NULL || res2[0] == NULL || (strlen(res2[0]) < 1))
2N/A res2_str = _NO_VALUE;
2N/A else
2N/A res2_str = res2[0];
2N/A
2N/A attr = __ns_ldap_getAttr(result->entry, _USER_ATTRS);
2N/A if (attr == NULL || attr[0] == NULL || (strlen(attr[0]) < 1))
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(qu_str) + strlen(attr_str) + 5;
2N/A if (len > buflen) {
2N/A nss_result = NSS_STR_PARSE_ERANGE;
2N/A goto result_user2str;
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_user2str;
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], qu_str, res1_str, res2_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_user2str:
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 nss_XbyY_args_t *argp = (nss_XbyY_args_t *)a;
2N/A char searchfilter[SEARCHFILTERLEN];
2N/A char userdata[SEARCHFILTERLEN];
2N/A char name[SEARCHFILTERLEN];
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 _USER_GETUSERNAME, name);
2N/A if (ret >= sizeof (userdata) || ret < 0)
2N/A return ((nss_status_t)NSS_NOTFOUND);
2N/A
2N/A ret = snprintf(userdata, sizeof (userdata),
2N/A _USER_GETUSERNAME_SSD, name);
2N/A if (ret >= sizeof (userdata) || ret < 0)
2N/A return ((nss_status_t)NSS_NOTFOUND);
2N/A
2N/A return ((nss_status_t)_nss_ldap_lookup(be, argp,
2N/A _USERATTR, searchfilter, NULL, _merge_SSD_filter, userdata));
2N/A}
2N/A
2N/A
2N/Astatic ldap_backend_op_t userattr_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_user_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(userattr_ops,
2N/A sizeof (userattr_ops)/sizeof (userattr_ops[0]), _USERATTR,
2N/A user_attrs, _nss_ldap_user2str));
2N/A}