cmcclain0831
Programmer
I'm fairly new to Perl, which I'm using to do sysadmin and dba stuff, and I'm consistently running into a need to execute an external command as a user different from the user executing my Perl script, with all of that user's environment variables, privileges, etc. Seems as if that should be easy, but I've done a lot of research and am not finding it so.
Specifically, I'm running an installation script, as root or admin, that copies files to various places, does chmods and chowns, etc. All of that is going fine. However, since a lot the files I'm installing are Oracle-related scripts, one or more steps involve invoking Oracle's sqlplus to run one of these scripts.
Because of Oracle's environmental requirements, I really need to "become" the OS user who is the Oracle instance owner, with all of his environment variables and privileges, for the purpose of invoking sqlplus. Simply sourcing his .bash_profile doesn't do the trick, because of the privilege issue. I also tried:
($<,$>) = (getpwnam("oracle10"),getpwnam("oracle10");
...thinking that would give me oracle10's privileges, but that doesn't seem to work, either. I'm stumped; all I really want to do is say, "For the purpose of running sqlplus right now, I am oracle10, thank you, and make me be admin again when sqlplus finishes".
I understand that there are security issues involved when you assume another user's identity; in this case, I am doing this in a closed lab environment, not production, and want to become a less-privileged user, not more-privileged.
I will appreciate any help anyone can offer; I've spent almost as much time researching and playing with this issue as I have spent on the rest of Perl.
Specifically, I'm running an installation script, as root or admin, that copies files to various places, does chmods and chowns, etc. All of that is going fine. However, since a lot the files I'm installing are Oracle-related scripts, one or more steps involve invoking Oracle's sqlplus to run one of these scripts.
Because of Oracle's environmental requirements, I really need to "become" the OS user who is the Oracle instance owner, with all of his environment variables and privileges, for the purpose of invoking sqlplus. Simply sourcing his .bash_profile doesn't do the trick, because of the privilege issue. I also tried:
($<,$>) = (getpwnam("oracle10"),getpwnam("oracle10");
...thinking that would give me oracle10's privileges, but that doesn't seem to work, either. I'm stumped; all I really want to do is say, "For the purpose of running sqlplus right now, I am oracle10, thank you, and make me be admin again when sqlplus finishes".
I understand that there are security issues involved when you assume another user's identity; in this case, I am doing this in a closed lab environment, not production, and want to become a less-privileged user, not more-privileged.
I will appreciate any help anyone can offer; I've spent almost as much time researching and playing with this issue as I have spent on the rest of Perl.