It did not work for either the '\n' nor the
PrintWriter! Do you have an idea why? I will address
the security issues later, this is an exercise only to
show that our company can use such a technique.

Any ideas?

Thanks.


<%@ page import="java.io.DataInputStream"%>
<%@ page import="java.io.PrintWriter"%>

<%@ page import="java.io.BufferedWriter"%>
<%@ page import="java.io.FileWriter"%>
<%@ page import="java.io.IOException"%>



<%

String username = "testUserId";

String old_p_word = "oldPassword";

String new_p_word = "newPassword";

   Process proc = null;
  
         
    Runtime thisRun = Runtime.getRuntime();
    
    String cmd = "passwd " + username;
    
    proc = thisRun.exec(cmd); 
   

//Returns a Stream connected to the output of the
child process. 
   
 DataInputStream inputstream = new
DataInputStream(proc.getInputStream());
 //Reads output from process
 
 String procOutputline = inputstream.readLine();
   
    if (procOutputline != null)
    {
       out.println("Process output: " +
procOutputline);
    }
    
//Returns a Stream connected to the input of the child
process. 
//we assume user exists and that the process will ask
for the old password first.

PrintWriter pw = new
PrintWriter(proc.getOutputStream());
pw.println(old_p_word);

 
//read output from process. We assume that the process
will ask for the new password
 procOutputline = inputstream.readLine();
    
     if (procOutputline != null)
     {
        out.println("Process output: " +
procOutputline);
    }

//send value of new password to the process.    
pw.println(new_p_word);


//Process should ask us to confirm the new password
//Returns a Stream connected to the output of the
child process. 

 procOutputline = inputstream.readLine();
    
     if (procOutputline != null)
     {
        out.println("Process output: " +
procOutputline);
    }

//confirm the new password to the process.    
pw.println(new_p_word);


 //Waits for the subprocess to complete. 
// proc.waitFor();

 //Returns the exit value for the subprocess.    
   out.println("Process existed with value: "
+proc.exitValue());
 
 //Returns the an InputStream connected to the error
stream of the child process. 
    DataInputStream errorinputstream = new
DataInputStream(proc.getErrorStream());
     String line = errorinputstream.readLine();
    
     if (line != null)
     {
        throw new Exception("There was a problem
setting up account: " + username + " --" + line);
     }
    
    //out.println("The output string is
"+proc.toString()); 
    proc.destroy(); 
  
  
%>



--- Randy Layman <[EMAIL PROTECTED]> wrote:
> 
>       1.  I believe that you want a PrintWriter or add \n
> to the end of
> the passwords (the user presses enter when running
> passwd).  This is
> probably causing your symptom of nothing happening
> (passwd waiting for you,
> you waiting for passwd).
>       2.  Only some users (maybe just root) can change
> other user's
> passwords.  You will need to run Tomcat as root,
> which introduces its own
> set of security issues.
> 
>       Randy
> 


__________________________________________________
Do You Yahoo!?
Send FREE Valentine eCards with Yahoo! Greetings!
http://greetings.yahoo.com

--
To unsubscribe:   <mailto:[EMAIL PROTECTED]>
For additional commands: <mailto:[EMAIL PROTECTED]>
Troubles with the list: <mailto:[EMAIL PROTECTED]>

Reply via email to