~ubuntu-branches/ubuntu/utopic/xulrunner-1.9/utopic

« back to all changes in this revision

Viewing changes to mozilla/toolkit/components/downloads/src/nsDownloadScanner.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alexander Sack, Alexander Sack, Fabien Tassin
  • Date: 2009-02-05 09:12:37 UTC
  • mfrom: (1.1.16 upstream)
  • Revision ID: james.westby@ubuntu.com-20090205091237-2uu65i47p00yi2xk
Tags: 1.9.0.6+nobinonly-0ubuntu1
[ Alexander Sack <asac@ubuntu.com> ]
* new security/stability update v1.9.0.6 (FIREFOX_3_0_6_RELEASE)
  - see USN-717-1
* adjust patches to changed code base
  - update debian/patches/dom_inspector_support_for_prism.patch

[ Fabien Tassin <fta@ubuntu.com> ]
* Fix preinst script to better handle the /etc/gre.d clean-up
  - update debian/xulrunner-1.9.preinst.in
* Fix permissions in the -dev package (LP: #303940)
  - update debian/rules

Show diffs side-by-side

added added

removed removed

Lines of Context:
47
47
#include "nsNetUtil.h"
48
48
#include "nsDeque.h"
49
49
#include "nsIFileURL.h"
 
50
#include "nsIPrefBranch2.h"
50
51
 
51
52
/**
52
53
 * Code overview
135
136
 */
136
137
 
137
138
#define PREF_BDA_DONTCLEAN "browser.download.antivirus.dontclean"
 
139
#define PREF_BDM_SKIPWINPOLICYCHECKS "browser.download.manager.skipWinSecurityPolicyChecks"
138
140
 
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;
172
174
};
173
175
 
174
 
nsDownloadScanner::nsDownloadScanner()
175
 
  : mHaveAVScanner(PR_FALSE), mHaveAttachmentExecute(PR_FALSE)
 
176
NS_IMPL_ISUPPORTS1(
 
177
  nsDownloadScanner
 
178
  , nsIObserver
 
179
  )
 
180
 
 
181
nsDownloadScanner::nsDownloadScanner() :
 
182
  mOAVExists(PR_FALSE)
 
183
  , mAESExists(PR_FALSE)
 
184
  , mUseAttachmentExecute(PR_FALSE)
176
185
{
177
186
}
178
187
 
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;
 
204
 
 
205
  // Check for the existence of IAE
 
206
  mAESExists = IsAESAvailable();
 
207
 
 
208
  // Init OAV scanner list
 
209
  mOAVExists = EnumerateOAVProviders();
 
210
  
197
211
  CoUninitialize();
198
 
  if (NS_SUCCEEDED(rv)) {
199
 
    mWatchdog = new nsDownloadScannerWatchdog();
200
 
    if (mWatchdog) {
201
 
      rv = mWatchdog->Init();
202
 
      if (FAILED(rv))
203
 
        mWatchdog = nsnull;
204
 
    } else {
205
 
      rv = NS_ERROR_OUT_OF_MEMORY;
206
 
    }
 
212
 
 
213
  if (!mAESExists && !mOAVExists)
 
214
    return NS_ERROR_NOT_AVAILABLE;
 
215
 
 
216
  if (mAESExists)
 
217
    mUseAttachmentExecute = PR_TRUE;
 
218
  
 
219
  // Initialize scanning
 
220
  mWatchdog = new nsDownloadScannerWatchdog();
 
221
  if (mWatchdog) {
 
222
    rv = mWatchdog->Init();
 
223
    if (FAILED(rv))
 
224
      mWatchdog = nsnull;
 
225
  } else {
 
226
    rv = NS_ERROR_OUT_OF_MEMORY;
207
227
  }
 
228
  
 
229
  if (NS_FAILED(rv))
 
230
    return rv;
 
231
 
 
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
 
235
  // content.
 
236
  PRBool skipPolicy = PR_FALSE;
 
237
  nsCOMPtr<nsIPrefBranch> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID));
 
238
  if (prefs)
 
239
    (void)prefs->GetBoolPref(PREF_BDM_SKIPWINPOLICYCHECKS, &skipPolicy);
 
240
  if (skipPolicy)
 
241
    mUseAttachmentExecute = PR_FALSE;
 
242
  
 
243
  // Setup a pref change even for the policy check pref.
 
244
  nsCOMPtr<nsIPrefBranch2> prefBranch =
 
245
    do_GetService(NS_PREFSERVICE_CONTRACTID);
 
246
 
 
247
  if (prefBranch)
 
248
    (void)prefBranch->AddObserver(PREF_BDM_SKIPWINPOLICYCHECKS, this, PR_FALSE);
 
249
 
 
250
  nsCOMPtr<nsIObserverService> observerService =
 
