mirror of
https://git.postgresql.org/git/postgresql.git
synced 2025-02-11 19:20:40 +08:00
Refactor hba_authname
The previous implementation (from 9afffcb833
) had an unnecessary check
on the boundaries of the enum which trigtered compile warnings. To clean
it up, move the pre-existing static assert to a central location and
call that.
Reported-By: Erik Rijkers
Reviewed-By: Michael Paquier
Discussion: https://postgr.es/m/1056399262.13159.1617793249020@webmailclassic.xs4all.nl
This commit is contained in:
parent
4560e0acda
commit
c1968426ba
@ -379,7 +379,7 @@ set_authn_id(Port *port, const char *id)
|
|||||||
ereport(LOG,
|
ereport(LOG,
|
||||||
errmsg("connection authenticated: identity=\"%s\" method=%s "
|
errmsg("connection authenticated: identity=\"%s\" method=%s "
|
||||||
"(%s:%d)",
|
"(%s:%d)",
|
||||||
port->authn_id, hba_authname(port), HbaFileName,
|
port->authn_id, hba_authname(port->hba->auth_method), HbaFileName,
|
||||||
port->hba->linenumber));
|
port->hba->linenumber));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2607,14 +2607,8 @@ fill_hba_line(Tuplestorestate *tuple_store, TupleDesc tupdesc,
|
|||||||
else
|
else
|
||||||
nulls[index++] = true;
|
nulls[index++] = true;
|
||||||
|
|
||||||
/*
|
|
||||||
* Make sure UserAuthName[] tracks additions to the UserAuth enum
|
|
||||||
*/
|
|
||||||
StaticAssertStmt(lengthof(UserAuthName) == USER_AUTH_LAST + 1,
|
|
||||||
"UserAuthName[] must match the UserAuth enum");
|
|
||||||
|
|
||||||
/* auth_method */
|
/* auth_method */
|
||||||
values[index++] = CStringGetTextDatum(UserAuthName[hba->auth_method]);
|
values[index++] = CStringGetTextDatum(hba_authname(hba->auth_method));
|
||||||
|
|
||||||
/* options */
|
/* options */
|
||||||
options = gethba_options(hba);
|
options = gethba_options(hba);
|
||||||
@ -3150,18 +3144,13 @@ hba_getauthmethod(hbaPort *port)
|
|||||||
* should not be freed.
|
* should not be freed.
|
||||||
*/
|
*/
|
||||||
const char *
|
const char *
|
||||||
hba_authname(hbaPort *port)
|
hba_authname(UserAuth auth_method)
|
||||||
{
|
{
|
||||||
UserAuth auth_method;
|
/*
|
||||||
|
* Make sure UserAuthName[] tracks additions to the UserAuth enum
|
||||||
Assert(port->hba);
|
*/
|
||||||
auth_method = port->hba->auth_method;
|
StaticAssertStmt(lengthof(UserAuthName) == USER_AUTH_LAST + 1,
|
||||||
|
"UserAuthName[] must match the UserAuth enum");
|
||||||
if (auth_method < 0 || USER_AUTH_LAST < auth_method)
|
|
||||||
{
|
|
||||||
/* Should never happen. */
|
|
||||||
elog(FATAL, "port has out-of-bounds UserAuth: %d", auth_method);
|
|
||||||
}
|
|
||||||
|
|
||||||
return UserAuthName[auth_method];
|
return UserAuthName[auth_method];
|
||||||
}
|
}
|
||||||
|
@ -137,7 +137,7 @@ typedef struct Port hbaPort;
|
|||||||
|
|
||||||
extern bool load_hba(void);
|
extern bool load_hba(void);
|
||||||
extern bool load_ident(void);
|
extern bool load_ident(void);
|
||||||
extern const char *hba_authname(hbaPort *port);
|
extern const char *hba_authname(UserAuth auth_method);
|
||||||
extern void hba_getauthmethod(hbaPort *port);
|
extern void hba_getauthmethod(hbaPort *port);
|
||||||
extern int check_usermap(const char *usermap_name,
|
extern int check_usermap(const char *usermap_name,
|
||||||
const char *pg_role, const char *auth_user,
|
const char *pg_role, const char *auth_user,
|
||||||
|
Loading…
Reference in New Issue
Block a user