[0001]
[0002]
[0003]
[0004]
[0005]
[0006]
[0007]
[0008]
[0009]
[0010]
[0011]
[0012]
[0013]
[0014]
[0015]
[0016]
[0017]
[0018]
[0019]
[0020]
[0021]
[0022]
[0023]
[0024]
[0025]
[0026]
[0027]
[0028]
[0029]
[0030]
[0031]
[0032]
[0033]
[0034]
[0035]
[0036]
[0037]
[0038]
[0039]
[0040]
[0041]
[0042]
[0043]
[0044]
[0045]
[0046]
[0047]
[0048]
[0049]
[0050]
[0051]
[0052]
[0053]
[0054]
[0055]
[0056]
[0057]
[0058]
[0059]
[0060]
[0061]
[0062]
[0063]
[0064]
[0065]
[0066]
[0067]
[0068]
[0069]
[0070]
[0071]
[0072]
[0073]
[0074]
[0075]
[0076]
[0077]
[0078]
[0079]
[0080]
[0081]
[0082]
[0083]
[0084]
[0085]
[0086]
[0087]
[0088]
[0089]
[0090]
[0091]
[0092]
[0093]
[0094]
[0095]
[0096]
[0097]
[0098]
[0099]
[0100]
[0101]
[0102]
[0103]
[0104]
[0105]
[0106]
[0107]
[0108]
[0109]
[0110]
[0111]
[0112]
[0113]
[0114]
[0115]
[0116]
[0117]
[0118]
[0119]
[0120]
[0121]
[0122]
[0123]
[0124]
[0125]
[0126]
[0127]
[0128]
[0129]
[0130]
[0131]
[0132]
[0133]
[0134]
[0135]
[0136]
[0137]
[0138]
[0139]
[0140]
[0141]
[0142]
[0143]
[0144]
[0145]
[0146]
[0147]
[0148]
[0149]
[0150]
[0151]
[0152]
[0153]
[0154]
[0155]
[0156]
[0157]
[0158]
[0159]
[0160]
[0161]
[0162]
[0163]
[0164]
[0165]
[0166]
[0167]
[0168]
[0169]
[0170]
[0171]
[0172]
[0173]
[0174]
[0175]
[0176]
[0177]
[0178]
[0179]
[0180]
[0181]
[0182]
[0183]
[0184]
[0185]
[0186]
[0187]
[0188]
[0189]
[0190]
[0191]
[0192]
[0193]
[0194]
[0195]
[0196]
[0197]
[0198]
[0199]
[0200]
[0201]
[0202]
[0203]
[0204]
[0205]
[0206]
[0207]
[0208]
[0209]
[0210]
[0211]
[0212]
[0213]
[0214]
[0215]
[0216]
[0217]
[0218]
[0219]
[0220]
[0221]
[0222]
[0223]
[0224]
[0225]
[0226]
[0227]
[0228]
[0229]
[0230]
[0231]
[0232]
[0233]
[0234]
[0235]
[0236]
[0237]
[0238]
[0239]
[0240]
[0241]
[0242]
[0243]
[0244]
[0245]
[0246]
[0247]
[0248]
[0249]
[0250]
[0251]
[0252]
[0253]
[0254]
[0255]
[0256]
[0257]
[0258]
[0259]
[0260]
[0261]
[0262]
[0263]
[0264]
[0265]
[0266]
[0267]
[0268]
[0269]
[0270]
[0271]
[0272]
[0273]
[0274]
[0275]
[0276]
[0277]
[0278]
[0279]
[0280]
[0281]
[0282]
[0283]
[0284]
[0285]
[0286]
[0287]
[0288]
[0289]
[0290]
[0291]
[0292]
[0293]
[0294]
[0295]
[0296]
[0297]
[0298]
[0299]
[0300]
[0301]
[0302]
[0303]
[0304]
[0305]
[0306]
[0307]
[0308]
[0309]
[0310]
[0311]
[0312]
[0313]
[0314]
[0315]
[0316]
[0317]
[0318]
[0319]
[0320]
[0321]
[0322]
[0323]
[0324]
[0325]
[0326]
[0327]
[0328]
[0329]
[0330]
[0331]
[0332]
[0333]
[0334]
[0335]
[0336]
[0337]
[0338]
[0339]
[0340]
[0341]
[0342]
[0343]
[0344]
[0345]
[0346]
[0347]
[0348]
[0349]
[0350]
[0351]
[0352]
[0353]
[0354]
[0355]
[0356]
[0357]
[0358]
[0359]
[0360]
[0361]
[0362]
[0363]
[0364]
[0365]
[0366]
[0367]
[0368]
[0369]
[0370]
[0371]
[0372]
[0373]
[0374]
[0375]
[0376]
[0377]
[0378]
[0379]
[0380]
[0381]
[0382]
[0383]
[0384]
[0385]
[0386]
[0387]
[0388]
[0389]
[0390]
[0391]
[0392]
[0393]
[0394]
[0395]
[0396]
[0397]
[0398]
[0399]
[0400]
[0401]
[0402]
[0403]
[0404]
[0405]
[0406]
[0407]
[0408]
[0409]
[0410]
[0411]
[0412]
[0413]
[0414]
[0415]
[0416]
[0417]
[0418]
[0419]
[0420]
[0421]
[0422]
[0423]
[0424]
[0425]
[0426]
[0427]
[0428]
[0429]
[0430]
[0431]
[0432]
[0433]
[0434]
[0435]
[0436]
[0437]
[0438]
[0439]
[0440]
[0441]
[0442]
[0443]
[0444]
[0445]
[0446]
[0447]
[0448]
[0449]
[0450]
[0451]
[0452]
[0453]
[0454]
[0455]
[0456]
[0457]
[0458]
[0459]
[0460]
[0461]
[0462]
[0463]
[0464]
[0465]
[0466]
[0467]
[0468]
[0469]
[0470]
[0471]
[0472]
[0473]
[0474]
[0475]
[0476]
[0477]
[0478]
[0479]
[0480]
[0481]
[0482]
[0483]
[0484]
[0485]
[0486]
[0487]
[0488]
[0489]
[0490]
[0491]
[0492]
[0493]
[0494]
[0495]
[0496]
[0497]
[0498]
[0499]
[0500]
[0501]
[0502]
[0503]
[0504]
[0505]
[0506]
[0507]
[0508]
[0509]
[0510]
[0511]
[0512]
[0513]
[0514]
[0515]
[0516]
[0517]
[0518]
[0519]
[0520]
[0521]
[0522]
[0523]
[0524]
[0525]
[0526]
[0527]
[0528]
[0529]
[0530]
[0531]
[0532]
[0533]
[0534]
[0535]
[0536]
[0537]
[0538]
[0539]
[0540]
[0541]
[0542]
[0543]
[0544]
[0545]
[0546]
[0547]
[0548]
[0549]
[0550]
[0551]
[0552]
[0553]
[0554]
[0555]
[0556]
[0557]
[0558]
[0559]
[0560]
[0561]
[0562]
[0563]
[0564]
[0565]
[0566]
[0567]
[0568]
[0569]
[0570]
[0571]
[0572]
[0573]
[0574]
[0575]
[0576]
[0577]
[0578]
[0579]
[0580]
[0581]
[0582]
[0583]
[0584]
[0585]
[0586]
[0587]
[0588]
[0589]
[0590]
[0591]
[0592]
[0593]
[0594]
[0595]
[0596]
[0597]
[0598]
[0599]
[0600]
[0601]
[0602]
[0603]
[0604]
[0605]
[0606]
[0607]
[0608]
[0609]
[0610]
[0611]
[0612]
[0613]
[0614]
[0615]
[0616]
[0617]
[0618]
[0619]
[0620]
[0621]
[0622]
[0623]
[0624]
[0625]
[0626]
[0627]
[0628]
[0629]
[0630]
[0631]
[0632]
[0633]
[0634]
[0635]
[0636]
[0637]
[0638]
[0639]
[0640]
[0641]
[0642]
[0643]
[0644]
[0645]
[0646]
[0647]
[0648]
[0649]
[0650]
[0651]
[0652]
/*****************************************************************************/
/*
                                 Auth.h
*/
/*****************************************************************************/

