// Read LEGACY_SERVER_CONFIG_FILE and fill server_properties::properties void server_properties::capture_legacy() { error result = SUCCESS(); std::string property; // property setting FILE *fptr; char buf[BUF_LEN]; char *fchar; int len; char *key; char DBKey[MAX_PASSWORD_LEN], DBPassword[MAX_PASSWORD_LEN]; memset( &DBKey, '\0', MAX_PASSWORD_LEN ); memset( &DBPassword, '\0', MAX_PASSWORD_LEN ); std::string cfg_file; error ret = irods::get_full_path_for_config_file( LEGACY_SERVER_CONFIG_FILE, cfg_file ); if ( !ret.ok() ) { THROW( ret.code(), ret.result() ); } if ( !fs::exists( cfg_file ) ) { return; } rodsLog( LOG_ERROR, "server_properties::capture_legacy - use of legacy configuration is deprecated" ); fptr = fopen( cfg_file.c_str(), "r" ); if ( fptr == NULL ) { rodsLog( LOG_DEBUG, "Cannot open LEGACY_SERVER_CONFIG_FILE file %s. errno = %d\n", cfg_file.c_str(), errno ); std::stringstream msg; msg << LEGACY_SERVER_CONFIG_FILE << " file error"; THROW( SYS_CONFIG_FILE_ERR, msg.str().c_str() ); } // =-=-=-=-=-=-=- // PAM configuration - init PAM values result = config_props_.set<bool>( PAM_NO_EXTEND_KW, false ); result = config_props_.set<size_t>( PAM_PW_LEN_KW, 20 ); property.assign( "121" ); result = config_props_.set<std::string>( PAM_PW_MIN_TIME_KW, property ); property.assign( "1209600" ); result = config_props_.set<std::string>( PAM_PW_MAX_TIME_KW, property ); // init PAM values std::string initializer[] = { ICAT_HOST_KW, RE_RULESET_KW, RE_FUNCMAPSET_KW, RE_VARIABLEMAPSET_KW, DB_USERNAME_KW, PAM_PW_MIN_TIME_KW, PAM_PW_MAX_TIME_KW, CATALOG_DATABASE_TYPE_KW, KERBEROS_NAME_KW, LOCAL_ZONE_SID_KW }; std::vector<std::string> keys( initializer, initializer + sizeof( initializer ) / sizeof( std::string ) ); buf[BUF_LEN - 1] = '\0'; fchar = fgets( buf, BUF_LEN - 1, fptr ); while ( fchar ) { if ( buf[0] == '#' || buf[0] == '/' ) { buf[0] = '\0'; /* Comment line, ignore */ } /** * Parsing of server configuration settings */ key = strstr( buf, DB_PASSWORD_KW ); if ( key != NULL ) { len = strlen( DB_PASSWORD_KW ); // Store password in temporary string snprintf( DBPassword, sizeof( DBPassword ), "%s", findNextTokenAndTerm( key + len ) ); } // DB_PASSWORD_KW key = strstr( buf, DB_KEY_KW ); if ( key != NULL ) { len = strlen( DB_KEY_KW ); // Store key in temporary string snprintf( DBKey, sizeof( DBKey ), "%s", findNextTokenAndTerm( key + len ) ); } // DB_KEY_KW for ( std::vector<std::string>::iterator it = keys.begin(); it != keys.end(); it++ ) { char * pos = strstr( buf, it->c_str() ); if ( pos != NULL ) { // Set property property.assign( findNextTokenAndTerm( pos + it->size() ) ); // Update properties table result = config_props_.set<std::string>( *it, property ); rodsLog( LOG_DEBUG1, "%s=%s", it->c_str(), property.c_str() ); } } key = strstr( buf, PAM_PW_LEN_KW ); if ( key != NULL ) { len = strlen( PAM_PW_LEN_KW ); // Set property property.assign( findNextTokenAndTerm( key + len ) ); // Update properties table result = config_props_.set<size_t>( PAM_PW_LEN_KW, atoi( property.c_str() ) ); rodsLog( LOG_DEBUG, "%s=%s", PAM_PW_LEN_KW, property.c_str() ); } // PAM_PW_LEN_KW key = strstr( buf, PAM_NO_EXTEND_KW ); if ( key != NULL ) { len = strlen( PAM_NO_EXTEND_KW ); // Set property property.assign( findNextTokenAndTerm( key + len ) ); std::transform( property.begin(), property.end(), property.begin(), ::tolower ); if ( property == "true" ) { result = config_props_.set<bool>( PAM_NO_EXTEND_KW, true ); } else { result = config_props_.set<bool>( PAM_NO_EXTEND_KW, false ); } rodsLog( LOG_DEBUG, "%s=%s", PAM_NO_EXTEND_KW, property.c_str() ); } // PAM_NO_EXTEND_KW key = strstr( buf, DEF_DIR_MODE_KW ); if ( key != NULL ) { len = strlen( DEF_DIR_MODE_KW ); // Set property property.assign( findNextTokenAndTerm( key + len ) ); // Update properties table result = config_props_.set<int>( DEF_DIR_MODE_KW, strtol( property.c_str(), 0, 0 ) ); rodsLog( LOG_DEBUG, "%s=%s", DEF_DIR_MODE_KW, property.c_str() ); } // DEF_DIR_MODE_KW key = strstr( buf, DEF_FILE_MODE_KW ); if ( key != NULL ) { len = strlen( DEF_FILE_MODE_KW ); // Set property property.assign( findNextTokenAndTerm( key + len ) ); // Update properties table result = config_props_.set<int>( DEF_FILE_MODE_KW, strtol( property.c_str(), 0, 0 ) ); rodsLog( LOG_DEBUG, "%s=%s", DEF_FILE_MODE_KW, property.c_str() ); } // DEF_FILE_MODE_KW key = strstr( buf, KERBEROS_KEYTAB_KW ); if ( key != NULL ) { len = strlen( KERBEROS_KEYTAB_KW ); // Set property property.assign( findNextTokenAndTerm( key + len ) ); // Update properties table result = config_props_.set<std::string>( KERBEROS_KEYTAB_KW, property ); rodsLog( LOG_DEBUG, "%s=%s", KERBEROS_KEYTAB_KW, property.c_str() ); // Now set the appropriate kerberos environment variable setenv( "KRB5_KTNAME", property.c_str(), 1 ); } // KERBEROS_KEYTAB_KW key = strstr( buf, DEFAULT_HASH_SCHEME_KW ); if ( key != NULL ) { len = strlen( DEFAULT_HASH_SCHEME_KW ); // Set property property.assign( findNextTokenAndTerm( key + len ) ); std::transform( property.begin(), property.end(), property.begin(), ::tolower ); // Update properties table result = config_props_.set<std::string>( DEFAULT_HASH_SCHEME_KW, property ); rodsLog( LOG_DEBUG, "%s=%s", DEFAULT_HASH_SCHEME_KW, property.c_str() ); } // DEFAULT_HASH_SCHEME_KW key = strstr( buf, MATCH_HASH_POLICY_KW ); if ( key != NULL ) { len = strlen( MATCH_HASH_POLICY_KW ); // Set property property.assign( findNextTokenAndTerm( key + len ) ); std::transform( property.begin(), property.end(), property.begin(), ::tolower ); // Update properties table result = config_props_.set<std::string>( MATCH_HASH_POLICY_KW, property ); rodsLog( LOG_DEBUG, "%s=%s", MATCH_HASH_POLICY_KW, property.c_str() ); } // MATCH_HASH_POLICY_KW key = strstr( buf, REMOTE_ZONE_SID_KW ); if ( key != NULL ) { len = strlen( REMOTE_ZONE_SID_KW ); // Set property property.assign( findNextTokenAndTerm( key + len ) ); // Update properties table std::vector<std::string> rem_sids; std::vector<std::string>::iterator sid_itr; if ( config_props_.has_entry( REMOTE_ZONE_SID_KW ) ) { result = config_props_.get< std::vector< std::string > >( REMOTE_ZONE_SID_KW, rem_sids ); // do not want duplicate entries sid_itr = std::find( rem_sids.begin(), rem_sids.end(), property ); } if ( sid_itr == rem_sids.end() ) { rem_sids.push_back( property ); result = config_props_.set< std::vector< std::string > >( REMOTE_ZONE_SID_KW, rem_sids ); } rodsLog( LOG_DEBUG, "%s=%s", REMOTE_ZONE_SID_KW, property.c_str() ); } // REMOTE_ZONE_SID_KW key = strstr( buf, AGENT_KEY_KW.c_str() ); if ( key != NULL ) { len = strlen( AGENT_KEY_KW.c_str() ); // Set property property.assign( findNextTokenAndTerm( key + len ) ); if ( 32 != property.size() ) { rodsLog( LOG_ERROR, "%s field in %s must be 32 characters in length (currently %d characters in length).", AGENT_KEY_KW.c_str(), LEGACY_SERVER_CONFIG_FILE, property.size() ); fclose( fptr ); std::stringstream msg; msg << LEGACY_SERVER_CONFIG_FILE << " file error"; THROW( SYS_CONFIG_FILE_ERR, msg.str().c_str() ); } // Update properties table result = config_props_.set<std::string>( AGENT_KEY_KW, property ); } // AGENT_KEY_KW fchar = fgets( buf, BUF_LEN - 1, fptr ); } // for ( ; fchar != '\0'; ) fclose( fptr ); // unscramble password if ( strlen( DBKey ) > 0 && strlen( DBPassword ) > 0 ) { char sPassword[MAX_PASSWORD_LEN + 10]; strncpy( sPassword, DBPassword, MAX_PASSWORD_LEN ); obfDecodeByKey( sPassword, DBKey, DBPassword ); memset( sPassword, 0, MAX_PASSWORD_LEN ); } // store password and key in server properties property.assign( DBPassword ); result = config_props_.set<std::string>( DB_PASSWORD_KW, property ); rodsLog( LOG_DEBUG1, "%s=%s", DB_PASSWORD_KW, property.c_str() ); property.assign( DBKey ); result = config_props_.set<std::string>( DB_KEY_KW, property ); rodsLog( LOG_DEBUG1, "%s=%s", DB_KEY_KW, property.c_str() ); // add expected zone_name, zone_user, zone_port, zone_auth_scheme // as these are now read from server_properties rodsEnv env; int status = getRodsEnv( &env ); if ( status < 0 ) { THROW( status, "failure in getRodsEnv" ); } result = config_props_.set<std::string>( irods::CFG_ZONE_NAME_KW, env.rodsZone ); if ( !result.ok() ) { irods::log( PASS( result ) ); } result = config_props_.set<std::string>( irods::CFG_ZONE_USER, env.rodsUserName ); if ( !result.ok() ) { irods::log( PASS( result ) ); } result = config_props_.set<std::string>( irods::CFG_ZONE_AUTH_SCHEME, env.rodsAuthScheme ); if ( !result.ok() ) { irods::log( PASS( result ) ); } result = config_props_.set<int>( irods::CFG_ZONE_PORT, env.rodsPort ); if ( !result.ok() ) { irods::log( PASS( result ) ); } if ( 0 != env.xmsgPort ) { result = config_props_.set<int>( irods::CFG_XMSG_PORT, env.xmsgPort ); if ( !result.ok() ) { irods::log( PASS( result ) ); } } } // server_properties::capture()
// Read server.config and fill server_properties::properties error server_properties::capture() { error result = SUCCESS(); std::string prop_name, prop_setting; // property name and setting FILE *fptr; char buf[BUF_LEN]; char *fchar; int len; char *key; char DBKey[MAX_PASSWORD_LEN], DBPassword[MAX_PASSWORD_LEN]; memset( &DBKey, '\0', MAX_PASSWORD_LEN ); memset( &DBPassword, '\0', MAX_PASSWORD_LEN ); std::string cfg_file; error ret = irods::get_full_path_for_config_file( SERVER_CONFIG_FILE, cfg_file ); if ( !ret.ok() ) { return PASS( ret ); } fptr = fopen( cfg_file.c_str(), "r" ); if ( fptr == NULL ) { rodsLog( LOG_DEBUG, "Cannot open SERVER_CONFIG_FILE file %s. errno = %d\n", cfg_file.c_str(), errno ); return ERROR( SYS_CONFIG_FILE_ERR, "server.config file error" ); } buf[BUF_LEN - 1] = '\0'; fchar = fgets( buf, BUF_LEN - 1, fptr ); for ( ; fchar != '\0'; ) { if ( buf[0] == '#' || buf[0] == '/' ) { buf[0] = '\0'; /* Comment line, ignore */ } /** * Parsing of server configuration settings */ key = strstr( buf, DB_PASSWORD_KW ); if ( key != NULL ) { len = strlen( DB_PASSWORD_KW ); // Store password in temporary string strncpy( DBPassword, findNextTokenAndTerm( key + len ), MAX_PASSWORD_LEN ); } // DB_PASSWORD_KW key = strstr( buf, DB_KEY_KW ); if ( key != NULL ) { len = strlen( DB_KEY_KW ); // Store key in temporary string strncpy( DBKey, findNextTokenAndTerm( key + len ), MAX_PASSWORD_LEN ); } // DB_KEY_KW // =-=-=-=-=-=-=- // PAM configuration - init PAM values result = properties.set<bool>( PAM_NO_EXTEND_KW, false ); result = properties.set<size_t>( PAM_PW_LEN_KW, 20 ); key = strstr( buf, DB_USERNAME_KW ); if ( key != NULL ) { len = strlen( DB_USERNAME_KW ); // Set property name and setting prop_name.assign( DB_USERNAME_KW ); prop_setting.assign( findNextTokenAndTerm( key + len ) ); // Update properties table result = properties.set<std::string>( prop_name, prop_setting ); rodsLog( LOG_DEBUG1, "%s=%s", prop_name.c_str(), prop_setting.c_str() ); } // DB_USERNAME_KW // =-=-=-=-=-=-=- // PAM configuration - init PAM values result = properties.set<bool>( PAM_NO_EXTEND_KW, false ); result = properties.set<size_t>( PAM_PW_LEN_KW, 20 ); prop_setting.assign( "121" ); result = properties.set<std::string>( PAM_PW_MIN_TIME_KW, prop_setting ); prop_setting.assign( "1209600" ); result = properties.set<std::string>( PAM_PW_MAX_TIME_KW, prop_setting ); // init PAM values key = strstr( buf, PAM_PW_LEN_KW ); if ( key != NULL ) { len = strlen( PAM_PW_LEN_KW ); // Set property name and setting prop_name.assign( PAM_PW_LEN_KW ); prop_setting.assign( findNextTokenAndTerm( key + len ) ); // Update properties table result = properties.set<size_t>( prop_name, atoi( prop_setting.c_str() ) ); rodsLog( LOG_DEBUG, "%s=%s", prop_name.c_str(), prop_setting.c_str() ); } // PAM_PW_LEN_KW key = strstr( buf, PAM_NO_EXTEND_KW ); if ( key != NULL ) { len = strlen( PAM_NO_EXTEND_KW ); // Set property name and setting prop_name.assign( PAM_NO_EXTEND_KW ); prop_setting.assign( findNextTokenAndTerm( key + len ) ); std::transform( prop_setting.begin(), prop_setting.end(), prop_setting.begin(), ::tolower ); if ( prop_setting == "true" ) { result = properties.set<bool>( PAM_NO_EXTEND_KW, true ); } else { result = properties.set<bool>( PAM_NO_EXTEND_KW, false ); } rodsLog( LOG_DEBUG, "%s=%s", prop_name.c_str(), prop_setting.c_str() ); } // PAM_NO_EXTEND_KW key = strstr( buf, PAM_PW_MIN_TIME_KW ); if ( key != NULL ) { len = strlen( PAM_PW_MIN_TIME_KW ); // Set property name and setting prop_name.assign( PAM_PW_MIN_TIME_KW ); prop_setting.assign( findNextTokenAndTerm( key + len ) ); // Update properties table result = properties.set<std::string>( prop_name, prop_setting ); rodsLog( LOG_DEBUG, "%s=%s", prop_name.c_str(), prop_setting.c_str() ); } // PAM_PW_MIN_TIME_KW key = strstr( buf, PAM_PW_MAX_TIME_KW ); if ( key != NULL ) { len = strlen( PAM_PW_MAX_TIME_KW ); // Set property name and setting prop_name.assign( PAM_PW_MAX_TIME_KW ); prop_setting.assign( findNextTokenAndTerm( key + len ) ); // Update properties table result = properties.set<std::string>( prop_name, prop_setting ); rodsLog( LOG_DEBUG, "%s=%s", prop_name.c_str(), prop_setting.c_str() ); } // PAM_PW_MAX_TIME_KW key = strstr( buf, RUN_SERVER_AS_ROOT_KW ); if ( key != NULL ) { len = strlen( RUN_SERVER_AS_ROOT_KW ); // Set property name and setting prop_name.assign( RUN_SERVER_AS_ROOT_KW ); prop_setting.assign( findNextTokenAndTerm( key + len ) ); std::transform( prop_setting.begin(), prop_setting.end(), prop_setting.begin(), ::tolower ); if ( prop_setting == "true" ) { result = properties.set<bool>( RUN_SERVER_AS_ROOT_KW, true ); } else { result = properties.set<bool>( RUN_SERVER_AS_ROOT_KW, false ); } rodsLog( LOG_DEBUG, "%s=%s", prop_name.c_str(), prop_setting.c_str() ); } // RUN_SERVER_AS_ROOT_KW key = strstr( buf, DEF_DIR_MODE_KW ); if ( key != NULL ) { len = strlen( DEF_DIR_MODE_KW ); // Set property name and setting prop_name.assign( DEF_DIR_MODE_KW ); prop_setting.assign( findNextTokenAndTerm( key + len ) ); // Update properties table result = properties.set<int>( prop_name, strtol( prop_setting.c_str(), 0, 0 ) ); rodsLog( LOG_DEBUG, "%s=%s", prop_name.c_str(), prop_setting.c_str() ); } // DEF_DIR_MODE_KW key = strstr( buf, DEF_FILE_MODE_KW ); if ( key != NULL ) { len = strlen( DEF_FILE_MODE_KW ); // Set property name and setting prop_name.assign( DEF_FILE_MODE_KW ); prop_setting.assign( findNextTokenAndTerm( key + len ) ); // Update properties table result = properties.set<int>( prop_name, strtol( prop_setting.c_str(), 0, 0 ) ); rodsLog( LOG_DEBUG, "%s=%s", prop_name.c_str(), prop_setting.c_str() ); } // DEF_FILE_MODE_KW key = strstr( buf, CATALOG_DATABASE_TYPE_KW ); if ( key != NULL ) { len = strlen( CATALOG_DATABASE_TYPE_KW ); // Set property name and setting prop_name.assign( CATALOG_DATABASE_TYPE_KW ); prop_setting.assign( findNextTokenAndTerm( key + len ) ); // Update properties table result = properties.set<std::string>( prop_name, prop_setting ); rodsLog( LOG_DEBUG, "%s=%s", prop_name.c_str(), prop_setting.c_str() ); } // CATALOG_DATABASE_TYPE_KW key = strstr( buf, KERBEROS_NAME_KW ); if ( key != NULL ) { len = strlen( KERBEROS_NAME_KW ); // Set property name and setting prop_name.assign( KERBEROS_NAME_KW ); prop_setting.assign( findNextTokenAndTerm( key + len ) ); // Update properties table result = properties.set<std::string>( prop_name, prop_setting ); rodsLog( LOG_DEBUG, "%s=%s", prop_name.c_str(), prop_setting.c_str() ); } // KERBEROS_NAME_KW key = strstr( buf, KERBEROS_KEYTAB_KW ); if ( key != NULL ) { len = strlen( KERBEROS_KEYTAB_KW ); // Set property name and setting prop_name.assign( KERBEROS_KEYTAB_KW ); prop_setting.assign( findNextTokenAndTerm( key + len ) ); // Update properties table result = properties.set<std::string>( prop_name, prop_setting ); rodsLog( LOG_DEBUG, "%s=%s", prop_name.c_str(), prop_setting.c_str() ); // Now set the appropriate kerberos environment variable setenv( "KRB5_KTNAME", prop_setting.c_str(), 1 ); } // KERBEROS_KEYTAB_KW key = strstr( buf, DEFAULT_HASH_SCHEME_KW ); if ( key != NULL ) { len = strlen( DEFAULT_HASH_SCHEME_KW ); // Set property name and setting prop_name.assign( DEFAULT_HASH_SCHEME_KW ); prop_setting.assign( findNextTokenAndTerm( key + len ) ); std::transform( prop_setting.begin(), prop_setting.end(), prop_setting.begin(), ::tolower ); // Update properties table result = properties.set<std::string>( prop_name, prop_setting ); rodsLog( LOG_DEBUG, "%s=%s", prop_name.c_str(), prop_setting.c_str() ); } // DEFAULT_HASH_SCHEME_KW key = strstr( buf, MATCH_HASH_POLICY_KW ); if ( key != NULL ) { len = strlen( MATCH_HASH_POLICY_KW ); // Set property name and setting prop_name.assign( MATCH_HASH_POLICY_KW ); prop_setting.assign( findNextTokenAndTerm( key + len ) ); std::transform( prop_setting.begin(), prop_setting.end(), prop_setting.begin(), ::tolower ); // Update properties table result = properties.set<std::string>( prop_name, prop_setting ); rodsLog( LOG_DEBUG, "%s=%s", prop_name.c_str(), prop_setting.c_str() ); } // MATCH_HASH_POLICY_KW key = strstr( buf, LOCAL_ZONE_SID_KW ); if ( key != NULL ) { len = strlen( LOCAL_ZONE_SID_KW ); // Set property name and setting prop_name.assign( LOCAL_ZONE_SID_KW ); prop_setting.assign( findNextTokenAndTerm( key + len ) ); // Update properties table result = properties.set<std::string>( prop_name, prop_setting ); rodsLog( LOG_DEBUG, "%s=%s", prop_name.c_str(), prop_setting.c_str() ); } // LOCAL_ZONE_SID_KW key = strstr( buf, AGENT_KEY_KW.c_str() ); if ( key != NULL ) { len = strlen( AGENT_KEY_KW.c_str() ); // Set property name and setting prop_name.assign( AGENT_KEY_KW ); prop_setting.assign( findNextTokenAndTerm( key + len ) ); if ( 32 != prop_setting.size() ) { rodsLog( LOG_ERROR, "%s field in server.config must be 32 characters in length (currently %d characters in length).", prop_name.c_str(), prop_setting.size() ); fclose( fptr ); return ERROR( SYS_CONFIG_FILE_ERR, "server.config file error" ); } // Update properties table result = properties.set<std::string>( prop_name, prop_setting ); } // AGENT_KEY_KW fchar = fgets( buf, BUF_LEN - 1, fptr ); } // for ( ; fchar != '\0'; ) fclose( fptr ); // unscramble password if ( strlen( DBKey ) > 0 && strlen( DBPassword ) > 0 ) { char sPassword[MAX_PASSWORD_LEN + 10]; strncpy( sPassword, DBPassword, MAX_PASSWORD_LEN ); obfDecodeByKey( sPassword, DBKey, DBPassword ); memset( sPassword, 0, MAX_PASSWORD_LEN ); } // store password and key in server properties prop_name.assign( DB_PASSWORD_KW ); prop_setting.assign( DBPassword ); result = properties.set<std::string>( prop_name, prop_setting ); rodsLog( LOG_DEBUG1, "%s=%s", prop_name.c_str(), prop_setting.c_str() ); prop_name.assign( DB_KEY_KW ); prop_setting.assign( DBKey ); result = properties.set<std::string>( prop_name, prop_setting ); rodsLog( LOG_DEBUG1, "%s=%s", prop_name.c_str(), prop_setting.c_str() ); // set the captured flag so we no its already been captured captured_ = true; return result; } // server_properties::capture()