GridLab
Grid Application Toolkit

A simple API for Grid Applications
GAT

Menu



Main Page   Alphabetical List   Compound List   File List   Compound Members   File Members  

GATSecurityContext.c

Go to the documentation of this file.
00001 /** @file GATSecurityContext.c
00002  * Main file for the GATSecurityContext class.
00003  * 
00004  * A container for security information.  Each context has a type associated with it.  
00005  * The type indicates if the GATSecurityContext instance corresponds to a "password"
00006  * GATSecurityContext or a "certificate" GATSecurityContext.
00007  *
00008  * Currently we provide additional auxiliary operations to create a context
00009  * based upon password information or upon credentials stored in a file.
00010  * GATContexts based upon these mechanisms can be used by adaptors to create
00011  * further contexts containing opaque data objects, e.g. GSSAPI credentials.
00012  * 
00013  * @date $Date: 2004/03/24 19:30:58 $
00014  * 
00015  * @version $Header: /export/cvs-gridlab/wp-1/Codes/GATEngine/C-reference/src/GATSecurityContext.c,v 1.9 2004/03/24 19:30:58 hartmutkaiser Exp $
00016  *
00017  *  Copyright (C) Kelly Davis
00018  *  This file is part of the GAT Engine.
00019  *  Contributed by Kelly Davis <kdavis@aei.mpg.de>.
00020  *
00021  *  Use, modification and distribution is subject to the Gridlab Software
00022  *  License. (See accompanying file GLlicense.txt or copy at
00023  *  http://www.gridlab.org/GLlicense.txt)
00024  */
00025  
00026 static const char *rcsid = "$Header: /export/cvs-gridlab/wp-1/Codes/GATEngine/C-reference/src/GATSecurityContext.c,v 1.9 2004/03/24 19:30:58 hartmutkaiser Exp $";
00027 
00028 /* System Header Files */
00029 
00030 #include <stdio.h>
00031 #include <stdlib.h>
00032 #include <string.h>
00033 
00034 /* GAT Header Files */
00035 
00036 #include "GATType.h"
00037 #include "GATErrors.h"
00038 #include "GATLocation.h"
00039 #include "GATSecurityContext.h"
00040 
00041 /* Macros */
00042 
00043 /* Structures, unions and enums */
00044 
00045 /* define the vtable types */
00046 GATOBJECT_DEFINE_VTABLE(GATSecurityContext);
00047 
00048 /* Declare the converters to/from GATObject */
00049 GATOBJECT_DEFINE_CONVERTERS(GATSecurityContext);
00050 GATOBJECT_DEFINE_CONVERTERS_QUALIFIED(extern, GATList_GATSecurityContext, GATType_GATList);
00051 
00052 /* GATList_GATSecurityContext */
00053 GATLIST_IMPLEMENT(extern, GATSecurityContext, GATList_GATSecurityContext, GATType_GATSecurityContext);
00054 
00055 typedef struct
00056 {
00057   char *name;
00058   char *passphrase;
00059   GATLocation location;
00060 } GATRemoteSecurityContext;
00061 
00062 typedef struct
00063 {
00064   char *username;
00065   char *password;
00066 } GATPasswordSecurityContext;
00067 
00068 typedef struct
00069 {
00070   char *keyfile;
00071   char *passphrase;
00072   char *certificate;
00073 } GATCertificateSecurityContext;
00074 
00075 typedef union
00076 {
00077   GATRemoteSecurityContext remoteSecurityContext;
00078   GATPasswordSecurityContext passwordSecurityContext;
00079   GATCertificateSecurityContext certificateSecurityContext;
00080 } GATSecurityContextUnion;
00081 
00082 struct GATSecurityContext_S
00083 {  
00084   GATSecurityContext_vtable *GATObject__vtable;
00085   
00086   GATSecurityContextType securityContextType;
00087   GATSecurityContextUnion securityContextUnion;
00088 };
00089 
00090 /* Static function prototypes */
00091 static char *GATSecurityContext_StringClone(const char *oldString);
00092 static void GATSecurityContext_PartialDestroy(GATSecurityContext *securityContext);
00093 
00094 /* File scope variables */
00095 static GATSecurityContext_vtable GATSecurityContext__vtable = {
00096   GATSecurityContext_GetType,
00097   GATSecurityContext_Destroy,
00098   GATSecurityContext_Equals,
00099   GATSecurityContext_Clone,
00100   GATSecurityContext_GetInterface,
00101   NULL
00102 };
00103 
00104 /* External functions */
00105 
00106 /**
00107  * Creates a new security context of a specific type. The type indicates 
00108  * the means by which this instance allows "secure" communications to be 
00109  * established. The allowed values for this type are the various public 
00110  * class variables of this class established for this purpose.
00111  *
00112  * @param type The type of this security context
00113  */
00114 GATSecurityContext GATSecurityContext_Create(GATSecurityContextType type)
00115 {
00116   GATSecurityContext this;
00117 
00118   this = (GATSecurityContext) malloc( sizeof(struct GATSecurityContext_S) );
00119   if(NULL != this)
00120   {
00121     memset(this, 0, sizeof(struct GATSecurityContext_S));
00122     this->GATObject__vtable = &GATSecurityContext__vtable;
00123     
00124     this->securityContextType = type;
00125   }
00126 
00127   return this;
00128 }
00129 
00130 /**
00131  * Destroys a security context.
00132  *
00133  * @param this The GATSecurityContext to destory
00134  */
00135 void GATSecurityContext_Destroy(GATSecurityContext *this)
00136 {
00137   if( NULL != (*this) )
00138   {
00139     if(GATSecurityContextType_Password == (*this)->securityContextType)
00140     {
00141       free( ((*this)->securityContextUnion).passwordSecurityContext.username );
00142       free( ((*this)->securityContextUnion).passwordSecurityContext.password );
00143       
00144       ((*this)->securityContextUnion).passwordSecurityContext.username = NULL;
00145       ((*this)->securityContextUnion).passwordSecurityContext.password = NULL;
00146     }
00147     
00148     if(GATSecurityContextType_Certificate == (*this)->securityContextType)
00149     {
00150       free( ((*this)->securityContextUnion).certificateSecurityContext.keyfile );
00151       free( ((*this)->securityContextUnion).certificateSecurityContext.passphrase );
00152       free( ((*this)->securityContextUnion).certificateSecurityContext.certificate );
00153       
00154       ((*this)->securityContextUnion).certificateSecurityContext.keyfile = NULL;
00155       ((*this)->securityContextUnion).certificateSecurityContext.passphrase = NULL;
00156       ((*this)->securityContextUnion).certificateSecurityContext.certificate = NULL;
00157     }
00158     
00159     if(GATSecurityContextType_Remote == (*this)->securityContextType)
00160     {
00161       free( ((*this)->securityContextUnion).remoteSecurityContext.name );
00162       free( ((*this)->securityContextUnion).remoteSecurityContext.passphrase );
00163       GATLocation_Destroy( &(((*this)->securityContextUnion).remoteSecurityContext.location) );
00164       
00165       ((*this)->securityContextUnion).remoteSecurityContext.name = NULL;
00166       ((*this)->securityContextUnion).remoteSecurityContext.passphrase = NULL;
00167     }
00168     
00169     free(*this);
00170     *this = NULL;
00171   }
00172 }
00173 
00174 /**
00175  * This fucntion returns the type, a #GATType of the passed #GATSecurityContext_const.
00176  * This function will always return #GATType_GATSecurityContext.
00177  *
00178  * @param this The #GATSecurityContext_const to query
00179  * @return The #GATType of the passed @c this
00180  */
00181 GATType GATSecurityContext_GetType(GATSecurityContext_const this)
00182 {
00183   GAT_UNUSED_PARAMETER(this);
00184   return GATType_GATSecurityContext;
00185 }
00186 
00187 /** GATSecurityContext_Clone
00188  * Clone is used to clone a specified context, copying all
00189  * state and security information.  The new GATSecurityContext is
00190  * completely independent from the original one, which may 
00191  * be destroyed with no effect on the new one.
00192  *
00193  * @param this The GATSecurityContext to clone
00194  * @param thisClone The cloned GATSecurityContext
00195  * @return An error code
00196  */
00197 GATResult GATSecurityContext_Clone(GATSecurityContext_const this, GATSecurityContext *thisClone)
00198 {
00199   GATResult retval;
00200   
00201   retval = GAT_INVALID_HANDLE;
00202   if( NULL != this )
00203   {
00204     retval = GAT_INVALID_PARAMETER;
00205     if( NULL != thisClone)
00206     {
00207       if( GATSecurityContextType_Password == this->securityContextType )
00208       {
00209         (*thisClone)->GATObject__vtable = &GATSecurityContext__vtable;
00210         
00211         (*thisClone)->securityContextType = GATSecurityContextType_Password;
00212         ((*thisClone)->securityContextUnion).passwordSecurityContext.username = 
00213           GATSecurityContext_StringClone( (this->securityContextUnion).passwordSecurityContext.username );
00214         ((*thisClone)->securityContextUnion).passwordSecurityContext.password = 
00215           GATSecurityContext_StringClone( (this->securityContextUnion).passwordSecurityContext.password );
00216           
00217         if( 
00218             (NULL == ((*thisClone)->securityContextUnion).passwordSecurityContext.username) ||
00219             (NULL == ((*thisClone)->securityContextUnion).passwordSecurityContext.password)
00220           )
00221         {
00222           retval = GAT_MEMORYFAILURE;
00223           GATSecurityContext_Destroy( thisClone );
00224         }
00225       }
00226       if( GATSecurityContextType_Certificate == this->securityContextType )
00227       {
00228         (*thisClone)->GATObject__vtable = &GATSecurityContext__vtable;
00229         
00230         (*thisClone)->securityContextType = GATSecurityContextType_Certificate;
00231         ((*thisClone)->securityContextUnion).certificateSecurityContext.keyfile = 
00232           GATSecurityContext_StringClone( (this->securityContextUnion).certificateSecurityContext.keyfile );
00233         ((*thisClone)->securityContextUnion).certificateSecurityContext.passphrase = 
00234           GATSecurityContext_StringClone( (this->securityContextUnion).certificateSecurityContext.passphrase );
00235         ((*thisClone)->securityContextUnion).certificateSecurityContext.certificate = 
00236           GATSecurityContext_StringClone( (this->securityContextUnion).certificateSecurityContext.certificate );
00237           
00238         if( 
00239             (NULL == ((*thisClone)->securityContextUnion).certificateSecurityContext.keyfile)     ||
00240             (NULL == ((*thisClone)->securityContextUnion).certificateSecurityContext.passphrase)  ||
00241             (NULL == ((*thisClone)->securityContextUnion).certificateSecurityContext.certificate)
00242           )
00243         {
00244           retval = GAT_MEMORYFAILURE;
00245           GATSecurityContext_Destroy( thisClone );
00246         }
00247       }
00248       if( GATSecurityContextType_Remote == this->securityContextType )
00249       {
00250         (*thisClone)->GATObject__vtable = &GATSecurityContext__vtable;
00251         
00252         (*thisClone)->securityContextType = GATSecurityContextType_Remote;
00253         ((*thisClone)->securityContextUnion).remoteSecurityContext.name = 
00254           GATSecurityContext_StringClone( (this->securityContextUnion).remoteSecurityContext.name );
00255         ((*thisClone)->securityContextUnion).remoteSecurityContext.passphrase = 
00256           GATSecurityContext_StringClone( (this->securityContextUnion).remoteSecurityContext.passphrase );
00257         GATLocation_Clone( (this->securityContextUnion).remoteSecurityContext.location, &(((*thisClone)->securityContextUnion).remoteSecurityContext.location) );
00258           
00259         if( 
00260             (NULL == ((*thisClone)->securityContextUnion).remoteSecurityContext.name)        ||
00261             (NULL == ((*thisClone)->securityContextUnion).remoteSecurityContext.passphrase)  ||
00262             (NULL == ((*thisClone)->securityContextUnion).remoteSecurityContext.location)
00263           )
00264         {
00265           retval = GAT_MEMORYFAILURE;
00266           GATSecurityContext_Destroy( thisClone );
00267         }
00268       }
00269     }
00270   }
00271   
00272   return retval;
00273 }
00274 
00275 /**
00276  * For two GATSecurityContexts to be considered equal requires that they 
00277  * must be acquired over the same mechanisms and must refer to the same 
00278  * name.
00279  *
00280  * @param this The first GATSecurityContext
00281  * @param that The second GATSecurityContext
00282  * @param isequal Result of comparrison
00283  * @return An error code
00284  */
00285 GATResult GATSecurityContext_Equals(GATSecurityContext_const this, GATSecurityContext_const that, GATBool *isequal)
00286 {
00287   GATResult retval;
00288   
00289   retval = GAT_INVALID_HANDLE;
00290   if( NULL != this )
00291   {
00292     retval = GAT_INVALID_PARAMETER;
00293     if( (NULL != that) && (NULL != isequal) )
00294     {
00295       retval = GAT_SUCCESS;
00296       (*isequal) = GATFalse;
00297       if( this->securityContextType == that->securityContextType )
00298       {
00299         if( GATSecurityContextType_Password == this->securityContextType )
00300         {
00301           if(
00302               ( 0 == strcmp((this->securityContextUnion).passwordSecurityContext.username, (that->securityContextUnion).passwordSecurityContext.username) ) &&
00303               ( 0 == strcmp((this->securityContextUnion).passwordSecurityContext.password, (that->securityContextUnion).passwordSecurityContext.password) )
00304             )
00305           {
00306             (*isequal) = GATTrue;
00307           }
00308         }
00309         
00310         if( GATSecurityContextType_Certificate == this->securityContextType )
00311         {
00312           if(
00313               ( 0 == strcmp((this->securityContextUnion).certificateSecurityContext.keyfile, (that->securityContextUnion).certificateSecurityContext.keyfile) )         &&
00314               ( 0 == strcmp((this->securityContextUnion).certificateSecurityContext.passphrase, (that->securityContextUnion).certificateSecurityContext.passphrase) )   &&
00315               ( 0 == strcmp((this->securityContextUnion).certificateSecurityContext.certificate, (that->securityContextUnion).certificateSecurityContext.certificate) ) 
00316             )
00317           {
00318             (*isequal) = GATTrue;
00319           }
00320         }
00321         
00322         if( GATSecurityContextType_Remote == this->securityContextType )
00323         {
00324           if(
00325               ( 0 == strcmp((this->securityContextUnion).remoteSecurityContext.name, (that->securityContextUnion).remoteSecurityContext.name) )             &&
00326               ( 0 == strcmp((this->securityContextUnion).remoteSecurityContext.passphrase, (that->securityContextUnion).remoteSecurityContext.passphrase) )
00327             )
00328           {
00329             retval = GATLocation_Equals( (this->securityContextUnion).remoteSecurityContext.location, (that->securityContextUnion).remoteSecurityContext.location, isequal );
00330           }
00331         }
00332       }
00333     }
00334   }
00335   
00336   return retval;
00337 }
00338 
00339 /** GATSecurityContext_GetInterface
00340  *  This function gets an interface supported by this GATSecurityContext
00341  *
00342  *  The function GATSecurityContext_GetInterface allows to get a pointer to an 
00343  *  additional interface supported by this GATSecurityContext.
00344  *
00345  *  @param object The object to be asked for the new interface.
00346  *  @param iftype The interface the object is to be asked for.
00347  *  @param ifp The pointer, through which the result is to be returned.
00348  *  @return An error type.
00349  */
00350 GATResult 
00351 GATSecurityContext_GetInterface(GATSecurityContext_const object, 
00352   GATInterface iftype, void const **ifp)
00353 {
00354   GATResult retval;
00355   
00356   retval = GAT_INVALID_PARAMETER;
00357   if( (NULL != object) && (NULL != ifp) )
00358   {
00359     (*ifp) = NULL;
00360     retval = GAT_NO_INTERFACE;
00361     GAT_UNUSED_PARAMETER(iftype);
00362   }
00363   
00364   return retval;
00365 }
00366 
00367 /**
00368  * Makes this a "Password" type security context and stores the username 
00369  * and password in the context.
00370  *
00371  * @param this The GATSecurityContext to modify
00372  * @param username Username associated with password
00373  * @param password Password
00374  * @return A GATResult indicating the GATError return code
00375  */
00376 GATResult GATSecurityContext_SetPasswordAuthenticate(GATSecurityContext this, const char *username, const char *password)
00377 {
00378   GATResult retval;
00379   
00380   retval = GAT_INVALID_HANDLE;
00381   if( NULL != this )
00382   {
00383     retval = GAT_INVALID_PARAMETER;
00384     if( (NULL != username) && (NULL != password) )
00385     {
00386       char *tempUsername;
00387       char *tempPassword;
00388       
00389       retval = GAT_MEMORYFAILURE;
00390       tempUsername = GATSecurityContext_StringClone(username);
00391       tempPassword = GATSecurityContext_StringClone(password);
00392       if( (NULL != tempUsername) && (NULL != tempPassword) )
00393       {
00394         retval = GAT_SUCCESS;
00395         GATSecurityContext_PartialDestroy( &this );
00396         this->securityContextType = GATSecurityContextType_Password;
00397         (this->securityContextUnion).passwordSecurityContext.username = tempUsername;
00398         (this->securityContextUnion).passwordSecurityContext.password = tempPassword;
00399       }
00400       else
00401       {
00402         free(tempUsername);
00403         free(tempPassword);
00404       }
00405     }
00406   }
00407   
00408   return retval;
00409 }
00410 
00411 /**
00412  * If this is a "Password" type security context get the username and password 
00413  * from the context.
00414  *
00415  * @param this The GATSecurityContext to query
00416  * @param username Pointer to the username pointer
00417  * @param password Pointer to the password pointer
00418  * @return A GATResult indicating the error state
00419  */
00420 GATResult GATSecurityContext_GetPasswordAuthenticate(GATSecurityContext this, char **username, char **password)
00421 {
00422   GATResult retval;
00423   
00424   retval = GAT_INVALID_HANDLE;
00425   if( NULL != this )
00426   {
00427     retval = GAT_INVALID_PARAMETER;
00428     if( (NULL != username) && (NULL != password) )
00429     {
00430       retval = GAT_INVALID_STATE;
00431       if( GATSecurityContextType_Password == this->securityContextType )
00432       {
00433         retval = GAT_MEMORYFAILURE;
00434         (*username) = GATSecurityContext_StringClone( (this->securityContextUnion).passwordSecurityContext.username );
00435         (*password) = GATSecurityContext_StringClone( (this->securityContextUnion).passwordSecurityContext.password );
00436         if( (NULL != *username) && (NULL != *password) )
00437         {
00438           retval = GAT_SUCCESS;
00439         }
00440         else
00441         {
00442           free(*username);
00443           free(*password);
00444         }
00445       }
00446     }
00447   }
00448   
00449   return retval;
00450 }
00451 
00452 /**
00453  * Makes this a "Certificate" type security context and stores the
00454  * information about the location of keyfile and certificate file 
00455  * in the context.
00456  *
00457  * @param this The GATSecurityContext to modify
00458  * @param keyfile Keyfile, containing valid absolute or relative local
00459  * path to keyfile.  A relative path will be converted to an absolute
00460  * path based upon the current working directory.
00461  * @param certificate Certificate, containing valid absolute or local 
00462  * path to certificate file. A relative path will be converted to an 
00463  * absolute path based upon the current working directory.
00464  * @param passphrase Passphrase (OPTIONAL)
00465  * @return A GATResult indicating the GATError return code
00466  */
00467 GATResult GATSecurityContext_SetCertificateAuthenticate(GATSecurityContext this, const char *keyfile, const char *certificate, const char *passphrase)
00468 {
00469   GATResult retval;
00470   
00471   retval = GAT_INVALID_HANDLE;
00472   if( NULL != this )
00473   {
00474     retval = GAT_INVALID_PARAMETER;
00475     if( (NULL != keyfile) && (NULL != certificate) && (NULL != passphrase) )
00476     {
00477       char *tempKeyfile;
00478       char *tempPassphrase;
00479       char *tempCertificate;
00480       
00481       retval = GAT_MEMORYFAILURE;
00482       tempKeyfile = GATSecurityContext_StringClone(keyfile);
00483       tempPassphrase = GATSecurityContext_StringClone(passphrase);
00484       tempCertificate = GATSecurityContext_StringClone(certificate);
00485       if( (NULL != tempKeyfile) && (NULL != tempPassphrase) && (NULL != tempCertificate) )
00486       {
00487         retval = GAT_SUCCESS;
00488         GATSecurityContext_PartialDestroy( &this );
00489         this->securityContextType = GATSecurityContextType_Certificate;
00490         (this->securityContextUnion).certificateSecurityContext.keyfile = tempKeyfile;
00491         (this->securityContextUnion).certificateSecurityContext.passphrase = tempPassphrase;
00492         (this->securityContextUnion).certificateSecurityContext.certificate = tempCertificate;
00493       }
00494       else
00495       {
00496         free(tempKeyfile);
00497         free(tempPassphrase);
00498         free(tempCertificate);
00499       }
00500     }
00501   }
00502   
00503   return retval;
00504 }
00505 
00506 /**
00507  * If this is a "Certificate" type security context get the
00508  * information about the location of keyfile and certificate 
00509  * file stored in the context.
00510  *
00511  * @param this The GATSecurityContext to query
00512  * @param keyfile Pointer to the keyfile pointer
00513  * @param certificate Pointer to the certificate pointer
00514  * @param passphrase Pointer to the passphrase pointer
00515  * @retun A GATResult indicating success
00516  */
00517 GATResult GATSecurityContext_GetCertificateAuthenticate(GATSecurityContext this, char **keyfile, char **certificate, char **passphrase)
00518 {
00519   GATResult retval;
00520   
00521   retval = GAT_INVALID_HANDLE;
00522   if( NULL != this )
00523   {
00524     retval = GAT_INVALID_PARAMETER;
00525     if( (NULL != keyfile) && (NULL != certificate) && (NULL != passphrase) )
00526     {
00527       retval = GAT_INVALID_STATE;
00528       if( GATSecurityContextType_Certificate == this->securityContextType )
00529       {
00530         retval = GAT_MEMORYFAILURE;
00531         (*keyfile) = GATSecurityContext_StringClone( (this->securityContextUnion).certificateSecurityContext.keyfile );
00532         (*passphrase) = GATSecurityContext_StringClone( (this->securityContextUnion).certificateSecurityContext.passphrase );
00533         (*certificate) = GATSecurityContext_StringClone( (this->securityContextUnion).certificateSecurityContext.certificate );
00534         if( (NULL != *keyfile) && (NULL != *passphrase) && (NULL != *certificate) )
00535         {
00536           retval = GAT_SUCCESS;
00537         }
00538         else
00539         {
00540           free(*keyfile);
00541           free(*passphrase);
00542           free(*certificate);
00543         }
00544       }
00545     }
00546   }
00547   
00548   return retval;
00549 }
00550 
00551 /**
00552  * Makes this a "Remote" type security context and stores the information 
00553  * about the location of remote credential server in the context.
00554  *
00555  * @param this The GATSecurityContext to modify
00556  * @param location Location for remote credential server
00557  * @param name Username associated with the credential
00558  * @param passphrase Passphrase associated with the credential
00559  * @return An int indicating the GATError return code
00560  */
00561 GATResult GATSecurityContext_SetRemoteAuthenticate(GATSecurityContext this, GATLocation location, const char *name, const char *passphrase)
00562 {
00563   GATResult retval;
00564   
00565   retval = GAT_INVALID_HANDLE;
00566   if( NULL != this )
00567   {
00568     retval = GAT_INVALID_PARAMETER;
00569     if( (NULL != location) && (NULL != name) && (NULL != passphrase) )
00570     {
00571       char *tempName;
00572       char *tempPassphrase;
00573       
00574       retval = GAT_MEMORYFAILURE;
00575       tempName = GATSecurityContext_StringClone(name);
00576       tempPassphrase = GATSecurityContext_StringClone(passphrase);
00577       if( (NULL != tempName) && (NULL != tempPassphrase) )
00578       {
00579         GATLocation tempLocation;
00580         
00581         retval = GATLocation_Clone(location, &tempLocation);
00582         if(GAT_SUCCESS == retval)
00583         {
00584           retval = GAT_SUCCESS;
00585           GATSecurityContext_PartialDestroy( &this );
00586           this->securityContextType = GATSecurityContextType_Remote;
00587           (this->securityContextUnion).remoteSecurityContext.name = tempName;
00588           (this->securityContextUnion).remoteSecurityContext.location = tempLocation;
00589           (this->securityContextUnion).remoteSecurityContext.passphrase = tempPassphrase;
00590         }
00591         else
00592         {
00593           free(tempName);
00594           free(tempPassphrase);
00595         }
00596       }
00597       else
00598       {
00599         free(tempName);
00600         free(tempPassphrase);
00601       }
00602     }
00603   }
00604   
00605   return retval;
00606 }
00607 
00608 /**
00609  * If this is a "Remote" type security context get the information about 
00610  * the location of remote credential server stored in the context.
00611  *
00612  * @param this The GATSecurityContext to query
00613  * @param location Pointer to the GATLocation
00614  * @param name Pointer to the name pointer
00615  * @param passphrase Pointer to the passphrase pointer
00616  * @retun A GATResult indicating success
00617  */
00618 GATResult GATSecurityContext_GetRemoteAuthenticate(GATSecurityContext this, GATLocation *location, char **name, char **passphrase)
00619 {
00620   GATResult retval;
00621   
00622   retval = GAT_INVALID_HANDLE;
00623   if( NULL != this )
00624   {
00625     retval = GAT_INVALID_PARAMETER;
00626     if( (NULL != location) && (NULL != name) && (NULL != passphrase) )
00627     {
00628       retval = GAT_INVALID_STATE;
00629       if( GATSecurityContextType_Remote == this->securityContextType )
00630       {
00631         retval = GAT_MEMORYFAILURE;
00632         (*name) = GATSecurityContext_StringClone( (this->securityContextUnion).remoteSecurityContext.name );
00633         (*passphrase) = GATSecurityContext_StringClone( (this->securityContextUnion).remoteSecurityContext.passphrase );
00634         if( (NULL != *name) && (NULL != *passphrase) )
00635         {
00636           retval = GATLocation_Clone( (this->securityContextUnion).remoteSecurityContext.location, location );
00637           if(GAT_SUCCESS != retval)
00638           {
00639             free(*name);
00640             free(*passphrase);
00641           }
00642         }
00643         else
00644         {
00645           free(*name);
00646           free(*passphrase);
00647         }
00648       }
00649     }
00650   }
00651   
00652   return retval;
00653 }
00654 
00655 /**
00656  * This function returns the GATSecurityContextType of this GATSecurityContext
00657  *
00658  * @param this The GATSecurityContext to query
00659  * @param type The GATSecurityContextType of this
00660  * @return An error code
00661  */
00662 GATResult GATSecurityContext_GetSecurityContextType(GATSecurityContext this, GATSecurityContextType *type)
00663 {
00664   GATResult retval;
00665   
00666   retval = GAT_INVALID_HANDLE;
00667   if( NULL != this )
00668   {
00669     retval = GAT_INVALID_PARAMETER;
00670     if( NULL != type )
00671     {
00672       retval = GAT_SUCCESS;
00673       (*type) = this->securityContextType;
00674     }
00675   }
00676   
00677   return retval;
00678 }
00679 
00680 /* Local functions */
00681 static char *GATSecurityContext_StringClone(const char *oldString)
00682 {
00683    char *newString;
00684    size_t memoryToAllocate;
00685    
00686    memoryToAllocate = strlen(oldString) + 1;
00687    newString = (char *) malloc( memoryToAllocate );
00688    if( NULL != newString )
00689    {
00690      strcpy(newString, oldString);
00691    }
00692    
00693    return newString;
00694 }
00695 
00696 static void GATSecurityContext_PartialDestroy(GATSecurityContext *this)
00697 {
00698   if( NULL != (*this) )
00699   {
00700     if(GATSecurityContextType_Password == (*this)->securityContextType)
00701     {
00702       free( ((*this)->securityContextUnion).passwordSecurityContext.username );
00703       free( ((*this)->securityContextUnion).passwordSecurityContext.password );
00704       
00705       ((*this)->securityContextUnion).passwordSecurityContext.username = NULL;
00706       ((*this)->securityContextUnion).passwordSecurityContext.password = NULL;
00707     }
00708     
00709     if(GATSecurityContextType_Certificate == (*this)->securityContextType)
00710     {
00711       free( ((*this)->securityContextUnion).certificateSecurityContext.keyfile );
00712       free( ((*this)->securityContextUnion).certificateSecurityContext.passphrase );
00713       free( ((*this)->securityContextUnion).certificateSecurityContext.certificate );
00714       
00715       ((*this)->securityContextUnion).certificateSecurityContext.keyfile = NULL;
00716       ((*this)->securityContextUnion).certificateSecurityContext.passphrase = NULL;
00717       ((*this)->securityContextUnion).certificateSecurityContext.certificate = NULL;
00718     }
00719     
00720     if(GATSecurityContextType_Remote == (*this)->securityContextType)
00721     {
00722       free( ((*this)->securityContextUnion).remoteSecurityContext.name );
00723       free( ((*this)->securityContextUnion).remoteSecurityContext.passphrase );
00724       GATLocation_Destroy( &(((*this)->securityContextUnion).remoteSecurityContext.location) );
00725       
00726       ((*this)->securityContextUnion).remoteSecurityContext.name = NULL;
00727       ((*this)->securityContextUnion).remoteSecurityContext.passphrase = NULL;
00728     }    
00729   }
00730 }