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 <auth_attr.h>
37 /* externs from parse.c */
38 extern char *_strtok_escape(char *, char *, char **);
40 static int authattr_stayopen
= 0;
42 * Unsynchronized, but it affects only
43 * efficiency, not correctness
46 static DEFINE_NSS_DB_ROOT(db_root
);
47 static DEFINE_NSS_GETENT(context
);
50 _nss_initf_authattr(nss_db_params_t
*p
)
52 p
->name
= NSS_DBNAM_AUTHATTR
;
53 p
->default_config
= NSS_DEFCONF_AUTHATTR
;
58 * Return values: 0 = success, 1 = parse error, 2 = erange ...
59 * The structure pointer passed in is a structure in the caller's space
60 * wherein the field pointers would be set to areas in the buffer if
61 * need be. instring and buffer should be separate areas.
64 str2authattr(const char *instr
, int lenstr
, void *ent
, char *buffer
, int buflen
)
67 char *sep
= KV_TOKEN_DELIMIT
;
68 authstr_t
*auth
= (authstr_t
*)ent
;
71 return (NSS_STR_PARSE_ERANGE
);
74 (void) strncpy(buffer
, instr
, buflen
);
77 * Remove newline that nis (yp_match) puts at the
78 * end of the entry it retrieves from the map.
80 if (buffer
[lenstr
] == '\n')
81 buffer
[lenstr
] = '\0';
83 /* quick exit do not entry fill if not needed */
84 if (ent
== (void *)NULL
)
85 return (NSS_STR_PARSE_SUCCESS
);
87 auth
->name
= _strtok_escape(buffer
, sep
, &last
);
88 auth
->res1
= _strtok_escape(NULL
, sep
, &last
);
89 auth
->res2
= _strtok_escape(NULL
, sep
, &last
);
90 auth
->short_desc
= _strtok_escape(NULL
, sep
, &last
);
91 auth
->long_desc
= _strtok_escape(NULL
, sep
, &last
);
92 auth
->attr
= _strtok_escape(NULL
, sep
, &last
);
101 authattr_stayopen
= 0;
102 nss_setent(&db_root
, _nss_initf_authattr
, &context
);
109 authattr_stayopen
= 0;
110 nss_endent(&db_root
, _nss_initf_authattr
, &context
);
111 nss_delete(&db_root
);
116 _getauthattr(authstr_t
*result
, char *buffer
, int buflen
, int *h_errnop
)
121 NSS_XbyY_INIT(&arg
, result
, buffer
, buflen
, str2authattr
);
122 res
= nss_getent(&db_root
, _nss_initf_authattr
, &context
, &arg
);
124 *h_errnop
= arg
.h_errno
;
125 return ((authstr_t
*)NSS_XbyY_FINI(&arg
));
130 _getauthnam(const char *name
, authstr_t
*result
, char *buffer
, int buflen
,
136 NSS_XbyY_INIT(&arg
, result
, buffer
, buflen
, str2authattr
);
138 arg
.stayopen
= authattr_stayopen
;
139 res
= nss_search(&db_root
, _nss_initf_authattr
,
140 NSS_DBOP_AUTHATTR_BYNAME
, &arg
);
142 *errnop
= arg
.h_errno
;
143 return ((authstr_t
*)NSS_XbyY_FINI(&arg
));