void KStandardDirs::createSpecialResource(const char *type) { char hostname[256]; hostname[0] = 0; gethostname(hostname, 255); QString dir = QString("%1%2-%3").arg(localkdedir()).arg(type).arg(hostname); char link[1024]; link[1023] = 0; int result = readlink(QFile::encodeName(dir).data(), link, 1023); bool relink = (result == -1) && (errno == ENOENT); if(result > 0) { link[result] = 0; if(!QDir::isRelativePath(link)) { KDE_struct_stat stat_buf; int res = KDE_lstat(link, &stat_buf); if((res == -1) && (errno == ENOENT)) { relink = true; } else if((res == -1) || (!S_ISDIR(stat_buf.st_mode))) { fprintf(stderr, "Error: \"%s\" is not a directory.\n", link); relink = true; } else if(stat_buf.st_uid != getuid()) { fprintf(stderr, "Error: \"%s\" is owned by uid %d instead of uid %d.\n", link, stat_buf.st_uid, getuid()); relink = true; } } } if(relink) { QString srv = findExe(QString::fromLatin1("lnusertemp"), kfsstnd_defaultbindir()); if(srv.isEmpty()) srv = findExe(QString::fromLatin1("lnusertemp")); if(!srv.isEmpty()) { system(QFile::encodeName(srv) + " " + type); result = readlink(QFile::encodeName(dir).data(), link, 1023); } } if(result > 0) { link[result] = 0; if(link[0] == '/') dir = QFile::decodeName(link); else dir = QDir::cleanDirPath(dir + QFile::decodeName(link)); } addResourceDir(type, dir + '/'); }
bool KStandardDirs::addResourceDir( const char *type, const QString& absdir) { // KDE4: change priority to bring in line with addResourceType return addResourceDir(type, absdir, false); }
bool KStandardDirs::addCustomized(KConfig *config) { if (addedCustoms && !d->checkRestrictions) // there are already customized entries return false; // we just quit and hope they are the right ones // save the numbers of config directories. If this changes, // we will return true to give KConfig a chance to reparse uint configdirs = resourceDirs("config").count(); // Remember original group QString oldGroup = config->group(); if (!addedCustoms) { // We only add custom entries once addedCustoms = true; // reading the prefixes in QString group = QString::fromLatin1("Directories"); config->setGroup(group); QString kioskAdmin = config->readEntry("kioskAdmin"); if (!kioskAdmin.isEmpty() && !kde_kiosk_admin) { int i = kioskAdmin.find(':'); QString user = kioskAdmin.left(i); QString host = kioskAdmin.mid(i+1); KUser thisUser; char hostname[ 256 ]; hostname[ 0 ] = '\0'; if (!gethostname( hostname, 255 )) hostname[sizeof(hostname)-1] = '\0'; if ((user == thisUser.loginName()) && (host.isEmpty() || (host == hostname))) { kde_kiosk_admin = true; } } bool readProfiles = true; if (kde_kiosk_admin && !QCString(getenv("KDE_KIOSK_NO_PROFILES")).isEmpty()) readProfiles = false; QString userMapFile = config->readEntry("userProfileMapFile"); QString profileDirsPrefix = config->readEntry("profileDirsPrefix"); if (!profileDirsPrefix.isEmpty() && !profileDirsPrefix.endsWith("/")) profileDirsPrefix.append('/'); QStringList profiles; if (readProfiles) profiles = lookupProfiles(userMapFile); QString profile; bool priority = false; while(true) { config->setGroup(group); QStringList list = config->readListEntry("prefixes"); for (QStringList::ConstIterator it = list.begin(); it != list.end(); ++it) { addPrefix(*it, priority); addXdgConfigPrefix(*it+"/etc/xdg", priority); addXdgDataPrefix(*it+"/share", priority); } // If there are no prefixes defined, check if there is a directory // for this profile under <profileDirsPrefix> if (list.isEmpty() && !profile.isEmpty() && !profileDirsPrefix.isEmpty()) { QString dir = profileDirsPrefix + profile; addPrefix(dir, priority); addXdgConfigPrefix(dir+"/etc/xdg", priority); addXdgDataPrefix(dir+"/share", priority); } // iterating over all entries in the group Directories // to find entries that start with dir_$type QMap<QString, QString> entries = config->entryMap(group); for (QMap<QString, QString>::ConstIterator it2 = entries.begin(); it2 != entries.end(); it2++) { QString key = it2.key(); if (key.startsWith("dir_")) { // generate directory list, there may be more than 1. QStringList dirs = QStringList::split(',', *it2); QStringList::Iterator sIt(dirs.begin()); QString resType = key.mid(4, key.length()); for (; sIt != dirs.end(); ++sIt) { addResourceDir(resType.latin1(), *sIt, priority); } } } if (profiles.isEmpty()) break; profile = profiles.back(); group = QString::fromLatin1("Directories-%1").arg(profile); profiles.pop_back(); priority = true; } } // Process KIOSK restrictions. if (!kde_kiosk_admin || QCString(getenv("KDE_KIOSK_NO_RESTRICTIONS")).isEmpty()) { config->setGroup("KDE Resource Restrictions"); QMap<QString, QString> entries = config->entryMap("KDE Resource Restrictions"); for (QMap<QString, QString>::ConstIterator it2 = entries.begin(); it2 != entries.end(); it2++) { QString key = it2.key(); if (!config->readBoolEntry(key, true)) { d->restrictionsActive = true; d->restrictions.insert(key.latin1(), &d->restrictionsActive); // Anything will do dircache.remove(key.latin1()); } } } config->setGroup(oldGroup); // check if the number of config dirs changed bool configDirsChanged = (resourceDirs("config").count() != configdirs); // If the config dirs changed, we check kiosk restrictions again. d->checkRestrictions = configDirsChanged; // return true if the number of config dirs changed: reparse config file return configDirsChanged; }
void KStandardDirs::addKDEDefaults() { QStringList kdedirList; // begin KDEDIRS QString kdedirs = readEnvPath("KDEDIRS"); if (!kdedirs.isEmpty()) { tokenize(kdedirList, kdedirs, QChar(KPATH_SEPARATOR)); } else { QString kdedir = readEnvPath("KDEDIR"); if (!kdedir.isEmpty()) { kdedir = KShell::tildeExpand(kdedir); kdedirList.append(kdedir); } } #ifndef Q_OS_WIN //no default KDEDIR on win32 defined kdedirList.append(KDEDIR); #endif #ifdef __KDE_EXECPREFIX QString execPrefix(__KDE_EXECPREFIX); if (execPrefix!="NONE") kdedirList.append(execPrefix); #endif #ifdef __linux__ const QString linuxExecPrefix = executablePrefix(); if ( !linuxExecPrefix.isEmpty() ) kdedirList.append( linuxExecPrefix ); #endif // We treat root differently to prevent a "su" shell messing up the // file permissions in the user's home directory. QString localKdeDir = readEnvPath(getuid() ? "KDEHOME" : "KDEROOTHOME"); if (!localKdeDir.isEmpty()) { if (localKdeDir[localKdeDir.length()-1] != '/') localKdeDir += '/'; } else { localKdeDir = QDir::homeDirPath() + "/.kde/"; } if (localKdeDir != "-/") { localKdeDir = KShell::tildeExpand(localKdeDir); addPrefix(localKdeDir); } QStringList::ConstIterator end(kdedirList.end()); for (QStringList::ConstIterator it = kdedirList.begin(); it != end; ++it) { QString dir = KShell::tildeExpand(*it); addPrefix(dir); } // end KDEDIRS // begin XDG_CONFIG_XXX QStringList xdgdirList; QString xdgdirs = readEnvPath("XDG_CONFIG_DIRS"); if (!xdgdirs.isEmpty()) { tokenize(xdgdirList, xdgdirs, QChar(KPATH_SEPARATOR)); } else { xdgdirList.clear(); xdgdirList.append("/etc/xdg"); #ifdef Q_WS_WIN xdgdirList.append(kfsstnd_defaultprefix() + "/etc/xdg"); #else xdgdirList.append(KDESYSCONFDIR "/xdg"); #endif } QString localXdgDir = readEnvPath("XDG_CONFIG_HOME"); if (!localXdgDir.isEmpty()) { if (localXdgDir[localXdgDir.length()-1] != '/') localXdgDir += '/'; } else { localXdgDir = QDir::homeDirPath() + "/.config/"; } localXdgDir = KShell::tildeExpand(localXdgDir); addXdgConfigPrefix(localXdgDir); for (QStringList::ConstIterator it = xdgdirList.begin(); it != xdgdirList.end(); ++it) { QString dir = KShell::tildeExpand(*it); addXdgConfigPrefix(dir); } // end XDG_CONFIG_XXX // begin XDG_DATA_XXX xdgdirs = readEnvPath("XDG_DATA_DIRS"); if (!xdgdirs.isEmpty()) { tokenize(xdgdirList, xdgdirs, QChar(KPATH_SEPARATOR)); } else { xdgdirList.clear(); for (QStringList::ConstIterator it = kdedirList.begin(); it != kdedirList.end(); ++it) { QString dir = *it; if (dir[dir.length()-1] != '/') dir += '/'; xdgdirList.append(dir+"share/"); } xdgdirList.append("/usr/local/share/"); xdgdirList.append("/usr/share/"); } localXdgDir = readEnvPath("XDG_DATA_HOME"); if (!localXdgDir.isEmpty()) { if (localXdgDir[localXdgDir.length()-1] != '/') localXdgDir += '/'; } else { localXdgDir = QDir::homeDirPath() + "/.local/share/"; } localXdgDir = KShell::tildeExpand(localXdgDir); addXdgDataPrefix(localXdgDir); for (QStringList::ConstIterator it = xdgdirList.begin(); it != xdgdirList.end(); ++it) { QString dir = KShell::tildeExpand(*it); addXdgDataPrefix(dir); } // end XDG_DATA_XXX uint index = 0; while (types[index] != 0) { addResourceType(types[index], kde_default(types[index])); index++; } addResourceDir("home", QDir::homeDirPath()); }