gksudo disable elevation persistence

Fabio A. Miranda fabio.a.miranda at gmail.com
Sat Jan 16 13:25:26 GMT 2010


Dismiss:

Given the above code, the second call to gksudo is password requested
again:

public static void main(String[] args) {
        // TODO code application logic here
        ProcessBuilder pb = new ProcessBuilder();
        String comando = "";
        try {
            pb = new ProcessBuilder();
            pb.redirectErrorStream(true);
            comando = "/usr/bin/gksudo touch /bin/foo";
            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" + exitVal);
        } catch (Exception e) {
            System.out.println(e.toString());
        }
        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" + exitVal);
        } catch (Exception e) {
            System.out.println(e.toString());
        }
        try {
            pb = new ProcessBuilder();
            pb.redirectErrorStream(true);
            comando = "/usr/bin/gksudo touch /bin/foo";
            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" + exitVal);
        } catch (Exception e) {
            System.out.println(e.toString());
        }
}

thanks,

fabio


On Sat, 2010-01-16 at 13:50 +0100, Jan Ceuleers wrote:
> Fabio A. Miranda wrote:
> > I need gksudo to always ask for password, limiting itself to elevate the
> > just fork'ed process and that is.
> 
> man sudoers:
> 
> passwd_timeout  Number of minutes before the sudo password prompt times
>                 out.  The default is 0; set this to 0 for no password
>                 timeout.





More information about the ubuntu-devel mailing list