auditxml_jni revision cd3e933325e68e23516a196a8fea7f49b1e497c3
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, 2010, 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 # warning: time_t is equated to jlong since there is no # java long is C long long, 64 bits. my %java_jni = ('ADT_DATE' => ['long', 'jlong'], 'ADT_UINT' => ['int', 'jint'], 'ADT_INT' => ['int', 'jint'], 'ADT_INT32' => ['int', 'jint'], 'ADT_UID' => ['int', 'jint'], 'ADT_GID' => ['int', 'jint'], 'ADT_UIDSTAR' => ['int[]', 'jintArray'], 'ADT_GIDSTAR' => ['int[]', 'jintArray'], 'ADT_CHAR' => ['String', 'jchar'], 'ADT_CHARSTAR' => ['String', 'jstring'], 'ADT_CHAR2STAR' => ['String[]', 'jstring'], 'ADT_MSG' => ['int', 'jint'], 'ADT_PID' => ['int', 'jint'], # ADT_PRIVSTAR omitted -- not implemented and the audit records that # use it must be coded to emit no java. We'll cross that bridge # when someone in Java land needs to generate a priv token. 'ADT_LONG' => ['int', 'jint'], 'ADT_TERMIDSTAR' => ['String', 'jstring'], # hostname -> termid 'ADT_ULONG' => ['int', 'jint'], 'ADT_UINT16' => ['int', 'jint'], 'ADT_UINT32' => ['int', 'jint'], 'ADT_UINT32STAR' => ['int[]', 'jintArray'], # ADT_UINT32ARRAY omitted; no Java implementation yet 'ADT_UINT64' => ['long', 'jlong'], 'ADT_UINT64STAR' => ['long[]', 'jlongArray'] #include "../../libbsm/common/adt_xlate.h" #include "../com/sun/audit/AuditSession.h" /* javah output */ static char *except_class = "java/lang/Exception"; public class AuditEvent { protected AuditSession sh; // associated session object public AuditEvent(AuditSession auSession) // Manifest values: keep them in sync with generated <bsm/adt_event.h>. // It is generated by \$SRC/lib/libbsm/auditxml public static final int ADT_SUCCESS = 0; // generated public static final int ADT_FAILURE = -1; // generated // See the subclasses of AuditEvent for mapping message codes SYMBOL_VERSION SUNWprivate_1.1 { Java_com_sun_audit_AuditSession_bsmAuditOn; Java_com_sun_audit_AuditSession_startSession; Java_com_sun_audit_AuditSession_endSession; Java_com_sun_audit_AuditSession_dupSession; Java_com_sun_audit_AuditSession_getSessionId; Java_com_sun_audit_AuditSession_exportSessionData; Java_com_sun_audit_AuditSession_sessionAttr; # One subclass of AuditEvent per audit record... # generate java final int classes to line up with string/enums # generate event creation and access functions and event # generation for both Java and JNI # the subclass file template isn't used; it may be needed to get # the right file header stuff in place. The subclassPath is # the directory that contains 'em. print STDERR "can't open class file AuditEvent_$root.java: $!\n"; // audit event: $eventId = $eventCode{"AUE_$root"} public class AuditEvent_$root extends AuditEvent { "\tadt_session_data_t *session;\n"; "\tadt_session_data_t *session;\n"; if ($type eq 'ADT_UINT32STAR') { # int array length = (*env)->GetArrayLength(env, $id); (int *)malloc(length * sizeof (int)); local_throw(env, except_class, (void) setlocale(LC_MESSAGES, locale); (*env)->GetIntArrayRegion(env, $id, 0, length, } elsif (($type eq 'ADT_UIDSTAR') || ($type eq 'ADT_GIDSTAR')) { # gid_t array length = (*env)->GetArrayLength(env, $id); ($cType *)malloc(length * sizeof ($cType)); local_throw(env, except_class, (void) setlocale(LC_MESSAGES, locale); (*env)->GetIntArrayRegion(env, $id, 0, length, } elsif ($type eq 'ADT_UINT64STAR') { # long array length = (*env)->GetArrayLength(env, $id); (long *)malloc(length * sizeof (long long)); local_throw(env, except_class, (void) setlocale(LC_MESSAGES, locale); (*env)->GetLongArrayRegion(env, $id, 0, length, } elsif ($type eq 'ADT_CHAR') { # string in Java, char in C c = (char *)(*env)->GetStringUTFChars(env, $id, NULL); goto cleanup; /* exception thrown */ (*env)->ReleaseStringUTFChars(env, $id, c); # no need to free anything } elsif ($type eq 'ADT_CHARSTAR') { string = (char *)(*env)->GetStringUTFChars( goto cleanup; /* exception thrown */ $p_event = strdup(string); (*env)->ReleaseStringUTFChars(env, $id, string); local_throw(env, except_class, (void) setlocale(LC_MESSAGES, locale); } elsif ($type eq 'ADT_CHAR2STAR') { # array of string length = (*env)->GetArrayLength(env, $id); $p_event = (char **)malloc(length local_throw(env, except_class, (void) setlocale(LC_MESSAGES, locale); for (i = 0; i < length; i++) { jString = (*env)->GetObjectArrayElement(env, $id, i); string = (char *)(*env)->GetStringUTFChars( goto cleanup; /* exception thrown */ (*env)->ReleaseStringUTFChars(env, jString, string); local_throw(env, except_class, (void) setlocale(LC_MESSAGES, locale); } elsif ($type eq 'ADT_TERMIDSTAR') { hostname$cntTermidDef = (char *)(*env)->GetStringUTFChars(env, $id, NULL); if (adt_load_hostname((const char *)hostname$cntTermidDef, &termid$cntTermidDef)) { local_throw(env, except_class, gettext("hostname lookup failed")); $p_event = termid$cntTermidDef; (*env)->ReleaseStringUTFChars(env, $id, hostname$cntTermidDef); } else { # all others are primitive types print Sfile "\t// Allowed values for eventId in putEvent:\n"; for ($i = 0; $i <= $#allowed; $i++) { private native void $javaPutEvent(byte[]session, $overrideParameter int status, int ret_val$nativeParameterList); public AuditEvent_$root(AuditSession session) # generate java native method prototypes # and the corresponding C method implementation ($type eq 'ADT_GIDSTAR')) { # int array } elsif ($type eq 'ADT_UINT64STAR') { # long array } elsif (($type eq 'ADT_CHARSTAR') || } elsif ($type eq 'ADT_CHAR2STAR') { # array of string } elsif ($type eq 'ADT_TERMIDSTAR') { # array of string } else { # all others are primitive types private $storage;$comment public void $javaMethodName($jParam setTo) $javaStorageName = setTo; } # end foreach (@entries) public void putEvent(int status, int ret_val, int eventId) byte[] session = super.sh.getSession(); if ((super.sh.AuditIsOn) && (super.sh.ValidSession)) $javaPutEvent(session, eventId, status, ret_val$javaParameterList); public void putEvent(int status, int ret_val) byte[] session = super.sh.getSession(); if ((super.sh.AuditIsOn) && (super.sh.ValidSession)) $javaPutEvent(session, status, ret_val$javaParameterList); } # end if ($validSfile); 'arbitrary' => 'AUT_ARBITRARY', 'command_1' => 'ADT_CMD_ALT', # dummy token id 'exec_args' => 'AUT_EXEC_ARGS', 'exec_env' => 'AUT_EXEC_ENV', 'groups' => 'AUT_GROUPS', # 'header' => 'AUT_HEADER', # not used 'in_addr' => 'AUT_IN_ADDR', 'ipc_perm' => 'AUT_IPC_PERM', 'newgroups' => 'AUT_NEWGROUPS', 'opaque' => 'AUT_OPAQUE', 'path_list' => '-AUT_PATH', # dummy token id 'process' => 'AUT_PROCESS', 'priv_effective' => 'ADT_AUT_PRIV_E', # dummy token id 'priv_limit' => 'ADT_AUT_PRIV_L', # dummy token id 'priv_inherit' => 'ADT_AUT_PRIV_I', # dummy token id 'return' => 'AUT_RETURN', 'socket' => 'AUT_SOCKET', 'socket-inet' => 'AUT_SOCKET_INET', 'subject' => 'AUT_SUBJECT', # 'trailer' => 'AUT_TRAILER', # not used 'zonename' => 'AUT_ZONENAME' # needs to be used by translate table my $i; # walk down the inputOrder list once my $k = 1; # discover next in line my $l = 0; # who should point to next in line else { # default order -- input order same as output $dataType =~ s/\s+//g; # remove blanks (char * => char*) # does this map belong in the xml source? (at least the defaults?) # fill in the default value only if it is other than zero. # base type adt name, default value my %entryDef = ( 'au_asid_t' => ['ADT_UINT32', ''], 'uint_t' => ['ADT_UINT32', ''], 'int' => ['ADT_INT', ''], 'int32_t' => ['ADT_INT32', ''], 'uid_t' => ['ADT_UID', 'AU_NOAUDITID'], 'gid_t' => ['ADT_GID', 'AU_NOAUDITID'], 'uid_t*' => ['ADT_UIDSTAR', ''], 'gid_t*' => ['ADT_GIDSTAR', ''], 'char' => ['ADT_CHAR', ''], 'char*' => ['ADT_CHARSTAR', ''], 'char**' => ['ADT_CHAR2STAR', ''], 'long' => ['ADT_LONG', ''], 'pid_t' => ['ADT_PID', ''], 'priv_set_t*' => ['ADT_PRIVSTAR', ''], 'ulong_t' => ['ADT_ULONG', ''], 'uint16_t', => ['ADT_UINT16', ''], 'uint32_t' => ['ADT_UINT32', ''], 'uint32_t*' => ['ADT_UINT32STAR', ''], 'uint32_t[]' => ['ADT_UINT32ARRAY', ''], 'uint64_t' => ['ADT_UINT64', ''], 'uint64_t*' => ['ADT_UINT64STAR', ''], 'm_label_t*' => ['ADT_MLABELSTAR', ''], # the list handling should be a simple loop with a loop of one unless ($type =~ /,/) { # if list, then generate sequence of entries $type =~ s/([^*]+)\s*(\*+)/$1 $2/; print STDERR "$type is not an implemented data type\n"; # "EOL" is where a comma should go unless end of list $type =~ s/([^*]+)\s*(\*+)/$1 $2/;