通過TRIGGER 限制使用者登陸時的IP地址,應用程式.加強對ORACLE使用者的Action Trail.
CREATE OR REPLACE TRIGGER trg_work_log
AFTER LOGON ON DATABASE
declare
v_program_name varchar2(200);
v_username varchar2(100);
v_ip_address varchar2(18);
v_error varchar2(1000);
begin
--擷取當前的串連使用者資訊
select username,program,SYS_CONTEXT('USERENV','IP_ADDRESS')
into v_username,v_program_name,v_ip_address
from v$session where AUDSID = SYS_CONTEXT('USERENV', 'SESSIONID');
if upper(v_username)='WOODY' then
if UPPER(v_program_name)<>'SQLNAV4.EXE' then
if v_ip_address <> ('192.168.1.101') then
RAISE_APPLICATION_ERROR(-20003,'You are not allowed to connect to the database');
end if;
ELSE
RAISE_APPLICATION_ERROR(-20003,'不能使用SQL Nav4.exe程式登陸');
end if;
else
RAISE_APPLICATION_ERROR(-20003,'You are not allowed to connect to the database');
end if;
END;
也可以根據需要加入其他的一些限制.
非DBA許可權可以通過SYS_CONTEXT函數擷取當前V$SESSION的會話資訊.
SYS_CONTEXT函數的用法:SYS_CONTEXT('namespace', 'parameter' [, length ]);
通過以下語句可以查看V$SESSION部分資訊.
select
SYS_CONTEXT('USERENV','LANGUAGE') language,
SYS_CONTEXT('USERENV','SESSIONID') sessionid,
SYS_CONTEXT('USERENV','INSTANCE') instance,
SYS_CONTEXT('USERENV','NLS_TERRITORY') nls_territory,
SYS_CONTEXT('USERENV','NLS_CURRENCY') nls_currency,
SYS_CONTEXT('USERENV','NLS_CALENDAR') nls_calendar,
SYS_CONTEXT('USERENV','NLS_DATE_FORMAT') nls_date_format,
SYS_CONTEXT('USERENV','NLS_DATE_LANGUAGE') nls_date_language,
SYS_CONTEXT('USERENV','CURRENT_USER') current_user,
SYS_CONTEXT('USERENV','CURRENT_USERID') current_userid,
SYS_CONTEXT('USERENV','SESSION_USER') session_user,
SYS_CONTEXT('USERENV','SESSION_USERID') session_userid,
SYS_CONTEXT('USERENV','HOST') host,
SYS_CONTEXT('USERENV','OS_USER') os_user,
SYS_CONTEXT('USERENV','EXTERNAL_NAME') external_name,
SYS_CONTEXT('USERENV','IP_ADDRESS') ip_address,
SYS_CONTEXT('USERENV','NETWORK_PROTOCOL') network_protocol
from dual
非法登陸的錯誤如下: