Skip to content

Commit

Permalink
mon: Build ceph-mon without using namespace declarations in headers
Browse files Browse the repository at this point in the history
This is part of a series of commits to clean up using namespace at top
level in headers.

Signed-off-by: Adam C. Emerson <[email protected]>
  • Loading branch information
adamemerson committed Mar 22, 2020
1 parent 0b1935b commit 1e88640
Show file tree
Hide file tree
Showing 121 changed files with 2,641 additions and 1,971 deletions.
49 changes: 25 additions & 24 deletions src/auth/cephx/CephxKeyServer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,18 @@
#undef dout_prefix
#define dout_prefix *_dout << "cephx keyserverdata: "

using std::ostringstream;
using std::string;
using std::stringstream;

using ceph::bufferptr;
using ceph::bufferlist;
using ceph::Formatter;

bool KeyServerData::get_service_secret(CephContext *cct, uint32_t service_id,
ExpiringCryptoKey& secret, uint64_t& secret_id) const
{
map<uint32_t, RotatingSecrets>::const_iterator iter =
rotating_secrets.find(service_id);
auto iter = rotating_secrets.find(service_id);
if (iter == rotating_secrets.end()) {
ldout(cct, 10) << "get_service_secret service " << ceph_entity_type_name(service_id) << " not found " << dendl;
return false;
Expand All @@ -34,8 +41,7 @@ bool KeyServerData::get_service_secret(CephContext *cct, uint32_t service_id,
const RotatingSecrets& secrets = iter->second;

// second to oldest, unless it's expired
map<uint64_t, ExpiringCryptoKey>::const_iterator riter =
secrets.secrets.begin();
auto riter = secrets.secrets.begin();
if (secrets.secrets.size() > 1)
++riter;

Expand Down Expand Up @@ -64,23 +70,20 @@ bool KeyServerData::get_service_secret(CephContext *cct, uint32_t service_id,
bool KeyServerData::get_service_secret(CephContext *cct, uint32_t service_id,
uint64_t secret_id, CryptoKey& secret) const
{
map<uint32_t, RotatingSecrets>::const_iterator iter =
rotating_secrets.find(service_id);
auto iter = rotating_secrets.find(service_id);
if (iter == rotating_secrets.end())
return false;

const RotatingSecrets& secrets = iter->second;
map<uint64_t, ExpiringCryptoKey>::const_iterator riter =
secrets.secrets.find(secret_id);
auto riter = secrets.secrets.find(secret_id);

if (riter == secrets.secrets.end()) {
ldout(cct, 10) << "get_service_secret service " << ceph_entity_type_name(service_id)
<< " secret " << secret_id << " not found" << dendl;
ldout(cct, 30) << " I have:" << dendl;
for (map<uint64_t, ExpiringCryptoKey>::const_iterator iter =
secrets.secrets.begin();
iter != secrets.secrets.end();
++iter)
for (auto iter = secrets.secrets.begin();
iter != secrets.secrets.end();
++iter)
ldout(cct, 30) << " id " << iter->first << " " << iter->second << dendl;
return false;
}
Expand All @@ -90,7 +93,7 @@ bool KeyServerData::get_service_secret(CephContext *cct, uint32_t service_id,
return true;
}
bool KeyServerData::get_auth(const EntityName& name, EntityAuth& auth) const {
map<EntityName, EntityAuth>::const_iterator iter = secrets.find(name);
auto iter = secrets.find(name);
if (iter != secrets.end()) {
auth = iter->second;
return true;
Expand All @@ -99,7 +102,7 @@ bool KeyServerData::get_auth(const EntityName& name, EntityAuth& auth) const {
}

bool KeyServerData::get_secret(const EntityName& name, CryptoKey& secret) const {
map<EntityName, EntityAuth>::const_iterator iter = secrets.find(name);
auto iter = secrets.find(name);
if (iter != secrets.end()) {
secret = iter->second.key;
return true;
Expand All @@ -113,10 +116,10 @@ bool KeyServerData::get_caps(CephContext *cct, const EntityName& name,
caps_info.allow_all = false;

ldout(cct, 10) << "get_caps: name=" << name.to_str() << dendl;
map<EntityName, EntityAuth>::const_iterator iter = secrets.find(name);
auto iter = secrets.find(name);
if (iter != secrets.end()) {
ldout(cct, 10) << "get_secret: num of caps=" << iter->second.caps.size() << dendl;
map<string, bufferlist>::const_iterator capsiter = iter->second.caps.find(type);
auto capsiter = iter->second.caps.find(type);
if (capsiter != iter->second.caps.end()) {
caps_info.caps = capsiter->second;
}
Expand Down Expand Up @@ -172,11 +175,11 @@ bool KeyServer::_check_rotating_secrets()
void KeyServer::_dump_rotating_secrets()
{
ldout(cct, 30) << "_dump_rotating_secrets" << dendl;
for (map<uint32_t, RotatingSecrets>::iterator iter = data.rotating_secrets.begin();
for (auto iter = data.rotating_secrets.begin();
iter != data.rotating_secrets.end();
++iter) {
RotatingSecrets& key = iter->second;
for (map<uint64_t, ExpiringCryptoKey>::iterator mapiter = key.secrets.begin();
for (auto mapiter = key.secrets.begin();
mapiter != key.secrets.end();
++mapiter)
ldout(cct, 30) << "service " << ceph_entity_type_name(iter->first)
Expand Down Expand Up @@ -289,7 +292,7 @@ bool KeyServer::contains(const EntityName& name) const
int KeyServer::encode_secrets(Formatter *f, stringstream *ds) const
{
std::scoped_lock l{lock};
map<EntityName, EntityAuth>::const_iterator mapiter = data.secrets_begin();
auto mapiter = data.secrets_begin();

if (mapiter == data.secrets_end())
return -ENOENT;
Expand All @@ -310,8 +313,7 @@ int KeyServer::encode_secrets(Formatter *f, stringstream *ds) const
f->open_object_section("caps");
}

map<string, bufferlist>::const_iterator capsiter =
mapiter->second.caps.begin();
auto capsiter = mapiter->second.caps.begin();
for (; capsiter != mapiter->second.caps.end(); ++capsiter) {
// FIXME: need a const_iterator for bufferlist, but it doesn't exist yet.
bufferlist *bl = const_cast<bufferlist*>(&capsiter->second);
Expand Down Expand Up @@ -374,14 +376,13 @@ bool KeyServer::get_rotating_encrypted(const EntityName& name,
{
std::scoped_lock l{lock};

map<EntityName, EntityAuth>::const_iterator mapiter = data.find_name(name);
auto mapiter = data.find_name(name);
if (mapiter == data.secrets_end())
return false;

const CryptoKey& specific_key = mapiter->second.key;

map<uint32_t, RotatingSecrets>::const_iterator rotate_iter =
data.rotating_secrets.find(name.get_type());
auto rotate_iter = data.rotating_secrets.find(name.get_type());
if (rotate_iter == data.rotating_secrets.end())
return false;

Expand Down
65 changes: 31 additions & 34 deletions src/auth/cephx/CephxKeyServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,26 @@

#include "auth/KeyRing.h"
#include "CephxProtocol.h"
#include "CephxKeyServer.h"
#include "common/ceph_mutex.h"
#include "include/common_fwd.h"

struct KeyServerData {
version_t version;

/* for each entity */
map<EntityName, EntityAuth> secrets;
std::map<EntityName, EntityAuth> secrets;
KeyRing *extra_secrets;

/* for each service type */
version_t rotating_ver;
map<uint32_t, RotatingSecrets> rotating_secrets;
std::map<uint32_t, RotatingSecrets> rotating_secrets;

explicit KeyServerData(KeyRing *extra)
: version(0),
extra_secrets(extra),
rotating_ver(0) {}

void encode(bufferlist& bl) const {
void encode(ceph::buffer::list& bl) const {
__u8 struct_v = 1;
using ceph::encode;
encode(struct_v, bl);
Expand All @@ -46,7 +45,7 @@ struct KeyServerData {
encode(secrets, bl);
encode(rotating_secrets, bl);
}
void decode(bufferlist::const_iterator& bl) {
void decode(ceph::buffer::list::const_iterator& bl) {
using ceph::decode;
__u8 struct_v;
decode(struct_v, bl);
Expand All @@ -56,14 +55,14 @@ struct KeyServerData {
decode(rotating_secrets, bl);
}

void encode_rotating(bufferlist& bl) const {
void encode_rotating(ceph::buffer::list& bl) const {
using ceph::encode;
__u8 struct_v = 1;
encode(struct_v, bl);
encode(rotating_ver, bl);
encode(rotating_secrets, bl);
}
void decode_rotating(bufferlist& rotating_bl) {
void decode_rotating(ceph::buffer::list& rotating_bl) {
using ceph::decode;
auto iter = rotating_bl.cbegin();
__u8 struct_v;
Expand All @@ -88,7 +87,7 @@ struct KeyServerData {
}

void remove_secret(const EntityName& name) {
map<EntityName, EntityAuth>::iterator iter = secrets.find(name);
auto iter = secrets.find(name);
if (iter == secrets.end())
return;
secrets.erase(iter);
Expand All @@ -105,17 +104,17 @@ struct KeyServerData {
bool get_caps(CephContext *cct, const EntityName& name,
const std::string& type, AuthCapsInfo& caps) const;

map<EntityName, EntityAuth>::iterator secrets_begin()
std::map<EntityName, EntityAuth>::iterator secrets_begin()
{ return secrets.begin(); }
map<EntityName, EntityAuth>::const_iterator secrets_begin() const
std::map<EntityName, EntityAuth>::const_iterator secrets_begin() const
{ return secrets.begin(); }
map<EntityName, EntityAuth>::iterator secrets_end()
std::map<EntityName, EntityAuth>::iterator secrets_end()
{ return secrets.end(); }
map<EntityName, EntityAuth>::const_iterator secrets_end() const
std::map<EntityName, EntityAuth>::const_iterator secrets_end() const
{ return secrets.end(); }
map<EntityName, EntityAuth>::iterator find_name(const EntityName& name)
std::map<EntityName, EntityAuth>::iterator find_name(const EntityName& name)
{ return secrets.find(name); }
map<EntityName, EntityAuth>::const_iterator find_name(const EntityName& name) const
std::map<EntityName, EntityAuth>::const_iterator find_name(const EntityName& name) const
{ return secrets.find(name); }


Expand All @@ -129,11 +128,11 @@ struct KeyServerData {

struct Incremental {
IncrementalOp op;
bufferlist rotating_bl; // if SET_ROTATING. otherwise,
ceph::buffer::list rotating_bl; // if SET_ROTATING. otherwise,
EntityName name;
EntityAuth auth;
void encode(bufferlist& bl) const {

void encode(ceph::buffer::list& bl) const {
using ceph::encode;
__u8 struct_v = 1;
encode(struct_v, bl);
Expand All @@ -146,7 +145,7 @@ struct KeyServerData {
encode(auth, bl);
}
}
void decode(bufferlist::const_iterator& bl) {
void decode(ceph::buffer::list::const_iterator& bl) {
using ceph::decode;
__u8 struct_v;
decode(struct_v, bl);
Expand Down Expand Up @@ -211,7 +210,7 @@ class KeyServer : public KeyStore {

bool get_secret(const EntityName& name, CryptoKey& secret) const override;
bool get_auth(const EntityName& name, EntityAuth& auth) const;
bool get_caps(const EntityName& name, const string& type, AuthCapsInfo& caps) const;
bool get_caps(const EntityName& name, const std::string& type, AuthCapsInfo& caps) const;
bool get_active_rotating_secret(const EntityName& name, CryptoKey& secret) const;
int start_server();
void rotate_timeout(double timeout);
Expand All @@ -233,25 +232,25 @@ class KeyServer : public KeyStore {

bool generate_secret(EntityName& name, CryptoKey& secret);

void encode(bufferlist& bl) const {
void encode(ceph::buffer::list& bl) const {
using ceph::encode;
encode(data, bl);
}
void decode(bufferlist::const_iterator& bl) {
void decode(ceph::buffer::list::const_iterator& bl) {
std::scoped_lock l{lock};
using ceph::decode;
decode(data, bl);
}
bool contains(const EntityName& name) const;
int encode_secrets(Formatter *f, stringstream *ds) const;
void encode_formatted(string label, Formatter *f, bufferlist &bl);
void encode_plaintext(bufferlist &bl);
int list_secrets(stringstream& ds) const {
int encode_secrets(ceph::Formatter *f, std::stringstream *ds) const;
void encode_formatted(std::string label, ceph::Formatter *f, ceph::buffer::list &bl);
void encode_plaintext(ceph::buffer::list &bl);
int list_secrets(std::stringstream& ds) const {
return encode_secrets(NULL, &ds);
}
version_t get_ver() const {
std::scoped_lock l{lock};
return data.version;
return data.version;
}

void clear_secrets() {
Expand Down Expand Up @@ -279,7 +278,7 @@ class KeyServer : public KeyStore {
}

bool has_secrets() {
map<EntityName, EntityAuth>::const_iterator b = data.secrets_begin();
auto b = data.secrets_begin();
return (b != data.secrets_end());
}
int get_num_secrets() {
Expand All @@ -293,24 +292,22 @@ class KeyServer : public KeyStore {
}
void export_keyring(KeyRing& keyring) {
std::scoped_lock l{lock};
for (map<EntityName, EntityAuth>::iterator p = data.secrets.begin();
p != data.secrets.end();
++p) {
for (auto p = data.secrets.begin(); p != data.secrets.end(); ++p) {
keyring.add(p->first, p->second);
}
}

bool updated_rotating(bufferlist& rotating_bl, version_t& rotating_ver);
bool updated_rotating(ceph::buffer::list& rotating_bl, version_t& rotating_ver);

bool get_rotating_encrypted(const EntityName& name, bufferlist& enc_bl) const;
bool get_rotating_encrypted(const EntityName& name, ceph::buffer::list& enc_bl) const;

ceph::mutex& get_lock() const { return lock; }
bool get_service_caps(const EntityName& name, uint32_t service_id,
AuthCapsInfo& caps) const;

map<EntityName, EntityAuth>::iterator secrets_begin()
std::map<EntityName, EntityAuth>::iterator secrets_begin()
{ return data.secrets_begin(); }
map<EntityName, EntityAuth>::iterator secrets_end()
std::map<EntityName, EntityAuth>::iterator secrets_end()
{ return data.secrets_end(); }
};
WRITE_CLASS_ENCODER(KeyServer)
Expand Down
14 changes: 11 additions & 3 deletions src/auth/cephx/CephxServiceHandler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@
#undef dout_prefix
#define dout_prefix *_dout << "cephx server " << entity_name << ": "

using std::dec;
using std::hex;
using std::vector;

using ceph::bufferlist;
using ceph::decode;
using ceph::encode;

int CephxServiceHandler::start_session(
const EntityName& name,
size_t connection_secret_required_length,
Expand Down Expand Up @@ -63,7 +71,7 @@ int CephxServiceHandler::handle_request(
struct CephXRequestHeader cephx_header;
try {
decode(cephx_header, indata);
} catch (buffer::error& e) {
} catch (ceph::buffer::error& e) {
ldout(cct, 0) << __func__ << " failed to decode CephXRequestHeader: "
<< e.what() << dendl;
return -EPERM;
Expand All @@ -78,7 +86,7 @@ int CephxServiceHandler::handle_request(
CephXAuthenticate req;
try {
decode(req, indata);
} catch (buffer::error& e) {
} catch (ceph::buffer::error& e) {
ldout(cct, 0) << __func__ << " failed to decode CephXAuthenticate: "
<< e.what() << dendl;
ret = -EPERM;
Expand Down Expand Up @@ -249,7 +257,7 @@ int CephxServiceHandler::handle_request(
CephXServiceTicketRequest ticket_req;
try {
decode(ticket_req, indata);
} catch (buffer::error& e) {
} catch (ceph::buffer::error& e) {
ldout(cct, 0) << __func__
<< " failed to decode CephXServiceTicketRequest: "
<< e.what() << dendl;
Expand Down
Loading

0 comments on commit 1e88640

Please sign in to comment.