cb5caa98562cf06753163f558cbcfe30b8f4673adjl/*
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * CDDL HEADER START
cb5caa98562cf06753163f558cbcfe30b8f4673adjl *
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * The contents of this file are subject to the terms of the
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * Common Development and Distribution License (the "License").
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * You may not use this file except in compliance with the License.
cb5caa98562cf06753163f558cbcfe30b8f4673adjl *
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * or http://www.opensolaris.org/os/licensing.
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * See the License for the specific language governing permissions
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * and limitations under the License.
cb5caa98562cf06753163f558cbcfe30b8f4673adjl *
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * When distributing Covered Code, include this CDDL HEADER in each
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * If applicable, add the following below this CDDL HEADER, with the
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * fields enclosed by brackets "[]" replaced with your own identifying
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * information: Portions Copyright [yyyy] [name of copyright owner]
cb5caa98562cf06753163f558cbcfe30b8f4673adjl *
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * CDDL HEADER END
cb5caa98562cf06753163f558cbcfe30b8f4673adjl */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl/*
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * Use is subject to license terms.
cb5caa98562cf06753163f558cbcfe30b8f4673adjl */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl#pragma ident "%Z%%M% %I% %E% SMI"
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl/*
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * Routines to handle getproj* calls in nscd
cb5caa98562cf06753163f558cbcfe30b8f4673adjl */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl#include <stdlib.h>
cb5caa98562cf06753163f558cbcfe30b8f4673adjl#include "cache.h"
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl#define nam_db ctx->nsc_db[0]
cb5caa98562cf06753163f558cbcfe30b8f4673adjl#define pid_db ctx->nsc_db[1]
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl#define NSC_NAME_PROJECT_BYNAME "getprojbyname"
cb5caa98562cf06753163f558cbcfe30b8f4673adjl#define NSC_NAME_PROJECT_BYID "getprojbyid"
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjlstatic void projid_getlogstr(char *, char *, size_t, nss_XbyY_args_t *);
cb5caa98562cf06753163f558cbcfe30b8f4673adjlstatic int projid_compar(const void *, const void *);
cb5caa98562cf06753163f558cbcfe30b8f4673adjlstatic uint_t projid_gethash(nss_XbyY_key_t *, int);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjlvoid
cb5caa98562cf06753163f558cbcfe30b8f4673adjlproject_init_ctx(nsc_ctx_t *ctx) {
cb5caa98562cf06753163f558cbcfe30b8f4673adjl ctx->dbname = NSS_DBNAM_PROJECT;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl ctx->file_name = "/etc/project";
cb5caa98562cf06753163f558cbcfe30b8f4673adjl ctx->db_count = 2;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl nam_db = make_cache(nsc_key_ces,
cb5caa98562cf06753163f558cbcfe30b8f4673adjl NSS_DBOP_PROJECT_BYNAME,
cb5caa98562cf06753163f558cbcfe30b8f4673adjl NSC_NAME_PROJECT_BYNAME,
cb5caa98562cf06753163f558cbcfe30b8f4673adjl NULL, NULL, NULL, nsc_ht_default, -1);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl pid_db = make_cache(nsc_key_other,
cb5caa98562cf06753163f558cbcfe30b8f4673adjl NSS_DBOP_PROJECT_BYID,
cb5caa98562cf06753163f558cbcfe30b8f4673adjl NSC_NAME_PROJECT_BYID,
cb5caa98562cf06753163f558cbcfe30b8f4673adjl projid_compar,
cb5caa98562cf06753163f558cbcfe30b8f4673adjl projid_getlogstr,
cb5caa98562cf06753163f558cbcfe30b8f4673adjl projid_gethash, nsc_ht_default, -1);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl}
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjlstatic int
cb5caa98562cf06753163f558cbcfe30b8f4673adjlprojid_compar(const void *n1, const void *n2) {
cb5caa98562cf06753163f558cbcfe30b8f4673adjl nsc_entry_t *e1, *e2;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl e1 = (nsc_entry_t *)n1;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl e2 = (nsc_entry_t *)n2;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl return (_NSC_INT_KEY_CMP(e1->key.projid, e2->key.projid));
cb5caa98562cf06753163f558cbcfe30b8f4673adjl}
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjlstatic uint_t
cb5caa98562cf06753163f558cbcfe30b8f4673adjlprojid_gethash(nss_XbyY_key_t *key, int htsize) {
cb5caa98562cf06753163f558cbcfe30b8f4673adjl return (db_gethash(&key->projid, sizeof (key->projid), htsize));
cb5caa98562cf06753163f558cbcfe30b8f4673adjl}
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjlstatic void
cb5caa98562cf06753163f558cbcfe30b8f4673adjlprojid_getlogstr(char *name, char *whoami, size_t len, nss_XbyY_args_t *argp) {
cb5caa98562cf06753163f558cbcfe30b8f4673adjl (void) snprintf(whoami, len, "%s [key=%d]", name, argp->key.projid);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl}