| 41 | using ceph::Formatter; |
| 42 | |
| 43 | int KeyRing::from_ceph_context(CephContext *cct) |
| 44 | { |
| 45 | const auto& conf = cct->_conf; |
| 46 | string filename; |
| 47 | |
| 48 | int ret = ceph_resolve_file_search(conf->keyring, filename); |
| 49 | if (!ret) { |
| 50 | ret = load(cct, filename); |
| 51 | if (ret < 0) |
| 52 | lderr(cct) << "failed to load " << filename |
| 53 | << ": " << cpp_strerror(ret) << dendl; |
| 54 | } else if (conf->key.empty() && conf->keyfile.empty()) { |
| 55 | lderr(cct) << "unable to find a keyring on " << conf->keyring |
| 56 | << ": " << cpp_strerror(ret) << dendl; |
| 57 | } |
| 58 | |
| 59 | if (!conf->key.empty()) { |
| 60 | EntityAuth ea; |
| 61 | try { |
| 62 | ea.key.decode_base64(conf->key); |
| 63 | add(conf->name, ea); |
| 64 | return 0; |
| 65 | } |
| 66 | catch (ceph::buffer::error& e) { |
| 67 | lderr(cct) << "failed to decode key '" << conf->key << "'" << dendl; |
| 68 | return -EINVAL; |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | if (!conf->keyfile.empty()) { |
| 73 | bufferlist bl; |
| 74 | string err; |
| 75 | int r = bl.read_file(conf->keyfile.c_str(), &err); |
| 76 | if (r < 0) { |
| 77 | lderr(cct) << err << dendl; |
| 78 | return r; |
| 79 | } |
| 80 | string k(bl.c_str(), bl.length()); |
| 81 | EntityAuth ea; |
| 82 | try { |
| 83 | ea.key.decode_base64(k); |
| 84 | add(conf->name, ea); |
| 85 | } |
| 86 | catch (ceph::buffer::error& e) { |
| 87 | lderr(cct) << "failed to decode key '" << k << "'" << dendl; |
| 88 | return -EINVAL; |
| 89 | } |
| 90 | return 0; |
| 91 | } |
| 92 | |
| 93 | return ret; |
| 94 | } |
| 95 | |
| 96 | int KeyRing::set_modifier(const char *type, |
| 97 | const char *val, |
no test coverage detected