root/branches/3.00/src/AntiVirus.cc

Revision 644, 5.1 kB (checked in by fujii, 3 years ago)

Add new netinstall source.

Line 
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
21 static const char *cvsid =
22   "\n%%% $Id: AntiVirus.cc,v 2.5 2003/07/29 14:14:06 maxb Exp $\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 */
41 static BoolOption DisableVirusOption (false, 'A', "disable-buggy-antivirus", "Disable known or suspected buggy anti virus software packages during execution.");
42
43 static bool KnownAVIsPresent = false;
44 static bool AVRunning = true;
45 static SC_HANDLE SCM = NULL;
46 static SC_HANDLE McAfeeService = NULL;
47 static void detect();
48
49 static int rb[] =
50 { IDC_DISABLE_AV, IDC_LEAVE_AV, 0};
51
52 static int disableAV = IDC_LEAVE_AV;
53
54 static void
55 load_dialog (HWND h)
56 {
57   rbset (h, rb, disableAV);
58 }
59
60 static void
61 save_dialog (HWND h)
62 {
63   disableAV = rbget (h, rb);
64 }
65
66 static BOOL
67 dialog_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
83 bool
84 AntiVirusPage::Create ()
85 {
86     detect();
87     return PropertyPage::Create (NULL, dialog_cmd, IDD_VIRUS);
88 }
89
90 void
91 AntiVirusPage::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 bool
107 AntiVirusPage::wantsActivation() const
108 {
109   // Check if there's an antivirus scanner to be disabled.
110   if(!KnownAVIsPresent)
111   {
112     // Nope, skip this page by "not accepting" activation.
113     return false;
114   }
115
116   return true;
117 }
118
119 long
120 AntiVirusPage::OnNext ()
121 {
122   HWND h = GetHWND ();
123
124   save_dialog (h);
125   /* if disable, do so now */
126   return 0;
127 }
128
129 long
130 AntiVirusPage::OnBack ()
131 {
132   save_dialog (GetHWND ());
133   return 0;
134 }
135
136 void
137 AntiVirusPage::OnDeactivate ()
138 {
139   if (!KnownAVIsPresent)
140         return;
141   if (disableAV == IDC_LEAVE_AV)
142       return;
143
144   SERVICE_STATUS status;
145   if (!ControlService (McAfeeService, SERVICE_CONTROL_STOP, &status) &&
146       GetLastError() != ERROR_SERVICE_NOT_ACTIVE)
147     {
148       log (LOG_PLAIN, "Could not stop McAfee service, disabled AV logic\n");
149       disableAV = IDC_LEAVE_AV;
150       return;
151     }
152        
153   AVRunning = false;
154   log (LOG_PLAIN, String ("Disabled Anti Virus software"));
155 }
156
157 long
158 AntiVirusPage::OnUnattended ()
159 {
160     if (!KnownAVIsPresent)
161         return OnNext();
162     if ((bool)DisableVirusOption)
163         disableAV = IDC_DISABLE_AV;
164     else
165         disableAV = IDC_LEAVE_AV;
166   return OnNext();
167 }
168
169 void
170 detect ()
171 {
172     if (Win32::OS () == Win32::Win9x)
173         return;
174     // TODO: trim the access rights down
175     SCM = OpenSCManager (NULL, NULL, SC_MANAGER_ALL_ACCESS);
176
177     if (!SCM) {
178         log (LOG_PLAIN, String ("Could not open Service control manager\n"));
179         return;
180     }
181    
182     /* in future, factor this to a routine to find service foo (ie norton, older
183        mcafee etc
184        */
185     McAfeeService = OpenService (SCM, "AvSynMgr",
186         SERVICE_QUERY_STATUS| SERVICE_STOP| SERVICE_START);
187
188     if (!McAfeeService) {
189         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"));
190         CloseServiceHandle(SCM);
191         return;
192     }
193
194     SERVICE_STATUS status;
195
196     if (!QueryServiceStatus (McAfeeService, &status))
197       {
198         CloseServiceHandle(SCM);
199         CloseServiceHandle(McAfeeService);
200         log (LOG_PLAIN, String("Couldn't determine status of McAfee service.\n"));
201         return;
202       }
203
204     if (status.dwCurrentState == SERVICE_STOPPED ||
205         status.dwCurrentState == SERVICE_STOP_PENDING)
206       {
207         CloseServiceHandle(SCM);
208         CloseServiceHandle(McAfeeService);
209         log (LOG_PLAIN, "Mcafee is already stopped, nothing to see here\n");
210       }
211    
212     log (LOG_PLAIN, "Found McAfee anti virus program\n");
213     KnownAVIsPresent = true;
214 }
215
216 bool
217 AntiVirus::Show()
218 {
219     return KnownAVIsPresent;
220 }
221
222 void
223 AntiVirus::AtExit()
224 {
225     if (!KnownAVIsPresent)
226         return;
227     if (disableAV == IDC_LEAVE_AV)
228         return;
229     if (AVRunning == true)
230         return;
231
232     if (!StartService(McAfeeService, 0, NULL))
233         {
234           log (LOG_PLAIN, "Could not start McAfee service again, disabled AV logic\n");
235           disableAV = IDC_LEAVE_AV;
236           return;
237         }
238
239     log (LOG_PLAIN, String ("Enabled Anti Virus software")); 
240    
241     AVRunning = true;
242        
243 }
Note: See TracBrowser for help on using the browser.