void Environment::initialize(int argc, char* argv[]) { std::string app = Shell::executeFetch("which " + std::string(argv[0])); std::string bin = Shell::executeFetch("dirname " + app); prefix = Shell::executeFetch("cd " + bin + "/..; pwd"); name = app.substr(app.find_last_of('/') + 1); #ifdef USE_FSH std::string conf = "/etc/opencde/" + name; #else std::string conf = prefix + "/etc/opencde/" + name; #endif setenv("OPENCDE_PREFIX", prefix.c_str(), 1); if(Filesystem::folderExists(conf) == true) { if(Filesystem::folderExists(getHome() + "/.opencde") == false) { Filesystem::createFolder(getHome() + "/.opencde"); } if(Filesystem::folderExists(getHome() + "/.opencde/" + name) == false) { Filesystem::copyFolder(conf, getHome() + "/.opencde/" + name); } } Motif::Application::addFallbackResource("*exceptionDialog.background: #1A1866"); Motif::Application::addFallbackResource("*exceptionDialog*informationLabel.background: #1A1866"); Motif::Application::addFallbackResource("*exceptionDialog*messageLabel.background: #1A1866"); Motif::Application::addFallbackResource("*exceptionDialog*informationPanel*shadowThickness: 1"); Motif::Application::addFallbackResource("*exceptionDialog*fontList: -*-fixed-*-*-*-*-*-120-*-*-*-*-*-*"); }
static const char *xdgConfigFolder() { static char xdgDir[QTC_MAX_FILENAME_LEN]={'\0'}; if(!xdgDir[0]) { static const char *home=NULL; #if 0 char *env=getenv("XDG_CONFIG_HOME"); /* Check the setting of XDG_CONFIG_HOME For some reason, sudo leaves the env vars set to those of the caller - so XDG_CONFIG_HOME would point to the users setting, and not roots. Therefore, check that home is first part of XDG_CONFIG_HOME */ if(env && 0==getuid()) { if(!home) home=getHome(); if(home && home!=strstr(env, home)) env=NULL; } #else /* Hmm... for 'root' dont bother to check env var, just set to ~/.config - as problems would arise if "sudo kcmshell style", and then "sudo su" / "kcmshell style". The 1st would write to ~/.config, but if root has a XDG_ set then that would be used on the second :-( */ char *env=0==getuid() ? NULL : getenv("XDG_CONFIG_HOME"); #endif if(!env) { if(!home) home=getHome(); sprintf(xdgDir, "%s/.config", home); } else strcpy(xdgDir, env); #ifdef CONFIG_WRITE #ifdef __cplusplus KStandardDirs::makeDir(xdgDir); #endif #endif } return xdgDir; }
void initDirectories(void) { if(PREF_DIR[0] != '~') sprintf(preferences_dir, PREF_DIR); else sprintf(preferences_dir, "%s%s", getHome(), PREF_DIR + 1); if(SNAP_DIR[0] != '~') sprintf(snapshots_dir, SNAP_DIR); else sprintf(snapshots_dir, "%s%s", getHome(), SNAP_DIR + 1); #ifdef LOCAL_DATA #ifdef macintosh sprintf(data_dir, ":data"); sprintf(art_dir, ":art"); sprintf(scripts_dir, ":scripts"); sprintf(music_dir, ":music"); sprintf(level_dir, ":levels"); #else sprintf(data_dir, "data"); sprintf(art_dir, "art"); sprintf(scripts_dir, "scripts"); sprintf(music_dir, "music"); sprintf(level_dir, "levels"); #endif #else sprintf(data_dir, "%s%c%s", DATA_DIR, SEPARATOR, "data"); sprintf(art_dir, "%s%c%s", DATA_DIR, SEPARATOR, "art"); sprintf(scripts_dir, "%s%c%s", DATA_DIR, SEPARATOR, "scripts"); sprintf(music_dir, "%s%c%s", DATA_DIR, SEPARATOR, "music"); sprintf(level_dir, "%s%c%s", DATA_DIR, SEPARATOR, "levels"); #endif /* printf("directories:\n" "\tprefs: %s\n" "\tsnaps: %s\n" "\tdata: %s\n" "\tart: %s\n" "\tscripts: %s\n" "\tmusic: %s\n", preferences_dir, snapshots_dir, data_dir, art_dir, scripts_dir, music_dir); */ makeDirectory(preferences_dir); makeDirectory(snapshots_dir); }
solvedMap_c::solvedMap_c(void) { std::ifstream in((getHome()+"solved.txt").c_str()); std::string line; // add default user users.push_back(userData_c()); while (in.good()) { getline(in, line); if (line != "") { if (line[0] == 'U' and line[1] == ' ') { users.push_back(userData_c(line.substr(2))); } else { map.insert(line); } } } currentUser = 0; }
// Load Configure File void Properties::loadConfigureFile(const char *fileName) { std::string adjustedFilename; if (fileName) { // perform a naive determination if this is a relative path if (fileName[0] != '/') { adjustedFilename = adjustedFilename + getHome() + "/" + fileName; } else { adjustedFilename += fileName; } } char *path = NULL; char full_path[PATH_MAX]; path = realpath(adjustedFilename.c_str(), full_path); logger_->log_info("Using configuration file located at %s", path); std::ifstream file(path, std::ifstream::in); if (!file.good()) { logger_->log_error("load configure file failed %s", path); return; } this->clear(); char buf[BUFFER_SIZE]; for (file.getline(buf, BUFFER_SIZE); file.good(); file.getline(buf, BUFFER_SIZE)) { parseConfigureFileLine(buf); } }
/** * Finds the Config folder according to the running system. * @return Config path. */ std::string findConfigFolder() { #ifdef __MORPHOS__ return "PROGDIR:"; #endif #if defined(_WIN32) || defined(__APPLE__) return ""; #elif defined (__HAIKU__) return "/boot/home/config/settings/openxcom/"; #else char const *home = getHome(); char path[MAXPATHLEN]; // Get config folders if (char const *const xdg_config_home = getenv("XDG_CONFIG_HOME")) { snprintf(path, MAXPATHLEN, "%s/openxcom/", xdg_config_home); return path; } else { snprintf(path, MAXPATHLEN, "%s/.config/openxcom/", home); return path; } #endif }
/** * Finds the Config folder according to the running system. * @return Config path. */ std::string findConfigFolder() { #ifdef __MORPHOS__ return "PROGDIR:"; #endif #if defined(_WIN32) || defined(__APPLE__) return ""; #elif defined (__HAIKU__) char settings_path[B_PATH_NAME_LENGTH]; find_directory(B_USER_SETTINGS_DIRECTORY, 0, true, settings_path, sizeof(settings_path)-strlen("/OpenXcom/")); strcat(settings_path,"/OpenXcom/"); return settings_path; #else char const *home = getHome(); char path[MAXPATHLEN]; // Get config folders if (char const *const xdg_config_home = getenv("XDG_CONFIG_HOME")) { snprintf(path, MAXPATHLEN, "%s/openxcom/", xdg_config_home); return path; } else { snprintf(path, MAXPATHLEN, "%s/.config/openxcom/", home); return path; } #endif }
/** * Builds a list of predefined paths for the User folder * according to the running system. * @return List of data paths. */ std::vector<std::string> findUserFolders() { std::vector<std::string> list; #ifdef _WIN32 char path[MAX_PATH]; // Get Documents folder if (SUCCEEDED(SHGetFolderPathA(NULL, CSIDL_PERSONAL, NULL, SHGFP_TYPE_CURRENT, path))) { PathAppendA(path, "OpenXcom\\"); list.push_back(path); } // Get binary directory if (GetModuleFileNameA(NULL, path, MAX_PATH) != 0) { PathRemoveFileSpecA(path); PathAppendA(path, "user\\"); list.push_back(path); } // Get working directory if (GetCurrentDirectoryA(MAX_PATH, path) != 0) { PathAppendA(path, "user\\"); list.push_back(path); } #else #ifdef __HAIKU__ list.push_back("/boot/apps/OpenXcom/"); #endif char const *home = getHome(); char path[MAXPATHLEN]; // Get user folders if (char const *const xdg_data_home = getenv("XDG_DATA_HOME")) { snprintf(path, MAXPATHLEN, "%s/openxcom/", xdg_data_home); } else { #ifdef __APPLE__ snprintf(path, MAXPATHLEN, "%s/Library/Application Support/OpenXcom/", home); #else snprintf(path, MAXPATHLEN, "%s/.local/share/openxcom/", home); #endif } list.push_back(path); // Get old-style folder snprintf(path, MAXPATHLEN, "%s/.openxcom/", home); list.push_back(path); // Get working directory list.push_back("./user/"); #endif return list; }
static std::string getLinuxFolderDefault(const char* envName, const char* defaultRelativePath) { std::string res; const char* tempRes = getenv(envName); if (tempRes) { throwOnRelative(envName, tempRes); res = tempRes; return res; } res = getHome() + "/" + defaultRelativePath; return res; }
void solvedMap_c::save(void) { std::ofstream out((getHome()+"solved.txt").c_str()); // save the users first, don't save the default user for (size_t i = 1; i <users.size(); i++) out << "U " << users[i].getUserString() << std::endl; for (std::set<std::string>::iterator i = map.begin(); i != map.end(); i++) out << *i << std::endl; }
VCard::AddressLabel QtVCardAddressLabelField::getAddressLabel() const { VCard::AddressLabel addressLabel; addressLabel.isPreferred = getPreferred(); addressLabel.isHome = getHome(); addressLabel.isWork = getWork(); addressLabel.deliveryType = domesticRadioButton->isChecked() ? VCard::DomesticDelivery : (internationalRadioButton->isChecked() ? VCard::InternationalDelivery : VCard::None); addressLabel.isPostal = getTagComboBox()->isTagSet("postal"); addressLabel.isParcel = getTagComboBox()->isTagSet("parcel"); std::string lines = Q2PSTRING(addressLabelPlainTextEdit->toPlainText()); boost::split(addressLabel.lines, lines, boost::is_any_of("\n")); return addressLabel; }
VCard::Address QtVCardAddressField::getAddress() const { VCard::Address address; address.isPreferred = getPreferred(); address.isHome = getHome(); address.isWork = getWork(); address.deliveryType = domesticRadioButton->isChecked() ? VCard::DomesticDelivery : (internationalRadioButton->isChecked() ? VCard::InternationalDelivery : VCard::None); address.isPostal = getTagComboBox()->isTagSet("postal"); address.isParcel = getTagComboBox()->isTagSet("parcel"); address.street = Q2PSTRING(streetLineEdit->text()); address.poBox = Q2PSTRING(poboxLineEdit->text()); address.addressExtension = Q2PSTRING(addressextLineEdit->text()); address.locality = Q2PSTRING(cityLineEdit->text()); address.postalCode = Q2PSTRING(pocodeLineEdit->text()); address.region = Q2PSTRING(regionLineEdit->text()); address.country = Q2PSTRING(countryLineEdit->text()); return address; }
static void PlatformFoldersFillData(std::map<std::string, std::string>& folders) { folders["XDG_DOCUMENTS_DIR"] = "$HOME/Documents"; folders["XDG_DESKTOP_DIR"] = "$HOME/Desktop"; folders["XDG_DOWNLOAD_DIR"] = "$HOME/Downloads"; folders["XDG_MUSIC_DIR"] = "$HOME/Music"; folders["XDG_PICTURES_DIR"] = "$HOME/Pictures"; folders["XDG_PUBLICSHARE_DIR"] = "$HOME/Public"; folders["XDG_TEMPLATES_DIR"] = "$HOME/.Templates"; folders["XDG_VIDEOS_DIR"] = "$HOME/Videos"; PlatformFoldersAddFromFile( getConfigHome()+"/user-dirs.dirs", folders); for (std::map<std::string, std::string>::iterator itr = folders.begin() ; itr != folders.end() ; itr ++ ) { std::string& value = itr->second; if (value.compare(0, 5, "$HOME") == 0) { value = getHome() + value.substr(5, std::string::npos); } } }
// Load filename from ~/.lolut/name // Returns 0 if fails, 1 else int loadName(char *name, int size) { int nb; FILE *file; char filename[PATH_MAX]; unsigned int lg; // Get file name if (!getHome(filename)) return 0; strcat(filename, "/.lolut/name"); // Open file file = fopen(filename, "r"); if (file == NULL) return 0; // Read name fread((char *)&lg, sizeof(lg), 1, file); fread(name, lg, 1, file); name[lg] = '\0'; fclose(file); return 1; }
// Save filename into ~/.lolut/name // Ignore all errors void saveName(char *name) { FILE *file; char filename[PATH_MAX]; int ok; unsigned int lg; // Get directory name if (!getHome(filename)) return; strcat(filename, "/.lolut"); // Create directory ok = mkdir(filename, 0777); if (ok != 0) { if (errno != 17) { printf("Can not create directory %s (errno %i)!\n", filename, errno); return; } } // Open file strcat(filename, "/name"); file = fopen(filename, "w"); if (file == NULL) { printf("Can not create (or open) file %s!\n", filename); return; } // Write name lg = strlen(name); fwrite((char *)&lg, sizeof(unsigned int), 1, file); fwrite(name, lg, 1, file); fclose(file); }
/** * Builds a list of predefined paths for the Data folder * according to the running system. * @return List of data paths. */ std::vector<std::string> findDataFolders() { std::vector<std::string> list; #ifdef _WIN32 char path[MAX_PATH]; // Get Documents folder if (SUCCEEDED(SHGetFolderPathA(NULL, CSIDL_PERSONAL, NULL, SHGFP_TYPE_CURRENT, path))) { PathAppendA(path, "OpenXcom\\data\\"); list.push_back(path); } // Get binary directory if (GetModuleFileNameA(NULL, path, MAX_PATH) != 0) { PathRemoveFileSpecA(path); PathAppendA(path, "data\\"); list.push_back(path); } // Get working directory if (GetCurrentDirectoryA(MAX_PATH, path) != 0) { PathAppendA(path, "data\\"); list.push_back(path); } #else #ifdef __HAIKU__ list.push_back("/boot/apps/OpenXcom/data/"); #endif char const *home = getHome(); char path[MAXPATHLEN]; // Get user-specific data folders if (char const *const xdg_data_home = getenv("XDG_DATA_HOME")) { snprintf(path, MAXPATHLEN, "%s/openxcom/data/", xdg_data_home); } else { #ifdef __APPLE__ snprintf(path, MAXPATHLEN, "%s/Library/Application Support/OpenXcom/data/", home); #else snprintf(path, MAXPATHLEN, "%s/.local/share/openxcom/data/", home); #endif } list.push_back(path); // Get global data folders if (char *xdg_data_dirs = getenv("XDG_DATA_DIRS")) { char *dir = strtok(xdg_data_dirs, ":"); while (dir != 0) { snprintf(path, MAXPATHLEN, "%s/openxcom/data/", dir); list.push_back(path); dir = strtok(0, ":"); } } else { #ifdef __APPLE__ snprintf(path, MAXPATHLEN, "%s/Users/Shared/OpenXcom/data/", home); list.push_back(path); #else list.push_back("/usr/local/share/openxcom/data/"); list.push_back("/usr/share/openxcom/data/"); #endif } // Get working directory list.push_back("./data/"); #endif return list; }
/** * Builds a list of predefined paths for the Data folder * according to the running system. * @return List of data paths. */ std::vector<std::string> findDataFolders() { std::vector<std::string> list; #ifdef __MORPHOS__ list.push_back("PROGDIR:"); return list; #endif #ifdef _WIN32 char path[MAX_PATH]; // Get Documents folder if (SUCCEEDED(SHGetFolderPathA(NULL, CSIDL_PERSONAL, NULL, SHGFP_TYPE_CURRENT, path))) { PathAppendA(path, "OpenXcom\\"); list.push_back(path); } // Get binary directory if (GetModuleFileNameA(NULL, path, MAX_PATH) != 0) { PathRemoveFileSpecA(path); list.push_back(path); } // Get working directory if (GetCurrentDirectoryA(MAX_PATH, path) != 0) { list.push_back(path); } #else char const *home = getHome(); #ifdef __HAIKU__ char data_path[B_PATH_NAME_LENGTH]; find_directory(B_SYSTEM_SETTINGS_DIRECTORY, 0, true, data_path, sizeof(data_path)-strlen("/OpenXcom/")); strcat(data_path,"/OpenXcom/"); list.push_back(data_path); #endif char path[MAXPATHLEN]; // Get user-specific data folders if (char const *const xdg_data_home = getenv("XDG_DATA_HOME")) { snprintf(path, MAXPATHLEN, "%s/openxcom/", xdg_data_home); } else { #ifdef __APPLE__ snprintf(path, MAXPATHLEN, "%s/Library/Application Support/OpenXcom/", home); #else snprintf(path, MAXPATHLEN, "%s/.local/share/openxcom/", home); #endif } list.push_back(path); // Get global data folders if (char *xdg_data_dirs = getenv("XDG_DATA_DIRS")) { char *dir = strtok(xdg_data_dirs, ":"); while (dir != 0) { snprintf(path, MAXPATHLEN, "%s/openxcom/", dir); list.push_back(path); dir = strtok(0, ":"); } } #ifdef __APPLE__ list.push_back("/Users/Shared/OpenXcom/"); #else list.push_back("/usr/local/share/openxcom/"); #ifndef __FreeBSD__ list.push_back("/usr/share/openxcom/"); #endif #ifdef DATADIR snprintf(path, MAXPATHLEN, "%s/", DATADIR); list.push_back(path); #endif #endif // Get working directory list.push_back("./"); #endif return list; }
extern bool File_FindInPath (char * out, int outSz, const char * path, const char * basename) { char name [FILENAME_MAX] ; int len ; assert (path != NULL) ; assert (basename != NULL) ; assert (out != NULL) ; /* regular path */ if (access (basename, F_OK) == 0) { sprintf (out, "%.*s", outSz-1, basename) ; return true ; } else /* relative to home directory */ if (strncmp (basename, "~/", 2) == 0 && getHome () != NULL) { sprintf (name, "%s%s", getHome (), basename+1) ; if (access (name, F_OK) == 0) { sprintf (out, "%.*s", outSz-1, name) ; return true ; } else { return false ; } } else /* forbid relative to PATH just like shell */ /* NB: absolute non-existent files also drop here */ if (strchr (basename, '/') != NULL) { return false ; } else { while (*path != EOS) { len = strcspn (path, ":") ; if (strncmp (path, "~/", 2) == 0) { sprintf (name, "%s%.*s/%s", getHome (), len-1, path+1, basename) ; } else { sprintf (name, "%.*s/%s", len, path, basename) ; } if (access (name, F_OK) == 0) { sprintf (out, "%.*s", outSz-1, name) ; return true ; } path += len ; while (*path == ':') path++ ; } return false ; } }
int readconfig(struct passwd *pwd, pam_handle_t * pamh, const char *user, char *path, char *targetpath, char *encfs_options, char *fuse_options) { FILE *conffile; char line[BUFSIZE]; char username[USERNAME_MAX]; int parsed; const char *tmp; // Return 1 = error, 2 = silent error (ie already mounted) if ((conffile = fopen(CONFIGFILE, "r")) == NULL) { _pam_log(LOG_ERR, "Failed to open conffile %s", CONFIGFILE); return 0; } while (fgets(line, BUFSIZE, conffile) != NULL) { if (line[0] == '#') continue; parsed = sscanf(line, "%s%s%s%s%s", username, path, targetpath, encfs_options, fuse_options); if (parsed == -1) continue; if (strcmp("drop_permissions", username) == 0) { drop_permissions = 1; continue; } if (strcmp("encfs_default", username) == 0) { if (parsed == 2 && !strcmp("-",path) == 0) strcpy(default_encfs_options, path); continue; } if (strcmp("fuse_default", username) == 0) { if (parsed == 2 && !strcmp("-",path) == 0) strcpy(default_fuse_options, path); continue; } if (parsed == 5) { // Parsing user: if (strcmp("-", encfs_options) == 0) strcpy(encfs_options, ""); if (strcmp("-", fuse_options) == 0) strcpy(fuse_options, ""); searchAndReplace(default_encfs_options); searchAndReplace(encfs_options); // Check if this is the right user / default user. if ((strcmp("-",username) != 0) && (strcmp(user,username) != 0) && (strcmp("*",username) !=0)) continue; if (strcmp("-",username) == 0) { strcat(path, "/"); strcat(path, user); // Todo check if dir exists and give better error msg. } // If username is '*', paths are relative to $HOME if (strcmp("*", username) == 0 && strcmp("-", targetpath) != 0) { if ((tmp = getHome(pwd, pamh))) { char home[PATH_MAX]; strcpy(home, tmp); strcat(home, "/"); strcat(home, path); strcpy(path, home); strcpy(home, tmp); strcat(home, "/"); strcat(home, targetpath); strcpy(targetpath, home); } } if (strcmp("-", targetpath) == 0) { // We do not have targetpath, construct one. strcpy(targetpath, ""); if ((tmp = getHome(pwd, pamh))) { strcpy(targetpath, tmp); } } // Done, check targetpath and return. if (!targetpath || *targetpath == '\0') { _pam_log(LOG_ERR, "Can't get to HOME dir for user %s", user); fclose(conffile); return 0; } // Check if path exists, if we're "-" then we dont care, if not we give error. if (is_dir(path)) { // We may fail to stat this directory (EPERM) if it's mounted because of fuse's funky permission system. if (!is_dir(targetpath)) { if (checkmnt(targetpath)) { // Doublecheck if we're mounted, for some reason we can't stat the dir even when root if it's mounted. // we are mounted, but we return 1 anyway so we can store targetpath fclose(conffile); return 1; } _pam_log(LOG_ERR, "TargetPath for %s does not exist (%s)", user, targetpath); fclose(conffile); return 0; } fclose(conffile); return 1; } // Path does not exist, if we're a specified user give error, if not keep looking. if ((strcmp("-", username) != 0) && (strcmp("*", username) != 0)) { _pam_log(LOG_ERR, "Path for %s does not exist (%s)", user, path); fclose(conffile); return 0; } continue; } continue; } fclose(conffile); return 0; }