1// Copyright (c) 2010 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "chrome/installer/util/compat_checks.h"
6
7#include "base/strings/string_number_conversions.h"
8#include "base/strings/string_split.h"
9#include "base/strings/string_util.h"
10#include "base/win/registry.h"
11
12namespace {
13
14// SEP stands for Symantec End Point Protection.
15std::wstring GetSEPVersion() {
16  const wchar_t kProductKey[] =
17      L"SOFTWARE\\Symantec\\Symantec Endpoint Protection\\SMC";
18  // Versions before 11MR3 were always 32-bit, so check in the 32-bit hive.
19  base::win::RegKey key(
20      HKEY_LOCAL_MACHINE, kProductKey, KEY_READ | KEY_WOW64_32KEY);
21  std::wstring version_str;
22  key.ReadValue(L"ProductVersion", &version_str);
23  return version_str;
24}
25
26// The product version should be a string like "11.0.3001.2224". This function
27// returns as params the first 3 values. Return value is false if anything
28// does not fit the format.
29bool ParseSEPVersion(const std::wstring& version, int* v0, int* v1, int* v2) {
30  std::vector<std::wstring> v;
31  base::SplitString(version, L'.', &v);
32  if (v.size() != 4)
33    return false;
34  if (!base::StringToInt(v[0], v0))
35    return false;
36  if (!base::StringToInt(v[1], v1))
37    return false;
38  if (!base::StringToInt(v[2], v2))
39    return false;
40  return true;
41}
42
43// The incompatible versions are anything before 11MR3, which is 11.0.3001.
44bool IsBadSEPVersion(int v0, int v1, int v2) {
45  if (v0 < 11)
46    return true;
47  if (v1 > 0)
48    return false;
49  if (v2 < 3001)
50    return true;
51  return false;
52}
53
54}  // namespace
55
56bool HasIncompatibleSymantecEndpointVersion(const wchar_t* version) {
57  int v0, v1, v2;
58  std::wstring ver_str(version ? version : GetSEPVersion());
59  if (!ParseSEPVersion(ver_str, &v0, &v1, &v2))
60    return false;
61  return IsBadSEPVersion(v0, v1, v2);
62}
63