I'd actually handle this using sudo or something similar to launch a Perl script with taint checking turned on since C doesn't provide a taint checking mechanism (you could use a set-UID Perl script or a setuidperl executable but I think that sudo is more secure -- though I'm not completely up-to-date on this).

Then the script starts with both UIDs, you use the effective UID to get the protected password and which script to pass it to, then you remove all trace of the privileged UID (this is a bit tricky) and launch the new script with a pipe open to it.

You can also protect the source code of the privileged script which means you can encrypt the protected password so that both the protected configuration file and the protected script would have to be compromised (and the culprit use the algorythm and key in the script to decrypt the password) for the password to be compromised.

        - tye (but my friends call me "Tye")

In reply to (tye)Re2: Question of safe data passing... by tye
in thread Question of safe data passing... by suaveant

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.