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. Mac sudo authorization help
QtWS25 Last Chance

Mac sudo authorization help

Scheduled Pinned Locked Moved General and Desktop
37 Posts 5 Posters 15.5k Views
  • 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.
  • K Offline
    K Offline
    Ketan Shah
    wrote on 15 Sept 2011, 11:04 last edited by
    #1

    From my application I am starting apache using sudo, but sudo command requires password.
    So how can I get this password from user..
    is there any sudo GUI that will ask for the password as soon as the user starts apache or is there any other authorization GUI that will ask for the password and set that password for that particular application session.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      Alicemirror
      wrote on 16 Sept 2011, 05:02 last edited by
      #2

      Hi Ketah,

      I think that this is not a problem of the Qt applicaiton itself but is related to the OS integration. Max Osx is linux so I can suggest that your Qt applicaiton will be able to manage a shell command launch. Tell me if it maybe the solution so I can post you whar piece of bash script / command you need. Then, to obfuscate it you can create the call directly from your application where you save the user password too for sudo.

      Don't forget that despite the application installation you need then that the installing user is member of the sudoers too. In Mac I think that it is by default, while on different Linux plaftorms it will be done manually.

      Enrico Miglino (aka Alicemirror)
      Balearic Dynamics
      Islas Baleares, Ibiza (Spain)
      www.balearicdynamics.com

      1 Reply Last reply
      0
      • K Offline
        K Offline
        Ketan Shah
        wrote on 16 Sept 2011, 07:12 last edited by
        #3

        Yes, it is fine.
        If I create a window that will ask the user for password, how can I verify it, whether the user has entered a correct password or not, is there any script or command that can help me to verify the password. By the way MAC is an Unix-based operating system(http://en.wikipedia.org/wiki/Mac_OS_X)

        1 Reply Last reply
        0
        • A Offline
          A Offline
          Alicemirror
          wrote on 16 Sept 2011, 08:15 last edited by
          #4

          you can ask with something like QProcess the desred system command, catch the result and the return code (i.e. using the stdio redirection) and manage all from the GUI

          Enrico Miglino (aka Alicemirror)
          Balearic Dynamics
          Islas Baleares, Ibiza (Spain)
          www.balearicdynamics.com

          1 Reply Last reply
          0
          • K Offline
            K Offline
            Ketan Shah
            wrote on 16 Sept 2011, 08:22 last edited by
            #5

            But how can i verify the password, is there any place where the sudo password are stored.? so that I can check it to verify.
            Is there any shell script that will do this verification.?

            1 Reply Last reply
            0
            • A Offline
              A Offline
              Alicemirror
              wrote on 16 Sept 2011, 08:32 last edited by
              #6

              I think you are following the wrong approach. You should not mind on how does Mac to manage its system strategies: you should thing on how your interface can send and receive parameters, error conditions and results.
              You should read the docuemntation of the linux commands, i.e. login
              then see that are the command parameters and what are the return code.

              In linux commands usually there are "verbose" modes that explain errors, warnings etc. useful when you use the commands from the terminal. but when you need to use them from a GUI you should pass parameters that returns e.g. error codes only.

              As a matter of fact you can "graphicize" almost any linux command with a GUI only managing them. It will be good if you can post the logic of your application and what you want exactly do. So we can be clear with some example.

              Enrico Miglino (aka Alicemirror)
              Balearic Dynamics
              Islas Baleares, Ibiza (Spain)
              www.balearicdynamics.com

              1 Reply Last reply
              0
              • K Offline
                K Offline
                Ketan Shah
                wrote on 16 Sept 2011, 08:35 last edited by
                #7

                Also I got a solution in the form of "Cocoasudo":http://www.performantdesign.com/2009/10/26/cocoasudo-a-graphical-cocoa-based-alternative-to-sudo/ which is a GUI based sudo.
                But as soon as I run apache with cocoasudo it prompts the user for password every time.
                Is there any way to set the timeout in Cocoasudo atleast for 15 mins, so till next 15mins it wont ask the user for password again.

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  Alicemirror
                  wrote on 16 Sept 2011, 08:58 last edited by
                  #8

                  Sorry but to give you a decent answer you should be aware that I need to know at least what are you doing ...

                  Enrico Miglino (aka Alicemirror)
                  Balearic Dynamics
                  Islas Baleares, Ibiza (Spain)
                  www.balearicdynamics.com

                  1 Reply Last reply
                  0
                  • K Offline
                    K Offline
                    Ketan Shah
                    wrote on 16 Sept 2011, 09:29 last edited by
                    #9

                    From my application I want to start apache but apache starts with sudo only as it is using port 80.
                    But sudo requires password that is why I am thinking to use Cocoasudo but it asks for password everytime I start or stop apache. For this reason I want to set the time out of 15 mins in Cocoasudo same like in normal sudo, so after every 15mins when the apache is being started or stopped the user will be prompted for the password.
                    And also my application requires that apache should always start on port 80.

                    1 Reply Last reply
                    0
                    • A Offline
                      A Offline
                      Alicemirror
                      wrote on 16 Sept 2011, 09:53 last edited by
                      #10

                      Yep
                      It is clear now

                      First ifnore cocasudo. To start apache I think that you should do something like the following:
                      @
                      $cd /etc/apache2
                      $sudo
                      insert password:


                      $./apache2
                      @
                      At this point you should know that sudo has more options and try to create a small shell script like the following naming it apachestarter.sh
                      @
                      #!/bin/bash
                      NUMPARMS=1 # Minimum required parameters

                      get the current user userId

                      ACTUALUSER=$(whoami)

                      check for parms

                      if [ $# -lt "$NUMPARMS" ]
                      then
                      echo
                      echo "Apache starter"
                      echo
                      echo "usage: ./apachestarter.sh <password for user $ACTUALUSER>"
                      echo "password omitted, so insert manually"
                      read PASSWORD
                      else
                      # read password argument
                      PASSWORD=$1
                      fi

                      The following command will run apache with the sudo password without asking nothing

                      echo $PASSWORD | sudo -S /etc/apache2/apache2
                      @
                      Then save this file in the user home folder or somewhere in the user area. Then remember to change the privileges of this command to be executable, i.e.
                      @
                      $sudo chmod +x apachestarter.sh
                      @
                      [Edit: the previous line has been changed as it is now for a correct and secure operation. See the following posts to understand the reasons]
                      At this point you can launch your command (that will be part of the package, installed in the installation folder etc.) directly from inside your GUI calling him with the password set by the user.

                      Enrico Miglino (aka Alicemirror)
                      Balearic Dynamics
                      Islas Baleares, Ibiza (Spain)
                      www.balearicdynamics.com

                      1 Reply Last reply
                      0
                      • G Offline
                        G Offline
                        goetz
                        wrote on 16 Sept 2011, 12:02 last edited by
                        #11

                        Just for the nitpicking records: Mac OS X is BSD/Darwin based, not Linux. It uses a couple of GNU software though :-)

                        Now for something serious:
                        Setting a file to mode 777 is a bad idea. Do not do that unless you are in need of everyone on the system changing the file's contents!

                        http://www.catb.org/~esr/faqs/smart-questions.html

                        1 Reply Last reply
                        0
                        • A Offline
                          A Offline
                          Alicemirror
                          wrote on 16 Sept 2011, 12:19 last edited by
                          #12

                          Hi Volker, I was just waiting you at this party :D

                          [quote author="Volker" date="1316174529"]Just for the nitpicking records: Mac OS X is BSD/Darwin based, not Linux. It uses a couple of GNU software though :-)

                          Now for something serious:
                          Setting a file to mode 777 is a bad idea. Do not do that unless you are in need of everyone on the system changing the file's contents![/quote]

                          It is all true, but what I wrote was only an exmple based on my memory and not the command to be created. I think that it can give idea of the concept.

                          Then +x or 666 instead of 777 maybe a good idea. But this was and example. The concept is: create a shell program then call it from the GUI and redirect the errio or console to the GUI and see what is the return code then act consequently.

                          Just to be precise: sure, Mac OSX is BSD and it is not a linux just like the debian based distributions (Meego, Harmattan, Ubuntu, Debian itself), gentoo, RedHat and many more including those like OpenWRT and Ltib especially dedicated to the embedded Linux platforms?

                          Cheers.

                          Enrico Miglino (aka Alicemirror)
                          Balearic Dynamics
                          Islas Baleares, Ibiza (Spain)
                          www.balearicdynamics.com

                          1 Reply Last reply
                          0
                          • G Offline
                            G Offline
                            goetz
                            wrote on 16 Sept 2011, 21:14 last edited by
                            #13

                            I know, it was just a quick example, and of course it works. But we all know, that not so experienced users may take the advice literally and end up with a, say suboptimal or dangerous setup. One should keep this always in mind, IMHO.

                            http://www.catb.org/~esr/faqs/smart-questions.html

                            1 Reply Last reply
                            0
                            • A Offline
                              A Offline
                              Alicemirror
                              wrote on 16 Sept 2011, 21:27 last edited by
                              #14

                              Corrected the post with the example and added a short not. So the problem is solved :)

                              Enrico Miglino (aka Alicemirror)
                              Balearic Dynamics
                              Islas Baleares, Ibiza (Spain)
                              www.balearicdynamics.com

                              1 Reply Last reply
                              0
                              • K Offline
                                K Offline
                                Ketan Shah
                                wrote on 19 Sept 2011, 06:43 last edited by
                                #15

                                After running the script that you provided I got an error.

                                "-bash: ./apachestarter.sh: /bin/bash^M: bad interpreter : No such file or directory".

                                What is the solution for this?

                                1 Reply Last reply
                                0
                                • G Offline
                                  G Offline
                                  goetz
                                  wrote on 19 Sept 2011, 23:03 last edited by
                                  #16

                                  You should change the file to unix line endings (newlines instead of carriage return).

                                  http://www.catb.org/~esr/faqs/smart-questions.html

                                  1 Reply Last reply
                                  0
                                  • A Offline
                                    A Offline
                                    Alicemirror
                                    wrote on 19 Sept 2011, 23:24 last edited by
                                    #17

                                    @Volker: are you sure? I exchange continuously files between mac and ubuntu and windows 7 too but the conversions is automatic. It is possible the the folder example that I have suggested can't be applied to the Mac folder structure. I have no idea where apache started is located in the Mac. But I think that Ketan should know.

                                    If the error is what you mean (I suspect too because of this ^M ...) it is strange that happens. Why ?

                                    Enrico Miglino (aka Alicemirror)
                                    Balearic Dynamics
                                    Islas Baleares, Ibiza (Spain)
                                    www.balearicdynamics.com

                                    1 Reply Last reply
                                    0
                                    • G Offline
                                      G Offline
                                      goetz
                                      wrote on 20 Sept 2011, 06:09 last edited by
                                      #18

                                      @alicemirror
                                      It heavily depends on the editor and it's settings. The rest is guessing from the crystal ball. You're right, my guess comes from the ^M - I stumbled over that myself already.

                                      http://www.catb.org/~esr/faqs/smart-questions.html

                                      1 Reply Last reply
                                      0
                                      • A Offline
                                        A Offline
                                        Alicemirror
                                        wrote on 20 Sept 2011, 06:43 last edited by
                                        #19

                                        @volker
                                        Me too, that character worried me too. But I use Mac dayly and just when I open a windows file that for sure has a different coding for the line termination the message that I receive is a fast msgBox "converting to line termination characters" etc. then it disappear. So think we can exclude that the problem is it. I know that the Linux of Mac is different from the Linux of debian in the management of /etc/launcher shell commands. Not only, there are different apache versions. My example was regarding the apache 2 on pure debian machine (always used on servers, not on desktop machines) ...

                                        Enrico Miglino (aka Alicemirror)
                                        Balearic Dynamics
                                        Islas Baleares, Ibiza (Spain)
                                        www.balearicdynamics.com

                                        1 Reply Last reply
                                        0
                                        • K Offline
                                          K Offline
                                          Ketan Shah
                                          wrote on 20 Sept 2011, 07:09 last edited by
                                          #20

                                          Thanks Alicemirror and Volker, finally the script executed successfully. As Volker told to change the file to Unix line endings. I did that by removing /r from the file and after that the script executed.

                                          Thanks a lot once again.

                                          1 Reply Last reply
                                          0

                                          6/37

                                          16 Sept 2011, 08:32

                                          topic:navigator.unread, 31
                                          • Login

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