Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(210)

Side by Side Diff: sandbox/linux/services/credentials.cc

Issue 51113009: Linux: add a Credentials class to handle Linux capabilities. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2013 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 "sandbox/linux/services/credentials.h"
6
7 #include <stdio.h>
8 #include <sys/capability.h>
9
10 #include "base/basictypes.h"
11 #include "base/logging.h"
12
13 namespace {
14
15 struct CapFreeDeleter {
16 inline void operator()(cap_t cap) const {
17 int ret = cap_free(cap);
18 CHECK_EQ(0, ret);
19 }
20 };
21
22 // Wrapper to manage libcap2's cap_t type.
23 typedef scoped_ptr<typeof(*((cap_t)0)), CapFreeDeleter> ScopedCap;
24
25 struct CapTextFreeDeleter {
26 inline void operator()(char* cap_text) const {
27 int ret = cap_free(cap_text);
28 CHECK_EQ(0, ret);
29 }
30 };
31
32 // Wrapper to manage the result from libcap2's cap_from_text().
33 typedef scoped_ptr<char, CapTextFreeDeleter> ScopedCapText;
34
35 } // namespace.
36
37 namespace sandbox {
38
39 Credentials::Credentials() {
40 }
41
42 Credentials::~Credentials() {
43 }
44
45 void Credentials::DropAllCapabilities() {
46 ScopedCap cap(cap_init());
47 PCHECK(0 == cap_set_proc(cap.get()));
48 }
49
50 bool Credentials::HasAnyCapability() {
51 ScopedCap current_cap(cap_get_proc());
52 ScopedCap empty_cap(cap_init());
53 return cap_compare(current_cap.get(), empty_cap.get()) != 0;
54 }
55
56 scoped_ptr<std::string> Credentials::GetCurrentCapString() {
57 ScopedCap current_cap(cap_get_proc());
58 ScopedCapText cap_text(cap_to_text(current_cap.get(), NULL));
59 return scoped_ptr<std::string> (new std::string(cap_text.get()));
60 }
61
62 } // namespace sandbox.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698