summaryrefslogtreecommitdiffstats
path: root/kdepasswd/kcm/chfnprocess.cpp
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commit4aed2c8219774f5d797760606b8489a92ddc5163 (patch)
tree3f8c130f7d269626bf6a9447407ef6c35954426a /kdepasswd/kcm/chfnprocess.cpp
downloadtdebase-4aed2c8219774f5d797760606b8489a92ddc5163.tar.gz
tdebase-4aed2c8219774f5d797760606b8489a92ddc5163.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdebase@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kdepasswd/kcm/chfnprocess.cpp')
-rw-r--r--kdepasswd/kcm/chfnprocess.cpp100
1 files changed, 100 insertions, 0 deletions
diff --git a/kdepasswd/kcm/chfnprocess.cpp b/kdepasswd/kcm/chfnprocess.cpp
new file mode 100644
index 000000000..ec39a152a
--- /dev/null
+++ b/kdepasswd/kcm/chfnprocess.cpp
@@ -0,0 +1,100 @@
+/***************************************************************************
+ * Copyright 2003 Braden MacDonald <bradenm_k@shaw.ca> *
+ * Copyright 2003 Ravikiran Rajagopal <ravi@ee.eng.ohio-state.edu> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License (version 2) as *
+ * published by the Free Software Foundation. *
+ * *
+ ***************************************************************************/
+
+/**
+ * @file Change a user's 'finger' information, specifically their full name.
+ * derived from kdepasswd.
+ */
+
+#include <unistd.h>
+#include <stdlib.h>
+
+#include <qcstring.h>
+
+#include <kdesu/process.h>
+#include <kdebug.h>
+#include <kdebug.h>
+#include "chfnprocess.h"
+
+
+int ChfnProcess::exec(const char *pass, const char *name)
+{
+ // Try to set the default locale to make the parsing of the output
+ // of `chfn' easier.
+ putenv((char*)"LC_ALL=C");
+
+ QCStringList args;
+ args += "-f";
+ args += name;
+ int ret = PtyProcess::exec("chfn", args);
+ if (ret < 0)
+ return ChfnNotFound;
+
+ ret = ConverseChfn(pass);
+
+ waitForChild();
+ return ret;
+}
+
+
+/*
+ * 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: " )/*isPrompt( line, "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;
+}
+