Skip to content

Commit c196842

Browse files
committed
Refactor hba_authname
The previous implementation (from 9afffcb) 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
1 parent 4560e0a commit c196842

File tree

3 files changed

+9
-20
lines changed

3 files changed

+9
-20
lines changed

src/backend/libpq/auth.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ set_authn_id(Port *port, const char *id)
379379
ereport(LOG,
380380
errmsg("connection authenticated: identity=\"%s\" method=%s "
381381
"(%s:%d)",
382-
port->authn_id, hba_authname(port), HbaFileName,
382+
port->authn_id, hba_authname(port->hba->auth_method), HbaFileName,
383383
port->hba->linenumber));
384384
}
385385
}

src/backend/libpq/hba.c

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2607,14 +2607,8 @@ fill_hba_line(Tuplestorestate *tuple_store, TupleDesc tupdesc,
26072607
else
26082608
nulls[index++] = true;
26092609

2610-
/*
2611-
* Make sure UserAuthName[] tracks additions to the UserAuth enum
2612-
*/
2613-
StaticAssertStmt(lengthof(UserAuthName) == USER_AUTH_LAST + 1,
2614-
"UserAuthName[] must match the UserAuth enum");
2615-
26162610
/* auth_method */
2617-
values[index++] = CStringGetTextDatum(UserAuthName[hba->auth_method]);
2611+
values[index++] = CStringGetTextDatum(hba_authname(hba->auth_method));
26182612

26192613
/* options */
26202614
options = gethba_options(hba);
@@ -3150,18 +3144,13 @@ hba_getauthmethod(hbaPort *port)
31503144
* should not be freed.
31513145
*/
31523146
const char *
3153-
hba_authname(hbaPort *port)
3147+
hba_authname(UserAuth auth_method)
31543148
{
3155-
UserAuth auth_method;
3156-
3157-
Assert(port->hba);
3158-
auth_method = port->hba->auth_method;
3159-
3160-
if (auth_method < 0 || USER_AUTH_LAST < auth_method)
3161-
{
3162-
/* Should never happen. */
3163-
elog(FATAL, "port has out-of-bounds UserAuth: %d", auth_method);
3164-
}
3149+
/*
3150+
* Make sure UserAuthName[] tracks additions to the UserAuth enum
3151+
*/
3152+
StaticAssertStmt(lengthof(UserAuthName) == USER_AUTH_LAST + 1,
3153+
"UserAuthName[] must match the UserAuth enum");
31653154

31663155
return UserAuthName[auth_method];
31673156
}

src/include/libpq/hba.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ typedef struct Port hbaPort;
137137

138138
extern bool load_hba(void);
139139
extern bool load_ident(void);
140-
extern const char *hba_authname(hbaPort *port);
140+
extern const char *hba_authname(UserAuth auth_method);
141141
extern void hba_getauthmethod(hbaPort *port);
142142
extern int check_usermap(const char *usermap_name,
143143
const char *pg_role, const char *auth_user,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy