From 422c749b84f575ea4be68974dd874b5890bd439c Mon Sep 17 00:00:00 2001 From: Karol Mroz Date: Tue, 9 Feb 2016 15:10:15 -0800 Subject: [PATCH] rgw_main: break up frontend config parsing Before invoking global_init(), determine which frontends are configured. If Civetweb is to be used, ensure it will be responsible for dropping permissions after radosgw startup. Signed-off-by: Karol Mroz --- src/rgw/rgw_main.cc | 82 +++++++++++++++++++++++++-------------------- 1 file changed, 46 insertions(+), 36 deletions(-) diff --git a/src/rgw/rgw_main.cc b/src/rgw/rgw_main.cc index 8f44299db05..b5adf5ebd25 100644 --- a/src/rgw/rgw_main.cc +++ b/src/rgw/rgw_main.cc @@ -200,8 +200,53 @@ int main(int argc, const char **argv) vector args; argv_to_vec(argc, argv, args); env_to_vec(args); + + // First, let's determine which frontends are configured. + int flags = CINIT_FLAG_UNPRIVILEGED_DAEMON_DEFAULTS; + global_pre_init(&def_args, args, CEPH_ENTITY_TYPE_CLIENT, CODE_ENVIRONMENT_DAEMON, + flags); + + list frontends; + get_str_list(g_conf->rgw_frontends, ",", frontends); + multimap fe_map; + list configs; + if (frontends.empty()) { + frontends.push_back("fastcgi"); + } + for (list::iterator iter = frontends.begin(); iter != frontends.end(); ++iter) { + string& f = *iter; + + if (f.find("civetweb") != string::npos) { + // If civetweb is configured as a frontend, prevent global_init() from + // dropping permissions by setting the appropriate flag. + flags |= CINIT_FLAG_DEFER_DROP_PRIVILEGES; + if (f.find("port") != string::npos) { + // check for the most common ws problems + if ((f.find("port=") == string::npos) || + (f.find("port= ") != string::npos)) { + derr << "WARNING: civetweb frontend config found unexpected spacing around 'port' (ensure civetweb port parameter has the form 'port=80' with no spaces before or after '=')" << dendl; + } + } + } + + RGWFrontendConfig *config = new RGWFrontendConfig(f); + int r = config->init(); + if (r < 0) { + cerr << "ERROR: failed to init config: " << f << std::endl; + return EINVAL; + } + + configs.push_back(config); + + string framework = config->get_framework(); + fe_map.insert(pair(framework, config)); + } + + // Now that we've determined which frontend(s) to use, continue with global + // initialization. Passing false as the final argument ensures that + // global_pre_init() is not invoked twice. global_init(&def_args, args, CEPH_ENTITY_TYPE_CLIENT, CODE_ENVIRONMENT_DAEMON, - CINIT_FLAG_UNPRIVILEGED_DAEMON_DEFAULTS, "rgw_data"); + flags, "rgw_data", false); for (std::vector::iterator i = args.begin(); i != args.end(); ++i) { if (ceph_argparse_flag(args, i, "-h", "--help", (char*)NULL)) { @@ -331,41 +376,6 @@ int main(int argc, const char **argv) register_async_signal_handler(SIGUSR1, handle_sigterm); sighandler_alrm = signal(SIGALRM, godown_alarm); - list frontends; - get_str_list(g_conf->rgw_frontends, ",", frontends); - - multimap fe_map; - list configs; - if (frontends.empty()) { - frontends.push_back("fastcgi"); - } - for (list::iterator iter = frontends.begin(); - iter != frontends.end(); ++iter) { - string& f = *iter; - - if (f.find("civetweb") != string::npos) { - if (f.find("port") != string::npos) { - // check for the most common ws problems - if ((f.find("port=") == string::npos) || - (f.find("port= ") != string::npos)) { - derr << "WARNING: civetweb frontend config found unexpected spacing around 'port' (ensure civetweb port parameter has the form 'port=80' with no spaces before or after '=')" << dendl; - } - } - } - - RGWFrontendConfig *config = new RGWFrontendConfig(f); - int r = config->init(); - if (r < 0) { - cerr << "ERROR: failed to init config: " << f << std::endl; - return EINVAL; - } - - configs.push_back(config); - - string framework = config->get_framework(); - fe_map.insert(pair(framework, config)); - } - list fes; for (multimap::iterator fiter = fe_map.begin();