Skip to content

Commit

Permalink
mon: let prepare_new_pool assign an auid.
Browse files Browse the repository at this point in the history
Add new version that takes an MPoolOp and checks permissions
first.
  • Loading branch information
Greg Farnum committed Mar 8, 2010
1 parent 07df67f commit fbe08c7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
23 changes: 20 additions & 3 deletions src/mon/OSDMonitor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1003,7 +1003,19 @@ bool OSDMonitor::preprocess_command(MMonCommand *m)
return false;
}

int OSDMonitor::prepare_new_pool(string& name)
int OSDMonitor::prepare_new_pool(MPoolOp *m)
{
//check permissions for the auid, then pass off to next function
Session * session = (Session *) m->get_connection()->get_priv();
if (m->auid) {
if(check_privileges(m->auid, session->caps, MON_CAP_W)) {
prepare_new_pool(m->name, m->auid);
} else return -EPERM;
} else prepare_new_pool(m->name, session->caps.auid);
return 0;
}

int OSDMonitor::prepare_new_pool(string& name, __u64 auid)
{
if (osdmap.name_pool.count(name)) {
return -EEXIST;
Expand All @@ -1019,6 +1031,7 @@ int OSDMonitor::prepare_new_pool(string& name)
pending_inc.new_pools[pool].v.lpg_num = 0;
pending_inc.new_pools[pool].v.lpgp_num = 0;
pending_inc.new_pools[pool].v.last_change = pending_inc.epoch;
pending_inc.new_pools[pool].v.auid = auid;
pending_inc.new_pool_names[pool] = name;
return 0;
}
Expand Down Expand Up @@ -1367,8 +1380,12 @@ bool OSDMonitor::prepare_pool_op (MPoolOp *m)

bool OSDMonitor::prepare_pool_op_create (MPoolOp *m)
{
int err = prepare_new_pool(m->name);
paxos->wait_for_commit(new OSDMonitor::C_PoolOp(this, m, err, pending_inc.epoch));
int err = prepare_new_pool(m);
if (!err) {
paxos->wait_for_commit(new OSDMonitor::C_PoolOp(this, m, err, pending_inc.epoch));
} else {
_pool_op(m, err, pending_inc.epoch);
}
return true;
}

Expand Down
4 changes: 2 additions & 2 deletions src/mon/OSDMonitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ class OSDMonitor : public PaxosService {
bool prepare_pool_op (MPoolOp *m);
bool prepare_pool_op_create (MPoolOp *m);
bool prepare_pool_op_delete(MPoolOp *m);
int prepare_new_pool(string& name, __u64 auid = CEPH_AUTH_UID_DEFAULT);
int prepare_new_pool(MPoolOp *m);
void _pool_op(MPoolOp *m, int replyCode, epoch_t epoch);

//check that the provided caps allow the given action in auid's name
Expand Down Expand Up @@ -156,8 +158,6 @@ class OSDMonitor : public PaxosService {
bool preprocess_command(MMonCommand *m);
bool prepare_command(MMonCommand *m);

int prepare_new_pool(string& name);

void mark_all_down();

void send_latest(PaxosServiceMessage *m, epoch_t start=0);
Expand Down

0 comments on commit fbe08c7

Please sign in to comment.