#ifndef AUTH_H_LOADED
#define AUTH_H_LOADED 1

#include "wasd.h"

/* some storage maximums */
#define  AUTH_MAX_DIGEST_RESPONSE       32
#define  AUTH_MAX_PASSWORD_LENGTH       31
#define  AUTH_MAX_REALM_GROUP_LENGTH    32
#define  AUTH_MAX_REALM_DESCR_LENGTH   127
#define  AUTH_MAX_USERNAME_LENGTH       64  /* 12 or so for VMS user name */
                                            /* 47 for X509 fingerprint */
                                            /* 64 for X509 common name */
#define  AUTH_MAX_HTA_USERNAME_LENGTH   15  /* MUST remain at 15 */
#define  AUTH_MAX_FULLNAME_LENGTH       31
#define  AUTH_MAX_EMAIL_LENGTH         127
#define  AUTH_MAX_CONTACT_LENGTH       127
#define  AUTH_MAX_PATH_PARAM_LENGTH    255
#define  AUTH_MAX_REALM_PARAM_LENGTH   255
#define  AUTH_MAX_COOKIE_CACHE          32

#define  AUTH_SIZE_TOKEN_VALUE          31
#define  AUTH_SIZE_TOKEN_PATH           63
#define  AUTH_TOKEN_DEFAULT_RECORD_MAX 128
#define  AUTH_TOKEN_RECORD_MIN          32
#define  AUTH_TOKEN_NAME_DEFAULT       "WASDtoken"
#define  AUTH_TOKEN_MAXAGE_DEFAULT     "60"  /* seconds (string) */
#define  AUTH_TOKEN_MAXAGE_MIN           5   /* seconds (integer) */

/* password minimum (when changing in HTADMIN.C) */
#define  AUTH_MIN_PASSWORD 6

/* maximum number of VMS identifiers in array */
#define  AUTH_MIN_VMS_IDENTIFIERS 64
#define  AUTH_MAX_VMS_IDENTIFIERS 1024

/* size of static storage allocated for sys$create_user_profile() use */
#define AUTH_CREATE_USER_PROFILE_SIZE 2048

/* constants used to identify authorization schemes */
#define  AUTH_SCHEME_BASIC    0x00000001
#define  AUTH_SCHEME_DIGEST   0x00000002
#define  AUTH_SCHEME_X509     0x00000003
#define  AUTH_SCHEME_RFC1413  0x00000004
#define  AUTH_SCHEME_NO401    0x00000005
#define  AUTH_SCHEME_TOKEN    0x00000006

/* constants for bits for flags in HTA database */
#define  AUTH_FLAG_GET         0x00000001
#define  AUTH_FLAG_HEAD        0x00000002
#define  AUTH_FLAG_POST        0x00000004
#define  AUTH_FLAG_PUT         0x00000008
#define  AUTH_FLAG_DELETE      0x00000010
#define  AUTH_FLAG_CONNECT     0x00000020
#define  AUTH_FLAG_TRACE       0x00000040
#define  AUTH_FLAG_OPTIONS     0x00000080
#define  AUTH_FLAG_EXTENSION   0x00000100
#define  AUTH_FLAG_EVERYTHING  0x00ffffff
#define  AUTH_FLAG_HTTPS_ONLY  0x20000000
#define  AUTH_FLAG_MANAGER     0x40000000
#define  AUTH_FLAG_ENABLED     0x80000000

#define  AUTH_READWRITE_ACCESS  HTTP_READ_METHODS | \
                                HTTP_WRITE_METHODS | \
                                HTTP_WEBDAV_READ_METHODS | \
                                HTTP_WEBDAV_WRITE_METHODS

#define  AUTH_READONLY_ACCESS   HTTP_READ_METHODS | \
                                HTTP_WEBDAV_READ_METHODS

/* does not include WebDAV methods as write-only WebDAV doesn't make sense! */
#define  AUTH_WRITEONLY_ACCESS  HTTP_WRITE_METHODS

#define  AUTH_REALM_ACME         "ACME"
#define  AUTH_REALM_EXTERNAL     "EXTERNAL"
#define  AUTH_REALM_FAIL         "-FAIL-"
#define  AUTH_REALM_NONE         "NONE"
#define  AUTH_REALM_OPAQUE       "OPAQUE"
#define  AUTH_REALM_PROMISCUOUS  "PROMISCUOUS"
#define  AUTH_REALM_RFC1413      "RFC1413"
#define  AUTH_REALM_SKELKEY      "SKELKEY"
#define  AUTH_REALM_TOKEN        "TOKEN"
#define  AUTH_REALM_VMS          "VMS"
#define  AUTH_REALM_WORLD        "WORLD"
#define  AUTH_REALM_X509         "X509"

