4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #pragma ident "%Z%%M% %I% %E% SMI"
29 * Routines to handle getexec* calls in nscd
33 #include <exec_attr.h>
36 static int execattr_compar(const void *, const void *);
37 static uint_t
execattr_gethash(nss_XbyY_key_t
*, int);
38 static void execattr_getlogstr(char *, char *, size_t, nss_XbyY_args_t
*);
40 #define nam_db ctx->nsc_db[0]
41 #define id_db ctx->nsc_db[1]
42 #define nam_id_db ctx->nsc_db[2]
43 #define NSC_NAME_EXECATTR_BYNAME "execattr_byname"
44 #define NSC_NAME_EXECATTR_BYID "execattr_byid"
45 #define NSC_NAME_EXECATTR_BYNAMEID "execattr_bynameid"
48 exec_init_ctx(nsc_ctx_t
*ctx
) {
49 ctx
->dbname
= NSS_DBNAM_EXECATTR
;
50 ctx
->file_name
= "/etc/security/exec_attr";
52 nam_db
= make_cache(nsc_key_other
,
53 NSS_DBOP_EXECATTR_BYNAME
,
54 NSC_NAME_EXECATTR_BYNAME
,
57 execattr_gethash
, nsc_ht_default
, -1);
58 id_db
= make_cache(nsc_key_other
,
59 NSS_DBOP_EXECATTR_BYID
,
60 NSC_NAME_EXECATTR_BYID
,
63 execattr_gethash
, nsc_ht_default
, -1);
64 nam_id_db
= make_cache(nsc_key_other
,
65 NSS_DBOP_EXECATTR_BYNAMEID
,
66 NSC_NAME_EXECATTR_BYNAMEID
,
69 execattr_gethash
, nsc_ht_default
, -1);
72 #define EXEC_STR_CMP(s1, s2) \
73 if ((a = s1) == NULL) \
75 if ((b = s2) == NULL) \
79 return (res > 0 ? 1 : -1);
82 execattr_compar(const void *n1
, const void *n2
) {
83 nsc_entry_t
*e1
= (nsc_entry_t
*)n1
;
84 nsc_entry_t
*e2
= (nsc_entry_t
*)n2
;
85 _priv_execattr
*ep1
= (_priv_execattr
*)e1
->key
.attrp
;
86 _priv_execattr
*ep2
= (_priv_execattr
*)e2
->key
.attrp
;
88 const char *a
, *b
, *z
= "";
91 EXEC_STR_CMP(ep1
->name
, ep2
->name
);
94 EXEC_STR_CMP(ep1
->policy
, ep2
->policy
);
97 EXEC_STR_CMP(ep1
->type
, ep2
->type
);
100 EXEC_STR_CMP(ep1
->id
, ep2
->id
);
102 /* compare search flag */
103 return (_NSC_INT_KEY_CMP(ep1
->search_flag
, ep2
->search_flag
));
107 execattr_gethash(nss_XbyY_key_t
*key
, int htsize
) {
108 _priv_execattr
*ep
= key
->attrp
;
112 len
= snprintf(keys
, sizeof (keys
), "%s:%s:%s:%s:%d",
113 ep
->name
? ep
->name
: "", ep
->type
? ep
->type
: "",
114 ep
->id
? ep
->id
: "", ep
->policy
? ep
->policy
: "",
116 return (db_gethash(keys
, len
, htsize
));
120 execattr_getlogstr(char *name
, char *whoami
, size_t len
,
121 nss_XbyY_args_t
*argp
) {
122 _priv_execattr
*ep
= argp
->key
.attrp
;
124 (void) snprintf(whoami
, len
,
125 "%s [name=%s:type=%s:id=%s:policy=%s:flags=%d]",
126 name
, check_null(ep
->name
), check_null(ep
->type
),
127 check_null(ep
->id
), check_null(ep
->policy
),