• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

KDEsu

  • kdesu
kcookie.cpp
Go to the documentation of this file.
1/* vi: ts=8 sts=4 sw=4
2 *
3 * This file is part of the KDE project, module kdesu.
4 * Copyright (C) 1999,2000 Geert Jansen <jansen@kde.org>
5 *
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.
9 *
10 * kcookie.cpp: KDE authentication cookies.
11 */
12
13#include "kcookie.h"
14
15#include <stdlib.h>
16
17#include <QtCore/QString>
18#include <QtCore/QStringList>
19#include <QtCore/QBool>
20#include <QtCore/Q_PID>
21
22#include <kdebug.h>
23
24extern int kdesuDebugArea();
25
26namespace KDESu {
27namespace KDESuPrivate {
28
29class KCookie::KCookiePrivate
30{
31public:
32 QByteArray m_Display;
33#ifdef Q_WS_X11
34 QByteArray m_DisplayAuth;
35#endif
36};
37
38
39
40KCookie::KCookie()
41 : d( new KCookiePrivate )
42{
43#ifdef Q_WS_X11
44 getXCookie();
45#endif
46}
47
48KCookie::~KCookie()
49{
50 delete d;
51}
52
53QByteArray KCookie::display() const
54{
55 return d->m_Display;
56}
57
58#ifdef Q_WS_X11
59QByteArray KCookie::displayAuth() const
60{
61 return d->m_DisplayAuth;
62}
63#endif
64
65void KCookie::getXCookie()
66{
67#ifdef Q_WS_X11
68 d->m_Display = qgetenv("DISPLAY");
69#else
70 d->m_Display = qgetenv("QWS_DISPLAY");
71#endif
72 if (d->m_Display.isEmpty())
73 {
74 kError(kdesuDebugArea()) << k_lineinfo << "$DISPLAY is not set.";
75 return;
76 }
77#ifdef Q_WS_X11 // No need to mess with X Auth stuff
78 QByteArray disp = d->m_Display;
79 if (disp.startsWith("localhost:")) // krazy:exclude=strings
80 disp.remove(0, 9);
81
82 QProcess proc;
83 proc.start("xauth", QStringList() << "list" << disp);
84 if (!proc.waitForStarted())
85 {
86 kError(kdesuDebugArea()) << k_lineinfo << "Could not run xauth.";
87 return;
88 }
89 proc.waitForReadyRead(100);
90 QByteArray output = proc.readLine().simplified();
91 if (output.isEmpty())
92 {
93 kWarning(kdesuDebugArea()) << "No X authentication info set for display" << d->m_Display;
94 return;
95 }
96 QList<QByteArray> lst = output.split(' ');
97 if (lst.count() != 3)
98 {
99 kError(kdesuDebugArea()) << k_lineinfo << "parse error.";
100 return;
101 }
102 d->m_DisplayAuth = (lst[1] + ' ' + lst[2]);
103 proc.waitForFinished(100); // give QProcess a chance to clean up gracefully
104#endif
105}
106
107}}
KDESu::KDESuPrivate::KCookie::~KCookie
~KCookie()
Definition: kcookie.cpp:48
KDESu::KDESuPrivate::KCookie::KCookie
KCookie()
Definition: kcookie.cpp:40
KDESu::KDESuPrivate::KCookie::displayAuth
QByteArray displayAuth() const
Returns the X11 magic cookie, if available.
Definition: kcookie.cpp:59
KDESu::KDESuPrivate::KCookie::display
QByteArray display() const
Returns the X11 display.
Definition: kcookie.cpp:53
QList
QProcess
kdesuDebugArea
int kdesuDebugArea()
Definition: su.cpp:43
output
void output(QList< Action > actions, QHash< QString, QString > domain)
kWarning
#define kWarning
k_lineinfo
#define k_lineinfo
kdesuDebugArea
int kdesuDebugArea()
Definition: su.cpp:43
kcookie.h
kdebug.h
KDESu
Definition: client.cpp:41
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDEsu

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

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal