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

KDEsu

  • sources
  • kde-4.12
  • kdelibs
  • 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 
24 extern int kdesuDebugArea();
25 
26 namespace KDESu {
27 namespace KDESuPrivate {
28 
29 class KCookie::KCookiePrivate
30 {
31 public:
32  QByteArray m_Display;
33 #ifdef Q_WS_X11
34  QByteArray m_DisplayAuth;
35 #endif
36 };
37 
38 
39 
40 KCookie::KCookie()
41  : d( new KCookiePrivate )
42 {
43 #ifdef Q_WS_X11
44  getXCookie();
45 #endif
46 }
47 
48 KCookie::~KCookie()
49 {
50  delete d;
51 }
52 
53 QByteArray KCookie::display() const
54 {
55  return d->m_Display;
56 }
57 
58 #ifdef Q_WS_X11
59 QByteArray KCookie::displayAuth() const
60 {
61  return d->m_DisplayAuth;
62 }
63 #endif
64 
65 void 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::display
QByteArray display() const
Returns the X11 display.
Definition: kcookie.cpp:53
kcookie.h
kdebug.h
KDESu::KDESuPrivate::KCookie::KCookie
KCookie()
Definition: kcookie.cpp:40
kError
static QDebug kError(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
KDESu::KDESuPrivate::KCookie::~KCookie
~KCookie()
Definition: kcookie.cpp:48
output
void output(QList< Action > actions, QHash< QString, QString > domain)
QStringList
kdesuDebugArea
int kdesuDebugArea()
Definition: su.cpp:43
kWarning
static QDebug kWarning(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
k_lineinfo
#define k_lineinfo
KDESu::KDESuPrivate::KCookie::displayAuth
QByteArray displayAuth() const
Returns the X11 magic cookie, if available.
Definition: kcookie.cpp:59
QProcess
QList< QByteArray >
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:49:48 by doxygen 1.8.7 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 API Reference

Skip menu "kdelibs 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
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



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