]> cygwin.com Git - cygwin-apps/setup.git/blame - AntiVirus.cc
2002-11-26 Robert Collins <rbtcollins@hotmail.com>
[cygwin-apps/setup.git] / AntiVirus.cc
CommitLineData
f9e903a3
RC
1/*
2 * Copyright (c) 2000, Red Hat, Inc.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * A copy of the GNU General Public License can be found at
10 * http://www.gnu.org/
11 *
12 * Written by DJ Delorie <dj@cygnus.com>
13 *
14 */
15
16/* The purpose of this file is to manage the dialog box that lets the
17 user choose the source of the install - from the net, from the
18 current directory, or to just download files. */
19
20#if 0
21static const char *cvsid =
22 "\n%%% $Id$\n";
23#endif
24
25#include "win32.h"
26#include <stdio.h>
27#include "dialog.h"
28#include "resource.h"
29#include "state.h"
30#include "msg.h"
31#include "log.h"
32#include "package_db.h"
33
34#include "AntiVirus.h"
35
36#include "getopt++/BoolOption.h"
37
38/* XXX: Split this into observer and model classes */
39
40/* Default is to leave well enough alone */
58983805 41static BoolOption DisableVirusOption (false, 'A', "disable-buggy-antivirus", "Disable known or suspected buggy anti virus software packages during execution.");
f9e903a3
RC
42
43static bool KnownAVIsPresent = false;
44static bool AVRunning = true;
45static SC_HANDLE SCM = NULL;
46static SC_HANDLE McAfeeService = NULL;
47static void detect();
48
49static int rb[] =
50{ IDC_DISABLE_AV, IDC_LEAVE_AV, 0};
51
52static int disableAV = IDC_LEAVE_AV;
53
54static void
55load_dialog (HWND h)
56{
57 rbset (h, rb, disableAV);
58}
59
60static void
61save_dialog (HWND h)
62{
63 disableAV = rbget (h, rb);
64}
65
66static BOOL
67dialog_cmd (HWND h, int id, HWND hwndctl, UINT code)
68{
69 switch (id)
70 {
71
72 case IDC_DISABLE_AV:
73 case IDC_LEAVE_AV:
74 save_dialog (h);
75 break;
76
77 default:
78 break;
79 }
80 return 0;
81}
82
83bool
84AntiVirusPage::Create ()
85{
86 detect();
87 return PropertyPage::Create (NULL, dialog_cmd, IDD_VIRUS);
88}
89
90void
91AntiVirusPage::OnActivate ()
92{
93 load_dialog (GetHWND ());
94 // Check to see if any radio buttons are selected. If not, select a default.
95 if ((!SendMessage
96 (GetDlgItem (IDC_DISABLE_AV), BM_GETCHECK, 0,
97 0) == BST_CHECKED)
98 && (!SendMessage (GetDlgItem (IDC_LEAVE_AV), BM_GETCHECK, 0, 0)
99 == BST_CHECKED))
100 {
101 SendMessage (GetDlgItem (IDC_LEAVE_AV), BM_SETCHECK,
102 BST_CHECKED, 0);
103 }
104
105}
106
107long
108AntiVirusPage::OnNext ()
109{
110 HWND h = GetHWND ();
111
112 save_dialog (h);
113 /* if disable, do so now */
114 return IDD_SOURCE;
115}
116
117long
118AntiVirusPage::OnBack ()
119{
120 save_dialog (GetHWND ());
121 return 0;
122}
123
124void
125AntiVirusPage::OnDeactivate ()
126{
127 if (!KnownAVIsPresent)
128 return;
129 if (disableAV == IDC_LEAVE_AV)
130 return;
131
132 SERVICE_STATUS status;
133 if (!ControlService (McAfeeService, SERVICE_CONTROL_STOP, &status) &&
134 GetLastError() != ERROR_SERVICE_NOT_ACTIVE)
135 {
136 log (LOG_PLAIN, "Could not stop McAfee service, disabled AV logic\n");
137 disableAV = IDC_LEAVE_AV;
138 return;
139 }
140
141 AVRunning = false;
142 log (LOG_PLAIN, String ("Disabled Anti Virus software"));
143}
144
145long
146AntiVirusPage::OnUnattended ()
147{
148 if (!KnownAVIsPresent)
149 return OnNext();
150 if ((bool)DisableVirusOption)
151 disableAV = IDC_DISABLE_AV;
152 else
153 disableAV = IDC_LEAVE_AV;
154 return OnNext();
155}
156
157void
158detect ()
159{
160 if (Win32::OS () == Win32::Win9x)
161 return;
162 // TODO: trim the access rights down
163 SCM = OpenSCManager (NULL, NULL, SC_MANAGER_ALL_ACCESS);
164
165 if (!SCM) {
166 log (LOG_PLAIN, String ("Could not open Service control manager\n"));
167 return;
168 }
169
170 /* in future, factor this to a routine to find service foo (ie norton, older
171 mcafee etc
172 */
173 McAfeeService = OpenService (SCM, "AvSynMgr",
174 SERVICE_QUERY_STATUS| SERVICE_STOP| SERVICE_START);
175
176 if (!McAfeeService) {
177 log (LOG_PLAIN, String("Could not open service McShield for query, start and stop. McAfee may not be installed, or we don't have access.\n"));
178 CloseServiceHandle(SCM);
179 return;
180 }
181
182 SERVICE_STATUS status;
183
184 if (!QueryServiceStatus (McAfeeService, &status))
185 {
186 CloseServiceHandle(SCM);
187 CloseServiceHandle(McAfeeService);
188 log (LOG_PLAIN, String("Couldn't determine status of McAfee service.\n"));
189 return;
190 }
191
192 if (status.dwCurrentState == SERVICE_STOPPED ||
193 status.dwCurrentState == SERVICE_STOP_PENDING)
194 {
195 CloseServiceHandle(SCM);
196 CloseServiceHandle(McAfeeService);
197 log (LOG_PLAIN, "Mcafee is already stopped, nothing to see here\n");
198 }
199
200 log (LOG_PLAIN, "Found McAfee anti virus program\n");
201 KnownAVIsPresent = true;
202}
203
204bool
205AntiVirus::Show()
206{
207 return KnownAVIsPresent;
208}
209
210void
211AntiVirus::AtExit()
212{
213 if (!KnownAVIsPresent)
214 return;
215 if (disableAV == IDC_LEAVE_AV)
216 return;
217 if (AVRunning == true)
218 return;
219
220 if (!StartService(McAfeeService, 0, NULL))
221 {
222 log (LOG_PLAIN, "Could not start McAfee service again, disabled AV logic\n");
223 disableAV = IDC_LEAVE_AV;
224 return;
225 }
226
227 log (LOG_PLAIN, String ("Enabled Anti Virus software"));
228
229 AVRunning = true;
230
231}
This page took 0.039422 seconds and 5 git commands to generate.