Skip to content

Commit bc2285f

Browse files
Merge pull request #358 from diffix/cristian/bugfix
Skip non-associated databases from filtering.
2 parents 2e196eb + 9f19908 commit bc2285f

File tree

4 files changed

+23
-1
lines changed

4 files changed

+23
-1
lines changed

pg_diffix/config.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,9 @@ extern void config_init(void);
4242
*/
4343
extern void config_validate(void);
4444

45+
/*
46+
* Returns true if the extension was activated for the current database.
47+
*/
48+
extern bool is_pg_diffix_active(void);
49+
4550
#endif /* PG_DIFFIX_CONFIG_H */

src/auth.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ AccessLevel get_user_access_level(void)
7979

8080
AccessLevel get_session_access_level(void)
8181
{
82+
/* If the extension wasn't activated, force the current session into direct access mode. */
83+
if (!is_pg_diffix_active())
84+
return ACCESS_DIRECT;
85+
8286
AccessLevel user_level = get_user_access_level();
8387
if (is_higher_access_level(g_config.session_access_level, user_level))
8488
{

src/config.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "postgres.h"
22

3+
#include "commands/extension.h"
34
#include "fmgr.h"
45
#include "lib/stringinfo.h"
56
#include "miscadmin.h"
@@ -63,6 +64,13 @@ static bool session_access_level_check(int *newval, void **extra, GucSource sour
6364
if (g_initializing)
6465
return true;
6566

67+
if (!is_pg_diffix_active())
68+
{
69+
GUC_check_errmsg_string = "Invalid operation requested for the current session.";
70+
GUC_check_errdetail_string = "pg_diffix wasn't activated for the current database.";
71+
return false;
72+
}
73+
6674
AccessLevel user_level = get_user_access_level();
6775
if (is_higher_access_level(*newval, user_level))
6876
{
@@ -414,3 +422,8 @@ void config_validate(void)
414422
if (g_config.strict && g_config.outlier_count_max - g_config.outlier_count_min < MIN_STRICT_INTERVAL_SIZE)
415423
FAILWITH("pg_diffix is misconfigured: outlier_count_max - outlier_count_min < %d.", MIN_STRICT_INTERVAL_SIZE);
416424
}
425+
426+
bool is_pg_diffix_active(void)
427+
{
428+
return OidIsValid(get_extension_oid("pg_diffix", true));
429+
}

src/pg_diffix.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ void _PG_fini(void);
2222

2323
void _PG_init(void)
2424
{
25-
DEBUG_LOG("Activating Diffix extension...");
25+
DEBUG_LOG("Initializing Diffix extension...");
2626

2727
auth_init();
2828
config_init();

0 commit comments

Comments
 (0)