41 #include <boost/filesystem.hpp>
42 #include <boost/format.hpp>
43 #include <boost/optional.hpp>
44 #include <boost/system/error_code.hpp>
71 "initServerInfo - queZone failed %d",
83 "initServerInfo: initHostConfigByFile error, status = %d",
91 "initServerInfo: initLocalServerHost error, status = %d",
99 "initServerInfo: initRcatServerHostByFile error, status = %d",
104 std::string svc_role;
116 "initServerInfo: connectRcat failed, status = %d",
126 "initServerInfo: initZone error, status = %d",
160 "initLocalServerHost: gethostname error, status = %d",
174 "initLocalServerHost: queAddr error, status = %d",
188 std::string prop_str;
195 memset( &addr, 0,
sizeof( addr ) );
203 "initRcatServerHostByFile: resolveHost error for %s, status = %d",
219 memset( &addr, 0,
sizeof( addr ) );
227 "initRcatServerHostByFile: resolveHost error for %s, status = %d",
252 const auto& federation = boost::any_cast<const std::unordered_map<std::string, boost::any>&>(el);
258 remote_SID_key_map[fed_zone_name] = std::make_pair( fed_zone_key, fed_zone_negotiation_key );
260 catch ( boost::bad_any_cast& _e ) {
263 "initRcatServerHostByFile - failed to cast federation entry to string" );
265 }
catch (
const std::out_of_range& ) {
268 "%s - federation object did not contain required keys",
269 __PRETTY_FUNCTION__);
272 }
catch (
const boost::bad_any_cast& ) {
275 "%s - failed to cast array member to federation object",
276 __PRETTY_FUNCTION__);
286 size_t pos = rem_sid.find(
"-" );
287 if ( pos == std::string::npos ) {
288 rodsLog(
LOG_ERROR,
"initRcatServerHostByFile - Unable to parse remote SID %s", rem_sid.c_str() );
292 std::string fed_zone_name = rem_sid.substr( 0, pos );
293 std::string fed_zone_key = rem_sid.substr( pos + 1 );
324 sqlResult_t *zoneName, *zoneType, *zoneConn, *zoneComment;
325 char *tmpZoneName, *tmpZoneType, *tmpZoneConn;
327 boost::optional<const std::string&>
zone_name;
338 while ( tmpRodsServerHost !=
NULL ) {
341 masterServerHost = tmpRodsServerHost;
345 slaveServerHost = tmpRodsServerHost;
347 tmpRodsServerHost = tmpRodsServerHost->
next;
352 memset( &genQueryInp, 0,
sizeof( genQueryInp ) );
366 "initZone: rsGenQuery error, status = %d",
status );
370 if ( genQueryOut ==
NULL ) {
372 "initZone: NULL genQueryOut" );
378 "initZone: getSqlResultByInx for COL_ZONE_NAME failed" );
384 "initZone: getSqlResultByInx for COL_ZONE_TYPE failed" );
390 "initZone: getSqlResultByInx for COL_ZONE_CONNECTION failed" );
396 "initZone: getSqlResultByInx for COL_ZONE_COMMENT failed" );
400 for ( i = 0; i < genQueryOut->
rowCnt; i++ ) {
403 tmpZoneName = &zoneName->
value[zoneName->
len * i];
404 tmpZoneType = &zoneType->
value[zoneType->
len * i];
405 tmpZoneConn = &zoneConn->
value[zoneConn->
len * i];
407 if ( strcmp( tmpZoneType,
"local" ) == 0 ) {
408 if ( strcmp(
zone_name->c_str(), tmpZoneName ) != 0 ) {
410 "initZone: zoneName in env %s does not match %s in icat ",
422 else if ( strlen( tmpZoneConn ) <= 0 ) {
424 "initZone: connection info for zone %s not configured",
429 memset( &addr, 0,
sizeof( addr ) );
439 "initZone: resolveHost error for %s for zone %s. status = %d",
445 "initZone: address %s for remote zone %s already in use",
446 tmpZoneConn, tmpZoneName );
470 "initAgent: initServerInfo error, status = %d",
480 "initAgent: initFileDesc error, status = %d",
486 memset( &rei, 0,
sizeof( rei ) );
495 "initAgent: acChkHostAccessControl error, status = %d",
515 rsComm->
cookie = (
int )( irods::getRandom<unsigned int>() >> 1 );
522 catch ( boost::thread_resource_error& ) {
541 "initAgent: acSetPublicUserPolicy error, status = %d",
551 std::string svc_role;
575 "Agent exiting with status = %d",
status );
593 "caught a signal and exiting\n" );
604 "caught a broken pipe signal and exiting" );
613 "caught a broken pipe signal and exiting" );
622 "caught a broken pipe signal. Attempt to reconnect" );
633 std::string cfg_file;
640 "config file [%s] not found",
646 ret = cfg.
load( cfg_file );
653 for (
const auto& el : cfg.
get<
const std::vector< boost::any > > (
"host_entries") ) {
655 const auto& host_entry = boost::any_cast<const std::unordered_map<std::string, boost::any>&>(el);
656 const auto& address_type = boost::any_cast<const std::string&>(host_entry.at(
"address_type"));
657 const auto& addresses = boost::any_cast<const std::vector<boost::any>&>(host_entry.at(
"addresses"));
662 if (
"remote" == address_type ) {
665 else if (
"local" == address_type ) {
673 "unsupported address type [%s]",
674 address_type.c_str() );
685 "queRodsServerHost failed" );
688 for (
const auto& el : addresses ) {
692 boost::any_cast<const std::string&>(
693 boost::any_cast<
const std::unordered_map<std::string, boost::any>&>(el
700 }
catch (
const boost::bad_any_cast&
e ) {
703 }
catch (
const std::out_of_range&
e ) {
708 }
catch (
const boost::bad_any_cast&
e ) {
711 }
catch (
const std::out_of_range&
e ) {
728 memset( rsComm, 0,
sizeof(
rsComm_t ) );
745 zone_auth_scheme.c_str(),
NAME_LEN );
749 zone_auth_scheme.c_str(),
NAME_LEN );
772 if ( setsid() < 0 ) {
773 fprintf( stderr,
"daemonize" );
774 perror(
"cannot create a new session." );
783 ( void ) dup2( logFd, 0 );
784 ( void ) dup2( logFd, 1 );
785 ( void ) dup2( logFd, 2 );
796 logFileOpen(
int runMode,
const char *logDir,
const char *logFileName ) {
797 char *logFile =
NULL;
808 if ( logFileName ==
NULL ) {
809 fprintf( stderr,
"logFileOpen: NULL input logFileName\n" );
814 if (
NULL == logFile ) {
815 fprintf( stderr,
"logFileOpen: unable to open log file" );
820 logFd = open( logFile, O_CREAT | O_WRONLY | O_APPEND, 0666 );
823 fprintf( stderr,
"logFileOpen: Unable to open %s. errno = %d\n",
867 if ( tmpStr ==
NULL ) {
869 "initRsCommWithStartupPack: env %s does not exist",
873 rsComm->
sock = atoi( tmpStr );
876 if ( tmpStr ==
NULL ) {
878 "initRsCommWithStartupPack: env %s does not exist",
885 if ( tmpStr ==
NULL ) {
887 "initRsCommWithStartupPack: env %s does not exist",
899 if ( tmpStr ==
NULL ) {
901 "initRsCommWithStartupPack: env %s does not exist",
908 if ( tmpStr ==
NULL ) {
910 "initRsCommWithStartupPack: env %s does not exist",
920 if ( tmpStr ==
NULL ) {
922 "initRsCommWithStartupPack: env %s does not exist",
929 if ( tmpStr ==
NULL ) {
931 "initRsCommWithStartupPack: env %s does not exist",
941 if ( tmpStr ==
NULL ) {
943 "initRsCommWithStartupPack: env %s does not exist",
950 if ( tmpStr ==
NULL ) {
952 "getstartupPackFromEnv: env %s does not exist",
959 if ( tmpStr ==
NULL ) {
961 "initRsCommWithStartupPack: env %s does not exist",
968 if ( tmpStr ==
NULL ) {
970 "initRsCommWithStartupPack: env %s does not exist",
977 if ( rsComm->
sock != 0 ) {
983 tmpStr = inet_ntoa( rsComm->
remoteAddr.sin_addr );
984 if ( tmpStr ==
NULL || *tmpStr ==
'\0' ) {
992 std::set<std::string>
994 std::set<std::string> user_set;
996 for (
const auto& user : boost::any_cast<
const std::vector<boost::any>&>(controlled_user_connection_list.at(
"users")) ) {
997 user_set.insert(boost::any_cast<const std::string&>(user));
999 }
catch (
const boost::bad_any_cast&
e ) {
1000 THROW(
INVALID_ANY_CAST,
"controlled_user_connection_list must contain a list of string values at key \"users\"" );
1001 }
catch (
const std::out_of_range&
e ) {
1002 THROW(
KEY_NOT_FOUND,
"controlled_user_connection_list must contain a list of string values at key \"users\"" );
1010 if ( userName ==
NULL || rodsZone ==
NULL ) {
1014 if ( strlen( userName ) == 0 ) {
1018 boost::optional<const std::unordered_map<std::string, boost::any>&> controlled_user_connection_list;
1020 controlled_user_connection_list.reset(
irods::get_server_property<
const std::unordered_map<std::string, boost::any> >(
"controlled_user_connection_list"));
1027 const auto user_and_zone = (boost::format(
"%s#%s") % userName % rodsZone).str();
1029 const auto& control_type = boost::any_cast<const std::string&>(controlled_user_connection_list->at(
"control_type"));
1031 if ( control_type ==
"whitelist" ) {
1032 if ( controlled_user_set.count( user_and_zone ) == 0 ) {
1036 else if ( control_type ==
"blacklist" ) {
1037 if ( controlled_user_set.count( user_and_zone ) != 0 ) {
1042 rodsLog(
LOG_ERROR,
"controlled_user_connection_list must specify \"whitelist\" or \"blacklist\"");
1048 }
catch (
const std::out_of_range&
e ) {
1051 }
catch (
const boost::bad_any_cast&
e ) {
1085 if ( *agentProcHead ==
NULL ) {
1097 while ( tmpAgentProc->
next !=
NULL ) {
1098 tmpAgentProc = tmpAgentProc->
next;
1111 struct dirent *myDirent;
1112 struct stat statbuf;
1114 int savedStatus = 0;
1115 struct flock myflock;
1118 std::string lock_dir;
1127 DIR *dirPtr = opendir( lock_dir.c_str() );
1128 if ( dirPtr ==
NULL ) {
1130 "purgeLockFileDir: opendir error for %s, errno = %d",
1131 lock_dir.c_str(), errno );
1134 bzero( &myflock,
sizeof( myflock ) );
1135 myflock.l_whence = SEEK_SET;
1137 while ( ( myDirent = readdir( dirPtr ) ) !=
NULL ) {
1138 if ( strcmp( myDirent->d_name,
"." ) == 0 ||
1139 strcmp( myDirent->d_name,
".." ) == 0 ) {
1143 lock_dir.c_str(), myDirent->d_name );
1144 if ( chkLockFlag ) {
1146 myFd = open( lockFilePath, O_RDWR | O_CREAT, 0644 );
1150 "purgeLockFileDir: open error for %s", lockFilePath );
1153 myflock.l_type = F_WRLCK;
1154 int error_code = fcntl( myFd, F_GETLK, &myflock );
1155 if ( error_code != 0 ) {
1156 rodsLog(
LOG_ERROR,
"fcntl failed in purgeLockFileDir with error code %d", error_code );
1160 if ( myflock.l_type != F_UNLCK ) {
1164 status = stat( lockFilePath, &statbuf );
1168 "purgeLockFileDir: stat error for %s, errno = %d",
1169 lockFilePath, errno );
1171 boost::system::error_code err;
1175 if ( chkLockFlag && (
int )purgeTime < statbuf.st_mtime ) {
1178 if ( ( statbuf.st_mode & S_IFREG ) == 0 ) {
1181 boost::system::error_code err;