OmniSciDB  c07336695a
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 1765 of file ParserNode.h.

Constructor & Destructor Documentation

◆ AlterUserStmt()

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

Definition at line 1767 of file ParserNode.h.

References session.

1767  : user_name(n) {
1768  if (l) {
1769  for (const auto e : *l) {
1770  name_value_list.emplace_back(e);
1771  }
1772  delete l;
1773  }
1774  }
std::unique_ptr< std::string > user_name
Definition: ParserNode.h:1778
std::list< std::unique_ptr< NameValueAssign > > name_value_list
Definition: ParserNode.h:1779

Member Function Documentation

◆ execute()

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

Implements Parser::DDLStmt.

Definition at line 4476 of file ParserNode.cpp.

References Catalog_Namespace::SessionInfo::get_currentUser(), Catalog_Namespace::UserMetadata::isSuper, anonymous_namespace{DBObjectPrivilegesTest.cpp}::user, and Catalog_Namespace::UserMetadata::userId.

4476  {
4477  // Parse the statement
4478  const std::string* passwd = nullptr;
4479  bool is_super = false;
4480  bool* is_superp = nullptr;
4481  const std::string* default_db = nullptr;
4482  for (auto& p : name_value_list) {
4483  if (boost::iequals(*p->get_name(), "password")) {
4484  if (!dynamic_cast<const StringLiteral*>(p->get_value())) {
4485  throw std::runtime_error("Password must be a string literal.");
4486  }
4487  passwd = static_cast<const StringLiteral*>(p->get_value())->get_stringval();
4488  } else if (boost::iequals(*p->get_name(), "is_super")) {
4489  if (!dynamic_cast<const StringLiteral*>(p->get_value())) {
4490  throw std::runtime_error("IS_SUPER option must be a string literal.");
4491  }
4492  const std::string* str =
4493  static_cast<const StringLiteral*>(p->get_value())->get_stringval();
4494  if (boost::iequals(*str, "true")) {
4495  is_super = true;
4496  is_superp = &is_super;
4497  } else if (boost::iequals(*str, "false")) {
4498  is_super = false;
4499  is_superp = &is_super;
4500  } else {
4501  throw std::runtime_error("Value to IS_SUPER must be TRUE or FALSE.");
4502  }
4503  } else if (boost::iequals(*p->get_name(), "default_db")) {
4504  if (dynamic_cast<const StringLiteral*>(p->get_value())) {
4505  default_db = static_cast<const StringLiteral*>(p->get_value())->get_stringval();
4506  } else if (dynamic_cast<const NullLiteral*>(p->get_value())) {
4507  static std::string blank;
4508  default_db = &blank;
4509  } else {
4510  throw std::runtime_error(
4511  "DEFAULT_DB option must be either a string literal or a NULL literal.");
4512  }
4513  } else {
4514  throw std::runtime_error("Invalid ALTER USER option " + *p->get_name() +
4515  ". Should be PASSWORD, DEFAULT_DB or IS_SUPER.");
4516  }
4517  }
4518 
4519  // Check if the user is authorized to execute ALTER USER statement
4521  if (!SysCatalog::instance().getMetadataForUser(*user_name, user)) {
4522  throw std::runtime_error("User " + *user_name + " does not exist.");
4523  }
4524  if (!session.get_currentUser().isSuper) {
4525  if (session.get_currentUser().userId != user.userId) {
4526  throw std::runtime_error("Only super user can change another user's attributes.");
4527  } else if (is_superp) {
4528  throw std::runtime_error(
4529  "A user can only update their own password or default database.");
4530  }
4531  }
4532 
4533  if (passwd || is_superp || default_db) {
4534  SysCatalog::instance().alterUser(user.userId, passwd, is_superp, default_db);
4535  }
4536 }
std::unique_ptr< std::string > user_name
Definition: ParserNode.h:1778
const UserMetadata & get_currentUser() const
Definition: SessionInfo.h:93
std::list< std::unique_ptr< NameValueAssign > > name_value_list
Definition: ParserNode.h:1779
+ 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 1779 of file ParserNode.h.

◆ user_name

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

Definition at line 1778 of file ParserNode.h.


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