OmniSciDB  29e35f4d58
Parser::CreateUserStmt Class Reference

#include <ParserNode.h>

+ Inheritance diagram for Parser::CreateUserStmt:
+ Collaboration diagram for Parser::CreateUserStmt:

Public Member Functions

 CreateUserStmt (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 1845 of file ParserNode.h.

Constructor & Destructor Documentation

◆ CreateUserStmt()

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

Definition at line 1847 of file ParserNode.h.

1847  : user_name(n) {
1848  if (l) {
1849  for (const auto e : *l) {
1850  name_value_list.emplace_back(e);
1851  }
1852  delete l;
1853  }
1854  }
std::unique_ptr< std::string > user_name
Definition: ParserNode.h:1858
std::list< std::unique_ptr< NameValueAssign > > name_value_list
Definition: ParserNode.h:1859

Member Function Documentation

◆ execute()

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

Implements Parser::DDLStmt.

Definition at line 4524 of file ParserNode.cpp.

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

4524  {
4525  std::string passwd;
4526  bool is_super = false;
4527  std::string default_db;
4528  bool can_login = true;
4529  for (auto& p : name_value_list) {
4530  if (boost::iequals(*p->get_name(), "password")) {
4531  checkStringLiteral("Password", p);
4532  passwd = *static_cast<const StringLiteral*>(p->get_value())->get_stringval();
4533  } else if (boost::iequals(*p->get_name(), "is_super")) {
4534  checkStringLiteral("IS_SUPER", p);
4535  is_super = readBooleanLiteral("IS_SUPER", p);
4536  } else if (boost::iequals(*p->get_name(), "default_db")) {
4537  checkStringLiteral("DEFAULT_DB", p);
4538  default_db = *static_cast<const StringLiteral*>(p->get_value())->get_stringval();
4539  } else if (boost::iequals(*p->get_name(), "can_login")) {
4540  checkStringLiteral("CAN_LOGIN", p);
4541  can_login = readBooleanLiteral("can_login", p);
4542  } else {
4543  throw std::runtime_error("Invalid CREATE USER option " + *p->get_name() +
4544  ". Should be PASSWORD, IS_SUPER, CAN_LOGIN"
4545  " or DEFAULT_DB.");
4546  }
4547  }
4548  if (!session.get_currentUser().isSuper) {
4549  throw std::runtime_error("Only super user can create new users.");
4550  }
4551  SysCatalog::instance().createUser(*user_name, passwd, is_super, default_db, can_login);
4552 }
static void checkStringLiteral(const std::string &option_name, const std::unique_ptr< NameValueAssign > &p)
std::unique_ptr< std::string > user_name
Definition: ParserNode.h:1858
const UserMetadata & get_currentUser() const
Definition: SessionInfo.h:93
static bool readBooleanLiteral(const std::string &option_name, const std::unique_ptr< NameValueAssign > &p)
std::list< std::unique_ptr< NameValueAssign > > name_value_list
Definition: ParserNode.h:1859
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::CreateUserStmt::name_value_list
private

Definition at line 1859 of file ParserNode.h.

◆ user_name

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

Definition at line 1858 of file ParserNode.h.


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