Thu 1 Oct 2009
Oracle client – changing the program name in the session
Posted by Slavik under OCI, Oracle, technical tips
[2] Comments
I always wondered how Oracle Client knows to send my program name to the server process to be stored in x$ksuse (v$session). I had my assumptions but finally I had a chance to verify them as a fellow developer asked me this question.
I’ve created a simple ocitest C program to connect to Oracle and select the program name from v$session and then started experimenting.
The first test was just overwriting argv[0] with a different value at the beginning of the program. The name was immediately changed in the Oracle session.
The second test was running the program with strace since there are several ways you can get the process name on Linux. It turns out that Oracle client chooses the simplest way:
open(“/proc/self/cmdline”, O_RDONLY) = 3
read(3, “xxxxxxxxx\0002\0″, 255) = 12
close(3) = 0
So, it looked to me that all I had to do is to intercept (interpose) the open call and replace it with my own version so that if the open tries to read /proc/self/cmdline I will return my own file containing my own chosen program name.
Which I immediately proceeded to test (ocitest2) and of course it worked.
Ha, try this to confuse the administrator – Oracle saying that program X is connected but in the processes list you cannot find program X (of course you can always check the process at the end of the socket).
Hi Slavik,
I guess I am confused but why not just rename the binary if you want Oracle to think its not running what it really is running? – I talked about the same issue for a different rewason 6 years ago in this paper – http://www.petefinnigan.com/news_letter_001.pdf and interestingly in 8.1.5 i was able to modify the string for SQL*Plus in the binary using a hex editor from SQl*Plus to SQL~Plus so that the PUP functionallity didnt recognise that the binary actually being used was SQl*plus as i found that simply renaming it didnt work.
Nice work Slavik,
cheers
Pete
@Pete
Sure, one can just rename the binary of SQL*Plus or such but we had a need to change the program name dynamically inside the executable to various different names. Also, sometimes you’re in an environment where you can’t change SQL*Plus but you have execution privileges and access to Oracle. You can use LD_PRELOAD in the same way as I showed here to override the program name.