Пример #1
0
        public static void SMain()
        {
#if !DEBUG
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
#endif
            FoxEventLog.RegisterEventLog();

            if (UsePipeAction == false && UseScreenAction == false && UseDNSAutoConfig == false && UseLoginRecovery == false) //Pipe Actions can also be run in user-space ...
            {
                if (IsSystemUser() != true)
                {
#if !DEBUG || DEBUGSERVICE
                    service.Stop();
#endif
                    return;
                }
            }

            if (LoadDLL() == false)
            {
#if !DEBUG || DEBUGSERVICE
                service.Stop();
#endif
                return;
            }

#if !DEBUG
            if (TestIntegrity(null) == false)
            {
                FoxEventLog.WriteEventLog("Integrity check failed!", EventLogEntryType.Error);
                service.Stop();
                return;
            }
#endif
            if (UseDNSAutoConfig == true)
            {
                try
                {
                    List <List <string> > Query = CPP.DNSQueryTXT("sdc-contract.my-vulpes-config.lu");

                    if (Query == null)
                    {
                        return;
                    }

                    string ContractID       = null;
                    string ContractPassword = null;
                    string UseOnPrem        = null;
                    string OnPremURL        = null;

                    foreach (List <string> Q in Query)
                    {
                        if (Q == null)
                        {
                            continue;
                        }

                        foreach (string QR in Q)
                        {
                            if (string.IsNullOrWhiteSpace(QR) == true)
                            {
                                continue;
                            }
                            if (QR.ToLower().StartsWith("contractid=") == true)
                            {
                                ContractID = QR.Substring(11).Trim();
                            }
                            if (QR.ToLower().StartsWith("contractpassword="******"useonprem=") == true)
                            {
                                UseOnPrem = QR.Substring(10).Trim();
                            }
                            if (QR.ToLower().StartsWith("onpremurl=") == true)
                            {
                                OnPremURL = QR.Substring(10).Trim();
                            }
                        }
                    }

                    using (RegistryKey k = Registry.LocalMachine.CreateSubKey("SOFTWARE\\Fox\\SDC"))
                    {
                        if (string.IsNullOrWhiteSpace(ContractID) == false && string.IsNullOrWhiteSpace(ContractPassword) == false)
                        {
                            k.SetValue("ContractID", ContractID, RegistryValueKind.String);
                            k.SetValue("ContractPassword", ContractPassword, RegistryValueKind.String);
                        }

                        int UseOnPremInt;
                        if (int.TryParse(UseOnPrem, out UseOnPremInt) == true)
                        {
                            if (UseOnPremInt == 1 && string.IsNullOrWhiteSpace(OnPremURL) == false)
                            {
                                k.SetValue("UseOnPremServer", 1, RegistryValueKind.DWord);
                                k.SetValue("Server", OnPremURL, RegistryValueKind.String);
                            }
                            else
                            {
                                k.SetValue("UseOnPremServer", 0, RegistryValueKind.DWord);
                            }
                        }
                        else
                        {
                            k.SetValue("UseOnPremServer", 0, RegistryValueKind.DWord);
                        }
                    }
                }
                catch (Exception ee)
                {
                    Debug.WriteLine(ee.ToString());
                }
                return;
            }

            if (UseLoginRecovery == true)
            {
                if (SystemInfos.CollectSystemInfo() != 0)
                {
                    return;
                }

#if !DEBUG
                if (SystemInfos.SysInfo.RunningInWindowsPE == false || SystemInfos.SysInfo.RunningInWindowsPE == null)
                {
                    return;
                }
#endif

                RecoveryLogon reclogon = new RecoveryLogon();
                reclogon.UCID             = SystemInfos.SysInfo.UCID;
                reclogon.ContractID       = SystemInfos.ContractID;
                reclogon.ContractPassword = SystemInfos.ContractPassword;

                string Check = SystemInfos.SysInfo.CPUName.Trim();
                Check += SystemInfos.SysInfo.ComputerModel == "" ? "N/A" : SystemInfos.SysInfo.ComputerModel.Trim();
                Check += SystemInfos.SysInfo.BIOS == "" ? "N/A" : SystemInfos.SysInfo.BIOS.Trim();

                reclogon.MoreMachineHash = MD5Utilities.CalcMD5(Check);
                Network net = Utilities.NoConnectNetwork();

                RecoveryData rd = net.GetRecoveryLogon(reclogon);
                if (rd == null)
                {
                    return;
                }
                if (rd.Worked == false)
                {
                    return;
                }

                string Registry = "Windows Registry Editor Version 5.00\r\n\r\n[HKEY_LOCAL_MACHINE\\SOFTWARE\\Fox\\SDC]\r\n\"ID\"=\"" + rd.MachineID + "\"\r\n\"PassID\"=\"" + rd.MachinePassword + "\"";
                try
                {
                    File.WriteAllText(Environment.ExpandEnvironmentVariables("%SYSTEMROOT%\\Fox SDC MachinePW.reg"), Registry, Encoding.Unicode);
                }
                catch
                {
                }
                return;
            }

            if (UsePipeAction == false && UseScreenAction == false)
            {
                using (RegistryKey installer = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\" + VulpesBranding.MSIGUID, false))
                {
                    if (installer == null)
                    {
                        FoxEventLog.WriteEventLog("Missing installer key in HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\" + VulpesBranding.MSIGUID + ". This can lead to erratic behavoir of the program!", EventLogEntryType.Warning);
                    }
                }

                if (CPP.SetToken() == false)
                {
                    FoxEventLog.WriteEventLog("Cannot setup token - 0x" + Marshal.GetLastWin32Error().ToString("X") + " - " + new Win32Exception(Marshal.GetLastWin32Error()).Message, System.Diagnostics.EventLogEntryType.Error);
                    return;
                }
            }

            if (UsePipeAction == true)
            {
                try
                {
                    Process2ProcessCommClient.RunPipeClient();
                }
                catch (Exception ee)
                {
                    FoxEventLog.WriteEventLog("Pipe SEH " + ee.ToString(), System.Diagnostics.EventLogEntryType.Error);
                }
                return;
            }

            if (UseScreenAction == true)
            {
                try
                {
                    if (SystemInfos.CollectSystemInfo() != 0)
                    {
                        return;
                    }
                    MainScreenSystemClient.RunPipeClient();
                }
                catch (Exception ee)
                {
                    FoxEventLog.WriteEventLog("Screen Pipe SEH " + ee.ToString(), System.Diagnostics.EventLogEntryType.Error);
                }
                return;
            }

            if (SystemInfos.CollectSystemInfo() != 0)
            {
#if !DEBUG || DEBUGSERVICE
                service.Stop();
#endif
                return;
            }

            RegistryData.InstallPath = AppPath;

            if (ApplicationCertificate.LoadCertificate() == false)
            {
                FoxEventLog.WriteEventLog("Cannot load certificate", System.Diagnostics.EventLogEntryType.Error);
#if !DEBUG || DEBUGSERVICE
                service.Stop();
#endif
                return;
            }

            if (FilesystemData.LoadCertificates() == false)
            {
#if !DEBUG || DEBUGSERVICE
                service.Stop();
#endif
                return;
            }
            if (FilesystemData.LoadPolicies() == false)
            {
#if !DEBUG || DEBUGSERVICE
                service.Stop();
#endif
                return;
            }
            FilesystemData.LoadLocalPackageData();
            FilesystemData.LoadLocalPackages();
            FilesystemData.LoadUserPackageData();
            FilesystemData.LoadEventLogList();

            SyncPolicy.ApplyPolicy(SyncPolicy.ApplyPolicyFunction.ApplySystem);

            PipeCommunicationSRV.StartPipeSrv();

            try
            {
                string p = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
                if (p.EndsWith("\\") == false)
                {
                    p += "\\";
                }

                using (RegistryKey reg = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true))
                {
                    reg.SetValue("FoxSDCAgent", p + "FoxSDC_Agent_UI.exe", RegistryValueKind.String);
                    reg.SetValue("FoxSDCAgentApply", p + "FoxSDC_ApplyUserSettings.exe", RegistryValueKind.String);
                    reg.Close();
                }
            }
            catch
            {
            }

            try
            {
                using (RegistryKey reg = Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System", true))
                {
                    object o      = reg.GetValue("SoftwareSASGeneration", null);
                    int    rvalue = 0;
                    if (o != null)
                    {
                        rvalue = Convert.ToInt32(o);
                    }

                    if (rvalue != 1 && rvalue != 3)
                    {
                        reg.SetValue("SoftwareSASGeneration", 1);
                    }
                    reg.Close();
                }
            }
            catch
            {
            }

            Threads.StartAllThreads();
        }
Пример #2
0
        static void PolicyThread()
        {
            Int64 NextRunTime = RegistryData.LastSyncPolicies;
            Int64 CurrentTime;

            while (StopThreads == false)
            {
                CurrentTime = CommonUtilities.DTtoINT(DateTime.Now);

                if (InvokePolicy == true)
                {
                    InvokePolicy = false;
                    NextRunTime  = CommonUtilities.DTtoINT(DateTime.Now.AddMinutes(-1));
                }

                if (CurrentTime < NextRunTime)
                {
                    Thread.Sleep(1000);
                    continue;
                }

                lock (LockLock3)
                {
                    if (LockPolicyUpdate == true)
                    {
                        Thread.Sleep(1000);
                        continue;
                    }
                    LockPolicyUpdate = true;
                }

                try
                {
                    SyncPolicy.DoSyncPolicy();

                    #region Prevent criss cross with reportings wait until done!
                    do
                    {
                        lock (LockLock1)
                        {
                            if (LockReportingUpdate1 == true)
                            {
                                if (StopThreads == true)
                                {
                                    LockReportingUpdate1 = false;
                                    break;
                                }
                                Thread.Sleep(1000);
                                continue;
                            }
                            LockReportingUpdate1 = true;
                            break;
                        }
                    } while (true);

                    #endregion

                    if (StopThreads == false)
                    {
                        SyncPolicy.ApplyPolicy(SyncPolicy.ApplyPolicyFunction.ApplySystem);
                    }

                    #region Prevent criss cross with reportings wait until done!
                    lock (LockLock1)
                    {
                        LockReportingUpdate1 = false;
                    }
                    #endregion
                }
                catch (Exception ee)
                {
                    Debug.WriteLine(ee.ToString());
                    FoxEventLog.WriteEventLog("Servere error while syncing / applying policies: " + ee.ToString(), EventLogEntryType.Error);
                }
                Int64 Tim = RegistryData.LastSyncPoliciesWaitTime;
                if (Tim < 1)
                {
                    Tim = 5;
                }

                NextRunTime = CommonUtilities.DTtoINT(DateTime.Now.AddMinutes(Tim));
                RegistryData.LastSyncPolicies = NextRunTime;

                lock (LockLock3)
                {
                    LockPolicyUpdate = false;
                }
            }
        }