void store_services(FixprivServices s)
        {
            string        svc_xmlfile = this.backup_dir + "\\FixprivServiceRules.xml";
            XmlSerializer ss          = new XmlSerializer(typeof(FixprivServices));

            try
            {
                TextWriter fs;
                fs = new StreamWriter(svc_xmlfile);
                ss.Serialize(fs, s);
                fs.Close();
            }
            catch (Exception e)
            {
                Debug.WriteLine("[e] serialize policies: " + e.Message);
            }
        }
Beispiel #2
0
        //[STAThread]
        static void Main(string[] args)
        {
            FileStream fs;
            String     dllpath = "C:\\Users\\ths\\Dev\\mod0-winX-priv\\fix-privacy\\x64\\Debug;."; // XXX

            Environment.SetEnvironmentVariable("PATH", Environment.GetEnvironmentVariable("PATH") + ";" + dllpath);
            List <string> cpath = new List <string>(Application.ExecutablePath.Split('\\'));

            cpath.RemoveRange(cpath.Count() - 1, 1);
            String exepath = string.Join("\\", cpath.ToArray());

            bool          show_help = false;
            List <string> mozpaths  = new List <string>();

            var p = new OptionSet()
            {
                { "f|fix", "fix privacy settings (default is check-only)", v => { if (v != null)
                                                                                  {
                                                                                      read_only = false;
                                                                                  }
                  } },
                { "b|batch", "batch-mode - no interaction", v => { if (v != null)
                                                                   {
                                                                       no_interaction = true;
                                                                   }
                  } },
                { "p|pxml=", "path to policy rules", v => pol_xmlfile = v },
                { "s|sxml=", "path to service rules", v => svc_xmlfile = v },
                { "v", "increase debug message verbosity", v => { if (v != null)
                                                                  {
                                                                      ++verbosity;
                                                                  }
                  } },
                { "h|help", "show this message and exit", v => show_help = v != null },
            };

            List <string> extra;

            try
            {
                extra = p.Parse(args);
            }
            catch (OptionException)
            {
                Console.WriteLine("Try '--help' for more information.");
                return;
            }

            if (show_help)
            {
                usage(p);
            }

            if (pol_xmlfile == null)
            {
                pol_xmlfile = exepath + "\\FixprivPolicyRules.xml";
            }

            if (svc_xmlfile == null)
            {
                svc_xmlfile = exepath + "\\FixprivServiceRules.xml";
            }

            FixprivPolicies fpol   = new FixprivPolicies();
            FixprivServices fsvc   = new FixprivServices();
            FixprivServices bsvc   = new FixprivServices(); // backup services
            FixprivBackup   backup = new FixprivBackup();

            XmlSerializer sp = new XmlSerializer(typeof(FixprivPolicies));
            XmlSerializer ss = new XmlSerializer(typeof(FixprivServices));

            string        arguments = String.Join(" ", args);
            StringBuilder av        = new StringBuilder(arguments);

            fixpriv_elevate_withargs(av);

            try
            {
                fixpriv_status_t result;
                shouldRun = true;

                fs = new FileStream(pol_xmlfile, FileMode.Open);

                fpol = (FixprivPolicies)sp.Deserialize(fs);

                FixprivWorker w = new FixprivWorker(fpol, backup, read_only); // if read_only = true, only read and compare values

                Thread t = new Thread(new ThreadStart(w.go));
                t.SetApartmentState(ApartmentState.STA);
                t.Start();

                while (shouldRun == true)
                {
                    signalQueue.WaitOne(1000);
                    fixpriv_result_t r;
                    while (returnValueQueue.TryDequeue(out r))
                    {
                        Console.WriteLine(" [Policy " + progress_count + "] [" + colors[(int)r.state] + "] "
                                          + r.policy.section_key
                                          + "\\" + r.policy.pol_key
                                          + "\\" + r.policy.pol_value_name);
                        progress_count++;
                    }
                }

                fs.Close();

                fs   = new FileStream(svc_xmlfile, FileMode.Open);
                fsvc = (FixprivServices)ss.Deserialize(fs);

                foreach (FixprivService svc in fsvc.rules)
                {
                    fixpriv_privsvc_t pi_svc        = new fixpriv_privsvc_t();
                    fixpriv_privsvc_t backup_pi_svc = new fixpriv_privsvc_t();
                    FixprivService    backup_svc    = new FixprivService();

                    pi_svc.service_name   = backup_svc.name = svc.name;
                    pi_svc.service_path   = backup_svc.servicePath = svc.servicePath;
                    pi_svc.service_params = backup_svc.serviceParams = svc.serviceParams;

                    backup_pi_svc.service_name   = svc.name;
                    backup_pi_svc.service_path   = svc.servicePath;
                    backup_pi_svc.service_params = svc.serviceParams;

                    backup_svc.serviceState       = "WS_STATUS_UNCHANGED";
                    backup_svc.serviceDescription = svc.serviceDescription;
                    backup_svc.id = svc.id;

                    if (svc.serviceCommand.Equals("WS_STARTUP_AUTOMATIC_DELAYED"))
                    {
                        pi_svc.service_startup = ws_startup_t.WS_STARTUP_AUTOMATIC_DELAYED;
                    }
                    else if (svc.serviceCommand.Equals("WS_STARTUP_AUTOMATIC"))
                    {
                        pi_svc.service_startup = ws_startup_t.WS_STARTUP_AUTOMATIC;
                    }
                    else if (svc.serviceCommand.Equals("WS_STARTUP_MANUAL"))
                    {
                        pi_svc.service_startup = ws_startup_t.WS_STARTUP_MANUAL;
                    }
                    else if (svc.serviceCommand.Equals("WS_STARTUP_DISABLED"))
                    {
                        pi_svc.service_startup = ws_startup_t.WS_STARTUP_DISABLED;
                    }
                    else if (svc.serviceCommand.Equals("WS_STARTUP_DELETE"))
                    {
                        pi_svc.service_startup = ws_startup_t.WS_STARTUP_DELETE;
                    }
                    else
                    {
                        pi_svc.service_startup = ws_startup_t.WS_STARTUP_UNCHANGED;
                    }

                    if (svc.serviceState.Equals("WS_STATUS_START"))
                    {
                        pi_svc.service_status = ws_status_t.WS_STATUS_START;
                    }
                    else if (svc.serviceState.Equals("WS_STATUS_STOP"))
                    {
                        pi_svc.service_status = ws_status_t.WS_STATUS_STOP;
                    }
                    else if (svc.serviceState.Equals("WS_STATUS_PAUSE"))
                    {
                        pi_svc.service_status = ws_status_t.WS_STATUS_PAUSE;
                    }
                    else if (svc.serviceState.Equals("WS_STATUS_RESUME"))
                    {
                        pi_svc.service_status = ws_status_t.WS_STATUS_RESUME;
                    }
                    else
                    {
                        pi_svc.service_status = ws_status_t.WS_STATUS_UNCHANGED;
                    }

                    fixpriv_svc_read(ref backup_pi_svc);

                    switch (backup_pi_svc.service_startup)
                    {
                    case ws_startup_t.WS_STARTUP_AUTOMATIC_DELAYED:
                        backup_svc.serviceCommand = "WS_STARTUP_AUTOMATIC_DELAYED";
                        break;

                    case ws_startup_t.WS_STARTUP_AUTOMATIC:
                        backup_svc.serviceCommand = "WS_STARTUP_AUTOMATIC";
                        break;

                    case ws_startup_t.WS_STARTUP_MANUAL:
                        backup_svc.serviceCommand = "WS_STARTUP_MANUAL";
                        break;

                    case ws_startup_t.WS_STARTUP_DISABLED:
                        backup_svc.serviceCommand = "WS_STARTUP_DISABLED";
                        break;

                    case ws_startup_t.WS_STARTUP_DELETE:
                        backup_svc.serviceCommand = "WS_STARTUP_DELETE";
                        break;

                    case ws_startup_t.WS_STARTUP_UNCHANGED:
                    default:
                        backup_svc.serviceCommand = "WS_STARTUP_UNCHANGED";
                        break;
                    }

                    bsvc.rules.Add(backup_svc);

                    if (false == read_only)
                    {
                        fixpriv_svc_modify(pi_svc);
                    }

                    result = fixpriv_svc_check(pi_svc);

                    if ((int)result == -2)
                    {
                        Console.WriteLine("[Windows Services " + progress_count + "] ["
                                          + colors[(int)fixpriv_status_t.FIXPRIV_NEUTRAL] + "] "
                                          + pi_svc.service_name + ": Permission Denied");
                    }
                    else
                    {
                        Console.WriteLine("[Windows Services "
                                          + progress_count + "] [" + colors[(int)result] + "] "
                                          + pi_svc.service_name + ": "
                                          + pi_svc.service_startup);
                    }

                    progress_count++;
                } // foreach svc

                if (false == read_only)
                {
                    backup.store(bsvc);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("[e] error in main: " + e.Message);
                if (false == read_only)
                {
                    backup.store(bsvc);
                }
            }

            if (no_interaction == false)
            {
                Console.Write("\nPress any key to continue... ");
                Console.ReadLine();
            }
        } // Main
 public void store(FixprivServices svc)
 {
     this.mk_backup_dir();
     this.store_services(svc);
 }