예제 #1
0
        public void start(Boolean read_only)
        {
            FileStream fs;
            String     dllpath = ".";

            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());

            this.exec_check_only = read_only;
            this.shouldRun       = true;

            if (this.restoremode == true)
            {
                pol_xmlfile = this.restorepath + "\\FixprivPolicyRules.xml";
                svc_xmlfile = this.restorepath + "\\FixprivServiceRules.xml";
            }
            else
            {
                pol_xmlfile = exepath + "\\FixprivPolicyRules.xml";
                svc_xmlfile = exepath + "\\FixprivServiceRules.xml";
            }

            FixprivPolicies fpol = new FixprivPolicies();
            FixprivServices fsvc = new FixprivServices();

            FixprivServices bsvc = new FixprivServices();

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

            try
            {
                fs        = new FileStream(pol_xmlfile, FileMode.Open);
                this.fpol = (FixprivPolicies)sp.Deserialize(fs);

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

                resultview.listView1.Columns[1].Width = 1000;
                resultview.listView1.Columns[2].Width = 0;

                while (this.shouldRun == true)
                {
                    this.signalQueue.WaitOne(1000);
                    fixpriv_result_t r;
                    while (this.returnValueQueue.TryDequeue(out r))
                    {
                        this.result_update(new[] {
                            colors[(int)r.state],
                            r.policy.section_key + "\\" + r.policy.pol_key + "\\" + r.policy.pol_value_name,
                            r.tooltip
                        });

                        this.status_update(r.policy.pol_value_name);
                        this.progress_update(resultview.listView1.Items.Count, this.fpol.rules.Count);
                    }
                }

                if (resultview.listView1.Items.Count > 0)
                {
                    resultview.listView1.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
                }

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

                //Debug.WriteLine("[*] processing {0} services", fsvc.rules.Count);

                foreach (FixprivService svc in fsvc.rules)
                {
                    fixpriv_status_t  result;
                    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 == this.exec_check_only)
                    {
                        fixpriv_svc_modify(pi_svc);
                    }

                    result = fixpriv_svc_check(pi_svc);

                    if ((int)result == -2)
                    {
                        this.result_update(new[] {
                            colors[(int)fixpriv_status_t.FIXPRIV_NEUTRAL],
                            "[Windows Services] " + pi_svc.service_name + ": Permission Denied",
                            svc.serviceDescription
                        });
                    }
                    else
                    {
                        this.result_update(new[] {
                            colors[(int)result],
                            "[Windows Services] " + pi_svc.service_name + ": " + pi_svc.service_startup,
                            svc.serviceDescription
                        });
                    }

                    this.status_update(pi_svc.service_name);
                } // foreach svc

                if (false == this.exec_check_only)
                {
                    this.backup.store(bsvc);
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine("[e] error in main: " + e.Message);
                if (false == this.exec_check_only)
                {
                    this.backup.store(bsvc);
                }
            }
            this.status_update("Done");
        }
예제 #2
0
 public static extern UInt32 fixpriv_svc_read(ref fixpriv_privsvc_t pol);
예제 #3
0
 public static extern fixpriv_status_t fixpriv_svc_check(fixpriv_privsvc_t privpol);
예제 #4
0
 public static extern UInt32 fixpriv_svc_modify(fixpriv_privsvc_t pol);