using namespace std;
KeyRing *KeyRing::
-from_ceph_conf(const md_config_t *conf)
+from_ceph_context(CephContext *cct)
{
+ const md_config_t *conf = cct->_conf;
bool found_key = false;
auto_ptr < KeyRing > keyring(new KeyRing());
if (!is_supported_auth(CEPH_AUTH_CEPHX)) {
- dout(2) << "KeyRing::from_ceph_conf: CephX auth is not supported." << dendl;
+ ldout(cct, 2) << "KeyRing::from_ceph_context: CephX auth is not supported." << dendl;
return keyring.release();
}
int ret = 0;
string filename;
if (ceph_resolve_file_search(conf->keyring, filename)) {
- ret = keyring->load(filename);
+ ret = keyring->load(cct, filename);
if (ret) {
- derr << "KeyRing::from_ceph_conf: failed to load " << filename
- << ": error " << ret << dendl;
+ lderr(cct) << "KeyRing::from_ceph_context: failed to load " << filename
+ << ": error " << ret << dendl;
}
else {
found_key = true;
int res = fread(buf, 1, sizeof(buf) - 1, fp);
if (res < 0) {
res = ferror(fp);
- derr << "KeyRing::from_ceph_conf: failed to read '" << conf->keyfile
- << "'" << dendl;
+ lderr(cct) << "KeyRing::from_ceph_conf: failed to read '" << conf->keyfile
+ << "'" << dendl;
}
else {
string k = buf;
ConfFile cf;
std::deque<std::string> parse_errors;
if (cf.parse_bufferlist(&bl, &parse_errors) != 0) {
- derr << "cannot parse buffer" << dendl;
- throw buffer::error();
+ throw buffer::malformed_input("cannot parse buffer");
}
for (ConfFile::const_section_iter_t s = cf.sections_begin();
EntityName ename;
map<string, bufferlist> caps;
if (!ename.from_str(name)) {
- derr << "bad entity name: " << name << dendl;
- throw buffer::error();
+ ostringstream oss;
+ oss << "bad entity name: " << name;
+ throw buffer::malformed_input(oss.str().c_str());
}
for (ConfSection::const_line_iter_t l = s->second.lines.begin();
std::replace(k.begin(), k.end(), '_', ' ');
ret = set_modifier(k.c_str(), l->val.c_str(), ename, caps);
if (ret < 0) {
- derr << "error setting modifier for [" << name << "] type=" << k
- << " val=" << l->val << dendl;
- throw buffer::error();
+ ostringstream oss;
+ oss << "error setting modifier for [" << name << "] type=" << k
+ << " val=" << l->val;
+ throw buffer::malformed_input(oss.str().c_str());
}
}
}
}
}
-int KeyRing::load(const std::string &filename)
+int KeyRing::load(CephContext *cct, const std::string &filename)
{
if (filename.empty())
return -EINVAL;
derr << "error parsing file " << filename << dendl;
}
- dout(2) << "KeyRing::load: loaded key file " << filename << dendl;
+ ldout(cct, 2) << "KeyRing::load: loaded key file " << filename << dendl;
return 0;
}
}
}
-void KeyRing::import(KeyRing& other)
+void KeyRing::import(CephContext *cct, KeyRing& other)
{
for (map<EntityName, EntityAuth>::iterator p = other.keys.begin();
p != other.keys.end();
++p) {
- dout(10) << " importing " << p->first << " " << p->second << dendl;
+ ldout(cct, 10) << " importing " << p->first << " " << p->second << dendl;
keys[p->first] = p->second;
}
}
int set_modifier(const char *type, const char *val, EntityName& name, map<string, bufferlist>& caps);
void decode_plaintext(bufferlist::iterator& bl);
public:
- /* Create a KeyRing from a Ceph configuration */
- static KeyRing *from_ceph_conf(const md_config_t *conf);
+ /* Create a KeyRing from a Ceph context.
+ * We will use the configuration stored inside the context. */
+ static KeyRing *from_ceph_context(CephContext *cct);
/* Create an empty KeyRing */
static KeyRing *create_empty();
map<EntityName, EntityAuth>& get_keys() { return keys; } // yuck
- int load(const std::string &filename);
+ int load(CephContext *cct, const std::string &filename);
void print(ostream& out);
// accessors
void set_key(EntityName& ename, CryptoKey& key) {
keys[ename].key = key;
}
- void import(KeyRing& other);
+ void import(CephContext *cct, KeyRing& other);
// encoders
void encode(bufferlist& bl) const {
void RotatingKeyRing::dump_rotating() const
{
- dout(10) << "dump_rotating:" << dendl;
+ ldout(cct, 10) << "dump_rotating:" << dendl;
for (map<uint64_t, ExpiringCryptoKey>::const_iterator iter = secrets.secrets.begin();
iter != secrets.secrets.end();
++iter)
- dout(10) << " id " << iter->first << " " << iter->second << dendl;
+ ldout(cct, 10) << " id " << iter->first << " " << iter->second << dendl;
}
bool RotatingKeyRing::get_secret(const EntityName& name, CryptoKey& secret) const
Mutex::Locker l(lock);
if (service_id_ != this->service_id) {
- dout(0) << "do not have service " << ceph_entity_type_name(service_id_)
+ ldout(cct, 0) << "do not have service " << ceph_entity_type_name(service_id_)
<< ", i am " << ceph_entity_type_name(this->service_id) << dendl;
return false;
}
map<uint64_t, ExpiringCryptoKey>::const_iterator iter =
secrets.secrets.find(secret_id);
if (iter == secrets.secrets.end()) {
- dout(0) << "could not find secret_id=" << secret_id << dendl;
+ ldout(cct, 0) << "could not find secret_id=" << secret_id << dendl;
dump_rotating();
return false;
}
class KeyRing;
class RotatingKeyRing : public KeyStore {
+ CephContext *cct;
uint32_t service_id;
RotatingSecrets secrets;
KeyRing *keyring;
mutable Mutex lock;
public:
- RotatingKeyRing(uint32_t s, KeyRing *kr) :
+ RotatingKeyRing(CephContext *cct_, uint32_t s, KeyRing *kr) :
+ cct(cct_),
service_id(s),
keyring(kr),
lock("RotatingKeyRing::lock") {}
cout << "importing contents of " << import_keyring << " into " << fn << std::endl;
//other.print(cout);
- keyring.import(other);
+ keyring.import(&g_ceph_context, other);
modified = true;
} else {
cerr << "can't open " << import_keyring << ": " << err << std::endl;
dout(10) << "create_initial -- creating initial map" << dendl;
KeyRing keyring;
- if (keyring.load(g_conf->keyring) == 0) {
+ if (keyring.load(&g_ceph_context, g_conf->keyring) == 0) {
import_keyring(keyring);
}
messenger->add_dispatcher_head(this);
- keyring = KeyRing::from_ceph_conf(cct->_conf);
+ keyring = KeyRing::from_ceph_context(cct);
if (!keyring) {
derr << "MonClient::init(): Failed to create keyring" << dendl;
return -EDOM;
}
- rotating_secrets = new RotatingKeyRing(cct->get_module_type(), keyring);
+ rotating_secrets = new RotatingKeyRing(cct, cct->get_module_type(), keyring);
entity_name = g_conf->name;