Python & Linux, some questions

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Luca T.

    Python & Linux, some questions

    Hello,
    i need some answers...

    1) I need to run some linux commands (from inside my app) that require
    superuser privileges (mkfs, losetup, etc), how do i do that? (I do not
    want to run my app with root privileges, but it will just ask the user
    for the root password before proceeding)
    2) When i execute the command i need to read its output (especially the
    error messages) to know if everything went fine but i do not know how :(
    3) How can i know if the user that is running my app is root or normal user?

    Thank you,
    Luca
  • Mathias Waack

    #2
    Re: Python & Linux, some questions

    Luca T. wrote:[color=blue]
    > 1) I need to run some linux commands (from inside my app) that
    > require superuser privileges (mkfs, losetup, etc), how do i do
    > that? (I do not want to run my app with root privileges, but it
    > will just ask the user for the root password before proceeding)[/color]

    man sudo(1), su(1) or setuid-bit (chmod(1))
    [color=blue]
    > 2) When i execute the command i need to read its output (especially
    > the error messages) to know if everything went fine but i do not
    > know how :[/color]

    see the popen family of functions in the Python library.
    [color=blue]
    >( 3) How can i know if the user that is running my app is
    > root or normal user?[/color]

    os.getuid()

    Mathias

    Comment

    • Luca T.

      #3
      Re: Python & Linux, some questions

      Mathias Waack wrote:[color=blue]
      > Luca T. wrote:
      >[color=green]
      >>1) I need to run some linux commands (from inside my app) that
      >>require superuser privileges (mkfs, losetup, etc), how do i do
      >>that? (I do not want to run my app with root privileges, but it
      >>will just ask the user for the root password before proceeding)[/color]
      >
      >
      > man sudo(1), su(1) or setuid-bit (chmod(1))[/color]

      Hmmmm,
      ok... "sudo" requires me to modify the user's system (or in other words
      write in /etc/sudoers), a thing that i don't want to do. My app has not
      to change the configuration of the machine.
      Same thing for setuid-bit/chmod.

      This leaves me with "su"... but there is a problem... "su" doesn't
      execute any command, it just gives you a "prompt" as root (or another
      user)... how can use this?

      Thank you,
      Luca

      Comment

      • Mathias Waack

        #4
        Re: Python & Linux, some questions

        Luca T. wrote:[color=blue]
        > This leaves me with "su"... but there is a problem... "su" doesn't
        > execute any command, it just gives you a "prompt" as root (or
        > another user)... how can use this?[/color]

        Please read su(1) until you find the answer. Or use the right group;)

        Mathias

        Comment

        • Luca T.

          #5
          Re: Python & Linux, some questions

          Mathias Waack wrote:
          [color=blue]
          > Please read su(1) until you find the answer. Or use the right group;)[/color]

          Damn, you are right, thanx... now i wonder why sudo exists though... oh
          well.

          Bye,
          Luca

          Comment

          • Nai Namae

            #6
            Re: Python & Linux, some questions

            a magic combination of both would be the command:

            sudo su -

            :)

            make a shell "script" out of it:

            #!/bin/bash
            sudo su -

            call it "root", make it executable to everyone, put it in /usr/local/bin or
            any other path in $PATH, add all users on your system to /etc/sudoers...

            and just run your new "root" command and enjoy.. ok, of course you should
            not do so!
            by using "root" you can now have a root shell withouth having to type a
            password every time :/

            Luca T. wrote:
            [color=blue]
            > Mathias Waack wrote:
            >[color=green]
            >> Please read su(1) until you find the answer. Or use the right group;)[/color]
            >
            > Damn, you are right, thanx... now i wonder why sudo exists though... oh
            > well.
            >
            > Bye,
            > Luca[/color]

            Comment

            • bobb

              #7
              Re: Python & Linux, some questions

              I use pexpect to telnet and ssh...

              "Luca T." <lucat@despamme d.com> wrote in message
              news:c32b2j$222 k3a$1@ID-99001.news.uni-berlin.de...[color=blue]
              > Hello,
              > i need some answers...
              >
              > 1) I need to run some linux commands (from inside my app) that require
              > superuser privileges (mkfs, losetup, etc), how do i do that? (I do not
              > want to run my app with root privileges, but it will just ask the user
              > for the root password before proceeding)
              > 2) When i execute the command i need to read its output (especially the
              > error messages) to know if everything went fine but i do not know how :(
              > 3) How can i know if the user that is running my app is root or normal[/color]
              user?[color=blue]
              >
              > Thank you,
              > Luca[/color]


              Comment

              • Dennis Lee Bieber

                #8
                Re: Python &amp; Linux, some questions

                On Sun, 14 Mar 2004 23:09:51 +0100, "Luca T." <lucat@despamme d.com>
                declaimed the following in comp.lang.pytho n:
                [color=blue]
                > Damn, you are right, thanx... now i wonder why sudo exists though... oh
                > well.
                >[/color]
                sudo doesn't require the root password, only the authorized
                user's password. It can also be configured to only allow access to
                certain commands, not everything.

                --[color=blue]
                > =============== =============== =============== =============== == <
                > wlfraed@ix.netc om.com | Wulfraed Dennis Lee Bieber KD6MOG <
                > wulfraed@dm.net | Bestiaria Support Staff <
                > =============== =============== =============== =============== == <
                > Home Page: <http://www.dm.net/~wulfraed/> <
                > Overflow Page: <http://wlfraed.home.ne tcom.com/> <[/color]

                Comment

                Working...