diff options
author | Magnus Hagander | 2021-04-07 12:21:19 +0000 |
---|---|---|
committer | Magnus Hagander | 2021-04-07 12:24:47 +0000 |
commit | c1968426ba3de1fe37848863e35fff30261bf941 (patch) | |
tree | 44b642d65b582ff1b080fe251cf94d6eaef9b424 /src/backend | |
parent | 4560e0acdafd57f3ba109b98e15ac047798d960c (diff) |
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
Diffstat (limited to 'src/backend')
-rw-r--r-- | src/backend/libpq/auth.c | 2 | ||||
-rw-r--r-- | src/backend/libpq/hba.c | 25 |
2 files changed, 8 insertions, 19 deletions
diff --git a/src/backend/libpq/auth.c b/src/backend/libpq/auth.c index dee056b0d65..27865b14a03 100644 --- a/src/backend/libpq/auth.c +++ b/src/backend/libpq/auth.c @@ -379,7 +379,7 @@ set_authn_id(Port *port, const char *id) ereport(LOG, errmsg("connection authenticated: identity=\"%s\" method=%s " "(%s:%d)", - port->authn_id, hba_authname(port), HbaFileName, + port->authn_id, hba_authname(port->hba->auth_method), HbaFileName, port->hba->linenumber)); } } diff --git a/src/backend/libpq/hba.c b/src/backend/libpq/hba.c index b720b03e9a5..60767f29572 100644 --- a/src/backend/libpq/hba.c +++ b/src/backend/libpq/hba.c @@ -2607,14 +2607,8 @@ fill_hba_line(Tuplestorestate *tuple_store, TupleDesc tupdesc, else 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 */ - values[index++] = CStringGetTextDatum(UserAuthName[hba->auth_method]); + values[index++] = CStringGetTextDatum(hba_authname(hba->auth_method)); /* options */ options = gethba_options(hba); @@ -3150,18 +3144,13 @@ hba_getauthmethod(hbaPort *port) * should not be freed. */ const char * -hba_authname(hbaPort *port) +hba_authname(UserAuth auth_method) { - UserAuth auth_method; - - Assert(port->hba); - auth_method = port->hba->auth_method; - - if (auth_method < 0 || USER_AUTH_LAST < auth_method) - { - /* Should never happen. */ - elog(FATAL, "port has out-of-bounds UserAuth: %d", auth_method); - } + /* + * Make sure UserAuthName[] tracks additions to the UserAuth enum + */ + StaticAssertStmt(lengthof(UserAuthName) == USER_AUTH_LAST + 1, + "UserAuthName[] must match the UserAuth enum"); return UserAuthName[auth_method]; } |