OmniSciDB  eb3a3d0a03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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)
 
 GrantPrivilegesStmt (const rapidjson::Value &payload)
 
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 > privileges_
 
std::unique_ptr< std::string > type_
 
std::unique_ptr< std::string > target_
 
std::vector< std::string > grantees_
 

Detailed Description

Definition at line 1562 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 1564 of file ParserNode.h.

References grantees_, Parser::parser_slistval_to_vector(), and privileges_.

1568  : type_(t), target_(o) {
1571  }
std::vector< std::string > privileges_
Definition: ParserNode.h:1581
std::unique_ptr< std::string > target_
Definition: ParserNode.h:1583
void parser_slistval_to_vector(std::list< std::string * > *l, std::vector< std::string > &v)
Definition: ParserNode.h:1548
std::vector< std::string > grantees_
Definition: ParserNode.h:1584
std::unique_ptr< std::string > type_
Definition: ParserNode.h:1582
char * t

+ Here is the call graph for this function:

Parser::GrantPrivilegesStmt::GrantPrivilegesStmt ( const rapidjson::Value &  payload)

Definition at line 5277 of file ParserNode.cpp.

References CHECK, grantees_, json_str(), privileges_, target_, and type_.

5277  {
5278  CHECK(payload.HasMember("type"));
5279  type_ = std::make_unique<std::string>(json_str(payload["type"]));
5280 
5281  CHECK(payload.HasMember("target"));
5282  target_ = std::make_unique<std::string>(json_str(payload["target"]));
5283 
5284  if (payload.HasMember("privileges")) {
5285  CHECK(payload["privileges"].IsArray());
5286  for (auto& privilege : payload["privileges"].GetArray()) {
5287  auto r = json_str(privilege);
5288  // privilege was a StringLiteral
5289  // and is wrapped with quotes which need to get removed
5290  boost::algorithm::trim_if(r, boost::is_any_of(" \"'`"));
5291  privileges_.emplace_back(r);
5292  }
5293  }
5294  if (payload.HasMember("grantees")) {
5295  CHECK(payload["grantees"].IsArray());
5296  for (auto& grantee : payload["grantees"].GetArray()) {
5297  std::string g = json_str(grantee);
5298  grantees_.emplace_back(g);
5299  }
5300  }
5301 }
std::vector< std::string > privileges_
Definition: ParserNode.h:1581
std::unique_ptr< std::string > target_
Definition: ParserNode.h:1583
const std::string json_str(const rapidjson::Value &obj) noexcept
Definition: JsonAccessors.h:44
std::vector< std::string > grantees_
Definition: ParserNode.h:1584
std::unique_ptr< std::string > type_
Definition: ParserNode.h:1582
#define CHECK(condition)
Definition: Logger.h:209

+ 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 5303 of file ParserNode.cpp.

References Parser::createObject(), DBObjectTypeFromString(), Parser::extractObjectNameFromHierName(), g_enable_fsi, Catalog_Namespace::SessionInfo::get_currentUser(), get_object(), get_object_type(), get_privs(), Catalog_Namespace::SessionInfo::getCatalog(), grantees_, i, Parser::parseStringPrivs(), ServerDBObjectType, and Parser::verifyObject().

Referenced by omnisci.cursor.Cursor::executemany().

5303  {
5304  auto& catalog = session.getCatalog();
5305  const auto& currentUser = session.get_currentUser();
5306  const auto parserObjectType = boost::to_upper_copy<std::string>(get_object_type());
5307  const auto objectName =
5308  extractObjectNameFromHierName(get_object(), parserObjectType, catalog);
5309  auto objectType = DBObjectTypeFromString(parserObjectType);
5310  if (objectType == ServerDBObjectType && !g_enable_fsi) {
5311  throw std::runtime_error("GRANT failed. SERVER object unrecognized.");
5312  }
5313  /* verify object exists and is of proper type *before* trying to execute */
5314  verifyObject(catalog, objectName, objectType, "GRANT");
5315 
5316  DBObject dbObject = createObject(objectName, objectType);
5317  /* verify object ownership if not suser */
5318  if (!currentUser.isSuper) {
5319  if (!SysCatalog::instance().verifyDBObjectOwnership(currentUser, dbObject, catalog)) {
5320  throw std::runtime_error(
5321  "GRANT failed. It can only be executed by super user or owner of the "
5322  "object.");
5323  }
5324  }
5325  /* set proper values of privileges & grant them to the object */
5326  std::vector<DBObject> objects(get_privs().size(), dbObject);
5327  for (size_t i = 0; i < get_privs().size(); ++i) {
5328  std::pair<AccessPrivileges, DBObjectType> priv = parseStringPrivs(
5329  boost::to_upper_copy<std::string>(get_privs()[i]), objectType, get_object());
5330  objects[i].setPrivileges(priv.first);
5331  objects[i].setPermissionType(priv.second);
5332  if (priv.second == ServerDBObjectType && !g_enable_fsi) {
5333  throw std::runtime_error("GRANT failed. SERVER object unrecognized.");
5334  }
5335  }
5336  SysCatalog::instance().grantDBObjectPrivilegesBatch(grantees_, objects, catalog);
5337 }
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:1575
DBObjectType DBObjectTypeFromString(const std::string &type)
Definition: DBObject.cpp:101
std::vector< std::string > grantees_
Definition: ParserNode.h:1584
Catalog & getCatalog() const
Definition: SessionInfo.h:67
static std::pair< AccessPrivileges, DBObjectType > parseStringPrivs(const std::string &privs, const DBObjectType &objectType, const std::string &object_name)
static void verifyObject(Catalog_Namespace::Catalog &sessionCatalog, const std::string &objectName, DBObjectType objectType, const std::string &command)
const std::vector< std::string > & get_privs() const
Definition: ParserNode.h:1574
static DBObject createObject(const std::string &objectName, DBObjectType objectType)
bool g_enable_fsi
Definition: Catalog.cpp:93
const UserMetadata & get_currentUser() const
Definition: SessionInfo.h:73
const std::string & get_object() const
Definition: ParserNode.h:1576

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 1577 of file ParserNode.h.

References grantees_.

1577 { return grantees_; }
std::vector< std::string > grantees_
Definition: ParserNode.h:1584
const std::string& Parser::GrantPrivilegesStmt::get_object ( ) const
inline

Definition at line 1576 of file ParserNode.h.

References target_.

Referenced by execute().

1576 { return *target_; }
std::unique_ptr< std::string > target_
Definition: ParserNode.h:1583

+ Here is the caller graph for this function:

const std::string& Parser::GrantPrivilegesStmt::get_object_type ( ) const
inline

Definition at line 1575 of file ParserNode.h.

References type_.

Referenced by execute().

1575 { return *type_; }
std::unique_ptr< std::string > type_
Definition: ParserNode.h:1582

+ Here is the caller graph for this function:

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

Definition at line 1574 of file ParserNode.h.

References privileges_.

Referenced by execute().

1574 { return privileges_; }
std::vector< std::string > privileges_
Definition: ParserNode.h:1581

+ Here is the caller graph for this function:

Member Data Documentation

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

Definition at line 1584 of file ParserNode.h.

Referenced by execute(), get_grantees(), and GrantPrivilegesStmt().

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

Definition at line 1581 of file ParserNode.h.

Referenced by get_privs(), and GrantPrivilegesStmt().

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

Definition at line 1583 of file ParserNode.h.

Referenced by get_object(), and GrantPrivilegesStmt().

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

Definition at line 1582 of file ParserNode.h.

Referenced by get_object_type(), and GrantPrivilegesStmt().


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