OmniSciDB  06b3bd477c
 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 1936 of file ParserNode.h.

Constructor & Destructor Documentation

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

Definition at line 1938 of file ParserNode.h.

References name_value_list.

1938  : user_name(n) {
1939  if (l) {
1940  for (const auto e : *l) {
1941  name_value_list.emplace_back(e);
1942  }
1943  delete l;
1944  }
1945  }
std::unique_ptr< std::string > user_name
Definition: ParserNode.h:1949
std::list< std::unique_ptr< NameValueAssign > > name_value_list
Definition: ParserNode.h:1950

Member Function Documentation

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

Implements Parser::DDLStmt.

Definition at line 4791 of file ParserNode.cpp.

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

4791  {
4792  // Parse the statement
4793  const std::string* passwd = nullptr;
4794  bool is_super = false;
4795  bool* is_superp = nullptr;
4796  const std::string* default_db = nullptr;
4797  bool can_login = true;
4798  bool* can_loginp = nullptr;
4799  for (auto& p : name_value_list) {
4800  if (boost::iequals(*p->get_name(), "password")) {
4801  checkStringLiteral("Password", p);
4802  passwd = static_cast<const StringLiteral*>(p->get_value())->get_stringval();
4803  } else if (boost::iequals(*p->get_name(), "is_super")) {
4804  checkStringLiteral("IS_SUPER", p);
4805  is_super = readBooleanLiteral("IS_SUPER", p);
4806  is_superp = &is_super;
4807  } else if (boost::iequals(*p->get_name(), "default_db")) {
4808  if (dynamic_cast<const StringLiteral*>(p->get_value())) {
4809  default_db = static_cast<const StringLiteral*>(p->get_value())->get_stringval();
4810  } else if (dynamic_cast<const NullLiteral*>(p->get_value())) {
4811  static std::string blank;
4812  default_db = &blank;
4813  } else {
4814  throw std::runtime_error(
4815  "DEFAULT_DB option must be either a string literal or a NULL literal.");
4816  }
4817  } else if (boost::iequals(*p->get_name(), "can_login")) {
4818  checkStringLiteral("CAN_LOGIN", p);
4819  can_login = readBooleanLiteral("CAN_LOGIN", p);
4820  can_loginp = &can_login;
4821  } else {
4822  throw std::runtime_error("Invalid ALTER USER option " + *p->get_name() +
4823  ". Should be PASSWORD, DEFAULT_DB, CAN_LOGIN"
4824  " or IS_SUPER.");
4825  }
4826  }
4827 
4828  // Check if the user is authorized to execute ALTER USER statement
4830  if (!SysCatalog::instance().getMetadataForUser(*user_name, user)) {
4831  throw std::runtime_error("User " + *user_name + " does not exist.");
4832  }
4833  if (!session.get_currentUser().isSuper) {
4834  if (session.get_currentUser().userId != user.userId) {
4835  throw std::runtime_error("Only super user can change another user's attributes.");
4836  } else if (is_superp || can_loginp) {
4837  throw std::runtime_error(
4838  "A user can only update their own password or default database.");
4839  }
4840  }
4841 
4842  if (passwd || is_superp || default_db || can_loginp) {
4843  SysCatalog::instance().alterUser(
4844  user.userId, passwd, is_superp, default_db, can_loginp);
4845  }
4846 }
static void checkStringLiteral(const std::string &option_name, const std::unique_ptr< NameValueAssign > &p)
std::unique_ptr< std::string > user_name
Definition: ParserNode.h:1949
std::list< std::unique_ptr< NameValueAssign > > name_value_list
Definition: ParserNode.h:1950
static bool readBooleanLiteral(const std::string &option_name, const std::unique_ptr< NameValueAssign > &p)
const UserMetadata & get_currentUser() const
Definition: SessionInfo.h:68
std::atomic< bool > isSuper
Definition: SysCatalog.h:96

+ 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 1950 of file ParserNode.h.

Referenced by AlterUserStmt().

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

Definition at line 1949 of file ParserNode.h.


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