251
    do_GetService(NS_OBSERVERSERVICE_CONTRACTID);
 
252
  
 
253
  if (observerService)
 
254
    (void)observerService->AddObserver(this, "quit-application", PR_FALSE);
208
255
 
209
256
  return rv;
210
257
}
212
259
PRBool
213
260
nsDownloadScanner::IsAESAvailable()
214
261
{
 
262
  // Try to instantiate IAE to see if it's available.    
215
263
  nsRefPtr<IAttachmentExecute> ae;
216
264
  HRESULT hr;
217
265
  hr = CoCreateInstance(CLSID_AttachmentServices, NULL, CLSCTX_INPROC,
220
268
    NS_WARNING("Could not instantiate attachment execution service\n");
221
269
    return PR_FALSE;
222
270
  }
223
 
 
224
 
  mHaveAVScanner = PR_TRUE;
225
 
  mHaveAttachmentExecute = PR_TRUE;
226
271
  return PR_TRUE;
227
272
}
228
273
 
229
 
PRInt32
230
 
nsDownloadScanner::ListCLSID()
 
274
PRBool
 
275
nsDownloadScanner::EnumerateOAVProviders()
231
276
{
232
277
  nsRefPtr<ICatInformation> catInfo;
233
278
  HRESULT hr;
235
280
                        IID_ICatInformation, getter_AddRefs(catInfo));
236
281
  if (FAILED(hr)) {
237
282
    NS_WARNING("Could not create category information class\n");
238
 
    return -1;
 
283
    return PR_FALSE;
239
284
  }
240
285
  nsRefPtr<IEnumCLSID> clsidEnumerator;
241
286
  GUID guids [1] = { CATID_MSOfficeAntiVirus };
243
288
      getter_AddRefs(clsidEnumerator));
244
289
  if (FAILED(hr)) {
245
290
    NS_WARNING("Could not get class enumerator for category\n");
246
 
    return -2;
 
291
    return PR_FALSE;
247
292
  }
248
293
 
249
294
  ULONG nReceived;
253
298
 
254
299
  if (mScanCLSID.Length() == 0) {
255
300
    // No installed Anti Virus program
256
 
    return -3;
257
 
  }
258
 
 
259
 
  mHaveAVScanner = PR_TRUE;
260
 
  return 0;
 
301
    return PR_FALSE;
 
302
  }
 
303
 
 
304
  return PR_TRUE;
 
305
}
 
306
 
 
307
// XPCOM pref change observer - reset our default scanner settings.
 
308
NS_IMETHODIMP
 
309
nsDownloadScanner::Observe(nsISupports *aSubject, const char *aTopic, const PRUnichar *someData)
 
310
{
 
311
  nsCOMPtr<nsIPrefBranch2> prefBranch =
 
312
    do_GetService(NS_PREFSERVICE_CONTRACTID);
 
313
 
 
314
  if (aTopic && !strcmp(aTopic, "quit-application")) {
 
315
    if (prefBranch)
 
316
      (void)prefBranch->RemoveObserver(PREF_BDM_SKIPWINPOLICYCHECKS, this);
 
317
 
 
318
    nsCOMPtr<nsIObserverService> observerService =
 
319
      do_GetService(NS_OBSERVERSERVICE_CONTRACTID);
 
320
    
 
321
    if (observerService)
 
322
      (void)observerService->RemoveObserver(this, "quit-application");
 
323
    return S_OK;
 
324
  }
 
325
  
 
326
  PRBool skipPolicyCheck = PR_FALSE;
 
327
  if (prefBranch)
 
328
    (void)prefBranch->GetBoolPref(PREF_BDM_SKIPWINPOLICYCHECKS, &skipPolicyCheck);
 
329
 
 
330
  mUseAttachmentExecute = !skipPolicyCheck && mAESExists;
 
331
  
 
332
  return NS_OK;
261
333
}
262
334
 
263
335
// If IAttachementExecute is available, use the CheckPolicy call to find out
267
339
{
268
340
  nsresult rv;
269
341
 
270
 
  if (!aSource || !aTarget || !mHaveAttachmentExecute)
 
342
  if (!aSource || !aTarget || !mUseAttachmentExecute)
271
343
    return AVPOLICY_DOWNLOAD;
272
344
 
273
345
  nsCAutoString source;
646
718
{
647
719
  CoInitialize(NULL);
648
720
 
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);
652
724
  } else {
702
774
nsresult
703
775
nsDownloadScanner::ScanDownload(nsDownload *download)
704
776
{
705
 
  if (!mHaveAVScanner)
 
777
  if (!mUseAttachmentExecute && !mOAVExists)
706
778
    return NS_ERROR_NOT_AVAILABLE;
707
779
 
708
780
  // No ref ptr, see comment below