137
138
#define PREF_BDA_DONTCLEAN "browser.download.antivirus.dontclean"
139
#define PREF_BDM_SKIPWINPOLICYCHECKS "browser.download.manager.skipWinSecurityPolicyChecks"
139
141
// IAttachementExecute supports user definable settings for certain
140
142
// security related prompts. This defines a general GUID for use in
171
173
HANDLE mQuitEvent;
174
nsDownloadScanner::nsDownloadScanner()
175
: mHaveAVScanner(PR_FALSE), mHaveAttachmentExecute(PR_FALSE)
181
nsDownloadScanner::nsDownloadScanner() :
183
, mAESExists(PR_FALSE)
184
, mUseAttachmentExecute(PR_FALSE)
192
201
// codebase. All other COM calls/objects are made on different threads.
193
202
nsresult rv = NS_OK;
194
203
CoInitialize(NULL);
195
if (!IsAESAvailable() && ListCLSID() < 0)
196
rv = NS_ERROR_NOT_AVAILABLE;
205
// Check for the existence of IAE
206
mAESExists = IsAESAvailable();
208
// Init OAV scanner list
209
mOAVExists = EnumerateOAVProviders();
197
211
CoUninitialize();
198
if (NS_SUCCEEDED(rv)) {
199
mWatchdog = new nsDownloadScannerWatchdog();
201
rv = mWatchdog->Init();
205
rv = NS_ERROR_OUT_OF_MEMORY;
213
if (!mAESExists && !mOAVExists)
214
return NS_ERROR_NOT_AVAILABLE;
217
mUseAttachmentExecute = PR_TRUE;
219
// Initialize scanning
220
mWatchdog = new nsDownloadScannerWatchdog();
222
rv = mWatchdog->Init();
226
rv = NS_ERROR_OUT_OF_MEMORY;
232
// If skipWinSecurityPolicyChecks is set, do not use attachement execute,
233
// fall back on the older interface. AE does virus scanning, applies
234
// security policy checks, and also adds security meta data to downloaded
236
PRBool skipPolicy = PR_FALSE;
237
nsCOMPtr<nsIPrefBranch> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID));
239
(void)prefs->GetBoolPref(PREF_BDM_SKIPWINPOLICYCHECKS, &skipPolicy);
241
mUseAttachmentExecute = PR_FALSE;
243
// Setup a pref change even for the policy check pref.
244
nsCOMPtr<nsIPrefBranch2> prefBranch =
245
do_GetService(NS_PREFSERVICE_CONTRACTID);
248
(void)prefBranch->AddObserver(PREF_BDM_SKIPWINPOLICYCHECKS, this, PR_FALSE);
250
nsCOMPtr<nsIObserverService> observerService =
251
do_GetService(NS_OBSERVERSERVICE_CONTRACTID);
254
(void)observerService->AddObserver(this, "quit-application", PR_FALSE);
213
260
nsDownloadScanner::IsAESAvailable()
262
// Try to instantiate IAE to see if it's available.
215
263
nsRefPtr<IAttachmentExecute> ae;
217
265
hr = CoCreateInstance(CLSID_AttachmentServices, NULL, CLSCTX_INPROC,
220
268
NS_WARNING("Could not instantiate attachment execution service\n");
224
mHaveAVScanner = PR_TRUE;
225
mHaveAttachmentExecute = PR_TRUE;
230
nsDownloadScanner::ListCLSID()
275
nsDownloadScanner::EnumerateOAVProviders()
232
277
nsRefPtr<ICatInformation> catInfo;
235
280
IID_ICatInformation, getter_AddRefs(catInfo));
236
281
if (FAILED(hr)) {
237
282
NS_WARNING("Could not create category information class\n");
240
285
nsRefPtr<IEnumCLSID> clsidEnumerator;
241
286
GUID guids [1] = { CATID_MSOfficeAntiVirus };
254
299
if (mScanCLSID.Length() == 0) {
255
300
// No installed Anti Virus program
259
mHaveAVScanner = PR_TRUE;
307
// XPCOM pref change observer - reset our default scanner settings.
309
nsDownloadScanner::Observe(nsISupports *aSubject, const char *aTopic, const PRUnichar *someData)
311
nsCOMPtr<nsIPrefBranch2> prefBranch =
312
do_GetService(NS_PREFSERVICE_CONTRACTID);
314
if (aTopic && !strcmp(aTopic, "quit-application")) {
316
(void)prefBranch->RemoveObserver(PREF_BDM_SKIPWINPOLICYCHECKS, this);
318
nsCOMPtr<nsIObserverService> observerService =
319
do_GetService(NS_OBSERVERSERVICE_CONTRACTID);
322
(void)observerService->RemoveObserver(this, "quit-application");
326
PRBool skipPolicyCheck = PR_FALSE;
328
(void)prefBranch->GetBoolPref(PREF_BDM_SKIPWINPOLICYCHECKS, &skipPolicyCheck);
330
mUseAttachmentExecute = !skipPolicyCheck && mAESExists;
263
335
// If IAttachementExecute is available, use the CheckPolicy call to find out
647
719
CoInitialize(NULL);
649
if (mDLScanner->mHaveAttachmentExecute ? DoScanAES() : DoScanOAV()) {
721
if (mDLScanner->mUseAttachmentExecute ? DoScanAES() : DoScanOAV()) {
650
722
// We need to do a few more things on the main thread
651
723
NS_DispatchToMainThread(this);
703
775
nsDownloadScanner::ScanDownload(nsDownload *download)
777
if (!mUseAttachmentExecute && !mOAVExists)
706
778
return NS_ERROR_NOT_AVAILABLE;
708
780
// No ref ptr, see comment below