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. Running application with user privillegions.
Qt 6.11 is out! See what's new in the release blog

Running application with user privillegions.

Scheduled Pinned Locked Moved Unsolved General and Desktop
27 Posts 7 Posters 1.9k Views 2 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.
  • N nicholas_ru

    please, describe code for this action, i am beginner.

    JonBJ Offline
    JonBJ Offline
    JonB
    wrote last edited by JonB
    #8

    @nicholas_ru
    You need to investigate these alternatives to decide which suits your use case the best. You can use man pages or Google. They don't really require "programming" at your side. You should start with: what is it you are trying to do which requires running as another user and why? Why do you want to run what as root from where? Will you only be running this yourself, within your own organization or for distribution to others in the outside world? And btw is this to be a command line or UI Qt application?

    1 Reply Last reply
    0
    • Joe von HabsburgJ Offline
      Joe von HabsburgJ Offline
      Joe von Habsburg
      wrote last edited by Joe von Habsburg
      #9

      I used to before on js many years ago, maybe that command help you

      // echo your-password | sudo -S your-command
      
      QString command = QString("echo %1 | sudo -S %2").arg(1234).arg("ifconfig")
      rocess->start(command)
      
      
      1 Reply Last reply
      0
      • N Offline
        N Offline
        nicholas_ru
        wrote last edited by nicholas_ru
        #10

        Debian running, for example, /usr/sbin/gparted, automatically with root requesting(without entering command sudo).How implementation this is, i am don't know.

        Joe von HabsburgJ jsulmJ 2 Replies Last reply
        0
        • N nicholas_ru

          Debian running, for example, /usr/sbin/gparted, automatically with root requesting(without entering command sudo).How implementation this is, i am don't know.

          Joe von HabsburgJ Offline
          Joe von HabsburgJ Offline
          Joe von Habsburg
          wrote last edited by
          #11

          @nicholas_ru said in Running application with user privillegions.:

          Debian running, for example, gparted, automatically with root requesting(without entering command sudo).How implementation this is, i am don't know.

          I don't understand what you mean. Are you saying that the gparted command runs as root but doesn't ask for a password, whereas other applications do?

          For example, you may have entered a password for the sudo command in the same terminal before, or you may have granted permissions for the gparted command. These are Linux-related tasks.

          If you need run command on qproccess with sudo and password: https://superuser.com/questions/67765/sudo-with-password-in-one-command-line

          1 Reply Last reply
          0
          • N nicholas_ru

            Debian running, for example, /usr/sbin/gparted, automatically with root requesting(without entering command sudo).How implementation this is, i am don't know.

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote last edited by
            #12

            @nicholas_ru said in Running application with user privillegions.:

            How implementation this is, i am don't know.

            This was answered by @JonB :
            "Make your executable file setuid to root or another user so it always runs with that user's privileges. It does not require a login or password."

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            3
            • P Offline
              P Offline
              Peter Watson
              wrote last edited by
              #13

              @fnaf free Could you please provide an example or some sample code for this? I’m still a beginner and trying to understand how it works.

              1 Reply Last reply
              0
              • Joe von HabsburgJ Offline
                Joe von HabsburgJ Offline
                Joe von Habsburg
                wrote last edited by
                #14

                You could ask ai or search on google

                sudo cp your_program.exe /usr/local/bin/your_program
                sudo chmod +x /usr/local/bin/your_program
                

                These are Linux-related tasks.

                JonBJ 1 Reply Last reply
                0
                • Joe von HabsburgJ Joe von Habsburg

                  You could ask ai or search on google

                  sudo cp your_program.exe /usr/local/bin/your_program
                  sudo chmod +x /usr/local/bin/your_program
                  

                  These are Linux-related tasks.

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote last edited by JonB
                  #15

                  @Joe-von-Habsburg said in Running application with user privillegions.:

                  sudo chmod +x /usr/local/bin/your_program

                  It's already executable after the copy, and chmod +x does nothing more than it already is. It does not make the executable run as root. You want/intended instead:

                  chmod u+s path-to-executable
                  

                  so it will look like:

                  root@ubuntu-22:~/QtTests/C++/sudopassword/build/Desktop-Debug# chmod u+s fred
                  root@ubuntu-22:~/QtTests/C++/sudopassword/build/Desktop-Debug# ls -l fred
                  -rwsr-xr-x 1 root root 379112 Mar 30 08:48 fred
                  

                  Note the -rws, the s there.

                  Note that you will need to repeat the chmod every time after you recompile/recopy your executable. If you redistribute your executable then wherever it gets installed the root user would need to choose to run the chmod u+s there once, you cannot distribute (I don't think) with the executable owned by root and setuid.

                  1 Reply Last reply
                  3
                  • N Offline
                    N Offline
                    nicholas_ru
                    wrote last edited by nicholas_ru
                    #16

                    You have ubuntu. I have Debian. This is method change chmod, not exit for programmers.First post with running command very nice,but not full.

                    JonBJ 1 Reply Last reply
                    0
                    • N nicholas_ru

                      You have ubuntu. I have Debian. This is method change chmod, not exit for programmers.First post with running command very nice,but not full.

                      JonBJ Offline
                      JonBJ Offline
                      JonB
                      wrote last edited by JonB
                      #17

                      @nicholas_ru
                      Did you even try it?? Debian man page https://manpages.debian.org/bookworm/coreutils/chmod.1.en.html

                      Each MODE is of the form '[ugoa]*([-+=]([rwxXst]*|[ugo]))+|[-+=][0-7]+'.

                      How else would you setuid under Debian? No point my suggesting things if they do work but you say they do not.

                      .First post with running command very nice,but not full.

                      If you mean @Joe-von-Habsburg 's QString command = QString("echo %1 | sudo -S %2").arg(1234).arg("ifconfig") it won't work as written if passed to QProcess::start().... But I am getting a bit dispirited trying to help you so up to you.

                      Joe von HabsburgJ N 2 Replies Last reply
                      0
                      • JonBJ JonB

                        @nicholas_ru
                        Did you even try it?? Debian man page https://manpages.debian.org/bookworm/coreutils/chmod.1.en.html

                        Each MODE is of the form '[ugoa]*([-+=]([rwxXst]*|[ugo]))+|[-+=][0-7]+'.

                        How else would you setuid under Debian? No point my suggesting things if they do work but you say they do not.

                        .First post with running command very nice,but not full.

                        If you mean @Joe-von-Habsburg 's QString command = QString("echo %1 | sudo -S %2").arg(1234).arg("ifconfig") it won't work as written if passed to QProcess::start().... But I am getting a bit dispirited trying to help you so up to you.

                        Joe von HabsburgJ Offline
                        Joe von HabsburgJ Offline
                        Joe von Habsburg
                        wrote last edited by
                        #18

                        @JonB said in Running application with user privillegions.:

                        But I am getting a bit dispirited trying to help you so up to you.

                        :(

                        @nicholas_ru said in Running application with user privillegions.:

                        You have ubuntu. I have Debian. This is method change chmod, not exit for programmers.First post with running command very nice,but not full.

                        so ? linux is linux and there is a qt forum. we try to help you

                        JonBJ 1 Reply Last reply
                        0
                        • Joe von HabsburgJ Joe von Habsburg

                          @JonB said in Running application with user privillegions.:

                          But I am getting a bit dispirited trying to help you so up to you.

                          :(

                          @nicholas_ru said in Running application with user privillegions.:

                          You have ubuntu. I have Debian. This is method change chmod, not exit for programmers.First post with running command very nice,but not full.

                          so ? linux is linux and there is a qt forum. we try to help you

                          JonBJ Offline
                          JonBJ Offline
                          JonB
                          wrote last edited by JonB
                          #19

                          @Joe-von-Habsburg said in Running application with user privillegions.:

                          But I am getting a bit dispirited trying to help you so up to you.

                          :(

                          To be clear: it is the OP I am getting "dispirited" trying to help, not your posts! :)

                          He could use your code approach (perhaps, if that is what he wants), just that it needs changing to work. But since we (at least I) don't even know exactly what he wants I have not corrected it so far, waiting to see.....

                          1 Reply Last reply
                          1
                          • JonBJ JonB

                            @nicholas_ru
                            Did you even try it?? Debian man page https://manpages.debian.org/bookworm/coreutils/chmod.1.en.html

                            Each MODE is of the form '[ugoa]*([-+=]([rwxXst]*|[ugo]))+|[-+=][0-7]+'.

                            How else would you setuid under Debian? No point my suggesting things if they do work but you say they do not.

                            .First post with running command very nice,but not full.

                            If you mean @Joe-von-Habsburg 's QString command = QString("echo %1 | sudo -S %2").arg(1234).arg("ifconfig") it won't work as written if passed to QProcess::start().... But I am getting a bit dispirited trying to help you so up to you.

                            N Offline
                            N Offline
                            nicholas_ru
                            wrote last edited by nicholas_ru
                            #20

                            @JonB i am think in Qt framework must be integrated this is function.

                            JonBJ 1 Reply Last reply
                            0
                            • N nicholas_ru

                              @JonB i am think in Qt framework must be integrated this is function.

                              JonBJ Offline
                              JonBJ Offline
                              JonB
                              wrote last edited by
                              #21

                              @nicholas_ru No idea what you mean. You have plenty of answers & suggestions above, so over to you to do something....

                              N 1 Reply Last reply
                              0
                              • JonBJ JonB

                                @nicholas_ru No idea what you mean. You have plenty of answers & suggestions above, so over to you to do something....

                                N Offline
                                N Offline
                                nicholas_ru
                                wrote last edited by
                                #22

                                @JonB if QProcess running with root true, if without false.

                                JonBJ 1 Reply Last reply
                                0
                                • N nicholas_ru

                                  @JonB if QProcess running with root true, if without false.

                                  JonBJ Offline
                                  JonBJ Offline
                                  JonB
                                  wrote last edited by
                                  #23

                                  @nicholas_ru
                                  Again, I don't know what that phrase means. You might trying typing in your questions/answers with full detail in your native language into Google and asking it to translate to English, that may give a more meaningful question.

                                  We have explained what the possibilities are for running programs under Linux setuid/as root. You have to pick one. You have to try the suggestions you have been given. I don't even believe what you said about chmod u+s not being available under your Debian. Qt as a framework has nothing to say or do about setuid. QProcess can be used to run other programs in the standard Linux exec-type way. Just because you say "i am think in Qt framework must be integrated this is function." does not make it so there is magically something else in Qt we have not discussed.

                                  At this point I don't think anybody here knows what you actually want, what your problem is or what you have tried from the suggestions.

                                  1 Reply Last reply
                                  0
                                  • S Offline
                                    S Offline
                                    SimonSchroeder
                                    wrote last edited by
                                    #24

                                    There is a reason why you can't just run anything with root privileges. And under normal circumstance you should not try to circumvent it. The most important question is if you really need to run something as root (while your own software is not started with root privileges). Qt does not provide anything special to run a process as root. You need to use OS functionality to run an elevated process (you can use QProcess to start sudo or use any of the other methods mentioned before). In the case of sudo it is up to you to ask the user for the password and hand it to sudo. But, even this is a bad idea because it is really easy to leak the password for an attacker.

                                    1 Reply Last reply
                                    0
                                    • N Offline
                                      N Offline
                                      nicholas_ru
                                      wrote last edited by nicholas_ru
                                      #25

                                      No,no attacker not recieve permissions, but idea not bad. I love Qt and this function for me needed for devleopment, because user also must be entering password.

                                      JonBJ 1 Reply Last reply
                                      0
                                      • N nicholas_ru

                                        No,no attacker not recieve permissions, but idea not bad. I love Qt and this function for me needed for devleopment, because user also must be entering password.

                                        JonBJ Offline
                                        JonBJ Offline
                                        JonB
                                        wrote last edited by
                                        #26

                                        @nicholas_ru
                                        We have given you the alternative approaches for running setuid. Qt itself is not going to add anything in this area.

                                        1 Reply Last reply
                                        0
                                        • N Offline
                                          N Offline
                                          nicholas_ru
                                          wrote last edited by
                                          #27

                                          Well then my development will be limited and I'll have to look for other ways to implement it.

                                          1 Reply Last reply
                                          0

                                          • Login

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