From 72696ea09ee546166513065f77902a56c19b4f09 Mon Sep 17 00:00:00 2001
From: Jelte Fennema <jelte.fennema@microsoft.com>
Date: Wed, 28 Dec 2022 09:48:31 +0100
Subject: [PATCH v2 1/2] Rename token to systemuser in IdentLine struct

The fieldname "token" is not descriptive of what the token actually
contains. This changes it the fieldname to systemuser. One reason for
this change is to prepare for a future commit where pg_role will become
a token.
---
 src/backend/libpq/hba.c          | 22 +++++++++++-----------
 src/backend/utils/adt/hbafuncs.c |  2 +-
 src/include/libpq/hba.h          |  2 +-
 3 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/src/backend/libpq/hba.c b/src/backend/libpq/hba.c
index 870b907697..3e966acfc0 100644
--- a/src/backend/libpq/hba.c
+++ b/src/backend/libpq/hba.c
@@ -2792,7 +2792,7 @@ parse_ident_line(TokenizedAuthLine *tok_line, int elevel)
 	token = linitial(tokens);
 
 	/* Copy the ident user token */
-	parsedline->token = copy_auth_token(token);
+	parsedline->systemuser = copy_auth_token(token);
 
 	/* Get the PG rolename token */
 	field = lnext(tok_line->fields, field);
@@ -2806,7 +2806,7 @@ parse_ident_line(TokenizedAuthLine *tok_line, int elevel)
 	 * Now that the field validation is done, compile a regex from the user
 	 * token, if necessary.
 	 */
-	if (regcomp_auth_token(parsedline->token, file_name, line_num,
+	if (regcomp_auth_token(parsedline->systemuser, file_name, line_num,
 						   err_msg, elevel))
 	{
 		/* err_msg includes the error to report */
@@ -2835,7 +2835,7 @@ check_ident_usermap(IdentLine *identLine, const char *usermap_name,
 		return;
 
 	/* Match? */
-	if (token_has_regexp(identLine->token))
+	if (token_has_regexp(identLine->systemuser))
 	{
 		/*
 		 * Process the system username as a regular expression that returns
@@ -2847,7 +2847,7 @@ check_ident_usermap(IdentLine *identLine, const char *usermap_name,
 		char	   *ofs;
 		char	   *regexp_pgrole;
 
-		r = regexec_auth_token(ident_user, identLine->token, 2, matches);
+		r = regexec_auth_token(ident_user, identLine->systemuser, 2, matches);
 		if (r)
 		{
 			char		errstr[100];
@@ -2855,11 +2855,11 @@ check_ident_usermap(IdentLine *identLine, const char *usermap_name,
 			if (r != REG_NOMATCH)
 			{
 				/* REG_NOMATCH is not an error, everything else is */
-				pg_regerror(r, identLine->token->regex, errstr, sizeof(errstr));
+				pg_regerror(r, identLine->systemuser->regex, errstr, sizeof(errstr));
 				ereport(LOG,
 						(errcode(ERRCODE_INVALID_REGULAR_EXPRESSION),
 						 errmsg("regular expression match for \"%s\" failed: %s",
-								identLine->token->string + 1, errstr)));
+								identLine->systemuser->string + 1, errstr)));
 				*error_p = true;
 			}
 			return;
@@ -2875,7 +2875,7 @@ check_ident_usermap(IdentLine *identLine, const char *usermap_name,
 				ereport(LOG,
 						(errcode(ERRCODE_INVALID_REGULAR_EXPRESSION),
 						 errmsg("regular expression \"%s\" has no subexpressions as requested by backreference in \"%s\"",
-								identLine->token->string + 1, identLine->pg_role)));
+								identLine->systemuser->string + 1, identLine->pg_role)));
 				*error_p = true;
 				return;
 			}
@@ -2922,13 +2922,13 @@ check_ident_usermap(IdentLine *identLine, const char *usermap_name,
 		if (case_insensitive)
 		{
 			if (pg_strcasecmp(identLine->pg_role, pg_role) == 0 &&
-				pg_strcasecmp(identLine->token->string, ident_user) == 0)
+				pg_strcasecmp(identLine->systemuser->string, ident_user) == 0)
 				*found_p = true;
 		}
 		else
 		{
 			if (strcmp(identLine->pg_role, pg_role) == 0 &&
-				strcmp(identLine->token->string, ident_user) == 0)
+				strcmp(identLine->systemuser->string, ident_user) == 0)
 				*found_p = true;
 		}
 	}
@@ -3073,7 +3073,7 @@ load_ident(void)
 		foreach(parsed_line_cell, new_parsed_lines)
 		{
 			newline = (IdentLine *) lfirst(parsed_line_cell);
-			free_auth_token(newline->token);
+			free_auth_token(newline->systemuser);
 		}
 		MemoryContextDelete(ident_context);
 		return false;
@@ -3085,7 +3085,7 @@ load_ident(void)
 		foreach(parsed_line_cell, parsed_ident_lines)
 		{
 			newline = (IdentLine *) lfirst(parsed_line_cell);
-			free_auth_token(newline->token);
+			free_auth_token(newline->systemuser);
 		}
 	}
 	if (parsed_ident_context != NULL)
diff --git a/src/backend/utils/adt/hbafuncs.c b/src/backend/utils/adt/hbafuncs.c
index 633eda30d3..be6b513d64 100644
--- a/src/backend/utils/adt/hbafuncs.c
+++ b/src/backend/utils/adt/hbafuncs.c
@@ -492,7 +492,7 @@ fill_ident_line(Tuplestorestate *tuple_store, TupleDesc tupdesc,
 	if (ident != NULL)
 	{
 		values[index++] = CStringGetTextDatum(ident->usermap);
-		values[index++] = CStringGetTextDatum(ident->token->string);
+		values[index++] = CStringGetTextDatum(ident->systemuser->string);
 		values[index++] = CStringGetTextDatum(ident->pg_role);
 	}
 	else
diff --git a/src/include/libpq/hba.h b/src/include/libpq/hba.h
index 90c51ad6fa..f1f27d6138 100644
--- a/src/include/libpq/hba.h
+++ b/src/include/libpq/hba.h
@@ -143,7 +143,7 @@ typedef struct IdentLine
 
 	char	   *usermap;
 	char	   *pg_role;
-	AuthToken  *token;
+	AuthToken  *systemuser;
 } IdentLine;
 
 /*
-- 
2.34.1