#define  AUTH_SOURCE_FAIL           1
#define  AUTH_SOURCE_NONE           2
#define  AUTH_SOURCE_WORLD          3
#define  AUTH_SOURCE_EXTERNAL       4
#define  AUTH_SOURCE_VMS            5
#define  AUTH_SOURCE_ID             6
#define  AUTH_SOURCE_ACME           7
#define  AUTH_SOURCE_LIST           8
#define  AUTH_SOURCE_DIR_LIST       9
#define  AUTH_SOURCE_HTA           10
#define  AUTH_SOURCE_DIR_HTA       11
#define  AUTH_SOURCE_WASD_ID       12
#define  AUTH_SOURCE_AGENT         13
#define  AUTH_SOURCE_AGENT_OPAQUE  14
#define  AUTH_SOURCE_X509          15
#define  AUTH_SOURCE_RFC1413       16
#define  AUTH_SOURCE_OPAQUE        17
#define  AUTH_SOURCE_HOST          18
#define  AUTH_SOURCE_PROMISCUOUS   19
#define  AUTH_SOURCE_SKELKEY       20
#define  AUTH_SOURCE_TOKEN         21
#define  AUTH_SOURCE_THEREST       22

#define  HTA_DIRECTORY     "?WASD_AUTH:\0HT_AUTH:\0"
#define  HTA_FILE_TYPE     ".$HTA"
#define  HTL_FILE_TYPE     ".$HTL"
#define  AUTH_AGENT_PATH   "/cgiauth-bin/"

/* bogus VMS status codes (errors), these can be passed back and detected */
#define  AUTH_DENIED_BY_FAIL      0x0fffff1a
#define  AUTH_DENIED_BY_GROUP     0x0fffff2a
#define  AUTH_DENIED_BY_HOSTNAME  0x0fffff3a
#define  AUTH_DENIED_BY_HOUR      0x0fffff4a
#define  AUTH_DENIED_BY_LOGIN     0x0fffff5a
#define  AUTH_DENIED_BY_LOGOUT    0x0fffff6a
#define  AUTH_DENIED_BY_NOCACHE   0x0fffff7a
#define  AUTH_DENIED_BY_OTHER     0x0fffff8a
#define  AUTH_DENIED_BY_PROTOCOL  0x0fffff9a
#define  AUTH_DENIED_BY_USERNAME  0x0fffffaa
#define  AUTH_DENIED_BY_REDIRECT  0x0fffffba
#define  AUTH_PENDING             0x0fffffca

/* identifier names controlling SYSUAF authentication with /SYSUAF=ID */
#define  AUTH_HTTPS_ONLY_VMS_ID        "WASD_HTTPS_ONLY"
#define  AUTH_NIL_ACCESS_VMS_ID        "WASD_NIL_ACCESS"
#define  AUTH_PASSWORD_CHANGE_VMS_ID   "WASD_PASSWORD_CHANGE"
#define  AUTH_PROXY_ACCESS_VMS_ID      "WASD_PROXY_ACCESS"

/* identifier names controlling SYSUAF authentication with /SYSUAF=WASD */
#define  AUTH_WASD__GROUP_VMS_ID  "WASD_VMS__"
#define  AUTH_WASD_HTTPS_VMS_ID   "WASD_VMS_HTTPS"
#define  AUTH_WASD_PWD_VMS_ID     "WASD_VMS_PWD"
#define  AUTH_WASD_WRITE_VMS_ID   "WASD_VMS_RW"
#define  AUTH_WASD_READ_VMS_ID    "WASD_VMS_R"

/* these values correspond with ACMEDEF.H ACME$K_NETWORK, etc., values */
#define  AUTH_LOGON_TYPE_NETWORK  1
#define  AUTH_LOGON_TYPE_BATCH    2
#define  AUTH_LOGON_TYPE_LOCAL    3
#define  AUTH_LOGON_TYPE_DIALUP   4
#define  AUTH_LOGON_TYPE_REMOTE   5

/* when checking for read/write access to the file-system */
#define  AUTH_ACCESS_READ           1
#define  AUTH_ACCESS_WRITE          2
/* unilaterally enable SYSPRV for access */
#define  AUTH_ACCESS_SYSPRV         9

/* has a path setting been made? */
#define  AUTH_ACCESS_IS_SET(rq) \
   ((rq)->rqPathSet.AccessProfile || (rq)->rqPathSet.AccessRead || \
    (rq)->rqPathSet.AccessServer || (rq)->rqPathSet.AccessWrite)

