fix nodeAtPoint for layers.
[kdelibs.git] / kdesu / stub.cpp
blob7d5a3957f7c260d58d26386c35b2f131e414fdde
1 /* vi: ts=8 sts=4 sw=4
3 * This file is part of the KDE project, module kdesu.
4 * Copyright (C) 1999,2000 Geert Jansen <jansen@kde.org>
6 * This is free software; you can use this library under the GNU Library
7 * General Public License, version 2. See the file "COPYING.LIB" for the
8 * exact licensing terms.
10 * stub.cpp: Conversation with kdesu_stub.
13 #include <config.h>
14 #include <stdlib.h>
15 #include <unistd.h>
17 #include <qglobal.h>
19 #include <kapplication.h>
20 #include <kdebug.h>
22 #include "stub.h"
23 #include "kcookie.h"
26 StubProcess::StubProcess()
28 m_User = "root";
29 m_Scheduler = SchedNormal;
30 m_Priority = 50;
31 m_pCookie = new KCookie;
32 m_bXOnly = true;
36 StubProcess::~StubProcess()
38 delete m_pCookie;
42 void StubProcess::setPriority(int prio)
44 if (prio > 100)
45 m_Priority = 100;
46 else if (prio < 0)
47 m_Priority = 0;
48 else
49 m_Priority = prio;
53 QByteArray StubProcess::commaSeparatedList(const QList<QByteArray> &lst)
55 QByteArray str;
56 for (int i = 0; i < lst.count(); ++i) {
57 str += ',';
58 str += lst.at(i);
60 return str;
64 * Conversation with kdesu_stub. This is how we pass the authentication
65 * tokens (X11) and other stuff to kdesu_stub.
66 * return values: -1 = error, 0 = ok, 1 = kill me
69 int StubProcess::ConverseStub(int check)
71 QByteArray line, tmp;
72 while (1)
74 line = readLine();
75 if (line.isNull())
76 return -1;
78 if (line == "kdesu_stub")
80 // This makes parsing a lot easier.
81 enableLocalEcho(false);
82 if (check) writeLine("stop");
83 else writeLine("ok");
84 } else if (line == "display") {
85 writeLine(display());
86 } else if (line == "display_auth") {
87 #ifdef Q_WS_X11
88 writeLine(displayAuth());
89 #else
90 writeLine("");
91 #endif
92 } else if (line == "command") {
93 writeLine(m_Command);
94 } else if (line == "path") {
95 QByteArray path = getenv("PATH");
96 if (!path.isEmpty() && path[0] == ':')
97 path = path.mid(1);
98 if (m_User == "root")
99 if (!path.isEmpty())
100 path = "/sbin:/bin:/usr/sbin:/usr/bin:" + path;
101 else
102 path = "/sbin:/bin:/usr/sbin:/usr/bin";
103 writeLine(path);
104 } else if (line == "user") {
105 writeLine(m_User);
106 } else if (line == "priority") {
107 tmp.setNum(m_Priority);
108 writeLine(tmp);
109 } else if (line == "scheduler") {
110 if (m_Scheduler == SchedRealtime) writeLine("realtime");
111 else writeLine("normal");
112 } else if (line == "xwindows_only") {
113 if (m_bXOnly) writeLine("no");
114 else writeLine("yes");
115 } else if (line == "app_startup_id") {
116 QList<QByteArray> env = environment();
117 QByteArray tmp;
118 for(int i = 0; i < env.count(); ++i)
120 const char startup_env[] = "DESKTOP_STARTUP_ID=";
121 if (env.at(i).startsWith(startup_env))
122 tmp = env.at(i).mid(sizeof(startup_env) - 1);
124 if( tmp.isEmpty())
125 tmp = "0";
126 writeLine(tmp);
127 } else if (line == "app_start_pid") { // obsolete
128 tmp.setNum(getpid());
129 writeLine(tmp);
130 } else if (line == "environment") { // additional env vars
131 QList<QByteArray> env = environment();
132 for (int i = 0; i < env.count(); ++i)
133 writeLine(env.at(i));
134 writeLine( "" );
135 } else if (line == "end") {
136 return 0;
137 } else
139 kWarning(900) << k_lineinfo << "Unknown request: -->" << line
140 << "<--\n";
141 return 1;
145 return 0;
149 void StubProcess::virtual_hook( int id, void* data )
150 { PtyProcess::virtual_hook( id, data ); }