| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chromeos_login.h" // NOLINT | 5 #include "chromeos_login.h" // NOLINT |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include <base/basictypes.h> | 9 #include <base/basictypes.h> |
| 10 #include <base/string_util.h> | 10 #include <base/string_util.h> |
| 11 #include <dbus/dbus-glib-lowlevel.h> | 11 #include <dbus/dbus-glib-lowlevel.h> |
| 12 #include <chromeos/dbus/dbus.h> | 12 #include <chromeos/dbus/dbus.h> |
| 13 #include <chromeos/dbus/service_constants.h> | 13 #include <chromeos/dbus/service_constants.h> |
| 14 #include <chromeos/glib/object.h> | 14 #include <chromeos/glib/object.h> |
| 15 | 15 |
| 16 #include "marshal.glibmarshal.h" // NOLINT | 16 #include "marshal.glibmarshal.h" // NOLINT |
| 17 | 17 |
| 18 namespace chromeos { // NOLINT | 18 namespace chromeos { // NOLINT |
| 19 | 19 |
| 20 |
| 21 #define SCOPED_SAFE_MESSAGE(e) (e->message ? e->message : "unknown error") |
| 22 |
| 20 namespace { | 23 namespace { |
| 21 chromeos::dbus::Proxy CreateProxy() { | 24 chromeos::dbus::Proxy CreateProxy() { |
| 22 dbus::BusConnection bus = dbus::GetSystemBusConnection(); | 25 dbus::BusConnection bus = dbus::GetSystemBusConnection(); |
| 23 return chromeos::dbus::Proxy(bus, | 26 return chromeos::dbus::Proxy(bus, |
| 24 login_manager::kSessionManagerServiceName, | 27 login_manager::kSessionManagerServiceName, |
| 25 login_manager::kSessionManagerServicePath, | 28 login_manager::kSessionManagerServicePath, |
| 26 login_manager::kSessionManagerInterface); | 29 login_manager::kSessionManagerInterface); |
| 27 } | 30 } |
| 28 } // Anonymous namespace. | 31 } // Anonymous namespace. |
| 29 | 32 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 41 } | 44 } |
| 42 | 45 |
| 43 private: | 46 private: |
| 44 SessionMonitor monitor_; | 47 SessionMonitor monitor_; |
| 45 void* object_; | 48 void* object_; |
| 46 | 49 |
| 47 DISALLOW_COPY_AND_ASSIGN(OpaqueSessionConnection); | 50 DISALLOW_COPY_AND_ASSIGN(OpaqueSessionConnection); |
| 48 }; | 51 }; |
| 49 | 52 |
| 50 extern "C" | 53 extern "C" |
| 54 bool ChromeOSCheckWhitelist(const char* email, |
| 55 std::vector<uint8>* signature) { |
| 56 DCHECK(signature); |
| 57 chromeos::dbus::Proxy proxy = CreateProxy(); |
| 58 chromeos::glib::ScopedError error; |
| 59 |
| 60 GArray* sig; |
| 61 |
| 62 if (!::dbus_g_proxy_call(proxy.gproxy(), |
| 63 login_manager::kSessionManagerCheckWhitelist, |
| 64 &Resetter(&error).lvalue(), |
| 65 G_TYPE_STRING, email, |
| 66 G_TYPE_INVALID, |
| 67 DBUS_TYPE_G_UCHAR_ARRAY, &sig, |
| 68 G_TYPE_INVALID)) { |
| 69 LOG(WARNING) << login_manager::kSessionManagerCheckWhitelist << " failed: " |
| 70 << SCOPED_SAFE_MESSAGE(error); |
| 71 return false; |
| 72 } |
| 73 bool rv = false; |
| 74 signature->resize(sig->len); |
| 75 if (signature->size() == sig->len) { |
| 76 memcpy(&(signature->at(0)), static_cast<const void*>(sig->data), sig->len); |
| 77 rv = true; |
| 78 } |
| 79 g_array_free(sig, false); |
| 80 return rv; |
| 81 } |
| 82 |
| 83 extern "C" |
| 51 bool ChromeOSEmitLoginPromptReady() { | 84 bool ChromeOSEmitLoginPromptReady() { |
| 52 chromeos::dbus::Proxy proxy = CreateProxy(); | 85 chromeos::dbus::Proxy proxy = CreateProxy(); |
| 53 gboolean done = false; | 86 gboolean done = false; |
| 54 chromeos::glib::ScopedError error; | 87 chromeos::glib::ScopedError error; |
| 55 | 88 |
| 56 if (!::dbus_g_proxy_call(proxy.gproxy(), | 89 if (!::dbus_g_proxy_call(proxy.gproxy(), |
| 57 login_manager::kSessionManagerEmitLoginPromptReady, | 90 login_manager::kSessionManagerEmitLoginPromptReady, |
| 58 &Resetter(&error).lvalue(), | 91 &Resetter(&error).lvalue(), |
| 59 G_TYPE_INVALID, | 92 G_TYPE_INVALID, |
| 60 G_TYPE_BOOLEAN, | 93 G_TYPE_BOOLEAN, &done, |
| 61 &done, | |
| 62 G_TYPE_INVALID)) { | 94 G_TYPE_INVALID)) { |
| 63 | 95 |
| 64 LOG(WARNING) << login_manager::kSessionManagerEmitLoginPromptReady | 96 LOG(WARNING) << login_manager::kSessionManagerEmitLoginPromptReady |
| 65 << " failed: " | 97 << " failed: " << SCOPED_SAFE_MESSAGE(error); |
| 66 << (error->message ? error->message : "Unknown Error."); | |
| 67 | 98 |
| 68 } | 99 } |
| 69 return done; | 100 return done; |
| 70 } | 101 } |
| 71 | 102 |
| 72 extern "C" | 103 extern "C" |
| 104 bool ChromeOSCheckRetrieveProperty(const char* name, |
| 105 std::string* out_value, |
| 106 std::vector<uint8>* signature) { |
| 107 DCHECK(signature); |
| 108 chromeos::dbus::Proxy proxy = CreateProxy(); |
| 109 chromeos::glib::ScopedError error; |
| 110 |
| 111 GArray* sig; |
| 112 gchar* value; |
| 113 |
| 114 if (!::dbus_g_proxy_call(proxy.gproxy(), |
| 115 login_manager::kSessionManagerCheckWhitelist, |
| 116 &Resetter(&error).lvalue(), |
| 117 G_TYPE_STRING, name, |
| 118 G_TYPE_INVALID, |
| 119 G_TYPE_STRING, value, |
| 120 DBUS_TYPE_G_UCHAR_ARRAY, &sig, |
| 121 G_TYPE_INVALID)) { |
| 122 LOG(WARNING) << login_manager::kSessionManagerCheckWhitelist << " failed: " |
| 123 << SCOPED_SAFE_MESSAGE(error); |
| 124 return false; |
| 125 } |
| 126 bool rv = false; |
| 127 signature->resize(sig->len); |
| 128 if (signature->size() == sig->len) { |
| 129 memcpy(&(signature->at(0)), static_cast<const void*>(sig->data), sig->len); |
| 130 rv = true; |
| 131 } |
| 132 g_array_free(sig, false); |
| 133 out_value->assign(value); |
| 134 return rv; |
| 135 } |
| 136 |
| 137 extern "C" |
| 73 bool ChromeOSSetOwnerKey(const std::vector<uint8>& public_key_der) { | 138 bool ChromeOSSetOwnerKey(const std::vector<uint8>& public_key_der) { |
| 74 chromeos::dbus::Proxy proxy = CreateProxy(); | 139 chromeos::dbus::Proxy proxy = CreateProxy(); |
| 75 chromeos::glib::ScopedError error; | 140 chromeos::glib::ScopedError error; |
| 76 | 141 |
| 77 GArray* key_der = g_array_sized_new(FALSE, FALSE, 1, public_key_der.size()); | 142 GArray* key_der = g_array_sized_new(FALSE, FALSE, 1, public_key_der.size()); |
| 78 g_array_append_vals(key_der, &public_key_der[0], public_key_der.size()); | 143 g_array_append_vals(key_der, &public_key_der[0], public_key_der.size()); |
| 79 | 144 |
| 80 bool rv = true; | 145 bool rv = true; |
| 81 if (!::dbus_g_proxy_call(proxy.gproxy(), | 146 if (!::dbus_g_proxy_call(proxy.gproxy(), |
| 82 login_manager::kSessionManagerSetOwnerKey, | 147 login_manager::kSessionManagerSetOwnerKey, |
| 83 &Resetter(&error).lvalue(), | 148 &Resetter(&error).lvalue(), |
| 84 DBUS_TYPE_G_UCHAR_ARRAY, | 149 DBUS_TYPE_G_UCHAR_ARRAY, key_der, |
| 85 key_der, | |
| 86 G_TYPE_INVALID, | 150 G_TYPE_INVALID, |
| 87 G_TYPE_INVALID)) { | 151 G_TYPE_INVALID)) { |
| 88 LOG(WARNING) << login_manager::kSessionManagerSetOwnerKey << " failed: " | 152 LOG(WARNING) << login_manager::kSessionManagerSetOwnerKey << " failed: " |
| 89 << (error->message ? error->message : "Unknown Error."); | 153 << SCOPED_SAFE_MESSAGE(error); |
| 90 rv = false; | 154 rv = false; |
| 91 } | 155 } |
| 92 g_array_free(key_der, TRUE); | 156 g_array_free(key_der, TRUE); |
| 93 return rv; | 157 return rv; |
| 94 } | 158 } |
| 95 | 159 |
| 96 extern "C" | 160 extern "C" |
| 97 bool ChromeOSStartSession(const char* user_email, | 161 bool ChromeOSStartSession(const char* user_email, |
| 98 const char* unique_id /* unused */) { | 162 const char* unique_id /* unused */) { |
| 99 chromeos::dbus::Proxy proxy = CreateProxy(); | 163 chromeos::dbus::Proxy proxy = CreateProxy(); |
| 100 gboolean done = false; | 164 gboolean done = false; |
| 101 chromeos::glib::ScopedError error; | 165 chromeos::glib::ScopedError error; |
| 102 | 166 |
| 103 if (!::dbus_g_proxy_call(proxy.gproxy(), | 167 if (!::dbus_g_proxy_call(proxy.gproxy(), |
| 104 login_manager::kSessionManagerStartSession, | 168 login_manager::kSessionManagerStartSession, |
| 105 &Resetter(&error).lvalue(), | 169 &Resetter(&error).lvalue(), |
| 106 G_TYPE_STRING, | 170 G_TYPE_STRING, user_email, |
| 107 user_email, | 171 G_TYPE_STRING, unique_id, |
| 108 G_TYPE_STRING, | |
| 109 unique_id, | |
| 110 G_TYPE_INVALID, | 172 G_TYPE_INVALID, |
| 111 G_TYPE_BOOLEAN, | 173 G_TYPE_BOOLEAN, &done, |
| 112 &done, | |
| 113 G_TYPE_INVALID)) { | 174 G_TYPE_INVALID)) { |
| 114 LOG(WARNING) << login_manager::kSessionManagerStartSession << " failed: " | 175 LOG(WARNING) << login_manager::kSessionManagerStartSession << " failed: " |
| 115 << (error->message ? error->message : "Unknown Error."); | 176 << SCOPED_SAFE_MESSAGE(error); |
| 116 } | 177 } |
| 117 return done; | 178 return done; |
| 118 } | 179 } |
| 119 | 180 |
| 120 extern "C" | 181 extern "C" |
| 121 bool ChromeOSStopSession(const char* unique_id /* unused */) { | 182 bool ChromeOSStopSession(const char* unique_id /* unused */) { |
| 122 chromeos::dbus::Proxy proxy = CreateProxy(); | 183 chromeos::dbus::Proxy proxy = CreateProxy(); |
| 123 gboolean done = false; | 184 gboolean done = false; |
| 124 chromeos::glib::ScopedError error; | 185 chromeos::glib::ScopedError error; |
| 125 | 186 |
| 126 if (!::dbus_g_proxy_call(proxy.gproxy(), | 187 if (!::dbus_g_proxy_call(proxy.gproxy(), |
| 127 login_manager::kSessionManagerStopSession, | 188 login_manager::kSessionManagerStopSession, |
| 128 &Resetter(&error).lvalue(), | 189 &Resetter(&error).lvalue(), |
| 129 G_TYPE_STRING, | 190 G_TYPE_STRING, unique_id, |
| 130 unique_id, | |
| 131 G_TYPE_INVALID, | 191 G_TYPE_INVALID, |
| 132 G_TYPE_BOOLEAN, | 192 G_TYPE_BOOLEAN, &done, |
| 133 &done, | |
| 134 G_TYPE_INVALID)) { | 193 G_TYPE_INVALID)) { |
| 135 LOG(WARNING) << login_manager::kSessionManagerStopSession << " failed: " | 194 LOG(WARNING) << login_manager::kSessionManagerStopSession << " failed: " |
| 136 << (error->message ? error->message : "Unknown Error."); | 195 << SCOPED_SAFE_MESSAGE(error); |
| 137 } | 196 } |
| 138 return done; | 197 return done; |
| 139 } | 198 } |
| 140 | 199 |
| 141 extern "C" | 200 extern "C" |
| 142 bool ChromeOSRestartJob(int pid, const char* command_line) { | 201 bool ChromeOSRestartJob(int pid, const char* command_line) { |
| 143 chromeos::dbus::Proxy proxy = CreateProxy(); | 202 chromeos::dbus::Proxy proxy = CreateProxy(); |
| 144 gboolean done = false; | 203 gboolean done = false; |
| 145 chromeos::glib::ScopedError error; | 204 chromeos::glib::ScopedError error; |
| 146 | 205 |
| 147 if (!::dbus_g_proxy_call(proxy.gproxy(), | 206 if (!::dbus_g_proxy_call(proxy.gproxy(), |
| 148 login_manager::kSessionManagerRestartJob, | 207 login_manager::kSessionManagerRestartJob, |
| 149 &Resetter(&error).lvalue(), | 208 &Resetter(&error).lvalue(), |
| 150 G_TYPE_INT, | 209 G_TYPE_INT, pid, |
| 151 pid, | 210 G_TYPE_STRING, command_line, |
| 152 G_TYPE_STRING, | |
| 153 command_line, | |
| 154 G_TYPE_INVALID, | 211 G_TYPE_INVALID, |
| 155 G_TYPE_BOOLEAN, | 212 G_TYPE_BOOLEAN, &done, |
| 156 &done, | |
| 157 G_TYPE_INVALID)) { | 213 G_TYPE_INVALID)) { |
| 158 LOG(WARNING) << login_manager::kSessionManagerRestartJob << " failed: " | 214 LOG(WARNING) << login_manager::kSessionManagerRestartJob << " failed: " |
| 159 << (error->message ? error->message : "Unknown Error."); | 215 << SCOPED_SAFE_MESSAGE(error); |
| 160 } | 216 } |
| 161 return done; | 217 return done; |
| 162 } | 218 } |
| 163 | 219 |
| 220 extern "C" |
| 221 bool ChromeOSStoreProperty(const char* name, |
| 222 const char* value, |
| 223 const std::vector<uint8>& signature) { |
| 224 chromeos::dbus::Proxy proxy = CreateProxy(); |
| 225 chromeos::glib::ScopedError error; |
| 164 | 226 |
| 227 GArray* sig = g_array_sized_new(FALSE, FALSE, 1, signature.size()); |
| 228 g_array_append_vals(sig, &signature[0], signature.size()); |
| 165 | 229 |
| 230 bool rv = true; |
| 231 if (!::dbus_g_proxy_call(proxy.gproxy(), |
| 232 login_manager::kSessionManagerStoreProperty, |
| 233 &Resetter(&error).lvalue(), |
| 234 G_TYPE_STRING, name, |
| 235 G_TYPE_STRING, value, |
| 236 DBUS_TYPE_G_UCHAR_ARRAY, sig, |
| 237 G_TYPE_INVALID, |
| 238 G_TYPE_INVALID)) { |
| 239 LOG(WARNING) << login_manager::kSessionManagerStoreProperty << " failed: " |
| 240 << SCOPED_SAFE_MESSAGE(error); |
| 241 rv = false; |
| 242 } |
| 243 g_array_free(sig, TRUE); |
| 244 return rv; |
| 245 } |
| 246 |
| 247 namespace { |
| 248 bool WhitelistOpHelper(const char* op, |
| 249 const char* email, |
| 250 const std::vector<uint8>& signature) { |
| 251 chromeos::dbus::Proxy proxy = CreateProxy(); |
| 252 chromeos::glib::ScopedError error; |
| 253 |
| 254 GArray* sig = g_array_sized_new(FALSE, FALSE, 1, signature.size()); |
| 255 g_array_append_vals(sig, &signature[0], signature.size()); |
| 256 |
| 257 bool rv = true; |
| 258 if (!::dbus_g_proxy_call(proxy.gproxy(), |
| 259 op, |
| 260 &Resetter(&error).lvalue(), |
| 261 G_TYPE_STRING, email, |
| 262 DBUS_TYPE_G_UCHAR_ARRAY, sig, |
| 263 G_TYPE_INVALID, |
| 264 G_TYPE_INVALID)) { |
| 265 LOG(WARNING) << op << " failed: " << SCOPED_SAFE_MESSAGE(error); |
| 266 rv = false; |
| 267 } |
| 268 g_array_free(sig, TRUE); |
| 269 return rv; |
| 270 } |
| 271 } // anonymous namespace |
| 272 |
| 273 extern "C" |
| 274 bool ChromeOSUnwhitelist(const char* email, |
| 275 const std::vector<uint8>& signature) { |
| 276 return WhitelistOpHelper(login_manager::kSessionManagerUnwhitelist, |
| 277 email, |
| 278 signature); |
| 279 } |
| 280 |
| 281 extern "C" |
| 282 bool ChromeOSWhitelist(const char* email, |
| 283 const std::vector<uint8>& signature) { |
| 284 return WhitelistOpHelper(login_manager::kSessionManagerWhitelist, |
| 285 email, |
| 286 signature); |
| 287 } |
| 288 |
| 289 namespace { |
| 166 #define SAFE_MESSAGE(e) (e.message ? e.message : "unknown error") | 290 #define SAFE_MESSAGE(e) (e.message ? e.message : "unknown error") |
| 167 | 291 |
| 168 namespace { | |
| 169 bool IsSuccess(DBusMessage* message) { | 292 bool IsSuccess(DBusMessage* message) { |
| 170 char* out_string = NULL; | 293 char* out_string = NULL; |
| 171 DBusError error; | 294 DBusError error; |
| 172 dbus_error_init (&error); | 295 dbus_error_init (&error); |
| 173 bool unpack = dbus_message_get_args(message, | 296 bool unpack = dbus_message_get_args(message, |
| 174 &error, | 297 &error, |
| 175 DBUS_TYPE_STRING, | 298 DBUS_TYPE_STRING, |
| 176 &out_string, | 299 &out_string, |
| 177 DBUS_TYPE_INVALID); | 300 DBUS_TYPE_INVALID); |
| 178 if (!unpack) { | 301 if (!unpack) { |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 extern "C" | 361 extern "C" |
| 239 void ChromeOSDisconnectSession(SessionConnection connection) { | 362 void ChromeOSDisconnectSession(SessionConnection connection) { |
| 240 DBusConnection *bus = ::dbus_g_connection_get_connection( | 363 DBusConnection *bus = ::dbus_g_connection_get_connection( |
| 241 dbus::GetSystemBusConnection().g_connection()); | 364 dbus::GetSystemBusConnection().g_connection()); |
| 242 ::dbus_connection_remove_filter(bus, &Filter, connection); | 365 ::dbus_connection_remove_filter(bus, &Filter, connection); |
| 243 delete connection; | 366 delete connection; |
| 244 LOG(INFO) << "Disconnected from session manager"; | 367 LOG(INFO) << "Disconnected from session manager"; |
| 245 } | 368 } |
| 246 | 369 |
| 247 } // namespace chromeos | 370 } // namespace chromeos |
| OLD | NEW |