1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright (c) 1999, 2001 by Sun Microsystems, Inc.
24*7c478bd9Sstevel@tonic-gate  * All rights reserved.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
28*7c478bd9Sstevel@tonic-gate #include <stdio.h>
29*7c478bd9Sstevel@tonic-gate #include <string.h>
30*7c478bd9Sstevel@tonic-gate #include <stdlib.h>
31*7c478bd9Sstevel@tonic-gate #include <nss_dbdefs.h>
32*7c478bd9Sstevel@tonic-gate #include <auth_attr.h>
33*7c478bd9Sstevel@tonic-gate 
34*7c478bd9Sstevel@tonic-gate 
35*7c478bd9Sstevel@tonic-gate /* Externs from libnsl */
36*7c478bd9Sstevel@tonic-gate extern authstr_t *_getauthnam(const char *, authstr_t *, char *, int, int *);
37*7c478bd9Sstevel@tonic-gate extern authstr_t *_getauthattr(authstr_t *, char *, int, int *);
38*7c478bd9Sstevel@tonic-gate extern void _setauthattr();
39*7c478bd9Sstevel@tonic-gate extern void _endauthattr(void);
40*7c478bd9Sstevel@tonic-gate 
41*7c478bd9Sstevel@tonic-gate 
42*7c478bd9Sstevel@tonic-gate static authattr_t *authstr2attr(authstr_t *);
43*7c478bd9Sstevel@tonic-gate 
44*7c478bd9Sstevel@tonic-gate 
45*7c478bd9Sstevel@tonic-gate authattr_t *
getauthattr()46*7c478bd9Sstevel@tonic-gate getauthattr()
47*7c478bd9Sstevel@tonic-gate {
48*7c478bd9Sstevel@tonic-gate 	int		err = 0;
49*7c478bd9Sstevel@tonic-gate 	char		buf[NSS_BUFLEN_AUTHATTR];
50*7c478bd9Sstevel@tonic-gate 	authstr_t	auth;
51*7c478bd9Sstevel@tonic-gate 	authstr_t	*tmp;
52*7c478bd9Sstevel@tonic-gate 
53*7c478bd9Sstevel@tonic-gate 	(void) memset(&auth, 0, sizeof (authstr_t));
54*7c478bd9Sstevel@tonic-gate 	tmp = _getauthattr(&auth, buf, NSS_BUFLEN_AUTHATTR, &err);
55*7c478bd9Sstevel@tonic-gate 	return (authstr2attr(tmp));
56*7c478bd9Sstevel@tonic-gate }
57*7c478bd9Sstevel@tonic-gate 
58*7c478bd9Sstevel@tonic-gate 
59*7c478bd9Sstevel@tonic-gate authattr_t *
getauthnam(const char * name)60*7c478bd9Sstevel@tonic-gate getauthnam(const char *name)
61*7c478bd9Sstevel@tonic-gate {
62*7c478bd9Sstevel@tonic-gate 	int		err = 0;
63*7c478bd9Sstevel@tonic-gate 	char		buf[NSS_BUFLEN_AUTHATTR];
64*7c478bd9Sstevel@tonic-gate 	authstr_t	auth;
65*7c478bd9Sstevel@tonic-gate 	authstr_t	*tmp;
66*7c478bd9Sstevel@tonic-gate 
67*7c478bd9Sstevel@tonic-gate 	if (name == NULL) {
68*7c478bd9Sstevel@tonic-gate 		return ((authattr_t *)NULL);
69*7c478bd9Sstevel@tonic-gate 	}
70*7c478bd9Sstevel@tonic-gate 	(void) memset(&auth, 0, sizeof (authstr_t));
71*7c478bd9Sstevel@tonic-gate 	tmp = _getauthnam(name, &auth, buf, NSS_BUFLEN_AUTHATTR, &err);
72*7c478bd9Sstevel@tonic-gate 	return (authstr2attr(tmp));
73*7c478bd9Sstevel@tonic-gate }
74*7c478bd9Sstevel@tonic-gate 
75*7c478bd9Sstevel@tonic-gate 
76*7c478bd9Sstevel@tonic-gate void
setauthattr(void)77*7c478bd9Sstevel@tonic-gate setauthattr(void)
78*7c478bd9Sstevel@tonic-gate {
79*7c478bd9Sstevel@tonic-gate 	_setauthattr();
80*7c478bd9Sstevel@tonic-gate }
81*7c478bd9Sstevel@tonic-gate 
82*7c478bd9Sstevel@tonic-gate 
83*7c478bd9Sstevel@tonic-gate void
endauthattr()84*7c478bd9Sstevel@tonic-gate endauthattr()
85*7c478bd9Sstevel@tonic-gate {
86*7c478bd9Sstevel@tonic-gate 	_endauthattr();
87*7c478bd9Sstevel@tonic-gate }
88*7c478bd9Sstevel@tonic-gate 
89*7c478bd9Sstevel@tonic-gate 
90*7c478bd9Sstevel@tonic-gate void
free_authattr(authattr_t * auth)91*7c478bd9Sstevel@tonic-gate free_authattr(authattr_t *auth)
92*7c478bd9Sstevel@tonic-gate {
93*7c478bd9Sstevel@tonic-gate 	if (auth) {
94*7c478bd9Sstevel@tonic-gate 		free(auth->name);
95*7c478bd9Sstevel@tonic-gate 		free(auth->res1);
96*7c478bd9Sstevel@tonic-gate 		free(auth->res2);
97*7c478bd9Sstevel@tonic-gate 		free(auth->short_desc);
98*7c478bd9Sstevel@tonic-gate 		free(auth->long_desc);
99*7c478bd9Sstevel@tonic-gate 		_kva_free(auth->attr);
100*7c478bd9Sstevel@tonic-gate 		free(auth);
101*7c478bd9Sstevel@tonic-gate 	}
102*7c478bd9Sstevel@tonic-gate }
103*7c478bd9Sstevel@tonic-gate 
104*7c478bd9Sstevel@tonic-gate 
105*7c478bd9Sstevel@tonic-gate static authattr_t *
authstr2attr(authstr_t * auth)106*7c478bd9Sstevel@tonic-gate authstr2attr(authstr_t *auth)
107*7c478bd9Sstevel@tonic-gate {
108*7c478bd9Sstevel@tonic-gate 	authattr_t *newauth;
109*7c478bd9Sstevel@tonic-gate 
110*7c478bd9Sstevel@tonic-gate 	if (auth == NULL)
111*7c478bd9Sstevel@tonic-gate 		return ((authattr_t *)NULL);
112*7c478bd9Sstevel@tonic-gate 
113*7c478bd9Sstevel@tonic-gate 	if ((newauth = (authattr_t *)malloc(sizeof (authattr_t))) == NULL)
114*7c478bd9Sstevel@tonic-gate 		return ((authattr_t *)NULL);
115*7c478bd9Sstevel@tonic-gate 
116*7c478bd9Sstevel@tonic-gate 	newauth->name = _do_unescape(auth->name);
117*7c478bd9Sstevel@tonic-gate 	newauth->res1 = _do_unescape(auth->res1);
118*7c478bd9Sstevel@tonic-gate 	newauth->res2 = _do_unescape(auth->res2);
119*7c478bd9Sstevel@tonic-gate 	newauth->short_desc = _do_unescape(auth->short_desc);
120*7c478bd9Sstevel@tonic-gate 	newauth->long_desc = _do_unescape(auth->long_desc);
121*7c478bd9Sstevel@tonic-gate 	newauth->attr = _str2kva(auth->attr, KV_ASSIGN, KV_DELIMITER);
122*7c478bd9Sstevel@tonic-gate 	return (newauth);
123*7c478bd9Sstevel@tonic-gate }
124*7c478bd9Sstevel@tonic-gate 
125*7c478bd9Sstevel@tonic-gate 
126*7c478bd9Sstevel@tonic-gate #ifdef DEBUG
127*7c478bd9Sstevel@tonic-gate void
print_authattr(authattr_t * auth)128*7c478bd9Sstevel@tonic-gate print_authattr(authattr_t *auth)
129*7c478bd9Sstevel@tonic-gate {
130*7c478bd9Sstevel@tonic-gate 	extern void print_kva(kva_t *);
131*7c478bd9Sstevel@tonic-gate 	char *empty = "empty";
132*7c478bd9Sstevel@tonic-gate 
133*7c478bd9Sstevel@tonic-gate 	if (auth == NULL) {
134*7c478bd9Sstevel@tonic-gate 		printf("NULL\n");
135*7c478bd9Sstevel@tonic-gate 		return;
136*7c478bd9Sstevel@tonic-gate 	}
137*7c478bd9Sstevel@tonic-gate 
138*7c478bd9Sstevel@tonic-gate 	printf("name=%s\n", auth->name ? auth->name : empty);
139*7c478bd9Sstevel@tonic-gate 	printf("res1=%s\n", auth->res1 ? auth->res1 : empty);
140*7c478bd9Sstevel@tonic-gate 	printf("res2=%s\n", auth->res2 ? auth->res2 : empty);
141*7c478bd9Sstevel@tonic-gate 	printf("short_desc=%s\n", auth->short_desc ? auth->short_desc : empty);
142*7c478bd9Sstevel@tonic-gate 	printf("long_desc=%s\n", auth->long_desc ? auth->long_desc : empty);
143*7c478bd9Sstevel@tonic-gate 	printf("attr=\n");
144*7c478bd9Sstevel@tonic-gate 	print_kva(auth->attr);
145*7c478bd9Sstevel@tonic-gate 	fflush(stdout);
146*7c478bd9Sstevel@tonic-gate }
147*7c478bd9Sstevel@tonic-gate #endif  /* DEBUG */
148