-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsdsec_sysobj.sql
119 lines (109 loc) · 4.25 KB
/
sdsec_sysobj.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
--------------------------------------------------------------------------------
-- OraDBA - Oracle Database Infrastructur and Security, 5630 Muri, Switzerland
--------------------------------------------------------------------------------
-- Name......: sdsec_sysobj.sql
-- Author....: Stefan Oehrli (oes) [email protected]
-- Editor....: Stefan Oehrli
-- Date......: 2023.11.29
-- Revision..:
-- Purpose...: Show respectively create a list of granted SYS object privileges
-- Notes.....:
-- Reference.: SYS (or grant manually to a DBA)
-- License...: Apache License Version 2.0, January 2004 as shown
-- at http://www.apache.org/licenses/
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- assign default value for parameter if argument 1 is empty
SET FEEDBACK OFF
SET VERIFY OFF
COLUMN db_name NEW_VALUE db_name NOPRINT
SELECT upper(name) db_name FROM v$database;
--------------------------------------------------------------------------------
-- Define SQLPlus configuration
SET SERVEROUTPUT ON
SET LINESIZE 160 PAGESIZE 200
SPOOL sdsec_sysobj_&db_name..sql
--------------------------------------------------------------------------------
-- create a temporary type
CREATE OR REPLACE TYPE table_varchar AS
TABLE OF VARCHAR2(128)
/
--------------------------------------------------------------------------------
-- Anonymous PL/SQL Block to get system privileges
DECLARE
-- list of known user to be excluded
excluded_users table_varchar := table_varchar('ZZ_SPOTLIGHT','PUBLIC');
TYPE t_dba_tab_privs IS
TABLE OF dba_tab_privs%rowtype;
r_dba_tab_privs t_dba_tab_privs;
v_grantable VARCHAR2(128) := '';
v_common VARCHAR2(128) := '';
v_container INT;
BEGIN
-- check if we are in a multitenant DATABASE
SELECT sys_context('userenv','con_id') INTO v_container FROM dual;
-- store the information from dba_tab_privs
SELECT
*
BULK COLLECT
INTO r_dba_tab_privs
FROM
dba_tab_privs
WHERE
owner = 'SYS' AND
grantee NOT IN ( 'PUBLIC' ) AND
grantee NOT IN (
SELECT
username
FROM
dba_users
WHERE
oracle_maintained='Y'
OR username IN ( SELECT * FROM TABLE ( excluded_users ) ) UNION
SELECT
role
FROM
dba_roles
WHERE
oracle_maintained='Y'
);
-- check if we do have an empty collection
IF r_dba_tab_privs IS NOT EMPTY THEN
dbms_output.put_line('REM SYS object grants found');
-- loop through the collection to create the grant statements
FOR i IN 1..r_dba_tab_privs.last LOOP
-- set the grantable option depending on the current setting
IF r_dba_tab_privs(i).grantable = 'YES' THEN
v_grantable := ' WITH GRANT OPTION';
ELSE
v_grantable := '';
END IF;
-- set the container option depending on the current setting
IF v_container = 1 AND r_dba_tab_privs(i).common = 'YES' THEN
v_common := ' CONTAINER=ALL';
ELSE
v_common := '';
END IF;
dbms_output.put_line('GRANT '
|| r_dba_tab_privs(i).privilege
|| ' ON '
|| sys.dbms_assert.enquote_name(r_dba_tab_privs(i).table_name)
|| ' TO '
|| sys.dbms_assert.enquote_name(r_dba_tab_privs(i).grantee)
|| v_grantable
|| v_common
|| ';');
END LOOP;
ELSE
dbms_output.put_line('REM no SYS object grants found');
END IF;
END;
/
--------------------------------------------------------------------------------
-- drop temporary created type
DROP TYPE table_varchar
/
SPOOL off
SET FEEDBACK ON
SET VERIFY ON
-- EOF -------------------------------------------------------------------------