Here is the only way I know to do it. You write your program in two parts. One part runs as a service with access to the file. The other part is a client, which connects to the service via a named pipe. You can use SECURITY_SQOS_PRESENT flag so that the service can verify (or even impersonate) the identity of the user running the client. The client sends requests to the service which then executes them.

I wrote this in C once to try it out. I have the source code at work which I can send you if you're interested. I don't think all the functions I used have been implemented in the Win32 modules.

For some time I have wanted to write a module which would perform this kind of automatically-authenticated IPC connection, with variants for different OSes. On some *nix systems there is a SO_PEERCRED socket option to identify a local connection. You can also use a convoluted protocol where the client proves his identity by performing some actions in the file system. But, alas, I haven't gotten around to doing it.

This style of programming is somewhat more secure than setuid or sudo. E.g. it's less susceptible to manipulation of environment variables. Also, with setuid programs, if you want to use a cryptographic key you have to store it in the file system and hope that file system security and obfuscation protect it. With the authenticated-IPC style, the (trusted) person who starts the process can type in a password once and the key can be kept in memory.


In reply to Re: suidperl/sudo function-alike on Win32 by Thelonius
in thread suidperl/sudo function-alike on Win32 by traveler

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.