/* when formatting can string */
#define  AUTH_CAN_FORMAT_SHORT  0
#define  AUTH_CAN_FORMAT_LONG   1
#define  AUTH_CAN_FORMAT_HTML   2

#define AUTH_HTA_VERSION 0x01

#define AUTH_DIR_NOT_CONFIGURED "DIRECTORY:[NOT.CONFIGURED]!"

#define HTTPD_VERIFY "/httpd/-/verify/"

#define AUTH_ACCESS_SET(rq) \
   (rq->pathSet.AccessProfile || rq->pathSet.AccessRead || \
    rq->pathSet.AccessServer || rq->pathSet.AccessWrite)

/**************/
/* structures */
/**************/

/*
   Store these structures naturally-aligned on AXP.
   Uses a bit more storage but makes access as efficient as possible.
*/

#pragma member_alignment __save
#pragma member_alignment


typedef struct AuthHtaRecordStruct AUTH_HTAREC;

/* record structure of on-disk HTA database - retain ulong[2]s! */
struct AuthHtaRecordStruct
{
   char  UserName [AUTH_MAX_HTA_USERNAME_LENGTH+1];
   char  FullName [AUTH_MAX_FULLNAME_LENGTH+1];
   char  Email [AUTH_MAX_EMAIL_LENGTH+1];
   int  UserNameLength;
   unsigned long  Flags;
   unsigned long  HashedPwd [2];
   unsigned char  A1DigestLoCase [16];
   unsigned char  A1DigestUpCase [16];
   int  ChangeCount;
   unsigned long  LastChangeTime64 [2];
   int  AccessCount;
   unsigned long  LastAccessTime64 [2];
   int  FailureCount;
   unsigned long  LastFailureTime64 [2];
   unsigned long  AddedTime64 [2];
   char  Contact [AUTH_MAX_CONTACT_LENGTH+1];
   char  FillTo512Bytes [115];
   unsigned char  DatabaseVersion;
};

typedef struct AuthConfigStruct AUTH_CONFIG_META;

struct AuthConfigStruct
{
   BOOL  ProxyRuleReset;
};


#define AUTH_REALM_RECORD_TYPE 1

typedef struct AuthRealmRecordStruct AUTH_REALM;

/* in-memory realm authorization structure */
struct AuthRealmRecordStruct
{
   /* must be the first int in the structure */
   int  RecordType;

   BOOL  RealmProblem;

   int  GroupReadLength,   
        GroupWriteLength,   
        MetaConNumber,
        RealmLength,
        RealmDescriptionLength,
        RealmParamLength;

   unsigned long  AuthGroupCan,
                  AuthWorldCan,
                  GroupReadVmsIdentifier,
                  GroupWriteVmsIdentifier,
                  RealmVmsIdentifier,
                  SourceRealm,
                  SourceGroupRead,
                  SourceGroupWrite;

   char  *GroupReadPtr,
         *GroupWritePtr,
         *RealmPtr,
         *RealmParamPtr,
         *RealmAccessPtr,
         *RealmDescrPtr;
   /* string data is stored here and pointed to by above pointers */
};


#define AUTH_PATH_RECORD_TYPE 2

typedef struct AuthPathRecordStruct AUTH_PATH;

/* in-memory path authorization structure */
struct AuthPathRecordStruct
{
   /* must be the first int in the structure */
   int  RecordType;

   BOOL  FinalRule,
         NoCache,
         PathProblem,
         VmsUserProfile,
         VmsUserScriptAs;

   int  GroupRestrictListLength,
        MetaConNumber,
        PathLength,
        PathParameterLength,
        ProxyStringLength,
        SourceRealm,
        WorldRestrictListLength;

   unsigned long  AuthGroupCan,
                  AuthWorldCan;

   char  *GroupRestrictListPtr,
         *PathPtr,
         *PathParameterPtr,
         *ProxyStringPtr,
         *WorldRestrictListPtr;

   /* storage for pre-compiled regular expression */
   regex_t  RegexPregPath;
};

#define AUTH_DEFAULT_CACHE_RECORD_MAX 32
#define AUTH_DEFAULT_CACHE_RECORD_SIZE 768
#define AUTH_DEFAULT_CACHE_RECORD_PROFILE_SIZE 1024

typedef struct AuthCacheRecordStruct AUTH_CREC;

