#include "common/ConfUtils.h"
#include "common/config.h"
#include "common/debug.h"
+#include "common/errno.h"
#include "include/str_list.h"
#define DOUT_SUBSYS auth
using std::auto_ptr;
using namespace std;
-KeyRing *KeyRing::from_ceph_context(CephContext *cct)
+int KeyRing::from_ceph_context(CephContext *cct, KeyRing **pkeyring)
{
const md_config_t *conf = cct->_conf;
bool found_key = false;
if (!supported.is_supported_auth(CEPH_AUTH_CEPHX)) {
ldout(cct, 2) << "KeyRing::from_ceph_context: CephX auth is not supported." << dendl;
- return keyring.release();
+ *pkeyring = keyring.release();
+ return 0;
}
int ret = 0;
ret = keyring->load(cct, filename);
if (ret) {
lderr(cct) << "KeyRing::from_ceph_context: failed to load " << filename
- << ": error " << ret << dendl;
- }
- else {
+ << ": " << cpp_strerror(ret) << dendl;
+ } else {
found_key = true;
}
}
int res = fread(buf, 1, sizeof(buf) - 1, fp);
if (res < 0) {
res = ferror(fp);
- lderr(cct) << "KeyRing::from_ceph_conf: failed to read '" << conf->keyfile
+ lderr(cct) << "KeyRing::from_ceph_context: failed to read '" << conf->keyfile
<< "'" << dendl;
}
else {
found_key = true;
}
fclose(fp);
+ } else {
+ ret = errno;
+ lderr(cct) << "KeyRing::conf_ceph_context: failed to open " << conf->keyfile
+ << ": " << cpp_strerror(ret) << dendl;
}
}
- if (!found_key)
- return NULL;
- return keyring.release();
+ if (!found_key) {
+ if (conf->keyring.length())
+ lderr(cct) << "failed to open keyring from " << conf->keyring << dendl;
+ return -ENOENT;
+ }
+
+ *pkeyring = keyring.release();
+ return 0;
}
KeyRing *KeyRing::create_empty()
public:
/* Create a KeyRing from a Ceph context.
* We will use the configuration stored inside the context. */
- static KeyRing *from_ceph_context(CephContext *cct);
+ static int from_ceph_context(CephContext *cct, KeyRing **pkeyring);
/* Create an empty KeyRing */
static KeyRing *create_empty();
messenger->add_dispatcher_head(this);
- keyring = KeyRing::from_ceph_context(cct);
- if (!keyring) {
- lderr(cct) << "MonClient::init(): Failed to create keyring" << dendl;
- return -EDOM;
+ int r = KeyRing::from_ceph_context(cct, &keyring);
+ if (r < 0) {
+ lderr(cct) << "failed to open keyring: " << cpp_strerror(r) << dendl;
+ return r;
}
rotating_secrets = new RotatingKeyRing(cct, cct->get_module_type(), keyring);