OmniSciDB  06b3bd477c
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Calcite.cpp File Reference
#include "Calcite.h"
#include "Catalog/Catalog.h"
#include "Shared/Logger.h"
#include "Shared/SystemParameters.h"
#include "Shared/ThriftClient.h"
#include "Shared/fixautotools.h"
#include "Shared/mapd_shared_ptr.h"
#include "Shared/mapdpath.h"
#include "Shared/measure.h"
#include "ThriftHandler/QueryState.h"
#include <thrift/protocol/TBinaryProtocol.h>
#include <thrift/transport/TSocket.h>
#include <thrift/transport/TTransportUtils.h>
#include <type_traits>
#include "gen-cpp/CalciteServer.h"
#include "rapidjson/document.h"
#include <utility>
+ Include dependency graph for Calcite.cpp:

Go to the source code of this file.

Namespaces

 anonymous_namespace{Calcite.cpp}
 

Functions

template<typename XDEBUG_OPTION , typename REMOTE_DEBUG_OPTION , typename... REMAINING_ARGS>
int anonymous_namespace{Calcite.cpp}::wrapped_execlp (char const *path, XDEBUG_OPTION &&x_debug, REMOTE_DEBUG_OPTION &&remote_debug, REMAINING_ARGS &&...standard_args)
 
static void start_calcite_server_as_daemon (const int db_port, const int port, const std::string &data_dir, const size_t calcite_max_mem, const std::string &ssl_trust_store, const std::string &ssl_trust_password_X, const std::string &ssl_keystore, const std::string &ssl_keystore_password_X, const std::string &ssl_key_file, const std::string &db_config_file, const std::string &udf_filename)
 
void checkPermissionForTables (const Catalog_Namespace::SessionInfo &session_info, std::vector< std::string > tableOrViewNames, AccessPrivileges tablePrivs, AccessPrivileges viewPrivs)
 

Function Documentation

void checkPermissionForTables ( const Catalog_Namespace::SessionInfo session_info,
std::vector< std::string >  tableOrViewNames,
AccessPrivileges  tablePrivs,
AccessPrivileges  viewPrivs 
)

Definition at line 356 of file Calcite.cpp.

References DBObjectKey::dbId, Catalog_Namespace::DBMetadata::dbId, Catalog_Namespace::SessionInfo::get_currentUser(), Catalog_Namespace::SessionInfo::getCatalog(), Catalog_Namespace::Catalog::getCurrentDB(), Catalog_Namespace::Catalog::getMetadataForTable(), AccessPrivileges::hasAny(), Catalog_Namespace::SysCatalog::instance(), TableDescriptor::isView, DBObjectKey::objectId, DBObjectKey::permissionType, TableDBObjectType, TableDescriptor::tableId, TableDescriptor::userId, Catalog_Namespace::UserMetadata::userName, and ViewDBObjectType.

Referenced by Calcite::checkAccessedObjectsPrivileges().

359  {
360  Catalog_Namespace::Catalog& catalog = session_info.getCatalog();
361 
362  for (auto tableOrViewName : tableOrViewNames) {
363  const TableDescriptor* tableMeta =
364  catalog.getMetadataForTable(tableOrViewName, false);
365 
366  if (!tableMeta) {
367  throw std::runtime_error("unknown table of view: " + tableOrViewName);
368  }
369 
370  DBObjectKey key;
371  key.dbId = catalog.getCurrentDB().dbId;
374  key.objectId = tableMeta->tableId;
375  AccessPrivileges privs = tableMeta->isView ? viewPrivs : tablePrivs;
376  DBObject dbobject(key, privs, tableMeta->userId);
377  std::vector<DBObject> privObjects{dbobject};
378 
379  if (!privs.hasAny()) {
380  throw std::runtime_error("Operation not supported for object " + tableOrViewName);
381  }
382 
383  if (!Catalog_Namespace::SysCatalog::instance().checkPrivileges(
384  session_info.get_currentUser(), privObjects)) {
385  throw std::runtime_error("Violation of access privileges: user " +
386  session_info.get_currentUser().userName +
387  " has no proper privileges for object " + tableOrViewName);
388  }
389  }
390 }
class for a per-database catalog. also includes metadata for the current database and the current use...
Definition: Catalog.h:86
bool hasAny() const
Definition: DBObject.h:141
int32_t objectId
Definition: DBObject.h:57
static SysCatalog & instance()
Definition: SysCatalog.h:288
const DBMetadata & getCurrentDB() const
Definition: Catalog.h:194
Catalog & getCatalog() const
Definition: SessionInfo.h:65
int32_t dbId
Definition: DBObject.h:56
int32_t permissionType
Definition: DBObject.h:55
const TableDescriptor * getMetadataForTable(const std::string &tableName, const bool populateFragmenter=true) const
Returns a pointer to a const TableDescriptor struct matching the provided tableName.
specifies the content in-memory of a row in the table metadata table
const UserMetadata & get_currentUser() const
Definition: SessionInfo.h:68

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void start_calcite_server_as_daemon ( const int  db_port,
const int  port,
const std::string &  data_dir,
const size_t  calcite_max_mem,
const std::string &  ssl_trust_store,
const std::string &  ssl_trust_password_X,
const std::string &  ssl_keystore,
const std::string &  ssl_keystore_password_X,
const std::string &  ssl_key_file,
const std::string &  db_config_file,
const std::string &  udf_filename 
)
static

