DWORD WriteMessagesToFile(HANDLE File,HACCOUNT Which) { DWORD WrittenBytes,Stat; HYAMNMAIL ActualMail=(HYAMNMAIL)Which->Mails; struct CMimeItem *items; while(ActualMail != NULL) { if (Stat=WriteStringToFile(File,ActualMail->ID)) return Stat; if (!WriteFile(File,(char *)&ActualMail->MailData->Size,sizeof(ActualMail->MailData->Size),&WrittenBytes,NULL) || !WriteFile(File,(char *)&ActualMail->Flags,sizeof(ActualMail->Flags),&WrittenBytes,NULL) || !WriteFile(File,(char *)&ActualMail->Number,sizeof(ActualMail->Number),&WrittenBytes,NULL)) return EACC_SYSTEM; if ((NULL != Which->Plugin->MailFcn) && (NULL != Which->Plugin->MailFcn->WriteMailOptsFcnPtr)) Which->Plugin->MailFcn->WriteMailOptsFcnPtr(File,ActualMail); //write plugin mail options to file for (items=ActualMail->MailData->TranslatedHeader;items != NULL;items=items->Next) { if (Stat=WriteStringToFile(File,items->name)) return Stat; if (Stat=WriteStringToFile(File,items->value)) return Stat; } if (Stat=WriteStringToFile(File,"")) return Stat; ActualMail=ActualMail->Next; } if (Stat=WriteStringToFile(File,"")) return Stat; return 0; }
bool UnshareUserNamespace() { // The uid and gid need to be retrieved before the unshare; see // below. uid_t uid = getuid(); gid_t gid = getgid(); char buf[80]; size_t len; if (syscall(__NR_unshare, CLONE_NEWUSER) != 0) { return false; } // As mentioned in the header, this function sets up uid/gid // mappings that preserve the process's previous ids. Mapping the // uid/gid to something is necessary in order to nest user // namespaces (not used yet, but we'll need this in the future for // pid namespace support), and leaving the ids unchanged is the // least confusing option. // // In recent kernels (3.19, 3.18.2, 3.17.8), for security reasons, // establishing gid mappings will fail unless the process first // revokes its ability to call setgroups() by using a /proc node // added in the same set of patches. // // Note that /proc/self points to the thread group leader, not the // current thread. However, CLONE_NEWUSER can be unshared only in a // single-threaded process, so those are equivalent if we reach this // point. len = size_t(SprintfLiteral(buf, "%u %u 1\n", uid, uid)); MOZ_ASSERT(len < sizeof(buf)); if (!WriteStringToFile("/proc/self/uid_map", buf, len)) { MOZ_CRASH("Failed to write /proc/self/uid_map"); } Unused << WriteStringToFile("/proc/self/setgroups", "deny", 4); len = size_t(SprintfLiteral(buf, "%u %u 1\n", gid, gid)); MOZ_ASSERT(len < sizeof(buf)); if (!WriteStringToFile("/proc/self/gid_map", buf, len)) { MOZ_CRASH("Failed to write /proc/self/gid_map"); } return true; }
void _LogXMLStringsToFiles(const CStdString& sExpectedXML, const CStdString& sDiscoveredXML, const TCHAR* const lpszFunction) { CStdString sFunction(lpszFunction); int n = sFunction.ReverseFind(_T(':')); if( 0 < n) sFunction.Delete(0, n+1); CStdString lpszRoot = TEST_PATH_MAKE_ABSOLUTE(_T("projects\\Protect\\src\\ApiWordDOMStrategiesTests\\docs\\TestWordDOMStrategies\\")); CStdString sExpectedFile(lpszRoot); CStdString sDiscoveredFile(lpszRoot); sExpectedFile += sFunction + _T("ExpectedXML.txt"); sDiscoveredFile += sFunction + _T("DiscoveredXML.txt"); MakeSureDirectoryPathExists(CT2A(sExpectedFile.c_str())); MakeSureDirectoryPathExists(CT2A(sDiscoveredFile.c_str())); WriteStringToFile(sExpectedFile, sExpectedXML); WriteStringToFile(sDiscoveredFile, sDiscoveredXML); }
static jint com_android_internal_os_Zygote_nativeForkSystemServer( JNIEnv* env, jclass, uid_t uid, gid_t gid, jintArray gids, jint runtime_flags, jobjectArray rlimits, jlong permitted_capabilities, jlong effective_capabilities) { pid_t pid = ForkCommon(env, true, /* managed_fds_to_close= */ nullptr, /* managed_fds_to_ignore= */ nullptr); if (pid == 0) { SpecializeCommon(env, uid, gid, gids, runtime_flags, rlimits, permitted_capabilities, effective_capabilities, MOUNT_EXTERNAL_DEFAULT, nullptr, nullptr, true, false, nullptr, nullptr); } else if (pid > 0) { // The zygote process checks whether the child process has died or not. ALOGI("System server process %d has been created", pid); gSystemServerPid = pid; // There is a slight window that the system server process has crashed // but it went unnoticed because we haven't published its pid yet. So // we recheck here just to make sure that all is well. int status; if (waitpid(pid, &status, WNOHANG) == pid) { ALOGE("System server process %d has died. Restarting Zygote!", pid); RuntimeAbort(env, __LINE__, "System server process has died. Restarting Zygote!"); } bool low_ram_device = GetBoolProperty("ro.config.low_ram", false); bool per_app_memcg = GetBoolProperty("ro.config.per_app_memcg", low_ram_device); if (per_app_memcg) { // Assign system_server to the correct memory cgroup. // Not all devices mount /dev/memcg so check for the file first // to avoid unnecessarily printing errors and denials in the logs. if (!access("/dev/memcg/system/tasks", F_OK) && !WriteStringToFile(StringPrintf("%d", pid), "/dev/memcg/system/tasks")) { ALOGE("couldn't write %d to /dev/memcg/system/tasks", pid); } } } return pid; }
static INT_PTR PerformAccountWriting(HYAMNPROTOPLUGIN Plugin,HANDLE File) { DWORD WrittenBytes,Stat; HACCOUNT ActualAccount; DWORD Ver=YAMN_ACCOUNTFILEVERSION; BOOL Writed=FALSE; DWORD ReturnValue=0,EnterCode; #ifdef DEBUG_SYNCHRO DebugLog(SynchroFile,"WriteAccountsToFile:AccountBrowserSO-read wait\n"); #endif SWMRGWaitToRead(Plugin->AccountBrowserSO,INFINITE); #ifdef DEBUG_SYNCHRO DebugLog(SynchroFile,"WriteAccountsToFile:AccountBrowserSO-read enter\n"); #endif try { for (ActualAccount=Plugin->FirstAccount;ActualAccount != NULL;ActualAccount=ActualAccount->Next) { #ifdef DEBUG_SYNCHRO DebugLog(SynchroFile,"WriteAccountsToFile:ActualAccountSO-read wait\n"); #endif EnterCode=WaitToReadFcn(ActualAccount->AccountAccessSO); if (EnterCode==WAIT_FINISH) //account is about to delete { #ifdef DEBUG_SYNCHRO DebugLog(SynchroFile,"WriteAccountsToFile:ActualAccountSO-read wait failed\n"); #endif ActualAccount=ActualAccount->Next; continue; } if (EnterCode==WAIT_FAILED) //account is deleted break; #ifdef DEBUG_SYNCHRO DebugLog(SynchroFile,"WriteAccountsToFile:ActualAccountSO-read enter\n"); #endif if ((ActualAccount->Name==NULL) || (*ActualAccount->Name==(TCHAR)0)) { #ifdef DEBUG_SYNCHRO DebugLog(SynchroFile,"WriteAccountsToFile:ActualAccountSO-read done\n"); #endif ReadDoneFcn(ActualAccount->AccountAccessSO); continue; } if (!Writed && !WriteFile(File,&Ver,sizeof(Ver),&WrittenBytes,NULL)) throw (DWORD)EACC_SYSTEM; Writed=TRUE; if (Stat=WriteStringToFile(File,ActualAccount->Name)) throw (DWORD)Stat; if (Stat=WriteStringToFile(File,ActualAccount->Server->Name)) throw (DWORD)Stat; if (!WriteFile(File,(char *)&ActualAccount->Server->Port,2,&WrittenBytes,NULL)) throw (DWORD)EACC_SYSTEM; if ((Stat=WriteStringToFile(File,ActualAccount->Server->Login))) throw (DWORD)Stat; CodeDecodeString(ActualAccount->Server->Passwd,TRUE); if (Stat=WriteStringToFile(File,ActualAccount->Server->Passwd)) { CodeDecodeString(ActualAccount->Server->Passwd,FALSE); throw (DWORD)Stat; } CodeDecodeString(ActualAccount->Server->Passwd,FALSE); if ((!WriteFile(File,(char *)&ActualAccount->Flags,sizeof(DWORD),&WrittenBytes,NULL) || (!WriteFile(File,(char *)&ActualAccount->StatusFlags,sizeof(DWORD),&WrittenBytes,NULL)) || (!WriteFile(File,(char *)&ActualAccount->PluginFlags,sizeof(DWORD),&WrittenBytes,NULL)))) throw (DWORD)EACC_SYSTEM; if (!WriteFile(File,(char *)&ActualAccount->Interval,sizeof(WORD),&WrittenBytes,NULL)) throw (DWORD)EACC_SYSTEM; if ((!WriteFile(File,(char *)&ActualAccount->NewMailN.Flags,sizeof(DWORD),&WrittenBytes,NULL)) || (!WriteFile(File,(char *)&ActualAccount->NewMailN.PopupB,sizeof(COLORREF),&WrittenBytes,NULL)) || (!WriteFile(File,(char *)&ActualAccount->NewMailN.PopupT,sizeof(COLORREF),&WrittenBytes,NULL)) || (!WriteFile(File,(char *)&ActualAccount->NewMailN.PopupTime,sizeof(DWORD),&WrittenBytes,NULL))) throw (DWORD)EACC_SYSTEM; if ((Stat=WriteStringToFileW(File,ActualAccount->NewMailN.App)) || (Stat=WriteStringToFileW(File,ActualAccount->NewMailN.AppParam))) throw (DWORD)Stat; if ((!WriteFile(File,(char *)&ActualAccount->NoNewMailN.Flags,sizeof(DWORD),&WrittenBytes,NULL)) || (!WriteFile(File,(char *)&ActualAccount->NoNewMailN.PopupB,sizeof(COLORREF),&WrittenBytes,NULL)) || (!WriteFile(File,(char *)&ActualAccount->NoNewMailN.PopupT,sizeof(COLORREF),&WrittenBytes,NULL)) || (!WriteFile(File,(char *)&ActualAccount->NoNewMailN.PopupTime,sizeof(DWORD),&WrittenBytes,NULL))) throw (DWORD)EACC_SYSTEM; if ((Stat=WriteStringToFileW(File,ActualAccount->NoNewMailN.App)) || (Stat=WriteStringToFileW(File,ActualAccount->NoNewMailN.AppParam))) throw (DWORD)Stat; if ((!WriteFile(File,(char *)&ActualAccount->BadConnectN.Flags,sizeof(DWORD),&WrittenBytes,NULL)) || (!WriteFile(File,(char *)&ActualAccount->BadConnectN.PopupB,sizeof(COLORREF),&WrittenBytes,NULL)) || (!WriteFile(File,(char *)&ActualAccount->BadConnectN.PopupT,sizeof(COLORREF),&WrittenBytes,NULL)) || (!WriteFile(File,(char *)&ActualAccount->BadConnectN.PopupTime,sizeof(DWORD),&WrittenBytes,NULL))) throw (DWORD)EACC_SYSTEM; if ((Stat=WriteStringToFileW(File,ActualAccount->BadConnectN.App)) || (Stat=WriteStringToFileW(File,ActualAccount->BadConnectN.AppParam))) throw (DWORD)Stat; //Let plugin write its own values into file if (ActualAccount->Plugin->Fcn != NULL && ActualAccount->Plugin->Fcn->WritePluginOptsFcnPtr != NULL) if (Stat=ActualAccount->Plugin->Fcn->WritePluginOptsFcnPtr(File,ActualAccount)) throw (DWORD)Stat; #ifdef DEBUG_SYNCHRO DebugLog(SynchroFile,"WriteAccountsToFile:ActualAccountMsgsSO-read wait\n"); #endif WaitToReadFcn(ActualAccount->MessagesAccessSO); #ifdef DEBUG_SYNCHRO DebugLog(SynchroFile,"WriteAccountsToFile:ActualAccountMsgsSO-read enter\n"); #endif if (Stat=WriteMessagesToFile(File,ActualAccount)) { #ifdef DEBUG_SYNCHRO DebugLog(SynchroFile,"WriteAccountsToFile:ActualAccountMsgsSO-read done\n"); #endif ReadDoneFcn(ActualAccount->MessagesAccessSO); throw (DWORD)Stat; } #ifdef DEBUG_SYNCHRO DebugLog(SynchroFile,"WriteAccountsToFile:ActualAccountMsgsSO-read done\n"); #endif ReadDoneFcn(ActualAccount->MessagesAccessSO); if ((!WriteFile(File,(char *)&ActualAccount->LastChecked,sizeof(SYSTEMTIME),&WrittenBytes,NULL)) || (!WriteFile(File,(char *)&ActualAccount->LastSChecked,sizeof(SYSTEMTIME),&WrittenBytes,NULL)) || (!WriteFile(File,(char *)&ActualAccount->LastSynchronised,sizeof(SYSTEMTIME),&WrittenBytes,NULL)) || (!WriteFile(File,(char *)&ActualAccount->LastMail,sizeof(SYSTEMTIME),&WrittenBytes,NULL))) throw (DWORD)Stat; #ifdef DEBUG_SYNCHRO DebugLog(SynchroFile,"WriteAccountsToFile:ActualAccountSO-read done\n"); #endif ReadDoneFcn(ActualAccount->AccountAccessSO); } } catch(DWORD ErrorCode) { #ifdef DEBUG_SYNCHRO DebugLog(SynchroFile,"WriteAccountsToFile:ActualAccountSO-read done\n"); #endif ReadDoneFcn(ActualAccount->AccountAccessSO); ReturnValue=ErrorCode; } #ifdef DEBUG_SYNCHRO DebugLog(SynchroFile,"WriteAccountsToFile:AccountBrowserSO-read done\n"); #endif SWMRGDoneReading(Plugin->AccountBrowserSO); CloseHandle(File); return 0; }