/* in-memory user authentication cache structure */
struct AuthCacheRecordStruct
{
   BOOL  CaseLess,
         DetailsUpdated,
         HttpsOnly,
         NoCache,
         ProxyStringMapped,
         SysUafAuthenticated,
         SysUafCanChangePwd,
         SysUafNilAccess,
         VmsUserScriptAs;

   int  AccessCount,
        AuthRemoteUserLength,
        AuthUserCan,
        BasicCount,
        ConfigDirectoryLength,
        ConfigDirectoryOffset,
        DataBaseCount,
        DigestCount,
        FailureCount,
        FindRecordCount,
        GroupReadLength,
        GroupReadOffset,
        GroupReadStatus,
        GroupWriteLength,
        GroupWriteOffset,
        GroupWriteStatus,
        LastAccessMinutesAgo,
        LastAccessSecondsAgo,
        LastAccessTickSecond,
        PathParameterLength,
        PathParameterOffset,
        ProxyUserNameLength,
        RealmLength,
        RealmParamLength,
        RemoteUserLength,
        StorageNextOffset,
        SysUafLogonType,
        UserDetailsLength,
        UserDetailsOffset,
        UserNameLength,
        VmsUserProfileLength,
        VmsUserProfileOffset;

   int64  LastAccessTime64;

   unsigned long  SourceRealm,
                  SourceGroupRead,
                  SourceGroupWrite,
                  UaiAccessP,
                  UaiAccessS,
                  UaiPrimeDays;

   char  *ConfigDirectory,
         *GroupWrite,
         *GroupRead,
         *PathParameter,
         *RealmParam,
         *UserDetails,
         *VmsUserProfilePtr;

   char  AuthRemoteUser [AUTH_MAX_USERNAME_LENGTH+1],
         DigestResponse [AUTH_MAX_DIGEST_RESPONSE+1],
         Password [AUTH_MAX_PASSWORD_LENGTH+1],
         ProxyUserName [AUTH_MAX_USERNAME_LENGTH+1],
         Realm [AUTH_MAX_REALM_GROUP_LENGTH+1],
         RemoteUser [AUTH_MAX_USERNAME_LENGTH+1],
         UserName [AUTH_MAX_USERNAME_LENGTH+1];

   /* variable length fields are stored from this point onwards */
   char  Storage [];
};


typedef struct AuthGblSecStruct AUTH_GBLSEC;

struct AuthGblSecStruct
{
   unsigned long  GblSecVersion,
                  GblSecLength;

   int  CacheHitCount,
        CacheMissCount,
        CacheRecordCount,
        CacheReuseCount,
        CacheTimeoutCount;

   int64  SinceTime64;

    /* authentication cache records are stored from this point onwards */
   char  CacheRecordPool [];
};

typedef struct AuthIdentStruct AUTH_IDENT;

struct AuthIdentStruct
{
   unsigned short  IdentChannel;

   char  ResponseString [128],
         RequestString [24];

   IO_SB  ConnectIOsb,
          ReadIOsb,
          WriteIOsb;

   REQUEST_STRUCT  *RequestPtr;
   REQUEST_AST  AuthAstFunction;
};

typedef struct AuthSysUafStruct AUTH_SYSUAF;

struct AuthSysUafStruct
{
   unsigned long  UaiFlags,
                  UaiPrimeDays,
                  UaiAccessP,
                  UaiAccessS,
                  UaiUic,
                  UserNameLength;

   unsigned long  UaiPriv [2];

   int64  UaiExpTime64,
          UaiPwdDateTime64,
          UaiPwd2DateTime64,
          UaiPwdLifeTime64;

   uint64  HashedPwd,
           UaiPwd,
           UaiPwd2;

   unsigned short  UaiSalt;

   unsigned char  UaiEncrypt;

   char  UaiOwner [1+31+1],
         UserName [15+1];

   /* this should be plenty of space */
   VMS_ITEM_LIST3  UaiItemList [32];
};

typedef struct AuthAcmeStruct AUTH_ACME;

struct AuthAcmeStruct
{
   int  AuthDoiNameLength,
        MappingAcmeNameLength,
        MappedVmsUserNameLength,
        TargetDoiNameLength;

   char  AuthDoiName [32+1],  /* ACME$K_MAXCHAR_DOI_NAME */
         MappingAcmeName [32+1],  /* ACME$K_MAXCHAR_DOI_NAME */
         MappedVmsUserName [AUTH_MAX_USERNAME_LENGTH+1],
         TargetDoiName [32+1];  /* ACME$K_MAXCHAR_DOI_NAME */

