OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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 "components/os_crypt/keyring_util_linux.h" |
| 6 |
| 7 #include <dlfcn.h> |
| 8 |
| 9 #include "base/logging.h" |
| 10 |
| 11 decltype(&::gnome_keyring_is_available) |
| 12 GnomeKeyringLoader::gnome_keyring_is_available_ptr; |
| 13 decltype(&::gnome_keyring_store_password) |
| 14 GnomeKeyringLoader::gnome_keyring_store_password_ptr; |
| 15 decltype(&::gnome_keyring_delete_password) |
| 16 GnomeKeyringLoader::gnome_keyring_delete_password_ptr; |
| 17 decltype(&::gnome_keyring_find_items) |
| 18 GnomeKeyringLoader::gnome_keyring_find_items_ptr; |
| 19 decltype(&::gnome_keyring_result_to_message) |
| 20 GnomeKeyringLoader::gnome_keyring_result_to_message_ptr; |
| 21 decltype(&::gnome_keyring_attribute_list_free) |
| 22 GnomeKeyringLoader::gnome_keyring_attribute_list_free_ptr; |
| 23 decltype(&::gnome_keyring_attribute_list_new) |
| 24 GnomeKeyringLoader::gnome_keyring_attribute_list_new_ptr; |
| 25 decltype(&::gnome_keyring_attribute_list_append_string) |
| 26 GnomeKeyringLoader::gnome_keyring_attribute_list_append_string_ptr; |
| 27 decltype(&::gnome_keyring_attribute_list_append_uint32) |
| 28 GnomeKeyringLoader::gnome_keyring_attribute_list_append_uint32_ptr; |
| 29 |
| 30 bool GnomeKeyringLoader::keyring_loaded = false; |
| 31 |
| 32 const GnomeKeyringLoader::FunctionInfo GnomeKeyringLoader::functions[] = { |
| 33 {"gnome_keyring_is_available", |
| 34 reinterpret_cast<void**>(&gnome_keyring_is_available_ptr)}, |
| 35 {"gnome_keyring_store_password", |
| 36 reinterpret_cast<void**>(&gnome_keyring_store_password_ptr)}, |
| 37 {"gnome_keyring_delete_password", |
| 38 reinterpret_cast<void**>(&gnome_keyring_delete_password_ptr)}, |
| 39 {"gnome_keyring_find_items", |
| 40 reinterpret_cast<void**>(&gnome_keyring_find_items_ptr)}, |
| 41 {"gnome_keyring_result_to_message", |
| 42 reinterpret_cast<void**>(&gnome_keyring_result_to_message_ptr)}, |
| 43 {"gnome_keyring_attribute_list_free", |
| 44 reinterpret_cast<void**>(&gnome_keyring_attribute_list_free_ptr)}, |
| 45 {"gnome_keyring_attribute_list_new", |
| 46 reinterpret_cast<void**>(&gnome_keyring_attribute_list_new_ptr)}, |
| 47 {"gnome_keyring_attribute_list_append_string", |
| 48 reinterpret_cast<void**>(&gnome_keyring_attribute_list_append_string_ptr)}, |
| 49 {"gnome_keyring_attribute_list_append_uint32", |
| 50 reinterpret_cast<void**>( |
| 51 &gnome_keyring_attribute_list_append_uint32_ptr)}}; |
| 52 |
| 53 /* Load the library and initialize the function pointers. */ |
| 54 bool GnomeKeyringLoader::LoadGnomeKeyring() { |
| 55 if (keyring_loaded) |
| 56 return true; |
| 57 |
| 58 void* handle = dlopen("libgnome-keyring.so.0", RTLD_NOW | RTLD_GLOBAL); |
| 59 if (!handle) { |
| 60 // We wanted to use GNOME Keyring, but we couldn't load it. Warn, because |
| 61 // either the user asked for this, or we autodetected it incorrectly. (Or |
| 62 // the system has broken libraries, which is also good to warn about.) |
| 63 LOG(WARNING) << "Could not load libgnome-keyring.so.0: " << dlerror(); |
| 64 return false; |
| 65 } |
| 66 |
| 67 for (size_t i = 0; i < arraysize(functions); ++i) { |
| 68 dlerror(); |
| 69 *functions[i].pointer = dlsym(handle, functions[i].name); |
| 70 const char* error = dlerror(); |
| 71 if (error) { |
| 72 LOG(ERROR) << "Unable to load symbol " << functions[i].name << ": " |
| 73 << error; |
| 74 dlclose(handle); |
| 75 return false; |
| 76 } |
| 77 } |
| 78 |
| 79 keyring_loaded = true; |
| 80 // We leak the library handle. That's OK: this function is called only once. |
| 81 return true; |
| 82 } |
OLD | NEW |