Oracle 数据库 11g 中的访问控制列表 (ACL) 拒绝了网络访问
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37817384/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Network access denied by access control list (ACL) in Oracle Database 11g
提问by K.I
Recently we have switched from Oracle 10g to 11g, and only now I noticed that my mailing function does not work, I now get an error:
最近我们从 Oracle 10g 切换到 11g,直到现在我才发现我的邮件功能不起作用,我现在收到一个错误:
ORA-24247: network access denied by access control list (ACL)
So I did a bit of googling and was able to figure out that a new feature in Oracle 11g is now restricting users from using certain packages including utl_smtp. Because I am looking for a quick solution I did not read Oracle documentation, but instead I went looking for easier solutions and came across this tutorial:
因此,我进行了一些谷歌搜索,发现 Oracle 11g 中的一个新特性现在限制用户使用某些包,包括 utl_smtp。因为我正在寻找一个快速的解决方案,所以我没有阅读 Oracle 文档,而是寻找更简单的解决方案并遇到了本教程:
https://www.pythian.com/blog/setting-up-network-acls-in-oracle-11g-for-dummies/
I messed around with it a little bit, but because I did not know any better I think I added two seperate configuration .xml files. So first part of my question is - HOW DO I REMOVE IT?
我把它弄乱了一点,但因为我不知道更好,我想我添加了两个单独的配置 .xml 文件。所以我的问题的第一部分是 - 我如何删除它?
Second question is:
第二个问题是:
After adding some grants to my user I try to test to see if it worked, but I soon realised it did not:
在向我的用户添加一些赠款后,我尝试测试它是否有效,但我很快意识到它没有:
SELECT DECODE(
DBMS_NETWORK_ACL_ADMIN.check_privilege('netacl.xml', 'TEST1', 'connect'),
1, 'GRANTED', 0, 'DENIED', NULL) privilege
FROM dual;
Returns:
返回:
PRIVILE
-------
DENIED
WHY?(THIS HAS BEEN SORTED)
为什么?(已排序)
Third part of the question - after reading it was denied I try to fix it like:
问题的第三部分 - 阅读后被拒绝,我尝试修复它:
BEGIN
DBMS_NETWORK_ACL_ADMIN.ADD_PRIVILEGE('netacl.xml' ,'TEST1', TRUE, 'connect');
END;
But that gives me an error:
但这给了我一个错误:
Ora19279 - XQuery dynamic type mismatch.....(more text meaning nothing to me).
WHY?(I FIGURED OUT, THAT ERROR HAPPENS WHEN YOU GRANT SAME PERMISSION TO SAME USER SECOND TIME)
为什么?(我发现,当您第二次向同一用户授予相同权限时会发生该错误)
UPDATE
更新
I have followed the suggested answer by kevinsky below and have learned quite a bit in the process, however I still have a problem. I still get the ORA-24247: network access denied by access control list (ACL). Because I did everything else as suggested, I am starting to think that the problem could be that first configuration file which I added, but cannot remove now because I cannot remember its name. If anyone can help me I would appreciate that very much.
我遵循了下面 kevinsky 的建议答案,并在此过程中学到了很多东西,但是我仍然遇到问题。我仍然收到 ORA-24247: network access denied by access control list (ACL)。因为我按照建议做了所有其他事情,所以我开始认为问题可能是我添加的第一个配置文件,但现在无法删除,因为我不记得它的名字。如果有人可以帮助我,我将不胜感激。
RESULTS OF(I was trying out a few different things so):
结果(我尝试了一些不同的东西):
select * from dba_network_acls;
Returns
退货
* | 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...
回答by kevinsky
I did this upgrade and it was hours of work. It all has to be redone differently for version 12. Every procedure call must have a commit. The general idea is that you create an access,add details, grant privileges. You must know:
我做了这个升级,这是几个小时的工作。对于版本 12,这一切都必须以不同的方式重做。每个过程调用都必须有一个提交。总体思路是创建访问权限、添加详细信息、授予权限。你必须知道:
- your mailserver name and port
- whether you need a user and password to access it (probably not)
- the user who will be calling the mail package, easier if they own the mail package too
- 您的邮件服务器名称和端口
- 您是否需要用户和密码才能访问它(可能不需要)
- 将调用邮件包的用户,如果他们也拥有邮件包,则更容易
/*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;