forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
seatbelt.cc
70 lines (58 loc) · 2.4 KB
/
seatbelt.cc
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
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "sandbox/mac/seatbelt.h"
#include <unistd.h>
extern "C" {
#include <sandbox.h>
int sandbox_init_with_parameters(const char* profile,
uint64_t flags,
const char* const parameters[],
char** errorbuf);
// Not deprecated. The canonical usage to test if sandboxed is
// sandbox_check(getpid(), NULL, SANDBOX_FILTER_NONE), which returns
// 1 if sandboxed. Note `type` is actually a sandbox_filter_type enum value, but
// it is unused currently.
int sandbox_check(pid_t pid, const char* operation, int type, ...);
}
namespace sandbox {
// Initialize the static member variables.
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
const char* Seatbelt::kProfileNoInternet = kSBXProfileNoInternet;
const char* Seatbelt::kProfileNoNetwork = kSBXProfileNoNetwork;
const char* Seatbelt::kProfileNoWrite = kSBXProfileNoWrite;
const char* Seatbelt::kProfileNoWriteExceptTemporary =
kSBXProfileNoWriteExceptTemporary;
const char* Seatbelt::kProfilePureComputation = kSBXProfilePureComputation;
#pragma clang diagnostic pop
// static
int Seatbelt::Init(const char* profile, uint64_t flags, char** errorbuf) {
// OS X deprecated these functions, but did not provide a suitable replacement,
// so ignore the deprecation warning.
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
return ::sandbox_init(profile, flags, errorbuf);
#pragma clang diagnostic pop
}
// static
int Seatbelt::InitWithParams(const char* profile,
uint64_t flags,
const char* const parameters[],
char** errorbuf) {
return ::sandbox_init_with_parameters(profile, flags, parameters, errorbuf);
}
// static
void Seatbelt::FreeError(char* errorbuf) {
// OS X deprecated these functions, but did not provide a suitable replacement,
// so ignore the deprecation warning.
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
return ::sandbox_free_error(errorbuf);
#pragma clang diagnostic pop
}
// static
bool Seatbelt::IsSandboxed() {
return ::sandbox_check(getpid(), NULL, 0);
}
} // namespace sandbox