OLD | NEW |
| (Empty) |
1 // Copyright (c) 2009 The Chromium OS 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 // Example client which exercises the DBus Cryptohome interfaces. | |
6 #include <iostream> | |
7 | |
8 #include <base/basictypes.h> | |
9 #include <base/command_line.h> | |
10 #include <base/logging.h> | |
11 #include <base/string_util.h> | |
12 #include <chromeos/dbus/dbus.h> | |
13 #include <chromeos/dbus/service_constants.h> | |
14 | |
15 #include "cryptohome/bindings/client.h" | |
16 | |
17 namespace switches { | |
18 static const char kActionSwitch[] = "action"; | |
19 static const char *kActions[] = { "mount", "unmount", "is_mounted", NULL }; | |
20 enum ActionEnum { ACTION_MOUNT, ACTION_UNMOUNT, ACTION_MOUNTED }; | |
21 } // namespace switches | |
22 | |
23 int main(int argc, char **argv) { | |
24 CommandLine::Init(argc, argv); | |
25 logging::InitLogging(NULL, | |
26 logging::LOG_ONLY_TO_SYSTEM_DEBUG_LOG, | |
27 logging::DONT_LOCK_LOG_FILE, | |
28 logging::APPEND_TO_OLD_LOG_FILE); | |
29 | |
30 CommandLine *cl = CommandLine::ForCurrentProcess(); | |
31 std::string action = cl->GetSwitchValueASCII(switches::kActionSwitch); | |
32 g_type_init(); | |
33 chromeos::dbus::BusConnection bus = chromeos::dbus::GetSystemBusConnection(); | |
34 chromeos::dbus::Proxy proxy(bus, | |
35 cryptohome::kCryptohomeServiceName, | |
36 cryptohome::kCryptohomeServicePath, | |
37 cryptohome::kCryptohomeInterface); | |
38 DCHECK(proxy.gproxy()) << "Failed to acquire proxy"; | |
39 | |
40 if (!strcmp(switches::kActions[switches::ACTION_MOUNT], action.c_str())) { | |
41 gboolean done = false; | |
42 static const gchar *kUser = "chromeos-user"; | |
43 static const gchar *kKey = "274146c6e8886a843ddfea373e2dc71b"; | |
44 chromeos::glib::ScopedError error; | |
45 GError **errptr = &chromeos::Resetter(&error).lvalue(); | |
46 if (!org_chromium_CryptohomeInterface_mount(proxy.gproxy(), | |
47 kUser, | |
48 kKey, | |
49 &done, | |
50 errptr)) { | |
51 LOG(FATAL) << "Mount call failed: " << error->message; | |
52 } | |
53 LOG_IF(ERROR, !done) << "Mount did not complete?"; | |
54 LOG_IF(INFO, done) << "Call completed"; | |
55 } else if (!strcmp(switches::kActions[switches::ACTION_UNMOUNT], | |
56 action.c_str())) { | |
57 chromeos::glib::ScopedError error; | |
58 GError **errptr = &chromeos::Resetter(&error).lvalue(); | |
59 gboolean done = false; | |
60 if (!org_chromium_CryptohomeInterface_unmount(proxy.gproxy(), | |
61 &done, | |
62 errptr)) { | |
63 LOG(FATAL) << "Unmount call failed: " << error->message; | |
64 } | |
65 LOG_IF(ERROR, !done) << "Unmount did not complete?"; | |
66 LOG_IF(INFO, done) << "Call completed"; | |
67 } else if (!strcmp(switches::kActions[switches::ACTION_MOUNTED], | |
68 action.c_str())) { | |
69 chromeos::glib::ScopedError error; | |
70 GError **errptr = &chromeos::Resetter(&error).lvalue(); | |
71 gboolean done = false; | |
72 if (!org_chromium_CryptohomeInterface_is_mounted(proxy.gproxy(), | |
73 &done, | |
74 errptr)) { | |
75 LOG(FATAL) << "IsMounted call failed: " << error->message; | |
76 } | |
77 std::cout << done << std::endl; | |
78 | |
79 } else { | |
80 LOG(FATAL) << "Unknown action or no action given (mount,unmount)"; | |
81 } | |
82 return 0; | |
83 } | |
OLD | NEW |