Wednesday, February 27, 2013

sybase logon trigger to prevent unauthorized user connections

USE sybsystemprocs
go
IF OBJECT_ID('dbo.sp_login_trigger') IS NOT NULL
BEGIN
    DROP PROCEDURE dbo.sp_login_trigger
    IF OBJECT_ID('dbo.sp_login_trigger') IS NOT NULL
        PRINT '<<< FAILED DROPPING PROCEDURE dbo.sp_login_trigger >>>'
    ELSE
        PRINT '<<< DROPPED PROCEDURE dbo.sp_login_trigger >>>'
END
go
create procedure dbo.sp_login_trigger
as
declare
        @loginname varchar(32),
        @hostname varchar(32),
        @ipaddress varchar(32)


--This is an example to simply restrict user bsun from connecting to the server via a specific IP address
--To configure a login-specific login trigger:
--sp_modifylogin my_login, 'login script',sp_login_trigger
--To drop the login trigger
--sp_modifylogin my_login, 'login script',NULL
-- drop the global login trigger
--sp_logintrigger 'drop'

-- change the global login trigger
--sp_logintrigger 'your_db.dbo.a_different_proc'

--To change the login trigger
--sp_modifylogin my_login,'login script',a_dirrerent_sp
--TO CONFIGURE a GLOBAL LOGIN TRIGGER
--sp_logintrigger 'sybsystemprocs.dbo.sp_login_trigger'
--or: sp_modifylogin NMULL,'login script','sybsystemprocs.dbo.sp_login_trigger'


select @loginname=suser_name(suid), @hostname=rtrim(clienthostname), @ipaddress=rtrim(ipaddr)
from master.dbo.sysprocesses where suid=suser_id()
--print "BEFORE IF"
--print @hostname
print @loginname
print @ipaddress

--if (@hostname='P019323' and @loginname='bsun') or (@ipaddress='192.168.23.74' and @loginname='bsun')
if @ipaddress='165.135.23.74' and @loginname='bsun'

    begin
        print 'Restricted User %1! using %2! blocked out', @loginname, @hostname
        print 'User %1! is not allowed to connect to %2! from %3!', @loginname,@@servername,@ipaddress
            /* Log an entry in an audit table */
            --insert into APP_ACCESS_VIOLATION values (@loginname, @appname, getdate(), 'Access Violation')
        select syb_quit()
    end
go
EXEC sp_procxmode 'dbo.sp_login_trigger', 'unchained'
go
IF OBJECT_ID('dbo.sp_login_trigger') IS NOT NULL
    PRINT '<<< CREATED PROCEDURE dbo.sp_login_trigger >>>'
ELSE
    PRINT '<<< FAILED CREATING PROCEDURE dbo.sp_login_trigger >>>'
go
REVOKE EXECUTE ON dbo.sp_login_trigger FROM public
go
GRANT EXECUTE ON dbo.sp_login_trigger TO public
go

Thursday, September 6, 2012

dba_2pc_pending distributed transaction cleanup delete

Hi,

You Can try the following to rollback your transactions:
(It appears that you are seeing distributed transactions as Prepared instead of collecting.

Try running this:

SQL> select LOCAL_TRAN_ID,STATE from DBA_2PC_PENDING;


Then based on your results issue the following:

SQL> rollback force '';


SQL> commit;

SQL> alter system set "_smu_debug_mode" = 4;

SQL> exec dbms_transaction.purge_lost_db_entry('');

SQL> exit


You should repeat this for each entry that you get back from the first query.

Good luck.

Stacy

Monday, July 2, 2012

sybase interface file convert from TLI to TCP


SERVERNAME

      master tli tcp /dev/tcp \x000213880a8d6b360000000000000000

      query tli tcp /dev/tcp \x000213880a8d6b360000000000000000


Indicates that this is a
"tli address" family. This is always the start of the start of a TLI address.
TCP/IP is family 2, depending on network vendor and byte order of the machine,
the most common is 0002, or 0200 depending whether the machine is 'big
endian' or 'little endian'. Check your current interfaces file.
This is the hexadecimal
equivalent of the port number
This is the first part of
the IP address.
This is the second part
of the IP address.
This is the third part of
the IP address.
This is the fourth part
of the IP address.
This is a 'padding' value,
and is platform dependant, on Solaris it is 16 zeros. It is mandatory
\x0002
1388
0a
14
1e
28
0000000000000000

Thursday, May 17, 2012

get oracle job DDLs with dbms_metadata.get_ddl

Trick:
is you query dba_objects for your job objects, the objecttype is "JOB". However, if you use this type to extract your DDL definition, you get the following:

SQL> select dbms_metadata.get_ddl('JOB','COORD_INC_BACKUP','DBA_ADMIN') from dual;
ERROR:
ORA-31604: invalid NAME parameter "NAME" for object type JOB in function
SET_FILTER
ORA-06512: at "SYS.DBMS_SYS_ERROR", line 116
ORA-06512: at "SYS.DBMS_METADATA_INT", line 4676
ORA-06512: at "SYS.DBMS_METADATA_INT", line 8552
ORA-06512: at "SYS.DBMS_METADATA", line 2881
ORA-06512: at "SYS.DBMS_METADATA", line 2747
ORA-06512: at "SYS.DBMS_METADATA", line 4333
ORA-06512: at line 1

no rows selected



Infact, the object type of your job object is not JOB, but PROCJOB
SQL> set long 2000000
SQL> set pagesize 0
SQL> select dbms_metadata.get_ddl('PROCOBJ','COORD_INC_BACKUP','DBA_ADMIN') from dual;


BEGIN
dbms_scheduler.create_job('"COORD_INC_BACKUP"',
job_type=>'EXECUTABLE', job_action=>
'/u01/app/oracle/scripts/rman_coord_inc.sh'
, number_of_arguments=>0,
start_date=>NULL, repeat_interval=>
NULL
, end_date=>NULL,
job_class=>'"DEFAULT_JOB_CLASS"', enabled=>FALSE, auto_drop=>TRUE,comments=>
'coordinated dump (incremental 1) using rman'
);
COMMIT;
END;




SQL> 


Tuesday, May 1, 2012

Optimizer statistics History Information

The following is used to get the optimizer statistics' history retention value and the timestamps for which statistics are available to be restored to the oracle database:
DECLARE
r number
a timestamp;
BEGIN
a:=dbms_stats.get_stats_history_availability;
r:=dbms_stats.get_stats_history_retention;
dbms_output.put_line(a||'--'||r);
END;

password file number of entries


1. At the time of creating a password file you specify the maximum number of 
distinct DBA and OPERs. But say already this step had been taken care and now I 
want to see in the exsisting password file the max. no of entries specified. 
Which data dictionary or anyother place where we can get this info.

take the size of the password file, subtract 1024 and divide by 128.  Eg:

$ ls -lag xxx yyy zzz
-rwSr-----   1 tkyte    other        3584 Dec 27 11:25 xxx
-rwSr-----   1 tkyte    other        6144 Dec 27 11:25 yyy


3584 -> 2560 -> 20, xxx has 20 entries
6144 -> 5120 -> 40, yyy has 40 entries