SQL> connect sys/aaa as sysdba
ERROR:
ORA-01017: 用户名/口令无效; 登录被拒绝
SQL> connect aaa/bbb as sysdba
ERROR:
ORA-01031: 权限不足
SQL> connect sys/system as sysdba
已连接。
SQL>
或者可以把oracle的安装用户从组ora_dba中删除掉,当然也可以直接把ora_dba这个组也删除,都可以屏蔽os功能。在unix/linux下也可以在文件sqlnet.ora中增加SQLNET.AUTHENTICATION_SERVICES=(none)以及删除dba(groupdel dba)组或者把oracle用户从dba组中删除都可以屏蔽os认证。利用这两种方法屏蔽os功能似乎总有些让人不放心,或者说不能让人完全信服,因为毕竟系统管理员还是可以创建ora_dba or dba组以及修改sqlnet.ora文件,如何彻底屏蔽os功能?让它"永世不得翻身"呢?我没有这方面的经验,大家可以补充!
SQL> grant sysdba, sysoper to test;
grant sysdba, sysoper to test
*
第 1 行出现错误:
ORA-01109: 数据库未打开
到底有几个用户被授予了sysdba或者sysoper权限,可以通过查询如下v$pwfile_users获得,v$pwfile_users的信息就是源于口令文件的(This view lists users who have been granted SYSDBA and SYSOPER privileges as derived from the password file.)
SQL> select * from v$pwfile_users;
USERNAME SYSDB SYSOP
------------------------------ ----- -----
SYS TRUE TRUE
TEST TRUE FALSE
下面看一个简单的测试:
SQL> declare
2 v_string varchar2(100);
3 begin
4 for i in 1..100 loop
5 v_string := 'create user test'||i||' identified by test'||i;
6 execute immediate v_string ;
7 end loop;
8 end;
9 /
PL/SQL 过程已成功完成。
SQL> select count(*) from dba_users where username like '%TEST%';
COUNT(*)
----------
101
这里之所以是101,是因为之前已经创建过test用户
SQL> declare
2 v_string varchar2(100);
3 begin
4 for i in 1..100 loop
5 v_string := 'grant sysdba to test'||i;
6 execute immediate v_string ;
7 end loop ;
8 end ;
9 /
declare
*
第 1 行出现错误:
ORA-01996: GRANT 失败: 口令文件 '' 已满
ORA-06512: 在 line 6
可以清楚的看到v$pwfile_users里面并不是创建口令文件时指定的entries=5而是9条记录,意味着9个用户的口令占用了一个os block,其实也可能是多个os block,总之这些block都是满的,但是观察口令文件,还是占了2k,这是我解释不清的地方。通过os命令发现;每个簇字节数4096;这里其实就是os block 大小实际上是4k,但是口令文件占用了2k,根本没有用满一个os block,不知道何故,也是我的疑惑 (
This parameter specifies the number of entries that you require the password file to accept. This number corresponds to the number of distinct users allowed to connect to the database as SYSDBA or SYSOPER. The actual number of allowable entries can be higher than the number of users, because the ORAPWD utility continues to assign password entries until an operating system block is filled. For example, if your operating system block size is 512 bytes, it holds four password entries. The number of password entries allocated is always a multiple of four.
)
SQL> show parameter remote_log
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
remote_login_passwordfile string SHARED
SQL> alter user sys identified by manager;
alter user sys identified by manager
*
第 1 行出现错误:
ORA-28046: 不允许更改 SYS 口令
,另外凡是修改具有sysdba or sysoper权限的用户,如果通过alter user来修改口令,那么同时修改了口令文件和数据库中的口令。
简单的测试如下:
SQL> create user test11 identified by test11;
用户已创建。
SQL> grant connect , alter user to test11;
授权成功。
SQL> connect test11/test11
已连接。
SQL> CONNECT / as sysdba
已连接。
SQL> grant select on dba_users to test11;
授权成功。
SQL> connect test11/test11
已连接。
SQL> col username format a10
SQL> col password format a30
SQL> select password , username from dba_users where username ='SYS';
PASSWORD USERNAME
------------------------------ ----------
75800913E1B66343 SYS
SQL> show user
USER 为 TEST11;
SQL> alter user sys identified by manager;
用户已更改。
SQL> select password , username from dba_users where username ='SYS';
PASSWORD USERNAME
------------------------------ ----------
5638228DAF52805F SYS
SQL>
remote_login_passwordfile=shared时,也不能把sysdba or sysoper授予普通用户!
SQL> grant sysdba to test;
grant sysdba to test
*
第 1 行出现错误:
ORA-01999: 口令文件不能在 SHARED 模式下更新
SQL> grant sysoper to test;
grant sysoper to test
*
第 1 行出现错误:
ORA-01999: 口令文件不能在 SHARED 模式下更新
通过上面两部分内容的解释,了解了os认证和口令文件之后,如果为了安全不想让用户以sysdba or sysoper权限连接数据库,可以通过上面的方法屏蔽os认证的同时静止使用口令文件。
3、sysdba 和 sysoper
很多人可能不了解sysdba and sysoper到底是什么,其实他们是oracle的system privilege,通过查询系统权限表system_privilege_map可以清楚的知道:
SQL> select name from system_privilege_map where name like 'SYS%';
NAME
----------------------------------------------------------------------------
SYSOPER
SYSDBA
只不过这两个权限就是以这种方式发挥作用的!
两种权限的比较在oracle doc上给出了明确的交代:
The following operati** are authorized by the SYSDBA and SYSOPER system privileges:
System Privilege Operati** Authorized
SYSDBA Perform STARTUP and SHUTDOWN operati**
ALTER DATABASE: open, mount, back up, or change character set
CREATE DATABASE
DROP DATABASE
CREATE SPFILE
ALTER DATABASE ARCHIVELOG
ALTER DATABASE RECOVER
Includes the RESTRICTED SESSION privilege
Effectively, this system privilege allows a user to connect as user SYS.
SYSOPER Perform STARTUP and SHUTDOWN operati**
CREATE SPFILE
ALTER DATABASE OPEN/MOUNT/BACKUP
ALTER DATABASE ARCHIVELOG
ALTER DATABASE RECOVER (Complete recovery only. Any form of incomplete recovery, such as UNTIL TIME|CHANGE|CANCEL|CONTROLFILE requires connecting as SYSDBA.)
Includes the RESTRICTED SESSION privilege
This privilege allows a user to perform basic operational tasks, but without the ability to look at user data.
[oracle@xys oracle]$ sqlplus /nolog
SQL*Plus: Release 11.1.0.6.0 - Production on Fri Dec 7 23:52:49 2007
Copyright (c) 1982, 2007, Oracle. All rights reserved.
SQL> connect / as sysoper
Connected to an idle instance.
SQL> create user wch identified externally;
用户已创建。
SQL> grant create session to wch;
授权成功。
SQL> show parameter auth
NAME TYPE VALUE
------------------------------------ ----------- -------------------------
os_authent_prefix string OPS$
remote_os_authent boolean FALSE
SQL> col username format a10
SQL> col password format a30
SQL> select username , password from dba_users where username='WCH';
USERNAME PASSWORD
---------- ------------------------------
WCH EXTERNAL