2N/A# The contents of this file are subject to the terms of the 2N/A# Common Development and Distribution License (the "License"). 2N/A# You may not use this file except in compliance with the License. 2N/A# See the License for the specific language governing permissions 2N/A# and limitations under the License. 2N/A# When distributing Covered Code, include this CDDL HEADER in each 2N/A# If applicable, add the following below this CDDL HEADER, with the 2N/A# fields enclosed by brackets "[]" replaced with your own identifying 2N/A# information: Portions Copyright [yyyy] [name of copyright owner] 2N/A# Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved. 2N/A# auditxml_jni [-d] <xml input file> 2N/A# auditxml takes the audit record description (.xml file) and 2N/A# generates the files needed for the Java 2N/Aour $debug =
0;
# normal use is to set via the file being parsed. 2N/A # <debug set="on"/> or <debug set="off"/> or <debug/> 2N/A # if the set attribute is omitted, debug state is toggled 2N/A # Override with appDebug, but toggle won't do what you 2N/ADO NOT EDIT. This file is auto generated by the Solaris Audit 2N/A# where everything comes from and where it goes: 2N/A # c file table for translation 2N/A # warning: time_t is equated to jlong since there is no 2N/A # java long is C long long, 64 bits. 2N/A # java int is 32 bits. 2N/A 'ADT_UINT' => ['int', 'jint'], 2N/A 'ADT_INT' => ['int', 'jint'], 2N/A 'ADT_INT32' => ['int', 'jint'], 2N/A 'ADT_UID' => ['int', 'jint'], 2N/A 'ADT_GID' => ['int', 'jint'], 2N/A 'ADT_UIDSTAR' => ['int[]', 'jintArray'], 2N/A 'ADT_GIDSTAR' => ['int[]', 'jintArray'], 2N/A 'ADT_CHAR' => ['String', 'jchar'], 2N/A 'ADT_CHARSTAR' => ['String', 'jstring'], 2N/A 'ADT_CHAR2STAR' => ['String[]', 'jstring'], 2N/A 'ADT_MSG' => ['int', 'jint'], 2N/A 'ADT_PID' => ['int', 'jint'], 2N/A# ADT_PRIVSTAR omitted -- not implemented and the audit records that 2N/A# use it must be coded to emit no java. We'll cross that bridge 2N/A# when someone in Java land needs to generate a priv token. 2N/A 'ADT_LONG' => ['int', 'jint'], 2N/A 'ADT_TERMIDSTAR' => ['String', 'jstring'], # hostname -> termid 2N/A 'ADT_ULONG' => ['int', 'jint'], 2N/A 'ADT_UINT16' => ['int', 'jint'], 2N/A 'ADT_UINT32' => ['int', 'jint'], 2N/A 'ADT_UINT32STAR' => ['int[]', 'jintArray'], 2N/A# ADT_UINT32ARRAY omitted; no Java implementation yet 2N/A 'ADT_UINT64' => ['long', 'jlong'], 2N/A 'ADT_UINT64STAR' => ['long[]', 'jlongArray'] 2N/A#include "../../libbsm/common/adt_xlate.h" 2N/A#include "../com/sun/audit/AuditSession.h" /* javah output */ 2N/Astatic char *except_class = "java/lang/Exception"; 2N/Apackage com.sun.audit; 2N/Apublic class AuditEvent { 2N/A protected AuditSession sh; // associated session object 2N/A public AuditEvent(AuditSession auSession) 2N/A // Manifest values: keep them in sync with generated <bsm/adt_event.h>. 2N/A // It is generated by \$SRC/lib/libbsm/auditxml 2N/A public static final int ADT_SUCCESS = 0; // generated 2N/A public static final int ADT_FAILURE = -1; // generated 2N/A // See the subclasses of AuditEvent for mapping message codes 2N/ASYMBOL_VERSION SUNWprivate_1.1 { 2N/A Java_com_sun_audit_AuditSession_bsmAuditOn; 2N/A Java_com_sun_audit_AuditSession_startSession; 2N/A Java_com_sun_audit_AuditSession_endSession; 2N/A Java_com_sun_audit_AuditSession_dupSession; 2N/A Java_com_sun_audit_AuditSession_getSessionId; 2N/A Java_com_sun_audit_AuditSession_exportSessionData; 2N/A Java_com_sun_audit_AuditSession_sessionAttr; 2N/A# One subclass of AuditEvent per audit record... 2N/A # generate event creation and access functions and event 2N/A # generation for both Java and JNI 2N/A # the subclass file template isn't used; it may be needed to get 2N/A # the right file header stuff in place. The subclassPath is 2N/A # the directory that contains 'em. 2N/Apackage com.sun.audit; 2N/A// audit event: $eventId = $eventCode{"AUE_$root"} 2N/Apublic class AuditEvent_$root extends AuditEvent { 2N/A "\tadt_session_data_t *session;\n"; 2N/A "\tadt_session_data_t *session;\n"; 2N/A length = (*env)->GetArrayLength(env, $id); 2N/A (int *)malloc(length * sizeof (int)); 2N/A if ($p_event == NULL) { 2N/A locale = I18N_SETUP; 2N/A local_throw(env, except_class, 2N/A (void) setlocale(LC_MESSAGES, locale); 2N/A (*env)->GetIntArrayRegion(env, $id, 0, length, 2N/A length = (*env)->GetArrayLength(env, $id); 2N/A ($cType *)malloc(length * sizeof ($cType)); 2N/A if ($p_event == NULL) { 2N/A locale = I18N_SETUP; 2N/A local_throw(env, except_class, 2N/A (void) setlocale(LC_MESSAGES, locale); 2N/A (*env)->GetIntArrayRegion(env, $id, 0, length, 2N/A } elsif ($type eq 'ADT_UINT64STAR') { # long array 2N/A length = (*env)->GetArrayLength(env, $id); 2N/A (long *)malloc(length * sizeof (long long)); 2N/A if ($p_event == NULL) { 2N/A locale = I18N_SETUP; 2N/A local_throw(env, except_class, 2N/A (void) setlocale(LC_MESSAGES, locale); 2N/A (*env)->GetLongArrayRegion(env, $id, 0, length, 2N/A } elsif ($type eq 'ADT_CHAR') { # string in Java, char in C 2N/A c = (char *)(*env)->GetStringUTFChars(env, $id, NULL); 2N/A goto cleanup; /* exception thrown */ 2N/A (*env)->ReleaseStringUTFChars(env, $id, c); 2N/A # no need to free anything 2N/A string = (char *)(*env)->GetStringUTFChars( 2N/A goto cleanup; /* exception thrown */ 2N/A $p_event = strdup(string); 2N/A (*env)->ReleaseStringUTFChars(env, $id, string); 2N/A if ($p_event == NULL) { 2N/A locale = I18N_SETUP; 2N/A local_throw(env, except_class, 2N/A (void) setlocale(LC_MESSAGES, locale); 2N/A } elsif ($type eq 'ADT_CHAR2STAR') { # array of string 2N/A length = (*env)->GetArrayLength(env, $id); 2N/A $p_event = (char **)malloc(length 2N/A if ($p_event == NULL) { 2N/A locale = I18N_SETUP; 2N/A local_throw(env, except_class, 2N/A (void) setlocale(LC_MESSAGES, locale); 2N/A for (i = 0; i < length; i++) { 2N/A jString = (*env)->GetObjectArrayElement(env, $id, i); 2N/A string = (char *)(*env)->GetStringUTFChars( 2N/A env, jString, NULL); 2N/A goto cleanup; /* exception thrown */ 2N/A *p = strdup(string); 2N/A (*env)->ReleaseStringUTFChars(env, jString, string); 2N/A locale = I18N_SETUP; 2N/A local_throw(env, except_class, 2N/A (void) setlocale(LC_MESSAGES, locale); 2N/A while (p >= $p_event) 2N/A hostname$cntTermidDef = (char *)(*env)->GetStringUTFChars(env, $id, NULL); 2N/A if (adt_load_hostname((const char *)hostname$cntTermidDef, &termid$cntTermidDef)) { 2N/A local_throw(env, except_class, 2N/A gettext("hostname lookup failed")); 2N/A $p_event = termid$cntTermidDef; 2N/A (*env)->ReleaseStringUTFChars(env, $id, hostname$cntTermidDef); 2N/A } else { # all others are primitive types 2N/A print Sfile "\t// Allowed values for eventId in putEvent:\n"; 2N/A private native void $javaPutEvent(byte[]session, $overrideParameter 2N/A int status, int ret_val$nativeParameterList); 2N/A public AuditEvent_$root(AuditSession session) 2N/A # generate java native method prototypes 2N/A # and the corresponding C method implementation 2N/A } elsif ($type eq 'ADT_UINT64STAR') { # long array 2N/A } elsif ($type eq 'ADT_CHAR2STAR') { # array of string 2N/A } elsif ($type eq 'ADT_TERMIDSTAR') { # array of string 2N/A } else { # all others are primitive types 2N/A private $storage;$comment 2N/A public void $javaMethodName($jParam setTo) 2N/A $javaStorageName = setTo; 2N/A } # end foreach (@entries) 2N/A public void putEvent(int status, int ret_val, int eventId) 2N/A byte[] session = super.sh.getSession(); 2N/A if ((super.sh.AuditIsOn) && (super.sh.ValidSession)) 2N/A $javaPutEvent(session, eventId, 2N/A status, ret_val$javaParameterList); 2N/A public void putEvent(int status, int ret_val) 2N/A byte[] session = super.sh.getSession(); 2N/A if ((super.sh.AuditIsOn) && (super.sh.ValidSession)) 2N/A $javaPutEvent(session, status, ret_val$javaParameterList); 2N/A } # end if ($validSfile); 2N/A 'arbitrary' => 'AUT_ARBITRARY', 2N/A 'attr' => 'AUT_ATTR', 2N/A 'command' => 'AUT_CMD', 2N/A 'command_1' => 'ADT_CMD_ALT', # dummy token id 2N/A 'date' => 'AUT_TEXT', 2N/A 'exec_args' => 'AUT_EXEC_ARGS', 2N/A 'exec_env' => 'AUT_EXEC_ENV', 2N/A 'exit' => 'AUT_EXIT', 2N/A 'file' => 'AUT_FILE', 2N/A 'fmri' => 'AUT_FMRI', 2N/A 'groups' => 'AUT_GROUPS', 2N/A # 'header' => 'AUT_HEADER', # not used 2N/A 'in_addr' => 'AUT_IN_ADDR', 2N/A 'ipc_perm' => 'AUT_IPC_PERM', 2N/A 'iport' => 'AUT_IPORT', 2N/A 'label' => 'AUT_LABEL', 2N/A 'newgroups' => 'AUT_NEWGROUPS', 2N/A 'opaque' => 'AUT_OPAQUE', 2N/A 'path' => 'AUT_PATH', 2N/A 'path_list' => '-AUT_PATH', # dummy token id 2N/A 'process' => 'AUT_PROCESS', 2N/A 'priv_effective' => 'ADT_AUT_PRIV_E', # dummy token id 2N/A 'priv_limit' => 'ADT_AUT_PRIV_L', # dummy token id 2N/A 'priv_inherit' => 'ADT_AUT_PRIV_I', # dummy token id 2N/A 'return' => 'AUT_RETURN', 2N/A 'socket' => 'AUT_SOCKET', 2N/A 'socket-inet' => 'AUT_SOCKET_INET', 2N/A 'subject' => 'AUT_SUBJECT', 2N/A 'text' => 'AUT_TEXT', 2N/A # 'trailer' => 'AUT_TRAILER', # not used 2N/A 'uauth' => 'AUT_UAUTH', 2N/A 'user' => 'AUT_USER', 2N/A 'zonename' => 'AUT_ZONENAME' 2N/A # needs to be used by translate table 2N/A my $i; # walk down the inputOrder list once 2N/A my $k = 1; # discover next in line 2N/A my $l = 0; # who should point to next in line 2N/A else { # default order -- input order same as output 2N/A # does this map belong in the xml source? (at least the defaults?) 2N/A # fill in the default value only if it is other than zero. 2N/A # base type adt name, default value 2N/A 'uint_t' => ['ADT_UINT32', ''], 2N/A 'int' => ['ADT_INT', ''], 2N/A 'int32_t' => ['ADT_INT32', ''], 2N/A 'uid_t' => ['ADT_UID', 'AU_NOAUDITID'], 2N/A 'gid_t' => ['ADT_GID', 'AU_NOAUDITID'], 2N/A 'uid_t*' => ['ADT_UIDSTAR', ''], 2N/A 'gid_t*' => ['ADT_GIDSTAR', ''], 2N/A 'char' => ['ADT_CHAR', ''], 2N/A 'char*' => ['ADT_CHARSTAR', ''], 2N/A 'char**' => ['ADT_CHAR2STAR', ''], 2N/A 'long' => ['ADT_LONG', ''], 2N/A 'pid_t' => ['ADT_PID', ''], 2N/A 'priv_set_t*' => ['ADT_PRIVSTAR', ''], 2N/A 'ulong_t' => ['ADT_ULONG', ''], 2N/A 'uint16_t', => ['ADT_UINT16', ''], 2N/A 'uint32_t' => ['ADT_UINT32', ''], 2N/A 'uint32_t*' => ['ADT_UINT32STAR', ''], 2N/A 'uint32_t[]' => ['ADT_UINT32ARRAY', ''], 2N/A 'uint64_t' => ['ADT_UINT64', ''], 2N/A 'uint64_t*' => ['ADT_UINT64STAR', ''], 2N/A 'm_label_t*' => ['ADT_MLABELSTAR', ''], 2N/A # the list handling should be a simple loop with a loop of one 2N/A # falling out naturally. 2N/A # "EOL" is where a comma should go unless end of list 2N/A } else { # is a list