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