summaryrefslogtreecommitdiffstats
path: root/tdepasswd/kcm/chfnprocess.cpp
diff options
context:
space:
mode:
authorSlávek Banko <[email protected]>2013-07-22 01:21:51 +0200
committerSlávek Banko <[email protected]>2013-07-22 01:23:57 +0200
commit763b290f0123855a1d9e8fde0583297e0ce5941b (patch)
tree9f7530fc18be8ce9efd93117567146b0dccdc063 /tdepasswd/kcm/chfnprocess.cpp
parent08390bda6cc11917a625253a98e48da9b0aac8e6 (diff)
downloadtdebase-763b290f0123855a1d9e8fde0583297e0ce5941b.tar.gz
tdebase-763b290f0123855a1d9e8fde0583297e0ce5941b.zip
Rename kdepasswd -> tdepasswd
Diffstat (limited to 'tdepasswd/kcm/chfnprocess.cpp')
-rw-r--r--tdepasswd/kcm/chfnprocess.cpp100
1 files changed, 100 insertions, 0 deletions
diff --git a/tdepasswd/kcm/chfnprocess.cpp b/tdepasswd/kcm/chfnprocess.cpp
new file mode 100644
index 000000000..72c1599fc
--- /dev/null
+++ b/tdepasswd/kcm/chfnprocess.cpp
@@ -0,0 +1,100 @@
+/***************************************************************************
+ * Copyright 2003 Braden MacDonald <[email protected]> *
+ * Copyright 2003 Ravikiran Rajagopal <[email protected]> *
+ * *
+ * 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 tdepasswd.
+ */
+
+#include <unistd.h>
+#include <stdlib.h>
+
+#include <tqcstring.h>
+
+#include <tdesu/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;
+
+ TQCString 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;
+}
+