executing command as a different OS user

This is a discussion on executing command as a different OS user within the C Programming forums, part of the General Programming Boards category; Hello all, While in a C program(say being executed as user A) due to security issues, I have to execute ...

  1. #1
    Registered User
    Join Date
    Jun 2010
    Posts
    2

    executing command as a different OS user

    Hello all,

    While in a C program(say being executed as user A) due to security issues, I have to execute a certain set of commands as a different OS user ( say user B ). The way I am trying to do is with the system command
    something like system("sudo -u userB cmd");
    But there are 2 un desirable side effects to this
    1, A has to be sudoer
    2, Having to enable passwordless sudo execution for A ( my admin is not happy with this ).

    Could any one please suggest any other effect way? ( with out use of sudo possibly.)
    Also can be done using setuid() calls?
    thanks
    Last edited by cneophyte; 06-09-2010 at 02:04 PM.

  2. #2
    {Jaxom,Imriel,Liam}'s Dad Kennedy's Avatar
    Join Date
    Aug 2006
    Location
    Alabama
    Posts
    1,065
    chmod +S <program>

    will always run the program as the Super user account (root). In your program, you have the ability, then, to change user IDs to ANYONE you want.

  3. #3
    Registered User
    Join Date
    Jun 2010
    Posts
    2
    thank you for the reply
    But will it run as the root or other user to which I set using setuid?

  4. #4
    {Jaxom,Imriel,Liam}'s Dad Kennedy's Avatar
    Join Date
    Aug 2006
    Location
    Alabama
    Posts
    1,065
    Initially, it will run as root. Consider all the many user space apps that are run as root from the beginning. These all change their privilege level at load (some don't, but they fork a child as a less privileged user).

    The kicker for you to decide is if you will ever need root access again.

  5. #5
    Registered User jeffcobb's Avatar
    Join Date
    Dec 2009
    Location
    Henderson, NV
    Posts
    875
    Although running as root when there isn't a compelling reason to do so isn't the brightest of ideas, particularly if you are a new programmer. Let me look this one up at work.
    C/C++ Environment: GNU CC/Emacs
    Make system: CMake
    Debuggers: Valgrind/GDB

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help managing user input
    By JayDiddums10 in forum C Programming
    Replies: 2
    Last Post: 11-19-2006, 04:01 PM
  2. Detecting if OS is Windows???
    By Ktulu in forum Windows Programming
    Replies: 2
    Last Post: 11-19-2006, 01:49 AM
  3. inquiry from a hungry mac os x user
    By terabyter in forum C Programming
    Replies: 3
    Last Post: 06-23-2006, 09:04 AM
  4. pass error before char
    By bazzano in forum C Programming
    Replies: 3
    Last Post: 03-26-2006, 11:00 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21