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.
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.
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]
23 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
31 #include <sys/types.h>
32 #include <nss_dbdefs.h>
34 #include <bsm/libbsm.h>
38 /* externs from parse.c */
39 extern char *_strtok_escape(char *, char *, char **);
41 static int auuser_stayopen
;
44 * Unsynchronized, but it affects only
45 * efficiency, not correctness
48 static DEFINE_NSS_DB_ROOT(db_root
);
49 static DEFINE_NSS_GETENT(context
);
53 _nss_initf_auuser(nss_db_params_t
*p
)
55 p
->name
= NSS_DBNAM_AUDITUSER
;
56 p
->config_name
= NSS_DBNAM_PASSWD
; /* use config for "passwd" */
57 p
->default_config
= NSS_DEFCONF_AUDITUSER
;
62 * Return values: 0 = success, 1 = parse error, 2 = erange ...
63 * The structure pointer passed in is a structure in the caller's space
64 * wherein the field pointers would be set to areas in the buffer if
65 * need be. instring and buffer should be separate areas.
68 str2auuser(const char *instr
, int lenstr
, void *ent
, char *buffer
, int buflen
)
71 char *sep
= KV_TOKEN_DELIMIT
;
72 au_user_str_t
*au_user
= (au_user_str_t
*)ent
;
75 return (NSS_STR_PARSE_ERANGE
);
78 (void) strncpy(buffer
, instr
, buflen
);
81 * Remove newline that nis (yp_match) puts at the
82 * end of the entry it retrieves from the map.
84 if (buffer
[lenstr
] == '\n') {
85 buffer
[lenstr
] = '\0';
88 /* quick exit do not entry fill if not needed */
90 return (NSS_STR_PARSE_SUCCESS
);
92 au_user
->au_name
= _strtok_escape(buffer
, sep
, &last
);
93 au_user
->au_always
= _strtok_escape(NULL
, sep
, &last
);
94 au_user
->au_never
= _strtok_escape(NULL
, sep
, &last
);
104 nss_setent(&db_root
, _nss_initf_auuser
, &context
);
112 nss_endent(&db_root
, _nss_initf_auuser
, &context
);
113 nss_delete(&db_root
);
119 _getauuserent(au_user_str_t
*result
, char *buffer
, int buflen
, int *h_errnop
)
124 NSS_XbyY_INIT(&arg
, result
, buffer
, buflen
, str2auuser
);
125 res
= nss_getent(&db_root
, _nss_initf_auuser
, &context
, &arg
);
127 *h_errnop
= arg
.h_errno
;
128 return ((au_user_str_t
*)NSS_XbyY_FINI(&arg
));
133 _getauusernam(const char *name
, au_user_str_t
*result
, char *buffer
,
134 int buflen
, int *errnop
)
139 if (result
== NULL
) {
140 *errnop
= AUDITUSER_PARSE_ERANGE
;
143 NSS_XbyY_INIT(&arg
, result
, buffer
, buflen
, str2auuser
);
145 arg
.stayopen
= auuser_stayopen
;
146 arg
.h_errno
= AUDITUSER_NOT_FOUND
;
147 res
= nss_search(&db_root
, _nss_initf_auuser
,
148 NSS_DBOP_AUDITUSER_BYNAME
, &arg
);
150 *errnop
= arg
.h_errno
;
151 return ((au_user_str_t
*)NSS_XbyY_FINI(&arg
));