File: enterprise_companion_status.cc

package info (click to toggle)
chromium 138.0.7204.157-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 6,071,864 kB
  • sloc: cpp: 34,936,859; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,967; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (162 lines) | stat: -rw-r--r-- 6,880 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/enterprise_companion/enterprise_companion_status.h"

#include <string>
#include <variant>

#include "base/functional/overloaded.h"
#include "build/build_config.h"
#include "components/policy/core/common/cloud/cloud_policy_constants.h"
#include "components/policy/core/common/cloud/cloud_policy_validator.h"

#if BUILDFLAG(IS_POSIX)
#include "base/posix/safe_strerror.h"
#else
#include "base/strings/strcat.h"
#include "base/strings/string_number_conversions.h"
#endif

namespace enterprise_companion {

namespace {

constexpr std::string DeviceManagementStatusToString(
    policy::DeviceManagementStatus status) {
  switch (status) {
    case policy::DM_STATUS_SUCCESS:
      return "Success";
    case policy::DM_STATUS_REQUEST_INVALID:
      return "Request payload invalid";
    case policy::DM_STATUS_REQUEST_FAILED:
      return "HTTP request failed";
    case policy::DM_STATUS_TEMPORARY_UNAVAILABLE:
      return "Server temporarily unavailable";
    case policy::DM_STATUS_HTTP_STATUS_ERROR:
      return "HTTP request returned a non-success code";
    case policy::DM_STATUS_RESPONSE_DECODING_ERROR:
      return "Response could not be decoded";
    case policy::DM_STATUS_SERVICE_MANAGEMENT_NOT_SUPPORTED:
      return "Management not supported";
    case policy::DM_STATUS_SERVICE_DEVICE_NOT_FOUND:
      return "Device not found";
    case policy::DM_STATUS_SERVICE_MANAGEMENT_TOKEN_INVALID:
      return "Device token invalid";
    case policy::DM_STATUS_SERVICE_ACTIVATION_PENDING:
      return "Activation pending";
    case policy::DM_STATUS_SERVICE_INVALID_SERIAL_NUMBER:
      return "The serial number is not valid or not known to the server";
    case policy::DM_STATUS_SERVICE_DEVICE_ID_CONFLICT:
      return "The device id used for registration is already taken";
    case policy::DM_STATUS_SERVICE_MISSING_LICENSES:
      return "The licenses have expired or have been exhausted";
    case policy::DM_STATUS_SERVICE_DEPROVISIONED:
      return "The administrator has deprovisioned this client";
    case policy::DM_STATUS_SERVICE_DOMAIN_MISMATCH:
      return "Device registration for the wrong domain";
    case policy::DM_STATUS_CANNOT_SIGN_REQUEST:
      return "Request could not be signed";
    case policy::DM_STATUS_REQUEST_TOO_LARGE:
      return "Request body is too large";
    case policy::DM_STATUS_SERVICE_TOO_MANY_REQUESTS:
      return "Too many requests";
    case policy::DM_STATUS_SERVICE_DEVICE_NEEDS_RESET:
      return "The device needs to be reset";
    case policy::DM_STATUS_SERVICE_POLICY_NOT_FOUND:
      return "Policy not found";
    case policy::DM_STATUS_SERVICE_ARC_DISABLED:
      return "ARC is not enabled on this domain";
    case policy::DM_STATUS_SERVICE_CONSUMER_ACCOUNT_WITH_PACKAGED_LICENSE:
      return "Non-dasher account with packaged license can't enroll";
    case policy::DM_STATUS_SERVICE_ENTERPRISE_ACCOUNT_IS_NOT_ELIGIBLE_TO_ENROLL:
      return "Not eligible enterprise account can't enroll";
    case policy::DM_STATUS_SERVICE_ENTERPRISE_TOS_HAS_NOT_BEEN_ACCEPTED:
      return "Enterprise TOS has not been accepted";
    case policy::DM_STATUS_SERVICE_ILLEGAL_ACCOUNT_FOR_PACKAGED_EDU_LICENSE:
      return "Illegal account for packaged EDU license";
    case policy::DM_STATUS_SERVICE_INVALID_PACKAGED_DEVICE_FOR_KIOSK:
      return "Packaged license device can't enroll KIOSK";
    case policy::DM_STATUS_SERVICE_ORG_UNIT_ENROLLMENT_LIMIT_EXCEEEDED:
      return "Organization unit initial enrollment limit has been exceeded";
  }
}

constexpr std::string ApplicationErrorToString(ApplicationError error) {
  switch (error) {
    case ApplicationError::kRegistrationPreconditionFailed:
      return "An action failed due to the client not being registered.";
    case ApplicationError::kPolicyPersistenceImpossible:
      return "Policies can not be persisted to storage.";
    case ApplicationError::kPolicyPersistenceFailed:
      return "Failed to persist policies to storage.";
    case ApplicationError::kCannotAcquireLock:
      return "Failed to acquire global singleton lock.";
    case ApplicationError::kMojoConnectionFailed:
      return "A Mojo IPC connection could not be established.";
    case ApplicationError::kInstallationFailed:
      return "The application could not be installed/uninstalled.";
    case ApplicationError::kIpcCallerNotAllowed:
      return "The IPC caller is not allowed.";
    case ApplicationError::kCOMInitializationFailed:
      return "COM initialization failed.";
    case ApplicationError::kCloudPolicyClientTimeout:
      return "Cloud Policy Client timed out";
    case ApplicationError::kInvalidEnrollmentToken:
      return "The enrollment token is invalid";
  }
}

std::string PosixErrnoToString(EnterpriseCompanionStatus::PosixErrno error) {
#if BUILDFLAG(IS_POSIX)
  return base::safe_strerror(error);
#else
  return base::StrCat({"Posix error code ", base::NumberToString(error), "."});
#endif
}

}  // namespace

PersistedError::PersistedError(int space,
                               int code,
                               const std::string& description)
    : space(space), code(code), description(description) {}
PersistedError::PersistedError(const PersistedError&) = default;
PersistedError::PersistedError(PersistedError&&) = default;
PersistedError::~PersistedError() = default;
PersistedError& PersistedError::operator=(const PersistedError&) = default;
PersistedError& PersistedError::operator=(PersistedError&&) = default;

std::string EnterpriseCompanionStatus::description() const {
  return std::visit(
      base::Overloaded{
          [](std::monostate) { return std::string("Success"); },
          [](const PersistedError& error) { return error.description; },
          [](policy::DeviceManagementStatus status) {
            return DeviceManagementStatusToString(status);
          },
          [](policy::CloudPolicyValidatorBase::Status status) {
            return std::string(
                policy::CloudPolicyValidatorBase::StatusToString(status));
          },
          [](ApplicationError error) {
            return ApplicationErrorToString(error);
          },
          [](PosixErrno error) { return PosixErrnoToString(error); },
      },
      status_variant_);
}

EnterpriseCompanionStatus::EnterpriseCompanionStatus(
    const EnterpriseCompanionStatus&) = default;
EnterpriseCompanionStatus::~EnterpriseCompanionStatus() = default;

EnterpriseCompanionStatus::EnterpriseCompanionStatus(ApplicationError error)
    : EnterpriseCompanionStatus(StatusVariant(error)) {}

EnterpriseCompanionStatus::EnterpriseCompanionStatus(
    StatusVariant status_variant)
    : status_variant_(std::move(status_variant)) {}

}  // namespace enterprise_companion