   /* the SYS$ACM() IO status block is a little different to the norm! */
   unsigned long  AcmIOsb [4];

   /*
      Want to keep ILE3 definitions out of here for backward compatbility.
      The equivalent to ILE3 and 16 items is ample for what we need.
   */
   VMS_ITEM_LIST3  AcmItemList [16];
};


typedef struct AuthTokenRecordStruct AUTH_TOKEN_RECORD;

struct AuthTokenRecordStruct
{
   char  AuthRealm [AUTH_MAX_REALM_GROUP_LENGTH+1],
         RemoteUser [AUTH_MAX_USERNAME_LENGTH+1],
         TokenValue [AUTH_SIZE_TOKEN_VALUE+1];
   int  AuthUserCan,
        SysUafAuthenticated,
        VmsUserProfile;
   unsigned int  ExpireSecond,
                 RemoteUserLength;
   IPADDRESS  ClientIpAddr;
};


typedef struct AuthTokenGblSecStruct AUTH_TOKEN_GBLSEC;

struct AuthTokenGblSecStruct
{
   unsigned long  GblSecVersion,
                  GblSecLength;

   int  RecordCount;
   int64  SinceTime64;

    /* token records are stored from this point onwards */
   char  RecordPool [];
};


#pragma member_alignment __restore

/***********************/
/* function prototypes */
/***********************/

/*** AUTH.C prototypes ***/

void Authorize (REQUEST_STRUCT*, char*, int, char*, int, REQUEST_AST);
void AuthorizeRealm (REQUEST_STRUCT*);
void AuthorizeRealmCheck (REQUEST_STRUCT*);
int AuthorizeWasdId (REQUEST_STRUCT*);
void AuthorizeGroupWrite (REQUEST_STRUCT*);
void AuthorizeGroupWriteCheck (REQUEST_STRUCT*);
void AuthorizeGroupRead (REQUEST_STRUCT*);
void AuthorizeGroupReadCheck (REQUEST_STRUCT*);
int AuthorizeGuaranteeAccess (REQUEST_STRUCT*, char*);
void AuthorizeFinal (REQUEST_STRUCT*);
void AuthorizeResponse (REQUEST_STRUCT*);
void AuthorizeNoCache (REQUEST_STRUCT*);

char* AuthCanString (unsigned long, int);
int AuthClientHostGroup (REQUEST_STRUCT*, char*);
int AuthDoAuthorization (REQUEST_STRUCT*);
int AuthParseAuthorization (REQUEST_STRUCT*);
char* AuthSourceString (char*, unsigned long);
char* AuthSysUafLogonType (int);
int AuthVerifyPassword (REQUEST_STRUCT*);
void AuthWatchCheck (REQUEST_STRUCT*, char*, char*, int);

/*** AUTHACME.C prototypes ***/

AuthAcmeVerifyUser (REQUEST_STRUCT*);
AuthAcmeVerifyUserAst (REQUEST_STRUCT*);
AuthAcmeChangePassword (REQUEST_STRUCT*, char*, char*);
AuthAcmeChangePasswordAst (REQUEST_STRUCT*);

/*** AUTHAGENT.C prototypes ***/

void AuthAgentBegin (REQUEST_STRUCT*, char*, REQUEST_AST);
void AuthAgentCallout (REQUEST_STRUCT*);
void AuthAgentCalloutResponseError (REQUEST_STRUCT*);

/*** AUTHHTA.C prototypes ***/

int AuthReadHtDatabase (REQUEST_STRUCT*, char*, BOOL);
int AuthHtDatabaseAccess (REQUEST_STRUCT*, BOOL, char*, char*, 
                          AUTH_HTAREC*, AUTH_HTAREC*, AUTH_HTAREC*);

/*** AUTHHTL.C prototypes ***/

int AuthReadSimpleList (REQUEST_STRUCT*, char*, BOOL);

/*** AUTHCACHE.C prototypes ***/

int AuthUserResetRecord (char*, char*, char*);
int AuthCacheAddRecord (AUTH_CREC*, AUTH_CREC**);
int AuthCacheEntry (AUTH_CREC*, AUTH_CREC*);
int AuthCacheFindRecord (AUTH_CREC*, AUTH_CREC**);
int AuthCacheGblSecInit ();
int AuthCacheInit ();
BOOL AuthCacheNeedsReval (REQUEST_STRUCT*, AUTH_CREC*);
int AuthCachePurge (BOOL);
int AuthCacheReport (REQUEST_STRUCT*);
void AuthCacheRequestRecord (REQUEST_STRUCT*, AUTH_CREC**);
int AuthCacheReset (REQUEST_STRUCT*, char*, char*);

