Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / sandbox / linux / services / namespace_utils.h
blobf3c88a94522622417218261bcdf2ee61bc5f8ac3
1 // Copyright 2015 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.
5 #ifndef SANDBOX_LINUX_SERVICES_NAMESPACE_UTILS_H_
6 #define SANDBOX_LINUX_SERVICES_NAMESPACE_UTILS_H_
8 #include <sys/types.h>
10 #include "base/compiler_specific.h"
11 #include "base/macros.h"
12 #include "base/template_util.h"
13 #include "sandbox/sandbox_export.h"
15 namespace sandbox {
17 // Utility functions for using Linux namepaces.
18 class SANDBOX_EXPORT NamespaceUtils {
19 public:
20 COMPILE_ASSERT((base::is_same<uid_t, gid_t>::value), UidAndGidAreSameType);
21 // generic_id_t can be used for either uid_t or gid_t.
22 typedef uid_t generic_id_t;
24 // Write a uid or gid mapping from |id| to |id| in |map_file|. This function
25 // is async-signal-safe.
26 static bool WriteToIdMapFile(const char* map_file,
27 generic_id_t id) WARN_UNUSED_RESULT;
29 // Returns true if unprivileged namespaces of type |type| is supported
30 // (meaning that both CLONE_NEWUSER and type are are supported). |type| must
31 // be one of CLONE_NEWIPC, CLONE_NEWNET, CLONE_NEWNS, CLONE_NEWPID,
32 // CLONE_NEWUSER, or CLONE_NEWUTS. This relies on access to /proc, so it will
33 // not work from within a sandbox.
34 static bool KernelSupportsUnprivilegedNamespace(int type);
36 // Returns true if the kernel supports denying setgroups in a user namespace.
37 // On kernels where this is supported, DenySetgroups must be called before a
38 // gid mapping can be added.
39 static bool KernelSupportsDenySetgroups();
41 // Disables setgroups() within the current user namespace. On Linux 3.18.2 and
42 // later, this is required in order to write to /proc/self/gid_map without
43 // having CAP_SETGID. Callers can determine whether is this needed with
44 // KernelSupportsDenySetgroups. This function is async-signal-safe.
45 static bool DenySetgroups() WARN_UNUSED_RESULT;
47 private:
48 DISALLOW_IMPLICIT_CONSTRUCTORS(NamespaceUtils);
51 } // namespace sandbox
53 #endif // SANDBOX_LINUX_SERVICES_NAMESPACE_UTILS_H_