Diffstat (limited to 'core/launcher/transferserver.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | core/launcher/transferserver.cpp | 41 |
1 files changed, 38 insertions, 3 deletions
diff --git a/core/launcher/transferserver.cpp b/core/launcher/transferserver.cpp index 9d18b7b..a20df2f 100644 --- a/core/launcher/transferserver.cpp +++ b/core/launcher/transferserver.cpp @@ -22,17 +22,21 @@ #include <sys/types.h> #include <unistd.h> #include <stdlib.h> #include <time.h> #include <shadow.h> +#ifndef _OS_LINUX_ + extern "C" { #include <uuid/uuid.h> #define UUID_H_INCLUDED } +#endif // not defined linux + #if defined(_OS_LINUX_) #include <shadow.h> #endif #include <qdir.h> #include <qfile.h> @@ -73,21 +77,52 @@ TransferServer::~TransferServer() void TransferServer::newConnection( int socket ) { (void) new ServerPI( socket, this ); } +/* + * small class in anonymous namespace + * to generate a QUUid for us + */ +namespace { + struct UidGen { + QString uuid(); + }; +#if defined(_OS_LINUX_) + /* + * linux got a /proc/sys/kernel/random/uuid file + * it'll generate the uuids for us + */ + QString UidGen::uuid() { + QFile file( "/proc/sys/kernel/random/uuid" ); + if (!file.open(IO_ReadOnly ) ) + return QString::null; + + QTextStream stream(&file); + + return "{" + stream.read().stripWhiteSpace() + "}"; + } +#else + QString UidGen::uuid() { + uuid_t uuid; + uuid_generate( uuid ); + return QUUid( uuid ).toString(); + } +#endif +} + QString SyncAuthentication::serverId() { Config cfg("Security"); cfg.setGroup("Sync"); QString r=cfg.readEntry("serverid"); if ( r.isEmpty() ) { - uuid_t uuid; - uuid_generate( uuid ); - cfg.writeEntry("serverid",(r = QUuid( uuid ).toString())); + UidGen gen; + r = gen.uuid(); + cfg.writeEntry("serverid", r ); } return r; } QString SyncAuthentication::ownerName() { |