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

KDEsu

kcookie.cpp

Go to the documentation of this file.
00001 /* vi: ts=8 sts=4 sw=4
00002  *
00003  * This file is part of the KDE project, module kdesu.
00004  * Copyright (C) 1999,2000 Geert Jansen <jansen@kde.org>
00005  *
00006  * This is free software; you can use this library under the GNU Library
00007  * General Public License, version 2. See the file "COPYING.LIB" for the
00008  * exact licensing terms.
00009  *
00010  * kcookie.cpp: KDE authentication cookies.
00011  */
00012 
00013 #include "kcookie.h"
00014 
00015 #include <stdlib.h>
00016 
00017 #include <QtCore/QString>
00018 #include <QtCore/QStringList>
00019 #include <QtCore/QBool>
00020 #include <QtCore/Q_PID>
00021 
00022 #include <kdebug.h>
00023 
00024 extern int kdesuDebugArea();
00025 
00026 namespace KDESu {
00027 namespace KDESuPrivate {
00028 
00029 class KCookie::KCookiePrivate
00030 {
00031 public:
00032     QByteArray m_Display;
00033 #ifdef Q_WS_X11
00034     QByteArray m_DisplayAuth;
00035 #endif
00036 };
00037 
00038 
00039 
00040 KCookie::KCookie()
00041     : d( new KCookiePrivate )
00042 {
00043 #ifdef Q_WS_X11
00044     getXCookie();
00045 #endif
00046 }
00047 
00048 KCookie::~KCookie()
00049 {
00050     delete d;
00051 }
00052 
00053 QByteArray KCookie::display() const
00054 {
00055     return d->m_Display;
00056 }
00057 
00058 #ifdef Q_WS_X11
00059 QByteArray KCookie::displayAuth() const
00060 {
00061     return d->m_DisplayAuth;
00062 }
00063 #endif
00064 
00065 void KCookie::getXCookie()
00066 {
00067 #ifdef Q_WS_X11
00068     d->m_Display = qgetenv("DISPLAY");
00069 #else
00070     d->m_Display = qgetenv("QWS_DISPLAY");
00071 #endif
00072     if (d->m_Display.isEmpty())
00073     {
00074     kError(kdesuDebugArea()) << k_lineinfo << "$DISPLAY is not set.";
00075     return;
00076     }
00077 #ifdef Q_WS_X11 // No need to mess with X Auth stuff
00078     QByteArray disp = d->m_Display;
00079     if (disp.startsWith("localhost:")) // krazy:exclude=strings
00080        disp.remove(0, 9);
00081 
00082     QProcess proc;
00083     proc.start("xauth", QStringList() << "list" << disp);
00084     if (!proc.waitForStarted())
00085     {
00086     kError(kdesuDebugArea()) << k_lineinfo << "Could not run xauth.";
00087     return;
00088     }
00089     proc.waitForReadyRead(100);
00090     QByteArray output = proc.readLine().simplified();
00091     if (output.isEmpty())
00092     {
00093        kWarning(kdesuDebugArea()) << "No X authentication info set for display" << d->m_Display;
00094        return;
00095     }
00096     QList<QByteArray> lst = output.split(' ');
00097     if (lst.count() != 3)
00098     {
00099     kError(kdesuDebugArea()) << k_lineinfo << "parse error.";
00100     return;
00101     }
00102     d->m_DisplayAuth = (lst[1] + ' ' + lst[2]);
00103     proc.waitForFinished(100); // give QProcess a chance to clean up gracefully
00104 #endif
00105 }
00106 
00107 }}

KDEsu

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

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • 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
Generated for kdelibs by doxygen 1.7.3
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal