19 #include <boost/algorithm/string.hpp>
20 #include <boost/filesystem.hpp>
21 #include <boost/lexical_cast.hpp>
22 #include <boost/archive/iterators/base64_from_binary.hpp>
23 #include <boost/archive/iterators/insert_linebreaks.hpp>
24 #include <boost/archive/iterators/transform_width.hpp>
25 #include <boost/archive/iterators/ostream_iterator.hpp>
29 #include <sys/utsname.h>
31 namespace fs = boost::filesystem;
50 if ( _feds.empty() ) {
54 auto array = json::array();
56 for (
const auto& federation : _feds ) {
57 std::vector<std::string> zone_sid_vals;
58 boost::split( zone_sid_vals, federation, boost::is_any_of(
"-" ) );
60 if ( zone_sid_vals.size() > 2 ) {
61 rodsLog(
LOG_ERROR,
"multiple hyphens found in RemoteZoneSID [%s]", federation.c_str() );
65 array.push_back(json::object({
66 {
"zone_name", zone_sid_vals[0]},
67 {
"zone_key",
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"},
68 {
"negotiation_key",
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"}
77 if ( _svr_cfg.is_null() ) {
82 _svr_cfg[
"zone_key"] =
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
83 _svr_cfg[
"negotiation_key"] =
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
84 _svr_cfg[
"server_control_plane_key"] =
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
87 if (!_svr_cfg.count(
"federation")) {
92 for (
auto&& o : _svr_cfg[
"federation"]) {
93 o[
"negotiation_key"] =
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
94 o[
"zone_key"] =
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
104 std::ifstream in{_file};
107 std::string msg(
"failed to load file [" );
110 return ERROR( -1, msg );
116 catch (
const json::parse_error&
e) {
117 return ERROR(-1, boost::format(
"failed to parse json [file=%s, error=%s].") % _file %
e.what());
134 if (
auto err = load_json_file(svr_cfg, _svr_cfg); !err.ok()) {
143 std::string cfg_file;
149 return load_json_file(cfg_file, _host_ctrl);
154 std::string cfg_file;
160 return load_json_file(cfg_file, _irods_host);
165 std::string env_file_path;
166 std::string session_file_path;
176 if (
const auto err = load_json_file(env_file_path, _svc_acct); !err.ok()) {
181 _svc_acct[
"irods_server_control_plane_key"] =
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
188 struct utsname os_name;
189 memset( &os_name, 0,
sizeof( os_name ) );
190 const int status = uname( &os_name );
196 _str +=
"SYS_NAME=" ;
197 _str += os_name.sysname;
198 _str +=
";NODE_NAME=";
199 _str += os_name.nodename;
201 _str += os_name.release;
203 _str += os_name.version;
205 _str += os_name.machine;
212 uid_t uid = getuid();
213 passwd *pw = getpwuid(uid);
217 user_name_string = pw->pw_name;
223 uid_t uid = getuid();
224 passwd *pw = getpwuid(uid);
228 group *grp = getgrgid(pw->pw_gid);
232 group_name_string = grp->gr_name;
238 _host_system_information = json::object();
240 std::string user_name_string;
243 _host_system_information[
"service_account_user_name"] = user_name_string;
246 _host_system_information[
"service_account_user_name"] =
nullptr;
249 std::string group_name_string;
252 _host_system_information[
"service_account_group_name"] = group_name_string;
255 _host_system_information[
"service_account_group_name"] =
nullptr;
258 char hostname_buf[512];
259 const int gethostname_ret = gethostname(hostname_buf,
sizeof(hostname_buf));
260 if (gethostname_ret != 0) {
261 rodsLog(
LOG_ERROR,
"get_host_system_information: gethostname() failed [%d]", errno);
262 _host_system_information[
"hostname"] =
nullptr;
264 _host_system_information[
"hostname"] = hostname_buf;
267 std::string uname_string;
270 _host_system_information[
"uname"] = uname_string;
273 _host_system_information[
"uname"] =
nullptr;
276 std::vector<std::string> args;
277 args.push_back(
"os_distribution_name" );
278 std::string os_distribution_name;
281 _host_system_information[
"os_distribution_name"] = os_distribution_name;
284 _host_system_information[
"os_distribution_name"] =
nullptr;
288 args.push_back(
"os_distribution_version" );
289 std::string os_distribution_version;
292 _host_system_information[
"os_distribution_version"] = os_distribution_version;
295 _host_system_information[
"os_distribution_version"] =
nullptr;
303 _resources = json::array();
311 const std::string local_host_name = my_env.
rodsHost;
334 std::string host_name;
349 std::string::npos == host_name.find( local_host_name ) &&
350 std::string::npos == local_host_name.find( host_name ) ) {
353 "get_resource_array - skipping non-local resource [%s] on [%s]",
361 auto entry = json::object();
370 _resources.push_back(
entry);
378 std::ifstream f( _fn.c_str() );
379 std::stringstream ss;
383 std::string in_s = ss.str();
385 namespace bitr = boost::archive::iterators;
386 std::stringstream o_str;
388 bitr::base64_from_binary <
389 bitr::transform_width <
398 base64_text( in_s.c_str() ),
399 base64_text( in_s.c_str() + in_s.size() ),
400 bitr::ostream_iterator<char>( o_str )
405 size_t pad = in_s.size() % 3;
406 _cont.insert( _cont.size(), ( 3 - pad ) % 3,
'=' );
413 namespace fs = boost::filesystem;
415 _cfg_dir = json::object();
417 auto files = json::object();
418 std::string cfg_file;
421 fs::path
p( cfg_file );
422 std::string config_dir =
p.parent_path().string();
424 _cfg_dir[
"path"] = config_dir;
426 for ( fs::directory_iterator itr( config_dir );
427 itr != fs::directory_iterator();
430 if ( fs::is_regular_file( itr->path() ) ) {
431 const fs::path&
p = itr->path();
432 const std::string
name =
p.string();
441 std::string contents;
449 files[
name] = contents;
453 _cfg_dir[
"files"] = files;
462 fs::path version_file;
467 return ERROR(-1,
"failed to get irods home directory");
469 version_file.append(
"VERSION.json");
472 return load_json_file(version_file.generic_string(), _version);
480 if ( !_comm || !_bbuf ) {
485 ( *_bbuf ) = (
bytesBuf_t* ) malloc(
sizeof( **_bbuf ) );
491 auto resc_svr = json::object();
500 json host_system_information;
505 resc_svr[
"host_system_information"] = host_system_information;
512 resc_svr[
"server_config"] = svr_cfg;
519 resc_svr[
"host_access_control_config"] = host_ctrl;
526 resc_svr[
"hosts_config"] = irods_host;
533 resc_svr[
"service_account_environment"] = svc_acct;
540 resc_svr[
"plugins"] = plugins;
554 resc_svr[
"configuration_directory"] = cfg_dir;
556 std::string svc_role;
563 const auto rs = resc_svr.dump(4);
564 char* tmp_buf =
new char[rs.length() + 1]{};
565 std::strncpy(tmp_buf, rs.c_str(), rs.length());
567 ( *_bbuf )->buf = tmp_buf;
568 ( *_bbuf )->len = rs.length();