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