Oracle
 sql >> Datenbank >  >> RDS >> Oracle

Netzwerkzugriff durch Zugriffssteuerungsliste (ACL) in Oracle Database 11g verweigert

Ich habe dieses Upgrade durchgeführt und es waren Stunden Arbeit. Für Version 12 muss das alles anders gemacht werden. Jeder Prozeduraufruf muss einen Commit haben. Die allgemeine Idee ist, dass Sie einen Zugriff erstellen, Details hinzufügen und Berechtigungen gewähren. Sie müssen Folgendes wissen:

  • Name und Port Ihres Mailservers
  • ob Sie einen Benutzer und ein Passwort benötigen, um darauf zuzugreifen (wahrscheinlich nicht)
  • der Benutzer, der das Mail-Paket aufruft, einfacher, wenn er auch das Mail-Paket besitzt
/*create the access permission to connect*/

BEGIN

  DBMS_NETWORK_ACL_ADMIN.create_acl (
    acl          => 'utl_smtp.xml', 
    description  => 'access to smtp email',
    principal    => 'YourUser',
    is_grant     => TRUE, 
    privilege    => 'connect',
    start_date   => SYSTIMESTAMP,
    end_date     => NULL);

  COMMIT;

END;

--add the privilege to resolve names

BEGIN

  DBMS_NETWORK_ACL_ADMIN.add_privilege (
    acl          => 'utl_smtp.xml', 
    principal    => 'YourUser',
    is_grant     => TRUE, 
    privilege    => 'resolve');

  COMMIT;

END;

--assign your mailserver

BEGIN

  DBMS_NETWORK_ACL_ADMIN.assign_acl (
    acl => 'utl_smtp.xml',
    host => 'mailserver.YourDomain.local', 
    lower_port => 25,
    upper_port => NULL); 
    commit;

END;


  BEGIN

  DBMS_NETWORK_ACL_ADMIN.assign_acl (
    acl => 'utl_smtp.xml',
    host => 'YourDBName', 
    lower_port => 25,
    upper_port => NULL); 

  COMMIT;

  END;

  --more housekeeping

  alter system set smtp_out_server = 'mailserver.YourDomain.local:25' scope = both;

 --make sure the user can access the smtp packages

 GRANT EXECUTE ON UTL_TCP TO YourUser;
 GRANT EXECUTE ON UTL_SMTP TO YourUser;
 GRANT EXECUTE ON UTL_MAIL TO YourUser;

--check your work

select * from dba_network_acls;

--verify permissions for your user

SELECT DECODE(
DBMS_NETWORK_ACL_ADMIN.CHECK_PRIVILEGE(
   'utl_smtp.xml', 'YourUser', 'resolve'),
1, 'GRANTED', 0, 'DENIED', NULL) PRIVILEGE 
FROM DUAL;

--if you have created access permissions you wish to delete
--using the information from the select use this to delete what you don't want

exec DBMS_NETWORK_ACL_ADMIN.DROP_ACL ('acl_utl_smtp.xml');

--for more troubleshooting try this barebones mail procedure, run with your user. Copied from [here][1]
DECLARE
v_From      VARCHAR2(80) := '[email protected]';
v_Recipient VARCHAR2(80) := '[email protected]';
v_Subject   VARCHAR2(80) := 'test subject';
v_Mail_Host VARCHAR2(30) := 'mail.mycompany.com';
v_Mail_Conn utl_smtp.Connection;
crlf        VARCHAR2(2)  := chr(13)||chr(10);
BEGIN
v_Mail_Conn := utl_smtp.Open_Connection(v_Mail_Host, 25);
utl_smtp.Helo(v_Mail_Conn, v_Mail_Host);
utl_smtp.Mail(v_Mail_Conn, v_From);
utl_smtp.Rcpt(v_Mail_Conn, v_Recipient);
utl_smtp.Data(v_Mail_Conn,
'Date: '   || to_char(sysdate, 'Dy, DD Mon YYYY hh24:mi:ss') || crlf ||
'From: '   || v_From || crlf ||
'Subject: '|| v_Subject || crlf ||
'To: '     || v_Recipient || crlf ||
crlf ||
'some message text'|| crlf ||   -- Message body
'more message text'|| crlf
 );
utl_smtp.Quit(v_mail_conn);
EXCEPTION
WHEN utl_smtp.Transient_Error OR utl_smtp.Permanent_Error then
raise_application_error(-20000, 'Unable to send mail', TRUE);
END;