OmniSciDB  c1a53651b2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Parser::AlterUserStmt Class Reference

#include <ParserNode.h>

+ Inheritance diagram for Parser::AlterUserStmt:
+ Collaboration diagram for Parser::AlterUserStmt:

Public Member Functions

 AlterUserStmt (const rapidjson::Value &payload)
 
 AlterUserStmt (std::string *n, std::list< NameValueAssign * > *l)
 
void execute (const Catalog_Namespace::SessionInfo &session, bool read_only_mode) 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::unique_ptr< std::string > user_name_
 
std::list< std::unique_ptr
< NameValueAssign > > 
options_
 

Detailed Description

Definition at line 1994 of file ParserNode.h.

Constructor & Destructor Documentation

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

Definition at line 6688 of file ParserNode.cpp.

References CHECK, json_str(), options_, Parser::anonymous_namespace{ParserNode.cpp}::parse_options(), and user_name_.

6688  {
6689  CHECK(payload.HasMember("name"));
6690  user_name_ = std::make_unique<std::string>(json_str(payload["name"]));
6691 
6692  parse_options(payload, options_, true, false);
6693 }
std::unique_ptr< std::string > user_name_
Definition: ParserNode.h:2009
std::list< std::unique_ptr< NameValueAssign > > options_
Definition: ParserNode.h:2010
const std::string json_str(const rapidjson::Value &obj) noexcept
Definition: JsonAccessors.h:44
void parse_options(const rapidjson::Value &payload, std::list< std::unique_ptr< NameValueAssign >> &nameValueList, bool stringToNull=false, bool stringToInteger=false)
#define CHECK(condition)
Definition: Logger.h:291

+ Here is the call graph for this function:

Parser::AlterUserStmt::AlterUserStmt ( std::string *  n,
std::list< NameValueAssign * > *  l 
)
inline

Definition at line 1997 of file ParserNode.h.

References options_.

1997  : user_name_(n) {
1998  if (l) {
1999  for (const auto e : *l) {
2000  options_.emplace_back(e);
2001  }
2002  delete l;
2003  }
2004  }
std::unique_ptr< std::string > user_name_
Definition: ParserNode.h:2009
std::list< std::unique_ptr< NameValueAssign > > options_
Definition: ParserNode.h:2010
constexpr double n
Definition: Utm.h:38

Member Function Documentation

void Parser::AlterUserStmt::execute ( const Catalog_Namespace::SessionInfo session,
bool  read_only_mode 
)
overridevirtual

Implements Parser::DDLStmt.

Definition at line 6695 of file ParserNode.cpp.

References Catalog_Namespace::UserAlterations::can_login, Parser::checkStringLiteral(), Catalog_Namespace::UserAlterations::default_db, Catalog_Namespace::SessionInfo::get_currentUser(), Catalog_Namespace::UserAlterations::is_super, Catalog_Namespace::UserMetadata::isSuper, options_, Catalog_Namespace::UserAlterations::passwd, Parser::readBooleanLiteral(), user_name_, and Catalog_Namespace::UserMetadata::userId.

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

6696  {
6697  if (read_only_mode) {
6698  throw std::runtime_error("ALTER USER invalid in read only mode.");
6699  }
6700  // Parse the statement
6702  for (auto& p : options_) {
6703  if (boost::iequals(*p->get_name(), "password")) {
6704  checkStringLiteral("Password", p);
6705  alts.passwd = *static_cast<const StringLiteral*>(p->get_value())->get_stringval();
6706  } else if (boost::iequals(*p->get_name(), "is_super")) {
6707  checkStringLiteral("IS_SUPER", p);
6708  alts.is_super = readBooleanLiteral("IS_SUPER", p);
6709  } else if (boost::iequals(*p->get_name(), "default_db")) {
6710  if (dynamic_cast<const StringLiteral*>(p->get_value())) {
6711  alts.default_db =
6712  *static_cast<const StringLiteral*>(p->get_value())->get_stringval();
6713  } else if (dynamic_cast<const NullLiteral*>(p->get_value())) {
6714  alts.default_db = "";
6715  } else {
6716  throw std::runtime_error(
6717  "DEFAULT_DB option must be either a string literal or a NULL "
6718  "literal.");
6719  }
6720  } else if (boost::iequals(*p->get_name(), "can_login")) {
6721  alts.can_login = readBooleanLiteral("CAN_LOGIN", p);
6722  } else {
6723  throw std::runtime_error("Invalid ALTER USER option " + *p->get_name() +
6724  ". Should be PASSWORD, DEFAULT_DB, CAN_LOGIN"
6725  " or IS_SUPER.");
6726  }
6727  }
6728 
6729  // Check if the user is authorized to execute ALTER USER statement
6731  if (!SysCatalog::instance().getMetadataForUser(*user_name_, user)) {
6732  throw std::runtime_error("User " + *user_name_ + " does not exist.");
6733  }
6734  if (!session.get_currentUser().isSuper) {
6735  if (session.get_currentUser().userId != user.userId) {
6736  throw std::runtime_error("Only super user can change another user's attributes.");
6737  } else if (alts.is_super || alts.can_login) {
6738  throw std::runtime_error(
6739  "A user can only update their own password or default database.");
6740  }
6741  }
6742 
6743  SysCatalog::instance().alterUser(*user_name_, alts);
6744 }
std::optional< std::string > passwd
Definition: SysCatalog.h:117
std::optional< std::string > default_db
Definition: SysCatalog.h:119
std::unique_ptr< std::string > user_name_
Definition: ParserNode.h:2009
static void checkStringLiteral(const std::string &option_name, const std::unique_ptr< NameValueAssign > &p)
std::list< std::unique_ptr< NameValueAssign > > options_
Definition: ParserNode.h:2010
std::optional< bool > is_super
Definition: SysCatalog.h:118
std::optional< bool > can_login
Definition: SysCatalog.h:120
static bool readBooleanLiteral(const std::string &option_name, const std::unique_ptr< NameValueAssign > &p)
const UserMetadata & get_currentUser() const
Definition: SessionInfo.h:88
std::atomic< bool > isSuper
Definition: SysCatalog.h:107

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

std::list<std::unique_ptr<NameValueAssign> > Parser::AlterUserStmt::options_
private

Definition at line 2010 of file ParserNode.h.

Referenced by AlterUserStmt(), and execute().

std::unique_ptr<std::string> Parser::AlterUserStmt::user_name_
private

Definition at line 2009 of file ParserNode.h.

Referenced by AlterUserStmt(), and execute().


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