OmniSciDB  a5dc49c757
 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 2034 of file ParserNode.h.

Constructor & Destructor Documentation

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

Definition at line 6996 of file ParserNode.cpp.

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

6996  {
6997  CHECK(payload.HasMember("name"));
6998  user_name_ = std::make_unique<std::string>(json_str(payload["name"]));
6999 
7000  parse_options(payload, options_, true, false);
7001 }
std::unique_ptr< std::string > user_name_
Definition: ParserNode.h:2049
std::list< std::unique_ptr< NameValueAssign > > options_
Definition: ParserNode.h:2050
const std::string json_str(const rapidjson::Value &obj) noexcept
Definition: JsonAccessors.h:46
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 2037 of file ParserNode.h.

References options_.

2037  : user_name_(n) {
2038  if (l) {
2039  for (const auto e : *l) {
2040  options_.emplace_back(e);
2041  }
2042  delete l;
2043  }
2044  }
std::unique_ptr< std::string > user_name_
Definition: ParserNode.h:2049
std::list< std::unique_ptr< NameValueAssign > > options_
Definition: ParserNode.h:2050
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 7003 of file ParserNode.cpp.

References Catalog_Namespace::UserAlterations::can_login, Parser::checkStringLiteral(), Catalog_Namespace::UserAlterations::default_db, Catalog_Namespace::SessionInfo::get_currentUser(), lockmgr::instance(), 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().

7004  {
7005  if (read_only_mode) {
7006  throw std::runtime_error("ALTER USER invalid in read only mode.");
7007  }
7008  // Parse the statement
7010  for (auto& p : options_) {
7011  if (boost::iequals(*p->get_name(), "password")) {
7012  checkStringLiteral("Password", p);
7013  alts.passwd = *static_cast<const StringLiteral*>(p->get_value())->get_stringval();
7014  } else if (boost::iequals(*p->get_name(), "is_super")) {
7015  checkStringLiteral("IS_SUPER", p);
7016  alts.is_super = readBooleanLiteral("IS_SUPER", p);
7017  } else if (boost::iequals(*p->get_name(), "default_db")) {
7018  if (dynamic_cast<const StringLiteral*>(p->get_value())) {
7019  alts.default_db =
7020  *static_cast<const StringLiteral*>(p->get_value())->get_stringval();
7021  } else if (dynamic_cast<const NullLiteral*>(p->get_value())) {
7022  alts.default_db = "";
7023  } else {
7024  throw std::runtime_error(
7025  "DEFAULT_DB option must be either a string literal or a NULL "
7026  "literal.");
7027  }
7028  } else if (boost::iequals(*p->get_name(), "can_login")) {
7029  alts.can_login = readBooleanLiteral("CAN_LOGIN", p);
7030  } else {
7031  throw std::runtime_error("Invalid ALTER USER option " + *p->get_name() +
7032  ". Should be PASSWORD, DEFAULT_DB, CAN_LOGIN"
7033  " or IS_SUPER.");
7034  }
7035  }
7036 
7037  // Check if the user is authorized to execute ALTER USER statement
7039  if (!SysCatalog::instance().getMetadataForUser(*user_name_, user)) {
7040  throw std::runtime_error("User " + *user_name_ + " does not exist.");
7041  }
7042  if (!session.get_currentUser().isSuper) {
7043  if (session.get_currentUser().userId != user.userId) {
7044  throw std::runtime_error("Only super user can change another user's attributes.");
7045  } else if (alts.is_super || alts.can_login) {
7046  throw std::runtime_error(
7047  "A user can only update their own password or default database.");
7048  }
7049  }
7050 
7051  SysCatalog::instance().alterUser(*user_name_, alts);
7052 }
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:2049
static void checkStringLiteral(const std::string &option_name, const std::unique_ptr< NameValueAssign > &p)
std::list< std::unique_ptr< NameValueAssign > > options_
Definition: ParserNode.h:2050
std::optional< bool > is_super
Definition: SysCatalog.h:118
T & instance()
Definition: LockMgr.cpp:101
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 2050 of file ParserNode.h.

Referenced by AlterUserStmt(), and execute().

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

Definition at line 2049 of file ParserNode.h.

Referenced by AlterUserStmt(), and execute().


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