libxdas_api_basic.c
Go to the documentation of this file.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_initialize_session(
00051 int * minor_status,
00052 const char * org_info,
00053 xdas_audit_ref_t * das_ref)
00054 {
00055 int err;
00056 xdas_session * xs;
00057 int bit_bucket;
00058
00059
00060 if (!minor_status)
00061 minor_status = &bit_bucket;
00062 *minor_status = 0;
00063
00064 xdas_assert(org_info != 0);
00065 if (org_info == 0)
00066 return XDAS_S_CALL_INACCESSIBLE_READ | XDAS_S_INVALID_ORIG_INFO;
00067
00068 xdas_assert(das_ref != 0);
00069 if (das_ref == 0)
00070 return XDAS_S_CALL_INACCESSIBLE_WRITE | XDAS_S_INVALID_DAS_REF;
00071
00072 *das_ref = 0;
00073
00074 #ifndef LINUX_KERNEL
00075
00076 if ((err = xdas_library_init(minor_status)) != 0)
00077 return err;
00078 #endif
00079
00080
00081 if ((xs = (xdas_session *)malloc(sizeof(*xs))) == 0)
00082 return (*minor_status = OXDAS_MS_OUT_OF_MEMORY), XDAS_S_FAILURE;
00083 memset(xs, 0, sizeof(*xs));
00084 xs->signature = XDAS_SESSION_SIG;
00085
00086 #ifndef LINUX_KERNEL
00087 xs->s = BAD_SOCKET;
00088 #endif
00089
00090
00091 xdas_set_session_rights(xs);
00092 if (!xdas_session_has_rights(xs, XDAS_AUDIT_SERVICE))
00093 {
00094 xdas_internal_terminate_session(xs);
00095 return XDAS_S_AUTHORIZATION_FAILURE;
00096 }
00097
00098
00099 if ((err = xdas_parse_info(org_info, 0,
00100 xs->org_info, xdas_elemcount(xs->org_info))) < 0)
00101 {
00102 xdas_internal_terminate_session(xs);
00103 switch(err)
00104 {
00105 case -1: return (*minor_status = OXDAS_MS_OUT_OF_MEMORY), XDAS_S_FAILURE;
00106 case -2: return XDAS_S_CALL_BAD_STRUCTURE | XDAS_S_INVALID_ORIG_INFO;
00107 default: return (*minor_status = OXDAS_MS_UNKNOWN_ERROR), XDAS_S_FAILURE;
00108 }
00109 }
00110
00111
00112 if (xdas_set_time_info(xs) < 0)
00113 {
00114 xdas_internal_terminate_session(xs);
00115 return (*minor_status = OXDAS_MS_OUT_OF_MEMORY), XDAS_S_FAILURE;
00116 }
00117
00118
00119 if ((err = xdas_service_connect(minor_status, xs)) != 0)
00120 {
00121 xdas_internal_terminate_session(xs);
00122 return err;
00123 }
00124
00125
00126 *das_ref = (xdas_audit_ref_t)xs;
00127
00128 return XDAS_S_COMPLETE;
00129 }
00130
00131
00132
00133 XDASXPC int XDASAPI xdas_terminate_session(
00134 int * minor_status,
00135 xdas_audit_ref_t * das_ref)
00136 {
00137 xdas_session * xs;
00138 int bit_bucket;
00139
00140
00141 if (!minor_status)
00142 minor_status = &bit_bucket;
00143 *minor_status = 0;
00144
00145 xdas_assert(das_ref != 0 && *das_ref != 0);
00146 if (das_ref == 0 || *das_ref == 0)
00147 return XDAS_S_CALL_INACCESSIBLE_READ | XDAS_S_INVALID_DAS_REF;
00148
00149 xs = xdas_validate_session(*das_ref);
00150 xdas_assert(xs != 0);
00151 if (xs == 0)
00152 return XDAS_S_CALL_BAD_STRUCTURE | XDAS_S_INVALID_DAS_REF;
00153
00154 xdas_internal_terminate_session(xs);
00155 *das_ref = 0;
00156 return XDAS_S_COMPLETE;
00157 }
00158