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 #pragma ident "%Z%%M% %I% %E% SMI" 28*7c478bd9Sstevel@tonic-gate 29*7c478bd9Sstevel@tonic-gate #include <sys/types.h> 30*7c478bd9Sstevel@tonic-gate #include <stdio.h> 31*7c478bd9Sstevel@tonic-gate #include <string.h> 32*7c478bd9Sstevel@tonic-gate #include <stdlib.h> 33*7c478bd9Sstevel@tonic-gate #include <nss_dbdefs.h> 34*7c478bd9Sstevel@tonic-gate #include <auth_attr.h> 35*7c478bd9Sstevel@tonic-gate 36*7c478bd9Sstevel@tonic-gate 37*7c478bd9Sstevel@tonic-gate /* Externs from libnsl */ 38*7c478bd9Sstevel@tonic-gate extern authstr_t *_getauthnam(const char *, authstr_t *, char *, int, int *); 39*7c478bd9Sstevel@tonic-gate extern authstr_t *_getauthattr(authstr_t *, char *, int, int *); 40*7c478bd9Sstevel@tonic-gate extern void _setauthattr(); 41*7c478bd9Sstevel@tonic-gate extern void _endauthattr(void); 42*7c478bd9Sstevel@tonic-gate 43*7c478bd9Sstevel@tonic-gate 44*7c478bd9Sstevel@tonic-gate static authattr_t *authstr2attr(authstr_t *); 45*7c478bd9Sstevel@tonic-gate 46*7c478bd9Sstevel@tonic-gate 47*7c478bd9Sstevel@tonic-gate authattr_t * 48*7c478bd9Sstevel@tonic-gate getauthattr() 49*7c478bd9Sstevel@tonic-gate { 50*7c478bd9Sstevel@tonic-gate int err = 0; 51*7c478bd9Sstevel@tonic-gate char buf[NSS_BUFLEN_AUTHATTR]; 52*7c478bd9Sstevel@tonic-gate authstr_t auth; 53*7c478bd9Sstevel@tonic-gate authstr_t *tmp; 54*7c478bd9Sstevel@tonic-gate 55*7c478bd9Sstevel@tonic-gate (void) memset(&auth, 0, sizeof (authstr_t)); 56*7c478bd9Sstevel@tonic-gate tmp = _getauthattr(&auth, buf, NSS_BUFLEN_AUTHATTR, &err); 57*7c478bd9Sstevel@tonic-gate return (authstr2attr(tmp)); 58*7c478bd9Sstevel@tonic-gate } 59*7c478bd9Sstevel@tonic-gate 60*7c478bd9Sstevel@tonic-gate 61*7c478bd9Sstevel@tonic-gate authattr_t * 62*7c478bd9Sstevel@tonic-gate getauthnam(const char *name) 63*7c478bd9Sstevel@tonic-gate { 64*7c478bd9Sstevel@tonic-gate int err = 0; 65*7c478bd9Sstevel@tonic-gate char buf[NSS_BUFLEN_AUTHATTR]; 66*7c478bd9Sstevel@tonic-gate authstr_t auth; 67*7c478bd9Sstevel@tonic-gate authstr_t *tmp; 68*7c478bd9Sstevel@tonic-gate 69*7c478bd9Sstevel@tonic-gate if (name == NULL) { 70*7c478bd9Sstevel@tonic-gate return ((authattr_t *)NULL); 71*7c478bd9Sstevel@tonic-gate } 72*7c478bd9Sstevel@tonic-gate (void) memset(&auth, 0, sizeof (authstr_t)); 73*7c478bd9Sstevel@tonic-gate tmp = _getauthnam(name, &auth, buf, NSS_BUFLEN_AUTHATTR, &err); 74*7c478bd9Sstevel@tonic-gate return (authstr2attr(tmp)); 75*7c478bd9Sstevel@tonic-gate } 76*7c478bd9Sstevel@tonic-gate 77*7c478bd9Sstevel@tonic-gate 78*7c478bd9Sstevel@tonic-gate void 79*7c478bd9Sstevel@tonic-gate setauthattr(void) 80*7c478bd9Sstevel@tonic-gate { 81*7c478bd9Sstevel@tonic-gate _setauthattr(); 82*7c478bd9Sstevel@tonic-gate } 83*7c478bd9Sstevel@tonic-gate 84*7c478bd9Sstevel@tonic-gate 85*7c478bd9Sstevel@tonic-gate void 86*7c478bd9Sstevel@tonic-gate endauthattr() 87*7c478bd9Sstevel@tonic-gate { 88*7c478bd9Sstevel@tonic-gate _endauthattr(); 89*7c478bd9Sstevel@tonic-gate } 90*7c478bd9Sstevel@tonic-gate 91*7c478bd9Sstevel@tonic-gate 92*7c478bd9Sstevel@tonic-gate void 93*7c478bd9Sstevel@tonic-gate free_authattr(authattr_t *auth) 94*7c478bd9Sstevel@tonic-gate { 95*7c478bd9Sstevel@tonic-gate if (auth) { 96*7c478bd9Sstevel@tonic-gate free(auth->name); 97*7c478bd9Sstevel@tonic-gate free(auth->res1); 98*7c478bd9Sstevel@tonic-gate free(auth->res2); 99*7c478bd9Sstevel@tonic-gate free(auth->short_desc); 100*7c478bd9Sstevel@tonic-gate free(auth->long_desc); 101*7c478bd9Sstevel@tonic-gate _kva_free(auth->attr); 102*7c478bd9Sstevel@tonic-gate free(auth); 103*7c478bd9Sstevel@tonic-gate } 104*7c478bd9Sstevel@tonic-gate } 105*7c478bd9Sstevel@tonic-gate 106*7c478bd9Sstevel@tonic-gate 107*7c478bd9Sstevel@tonic-gate static authattr_t * 108*7c478bd9Sstevel@tonic-gate authstr2attr(authstr_t *auth) 109*7c478bd9Sstevel@tonic-gate { 110*7c478bd9Sstevel@tonic-gate authattr_t *newauth; 111*7c478bd9Sstevel@tonic-gate 112*7c478bd9Sstevel@tonic-gate if (auth == NULL) 113*7c478bd9Sstevel@tonic-gate return ((authattr_t *)NULL); 114*7c478bd9Sstevel@tonic-gate 115*7c478bd9Sstevel@tonic-gate if ((newauth = (authattr_t *)malloc(sizeof (authattr_t))) == NULL) 116*7c478bd9Sstevel@tonic-gate return ((authattr_t *)NULL); 117*7c478bd9Sstevel@tonic-gate 118*7c478bd9Sstevel@tonic-gate newauth->name = _do_unescape(auth->name); 119*7c478bd9Sstevel@tonic-gate newauth->res1 = _do_unescape(auth->res1); 120*7c478bd9Sstevel@tonic-gate newauth->res2 = _do_unescape(auth->res2); 121*7c478bd9Sstevel@tonic-gate newauth->short_desc = _do_unescape(auth->short_desc); 122*7c478bd9Sstevel@tonic-gate newauth->long_desc = _do_unescape(auth->long_desc); 123*7c478bd9Sstevel@tonic-gate newauth->attr = _str2kva(auth->attr, KV_ASSIGN, KV_DELIMITER); 124*7c478bd9Sstevel@tonic-gate return (newauth); 125*7c478bd9Sstevel@tonic-gate } 126*7c478bd9Sstevel@tonic-gate 127*7c478bd9Sstevel@tonic-gate 128*7c478bd9Sstevel@tonic-gate #ifdef DEBUG 129*7c478bd9Sstevel@tonic-gate void 130*7c478bd9Sstevel@tonic-gate print_authattr(authattr_t *auth) 131*7c478bd9Sstevel@tonic-gate { 132*7c478bd9Sstevel@tonic-gate extern void print_kva(kva_t *); 133*7c478bd9Sstevel@tonic-gate char *empty = "empty"; 134*7c478bd9Sstevel@tonic-gate 135*7c478bd9Sstevel@tonic-gate if (auth == NULL) { 136*7c478bd9Sstevel@tonic-gate printf("NULL\n"); 137*7c478bd9Sstevel@tonic-gate return; 138*7c478bd9Sstevel@tonic-gate } 139*7c478bd9Sstevel@tonic-gate 140*7c478bd9Sstevel@tonic-gate printf("name=%s\n", auth->name ? auth->name : empty); 141*7c478bd9Sstevel@tonic-gate printf("res1=%s\n", auth->res1 ? auth->res1 : empty); 142*7c478bd9Sstevel@tonic-gate printf("res2=%s\n", auth->res2 ? auth->res2 : empty); 143*7c478bd9Sstevel@tonic-gate printf("short_desc=%s\n", auth->short_desc ? auth->short_desc : empty); 144*7c478bd9Sstevel@tonic-gate printf("long_desc=%s\n", auth->long_desc ? auth->long_desc : empty); 145*7c478bd9Sstevel@tonic-gate printf("attr=\n"); 146*7c478bd9Sstevel@tonic-gate print_kva(auth->attr); 147*7c478bd9Sstevel@tonic-gate fflush(stdout); 148*7c478bd9Sstevel@tonic-gate } 149*7c478bd9Sstevel@tonic-gate #endif /* DEBUG */ 150