hba.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /*-------------------------------------------------------------------------
  2. *
  3. * hba.h
  4. * Interface to hba.c
  5. *
  6. *
  7. * src/include/libpq/hba.h
  8. *
  9. *-------------------------------------------------------------------------
  10. */
  11. #ifndef HBA_H
  12. #define HBA_H
  13. #include "libpq/pqcomm.h" /* pgrminclude ignore */ /* needed for NetBSD */
  14. #include "nodes/pg_list.h"
  15. #include "regex/regex.h"
  16. /*
  17. * The following enum represents the authentication methods that
  18. * are supported by PostgreSQL.
  19. *
  20. * Note: keep this in sync with the UserAuthName array in hba.c.
  21. */
  22. typedef enum UserAuth
  23. {
  24. uaReject,
  25. uaImplicitReject, /* Not a user-visible option */
  26. uaTrust,
  27. uaIdent,
  28. uaPassword,
  29. uaMD5,
  30. uaSCRAM,
  31. uaGSS,
  32. uaSSPI,
  33. uaPAM,
  34. uaBSD,
  35. uaLDAP,
  36. uaCert,
  37. uaRADIUS,
  38. uaPeer
  39. #define USER_AUTH_LAST uaPeer /* Must be last value of this enum */
  40. } UserAuth;
  41. /*
  42. * Data structures representing pg_hba.conf entries
  43. */
  44. typedef enum IPCompareMethod
  45. {
  46. ipCmpMask,
  47. ipCmpSameHost,
  48. ipCmpSameNet,
  49. ipCmpAll
  50. } IPCompareMethod;
  51. typedef enum ConnType
  52. {
  53. ctLocal,
  54. ctHost,
  55. ctHostSSL,
  56. ctHostNoSSL,
  57. ctHostGSS,
  58. ctHostNoGSS,
  59. } ConnType;
  60. typedef enum ClientCertMode
  61. {
  62. clientCertOff,
  63. clientCertCA,
  64. clientCertFull
  65. } ClientCertMode;
  66. typedef enum ClientCertName
  67. {
  68. clientCertCN,
  69. clientCertDN
  70. } ClientCertName;
  71. typedef struct HbaLine
  72. {
  73. int linenumber;
  74. char *rawline;
  75. ConnType conntype;
  76. List *databases;
  77. List *roles;
  78. struct sockaddr_storage addr;
  79. int addrlen; /* zero if we don't have a valid addr */
  80. struct sockaddr_storage mask;
  81. int masklen; /* zero if we don't have a valid mask */
  82. IPCompareMethod ip_cmp_method;
  83. char *hostname;
  84. UserAuth auth_method;
  85. char *usermap;
  86. char *pamservice;
  87. bool pam_use_hostname;
  88. bool ldaptls;
  89. char *ldapscheme;
  90. char *ldapserver;
  91. int ldapport;
  92. char *ldapbinddn;
  93. char *ldapbindpasswd;
  94. char *ldapsearchattribute;
  95. char *ldapsearchfilter;
  96. char *ldapbasedn;
  97. int ldapscope;
  98. char *ldapprefix;
  99. char *ldapsuffix;
  100. ClientCertMode clientcert;
  101. ClientCertName clientcertname;
  102. char *krb_realm;
  103. bool include_realm;
  104. bool compat_realm;
  105. bool upn_username;
  106. List *radiusservers;
  107. char *radiusservers_s;
  108. List *radiussecrets;
  109. char *radiussecrets_s;
  110. List *radiusidentifiers;
  111. char *radiusidentifiers_s;
  112. List *radiusports;
  113. char *radiusports_s;
  114. } HbaLine;
  115. typedef struct IdentLine
  116. {
  117. int linenumber;
  118. char *usermap;
  119. char *ident_user;
  120. char *pg_role;
  121. regex_t re;
  122. } IdentLine;
  123. /*
  124. * A single string token lexed from an authentication configuration file
  125. * (pg_ident.conf or pg_hba.conf), together with whether the token has
  126. * been quoted.
  127. */
  128. typedef struct AuthToken
  129. {
  130. char *string;
  131. bool quoted;
  132. } AuthToken;
  133. /*
  134. * TokenizedAuthLine represents one line lexed from an authentication
  135. * configuration file. Each item in the "fields" list is a sub-list of
  136. * AuthTokens. We don't emit a TokenizedAuthLine for empty or all-comment
  137. * lines, so "fields" is never NIL (nor are any of its sub-lists).
  138. *
  139. * Exception: if an error occurs during tokenization, we might have
  140. * fields == NIL, in which case err_msg != NULL.
  141. */
  142. typedef struct TokenizedAuthLine
  143. {
  144. List *fields; /* List of lists of AuthTokens */
  145. int line_num; /* Line number */
  146. char *raw_line; /* Raw line text */
  147. char *err_msg; /* Error message if any */
  148. } TokenizedAuthLine;
  149. /* kluge to avoid including libpq/libpq-be.h here */
  150. typedef struct Port hbaPort;
  151. extern bool load_hba(void);
  152. extern bool load_ident(void);
  153. extern const char *hba_authname(UserAuth auth_method);
  154. extern void hba_getauthmethod(hbaPort *port);
  155. extern int check_usermap(const char *usermap_name,
  156. const char *pg_role, const char *auth_user,
  157. bool case_insensitive);
  158. extern HbaLine *parse_hba_line(TokenizedAuthLine *tok_line, int elevel);
  159. extern IdentLine *parse_ident_line(TokenizedAuthLine *tok_line, int elevel);
  160. extern bool pg_isblank(const char c);
  161. extern MemoryContext tokenize_auth_file(const char *filename, FILE *file,
  162. List **tok_lines, int elevel);
  163. #endif /* HBA_H */