mirror of
https://github.com/OpenNebula/one.git
synced 2025-01-25 06:03:36 +03:00
feature #1304: Removed name uniqueness for document pool. Simplify related functions because of this
This commit is contained in:
parent
85644bfe0e
commit
cb9e8bdb82
@ -21,6 +21,9 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <libxml/tree.h>
|
#include <libxml/tree.h>
|
||||||
|
|
||||||
|
#include "PoolObjectSQL.h"
|
||||||
|
#include "AuthManager.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -224,6 +227,20 @@ private:
|
|||||||
* Builds the human representation of the ACL
|
* Builds the human representation of the ACL
|
||||||
*/
|
*/
|
||||||
void build_str();
|
void build_str();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Array of PoolObjectSQL types to iterate over all types
|
||||||
|
*/
|
||||||
|
static const int num_pool_objects;
|
||||||
|
|
||||||
|
static const PoolObjectSQL::ObjectType pool_objects[];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Array of Auth operation types to iterate over all types
|
||||||
|
*/
|
||||||
|
static const int num_auth_operations;
|
||||||
|
|
||||||
|
static const AuthRequest::Operation auth_operations[];
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /*ACL_RULE_H*/
|
#endif /*ACL_RULE_H*/
|
||||||
|
@ -80,11 +80,6 @@ private:
|
|||||||
// Document Attributes
|
// Document Attributes
|
||||||
// -------------------------------------------------------------------------
|
// -------------------------------------------------------------------------
|
||||||
|
|
||||||
/**
|
|
||||||
* Registration time
|
|
||||||
*/
|
|
||||||
time_t regtime;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Document type, to implement generic objects.
|
* Document type, to implement generic objects.
|
||||||
*/
|
*/
|
||||||
|
@ -27,7 +27,7 @@ class DocumentPool : public PoolSQL
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
DocumentPool(SqlDB * db) : PoolSQL(db, Document::table, true){};
|
DocumentPool(SqlDB * db) : PoolSQL(db, Document::table, false){};
|
||||||
|
|
||||||
~DocumentPool(){};
|
~DocumentPool(){};
|
||||||
|
|
||||||
@ -52,48 +52,26 @@ public:
|
|||||||
int type,
|
int type,
|
||||||
Template * template_contents,
|
Template * template_contents,
|
||||||
int * oid,
|
int * oid,
|
||||||
string& error_str);
|
string& error_str)
|
||||||
|
{
|
||||||
|
*oid = PoolSQL::allocate(
|
||||||
|
new Document(-1, uid, gid, uname, gname, type, template_contents),
|
||||||
|
error_str);
|
||||||
|
|
||||||
|
return *oid;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets an object from the pool (if needed the object is loaded from the
|
* Gets an object from the pool (if needed the object is loaded from the
|
||||||
* database).
|
* database).
|
||||||
* @param oid the object unique identifier
|
* @param oid the object unique identifier
|
||||||
* @param type the document type
|
|
||||||
* @param lock locks the object if true
|
* @param lock locks the object if true
|
||||||
*
|
*
|
||||||
* @return a pointer to the object, 0 in case of failure
|
* @return a pointer to the object, 0 in case of failure
|
||||||
*/
|
*/
|
||||||
Document * get(int oid, int type, bool lock)
|
Document * get(int oid, bool lock)
|
||||||
{
|
{
|
||||||
Document* tmpl = static_cast<Document *>(PoolSQL::get(oid,lock));
|
return static_cast<Document *>(PoolSQL::get(oid,lock));
|
||||||
|
|
||||||
if ( tmpl != 0 && tmpl->get_document_type() != type )
|
|
||||||
{
|
|
||||||
if ( lock )
|
|
||||||
{
|
|
||||||
tmpl->unlock();
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return tmpl;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets an object from the pool (if needed the object is loaded from the
|
|
||||||
* database).
|
|
||||||
* @param name of the object
|
|
||||||
* @param uid id of owner
|
|
||||||
* @param type the document type
|
|
||||||
* @param lock locks the object if true
|
|
||||||
*
|
|
||||||
* @return a pointer to the object, 0 in case of failure
|
|
||||||
*/
|
|
||||||
Document * get(const string& name, int uid, int type, bool lock)
|
|
||||||
{
|
|
||||||
// TODO: use type
|
|
||||||
return static_cast<Document *>(PoolSQL::get(name,uid,lock));
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -30,9 +30,8 @@ class RequestManagerChmod : public Request
|
|||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
RequestManagerChmod(const string& method_name,
|
RequestManagerChmod(const string& method_name,
|
||||||
const string& help,
|
const string& help)
|
||||||
const string& params = "A:siiiiiiiiii")
|
:Request(method_name, "A:siiiiiiiiii", help){};
|
||||||
:Request(method_name,params,help){};
|
|
||||||
|
|
||||||
~RequestManagerChmod(){};
|
~RequestManagerChmod(){};
|
||||||
|
|
||||||
@ -40,12 +39,6 @@ protected:
|
|||||||
|
|
||||||
virtual void request_execute(xmlrpc_c::paramList const& _paramList,
|
virtual void request_execute(xmlrpc_c::paramList const& _paramList,
|
||||||
RequestAttributes& att);
|
RequestAttributes& att);
|
||||||
|
|
||||||
virtual PoolObjectSQL * get_obj(
|
|
||||||
int oid, xmlrpc_c::paramList const& paramList)
|
|
||||||
{
|
|
||||||
return pool->get(oid,true);
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------- */
|
/* ------------------------------------------------------------------------- */
|
||||||
@ -149,8 +142,7 @@ class DocumentChmod : public RequestManagerChmod
|
|||||||
public:
|
public:
|
||||||
DocumentChmod():
|
DocumentChmod():
|
||||||
RequestManagerChmod("DocumentChmod",
|
RequestManagerChmod("DocumentChmod",
|
||||||
"Changes permission bits of a generic document",
|
"Changes permission bits of a generic document")
|
||||||
"A:siiiiiiiiiii")
|
|
||||||
{
|
{
|
||||||
Nebula& nd = Nebula::instance();
|
Nebula& nd = Nebula::instance();
|
||||||
pool = nd.get_docpool();
|
pool = nd.get_docpool();
|
||||||
@ -158,16 +150,8 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
~DocumentChmod(){};
|
~DocumentChmod(){};
|
||||||
|
|
||||||
/* -------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
PoolObjectSQL * get_obj(int oid, xmlrpc_c::paramList const& paramList)
|
|
||||||
{
|
|
||||||
int obj_type = xmlrpc_c::value_int(paramList.getInt(11));
|
|
||||||
|
|
||||||
return static_cast<DocumentPool*>(pool)->get(oid, obj_type, true);
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
|
@ -52,13 +52,6 @@ protected:
|
|||||||
|
|
||||||
virtual void request_execute(xmlrpc_c::paramList const& _paramList,
|
virtual void request_execute(xmlrpc_c::paramList const& _paramList,
|
||||||
RequestAttributes& att);
|
RequestAttributes& att);
|
||||||
|
|
||||||
|
|
||||||
virtual PoolObjectSQL * get_obj(
|
|
||||||
int oid, xmlrpc_c::paramList const& paramList)
|
|
||||||
{
|
|
||||||
return pool->get(oid,true);
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------- */
|
/* ------------------------------------------------------------------------- */
|
||||||
@ -196,15 +189,6 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
~DocumentChown(){};
|
~DocumentChown(){};
|
||||||
|
|
||||||
/* -------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
PoolObjectSQL * get_obj(int oid, xmlrpc_c::paramList const& paramList)
|
|
||||||
{
|
|
||||||
int obj_type = xmlrpc_c::value_int(paramList.getInt(4));
|
|
||||||
|
|
||||||
return static_cast<DocumentPool*>(pool)->get(oid, obj_type, true);
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
|
@ -42,12 +42,6 @@ protected:
|
|||||||
virtual void request_execute(xmlrpc_c::paramList const& _paramList,
|
virtual void request_execute(xmlrpc_c::paramList const& _paramList,
|
||||||
RequestAttributes& att);
|
RequestAttributes& att);
|
||||||
|
|
||||||
virtual PoolObjectSQL * get_obj(
|
|
||||||
int oid, xmlrpc_c::paramList const& paramList)
|
|
||||||
{
|
|
||||||
return pool->get(oid,true);
|
|
||||||
};
|
|
||||||
|
|
||||||
virtual Template * clone_template(PoolObjectSQL* obj) = 0;
|
virtual Template * clone_template(PoolObjectSQL* obj) = 0;
|
||||||
|
|
||||||
virtual int pool_allocate(
|
virtual int pool_allocate(
|
||||||
|
@ -50,17 +50,10 @@ protected:
|
|||||||
RequestAttributes& att);
|
RequestAttributes& att);
|
||||||
|
|
||||||
bool delete_authorization(int oid,
|
bool delete_authorization(int oid,
|
||||||
RequestAttributes& att,
|
RequestAttributes& att);
|
||||||
xmlrpc_c::paramList const& paramList);
|
|
||||||
|
|
||||||
/* -------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------- */
|
||||||
|
|
||||||
virtual PoolObjectSQL * get_obj(
|
|
||||||
int oid, xmlrpc_c::paramList const& paramList)
|
|
||||||
{
|
|
||||||
return pool->get(oid,true);
|
|
||||||
};
|
|
||||||
|
|
||||||
virtual int drop(int oid, PoolObjectSQL * object, string& error_msg);
|
virtual int drop(int oid, PoolObjectSQL * object, string& error_msg);
|
||||||
|
|
||||||
virtual int get_cluster_id(PoolObjectSQL * object)
|
virtual int get_cluster_id(PoolObjectSQL * object)
|
||||||
@ -295,15 +288,6 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
~DocumentDelete(){};
|
~DocumentDelete(){};
|
||||||
|
|
||||||
/* -------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
PoolObjectSQL * get_obj(int oid, xmlrpc_c::paramList const& paramList)
|
|
||||||
{
|
|
||||||
int obj_type = xmlrpc_c::value_int(paramList.getInt(2));
|
|
||||||
|
|
||||||
return static_cast<DocumentPool*>(pool)->get(oid, obj_type, true);
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
|
@ -50,12 +50,6 @@ protected:
|
|||||||
{
|
{
|
||||||
object->to_xml(str);
|
object->to_xml(str);
|
||||||
};
|
};
|
||||||
|
|
||||||
virtual PoolObjectSQL * get_obj(
|
|
||||||
int oid, xmlrpc_c::paramList const& paramList)
|
|
||||||
{
|
|
||||||
return pool->get(oid,true);
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------- */
|
/* ------------------------------------------------------------------------- */
|
||||||
@ -255,15 +249,6 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
~DocumentInfo(){};
|
~DocumentInfo(){};
|
||||||
|
|
||||||
/* -------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
PoolObjectSQL * get_obj(int oid, xmlrpc_c::paramList const& paramList)
|
|
||||||
{
|
|
||||||
int obj_type = xmlrpc_c::value_int(paramList.getInt(2));
|
|
||||||
|
|
||||||
return static_cast<DocumentPool*>(pool)->get(oid, obj_type, true);
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
|
@ -43,12 +43,6 @@ protected:
|
|||||||
|
|
||||||
void request_execute(xmlrpc_c::paramList const& _paramList,
|
void request_execute(xmlrpc_c::paramList const& _paramList,
|
||||||
RequestAttributes& att);
|
RequestAttributes& att);
|
||||||
|
|
||||||
virtual PoolObjectSQL * get_obj(
|
|
||||||
int oid, xmlrpc_c::paramList const& paramList)
|
|
||||||
{
|
|
||||||
return pool->get(oid,true);
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------- */
|
/* ------------------------------------------------------------------------- */
|
||||||
@ -176,15 +170,6 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
~DocumentUpdateTemplate(){};
|
~DocumentUpdateTemplate(){};
|
||||||
|
|
||||||
/* -------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
PoolObjectSQL * get_obj(int oid, xmlrpc_c::paramList const& paramList)
|
|
||||||
{
|
|
||||||
int obj_type = xmlrpc_c::value_int(paramList.getInt(3));
|
|
||||||
|
|
||||||
return static_cast<DocumentPool*>(pool)->get(oid, obj_type, true);
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
|
@ -27,6 +27,28 @@ const long long AclRule::ALL_ID = 0x0000000400000000LL;
|
|||||||
|
|
||||||
const long long AclRule::NONE_ID = 0x1000000000000000LL;
|
const long long AclRule::NONE_ID = 0x1000000000000000LL;
|
||||||
|
|
||||||
|
const int AclRule::num_pool_objects = 10;
|
||||||
|
const PoolObjectSQL::ObjectType AclRule::pool_objects[] = {
|
||||||
|
PoolObjectSQL::VM,
|
||||||
|
PoolObjectSQL::HOST,
|
||||||
|
PoolObjectSQL::NET,
|
||||||
|
PoolObjectSQL::IMAGE,
|
||||||
|
PoolObjectSQL::USER,
|
||||||
|
PoolObjectSQL::TEMPLATE,
|
||||||
|
PoolObjectSQL::GROUP,
|
||||||
|
PoolObjectSQL::DATASTORE,
|
||||||
|
PoolObjectSQL::CLUSTER,
|
||||||
|
PoolObjectSQL::DOCUMENT
|
||||||
|
};
|
||||||
|
|
||||||
|
const int AclRule::num_auth_operations = 4;
|
||||||
|
const AuthRequest::Operation AclRule::auth_operations[] = {
|
||||||
|
AuthRequest::USE,
|
||||||
|
AuthRequest::MANAGE,
|
||||||
|
AuthRequest::ADMIN,
|
||||||
|
AuthRequest::CREATE
|
||||||
|
};
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
|
|
||||||
@ -246,32 +268,18 @@ void AclRule::build_str()
|
|||||||
|
|
||||||
oss << " ";
|
oss << " ";
|
||||||
|
|
||||||
int n_objects = 10;
|
|
||||||
PoolObjectSQL::ObjectType objects[] = {
|
|
||||||
PoolObjectSQL::VM,
|
|
||||||
PoolObjectSQL::HOST,
|
|
||||||
PoolObjectSQL::NET,
|
|
||||||
PoolObjectSQL::IMAGE,
|
|
||||||
PoolObjectSQL::USER,
|
|
||||||
PoolObjectSQL::TEMPLATE,
|
|
||||||
PoolObjectSQL::GROUP,
|
|
||||||
PoolObjectSQL::DATASTORE,
|
|
||||||
PoolObjectSQL::CLUSTER,
|
|
||||||
PoolObjectSQL::DOCUMENT
|
|
||||||
};
|
|
||||||
|
|
||||||
bool prefix = false;
|
bool prefix = false;
|
||||||
|
|
||||||
for ( int i = 0; i < n_objects; i++ )
|
for ( int i = 0; i < num_pool_objects; i++ )
|
||||||
{
|
{
|
||||||
if ( (resource & objects[i]) != 0 )
|
if ( (resource & pool_objects[i]) != 0 )
|
||||||
{
|
{
|
||||||
if ( prefix )
|
if ( prefix )
|
||||||
{
|
{
|
||||||
oss << "+";
|
oss << "+";
|
||||||
}
|
}
|
||||||
|
|
||||||
oss << PoolObjectSQL::type_to_str( objects[i] );
|
oss << PoolObjectSQL::type_to_str( pool_objects[i] );
|
||||||
prefix = true;
|
prefix = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -295,29 +303,20 @@ void AclRule::build_str()
|
|||||||
oss << "??";
|
oss << "??";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
oss << " ";
|
oss << " ";
|
||||||
|
|
||||||
|
|
||||||
AuthRequest::Operation operations[] = {
|
|
||||||
AuthRequest::USE,
|
|
||||||
AuthRequest::MANAGE,
|
|
||||||
AuthRequest::ADMIN,
|
|
||||||
AuthRequest::CREATE
|
|
||||||
};
|
|
||||||
|
|
||||||
prefix = false;
|
prefix = false;
|
||||||
|
|
||||||
for ( int i = 0; i < 4; i++ )
|
for ( int i = 0; i < num_auth_operations; i++ )
|
||||||
{
|
{
|
||||||
if ( (rights & operations[i]) != 0 )
|
if ( (rights & auth_operations[i]) != 0 )
|
||||||
{
|
{
|
||||||
if ( prefix )
|
if ( prefix )
|
||||||
{
|
{
|
||||||
oss << "+";
|
oss << "+";
|
||||||
}
|
}
|
||||||
|
|
||||||
oss << AuthRequest::operation_to_str( operations[i] );
|
oss << AuthRequest::operation_to_str( auth_operations[i] );
|
||||||
prefix = true;
|
prefix = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -399,4 +398,3 @@ int AclRule::from_xml(xmlNodePtr node)
|
|||||||
|
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
@ -27,9 +27,7 @@ Document::Document( int id,
|
|||||||
const string& _gname,
|
const string& _gname,
|
||||||
int _type,
|
int _type,
|
||||||
Template * _template_contents):
|
Template * _template_contents):
|
||||||
PoolObjectSQL(id,DOCUMENT,"",_uid,_gid,_uname,_gname,table),
|
PoolObjectSQL(id,DOCUMENT,"",_uid,_gid,_uname,_gname,table), type(_type)
|
||||||
regtime(time(0)),
|
|
||||||
type(_type)
|
|
||||||
{
|
{
|
||||||
if (_template_contents != 0)
|
if (_template_contents != 0)
|
||||||
{
|
{
|
||||||
@ -64,8 +62,7 @@ const char * Document::db_names =
|
|||||||
const char * Document::db_bootstrap =
|
const char * Document::db_bootstrap =
|
||||||
"CREATE TABLE IF NOT EXISTS document_pool (oid INTEGER PRIMARY KEY, "
|
"CREATE TABLE IF NOT EXISTS document_pool (oid INTEGER PRIMARY KEY, "
|
||||||
"name VARCHAR(128), body TEXT, type INTEGER, uid INTEGER, gid INTEGER, "
|
"name VARCHAR(128), body TEXT, type INTEGER, uid INTEGER, gid INTEGER, "
|
||||||
"owner_u INTEGER, group_u INTEGER, other_u INTEGER,"
|
"owner_u INTEGER, group_u INTEGER, other_u INTEGER)";
|
||||||
"UNIQUE(name,uid,type))";
|
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------ */
|
/* ------------------------------------------------------------------------ */
|
||||||
/* ------------------------------------------------------------------------ */
|
/* ------------------------------------------------------------------------ */
|
||||||
@ -204,7 +201,6 @@ string& Document::to_xml(string& xml) const
|
|||||||
<< "<NAME>" << name << "</NAME>"
|
<< "<NAME>" << name << "</NAME>"
|
||||||
<< "<TYPE>" << type << "</TYPE>"
|
<< "<TYPE>" << type << "</TYPE>"
|
||||||
<< perms_to_xml(perm_str)
|
<< perms_to_xml(perm_str)
|
||||||
<< "<REGTIME>" << regtime << "</REGTIME>"
|
|
||||||
<< obj_template->to_xml(template_xml)
|
<< obj_template->to_xml(template_xml)
|
||||||
<< "</DOCUMENT>";
|
<< "</DOCUMENT>";
|
||||||
|
|
||||||
@ -232,7 +228,6 @@ int Document::from_xml(const string& xml)
|
|||||||
rc += xpath(gname, "/DOCUMENT/GNAME", "not_found");
|
rc += xpath(gname, "/DOCUMENT/GNAME", "not_found");
|
||||||
rc += xpath(name, "/DOCUMENT/NAME", "not_found");
|
rc += xpath(name, "/DOCUMENT/NAME", "not_found");
|
||||||
rc += xpath(type, "/DOCUMENT/TYPE", 0);
|
rc += xpath(type, "/DOCUMENT/TYPE", 0);
|
||||||
rc += xpath(regtime, "/DOCUMENT/REGTIME", 0);
|
|
||||||
|
|
||||||
// Permissions
|
// Permissions
|
||||||
rc += perms_from_xml();
|
rc += perms_from_xml();
|
||||||
|
@ -1,80 +0,0 @@
|
|||||||
/* -------------------------------------------------------------------------- */
|
|
||||||
/* Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) */
|
|
||||||
/* */
|
|
||||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
|
||||||
/* not use this file except in compliance with the License. You may obtain */
|
|
||||||
/* a copy of the License at */
|
|
||||||
/* */
|
|
||||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
|
||||||
/* */
|
|
||||||
/* Unless required by applicable law or agreed to in writing, software */
|
|
||||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
|
||||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
|
||||||
/* See the License for the specific language governing permissions and */
|
|
||||||
/* limitations under the License. */
|
|
||||||
/* -------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
/* ************************************************************************** */
|
|
||||||
/* Document Pool */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "DocumentPool.h"
|
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------- */
|
|
||||||
/* -------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
int DocumentPool::allocate (
|
|
||||||
int uid,
|
|
||||||
int gid,
|
|
||||||
const string& uname,
|
|
||||||
const string& gname,
|
|
||||||
int type,
|
|
||||||
Template * template_contents,
|
|
||||||
int * oid,
|
|
||||||
string& error_str)
|
|
||||||
{
|
|
||||||
Document * document;
|
|
||||||
Document * document_aux = 0;
|
|
||||||
string name;
|
|
||||||
ostringstream oss;
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------
|
|
||||||
// Build a new Document object
|
|
||||||
// ------------------------------------------------------------------------
|
|
||||||
document = new Document(-1, uid, gid, uname, gname,
|
|
||||||
type, template_contents);
|
|
||||||
|
|
||||||
// Check name
|
|
||||||
document->get_template_attribute("NAME", name);
|
|
||||||
|
|
||||||
if ( !name.empty() )
|
|
||||||
{
|
|
||||||
// Check for duplicates
|
|
||||||
document_aux = get(name, uid, type, false);
|
|
||||||
|
|
||||||
if( document_aux != 0 )
|
|
||||||
{
|
|
||||||
goto error_duplicated;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------
|
|
||||||
// Insert the Object in the pool
|
|
||||||
// ------------------------------------------------------------------------
|
|
||||||
|
|
||||||
*oid = PoolSQL::allocate(document, error_str);
|
|
||||||
|
|
||||||
return *oid;
|
|
||||||
|
|
||||||
|
|
||||||
error_duplicated:
|
|
||||||
oss << "NAME is already taken by DOCUMENT "
|
|
||||||
<< document_aux->get_oid() << ".";
|
|
||||||
|
|
||||||
delete document;
|
|
||||||
|
|
||||||
*oid = -1;
|
|
||||||
error_str = oss.str();
|
|
||||||
|
|
||||||
return *oid;
|
|
||||||
}
|
|
@ -22,8 +22,7 @@ lib_name='nebula_document'
|
|||||||
|
|
||||||
# Sources to generate the library
|
# Sources to generate the library
|
||||||
source_files=[
|
source_files=[
|
||||||
'Document.cc',
|
'Document.cc'
|
||||||
'DocumentPool.cc'
|
|
||||||
]
|
]
|
||||||
|
|
||||||
# Build library
|
# Build library
|
||||||
|
@ -139,7 +139,7 @@ module OpenNebula
|
|||||||
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
||||||
# otherwise
|
# otherwise
|
||||||
def chown(uid, gid)
|
def chown(uid, gid)
|
||||||
super(DOCUMENT_METHODS[:chown], uid, gid, TYPE)
|
super(DOCUMENT_METHODS[:chown], uid, gid)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Changes the Document permissions.
|
# Changes the Document permissions.
|
||||||
@ -149,7 +149,7 @@ module OpenNebula
|
|||||||
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
||||||
# otherwise
|
# otherwise
|
||||||
def chmod_octet(octet)
|
def chmod_octet(octet)
|
||||||
super(DOCUMENT_METHODS[:chmod], octet, TYPE)
|
super(DOCUMENT_METHODS[:chmod], octet)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Changes the Document permissions.
|
# Changes the Document permissions.
|
||||||
@ -160,7 +160,7 @@ module OpenNebula
|
|||||||
def chmod(owner_u, owner_m, owner_a, group_u, group_m, group_a, other_u,
|
def chmod(owner_u, owner_m, owner_a, group_u, group_m, group_a, other_u,
|
||||||
other_m, other_a)
|
other_m, other_a)
|
||||||
super(DOCUMENT_METHODS[:chmod], owner_u, owner_m, owner_a, group_u,
|
super(DOCUMENT_METHODS[:chmod], owner_u, owner_m, owner_a, group_u,
|
||||||
group_m, group_a, other_u, other_m, other_a, TYPE)
|
group_m, group_a, other_u, other_m, other_a)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Clones this Document into a new one
|
# Clones this Document into a new one
|
||||||
|
@ -270,12 +270,11 @@ module OpenNebula
|
|||||||
# @param [String] xml_method the name of the XML-RPC method
|
# @param [String] xml_method the name of the XML-RPC method
|
||||||
# @param [Integer] uid the new owner id. Set to -1 to leave the current one
|
# @param [Integer] uid the new owner id. Set to -1 to leave the current one
|
||||||
# @param [Integer] gid the new goup id. Set to -1 to leave the current one
|
# @param [Integer] gid the new goup id. Set to -1 to leave the current one
|
||||||
# @param [Array] args any extra arguments for the xml-rpc method
|
|
||||||
#
|
#
|
||||||
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
||||||
# otherwise
|
# otherwise
|
||||||
def chown(xml_method, uid, gid, *args)
|
def chown(xml_method, uid, gid)
|
||||||
return call(xml_method, @pe_id, uid, gid, *args)
|
return call(xml_method, @pe_id, uid, gid)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Calls to the corresponding chmod method to modify
|
# Calls to the corresponding chmod method to modify
|
||||||
@ -286,7 +285,7 @@ module OpenNebula
|
|||||||
#
|
#
|
||||||
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
||||||
# otherwise
|
# otherwise
|
||||||
def chmod_octet(xml_method, octet, *args)
|
def chmod_octet(xml_method, octet)
|
||||||
owner_u = octet[0..0].to_i & 4 != 0 ? 1 : 0
|
owner_u = octet[0..0].to_i & 4 != 0 ? 1 : 0
|
||||||
owner_m = octet[0..0].to_i & 2 != 0 ? 1 : 0
|
owner_m = octet[0..0].to_i & 2 != 0 ? 1 : 0
|
||||||
owner_a = octet[0..0].to_i & 1 != 0 ? 1 : 0
|
owner_a = octet[0..0].to_i & 1 != 0 ? 1 : 0
|
||||||
@ -298,7 +297,7 @@ module OpenNebula
|
|||||||
other_a = octet[2..2].to_i & 1 != 0 ? 1 : 0
|
other_a = octet[2..2].to_i & 1 != 0 ? 1 : 0
|
||||||
|
|
||||||
chmod(owner_u, owner_m, owner_a, group_u, group_m, group_a, other_u,
|
chmod(owner_u, owner_m, owner_a, group_u, group_m, group_a, other_u,
|
||||||
other_m, other_a, *args)
|
other_m, other_a)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Calls to the corresponding chmod method to modify
|
# Calls to the corresponding chmod method to modify
|
||||||
@ -310,10 +309,10 @@ module OpenNebula
|
|||||||
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
||||||
# otherwise
|
# otherwise
|
||||||
def chmod(xml_method, owner_u, owner_m, owner_a, group_u, group_m, group_a, other_u,
|
def chmod(xml_method, owner_u, owner_m, owner_a, group_u, group_m, group_a, other_u,
|
||||||
other_m, other_a, *args)
|
other_m, other_a)
|
||||||
return call(xml_method, @pe_id, owner_u, owner_m,
|
return call(xml_method, @pe_id, owner_u, owner_m,
|
||||||
owner_a, group_u, group_m, group_a, other_u,
|
owner_a, group_u, group_m, group_a, other_u,
|
||||||
other_m, other_a, *args)
|
other_m, other_a)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -144,7 +144,7 @@ module Migrator
|
|||||||
|
|
||||||
@db.run "DROP TABLE old_history;"
|
@db.run "DROP TABLE old_history;"
|
||||||
|
|
||||||
@db.run "CREATE TABLE document_pool (oid INTEGER PRIMARY KEY, name VARCHAR(128), body TEXT, type INTEGER, uid INTEGER, gid INTEGER, owner_u INTEGER, group_u INTEGER, other_u INTEGER, UNIQUE(name,uid,type));"
|
@db.run "CREATE TABLE document_pool (oid INTEGER PRIMARY KEY, name VARCHAR(128), body TEXT, type INTEGER, uid INTEGER, gid INTEGER, owner_u INTEGER, group_u INTEGER, other_u INTEGER);"
|
||||||
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
@ -49,7 +49,7 @@ void RequestManagerChmod::request_execute(xmlrpc_c::paramList const& paramList,
|
|||||||
AuthRequest::Operation op = AuthRequest::MANAGE;
|
AuthRequest::Operation op = AuthRequest::MANAGE;
|
||||||
PoolObjectAuth perms;
|
PoolObjectAuth perms;
|
||||||
|
|
||||||
object = get_obj(oid, paramList);
|
object = pool->get(oid,true);
|
||||||
|
|
||||||
if ( object == 0 )
|
if ( object == 0 )
|
||||||
{
|
{
|
||||||
@ -128,7 +128,7 @@ void RequestManagerChmod::request_execute(xmlrpc_c::paramList const& paramList,
|
|||||||
|
|
||||||
// ------------- Update the object ---------------------
|
// ------------- Update the object ---------------------
|
||||||
|
|
||||||
object = get_obj(oid, paramList);
|
object = pool->get(oid,true);
|
||||||
|
|
||||||
if ( object == 0 )
|
if ( object == 0 )
|
||||||
{
|
{
|
||||||
|
@ -104,7 +104,7 @@ void RequestManagerChown::request_execute(xmlrpc_c::paramList const& paramList,
|
|||||||
|
|
||||||
// ------------- Update the object ---------------------
|
// ------------- Update the object ---------------------
|
||||||
|
|
||||||
object = get_obj(oid, paramList);
|
object = pool->get(oid,true);
|
||||||
|
|
||||||
if ( object == 0 )
|
if ( object == 0 )
|
||||||
{
|
{
|
||||||
|
@ -37,7 +37,7 @@ void RequestManagerClone::request_execute(
|
|||||||
|
|
||||||
string error_str;
|
string error_str;
|
||||||
|
|
||||||
source_obj = get_obj(source_id, paramList);
|
source_obj = pool->get(source_id, true);
|
||||||
|
|
||||||
if ( source_obj == 0 )
|
if ( source_obj == 0 )
|
||||||
{
|
{
|
||||||
|
@ -23,8 +23,7 @@ using namespace std;
|
|||||||
|
|
||||||
bool RequestManagerDelete::delete_authorization(
|
bool RequestManagerDelete::delete_authorization(
|
||||||
int oid,
|
int oid,
|
||||||
RequestAttributes& att,
|
RequestAttributes& att)
|
||||||
xmlrpc_c::paramList const& paramList)
|
|
||||||
{
|
{
|
||||||
PoolObjectSQL * object;
|
PoolObjectSQL * object;
|
||||||
PoolObjectAuth perms;
|
PoolObjectAuth perms;
|
||||||
@ -34,7 +33,7 @@ bool RequestManagerDelete::delete_authorization(
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
object = get_obj(oid, paramList);
|
object = pool->get(oid,true);
|
||||||
|
|
||||||
if ( object == 0 )
|
if ( object == 0 )
|
||||||
{
|
{
|
||||||
@ -74,12 +73,12 @@ void RequestManagerDelete::request_execute(xmlrpc_c::paramList const& paramList,
|
|||||||
PoolObjectSQL * object;
|
PoolObjectSQL * object;
|
||||||
string error_msg;
|
string error_msg;
|
||||||
|
|
||||||
if ( delete_authorization(oid, att, paramList) == false )
|
if ( delete_authorization(oid, att) == false )
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
object = get_obj(oid, paramList);
|
object = pool->get(oid,true);
|
||||||
|
|
||||||
if ( object == 0 )
|
if ( object == 0 )
|
||||||
{
|
{
|
||||||
|
@ -45,7 +45,7 @@ void RequestManagerInfo::request_execute(xmlrpc_c::paramList const& paramList,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
object = get_obj(oid, paramList);
|
object = pool->get(oid,true);
|
||||||
|
|
||||||
if ( object == 0 )
|
if ( object == 0 )
|
||||||
{
|
{
|
||||||
|
@ -38,7 +38,7 @@ void RequestManagerUpdateTemplate::request_execute(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
object = get_obj(oid, paramList);
|
object = pool->get(oid,true);
|
||||||
|
|
||||||
if ( object == 0 )
|
if ( object == 0 )
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user