irods  4.2.8
About: iRODS (the integrated Rule Oriented Data System) is a distributed data-management system for creating data grids, digital libraries, persistent archives, and real-time data systems.
  Fossies Dox: irods-4.2.8.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

rsClientHints.cpp
Go to the documentation of this file.
1 #include "rcMisc.h"
2 #include "rsGlobalExtern.hpp"
3 #include "rodsErrorTable.h"
4 #include "rsClientHints.hpp"
5 
7 #include "irods_log.hpp"
12 
13 #include "client_hints.h"
14 #include "ies_client_hints.h"
15 #include "rsIESClientHints.hpp"
16 
17 #include <fstream>
18 #include <boost/algorithm/string.hpp>
19 #include <boost/filesystem.hpp>
20 #include <boost/lexical_cast.hpp>
21 #include <boost/archive/iterators/base64_from_binary.hpp>
22 #include <boost/archive/iterators/insert_linebreaks.hpp>
23 #include <boost/archive/iterators/transform_width.hpp>
24 #include <boost/archive/iterators/ostream_iterator.hpp>
25 
26 #include <sys/utsname.h>
27 
28 #include "json.hpp"
29 
31 
32 const std::string HOST_ACCESS_CONTROL_FILE( "HostAccessControl" );
33 
34 int _rsClientHints( rsComm_t* _comm, bytesBuf_t** _bbuf );
35 
36 int rsClientHints( rsComm_t* _comm, bytesBuf_t** _bbuf )
37 {
38  // always execute this locally
39  int status = _rsClientHints(
40  _comm,
41  _bbuf );
42  if ( status < 0 ) {
43  rodsLog(
44  LOG_ERROR,
45  "rsClientHints: rcClientHints failed, status = %d",
46  status );
47  }
48 
49  return status;
50 } // rsClientHints
51 
53  rsComm_t* _comm,
54  std::string& _hash,
55  std::string& _policy )
56 {
57  if ( !_comm ) {
58  return ERROR( SYS_INVALID_INPUT_PARAM, "comm is null" );
59  }
60 
61  try {
62  _hash = irods::get_server_property<const std::string>(irods::CFG_DEFAULT_HASH_SCHEME_KW);
63  } catch ( const irods::exception& ) {
64  _hash = "SHA256";
65  }
66 
67  try {
68  _policy = irods::get_server_property<const std::string>(irods::CFG_MATCH_HASH_POLICY_KW);
69  } catch ( const irods::exception& ) {
70  _policy = "compatible";
71  }
72 
73  return SUCCESS();
74 } // get_hash_and_policy
75 
76 int _rsClientHints( rsComm_t* _comm, bytesBuf_t** _bbuf )
77 {
78  if ( !_comm || !_bbuf ) {
79  rodsLog( LOG_ERROR, "_rsServerReport: null comm or bbuf" );
81  }
82 
83  ( *_bbuf ) = ( bytesBuf_t* ) malloc( sizeof( bytesBuf_t ) );
84  if ( !( *_bbuf ) ) {
85  rodsLog( LOG_ERROR, "_rsClientHints: failed to allocate _bbuf" );
86  return SYS_MALLOC_ERR;
87  }
88 
89  bytesBuf_t* ies_buf = 0;
90  int status = rsIESClientHints( _comm, &ies_buf );
91  if ( status < 0 ) {
92  rodsLog( LOG_ERROR, "_rsClientHints: rsIESClientHints failed %d", status );
93  return status;
94  }
95 
96  json client_hints;
97 
98  try {
99  client_hints = json::parse(std::string(static_cast<const char*>(ies_buf->buf), ies_buf->len));
100  freeBBuf( ies_buf );
101  }
102  catch (const json::parse_error& e) {
103  rodsLog( LOG_ERROR, "_rsClientHints - json::parse failed [%s]", e.what());
104  return ACTION_FAILED_ERR;
105  }
106 
107  std::string hash, hash_policy;
108  irods::error ret = get_hash_and_policy( _comm, hash, hash_policy );
109  if ( !ret.ok() ) {
110  irods::log( PASS( ret ) );
111  }
112 
113  client_hints["hash_scheme"] = hash;
114  client_hints["match_hash_policy"] = hash_policy;
115 
116  json plugins;
117  ret = irods::get_plugin_array(plugins);
118  if (!ret.ok()) {
119  irods::log(PASS(ret));
120  }
121  client_hints["plugins"] = plugins;
122 
123  // List rules
124  ruleExecInfo_t rei;
125  memset( ( char*) &rei, 0, sizeof( ruleExecInfo_t ) );
126  rei.rsComm = _comm;
127  rei.uoic = &_comm->clientUser;
128  rei.uoip = &_comm->proxyUser;
129  rei.uoio = nullptr;
130  rei.coi = nullptr;
131 
133  irods::unit,
135  irods::DONT_AUDIT_RULE > re_ctx_mgr(
136  irods::re_plugin_globals->global_re_mgr,
137  &rei );
138 
139  std::vector< std::string > rule_vec;
140  ret = re_ctx_mgr.list_rules( rule_vec );
141  if ( !ret.ok() ) {
142  irods::log( PASS( ret ) );
143  }
144 
145  auto rules = json::array();
146  for ( const auto& rule : rule_vec ) {
147  rules.push_back(rule);
148  }
149  client_hints["rules"] = rules;
150 
151  const auto ch = client_hints.dump(4);
152  char* tmp_buf = new char[ch.length() + 1]{};
153  std::strncpy(tmp_buf, ch.c_str(), ch.length());
154 
155  ( *_bbuf )->buf = tmp_buf;
156  ( *_bbuf )->len = ch.length();
157 
158  return 0;
159 } // _rsClientHints
160 
rodsLog
void rodsLog(int level, const char *formatStr,...)
Definition: rodsLog.cpp:86
irods::unit
std::tuple<> unit
Definition: irods_re_plugin.hpp:736
rsComm_t
Definition: rcConnect.h:145
irods_server_properties.hpp
irods::CFG_DEFAULT_HASH_SCHEME_KW
const std::string CFG_DEFAULT_HASH_SCHEME_KW("default_hash_scheme")
BytesBuf::buf
void * buf
Definition: rodsDef.h:199
rsClientHints
int rsClientHints(rsComm_t *_comm, bytesBuf_t **_bbuf)
Definition: rsClientHints.cpp:36
SYS_MALLOC_ERR
@ SYS_MALLOC_ERR
Definition: rodsErrorTable.h:84
irods::rule_engine_context_manager
Definition: irods_re_plugin.hpp:522
irods_get_full_path_for_config_file.hpp
PASS
#define PASS(prev_error_)
Definition: irods_error.hpp:118
rcMisc.h
json
nlohmann::json json
Definition: group.cpp:5
LOG_ERROR
#define LOG_ERROR
Definition: rodsLog.h:43
client_hints.h
SYS_INVALID_INPUT_PARAM
@ SYS_INVALID_INPUT_PARAM
Definition: rodsErrorTable.h:195
rsIESClientHints.hpp
_rsClientHints
int _rsClientHints(rsComm_t *_comm, bytesBuf_t **_bbuf)
Definition: rsClientHints.cpp:76
BytesBuf::len
int len
Definition: rodsDef.h:198
SUCCESS
#define SUCCESS()
Definition: irods_error.hpp:121
rsGlobalExtern.hpp
rsComm_t::proxyUser
userInfo_t proxyUser
Definition: rcConnect.h:152
rsClientHints.hpp
irods::get_plugin_array
error get_plugin_array(nlohmann::json &_plugins)
Definition: irods_report_plugins_in_json.cpp:42
terminate_irods_processes.e
e
Definition: terminate_irods_processes.py:19
get_hash_and_policy
irods::error get_hash_and_policy(rsComm_t *_comm, std::string &_hash, std::string &_policy)
Definition: rsClientHints.cpp:52
irods.pypyodbc.status
status
Definition: pypyodbc.py:467
json
nlohmann::json json
Definition: rsClientHints.cpp:30
irods::log
void log(const error &)
Definition: irods_log.cpp:13
irods::CFG_MATCH_HASH_POLICY_KW
const std::string CFG_MATCH_HASH_POLICY_KW("match_hash_policy")
rsComm_t::clientUser
userInfo_t clientUser
Definition: rcConnect.h:153
ERROR
#define ERROR(code_, message_)
Definition: irods_error.hpp:117
BytesBuf
Definition: rodsDef.h:197
irods::error
Definition: irods_error.hpp:23
irods_plugin_name_generator.hpp
RuleExecInfo
Definition: irods_re_structs.hpp:18
ACTION_FAILED_ERR
@ ACTION_FAILED_ERR
Definition: rodsErrorTable.h:664
rsIESClientHints
int rsIESClientHints(rsComm_t *server_comm_ptr, bytesBuf_t **json_response)
Definition: rsIESClientHints.cpp:23
irods_resource_manager.hpp
irods::DONT_AUDIT_RULE
@ DONT_AUDIT_RULE
Definition: irods_re_plugin.hpp:125
irods::exception
Definition: irods_exception.hpp:15
rodsErrorTable.h
freeBBuf
int freeBBuf(bytesBuf_t *myBBuf)
Definition: rcMisc.cpp:88
irods::error::ok
bool ok()
Definition: irods_error.cpp:258
irods_report_plugins_in_json.hpp
HOST_ACCESS_CONTROL_FILE
const std::string HOST_ACCESS_CONTROL_FILE("HostAccessControl")
irods::re_plugin_globals
std::unique_ptr< struct irods::global_re_plugin_mgr > re_plugin_globals
Definition: irods_re_plugin.cpp:16
irods_log.hpp
ies_client_hints.h