import less(1)
[unleashed/tickless.git] / usr / src / lib / libc / port / nsl / getauuser.c
blobb93f1e3dd0b4d7c8439c1708ca1f7c944d619a98
1 /*
2 * CDDL HEADER START
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]
19 * CDDL HEADER END
23 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
29 #include "mt.h"
30 #include <stdlib.h>
31 #include <sys/types.h>
32 #include <nss_dbdefs.h>
33 #include <string.h>
34 #include <bsm/libbsm.h>
35 #include <secdb.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);
52 void
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.
67 int
68 str2auuser(const char *instr, int lenstr, void *ent, char *buffer, int buflen)
70 char *last = NULL;
71 char *sep = KV_TOKEN_DELIMIT;
72 au_user_str_t *au_user = (au_user_str_t *)ent;
74 if (lenstr >= buflen)
75 return (NSS_STR_PARSE_ERANGE);
77 if (instr != buffer)
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 */
89 if (ent == NULL)
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);
96 return (0);
100 void
101 _setauuser(void)
103 auuser_stayopen = 0;
104 nss_setent(&db_root, _nss_initf_auuser, &context);
109 _endauuser(void)
111 auuser_stayopen = 0;
112 nss_endent(&db_root, _nss_initf_auuser, &context);
113 nss_delete(&db_root);
114 return (0);
118 au_user_str_t *
119 _getauuserent(au_user_str_t *result, char *buffer, int buflen, int *h_errnop)
121 nss_XbyY_args_t arg;
122 nss_status_t res;
124 NSS_XbyY_INIT(&arg, result, buffer, buflen, str2auuser);
125 res = nss_getent(&db_root, _nss_initf_auuser, &context, &arg);
126 arg.status = res;
127 *h_errnop = arg.h_errno;
128 return ((au_user_str_t *)NSS_XbyY_FINI(&arg));
132 au_user_str_t *
133 _getauusernam(const char *name, au_user_str_t *result, char *buffer,
134 int buflen, int *errnop)
136 nss_XbyY_args_t arg;
137 nss_status_t res;
139 if (result == NULL) {
140 *errnop = AUDITUSER_PARSE_ERANGE;
141 return (NULL);
143 NSS_XbyY_INIT(&arg, result, buffer, buflen, str2auuser);
144 arg.key.name = name;
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);
149 arg.status = res;
150 *errnop = arg.h_errno;
151 return ((au_user_str_t *)NSS_XbyY_FINI(&arg));