OmniSciDB  72c90bc290
 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 6975 of file ParserNode.cpp.

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

6975  {
6976  CHECK(payload.HasMember("name"));
6977  user_name_ = std::make_unique<std::string>(json_str(payload["name"]));
6978 
6979  parse_options(payload, options_, true, false);
6980 }
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 6982 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().

6983  {
6984  if (read_only_mode) {
6985  throw std::runtime_error("ALTER USER invalid in read only mode.");
6986  }
6987  // Parse the statement
6989  for (auto& p : options_) {
6990  if (boost::iequals(*p->get_name(), "password")) {
6991  checkStringLiteral("Password", p);
6992  alts.passwd = *static_cast<const StringLiteral*>(p->get_value())->get_stringval();
6993  } else if (boost::iequals(*p->get_name(), "is_super")) {
6994  checkStringLiteral("IS_SUPER", p);
6995  alts.is_super = readBooleanLiteral("IS_SUPER", p);
6996  } else if (boost::iequals(*p->get_name(), "default_db")) {
6997  if (dynamic_cast<const StringLiteral*>(p->get_value())) {
6998  alts.default_db =
6999  *static_cast<const StringLiteral*>(p->get_value())->get_stringval();
7000  } else if (dynamic_cast<const NullLiteral*>(p->get_value())) {
7001  alts.default_db = "";
7002  } else {
7003  throw std::runtime_error(
7004  "DEFAULT_DB option must be either a string literal or a NULL "
7005  "literal.");
7006  }
7007  } else if (boost::iequals(*p->get_name(), "can_login")) {
7008  alts.can_login = readBooleanLiteral("CAN_LOGIN", p);
7009  } else {
7010  throw std::runtime_error("Invalid ALTER USER option " + *p->get_name() +
7011  ". Should be PASSWORD, DEFAULT_DB, CAN_LOGIN"
7012  " or IS_SUPER.");
7013  }
7014  }
7015 
7016  // Check if the user is authorized to execute ALTER USER statement
7018  if (!SysCatalog::instance().getMetadataForUser(*user_name_, user)) {
7019  throw std::runtime_error("User " + *user_name_ + " does not exist.");
7020  }
7021  if (!session.get_currentUser().isSuper) {
7022  if (session.get_currentUser().userId != user.userId) {
7023  throw std::runtime_error("Only super user can change another user's attributes.");
7024  } else if (alts.is_super || alts.can_login) {
7025  throw std::runtime_error(
7026  "A user can only update their own password or default database.");
7027  }
7028  }
7029 
7030  SysCatalog::instance().alterUser(*user_name_, alts);
7031 }
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
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: