Find the answer to your Linux question:
Results 1 to 4 of 4
Hi everyone. my problem is such: I am working in Linux on a program in c++ that incorporates qt. In this programs I am using some system() calls. these system() ...
  1. #1
    Just Joined!
    Join Date
    Jul 2009
    Posts
    8

    C++ program getting sudo password

    Hi everyone.

    my problem is such:

    I am working in Linux on a program in c++ that incorporates qt.
    In this programs I am using some system() calls.
    these system() calls are operation that require root privileges.
    so for example:

    mycode:

    Code:
    system("sudo su");
    but when I run this my program just freezes because it is waiting for a password.

    Is there any way with qt that I could prompt the user for a password and then pass it in when I call the system() commands???

    so something layed out like this:

    Code:
    // Message box: what is you password?
    
    system("sudo su") < password;
    I hope you can understand this. Thanks for any help that anyone maybe able to supply!!

  2. #2
    Linux Enthusiast gerard4143's Avatar
    Join Date
    Dec 2007
    Location
    Canada, Prince Edward Island
    Posts
    714
    The proper way to do this in Linux is with Setuid.

    Check out this link...Gerard4143

    GNU C Library (libc) Programming Guide - Setuid Program Example
    Make mine Arch Linux

  3. #3
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    8,974
    If this program needs to run as root, then make it owned by root and set the setuid bit so that it will always run as a root process. WARNING! This is very dangerous as it provides a means for malware to access the system as root. Be very judicious in your use of this capability.
    Code:
    # as root
    chown root progname
    chmod ugo+s progname
    Doing this, when then program is run, it will run as user root and thus system() calls will run with root privileges. You will not need to do the "sudo su -" thing.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  4. #4
    Just Joined!
    Join Date
    Jul 2009
    Posts
    8
    Thank you both for the reply!!!

    I will have to try this and see if it works!!!

    Many thanks again!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...