gridsite.h

Go to the documentation of this file.
00001 /*
00002    Copyright (c) 2002-9, Andrew McNab, University of Manchester
00003    All rights reserved.
00004 
00005    Redistribution and use in source and binary forms, with or
00006    without modification, are permitted provided that the following
00007    conditions are met:
00008 
00009      o Redistributions of source code must retain the above
00010        copyright notice, this list of conditions and the following
00011        disclaimer. 
00012      o Redistributions in binary form must reproduce the above
00013        copyright notice, this list of conditions and the following
00014        disclaimer in the documentation and/or other materials
00015        provided with the distribution. 
00016 
00017    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
00018    CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
00019    INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00020    MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00021    DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
00022    BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00023    EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
00024    TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00025    DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
00026    ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00027    OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00028    OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00029    POSSIBILITY OF SUCH DAMAGE.
00030 */
00031 
00032 /*---------------------------------------------------------------*
00033  * For more about GridSite: http://www.gridsite.org/             *
00034  *---------------------------------------------------------------*/
00035 
00036 #ifndef GRST_VERSION
00037 #define GRST_VERSION 010500
00038 #endif
00039 
00040 #ifndef HEADER_SSL_H
00041 #include <openssl/ssl.h>
00042 #endif
00043 
00044 #ifndef HEADER_CRYPTO_H
00045 #include <openssl/crypto.h>
00046 #endif
00047 
00048 #ifndef _STDINT_H
00049 #include <stdint.h>
00050 #endif
00051 
00052 #ifndef FALSE
00053 #define FALSE (0)
00054 #endif
00055 #ifndef TRUE
00056 #define TRUE (!FALSE)
00057 #endif
00058 
00059 // Everything ok (= OpenSSL X509_V_OK)
00060 #define GRST_RET_OK             0
00061 
00062 // Failed for unspecified reason
00063 #define GRST_RET_FAILED         1000
00064 
00065 // Failed to find certificate in some cert store / directory
00066 #define GRST_RET_CERT_NOT_FOUND 1001
00067 
00068 // Bad signature
00069 #define GRST_RET_BAD_SIGNATURE  1002
00070 
00071 // No such file or directory
00072 #define GRST_RET_NO_SUCH_FILE   1003
00073 
00074 /* We use && now rather than if so this macro can be used inside if...else
00075    but that means the function must return an int rather than be void */
00076 #define GRSTerrorLog(GRSTerrorLevel, ...) ((GRSTerrorLogFunc != NULL) && ((GRSTerrorLogFunc)(__FILE__, __LINE__, GRSTerrorLevel, __VA_ARGS__)))
00077 
00078 extern int (*GRSTerrorLogFunc)(char *, int, int, char *, ...);
00079 
00080 /* these levels are the same as Unix syslog() and Apache ap_log_error() */
00081 
00082 #define GRST_LOG_EMERG   0
00083 #define GRST_LOG_ALERT   1
00084 #define GRST_LOG_CRIT    2
00085 #define GRST_LOG_ERR     3
00086 #define GRST_LOG_WARNING 4
00087 #define GRST_LOG_NOTICE  5
00088 #define GRST_LOG_INFO    6
00089 #define GRST_LOG_DEBUG   7
00090 
00091 #define GRST_MAX_TIME_T  INT32_MAX
00092 
00093 typedef struct { char                      *auri;
00094                  int                        delegation;
00095                  int                        nist_loa;
00096                  time_t                     notbefore;
00097                  time_t                     notafter;
00098                  void                      *next;     } GRSTgaclCred;
00099 
00100 /* used by pre-AURI GRSTgaclCred structs */ 
00101 __attribute__ ((deprecated))
00102 typedef struct { char                      *name;
00103                  char                      *value;
00104                  void                      *next;  } GRSTgaclNamevalue;
00105 
00106 typedef int                GRSTgaclAction;
00107 typedef unsigned int       GRSTgaclPerm;
00108  
00109 typedef struct { GRSTgaclCred   *firstcred;
00110                  GRSTgaclPerm    allowed;
00111                  GRSTgaclPerm    denied;
00112                  void           *next;    } GRSTgaclEntry;
00113  
00114 typedef struct { GRSTgaclEntry *firstentry; } GRSTgaclAcl;
00115  
00116 typedef struct { GRSTgaclCred *firstcred; char *dnlists; } GRSTgaclUser;
00117 
00118 #define GRST_PERM_NONE   0
00119 #define GRST_PERM_READ   1
00120 #define GRST_PERM_EXEC   2
00121 #define GRST_PERM_LIST   4
00122 #define GRST_PERM_WRITE  8
00123 #define GRST_PERM_ADMIN 16
00124 #define GRST_PERM_ALL   31
00125 
00126 /* DO NOT USE PermIsNone!! */
00127 #define GRSTgaclPermIsNone(perm)    ((perm) == 0)
00128 
00129 #define GRSTgaclPermHasNone(perm)    ((perm) == 0)
00130 #define GRSTgaclPermHasRead(perm)  (((perm) & GRST_PERM_READ ) != 0)
00131 #define GRSTgaclPermHasExec(perm)  (((perm) & GRST_PERM_EXEC ) != 0)
00132 #define GRSTgaclPermHasList(perm)  (((perm) & GRST_PERM_LIST ) != 0)
00133 #define GRSTgaclPermHasWrite(perm) (((perm) & GRST_PERM_WRITE) != 0)
00134 #define GRSTgaclPermHasAdmin(perm) (((perm) & GRST_PERM_ADMIN) != 0)
00135 
00136 #define GRST_ACTION_ALLOW 0
00137 #define GRST_ACTION_DENY  1
00138 
00139 #define GRST_HIST_PREFIX  ".grsthist"
00140 #define GRST_ACL_FILE     ".gacl"
00141 #define GRST_DN_LISTS     "/etc/grid-security/dn-lists"
00142 #define GRST_RECURS_LIMIT 9
00143 
00144 #define GRST_PROXYCERTINFO_OLD_OID      "1.3.6.1.4.1.3536.1.222"
00145 #define GRST_PROXYCERTINFO_OID          "1.3.6.1.5.5.7.1.14"
00146 #define GRST_VOMS_OID           "1.3.6.1.4.1.8005.100.100.5"
00147 #define GRST_VOMS_DIR           "/etc/grid-security/vomsdir"
00148 #define GRST_KEYUSAGE_OID       "2.5.29.15"
00149  
00150 #define GRST_ASN1_MAXCOORDLEN   50
00151 #define GRST_ASN1_MAXTAGS       500
00152 
00153 struct GRSTasn1TagList { char treecoords[GRST_ASN1_MAXCOORDLEN+1];
00154                          int  start;
00155                          int  headerlength;
00156                          int  length;
00157                          int  tag; } ;
00158 
00159 typedef struct { int    type;           /* CA, user, proxy, VOMS, ... */
00160                  int    errors;         /* unchecked, bad sig, bad time */
00161                  char   *issuer;        /* Cert CA DN, EEC of PC, or VOMS DN */
00162                  char   *dn;            /* Cert DN, or VOMS AC holder DN */
00163                  char   *value;         /* VOMS FQAN or NULL */
00164                  time_t notbefore;
00165                  time_t notafter;
00166                  int    delegation;     /* relative to END of any chain */
00167                  int    serial;
00168                  char   *ocsp;          /* accessLocation field */
00169                  void   *raw;           /* X509 or VOMS Extension object */
00170                  void   *next; } GRSTx509Cert;
00171 
00172 #define GRST_CERT_BAD_FORMAT 1
00173 #define GRST_CERT_BAD_CHAIN  2
00174 #define GRST_CERT_BAD_SIG    4
00175 #define GRST_CERT_BAD_TIME   8
00176 #define GRST_CERT_BAD_OCSP  16
00177 
00178 #define GRST_CERT_TYPE_CA    1
00179 #define GRST_CERT_TYPE_EEC   2
00180 #define GRST_CERT_TYPE_PROXY 3
00181 #define GRST_CERT_TYPE_VOMS  4
00182 
00183 /* a chain of certs, starting from the first CA */
00184 typedef struct { GRSTx509Cert *firstcert; } GRSTx509Chain;
00185 
00186 int GRSTx509CertLoad(GRSTx509Cert *, X509 *);
00187 int GRSTx509ChainLoadCheck(GRSTx509Chain **, STACK_OF(X509) *, X509 *, char *, char *);
00188 int GRSTx509ChainFree(GRSTx509Chain *);
00189 
00190 #define GRST_HTTP_PORT          777
00191 #define GRST_HTTPS_PORT         488
00192 #define GRST_HTCP_PORT          777
00193 #define GRST_GSIFTP_PORT        2811
00194                          
00195 #define GRSThtcpNOPop 0
00196 #define GRSThtcpTSTop 1
00197 
00198 typedef struct { unsigned char length_msb;
00199                  unsigned char length_lsb;
00200                  char text[1]; } GRSThtcpCountstr;
00201 
00202 #define GRSThtcpCountstrLen(string) (256*((string)->length_msb) + (string)->length_lsb)
00203 
00204 typedef struct { unsigned char total_length_msb;
00205                  unsigned char total_length_lsb;
00206                  unsigned char version_msb;
00207                  unsigned char version_lsb;
00208                  unsigned char data_length_msb;
00209                  unsigned char data_length_lsb;
00210                  unsigned int  response : 4;
00211                  unsigned int  opcode   : 4;
00212                  unsigned int  rr       : 1;                 
00213                  unsigned int  f1       : 1;
00214                  unsigned int  reserved : 6;
00215                  unsigned int  trans_id;        /* must be 4 bytes */
00216                  GRSThtcpCountstr *method;
00217                  GRSThtcpCountstr *uri;
00218                  GRSThtcpCountstr *version;
00219                  GRSThtcpCountstr *req_hdrs;
00220                  GRSThtcpCountstr *resp_hdrs;
00221                  GRSThtcpCountstr *entity_hdrs;
00222                  GRSThtcpCountstr *cache_hdrs;   } GRSThtcpMessage;
00223 
00224 int GRSTgaclInit(void);
00225 
00226 __attribute__ ((deprecated))
00227 GRSTgaclCred *GRSTgaclCredNew(char *);
00228 
00229 GRSTgaclCred *GRSTgaclCredCreate(char *, char *);
00230 
00231 __attribute__ ((deprecated))
00232 int     GRSTgaclCredAddValue(GRSTgaclCred *, char *, char *);
00233 
00234 #define GRSTgaclCredGetAuri(cred) ((cred)->auri)
00235 
00236 #define GRSTgaclCredSetNotBefore(cred, time) ((cred)->notbefore = (time))
00237 #define GRSTgaclCredGetNotBefore(cred) ((cred)->notbefore)
00238 
00239 #define GRSTgaclCredSetNotAfter(cred, time) ((cred)->notafter = (time))
00240 #define GRSTgaclCredGetNotAfter(cred) ((cred)->notafter)
00241 
00242 #define GRSTgaclCredSetDelegation(cred, level) ((cred)->delegation = (level))
00243 #define GRSTgaclCredGetDelegation(cred) ((cred)->delegation)
00244 
00245 #define GRSTgaclCredSetNistLoa(cred, level) ((cred)->nist_loa = (level))
00246 #define GRSTgaclCredGetNistLoa(cred) ((cred)->nist_loa)
00247 
00248 /* #define GACLfreeCred(x)              GRSTgaclCredFree((x)) */
00249 int        GRSTgaclCredFree(GRSTgaclCred *);
00250 
00251 /*  #define GACLaddCred(x,y)    GRSTgaclEntryAddCred((x),(y)) */
00252 int        GRSTgaclEntryAddCred(GRSTgaclEntry *, GRSTgaclCred *);
00253 
00254 /*  #define GACLdelCred(x,y)    GRSTgaclEntryDelCred((x),(y)) */
00255 int        GRSTgaclEntryDelCred(GRSTgaclEntry *, GRSTgaclCred *);
00256 
00257 /*  #define GACLprintCred(x,y)  GRSTgaclCredPrint((x),(y)) */
00258 int        GRSTgaclCredCredPrint(GRSTgaclCred *, FILE *);
00259 
00260 int        GRSTgaclCredCmpAuri(GRSTgaclCred *, GRSTgaclCred *);
00261 
00262 /*  #define GACLnewEntry(x)             GRSTgaclEntryNew((x)) */
00263 GRSTgaclEntry *GRSTgaclEntryNew(void);
00264 
00265 /*  #define GACLfreeEntry(x)    GRSTgaclEntryFree((x)) */
00266 int        GRSTgaclEntryFree(GRSTgaclEntry *);
00267 
00268 /*  #define GACLaddEntry(x,y)   GRSTgaclAclAddEntry((x),(y)) */
00269 int        GRSTgaclAclAddEntry(GRSTgaclAcl *, GRSTgaclEntry *);
00270 
00271 /*  #define GACLprintEntry(x,y) GRSTgaclEntryPrint((x),(y)) */
00272 int        GRSTgaclEntryPrint(GRSTgaclEntry *, FILE *);
00273 
00274 
00275 /*  #define GACLprintPerm(x,y)  GRSTgaclPermPrint((x),(y)) */
00276 int        GRSTgaclPermPrint(GRSTgaclPerm, FILE *);
00277 
00278 /*  #define GACLallowPerm(x,y)  GRSTgaclEntryAllowPerm((x),(y)) */
00279 int        GRSTgaclEntryAllowPerm(GRSTgaclEntry *, GRSTgaclPerm);
00280 
00281 /*  #define GACLunallowPerm(x,y)        GRSTgaclEntryUnallowPerm((x),(y)) */
00282 int        GRSTgaclEntryUnallowPerm(GRSTgaclEntry *, GRSTgaclPerm);
00283 
00284 /*  #define GACLdenyPerm(x,y)   GRSTgaclEntryDenyPerm((x),(y)) */
00285 int        GRSTgaclEntryDenyPerm(GRSTgaclEntry *, GRSTgaclPerm);
00286 
00287 /*  #define GACLundenyPerm(x,y) GRSTgaclEntryUndenyPerm((x),(y)) */
00288 int        GRSTgaclEntryUndenyPerm(GRSTgaclEntry *, GRSTgaclPerm);
00289 
00290 /*  #define GACLpermToChar(x)   GRSTgaclPermToChar((x)) */
00291 char      *GRSTgaclPermToChar(GRSTgaclPerm);
00292 
00293 /*  #define GACLcharToPerm(x)   GRSTgaclPermFromChar((x)) */
00294 GRSTgaclPerm   GRSTgaclPermFromChar(char *);
00295 
00296 /*  #define GACLnewAcl(x)               GRSTgaclAclNew((x)) */
00297 GRSTgaclAcl   *GRSTgaclAclNew(void);
00298 
00299 /*  #define GACLfreeAcl(x)              GRSTgaclAclFree((x)) */
00300 int        GRSTgaclAclFree(GRSTgaclAcl *);
00301 
00302 /*  #define GACLprintAcl(x,y)   GRSTgaclAclPrint((x),(y)) */
00303 int        GRSTgaclAclPrint(GRSTgaclAcl *, FILE *);
00304 
00305 /*  #define GACLsaveAcl(x,y)    GRSTgaclAclSave((y),(x)) */
00306 int        GRSTgaclAclSave(GRSTgaclAcl *, char *);
00307 
00308 /*  #define GACLloadAcl(x)              GRSTgaclFileLoadAcl((x)) */
00309 GRSTgaclAcl   *GRSTgaclAclLoadFile(char *);
00310 
00311 /*  #define GACLfindAclForFile(x)       GRSTgaclFileFindAclname((x)) */
00312 char      *GRSTgaclFileFindAclname(char *);
00313 
00314 /*  #define GACLloadAclForFile(x)       GRSTgaclFileLoadAcl((x)) */
00315 GRSTgaclAcl   *GRSTgaclAclLoadforFile(char *);
00316 
00317 /*  #define GACLisAclFile(x)    GRSTgaclFileIsAcl((x)) */
00318 int        GRSTgaclFileIsAcl(char *);
00319 
00320 
00321 /*  #define GACLnewUser(x)              GRSTgaclUserNew((x)) */
00322 GRSTgaclUser *GRSTgaclUserNew(GRSTgaclCred *);
00323 
00324 /*  #define GACLfreeUser(x)             GRSTgaclUserFree((x)) */
00325 int       GRSTgaclUserFree(GRSTgaclUser *);
00326 
00327 /*  #define GACLuserAddCred(x,y)        GRSTgaclUserAddCred((x),(y)) */
00328 int       GRSTgaclUserAddCred(GRSTgaclUser *, GRSTgaclCred *);
00329 
00330 /*  #define GACLuserHasCred(x,y)        GRSTgaclUserHasCred((x),(y)) */
00331 int       GRSTgaclUserHasCred(GRSTgaclUser *, GRSTgaclCred *);
00332 
00333 __attribute__ ((deprecated))
00334 int       GRSTgaclUserSetDNlists(GRSTgaclUser *, char *);
00335 
00336 int       GRSTgaclUserLoadDNlists(GRSTgaclUser *, char *);
00337 
00338 /*  #define GACLuserFindCredType(x,y) GRSTgaclUserFindCredtype((x),(y)) */
00339 GRSTgaclCred *GRSTgaclUserFindCredtype(GRSTgaclUser *, char *);
00340 
00341 __attribute__ ((deprecated))
00342 int GRSTgaclDNlistHasUser(char *, GRSTgaclUser *);
00343 
00344 int GRSTgaclUserHasAURI(GRSTgaclUser *, char *);
00345 
00346 /*  #define GACLtestUserAcl(x,y)        GRSTgaclAclTestUser((x),(y)) */
00347 GRSTgaclPerm   GRSTgaclAclTestUser(GRSTgaclAcl *, GRSTgaclUser *);
00348 
00349 /*  #define GACLtestExclAcl(x,y)        GRSTgaclAclTestexclUser((x),(y)) */
00350 GRSTgaclPerm   GRSTgaclAclTestexclUser(GRSTgaclAcl *, GRSTgaclUser *);
00351 
00352 char      *GRSThttpUrlDecode(char *);
00353 
00354 /*  #define GACLurlEncode(x)    GRSThttpUrlEncode((x)) */
00355 char      *GRSThttpUrlEncode(char *);
00356 
00357 /*  #define GACLmildUrlEncode(x)        GRSThttpMildUrlEncode((x)) */
00358 char      *GRSThttpUrlMildencode(char *);
00359 
00360 int GRSTx509NameCmp(char *, char *);
00361 
00362 int GRSTx509KnownCriticalExts(X509 *);
00363 
00364 int GRSTx509IsCA(X509 *);
00365 int GRSTx509CheckChain(int *, X509_STORE_CTX *);
00366 int GRSTx509VerifyCallback(int, X509_STORE_CTX *);
00367 
00368 __attribute__ ((deprecated))
00369 int GRSTx509GetVomsCreds(int *, int, size_t, char *, X509 *, STACK_OF(X509) *, char *);
00370 
00371 __attribute__ ((deprecated))
00372 GRSTgaclCred *GRSTx509CompactToCred(char *);
00373 
00374 __attribute__ ((deprecated))
00375 int GRSTx509CompactCreds(int *, int, size_t, char *, STACK_OF(X509) *, char *, X509 *);
00376 
00377 char *GRSTx509CachedProxyFind(char *, char *, char *);
00378 char *GRSTx509FindProxyFileName(void);
00379 int GRSTx509MakeProxyCert(char **, FILE *, char *, char *, char *, int);
00380 char *GRSTx509CachedProxyKeyFind(char *, char *, char *);
00381 int GRSTx509ProxyDestroy(char *, char *, char *);
00382 int GRSTx509ProxyGetTimes(char *, char *, char *, time_t *, time_t *);
00383 int GRSTx509CreateProxyRequest(char **, char **, char *);
00384 int GRSTx509MakeProxyRequest(char **, char *, char *, char *);
00385 int GRSTx509StringToChain(STACK_OF(X509) **, char *);
00386 char *GRSTx509MakeDelegationID(void);
00387 char *GRSTx509MakeProxyFileName(char *, STACK_OF(X509) *);
00388 int GRSTx509CacheProxy(char *, char *, char *, char *);
00389 
00390 #define GRST_HEADFILE   "gridsitehead.txt"
00391 #define GRST_FOOTFILE   "gridsitefoot.txt"
00392 #define GRST_ADMIN_FILE "gridsite-admin.cgi"
00393 
00394 typedef struct { char *text;
00395                  void *next; } GRSThttpCharsList;
00396 
00397 typedef struct { size_t             size;
00398                  GRSThttpCharsList *first;
00399                  GRSThttpCharsList *last;  } GRSThttpBody;
00400 
00401 void  GRSThttpBodyInit(GRSThttpBody *); 
00402 void  GRSThttpPrintf(GRSThttpBody *, char *, ...);
00403 int   GRSThttpCopy(GRSThttpBody *, char *);
00404 void  GRSThttpWriteOut(GRSThttpBody *);
00405 int   GRSThttpPrintHeaderFooter(GRSThttpBody *, char *, char *);
00406 int   GRSThttpPrintHeader(GRSThttpBody *, char *);
00407 int   GRSThttpPrintFooter(GRSThttpBody *, char *);
00408 char *GRSThttpGetCGI(char *);
00409 
00410 time_t GRSTasn1TimeToTimeT(char *, size_t);
00411 int    GRSTasn1SearchTaglist(struct GRSTasn1TagList taglist[], int, char *);
00412 int    GRSTasn1ParseDump(BIO *, unsigned char *, long,
00413                          struct GRSTasn1TagList taglist[], int, int *);
00414 int    GRSTasn1GetX509Name(char *, int, char *, char *,
00415                            struct GRSTasn1TagList taglist[], int);
00416 
00417 int    GRSThtcpNOPrequestMake(char **, int *, unsigned int);
00418 int    GRSThtcpNOPresponseMake(char **, int *, unsigned int);
00419 int    GRSThtcpTSTrequestMake(char **, int *, unsigned int, char *, char *, char *);
00420 int    GRSThtcpTSTresponseMake(char **, int *, unsigned int, char *, char *, char *);
00421 int    GRSThtcpMessageParse(GRSThtcpMessage *, char *, int);

Generated on Wed Sep 22 00:12:19 2010 by  doxygen 1.5.5