]>
Commit | Line | Data |
---|---|---|
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 | ||
a77b6167 MB |
16 | #include "AntiVirus.h" |
17 | ||
18 | #include "getopt++/BoolOption.h" | |
f9e903a3 | 19 | |
a77b6167 | 20 | #include "LogSingleton.h" |
f9e903a3 RC |
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" | |
f9e903a3 RC |
28 | #include "package_db.h" |
29 | ||
f9e903a3 RC |
30 | |
31 | /* XXX: Split this into observer and model classes */ | |
30718d6f | 32 | |
f9e903a3 | 33 | /* Default is to leave well enough alone */ |
20f237b4 | 34 | static BoolOption DisableVirusOption (false, 'A', "disable-buggy-antivirus", IDS_HELPTEXT_DISABLE_ANTIVIRUS); |
f9e903a3 RC |
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. | |
8c34cc98 CV |
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); | |
b28e9f01 | 93 | } |
f9e903a3 | 94 | |
b28e9f01 MB |
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; | |
f9e903a3 RC |
106 | } |
107 | ||
108 | long | |
109 | AntiVirusPage::OnNext () | |
110 | { | |
111 | HWND h = GetHWND (); | |
112 | ||
113 | save_dialog (h); | |
114 | /* if disable, do so now */ | |
0f61a6a4 | 115 | return 0; |
f9e903a3 RC |
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 | { | |
157dc2b8 | 137 | Log (LOG_PLAIN) << "Could not stop McAfee service, disabled AV logic" |
30718d6f | 138 | << endLog; |
f9e903a3 RC |
139 | disableAV = IDC_LEAVE_AV; |
140 | return; | |
141 | } | |
30718d6f | 142 | |
f9e903a3 | 143 | AVRunning = false; |
157dc2b8 | 144 | Log (LOG_PLAIN) << "Disabled Anti Virus software" << endLog; |
f9e903a3 RC |
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 | |
30718d6f | 155 | disableAV = IDC_LEAVE_AV; |
f9e903a3 RC |
156 | return OnNext(); |
157 | } | |
158 | ||
159 | void | |
160 | detect () | |
161 | { | |
30718d6f | 162 | // TODO: trim the access rights down |
f9e903a3 RC |
163 | SCM = OpenSCManager (NULL, NULL, SC_MANAGER_ALL_ACCESS); |
164 | ||
165 | if (!SCM) { | |
a692b7f4 | 166 | Log (LOG_BABBLE) << "Could not open Service control manager" << endLog; |
f9e903a3 RC |
167 | return; |
168 | } | |
30718d6f | 169 | |
f9e903a3 | 170 | /* in future, factor this to a routine to find service foo (ie norton, older |
30718d6f | 171 | mcafee etc |
f9e903a3 | 172 | */ |
30718d6f | 173 | McAfeeService = OpenService (SCM, "AvSynMgr", |
f9e903a3 RC |
174 | SERVICE_QUERY_STATUS| SERVICE_STOP| SERVICE_START); |
175 | ||
176 | if (!McAfeeService) { | |
a692b7f4 | 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; |
f9e903a3 RC |
178 | CloseServiceHandle(SCM); |
179 | return; | |
180 | } | |
181 | ||
182 | SERVICE_STATUS status; | |
183 | ||
184 | if (!QueryServiceStatus (McAfeeService, &status)) | |
185 | { | |
186 | CloseServiceHandle(SCM); | |
187 | CloseServiceHandle(McAfeeService); | |
157dc2b8 | 188 | Log (LOG_PLAIN) << "Couldn't determine status of McAfee service." |
30718d6f | 189 | << endLog; |
f9e903a3 RC |
190 | return; |
191 | } | |
192 | ||
193 | if (status.dwCurrentState == SERVICE_STOPPED || | |
30718d6f | 194 | status.dwCurrentState == SERVICE_STOP_PENDING) |
f9e903a3 RC |
195 | { |
196 | CloseServiceHandle(SCM); | |
197 | CloseServiceHandle(McAfeeService); | |
157dc2b8 | 198 | Log (LOG_PLAIN) << "Mcafee is already stopped, nothing to see here" |
30718d6f | 199 | << endLog; |
f9e903a3 | 200 | } |
30718d6f | 201 | |
157dc2b8 | 202 | Log (LOG_PLAIN) << "Found McAfee anti virus program" << endLog; |
f9e903a3 RC |
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)) | |
30718d6f | 223 | { |
157dc2b8 | 224 | Log (LOG_PLAIN) << "Could not start McAfee service again, disabled AV logic" << endLog; |
f9e903a3 RC |
225 | disableAV = IDC_LEAVE_AV; |
226 | return; | |
227 | } | |
228 | ||
157dc2b8 | 229 | Log (LOG_PLAIN) << "Enabled Anti Virus software" << endLog; |
30718d6f | 230 | |
f9e903a3 | 231 | AVRunning = true; |
f9e903a3 | 232 | } |