xdastest.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 
00039 #include <xdas.h>
00040 #include "mt.h"
00041 
00042 #include <stdio.h>
00043 #include <string.h>
00044 #include <stdlib.h>
00045 
00046 #include <time.h>
00047 
00052 #ifdef _WIN32
00053 # define tzname _tzname
00054 # define tzset  _tzset
00055 # define strdup _strdup
00056 #endif
00057 
00060 #define CHECK(x)                                         \
00061    {                                                     \
00062       int err;                                           \
00063       if ((err = (x)) != 0)                              \
00064       {                                                  \
00065          printf("xdastest: error %d, %d at: %s(%d).\n",  \
00066                err, minor, __FILE__, __LINE__);          \
00067          exit(1);                                        \
00068       }                                                  \
00069    }
00070 
00078 int main(int argc, char ** argv)
00079 {
00080 
00081    int minor;
00082    xdas_audit_ref_t dasref;
00083 
00084    const char * orginfo = ":addr1%:addr2:service-type::principal_name:principal_id";
00085 
00086    /* initialize */
00087 
00088    CHECK(xdas_initialize_session(&minor, orginfo, &dasref));
00089 
00090    /* check for file import request */
00091 
00092    if (argc > 1)  /* file specified - import file contents... */
00093    {
00094       FILE * fin = fopen(argv[1], "r");
00095       if (fin != 0)
00096       {
00097          char buf[64 * 1024];
00098          while (fgets(buf, sizeof buf, fin) != 0)
00099          {
00100             char * p;
00101 
00102             /* search for "ev_parse: [" in xdasd.log, containing complete
00103                records - skip all lines that don't contain this pattern */
00104             if ((p = strstr(buf, "ev_parse: [HDR:")) != 0)
00105             {
00106                xdas_buffer_desc arec;
00107 
00108                arec.value = p + 11; /* point to char following "ev_parse: [" */
00109                if ((p = strstr(arec.value, ":END")) != 0)
00110                {
00111                   int minor;
00112                   size_t bufpos;
00113 
00114                   arec.length = p - arec.value + 4;   /* +4 includes ":END" */
00115                   CHECK(xdas_import_event_records(&minor, dasref, &arec, &bufpos));
00116                }
00117             }
00118          }
00119          fclose(fin);
00120       }
00121       else 
00122          printf("xdastest: Unable to open %s for reading. Terminating.\n", argv[1]);
00123    }
00124    else           /* no file given, just create one bogus record */
00125    {
00126       xdas_audit_rec_desc_t arec;
00127       int evtnum = XDAS_AE_AUD_DS_CORR;
00128       int resnum = XDAS_OUT_ENTITY_NON_EXISTENT;
00129 
00130       const char * intinfo = "initiator-info";
00131       const char * tgtinfo = "target-info";
00132       const char * evtinfo = "event-info";
00133 
00134       /* check submit api */
00135 
00136       CHECK(xdas_start_record(&minor, dasref, &arec, evtnum, resnum, intinfo, tgtinfo, 0));
00137 
00138       CHECK(xdas_put_event_info(&minor, dasref, &arec, 0, XDAS_OUT_NOT_SPECIFIED, 0, 0, evtinfo));
00139 
00140    /* CHECK(xdas_discard_record(&minor, dasref, &arec)); */
00141 
00142       CHECK(xdas_timestamp_record(&minor, dasref, arec));
00143 
00144       CHECK(xdas_commit_record(&minor, dasref, &arec));
00145    }
00146 
00147    /* terminate */
00148 
00149    CHECK(xdas_terminate_session(&minor, &dasref));
00150 
00151    return 0;
00152 }
00153 

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