dazukoio_trusted_core.c

Go to the documentation of this file.
00001 /* Dazuko Interface. Interace with Dazuko for file access control.
00002    Written by John Ogness <jogness@antivir.de>
00003 
00004    Copyright (c) 2005 H+BEDV Datentechnik GmbH
00005    All rights reserved.
00006 
00007    Redistribution and use in source and binary forms, with or without
00008    modification, are permitted provided that the following conditions
00009    are met:
00010 
00011    1. Redistributions of source code must retain the above copyright notice,
00012    this list of conditions and the following disclaimer.
00013 
00014    2. Redistributions in binary form must reproduce the above copyright notice,
00015    this list of conditions and the following disclaimer in the documentation
00016    and/or other materials provided with the distribution.
00017 
00018    3. Neither the name of Dazuko nor the names of its contributors may be used
00019    to endorse or promote products derived from this software without specific
00020    prior written permission.
00021 
00022    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00023    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00024    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00025    ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00026    LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00027    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00028    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00029    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00030    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00031    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032    POSSIBILITY OF SUCH DAMAGE.
00033 */
00034 
00035 #include <stdio.h>
00036 #include <stdlib.h>
00037 #include <string.h>
00038 #include "dazukoio.h"
00039 #include "dazukoio_core.h"
00040 #include "dazuko_transport.h"
00041 
00042 int dazukoRegisterTrusted(const char *groupName, const char *token, int flags)
00043 {
00044         struct dazuko_request   *request;
00045         char                    buffer[ITOA_SIZE];
00046         dazuko_id_t             *temp_id;
00047         size_t                  size;
00048 
00049         if (groupName == NULL || token == NULL)
00050                 return -1;
00051 
00052         /* create temporary id */
00053         temp_id = (dazuko_id_t *)malloc(sizeof(dazuko_id_t));
00054         if (temp_id == NULL)
00055                 return -1;
00056 
00057         memset(temp_id, 0, sizeof(dazuko_id_t));
00058 
00059         /* open device */
00060         if (xp_connection_open(temp_id) != 0)
00061         {
00062                 free(temp_id);
00063                 return -1;
00064         }
00065 
00066         request = (struct dazuko_request *)malloc(sizeof(struct dazuko_request));
00067         if (request == NULL)
00068         {
00069                 xp_connection_close(temp_id);
00070                 free(temp_id);
00071                 return -1;
00072         }
00073 
00074         memset(request, 0, sizeof(struct dazuko_request));
00075 
00076         request->type[0] = REGISTER_TRUSTED;
00077 
00078         size = 1 + 2 + 1 + strlen(groupName); /* \nGN=groupName */
00079         size += 1 + 2 + 1 + strlen(token); /* \nTT=token */
00080         if (flags & DAZUKO_TRUST_CHILDREN)
00081         {
00082                 size += 1 + 2 + 1 + 1; /* \nTF=C */
00083         }
00084         size += 1; /* \0 */
00085 
00086         request->buffer = (char *)malloc(size);
00087         if (request->buffer == NULL)
00088         {
00089                 xp_connection_close(temp_id);
00090                 free(temp_id);
00091                 free(request);
00092                 return -1;
00093         }
00094         snprintf(request->buffer, size, "\nGN=%s\nTT=%s%s", groupName, token, (flags & DAZUKO_TRUST_CHILDREN) ? "\nTF=C" : "");
00095         request->buffer[size - 1] = 0;
00096 
00097         request->buffer_size = strlen(request->buffer) + 1;
00098 
00099         size = 4096;
00100         request->reply_buffer = (char *)malloc(size);
00101         if (request->reply_buffer == NULL)
00102         {
00103                 xp_connection_close(temp_id);
00104                 free(temp_id);
00105                 free(request->buffer);
00106                 free(request);
00107                 return -1;
00108         }
00109         memset(request->reply_buffer, 0, size);
00110         request->reply_buffer_size = size;
00111 
00112         snprintf(buffer, sizeof(buffer), "\nRA=%lu", (unsigned long)request);
00113         buffer[sizeof(buffer)-1] = 0;
00114         size = strlen(buffer) + 1;
00115 
00116         if (xp_process_request(temp_id, buffer, size) != 0)
00117         {
00118                 xp_connection_close(temp_id);
00119                 free(temp_id);
00120                 free(request->buffer);
00121                 free(request->reply_buffer);
00122                 free(request);
00123 
00124                 return -1;
00125         }
00126 
00127         if (dazuko_get_value("\nDN=", request->reply_buffer, buffer, sizeof(buffer)) != 0)
00128         {
00129                 xp_connection_close(temp_id);
00130                 free(temp_id);
00131                 free(request->buffer);
00132                 free(request->reply_buffer);
00133                 free(request);
00134 
00135                 return -1;
00136         }
00137 
00138         xp_connection_close(temp_id);
00139         free(temp_id);
00140         free(request->buffer);
00141         free(request->reply_buffer);
00142         free(request);
00143 
00144         if (atoi(buffer) != 0)
00145                 return -1;
00146 
00147         return 0;
00148 }
00149 
00150 int dazukoUnregisterTrusted(void)
00151 {
00152         struct dazuko_request   *request;
00153         char                    buffer[ITOA_SIZE];
00154         dazuko_id_t             *temp_id;
00155         size_t                  size;
00156         int                     error = 0;
00157 
00158         /* create temporary id */
00159         temp_id = (dazuko_id_t *)malloc(sizeof(dazuko_id_t));
00160         if (temp_id == NULL)
00161                 return -1;
00162 
00163         memset(temp_id, 0, sizeof(dazuko_id_t));
00164 
00165         /* open device */
00166         if (xp_connection_open(temp_id) != 0)
00167         {
00168                 free(temp_id);
00169                 return -1;
00170         }
00171 
00172         request = (struct dazuko_request *)malloc(sizeof(struct dazuko_request));
00173         if (request == NULL)
00174         {
00175                 free(temp_id);
00176                 return -1;
00177         }
00178 
00179         memset(request, 0, sizeof(struct dazuko_request));
00180 
00181         request->type[0] = UNREGISTER_TRUSTED;
00182 
00183         snprintf(buffer, sizeof(buffer), "\nRA=%lu", (unsigned long)request);
00184         buffer[sizeof(buffer)-1] = 0;
00185         size = strlen(buffer) + 1;
00186 
00187         if (xp_process_request(temp_id, buffer, size) != 0)
00188         {
00189                 error = -1;
00190         }
00191 
00192         xp_connection_close(temp_id);
00193         free(temp_id);
00194         free(request);
00195 
00196         return error;
00197 }
00198 

Generated on Sun May 21 14:30:50 2006 for RSBAC by  doxygen 1.4.2