gksudo disable elevation persistence

Karl Auer kauer at biplane.com.au
Sat Jan 16 13:27:33 UTC 2010


On Sat, 2010-01-16 at 07:02 -0600, Fabio A. Miranda wrote:
> Please, take the above code, and running it twice.

Running the program you sent twice is exactly the same as just running
"/usr/bin/gksudo touch /bin/foo" twice. You've just wrapped it up in a
lot of Java.

Here is a fast and ugly hack (because I have never used ProcessBuilder
before) that will always ask for a password. It just calls "sudo -k"
before each call to gksudo. As was suggested in the very first answer to
your question.

Regards, K.

import java.io.BufferedReader ;
import java.io.InputStreamReader ;

public class test1
{
   public static void main(String[] args) {
        ProcessBuilder pb = new ProcessBuilder();
        String comando = "";
        try {
            pb = new ProcessBuilder();
            pb.redirectErrorStream(true);
            comando = "/usr/bin/sudo -k";
            pb.command("/bin/bash", "-c", comando);
            System.out.println(comando);
            Process p = pb.start();
            BufferedReader output = new BufferedReader(new
InputStreamReader(p.getInputStream()));
            String line;
            while ((line = output.readLine()) != null) {
                System.out.println(line);
            }
            int exitVal = p.waitFor();
            System.out.println("exit code from \"sudo -k\"" + exitVal);

            pb = new ProcessBuilder();
            pb.redirectErrorStream(true);
            comando = "/usr/bin/gksudo touch /bin/foo";
            pb.command("/bin/bash", "-c", comando);
            System.out.println(comando);
            p = pb.start();
            output = new BufferedReader(new
InputStreamReader(p.getInputStream()));
            while ((line = output.readLine()) != null) {
                System.out.println(line);
            }
            exitVal = p.waitFor();
            System.out.println("exit code from \"gksudo\"" + exitVal);
        } catch (Exception e) {
            System.out.println(e.toString());
        }
   }
}

-- 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Karl Auer (kauer at biplane.com.au)                   +61-2-64957160 (h)
http://www.biplane.com.au/~kauer/                  +61-428-957160 (mob)

GPG fingerprint: B386 7819 B227 2961 8301 C5A9 2EBC 754B CD97 0156
Old fingerprint: 07F3 1DF9 9D45 8BCD 7DD5 00CE 4A44 6A03 F43A 7DEF
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part
URL: <https://lists.ubuntu.com/archives/ubuntu-users/attachments/20100117/5541cb99/attachment.pgp>


More information about the ubuntu-users mailing list