/* * The actual work. * Return values: -1 = unknown error, 0 = ok, >0 = error code. */ int ChfnProcess::ConverseChfn(const char *pass) { int status=-1; QCString line; while(1) { line = readLine(); if ( line.isEmpty() ) continue;// discard line if ( line.contains( "Password: "******"password" )*/ ) { WaitSlave(); write(m_Fd, pass, strlen(pass)); write(m_Fd, "\n", 1); } line = readLine(); // Let's see what the outcome was if ( line.contains( "Changing finger info" ) ) { // do nothing } else if ( line.contains( "information changed" ) ) { status=0; break; } else if ( line.isEmpty() ) { status=0; break; } else if ( line.contains( "Password error" ) || line.contains("Incorrect password") ) { status=PasswordError; break; } else { status=MiscError; m_Error=line; break; } } return status; }
int SshProcess::ConverseSsh(const char *password, int check) { unsigned i, j, colon; QCString line; int state = 0; while(state < 2) { line = readLine(); const uint len = line.length(); if(line.isNull()) return -1; switch(state) { case 0: // Check for "kdesu_stub" header. if(line == "kdesu_stub") { unreadLine(line); return 0; } // Match "Password: "******"\n", 1); state++; break; } // Warning/error message. m_Error += line; m_Error += "\n"; if(m_bTerminal) fprintf(stderr, "ssh: %s\n", line.data()); break; case 1: if(line.isEmpty()) { state++; break; } return -1; } } return 0; }
int PasswdProcess::ConversePasswd(const char *oldpass, const char *newpass, int check) { QCString line, errline; int state = 0; while(state != 7) { line = readLine(); if(line.isNull()) { return -1; } if(state == 0 && isPrompt(line, "new")) // If root is changing a user's password, // passwd can't prompt for the original password. // Therefore, we have to start at state=2. state = 2; switch(state) { case 0: // Eat garbage, wait for prompt m_Error += line + "\n"; if(isPrompt(line, "password")) { WaitSlave(); write(m_Fd, oldpass, strlen(oldpass)); write(m_Fd, "\n", 1); state++; break; } if(m_bTerminal) fputs(line, stdout); break; case 1: case 3: case 6: // Wait for \n if(line.isEmpty()) { state++; break; } // error return -1; case 2: m_Error = ""; if(line.contains("again")) { m_Error = line; kill(m_Pid, SIGKILL); waitForChild(); return PasswordIncorrect; } // Wait for second prompt. errline = line; // use first line for error message while(!isPrompt(line, "new")) { line = readLine(); if(line.isNull()) { // We didn't get the new prompt so assume incorrect password. if(m_bTerminal) fputs(errline, stdout); m_Error = errline; return PasswordIncorrect; } } // we have the new prompt if(check) { kill(m_Pid, SIGKILL); waitForChild(); return 0; } WaitSlave(); write(m_Fd, newpass, strlen(newpass)); write(m_Fd, "\n", 1); state++; break; case 4: // Wait for third prompt if(isPrompt(line, "re")) { WaitSlave(); write(m_Fd, newpass, strlen(newpass)); write(m_Fd, "\n", 1); state += 2; break; } // Warning or error about the new password if(m_bTerminal) fputs(line, stdout); m_Error = line + "\n"; state++; break; case 5: // Wait for either a "Reenter password" or a "Enter password" prompt if(isPrompt(line, "re")) { WaitSlave(); write(m_Fd, newpass, strlen(newpass)); write(m_Fd, "\n", 1); state++; break; } else if(isPrompt(line, "password")) { kill(m_Pid, SIGKILL); waitForChild(); return PasswordNotGood; } if(m_bTerminal) fputs(line, stdout); m_Error += line + "\n"; break; } } // Are we ok or do we still get an error thrown at us? m_Error = ""; state = 0; while(state != 1) { line = readLine(); if(line.isNull()) { // No more input... OK return 0; } if(isPrompt(line, "password")) { // Uh oh, another prompt. Not good! kill(m_Pid, SIGKILL); waitForChild(); return PasswordNotGood; } m_Error += line + "\n"; // Collect error message } kdDebug(1512) << k_lineinfo << "Conversation ended successfully.\n"; return 0; }