00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00039 #include <xdas.h>
00040 #include <xdas_util.h>
00041 #include <xdas_debug.h>
00042
00043 #include "libxdas_impl.h"
00044
00045 #include <malloc.h>
00046 #include <string.h>
00047
00048
00049
00050 XDASXPC int XDASAPI xdas_commit_record(
00051 int * minor_status,
00052 xdas_audit_ref_t das_ref,
00053 xdas_audit_rec_desc_t * audit_record_descriptor)
00054 {
00055 xdas_session * xs;
00056 xdas_record * xr;
00057 int rv, bit_bucket;
00058
00059
00060 if (!minor_status)
00061 minor_status = &bit_bucket;
00062 *minor_status = 0;
00063
00064 xdas_assert(das_ref != 0);
00065 if (das_ref == 0)
00066 return XDAS_S_CALL_INACCESSIBLE_READ | XDAS_S_INVALID_DAS_REF;
00067
00068 xs = xdas_validate_session(das_ref);
00069 xdas_assert(xs != 0);
00070 if (xs == 0)
00071 return XDAS_S_CALL_BAD_STRUCTURE | XDAS_S_INVALID_DAS_REF;
00072
00073 if (!xdas_session_has_rights(xs, XDAS_AUDIT_SERVICE | XDAS_AUDIT_SUBMIT))
00074 return XDAS_S_AUTHORIZATION_FAILURE;
00075
00076 xdas_assert(audit_record_descriptor != 0 && *audit_record_descriptor != 0);
00077 if (audit_record_descriptor == 0 || *audit_record_descriptor == 0)
00078 return XDAS_S_CALL_INACCESSIBLE_READ | XDAS_S_INVALID_RECORD_DESCRIPTOR;
00079
00080 xr = xdas_validate_record(*audit_record_descriptor);
00081 xdas_assert(xr != 0);
00082 if (xr == 0)
00083 return XDAS_S_CALL_BAD_STRUCTURE | XDAS_S_INVALID_RECORD_DESCRIPTOR;
00084
00085
00086 if (xr->event_number == 0 || xr->outcome == XDAS_OUT_NOT_SPECIFIED
00087 || xr->int_info[0] == 0 || xr->tgt_info[0] == 0 || xr->evt_info == 0)
00088 return XDAS_S_INCOMPLETE_RECORD;
00089
00090
00091 if (xr->time_offset == 0)
00092 xdas_set_record_timestamp(xr);
00093
00094
00095 if ((rv = xdas_send_record(minor_status, xs, xr, 0, 0)) == 0)
00096 {
00097 xdas_internal_discard_record(xr);
00098 *audit_record_descriptor = 0;
00099 }
00100 return rv;
00101 }
00102
00103
00104
00105 XDASXPC int XDASAPI xdas_discard_record(
00106 int * minor_status,
00107 xdas_audit_ref_t das_ref,
00108 xdas_audit_rec_desc_t * audit_record_descriptor)
00109 {
00110 xdas_session * xs;
00111 xdas_record * xr;
00112 int bit_bucket;
00113
00114
00115 if (!minor_status)
00116 minor_status = &bit_bucket;
00117 *minor_status = 0;
00118
00119 xdas_assert(das_ref != 0);
00120 if (das_ref == 0)
00121 return XDAS_S_CALL_INACCESSIBLE_READ | XDAS_S_INVALID_DAS_REF;
00122
00123 xs = xdas_validate_session(das_ref);
00124 xdas_assert(xs != 0);
00125 if (xs == 0)
00126 return XDAS_S_CALL_BAD_STRUCTURE | XDAS_S_INVALID_DAS_REF;
00127
00128 if (!xdas_session_has_rights(xs, XDAS_AUDIT_SERVICE | XDAS_AUDIT_SUBMIT))
00129 return XDAS_S_AUTHORIZATION_FAILURE;
00130
00131 xdas_assert(audit_record_descriptor != 0 && *audit_record_descriptor != 0);
00132 if (audit_record_descriptor == 0 || *audit_record_descriptor == 0)
00133 return XDAS_S_CALL_INACCESSIBLE_READ | XDAS_S_INVALID_RECORD_DESCRIPTOR;
00134
00135 xr = xdas_validate_record(*audit_record_descriptor);
00136 xdas_assert(xr != 0);
00137 if (xr == 0)
00138 return XDAS_S_CALL_BAD_STRUCTURE | XDAS_S_INVALID_RECORD_DESCRIPTOR;
00139
00140 xdas_internal_discard_record(xr);
00141 *audit_record_descriptor = 0;
00142 return XDAS_S_COMPLETE;
00143 }
00144
00145
00146
00147 XDASXPC int XDASAPI xdas_put_event_info(
00148 int * minor_status,
00149 xdas_audit_ref_t das_ref,
00150 xdas_audit_rec_desc_t * audit_record_descriptor,
00151 unsigned event_number,
00152 unsigned outcome,
00153 const char * initiator_information,
00154 const char * target_information,
00155 const char * event_information)
00156 {
00157 xdas_session * xs;
00158 xdas_record * xr;
00159 int bit_bucket;
00160 char * int_info[xdas_elemcount(xr->int_info)];
00161 char * tgt_info[xdas_elemcount(xr->tgt_info)];
00162 char * evt_info;
00163
00164
00165 if (!minor_status)
00166 minor_status = &bit_bucket;
00167 *minor_status = 0;
00168
00169 xdas_assert(das_ref != 0);
00170 if (das_ref == 0)
00171 return XDAS_S_CALL_INACCESSIBLE_READ | XDAS_S_INVALID_DAS_REF;
00172
00173 xs = xdas_validate_session(das_ref);
00174 xdas_assert(xs != 0);
00175 if (xs == 0)
00176 return XDAS_S_CALL_BAD_STRUCTURE | XDAS_S_INVALID_DAS_REF;
00177
00178 if (!xdas_session_has_rights(xs, XDAS_AUDIT_SERVICE | XDAS_AUDIT_SUBMIT))
00179 return XDAS_S_AUTHORIZATION_FAILURE;
00180
00181 xdas_assert(audit_record_descriptor != 0 && *audit_record_descriptor != 0);
00182 if (audit_record_descriptor == 0 || *audit_record_descriptor == 0)
00183 return XDAS_S_CALL_INACCESSIBLE_READ | XDAS_S_INVALID_RECORD_DESCRIPTOR;
00184
00185 xr = xdas_validate_record(*audit_record_descriptor);
00186 xdas_assert(xr != 0);
00187 if (xr == 0)
00188 return XDAS_S_CALL_BAD_STRUCTURE | XDAS_S_INVALID_RECORD_DESCRIPTOR;
00189
00190
00191 int_info[0] = tgt_info[0] = evt_info = 0;
00192
00193
00194 if (outcome != XDAS_OUT_NOT_SPECIFIED
00195 && !xdas_is_valid_outcome(outcome))
00196 return XDAS_S_INVALID_OUTCOME;
00197
00198
00199 if (initiator_information)
00200 {
00201 int rv;
00202 if ((rv = xdas_parse_info(initiator_information, 0,
00203 int_info, xdas_elemcount(int_info))) < 0)
00204 {
00205 switch(rv)
00206 {
00207 case -1: return (*minor_status = OXDAS_MS_OUT_OF_MEMORY), XDAS_S_FAILURE;
00208 case -2: return XDAS_S_CALL_BAD_STRUCTURE | XDAS_S_INVALID_INITIATOR_INFO;
00209 default: return (*minor_status = OXDAS_MS_UNKNOWN_ERROR), XDAS_S_FAILURE;
00210 }
00211 }
00212 }
00213
00214
00215 if (target_information)
00216 {
00217 int rv;
00218 if ((rv = xdas_parse_info(target_information, 0,
00219 tgt_info, xdas_elemcount(tgt_info))) < 0)
00220 {
00221 free(int_info[0]);
00222 switch(rv)
00223 {
00224 case -1: return (*minor_status = OXDAS_MS_OUT_OF_MEMORY), XDAS_S_FAILURE;
00225 case -2: return XDAS_S_CALL_BAD_STRUCTURE | XDAS_S_INVALID_TARGET_INFO;
00226 default: return (*minor_status = OXDAS_MS_UNKNOWN_ERROR), XDAS_S_FAILURE;
00227 }
00228 }
00229 }
00230
00231
00232 if (event_information)
00233 {
00235 if ((evt_info = strdup(event_information)) == 0)
00236 {
00237 free(int_info[0]);
00238 free(tgt_info[0]);
00239 return (*minor_status = OXDAS_MS_OUT_OF_MEMORY), XDAS_S_FAILURE;
00240 }
00241 }
00242
00243
00244
00245
00246 if (event_number != 0 && event_number != xr->event_number)
00247 {
00248 xr->event_number = event_number;
00249 xr->fmt_cache_dirty = 1;
00250 }
00251
00252
00253 if (outcome != XDAS_OUT_NOT_SPECIFIED && outcome != xr->outcome)
00254 {
00255 xr->outcome = outcome;
00256 xr->fmt_cache_dirty = 1;
00257 }
00258
00259
00260 if (initiator_information)
00261 {
00263 free(xr->int_info[0]);
00264 memcpy(xr->int_info, int_info, sizeof(xr->int_info));
00265 xr->fmt_cache_dirty = 1;
00266 }
00267
00268
00269 if (target_information)
00270 {
00272 free(xr->tgt_info[0]);
00273 memcpy(xr->tgt_info, tgt_info, sizeof(xr->tgt_info));
00274 xr->fmt_cache_dirty = 1;
00275 }
00276
00277
00278 if (event_information)
00279 {
00280 if (xr->evt_info && strcmp(event_information, xr->evt_info) == 0)
00281 free(evt_info);
00282 else
00283 {
00284 free(xr->evt_info);
00285 xr->evt_info = evt_info;
00286 xr->fmt_cache_dirty = 1;
00287 }
00288 }
00289
00290 #ifndef LINUX_KERNEL
00291
00292 if (xr->fmt_cache_dirty)
00293 {
00294 int rv;
00295 if ((rv = xdas_send_record(
00296 minor_status, xs, xr, 1, 0)) == XDAS_S_NO_AUDIT)
00297 {
00298 xdas_internal_discard_record(xr);
00299 *audit_record_descriptor = 0;
00300 }
00301 xr->fmt_cache_dirty = 0;
00302 return rv;
00303 }
00304 return xr->last_status;
00305 #else
00306 return XDAS_S_COMPLETE;
00307 #endif
00308 }
00309
00310
00311
00312 XDASXPC int XDASAPI xdas_start_record(
00313 int * minor_status,
00314 xdas_audit_ref_t das_ref,
00315 xdas_audit_rec_desc_t * audit_record_descriptor,
00316 unsigned event_number,
00317 unsigned outcome,
00318 const char * initiator_information,
00319 const char * target_information,
00320 const char * event_information)
00321 {
00322 xdas_record * xr;
00323 xdas_session * xs;
00324 int bit_bucket, rv = XDAS_S_COMPLETE;
00325
00326
00327 if (!minor_status)
00328 minor_status = &bit_bucket;
00329 *minor_status = 0;
00330
00331 xdas_assert(das_ref != 0);
00332 if (das_ref == 0)
00333 return XDAS_S_CALL_INACCESSIBLE_READ | XDAS_S_INVALID_DAS_REF;
00334
00335 xs = xdas_validate_session(das_ref);
00336 xdas_assert(xs != 0);
00337 if (xs == 0)
00338 return XDAS_S_CALL_BAD_STRUCTURE | XDAS_S_INVALID_DAS_REF;
00339
00340 if (!xdas_session_has_rights(xs, XDAS_AUDIT_SERVICE | XDAS_AUDIT_SUBMIT))
00341 return XDAS_S_AUTHORIZATION_FAILURE;
00342
00343 xdas_assert(audit_record_descriptor != 0);
00344 if (audit_record_descriptor == 0)
00345 return XDAS_S_CALL_INACCESSIBLE_WRITE | XDAS_S_INVALID_RECORD_DESCRIPTOR;
00346
00347
00348 *audit_record_descriptor = 0;
00349 if ((xr = (xdas_record *)malloc(sizeof(*xr))) == 0)
00350 return (*minor_status = OXDAS_MS_OUT_OF_MEMORY), XDAS_S_FAILURE;
00351 memset(xr, 0, sizeof(*xr));
00352 xr->signature = XDAS_RECORD_SIG;
00353
00354
00355 xr->outcome = XDAS_OUT_NOT_SPECIFIED;
00356
00357 xr->record_number = xdas_get_next_record_number();
00358
00359
00360 if (event_number != 0)
00361 xr->event_number = event_number;
00362
00363
00364 if (outcome != XDAS_OUT_NOT_SPECIFIED)
00365 {
00366 if (!xdas_is_valid_outcome(outcome))
00367 return XDAS_S_INVALID_OUTCOME;
00368 xr->outcome = outcome;
00369 }
00370
00371
00372 if (initiator_information)
00373 {
00374 if ((rv = xdas_parse_info(initiator_information, 0,
00375 xr->int_info, xdas_elemcount(xr->int_info))) < 0)
00376 {
00377 xdas_internal_discard_record(xr);
00378 switch(rv)
00379 {
00380 case -1: return (*minor_status = OXDAS_MS_OUT_OF_MEMORY), XDAS_S_FAILURE;
00381 case -2: return XDAS_S_CALL_BAD_STRUCTURE | XDAS_S_INVALID_INITIATOR_INFO;
00382 default: return (*minor_status = OXDAS_MS_UNKNOWN_ERROR), XDAS_S_FAILURE;
00383 }
00384 }
00385 }
00386
00387
00388 if (target_information)
00389 {
00390 if ((rv = xdas_parse_info(target_information, 0,
00391 xr->tgt_info, xdas_elemcount(xr->tgt_info))) < 0)
00392 {
00393 xdas_internal_discard_record(xr);
00394 switch(rv)
00395 {
00396 case -1: return (*minor_status = OXDAS_MS_OUT_OF_MEMORY), XDAS_S_FAILURE;
00397 case -2: return XDAS_S_CALL_BAD_STRUCTURE | XDAS_S_INVALID_TARGET_INFO;
00398 default: return (*minor_status = OXDAS_MS_UNKNOWN_ERROR), XDAS_S_FAILURE;
00399 }
00400 }
00401 }
00402
00403
00404 if (event_information && (xr->evt_info = strdup(event_information)) == 0)
00405 {
00407 xdas_internal_discard_record(xr);
00408 return (*minor_status = OXDAS_MS_OUT_OF_MEMORY), XDAS_S_FAILURE;
00409 }
00410
00411 #ifndef LINUX_KERNEL
00412
00413 if ((rv = xdas_send_record(minor_status, xs, xr, 1, 0)) == XDAS_S_NO_AUDIT)
00414 {
00415 xdas_internal_discard_record(xr);
00416 xr = 0;
00417 }
00418 #endif
00419
00420
00421 *audit_record_descriptor = (xdas_audit_rec_desc_t)xr;
00422
00423 return rv;
00424 }
00425
00426
00427
00428 XDASXPC int XDASAPI xdas_timestamp_record(
00429 int * minor_status,
00430 xdas_audit_ref_t das_ref,
00431 xdas_audit_rec_desc_t audit_record_descriptor)
00432 {
00433 xdas_session * xs;
00434 xdas_record * xr;
00435 int bit_bucket;
00436
00437
00438 if (!minor_status)
00439 minor_status = &bit_bucket;
00440 *minor_status = 0;
00441
00442 xdas_assert(das_ref != 0);
00443 if (das_ref == 0)
00444 return XDAS_S_CALL_INACCESSIBLE_READ | XDAS_S_INVALID_DAS_REF;
00445
00446 xs = xdas_validate_session(das_ref);
00447 xdas_assert(xs != 0);
00448 if (xs == 0)
00449 return XDAS_S_CALL_BAD_STRUCTURE | XDAS_S_INVALID_DAS_REF;
00450
00451 if (!xdas_session_has_rights(xs, XDAS_AUDIT_SERVICE | XDAS_AUDIT_SUBMIT))
00452 return XDAS_S_AUTHORIZATION_FAILURE;
00453
00454 xdas_assert(audit_record_descriptor != 0);
00455 if (audit_record_descriptor == 0)
00456 return XDAS_S_CALL_INACCESSIBLE_READ | XDAS_S_INVALID_RECORD_DESCRIPTOR;
00457
00458 xr = xdas_validate_record(audit_record_descriptor);
00459 xdas_assert(xr != 0);
00460 if (xr == 0)
00461 return XDAS_S_CALL_BAD_STRUCTURE | XDAS_S_INVALID_RECORD_DESCRIPTOR;
00462
00463 xdas_set_record_timestamp(xr);
00464 xr->fmt_cache_dirty = 1;
00465
00466 return XDAS_S_COMPLETE;
00467 }
00468