xref: /titanic_41/usr/src/lib/nsswitch/files/common/getuserattr.c (revision 66f9d5cb3cc0652e2d9d1366fb950efbe4ca2f24)
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-2001 by Sun Microsystems, Inc.
24  * All rights reserved.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 
30 #include "files_common.h"
31 #include <user_attr.h>
32 #include <string.h>
33 
34 /*
35  *    files/getuserattr.c --
36  *           "files" backend for nsswitch "user_attr" database
37  */
38 static int
39 check_name(nss_XbyY_args_t *args)
40 {
41 	userstr_t *user = (userstr_t *)args->returnval;
42 	const char *name    = args->key.name;
43 
44 	if (strcmp(user->name, name) == 0) {
45 		return (1);
46 	}
47 	return (0);
48 }
49 
50 static nss_status_t
51 getbyname(files_backend_ptr_t be, void *a)
52 {
53 	nss_XbyY_args_t *argp = (nss_XbyY_args_t *)a;
54 
55 	return (_nss_files_XY_all(be, argp, 1, argp->key.name, check_name));
56 }
57 
58 static files_backend_op_t userattr_ops[] = {
59 	_nss_files_destr,
60 	_nss_files_endent,
61 	_nss_files_setent,
62 	_nss_files_getent_netdb,
63 	getbyname
64 };
65 
66 nss_backend_t *
67 _nss_files_user_attr_constr(const char *dummy1,
68     const char *dummy2,
69     const char *dummy3,
70     const char *dummy4,
71     const char *dummy5)
72 {
73 	return (_nss_files_constr(userattr_ops,
74 	    sizeof (userattr_ops) / sizeof (userattr_ops[0]),
75 	    USERATTR_FILENAME,
76 	    NSS_LINELEN_USERATTR,
77 	    NULL));
78 }
79