// ======================================================= void Initialize() { char szTemp[2048]; // open log files as root if (g_dwDebugLevel) { g_fDebug = openFileDescriptorSecure(PARTIMAGED_LOG, "a", O_WRONLY | O_CREAT | O_NOFOLLOW | O_TRUNC, S_IRUSR | S_IWUSR); if (!g_fDebug) { fprintf(stderr, i18n("Impossible to open logfile %s: %s\n"), PARTIMAGED_LOG, strerror(errno)); fprintf(stderr, i18n("Fix this and retry.\n")); } } else g_fDebug = NULL; if (!g_fDebug) { g_fDebug = fopen("/dev/null", "w"); if (!g_fDebug) exit(1); } g_fLocalDebug = fopen("/dev/null", "w"); if (!g_fLocalDebug) g_fDebug = stderr; // find PARTIMAGED_USER euid and register it to be used later. g_privs = new CPrivs(PARTIMAGED_USER); if (!g_privs) { fprintf(stderr, i18n("impossible to find user \"%s\"\n"),PARTIMAGED_USER); fprintf(stderr, i18n("add it and retry\n")); } if (!g_privs->AsSwitched()) showDebug(4, i18n("Warning: we couldn't changed euid because we weren't " "launched as root\nexpect some access denied or troubles like this.\n")); // add usefull informations into logfile showDebug(1, "partimaged %s(%s)\n", PACKAGE_VERSION, Revision); showDebug(1,"-----------------------------------------\n"); formatCompilOptions(szTemp, sizeof(szTemp)); showDebug(1, "%s\n\n", szTemp); showDebug(1,"-----------------------------------------\n"); // we only exit here because we must write informations in logfile to help // debugging if (!g_privs) exit(0); }
// ======================================================= int CImageDisk::createSpaceFile() // [Main-Thread] { char cBuffer[1024]; //int nSpaceFd; FILE *fStream; DWORD dwFileSize; int nRes; WORD i; showDebug(1, "CREATE SPACE FILE [%s]\n", m_szSpaceFilename); // write random numbers for (i=0; i < sizeof(cBuffer); i++) cBuffer[i] = (i ^ 94) % 256; // open file descriptor ICI fStream = openFileDescriptorSecure(m_szSpaceFilename, "a", O_WRONLY | O_CREAT | O_NOFOLLOW | O_TRUNC, S_IREAD | S_IWRITE); if (!fStream) return -1; dwFileSize = 0; while (dwFileSize < SPACEFILE_SIZE) { //nRes = ::write(nSpaceFd, cBuffer, sizeof(cBuffer)); nRes = fwrite(cBuffer, sizeof(cBuffer), 1, fStream); if (nRes != 1) { fclose(fStream); destroySpaceFile(); return -1; } dwFileSize += sizeof(cBuffer); } nRes = fclose(fStream); if (nRes == -1) return -1; return 0; // success }