OmniSciDB  f632821e96
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 1915 of file ParserNode.h.

Constructor & Destructor Documentation

◆ CreateUserStmt()

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

Definition at line 1917 of file ParserNode.h.

1917  : user_name(n) {
1918  if (l) {
1919  for (const auto e : *l) {
1920  name_value_list.emplace_back(e);
1921  }
1922  delete l;
1923  }
1924  }
std::unique_ptr< std::string > user_name
Definition: ParserNode.h:1928
std::list< std::unique_ptr< NameValueAssign > > name_value_list
Definition: ParserNode.h:1929

Member Function Documentation

◆ execute()

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

Implements Parser::DDLStmt.

Definition at line 4764 of file ParserNode.cpp.

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

4764  {
4765  std::string passwd;
4766  bool is_super = false;
4767  std::string default_db;
4768  bool can_login = true;
4769  for (auto& p : name_value_list) {
4770  if (boost::iequals(*p->get_name(), "password")) {
4771  checkStringLiteral("Password", p);
4772  passwd = *static_cast<const StringLiteral*>(p->get_value())->get_stringval();
4773  } else if (boost::iequals(*p->get_name(), "is_super")) {
4774  checkStringLiteral("IS_SUPER", p);
4775  is_super = readBooleanLiteral("IS_SUPER", p);
4776  } else if (boost::iequals(*p->get_name(), "default_db")) {
4777  checkStringLiteral("DEFAULT_DB", p);
4778  default_db = *static_cast<const StringLiteral*>(p->get_value())->get_stringval();
4779  } else if (boost::iequals(*p->get_name(), "can_login")) {
4780  checkStringLiteral("CAN_LOGIN", p);
4781  can_login = readBooleanLiteral("can_login", p);
4782  } else {
4783  throw std::runtime_error("Invalid CREATE USER option " + *p->get_name() +
4784  ". Should be PASSWORD, IS_SUPER, CAN_LOGIN"
4785  " or DEFAULT_DB.");
4786  }
4787  }
4788  if (!session.get_currentUser().isSuper) {
4789  throw std::runtime_error("Only super user can create new users.");
4790  }
4791  SysCatalog::instance().createUser(*user_name, passwd, is_super, default_db, can_login);
4792 }
static void checkStringLiteral(const std::string &option_name, const std::unique_ptr< NameValueAssign > &p)
std::unique_ptr< std::string > user_name
Definition: ParserNode.h:1928
const UserMetadata & get_currentUser() const
Definition: SessionInfo.h:68
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:1929
std::atomic< bool > isSuper
Definition: SysCatalog.h:94
+ 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 1929 of file ParserNode.h.

◆ user_name

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

Definition at line 1928 of file ParserNode.h.


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