Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Hector Sanjuan committed 2012-04-12 11:43:00 +02:00
commit 7666d598c6
10 files changed
+260 -9

No files matched your search

+21
View File
@@ -93,6 +93,20 @@ public:
*/
virtual int del_rule(int oid, string& error_str);
/**
* Deletes rules that apply to this user id
*
* @param uid The user id
*/
void del_uid_rules(int uid);
/**
* Deletes rules that apply to this group id
*
* @param gid The group id
*/
void del_gid_rules(int gid);
/**
* Searches what resources of type obj_type the ACL rules set allows
* the given user to perform the operation.
@@ -199,6 +213,13 @@ private:
long long group_obj_type,
multimap<long long, AclRule*> &tmp_rules);
/**
* Deletes all rules that match the user mask
*
* @param user_req Mask to match
*/
void del_user_matching_rules(long long user_req);
// ----------------------------------------
// Mutex synchronization
// ----------------------------------------
+16 -1
View File
@@ -125,6 +125,16 @@ public:
return _time_out;
}
/**
* Returns true if there is an authorization driver enabled
*
* @return true if there is an authorization driver enabled
*/
bool is_authz_enabled()
{
return authz_enabled;
};
private:
/**
* Thread id for the Transfer Manager
@@ -159,7 +169,12 @@ private:
/**
* Generic name for the Auth driver
*/
static const char * auth_driver_name;
static const char * auth_driver_name;
/**
* True if there is an authorization driver enabled
*/
bool authz_enabled;
/**
* Returns a pointer to a Auth Manager driver.
+18
View File
@@ -180,11 +180,21 @@ public:
{
Nebula& nd = Nebula::instance();
pool = nd.get_gpool();
aclm = nd.get_aclm();
auth_object = PoolObjectSQL::GROUP;
auth_op = AuthRequest::ADMIN;
};
~GroupDelete(){};
/* -------------------------------------------------------------------- */
AclManager * aclm;
/* -------------------------------------------------------------------- */
int drop(int oid, PoolObjectSQL * object, string& error_msg);
};
/* ------------------------------------------------------------------------- */
@@ -198,6 +208,9 @@ public:
{
Nebula& nd = Nebula::instance();
pool = nd.get_upool();
gpool = nd.get_gpool();
aclm = nd.get_aclm();
auth_object = PoolObjectSQL::USER;
auth_op = AuthRequest::ADMIN;
};
@@ -206,6 +219,11 @@ public:
/* -------------------------------------------------------------------- */
GroupPool * gpool;
AclManager * aclm;
/* -------------------------------------------------------------------- */
int drop(int oid, PoolObjectSQL * object, string& error_msg);
};
+2 -2
View File
@@ -422,8 +422,8 @@ HM_MAD = [
AUTH_MAD = [
executable = "one_auth_mad",
arguments = "--authn ssh,x509,ldap,server_cipher,server_x509"
# arguments = "--authz quota --authn ssh,x509,ldap,server_cipher,server_x509"
authn = "ssh,x509,ldap,server_cipher,server_x509"
# , authz = "quota"
]
SESSION_EXPIRATION_TIME = 900
+50 -1
View File
@@ -504,7 +504,6 @@ int AclManager::del_rule(int oid, string& error_str)
{
found = *rule == *(it->second);
if ( !found )
{
it++;
@@ -546,6 +545,56 @@ int AclManager::del_rule(int oid, string& error_str)
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void AclManager::del_uid_rules(int uid)
{
long long user_req = AclRule::INDIVIDUAL_ID | uid;
del_user_matching_rules(user_req);
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void AclManager::del_gid_rules(int gid)
{
long long user_req = AclRule::GROUP_ID | gid;
del_user_matching_rules(user_req);
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void AclManager::del_user_matching_rules(long long user_req)
{
multimap<long long, AclRule *>::iterator it;
pair<multimap<long long, AclRule *>::iterator,
multimap<long long, AclRule *>::iterator> index;
vector<int> oids;
vector<int>::iterator oid_it;
string error_str;
lock();
index = acl_rules.equal_range( user_req );
for ( it = index.first; it != index.second; it++)
{
oids.push_back(it->second->oid);
}
unlock();
for ( oid_it = oids.begin() ; oid_it < oids.end(); oid_it++ )
{
del_rule(*oid_it, error_str);
}
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void AclManager::reverse_search(int uid,
int gid,
PoolObjectSQL::ObjectType obj_type,
+23
View File
@@ -453,6 +453,29 @@ void AuthManager::load_mads(int uid)
auth_conf.replace("NAME",auth_driver_name);
oss.str("");
string authn = auth_conf.vector_value("AUTHN");
if ( !authn.empty() )
{
oss << "--authn " << authn;
}
string authz = auth_conf.vector_value("AUTHZ");
if ( !authz.empty() )
{
authz_enabled = true;
oss << " --authz " << authz;
}
else
{
authz_enabled = false;
}
auth_conf.replace("ARGUMENTS", oss.str());
authm_driver = new AuthManagerDriver(uid,auth_conf.value(),(uid!=0),this);
rc = add(authm_driver);
+11
View File
@@ -101,6 +101,8 @@ module OpenNebula
end
end
# Delete an element from the xml
# xpath::_String_ xpath expression that selects the elemnts to be deleted
def delete_element(xpath)
if NOKOGIRI
@xml.xpath(xpath.to_s).remove
@@ -109,6 +111,15 @@ module OpenNebula
end
end
# Add a new element to the xml
# xpath::_String_ xpath xpression where the elemente will be added
# elems::_Hash_ Hash containing the pairs key-value to be included
# Examples:
# add_element('VM', 'NEW_ITEM' => 'NEW_VALUE')
# <VM><NEW_ITEM>NEW_VALUE</NEW_ITEM>...</VM>
#
# add_element('VM/TEMPLATE', 'V1' => {'X1' => 'A1', 'Y2' => 'A2'})
# <VM><TEMPLATE><V1><X1>A1</X1><Y2>A2</Y2>...</TEMPLATE></VM>
def add_element(xpath, elems)
elems.each { |key, value|
if value.instance_of?(Hash)
+100
View File
@@ -0,0 +1,100 @@
$: << '..'
require 'rexml/document'
require 'OpenNebula/XMLUtils'
shared_examples "modifying XML" do
it "add a new element '.', 'B2' => 'bdos'" do
@xml_element.add_element('.', 'B2' => 'bdos')
@xml_element.to_xml(true).should eql "<V1>
<A1>auno</A1>
<B2>bdos</B2>
</V1>"
end
it "add a new element '.', 'V2' => {'CC3' => 'cctres'}" do
@xml_element.add_element('.', 'V2' => {'CC3' => 'cctres'})
@xml_element.to_xml(true).should eql "<V1>
<A1>auno</A1>
<B2>bdos</B2>
<V2>
<CC3>cctres</CC3>
</V2>
</V1>"
end
it "add a new element 'V2', 'DD4' => 'ddcuatro'" do
@xml_element.add_element('V2', 'DD4' => 'ddcuatro')
@xml_element.to_xml(true).should eql "<V1>
<A1>auno</A1>
<B2>bdos</B2>
<V2>
<CC3>cctres</CC3>
<DD4>ddcuatro</DD4>
</V2>
</V1>"
end
it "delete an element 'B2'" do
@xml_element.delete_element('B2')
@xml_element.to_xml(true).should eql "<V1>
<A1>auno</A1>
<V2>
<CC3>cctres</CC3>
<DD4>ddcuatro</DD4>
</V2>
</V1>"
end
it "delete an element 'V2/DD4'" do
@xml_element.delete_element('V2/DD4')
@xml_element.to_xml(true).should eql "<V1>
<A1>auno</A1>
<V2>
<CC3>cctres</CC3>
</V2>
</V1>"
end
it "delete an element 'V2'" do
@xml_element.delete_element('V2')
@xml_element.to_xml(true).should eql "<V1>
<A1>auno</A1>
</V1>"
end
end
describe 'NOKOGIRI' do
before :all do
xml = "<V1><A1>auno</A1></V1>"
bxml = OpenNebula::XMLElement.build_xml(xml, "V1")
bxml.class.to_s.should eql('Nokogiri::XML::NodeSet')
@xml_element = OpenNebula::XMLElement.new(bxml)
end
it_behaves_like "modifying XML"
end
describe 'REXML' do
before :all do
OpenNebula::NOKOGIRI = false
xml = "<V1><A1>auno</A1></V1>"
bxml = OpenNebula::XMLElement.build_xml(xml, "V1")
bxml.class.to_s.should eql('REXML::Element')
@xml_element = OpenNebula::XMLElement.new(bxml)
end
it_behaves_like "modifying XML"
end
+18 -4
View File
@@ -192,6 +192,21 @@ int ImageDelete::drop(int oid, PoolObjectSQL * object, string& error_msg)
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
int GroupDelete::drop(int oid, PoolObjectSQL * object, string& error_msg)
{
int rc = RequestManagerDelete::drop(oid, object, error_msg);
if ( rc == 0 )
{
aclm->del_gid_rules(oid);
}
return rc;
}
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
int UserDelete::drop(int oid, PoolObjectSQL * object, string& error_msg)
{
User * user = static_cast<User *>(object);
@@ -211,10 +226,7 @@ int UserDelete::drop(int oid, PoolObjectSQL * object, string& error_msg)
if ( rc == 0 )
{
Nebula& nd = Nebula::instance();
GroupPool * gpool = nd.get_gpool();
Group * group = gpool->get(group_id, true);
Group * group = gpool->get(group_id, true);
if( group != 0 )
{
@@ -223,6 +235,8 @@ int UserDelete::drop(int oid, PoolObjectSQL * object, string& error_msg)
group->unlock();
}
aclm->del_uid_rules(oid);
}
return rc;
+1 -1
View File
@@ -735,7 +735,7 @@ int UserPool::authorize(AuthRequest& ar)
AuthManager * authm = nd.get_authm();
int rc = -1;
if (authm == 0)
if (authm == 0 || !authm->is_authz_enabled())
{
if (ar.core_authorize())
{