HTAAUtil.h
上传用户:zlh9724
上传日期:2007-01-04
资源大小:1991k
文件大小:9k
源码类别:

浏览器

开发平台:

Unix_Linux

  1. /*                                                            Utilities for the Authorization
  2.              COMMON PARTS OF AUTHORIZATION MODULE TO BOTH SERVER AND BROWSER
  3.                                              
  4.  */
  5. /*
  6. **      (c) COPYRIGHT MIT 1995.
  7. **      Please first read the full copyright statement in the file COPYRIGH.
  8. */
  9. /*
  10.    This module is the interface to the common parts of Access Authorization (AA) package
  11.    for both server and browser. Important to know about memory allocation:
  12.    
  13.    Routines in this module use dynamic allocation, but free automatically all the memory
  14.    reserved by them. Therefore the caller never has to (and never should) free() any
  15.    object returned by these functions.
  16.    
  17.    Therefore also all the strings returned by this package are only valid until the next
  18.    call to the same function is made. This approach is selected, because of the nature of
  19.    access authorization: no string returned by the package needs to be valid longer than
  20.    until the next call.  This also makes it easy to plug the AA package in: you don't have
  21.    to ponder whether to free() something here or is it done somewhere else (because it is
  22.    always done somewhere else).
  23.    
  24.    The strings that the package needs to store are copied so the original strings given as
  25.    parameters to AA functions may be freed or modified with no side effects.
  26.    
  27.    Also note: The AA package does not free() anything else than what it has itself
  28.    allocated.
  29.    
  30.    This module is implemented by HTAAUtil.c, and it is a part of the W3C Reference
  31.    Library.
  32.    
  33.  */
  34. #ifndef HTAAUTIL_H
  35. #define HTAAUTIL_H
  36. #include "HTList.h"
  37. #include "HTReq.h"
  38. /*
  39. Default filenames
  40.  */
  41. #ifndef PASSWD_FILE
  42. #define PASSWD_FILE     "/home2/luotonen/passwd"
  43. #endif
  44. #ifndef GROUP_FILE
  45. #define GROUP_FILE      "/home2/luotonen/group"
  46. #endif
  47. #define ACL_FILE_NAME   ".www_acl"
  48. /*
  49. ** Numeric constants
  50. */
  51. #define MAX_USERNAME_LEN        16      /* @@ Longest allowed username    */
  52. #define MAX_PASSWORD_LEN        4*13    /* @@ Longest allowed password    */
  53.                                         /* (encrypted, so really only 4*8)*/
  54. #define MAX_METHODNAME_LEN      12      /* @@ Longest allowed method name */
  55. #define MAX_FIELDNAME_LEN       16      /* @@ Longest field name in       */
  56.                                         /* protection setup file          */
  57. #define MAX_PATHNAME_LEN        80      /* @@ Longest passwd/group file   */
  58.                                         /* patname to allow               */
  59. /*
  60.    We need to define the following structures as they are used in the HTRequest structure.
  61.    The AA module is declared in HTAAUtil and HTAABrow. The enumeration HTAAScheme
  62.    represents the possible authentication schemes used by the WWW Access Authorization.
  63.    
  64.  */
  65. typedef enum {
  66.     HTAA_UNKNOWN,
  67.     HTAA_NONE,
  68.     HTAA_BASIC,
  69.     HTAA_PUBKEY,
  70.     HTAA_KERBEROS_V4,
  71.     HTAA_KERBEROS_V5,
  72.     HTAA_MAX_SCHEMES                            /* THIS MUST ALWAYS BE LAST! */
  73. } HTAAScheme;
  74. /*
  75. ** Access Authorization failure reasons
  76. */
  77. typedef enum {
  78.     HTAA_OK,            /* 200 OK                               */
  79.     HTAA_OK_GATEWAY,    /* 200 OK, acting as a gateway          */
  80.     HTAA_OK_REDIRECT,   /* 302 OK, redirected                   */
  81.     HTAA_NO_AUTH,       /* 401 Unauthorized, not authenticated  */
  82.     HTAA_NOT_MEMBER,    /* 401 Unauthorized, not authorized     */
  83.     HTAA_IP_MASK,       /* 403 Forbidden by IP mask             */
  84.     HTAA_IP_MASK_PROXY, /* 403 Forbidden by IP mask on proxy    */
  85.     HTAA_BY_RULE,       /* 403 Forbidden by rule                */
  86.     HTAA_NO_ACL,        /* 403 Forbidden, ACL non-existent      */
  87.     HTAA_NO_ENTRY,      /* 403 Forbidden, no ACL entry          */
  88.     HTAA_SETUP_ERROR,   /* 403 Forbidden, server setup error    */
  89.     HTAA_DOTDOT,        /* 403 Forbidden, URL with /../ illegal */
  90.     HTAA_HTBIN,         /* 403 Forbidden, /htbin not enabled    */
  91.     HTAA_INVALID_REDIRECT,
  92.                         /* 403 Forbidden, bad redirection setup */
  93.     HTAA_INVALID_USER,  /* 403 Forbidden, bad user directory    */
  94.     HTAA_NOT_ALLOWED,   /* 403 Forbidden, dangerous method must */
  95.                         /*                be explicitly allowed */
  96.     HTAA_NOT_FOUND,     /* 404 Not found, or read protected     */
  97.     HTAA_MULTI_FAILED   /* 404 No suitable presentation found   */
  98. } HTAAFailReason;
  99. /*
  100. Authentication Schemes
  101.  */
  102. /* PUBLIC                                               HTAAScheme_enum()
  103. **              TRANSLATE SCHEME NAME TO A SCHEME ENUMERATION
  104. ** ON ENTRY:
  105. **      name            is a string representing the scheme name.
  106. **
  107. ** ON EXIT:
  108. **      returns         the enumerated constant for that scheme.
  109. */
  110. extern HTAAScheme HTAAScheme_enum (CONST char* name);
  111. /* PUBLIC                                               HTAAScheme_name()
  112. **                      GET THE NAME OF A GIVEN SCHEME
  113. ** ON ENTRY:
  114. **      scheme          is one of the scheme enum values:
  115. **                      HTAA_NONE, HTAA_BASIC, HTAA_PUBKEY, ...
  116. **
  117. ** ON EXIT:
  118. **      returns         the name of the scheme, i.e.
  119. **                      "none", "basic", "pubkey", ...
  120. */
  121. extern char *HTAAScheme_name (HTAAScheme scheme);
  122. /* extern                                               HTAA_templateMatch()
  123. **              STRING COMPARISON FUNCTION FOR FILE NAMES
  124. **                 WITH ONE WILDCARD * IN THE TEMPLATE
  125. ** NOTE:
  126. **      This is essentially the same code as in HTRules.c, but it
  127. **      cannot be used because it is embedded in between other code.
  128. **      (In fact, HTRules.c should use this routine, but then this
  129. **       routine would have to be more sophisticated... why is life
  130. **       sometimes so hard...)
  131. **
  132. ** ON ENTRY:
  133. **      tmplate         is a template string to match the file name
  134. **                      agaist, may contain a single wildcard
  135. **                      character * which matches zero or more
  136. **                      arbitrary characters.
  137. **      filename        is the filename (or pathname) to be matched
  138. **                      agaist the template.
  139. **
  140. ** ON EXIT:
  141. **      returns         YES, if filename matches the template.
  142. **                      NO, otherwise.
  143. */
  144. extern BOOL HTAA_templateMatch (CONST char * tmplate, CONST char * filename);
  145. /* PUBLIC                                           HTAA_templateCaseMatch()
  146. **              STRING COMPARISON FUNCTION FOR FILE NAMES
  147. **                 WITH ONE WILDCARD * IN THE TEMPLATE (Case Insensitive)
  148. ** NOTE:
  149. **      This is essentially the same code as in HTAA_templateMatch, but
  150. **      it compares case insensitive (for VMS). Reason for this routine
  151. **      is that HTAA_templateMatch gets called from several places, also
  152. **      there where a case sensitive match is needed, so one cannot just
  153. **      change the HTAA_templateMatch routine for VMS.
  154. **
  155. ** ON ENTRY:
  156. **      template        is a template string to match the file name
  157. **                      agaist, may contain a single wildcard
  158. **                      character * which matches zero or more
  159. **                      arbitrary characters.
  160. **      filename        is the filename (or pathname) to be matched
  161. **                      agaist the template.
  162. **
  163. ** ON EXIT:
  164. **      returns         YES, if filename matches the template.
  165. **                      NO, otherwise.
  166. */
  167. extern BOOL HTAA_templateCaseMatch (CONST char * tmpl, CONST char * filename);
  168. /* PUBLIC                                       HTAA_makeProtectionTemplate()
  169. **              CREATE A PROTECTION TEMPLATE FOR THE FILES
  170. **              IN THE SAME DIRECTORY AS THE GIVEN FILE
  171. **              (Used by server if there is no fancier way for
  172. **              it to tell the client, and by browser if server
  173. **              didn't send WWW-ProtectionTemplate: field)
  174. ** ON ENTRY:
  175. **      docname is the document pathname (from URL).
  176. **
  177. ** ON EXIT:
  178. **      returns a template matching docname, and other files
  179. **              files in that directory.
  180. **
  181. **              E.g.  /foo/bar/x.html  =>  /foo/bar/ *
  182. **                                                  ^
  183. **                              Space only to prevent it from
  184. **                              being a comment marker here,
  185. **                              there really isn't any space.
  186. */
  187. extern char *HTAA_makeProtectionTemplate (CONST char * docname);
  188. /*
  189. MIME Argument List Parser
  190.  */
  191. /* PUBLIC                                               HTAA_parseArgList()
  192. **              PARSE AN ARGUMENT LIST GIVEN IN A HEADER FIELD
  193. ** ON ENTRY:
  194. **      str     is a comma-separated list:
  195. **
  196. **                      item, item, item
  197. **              where
  198. **                      item ::= value
  199. **                             | name=value
  200. **                             | name="value"
  201. **
  202. **              Leading and trailing whitespace is ignored
  203. **              everywhere except inside quotes, so the following
  204. **              examples are equal:
  205. **
  206. **                      name=value,foo=bar
  207. **                       name="value",foo="bar"
  208. **                        name = value ,  foo = bar
  209. **                         name = "value" ,  foo = "bar"
  210. **
  211. ** ON EXIT:
  212. **      returns a list of name-value pairs (actually HTAssocList*).
  213. **              For items with no name, just value, the name is
  214. **              the number of order number of that item. E.g.
  215. **              "1" for the first, etc.
  216. */
  217. extern HTList *HTAA_parseArgList (char * str);
  218. /*
  219.  */
  220. #endif  /* NOT HTAAUTIL_H */
  221. /*
  222.    End of file HTAAUtil.h. */