Qt 4.8
Public Functions | Public Variables | List of all members
QTransportAuthPrivate Class Reference

#include <qtransportauth_qws_p.h>

Inheritance diagram for QTransportAuthPrivate:
QObjectPrivate QObjectData

Public Functions

const unsigned char * getClientKey (unsigned char progId)
 Find client keys for the progId. More...
 
void invalidateClientKeyCache ()
 
 QTransportAuthPrivate ()
 
 ~QTransportAuthPrivate ()
 
- Public Functions inherited from QObjectPrivate
void _q_reregisterTimers (void *pointer)
 
void addConnection (int signal, Connection *c)
 
void cleanConnectionLists ()
 
void connectNotify (const char *signal)
 
void deleteChildren ()
 
void disconnectNotify (const char *signal)
 
bool isSender (const QObject *receiver, const char *signal) const
 
bool isSignalConnected (uint signalIdx) const
 Returns true if the signal with index signal_index from object sender is connected. More...
 
void moveToThread_helper ()
 
 QObjectPrivate (int version=QObjectPrivateVersion)
 
QObjectList receiverList (const char *signal) const
 
QObjectList senderList () const
 
void setParent_helper (QObject *)
 
void setThreadData_helper (QThreadData *currentData, QThreadData *targetData)
 
int signalIndex (const char *signalName) const
 Returns the signal index used in the internal connectionLists vector. More...
 
virtual ~QObjectPrivate ()
 
- Public Functions inherited from QObjectData
virtual ~QObjectData ()=0
 

Public Variables

AuthCookie authKey
 
QHash< QObject *, QIODevice * > buffersByClient
 
QCache< unsigned char, char > keyCache
 
QMutex keyfileMutex
 
bool keyInitialised
 
QString m_keyFilePath
 
QString m_logFilePath
 
QObjectm_packageRegistry
 
- Public Variables inherited from QObjectPrivate
union {
   QObject *   currentChildBeingDeleted
 
   QAbstractDeclarativeData *   declarativeData
 
}; 
 
quint32 connectedSignals [2]
 
QObjectConnectionListVectorconnectionLists
 
SendercurrentSender
 
QList< QPointer< QObject > > eventFilters
 
ExtraDataextraData
 
QString objectName
 
Connectionsenders
 
QAtomicPointer< QtSharedPointer::ExternalRefCountData > sharedRefcount
 
QThreadDatathreadData
 
void * unused
 
- Public Variables inherited from QObjectData
uint blockSig: 1
 
QObjectList children
 
uint hasGuards: 1
 
uint inEventHandler: 1
 
uint inThreadChangeEvent: 1
 
uint isWidget: 1
 
QMetaObjectmetaObject
 
uint ownObjectName: 1
 
QObjectparent
 
uint pendTimer: 1
 
int postedEvents
 
QObjectq_ptr
 
uint receiveChildEvents: 1
 
uint sendChildEvents: 1
 
uint unused: 22
 
uint wasDeleted: 1
 

Additional Inherited Members

- Public Types inherited from QObjectPrivate
typedef void(* StaticMetaCallFunction) (QObject *, QMetaObject::Call, int, void **)
 
- Static Public Functions inherited from QObjectPrivate
static void clearGuards (QObject *)
 
static QObjectPrivateget (QObject *o)
 
static void resetCurrentSender (QObject *receiver, Sender *currentSender, Sender *previousSender)
 
static SendersetCurrentSender (QObject *receiver, Sender *sender)
 
static void signalSignature (const QMetaMethod &signal, QVarLengthArray< char > *result)
 

Detailed Description

Definition at line 141 of file qtransportauth_qws_p.h.

Constructors and Destructors

◆ QTransportAuthPrivate()

QTransportAuthPrivate::QTransportAuthPrivate ( )

Definition at line 184 of file qtransportauth_qws.cpp.

185  : keyInitialised(false)
186  , m_packageRegistry( 0 )
187 {
188 }

◆ ~QTransportAuthPrivate()

QTransportAuthPrivate::~QTransportAuthPrivate ( )

Definition at line 190 of file qtransportauth_qws.cpp.

191 {
192 }

Functions

◆ getClientKey()

const unsigned char * QTransportAuthPrivate::getClientKey ( unsigned char  progId)

Find client keys for the progId.

