Permalink
Browse files

Merge branch 'master' of github.com:dimitri/pgextwlist

  • Loading branch information...
dimitri committed Jan 17, 2012
2 parents 2bcfbf2 + aec8d3c commit 8195e02d20eb14157e2f97919d8b242b3367e72a
Showing with 24 additions and 21 deletions.
  1. +24 −21 pgextwlist.c
View
@@ -156,16 +156,30 @@ extwlist_ProcessUtility(Node *parsetree, const char *queryString,
if (whitelisted)
{
- bool is_superuser = superuser();
+ const bool already_superuser = superuser();
- if (!is_superuser)
+ if (!already_superuser)
UpdateCurrentRoleToSuperuser(true);
- call_ProcessUtility(parsetree, queryString, params,
- isTopLevel, dest, completionTag);
+ /*
+ * Be extra careful here, we need to drop off superuser privileges
+ * in case of either success or failure.
+ */
+ PG_TRY();
+ {
+ call_ProcessUtility(parsetree, queryString, params,
+ isTopLevel, dest, completionTag);
+ }
+ PG_CATCH();
+ {
+ if (!already_superuser)
+ UpdateCurrentRoleToSuperuser(false);
+ PG_RE_THROW();
+ }
+ PG_END_TRY();
/* Don't forget to get back to what it was before */
- if (!is_superuser)
+ if (!already_superuser)
UpdateCurrentRoleToSuperuser(false);
}
else
@@ -192,20 +206,12 @@ call_ProcessUtility(Node *parsetree, const char *queryString,
ParamListInfo params, bool isTopLevel,
DestReceiver *dest, char *completionTag)
{
- PG_TRY();
- {
- if (prev_ProcessUtility)
- prev_ProcessUtility(parsetree, queryString, params,
+ if (prev_ProcessUtility)
+ prev_ProcessUtility(parsetree, queryString, params,
+ isTopLevel, dest, completionTag);
+ else
+ standard_ProcessUtility(parsetree, queryString, params,
isTopLevel, dest, completionTag);
- else
- standard_ProcessUtility(parsetree, queryString, params,
- isTopLevel, dest, completionTag);
- }
- PG_CATCH();
- {
- PG_RE_THROW();
- }
- PG_END_TRY();
}
/*
@@ -225,7 +231,6 @@ UpdateCurrentRoleToSuperuser(bool issuper)
HeapTuple tuple,
new_tuple;
char *role = GetUserNameFromId(GetUserId());
- Oid roleid;
/*
* Scan the pg_authid relation to be certain the user exists.
@@ -239,8 +244,6 @@ UpdateCurrentRoleToSuperuser(bool issuper)
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("role \"%s\" does not exist", role)));
- roleid = HeapTupleGetOid(tuple);
-
/*
* Build an updated tuple, perusing the information just obtained
*/

0 comments on commit 8195e02

Please sign in to comment.