/*** AUTHACCESS.C prototypes ***/

int AuthAccessCheck (REQUEST_STRUCT*, char*, int, int);

#define AuthAccessReadCheck(rq,fn,fl) \
        AuthAccessCheck (rq, fn, fl, AUTH_ACCESS_READ)

#define AuthAccessWriteCheck(rq,fn,fl) \
        AuthAccessCheck (rq, fn, fl, AUTH_ACCESS_WRITE)

int AuthAccessEnable (REQUEST_STRUCT*, char*, int);

/*** AUTHCONFIG.C prototypes ***/

int AuthConfigInit();
int AuthConfigIdentifier (char*, unsigned long*);
AuthConfigAddPath (META_CONFIG*,
                   BOOL, char*, BOOL, BOOL,
                   char*, char*, char*, char*,
                   unsigned long, unsigned long, unsigned long,
                   BOOL, BOOL, BOOL);
AuthConfigAddRealm (META_CONFIG*,
                    BOOL, char*, char*, char*, unsigned long, unsigned long,
                    char*, unsigned long, unsigned long,
                    char*, unsigned long, unsigned long,
                    unsigned long, unsigned long);
int AuthConfigAddLine (META_CONFIG, char*);
int AuthConfigLoad (META_CONFIG**);
BOOL AuthConfigLoadCallBack (META_CONFIG*);
int AuthConfigOther();
char* AuthConfigParseProtectRule (REQUEST_STRUCT*, char*, int);
char* AuthConfigProxy (META_CONFIG*, char*);
int AuthConfigProxyMap (REQUEST_STRUCT*, AUTH_CREC*);
int AuthConfigRead (AUTH_CONFIG_META*);
int AuthConfigReadStatus (AUTH_CONFIG_META*, char*, ...);
int AuthConfigReport (REQUEST_STRUCT*, BOOL, char*);
int AuthConfigReportNow (REQUEST_STRUCT*, META_CONFIG*, BOOL, char*);
int AuthConfigReportRule (REQUEST_STRUCT*, METACON_LINE*, BOOL, char*, int);
int AuthConfigSearch (REQUEST_STRUCT*, char*);
int AuthConfigUnLoad (META_CONFIG*);
AuthConfigUnloadLineData (void*);

/*** AUTHIDENT.C prototypes ***/

void AuthIdentBegin (REQUEST_STRUCT*, REQUEST_AST);
int AuthIdentCloseSocket (AUTH_IDENT*);
int AuthIdentEnd (AUTH_IDENT*);
int AuthIdentConnectAst (AUTH_IDENT*);
int AuthIdentReadAst (AUTH_IDENT*);
int AuthIdentReadTimeoutAst (AUTH_IDENT*);
int AuthIdentWriteAst (AUTH_IDENT*);

/*** AUTHTOKEN.C prototypes ***/

int AuthTokenInit ();
char* AuthTokenFromCookie (REQUEST_STRUCT*, char*);
AUTH_TOKEN_RECORD* AuthTokenFind (char*);
int AuthTokenGblSecInit ();
void AuthTokenProcess (REQUEST_STRUCT*);
void AuthTokenGenerate (REQUEST_STRUCT*);

/*** AUTHVMS.C prototypes ***/

int AuthVmsGetUai (REQUEST_STRUCT*, char*);
AuthVmsChangePassword (REQUEST_STRUCT*, char*);
int AuthVmsCheckIdentifier (REQUEST_STRUCT*);
int AuthVmsCreateHttpdProfile ();
int AuthVmsCreateUserProfile (REQUEST_STRUCT*);
int AuthVmsHoldsIdentifier (REQUEST_STRUCT*, char*, unsigned long);
int AuthVmsHoldsWasdGroupIdent (REQUEST_STRUCT*, char*);
int AuthVmsLoadIdentifiers (REQUEST_STRUCT*, unsigned long);
int AuthVmsVerifyUser (REQUEST_STRUCT*);
int AuthVmsVerifyPassword (REQUEST_STRUCT*);

#endif /* AUTH_H_LOADED */

/*****************************************************************************/