• Skip to content
  • Skip to link menu
KDE 4.1 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • 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 namespace KDESu {
00025 namespace KDESuPrivate {
00026 
00027 class KCookie::KCookiePrivate
00028 {
00029 public:
00030     QByteArray m_Display;
00031 #ifdef Q_WS_X11
00032     QByteArray m_DisplayAuth;
00033 #endif
00034 };
00035 
00036 
00037 
00038 KCookie::KCookie()
00039     : d( new KCookiePrivate )
00040 {
00041 #ifdef Q_WS_X11
00042     getXCookie();
00043 #endif
00044 }
00045 
00046 KCookie::~KCookie()
00047 {
00048     delete d;
00049 }
00050 
00051 QByteArray KCookie::display() const
00052 {
00053     return d->m_Display;
00054 }
00055 
00056 #ifdef Q_WS_X11
00057 QByteArray KCookie::displayAuth() const
00058 {
00059     return d->m_DisplayAuth;
00060 }
00061 #endif
00062 
00063 void KCookie::getXCookie()
00064 {
00065 #ifdef Q_WS_X11
00066     d->m_Display = qgetenv("DISPLAY");
00067 #else
00068     d->m_Display = qgetenv("QWS_DISPLAY");
00069 #endif
00070     if (d->m_Display.isEmpty())
00071     {
00072     kError(900) << k_lineinfo << "$DISPLAY is not set.\n";
00073     return;
00074     }
00075 #ifdef Q_WS_X11 // No need to mess with X Auth stuff
00076     QByteArray disp = d->m_Display;
00077     if (disp.startsWith("localhost:"))
00078        disp.remove(0, 9);
00079 
00080     QProcess proc;
00081     proc.start("xauth", QStringList() << "list" << disp);
00082     if (!proc.waitForStarted())
00083     {
00084     kError(900) << k_lineinfo << "Could not run xauth.\n";
00085     return;
00086     }
00087     proc.waitForReadyRead(100);
00088     QByteArray output = proc.readLine().simplified();
00089     if (output.isEmpty())
00090     {
00091        kWarning(900) << "No X authentication info set for display " <<
00092        d->m_Display << endl; return;
00093     }
00094     QList<QByteArray> lst = output.split(' ');
00095     if (lst.count() != 3)
00096     {
00097     kError(900) << k_lineinfo << "parse error.\n";
00098     return;
00099     }
00100     d->m_DisplayAuth = (lst[1] + ' ' + lst[2]);
00101     proc.waitForFinished(100); // give QProcess a chance to clean up gracefully
00102 #endif
00103 }
00104 
00105 }}

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
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • KIO
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.4
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