RandomQuestions RandomQuestions - 10 months ago 88
Java Question

Changing SAMBA Password in Java

I have a Java program running on linux that needs to be able to both set a users initial samba password, and then allow them to change their password without giving them access to the terminal.

Below is my code for changing the users password, as this is easier to test with, and I will be able to figure the other part out once I get this worked out.

The -s flag is supposed to allow stdin to be used.

String cmd = "smbpasswd -s -U user";
Process p = Runtime.getRuntime().exec(cmd);
OutputStreamWriter Out = new OutputStreamWriter(p.getOutputStream());
InputStreamReader In = new InputStreamReader(p.getInputStream());
BufferedWriter Write = new BufferedWriter(Out);
BufferedReader Read = new BufferedReader(In);
char[] output = null;

//I write all of the output lines to the log, but nothing is written, and the password doesn't change.

I need some help to figure out what I am doing wrong, and how I would go about this correctly. Any help is appreciated.


According to the man page for SMBPASSWD(8):

-s: This option causes smbpasswd to be silent (i.e. not issue prompts) and to read its old and new passwords from standard input, rather than from /dev/tty (like the passwd(1) program does). This option is to aid people writing scripts to drive smbpasswd

Emphasis on "not issue prompts". If I'm reading your code correctly, you seem to be waiting for prompts from the utility, which won't come (test it from the command line). But I may have misinterpreted your Java code.