10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*2830Sdjl * Common Development and Distribution License (the "License"). 6*2830Sdjl * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 21132Srobinson 220Sstevel@tonic-gate /* 231219Sraf * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 240Sstevel@tonic-gate * Use is subject to license terms. 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate 270Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 280Sstevel@tonic-gate 291219Sraf #include "mt.h" 300Sstevel@tonic-gate #include <stdlib.h> 310Sstevel@tonic-gate #include <sys/types.h> 320Sstevel@tonic-gate #include <nss_dbdefs.h> 330Sstevel@tonic-gate #include <string.h> 340Sstevel@tonic-gate #include <bsm/libbsm.h> 350Sstevel@tonic-gate #include <secdb.h> 360Sstevel@tonic-gate 370Sstevel@tonic-gate 380Sstevel@tonic-gate /* externs from parse.c */ 390Sstevel@tonic-gate extern char *_strtok_escape(char *, char *, char **); 400Sstevel@tonic-gate 410Sstevel@tonic-gate static int auuser_stayopen; 420Sstevel@tonic-gate 430Sstevel@tonic-gate /* 440Sstevel@tonic-gate * Unsynchronized, but it affects only 450Sstevel@tonic-gate * efficiency, not correctness 460Sstevel@tonic-gate */ 470Sstevel@tonic-gate 480Sstevel@tonic-gate static DEFINE_NSS_DB_ROOT(db_root); 490Sstevel@tonic-gate static DEFINE_NSS_GETENT(context); 500Sstevel@tonic-gate 510Sstevel@tonic-gate 520Sstevel@tonic-gate void 530Sstevel@tonic-gate _nss_initf_auuser(nss_db_params_t *p) 540Sstevel@tonic-gate { 550Sstevel@tonic-gate p->name = NSS_DBNAM_AUDITUSER; 560Sstevel@tonic-gate p->config_name = NSS_DBNAM_PASSWD; /* use config for "passwd" */ 570Sstevel@tonic-gate p->default_config = NSS_DEFCONF_AUDITUSER; 580Sstevel@tonic-gate } 590Sstevel@tonic-gate 600Sstevel@tonic-gate 610Sstevel@tonic-gate /* 620Sstevel@tonic-gate * Return values: 0 = success, 1 = parse error, 2 = erange ... 630Sstevel@tonic-gate * The structure pointer passed in is a structure in the caller's space 640Sstevel@tonic-gate * wherein the field pointers would be set to areas in the buffer if 650Sstevel@tonic-gate * need be. instring and buffer should be separate areas. 660Sstevel@tonic-gate */ 670Sstevel@tonic-gate int 680Sstevel@tonic-gate str2auuser(const char *instr, int lenstr, void *ent, char *buffer, int buflen) 690Sstevel@tonic-gate { 70132Srobinson char *last = NULL; 710Sstevel@tonic-gate char *sep = KV_TOKEN_DELIMIT; 720Sstevel@tonic-gate au_user_str_t *au_user = (au_user_str_t *)ent; 730Sstevel@tonic-gate 74132Srobinson if (lenstr >= buflen) 750Sstevel@tonic-gate return (NSS_STR_PARSE_ERANGE); 76*2830Sdjl 77*2830Sdjl if (instr != buffer) 78*2830Sdjl (void) strncpy(buffer, instr, buflen); 79*2830Sdjl 800Sstevel@tonic-gate /* 810Sstevel@tonic-gate * Remove newline that nis (yp_match) puts at the 820Sstevel@tonic-gate * end of the entry it retrieves from the map. 830Sstevel@tonic-gate */ 840Sstevel@tonic-gate if (buffer[lenstr] == '\n') { 850Sstevel@tonic-gate buffer[lenstr] = '\0'; 860Sstevel@tonic-gate } 870Sstevel@tonic-gate 88*2830Sdjl /* quick exit do not entry fill if not needed */ 89*2830Sdjl if (ent == (void *)NULL) 90*2830Sdjl return (NSS_STR_PARSE_SUCCESS); 91*2830Sdjl 920Sstevel@tonic-gate au_user->au_name = _strtok_escape(buffer, sep, &last); 930Sstevel@tonic-gate au_user->au_always = _strtok_escape(NULL, sep, &last); 940Sstevel@tonic-gate au_user->au_never = _strtok_escape(NULL, sep, &last); 950Sstevel@tonic-gate 960Sstevel@tonic-gate return (0); 970Sstevel@tonic-gate } 980Sstevel@tonic-gate 990Sstevel@tonic-gate 1000Sstevel@tonic-gate void 1010Sstevel@tonic-gate _setauuser(void) 1020Sstevel@tonic-gate { 1030Sstevel@tonic-gate auuser_stayopen = 0; 1040Sstevel@tonic-gate nss_setent(&db_root, _nss_initf_auuser, &context); 1050Sstevel@tonic-gate } 1060Sstevel@tonic-gate 1070Sstevel@tonic-gate 1080Sstevel@tonic-gate int 1090Sstevel@tonic-gate _endauuser(void) 1100Sstevel@tonic-gate { 1110Sstevel@tonic-gate auuser_stayopen = 0; 1120Sstevel@tonic-gate nss_endent(&db_root, _nss_initf_auuser, &context); 1130Sstevel@tonic-gate nss_delete(&db_root); 1140Sstevel@tonic-gate return (0); 1150Sstevel@tonic-gate } 1160Sstevel@tonic-gate 1170Sstevel@tonic-gate 1180Sstevel@tonic-gate au_user_str_t * 1190Sstevel@tonic-gate _getauuserent(au_user_str_t *result, char *buffer, int buflen, int *h_errnop) 1200Sstevel@tonic-gate { 1210Sstevel@tonic-gate nss_XbyY_args_t arg; 1220Sstevel@tonic-gate nss_status_t res; 1230Sstevel@tonic-gate 1240Sstevel@tonic-gate NSS_XbyY_INIT(&arg, result, buffer, buflen, str2auuser); 1250Sstevel@tonic-gate res = nss_getent(&db_root, _nss_initf_auuser, &context, &arg); 1260Sstevel@tonic-gate arg.status = res; 1270Sstevel@tonic-gate *h_errnop = arg.h_errno; 1280Sstevel@tonic-gate return ((au_user_str_t *)NSS_XbyY_FINI(&arg)); 1290Sstevel@tonic-gate } 1300Sstevel@tonic-gate 1310Sstevel@tonic-gate 1320Sstevel@tonic-gate au_user_str_t * 1330Sstevel@tonic-gate _getauusernam(const char *name, au_user_str_t *result, char *buffer, 1340Sstevel@tonic-gate int buflen, int *errnop) 1350Sstevel@tonic-gate { 1360Sstevel@tonic-gate nss_XbyY_args_t arg; 1370Sstevel@tonic-gate nss_status_t res; 1380Sstevel@tonic-gate 1390Sstevel@tonic-gate if (result == NULL) { 1400Sstevel@tonic-gate *errnop = AUDITUSER_PARSE_ERANGE; 1410Sstevel@tonic-gate return (NULL); 1420Sstevel@tonic-gate } 1430Sstevel@tonic-gate NSS_XbyY_INIT(&arg, result, buffer, buflen, str2auuser); 1440Sstevel@tonic-gate arg.key.name = name; 1450Sstevel@tonic-gate arg.stayopen = auuser_stayopen; 1460Sstevel@tonic-gate arg.h_errno = AUDITUSER_NOT_FOUND; 1470Sstevel@tonic-gate res = nss_search(&db_root, _nss_initf_auuser, 1480Sstevel@tonic-gate NSS_DBOP_AUDITUSER_BYNAME, &arg); 1490Sstevel@tonic-gate arg.status = res; 1500Sstevel@tonic-gate *errnop = arg.h_errno; 1510Sstevel@tonic-gate return ((au_user_str_t *)NSS_XbyY_FINI(&arg)); 1520Sstevel@tonic-gate } 153