OmniSciDB  1dac507f6e
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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

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

Definition at line 1868 of file ParserNode.h.

References name_value_list.

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

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

Implements Parser::DDLStmt.

Definition at line 4544 of file ParserNode.cpp.

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

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

+ Here is the call graph for this function:

Member Data Documentation

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

Definition at line 1880 of file ParserNode.h.

Referenced by AlterUserStmt().

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: