/* * Gets the dir name of a file path, analogous to dirname(1) */ inline std::string dirName(std::string path) { removeDuplicateSlashes(path); removeTrailingSlash(path); path.erase(std::find(path.rbegin(), path.rend(), '/').base(), path.end()); removeTrailingSlash(path); if (path.empty()) { return "."; } return path; }
/* **************************************************************************** * * servicePathSplit - */ int servicePathSplit(ConnectionInfo* ciP) { int servicePaths = stringSplit(ciP->servicePath, ',', ciP->servicePathV); if (servicePaths == 0) { /* In this case the result is a 0 length vector */ return 0; } if (servicePaths > 10) { OrionError e(SccBadRequest, "too many service paths - a maximum of ten service paths is allowed"); ciP->answer = e.render(ciP->outFormat, ""); return -1; } for (int ix = 0; ix < servicePaths; ++ix) { ciP->servicePathV[ix] = std::string(wsStrip((char*) ciP->servicePathV[ix].c_str())); ciP->servicePathV[ix] = removeTrailingSlash(ciP->servicePathV[ix]); LM_T(LmtServicePath, ("Service Path %d: '%s'", ix, ciP->servicePathV[ix].c_str())); } for (int ix = 0; ix < servicePaths; ++ix) { int s; if ((s = servicePathCheck(ciP, ciP->servicePathV[ix].c_str())) != 0) return s; } return 0; }
static bool getPathsForPathCompletion(generic_string input, generic_string &rawPath_out, generic_string &pathToMatch_out) { generic_string rawPath; if(! getRawPath(input, rawPath)) { return false; } else if(isFile(rawPath) || isFile(removeTrailingSlash(rawPath))) { return false; } else if(isDirectory(rawPath)) { rawPath_out = rawPath; pathToMatch_out = rawPath; return true; } else { size_t last_occurrence = rawPath.rfind(L"\\"); if(last_occurrence == std::string::npos) // No match. { return false; } else { rawPath_out = rawPath; pathToMatch_out = rawPath.substr(0, last_occurrence); return true; } } }
DiscData DiscName::split(const QString & disc_url, bool * ok) { qDebug("DiscName::split: disc_url: '%s'", disc_url.toUtf8().constData()); QRegExp rx1("^(dvd|dvdnav|vcd|cdda)://(\\d+)/(.*)"); QRegExp rx2("^(dvd|dvdnav|vcd|cdda)://(\\d+)"); QRegExp rx3("^(dvd|dvdnav|vcd|cdda):///(.*)"); QRegExp rx4("^(dvd|dvdnav|vcd|cdda):(.*)"); DiscData d; bool success = false; if (rx1.indexIn(disc_url) != -1) { d.protocol = rx1.cap(1); d.title = rx1.cap(2).toInt(); d.device = rx1.cap(3); success = true; } else if (rx2.indexIn(disc_url) != -1) { d.protocol = rx2.cap(1); d.title = rx2.cap(2).toInt(); d.device = ""; success = true; } else if (rx3.indexIn(disc_url) != -1) { d.protocol = rx3.cap(1); d.title = 0; d.device = rx3.cap(2); success = true; } else if (rx4.indexIn(disc_url) != -1) { d.protocol = rx4.cap(1); d.title = 0; d.device =""; success = true; } if (!d.device.isEmpty()) d.device = removeTrailingSlash(d.device); if (success) { qDebug("DiscName::split: protocol: '%s'", d.protocol.toUtf8().constData()); qDebug("DiscName::split: title: '%d'", d.title); qDebug("DiscName::split: device: '%s'", d.device.toUtf8().constData()); } else { qWarning("DiscName::split: no match in regular expression"); } if (ok != 0) (*ok) = success; return d; }
QString DiscName::join(const DiscData & d) { QString s = d.protocol + "://"; if (d.title > 0) s += QString::number(d.title); if (!d.device.isEmpty()) s+= "/" + removeTrailingSlash(d.device); qDebug("DiscName::join: result: '%s'", s.toUtf8().constData()); return s; }
/** \brief Find the parent directory of a path * \param[in] path path * \return parent directory */ inline std::string getParentDir (const std::string &path) { std::string parentDir = boost::filesystem::path(removeTrailingSlash(path)).parent_path().string(); if (parentDir == "") parentDir = "./"; return parentDir; }
/* **************************************************************************** * * servicePathSplit - */ int servicePathSplit(ConnectionInfo* ciP) { #if 0 // // Special case: empty service-path // // FIXME P4: We're not sure what this 'fix' really fixes. // Must implement a functest to reproduce this situation. // And, if that is not possible, just remove the whole thing // if ((ciP->httpHeaders.servicePathReceived == true) && (ciP->servicePath == "")) { OrionError e(SccBadRequest, "empty service path"); ciP->answer = e.render(ciP, ""); alarmMgr.badInput(clientIp, "empty service path"); return -1; } #endif int servicePaths = stringSplit(ciP->servicePath, ',', ciP->servicePathV); if (servicePaths == 0) { /* In this case the result is a vector with an empty string */ ciP->servicePathV.push_back(""); return 0; } if (servicePaths > SERVICE_PATH_MAX_COMPONENTS) { OrionError e(SccBadRequest, "too many service paths - a maximum of ten service paths is allowed"); ciP->answer = e.render(ciP, ""); return -1; } for (int ix = 0; ix < servicePaths; ++ix) { std::string stripped = std::string(wsStrip((char*) ciP->servicePathV[ix].c_str())); ciP->servicePathV[ix] = removeTrailingSlash(stripped); // This was previously a LM_T trace, but we have "promoted" it to INFO due to it is needed to check logs in a .test case (case 0392 service_path_http_header.test) LM_I(("Service Path %d: '%s'", ix, ciP->servicePathV[ix].c_str())); } for (int ix = 0; ix < servicePaths; ++ix) { int s; if ((s = servicePathCheck(ciP, ciP->servicePathV[ix].c_str())) != 0) { return s; } } return 0; }
/* **************************************************************************** * * servicePathSplit - */ int servicePathSplit(ConnectionInfo* ciP) { #if 0 // // Special case: empty service-path // // FIXME P4: We're not sure what this 'fix' really fixes. // Must implement a functest to reproduce this situation. // And, if that is not possible, just remove the whole thing // if ((ciP->httpHeaders.servicePathReceived == true) && (ciP->servicePath == "")) { OrionError e(SccBadRequest, "empty service path"); ciP->answer = e.render(ciP->outFormat, ""); LM_W(("Bad Input (empty service path)")); return -1; } #endif int servicePaths = stringSplit(ciP->servicePath, ',', ciP->servicePathV); if (servicePaths == 0) { /* In this case the result is a 0 length vector */ return 0; } if (servicePaths > 10) { OrionError e(SccBadRequest, "too many service paths - a maximum of ten service paths is allowed"); ciP->answer = e.render(ciP->outFormat, ""); return -1; } for (int ix = 0; ix < servicePaths; ++ix) { ciP->servicePathV[ix] = std::string(wsStrip((char*) ciP->servicePathV[ix].c_str())); ciP->servicePathV[ix] = removeTrailingSlash(ciP->servicePathV[ix]); LM_T(LmtServicePath, ("Service Path %d: '%s'", ix, ciP->servicePathV[ix].c_str())); } for (int ix = 0; ix < servicePaths; ++ix) { int s; if ((s = servicePathCheck(ciP, ciP->servicePathV[ix].c_str())) != 0) return s; } return 0; }
void SocketApi::slotNewConnection() { QIODevice* socket = _localServer.nextPendingConnection(); if( ! socket ) { return; } DEBUG << "New connection" << socket; connect(socket, SIGNAL(readyRead()), this, SLOT(slotReadSocket())); connect(socket, SIGNAL(disconnected()), this, SLOT(onLostConnection())); Q_ASSERT(socket->readAll().isEmpty()); _listeners.append(socket); foreach( Folder *f, FolderMan::instance()->map() ) { if (f->canSync()) { QString message = buildRegisterPathMessage(removeTrailingSlash(f->path())); sendMessage(socket, message); } } }
void Ntop::setWorkingDir(char *dir) { snprintf(working_dir, sizeof(working_dir), "%s", dir); removeTrailingSlash(working_dir); };
void SyscallPolicy::addDefaultWebProcessPolicy(const WebProcessCreationParameters& parameters) { // Directories settings coming from the UIProcess. if (!parameters.applicationCacheDirectory.isEmpty()) addDirectoryPermission(removeTrailingSlash(parameters.applicationCacheDirectory), ReadAndWrite); if (!parameters.webSQLDatabaseDirectory.isEmpty()) addDirectoryPermission(removeTrailingSlash(parameters.webSQLDatabaseDirectory), ReadAndWrite); if (!parameters.diskCacheDirectory.isEmpty()) addDirectoryPermission(removeTrailingSlash(parameters.diskCacheDirectory), ReadAndWrite); if (!parameters.cookieStorageDirectory.isEmpty()) addDirectoryPermission(removeTrailingSlash(parameters.cookieStorageDirectory), ReadAndWrite); #if USE(SOUP) if (!parameters.cookiePersistentStoragePath.isEmpty()) addDirectoryPermission(removeTrailingSlash(parameters.cookiePersistentStoragePath), ReadAndWrite); #endif // The root policy will block access to any directory or // file unless white listed bellow or by platform. addDirectoryPermission(ASCIILiteral("/"), NotAllowed); // Shared libraries, plugins and fonts. addDirectoryPermission(ASCIILiteral("/lib"), Read); addDirectoryPermission(ASCIILiteral("/lib32"), Read); addDirectoryPermission(ASCIILiteral("/lib64"), Read); addDirectoryPermission(ASCIILiteral("/usr/lib"), Read); addDirectoryPermission(ASCIILiteral("/usr/lib32"), Read); addDirectoryPermission(ASCIILiteral("/usr/lib64"), Read); addDirectoryPermission(ASCIILiteral("/usr/share"), Read); // Support for alternative install prefixes, e.g. /usr/local. addDirectoryPermission(ASCIILiteral(DATADIR), Read); addDirectoryPermission(ASCIILiteral(LIBDIR), Read); // Plugin search path for (String& path : pluginsDirectories()) addDirectoryPermission(path, Read); // SSL Certificates. addDirectoryPermission(ASCIILiteral("/etc/ssl/certs"), Read); // Fontconfig cache. addDirectoryPermission(ASCIILiteral("/etc/fonts"), Read); addDirectoryPermission(ASCIILiteral("/var/cache/fontconfig"), Read); // Audio devices, random number generators, etc. addDirectoryPermission(ASCIILiteral("/dev"), ReadAndWrite); // Temporary files and process self information. addDirectoryPermission(ASCIILiteral("/tmp"), ReadAndWrite); addDirectoryPermission(ASCIILiteral("/proc/") + String::number(getpid()), ReadAndWrite); // In some distros /dev/shm is a symbolic link to /run/shm, and in // this case, the canonical path resolver will follow the link. If // inside /dev, the policy is already set. addDirectoryPermission(ASCIILiteral("/run/shm"), ReadAndWrite); // Needed by glibc for networking and locale. addFilePermission(ASCIILiteral("/etc/gai.conf"), Read); addFilePermission(ASCIILiteral("/etc/host.conf"), Read); addFilePermission(ASCIILiteral("/etc/hosts"), Read); addFilePermission(ASCIILiteral("/etc/localtime"), Read); addFilePermission(ASCIILiteral("/etc/nsswitch.conf"), Read); // Needed for DNS resoltion. In some distros, the resolv.conf inside // /etc is just a symbolic link. addFilePermission(ASCIILiteral("/etc/resolv.conf"), Read); addFilePermission(ASCIILiteral("/run/resolvconf/resolv.conf"), Read); // Needed to convert uid and gid into names. addFilePermission(ASCIILiteral("/etc/group"), Read); addFilePermission(ASCIILiteral("/etc/passwd"), Read); // Needed by the loader. addFilePermission(ASCIILiteral("/etc/ld.so.cache"), Read); // Needed by various, including toolkits, for optimizations based // on the current amount of free system memory. addFilePermission(ASCIILiteral("/proc/cpuinfo"), Read); addFilePermission(ASCIILiteral("/proc/filesystems"), Read); addFilePermission(ASCIILiteral("/proc/meminfo"), Read); addFilePermission(ASCIILiteral("/proc/stat"), Read); // Needed by D-Bus. addFilePermission(ASCIILiteral("/var/lib/dbus/machine-id"), Read); // Needed by at-spi2. // FIXME This is too permissive: https://bugs.webkit.org/show_bug.cgi?id=143004 addDirectoryPermission("/run/user/" + String::number(getuid()), ReadAndWrite); // Needed by WebKit's memory pressure handler addFilePermission(ASCIILiteral("/sys/fs/cgroup/memory/memory.pressure_level"), Read); addFilePermission(ASCIILiteral("/sys/fs/cgroup/memory/cgroup.event_control"), Read); char* homeDir = getenv("HOME"); if (homeDir) { // X11 connection token. addFilePermission(String::fromUTF8(homeDir) + "/.Xauthority", Read); } // MIME type resolution. char* dataHomeDir = getenv("XDG_DATA_HOME"); if (dataHomeDir) addDirectoryPermission(String::fromUTF8(dataHomeDir) + "/mime", Read); else if (homeDir) addDirectoryPermission(String::fromUTF8(homeDir) + "/.local/share/mime", Read); #if ENABLE(WEBGL) || ENABLE(ACCELERATED_2D_CANVAS) // Needed on most non-Debian distros by libxshmfence <= 1.1, or newer // libxshmfence with older kernels (linux <= 3.16), for DRI3 shared memory. // FIXME Try removing this permission when we can rely on a newer libxshmfence. // See http://code.google.com/p/chromium/issues/detail?id=415681 addDirectoryPermission(ASCIILiteral("/var/tmp"), ReadAndWrite); // Optional Mesa DRI configuration file addFilePermission(ASCIILiteral("/etc/drirc"), Read); if (homeDir) addFilePermission(String::fromUTF8(homeDir) + "/.drirc", Read); // Mesa uses udev. addDirectoryPermission(ASCIILiteral("/etc/udev"), Read); addDirectoryPermission(ASCIILiteral("/run/udev"), Read); addDirectoryPermission(ASCIILiteral("/sys/bus"), Read); addDirectoryPermission(ASCIILiteral("/sys/class"), Read); addDirectoryPermission(ASCIILiteral("/sys/devices"), Read); #endif // Needed by NVIDIA proprietary graphics driver if (homeDir) addDirectoryPermission(String::fromUTF8(homeDir) + "/.nv", ReadAndWrite); #if ENABLE(DEVELOPER_MODE) && defined(SOURCE_DIR) // Developers using build-webkit expect some libraries to be loaded // from the build root directory and they also need access to layout test // files. char* sourceDir = canonicalize_file_name(SOURCE_DIR); if (sourceDir) { addDirectoryPermission(String::fromUTF8(sourceDir), SyscallPolicy::ReadAndWrite); free(sourceDir); } #endif }