• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • kdesu
 

kdesu

stub.cpp
00001 /* vi: ts=8 sts=4 sw=4
00002  *
00003  * $Id$
00004  *
00005  * This file is part of the KDE project, module kdesu.
00006  * Copyright (C) 1999,2000 Geert Jansen <jansen@kde.org>
00007  * 
00008  * This is free software; you can use this library under the GNU Library 
00009  * General Public License, version 2. See the file "COPYING.LIB" for the 
00010  * exact licensing terms.
00011  *
00012  * stub.cpp: Conversation with kdesu_stub.
00013  */
00014 
00015 #include <config.h>
00016 #include <stdlib.h>
00017 #include <unistd.h>
00018 
00019 #include <tqglobal.h>
00020 #include <tqcstring.h>
00021 #include <kdatastream.h>
00022 
00023 #include <kapplication.h>
00024 #include <kdebug.h>
00025 #include <dcopclient.h>
00026 
00027 #include "stub.h"
00028 #include "kcookie.h"
00029 
00030 
00031 StubProcess::StubProcess()
00032 {
00033     m_User = "root";
00034     m_Scheduler = SchedNormal;
00035     m_Priority = 50;
00036     m_pCookie = new KCookie;
00037     m_bXOnly = true;
00038     m_bDCOPForwarding = false;
00039 }
00040 
00041 
00042 StubProcess::~StubProcess()
00043 {
00044     delete m_pCookie;
00045 }
00046 
00047 
00048 void StubProcess::setPriority(int prio)
00049 {
00050     if (prio > 100)
00051     m_Priority = 100;
00052     else if (prio < 0)
00053     m_Priority = 0;
00054     else
00055     m_Priority = prio;
00056 }
00057 
00058 
00059 TQCString StubProcess::commaSeparatedList(QCStringList lst)
00060 {
00061     if (lst.count() == 0)
00062     return TQCString("");
00063 
00064     QCStringList::Iterator it = lst.begin();
00065     TQCString str = *it;
00066     for (it++; it!=lst.end(); it++) 
00067     {
00068     str += ',';
00069     str += *it;
00070     }
00071     return str;
00072 }
00073     
00074 /*
00075  * Conversation with kdesu_stub. This is how we pass the authentication
00076  * tokens (X11, DCOP) and other stuff to kdesu_stub.
00077  * return values: -1 = error, 0 = ok, 1 = kill me
00078  */
00079 
00080 int StubProcess::ConverseStub(int check)
00081 {
00082     TQCString line, tmp;
00083     while (1) 
00084     {
00085     line = readLine();
00086     if (line.isNull())
00087         return -1;
00088 
00089     if (line == "kdesu_stub") 
00090     {
00091         // This makes parsing a lot easier.
00092         enableLocalEcho(false);
00093         if (check) writeLine("stop");
00094         else writeLine("ok");
00095     } else if (line == "display") {
00096         writeLine(display());
00097     } else if (line == "display_auth") {
00098 #ifdef Q_WS_X11
00099         writeLine(displayAuth());
00100 #else
00101         writeLine("");
00102 #endif
00103     } else if (line == "dcopserver") {
00104         if (m_bDCOPForwarding)
00105            writeLine(dcopServer());
00106         else
00107            writeLine("no");
00108     } else if (line == "dcop_auth") {
00109         if (m_bDCOPForwarding)
00110            writeLine(dcopAuth());
00111         else
00112            writeLine("no");
00113     } else if (line == "ice_auth") {
00114         if (m_bDCOPForwarding)
00115            writeLine(iceAuth());
00116         else
00117            writeLine("no");
00118     } else if (line == "command") {
00119         writeLine(m_Command);
00120     } else if (line == "path") {
00121         TQCString path = getenv("PATH");
00122             if (!path.isEmpty() && path[0] == ':')
00123                 path = path.mid(1);
00124         if (m_User == "root")
00125            if (!path.isEmpty())
00126               path = "/usr/local/sbin:/usr/sbin:/sbin:" + path;
00127            else
00128                   if (strcmp(__KDE_BINDIR, "/usr/bin") == 0) {
00129                   path = "/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin";
00130           }
00131           else {
00132               path = "/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:" __KDE_BINDIR ":/usr/bin:/bin";
00133           }
00134         writeLine(path);
00135     } else if (line == "user") {
00136         writeLine(m_User);
00137     } else if (line == "priority") {
00138         tmp.setNum(m_Priority);
00139         writeLine(tmp);
00140     } else if (line == "scheduler") {
00141         if (m_Scheduler == SchedRealtime) writeLine("realtime");
00142         else writeLine("normal");
00143     } else if (line == "xwindows_only") {
00144         if (m_bXOnly) writeLine("no");
00145         else writeLine("yes");
00146     } else if (line == "app_startup_id") {
00147         QCStringList env = environment();
00148         TQCString tmp;
00149         for( QCStringList::ConstIterator it = env.begin();
00150          it != env.end();
00151          ++it )
00152         {
00153         if( (*it).find( "DESKTOP_STARTUP_ID=" ) == 0 )
00154             tmp = (*it).mid( strlen( "DESKTOP_STARTUP_ID=" ));
00155         }
00156         if( tmp.isEmpty())
00157         tmp = "0";
00158         writeLine(tmp);
00159     } else if (line == "app_start_pid") { // obsolete
00160         tmp.setNum(getpid());
00161         writeLine(tmp);
00162     } else if (line == "environment") { // additional env vars
00163         QCStringList env = environment();
00164         for( QCStringList::ConstIterator it = env.begin();
00165          it != env.end();
00166          ++it )
00167         writeLine( *it );
00168         writeLine( "" );
00169     } else if (line == "end") {
00170         return 0;
00171     } else 
00172     {
00173         kdWarning(900) << k_lineinfo << "Unknown request: -->" << line 
00174                    << "<--\n";
00175         return 1;
00176     }
00177     }
00178 
00179     return 0;
00180 }
00181 
00182 
00183 void StubProcess::notifyTaskbar(const TQString &)
00184 {
00185     kdWarning(900) << "Obsolete StubProcess::notifyTaskbar() called!" << endl;
00186 }
00187 
00188 void StubProcess::virtual_hook( int id, void* data )
00189 { PtyProcess::virtual_hook( id, data ); }

kdesu

Skip menu "kdesu"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

kdesu

Skip menu "kdesu"
  • arts
  • dcop
  • dnssd
  • interfaces
  •     interface
  •     library
  •   kspeech
  •   ktexteditor
  • kabc
  • kate
  • kcmshell
  • kdecore
  • kded
  • kdefx
  • kdeprint
  • kdesu
  • kdeui
  • kdoctools
  • khtml
  • kimgio
  • kinit
  • kio
  •   bookmarks
  •   httpfilter
  •   kfile
  •   kio
  •   kioexec
  •   kpasswdserver
  •   kssl
  • kioslave
  •   http
  • kjs
  • kmdi
  •   kmdi
  • knewstuff
  • kparts
  • krandr
  • kresources
  • kspell2
  • kunittest
  • kutils
  • kwallet
  • libkmid
  • libkscreensaver
Generated for kdesu by doxygen 1.7.6.1
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |