### # dnswrapper.pl to transmit dsn lines (usernames,passwords) to applications ### #!/usr/bin/perl use strict; use Storable qw(freeze); use vars qw($configfile %config $caller $dbi); $configfile="dsn.conf"; open(C,$configfile) || die("$!: $configfile"); while() {$config{$1}=$2 if(/^\[([^\[|^\]]+)\]=\[([^\[|^\]]+)\]/)} close(C); die("No DSN Line !\n") if (!exists $config{DSN}); die("No USER Line !\n") if (!exists $config{USER}); die("No CALLER Line !\n") if (!exists $config{CALLER}); die("What Iam my own parent !") if($$==getppid()); open(P,'/proc/'.getppid().'/cmdline') || die("$!: PARENT CMDLINE"); $caller=

; close(P); $caller=$1 if ($caller=~/^perl\0([^\0]+)/); if (getpwuid($<) eq $config{USER} and $caller eq $config{CALLER}) { print freeze({DSN=>$config{DSN}}); } else { die("Something went wroung !\n"); } #### [USER]=[jason] [DSN]=[DBI:mysql:dbname;user=dbuser] [CALLER]=[/usr/local/bin/caller.pl] #### #!/usr/bin/perl open(P,"perl ./dsnwrapper.pl|"); binmode(P); my($dsn)=${(thaw(join('',

)))[0]}{DSN}; close(P); my($dbh)=DBI->connect($dsn) || die(DBI->errstr);