Warning
This function is not part of the public interface. If it is cached should be very fast, otherwise requires a read of the secret key file

In the success case a pointer to the keys is returned. The pointer is to storage allocated for the internal cache and must be used asap.

The list returned is a sequence of one or more keys which match the progId. There is no separator, each 16 byte sequence represents a key. The sequence is followed by two iterations of the SXE magic bytes,eg 0xBA, 0xD4, 0xD4, 0xBA, 0xBA, 0xD4, 0xD4, 0xBA

NULL is returned in the following cases:

  • the keyfiles could not be accessed - error condition
  • there was no key for the supplied program id - key auth failed

Note that for the keyfiles, there is multi-thread and multi-process concurrency issues: they can be read by the qpe process when QTransportAuth calls getClientKey to verify a request, and they can be read or written by the packagemanager when updating package data.

To protect against this, the keyfileMutex & SxeRegistryLocker is used.

The sxe_installer tool can also update inode and device numbers in the manifest file, but this only occurs outside of normal operation, so qpe and packagemanager are never running when this occurs.

Definition at line 658 of file qtransportauth_qws.cpp.

659 {
660  int manifestMatchCount = 0;
661  struct IdBlock mr;
662  int total_size = 0;
663  char *result = 0;
664  char *result_ptr;
665  int keysFound = 0;
666  bool foundKey;
667  int keysRead = 0;
668  struct usr_key_entry keys_list[128];
669 
670  if ( keyCache.contains( progId ))
671  return (const unsigned char *)keyCache[progId];
672 
674 
675  // ### Qt 4.3: this is hacky - see documentation for setKeyFilePath
676  QString manifestPath = m_keyFilePath + QLatin1String("/manifest");
677  QString actualKeyPath = QLatin1String("/proc/lids/keys");
678  bool noFailOnKeyMissing = true;
679  if ( !QFile::exists( actualKeyPath )) {
680  actualKeyPath = m_keyFilePath + QLatin1String( "/" QSXE_KEYFILE );
681  }
682  QFile kf( actualKeyPath );
683  QFile mn( manifestPath );
684  if ( !__fileOpen( &mn ))
685  goto key_not_found;
686  // first find how much storage is needed
687  while ( mn.read( (char*)&mr, sizeof(struct IdBlock)) > 0 )
688  if ( mr.progId == progId )
689  manifestMatchCount++;
690  if ( manifestMatchCount == 0 )
691  goto key_not_found;
692  if ( !__fileOpen( &kf ))
693  {
694  noFailOnKeyMissing = false;
695  goto key_not_found;
696  }
697  total_size = 2 * QSXE_MAGIC_BYTES + manifestMatchCount * QSXE_KEY_LEN;
698  result = (char*)malloc( total_size );
699  Q_CHECK_PTR( result );
700  mn.seek( 0 );
701  result_ptr = result;
702  /* reading whole key array in is much more efficient, 99% case is this loop only
703  executes once, should not have more than 128 keyed items */
704  while (( keysRead = kf.read( (char*)keys_list, sizeof(struct usr_key_entry)*128 )) > 0 )
705  {
706  /* qDebug("PID %d: getClientKey() - read %d bytes = %d keys from %s", getpid(), keysRead,
707  keysRead/sizeof(struct usr_key_entry), qPrintable(actualKeyPath)); */
708  keysRead /= sizeof(struct usr_key_entry);
709  while ( mn.read( (char*)&mr, sizeof(struct IdBlock)) > 0 )
710  {
711  if ( mr.progId == progId )
712  {
713  foundKey = false;
714  for ( int i = 0; i < keysRead; ++i )
715  {
716  /* if ( i == 0 )
717  qDebug() << " pid" << getpid() << "looking for device" << (dev_t)mr.device << "inode" << (ino_t)mr.inode;
718  qDebug() << " pid" << getpid() << "trying device" << keys_list[i].dev << "inode" << keys_list[i].ino; */
719  if ( keys_list[i].ino == (ino_t)mr.inode && keys_list[i].dev == (dev_t)mr.device )
720  {
721  memcpy( result_ptr, keys_list[i].key, QSXE_KEY_LEN );
722  result_ptr += QSXE_KEY_LEN;
723  foundKey = true;
724  break;
725  }
726  }
727  if ( foundKey )
728  {
729  keysFound++;
730  if ( keysFound == manifestMatchCount )
731  break;
732  }
733  }
734  }
735  }
736  if ( result_ptr == result ) // nothing found!
737  goto key_not_found;
738  // 2 x magic bytes sentinel at end of sequence
739  for ( int i = 0; i < 2; ++i )
740  for ( int j = 0; j < QSXE_MAGIC_BYTES; ++j )
741  *result_ptr++ = magic[j];
742  keyCache.insert( progId, result, total_size / 10 );
743  /* qDebug( "PID %d : Found %d client keys for prog %u", getpid(), keysFound, progId ); */
744  goto success_out;
745 
746 key_not_found:
747  if ( noFailOnKeyMissing ) // return an "empty" set of keys in this case
748  {
749  if ( result == 0 )
750  {
751  result = (char*)malloc( 2 * QSXE_MAGIC_BYTES );
752  Q_CHECK_PTR( result );
753  }
754  result_ptr = result;
755  for ( int i = 0; i < 2; ++i )
756  for ( int j = 0; j < QSXE_MAGIC_BYTES; ++j )
757  *result_ptr++ = magic[j];
758  return (unsigned char *)result;
759  }
760  qWarning( "PID %d : Not found client key for prog %u", getpid(), progId );
761  if ( result )
762  {
763  free( result );
764  result = 0;
765  }
766 success_out:
767  if ( mn.isOpen() )
768  mn.close();
769  if ( kf.isOpen() )
770  kf.close();
771  return (unsigned char *)result;
772 }
const unsigned char magic[QSXE_MAGIC_BYTES]
bool __fileOpen(QFile *f)
QCache< unsigned char, char > keyCache
Data record for the manifest file.
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
#define QSXE_KEY_LEN
The QString class provides a Unicode character string.
Definition: qstring.h:83
bool exists() const
Returns true if the file specified by fileName() exists; otherwise returns false. ...
Definition: qfile.cpp:626
#define QSXE_KEYFILE
This comes from the SXE kernel patch file include/linux/lidsif.
Q_CORE_EXPORT void qWarning(const char *,...)
bool insert(const Key &key, T *object, int cost=1)
Definition: qcache.h:181
bool contains(const Key &key) const
Definition: qcache.h:118
#define Q_CHECK_PTR(p)
Definition: qglobal.h:1853
The QFile class provides an interface for reading from and writing to files.
Definition: qfile.h:65
int key
#define QSXE_MAGIC_BYTES
ino_t ino

◆ invalidateClientKeyCache()

void QTransportAuthPrivate::invalidateClientKeyCache ( )

Definition at line 774 of file qtransportauth_qws.cpp.

775 {
776  keyfileMutex.lock();
777  keyCache.clear();
779 }
void lock()
Locks the mutex.
Definition: qmutex.cpp:151
QCache< unsigned char, char > keyCache
void clear()
Definition: qcache.h:138
void unlock()
Unlocks the mutex.
Definition: qmutex.cpp:296

Properties

◆ authKey

AuthCookie QTransportAuthPrivate::authKey

Definition at line 155 of file qtransportauth_qws_p.h.

◆ buffersByClient

QHash< QObject*, QIODevice*> QTransportAuthPrivate::buffersByClient

Definition at line 157 of file qtransportauth_qws_p.h.

◆ keyCache

QCache<unsigned char, char> QTransportAuthPrivate::keyCache

Definition at line 156 of file qtransportauth_qws_p.h.

◆ keyfileMutex

QMutex QTransportAuthPrivate::keyfileMutex

Definition at line 158 of file qtransportauth_qws_p.h.

◆ keyInitialised

bool QTransportAuthPrivate::keyInitialised

Definition at line 151 of file qtransportauth_qws_p.h.

◆ m_keyFilePath

QString QTransportAuthPrivate::m_keyFilePath

Definition at line 153 of file qtransportauth_qws_p.h.

◆ m_logFilePath

QString QTransportAuthPrivate::m_logFilePath

Definition at line 152 of file qtransportauth_qws_p.h.

◆ m_packageRegistry

QObject* QTransportAuthPrivate::m_packageRegistry

Definition at line 154 of file qtransportauth_qws_p.h.


The documentation for this class was generated from the following files: