OmniSciDB  eb3a3d0a03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Parser::AlterUserStmt Class Reference

#include <ParserNode.h>

+ Inheritance diagram for Parser::AlterUserStmt:
+ Collaboration diagram for Parser::AlterUserStmt:

Public Member Functions

 AlterUserStmt (const rapidjson::Value &payload)
 
 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 > > 
options_
 

Detailed Description

Definition at line 1994 of file ParserNode.h.

Constructor & Destructor Documentation

Parser::AlterUserStmt::AlterUserStmt ( const rapidjson::Value &  payload)

Definition at line 6113 of file ParserNode.cpp.

References CHECK, json_str(), and Parser::anonymous_namespace{ParserNode.cpp}::parse_options().

6113  {
6114  CHECK(payload.HasMember("name"));
6115  user_name_ = std::make_unique<std::string>(json_str(payload["name"]));
6116 
6117  parse_options(payload, options_, true, false);
6118 }
std::unique_ptr< std::string > user_name_
Definition: ParserNode.h:2008
std::list< std::unique_ptr< NameValueAssign > > options_
Definition: ParserNode.h:2009
const std::string json_str(const rapidjson::Value &obj) noexcept
Definition: JsonAccessors.h:44
void parse_options(const rapidjson::Value &payload, std::list< std::unique_ptr< NameValueAssign >> &nameValueList, bool stringToNull=false, bool stringToInteger=false)
#define CHECK(condition)
Definition: Logger.h:209

+ Here is the call graph for this function:

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

Definition at line 1997 of file ParserNode.h.

References options_.

1997  : user_name_(n) {
1998  if (l) {
1999  for (const auto e : *l) {
2000  options_.emplace_back(e);
2001  }
2002  delete l;
2003  }
2004  }
std::unique_ptr< std::string > user_name_
Definition: ParserNode.h:2008
std::list< std::unique_ptr< NameValueAssign > > options_
Definition: ParserNode.h:2009
constexpr double n
Definition: Utm.h:40

Member Function Documentation

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

Implements Parser::DDLStmt.

Definition at line 6120 of file ParserNode.cpp.

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

Referenced by omnisci.cursor.Cursor::executemany().

6120  {
6121  // Parse the statement
6122  const std::string* passwd = nullptr;
6123  bool is_super = false;
6124  bool* is_superp = nullptr;
6125  const std::string* default_db = nullptr;
6126  bool can_login = true;
6127  bool* can_loginp = nullptr;
6128  for (auto& p : options_) {
6129  if (boost::iequals(*p->get_name(), "password")) {
6130  checkStringLiteral("Password", p);
6131  passwd = static_cast<const StringLiteral*>(p->get_value())->get_stringval();
6132  } else if (boost::iequals(*p->get_name(), "is_super")) {
6133  checkStringLiteral("IS_SUPER", p);
6134  is_super = readBooleanLiteral("IS_SUPER", p);
6135  is_superp = &is_super;
6136  } else if (boost::iequals(*p->get_name(), "default_db")) {
6137  if (dynamic_cast<const StringLiteral*>(p->get_value())) {
6138  default_db = static_cast<const StringLiteral*>(p->get_value())->get_stringval();
6139  } else if (dynamic_cast<const NullLiteral*>(p->get_value())) {
6140  static std::string blank;
6141  default_db = &blank;
6142  } else {
6143  throw std::runtime_error(
6144  "DEFAULT_DB option must be either a string literal or a NULL "
6145  "literal.");
6146  }
6147  } else if (boost::iequals(*p->get_name(), "can_login")) {
6148  checkStringLiteral("CAN_LOGIN", p);
6149  can_login = readBooleanLiteral("CAN_LOGIN", p);
6150  can_loginp = &can_login;
6151  } else {
6152  throw std::runtime_error("Invalid ALTER USER option " + *p->get_name() +
6153  ". Should be PASSWORD, DEFAULT_DB, CAN_LOGIN"
6154  " or IS_SUPER.");
6155  }
6156  }
6157 
6158  // Check if the user is authorized to execute ALTER USER statement
6160  if (!SysCatalog::instance().getMetadataForUser(*user_name_, user)) {
6161  throw std::runtime_error("User " + *user_name_ + " does not exist.");
6162  }
6163  if (!session.get_currentUser().isSuper) {
6164  if (session.get_currentUser().userId != user.userId) {
6165  throw std::runtime_error("Only super user can change another user's attributes.");
6166  } else if (is_superp || can_loginp) {
6167  throw std::runtime_error(
6168  "A user can only update their own password or default database.");
6169  }
6170  }
6171 
6172  if (passwd || is_superp || default_db || can_loginp) {
6173  SysCatalog::instance().alterUser(
6174  *user_name_, passwd, is_superp, default_db, can_loginp);
6175  }
6176 }
std::unique_ptr< std::string > user_name_
Definition: ParserNode.h:2008
static void checkStringLiteral(const std::string &option_name, const std::unique_ptr< NameValueAssign > &p)
std::list< std::unique_ptr< NameValueAssign > > options_
Definition: ParserNode.h:2009
static bool readBooleanLiteral(const std::string &option_name, const std::unique_ptr< NameValueAssign > &p)
const UserMetadata & get_currentUser() const
Definition: SessionInfo.h:73
std::atomic< bool > isSuper
Definition: SysCatalog.h:118

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

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

Definition at line 2009 of file ParserNode.h.

Referenced by AlterUserStmt().

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

Definition at line 2008 of file ParserNode.h.


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