OmniSciDB  b24e664e58
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Parser::GrantPrivilegesStmt Class Reference

#include <ParserNode.h>

+ Inheritance diagram for Parser::GrantPrivilegesStmt:
+ Collaboration diagram for Parser::GrantPrivilegesStmt:

Public Member Functions

 GrantPrivilegesStmt (std::list< std::string * > *p, std::string *t, std::string *o, std::list< std::string * > *g)
 
const std::vector< std::string > & get_privs () const
 
const std::string & get_object_type () const
 
const std::string & get_object () const
 
const std::vector< std::string > & get_grantees () const
 
void execute (const Catalog_Namespace::SessionInfo &session) override
 
- Public Member Functions inherited from Parser::DDLStmt
void setColumnDescriptor (ColumnDescriptor &cd, const ColumnDef *coldef)
 
- Public Member Functions inherited from Parser::Node
virtual ~Node ()
 

Private Attributes

std::vector< std::string > privs
 
std::unique_ptr< std::string > object_type
 
std::unique_ptr< std::string > object
 
std::vector< std::string > grantees
 

Detailed Description

Definition at line 1462 of file ParserNode.h.

Constructor & Destructor Documentation

Parser::GrantPrivilegesStmt::GrantPrivilegesStmt ( std::list< std::string * > *  p,
std::string *  t,
std::string *  o,
std::list< std::string * > *  g 
)
inline

Definition at line 1464 of file ParserNode.h.

References grantees, Parser::parser_slistval_to_vector(), and privs.

1468  : object_type(t), object(o) {
1471  }
std::unique_ptr< std::string > object
Definition: ParserNode.h:1482
void parser_slistval_to_vector(std::list< std::string * > *l, std::vector< std::string > &v)
Definition: ParserNode.h:1448
std::vector< std::string > grantees
Definition: ParserNode.h:1483
std::vector< std::string > privs
Definition: ParserNode.h:1480
std::unique_ptr< std::string > object_type
Definition: ParserNode.h:1481

+ Here is the call graph for this function:

Member Function Documentation

void Parser::GrantPrivilegesStmt::execute ( const Catalog_Namespace::SessionInfo session)
overridevirtual

Implements Parser::DDLStmt.

Definition at line 3960 of file ParserNode.cpp.

References Parser::createObject(), DBObjectTypeFromString(), Parser::extractObjectNameFromHierName(), Catalog_Namespace::SessionInfo::get_currentUser(), Catalog_Namespace::SessionInfo::getCatalog(), and Parser::parseStringPrivs().

3960  {
3961  auto& catalog = session.getCatalog();
3962  const auto& currentUser = session.get_currentUser();
3963  const auto parserObjectType = boost::to_upper_copy<std::string>(get_object_type());
3964  const auto objectName =
3965  extractObjectNameFromHierName(get_object(), parserObjectType, catalog);
3966  auto objectType = DBObjectTypeFromString(parserObjectType);
3967  DBObject dbObject = createObject(objectName, objectType);
3968  /* verify object ownership if not suser */
3969  if (!currentUser.isSuper) {
3970  if (!SysCatalog::instance().verifyDBObjectOwnership(currentUser, dbObject, catalog)) {
3971  throw std::runtime_error(
3972  "GRANT failed. It can only be executed by super user or owner of the object.");
3973  }
3974  }
3975  /* set proper values of privileges & grant them to the object */
3976  std::vector<DBObject> objects(get_privs().size(), dbObject);
3977  for (size_t i = 0; i < get_privs().size(); ++i) {
3978  std::pair<AccessPrivileges, DBObjectType> priv = parseStringPrivs(
3979  boost::to_upper_copy<std::string>(get_privs()[i]), objectType, get_object());
3980  objects[i].setPrivileges(priv.first);
3981  objects[i].setPermissionType(priv.second);
3982  }
3983  SysCatalog::instance().grantDBObjectPrivilegesBatch(grantees, objects, catalog);
3984 }
std::string extractObjectNameFromHierName(const std::string &objectHierName, const std::string &objectType, const Catalog_Namespace::Catalog &cat)
const std::string & get_object_type() const
Definition: ParserNode.h:1474
DBObjectType DBObjectTypeFromString(const std::string &type)
Definition: DBObject.cpp:88
std::vector< std::string > grantees
Definition: ParserNode.h:1483
Catalog & getCatalog() const
Definition: SessionInfo.h:90
static std::pair< AccessPrivileges, DBObjectType > parseStringPrivs(const std::string &privs, const DBObjectType &objectType, const std::string &object_name)
const std::vector< std::string > & get_privs() const
Definition: ParserNode.h:1473
static DBObject createObject(const std::string &objectName, DBObjectType objectType)
const UserMetadata & get_currentUser() const
Definition: SessionInfo.h:93
const std::string & get_object() const
Definition: ParserNode.h:1475

+ Here is the call graph for this function:

const std::vector<std::string>& Parser::GrantPrivilegesStmt::get_grantees ( ) const
inline

Definition at line 1476 of file ParserNode.h.

References grantees.

1476 { return grantees; }
std::vector< std::string > grantees
Definition: ParserNode.h:1483
const std::string& Parser::GrantPrivilegesStmt::get_object ( ) const
inline

Definition at line 1475 of file ParserNode.h.

References object.

1475 { return *object; }
std::unique_ptr< std::string > object
Definition: ParserNode.h:1482
const std::string& Parser::GrantPrivilegesStmt::get_object_type ( ) const
inline

Definition at line 1474 of file ParserNode.h.

References object_type.

1474 { return *object_type; }
std::unique_ptr< std::string > object_type
Definition: ParserNode.h:1481
const std::vector<std::string>& Parser::GrantPrivilegesStmt::get_privs ( ) const
inline

Definition at line 1473 of file ParserNode.h.

References privs.

1473 { return privs; }
std::vector< std::string > privs
Definition: ParserNode.h:1480

Member Data Documentation

std::vector<std::string> Parser::GrantPrivilegesStmt::grantees
private

Definition at line 1483 of file ParserNode.h.

Referenced by get_grantees(), and GrantPrivilegesStmt().

std::unique_ptr<std::string> Parser::GrantPrivilegesStmt::object
private

Definition at line 1482 of file ParserNode.h.

Referenced by get_object().

std::unique_ptr<std::string> Parser::GrantPrivilegesStmt::object_type
private

Definition at line 1481 of file ParserNode.h.

Referenced by get_object_type().

std::vector<std::string> Parser::GrantPrivilegesStmt::privs
private

Definition at line 1480 of file ParserNode.h.

Referenced by get_privs(), and GrantPrivilegesStmt().


The documentation for this class was generated from the following files: