壹佰网|ERP100 - 企业信息化知识门户

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8084|回复: 5

ORACLE用户审计功能

[复制链接]
发表于 2006/7/3 16:51:49 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。如果您注册时有任何问题请联系客服QQ: 83569622  。

您需要 登录 才可以下载或查看,没有帐号?注册

x


  1. create table login_log(
  2.     session_id int not null,
  3.     login_on_time date,
  4.     login_off_time date,
  5.     user_in_db varchar2(30),
  6.     machine varchar2(20),
  7.     ip_address varchar2(20),
  8.     run_program varchar2(20)
  9. );

  10. create table allow_user(
  11.     ip_address  varchar2(20),
  12.     login_user_name  nvarchar2(20)
  13. );

  14. create or replace trigger login_on_info
  15. after logon on database
  16. Begin
  17.     insert into login_log(session_id,login_on_time,login_off_time,user_in_db,machine,ip_address,run_program)
  18.     select AUDSID,sysdate,null,sys.login_user,machine,SYS_CONTEXT('USERENV','IP_ADDRESS'),program
  19.     from v$session where AUDSID=USERENV('SESSIONID');
  20. END;

  21. create or replace trigger login_off_info
  22. before logoff on database
  23. Begin
  24.     update login_log set login_off_time=sysdate where session_id=USERENV('SESSIONID');
  25.     exception when others then
  26.         null;
  27. END;
  28. /

复制代码
 楼主| 发表于 2006/7/3 16:56:14 | 显示全部楼层

  1.      Auditing LOGOFF and LOGON

  2.          This tip comes from Milind Deobhankar, Oracle Software Engineer in
  3.       Ahmedabad, Gujarat, India.
  4.       Auditing the database to find out who is logged on, who has logged off,
  5.       from which machines users are logged in, and from which program users are
  6.       connected can be a very cumbersome task. Here is a procedure that will
  7.       help the DBA to trace who has logged on, logged off, and at what times.
  8.       First log on as the sys user (as this task is of the database
  9.       administrator).
  10.       Create the table in which all information will be stored.
  11.       create table
  12.       SYSTEM.login_info
  13.       ( logindatetime date,
  14.       LogoffDateTime Date,
  15.       LoggedUser Varchar2(30),
  16.       SESSIONID Number,
  17.       TERMINAL varchar2(20),
  18.       PROGRAM varchar2(20)
  19.       );
  20.       /
  21.       Now create the trigger on the logon event so that whenever anybody logs
  22.       on, the trigger will fire.
  23.       CREATE OR REPLACE TRIGGER logon_audit AFTER LOGON ON DATABASE
  24.       BEGIN
  25.       insert into system.login_info
  26.       values(sysdate,null,user,sys_context('USERENV','SESSIONID'),sys_context(
  27.       'USERENV','TERMINAL'),null);
  28.       END;
  29.       /
  30.       Now create the trigger on the logoff event so that whenever anybody logs
  31.       off, the trigger will fire.
  32.       CREATE OR REPLACE TRIGGER logoff_audit Before LOGOFF ON DATABASE
  33.       BEGIN
  34.       insert into system.login_info
  35.       select
  36.       '',sysdate,user,sys_context('USERENV','SESSIONID'),sys_context('USERENV'
  37.       ,'TERMINAL'), program from v$session where logon_time = (select
  38.       logindatetime from SYSTEM.login_info where SESSIONID=
  39.       sys_context('USERENV','SESSIONID'));
  40.       END;
  41.       /
  42.       Shutdown the database, restart it, and log on as SYS. There will be values
  43.       inserted in the table. Now retrieve the value from the table.
  44.       select to_char(logindatetime,'DD-MON-YYYY
  45.       hh:mi:ss')LOGIN,to_char(LogoffDateTime,'DD-MON-YYYY hh:mi:ss')LOGOFF,
  46.       SESSIONID,
  47.       TERMINAL,
  48.       PROGRAM
  49.       from SYSTEM.login_info
  50.       group by SESSIONID,logindatetime,LogoffDateTime,TERMINAL,PROGRAM;
  51.       /
  52.       Alternatively, you can also develop a PL/SQL procedure to do the same
  53.       thing.
  54.       create or replace procedure traceusers
  55.       as
  56.       CURSOR BROWSER IS
  57.       select to_char(logindatetime,'DD-MON-YYYY
  58.       hh:mi:ss')LOGIN,to_char(LogoffDateTime,'DD-MON-YYYY hh:mi:ss')LOGOFF,
  59.       SESSIONID,
  60.       TERMINAL,
  61.       PROGRAM
  62.       from SYSTEM.login_info
  63.       group by SESSIONID,logindatetime,LogoffDateTime,TERMINAL,PROGRAM;
  64.       BROWSEIT BROWSER%ROWTYPE;
  65.       begin
  66.       OPEN BROWSER;
  67.       LOOP
  68.       FETCH BROWSER INTO BROWSEIT;
  69.       EXIT WHEN BROWSER%NOTFOUND;
  70.       dbms_output.put_line('Logged In: '||BROWSEIT.LOGIN ||' Logged Off: '||
  71.       BROWSEIT.LOGOFF || ' SessionID: '||BROWSEIT.SESSIONID||'
  72.       Terminal:'||BROWSEIT.TERMINAL||' Program: '||BROWSEIT.PROGRAM);
  73.       END LOOP;
  74.       CLOSE BROWSER;
  75.       end;
  76.       /


复制代码
发表于 2006/7/15 11:51:35 | 显示全部楼层
这个怎么用啊,老大
发表于 2006/7/15 11:53:29 | 显示全部楼层
不好意思,起先没仔细看,现在明白了!
谢谢
发表于 2006/7/20 19:37:30 | 显示全部楼层
这是数据库方面的审计 如何实现ERP方面的审计
发表于 2006/7/24 20:19:23 | 显示全部楼层

回复 #1 纵横四海 的帖子

34
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|Archiver|小黑屋|手机版|壹佰网 ERP100 ( 京ICP备19053597号-2 )

Copyright © 2005-2012 北京海之大网络技术有限责任公司 服务器托管由互联互通
手机:13911575376
网站技术点击发送消息给对方83569622   广告&合作 点击发送消息给对方27675401   点击发送消息给对方634043306   咨询及人才点击发送消息给对方138011526

GMT+8, 2025/11/30 00:22 , Processed in 0.017603 second(s), 14 queries , File On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表