69#define token_has_regexp(t) (t->regex != NULL)
70#define token_is_member_check(t) (!t->quoted && t->string[0] == '+')
71#define token_is_keyword(t, k) (!t->quoted && strcmp(t->string, k) == 0)
72#define token_matches(t, k) (strcmp(t->string, k) == 0)
73#define token_matches_insensitive(t,k) (pg_strcasecmp(t->string, k) == 0)
126 "UserAuthName[] must match the UserAuth enum");
130 const char *inc_filename,
int elevel,
131 int depth,
char **err_msg);
133 int elevel,
char **err_msg);
135 char **err_msg,
int elevel);
148 return c ==
' ' ||
c ==
'\t' ||
c ==
'\r';
188 bool *initial_quote,
bool *terminating_comma)
191 bool in_quote =
false;
192 bool was_quote =
false;
193 bool saw_quote =
false;
197 *initial_quote =
false;
198 *terminating_comma =
false;
212 if (
c ==
'#' && !in_quote)
214 while ((
c = (*(*
lineptr)++)) !=
'\0')
220 if (
c ==
',' && !in_quote)
222 *terminating_comma =
true;
226 if (
c !=
'"' || was_quote)
230 if (in_quote &&
c ==
'"')
231 was_quote = !was_quote;
237 in_quote = !in_quote;
240 *initial_quote =
true;
252 return (saw_quote ||
buf->len > 0);
264 toklen = strlen(
token);
268 authtoken->
quoted = quoted;
269 authtoken->
regex = NULL;
304 char **err_msg,
int elevel)
312 if (
token->string[0] !=
'/')
318 wstr, strlen(
token->string + 1));
328 (
errcode(ERRCODE_INVALID_REGULAR_EXPRESSION),
329 errmsg(
"invalid regular expression \"%s\": %s",
330 token->string + 1, errstr),
331 errcontext(
"line %d of configuration file \"%s\"",
334 *err_msg =
psprintf(
"invalid regular expression \"%s\": %s",
335 token->string + 1, errstr);
360 r =
pg_regexec(
token->regex, wmatchstr, wmatchlen, 0, NULL, nmatch, pmatch, 0);
382 int elevel,
int depth,
char **err_msg)
394 &initial_quote, &trailing_comma))
398 if (!initial_quote &&
buf.len > 1 &&
buf.data[0] ==
'@')
400 elevel, depth + 1, err_msg);
413 }
while (trailing_comma && (*err_msg == NULL));
441 const char *inc_filename,
456 if (errno == ENOENT && missing_ok)
459 (
errmsg(
"skipping missing authentication file \"%s\"",
496 const char *outer_filename,
497 const char *inc_filename,
510 if (inc_file == NULL)
530 foreach(inc_line, inc_lines)
542 foreach(inc_field, tok_line->
fields)
547 foreach(inc_token, inc_tokens)
611 errmsg(
"could not open file \"%s\": maximum nesting depth exceeded",
614 *err_msg =
psprintf(
"could not open file \"%s\": maximum nesting depth exceeded",
622 int save_errno = errno;
626 errmsg(
"could not open file \"%s\": %m",
631 *err_msg =
psprintf(
"could not open file \"%s\": %m",
666 errcontext(
"line %d of configuration file \"%s\"",
692 int elevel,
int depth)
704 callback_arg.
linenum = line_number;
707 tokenerrcontext.
arg = &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;
771 err_msg =
psprintf(
"could not read file \"%s\": %m",
778 while (*
lineptr && err_msg == NULL)
783 elevel, depth, &err_msg);
785 if (current_field !=
NIL)
792 current_line =
lappend(current_line, current_field);
801 if (current_line ==
NIL && err_msg == NULL)
805 if (err_msg == NULL &&
list_length(current_line) == 2)
813 if (strcmp(first->
string,
"include") == 0)
816 elevel, depth + 1,
false, &err_msg);
827 else if (strcmp(first->
string,
"include_dir") == 0)
830 char *dir_name = second->
string;
835 &num_filenames, &err_msg);
844 for (
int i = 0;
i < num_filenames;
i++)
847 elevel, depth + 1,
false, &err_msg);
858 for (
int i = 0;
i < num_filenames;
i++)
866 if (err_buf.
len == 0)
870 err_msg = err_buf.
data;
873 else if (strcmp(first->
string,
"include_if_exists") == 0)
877 elevel, depth + 1,
true, &err_msg);
898 tok_line->
fields = current_line;
903 *tok_lines =
lappend(*tok_lines, tok_line);
907 line_number += continuations + 1;
908 callback_arg.
linenum = line_number;
959 foreach(cell, tokens)
974 else if (case_insensitive)
998 foreach(cell, tokens)
1014 if (strcmp(
dbname, role) == 0)
1039 return (
a->sin_addr.s_addr ==
b->sin_addr.s_addr);
1047 for (
i = 0;
i < 16;
i++)
1048 if (
a->sin6_addr.s6_addr[
i] !=
b->sin6_addr.s6_addr[
i])
1060 if (pattern[0] ==
'.')
1062 size_t plen = strlen(pattern);
1063 size_t hlen = strlen(actual_hostname);
1068 return (
pg_strcasecmp(pattern, actual_hostname + (hlen - plen)) == 0);
1080 struct addrinfo *gai_result,
1086 if (
port->remote_hostname_resolv < 0)
1090 if (!
port->remote_hostname)
1092 char remote_hostname[NI_MAXHOST];
1095 remote_hostname,
sizeof(remote_hostname),
1101 port->remote_hostname_resolv = -2;
1102 port->remote_hostname_errcode = ret;
1114 if (
port->remote_hostname_resolv == +1)
1118 ret = getaddrinfo(
port->remote_hostname, NULL, NULL, &gai_result);
1122 port->remote_hostname_resolv = -2;
1123 port->remote_hostname_errcode = ret;
1128 for (gai = gai_result; gai; gai = gai->ai_next)
1130 if (gai->ai_addr->sa_family ==
port->raddr.addr.ss_family)
1132 if (gai->ai_addr->sa_family == AF_INET)
1134 if (
ipv4eq((
struct sockaddr_in *) gai->ai_addr,
1135 (
struct sockaddr_in *) &
port->raddr.addr))
1141 else if (gai->ai_addr->sa_family == AF_INET6)
1143 if (
ipv6eq((
struct sockaddr_in6 *) gai->ai_addr,
1144 (
struct sockaddr_in6 *) &
port->raddr.addr))
1154 freeaddrinfo(gai_result);
1157 elog(
DEBUG2,
"pg_hba.conf host name \"%s\" rejected because address resolution did not return a match with IP address of client",
1160 port->remote_hostname_resolv = found ? +1 : -1;
1171 if (raddr->
addr.ss_family == addr->sa_family &&
1173 (
struct sockaddr_storage *) addr,
1174 (
struct sockaddr_storage *) mask))
1187 struct sockaddr_storage mask;
1222 (
errmsg(
"error enumerating network interfaces: %m")));
1244#define INVALID_AUTH_OPTION(optname, validmethods) \
1247 (errcode(ERRCODE_CONFIG_FILE_ERROR), \
1249 errmsg("authentication option \"%s\" is only valid for authentication methods %s", \
1250 optname, _(validmethods)), \
1251 errcontext("line %d of configuration file \"%s\"", \
1252 line_num, file_name))); \
1253 *err_msg = psprintf("authentication option \"%s\" is only valid for authentication methods %s", \
1254 optname, validmethods); \
1258#define REQUIRE_AUTH_OPTION(methodval, optname, validmethods) \
1260 if (hbaline->auth_method != methodval) \
1261 INVALID_AUTH_OPTION(optname, validmethods); \
1264#define MANDATORY_AUTH_ARG(argvar, argname, authname) \
1266 if (argvar == NULL) { \
1268 (errcode(ERRCODE_CONFIG_FILE_ERROR), \
1269 errmsg("authentication method \"%s\" requires argument \"%s\" to be set", \
1270 authname, argname), \
1271 errcontext("line %d of configuration file \"%s\"", \
1272 line_num, file_name))); \
1273 *err_msg = psprintf("authentication method \"%s\" requires argument \"%s\" to be set", \
1274 authname, argname); \
1288#define IDENT_FIELD_ABSENT(field) \
1292 (errcode(ERRCODE_CONFIG_FILE_ERROR), \
1293 errmsg("missing entry at end of line"), \
1294 errcontext("line %d of configuration file \"%s\"", \
1295 line_num, file_name))); \
1296 *err_msg = pstrdup("missing entry at end of line"); \
1301#define IDENT_MULTI_VALUE(tokens) \
1303 if (tokens->length > 1) { \
1305 (errcode(ERRCODE_CONFIG_FILE_ERROR), \
1306 errmsg("multiple values in ident field"), \
1307 errcontext("line %d of configuration file \"%s\"", \
1308 line_num, file_name))); \
1309 *err_msg = pstrdup("multiple values in ident field"); \
1332 char **err_msg = &tok_line->
err_msg;
1334 struct addrinfo *gai_result;
1335 struct addrinfo hints;
1357 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
1358 errmsg(
"multiple values specified for connection type"),
1359 errhint(
"Specify exactly one connection type per line."),
1360 errcontext(
"line %d of configuration file \"%s\"",
1361 line_num, file_name)));
1362 *err_msg =
"multiple values specified for connection type";
1366 if (strcmp(
token->string,
"local") == 0)
1370 else if (strcmp(
token->string,
"host") == 0 ||
1371 strcmp(
token->string,
"hostssl") == 0 ||
1372 strcmp(
token->string,
"hostnossl") == 0 ||
1373 strcmp(
token->string,
"hostgssenc") == 0 ||
1374 strcmp(
token->string,
"hostnogssenc") == 0)
1377 if (
token->string[4] ==
's')
1385 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
1386 errmsg(
"hostssl record cannot match because SSL is disabled"),
1387 errhint(
"Set \"ssl = on\" in postgresql.conf."),
1388 errcontext(
"line %d of configuration file \"%s\"",
1389 line_num, file_name)));
1390 *err_msg =
"hostssl record cannot match because SSL is disabled";
1394 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
1395 errmsg(
"hostssl record cannot match because SSL is not supported by this build"),
1396 errcontext(
"line %d of configuration file \"%s\"",
1397 line_num, file_name)));
1398 *err_msg =
"hostssl record cannot match because SSL is not supported by this build";
1401 else if (
token->string[4] ==
'g')
1406 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
1407 errmsg(
"hostgssenc record cannot match because GSSAPI is not supported by this build"),
1408 errcontext(
"line %d of configuration file \"%s\"",
1409 line_num, file_name)));
1410 *err_msg =
"hostgssenc record cannot match because GSSAPI is not supported by this build";
1413 else if (
token->string[4] ==
'n' &&
token->string[6] ==
's')
1415 else if (
token->string[4] ==
'n' &&
token->string[6] ==
'g')
1426 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
1427 errmsg(
"invalid connection type \"%s\"",
1429 errcontext(
"line %d of configuration file \"%s\"",
1430 line_num, file_name)));
1431 *err_msg =
psprintf(
"invalid connection type \"%s\"",
token->string);
1440 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
1441 errmsg(
"end-of-line before database specification"),
1442 errcontext(
"line %d of configuration file \"%s\"",
1443 line_num, file_name)));
1444 *err_msg =
"end-of-line before database specification";
1449 foreach(tokencell, tokens)
1465 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
1466 errmsg(
"end-of-line before role specification"),
1467 errcontext(
"line %d of configuration file \"%s\"",
1468 line_num, file_name)));
1469 *err_msg =
"end-of-line before role specification";
1474 foreach(tokencell, tokens)
1492 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
1493 errmsg(
"end-of-line before IP address specification"),
1494 errcontext(
"line %d of configuration file \"%s\"",
1495 line_num, file_name)));
1496 *err_msg =
"end-of-line before IP address specification";
1503 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
1504 errmsg(
"multiple values specified for host address"),
1505 errhint(
"Specify one address range per line."),
1506 errcontext(
"line %d of configuration file \"%s\"",
1507 line_num, file_name)));
1508 *err_msg =
"multiple values specified for host address";
1536 cidr_slash = strchr(
str,
'/');
1541 hints.ai_flags = AI_NUMERICHOST;
1542 hints.ai_family = AF_UNSPEC;
1543 hints.ai_socktype = 0;
1544 hints.ai_protocol = 0;
1545 hints.ai_addrlen = 0;
1546 hints.ai_canonname = NULL;
1547 hints.ai_addr = NULL;
1548 hints.ai_next = NULL;
1551 if (ret == 0 && gai_result)
1553 memcpy(&parsedline->
addr, gai_result->ai_addr,
1554 gai_result->ai_addrlen);
1555 parsedline->
addrlen = gai_result->ai_addrlen;
1557 else if (ret == EAI_NONAME)
1562 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
1563 errmsg(
"invalid IP address \"%s\": %s",
1565 errcontext(
"line %d of configuration file \"%s\"",
1566 line_num, file_name)));
1567 *err_msg =
psprintf(
"invalid IP address \"%s\": %s",
1582 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
1583 errmsg(
"specifying both host name and CIDR mask is invalid: \"%s\"",
1585 errcontext(
"line %d of configuration file \"%s\"",
1586 line_num, file_name)));
1587 *err_msg =
psprintf(
"specifying both host name and CIDR mask is invalid: \"%s\"",
1593 parsedline->
addr.ss_family) < 0)
1596 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
1597 errmsg(
"invalid CIDR mask in address \"%s\"",
1599 errcontext(
"line %d of configuration file \"%s\"",
1600 line_num, file_name)));
1601 *err_msg =
psprintf(
"invalid CIDR mask in address \"%s\"",
1616 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
1617 errmsg(
"end-of-line before netmask specification"),
1618 errhint(
"Specify an address range in CIDR notation, or provide a separate netmask."),
1619 errcontext(
"line %d of configuration file \"%s\"",
1620 line_num, file_name)));
1621 *err_msg =
"end-of-line before netmask specification";
1628 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
1629 errmsg(
"multiple values specified for netmask"),
1630 errcontext(
"line %d of configuration file \"%s\"",
1631 line_num, file_name)));
1632 *err_msg =
"multiple values specified for netmask";
1638 &hints, &gai_result);
1639 if (ret || !gai_result)
1642 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
1643 errmsg(
"invalid IP mask \"%s\": %s",
1645 errcontext(
"line %d of configuration file \"%s\"",
1646 line_num, file_name)));
1647 *err_msg =
psprintf(
"invalid IP mask \"%s\": %s",
1654 memcpy(&parsedline->
mask, gai_result->ai_addr,
1655 gai_result->ai_addrlen);
1656 parsedline->
masklen = gai_result->ai_addrlen;
1659 if (parsedline->
addr.ss_family != parsedline->
mask.ss_family)
1662 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
1663 errmsg(
"IP address and mask do not match"),
1664 errcontext(
"line %d of configuration file \"%s\"",
1665 line_num, file_name)));
1666 *err_msg =
"IP address and mask do not match";
1678 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
1679 errmsg(
"end-of-line before authentication method"),
1680 errcontext(
"line %d of configuration file \"%s\"",
1681 line_num, file_name)));
1682 *err_msg =
"end-of-line before authentication method";
1689 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
1690 errmsg(
"multiple values specified for authentication type"),
1691 errhint(
"Specify exactly one authentication type per line."),
1692 errcontext(
"line %d of configuration file \"%s\"",
1693 line_num, file_name)));
1694 *err_msg =
"multiple values specified for authentication type";
1700 if (strcmp(
token->string,
"trust") == 0)
1702 else if (strcmp(
token->string,
"ident") == 0)
1704 else if (strcmp(
token->string,
"peer") == 0)
1706 else if (strcmp(
token->string,
"password") == 0)
1708 else if (strcmp(
token->string,
"gss") == 0)
1714 else if (strcmp(
token->string,
"sspi") == 0)
1720 else if (strcmp(
token->string,
"reject") == 0)
1722 else if (strcmp(
token->string,
"md5") == 0)
1724 else if (strcmp(
token->string,
"scram-sha-256") == 0)
1726 else if (strcmp(
token->string,
"pam") == 0)
1732 else if (strcmp(
token->string,
"bsd") == 0)
1738 else if (strcmp(
token->string,
"ldap") == 0)
1744 else if (strcmp(
token->string,
"cert") == 0)
1750 else if (strcmp(
token->string,
"radius") == 0)
1752 else if (strcmp(
token->string,
"oauth") == 0)
1757 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
1758 errmsg(
"invalid authentication method \"%s\"",
1760 errcontext(
"line %d of configuration file \"%s\"",
1761 line_num, file_name)));
1762 *err_msg =
psprintf(
"invalid authentication method \"%s\"",
1770 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
1771 errmsg(
"invalid authentication method \"%s\": not supported by this build",
1773 errcontext(
"line %d of configuration file \"%s\"",
1774 line_num, file_name)));
1775 *err_msg =
psprintf(
"invalid authentication method \"%s\": not supported by this build",
1793 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
1794 errmsg(
"gssapi authentication is not supported on local sockets"),
1795 errcontext(
"line %d of configuration file \"%s\"",
1796 line_num, file_name)));
1797 *err_msg =
"gssapi authentication is not supported on local sockets";
1805 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
1806 errmsg(
"peer authentication is only supported on local sockets"),
1807 errcontext(
"line %d of configuration file \"%s\"",
1808 line_num, file_name)));
1809 *err_msg =
"peer authentication is only supported on local sockets";
1823 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
1824 errmsg(
"cert authentication is only supported on hostssl connections"),
1825 errcontext(
"line %d of configuration file \"%s\"",
1826 line_num, file_name)));
1827 *err_msg =
"cert authentication is only supported on hostssl connections";
1856 while ((field =
lnext(tok_line->
fields, field)) != NULL)
1859 foreach(tokencell, tokens)
1873 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
1874 errmsg(
"authentication option not in name=value format: %s",
token->string),
1875 errcontext(
"line %d of configuration file \"%s\"",
1876 line_num, file_name)));
1877 *err_msg =
psprintf(
"authentication option not in name=value format: %s",
1896#ifndef HAVE_LDAP_INITIALIZE
1917 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
1918 errmsg(
"cannot mix options for simple bind and search+bind modes"),
1919 errcontext(
"line %d of configuration file \"%s\"",
1920 line_num, file_name)));
1921 *err_msg =
"cannot mix options for simple bind and search+bind modes";
1928 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
1929 errmsg(
"authentication method \"ldap\" requires argument \"ldapbasedn\", \"ldapprefix\", or \"ldapsuffix\" to be set"),
1930 errcontext(
"line %d of configuration file \"%s\"",
1931 line_num, file_name)));
1932 *err_msg =
"authentication method \"ldap\" requires argument \"ldapbasedn\", \"ldapprefix\", or \"ldapsuffix\" to be set";
1944 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
1945 errmsg(
"cannot use ldapsearchattribute together with ldapsearchfilter"),
1946 errcontext(
"line %d of configuration file \"%s\"",
1947 line_num, file_name)));
1948 *err_msg =
"cannot use ldapsearchattribute together with ldapsearchfilter";
1961 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
1962 errmsg(
"list of RADIUS servers cannot be empty"),
1963 errcontext(
"line %d of configuration file \"%s\"",
1964 line_num, file_name)));
1965 *err_msg =
"list of RADIUS servers cannot be empty";
1972 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
1973 errmsg(
"list of RADIUS secrets cannot be empty"),
1974 errcontext(
"line %d of configuration file \"%s\"",
1975 line_num, file_name)));
1976 *err_msg =
"list of RADIUS secrets cannot be empty";
1989 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
1990 errmsg(
"the number of RADIUS secrets (%d) must be 1 or the same as the number of RADIUS servers (%d)",
1993 errcontext(
"line %d of configuration file \"%s\"",
1994 line_num, file_name)));
1995 *err_msg =
psprintf(
"the number of RADIUS secrets (%d) must be 1 or the same as the number of RADIUS servers (%d)",
2005 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
2006 errmsg(
"the number of RADIUS ports (%d) must be 1 or the same as the number of RADIUS servers (%d)",
2009 errcontext(
"line %d of configuration file \"%s\"",
2010 line_num, file_name)));
2011 *err_msg =
psprintf(
"the number of RADIUS ports (%d) must be 1 or the same as the number of RADIUS servers (%d)",
2021 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
2022 errmsg(
"the number of RADIUS identifiers (%d) must be 1 or the same as the number of RADIUS servers (%d)",
2025 errcontext(
"line %d of configuration file \"%s\"",
2026 line_num, file_name)));
2027 *err_msg =
psprintf(
"the number of RADIUS identifiers (%d) must be 1 or the same as the number of RADIUS servers (%d)",
2065 errcode(ERRCODE_CONFIG_FILE_ERROR),
2067 errmsg(
"%s cannot be used in combination with %s",
2068 "map",
"delegate_ident_mapping"),
2069 errcontext(
"line %d of configuration file \"%s\"",
2070 line_num, file_name));
2071 *err_msg =
"map cannot be used in combination with delegate_ident_mapping";
2088 int elevel,
char **err_msg)
2094 hbaline->
ldapscope = LDAP_SCOPE_SUBTREE;
2097 if (strcmp(
name,
"map") == 0)
2108 else if (strcmp(
name,
"clientcert") == 0)
2113 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
2114 errmsg(
"clientcert can only be configured for \"hostssl\" rows"),
2115 errcontext(
"line %d of configuration file \"%s\"",
2116 line_num, file_name)));
2117 *err_msg =
"clientcert can only be configured for \"hostssl\" rows";
2121 if (strcmp(
val,
"verify-full") == 0)
2125 else if (strcmp(
val,
"verify-ca") == 0)
2130 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
2131 errmsg(
"clientcert only accepts \"verify-full\" when using \"cert\" authentication"),
2132 errcontext(
"line %d of configuration file \"%s\"",
2133 line_num, file_name)));
2134 *err_msg =
"clientcert can only be set to \"verify-full\" when using \"cert\" authentication";
2143 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
2144 errmsg(
"invalid value for clientcert: \"%s\"",
val),
2145 errcontext(
"line %d of configuration file \"%s\"",
2146 line_num, file_name)));
2150 else if (strcmp(
name,
"clientname") == 0)
2155 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
2156 errmsg(
"clientname can only be configured for \"hostssl\" rows"),
2157 errcontext(
"line %d of configuration file \"%s\"",
2158 line_num, file_name)));
2159 *err_msg =
"clientname can only be configured for \"hostssl\" rows";
2163 if (strcmp(
val,
"CN") == 0)
2167 else if (strcmp(
val,
"DN") == 0)
2174 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
2175 errmsg(
"invalid value for clientname: \"%s\"",
val),
2176 errcontext(
"line %d of configuration file \"%s\"",
2177 line_num, file_name)));
2181 else if (strcmp(
name,
"pamservice") == 0)
2186 else if (strcmp(
name,
"pam_use_hostname") == 0)
2189 if (strcmp(
val,
"1") == 0)
2194 else if (strcmp(
name,
"ldapurl") == 0)
2196#ifdef LDAP_API_FEATURE_X_OPENLDAP
2197 LDAPURLDesc *urldata;
2202#ifdef LDAP_API_FEATURE_X_OPENLDAP
2203 rc = ldap_url_parse(
val, &urldata);
2204 if (rc != LDAP_SUCCESS)
2207 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
2208 errmsg(
"could not parse LDAP URL \"%s\": %s",
val, ldap_err2string(rc))));
2209 *err_msg =
psprintf(
"could not parse LDAP URL \"%s\": %s",
2210 val, ldap_err2string(rc));
2214 if (strcmp(urldata->lud_scheme,
"ldap") != 0 &&
2215 strcmp(urldata->lud_scheme,
"ldaps") != 0)
2218 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
2219 errmsg(
"unsupported LDAP URL scheme: %s", urldata->lud_scheme)));
2220 *err_msg =
psprintf(
"unsupported LDAP URL scheme: %s",
2221 urldata->lud_scheme);
2222 ldap_free_urldesc(urldata);
2226 if (urldata->lud_scheme)
2228 if (urldata->lud_host)
2230 hbaline->
ldapport = urldata->lud_port;
2231 if (urldata->lud_dn)
2234 if (urldata->lud_attrs)
2236 hbaline->
ldapscope = urldata->lud_scope;
2237 if (urldata->lud_filter)
2239 ldap_free_urldesc(urldata);
2242 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2243 errmsg(
"LDAP URLs not supported on this platform")));
2244 *err_msg =
"LDAP URLs not supported on this platform";
2247 else if (strcmp(
name,
"ldaptls") == 0)
2250 if (strcmp(
val,
"1") == 0)
2255 else if (strcmp(
name,
"ldapscheme") == 0)
2258 if (strcmp(
val,
"ldap") != 0 && strcmp(
val,
"ldaps") != 0)
2260 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
2261 errmsg(
"invalid ldapscheme value: \"%s\"",
val),
2262 errcontext(
"line %d of configuration file \"%s\"",
2263 line_num, file_name)));
2266 else if (strcmp(
name,
"ldapserver") == 0)
2271 else if (strcmp(
name,
"ldapport") == 0)
2278 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
2279 errmsg(
"invalid LDAP port number: \"%s\"",
val),
2280 errcontext(
"line %d of configuration file \"%s\"",
2281 line_num, file_name)));
2282 *err_msg =
psprintf(
"invalid LDAP port number: \"%s\"",
val);
2286 else if (strcmp(
name,
"ldapbinddn") == 0)
2291 else if (strcmp(
name,
"ldapbindpasswd") == 0)
2296 else if (strcmp(
name,
"ldapsearchattribute") == 0)
2301 else if (strcmp(
name,
"ldapsearchfilter") == 0)
2306 else if (strcmp(
name,
"ldapbasedn") == 0)
2311 else if (strcmp(
name,
"ldapprefix") == 0)
2316 else if (strcmp(
name,
"ldapsuffix") == 0)
2321 else if (strcmp(
name,
"krb_realm") == 0)
2328 else if (strcmp(
name,
"include_realm") == 0)
2333 if (strcmp(
val,
"1") == 0)
2338 else if (strcmp(
name,
"compat_realm") == 0)
2342 if (strcmp(
val,
"1") == 0)
2347 else if (strcmp(
name,
"upn_username") == 0)
2351 if (strcmp(
val,
"1") == 0)
2356 else if (strcmp(
name,
"radiusservers") == 0)
2358 struct addrinfo *gai_result;
2359 struct addrinfo hints;
2361 List *parsed_servers;
2371 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
2372 errmsg(
"could not parse RADIUS server list \"%s\"",
2374 errcontext(
"line %d of configuration file \"%s\"",
2375 line_num, file_name)));
2380 foreach(l, parsed_servers)
2382 MemSet(&hints, 0,
sizeof(hints));
2383 hints.ai_socktype = SOCK_DGRAM;
2384 hints.ai_family = AF_UNSPEC;
2387 if (ret || !gai_result)
2390 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
2391 errmsg(
"could not translate RADIUS server name \"%s\" to address: %s",
2393 errcontext(
"line %d of configuration file \"%s\"",
2394 line_num, file_name)));
2408 else if (strcmp(
name,
"radiusports") == 0)
2419 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
2420 errmsg(
"could not parse RADIUS port list \"%s\"",
2422 errcontext(
"line %d of configuration file \"%s\"",
2423 line_num, file_name)));
2424 *err_msg =
psprintf(
"invalid RADIUS port number: \"%s\"",
val);
2428 foreach(l, parsed_ports)
2430 if (atoi(
lfirst(l)) == 0)
2433 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
2434 errmsg(
"invalid RADIUS port number: \"%s\"",
val),
2435 errcontext(
"line %d of configuration file \"%s\"",
2436 line_num, file_name)));
2444 else if (strcmp(
name,
"radiussecrets") == 0)
2446 List *parsed_secrets;
2455 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
2456 errmsg(
"could not parse RADIUS secret list \"%s\"",
2458 errcontext(
"line %d of configuration file \"%s\"",
2459 line_num, file_name)));
2466 else if (strcmp(
name,
"radiusidentifiers") == 0)
2468 List *parsed_identifiers;
2477 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
2478 errmsg(
"could not parse RADIUS identifiers list \"%s\"",
2480 errcontext(
"line %d of configuration file \"%s\"",
2481 line_num, file_name)));
2488 else if (strcmp(
name,
"issuer") == 0)
2493 else if (strcmp(
name,
"scope") == 0)
2498 else if (strcmp(
name,
"validator") == 0)
2503 else if (strcmp(
name,
"delegate_ident_mapping") == 0)
2506 if (strcmp(
val,
"1") == 0)
2514 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
2515 errmsg(
"unrecognized authentication option name: \"%s\"",
2517 errcontext(
"line %d of configuration file \"%s\"",
2518 line_num, file_name)));
2519 *err_msg =
psprintf(
"unrecognized authentication option name: \"%s\"",
2547 if (
port->raddr.addr.ss_family != AF_UNIX)
2552 if (
port->raddr.addr.ss_family == AF_UNIX)
2556 if (
port->ssl_in_use)
2574 else if (!(
port->gss &&
port->gss->enc) &&
2595 (
struct sockaddr *) &hba->
addr,
2596 (
struct sockaddr *) &hba->
mask))
2667 "hba parser context",
2670 foreach(line, hba_lines)
2676 if (tok_line->
err_msg != NULL)
2703 if (ok && new_parsed_lines ==
NIL)
2706 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
2707 errmsg(
"configuration file \"%s\" contains no entries",
2755 char **err_msg = &tok_line->
err_msg;
2821 bool case_insensitive,
bool *found_p,
bool *error_p)
2828 if (strcmp(identLine->
usermap, usermap_name) != 0)
2847 bool created_temporary_token =
false;
2859 (
errcode(ERRCODE_INVALID_REGULAR_EXPRESSION),
2860 errmsg(
"regular expression match for \"%s\" failed: %s",
2876 char *expanded_pg_user;
2880 if (matches[1].rm_so < 0)
2883 (
errcode(ERRCODE_INVALID_REGULAR_EXPRESSION),
2884 errmsg(
"regular expression \"%s\" has no subexpressions as requested by backreference in \"%s\"",
2894 expanded_pg_user =
palloc0(strlen(identLine->
pg_user->
string) - 2 + (matches[1].rm_eo - matches[1].rm_so) + 1);
2896 memcpy(expanded_pg_user, identLine->
pg_user->
string, offset);
2897 memcpy(expanded_pg_user + offset,
2899 matches[1].rm_eo - matches[1].rm_so);
2900 strcat(expanded_pg_user, ofs + 2);
2908 created_temporary_token =
true;
2909 pfree(expanded_pg_user);
2913 expanded_pg_user_token = identLine->
pg_user;
2921 if (created_temporary_token)
2932 if (case_insensitive)
2967 const char *pg_user,
2969 bool case_insensitive)
2971 bool found_entry =
false,
2974 if (usermap_name == NULL || usermap_name[0] ==
'\0')
2976 if (case_insensitive)
2987 (
errmsg(
"provided user name (%s) and authenticated user name (%s) do not match",
2999 &found_entry, &
error);
3000 if (found_entry ||
error)
3004 if (!found_entry && !
error)
3007 (
errmsg(
"no match in usermap \"%s\" for user \"%s\" authenticated as \"%s\"",
3045 "ident parser context",
3048 foreach(line_cell, ident_lines)
3053 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)
bool check_oauth_validator(HbaLine *hbaline, int elevel, char **err_msg)
#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
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)
Assert(PointerIsAligned(start, uint64))
bool pg_isblank(const char c)
static AuthToken * make_auth_token(const char *token, bool quoted)
#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)
HbaLine * parse_hba_line(TokenizedAuthLine *tok_line, int elevel)
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 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 List * next_field_expand(const char *filename, char **lineptr, int elevel, int depth, char **err_msg)
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)
static MemoryContext parsed_hba_context
static AuthToken * copy_auth_token(AuthToken *in)
#define IDENT_MULTI_VALUE(tokens)
void hba_getauthmethod(hbaPort *port)
IdentLine * parse_ident_line(TokenizedAuthLine *tok_line, int elevel)
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)
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)
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)
const char * hba_authname(UserAuth auth_method)
#define REQUIRE_AUTH_OPTION(methodval, optname, validmethods)
FILE * open_auth_file(const char *filename, int elevel, int depth, char **err_msg)
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)
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)
const char * gai_strerror(int ecode)
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)