Handle different versions of "passwd" (BR56860)

svn path=/trunk/kdeutils/kdepasswd/; revision=225788
This commit is contained in:
Waldo Bastian 2003-05-14 11:03:33 +00:00
parent 6ec02913e8
commit dd831c76aa
4 changed files with 56 additions and 18 deletions

View file

@ -63,8 +63,6 @@ int main(int argc, char **argv)
KDEpasswd2Dialog *dlg = new KDEpasswd2Dialog(oldpass, user);
dlg->exec();
if (dlg->result() == KDEpasswd2Dialog::Accepted)
KMessageBox::information(0L, i18n("Your password has been changed."));
return 0;
}

View file

@ -92,9 +92,11 @@ int PasswdProcess::exec(const char *oldpass, const char *newpass,
ret = ConversePasswd(oldpass, newpass, check);
if (ret < 0)
kdDebug(1512) << k_lineinfo << "Conversation with passwd failed.\n";
kdDebug(1512) << k_lineinfo << "Conversation with passwd failed. pid = " << pid() << endl;
if ((waitForChild() != 0) && !check)
return PasswordNotGood;
waitForChild();
return ret;
}
@ -222,6 +224,27 @@ int PasswdProcess::ConversePasswd(const char *oldpass, const char *newpass,
}
}
// 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;
}

View file

@ -34,9 +34,15 @@ bool KDEpasswd1Dialog::checkPassword(const char *password)
switch (ret)
{
case -1:
KMessageBox::error(this, i18n("Conversation with `passwd' failed:\n")+QString::fromLocal8Bit(proc.error()));
{
QString msg = QString::fromLocal8Bit(proc.error());
if (!msg.isEmpty())
msg = "<p>\"<i>" + msg + "</i>\"";
msg = "<qt>" + i18n("Conversation with `passwd' failed.") + msg;
KMessageBox::error(this, msg);
done(Rejected);
return false;
}
case 0:
return true;
@ -124,20 +130,34 @@ bool KDEpasswd2Dialog::checkPassword(const char *password)
switch (ret)
{
case 0:
if (!proc.error().isEmpty())
{
// The pw change succeeded but there is a warning.
KMessageBox::information(this, proc.error());
}
return true;
{
hide();
QString msg = QString::fromLocal8Bit(proc.error());
if (!msg.isEmpty())
msg = "<p>\"<i>" + msg + "</i>\"";
msg = "<qt>" + i18n("Your password has been changed.") + msg;
KMessageBox::information(0L, msg);
return true;
}
case PasswdProcess::PasswordNotGood:
// The pw change did not succeed. Print the error.
KMessageBox::sorry(this, proc.error());
return false;
{
QString msg = QString::fromLocal8Bit(proc.error());
if (!msg.isEmpty())
msg = "<p>\"<i>" + msg + "</i>\"";
msg = "<qt>" + i18n("Your password has not been changed.") + msg;
// The pw change did not succeed. Print the error.
KMessageBox::sorry(this, msg);
return false;
}
default:
KMessageBox::sorry(this, i18n("Conversation with `passwd' failed."));
QString msg = QString::fromLocal8Bit(proc.error());
if (!msg.isEmpty())
msg = "<p>\"<i>" + msg + "</i>\"";
msg = "<qt>" + i18n("Conversation with `passwd' failed.") + msg;
KMessageBox::sorry(this, msg);
done(Rejected);
return true;
}

View file

@ -259,9 +259,6 @@ void KUserInfoConfig::slotChangePassword()
KDEpasswd2Dialog *dlg = new KDEpasswd2Dialog(oldpass, user);
dlg->exec();
if (dlg->result() == KDEpasswd2Dialog::Accepted)
KMessageBox::information(0L, i18n("Your password has been changed."));
delete dlg;
}