2 * Copyright (c) 2000, Red Hat, Inc.
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.
9 * A copy of the GNU General Public License can be found at
12 * Written by DJ Delorie <dj@cygnus.com>
16 #include "AntiVirus.h"
18 #include "getopt++/BoolOption.h"
20 #include "LogSingleton.h"
28 #include "package_db.h"
31 /* XXX: Split this into observer and model classes */
33 /* Default is to leave well enough alone */
34 static BoolOption
DisableVirusOption (false, 'A', "disable-buggy-antivirus", IDS_HELPTEXT_DISABLE_ANTIVIRUS
);
36 static bool KnownAVIsPresent
= false;
37 static bool AVRunning
= true;
38 static SC_HANDLE SCM
= NULL
;
39 static SC_HANDLE McAfeeService
= NULL
;
43 { IDC_DISABLE_AV
, IDC_LEAVE_AV
, 0};
45 static int disableAV
= IDC_LEAVE_AV
;
50 rbset (h
, rb
, disableAV
);
56 disableAV
= rbget (h
, rb
);
60 dialog_cmd (HWND h
, int id
, HWND hwndctl
, UINT code
)
77 AntiVirusPage::Create ()
80 return PropertyPage::Create (NULL
, dialog_cmd
, IDD_VIRUS
);
84 AntiVirusPage::OnActivate ()
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)
90 && SendMessage (GetDlgItem (IDC_LEAVE_AV
), BM_GETCHECK
, 0, 0)
92 SendMessage (GetDlgItem (IDC_LEAVE_AV
), BM_SETCHECK
, BST_CHECKED
, 0);
96 AntiVirusPage::wantsActivation() const
98 // Check if there's an antivirus scanner to be disabled.
101 // Nope, skip this page by "not accepting" activation.
109 AntiVirusPage::OnNext ()
114 /* if disable, do so now */
119 AntiVirusPage::OnBack ()
121 save_dialog (GetHWND ());
126 AntiVirusPage::OnDeactivate ()
128 if (!KnownAVIsPresent
)
130 if (disableAV
== IDC_LEAVE_AV
)
133 SERVICE_STATUS status
;
134 if (!ControlService (McAfeeService
, SERVICE_CONTROL_STOP
, &status
) &&
135 GetLastError() != ERROR_SERVICE_NOT_ACTIVE
)
137 Log (LOG_PLAIN
) << "Could not stop McAfee service, disabled AV logic"
139 disableAV
= IDC_LEAVE_AV
;
144 Log (LOG_PLAIN
) << "Disabled Anti Virus software" << endLog
;
148 AntiVirusPage::OnUnattended ()
150 if (!KnownAVIsPresent
)
152 if ((bool)DisableVirusOption
)
153 disableAV
= IDC_DISABLE_AV
;
155 disableAV
= IDC_LEAVE_AV
;
162 // TODO: trim the access rights down
163 SCM
= OpenSCManager (NULL
, NULL
, SC_MANAGER_ALL_ACCESS
);
166 Log (LOG_BABBLE
) << "Could not open Service control manager" << endLog
;
170 /* in future, factor this to a routine to find service foo (ie norton, older
173 McAfeeService
= OpenService (SCM
, "AvSynMgr",
174 SERVICE_QUERY_STATUS
| SERVICE_STOP
| SERVICE_START
);
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
);
182 SERVICE_STATUS status
;
184 if (!QueryServiceStatus (McAfeeService
, &status
))
186 CloseServiceHandle(SCM
);
187 CloseServiceHandle(McAfeeService
);
188 Log (LOG_PLAIN
) << "Couldn't determine status of McAfee service."
193 if (status
.dwCurrentState
== SERVICE_STOPPED
||
194 status
.dwCurrentState
== SERVICE_STOP_PENDING
)
196 CloseServiceHandle(SCM
);
197 CloseServiceHandle(McAfeeService
);
198 Log (LOG_PLAIN
) << "Mcafee is already stopped, nothing to see here"
202 Log (LOG_PLAIN
) << "Found McAfee anti virus program" << endLog
;
203 KnownAVIsPresent
= true;
209 return KnownAVIsPresent
;
215 if (!KnownAVIsPresent
)
217 if (disableAV
== IDC_LEAVE_AV
)
219 if (AVRunning
== true)
222 if (!StartService(McAfeeService
, 0, NULL
))
224 Log (LOG_PLAIN
) << "Could not start McAfee service again, disabled AV logic" << endLog
;
225 disableAV
= IDC_LEAVE_AV
;
229 Log (LOG_PLAIN
) << "Enabled Anti Virus software" << endLog
;