73 #define token_has_regexp(t) (t->regex != NULL)
74 #define token_is_member_check(t) (!t->quoted && t->string[0] == '+')
75 #define token_is_keyword(t, k) (!t->quoted && strcmp(t->string, k) == 0)
76 #define token_matches(t, k) (strcmp(t->string, k) == 0)
77 #define token_matches_insensitive(t,k) (pg_strcasecmp(t->string, k) == 0)
129 "UserAuthName[] must match the UserAuth enum");
133 const char *inc_filename,
int elevel,
134 int depth,
char **err_msg);
136 int elevel,
char **err_msg);
138 char **err_msg,
int elevel);
151 return c ==
' ' ||
c ==
'\t' ||
c ==
'\r';
191 bool *initial_quote,
bool *terminating_comma)
194 bool in_quote =
false;
195 bool was_quote =
false;
196 bool saw_quote =
false;
200 *initial_quote =
false;
201 *terminating_comma =
false;
215 if (
c ==
'#' && !in_quote)
217 while ((
c = (*(*
lineptr)++)) !=
'\0')
223 if (
c ==
',' && !in_quote)
225 *terminating_comma =
true;
229 if (
c !=
'"' || was_quote)
233 if (in_quote &&
c ==
'"')
234 was_quote = !was_quote;
240 in_quote = !in_quote;
243 *initial_quote =
true;
255 return (saw_quote ||
buf->len > 0);
267 toklen = strlen(
token);
271 authtoken->
quoted = quoted;
272 authtoken->
regex = NULL;
307 char **err_msg,
int elevel)
315 if (
token->string[0] !=
'/')
321 wstr, strlen(
token->string + 1));
331 (
errcode(ERRCODE_INVALID_REGULAR_EXPRESSION),
332 errmsg(
"invalid regular expression \"%s\": %s",
333 token->string + 1, errstr),
334 errcontext(
"line %d of configuration file \"%s\"",
337 *err_msg =
psprintf(
"invalid regular expression \"%s\": %s",
338 token->string + 1, errstr);
363 r =
pg_regexec(
token->regex, wmatchstr, wmatchlen, 0, NULL, nmatch, pmatch, 0);
385 int elevel,
int depth,
char **err_msg)
397 &initial_quote, &trailing_comma))
401 if (!initial_quote &&
buf.len > 1 &&
buf.data[0] ==
'@')
403 elevel, depth + 1, err_msg);
416 }
while (trailing_comma && (*err_msg == NULL));
444 const char *inc_filename,
459 if (errno == ENOENT && missing_ok)
462 (
errmsg(
"skipping missing authentication file \"%s\"",
499 const char *outer_filename,
500 const char *inc_filename,
513 if (inc_file == NULL)
533 foreach(inc_line, inc_lines)
545 foreach(inc_field, tok_line->
fields)
550 foreach(inc_token, inc_tokens)
614 errmsg(
"could not open file \"%s\": maximum nesting depth exceeded",
617 *err_msg =
psprintf(
"could not open file \"%s\": maximum nesting depth exceeded",
625 int save_errno = errno;
629 errmsg(
"could not open file \"%s\": %m",
632 *err_msg =
psprintf(
"could not open file \"%s\": %s",
666 errcontext(
"line %d of configuration file \"%s\"",
692 int elevel,
int depth)
704 callback_arg.
linenum = line_number;
707 tokenerrcontext.
arg = (
void *) &callback_arg;
716 "tokenize_auth_file",
725 while (!feof(file) && !ferror(file))
731 char *err_msg = NULL;
732 int last_backslash_buflen = 0;
733 int continuations = 0;
748 if (
buf.len > last_backslash_buflen &&
749 buf.data[
buf.len - 1] ==
'\\')
752 buf.data[--
buf.len] =
'\0';
753 last_backslash_buflen =
buf.len;
765 int save_errno = errno;
770 err_msg =
psprintf(
"could not read file \"%s\": %s",
777 while (*
lineptr && err_msg == NULL)
782 elevel, depth, &err_msg);
784 if (current_field !=
NIL)
791 current_line =
lappend(current_line, current_field);
800 if (current_line ==
NIL && err_msg == NULL)
804 if (err_msg == NULL &&
list_length(current_line) == 2)
812 if (strcmp(first->
string,
"include") == 0)
815 elevel, depth + 1,
false, &err_msg);
826 else if (strcmp(first->
string,
"include_dir") == 0)
829 char *dir_name = second->
string;
834 &num_filenames, &err_msg);
843 for (
int i = 0;
i < num_filenames;
i++)
846 elevel, depth + 1,
false, &err_msg);
857 for (
int i = 0;
i < num_filenames;
i++)
865 if (err_buf.
len == 0)
869 err_msg = err_buf.
data;
872 else if (strcmp(first->
string,
"include_if_exists") == 0)
876 elevel, depth + 1,
true, &err_msg);
897 tok_line->
fields = current_line;
902 *tok_lines =
lappend(*tok_lines, tok_line);
906 line_number += continuations + 1;
907 callback_arg.
linenum = line_number;
958 foreach(cell, tokens)
973 else if (case_insensitive)
997 foreach(cell, tokens)
1013 if (strcmp(
dbname, role) == 0)
1038 return (
a->sin_addr.s_addr ==
b->sin_addr.s_addr);
1046 for (
i = 0;
i < 16;
i++)
1047 if (
a->sin6_addr.s6_addr[
i] !=
b->sin6_addr.s6_addr[
i])
1059 if (pattern[0] ==
'.')
1061 size_t plen = strlen(pattern);
1062 size_t hlen = strlen(actual_hostname);
1067 return (
pg_strcasecmp(pattern, actual_hostname + (hlen - plen)) == 0);
1079 struct addrinfo *gai_result,
1085 if (
port->remote_hostname_resolv < 0)
1089 if (!
port->remote_hostname)
1091 char remote_hostname[NI_MAXHOST];
1094 remote_hostname,
sizeof(remote_hostname),
1100 port->remote_hostname_resolv = -2;
1101 port->remote_hostname_errcode = ret;
1113 if (
port->remote_hostname_resolv == +1)
1117 ret = getaddrinfo(
port->remote_hostname, NULL, NULL, &gai_result);
1121 port->remote_hostname_resolv = -2;
1122 port->remote_hostname_errcode = ret;
1127 for (gai = gai_result; gai; gai = gai->ai_next)
1129 if (gai->ai_addr->sa_family ==
port->raddr.addr.ss_family)
1131 if (gai->ai_addr->sa_family == AF_INET)
1133 if (
ipv4eq((
struct sockaddr_in *) gai->ai_addr,
1134 (
struct sockaddr_in *) &
port->raddr.addr))
1140 else if (gai->ai_addr->sa_family == AF_INET6)
1142 if (
ipv6eq((
struct sockaddr_in6 *) gai->ai_addr,
1143 (
struct sockaddr_in6 *) &
port->raddr.addr))
1153 freeaddrinfo(gai_result);
1156 elog(
DEBUG2,
"pg_hba.conf host name \"%s\" rejected because address resolution did not return a match with IP address of client",
1159 port->remote_hostname_resolv = found ? +1 : -1;
1170 if (raddr->
addr.ss_family == addr->sa_family &&
1172 (
struct sockaddr_storage *) addr,
1173 (
struct sockaddr_storage *) mask))
1186 struct sockaddr_storage mask;
1221 (
errmsg(
"error enumerating network interfaces: %m")));
1243 #define INVALID_AUTH_OPTION(optname, validmethods) \
1246 (errcode(ERRCODE_CONFIG_FILE_ERROR), \
1248 errmsg("authentication option \"%s\" is only valid for authentication methods %s", \
1249 optname, _(validmethods)), \
1250 errcontext("line %d of configuration file \"%s\"", \
1251 line_num, file_name))); \
1252 *err_msg = psprintf("authentication option \"%s\" is only valid for authentication methods %s", \
1253 optname, validmethods); \
1257 #define REQUIRE_AUTH_OPTION(methodval, optname, validmethods) \
1259 if (hbaline->auth_method != methodval) \
1260 INVALID_AUTH_OPTION(optname, validmethods); \
1263 #define MANDATORY_AUTH_ARG(argvar, argname, authname) \
1265 if (argvar == NULL) { \
1267 (errcode(ERRCODE_CONFIG_FILE_ERROR), \
1268 errmsg("authentication method \"%s\" requires argument \"%s\" to be set", \
1269 authname, argname), \
1270 errcontext("line %d of configuration file \"%s\"", \
1271 line_num, file_name))); \
1272 *err_msg = psprintf("authentication method \"%s\" requires argument \"%s\" to be set", \
1273 authname, argname); \
1287 #define IDENT_FIELD_ABSENT(field) \
1291 (errcode(ERRCODE_CONFIG_FILE_ERROR), \
1292 errmsg("missing entry at end of line"), \
1293 errcontext("line %d of configuration file \"%s\"", \
1294 line_num, file_name))); \
1295 *err_msg = pstrdup("missing entry at end of line"); \
1300 #define IDENT_MULTI_VALUE(tokens) \
1302 if (tokens->length > 1) { \
1304 (errcode(ERRCODE_CONFIG_FILE_ERROR), \
1305 errmsg("multiple values in ident field"), \
1306 errcontext("line %d of configuration file \"%s\"", \
1307 line_num, file_name))); \
1308 *err_msg = pstrdup("multiple values in ident field"); \
1331 char **err_msg = &tok_line->
err_msg;
1333 struct addrinfo *gai_result;
1334 struct addrinfo hints;
1356 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
1357 errmsg(
"multiple values specified for connection type"),
1358 errhint(
"Specify exactly one connection type per line."),
1359 errcontext(
"line %d of configuration file \"%s\"",
1360 line_num, file_name)));
1361 *err_msg =
"multiple values specified for connection type";
1365 if (strcmp(
token->string,
"local") == 0)
1369 else if (strcmp(
token->string,
"host") == 0 ||
1370 strcmp(
token->string,
"hostssl") == 0 ||
1371 strcmp(
token->string,
"hostnossl") == 0 ||
1372 strcmp(
token->string,
"hostgssenc") == 0 ||
1373 strcmp(
token->string,
"hostnogssenc") == 0)
1376 if (
token->string[4] ==
's')
1384 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
1385 errmsg(
"hostssl record cannot match because SSL is disabled"),
1386 errhint(
"Set ssl = on in postgresql.conf."),
1387 errcontext(
"line %d of configuration file \"%s\"",
1388 line_num, file_name)));
1389 *err_msg =
"hostssl record cannot match because SSL is disabled";
1393 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
1394 errmsg(
"hostssl record cannot match because SSL is not supported by this build"),
1395 errcontext(
"line %d of configuration file \"%s\"",
1396 line_num, file_name)));
1397 *err_msg =
"hostssl record cannot match because SSL is not supported by this build";
1400 else if (
token->string[4] ==
'g')
1405 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
1406 errmsg(
"hostgssenc record cannot match because GSSAPI is not supported by this build"),
1407 errcontext(
"line %d of configuration file \"%s\"",
1408 line_num, file_name)));
1409 *err_msg =
"hostgssenc record cannot match because GSSAPI is not supported by this build";
1412 else if (
token->string[4] ==
'n' &&
token->string[6] ==
's')
1414 else if (
token->string[4] ==
'n' &&
token->string[6] ==
'g')
1425 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
1426 errmsg(
"invalid connection type \"%s\"",
1428 errcontext(
"line %d of configuration file \"%s\"",
1429 line_num, file_name)));
1430 *err_msg =
psprintf(
"invalid connection type \"%s\"",
token->string);
1439 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
1440 errmsg(
"end-of-line before database specification"),
1441 errcontext(
"line %d of configuration file \"%s\"",
1442 line_num, file_name)));
1443 *err_msg =
"end-of-line before database specification";
1448 foreach(tokencell, tokens)
1464 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
1465 errmsg(
"end-of-line before role specification"),
1466 errcontext(
"line %d of configuration file \"%s\"",
1467 line_num, file_name)));
1468 *err_msg =
"end-of-line before role specification";
1473 foreach(tokencell, tokens)
1491 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
1492 errmsg(
"end-of-line before IP address specification"),
1493 errcontext(
"line %d of configuration file \"%s\"",
1494 line_num, file_name)));
1495 *err_msg =
"end-of-line before IP address specification";
1502 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
1503 errmsg(
"multiple values specified for host address"),
1504 errhint(
"Specify one address range per line."),
1505 errcontext(
"line %d of configuration file \"%s\"",
1506 line_num, file_name)));
1507 *err_msg =
"multiple values specified for host address";
1535 cidr_slash = strchr(
str,
'/');
1540 hints.ai_flags = AI_NUMERICHOST;
1541 hints.ai_family = AF_UNSPEC;
1542 hints.ai_socktype = 0;
1543 hints.ai_protocol = 0;
1544 hints.ai_addrlen = 0;
1545 hints.ai_canonname = NULL;
1546 hints.ai_addr = NULL;
1547 hints.ai_next = NULL;
1550 if (ret == 0 && gai_result)
1552 memcpy(&parsedline->
addr, gai_result->ai_addr,
1553 gai_result->ai_addrlen);
1554 parsedline->
addrlen = gai_result->ai_addrlen;
1556 else if (ret == EAI_NONAME)
1561 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
1562 errmsg(
"invalid IP address \"%s\": %s",
1563 str, gai_strerror(ret)),
1564 errcontext(
"line %d of configuration file \"%s\"",
1565 line_num, file_name)));
1566 *err_msg =
psprintf(
"invalid IP address \"%s\": %s",
1567 str, gai_strerror(ret));
1581 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
1582 errmsg(
"specifying both host name and CIDR mask is invalid: \"%s\"",
1584 errcontext(
"line %d of configuration file \"%s\"",
1585 line_num, file_name)));
1586 *err_msg =
psprintf(
"specifying both host name and CIDR mask is invalid: \"%s\"",
1592 parsedline->
addr.ss_family) < 0)
1595 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
1596 errmsg(
"invalid CIDR mask in address \"%s\"",
1598 errcontext(
"line %d of configuration file \"%s\"",
1599 line_num, file_name)));
1600 *err_msg =
psprintf(
"invalid CIDR mask in address \"%s\"",
1615 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
1616 errmsg(
"end-of-line before netmask specification"),
1617 errhint(
"Specify an address range in CIDR notation, or provide a separate netmask."),
1618 errcontext(
"line %d of configuration file \"%s\"",
1619 line_num, file_name)));
1620 *err_msg =
"end-of-line before netmask specification";
1627 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
1628 errmsg(
"multiple values specified for netmask"),
1629 errcontext(
"line %d of configuration file \"%s\"",
1630 line_num, file_name)));
1631 *err_msg =
"multiple values specified for netmask";
1637 &hints, &gai_result);
1638 if (ret || !gai_result)
1641 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
1642 errmsg(
"invalid IP mask \"%s\": %s",
1643 token->string, gai_strerror(ret)),
1644 errcontext(
"line %d of configuration file \"%s\"",
1645 line_num, file_name)));
1646 *err_msg =
psprintf(
"invalid IP mask \"%s\": %s",
1647 token->string, gai_strerror(ret));
1653 memcpy(&parsedline->
mask, gai_result->ai_addr,
1654 gai_result->ai_addrlen);
1655 parsedline->
masklen = gai_result->ai_addrlen;
1658 if (parsedline->
addr.ss_family != parsedline->
mask.ss_family)
1661 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
1662 errmsg(
"IP address and mask do not match"),
1663 errcontext(
"line %d of configuration file \"%s\"",
1664 line_num, file_name)));
1665 *err_msg =
"IP address and mask do not match";
1677 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
1678 errmsg(
"end-of-line before authentication method"),
1679 errcontext(
"line %d of configuration file \"%s\"",
1680 line_num, file_name)));
1681 *err_msg =
"end-of-line before authentication method";
1688 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
1689 errmsg(
"multiple values specified for authentication type"),
1690 errhint(
"Specify exactly one authentication type per line."),
1691 errcontext(
"line %d of configuration file \"%s\"",
1692 line_num, file_name)));
1693 *err_msg =
"multiple values specified for authentication type";
1699 if (strcmp(
token->string,
"trust") == 0)
1701 else if (strcmp(
token->string,
"ident") == 0)
1703 else if (strcmp(
token->string,
"peer") == 0)
1705 else if (strcmp(
token->string,
"password") == 0)
1707 else if (strcmp(
token->string,
"gss") == 0)
1713 else if (strcmp(
token->string,
"sspi") == 0)
1719 else if (strcmp(
token->string,
"reject") == 0)
1721 else if (strcmp(
token->string,
"md5") == 0)
1723 else if (strcmp(
token->string,
"scram-sha-256") == 0)
1725 else if (strcmp(
token->string,
"pam") == 0)
1731 else if (strcmp(
token->string,
"bsd") == 0)
1737 else if (strcmp(
token->string,
"ldap") == 0)
1743 else if (strcmp(
token->string,
"cert") == 0)
1749 else if (strcmp(
token->string,
"radius") == 0)
1754 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
1755 errmsg(
"invalid authentication method \"%s\"",
1757 errcontext(
"line %d of configuration file \"%s\"",
1758 line_num, file_name)));
1759 *err_msg =
psprintf(
"invalid authentication method \"%s\"",
1767 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
1768 errmsg(
"invalid authentication method \"%s\": not supported by this build",
1770 errcontext(
"line %d of configuration file \"%s\"",
1771 line_num, file_name)));
1772 *err_msg =
psprintf(
"invalid authentication method \"%s\": not supported by this build",
1790 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
1791 errmsg(
"gssapi authentication is not supported on local sockets"),
1792 errcontext(
"line %d of configuration file \"%s\"",
1793 line_num, file_name)));
1794 *err_msg =
"gssapi authentication is not supported on local sockets";
1802 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
1803 errmsg(
"peer authentication is only supported on local sockets"),
1804 errcontext(
"line %d of configuration file \"%s\"",
1805 line_num, file_name)));
1806 *err_msg =
"peer authentication is only supported on local sockets";
1820 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
1821 errmsg(
"cert authentication is only supported on hostssl connections"),
1822 errcontext(
"line %d of configuration file \"%s\"",
1823 line_num, file_name)));
1824 *err_msg =
"cert authentication is only supported on hostssl connections";
1853 while ((field =
lnext(tok_line->
fields, field)) != NULL)
1856 foreach(tokencell, tokens)
1870 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
1871 errmsg(
"authentication option not in name=value format: %s",
token->string),
1872 errcontext(
"line %d of configuration file \"%s\"",
1873 line_num, file_name)));
1874 *err_msg =
psprintf(
"authentication option not in name=value format: %s",
1893 #ifndef HAVE_LDAP_INITIALIZE
1914 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
1915 errmsg(
"cannot use ldapbasedn, ldapbinddn, ldapbindpasswd, ldapsearchattribute, ldapsearchfilter, or ldapurl together with ldapprefix"),
1916 errcontext(
"line %d of configuration file \"%s\"",
1917 line_num, file_name)));
1918 *err_msg =
"cannot use ldapbasedn, ldapbinddn, ldapbindpasswd, ldapsearchattribute, ldapsearchfilter, or ldapurl together with ldapprefix";
1925 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
1926 errmsg(
"authentication method \"ldap\" requires argument \"ldapbasedn\", \"ldapprefix\", or \"ldapsuffix\" to be set"),
1927 errcontext(
"line %d of configuration file \"%s\"",
1928 line_num, file_name)));
1929 *err_msg =
"authentication method \"ldap\" requires argument \"ldapbasedn\", \"ldapprefix\", or \"ldapsuffix\" to be set";
1941 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
1942 errmsg(
"cannot use ldapsearchattribute together with ldapsearchfilter"),
1943 errcontext(
"line %d of configuration file \"%s\"",
1944 line_num, file_name)));
1945 *err_msg =
"cannot use ldapsearchattribute together with ldapsearchfilter";
1958 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
1959 errmsg(
"list of RADIUS servers cannot be empty"),
1960 errcontext(
"line %d of configuration file \"%s\"",
1961 line_num, file_name)));
1962 *err_msg =
"list of RADIUS servers cannot be empty";
1969 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
1970 errmsg(
"list of RADIUS secrets cannot be empty"),
1971 errcontext(
"line %d of configuration file \"%s\"",
1972 line_num, file_name)));
1973 *err_msg =
"list of RADIUS secrets cannot be empty";
1986 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
1987 errmsg(
"the number of RADIUS secrets (%d) must be 1 or the same as the number of RADIUS servers (%d)",
1990 errcontext(
"line %d of configuration file \"%s\"",
1991 line_num, file_name)));
1992 *err_msg =
psprintf(
"the number of RADIUS secrets (%d) must be 1 or the same as the number of RADIUS servers (%d)",
2002 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
2003 errmsg(
"the number of RADIUS ports (%d) must be 1 or the same as the number of RADIUS servers (%d)",
2006 errcontext(
"line %d of configuration file \"%s\"",
2007 line_num, file_name)));
2008 *err_msg =
psprintf(
"the number of RADIUS ports (%d) must be 1 or the same as the number of RADIUS servers (%d)",
2018 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
2019 errmsg(
"the number of RADIUS identifiers (%d) must be 1 or the same as the number of RADIUS servers (%d)",
2022 errcontext(
"line %d of configuration file \"%s\"",
2023 line_num, file_name)));
2024 *err_msg =
psprintf(
"the number of RADIUS identifiers (%d) must be 1 or the same as the number of RADIUS servers (%d)",
2055 int elevel,
char **err_msg)
2061 hbaline->
ldapscope = LDAP_SCOPE_SUBTREE;
2064 if (strcmp(
name,
"map") == 0)
2074 else if (strcmp(
name,
"clientcert") == 0)
2079 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
2080 errmsg(
"clientcert can only be configured for \"hostssl\" rows"),
2081 errcontext(
"line %d of configuration file \"%s\"",
2082 line_num, file_name)));
2083 *err_msg =
"clientcert can only be configured for \"hostssl\" rows";
2087 if (strcmp(
val,
"verify-full") == 0)
2091 else if (strcmp(
val,
"verify-ca") == 0)
2096 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
2097 errmsg(
"clientcert only accepts \"verify-full\" when using \"cert\" authentication"),
2098 errcontext(
"line %d of configuration file \"%s\"",
2099 line_num, file_name)));
2100 *err_msg =
"clientcert can only be set to \"verify-full\" when using \"cert\" authentication";
2109 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
2110 errmsg(
"invalid value for clientcert: \"%s\"",
val),
2111 errcontext(
"line %d of configuration file \"%s\"",
2112 line_num, file_name)));
2116 else if (strcmp(
name,
"clientname") == 0)
2121 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
2122 errmsg(
"clientname can only be configured for \"hostssl\" rows"),
2123 errcontext(
"line %d of configuration file \"%s\"",
2124 line_num, file_name)));
2125 *err_msg =
"clientname can only be configured for \"hostssl\" rows";
2129 if (strcmp(
val,
"CN") == 0)
2133 else if (strcmp(
val,
"DN") == 0)
2140 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
2141 errmsg(
"invalid value for clientname: \"%s\"",
val),
2142 errcontext(
"line %d of configuration file \"%s\"",
2143 line_num, file_name)));
2147 else if (strcmp(
name,
"pamservice") == 0)
2152 else if (strcmp(
name,
"pam_use_hostname") == 0)
2155 if (strcmp(
val,
"1") == 0)
2160 else if (strcmp(
name,
"ldapurl") == 0)
2162 #ifdef LDAP_API_FEATURE_X_OPENLDAP
2163 LDAPURLDesc *urldata;
2168 #ifdef LDAP_API_FEATURE_X_OPENLDAP
2169 rc = ldap_url_parse(
val, &urldata);
2170 if (rc != LDAP_SUCCESS)
2173 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
2174 errmsg(
"could not parse LDAP URL \"%s\": %s",
val, ldap_err2string(rc))));
2175 *err_msg =
psprintf(
"could not parse LDAP URL \"%s\": %s",
2176 val, ldap_err2string(rc));
2180 if (strcmp(urldata->lud_scheme,
"ldap") != 0 &&
2181 strcmp(urldata->lud_scheme,
"ldaps") != 0)
2184 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
2185 errmsg(
"unsupported LDAP URL scheme: %s", urldata->lud_scheme)));
2186 *err_msg =
psprintf(
"unsupported LDAP URL scheme: %s",
2187 urldata->lud_scheme);
2188 ldap_free_urldesc(urldata);
2192 if (urldata->lud_scheme)
2194 if (urldata->lud_host)
2196 hbaline->
ldapport = urldata->lud_port;
2197 if (urldata->lud_dn)
2200 if (urldata->lud_attrs)
2202 hbaline->
ldapscope = urldata->lud_scope;
2203 if (urldata->lud_filter)
2205 ldap_free_urldesc(urldata);
2208 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2209 errmsg(
"LDAP URLs not supported on this platform")));
2210 *err_msg =
"LDAP URLs not supported on this platform";
2213 else if (strcmp(
name,
"ldaptls") == 0)
2216 if (strcmp(
val,
"1") == 0)
2221 else if (strcmp(
name,
"ldapscheme") == 0)
2224 if (strcmp(
val,
"ldap") != 0 && strcmp(
val,
"ldaps") != 0)
2226 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
2227 errmsg(
"invalid ldapscheme value: \"%s\"",
val),
2228 errcontext(
"line %d of configuration file \"%s\"",
2229 line_num, file_name)));
2232 else if (strcmp(
name,
"ldapserver") == 0)
2237 else if (strcmp(
name,
"ldapport") == 0)
2244 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
2245 errmsg(
"invalid LDAP port number: \"%s\"",
val),
2246 errcontext(
"line %d of configuration file \"%s\"",
2247 line_num, file_name)));
2248 *err_msg =
psprintf(
"invalid LDAP port number: \"%s\"",
val);
2252 else if (strcmp(
name,
"ldapbinddn") == 0)
2257 else if (strcmp(
name,
"ldapbindpasswd") == 0)
2262 else if (strcmp(
name,
"ldapsearchattribute") == 0)
2267 else if (strcmp(
name,
"ldapsearchfilter") == 0)
2272 else if (strcmp(
name,
"ldapbasedn") == 0)
2277 else if (strcmp(
name,
"ldapprefix") == 0)
2282 else if (strcmp(
name,
"ldapsuffix") == 0)
2287 else if (strcmp(
name,
"krb_realm") == 0)
2294 else if (strcmp(
name,
"include_realm") == 0)
2299 if (strcmp(
val,
"1") == 0)
2304 else if (strcmp(
name,
"compat_realm") == 0)
2308 if (strcmp(
val,
"1") == 0)
2313 else if (strcmp(
name,
"upn_username") == 0)
2317 if (strcmp(
val,
"1") == 0)
2322 else if (strcmp(
name,
"radiusservers") == 0)
2324 struct addrinfo *gai_result;
2325 struct addrinfo hints;
2327 List *parsed_servers;
2337 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
2338 errmsg(
"could not parse RADIUS server list \"%s\"",
2340 errcontext(
"line %d of configuration file \"%s\"",
2341 line_num, file_name)));
2346 foreach(l, parsed_servers)
2348 MemSet(&hints, 0,
sizeof(hints));
2349 hints.ai_socktype = SOCK_DGRAM;
2350 hints.ai_family = AF_UNSPEC;
2353 if (ret || !gai_result)
2356 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
2357 errmsg(
"could not translate RADIUS server name \"%s\" to address: %s",
2358 (
char *)
lfirst(l), gai_strerror(ret)),
2359 errcontext(
"line %d of configuration file \"%s\"",
2360 line_num, file_name)));
2374 else if (strcmp(
name,
"radiusports") == 0)
2385 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
2386 errmsg(
"could not parse RADIUS port list \"%s\"",
2388 errcontext(
"line %d of configuration file \"%s\"",
2389 line_num, file_name)));
2390 *err_msg =
psprintf(
"invalid RADIUS port number: \"%s\"",
val);
2394 foreach(l, parsed_ports)
2396 if (atoi(
lfirst(l)) == 0)
2399 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
2400 errmsg(
"invalid RADIUS port number: \"%s\"",
val),
2401 errcontext(
"line %d of configuration file \"%s\"",
2402 line_num, file_name)));
2410 else if (strcmp(
name,
"radiussecrets") == 0)
2412 List *parsed_secrets;
2421 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
2422 errmsg(
"could not parse RADIUS secret list \"%s\"",
2424 errcontext(
"line %d of configuration file \"%s\"",
2425 line_num, file_name)));
2432 else if (strcmp(
name,
"radiusidentifiers") == 0)
2434 List *parsed_identifiers;
2443 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
2444 errmsg(
"could not parse RADIUS identifiers list \"%s\"",
2446 errcontext(
"line %d of configuration file \"%s\"",
2447 line_num, file_name)));
2457 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
2458 errmsg(
"unrecognized authentication option name: \"%s\"",
2460 errcontext(
"line %d of configuration file \"%s\"",
2461 line_num, file_name)));
2462 *err_msg =
psprintf(
"unrecognized authentication option name: \"%s\"",
2490 if (
port->raddr.addr.ss_family != AF_UNIX)
2495 if (
port->raddr.addr.ss_family == AF_UNIX)
2499 if (
port->ssl_in_use)
2517 else if (!(
port->gss &&
port->gss->enc) &&
2538 (
struct sockaddr *) &hba->
addr,
2539 (
struct sockaddr *) &hba->
mask))
2610 "hba parser context",
2613 foreach(line, hba_lines)
2619 if (tok_line->
err_msg != NULL)
2646 if (ok && new_parsed_lines ==
NIL)
2649 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
2650 errmsg(
"configuration file \"%s\" contains no entries",
2698 char **err_msg = &tok_line->
err_msg;
2764 bool case_insensitive,
bool *found_p,
bool *error_p)
2771 if (strcmp(identLine->
usermap, usermap_name) != 0)
2790 bool created_temporary_token =
false;
2802 (
errcode(ERRCODE_INVALID_REGULAR_EXPRESSION),
2803 errmsg(
"regular expression match for \"%s\" failed: %s",
2819 char *expanded_pg_user;
2823 if (matches[1].rm_so < 0)
2826 (
errcode(ERRCODE_INVALID_REGULAR_EXPRESSION),
2827 errmsg(
"regular expression \"%s\" has no subexpressions as requested by backreference in \"%s\"",
2839 memcpy(expanded_pg_user, identLine->
pg_user->
string, offset);
2840 memcpy(expanded_pg_user + offset,
2842 matches[1].rm_eo - matches[1].rm_so);
2843 strcat(expanded_pg_user, ofs + 2);
2851 created_temporary_token =
true;
2852 pfree(expanded_pg_user);
2856 expanded_pg_user_token = identLine->
pg_user;
2864 if (created_temporary_token)
2875 if (case_insensitive)
2910 const char *pg_user,
2912 bool case_insensitive)
2914 bool found_entry =
false,
2917 if (usermap_name == NULL || usermap_name[0] ==
'\0')
2919 if (case_insensitive)
2930 (
errmsg(
"provided user name (%s) and authenticated user name (%s) do not match",
2942 &found_entry, &
error);
2943 if (found_entry ||
error)
2947 if (!found_entry && !
error)
2950 (
errmsg(
"no match in usermap \"%s\" for user \"%s\" authenticated as \"%s\"",
2988 "ident parser context",
2991 foreach(line_cell, ident_lines)
2996 if (tok_line->
err_msg != NULL)
bool is_member_of_role_nosuper(Oid member, Oid role)
Oid get_role_oid(const char *rolname, bool missing_ok)
#define MemSet(start, val, len)
#define OidIsValid(objectId)
char * AbsoluteConfigLocation(const char *location, const char *calling_file)
char ** GetConfFilesInDir(const char *includedir, const char *calling_file, int elevel, int *num_filenames, char **err_msg)
#define CONF_FILE_MAX_DEPTH
#define CONF_FILE_START_DEPTH
elog(ERROR, "%s: %s", p2, msg)
int errcode_for_file_access(void)
ErrorContextCallback * error_context_stack
int errhint(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
FILE * AllocateFile(const char *name, const char *mode)
IdentLine * parse_ident_line(TokenizedAuthLine *tok_line, int elevel)
bool pg_isblank(const char c)
FILE * open_auth_file(const char *filename, int elevel, int depth, char **err_msg)
#define MANDATORY_AUTH_ARG(argvar, argname, authname)
static bool is_member(Oid userid, const char *role)
static bool check_role(const char *role, Oid roleid, List *tokens, bool case_insensitive)
static bool hostname_match(const char *pattern, const char *actual_hostname)
StaticAssertDecl(lengthof(UserAuthName)==USER_AUTH_LAST+1, "UserAuthName[] must match the UserAuth enum")
static List * next_field_expand(const char *filename, char **lineptr, int elevel, int depth, char **err_msg)
static bool check_ip(SockAddr *raddr, struct sockaddr *addr, struct sockaddr *mask)
#define token_is_member_check(t)
#define IDENT_FIELD_ABSENT(field)
#define token_is_keyword(t, k)
static bool ipv4eq(struct sockaddr_in *a, struct sockaddr_in *b)
static MemoryContext parsed_ident_context
#define token_matches_insensitive(t, k)
struct check_network_data check_network_data
static bool parse_hba_auth_opt(char *name, char *val, HbaLine *hbaline, int elevel, char **err_msg)
static bool check_same_host_or_net(SockAddr *raddr, IPCompareMethod method)
static int regcomp_auth_token(AuthToken *token, char *filename, int line_num, char **err_msg, int elevel)
static MemoryContext tokenize_context
static int regexec_auth_token(const char *match, AuthToken *token, size_t nmatch, regmatch_t pmatch[])
static void tokenize_include_file(const char *outer_filename, const char *inc_filename, List **tok_lines, int elevel, int depth, bool missing_ok, char **err_msg)
static bool check_hostname(hbaPort *port, const char *hostname)
static void tokenize_error_callback(void *arg)
static void check_hba(hbaPort *port)
static void check_network_callback(struct sockaddr *addr, struct sockaddr *netmask, void *cb_data)
#define token_has_regexp(t)
const char * hba_authname(UserAuth auth_method)
static MemoryContext parsed_hba_context
static AuthToken * copy_auth_token(AuthToken *in)
#define IDENT_MULTI_VALUE(tokens)
void hba_getauthmethod(hbaPort *port)
int check_usermap(const char *usermap_name, const char *pg_user, const char *system_user, bool case_insensitive)
void free_auth_file(FILE *file, int depth)
static bool ipv6eq(struct sockaddr_in6 *a, struct sockaddr_in6 *b)
static List * tokenize_expand_file(List *tokens, const char *outer_filename, const char *inc_filename, int elevel, int depth, char **err_msg)
static void free_auth_token(AuthToken *token)
static List * parsed_ident_lines
static const char *const UserAuthName[]
#define token_matches(t, k)
HbaLine * parse_hba_line(TokenizedAuthLine *tok_line, int elevel)
static bool next_token(char **lineptr, StringInfo buf, bool *initial_quote, bool *terminating_comma)
static List * parsed_hba_lines
#define INVALID_AUTH_OPTION(optname, validmethods)
static AuthToken * make_auth_token(const char *token, bool quoted)
void tokenize_auth_file(const char *filename, FILE *file, List **tok_lines, int elevel, int depth)
static void check_ident_usermap(IdentLine *identLine, const char *usermap_name, const char *pg_user, const char *system_user, bool case_insensitive, bool *found_p, bool *error_p)
static bool check_db(const char *dbname, const char *role, Oid roleid, List *tokens)
#define REQUIRE_AUTH_OPTION(methodval, optname, validmethods)
int pg_sockaddr_cidr_mask(struct sockaddr_storage *mask, char *numbits, int family)
int pg_foreach_ifaddr(PgIfAddrCallback callback, void *cb_data)
int pg_range_sockaddr(const struct sockaddr_storage *addr, const struct sockaddr_storage *netaddr, const struct sockaddr_storage *netmask)
void pg_freeaddrinfo_all(int hint_ai_family, struct addrinfo *ai)
int pg_getnameinfo_all(const struct sockaddr_storage *addr, int salen, char *node, int nodelen, char *service, int servicelen, int flags)
int pg_getaddrinfo_all(const char *hostname, const char *servname, const struct addrinfo *hintp, struct addrinfo **result)
Assert(fmt[strlen(fmt) - 1] !='\n')
List * lappend(List *list, void *datum)
void list_free(List *list)
int pg_mb2wchar_with_len(const char *from, pg_wchar *to, int len)
char * pstrdup(const char *in)
void pfree(void *pointer)
void * palloc0(Size size)
MemoryContext CurrentMemoryContext
MemoryContext PostmasterContext
void MemoryContextDelete(MemoryContext context)
#define AllocSetContextCreate
#define ALLOCSET_START_SMALL_SIZES
#define ALLOCSET_SMALL_SIZES
Datum system_user(PG_FUNCTION_ARGS)
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
bool pg_get_line_append(FILE *stream, StringInfo buf, PromptInterruptContext *prompt_ctx)
static int list_length(const List *l)
#define linitial_node(type, l)
#define lsecond_node(type, l)
static ListCell * list_head(const List *l)
static ListCell * lnext(const List *l, const ListCell *c)
int pg_strcasecmp(const char *s1, const char *s2)
char * psprintf(const char *fmt,...)
int pg_regcomp(regex_t *re, const chr *string, size_t len, int flags, Oid collation)
size_t pg_regerror(int errcode, const regex_t *preg, char *errbuf, size_t errbuf_size)
int pg_regexec(regex_t *re, const chr *string, size_t len, size_t search_start, rm_detail_t *details, size_t nmatch, regmatch_t pmatch[], int flags)
void pg_regfree(regex_t *re)
int pg_strip_crlf(char *str)
void resetStringInfo(StringInfo str)
void appendStringInfoString(StringInfo str, const char *s)
void appendStringInfoChar(StringInfo str, char ch)
void initStringInfo(StringInfo str)
struct ErrorContextCallback * previous
void(* callback)(void *arg)
struct sockaddr_storage mask
ClientCertName clientcertname
ClientCertMode clientcert
char * ldapsearchattribute
struct sockaddr_storage addr
IPCompareMethod ip_cmp_method
char * radiusidentifiers_s
struct sockaddr_storage addr
bool SplitGUCList(char *rawstring, char separator, List **namelist)