From 4e7367844e65a89502d0a4fc6f9352d36e52e634 Mon Sep 17 00:00:00 2001 From: Yacine31 Date: Tue, 13 Feb 2024 19:00:16 +0100 Subject: [PATCH] update ddl user --- get_grant_and_priv.sql | 49 ------------------------------------------ get_users_ddl.sql | 28 ++++++++++++------------ 2 files changed, 14 insertions(+), 63 deletions(-) delete mode 100644 get_grant_and_priv.sql diff --git a/get_grant_and_priv.sql b/get_grant_and_priv.sql deleted file mode 100644 index 6c0ba4f..0000000 --- a/get_grant_and_priv.sql +++ /dev/null @@ -1,49 +0,0 @@ --- --- Le script prend en parametre un compte utilisateur --- ensuite il retourne les requetes pour creer les grants associe a ce compte --- un fichier grant_USER.lst est généré dans le répertoire courant --- -SET PAGES 999 HEAD OFF FEEDBACK OFF -ACCEPT v_user CHAR PROMPT 'compte utilisateur pour lequel on va extraire les GRANTS : ' -set verify off - -SPOOL grant_&v_user -SELECT '-- Les roles pour le compte &v_user :' FROM DUAL; -SELECT DISTINCT 'CREATE ROLE '||GRANTED_ROLE||';' FROM DBA_ROLE_PRIVS WHERE GRANTEE=upper('&v_user'); - -SELECT '-- Les GRANTs depuis DBA_ROLE_PRIVS pour le compte &v_user :' FROM DUAL; -SELECT DISTINCT 'GRANT '||GRANTED_ROLE||' TO '||GRANTEE|| CASE WHEN ADMIN_OPTION='YES' THEN ' WITH ADMIN OPTION;' ELSE ';' END "Granted Roles" FROM DBA_ROLE_PRIVS WHERE GRANTEE=upper('&v_user') ORDER BY 1; - -SELECT '-- Les GRANTs depuis DBA_SYS_PRIVS pour le compte &v_user :' FROM DUAL; -SELECT 'GRANT '||PRIVILEGE||' TO '||GRANTEE|| case when ADMIN_OPTION='YES' THEN ' WITH ADMIN OPTION;' ELSE ';' END "Granted System Privileges" FROM DBA_SYS_PRIVS WHERE GRANTEE=upper('&v_user'); - -SELECT '-- Les GRANTs depuis DBA_TAB_PRIVS pour le compte &v_user :' FROM DUAL; -SELECT DISTINCT - 'GRANT ' - || privilege - || ' ON ' - || - CASE - WHEN type = 'DIRECTORY' THEN - 'DIRECTORY ' - END - || owner - || '.' - || table_name - || ' TO ' - || grantee - || - CASE - WHEN grantable = 'YES' THEN - ' WITH GRANT OPTION;' - ELSE - ';' - END - "Granted Object Privileges" -FROM - dba_tab_privs -WHERE - grantee = upper('&v_user'); -SPOOL OFF -EXIT - diff --git a/get_users_ddl.sql b/get_users_ddl.sql index 7ccc019..31be1a5 100644 --- a/get_users_ddl.sql +++ b/get_users_ddl.sql @@ -11,56 +11,56 @@ set long 2000000000 select (case when ((select count(*) from dba_users -where username = '&&User_in_Uppercase' and profile <> 'DEFAULT') > 0) -then chr(10)||' -- Note: Profile'||(select dbms_metadata.get_ddl('PROFILE', u.profile) AS ddl from dba_users u where u.username = '&User_in_Uppercase') +where username = UPPER('&&User_in_Uppercase') and profile <> 'DEFAULT') > 0) +then chr(10)||' -- Note: Profile'||(select dbms_metadata.get_ddl('PROFILE', u.profile) AS ddl from dba_users u where u.username = UPPER('&User_in_Uppercase')) else to_clob (chr(10)||' -- Note: Default profile, no need to create!') end ) from dual UNION ALL select (case when ((select count(*) from dba_users -where username = '&User_in_Uppercase') > 0) -then ' -- Note: Create user statement'||dbms_metadata.get_ddl ('USER', '&User_in_Uppercase') +where username = UPPER('&User_in_Uppercase')) > 0) +then ' -- Note: Create user statement'||dbms_metadata.get_ddl ('USER', UPPER('&User_in_Uppercase')) else to_clob (chr(10)||' -- Note: User not found!') end ) Extracted_DDL from dual UNION ALL select (case when ((select count(*) from dba_ts_quotas -where username = '&User_in_Uppercase') > 0) -then ' -- Note: TBS quota'||dbms_metadata.get_granted_ddl( 'TABLESPACE_QUOTA', '&User_in_Uppercase') +where username = UPPER('&User_in_Uppercase')) > 0) +then ' -- Note: TBS quota'||dbms_metadata.get_granted_ddl( 'TABLESPACE_QUOTA', UPPER('&User_in_Uppercase')) else to_clob (chr(10)||' -- Note: No TS Quotas found!') end ) from dual UNION ALL select (case when ((select count(*) from dba_role_privs -where grantee = '&User_in_Uppercase') > 0) -then ' -- Note: Roles'||dbms_metadata.get_granted_ddl ('ROLE_GRANT', '&User_in_Uppercase') +where grantee = UPPER('&User_in_Uppercase')) > 0) +then ' -- Note: Roles'||dbms_metadata.get_granted_ddl ('ROLE_GRANT', UPPER('&User_in_Uppercase')) else to_clob (chr(10)||' -- Note: No granted Roles found!') end ) from dual UNION ALL select (case when ((select count(*) from V$PWFILE_USERS -where username = '&User_in_Uppercase' and SYSDBA='TRUE') > 0) -then ' -- Note: sysdba'||chr(10)||to_clob (' GRANT SYSDBA TO '||'"'||'&User_in_Uppercase'||'"'||';') +where username = UPPER('&User_in_Uppercase') and SYSDBA='TRUE') > 0) +then ' -- Note: sysdba'||chr(10)||to_clob (' GRANT SYSDBA TO '||'"'||UPPER('&User_in_Uppercase')||'"'||';') else to_clob (chr(10)||' -- Note: No sysdba administrative Privilege found!') end ) from dual UNION ALL select (case when ((select count(*) from dba_sys_privs -where grantee = '&User_in_Uppercase') > 0) -then ' -- Note: System Privileges'||dbms_metadata.get_granted_ddl ('SYSTEM_GRANT', '&User_in_Uppercase') +where grantee = UPPER('&User_in_Uppercase')) > 0) +then ' -- Note: System Privileges'||dbms_metadata.get_granted_ddl ('SYSTEM_GRANT', UPPER('&User_in_Uppercase')) else to_clob (chr(10)||' -- Note: No System Privileges found!') end ) from dual UNION ALL select (case when ((select count(*) from dba_tab_privs -where grantee = '&User_in_Uppercase') > 0) -then ' -- Note: Object Privileges'||dbms_metadata.get_granted_ddl ('OBJECT_GRANT', '&User_in_Uppercase') +where grantee = UPPER('&User_in_Uppercase')) > 0) +then ' -- Note: Object Privileges'||dbms_metadata.get_granted_ddl ('OBJECT_GRANT', UPPER('&User_in_Uppercase')) else to_clob (chr(10)||' -- Note: No Object Privileges found!') end ) from dual / \ No newline at end of file