String CMake::joinPaths(const List<String>& items, bool absolute) { String result; const List<String>::Node* i = items.getFirst(); if(i) { result = translatePath(i->data, absolute); for(i = i->getNext(); i; i = i->getNext()) { result.append(' '); result.append(translatePath(i->data, absolute)); } } return result; }
void KConfigGroup::writePathEntry(const char *pKey, const QString & path, WriteConfigFlags pFlags) { Q_ASSERT_X(isValid(), "KConfigGroup::writePathEntry", "accessing an invalid group"); Q_ASSERT_X(!d->bConst, "KConfigGroup::writePathEntry", "writing to a read-only group"); config()->d_func()->putData(d->fullName(), pKey, translatePath(path).toUtf8(), pFlags, true); }
void KConfigGroup::writePathEntry(const char *pKey, const QStringList &value, WriteConfigFlags pFlags) { Q_ASSERT_X(isValid(), "KConfigGroup::writePathEntry", "accessing an invalid group"); Q_ASSERT_X(!d->bConst, "KConfigGroup::writePathEntry", "writing to a read-only group"); QList<QByteArray> list; Q_FOREACH(const QString& path, value) list << translatePath(path).toUtf8(); config()->d_func()->putData(d->fullName(), pKey, KConfigGroupPrivate::serializeList(list), pFlags, true); }
void Alcatraz::rmdir_entry() { CString arg0(getArgRep(0)) ; pid_t pid = mp->pid() ; ArchDep *arch = mp->getArch() ; char normpath[PATH_MAX], buf[PATH_MAX] ; normalizePath(arg0.get().c_str(), normpath) ; int maptype = translatePath(normpath, buf, false, tempname); switch(maptype) { case PATH_NOTALLOWED: arch->abortCall(pid, -1, ENOENT); break ; case PATH_DELETED:{ arch->abortCall(pid, -1, ENOENT); break ; } case PATH_CREATED: case PATH_MODIFIED:{ int retval = rmdir(buf) ; if (0 == retval) { mt.delMapping(tempname) ; arch->abortCall(pid, 0, 0) ; #ifdef INSTALL_SHIELD pid_t ppid = mp->ppid() ; mod_log("D", normpath, "N/A", "DE", pid, ppid) ; #endif } else { arch->abortCall(pid, -1, errno) ; } break ; } case PATH_NEW:{ int retval = rmdir_failure(buf) ; if (retval != 0) { arch->abortCall(pid, -1, retval) ; } else { mt.newDelete(TYPE_DIRECTORY, buf) ; arch->abortCall(pid, 0, 0) ; #ifdef INSTALL_SHIELD pid_t ppid = mp->ppid() ; mod_log("D", buf, "N/A", "DE", pid, ppid) ; #endif } break ; } default: break; } }
void KConfigBase::writePathEntry(const char *pKey, const QStringList &list, char sep, bool bPersistent, bool bGlobal, bool bNLS) { if(list.isEmpty()) { writeEntry(pKey, QString::fromLatin1(""), bPersistent); return; } QStringList new_list; QStringList::ConstIterator it = list.begin(); for(; it != list.end(); ++it) { QString value = *it; new_list.append(translatePath(value)); } writeEntry(pKey, new_list, sep, bPersistent, bGlobal, bNLS, true); }
void Alcatraz::mknod_entry() { CString arg0(getArgRep(0)) ; pid_t pid = mp->pid() ; ArchDep *arch = mp->getArch() ; char normpath[PATH_MAX], buf[PATH_MAX] ; normalizePath(arg0.get().c_str(), normpath) ; int maptype = translatePath(normpath, buf, false, tempname); switch (maptype) { case PATH_NOTALLOWED: arch->abortCall(pid, -1, ENOENT); break; case PATH_DELETED:{ mt.delMapping(tempname) ; char tempfile[PATH_MAX] ; mt.newEntry(TYPE_FILE, PATH_MODIFIED, tempname, tempfile) ; #ifdef INSTALL_SHIELD pid_t ppid = mp->ppid() ; mod_log("F", normpath, tempfile, "CR", pid, ppid) ; #endif arg0.set(tempfile) ; break ; } case PATH_CREATED: case PATH_MODIFIED: arg0.set(buf) ; break ; case PATH_NEW :{ int retval = mknod_failure(buf) ; if (retval != 0) { arch->abortCall(pid, -1, retval) ; } else { char tempfile[PATH_MAX] ; mt.newEntry(TYPE_FILE, PATH_CREATED, buf, tempfile) ; arg0.set(tempfile) ; #ifdef INSTALL_SHIELD pid_t ppid = mp->ppid() ; mod_log("F", normpath, tempfile, "CR", pid, ppid) ; #endif } } } }
void Alcatraz::truncate_entry() { CString arg0(getArgRep(0)) ; pid_t pid = mp->pid() ; ArchDep *arch = mp->getArch() ; char normpath[PATH_MAX], buf[PATH_MAX] ; /* first get the real path of the file */ normalizePath(arg0.get().c_str(), normpath) ; int maptype = translatePath(normpath, buf, true); switch (maptype) { case PATH_NOTALLOWED: arch->abortCall(pid, -1, ENOENT) ; break ; case PATH_DELETED: arch->abortCall(pid, -1, ENOENT) ; break ; case PATH_CREATED: case PATH_MODIFIED:{ #ifdef INSTALL_SHIELD pid_t ppid = mp->ppid() ; mod_log("F", normpath, buf, "MD", pid, ppid) ; #endif arg0.set(buf) ; break ; } case PATH_NEW: { int retval = truncate_failure(buf) ; if (retval != 0) { arch->abortCall(pid, -1, retval) ; } else { char tempfile[PATH_MAX] ; mt.isolate(buf, tempfile, false) ; #ifdef INSTALL_SHIELD pid_t ppid = mp->ppid() ; mod_log("F", normpath, tempfile, "MD", pid, ppid) ; #endif arg0.set(tempfile) ; } break ; } } }
bool CMake::writeProject(const String& targetName, Project& project) { Directory::create(String(".CMake/") + targetName); fileOpen(String(".CMake/") + targetName + "/CMakeLists.txt"); fileWrite("cmake_policy(SET CMP0015 NEW)\n\n"); for(const Map<String, ProjectConfiguration>::Node* i = project.configurations.getFirst(); i; i = i->getNext()) { const String& configName = i->key; const ProjectConfiguration& config = i->data; const Target& target = *config.target; if(i == project.configurations.getFirst()) fileWrite(String("if(CMAKE_BUILD_TYPE STREQUAL \"") + configName +"\")\n"); else fileWrite(String("elseif(CMAKE_BUILD_TYPE STREQUAL \"") + configName +"\")\n"); if(!target.includePaths.isEmpty()) fileWrite(String("include_directories(") + joinPaths(target.includePaths) + ")\n"); if(!target.libPaths.isEmpty()) fileWrite(String("link_directories(") + joinPaths(target.libPaths) + ")\n"); List<String> customBuildOutput; for(const List<const File*>::Node* i = config.customBuildFiles.getFirst(); i; i = i->getNext()) { const File& file = *i->data; fileWrite("add_custom_command(\n"); fileWrite(String(" OUTPUT ") + joinPaths(file.output, true) + "\n"); Map<String, void*> outputDirs; for(const List<String>::Node* i = file.output.getFirst(); i; i = i->getNext()) { String dir = ::File::getDirname(i->data); if(dir != "." && !outputDirs.find(dir)) outputDirs.append(dir); } for(Map<String, void*>::Node* i = outputDirs.getFirst(); i; i = i->getNext()) fileWrite(String(" COMMAND ${CMAKE_COMMAND} -E make_directory ") + translatePath(i->key, true) + "\n"); for(const List<String>::Node* i = file.command.getFirst(); i; i = i->getNext()) fileWrite(String(" COMMAND ") + i->data + "\n"); fileWrite(String(" DEPENDS ") + joinPaths(file.input) + "\n"); fileWrite(" WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../..\n"); if(!file.message.isEmpty()) fileWrite(String(" COMMENT \"") + file.message.getFirst()->data + "\"\n"); fileWrite(" )\n"); for(const List<String>::Node* i = file.output.getFirst(); i; i = i->getNext()) customBuildOutput.append(i->data); } if(config.type == ProjectConfiguration::applicationType) fileWrite(String("add_executable(") + targetName + " " + joinPaths(config.sourceFiles) + " " + joinPaths(customBuildOutput, true) + ")\n"); else if(config.type == ProjectConfiguration::dynamicLibraryType) fileWrite(String("add_library(") + targetName + " SHARED " + joinPaths(config.sourceFiles) + " " + joinPaths(customBuildOutput, true) + ")\n"); else if(config.type == ProjectConfiguration::staticLibraryType) fileWrite(String("add_library(") + targetName + " STATIC " + joinPaths(config.sourceFiles) + " " + joinPaths(customBuildOutput, true) + ")\n"); else if(config.type == ProjectConfiguration::customTargetType) { if(!target.output.isEmpty() && !target.command.isEmpty()) { fileWrite("add_custom_command(\n"); fileWrite(String(" OUTPUT ") + joinPaths(target.output, true) + "\n"); Map<String, void*> outputDirs; for(const List<String>::Node* i = target.output.getFirst(); i; i = i->getNext()) { String dir = ::File::getDirname(i->data); if(dir != "." && !outputDirs.find(dir)) outputDirs.append(dir); customBuildOutput.append(i->data); } for(Map<String, void*>::Node* i = outputDirs.getFirst(); i; i = i->getNext()) fileWrite(String(" COMMAND ${CMAKE_COMMAND} -E make_directory ") + translatePath(i->key, true) + "\n"); for(const List<String>::Node* i = target.command.getFirst(); i; i = i->getNext()) fileWrite(String(" COMMAND ") + i->data + "\n"); fileWrite(String(" DEPENDS ") + joinPaths(target.input) + "\n"); fileWrite(" WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../..\n"); if(!target.message.isEmpty()) fileWrite(String(" COMMENT \"") + target.message.getFirst()->data + "\"\n"); fileWrite(" )\n"); } fileWrite(String("add_custom_target(") + targetName + " ALL\n"); fileWrite(String(" DEPENDS ") + joinPaths(customBuildOutput, true) + "\n"); fileWrite(String(" SOURCES ") + joinPaths(config.sourceFiles) + "\n"); fileWrite(" )\n"); } /* if(!config.libs.isEmpty()) { List<String> libs; for(const List<Library>::Node* i = config.libs.getFirst(); i; i = i->getNext()) { const Library& lib = i->data; if(lib.type == Library::localType) libs.append(lib.name); else { fileWrite(String("find_library(") + lib.name + "_LIBRARY " + lib.name + " PATHS " + join(target.libPaths) + ")\n"); libs.append(String("${") + lib.name + "_LIBRARY}"); } } fileWrite(String("target_link_libraries(") + targetName + " " + join(libs) + ")\n"); } */ if(!config.libs.isEmpty()) { List<String> libs; for(const List<Library>::Node* i = config.libs.getFirst(); i; i = i->getNext()) libs.append(i->data.name); fileWrite(String("target_link_libraries(") + targetName + " " + join(libs) + ")\n"); } if(!target.cppCompiler.isEmpty()) { String cppCompiler; for(const List<String>::Node* i = target.cppCompiler.getFirst(); i; i = i->getNext()) { const String& word = i->data; size_t sep; if(word.find('=', sep)) fileWrite(String("set(ENV{") + word.substr(0, sep) + "} \"" + word.substr(sep + 1) + "\")\n"); else { cppCompiler = word; break; } } if(!cppCompiler.isEmpty()) { if(!::File::isPathAbsolute(cppCompiler) && ::File::exists(cppCompiler)) fileWrite(String("set(CMAKE_CXX_COMPILER \"${CMAKE_CURRENT_SOURCE_DIR}/../../") + cppCompiler + "\")\n"); else fileWrite(String("set(CMAKE_CXX_COMPILER \"") + cppCompiler + "\")\n"); } } if(!target.cCompiler.isEmpty()) { String cCompiler; for(const List<String>::Node* i = target.cCompiler.getFirst(); i; i = i->getNext()) { const String& word = i->data; size_t sep; if(word.find('=', sep)) fileWrite(String("set(ENV{") + word.substr(0, sep) + "} \"" + word.substr(sep + 1) + "\")\n"); else { cCompiler = word; break; } } if(!cCompiler.isEmpty()) { if(!::File::isPathAbsolute(cCompiler) && ::File::exists(cCompiler)) fileWrite(String("set(CMAKE_C_COMPILER \"${CMAKE_CURRENT_SOURCE_DIR}/../../") + cCompiler + "\")\n"); else fileWrite(String("set(CMAKE_C_COMPILER \"") + cCompiler + "\")\n"); } } /* if(!target.cppFlags.isEmpty()) fileWrite(String("set_property(TARGET ") + targetName + " PROPERTY COMPILE_FLAGS \"" + join(target.cppFlags) + "\")\n"); */ if(!target.cppFlags.isEmpty()) fileWrite(String("set(CMAKE_CXX_FLAGS \"") + join(target.cppFlags) + "\")\n"); if(!target.cFlags.isEmpty()) fileWrite(String("set(CMAKE_C_FLAGS \"") + join(target.cFlags) + "\")\n"); if(!target.output.isEmpty()) { String outputDirectory = ::File::getDirname(target.output.getFirst()->data); // Hi cmake devs! I do not know whats considered to be an ARCHIVE, LIBRARY or RUNTIME. So I will set all properties to be sure. fileWrite(String("set_property(TARGET ") + targetName + " PROPERTY ARCHIVE_OUTPUT_DIRECTORY \"" + translatePath(outputDirectory) + "\")\n"); fileWrite(String("set_property(TARGET ") + targetName + " PROPERTY LIBRARY_OUTPUT_DIRECTORY \"" + translatePath(outputDirectory) + "\")\n"); fileWrite(String("set_property(TARGET ") + targetName + " PROPERTY RUNTIME_OUTPUT_DIRECTORY \"" + translatePath(outputDirectory) + "\")\n"); String outputName = ::File::getWithoutExtension(::File::getBasename(target.output.getFirst()->data)); outputName.patsubst("lib%", "%"); fileWrite(String("set_property(TARGET ") + targetName + " PROPERTY OUTPUT_NAME \"" + outputName + "\")\n"); } if(!target.linkFlags.isEmpty()) { if(config.type == ProjectConfiguration::staticLibraryType) fileWrite(String("set_property(TARGET ") + targetName + " PROPERTY STATIC_LIBRARY_FLAGS " + join(target.linkFlags) + ")\n"); else fileWrite(String("set_property(TARGET ") + targetName + " PROPERTY LINK_FLAGS \"" + join(target.linkFlags) + "\")\n"); } if(!target.defines.isEmpty()) fileWrite(String("set_property(TARGET ") + targetName + " PROPERTY COMPILE_DEFINITIONS " + join(target.defines) + ")\n"); if(!target.dependencies.isEmpty()) fileWrite(String("add_dependencies(") + targetName + " " + join(target.dependencies) + ")\n"); } fileWrite("endif()\n"); fileClose(); return true; }
void Alcatraz::unlink_entry() { CString arg0(getArgRep(0)) ; pid_t pid = mp->pid() ; ArchDep *arch = mp->getArch() ; state = -1 ; char normpath[PATH_MAX], buf[PATH_MAX]; if (strlen(arg0.get().c_str()) == 0) arch->abortCall(pid, 0, 0) ; normalizePath(arg0.get().c_str(), normpath) ; int maptype = translatePath(normpath, buf, false, tempname); switch (maptype) { case PATH_NOTALLOWED: arch->abortCall(pid, -1, ENOENT); break; case PATH_DELETED:{ arch->abortCall(pid, -1, ENOENT) ; break ; } case PATH_CREATED: { state = 0 ; arg0.set(buf) ; #ifdef INSTALL_SHIELD pid_t ppid = mp->ppid() ; mod_log("F", normpath, "N/A", "DE", pid, ppid) ; #endif break ; } case PATH_MODIFIED:{ state = 1 ; arg0.set(buf) ; #ifdef INSTALL_SHIELD pid_t ppid = mp->ppid() ; mod_log("F", normpath, "N/A", "DE", pid, ppid) ; #endif break ; } case PATH_NEW:{ int retval ; retval = unlink_failure(buf) ; if (retval != 0) { arch->abortCall(pid, -1, retval) ; } else { mt.newDelete(TYPE_FILE, buf) ; arch->abortCall(pid, 0, 0) ; #ifdef INSTALL_SHIELD pid_t ppid = mp->ppid() ; mod_log("F", buf, "N/A", "DE", pid, ppid) ; #endif } break ; } default: break; } }
void Alcatraz::open_entry() { CString arg0(getArgRep(0)) ; Integer arg1(getArgRep(1)) ; pid_t pid = mp->pid() ; ArchDep *arch = mp->getArch() ; char normpath[PATH_MAX], buf[PATH_MAX] ; int maptype ; if (strncmp("/.a_to_GUI", arg0.get().c_str(), 10) == 0) { mt.mapping.sendtoGUI(false) ; arch->abortCall(pid, -1, EPERM) ; return ; } if (strncmp("/.alcatraz", arg0.get().c_str(), 10) == 0) { arg0.set(arg0.get().c_str()+10) ; arg1.set(0) ; return ; } // check open modes int flag = arg1.get() ; bool readonly = true ; if (flag&O_WRONLY || flag&O_RDWR || flag&O_CREAT) readonly = false ; bool trunc = false ; if (!readonly && flag&O_TRUNC) trunc = true ; normalizePath(arg0.get().c_str(), normpath) ; maptype = translatePath(normpath, buf, true, tempname); // Remember the association between file descriptors and path names // It remembers the canonized name char *tmp ; if (PATH_NEW == maptype) tmp = buf ; else tmp = normpath ; size_t strsize = strlen(tmp) + 1 ; char *duppath = new char[strsize] ; if (0 != duppath) { memcpy(duppath, tmp, strsize) ; } ProcData *pData = processData.lookUp(pid) ; if (0 == pData) { pData = new ProcData() ; processData.insert(pid, pData) ; } pData->storeOpenName(duppath) ; switch(maptype) { case PATH_NOTALLOWED: arch->abortCall(pid, -1, ENOENT); break; case PATH_CREATED: case PATH_MODIFIED: #ifdef INSTALL_SHIELD if (!readonly) { pid_t ppid = mp->ppid() ; mt.mapping.appendTime(normpath, pid, ppid) ; if (access(buf, F_OK) == 0) mod_log("F", normpath, buf, "MD", pid, ppid) ; else mod_log("F", normpath, buf, "CR", pid, ppid) ; } #endif arg0.set(buf) ; break ; case PATH_DELETED: { if (readonly) arch->abortCall(pid, -1, ENOENT) ; else { /* create a new file, delete previous entry and generate a new temp file */ char tempfile[PATH_MAX] ; mt.delMapping(tempname) ; mt.newEntry(TYPE_FILE, PATH_MODIFIED, tempname, tempfile) ; arg0.set(tempfile) ; #ifdef INSTALL_SHIELD pid_t ppid = mp->ppid() ; mod_log("F", normpath, tempfile, "CR", pid, ppid) ; #endif } break ; } case PATH_NEW: { if (!readonly){ if (access(buf, F_OK)==0) { /* File exists */ struct stat statbuf ; if (stat(buf, &statbuf) == 0){/*success*/ if (!S_ISREG(statbuf.st_mode)) break ; } if (access(buf, W_OK) == 0) { /* can write, isolate file */ char tempfile[PATH_MAX] ; mt.isolate(buf, tempfile, trunc) ; arg0.set(tempfile) ; #ifdef INSTALL_SHIELD pid_t ppid = mp->ppid() ; mod_log("F", normpath, tempfile, "MD", pid, ppid) ; #endif } } else { /* File Not Exists */ if (parent_writable(buf)) { char tempfile[PATH_MAX] ; mt.newEntry(TYPE_FILE, PATH_CREATED, buf, tempfile) ; // mt.getStatus(normpath, buf) ; arg0.set(tempfile) ; #ifdef INSTALL_SHIELD pid_t ppid = mp->ppid() ; mod_log("F", normpath, tempfile, "CR", pid, ppid) ; #endif } } } else { arg0.set(buf) ; } break ; } default: break ; } }
void KConfigBase::writePathEntry(const char *pKey, const QString &path, bool bPersistent, bool bGlobal, bool bNLS) { writeEntry(pKey, translatePath(path), bPersistent, bGlobal, bNLS, true); }