9
9
*
10
10
*
11
11
* IDENTIFICATION
12
- * $Header: /cvsroot/pgsql/src/backend/commands/variable.c,v 1.72 2002/12/05 04:04:42 momjian Exp $
12
+ * $Header: /cvsroot/pgsql/src/backend/commands/variable.c,v 1.73 2003/02/01 18:31:28 tgl Exp $
13
13
*
14
14
*-------------------------------------------------------------------------
15
15
*/
@@ -519,25 +519,36 @@ show_server_encoding(void)
519
519
/*
520
520
* SET SESSION AUTHORIZATION
521
521
*
522
- * Note: when resetting session auth after an error, we can't expect to do
523
- * catalog lookups. Hence, the stored form of the value is always a numeric
524
- * userid that can be re-used directly.
522
+ * When resetting session auth after an error, we can't expect to do catalog
523
+ * lookups. Hence, the stored form of the value must provide a numeric userid
524
+ * that can be re-used directly. We store the string in the form of
525
+ * NAMEDATALEN 'x's followed by the numeric userid --- this cannot conflict
526
+ * with any valid user name, because of the NAMEDATALEN limit on names.
525
527
*/
526
528
const char *
527
529
assign_session_authorization (const char * value , bool doit , bool interactive )
528
530
{
529
- AclId usesysid ;
530
- char * endptr ;
531
+ AclId usesysid = 0 ;
531
532
char * result ;
532
533
533
- usesysid = (Oid ) strtoul (value , & endptr , 10 );
534
-
535
- if (endptr != value && * endptr == '\0' && OidIsValid (usesysid ))
534
+ if (strspn (value , "x" ) == NAMEDATALEN )
536
535
{
537
- /* use the numeric user ID */
536
+ /* might be a saved numeric userid */
537
+ char * endptr ;
538
+
539
+ usesysid = (AclId ) strtoul (value + NAMEDATALEN , & endptr , 10 );
540
+
541
+ if (endptr != value + NAMEDATALEN && * endptr == '\0' )
542
+ {
543
+ /* syntactically valid, so use the numeric user ID */
544
+ }
545
+ else
546
+ usesysid = 0 ;
538
547
}
539
- else
548
+
549
+ if (usesysid == 0 )
540
550
{
551
+ /* not a saved ID, so look it up */
541
552
HeapTuple userTup ;
542
553
543
554
userTup = SearchSysCache (SHADOWNAME ,
@@ -558,17 +569,23 @@ assign_session_authorization(const char *value, bool doit, bool interactive)
558
569
if (doit )
559
570
SetSessionAuthorization (usesysid );
560
571
561
- result = (char * ) malloc (32 );
572
+ result = (char * ) malloc (NAMEDATALEN + 32 );
562
573
if (!result )
563
574
return NULL ;
564
575
565
- snprintf (result , 32 , "%lu" , (unsigned long ) usesysid );
576
+ memset (result , 'x' , NAMEDATALEN );
577
+
578
+ snprintf (result + NAMEDATALEN , 32 , "%lu" , (unsigned long ) usesysid );
566
579
567
580
return result ;
568
581
}
569
582
570
583
const char *
571
584
show_session_authorization (void )
572
585
{
586
+ /*
587
+ * We can't use the stored string; see comments for
588
+ * assign_session_authorization
589
+ */
573
590
return GetUserNameFromId (GetSessionUserId ());
574
591
}
0 commit comments