xref: /illumos-gate/usr/src/lib/nsswitch/compat/common/getauuser.c (revision 8119dad84d6416f13557b0ba8e2aaf9064cbcfd3)
1 /*
2  * CDDL HEADER START
3  *
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.
7  *
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.
12  *
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]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #include <sys/types.h>
27 #include <stdlib.h>
28 #include <string.h>
29 #include <bsm/libbsm.h>
30 #include "compat_common.h"
31 
32 static DEFINE_NSS_DB_ROOT(db_root);
33 
34 static void
35 _nss_initf_auuser_compat(nss_db_params_t *p)
36 {
37 	p->name = NSS_DBNAM_AUDITUSER;
38 	p->config_name = NSS_DBNAM_PASSWD_COMPAT;
39 	p->default_config = NSS_DEFCONF_PASSWD_COMPAT;
40 }
41 
42 static const char *
43 get_auname(nss_XbyY_args_t *argp)
44 {
45 	au_user_str_t *au_user = (au_user_str_t *)argp->returnval;
46 
47 	return (au_user->au_name);
48 }
49 
50 static int
51 check_name(nss_XbyY_args_t *argp)
52 {
53 	au_user_str_t	*au_user = (au_user_str_t *)argp->returnval;
54 	const char	*name = argp->key.name;
55 
56 #ifdef	DEBUG
57 	(void) fprintf(stdout,
58 	    "\n[getauuser.c: check_name %s with %s]\n", au_user->au_name, name);
59 #endif	/* DEBUG */
60 
61 	if (strcmp(au_user->au_name, name) == 0) {
62 		return (1);
63 	}
64 	return (0);
65 }
66 
67 static nss_status_t
68 getbynam(compat_backend_ptr_t be, void *a)
69 {
70 	nss_status_t	res;
71 	nss_XbyY_args_t *argp = (nss_XbyY_args_t *)a;
72 
73 #ifdef	DEBUG
74 	(void) fprintf(stdout, "\n[getauuser.c: getbynam]\n");
75 #endif	/* DEBUG */
76 
77 	res = _attrdb_compat_XY_all(be,
78 	    argp, 1, check_name, NSS_DBOP_AUDITUSER_BYNAME);
79 
80 	return (res);
81 }
82 
83 static compat_backend_op_t auuser_ops[] = {
84 	_nss_compat_destr,
85 	_nss_compat_endent,
86 	_nss_compat_setent,
87 	_nss_compat_getent,
88 	getbynam
89 };
90 
91 /*ARGSUSED*/
92 nss_backend_t  *
93 _nss_compat_audit_user_constr(const char *dummy1,
94     const char *dummy2,
95     const char *dummy3,
96     const char *dummy4,
97     const char *dummy5)
98 {
99 	return (_nss_compat_constr(auuser_ops,
100 		sizeof (auuser_ops)/sizeof (auuser_ops[0]),
101 		AUDITUSER_FILENAME,
102 		NSS_LINELEN_AUDITUSER,
103 		&db_root,
104 		_nss_initf_auuser_compat,
105 		0,
106 		get_auname,
107 		NULL));
108 }
109