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
00031
00032
00033
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
00060 #define GRST_RET_OK 0
00061
00062
00063 #define GRST_RET_FAILED 1000
00064
00065
00066 #define GRST_RET_CERT_NOT_FOUND 1001
00067
00068
00069 #define GRST_RET_BAD_SIGNATURE 1002
00070
00071
00072 #define GRST_RET_NO_SUCH_FILE 1003
00073
00074
00075
00076 #define GRSTerrorLog(GRSTerrorLevel, ...) ((GRSTerrorLogFunc != NULL) && ((GRSTerrorLogFunc)(__FILE__, __LINE__, GRSTerrorLevel, __VA_ARGS__)))
00077
00078 extern int (*GRSTerrorLogFunc)(char *, int, int, char *, ...);
00079
00080
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
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
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;
00160 int errors;
00161 char *issuer;
00162 char *dn;
00163 char *value;
00164 time_t notbefore;
00165 time_t notafter;
00166 int delegation;
00167 int serial;
00168 char *ocsp;
00169 void *raw;
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
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;
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
00249 int GRSTgaclCredFree(GRSTgaclCred *);
00250
00251
00252 int GRSTgaclEntryAddCred(GRSTgaclEntry *, GRSTgaclCred *);
00253
00254
00255 int GRSTgaclEntryDelCred(GRSTgaclEntry *, GRSTgaclCred *);
00256
00257
00258 int GRSTgaclCredCredPrint(GRSTgaclCred *, FILE *);
00259
00260 int GRSTgaclCredCmpAuri(GRSTgaclCred *, GRSTgaclCred *);
00261
00262
00263 GRSTgaclEntry *GRSTgaclEntryNew(void);
00264
00265
00266 int GRSTgaclEntryFree(GRSTgaclEntry *);
00267
00268
00269 int GRSTgaclAclAddEntry(GRSTgaclAcl *, GRSTgaclEntry *);
00270
00271
00272 int GRSTgaclEntryPrint(GRSTgaclEntry *, FILE *);
00273
00274
00275
00276 int GRSTgaclPermPrint(GRSTgaclPerm, FILE *);
00277
00278
00279 int GRSTgaclEntryAllowPerm(GRSTgaclEntry *, GRSTgaclPerm);
00280
00281
00282 int GRSTgaclEntryUnallowPerm(GRSTgaclEntry *, GRSTgaclPerm);
00283
00284
00285 int GRSTgaclEntryDenyPerm(GRSTgaclEntry *, GRSTgaclPerm);
00286
00287
00288 int GRSTgaclEntryUndenyPerm(GRSTgaclEntry *, GRSTgaclPerm);
00289
00290
00291 char *GRSTgaclPermToChar(GRSTgaclPerm);
00292
00293
00294 GRSTgaclPerm GRSTgaclPermFromChar(char *);
00295
00296
00297 GRSTgaclAcl *GRSTgaclAclNew(void);
00298
00299
00300 int GRSTgaclAclFree(GRSTgaclAcl *);
00301
00302
00303 int GRSTgaclAclPrint(GRSTgaclAcl *, FILE *);
00304
00305
00306 int GRSTgaclAclSave(GRSTgaclAcl *, char *);
00307
00308
00309 GRSTgaclAcl *GRSTgaclAclLoadFile(char *);
00310
00311
00312 char *GRSTgaclFileFindAclname(char *);
00313
00314
00315 GRSTgaclAcl *GRSTgaclAclLoadforFile(char *);
00316
00317
00318 int GRSTgaclFileIsAcl(char *);
00319
00320
00321
00322 GRSTgaclUser *GRSTgaclUserNew(GRSTgaclCred *);
00323
00324
00325 int GRSTgaclUserFree(GRSTgaclUser *);
00326
00327
00328 int GRSTgaclUserAddCred(GRSTgaclUser *, GRSTgaclCred *);
00329
00330
00331 int GRSTgaclUserHasCred(GRSTgaclUser *, GRSTgaclCred *);
00332
00333 __attribute__ ((deprecated))
00334 int GRSTgaclUserSetDNlists(GRSTgaclUser *, char *);
00335
00336 int GRSTgaclUserLoadDNlists(GRSTgaclUser *, char *);
00337
00338
00339 GRSTgaclCred *GRSTgaclUserFindCredtype(GRSTgaclUser *, char *);
00340
00341 __attribute__ ((deprecated))
00342 int GRSTgaclDNlistHasUser(char *, GRSTgaclUser *);
00343
00344 int GRSTgaclUserHasAURI(GRSTgaclUser *, char *);
00345
00346
00347 GRSTgaclPerm GRSTgaclAclTestUser(GRSTgaclAcl *, GRSTgaclUser *);
00348
00349
00350 GRSTgaclPerm GRSTgaclAclTestexclUser(GRSTgaclAcl *, GRSTgaclUser *);
00351
00352 char *GRSThttpUrlDecode(char *);
00353
00354
00355 char *GRSThttpUrlEncode(char *);
00356
00357
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);