Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to make Qprocess run a command line as Root
Forum Updated to NodeBB v4.3 + New Features

How to make Qprocess run a command line as Root

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 13.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dcbasso
    wrote on 16 Oct 2012, 19:23 last edited by
    #1

    Hi all!
    I'm trying to execute a comando as root user, using QProcess!
    I ask user for password and will add to command line... how It's possible?

    The command can use "su" or "sudo" to execute...
    Thanks all.

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dlfo
      wrote on 16 Oct 2012, 20:24 last edited by
      #2

      You should give the executable "setuid/gid" permission. You can do this by invoking this command:
      @chmod +s ./executable@

      Read more at:

      http://en.wikipedia.org/wiki/Modes_(Unix)

      But be warned that if this process gets exploited, the whole system may be compromised. There is a chance that you can do what you want to do without setuid.

      1 Reply Last reply
      0
      • D Offline
        D Offline
        dcbasso
        wrote on 16 Oct 2012, 20:28 last edited by
        #3

        I need to add all users on the system to a group...
        I use this command:

        @
        awk -F: '$3 > 999 {print $1}' /etc/passwd | xargs -I USERNAME sudo usermod -a -G dialout USERNAME
        @

        1 Reply Last reply
        0
        • D Offline
          D Offline
          dlfo
          wrote on 16 Oct 2012, 21:34 last edited by
          #4

          Save the command to a shell script file and give it +s permission. Run the shell script using whatever means you can in your application, and it should be ok. But beware, if someone changes the shellscript to destroy your system, you will be in trouble, because he may do whatever root can do. So, place the file in appropriate location and revoke write permisson from it for all users except root. I think this should work:

          @sudo chown root:root script.sh
          sudo chmod 4755 script.sh@

          Be sure to read these articles on setuid before actually using it:

          • "setuid on Shell Scripts":http://www.tuxation.com/setuid-on-shell-scripts.html
          • "UNIX / Linux: Explains setuid File Permission":http://www.cyberciti.biz/faq/unix-bsd-linux-setuid-file/
          1 Reply Last reply
          0
          • D Offline
            D Offline
            dcbasso
            wrote on 17 Oct 2012, 11:40 last edited by
            #5

            If its possible I would like to set my code inside the compiled code, "hard coded" script... In this way I will not have any problems, I guess...

            1 Reply Last reply
            0
            • A Offline
              A Offline
              AcerExtensa
              wrote on 17 Oct 2012, 12:32 last edited by
              #6

              It was already discussed on this forum. With details and at least 2 possible solutions with source code for testing. Please use search functions of this forum before you create new topic. Maybe you problem is already solved.

              Topic I'm talking about: "[SOLVED]Is it possible to pass on password to process requiring root privileges":http://qt-project.org/forums/viewthread/20673/

              God is Real unless explicitly declared as Integer.

              1 Reply Last reply
              0

              1/6

              16 Oct 2012, 19:23

              • Login

              • Login or register to search.
              1 out of 6
              • First post
                1/6
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved