OmniSciDB  29e35f4d58
Parser::AlterUserStmt Class Reference

#include <ParserNode.h>

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

Public Member Functions

 AlterUserStmt (std::string *n, std::list< NameValueAssign *> *l)
 
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::unique_ptr< std::string > user_name
 
std::list< std::unique_ptr< NameValueAssign > > name_value_list
 

Detailed Description

Definition at line 1866 of file ParserNode.h.

Constructor & Destructor Documentation

◆ AlterUserStmt()

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

Definition at line 1868 of file ParserNode.h.

1868  : user_name(n) {
1869  if (l) {
1870  for (const auto e : *l) {
1871  name_value_list.emplace_back(e);
1872  }
1873  delete l;
1874  }
1875  }
std::unique_ptr< std::string > user_name
Definition: ParserNode.h:1879
std::list< std::unique_ptr< NameValueAssign > > name_value_list
Definition: ParserNode.h:1880

Member Function Documentation

◆ execute()

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

Implements Parser::DDLStmt.

Definition at line 4554 of file ParserNode.cpp.

References Parser::checkStringLiteral(), Catalog_Namespace::SessionInfo::get_currentUser(), Catalog_Namespace::UserMetadata::isSuper, Parser::readBooleanLiteral(), and Catalog_Namespace::UserMetadata::userId.

4554  {
4555  // Parse the statement
4556  const std::string* passwd = nullptr;
4557  bool is_super = false;
4558  bool* is_superp = nullptr;
4559  const std::string* default_db = nullptr;
4560  bool can_login = true;
4561  bool* can_loginp = nullptr;
4562  for (auto& p : name_value_list) {
4563  if (boost::iequals(*p->get_name(), "password")) {
4564  checkStringLiteral("Password", p);
4565  passwd = static_cast<const StringLiteral*>(p->get_value())->get_stringval();
4566  } else if (boost::iequals(*p->get_name(), "is_super")) {
4567  checkStringLiteral("IS_SUPER", p);
4568  is_super = readBooleanLiteral("IS_SUPER", p);
4569  is_superp = &is_super;
4570  } else if (boost::iequals(*p->get_name(), "default_db")) {
4571  if (dynamic_cast<const StringLiteral*>(p->get_value())) {
4572  default_db = static_cast<const StringLiteral*>(p->get_value())->get_stringval();
4573  } else if (dynamic_cast<const NullLiteral*>(p->get_value())) {
4574  static std::string blank;
4575  default_db = &blank;
4576  } else {
4577  throw std::runtime_error(
4578  "DEFAULT_DB option must be either a string literal or a NULL literal.");
4579  }
4580  } else if (boost::iequals(*p->get_name(), "can_login")) {
4581  checkStringLiteral("CAN_LOGIN", p);
4582  can_login = readBooleanLiteral("CAN_LOGIN", p);
4583  can_loginp = &can_login;
4584  } else {
4585  throw std::runtime_error("Invalid ALTER USER option " + *p->get_name() +
4586  ". Should be PASSWORD, DEFAULT_DB, CAN_LOGIN"
4587  " or IS_SUPER.");
4588  }
4589  }
4590 
4591  // Check if the user is authorized to execute ALTER USER statement
4593  if (!SysCatalog::instance().getMetadataForUser(*user_name, user)) {
4594  throw std::runtime_error("User " + *user_name + " does not exist.");
4595  }
4596  if (!session.get_currentUser().isSuper) {
4597  if (session.get_currentUser().userId != user.userId) {
4598  throw std::runtime_error("Only super user can change another user's attributes.");
4599  } else if (is_superp || can_loginp) {
4600  throw std::runtime_error(
4601  "A user can only update their own password or default database.");
4602  }
4603  }
4604 
4605  if (passwd || is_superp || default_db || can_loginp) {
4606  SysCatalog::instance().alterUser(
4607  user.userId, passwd, is_superp, default_db, can_loginp);
4608  }
4609 }
static void checkStringLiteral(const std::string &option_name, const std::unique_ptr< NameValueAssign > &p)
std::unique_ptr< std::string > user_name
Definition: ParserNode.h:1879
const UserMetadata & get_currentUser() const
Definition: SessionInfo.h:93
std::list< std::unique_ptr< NameValueAssign > > name_value_list
Definition: ParserNode.h:1880
static bool readBooleanLiteral(const std::string &option_name, const std::unique_ptr< NameValueAssign > &p)
std::atomic< bool > isSuper
Definition: SysCatalog.h:97
+ Here is the call graph for this function:

Member Data Documentation

◆ name_value_list

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

Definition at line 1880 of file ParserNode.h.

◆ user_name

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

Definition at line 1879 of file ParserNode.h.


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