Android-cuttlefish cvd tool
privilege.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2025 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16#ifndef CUTTLEFISH_HOST_COMMANDS_CVDALLOC_PRIVILEGE_H_
17#define CUTTLEFISH_HOST_COMMANDS_CVDALLOC_PRIVILEGE_H_
18
19#include <unistd.h>
20
21#include <optional>
22#include <vector>
23
24#include "absl/strings/string_view.h"
25
27
28namespace cuttlefish {
29
30Result<void> ValidateCvdallocBinary(absl::string_view path);
31
33 public:
35
36 ScopedPrivileges(ScopedPrivileges&& other) noexcept;
41
42 private:
43 explicit ScopedPrivileges(uid_t orig);
44
45 std::optional<uid_t> orig_;
46 // A copy of the environ array from before Elevate() replaced it, if it did.
47 std::optional<std::vector<char*>> saved_env_;
48};
49
50} // namespace cuttlefish
51
52#endif // CUTTLEFISH_HOST_COMMANDS_CVDALLOC_PRIVILEGE_H_
Definition: privilege.h:32
std::optional< uid_t > orig_
Definition: privilege.h:45
ScopedPrivileges(ScopedPrivileges &&other) noexcept
Definition: privilege.cpp:227
ScopedPrivileges(const ScopedPrivileges &)=delete
std::optional< std::vector< char * > > saved_env_
Definition: privilege.h:47
~ScopedPrivileges()
Definition: privilege.cpp:231
ScopedPrivileges & operator=(const ScopedPrivileges &)=delete
ScopedPrivileges & operator=(ScopedPrivileges &&other)=delete
static Result< ScopedPrivileges > Elevate()
Definition: privilege.cpp:199
Definition: alloc_driver.h:21
Result< void > ValidateCvdallocBinary(absl::string_view path)
Definition: privilege.cpp:99
tl::expected< T, StackTraceError< E > > Result
Definition: result_type.h:30