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