I wrote this script because of Question of safe data passing.... Keep in mind that it only an example and was not written as a script to use, but it would prolly work :)

If one was going to use this script or one like it, they most likly would want to chmod 400 the config file and chmod 6755 the wrapper script. Read Question of safe data passing... to under stand why I say this.

### # dnswrapper.pl to transmit dsn lines (usernames,passwords) to applica +tions ### #!/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(<C>) {$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=<P>; 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"); }
and the config
[USER]=[jason] [DSN]=[DBI:mysql:dbname;user=dbuser] [CALLER]=[/usr/local/bin/caller.pl]
and my example caller script
#!/usr/bin/perl open(P,"perl ./dsnwrapper.pl|"); binmode(P); my($dsn)=${(thaw(join('',<P>)))[0]}{DSN}; close(P); my($dbh)=DBI->connect($dsn) || die(DBI->errstr);

In reply to DSN Wrapper for Secure DBI Passwords by lindex

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.