2009-08-19 16 views

risposta

99

Se si desidera più di sovvenzioni tavolo solo diretti (ad esempio, borse di studio tramite i ruoli, privilegi di sistema come ad esempio selezionare qualsiasi tavolo, ecc), qui ci sono alcune query aggiuntive:

privilegi di sistema per un utente:

SELECT PRIVILEGE 
    FROM sys.dba_sys_privs 
WHERE grantee = <theUser> 
UNION 
SELECT PRIVILEGE 
    FROM dba_role_privs rp JOIN role_sys_privs rsp ON (rp.granted_role = rsp.role) 
WHERE rp.grantee = <theUser> 
ORDER BY 1; 

sovvenzioni diretto alle tabelle/vista:

SELECT owner, table_name, select_priv, insert_priv, delete_priv, update_priv, references_priv, alter_priv, index_priv 
    FROM table_privileges 
WHERE grantee = <theUser> 
ORDER BY owner, table_name; 

concede indiretti alle tabelle/vista:

SELECT DISTINCT owner, table_name, PRIVILEGE 
    FROM dba_role_privs rp JOIN role_tab_privs rtp ON (rp.granted_role = rtp.role) 
WHERE rp.grantee = <theUser> 
ORDER BY owner, table_name; 
+1

Potresti non avere il diritto di vedere la tabella sys.dba_sys_privs. – Hannes

+1

assolutamente corretto. Vedi il tuo DBA. Se rifiutano, possono avere problemi di sicurezza legittimi. Vedere il contenuto di queste viste fornisce a un utente informazioni che non sarebbero in grado di avere altrimenti. – DCookie

+2

Sarebbe interessante lasciare unirsi alla tabella 'role_role_privs' e quindi' CONNECT BY PRIOR granted_role = role' per ricorrere ai privilegi di ruolo transitivi ... –

27

Supponendo che si desidera elencare borse di studio su tutti gli oggetti un particolare utente ha ricevuto :

select * from all_tab_privs_recd where grantee = 'your user' 

Questo non restituirà gli oggetti di proprietà dell'utente. Se ti servono, usa invece la vista all_tab_privs.

4
select distinct 'GRANT '||privilege||' ON '||OWNER||'.'||TABLE_NAME||' TO '||RP.GRANTEE 
from DBA_ROLE_PRIVS RP join ROLE_TAB_PRIVS RTP 
on (RP.GRANTED_ROLE = RTP.role) 
where (OWNER in ('YOUR USER') --Change User Name 
    OR RP.GRANTEE in ('YOUR USER')) --Change User Name 
and RP.GRANTEE not in ('SYS', 'SYSTEM') 
; 
+5

Alcune spiegazioni potrebbero aiutare questa risposta, per quando altre persone vengono a trovarla. –

12

Scusate ragazzi, ma scegliendo tra all_tab_privs_recd dove grantee = 'l'utente' non darà alcun output ad eccezione contributi pubblici e attuali utente concede se si esegue la selezione da un diverso (diciamo, SYS) utenti . Come dice la documentazione,

ALL_TAB_PRIVS_RECD descrive i seguenti tipi di sovvenzioni:

Object grants for which the current user is the grantee 
Object grants for which an enabled role or PUBLIC is the grantee 

Quindi, se sei un amministratore di database e si desidera elencare tutti oggetto sovvenzioni per un particolare (non SYS stesso) utente, non è possibile utilizzare quella vista di sistema.

In questo caso, è necessario eseguire una query più complessa. Qui è una presa (tracciato) dal ROSPO per selezionare tutte le sovvenzioni oggetto per un particolare utente:

