Standardize GetTokenInformation() error reporting.
authorNoah Misch <noah@leadboat.com>
Thu, 7 Apr 2016 03:41:43 +0000 (23:41 -0400)
committerNoah Misch <noah@leadboat.com>
Thu, 7 Apr 2016 03:41:43 +0000 (23:41 -0400)
Commit c22650cd6450854e1a75064b698d7dcbb4a8821a sparked a discussion
about diverse interpretations of "token user" in error messages.  Expel
old and new specimens of that phrase by making all GetTokenInformation()
callers report errors the way GetTokenUser() has been reporting them.
These error conditions almost can't happen, so users are unlikely to
observe this change.

Reviewed by Tom Lane and Stephen Frost.

src/backend/libpq/auth.c
src/port/win32security.c
src/test/regress/pg_regress.c

index 2751183c3e694dac307344ed08e6c75682b1bdd2..f21056e2445d8db9cd67b36663d38552f668ffe3 100644 (file)
@@ -1242,8 +1242,8 @@ pg_SSPI_recvauth(Port *port)
 
        if (!GetTokenInformation(token, TokenUser, NULL, 0, &retlen) && GetLastError() != 122)
                ereport(ERROR,
-                       (errmsg_internal("could not get token user size: error code %lu",
-                                                        GetLastError())));
+                               (errmsg_internal("could not get token information buffer size: error code %lu",
+                                                                GetLastError())));
 
        tokenuser = malloc(retlen);
        if (tokenuser == NULL)
@@ -1252,8 +1252,8 @@ pg_SSPI_recvauth(Port *port)
 
        if (!GetTokenInformation(token, TokenUser, tokenuser, retlen, &retlen))
                ereport(ERROR,
-                               (errmsg_internal("could not get token user: error code %lu",
-                                                                GetLastError())));
+                 (errmsg_internal("could not get token information: error code %lu",
+                                                  GetLastError())));
 
        CloseHandle(token);
 
index d3eba9a20b570cb682ccf61f69caf9a0dabcf783..ab9cd67748dd026f65ede6ad23d6e508470d99fe 100644 (file)
@@ -248,14 +248,14 @@ pgwin32_get_dynamic_tokeninfo(HANDLE token, TOKEN_INFORMATION_CLASS class,
        if (GetTokenInformation(token, class, NULL, 0, &InfoBufferSize))
        {
                snprintf(errbuf, errsize,
-                                "could not get token information: got zero size\n");
+                        "could not get token information buffer size: got zero size\n");
                return FALSE;
        }
 
        if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
        {
                snprintf(errbuf, errsize,
-                                "could not get token information: error code %lu\n",
+                        "could not get token information buffer size: error code %lu\n",
                                 GetLastError());
                return FALSE;
        }
index 343fd19b554a630dd1c2f8560df2bc200636a839..167444591df41a4e50f70b89150bf36577af277b 100644 (file)
@@ -904,7 +904,7 @@ current_windows_user(const char **acct, const char **dom)
        if (!GetTokenInformation(token, TokenUser, NULL, 0, &retlen) && GetLastError() != 122)
        {
                fprintf(stderr,
-                               _("%s: could not get token user size: error code %lu\n"),
+                               _("%s: could not get token information buffer size: error code %lu\n"),
                                progname, GetLastError());
                exit(2);
        }
@@ -912,7 +912,7 @@ current_windows_user(const char **acct, const char **dom)
        if (!GetTokenInformation(token, TokenUser, tokenuser, retlen, &retlen))
        {
                fprintf(stderr,
-                               _("%s: could not get token user: error code %lu\n"),
+                               _("%s: could not get token information: error code %lu\n"),
                                progname, GetLastError());
                exit(2);
        }