libxdas_api_basic.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 <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    /* check parameters */
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    /* ensure xdas library is initialized */
00076    if ((err = xdas_library_init(minor_status)) != 0)
00077       return err;
00078 #endif
00079 
00080    /* create a new session structure */
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    /* populate and check caller's rights */
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    /* parse originator info */
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    /* retreive system time information */
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    /* establish connection with the xdas daemon/service */
00119    if ((err = xdas_service_connect(minor_status, xs)) != 0)
00120    {
00121       xdas_internal_terminate_session(xs);
00122       return err;
00123    }
00124 
00125    /* return session pointer as a handle */
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    /* check parameters */
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 

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