PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
hba.h
Go to the documentation of this file.
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
14#include "libpq/pqcomm.h" /* needed for NetBSD */
15#include "nodes/pg_list.h"
16#include "regex/regex.h"
17
18
19/*
20 * The following enum represents the authentication methods that
21 * are supported by PostgreSQL.
22 *
23 * Note: keep this in sync with the UserAuthName array in hba.c.
24 */
25typedef enum UserAuth
26{
28 uaImplicitReject, /* Not a user-visible option */
43#define USER_AUTH_LAST uaOAuth /* Must be last value of this enum */
45
46/*
47 * Data structures representing pg_hba.conf entries
48 */
49
50typedef enum IPCompareMethod
51{
57
58typedef enum ConnType
59{
67
68typedef enum ClientCertMode
69{
74
75typedef enum ClientCertName
76{
80
81/*
82 * A single string token lexed from an authentication configuration file
83 * (pg_ident.conf or pg_hba.conf), together with whether the token has
84 * been quoted. If "string" begins with a slash, it may optionally
85 * contain a regular expression (currently used for pg_ident.conf when
86 * building IdentLines and for pg_hba.conf when building HbaLines).
87 */
88typedef struct AuthToken
89{
90 char *string;
91 bool quoted;
94
95typedef struct HbaLine
96{
99 char *rawline;
103 struct sockaddr_storage addr;
104 int addrlen; /* zero if we don't have a valid addr */
105 struct sockaddr_storage mask;
106 int masklen; /* zero if we don't have a valid mask */
108 char *hostname;
110 char *usermap;
144
145typedef struct IdentLine
146{
148
149 char *usermap;
153
154/*
155 * TokenizedAuthLine represents one line lexed from an authentication
156 * configuration file. Each item in the "fields" list is a sub-list of
157 * AuthTokens. We don't emit a TokenizedAuthLine for empty or all-comment
158 * lines, so "fields" is never NIL (nor are any of its sub-lists).
159 *
160 * Exception: if an error occurs during tokenization, we might have
161 * fields == NIL, in which case err_msg != NULL.
162 */
163typedef struct TokenizedAuthLine
164{
165 List *fields; /* List of lists of AuthTokens */
166 char *file_name; /* File name of origin */
167 int line_num; /* Line number */
168 char *raw_line; /* Raw line text */
169 char *err_msg; /* Error message if any */
171
172/* kluge to avoid including libpq/libpq-be.h here */
173typedef struct Port hbaPort;
174
175extern bool load_hba(void);
176extern bool load_ident(void);
177extern const char *hba_authname(UserAuth auth_method);
178extern void hba_getauthmethod(hbaPort *port);
179extern int check_usermap(const char *usermap_name,
180 const char *pg_user, const char *system_user,
181 bool case_insensitive);
182extern HbaLine *parse_hba_line(TokenizedAuthLine *tok_line, int elevel);
183extern IdentLine *parse_ident_line(TokenizedAuthLine *tok_line, int elevel);
184extern bool pg_isblank(const char c);
185extern FILE *open_auth_file(const char *filename, int elevel, int depth,
186 char **err_msg);
187extern void free_auth_file(FILE *file, int depth);
188extern void tokenize_auth_file(const char *filename, FILE *file,
189 List **tok_lines, int elevel, int depth);
190
191#endif /* HBA_H */
bool pg_isblank(const char c)
Definition: hba.c:146
IPCompareMethod
Definition: hba.h:51
@ ipCmpAll
Definition: hba.h:55
@ ipCmpSameNet
Definition: hba.h:54
@ ipCmpMask
Definition: hba.h:52
@ ipCmpSameHost
Definition: hba.h:53
HbaLine * parse_hba_line(TokenizedAuthLine *tok_line, int elevel)
Definition: hba.c:1328
ConnType
Definition: hba.h:59
@ ctHostNoGSS
Definition: hba.h:65
@ ctHostSSL
Definition: hba.h:62
@ ctHostNoSSL
Definition: hba.h:63
@ ctHost
Definition: hba.h:61
@ ctHostGSS
Definition: hba.h:64
@ ctLocal
Definition: hba.h:60
struct IdentLine IdentLine
bool load_ident(void)
Definition: hba.c:3021
struct HbaLine HbaLine
UserAuth
Definition: hba.h:26
@ uaBSD
Definition: hba.h:37
@ uaLDAP
Definition: hba.h:38
@ uaPeer
Definition: hba.h:41
@ uaPAM
Definition: hba.h:36
@ uaPassword
Definition: hba.h:31
@ uaCert
Definition: hba.h:39
@ uaMD5
Definition: hba.h:32
@ uaReject
Definition: hba.h:27
@ uaGSS
Definition: hba.h:34
@ uaSCRAM
Definition: hba.h:33
@ uaImplicitReject
Definition: hba.h:28
@ uaRADIUS
Definition: hba.h:40
@ uaIdent
Definition: hba.h:30
@ uaOAuth
Definition: hba.h:42
@ uaTrust
Definition: hba.h:29
@ uaSSPI
Definition: hba.h:35
void hba_getauthmethod(hbaPort *port)
Definition: hba.c:3110
bool load_hba(void)
Definition: hba.c:2645
IdentLine * parse_ident_line(TokenizedAuthLine *tok_line, int elevel)
Definition: hba.c:2751
int check_usermap(const char *usermap_name, const char *pg_user, const char *system_user, bool case_insensitive)
Definition: hba.c:2966
void free_auth_file(FILE *file, int depth)
Definition: hba.c:572
struct TokenizedAuthLine TokenizedAuthLine
struct AuthToken AuthToken
ClientCertName
Definition: hba.h:76
@ clientCertDN
Definition: hba.h:78
@ clientCertCN
Definition: hba.h:77
ClientCertMode
Definition: hba.h:69
@ clientCertOff
Definition: hba.h:70
@ clientCertFull
Definition: hba.h:72
@ clientCertCA
Definition: hba.h:71
void tokenize_auth_file(const char *filename, FILE *file, List **tok_lines, int elevel, int depth)
Definition: hba.c:691
const char * hba_authname(UserAuth auth_method)
Definition: hba.c:3123
FILE * open_auth_file(const char *filename, int elevel, int depth, char **err_msg)
Definition: hba.c:597
Datum system_user(PG_FUNCTION_ARGS)
Definition: miscinit.c:949
static char * filename
Definition: pg_dumpall.c:123
static int port
Definition: pg_regress.c:115
char * c
#define regex_t
Definition: regex.h:245
Definition: hba.h:89
regex_t * regex
Definition: hba.h:92
char * string
Definition: hba.h:90
bool quoted
Definition: hba.h:91
Definition: hba.h:96
UserAuth auth_method
Definition: hba.h:109
bool upn_username
Definition: hba.h:130
struct sockaddr_storage mask
Definition: hba.h:105
char * sourcefile
Definition: hba.h:97
ClientCertName clientcertname
Definition: hba.h:126
int addrlen
Definition: hba.h:104
List * radiusservers
Definition: hba.h:131
bool oauth_skip_usermap
Definition: hba.h:142
char * ldapserver
Definition: hba.h:115
bool include_realm
Definition: hba.h:128
int masklen
Definition: hba.h:106
ClientCertMode clientcert
Definition: hba.h:125
char * ldapsearchfilter
Definition: hba.h:120
char * ldapscheme
Definition: hba.h:114
char * rawline
Definition: hba.h:99
char * oauth_issuer
Definition: hba.h:139
char * ldapprefix
Definition: hba.h:123
List * radiussecrets
Definition: hba.h:133
char * ldapsearchattribute
Definition: hba.h:119
char * krb_realm
Definition: hba.h:127
char * ldapbasedn
Definition: hba.h:121
bool pam_use_hostname
Definition: hba.h:112
int linenumber
Definition: hba.h:98
char * radiussecrets_s
Definition: hba.h:134
char * oauth_scope
Definition: hba.h:140
List * radiusports
Definition: hba.h:137
List * radiusidentifiers
Definition: hba.h:135
char * oauth_validator
Definition: hba.h:141
char * hostname
Definition: hba.h:108
char * pamservice
Definition: hba.h:111
List * databases
Definition: hba.h:101
ConnType conntype
Definition: hba.h:100
char * usermap
Definition: hba.h:110
char * ldapsuffix
Definition: hba.h:124
int ldapport
Definition: hba.h:116
struct sockaddr_storage addr
Definition: hba.h:103
char * ldapbindpasswd
Definition: hba.h:118
List * roles
Definition: hba.h:102
char * radiusports_s
Definition: hba.h:138
char * ldapbinddn
Definition: hba.h:117
bool compat_realm
Definition: hba.h:129
int ldapscope
Definition: hba.h:122
IPCompareMethod ip_cmp_method
Definition: hba.h:107
bool ldaptls
Definition: hba.h:113
char * radiusservers_s
Definition: hba.h:132
char * radiusidentifiers_s
Definition: hba.h:136
Definition: hba.h:146
AuthToken * pg_user
Definition: hba.h:151
AuthToken * system_user
Definition: hba.h:150
char * usermap
Definition: hba.h:149
int linenumber
Definition: hba.h:147
Definition: pg_list.h:54
Definition: libpq-be.h:129
char * raw_line
Definition: hba.h:168
int line_num
Definition: hba.h:167
char * file_name
Definition: hba.h:166
char * err_msg
Definition: hba.h:169
List * fields
Definition: hba.h:165