Definition at line 68 of file Calcite.cpp.

References logger::FATAL, logger::INFO, LOG, mapd_root_abs_path(), to_string(), and anonymous_namespace{Calcite.cpp}::wrapped_execlp().

Referenced by Calcite::runServer().

78  {
79  std::string const xDebug = "-Xdebug";
80  std::string const remoteDebug =
81  "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005";
82  std::string xmxP = "-Xmx" + std::to_string(calcite_max_mem) + "m";
83  std::string jarP = "-jar";
84  std::string jarD =
85  mapd_root_abs_path() + "/bin/calcite-1.0-SNAPSHOT-jar-with-dependencies.jar";
86  std::string extensionsP = "-e";
87  std::string extensionsD = mapd_root_abs_path() + "/QueryEngine/";
88  std::string dataP = "-d";
89  std::string dataD = data_dir;
90  std::string localPortP = "-p";
91  std::string localPortD = std::to_string(port);
92  std::string dbPortP = "-m";
93  std::string dbPortD = std::to_string(db_port);
94  std::string TrustStoreP = "-T";
95  std::string TrustPasswdP = "-P";
96  std::string ConfigFileP = "-c";
97  std::string KeyStoreP = "-Y";
98  std::string KeyStorePasswdP = "-Z";
99  std::string logDirectory = "-DMAPD_LOG_DIR=" + data_dir;
100  std::string userDefinedFunctionsP = "";
101  std::string userDefinedFunctionsD = "";
102 
103  if (!udf_filename.empty()) {
104  userDefinedFunctionsP += "-u";
105  userDefinedFunctionsD += udf_filename;
106  }
107 
108  // If a config file hasn't been supplied then put the password in the params
109  // otherwise send an empty string and Calcite should get it from the config file.
110  std::string key_store_password = (db_config_file == "") ? ssl_keystore_password_X : "";
111  std::string trust_store_password = (db_config_file == "") ? ssl_trust_password_X : "";
112 
113  int pid = fork();
114  if (pid == 0) {
115  int i;
116 
117  if (udf_filename.empty()) {
118  i = wrapped_execlp("java",
119  xDebug.c_str(),
120  remoteDebug.c_str(),
121  xmxP.c_str(),
122  logDirectory.c_str(),
123  jarP.c_str(),
124  jarD.c_str(),
125  extensionsP.c_str(),
126  extensionsD.c_str(),
127  dataP.c_str(),
128  dataD.c_str(),
129  localPortP.c_str(),
130  localPortD.c_str(),
131  dbPortP.c_str(),
132  dbPortD.c_str(),
133  TrustStoreP.c_str(),
134  ssl_trust_store.c_str(),
135  TrustPasswdP.c_str(),
136  trust_store_password.c_str(),
137  KeyStoreP.c_str(),
138  ssl_keystore.c_str(),
139  KeyStorePasswdP.c_str(),
140  key_store_password.c_str(),
141  ConfigFileP.c_str(),
142  db_config_file.c_str(),
143  (char*)0);
144  } else {
145  i = wrapped_execlp("java",
146  xDebug.c_str(),
147  remoteDebug.c_str(),
148  xmxP.c_str(),
149  logDirectory.c_str(),
150  jarP.c_str(),
151  jarD.c_str(),
152  extensionsP.c_str(),
153  extensionsD.c_str(),
154  dataP.c_str(),
155  dataD.c_str(),
156  localPortP.c_str(),
157  localPortD.c_str(),
158  dbPortP.c_str(),
159  dbPortD.c_str(),
160  TrustStoreP.c_str(),
161  ssl_trust_store.c_str(),
162  TrustPasswdP.c_str(),
163  trust_store_password.c_str(),
164  KeyStoreP.c_str(),
165  ssl_keystore.c_str(),
166  KeyStorePasswdP.c_str(),
167  key_store_password.c_str(),
168  ConfigFileP.c_str(),
169  db_config_file.c_str(),
170  userDefinedFunctionsP.c_str(),
171  userDefinedFunctionsD.c_str(),
172  (char*)0);
173  }
174 
175  if (i) {
176  int errsv = errno;
177  LOG(FATAL) << "Failed to start Calcite server [errno=" << errsv
178  << "]: " << strerror(errsv);
179  } else {
180  LOG(INFO) << "Successfully started Calcite server";
181  }
182  }
183 }
int wrapped_execlp(char const *path, XDEBUG_OPTION &&x_debug, REMOTE_DEBUG_OPTION &&remote_debug, REMAINING_ARGS &&...standard_args)
Definition: Calcite.cpp:55
#define LOG(tag)
Definition: Logger.h:188
std::string mapd_root_abs_path()
Definition: mapdpath.h:30
std::string to_string(char const *&&v)

+ Here is the call graph for this function:

+ Here is the caller graph for this function: