* Execute the appropriate script file for installing or updating the extension * * If from_version isn't NULL, it's an update * * If stmt isn't NULL, it means that there already has been a Gang of type GANGTYPE_PRIMARY_WRITER, * and the BEGIN phase of stmt has been executed in every QE in this Gang. */
| 868 | * and the BEGIN phase of stmt has been executed in every QE in this Gang. |
| 869 | */ |
| 870 | static void |
| 871 | execute_extension_script(Node *stmt, |
| 872 | Oid extensionOid, ExtensionControlFile *control, |
| 873 | const char *from_version, |
| 874 | const char *version, |
| 875 | List *requiredSchemas, |
| 876 | const char *schemaName, Oid schemaOid) |
| 877 | { |
| 878 | bool switch_to_superuser = false; |
| 879 | char *filename; |
| 880 | Oid save_userid = 0; |
| 881 | int save_sec_context = 0; |
| 882 | int save_nestlevel; |
| 883 | StringInfoData pathbuf; |
| 884 | ListCell *lc; |
| 885 | StringInfoData search_path_buffer; |
| 886 | |
| 887 | AssertState(Gp_role != GP_ROLE_EXECUTE); |
| 888 | AssertImply(Gp_role == GP_ROLE_DISPATCH, stmt != NULL && |
| 889 | (nodeTag(stmt) == T_CreateExtensionStmt || nodeTag(stmt) == T_AlterExtensionStmt) && |
| 890 | is_begin_state(stmt)); |
| 891 | |
| 892 | /* |
| 893 | * Enforce superuser-ness if appropriate. We postpone these checks until |
| 894 | * here so that the control flags are correctly associated with the right |
| 895 | * script(s) if they happen to be set in secondary control files. |
| 896 | */ |
| 897 | if (control->superuser && !superuser()) |
| 898 | { |
| 899 | if (extension_is_trusted(control)) |
| 900 | switch_to_superuser = true; |
| 901 | else if (from_version == NULL) |
| 902 | ereport(ERROR, |
| 903 | (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), |
| 904 | errmsg("permission denied to create extension \"%s\"", |
| 905 | control->name), |
| 906 | control->trusted |
| 907 | ? errhint("Must have CREATE privilege on current database to create this extension.") |
| 908 | : errhint("Must be superuser to create this extension."))); |
| 909 | else |
| 910 | ereport(ERROR, |
| 911 | (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), |
| 912 | errmsg("permission denied to update extension \"%s\"", |
| 913 | control->name), |
| 914 | control->trusted |
| 915 | ? errhint("Must have CREATE privilege on current database to update this extension.") |
| 916 | : errhint("Must be superuser to update this extension."))); |
| 917 | } |
| 918 | |
| 919 | filename = get_extension_script_filename(control, from_version, version); |
| 920 | |
| 921 | /* |
| 922 | * If installing a trusted extension on behalf of a non-superuser, become |
| 923 | * the bootstrap superuser. (This switch will be cleaned up automatically |
| 924 | * if the transaction aborts, as will the GUC changes below.) |
| 925 | */ |
| 926 | if (switch_to_superuser) |
| 927 | { |
no test coverage detected