static uid_t dropped_uid() { uid_t uid = -1; try { uid = boost::lexical_cast<int>(user.get()); } catch (boost::bad_lexical_cast const &) { uid = uid_by_name(user.get()); } return uid; }
void Window::on_start_button () { app.argument.clear(); app.option.clear(); // argument list: for (Gtk::Box_Helpers::BoxList::iterator it = arguments_box.children().begin(); it != arguments_box.children().end(); ++it) { Argument* arg = (Argument*) (it->get_widget()); app.argument.push_back (arg->get()); if (app.argument.back().type() == Undefined) { error (String ("value supplied for argument \"") + arg->arg.lname + "\" is not valid"); return; } } ProgressBar::display = true; App::log_level = 1 + message_level.get_active_row_number(); stop_button.set_sensitive (true); start_button.set_sensitive (false); try { app.execute(); print ("\nCompleted successfully\n\n"); } catch (...) { error ("Error during execution!"); } stop_button.set_sensitive (false); start_button.set_sensitive (true); }
bool loadConfigFile() { std::string path(config.get()); struct stat st; if (::stat(path.c_str(), &st) < 0 || !S_ISREG(st.st_mode)) { std::cerr << "Not a file: " << path << std::endl; return false; } std::ifstream is(path.c_str(), std::ios::binary); if (!is.is_open()) { std::cerr << "File not readable: " << path << std::endl; return false; } is.seekg(0, std::ios_base::end); std::streampos len = is.tellg(); is.seekg(0, std::ios::beg); std::string data; if (len > 0) { data.resize(len); is.read(&data[0], len); std::string error; if (!ArgumentBase::parseData(data, error)) { std::cerr << error << std::endl; return false; } } return true; }
static void printRequest(HttpRequestHolder const &req, StatServer *ss) { if (debugHttp.enabled()) { LogNotice << "http serving" << req->url(); } LogDebug << "Serving:" << req->method() << req->url(); boost::shared_ptr<RequestInFlight> rif(new RequestInFlight(req.p_, ss, filesDir.get())); ss->service().post(boost::bind(&RequestInFlight::go, rif)); }
void drop_privileges() { LogSpam << "drop_privileges()"; uid_t uid = dropped_uid(); if (uid < 0) { throw std::runtime_error("User " + user.get() + " is not known."); } if ((geteuid() != uid) && (seteuid(uid) < 0)) { throw std::runtime_error("Could not seteuid(" + boost::lexical_cast<std::string>(uid) + ")."); } }