Skip to content
Permalink
Browse files

Resolves #693

Added scripts to validate privileges before install.
  • Loading branch information...
jgebal committed Jul 9, 2018
1 parent f0c90dd commit e51c42456c592eb07d63547bbfb59a037c89c84d
Showing with 76 additions and 0 deletions.
  1. +40 −0 source/check_object_grants.sql
  2. +33 −0 source/check_sys_grants.sql
  3. +3 −0 source/install.sql
@@ -0,0 +1,40 @@
declare
c_expected_grants constant dbmsoutput_linesarray := dbmsoutput_linesarray('DBMS_LOCK','DBMS_CRYPTO');

l_missing_grants varchar2(4000);

function get_view(a_dba_view_name varchar2) return varchar2 is
l_invalid_object_name exception;
l_result varchar2(128) := lower(a_dba_view_name);
pragma exception_init(l_invalid_object_name,-44002);
begin
l_result := dbms_assert.sql_object_name(l_result);
return l_result;
exception
when l_invalid_object_name then
return replace(l_result,'dba_','all_');
end;

begin
execute immediate q'[
select listagg(' - '||object_name,CHR(10)) within group(order by object_name)
from (
select column_value as object_name
from table(:l_expected_grants)
minus
select table_name as object_name
from ]'||get_view('dba_tab_privs')||q'[
where grantee = SYS_CONTEXT('userenv','current_schema')
and owner = 'SYS')]'
into l_missing_grants using c_expected_grants;
if l_missing_grants is not null then
raise_application_error(
-20000
, 'The following object grants are missing for user "'||SYS_CONTEXT('userenv','current_schema')||'" to install utPLSQL:'||CHR(10)
||l_missing_grants||CHR(10)
||'Please read the installation documentation at http://utplsql.org/utPLSQL/'
);
end if;
end;
/

@@ -0,0 +1,33 @@
declare
c_expected_grants constant dbmsoutput_linesarray
:= dbmsoutput_linesarray(
'CREATE TYPE','CREATE VIEW','CREATE SYNONYM','CREATE SEQUENCE','CREATE PROCEDURE','CREATE TABLE'
);

l_expected_grants dbmsoutput_linesarray := c_expected_grants;
l_missing_grants varchar2(4000);
begin
if user != SYS_CONTEXT('userenv','current_schema') then
for i in 1 .. l_expected_grants.count loop
l_expected_grants(i) := replace(l_expected_grants(i),' ',' ANY ');
end loop;
end if;
select listagg(' - '||privilege,CHR(10)) within group(order by privilege)
into l_missing_grants
from (
select column_value as privilege
from table(l_expected_grants)
minus
select privilege
from user_sys_privs
);
if l_missing_grants is not null then
raise_application_error(
-20000
, 'The following privileges are required for user "'||user||'" to install into schema "'||SYS_CONTEXT('userenv','current_schema')||'"'||CHR(10)
||l_missing_grants
||'Please read the installation documentation at http://utplsql.org/utPLSQL/'
);
end if;
end;
/
@@ -29,6 +29,9 @@ whenever oserror exit failure rollback
prompt Switching current schema to &&ut3_owner
prompt &&line_separator
alter session set current_schema = &&ut3_owner;

@@check_object_grants.sql
@@check_sys_grants.sql
--set define off

--dbms_output buffer cache table

0 comments on commit e51c424

Please sign in to comment.
You can’t perform that action at this time.