From 5f63c8c248fffd4594543d2d204c7ca6d595b72e Mon Sep 17 00:00:00 2001
From: Timothy Pearson <kb9vqf@pearsoncomputing.net>
Date: Sun, 6 Nov 2011 15:56:15 -0600
Subject: Actually move the kde files that were renamed in the last commit

---
 kdesudo/Makefile.am |  64 --------
 kdesudo/kdesudo.cpp | 446 ----------------------------------------------------
 kdesudo/kdesudo.h   |  98 ------------
 kdesudo/main.cpp    | 149 ------------------
 tdesudo/Makefile.am |  64 ++++++++
 tdesudo/main.cpp    | 149 ++++++++++++++++++
 tdesudo/tdesudo.cpp | 446 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 tdesudo/tdesudo.h   |  98 ++++++++++++
 8 files changed, 757 insertions(+), 757 deletions(-)
 delete mode 100644 kdesudo/Makefile.am
 delete mode 100644 kdesudo/kdesudo.cpp
 delete mode 100644 kdesudo/kdesudo.h
 delete mode 100644 kdesudo/main.cpp
 create mode 100644 tdesudo/Makefile.am
 create mode 100644 tdesudo/main.cpp
 create mode 100644 tdesudo/tdesudo.cpp
 create mode 100644 tdesudo/tdesudo.h

diff --git a/kdesudo/Makefile.am b/kdesudo/Makefile.am
deleted file mode 100644
index 354f75a..0000000
--- a/kdesudo/Makefile.am
+++ /dev/null
@@ -1,64 +0,0 @@
-####### kdevelop will overwrite this part!!! (begin)##########
-bin_PROGRAMS = tdesudo
-
-## INCLUDES were found outside kdevelop specific part
-
-tdesudo_SOURCES = tdesudo.cpp main.cpp 
-tdesudo_LDADD   =  $(LIB_QT) $(LIB_KDECORE) $(LIB_KDEUI)  $(LIBSOCKET) -ltdesu
-
-
-EXTRA_DIST = main.cpp tdesudo.cpp tdesudo.h
-
-install-data-local:
-
-uninstall-local:
-
-####### kdevelop will overwrite this part!!! (end)############
-# These paths are KDE specific. Use them:
-# kde_appsdir         Where your application's menu entry (.desktop) should go to.
-# kde_icondir         Where your icon should go to - better use KDE_ICON.
-# kde_sounddir        Where your sounds should go to.
-# kde_htmldir         Where your docs should go to. (contains lang subdirs)
-# kde_datadir         Where you install application data. (Use a subdir)
-# kde_locale          Where translation files should go to. (contains lang subdirs)
-# kde_cgidir          Where cgi-bin executables should go to.
-# kde_confdir         Where config files should go to (system-wide ones with default values).
-# kde_mimedir         Where mimetypes .desktop files should go to.
-# kde_servicesdir     Where services .desktop files should go to.
-# kde_servicetypesdir Where servicetypes .desktop files should go to.
-# kde_toolbardir      Where general toolbar icons should go to (deprecated, use KDE_ICON).
-# kde_wallpaperdir    Where general wallpapers should go to.
-# kde_templatesdir    Where templates for the "New" menu (Konqueror/KDesktop) should go to.
-# kde_bindir          Where executables should go to. Use bin_PROGRAMS or bin_SCRIPTS.
-# kde_libdir          Where shared libraries should go to. Use lib_LTLIBRARIES.
-# kde_moduledir       Where modules (e.g. parts) should go to. Use kde_module_LTLIBRARIES.
-# kde_styledir        Where Qt/KDE widget styles should go to (new in KDE 3).
-# kde_designerdir     Where Qt Designer plugins should go to (new in KDE 3).
-
-# set the include path for X, qt and KDE
-INCLUDES= $(all_includes)
-
-METASOURCES = AUTO
-
-# the library search path. 
-tdesudo_LDFLAGS = $(all_libraries) $(KDE_RPATH) $(LIB_QT) -lDCOP $(LIB_KDECORE) $(LIB_KDEUI) -ltdefx $(LIB_KIO) -lktexteditor
-
-# Uncomment the following two lines if you add a ui.rc file for your application to make use of
-# KDE?s XML GUI builing
-#rcdir = $(kde_datadir)/tdesudo
-#rc_DATA = tdesudoui.rc
-
-#WARNING: if you use a ui.rc file above, use:
-
-# messages: rc.cpp
-
-# instead of 
-
-# messages:
-
-messages: 
-	LIST=`find . -name \*.h -o -name \*.hh -o -name \*.H -o -name \*.hxx -o -name \*.hpp -o -name \*.cpp -o -name \*.cc -o -name \*.cxx -o -name \*.ecpp -o -name \*.C`; \
-	if test -n "$$LIST"; then \
-	 $(XGETTEXT) $$LIST -o $(podir)/tdesudo.pot; \
-	fi
-
diff --git a/kdesudo/kdesudo.cpp b/kdesudo/kdesudo.cpp
deleted file mode 100644
index 5649da6..0000000
--- a/kdesudo/kdesudo.cpp
+++ /dev/null
@@ -1,446 +0,0 @@
-/***************************************************************************
-                          tdesudo.cpp  -  description
-                             -------------------
-    begin                : Sam Feb 15 15:42:12 CET 2003
-    copyright            : (C) 2003 by Robert Gruber <rgruber@users.sourceforge.net>
-                           (C) 2007 by Martin Böhm <martin.bohm@kubuntu.org>
-                                       Anthony Mercatante <tonio@kubuntu.org>
-                                       Canonical Ltd (Jonathan Riddell <jriddell@ubuntu.com>)
-                           (C) 2011 by Timothy Pearson <kb9vqf@pearsoncomputing.net>
-
- ***************************************************************************/
-
-/***************************************************************************
- *                                                                         *
- *   This program is free software; you can redistribute it and/or modify  *
- *   it under the terms of the GNU General Public License as published by  *
- *   the Free Software Foundation; either version 2 of the License, or     *
- *   (at your option) any later version.                                   *
- *                                                                         *
- ***************************************************************************/
-
-#include "tdesudo.h"
-
-#include <tqfile.h>
-#include <tqdir.h>
-#include <tqdatastream.h>
-#include <tqstring.h>
-
-#include <kcmdlineargs.h>
-#include <klocale.h>
-#include <kmessagebox.h>
-#include <kpushbutton.h>
-#include <kpassdlg.h>
-#include <kstandarddirs.h>
-#include <tdesu/kcookie.h>
-#include <kdebug.h>
-#include <kshell.h>
-#include <ktempfile.h>
-
-#include <iostream>
-#include <cstdio>
-#include <cstdlib>
-#include <signal.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-
-KdeSudo::KdeSudo(TQWidget *parent, const char *name,const TQString& icon, const TQString& generic, bool withIgnoreButton)
-	: KPasswordDialog(KPasswordDialog::Password, false, (withIgnoreButton ? User1: false), icon, parent, name)
-{
-	KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
-
-	TQString defaultComment = i18n("<b>%1</b> needs administrative privileges. Please enter your password for verification.");
-	p=NULL;
-	bError=false;
-
-	m_pCookie = new KCookie;
-
-	// Set vars
-	bool newDcop = args->isSet("newdcop");
-	bool realtime = args->isSet("r");
-	bool priority = args->isSet("p");
-	bool showCommand = (!args->isSet("d"));
-	bool keepCurrentHome = true;
-	bool changeUID = true;
-	bool noExec = false;
-	keepPwd = (!args->isSet("n"));
-	emptyPwd = args->isSet("s");
-	TQString runas = args->getOption("u");
-	TQString cmd;
-
-	if (!args->isSet("c") && !args->count() && (!args->isSet("s")))
-	{
-		KMessageBox::information(NULL, i18n("No command arguments supplied!\nUsage: tdesudo [-u <runas>] <command>\nKdeSudo will now exit..."));
-		noExec = true;
-	}
-
-	p = new KProcess;
-	p->clearArguments();
-
-	// Parsins args
-
-	/* Get the comment out of cli args */
-	TQByteArray commentBytes = args->getOption("comment");
-	TQTextCodec* tCodecConv = TQTextCodec::codecForLocale();
-	TQString comment = tCodecConv->toUnicode(commentBytes, commentBytes.size());
-
-	if (args->isSet("f"))
-	{
-		// If file is writeable, do not change uid
-		TQString filename = TQFile::decodeName(args->getOption("f"));
-		TQString file = filename;
-		if (!file.isEmpty())
-		{
-			if (file.at(0) != '/')
-			{
-				KStandardDirs dirs;
-				dirs.addKDEDefaults();
-				file = dirs.findResource("config", file);
-				if (file.isEmpty())
-				{
-					kdError(1206) << "Config file not found: " << file << "\n";
-					exit(1);
-				}
-			}
-			TQFileInfo fi(file);
-			if (!fi.exists())
-			{
-				kdError(1206) << "File does not exist: " << file << "\n";
-				exit(1);
-			}
-			if (fi.isWritable())
-			{
-				changeUID = false;
-			}
-		}
-	}
-
-	if (withIgnoreButton)
-	{
-		setButtonText(User1, i18n("&Ignore"));
-	}
-
-	// Apologies for the C code, taken from kdelibs/tdesu/tdesu_stub.c
-	// KControl and other places need to use the user's existing DCOP server
-	// For that we set DCOPSERVER.  Create a file in /tmp and use iceauth to add magic cookies
-	// from the existing server and set ICEAUTHORITY to point to the file
-	if (!newDcop) {
-		dcopServer = m_pCookie->dcopServer();
-		TQCString dcopAuth = m_pCookie->dcopAuth();
-		TQCString iceAuth = m_pCookie->iceAuth();
-
-		FILE *fout;
-		char iceauthority[200];
-		char *host, *auth;
-		host = qstrdup(dcopServer);
-		auth = qstrdup(iceAuth);
-		int tempfile;
-		int oldumask = umask(077);
-
-		strcpy(iceauthority, "/tmp/iceauth.XXXXXXXXXX");
-		tempfile = mkstemp(iceauthority);
-		umask(oldumask);
-		if (tempfile == -1) {
-			kdError() << "error in tdesudo mkstemp" << endl;
-			exit(1);
-		} else {
-			// close(tempfile); //FIXME why does this make the connect() call later crash?
-		}
-		iceauthorityFile = iceauthority;
-		//FIXME we should change owner of iceauthority file, but don't have permissions
-		setenv("ICEAUTHORITY", iceauthorityFile, 1);
-	
-		fout = popen("iceauth >/dev/null 2>&1", "w");
-		if (!fout) {
-			kdError() << "error in tdesudo running iceauth" << endl;
-			exit(1);
-		}
-		fprintf(fout, "add ICE \"\" %s %s\n", host, auth);
-		auth = qstrdup(dcopAuth);
-		//auth = xstrsep(params[P_DCOP_AUTH].value);
-		fprintf(fout, "add DCOP \"\" %s %s\n", host, auth);
-		unsetenv("ICEAUTHORITY");
-		pclose(fout);
-
-		// Exporting the user's sycoca
-		kdeSycoca = TQFile::encodeName(locateLocal("cache", "ksycoca"));
-	}
-
-	connect( p, TQT_SIGNAL(receivedStdout(KProcess*, char*, int)), this, TQT_SLOT(receivedOut(KProcess*, char*, int)) );
-	connect( p, TQT_SIGNAL(receivedStderr(KProcess*, char*, int)), this, TQT_SLOT(receivedOut(KProcess*, char*, int)) );
-	connect( p, TQT_SIGNAL(processExited (KProcess *)), this, TQT_SLOT(procExited(KProcess*)));
-
-	TQString xauthenv = TQString(getenv("HOME")) + "/.Xauthority";
-	p->setEnvironment("XAUTHORITY", xauthenv);
-
-	// Generate the xauth cookie and put it in a tempfile
-	// set the environment variables to reflect that.
-	// Default cookie-timeout is 60 sec. .
-	// 'man xauth' for more info on xauth cookies.
-	
-	KTempFile temp = KTempFile("/tmp/tdesudo-","-xauth");
-	m_tmpname = temp.name();
-	
-	FILE *f;
-	char buf[1024];
-	
-	TQCString disp = m_pCookie->display();
-	// command: xauth -q -f m_tmpname generate $DISPLAy . trusted timeout 60
-	TQString c = "/usr/bin/xauth -q -f " + m_tmpname + " generate " 
-		+ TQString::fromLocal8Bit(disp) + " . trusted timeout 60";
-	blockSigChild(); // pclose uses waitpid()
-	
-	if (!(f = popen(c, "r"))) {
-		kdWarning() << k_lineinfo << "Cannot run: " << c << "\n";
-		unblockSigChild();
-		return;
-	}
-	
-	// non root users need to be able to read the xauth file.
-	// the xauth file is deleted when tdesudo exits. security?
-	TQFile tf(m_tmpname);
-	if (!runas.isEmpty() && runas != "root" && tf.exists())
-		chmod(m_tmpname.ascii(),0644);
-	
-	QCStringList output;
-	while (fgets(buf, 1024, f) > 0)
-		output += buf; 
-	if (pclose(f) < 0) {
-		kdError() << k_lineinfo << "Could not run xauth.\n";
-		unblockSigChild();
-		return;
-	}
-	unblockSigChild();
-	
-	p->setEnvironment("DISPLAY", disp); 
-	p->setEnvironment("XAUTHORITY", m_tmpname);
-
-	if (emptyPwd)
-		*p << "sudo" << "-k";
-	else
-	{
-		if (changeUID)
-		{
-			*p << "sudo";
-
-			if (!keepCurrentHome)
-				*p << "-H";
-
-			*p << "-S" << "-p" << "passprompt";
-
-			if (!runas.isEmpty())
-				*p << "-u" << runas;
-		}
-
-		if (!dcopServer.isEmpty())
-			*p << "DCOPSERVER=" + dcopServer;
-
-		if (!iceauthorityFile.isEmpty())
-			*p << "ICEAUTHORITY=" + iceauthorityFile;
-
-		if (!kdeSycoca.isEmpty())
-			*p << "KDESYCOCA=" + kdeSycoca;
-
-		if (realtime)
-		{
-			*p << "nice" << "-n" << "10";
-			addLine(i18n("Priority:"), i18n("realtime:") + TQChar(' ') + TQString("50/100"));
-		}
-		else if (priority)
-		{
-			TQString n = args->getOption("p");
-			int intn = atoi(n);
-			intn =  (intn * 40 / 100) - (20 + 0.5);
-		
-			TQString strn;
-			strn.sprintf("%d",intn);
-
-			*p << "nice" << "-n" << strn;
-			addLine(i18n("Priority:"), n + TQString("/100"));
-		}
-
-		*p << "--";
-
-		if (args->isSet("c"))
-		{
-			TQString command = args->getOption("c");
-			TQStringList commandSplit = KShell::splitArgs(command);
-			
-			for (int i = 0; i < commandSplit.count(); i++)
-			{
-				TQString arg = validArg(commandSplit[i]);
-				*p << arg;
-				if (i == 0)
-					cmd += validArg(commandSplit[i]) + TQChar(' ');
-				else
-					cmd += KProcess::quote(validArg(commandSplit[i])) + TQChar(' ');
-			}
-		}
-
-		if (args->count())
-		{
-			for (int i = 0; i < args->count(); i++)
-			{
-                                if ((!args->isSet("c")) && (i == 0))
-				{
-					TQStringList argsSplit = KShell::splitArgs(args->arg(i));
-					for (int j = 0; j < argsSplit.count(); j++)
-					{
-						*p << validArg(argsSplit[j]);
-						if (j == 0)
-							cmd += validArg(argsSplit[j]) + TQChar(' ');
-						else
-							cmd += KProcess::quote(validArg(argsSplit[j])) + TQChar(' ');
-					}
-				}
-				else
-				{
-					*p << validArg(args->arg(i));
-					cmd += validArg(args->arg(i)) + TQChar(' ');
-				}
-			}
-		}
-
-		if (showCommand && !cmd.isEmpty())
-			addLine(i18n("Command:"), cmd);
-	}
-
-	if (comment.isEmpty())
-	{
-		if (!generic.isEmpty())
-			setPrompt(defaultComment.tqarg(generic));
-		else
-			setPrompt(defaultComment.tqarg(cmd));
-	}
-	else
-		setPrompt(comment);
-
-	if (noExec)
-		exit(0);
-	else
-		p->start( KProcess::NotifyOnExit, KProcess::All );
-}
-
-KdeSudo::~KdeSudo()
-{
-}
-
-void KdeSudo::receivedOut(KProcess*, char*buffer, int buflen)
-{
-	char *pcTmp= new char[buflen+1];
-	strncpy(pcTmp,buffer,buflen);
-	pcTmp[buflen]='\0';
-	TQString strOut(pcTmp);
-
-	std::cout << strOut << std::endl;
-
-	static int badpass = 0;
-
-	if (strOut.find("Sorry, try again")!=-1)
-	{
-		badpass++;
-		if (badpass>2)
-		{
-			bError=true;
-			KMessageBox::error(this, i18n("Wrong password! Exiting..."));
-			kapp->quit();
-		}
-	}
-	if (strOut.find("command not found")!=-1)
-	{
-		bError=true;
-		KMessageBox::error(this, i18n("Command not found!"));
-		kapp->quit();
-	}
-	if (strOut.find("is not in the sudoers file")!=-1)
-	{
-		bError=true;
-		KMessageBox::error(this, i18n("Your username is unknown to sudo!"));
-                kapp->quit();
-	}
-	if (strOut.find("is not allowed to execute")!=-1)
-	{
-		bError=true;
-		KMessageBox::error(this, i18n("Your user is not allowed to run the specified command!"));
-		kapp->quit();
-	}
-	if (strOut.find("is not allowed to run sudo on")!=-1)
-	{
-		bError=true;
-		KMessageBox::error(this, i18n("Your user is not allowed to run sudo on this host!"));
-                kapp->quit();
-	}
-	if (strOut.find("may not run sudo on")!=-1)
-	{
-		bError=true;
-		KMessageBox::error(this, i18n("Your user is not allowed to run sudo on this host!"));
-                kapp->quit();
-	}
-	if ((strOut.find("passprompt")!=-1) || (strOut.find("PIN (CHV2)")!=-1))
-	{
-		this->clearPassword();
-		this->show();
-	}
-}
-
-void KdeSudo::procExited(KProcess*)
-{
-	if (!keepPwd && unCleaned)
-	{
-		unCleaned = false;
-		p->clearArguments();
-		*p << "sudo" << "-k";
-		p->start( KProcess::NotifyOnExit, KProcess::All );
-	}
-
-	if (!newDcop && !iceauthorityFile.isEmpty())
-		if (!iceauthorityFile.isEmpty())
-		TQFile::remove(iceauthorityFile);
-
-	if (!bError) {
-		if (!m_tmpname.isEmpty())
-			TQFile::remove(m_tmpname);
-		kapp->quit();
-	}
-}
-
-void KdeSudo::slotOk()
-{
-	TQString strTmp(password());
-	strTmp+="\n";
-	p->writeStdin(strTmp.ascii(),(int)strTmp.length());
-	this->hide();
-}
-
-void KdeSudo::slotUser1()
-{
-	done(AsUser);
-}
-
-void KdeSudo::blockSigChild()
-{
-	sigset_t sset;
-	sigemptyset(&sset);
-	sigaddset(&sset, SIGCHLD);
-	sigprocmask(SIG_BLOCK, &sset, 0L);
-}
-void KdeSudo::unblockSigChild()
-{
-	sigset_t sset;
-	sigemptyset(&sset);
-	sigaddset(&sset, SIGCHLD);
-	sigprocmask(SIG_UNBLOCK, &sset, 0L);
-}
-
-TQString KdeSudo::validArg(TQString arg)
-{
-	TQChar firstChar = arg.at(0);
-	TQChar lastChar = arg.at(arg.length() - 1);
-
-	if ( (firstChar == '"' && lastChar == '"') || (firstChar == '\'' && lastChar == '\'') )
-	{
-		arg = arg.remove(0, 1);
-		arg = arg.remove(arg.length() - 1, 1);
-	}
-	return arg;
-}
diff --git a/kdesudo/kdesudo.h b/kdesudo/kdesudo.h
deleted file mode 100644
index 61b4f13..0000000
--- a/kdesudo/kdesudo.h
+++ /dev/null
@@ -1,98 +0,0 @@
-/***************************************************************************
-                          tdesudo.cpp  -  description
-                             -------------------
-    begin                : Sam Feb 15 15:42:12 CET 2003
-    copyright            : (C) 2003 by Robert Gruber <rgruber@users.sourceforge.net>
-                           (C) 2007 by Martin Böhm <martin.bohm@kubuntu.org>
-                                       Anthony Mercatante <tonio@kubuntu.org>
-                                       Canonical Ltd (Jonathan Riddell <jriddell@ubuntu.com>)
-
- ***************************************************************************/
-
-/***************************************************************************
- *                                                                         *
- *   This program is free software; you can redistribute it and/or modify  *
- *   it under the terms of the GNU General Public License as published by  *
- *   the Free Software Foundation; either version 2 of the License, or     *
- *   (at your option) any later version.                                   *
- *                                                                         *
- ***************************************************************************/
-
-#ifndef KDESUDO_H
-#define KDESUDO_H
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <kapp.h>
-#include <tqwidget.h>
-#include <kpassdlg.h>
-#include <tqstring.h>
-#include <tqtextcodec.h>
-#include <kprocess.h>
-class KCookie;
-
-/*
-* KdeSudo is the base class of the project
-*
-* It inherits KPasswordDialog and overrrides the
-* slot slotOK()
-*
-* @author Robert Gruber <rgruber@users.sourceforge.net>
-* @version 2.4
-*/
-
-class KdeSudo : public KPasswordDialog
-{
-	Q_OBJECT
-	TQ_OBJECT
-
-public:
-	/*
-	* Default construtor
-	*/
-	KdeSudo(TQWidget* parent=0, const char *name=0, const TQString& icon=TQString(), const TQString& generic=TQString(), bool withIgnoreButton=false);
-
-	/*
-	* Default destructor
-	*/
-	~KdeSudo();
-	enum ResultCodes { AsUser = 10 };
-
-public slots: // Public slots
-	/*
-	* This slot gets exectuted if sudo creates some output
-	*/
-	void receivedOut(KProcess*proc, char*buffer, int buflen);
-	/*
-	* This slot gets exectuted when sudo exits
-	*/
-	void procExited(KProcess *proc);
-	/*
-	* This slot overrides the slot from KPasswordDialog
-	* @see KPasswordDialog
-	*/
-	void slotOk();
-	void slotUser1();
-	TQString validArg(TQString arg);
-
-private: // Private attributes
-	KProcess * p;
-	bool bError;
-	bool newDcop;
-	bool keepPwd;
-	bool emptyPwd;
-	bool useTerm;
-	bool noExec;
-	bool unCleaned;
-	TQString m_tmpname;
-	TQString iceauthorityFile;
-	TQString dcopServer;
-	TQString kdeSycoca;
-	KCookie* m_pCookie;
-	void blockSigChild();
-	void unblockSigChild();
-};
-
-#endif
diff --git a/kdesudo/main.cpp b/kdesudo/main.cpp
deleted file mode 100644
index 9fa63f1..0000000
--- a/kdesudo/main.cpp
+++ /dev/null
@@ -1,149 +0,0 @@
-/***************************************************************************
-                          tdesudo.cpp  -  description
-                             -------------------
-    begin                : Sam Feb 15 15:42:12 CET 2003
-    copyright            : (C) 2003 by Robert Gruber <rgruber@users.sourceforge.net>
-                           (C) 2007 by Martin Böhm <martin.bohm@kubuntu.org>
-                                       Anthony Mercatante <tonio@kubuntu.org>
-                                       Canonical Ltd (Jonathan Riddell <jriddell@ubuntu.com>)
-                           (C) 2011 by Timothy Pearson <kb9vqf@pearsoncomputing.net>
-
- ***************************************************************************/
-
-/***************************************************************************
- *                                                                         *
- *   This program is free software; you can redistribute it and/or modify  *
- *   it under the terms of the GNU General Public License as published by  *
- *   the Free Software Foundation; either version 2 of the License, or     *
- *   (at your option) any later version.                                   *
- *                                                                         *
- ***************************************************************************/
-
-#include <cstdlib>
-
-#include <kcmdlineargs.h>
-#include <kaboutdata.h>
-#include <klocale.h>
-
-#include "tdesudo.h"
-#include <kmessagebox.h>
-#include <kdesktopfile.h>
-#include <kiconloader.h>
-#include <kicontheme.h>
-#include <kglobal.h>
-#include <kstandarddirs.h>
-#include <kprocess.h>
-#include <kdebug.h>
-#include <tqfile.h>
-#include <tqfileinfo.h>
-
-static const char *description =
-	I18N_NOOP("KdeSudo");
-// INSERT A DESCRIPTION FOR YOUR APPLICATION HERE
-
-
-static KCmdLineOptions options[] =
-{
-	{ "u <runas>", I18N_NOOP("sets a runas user"), 0 },
-	{ "c <command>", I18N_NOOP("The command to execute"), 0 },
-	{ "s", I18N_NOOP("Forget passwords"), 0 },
-	{ "i <icon name>", I18N_NOOP("Specify icon to use in the password dialog"), 0},
-	{ "d", I18N_NOOP("Do not show the command to be run in the dialog"), 0},
-	{ "p <priority>", I18N_NOOP("Process priority, between 0 and 100, 0 the lowest [50]"), 0},
-	{ "r", I18N_NOOP("Use realtime scheduling"), 0},
-	{ "f <file>", I18N_NOOP("Use target UID if <file> is not writeable"), 0},
-	{ "t", I18N_NOOP("Fake option for KDE's KdeSu compatibility"), 0 },
-	{ "n", I18N_NOOP("Do not keep password"), 0},
-	{ "nonewdcop", I18N_NOOP("Use existing DCOP server"), 0},
-	{ "comment <dialog text>", I18N_NOOP("The comment that should be displayed in the dialog"),  0},
-	{ "noignorebutton", I18N_NOOP("Do not display « ignore » button"), 0 },
-	{ "+command", I18N_NOOP("The command to execute"), 0 },
-	KCmdLineLastOption
-};
-
-int main(int argc, char **argv)
-{
-	KAboutData aboutData("tdesudo", I18N_NOOP("KdeSudo"),
-		VERSION, description, KAboutData::License_GPL,
-		"(c) 2007-2008, Anthony Mercatante", 0, 0, "tonio@ubuntu.com");
-	aboutData.addAuthor("Robert Gruber",0, "rgruber@users.sourceforge.net");
-	aboutData.addAuthor("Anthony Mercatante",0, "tonio@ubuntu.com");
-	KCmdLineArgs::init(argc, argv, &aboutData);
-	KCmdLineArgs::addCmdLineOptions(options); // Add our own options.
-
-	KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
-
-	KApplication a;
-
-	TQString executable;
-	TQStringList executableList;
-	TQString arg;
-	TQString command;
-	TQStringList commandlist;
-	TQString icon;
-
-	bool withIgnoreButton = args->isSet("ignorebutton");
-
-	if (args->isSet("c"))
-		executable = args->getOption("c");
-
-	if (args->count())
-	{
-		if (executable.isEmpty())
-		{
-			command = args->arg(0);
-			commandlist = TQStringList::split(TQChar(' '), command);
-			executable = commandlist[0];
-		}
-	}
-
-	if ((!args->isSet("c")) && (!args->count())) {
-		kdError() << I18N_NOOP("You must provide the name of the executable you want to run as an argument to tdesudo") << endl;
-		exit(1);
-	}
-
-	/* We have to make sure the executable is only the binary name */
-	executableList = TQStringList::split(" ", executable);
-	executable = executableList[0];
-
-	executableList = TQStringList::split("/", executable);
-	int i = executableList.count() - 1;
-	executable = executableList[i];
-
-	/* Kubuntu has a bug in it - this is a workaround for it */
-	KGlobal::dirs()->addResourceDir("apps","/usr/share/applications/kde");
-	KGlobal::dirs()->addResourceDir("apps","/usr/share/applications");
-
-	TQString deskFilePath = KGlobal::dirs()->findResource("apps",executable + ".desktop");
-	KDesktopFile desktopFile(deskFilePath,true);
-
-	/* icon parsing */
-	if (args->isSet("i"))
-		icon = args->getOption("i");
-	else
-	{
-		TQString iconName = desktopFile.readIcon();
-		icon = KGlobal::iconLoader()->iconPath(iconName, -1* KIcon::StdSizes(KIcon::SizeHuge), true);
-	}
-
-	/* generic name parsing */
-	TQString name = desktopFile.readName();
-	TQString genericName = desktopFile.readGenericName();
-
-	if (!name.isEmpty())
-	{
-		if (!genericName.isEmpty())
-		name += " - " + genericName;
-	}
-	else if (!genericName.isEmpty())
-		name = genericName;
-	else
-		name = executable;
-
-	KdeSudo *tdesudo = new KdeSudo(0,0,icon,name,withIgnoreButton);
-
-	a.setMainWidget(tdesudo);
-	args->clear();
-
-	return a.exec();
-}
diff --git a/tdesudo/Makefile.am b/tdesudo/Makefile.am
new file mode 100644
index 0000000..354f75a
--- /dev/null
+++ b/tdesudo/Makefile.am
@@ -0,0 +1,64 @@
+####### kdevelop will overwrite this part!!! (begin)##########
+bin_PROGRAMS = tdesudo
+
+## INCLUDES were found outside kdevelop specific part
+
+tdesudo_SOURCES = tdesudo.cpp main.cpp 
+tdesudo_LDADD   =  $(LIB_QT) $(LIB_KDECORE) $(LIB_KDEUI)  $(LIBSOCKET) -ltdesu
+
+
+EXTRA_DIST = main.cpp tdesudo.cpp tdesudo.h
+
+install-data-local:
+
+uninstall-local:
+
+####### kdevelop will overwrite this part!!! (end)############
+# These paths are KDE specific. Use them:
+# kde_appsdir         Where your application's menu entry (.desktop) should go to.
+# kde_icondir         Where your icon should go to - better use KDE_ICON.
+# kde_sounddir        Where your sounds should go to.
+# kde_htmldir         Where your docs should go to. (contains lang subdirs)
+# kde_datadir         Where you install application data. (Use a subdir)
+# kde_locale          Where translation files should go to. (contains lang subdirs)
+# kde_cgidir          Where cgi-bin executables should go to.
+# kde_confdir         Where config files should go to (system-wide ones with default values).
+# kde_mimedir         Where mimetypes .desktop files should go to.
+# kde_servicesdir     Where services .desktop files should go to.
+# kde_servicetypesdir Where servicetypes .desktop files should go to.
+# kde_toolbardir      Where general toolbar icons should go to (deprecated, use KDE_ICON).
+# kde_wallpaperdir    Where general wallpapers should go to.
+# kde_templatesdir    Where templates for the "New" menu (Konqueror/KDesktop) should go to.
+# kde_bindir          Where executables should go to. Use bin_PROGRAMS or bin_SCRIPTS.
+# kde_libdir          Where shared libraries should go to. Use lib_LTLIBRARIES.
+# kde_moduledir       Where modules (e.g. parts) should go to. Use kde_module_LTLIBRARIES.
+# kde_styledir        Where Qt/KDE widget styles should go to (new in KDE 3).
+# kde_designerdir     Where Qt Designer plugins should go to (new in KDE 3).
+
+# set the include path for X, qt and KDE
+INCLUDES= $(all_includes)
+
+METASOURCES = AUTO
+
+# the library search path. 
+tdesudo_LDFLAGS = $(all_libraries) $(KDE_RPATH) $(LIB_QT) -lDCOP $(LIB_KDECORE) $(LIB_KDEUI) -ltdefx $(LIB_KIO) -lktexteditor
+
+# Uncomment the following two lines if you add a ui.rc file for your application to make use of
+# KDE?s XML GUI builing
+#rcdir = $(kde_datadir)/tdesudo
+#rc_DATA = tdesudoui.rc
+
+#WARNING: if you use a ui.rc file above, use:
+
+# messages: rc.cpp
+
+# instead of 
+
+# messages:
+
+messages: 
+	LIST=`find . -name \*.h -o -name \*.hh -o -name \*.H -o -name \*.hxx -o -name \*.hpp -o -name \*.cpp -o -name \*.cc -o -name \*.cxx -o -name \*.ecpp -o -name \*.C`; \
+	if test -n "$$LIST"; then \
+	 $(XGETTEXT) $$LIST -o $(podir)/tdesudo.pot; \
+	fi
+
diff --git a/tdesudo/main.cpp b/tdesudo/main.cpp
new file mode 100644
index 0000000..9fa63f1
--- /dev/null
+++ b/tdesudo/main.cpp
@@ -0,0 +1,149 @@
+/***************************************************************************
+                          tdesudo.cpp  -  description
+                             -------------------
+    begin                : Sam Feb 15 15:42:12 CET 2003
+    copyright            : (C) 2003 by Robert Gruber <rgruber@users.sourceforge.net>
+                           (C) 2007 by Martin Böhm <martin.bohm@kubuntu.org>
+                                       Anthony Mercatante <tonio@kubuntu.org>
+                                       Canonical Ltd (Jonathan Riddell <jriddell@ubuntu.com>)
+                           (C) 2011 by Timothy Pearson <kb9vqf@pearsoncomputing.net>
+
+ ***************************************************************************/
+
+/***************************************************************************
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ ***************************************************************************/
+
+#include <cstdlib>
+
+#include <kcmdlineargs.h>
+#include <kaboutdata.h>
+#include <klocale.h>
+
+#include "tdesudo.h"
+#include <kmessagebox.h>
+#include <kdesktopfile.h>
+#include <kiconloader.h>
+#include <kicontheme.h>
+#include <kglobal.h>
+#include <kstandarddirs.h>
+#include <kprocess.h>
+#include <kdebug.h>
+#include <tqfile.h>
+#include <tqfileinfo.h>
+
+static const char *description =
+	I18N_NOOP("KdeSudo");
+// INSERT A DESCRIPTION FOR YOUR APPLICATION HERE
+
+
+static KCmdLineOptions options[] =
+{
+	{ "u <runas>", I18N_NOOP("sets a runas user"), 0 },
+	{ "c <command>", I18N_NOOP("The command to execute"), 0 },
+	{ "s", I18N_NOOP("Forget passwords"), 0 },
+	{ "i <icon name>", I18N_NOOP("Specify icon to use in the password dialog"), 0},
+	{ "d", I18N_NOOP("Do not show the command to be run in the dialog"), 0},
+	{ "p <priority>", I18N_NOOP("Process priority, between 0 and 100, 0 the lowest [50]"), 0},
+	{ "r", I18N_NOOP("Use realtime scheduling"), 0},
+	{ "f <file>", I18N_NOOP("Use target UID if <file> is not writeable"), 0},
+	{ "t", I18N_NOOP("Fake option for KDE's KdeSu compatibility"), 0 },
+	{ "n", I18N_NOOP("Do not keep password"), 0},
+	{ "nonewdcop", I18N_NOOP("Use existing DCOP server"), 0},
+	{ "comment <dialog text>", I18N_NOOP("The comment that should be displayed in the dialog"),  0},
+	{ "noignorebutton", I18N_NOOP("Do not display « ignore » button"), 0 },
+	{ "+command", I18N_NOOP("The command to execute"), 0 },
+	KCmdLineLastOption
+};
+
+int main(int argc, char **argv)
+{
+	KAboutData aboutData("tdesudo", I18N_NOOP("KdeSudo"),
+		VERSION, description, KAboutData::License_GPL,
+		"(c) 2007-2008, Anthony Mercatante", 0, 0, "tonio@ubuntu.com");
+	aboutData.addAuthor("Robert Gruber",0, "rgruber@users.sourceforge.net");
+	aboutData.addAuthor("Anthony Mercatante",0, "tonio@ubuntu.com");
+	KCmdLineArgs::init(argc, argv, &aboutData);
+	KCmdLineArgs::addCmdLineOptions(options); // Add our own options.
+
+	KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
+
+	KApplication a;
+
+	TQString executable;
+	TQStringList executableList;
+	TQString arg;
+	TQString command;
+	TQStringList commandlist;
+	TQString icon;
+
+	bool withIgnoreButton = args->isSet("ignorebutton");
+
+	if (args->isSet("c"))
+		executable = args->getOption("c");
+
+	if (args->count())
+	{
+		if (executable.isEmpty())
+		{
+			command = args->arg(0);
+			commandlist = TQStringList::split(TQChar(' '), command);
+			executable = commandlist[0];
+		}
+	}
+
+	if ((!args->isSet("c")) && (!args->count())) {
+		kdError() << I18N_NOOP("You must provide the name of the executable you want to run as an argument to tdesudo") << endl;
+		exit(1);
+	}
+
+	/* We have to make sure the executable is only the binary name */
+	executableList = TQStringList::split(" ", executable);
+	executable = executableList[0];
+
+	executableList = TQStringList::split("/", executable);
+	int i = executableList.count() - 1;
+	executable = executableList[i];
+
+	/* Kubuntu has a bug in it - this is a workaround for it */
+	KGlobal::dirs()->addResourceDir("apps","/usr/share/applications/kde");
+	KGlobal::dirs()->addResourceDir("apps","/usr/share/applications");
+
+	TQString deskFilePath = KGlobal::dirs()->findResource("apps",executable + ".desktop");
+	KDesktopFile desktopFile(deskFilePath,true);
+
+	/* icon parsing */
+	if (args->isSet("i"))
+		icon = args->getOption("i");
+	else
+	{
+		TQString iconName = desktopFile.readIcon();
+		icon = KGlobal::iconLoader()->iconPath(iconName, -1* KIcon::StdSizes(KIcon::SizeHuge), true);
+	}
+
+	/* generic name parsing */
+	TQString name = desktopFile.readName();
+	TQString genericName = desktopFile.readGenericName();
+
+	if (!name.isEmpty())
+	{
+		if (!genericName.isEmpty())
+		name += " - " + genericName;
+	}
+	else if (!genericName.isEmpty())
+		name = genericName;
+	else
+		name = executable;
+
+	KdeSudo *tdesudo = new KdeSudo(0,0,icon,name,withIgnoreButton);
+
+	a.setMainWidget(tdesudo);
+	args->clear();
+
+	return a.exec();
+}
diff --git a/tdesudo/tdesudo.cpp b/tdesudo/tdesudo.cpp
new file mode 100644
index 0000000..5649da6
--- /dev/null
+++ b/tdesudo/tdesudo.cpp
@@ -0,0 +1,446 @@
+/***************************************************************************
+                          tdesudo.cpp  -  description
+                             -------------------
+    begin                : Sam Feb 15 15:42:12 CET 2003
+    copyright            : (C) 2003 by Robert Gruber <rgruber@users.sourceforge.net>
+                           (C) 2007 by Martin Böhm <martin.bohm@kubuntu.org>
+                                       Anthony Mercatante <tonio@kubuntu.org>
+                                       Canonical Ltd (Jonathan Riddell <jriddell@ubuntu.com>)
+                           (C) 2011 by Timothy Pearson <kb9vqf@pearsoncomputing.net>
+
+ ***************************************************************************/
+
+/***************************************************************************
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ ***************************************************************************/
+
+#include "tdesudo.h"
+
+#include <tqfile.h>
+#include <tqdir.h>
+#include <tqdatastream.h>
+#include <tqstring.h>
+
+#include <kcmdlineargs.h>
+#include <klocale.h>
+#include <kmessagebox.h>
+#include <kpushbutton.h>
+#include <kpassdlg.h>
+#include <kstandarddirs.h>
+#include <tdesu/kcookie.h>
+#include <kdebug.h>
+#include <kshell.h>
+#include <ktempfile.h>
+
+#include <iostream>
+#include <cstdio>
+#include <cstdlib>
+#include <signal.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+
+KdeSudo::KdeSudo(TQWidget *parent, const char *name,const TQString& icon, const TQString& generic, bool withIgnoreButton)
+	: KPasswordDialog(KPasswordDialog::Password, false, (withIgnoreButton ? User1: false), icon, parent, name)
+{
+	KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
+
+	TQString defaultComment = i18n("<b>%1</b> needs administrative privileges. Please enter your password for verification.");
+	p=NULL;
+	bError=false;
+
+	m_pCookie = new KCookie;
+
+	// Set vars
+	bool newDcop = args->isSet("newdcop");
+	bool realtime = args->isSet("r");
+	bool priority = args->isSet("p");
+	bool showCommand = (!args->isSet("d"));
+	bool keepCurrentHome = true;
+	bool changeUID = true;
+	bool noExec = false;
+	keepPwd = (!args->isSet("n"));
+	emptyPwd = args->isSet("s");
+	TQString runas = args->getOption("u");
+	TQString cmd;
+
+	if (!args->isSet("c") && !args->count() && (!args->isSet("s")))
+	{
+		KMessageBox::information(NULL, i18n("No command arguments supplied!\nUsage: tdesudo [-u <runas>] <command>\nKdeSudo will now exit..."));
+		noExec = true;
+	}
+
+	p = new KProcess;
+	p->clearArguments();
+
+	// Parsins args
+
+	/* Get the comment out of cli args */
+	TQByteArray commentBytes = args->getOption("comment");
+	TQTextCodec* tCodecConv = TQTextCodec::codecForLocale();
+	TQString comment = tCodecConv->toUnicode(commentBytes, commentBytes.size());
+
+	if (args->isSet("f"))
+	{
+		// If file is writeable, do not change uid
+		TQString filename = TQFile::decodeName(args->getOption("f"));
+		TQString file = filename;
+		if (!file.isEmpty())
+		{
+			if (file.at(0) != '/')
+			{
+				KStandardDirs dirs;
+				dirs.addKDEDefaults();
+				file = dirs.findResource("config", file);
+				if (file.isEmpty())
+				{
+					kdError(1206) << "Config file not found: " << file << "\n";
+					exit(1);
+				}
+			}
+			TQFileInfo fi(file);
+			if (!fi.exists())
+			{
+				kdError(1206) << "File does not exist: " << file << "\n";
+				exit(1);
+			}
+			if (fi.isWritable())
+			{
+				changeUID = false;
+			}
+		}
+	}
+
+	if (withIgnoreButton)
+	{
+		setButtonText(User1, i18n("&Ignore"));
+	}
+
+	// Apologies for the C code, taken from kdelibs/tdesu/tdesu_stub.c
+	// KControl and other places need to use the user's existing DCOP server
+	// For that we set DCOPSERVER.  Create a file in /tmp and use iceauth to add magic cookies
+	// from the existing server and set ICEAUTHORITY to point to the file
+	if (!newDcop) {
+		dcopServer = m_pCookie->dcopServer();
+		TQCString dcopAuth = m_pCookie->dcopAuth();
+		TQCString iceAuth = m_pCookie->iceAuth();
+
+		FILE *fout;
+		char iceauthority[200];
+		char *host, *auth;
+		host = qstrdup(dcopServer);
+		auth = qstrdup(iceAuth);
+		int tempfile;
+		int oldumask = umask(077);
+
+		strcpy(iceauthority, "/tmp/iceauth.XXXXXXXXXX");
+		tempfile = mkstemp(iceauthority);
+		umask(oldumask);
+		if (tempfile == -1) {
+			kdError() << "error in tdesudo mkstemp" << endl;
+			exit(1);
+		} else {
+			// close(tempfile); //FIXME why does this make the connect() call later crash?
+		}
+		iceauthorityFile = iceauthority;
+		//FIXME we should change owner of iceauthority file, but don't have permissions
+		setenv("ICEAUTHORITY", iceauthorityFile, 1);
+	
+		fout = popen("iceauth >/dev/null 2>&1", "w");
+		if (!fout) {
+			kdError() << "error in tdesudo running iceauth" << endl;
+			exit(1);
+		}
+		fprintf(fout, "add ICE \"\" %s %s\n", host, auth);
+		auth = qstrdup(dcopAuth);
+		//auth = xstrsep(params[P_DCOP_AUTH].value);
+		fprintf(fout, "add DCOP \"\" %s %s\n", host, auth);
+		unsetenv("ICEAUTHORITY");
+		pclose(fout);
+
+		// Exporting the user's sycoca
+		kdeSycoca = TQFile::encodeName(locateLocal("cache", "ksycoca"));
+	}
+
+	connect( p, TQT_SIGNAL(receivedStdout(KProcess*, char*, int)), this, TQT_SLOT(receivedOut(KProcess*, char*, int)) );
+	connect( p, TQT_SIGNAL(receivedStderr(KProcess*, char*, int)), this, TQT_SLOT(receivedOut(KProcess*, char*, int)) );
+	connect( p, TQT_SIGNAL(processExited (KProcess *)), this, TQT_SLOT(procExited(KProcess*)));
+
+	TQString xauthenv = TQString(getenv("HOME")) + "/.Xauthority";
+	p->setEnvironment("XAUTHORITY", xauthenv);
+
+	// Generate the xauth cookie and put it in a tempfile
+	// set the environment variables to reflect that.
+	// Default cookie-timeout is 60 sec. .
+	// 'man xauth' for more info on xauth cookies.
+	
+	KTempFile temp = KTempFile("/tmp/tdesudo-","-xauth");
+	m_tmpname = temp.name();
+	
+	FILE *f;
+	char buf[1024];
+	
+	TQCString disp = m_pCookie->display();
+	// command: xauth -q -f m_tmpname generate $DISPLAy . trusted timeout 60
+	TQString c = "/usr/bin/xauth -q -f " + m_tmpname + " generate " 
+		+ TQString::fromLocal8Bit(disp) + " . trusted timeout 60";
+	blockSigChild(); // pclose uses waitpid()
+	
+	if (!(f = popen(c, "r"))) {
+		kdWarning() << k_lineinfo << "Cannot run: " << c << "\n";
+		unblockSigChild();
+		return;
+	}
+	
+	// non root users need to be able to read the xauth file.
+	// the xauth file is deleted when tdesudo exits. security?
+	TQFile tf(m_tmpname);
+	if (!runas.isEmpty() && runas != "root" && tf.exists())
+		chmod(m_tmpname.ascii(),0644);
+	
+	QCStringList output;
+	while (fgets(buf, 1024, f) > 0)
+		output += buf; 
+	if (pclose(f) < 0) {
+		kdError() << k_lineinfo << "Could not run xauth.\n";
+		unblockSigChild();
+		return;
+	}
+	unblockSigChild();
+	
+	p->setEnvironment("DISPLAY", disp); 
+	p->setEnvironment("XAUTHORITY", m_tmpname);
+
+	if (emptyPwd)
+		*p << "sudo" << "-k";
+	else
+	{
+		if (changeUID)
+		{
+			*p << "sudo";
+
+			if (!keepCurrentHome)
+				*p << "-H";
+
+			*p << "-S" << "-p" << "passprompt";
+
+			if (!runas.isEmpty())
+				*p << "-u" << runas;
+		}
+
+		if (!dcopServer.isEmpty())
+			*p << "DCOPSERVER=" + dcopServer;
+
+		if (!iceauthorityFile.isEmpty())
+			*p << "ICEAUTHORITY=" + iceauthorityFile;
+
+		if (!kdeSycoca.isEmpty())
+			*p << "KDESYCOCA=" + kdeSycoca;
+
+		if (realtime)
+		{
+			*p << "nice" << "-n" << "10";
+			addLine(i18n("Priority:"), i18n("realtime:") + TQChar(' ') + TQString("50/100"));
+		}
+		else if (priority)
+		{
+			TQString n = args->getOption("p");
+			int intn = atoi(n);
+			intn =  (intn * 40 / 100) - (20 + 0.5);
+		
+			TQString strn;
+			strn.sprintf("%d",intn);
+
+			*p << "nice" << "-n" << strn;
+			addLine(i18n("Priority:"), n + TQString("/100"));
+		}
+
+		*p << "--";
+
+		if (args->isSet("c"))
+		{
+			TQString command = args->getOption("c");
+			TQStringList commandSplit = KShell::splitArgs(command);
+			
+			for (int i = 0; i < commandSplit.count(); i++)
+			{
+				TQString arg = validArg(commandSplit[i]);
+				*p << arg;
+				if (i == 0)
+					cmd += validArg(commandSplit[i]) + TQChar(' ');
+				else
+					cmd += KProcess::quote(validArg(commandSplit[i])) + TQChar(' ');
+			}
+		}
+
+		if (args->count())
+		{
+			for (int i = 0; i < args->count(); i++)
+			{
+                                if ((!args->isSet("c")) && (i == 0))
+				{
+					TQStringList argsSplit = KShell::splitArgs(args->arg(i));
+					for (int j = 0; j < argsSplit.count(); j++)
+					{
+						*p << validArg(argsSplit[j]);
+						if (j == 0)
+							cmd += validArg(argsSplit[j]) + TQChar(' ');
+						else
+							cmd += KProcess::quote(validArg(argsSplit[j])) + TQChar(' ');
+					}
+				}
+				else
+				{
+					*p << validArg(args->arg(i));
+					cmd += validArg(args->arg(i)) + TQChar(' ');
+				}
+			}
+		}
+
+		if (showCommand && !cmd.isEmpty())
+			addLine(i18n("Command:"), cmd);
+	}
+
+	if (comment.isEmpty())
+	{
+		if (!generic.isEmpty())
+			setPrompt(defaultComment.tqarg(generic));
+		else
+			setPrompt(defaultComment.tqarg(cmd));
+	}
+	else
+		setPrompt(comment);
+
+	if (noExec)
+		exit(0);
+	else
+		p->start( KProcess::NotifyOnExit, KProcess::All );
+}
+
+KdeSudo::~KdeSudo()
+{
+}
+
+void KdeSudo::receivedOut(KProcess*, char*buffer, int buflen)
+{
+	char *pcTmp= new char[buflen+1];
+	strncpy(pcTmp,buffer,buflen);
+	pcTmp[buflen]='\0';
+	TQString strOut(pcTmp);
+
+	std::cout << strOut << std::endl;
+
+	static int badpass = 0;
+
+	if (strOut.find("Sorry, try again")!=-1)
+	{
+		badpass++;
+		if (badpass>2)
+		{
+			bError=true;
+			KMessageBox::error(this, i18n("Wrong password! Exiting..."));
+			kapp->quit();
+		}
+	}
+	if (strOut.find("command not found")!=-1)
+	{
+		bError=true;
+		KMessageBox::error(this, i18n("Command not found!"));
+		kapp->quit();
+	}
+	if (strOut.find("is not in the sudoers file")!=-1)
+	{
+		bError=true;
+		KMessageBox::error(this, i18n("Your username is unknown to sudo!"));
+                kapp->quit();
+	}
+	if (strOut.find("is not allowed to execute")!=-1)
+	{
+		bError=true;
+		KMessageBox::error(this, i18n("Your user is not allowed to run the specified command!"));
+		kapp->quit();
+	}
+	if (strOut.find("is not allowed to run sudo on")!=-1)
+	{
+		bError=true;
+		KMessageBox::error(this, i18n("Your user is not allowed to run sudo on this host!"));
+                kapp->quit();
+	}
+	if (strOut.find("may not run sudo on")!=-1)
+	{
+		bError=true;
+		KMessageBox::error(this, i18n("Your user is not allowed to run sudo on this host!"));
+                kapp->quit();
+	}
+	if ((strOut.find("passprompt")!=-1) || (strOut.find("PIN (CHV2)")!=-1))
+	{
+		this->clearPassword();
+		this->show();
+	}
+}
+
+void KdeSudo::procExited(KProcess*)
+{
+	if (!keepPwd && unCleaned)
+	{
+		unCleaned = false;
+		p->clearArguments();
+		*p << "sudo" << "-k";
+		p->start( KProcess::NotifyOnExit, KProcess::All );
+	}
+
+	if (!newDcop && !iceauthorityFile.isEmpty())
+		if (!iceauthorityFile.isEmpty())
+		TQFile::remove(iceauthorityFile);
+
+	if (!bError) {
+		if (!m_tmpname.isEmpty())
+			TQFile::remove(m_tmpname);
+		kapp->quit();
+	}
+}
+
+void KdeSudo::slotOk()
+{
+	TQString strTmp(password());
+	strTmp+="\n";
+	p->writeStdin(strTmp.ascii(),(int)strTmp.length());
+	this->hide();
+}
+
+void KdeSudo::slotUser1()
+{
+	done(AsUser);
+}
+
+void KdeSudo::blockSigChild()
+{
+	sigset_t sset;
+	sigemptyset(&sset);
+	sigaddset(&sset, SIGCHLD);
+	sigprocmask(SIG_BLOCK, &sset, 0L);
+}
+void KdeSudo::unblockSigChild()
+{
+	sigset_t sset;
+	sigemptyset(&sset);
+	sigaddset(&sset, SIGCHLD);
+	sigprocmask(SIG_UNBLOCK, &sset, 0L);
+}
+
+TQString KdeSudo::validArg(TQString arg)
+{
+	TQChar firstChar = arg.at(0);
+	TQChar lastChar = arg.at(arg.length() - 1);
+
+	if ( (firstChar == '"' && lastChar == '"') || (firstChar == '\'' && lastChar == '\'') )
+	{
+		arg = arg.remove(0, 1);
+		arg = arg.remove(arg.length() - 1, 1);
+	}
+	return arg;
+}
diff --git a/tdesudo/tdesudo.h b/tdesudo/tdesudo.h
new file mode 100644
index 0000000..61b4f13
--- /dev/null
+++ b/tdesudo/tdesudo.h
@@ -0,0 +1,98 @@
+/***************************************************************************
+                          tdesudo.cpp  -  description
+                             -------------------
+    begin                : Sam Feb 15 15:42:12 CET 2003
+    copyright            : (C) 2003 by Robert Gruber <rgruber@users.sourceforge.net>
+                           (C) 2007 by Martin Böhm <martin.bohm@kubuntu.org>
+                                       Anthony Mercatante <tonio@kubuntu.org>
+                                       Canonical Ltd (Jonathan Riddell <jriddell@ubuntu.com>)
+
+ ***************************************************************************/
+
+/***************************************************************************
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ ***************************************************************************/
+
+#ifndef KDESUDO_H
+#define KDESUDO_H
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <kapp.h>
+#include <tqwidget.h>
+#include <kpassdlg.h>
+#include <tqstring.h>
+#include <tqtextcodec.h>
+#include <kprocess.h>
+class KCookie;
+
+/*
+* KdeSudo is the base class of the project
+*
+* It inherits KPasswordDialog and overrrides the
+* slot slotOK()
+*
+* @author Robert Gruber <rgruber@users.sourceforge.net>
+* @version 2.4
+*/
+
+class KdeSudo : public KPasswordDialog
+{
+	Q_OBJECT
+	TQ_OBJECT
+
+public:
+	/*
+	* Default construtor
+	*/
+	KdeSudo(TQWidget* parent=0, const char *name=0, const TQString& icon=TQString(), const TQString& generic=TQString(), bool withIgnoreButton=false);
+
+	/*
+	* Default destructor
+	*/
+	~KdeSudo();
+	enum ResultCodes { AsUser = 10 };
+
+public slots: // Public slots
+	/*
+	* This slot gets exectuted if sudo creates some output
+	*/
+	void receivedOut(KProcess*proc, char*buffer, int buflen);
+	/*
+	* This slot gets exectuted when sudo exits
+	*/
+	void procExited(KProcess *proc);
+	/*
+	* This slot overrides the slot from KPasswordDialog
+	* @see KPasswordDialog
+	*/
+	void slotOk();
+	void slotUser1();
+	TQString validArg(TQString arg);
+
+private: // Private attributes
+	KProcess * p;
+	bool bError;
+	bool newDcop;
+	bool keepPwd;
+	bool emptyPwd;
+	bool useTerm;
+	bool noExec;
+	bool unCleaned;
+	TQString m_tmpname;
+	TQString iceauthorityFile;
+	TQString dcopServer;
+	TQString kdeSycoca;
+	KCookie* m_pCookie;
+	void blockSigChild();
+	void unblockSigChild();
+};
+
+#endif
-- 
cgit v1.2.3

