Skip to content

Commit eb9e05f

Browse files
committed
fix: run custom scripts on non-privileged extensions
1 parent 18718e5 commit eb9e05f

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

src/supautils.c

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -448,29 +448,36 @@ static void supautils_hook(PROCESS_UTILITY_PARAMS) {
448448

449449
constrain_extension(stmt->extname, cexts, total_cexts);
450450

451-
if (is_extension_privileged(stmt->extname, privileged_extensions)) {
452-
bool already_switched_to_superuser = false;
451+
bool already_switched_to_superuser = false;
453452

454-
switch_to_superuser(supautils_superuser, &already_switched_to_superuser);
453+
switch_to_superuser(supautils_superuser, &already_switched_to_superuser);
455454

456-
run_global_before_create_script(stmt->extname, stmt->options, privileged_extensions_custom_scripts_path);
455+
run_global_before_create_script(stmt->extname, stmt->options, privileged_extensions_custom_scripts_path);
457456

458-
run_ext_before_create_script(stmt->extname, stmt->options, privileged_extensions_custom_scripts_path);
457+
run_ext_before_create_script(stmt->extname, stmt->options, privileged_extensions_custom_scripts_path);
459458

460-
override_create_ext_statement(stmt, total_epos, epos);
459+
override_create_ext_statement(stmt, total_epos, epos);
461460

462-
run_process_utility_hook(prev_hook);
461+
if (is_extension_privileged(stmt->extname, privileged_extensions)) {
462+
run_process_utility_hook(prev_hook);
463+
} else {
464+
if (!already_switched_to_superuser) {
465+
switch_to_original_role();
466+
already_switched_to_superuser = false;
467+
}
463468

464-
run_ext_after_create_script(stmt->extname, stmt->options, privileged_extensions_custom_scripts_path);
469+
run_process_utility_hook(prev_hook);
465470

466-
if (!already_switched_to_superuser) {
467-
switch_to_original_role();
468-
}
471+
switch_to_superuser(supautils_superuser, &already_switched_to_superuser);
472+
}
469473

470-
return;
474+
run_ext_after_create_script(stmt->extname, stmt->options, privileged_extensions_custom_scripts_path);
475+
476+
if (!already_switched_to_superuser) {
477+
switch_to_original_role();
471478
}
472479

473-
break;
480+
return;
474481
}
475482

476483
/*

0 commit comments

Comments
 (0)