User Profile

Collapse

Profile Sidebar

Collapse
djurdjura
djurdjura
Last Activity: Oct 15 '23, 03:23 AM
Joined: Aug 31 '10
Location:
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • May be I wasn't clear enough. The script runs as root all the time. I just need to run the few steps as a given user and get back to root. Theses steps involve populating a cron tab. I'm looking for the best way of doing that. An idea that I was thinking of was to do this in a separate thread, then this approach isn't Posix compliant and I'm not sure if the whole process doesn't get the same UID (the script runs under Solaris).

    Any...
    See more | Go to post

    Leave a comment:


  • djurdjura
    replied to switch back and forth from root to a user
    Oops! Correcting indentation:

    Code:
    import os
    try:
      if os.name == 'posix':
        import pwd
    
        pw = pwd.getpwnam(user)
        uid = pw.pw_uid
        os.setuid(uid)
    else:
        # Do something useful here
    except:
      return 1 # Error
    finally:
      # Put back root user...
      os.setuid(0)
    See more | Go to post
    Last edited by djurdjura; Aug 31 '10, 06:29 PM. Reason: Inedentation still not correct :-(

    Leave a comment:


  • djurdjura
    started a topic switch back and forth from root to a user

    switch back and forth from root to a user

    Hi there,

    I looked around and couldn't find an answer to this question (and I'm now wondering is there is one :-)

    I have a piece of code in which I need to switch from root to a particular user, run the command as this user and would like to return to root. I don't want to use, if possible at all, "su".

    Here is the snippet code that is run as root initially:
    Code:
    import os
    try:
    ...
    See more | Go to post
    Last edited by bvdet; Aug 31 '10, 06:53 PM. Reason: Add code tags
No activity results to display
Show More
Working...