xref: /titanic_51/usr/src/lib/nsswitch/compat/common/getuserattr.c (revision bfed486ad8de8b8ebc6345a8e10accae08bf2f45)
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 <user_attr.h>
32 #include "compat_common.h"
33 
34 static DEFINE_NSS_DB_ROOT(db_root);
35 
36 static void
37 _nss_initf_userattr_compat(nss_db_params_t *p)
38 {
39 	p->name = NSS_DBNAM_USERATTR;
40 	p->config_name = NSS_DBNAM_PASSWD_COMPAT;
41 	p->default_config = NSS_DEFCONF_PASSWD_COMPAT;
42 }
43 
44 static const char *
45 get_username(nss_XbyY_args_t *argp)
46 {
47 	userstr_t *user = (userstr_t *)argp->returnval;
48 
49 	return (user->name);
50 }
51 
52 static int
53 check_name(nss_XbyY_args_t *argp)
54 {
55 	userstr_t	*user = (userstr_t *)argp->returnval;
56 	const char	*name = argp->key.name;
57 
58 #ifdef	DEBUG
59 	(void) fprintf(stdout,
60 	    "\n[getuserattr.c: check_name %s with %s]\n", user->name, name);
61 #endif	/* DEBUG */
62 
63 	if (strcmp(user->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[getuserattr.c: getbynam]\n");
77 #endif	/* DEBUG */
78 
79 	res = _attrdb_compat_XY_all(be,
80 	    argp, 1, check_name, NSS_DBOP_USERATTR_BYNAME);
81 
82 	return (res);
83 }
84 
85 static compat_backend_op_t userattr_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_user_attr_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(userattr_ops,
102 		sizeof (userattr_ops)/sizeof (userattr_ops[0]),
103 		USERATTR_FILENAME,
104 		NSS_LINELEN_USERATTR,
105 		&db_root,
106 		_nss_initf_userattr_compat,
107 		0,
108 		get_username,
109 		NULL));
110 }
111