xdas_stub.c

Go to the documentation of this file.
00001 /*----------------------------------------------------------------------------
00002  * Copyright (c) 2006, Novell, Inc.
00003  * All rights reserved.
00004  * 
00005  * Redistribution and use in source and binary forms, with or without 
00006  * modification, are permitted provided that the following conditions are 
00007  * met:
00008  * 
00009  *     * Redistributions of source code must retain the above copyright 
00010  *       notice, this list of conditions and the following disclaimer.
00011  *     * Redistributions in binary form must reproduce the above copyright 
00012  *       notice, this list of conditions and the following disclaimer in the 
00013  *       documentation and/or other materials provided with the distribution.
00014  *     * Neither the name of the Novell nor the names of its contributors 
00015  *       may be used to endorse or promote products derived from this 
00016  *       software without specific prior written permission.
00017  * 
00018  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
00019  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
00020  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
00021  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 
00022  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
00023  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
00024  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
00025  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 
00026  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 
00027  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 
00028  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00029  *--------------------------------------------------------------------------*/
00030 
00044 #define XDAS_STATIC
00045 #include <xdas.h>
00046 
00047 #ifdef _WIN32
00048 # define WIN32_LEAN_AND_MEAN
00049 # include <windows.h>
00050 # define libhandle_t HANDLE
00051 # define LOAD_LIBRARY(n)      LoadLibraryA(n)
00052 # define FREE_LIBRARY(h)      FreeLibrary((h))
00053 # define IMPORT_SYMBOL(h,n)   (fptr_t)GetProcAddress((h),(n))
00054 # define LN_XDAS_CLIENT       "libxdas.dll"
00055 #else
00056 # include <config.h>
00057 # ifndef HAVE_DLFCN_H
00058 #  error Unable to build the stub library without dynamic linking.
00059 # endif
00060 # include <dlfcn.h>
00061 # define libhandle_t void *
00062 # define LOAD_LIBRARY(n)      dlopen((n), RTLD_NOW)
00063 # define FREE_LIBRARY(h)      dlclose((h))
00064 # define IMPORT_SYMBOL(h,n)   (fptr_t)dlsym((h),(n))
00065 # define LN_XDAS_CLIENT       "libxdas.so"
00066 #endif
00067 
00068 /* this set of names works for windows and linux - perhaps others... */
00069 
00070 #define FN_XDAS_INITIALIZE_SESSION     "xdas_initialize_session"
00071 #define FN_XDAS_TERMINATE_SESSION      "xdas_terminate_session"
00072 #define FN_XDAS_CLOSE_AUDIT_STREAM     "xdas_close_audit_stream"
00073 #define FN_XDAS_GET_NEXT               "xdas_get_next"
00074 #define FN_XDAS_OPEN_AUDIT_STREAM      "xdas_open_audit_stream"
00075 #define FN_XDAS_PARSE_RECORD           "xdas_parse_record"
00076 #define FN_XDAS_REWIND_AUDIT_STREAM    "xdas_rewind_audit_stream"
00077 #define FN_XDAS_IMPORT_EVENT_RECORDS   "xdas_import_event_records"
00078 #define FN_XDAS_COMMIT_RECORD          "xdas_commit_record"
00079 #define FN_XDAS_DISCARD_RECORD         "xdas_discard_record"
00080 #define FN_XDAS_PUT_EVENT_INFO         "xdas_put_event_info"
00081 #define FN_XDAS_START_RECORD           "xdas_start_record"
00082 #define FN_XDAS_TIMESTAMP_RECORD       "xdas_timestamp_record"
00083 #define FN_XDAS_CREATE_FILTER          "xdas_create_filter"
00084 #define FN_XDAS_DELETE_FILTER          "xdas_delete_filter"
00085 #define FN_XDAS_DISABLE_FILTER         "xdas_disable_filter"
00086 #define FN_XDAS_ENABLE_FILTER          "xdas_enable_filter"
00087 #define FN_XDAS_GET_FILTER             "xdas_get_filter"
00088 #define FN_XDAS_LIST_FILTERS           "xdas_list_filters"
00089 
00090 typedef void (*fptr_t)(void);
00091 
00092 typedef struct
00093 {
00094    const char * fname;
00095    fptr_t * fpp;
00096 } fptable_t;
00097 
00098 typedef int XDASAPI xdas_initialize_session_t(int * minor_status, const char * org_info, xdas_audit_ref_t * das_ref);
00099 typedef int XDASAPI xdas_terminate_session_t(int * minor_status, xdas_audit_ref_t * das_ref);
00100 typedef int XDASAPI xdas_close_audit_stream_t(int * minor_status, xdas_audit_ref_t das_ref, xdas_audit_stream_t * audit_stream_ref);
00101 typedef int XDASAPI xdas_get_next_t(int * minor_status, xdas_audit_ref_t das_ref, xdas_audit_stream_t audit_stream_ref, unsigned max_records, xdas_buffer_t audit_record_buffer, unsigned * no_of_records);
00102 typedef int XDASAPI xdas_open_audit_stream_t(int * minor_status, xdas_audit_ref_t das_ref, xdas_audit_stream_t * audit_stream_ref); 
00103 typedef int XDASAPI xdas_parse_record_t(int * minor_status, xdas_audit_ref_t das_ref, xdas_buffer_t audit_record_buffer, unsigned record_number, xdas_audit_record_t audit_record);
00104 typedef int XDASAPI xdas_rewind_audit_stream_t(int * minor_status, xdas_audit_ref_t das_ref, xdas_audit_stream_t audit_stream_ref); 
00105 typedef int XDASAPI xdas_import_event_records_t(int * minor_status, xdas_audit_ref_t das_ref, xdas_buffer_t audit_record_buffer, size_t * position_in_buffer);
00106 typedef int XDASAPI xdas_commit_record_t(int * minor_status, xdas_audit_ref_t das_ref, xdas_audit_rec_desc_t * audit_record_descriptor); 
00107 typedef int XDASAPI xdas_discard_record_t(int * minor_status, xdas_audit_ref_t das_ref, xdas_audit_rec_desc_t * audit_record_descriptor);
00108 typedef int XDASAPI xdas_put_event_info_t(int * minor_status, xdas_audit_ref_t das_ref, xdas_audit_rec_desc_t * audit_record_descriptor, unsigned event_number, unsigned outcome, const char * initiator_information, const char * target_information, const char * event_information);
00109 typedef int XDASAPI xdas_start_record_t(int * minor_status, xdas_audit_ref_t das_ref, xdas_audit_rec_desc_t * audit_record_descriptor, unsigned event_number, unsigned outcome, const char * initiator_information, const char * target_information, const char * event_information);
00110 typedef int XDASAPI xdas_timestamp_record_t(int * minor_status, xdas_audit_ref_t das_ref, xdas_audit_rec_desc_t audit_record_descriptor); 
00111 typedef int XDASAPI xdas_create_filter_t(int * minor_status, xdas_audit_ref_t das_ref, const char * name, unsigned filter_type, const char * filter_exp, const char * filter_act);
00112 typedef int XDASAPI xdas_delete_filter_t(int * minor_status, xdas_audit_ref_t das_ref, const char * name);
00113 typedef int XDASAPI xdas_disable_filter_t(int * minor_status, xdas_audit_ref_t das_ref, const char * name); 
00114 typedef int XDASAPI xdas_enable_filter_t(int * minor_status, xdas_audit_ref_t das_ref, const char * name);
00115 typedef int XDASAPI xdas_get_filter_t(int * minor_status, xdas_audit_ref_t das_ref, const char * name, unsigned * filter_type, xdas_buffer_t filter_exp, xdas_buffer_t filter_act, unsigned * filter_status);
00116 typedef int XDASAPI xdas_list_filters_t(int * minor_status, xdas_audit_ref_t das_ref, char ** filter_name_list, size_t * buffer_size);
00117 
00118 static xdas_initialize_session_t * fp_xdas_initialize_session;
00119 static xdas_terminate_session_t * fp_xdas_terminate_session;
00120 static xdas_close_audit_stream_t * fp_xdas_close_audit_stream;
00121 static xdas_get_next_t * fp_xdas_get_next;
00122 static xdas_open_audit_stream_t * fp_xdas_open_audit_stream;
00123 static xdas_parse_record_t * fp_xdas_parse_record;
00124 static xdas_rewind_audit_stream_t * fp_xdas_rewind_audit_stream;
00125 static xdas_import_event_records_t * fp_xdas_import_event_records;
00126 static xdas_commit_record_t * fp_xdas_commit_record;
00127 static xdas_discard_record_t * fp_xdas_discard_record;
00128 static xdas_put_event_info_t * fp_xdas_put_event_info;
00129 static xdas_start_record_t * fp_xdas_start_record;
00130 static xdas_timestamp_record_t * fp_xdas_timestamp_record;
00131 static xdas_create_filter_t * fp_xdas_create_filter;
00132 static xdas_delete_filter_t * fp_xdas_delete_filter;
00133 static xdas_disable_filter_t * fp_xdas_disable_filter;
00134 static xdas_enable_filter_t * fp_xdas_enable_filter;
00135 static xdas_get_filter_t * fp_xdas_get_filter;
00136 static xdas_list_filters_t * fp_xdas_list_filters;
00137 
00138 static fptable_t xdas_ftable[] = {
00139    {FN_XDAS_INITIALIZE_SESSION,     (fptr_t*)&fp_xdas_initialize_session},
00140    {FN_XDAS_TERMINATE_SESSION,      (fptr_t*)&fp_xdas_terminate_session},
00141    {FN_XDAS_CLOSE_AUDIT_STREAM,     (fptr_t*)&fp_xdas_close_audit_stream},
00142    {FN_XDAS_GET_NEXT,               (fptr_t*)&fp_xdas_get_next},
00143    {FN_XDAS_OPEN_AUDIT_STREAM,      (fptr_t*)&fp_xdas_open_audit_stream},
00144    {FN_XDAS_PARSE_RECORD,           (fptr_t*)&fp_xdas_parse_record},
00145    {FN_XDAS_REWIND_AUDIT_STREAM,    (fptr_t*)&fp_xdas_rewind_audit_stream},
00146    {FN_XDAS_IMPORT_EVENT_RECORDS,   (fptr_t*)&fp_xdas_import_event_records},
00147    {FN_XDAS_COMMIT_RECORD,          (fptr_t*)&fp_xdas_commit_record},
00148    {FN_XDAS_DISCARD_RECORD,         (fptr_t*)&fp_xdas_discard_record},
00149    {FN_XDAS_PUT_EVENT_INFO,         (fptr_t*)&fp_xdas_put_event_info},
00150    {FN_XDAS_START_RECORD,           (fptr_t*)&fp_xdas_start_record},
00151    {FN_XDAS_TIMESTAMP_RECORD,       (fptr_t*)&fp_xdas_timestamp_record},
00152    {FN_XDAS_CREATE_FILTER,          (fptr_t*)&fp_xdas_create_filter},
00153    {FN_XDAS_DELETE_FILTER,          (fptr_t*)&fp_xdas_delete_filter},
00154    {FN_XDAS_DISABLE_FILTER,         (fptr_t*)&fp_xdas_disable_filter},
00155    {FN_XDAS_ENABLE_FILTER,          (fptr_t*)&fp_xdas_enable_filter},
00156    {FN_XDAS_GET_FILTER,             (fptr_t*)&fp_xdas_get_filter},
00157    {FN_XDAS_LIST_FILTERS,           (fptr_t*)&fp_xdas_list_filters},
00158 };
00159 
00160 static libhandle_t xdas_lib_handle = 0;
00161 
00164 static void unload_xdas_client(void)
00165 {
00166    FREE_LIBRARY(xdas_lib_handle);
00167    xdas_lib_handle = 0;
00168 }
00169 
00172 static void load_xdas_client(void)
00173 {
00174    if (xdas_lib_handle == 0 
00175          && (xdas_lib_handle = LOAD_LIBRARY(LN_XDAS_CLIENT)) != 0)
00176    {
00177       int i;
00178       for (i = 0; i < sizeof(xdas_ftable)/sizeof(*xdas_ftable); i++)
00179          if ((*xdas_ftable[i].fpp = IMPORT_SYMBOL(xdas_lib_handle, 
00180                   xdas_ftable[i].fname)) == 0)
00181          {
00182             unload_xdas_client();
00183             break;
00184          }
00185    }
00186 }
00187 
00188 /*---------------------------------------------------------------------------
00189  */
00190 XDASXPC int XDASAPI xdas_initialize_session(
00191       int * minor_status,
00192       const char * org_info,
00193       xdas_audit_ref_t * das_ref)
00194 {
00195    if (xdas_lib_handle == 0)
00196       load_xdas_client();
00197    return xdas_lib_handle == 0? XDAS_S_SERVICE_FAILURE
00198          : fp_xdas_initialize_session(minor_status, org_info, das_ref);
00199 }
00200 
00201 /*---------------------------------------------------------------------------
00202  */
00203 XDASXPC int XDASAPI xdas_terminate_session(
00204       int * minor_status,
00205       xdas_audit_ref_t * das_ref)
00206 {
00207    int rv = 0;
00208    if (xdas_lib_handle != 0)
00209    {
00210       rv = xdas_lib_handle == 0? XDAS_S_SERVICE_FAILURE
00211             : fp_xdas_terminate_session(minor_status, das_ref);
00212       unload_xdas_client();
00213    }
00214    return rv;
00215 }
00216 
00217 /*---------------------------------------------------------------------------
00218  */
00219 XDASXPC int XDASAPI xdas_close_audit_stream(
00220       int * minor_status,
00221       xdas_audit_ref_t das_ref,
00222       xdas_audit_stream_t * audit_stream_ref)
00223 {
00224    return xdas_lib_handle == 0? XDAS_S_SERVICE_FAILURE
00225          : fp_xdas_close_audit_stream(minor_status, das_ref, 
00226                audit_stream_ref);
00227 }
00228 
00229 /*---------------------------------------------------------------------------
00230  */
00231 XDASXPC int XDASAPI xdas_get_next(
00232       int * minor_status,
00233       xdas_audit_ref_t das_ref,
00234       xdas_audit_stream_t audit_stream_ref,
00235       unsigned max_records,
00236       xdas_buffer_t audit_record_buffer,
00237       unsigned * no_of_records)
00238 {
00239    return xdas_lib_handle == 0? XDAS_S_SERVICE_FAILURE
00240          : fp_xdas_get_next(minor_status, das_ref, audit_stream_ref, 
00241                max_records, audit_record_buffer, no_of_records);
00242 }
00243 
00244 /*---------------------------------------------------------------------------
00245  */
00246 XDASXPC int XDASAPI xdas_open_audit_stream(
00247       int * minor_status,
00248       xdas_audit_ref_t das_ref,
00249       xdas_audit_stream_t * audit_stream_ref)
00250 {
00251    return xdas_lib_handle == 0? XDAS_S_SERVICE_FAILURE
00252          : fp_xdas_open_audit_stream(minor_status, das_ref, 
00253                audit_stream_ref);
00254 }
00255 
00256 /*---------------------------------------------------------------------------
00257  */
00258 XDASXPC int XDASAPI xdas_parse_record(
00259       int * minor_status,
00260       xdas_audit_ref_t das_ref,
00261       xdas_buffer_t audit_record_buffer,
00262       unsigned record_number,
00263       xdas_audit_record_t audit_record)
00264 {
00265    return xdas_lib_handle == 0? XDAS_S_SERVICE_FAILURE
00266          : fp_xdas_parse_record(minor_status, das_ref, 
00267                audit_record_buffer, record_number, audit_record);
00268 }
00269 
00270 /*---------------------------------------------------------------------------
00271  */
00272 XDASXPC int XDASAPI xdas_rewind_audit_stream(
00273       int * minor_status,
00274       xdas_audit_ref_t das_ref,
00275       xdas_audit_stream_t audit_stream_ref)
00276 {
00277    return xdas_lib_handle == 0? XDAS_S_SERVICE_FAILURE
00278          : fp_xdas_rewind_audit_stream(minor_status, das_ref, 
00279                audit_stream_ref);
00280 }
00281 
00282 /*---------------------------------------------------------------------------
00283  */
00284 XDASXPC int XDASAPI xdas_import_event_records(
00285       int * minor_status,
00286       xdas_audit_ref_t das_ref,
00287       xdas_buffer_t audit_record_buffer,
00288       size_t * position_in_buffer)
00289 {
00290    return xdas_lib_handle == 0? XDAS_S_SERVICE_FAILURE
00291          : fp_xdas_import_event_records(minor_status, das_ref, 
00292                audit_record_buffer, position_in_buffer);
00293 }
00294 
00295 /*---------------------------------------------------------------------------
00296  */
00297 XDASXPC int XDASAPI xdas_commit_record(
00298       int * minor_status,
00299       xdas_audit_ref_t das_ref,
00300       xdas_audit_rec_desc_t * audit_record_descriptor)
00301 {
00302    return xdas_lib_handle == 0? XDAS_S_SERVICE_FAILURE
00303          : fp_xdas_commit_record(minor_status, das_ref, 
00304                audit_record_descriptor);
00305 }
00306 
00307 /*---------------------------------------------------------------------------
00308  */
00309 XDASXPC int XDASAPI xdas_discard_record(
00310       int * minor_status,
00311       xdas_audit_ref_t das_ref,
00312       xdas_audit_rec_desc_t * audit_record_descriptor)
00313 {
00314    return xdas_lib_handle == 0? XDAS_S_SERVICE_FAILURE
00315          : fp_xdas_discard_record(minor_status, das_ref, 
00316                audit_record_descriptor);
00317 }
00318 
00319 /*---------------------------------------------------------------------------
00320  */
00321 XDASXPC int XDASAPI xdas_put_event_info(
00322       int * minor_status,
00323       xdas_audit_ref_t das_ref,
00324       xdas_audit_rec_desc_t * audit_record_descriptor,
00325       unsigned event_number,
00326       unsigned outcome,
00327       const char * initiator_information,
00328       const char * target_information,
00329       const char * event_information)
00330 {
00331    return xdas_lib_handle == 0? XDAS_S_SERVICE_FAILURE
00332          : fp_xdas_put_event_info(minor_status, das_ref, 
00333                audit_record_descriptor, event_number, outcome, 
00334                initiator_information, target_information,
00335                event_information);
00336 }
00337 
00338 /*---------------------------------------------------------------------------
00339  */
00340 XDASXPC int XDASAPI xdas_start_record(
00341       int * minor_status,
00342       xdas_audit_ref_t das_ref,
00343       xdas_audit_rec_desc_t * audit_record_descriptor,
00344       unsigned event_number,
00345       unsigned outcome,
00346       const char * initiator_information,
00347       const char * target_information,
00348       const char * event_information)
00349 {
00350    return xdas_lib_handle == 0? XDAS_S_SERVICE_FAILURE
00351          : fp_xdas_start_record(minor_status, das_ref, 
00352                audit_record_descriptor, event_number, outcome, 
00353                initiator_information, target_information, 
00354                event_information);
00355 }
00356 
00357 /*---------------------------------------------------------------------------
00358  */
00359 XDASXPC int XDASAPI xdas_timestamp_record(
00360       int * minor_status,
00361       xdas_audit_ref_t das_ref,
00362       xdas_audit_rec_desc_t audit_record_descriptor)
00363 {
00364    return xdas_lib_handle == 0? XDAS_S_SERVICE_FAILURE
00365          : fp_xdas_timestamp_record(minor_status, das_ref, 
00366                audit_record_descriptor);
00367 }
00368 
00369 /*---------------------------------------------------------------------------
00370  */
00371 XDASXPC int XDASAPI xdas_create_filter(
00372       int * minor_status,
00373       xdas_audit_ref_t das_ref,
00374       const char * name,
00375       unsigned filter_type,
00376       const char * filter_exp,
00377       const char * filter_act)
00378 {
00379    return xdas_lib_handle == 0? XDAS_S_SERVICE_FAILURE
00380          : fp_xdas_create_filter(minor_status, das_ref, 
00381                name, filter_type, filter_exp, filter_act);
00382 }
00383 
00384 /*---------------------------------------------------------------------------
00385  */
00386 XDASXPC int XDASAPI xdas_delete_filter(
00387       int * minor_status,
00388       xdas_audit_ref_t das_ref,
00389       const char * name)
00390 {
00391    return xdas_lib_handle == 0? XDAS_S_SERVICE_FAILURE
00392          : fp_xdas_delete_filter(minor_status, das_ref, name);
00393 }
00394 
00395 /*---------------------------------------------------------------------------
00396  */
00397 XDASXPC int XDASAPI xdas_disable_filter(
00398       int * minor_status,
00399       xdas_audit_ref_t das_ref,
00400       const char * name)
00401 {
00402    return xdas_lib_handle == 0? XDAS_S_SERVICE_FAILURE
00403          : fp_xdas_disable_filter(minor_status, das_ref, name);
00404 }
00405 
00406 /*---------------------------------------------------------------------------
00407  */
00408 XDASXPC int XDASAPI xdas_enable_filter(
00409       int * minor_status,
00410       xdas_audit_ref_t das_ref,
00411       const char * name)
00412 {
00413    return xdas_lib_handle == 0? XDAS_S_SERVICE_FAILURE
00414          : fp_xdas_enable_filter(minor_status, das_ref, name);
00415 }
00416 
00417 /*---------------------------------------------------------------------------
00418  */
00419 XDASXPC int XDASAPI xdas_get_filter(
00420       int * minor_status,
00421       xdas_audit_ref_t das_ref,
00422       const char * name,
00423       unsigned * filter_type,
00424       xdas_buffer_t filter_exp,
00425       xdas_buffer_t filter_act,
00426       unsigned * filter_status)
00427 {
00428    return xdas_lib_handle == 0? XDAS_S_SERVICE_FAILURE
00429          : fp_xdas_get_filter(minor_status, das_ref, name, 
00430                filter_type, filter_exp, filter_act, filter_status);
00431 }
00432 
00433 /*---------------------------------------------------------------------------
00434  */
00435 XDASXPC int XDASAPI xdas_list_filters(
00436       int * minor_status,
00437       xdas_audit_ref_t das_ref,
00438       char ** filter_name_list,
00439       size_t * buffer_size)
00440 {
00441    return xdas_lib_handle == 0? XDAS_S_SERVICE_FAILURE
00442          : fp_xdas_list_filters(minor_status, das_ref, 
00443                filter_name_list, buffer_size);
00444 }

Generated on Thu Aug 20 22:33:05 2009 for OpenXDAS by  doxygen 1.5.6