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 <user_attr.h>
30 #include "compat_common.h"
31
32 static DEFINE_NSS_DB_ROOT(db_root);
33
34 static void
_nss_initf_userattr_compat(nss_db_params_t * p)35 _nss_initf_userattr_compat(nss_db_params_t *p)
36 {
37 p->name = NSS_DBNAM_USERATTR;
38 p->config_name = NSS_DBNAM_PASSWD_COMPAT;
39 p->default_config = NSS_DEFCONF_PASSWD_COMPAT;
40 }
41
42 static const char *
get_username(nss_XbyY_args_t * argp)43 get_username(nss_XbyY_args_t *argp)
44 {
45 userstr_t *user = (userstr_t *)argp->returnval;
46
47 return (user->name);
48 }
49
50 static int
check_name(nss_XbyY_args_t * argp)51 check_name(nss_XbyY_args_t *argp)
52 {
53 userstr_t *user = (userstr_t *)argp->returnval;
54 const char *name = argp->key.name;
55
56 #ifdef DEBUG
57 (void) fprintf(stdout,
58 "\n[getuserattr.c: check_name %s with %s]\n", user->name, name);
59 #endif /* DEBUG */
60
61 if (strcmp(user->name, name) == 0) {
62 return (1);
63 }
64 return (0);
65 }
66
67 static nss_status_t
getbynam(compat_backend_ptr_t be,void * a)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[getuserattr.c: getbynam]\n");
75 #endif /* DEBUG */
76
77 res = _attrdb_compat_XY_all(be,
78 argp, 1, check_name, NSS_DBOP_USERATTR_BYNAME);
79
80 return (res);
81 }
82
83 static compat_backend_op_t userattr_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 *
_nss_compat_user_attr_constr(const char * dummy1,const char * dummy2,const char * dummy3,const char * dummy4,const char * dummy5)93 _nss_compat_user_attr_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(userattr_ops,
100 sizeof (userattr_ops)/sizeof (userattr_ops[0]),
101 USERATTR_FILENAME,
102 NSS_LINELEN_USERATTR,
103 &db_root,
104 _nss_initf_userattr_compat,
105 0,
106 get_username,
107 NULL));
108 }
109