]> cygwin.com Git - cygwin-apps/setup.git/blob - AntiVirus.cc
Also localize options helptext framing text
[cygwin-apps/setup.git] / AntiVirus.cc
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 #include "AntiVirus.h"
17
18 #include "getopt++/BoolOption.h"
19
20 #include "LogSingleton.h"
21
22 #include "win32.h"
23 #include <stdio.h>
24 #include "dialog.h"
25 #include "resource.h"
26 #include "state.h"
27 #include "msg.h"
28 #include "package_db.h"
29
30
31 /* XXX: Split this into observer and model classes */
32
33 /* Default is to leave well enough alone */
34 static BoolOption DisableVirusOption (false, 'A', "disable-buggy-antivirus", IDS_HELPTEXT_DISABLE_ANTIVIRUS);
35
36 static bool KnownAVIsPresent = false;
37 static bool AVRunning = true;
38 static SC_HANDLE SCM = NULL;
39 static SC_HANDLE McAfeeService = NULL;
40 static void detect();
41
42 static int rb[] =
43 { IDC_DISABLE_AV, IDC_LEAVE_AV, 0};
44
45 static int disableAV = IDC_LEAVE_AV;
46
47 static void
48 load_dialog (HWND h)
49 {
50 rbset (h, rb, disableAV);
51 }
52
53 static void
54 save_dialog (HWND h)
55 {
56 disableAV = rbget (h, rb);
57 }
58
59 static BOOL
60 dialog_cmd (HWND h, int id, HWND hwndctl, UINT code)
61 {
62 switch (id)
63 {
64
65 case IDC_DISABLE_AV:
66 case IDC_LEAVE_AV:
67 save_dialog (h);
68 break;
69
70 default:
71 break;
72 }
73 return 0;
74 }
75
76 bool
77 AntiVirusPage::Create ()
78 {
79 detect();
80 return PropertyPage::Create (NULL, dialog_cmd, IDD_VIRUS);
81 }
82
83 void
84 AntiVirusPage::OnActivate ()
85 {
86 load_dialog (GetHWND ());
87 // Check to see if any radio buttons are selected. If not, select a default.
88 if (SendMessage (GetDlgItem (IDC_DISABLE_AV), BM_GETCHECK, 0, 0)
89 != BST_CHECKED
90 && SendMessage (GetDlgItem (IDC_LEAVE_AV), BM_GETCHECK, 0, 0)
91 != BST_CHECKED)
92 SendMessage (GetDlgItem (IDC_LEAVE_AV), BM_SETCHECK, BST_CHECKED, 0);
93 }
94
95 bool
96 AntiVirusPage::wantsActivation() const
97 {
98 // Check if there's an antivirus scanner to be disabled.
99 if(!KnownAVIsPresent)
100 {
101 // Nope, skip this page by "not accepting" activation.
102 return false;
103 }
104
105 return true;
106 }
107
108 long
109 AntiVirusPage::OnNext ()
110 {
111 HWND h = GetHWND ();
112
113 save_dialog (h);
114 /* if disable, do so now */
115 return 0;
116 }
117
118 long
119 AntiVirusPage::OnBack ()
120 {
121 save_dialog (GetHWND ());
122 return 0;
123 }
124
125 void
126 AntiVirusPage::OnDeactivate ()
127 {
128 if (!KnownAVIsPresent)
129 return;
130 if (disableAV == IDC_LEAVE_AV)
131 return;
132
133 SERVICE_STATUS status;
134 if (!ControlService (McAfeeService, SERVICE_CONTROL_STOP, &status) &&
135 GetLastError() != ERROR_SERVICE_NOT_ACTIVE)
136 {
137 Log (LOG_PLAIN) << "Could not stop McAfee service, disabled AV logic"
138 << endLog;
139 disableAV = IDC_LEAVE_AV;
140 return;
141 }
142
143 AVRunning = false;
144 Log (LOG_PLAIN) << "Disabled Anti Virus software" << endLog;
145 }
146
147 long
148 AntiVirusPage::OnUnattended ()
149 {
150 if (!KnownAVIsPresent)
151 return OnNext();
152 if ((bool)DisableVirusOption)
153 disableAV = IDC_DISABLE_AV;
154 else
155 disableAV = IDC_LEAVE_AV;
156 return OnNext();
157 }
158
159 void
160 detect ()
161 {
162 // TODO: trim the access rights down
163 SCM = OpenSCManager (NULL, NULL, SC_MANAGER_ALL_ACCESS);
164
165 if (!SCM) {
166 Log (LOG_BABBLE) << "Could not open Service control manager" << endLog;
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_BABBLE) << "Could not open service McShield for query, start and stop. McAfee may not be installed, or we don't have access." << endLog;
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) << "Couldn't determine status of McAfee service."
189 << endLog;
190 return;
191 }
192
193 if (status.dwCurrentState == SERVICE_STOPPED ||
194 status.dwCurrentState == SERVICE_STOP_PENDING)
195 {
196 CloseServiceHandle(SCM);
197 CloseServiceHandle(McAfeeService);
198 Log (LOG_PLAIN) << "Mcafee is already stopped, nothing to see here"
199 << endLog;
200 }
201
202 Log (LOG_PLAIN) << "Found McAfee anti virus program" << endLog;
203 KnownAVIsPresent = true;
204 }
205
206 bool
207 AntiVirus::Show()
208 {
209 return KnownAVIsPresent;
210 }
211
212 void
213 AntiVirus::AtExit()
214 {
215 if (!KnownAVIsPresent)
216 return;
217 if (disableAV == IDC_LEAVE_AV)
218 return;
219 if (AVRunning == true)
220 return;
221
222 if (!StartService(McAfeeService, 0, NULL))
223 {
224 Log (LOG_PLAIN) << "Could not start McAfee service again, disabled AV logic" << endLog;
225 disableAV = IDC_LEAVE_AV;
226 return;
227 }
228
229 Log (LOG_PLAIN) << "Enabled Anti Virus software" << endLog;
230
231 AVRunning = true;
232 }
This page took 0.045961 seconds and 5 git commands to generate.