17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
581490fd2Sgww  * Common Development and Distribution License (the "License").
681490fd2Sgww  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
227c478bd9Sstevel@tonic-gate  * adt_jni.c
237c478bd9Sstevel@tonic-gate  *
247c478bd9Sstevel@tonic-gate  * JNI wrapper for adt interface within libbsm
257c478bd9Sstevel@tonic-gate  *
26*33267025Sgww  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
277c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
287c478bd9Sstevel@tonic-gate  *
297c478bd9Sstevel@tonic-gate  */
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate #include <bsm/adt.h>
327c478bd9Sstevel@tonic-gate #include "adt_jni.h"
337c478bd9Sstevel@tonic-gate #include <jni.h>
347c478bd9Sstevel@tonic-gate #include "../com/sun/audit/AuditSession.h"	/* javah output */
357c478bd9Sstevel@tonic-gate #include <assert.h>
367c478bd9Sstevel@tonic-gate #include <stdlib.h>
377c478bd9Sstevel@tonic-gate #include <string.h>
387c478bd9Sstevel@tonic-gate #include <netdb.h>
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate /*
417c478bd9Sstevel@tonic-gate  * local_throw  -- throw an exception.
427c478bd9Sstevel@tonic-gate  * "why" string must be i18n'd before calling here.
437c478bd9Sstevel@tonic-gate  *
447c478bd9Sstevel@tonic-gate  */
457c478bd9Sstevel@tonic-gate 
467c478bd9Sstevel@tonic-gate void
local_throw(JNIEnv * env,const char * exception,const char * why)477c478bd9Sstevel@tonic-gate local_throw(JNIEnv *env, const char *exception, const char *why) {
487c478bd9Sstevel@tonic-gate 	jobject jexception;
497c478bd9Sstevel@tonic-gate 	jclass exceptionclass;
507c478bd9Sstevel@tonic-gate 	jmethodID jexceptionnew;
517c478bd9Sstevel@tonic-gate 
527c478bd9Sstevel@tonic-gate 	jbyteArray jbarray;
537c478bd9Sstevel@tonic-gate 
547c478bd9Sstevel@tonic-gate 	jstring jmsg;
557c478bd9Sstevel@tonic-gate 	jclass strclass;
567c478bd9Sstevel@tonic-gate 	jmethodID jstrnew;
577c478bd9Sstevel@tonic-gate 
587c478bd9Sstevel@tonic-gate 	/* Get a String class and "new" method */
597c478bd9Sstevel@tonic-gate 	strclass = (*env)->FindClass(env, "java/lang/String");
607c478bd9Sstevel@tonic-gate 	jstrnew = (*env)->GetMethodID(env, strclass, "<init>", "([B)V");
617c478bd9Sstevel@tonic-gate 
627c478bd9Sstevel@tonic-gate 	/* Create a Byte Array from message "why" */
637c478bd9Sstevel@tonic-gate 	jbarray = (*env)->NewByteArray(env, (jsize)(strlen(why)));
647c478bd9Sstevel@tonic-gate 	(*env)->SetByteArrayRegion(env, jbarray, (jsize)0,
657c478bd9Sstevel@tonic-gate 	    (jsize)(strlen(why)), (jbyte*) why);
667c478bd9Sstevel@tonic-gate 
677c478bd9Sstevel@tonic-gate 	/* Create string from byte array */
687c478bd9Sstevel@tonic-gate 	jmsg = (*env)->NewObject(env, strclass, jstrnew, jbarray);
697c478bd9Sstevel@tonic-gate 	exceptionclass = (*env)->FindClass(env, exception);
707c478bd9Sstevel@tonic-gate 	jexceptionnew = (*env)->GetMethodID(env, exceptionclass,
717c478bd9Sstevel@tonic-gate 	    "<init>", "(Ljava/lang/String;)V");
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate 	jexception = (*env)->NewObject(env, exceptionclass, jexceptionnew,
747c478bd9Sstevel@tonic-gate 	    jmsg);
757c478bd9Sstevel@tonic-gate 	(*env)->Throw(env, jexception);
767c478bd9Sstevel@tonic-gate }
777c478bd9Sstevel@tonic-gate 
787c478bd9Sstevel@tonic-gate /*
797c478bd9Sstevel@tonic-gate  * i18n the strerror return.  Input is errno.
807c478bd9Sstevel@tonic-gate  *
817c478bd9Sstevel@tonic-gate  */
827c478bd9Sstevel@tonic-gate 
837c478bd9Sstevel@tonic-gate static char *
errno_to_i18n(int error_code)847c478bd9Sstevel@tonic-gate errno_to_i18n(int error_code) {
857c478bd9Sstevel@tonic-gate 	char	*locale;
867c478bd9Sstevel@tonic-gate 	char	*local_text;
877c478bd9Sstevel@tonic-gate 
887c478bd9Sstevel@tonic-gate 	locale = I18N_SETUP;
897c478bd9Sstevel@tonic-gate 	local_text = strerror(error_code);
907c478bd9Sstevel@tonic-gate 	(void) setlocale(LC_MESSAGES, locale);
917c478bd9Sstevel@tonic-gate 	return (local_text);
927c478bd9Sstevel@tonic-gate }
937c478bd9Sstevel@tonic-gate 
947c478bd9Sstevel@tonic-gate /*
957c478bd9Sstevel@tonic-gate  * j2c_pointer
967c478bd9Sstevel@tonic-gate  *
977c478bd9Sstevel@tonic-gate  * convert java byte array into a C pointer
987c478bd9Sstevel@tonic-gate  */
997c478bd9Sstevel@tonic-gate int
j2c_pointer(JNIEnv * env,jbyteArray jpointer,caddr_t * cpointer)1007c478bd9Sstevel@tonic-gate j2c_pointer(JNIEnv *env, jbyteArray jpointer, caddr_t *cpointer) {
1017c478bd9Sstevel@tonic-gate 	union {
1027c478bd9Sstevel@tonic-gate 		caddr_t		ptr;
1037c478bd9Sstevel@tonic-gate 		jbyte		buf[sizeof (uint64_t)];
1047c478bd9Sstevel@tonic-gate 	} u;
1057c478bd9Sstevel@tonic-gate 	size_t			jpointer_length;
1067c478bd9Sstevel@tonic-gate 	char	*locale;
1077c478bd9Sstevel@tonic-gate 
1087c478bd9Sstevel@tonic-gate 	(void) memset(u.buf, 0, sizeof (uint64_t));
1097c478bd9Sstevel@tonic-gate 
1107c478bd9Sstevel@tonic-gate 	assert(jpointer != NULL);
1117c478bd9Sstevel@tonic-gate 
1127c478bd9Sstevel@tonic-gate 	jpointer_length = (*env)->GetArrayLength(env, jpointer);
1137c478bd9Sstevel@tonic-gate 	if (jpointer_length != sizeof (uint64_t)) {
1147c478bd9Sstevel@tonic-gate 		locale = I18N_SETUP;
1157c478bd9Sstevel@tonic-gate 		local_throw(env, "java/lang/Error",
1167c478bd9Sstevel@tonic-gate 		    gettext("Bad session handle"));
1177c478bd9Sstevel@tonic-gate 		(void) setlocale(LC_MESSAGES, locale);
1187c478bd9Sstevel@tonic-gate 		return (-1);
1197c478bd9Sstevel@tonic-gate 	}
1207c478bd9Sstevel@tonic-gate 	(*env)->GetByteArrayRegion(env, jpointer, 0, jpointer_length,
1217c478bd9Sstevel@tonic-gate 	    &(u.buf[0]));
1227c478bd9Sstevel@tonic-gate 	*cpointer = (caddr_t)u.ptr;
1237c478bd9Sstevel@tonic-gate 
1247c478bd9Sstevel@tonic-gate 	return (0);
1257c478bd9Sstevel@tonic-gate }
1267c478bd9Sstevel@tonic-gate 
1277c478bd9Sstevel@tonic-gate /*
1287c478bd9Sstevel@tonic-gate  * c2j_pointer
1297c478bd9Sstevel@tonic-gate  *
1307c478bd9Sstevel@tonic-gate  * convert a C pointer into a java byte array
1317c478bd9Sstevel@tonic-gate  */
1327c478bd9Sstevel@tonic-gate void
c2j_pointer(JNIEnv * env,caddr_t cpointer,jbyteArray * jpointer)1337c478bd9Sstevel@tonic-gate c2j_pointer(JNIEnv *env, caddr_t cpointer, jbyteArray *jpointer) {
1347c478bd9Sstevel@tonic-gate 	union {
1357c478bd9Sstevel@tonic-gate 		caddr_t		ptr;
1367c478bd9Sstevel@tonic-gate 		jbyte		buf[sizeof (uint64_t)];
1377c478bd9Sstevel@tonic-gate 	} u;
1387c478bd9Sstevel@tonic-gate 
1397c478bd9Sstevel@tonic-gate 	(void) memset(u.buf, 0, sizeof (uint64_t));
1407c478bd9Sstevel@tonic-gate 	u.ptr = cpointer;
1417c478bd9Sstevel@tonic-gate 
1427c478bd9Sstevel@tonic-gate 	*jpointer = (*env)->NewByteArray(env, sizeof (uint64_t));
1437c478bd9Sstevel@tonic-gate 
1447c478bd9Sstevel@tonic-gate 	(*env)->SetByteArrayRegion(env, *jpointer, 0, sizeof (uint64_t),
1457c478bd9Sstevel@tonic-gate 	    &(u.buf[0]));
1467c478bd9Sstevel@tonic-gate }
1477c478bd9Sstevel@tonic-gate 
1487c478bd9Sstevel@tonic-gate /*
1497c478bd9Sstevel@tonic-gate  * adt_start_session wrapper
1507c478bd9Sstevel@tonic-gate  *
1517c478bd9Sstevel@tonic-gate  */
1527c478bd9Sstevel@tonic-gate /*ARGSUSED*/
1537c478bd9Sstevel@tonic-gate JNIEXPORT jbyteArray JNICALL
Java_com_sun_audit_AuditSession_startSession(JNIEnv * env,jobject cls,jbyteArray jimport,jlong flags)1547c478bd9Sstevel@tonic-gate Java_com_sun_audit_AuditSession_startSession(JNIEnv *env, jobject cls,
1557c478bd9Sstevel@tonic-gate     jbyteArray jimport, jlong flags) {
1567c478bd9Sstevel@tonic-gate 	jbyteArray		jstate;
1577c478bd9Sstevel@tonic-gate 	adt_session_data_t	*state;
1587c478bd9Sstevel@tonic-gate 	jbyte			*import;
1597c478bd9Sstevel@tonic-gate 	size_t			import_size;
1607c478bd9Sstevel@tonic-gate 	int			rc;
1617c478bd9Sstevel@tonic-gate 
1627c478bd9Sstevel@tonic-gate 	if (jimport == NULL) {
1637c478bd9Sstevel@tonic-gate 		import = NULL;
1647c478bd9Sstevel@tonic-gate 	} else {
1657c478bd9Sstevel@tonic-gate 		import_size = (*env)->GetArrayLength(env, jimport);
1667c478bd9Sstevel@tonic-gate 		import = (jbyte *)malloc(import_size * sizeof (jbyte));
1677c478bd9Sstevel@tonic-gate 		if (import == NULL) {
1687c478bd9Sstevel@tonic-gate 			local_throw(env, "java/lang/Error",
1697c478bd9Sstevel@tonic-gate 			    errno_to_i18n(errno));
1707c478bd9Sstevel@tonic-gate 			return (NULL);
1717c478bd9Sstevel@tonic-gate 		}
1727c478bd9Sstevel@tonic-gate 		(*env)->GetByteArrayRegion(env, jimport, 0, import_size,
1737c478bd9Sstevel@tonic-gate 		    import);
1747c478bd9Sstevel@tonic-gate 	}
1757c478bd9Sstevel@tonic-gate 	rc = adt_start_session(&state, (adt_export_data_t *)import, flags);
1767c478bd9Sstevel@tonic-gate 
1777c478bd9Sstevel@tonic-gate 	if (import != NULL)
1787c478bd9Sstevel@tonic-gate 		free(import);
1797c478bd9Sstevel@tonic-gate 
1807c478bd9Sstevel@tonic-gate 	if (rc) {
1817c478bd9Sstevel@tonic-gate 		local_throw(env, "java/lang/Error", errno_to_i18n(errno));
1827c478bd9Sstevel@tonic-gate 		return (NULL);
1837c478bd9Sstevel@tonic-gate 	}
1847c478bd9Sstevel@tonic-gate 	c2j_pointer(env, (caddr_t)state, &jstate);
1857c478bd9Sstevel@tonic-gate 
1867c478bd9Sstevel@tonic-gate 	return (jstate);
1877c478bd9Sstevel@tonic-gate }
1887c478bd9Sstevel@tonic-gate 
1897c478bd9Sstevel@tonic-gate /*
1907c478bd9Sstevel@tonic-gate  * adt_end_session wrapper
1917c478bd9Sstevel@tonic-gate  */
1927c478bd9Sstevel@tonic-gate 
1937c478bd9Sstevel@tonic-gate /* ARGSUSED */
1947c478bd9Sstevel@tonic-gate JNIEXPORT void JNICALL
Java_com_sun_audit_AuditSession_endSession(JNIEnv * env,jobject cls,jbyteArray jstate)1957c478bd9Sstevel@tonic-gate Java_com_sun_audit_AuditSession_endSession(JNIEnv *env, jobject cls,
1967c478bd9Sstevel@tonic-gate     jbyteArray jstate) {
1977c478bd9Sstevel@tonic-gate 	adt_session_data_t	*state;
1987c478bd9Sstevel@tonic-gate 	char	*locale;
1997c478bd9Sstevel@tonic-gate 
2007c478bd9Sstevel@tonic-gate 	if (j2c_pointer(env, jstate, (caddr_t *)&state))
2017c478bd9Sstevel@tonic-gate 		return;
2027c478bd9Sstevel@tonic-gate 
2037c478bd9Sstevel@tonic-gate 	if (state == NULL)
2047c478bd9Sstevel@tonic-gate 		return;  /* invalid session, nothing to free */
2057c478bd9Sstevel@tonic-gate 
2067c478bd9Sstevel@tonic-gate 	/* presently, no errors defined, but what the heck? */
2077c478bd9Sstevel@tonic-gate 	if (adt_end_session(state)) {
2087c478bd9Sstevel@tonic-gate 		locale = I18N_SETUP;
2097c478bd9Sstevel@tonic-gate 		local_throw(env, "java/lang/Error",
2107c478bd9Sstevel@tonic-gate 		    gettext("Bad session handle"));
2117c478bd9Sstevel@tonic-gate 		(void) setlocale(LC_MESSAGES, locale);
2127c478bd9Sstevel@tonic-gate 	}
2137c478bd9Sstevel@tonic-gate }
2147c478bd9Sstevel@tonic-gate 
2157c478bd9Sstevel@tonic-gate /*
2167c478bd9Sstevel@tonic-gate  * adt_dup_session wrapper
2177c478bd9Sstevel@tonic-gate  */
2187c478bd9Sstevel@tonic-gate 
2197c478bd9Sstevel@tonic-gate /* ARGSUSED */
2207c478bd9Sstevel@tonic-gate JNIEXPORT jbyteArray JNICALL
Java_com_sun_audit_AuditSession_dupSession(JNIEnv * env,jobject cls,jbyteArray jsource)2217c478bd9Sstevel@tonic-gate Java_com_sun_audit_AuditSession_dupSession(JNIEnv *env, jobject cls,
2227c478bd9Sstevel@tonic-gate     jbyteArray jsource) {
2237c478bd9Sstevel@tonic-gate 	jbyteArray		jdest;
2247c478bd9Sstevel@tonic-gate 	adt_session_data_t	*source, *dest;
2257c478bd9Sstevel@tonic-gate 	char	*locale;
2267c478bd9Sstevel@tonic-gate 
2277c478bd9Sstevel@tonic-gate 	if (j2c_pointer(env, jsource, (caddr_t *)&source))
2287c478bd9Sstevel@tonic-gate 		return (NULL);
2297c478bd9Sstevel@tonic-gate 
2307c478bd9Sstevel@tonic-gate 	if (adt_dup_session(source, &dest)) {
2317c478bd9Sstevel@tonic-gate 		locale = I18N_SETUP;
2327c478bd9Sstevel@tonic-gate 		local_throw(env, "java/lang/Error",
2337c478bd9Sstevel@tonic-gate 		    gettext("Out of memory"));
2347c478bd9Sstevel@tonic-gate 		(void) setlocale(LC_MESSAGES, locale);
2357c478bd9Sstevel@tonic-gate 	}
2367c478bd9Sstevel@tonic-gate 
2377c478bd9Sstevel@tonic-gate 	c2j_pointer(env, (caddr_t)dest, &jdest);
2387c478bd9Sstevel@tonic-gate 
2397c478bd9Sstevel@tonic-gate 	return (jdest);
2407c478bd9Sstevel@tonic-gate }
2417c478bd9Sstevel@tonic-gate 
2427c478bd9Sstevel@tonic-gate /*
2437c478bd9Sstevel@tonic-gate  * adt_get_session_id wrapper
2447c478bd9Sstevel@tonic-gate  *
2457c478bd9Sstevel@tonic-gate  */
2467c478bd9Sstevel@tonic-gate 
2477c478bd9Sstevel@tonic-gate /* ARGSUSED */
2487c478bd9Sstevel@tonic-gate JNIEXPORT jstring JNICALL
Java_com_sun_audit_AuditSession_getSessionId(JNIEnv * env,jobject cls,jbyteArray jstate)2497c478bd9Sstevel@tonic-gate Java_com_sun_audit_AuditSession_getSessionId(JNIEnv *env, jobject cls,
2507c478bd9Sstevel@tonic-gate     jbyteArray jstate) {
2517c478bd9Sstevel@tonic-gate 	adt_session_data_t	*state;
2527c478bd9Sstevel@tonic-gate 	char			*session_id;
2537c478bd9Sstevel@tonic-gate 	jstring			return_val;
2547c478bd9Sstevel@tonic-gate 
2557c478bd9Sstevel@tonic-gate 	if (j2c_pointer(env, jstate, (caddr_t *)&state))
2567c478bd9Sstevel@tonic-gate 		return (NULL);
2577c478bd9Sstevel@tonic-gate 
2587c478bd9Sstevel@tonic-gate 	if (adt_get_session_id(state, &session_id)) {
2597c478bd9Sstevel@tonic-gate 		return_val = (*env)->NewStringUTF(env, session_id);
2607c478bd9Sstevel@tonic-gate 		free(session_id);
2617c478bd9Sstevel@tonic-gate 		return (return_val);
2627c478bd9Sstevel@tonic-gate 	} else
2637c478bd9Sstevel@tonic-gate 		return (NULL);
2647c478bd9Sstevel@tonic-gate }
2657c478bd9Sstevel@tonic-gate 
2667c478bd9Sstevel@tonic-gate /*
2677c478bd9Sstevel@tonic-gate  * adt_get_session_id wrapper
2687c478bd9Sstevel@tonic-gate  */
2697c478bd9Sstevel@tonic-gate 
2707c478bd9Sstevel@tonic-gate /* ARGSUSED */
2717c478bd9Sstevel@tonic-gate JNIEXPORT jbyteArray JNICALL
Java_com_sun_audit_AuditSession_exportSessionData(JNIEnv * env,jobject cls,jbyteArray jstate)2727c478bd9Sstevel@tonic-gate Java_com_sun_audit_AuditSession_exportSessionData
2737c478bd9Sstevel@tonic-gate 	(JNIEnv *env, jobject cls, jbyteArray jstate) {
2747c478bd9Sstevel@tonic-gate 	adt_session_data_t	*state;
2757c478bd9Sstevel@tonic-gate 	size_t			length;
2767c478bd9Sstevel@tonic-gate 	jbyte			*buffer;
2777c478bd9Sstevel@tonic-gate 	jbyteArray		jbuf;
2787c478bd9Sstevel@tonic-gate 
2797c478bd9Sstevel@tonic-gate 	if (j2c_pointer(env, jstate, (caddr_t *)&state))
2807c478bd9Sstevel@tonic-gate 		return (NULL);
2817c478bd9Sstevel@tonic-gate 
2827c478bd9Sstevel@tonic-gate 	length = adt_export_session_data(state, (adt_export_data_t **)&buffer);
2837c478bd9Sstevel@tonic-gate 
2847c478bd9Sstevel@tonic-gate 	if ((jbuf = (*env)->NewByteArray(env, length)) == NULL) {
2857c478bd9Sstevel@tonic-gate 		free(buffer);
2867c478bd9Sstevel@tonic-gate 		return (NULL);
2877c478bd9Sstevel@tonic-gate 	}
2887c478bd9Sstevel@tonic-gate 	(*env)->SetByteArrayRegion(env, jbuf, 0, length, buffer);
2897c478bd9Sstevel@tonic-gate 	free(buffer);
2907c478bd9Sstevel@tonic-gate 
2917c478bd9Sstevel@tonic-gate 	return (jbuf);
2927c478bd9Sstevel@tonic-gate }
2937c478bd9Sstevel@tonic-gate 
2947c478bd9Sstevel@tonic-gate /* ARGSUSED */
2957c478bd9Sstevel@tonic-gate JNIEXPORT void JNICALL
Java_com_sun_audit_AuditSession_sessionAttr(JNIEnv * env,jobject cls,jbyteArray jstate,jint euid,jint egid,jint ruid,jint rgid,jstring jhostname,jint context)2967c478bd9Sstevel@tonic-gate Java_com_sun_audit_AuditSession_sessionAttr(JNIEnv *env, jobject cls,
2977c478bd9Sstevel@tonic-gate     jbyteArray jstate,
2987c478bd9Sstevel@tonic-gate     jint euid, jint egid, jint ruid, jint rgid,
2997c478bd9Sstevel@tonic-gate     jstring jhostname, jint context) {
3007c478bd9Sstevel@tonic-gate 	adt_session_data_t	*state;
3017c478bd9Sstevel@tonic-gate 	const char		*hostname;
3027c478bd9Sstevel@tonic-gate 	adt_termid_t		*termid;
3037c478bd9Sstevel@tonic-gate 
3047c478bd9Sstevel@tonic-gate 	if (j2c_pointer(env, jstate, (caddr_t *)&state))
3057c478bd9Sstevel@tonic-gate 		return;	/* j2c_pointer threw exception */
3067c478bd9Sstevel@tonic-gate 
3077c478bd9Sstevel@tonic-gate 	if (state == NULL)
3087c478bd9Sstevel@tonic-gate 		return;	/* invalid session */
3097c478bd9Sstevel@tonic-gate 
3107c478bd9Sstevel@tonic-gate 	hostname = (*env)->GetStringUTFChars(env, jhostname, NULL);
3117c478bd9Sstevel@tonic-gate 
312*33267025Sgww 	if (adt_load_hostname(hostname, &termid)) {
3137c478bd9Sstevel@tonic-gate 		local_throw(env, "java/lang/Error", errno_to_i18n(errno));
314*33267025Sgww 	} else if (adt_set_user(state, euid, egid, ruid, rgid, termid,
315*33267025Sgww 	    context)) {
316*33267025Sgww 		free(termid);
3177c478bd9Sstevel@tonic-gate 		local_throw(env, "java/lang/Error", errno_to_i18n(errno));
318*33267025Sgww 	}
3197c478bd9Sstevel@tonic-gate 	(*env)->ReleaseStringUTFChars(env, jhostname, hostname);
320*33267025Sgww 	free(termid);
3217c478bd9Sstevel@tonic-gate }
3227c478bd9Sstevel@tonic-gate 
3237c478bd9Sstevel@tonic-gate /* ARGSUSED */
3247c478bd9Sstevel@tonic-gate JNIEXPORT jboolean JNICALL
Java_com_sun_audit_AuditSession_bsmAuditOn(JNIEnv * env,jobject cls)3257c478bd9Sstevel@tonic-gate Java_com_sun_audit_AuditSession_bsmAuditOn(JNIEnv *env, jobject cls) {
3267c478bd9Sstevel@tonic-gate 	int condition;
3277c478bd9Sstevel@tonic-gate 
3287c478bd9Sstevel@tonic-gate 	if (auditon(A_GETCOND, (caddr_t)&condition, sizeof (condition)))
3297c478bd9Sstevel@tonic-gate 		return (0);
3307c478bd9Sstevel@tonic-gate 
3317c478bd9Sstevel@tonic-gate 	return (1);
3327c478bd9Sstevel@tonic-gate }
333