xref: /titanic_41/usr/src/lib/nsswitch/compat/common/getauuser.c (revision 70025d765b044c6d8594bb965a2247a61e991a99)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright (c) 1999-2000 by Sun Microsystems, Inc.
24  * All rights reserved.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 #include <sys/types.h>
30 #include <stdlib.h>
31 #include <string.h>
32 #include <bsm/libbsm.h>
33 #include "compat_common.h"
34 
35 static DEFINE_NSS_DB_ROOT(db_root);
36 
37 void
38 _nss_initf_auuser_compat(nss_db_params_t *p)
39 {
40 	p->name = NSS_DBNAM_AUDITUSER;
41 	p->config_name = NSS_DBNAM_PASSWD_COMPAT;
42 	p->default_config = NSS_DEFCONF_PASSWD_COMPAT;
43 }
44 
45 static const char *
46 get_auname(nss_XbyY_args_t *argp)
47 {
48 	au_user_str_t *au_user = (au_user_str_t *)argp->returnval;
49 
50 	return (au_user->au_name);
51 }
52 
53 static int
54 check_name(nss_XbyY_args_t *argp)
55 {
56 	au_user_str_t	*au_user = (au_user_str_t *)argp->returnval;
57 	const char	*name = argp->key.name;
58 
59 #ifdef	DEBUG
60 	(void) fprintf(stdout,
61 	    "\n[getauuser.c: check_name %s with %s]\n", au_user->au_name, name);
62 #endif	/* DEBUG */
63 
64 	if (strcmp(au_user->au_name, name) == 0) {
65 		return (1);
66 	}
67 	return (0);
68 }
69 
70 static nss_status_t
71 getbynam(compat_backend_ptr_t be, void *a)
72 {
73 	nss_status_t	res;
74 	nss_XbyY_args_t *argp = (nss_XbyY_args_t *)a;
75 
76 #ifdef	DEBUG
77 	(void) fprintf(stdout, "\n[getauuser.c: getbynam]\n");
78 #endif	/* DEBUG */
79 
80 	res = _attrdb_compat_XY_all(be,
81 	    argp, 1, check_name, NSS_DBOP_AUDITUSER_BYNAME);
82 
83 	return (res);
84 }
85 
86 static compat_backend_op_t auuser_ops[] = {
87 	_nss_compat_destr,
88 	_nss_compat_endent,
89 	_nss_compat_setent,
90 	_nss_compat_getent,
91 	getbynam
92 };
93 
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