K.I*_*K.I 2 oracle plsql oracle11g ora-24247
最近,我们已经从Oracle 10g切换到11g,直到现在我才注意到我的邮件发送功能不起作用,现在我得到一个错误:
ORA-24247: network access denied by access control list (ACL)
Run Code Online (Sandbox Code Playgroud)
因此,我做了一些谷歌搜索,并发现Oracle 11g中的一项新功能现在限制了用户使用某些软件包,包括utl_smtp。因为我正在寻找一种快速的解决方案,所以我没有阅读Oracle文档,而是去寻找更简单的解决方案,并看了本教程:
https://www.pythian.com/blog/setting-up-network-acls-in-oracle-11g-for-dummies/
Run Code Online (Sandbox Code Playgroud)
我稍微弄乱了一点,但是因为我不知道更好,我想我添加了两个单独的配置.xml文件。因此,我的问题的第一部分是-如何删除它?
第二个问题是:
在向用户添加了一些授权之后,我尝试测试它是否有效,但是我很快意识到它没有作用:
SELECT DECODE(
DBMS_NETWORK_ACL_ADMIN.check_privilege('netacl.xml', 'TEST1', 'connect'),
1, 'GRANTED', 0, 'DENIED', NULL) privilege
FROM dual;
Run Code Online (Sandbox Code Playgroud)
返回值:
PRIVILE
-------
DENIED
Run Code Online (Sandbox Code Playgroud)
为什么?(已排序)
问题的第三部分-阅读后被拒绝,我尝试将其修复为:
BEGIN
DBMS_NETWORK_ACL_ADMIN.ADD_PRIVILEGE('netacl.xml' ,'TEST1', TRUE, 'connect');
END;
Run Code Online (Sandbox Code Playgroud)
但这给了我一个错误:
Ora19279 - XQuery dynamic type mismatch.....(more text meaning nothing to me).
Run Code Online (Sandbox Code Playgroud)
为什么?(我想出了,如果您授予同一用户第二次相同的权限,就会发生错误)
更新
我遵循下面kevinsky的建议答案,并且在此过程中学到了很多东西,但是我仍然有问题。我仍然收到ORA-24247:访问控制列表(ACL)拒绝了网络访问。因为我按照建议执行了所有其他操作,所以我开始认为问题可能是我添加的第一个配置文件,但现在无法删除,因为我不记得它的名称了。如果有人可以帮助我,我将非常感谢。
结果(我正在尝试一些不同的事情):
select * from dba_network_acls;
Run Code Online (Sandbox Code Playgroud)
退货
* | 25 | 25 | /sys/acls/utl_smtp.xml| ACLID...
myservername.com | 25 | 25 | /sys/acls/utl_smtp.xml| ACLID...
myDBName | 25 | 25 | /sys/acls/utl_smtp.xml| ACLID...
mailServerDomainName | 25 | 25 | /sys/acls/utl_smtp.xml| ACLID...
mailserver.myDomain.local | 25 | 25 | /sys/acls/utl_smtp.xml| ACLID...
Run Code Online (Sandbox Code Playgroud)
我做了这次升级,这是工作时间。对于版本12,所有操作都必须进行不同的重做。每个过程调用都必须具有一个提交。一般的想法是您创建访问权限,添加详细信息,授予特权。您必须知道:
/*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) := 'oracle@mycompany.com';
v_Recipient VARCHAR2(80) := 'test@mycompany.com';
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;
Run Code Online (Sandbox Code Playgroud)