user$中的日期
客户做数据库安全检查用到如下语句
select name, CTIME, PTIME, EXPTIME, LTIME from sys.user$ where name in (select username from dba_users where account_status='OPEN');
问其中的CTIME、PTIME、EXPTIME、LTIME是什么意思。
查一下dba_user这个视图的定义:
SQL>set head off
SQL>select to_char(dbms_metadata.get_ddl('VIEW','DBA_USERS')) from dual;
CREATE OR REPLACE FORCE VIEW "SYS"."DBA_USERS" ("USERNAME", "USER_ID", "PASSWO
RD", "ACCOUNT_STATUS", "LOCK_DATE", "EXPIRY_DATE", "DEFAULT_TABLESPACE", "TEMPOR
ARY_TABLESPACE", "CREATED", "PROFILE", "INITIAL_RSRC_CONSUMER_GROUP", "EXTERNAL_
NAME") AS
select u.name, u.user#, u.password,
m.status,
decode(u.astatus, 4, u.ltime,
5, u.ltime,
6, u.ltime,
8, u.ltime,
9, u.ltime,
10, u.ltime, to_date(NULL)),
decode(u.astatus,
1, u.exptime,
2, u.exptime,
5, u.exptime,
6, u.exptime,
9, u.exptime,
10, u.exptime,
decode(u.ptime, '', to_date(NULL),
decode(pr.limit#, 2147483647, to_date(NULL),
decode(pr.limit#, 0,
decode(dp.limit#, 2147483647, to_date(NULL), u.ptime +
dp.limit#/86400),
u.ptime + pr.limit#/86400)))),
dts.name, tts.name, u.ctime, p.name,
nvl(cgm.consumer_group, 'DEFAULT_CONSUMER_GROUP'),
u.ext_username
from sys.user$ u left outer join sys.resource_group_mapping$ cgm
on (cgm.attribute = 'ORACLE_USER' and cgm.status = 'ACTIVE' and
cgm.value = u.name),
sys.ts$ dts, sys.ts$ tts, sys.profname$ p,
sys.user_astatus_map m, sys.profile$ pr, sys.profile$ dp
where u.datats# = dts.ts#
and u.resource$ = p.profile#
and u.tempts# = tts.ts#
and u.astatus = m.status#
and u.type# = 1
and u.resource$ = pr.profile#
and dp.profile# = 0
and dp.type#=1
and dp.resource#=1
and pr.type# = 1
and pr.resource# = 1
可以看出:
1、u.ltime对应的是LOCK_DATE
2、u.exptime对应的是EXPIRY_DATE,这其中提到了ptime
3、u.ctime对应的是CREATEDexpiry_date
4、ptime没有明确定义,我们可从
decode(u.ptime, '', to_date(NULL),
decode(pr.limit#, 2147483647, to_date(NULL),
decode(pr.limit#, 0,
decode(dp.limit#, 2147483647, to_date(NULL), u.ptime +
dp.limit#/86400),
u.ptime + pr.limit#/86400)))
进行推断。
同样查看dba_profiles的定义:
SQL> select to_char(dbms_metadata.get_ddl('VIEW','DBA_PROFILES')) from dual;
CREATE OR REPLACE FORCE VIEW "SYS"."DBA_PROFILES" ("PROFILE", "RESOURCE_NAME",
"RESOURCE_TYPE", "LIMIT") AS
select
n.name, m.name,
decode(u.type#, 0, 'KERNEL', 1, 'PASSWORD', 'INVALID'),
decode(u.limit#,
0, 'DEFAULT',
2147483647, decode(u.resource#,
4, decode(u.type#,
1, 'NULL', 'UNLIMITED'),
'UNLIMITED'),
decode(u.resource#,
4, decode(u.type#, 1, o.name, u.limit#),
decode(u.type#,
0, u.limit#,
decode(u.resource#,
1, trunc(u.limit#/86400, 4),
2, trunc(u.limit#/86400, 4),
5, trunc(u.limit#/86400, 4),
6, trunc(u.limit#/86400, 4),
u.limit#))))
from sys.profile$ u, sys.profname$ n, sys.resource_map m, sys.obj$ o
where u.resource# = m.resource#
and u.type#=m.type#
and o.obj# (+) = u.limit#
and n.profile# = u.profile#
当limit#为2147483647时,dba_profiles的limit实际上为unlimited.
因此
decode(dp.limit#, 2147483647, to_date(NULL), u.ptime +
dp.limit#/86400)
当limit#非2147483647时,为u.ptime+dp.limit#/86400。
我们知道,从dba_users中查询时,expiry_date要么为空,代表永不过期;要么显示日期值,这个日期或者是已经失效的用户的失效日期,或者是根据profile策略的即将失效的日期。
已失效日期为u.exptime,则根据ptime计算的为即将失效的日期。
这么推断的话,结合公式ptime+dp.limit#/86400,则ptime为密码更改日期。
因此,结论是:
1、u.ltime 帐号锁定日期
2、u.exptime 帐号失效日期
3、u.ctime 帐号创建日期
4、ptime 帐号密码上次更改日期