select tpm.name privilege, 
     decode(mod(oa.option$,2), 1, 'YES', 'NO') grantable, 
     ue.name grantee, 
     ur.name grantor, 
     u.name owner, 
     decode(o.TYPE#, 0, 'NEXT OBJECT', 1, 'INDEX', 2, 'TABLE', 3, 'CLUSTER', 
         4, 'VIEW', 5, 'SYNONYM', 6, 'SEQUENCE', 
         7, 'PROCEDURE', 8, 'FUNCTION', 9, 'PACKAGE', 
         11, 'PACKAGE BODY', 12, 'TRIGGER', 
         13, 'TYPE', 14, 'TYPE BODY', 
         19, 'TABLE PARTITION', 20, 'INDEX PARTITION', 21, 'LOB', 
         22, 'LIBRARY', 23, 'DIRECTORY', 24, 'QUEUE', 
         28, 'JAVA SOURCE', 29, 'JAVA CLASS', 30, 'JAVA RESOURCE', 
         32, 'INDEXTYPE', 33, 'OPERATOR', 
         34, 'TABLE SUBPARTITION', 35, 'INDEX SUBPARTITION', 
         40, 'LOB PARTITION', 41, 'LOB SUBPARTITION', 
         42, 'MATERIALIZED VIEW', 
         43, 'DIMENSION', 
         44, 'CONTEXT', 46, 'RULE SET', 47, 'RESOURCE PLAN', 
         66, 'JOB', 67, 'PROGRAM', 74, 'SCHEDULE', 
         48, 'CONSUMER GROUP', 
         51, 'SUBSCRIPTION', 52, 'LOCATION', 
         55, 'XML SCHEMA', 56, 'JAVA DATA', 
         57, 'EDITION', 59, 'RULE', 
         62, 'EVALUATION CONTEXT', 
         'UNDEFINED') object_type, 
     o.name object_name, 
     '' column_name 
     from sys.objauth$ oa, sys.obj$ o, sys.user$ u, sys.user$ ur, sys.user$ ue, 
      table_privilege_map tpm 
     where oa.obj# = o.obj# 
      and oa.grantor# = ur.user# 
      and oa.grantee# = ue.user# 
      and oa.col# is null 
      and oa.privilege# = tpm.privilege 
      and u.user# = o.owner# 
      and o.TYPE# in (2, 4, 6, 9, 7, 8, 42, 23, 22, 13, 33, 32, 66, 67, 74, 57) 
    and ue.name = 'your user' 
    and bitand (o.flags, 128) = 0 
union all -- column level grants 
select tpm.name privilege, 
     decode(mod(oa.option$,2), 1, 'YES', 'NO') grantable, 
     ue.name grantee, 
     ur.name grantor, 
     u.name owner, 
     decode(o.TYPE#, 2, 'TABLE', 4, 'VIEW', 42, 'MATERIALIZED VIEW') object_type, 
     o.name object_name, 
     c.name column_name 
from sys.objauth$ oa, sys.obj$ o, sys.user$ u, sys.user$ ur, sys.user$ ue, 
    sys.col$ c, table_privilege_map tpm 
where oa.obj# = o.obj# 
    and oa.grantor# = ur.user# 
    and oa.grantee# = ue.user# 
    and oa.obj# = c.obj# 
    and oa.col# = c.col# 
    and bitand(c.property, 32) = 0 /* not hidden column */ 
    and oa.col# is not null 
    and oa.privilege# = tpm.privilege 
    and u.user# = o.owner# 
    and o.TYPE# in (2, 4, 42) 
    and ue.name = 'your user' 
    and bitand (o.flags, 128) = 0; 

Questo elenco di tutte le sovvenzioni di oggetti (comprese le sovvenzioni colonna) per l'utente (specificato). Se non si desidera concedere sovvenzioni a livello di colonna, eliminare tutta la parte della selezione che inizia con la clausola 'unione'.

UPD: Studiando la documentazione ho trovato un'altra vista che elenca tutte le sovvenzioni in modo molto più semplice:

select * from DBA_TAB_PRIVS where grantee = 'your user'; 

Tenete a mente che non c'è nessuna vista DBA_TAB_PRIVS_RECD in Oracle.

7

Il metodo più completo e affidabile che so è ancora utilizzando DBMS_METADATA:

select dbms_metadata.get_granted_ddl('SYSTEM_GRANT', :username) from dual; 
select dbms_metadata.get_granted_ddl('OBJECT_GRANT', :username) from dual; 
select dbms_metadata.get_granted_ddl('ROLE_GRANT', :username) from dual; 

risposte interessante però.

Problemi correlati