const std::string get_user_dir(const UserDir userdir) { std::string path; std::string envVar; if (userdir == UserDir::Config) envVar = get_env_var("XDG_CONFIG_HOME"); else if (userdir == UserDir::Data) envVar = get_env_var("XDG_DATA_HOME"); if (envVar.empty()) { envVar = get_env_var("HOME"); if (!envVar.empty()) { path += std::string(envVar); if (userdir == UserDir::Config) path += "/.config"; else if (userdir == UserDir::Data) path += "/.local/share"; } } if (!path.empty()) { path += "/" OBV_NAME "/"; if (create_dirs(path)) return path; // Check if dir already exists and create it otherwise } return "./"; // Something went wrong, use current dir }
configuration::configuration() { // set defaults #ifdef WINDOWS assign_value(CONFIG_FILE, get_env_var("PROGRAMFILES") + "\\sdns\\sdns.conf"); assign_value(ROOT_HINTS_FILE, get_env_var("PROGRAMFILES") + "\\sdns\\root.names"); assign_value(STATIC_RECORDS_FILE, get_env_var("PROGRAMFILES") + "\\sdns\\local.names"); assign_value(DNS_FORWARDERS_DIR, get_env_var("PROGRAMFILES") + "\\sdns\\forwarders"); #else assign_value(CONFIG_FILE, "/etc/sdns/sdns.conf"); assign_value(ROOT_HINTS_FILE, "/etc/sdns/root.names"); assign_value(STATIC_RECORDS_FILE, "/etc/sdns/local.names"); assign_value(DNS_FORWARDERS_DIR, "/etc/sdns/forwarders"); #endif assign_value(SDNS_USER, ""); assign_value(BIND4_ADDRS, std::vector<uint32_t>(1, htonl(INADDR_LOOPBACK))); assign_value(BIND6_ADDRS, std::vector<in6_addr>(1, in6addr_loopback)); assign_value(RETRIES_PER_NAMESERVER_ADDR, 4); // had tried setting max depth at 10 and download.windowsupdate.com could not resolve first try with empty cache because it has five (5) chained CNAMEs // which exceeded depth 10 between following CNAMEs and following referrals assign_value(MAX_DNS_QUERY_DEPTH, 25); assign_value(MAX_UDP_SIZE, 65535); assign_value(MAX_CLIENT_UDP_RESPONSE, 8192); assign_value(QUERY_RETRY_MS, 500); assign_value(DNS_PORT, 53); assign_value(SNOW_NAMESERV_PORT, 8); assign_value(SNOW_NAMESERV_TIMEOUT_SECS, 1); assign_value(SNOW_NAMESERV_TIMEOUT_RETRIES, 8); assign_value(CACHE_SIZE, 1024*1024); assign_value(MAX_TTL, 86400); assign_value(DEFAULT_STATIC_TTL, 1800); assign_value(MAX_TCP_CLIENTS, 250); assign_value(SNOW, true); }
std::string uhd::get_app_path(void){ const std::string uhdcalib_path = get_env_var("UHD_CONFIG_DIR"); if (not uhdcalib_path.empty()) return uhdcalib_path; const std::string appdata_path = get_env_var("APPDATA"); if (not appdata_path.empty()) return appdata_path; const std::string home_path = get_env_var("HOME"); if (not home_path.empty()) return home_path; return uhd::get_tmp_path(); }
// Automatically starts when UE4 is started. // Populates the Token variable with the robot user's token. void CloudyWebAPIImpl::StartupModule() { UE_LOG(CloudyWebAPILog, Warning, TEXT("CloudyWebAPI started")); // Initialize the array with InitialArraySize SaveFileUrls.SetNumUninitialized(InitialArraySize); // BaseUrl will be updated with the correct URL BaseUrl = get_env_var(ENV_VAR_CLOUDYWEB_URL).c_str(); // Token variable will be populated with the robot user's token. AttemptAuthentication(); // Set up socket listener to receive commands from CloudyWeb //Create Socket FIPv4Endpoint Endpoint(SERVER_ENDPOINT); ListenSocket = FTcpSocketBuilder(SERVER_NAME).AsReusable().BoundToEndpoint(Endpoint).Listening(8); //Set Buffer Size int32 NewSize = 0; ListenSocket->SetReceiveBufferSize(BUFFER_SIZE, NewSize); TcpListener = new FTcpListener(*ListenSocket, CONNECTION_THREAD_TIME); TcpListener->OnConnectionAccepted().BindRaw(this, &CloudyWebAPIImpl::InputHandler); FTicker::GetCoreTicker().AddTicker(FTickerDelegate::CreateRaw(this, &CloudyWebAPIImpl::CheckConnection), CONNECTION_THREAD_TIME); // initialise class variables InputStr = ""; HasInputStrChanged = false; }
/** * Uses the robot user's username and password to obtain an operator token to use for * various functions. The username and password is obtained from the system environment variables. * * * @return Returns true if the authentication was successful. Else, returns false. */ bool CloudyWebAPIImpl::AttemptAuthentication() { bool RequestSuccess = false; FString Username; FString Password; FString value = get_env_var(ENV_VAR_ROBOT_USER).c_str(); value.Split(";", &Username, &Password); UE_LOG(CloudyWebAPILog, Warning, TEXT("RobotUserName = %s, RobotPassword = %s"), *Username.Trim(), *Password.Trim()); FString Url = BaseUrl + AuthUrl; // "http://127.0.0.1:8000/api-token-auth/"; FString ContentString; TSharedPtr<FJsonObject> JsonObject = MakeShareable(new FJsonObject()); JsonObject->SetStringField(TEXT("username"), Username.Trim()); JsonObject->SetStringField(TEXT("password"), Password.Trim()); TSharedRef<TJsonWriter<TCHAR>> JsonWriter = TJsonWriterFactory<>::Create(&ContentString); FJsonSerializer::Serialize(JsonObject.ToSharedRef(), JsonWriter); TSharedRef<IHttpRequest> HttpRequest = FHttpModule::Get().CreateRequest(); HttpRequest->SetHeader(TEXT("Content-Type"), TEXT("application/json")); HttpRequest->SetURL(Url); HttpRequest->SetVerb(TEXT("POST")); HttpRequest->SetContentAsString(ContentString); HttpRequest->OnProcessRequestComplete().BindRaw(this, &CloudyWebAPIImpl::OnAuthResponseComplete); RequestSuccess = HttpRequest->ProcessRequest(); UE_LOG(CloudyWebAPILog, Warning, TEXT("URL = %s"), *Url); return RequestSuccess; }
static std::vector<fs::path> get_env_paths(const std::string &var_name){ /*********************************************************************** * Determine the paths separator **********************************************************************/ #ifdef UHD_PLATFORM_WIN32 static const std::string env_path_sep = ";"; #else static const std::string env_path_sep = ":"; #endif /*UHD_PLATFORM_WIN32*/ #define path_tokenizer(inp) \ boost::tokenizer<boost::char_separator<char> > \ (inp, boost::char_separator<char>(env_path_sep.c_str())) std::string var_value = get_env_var(var_name); //convert to filesystem path, filter blank paths std::vector<fs::path> paths; if (var_value.empty()) return paths; //FIXME boost tokenizer throws w/ blank strings on some platforms BOOST_FOREACH(const std::string &path_string, path_tokenizer(var_value)){ if (path_string.empty()) continue; paths.push_back(fs::system_complete(path_string)); } return paths; }
int builtin_launch(t_cmd *cmd, t_system *sys) { if (cmd->path == NULL) return (launch_not_found(cmd)); get_env_var(cmd, sys); check_if_wildcard(cmd, sys); if (execve(cmd->path, cmd->args, sys->env) == -1) return (launch_not_found(cmd)); return (SIGRTN_NOERR); }
/*! Expand a tilde character to the $HOME path. * * The path passed to this function must start with the tilde character in order * for this function to work properly. If it does not, it will simply return the * original path. The $HOME environment variable must exist. * * \param path The path starting with the tilde character * \returns The same path with the tilde expanded to contents of $HOME. */ static std::string expand_home_directory(std::string path) { boost::trim(path); if(path.empty() || (path[0] != '~')) { return path; } std::string user_home_path = get_env_var("HOME"); path.replace(0, 1, user_home_path); return path; }
void built_unsetenv(char **entry) { t_env *env_line; if (!entry[0]) ft_putendl("\033[33munsetenv: too few arguments.\033[0m"); else { env_line = get_env_var(entry[0]); if (env_line && env_line->var) suppr_link(env_line->var); } }
configuration::configuration() { // set defaults // strings #ifdef WINDOWS //std::string programdata = get_env_var("PROGRAMDATA"); // [new ALLUSERSPROFILE, doesn't exist on XP/2003] std::string programdata = get_env_var("ALLUSERSPROFILE"); assign_value(CONFIG_FILE, programdata+"/Application Data/snow/snow.conf"); assign_value(KEY_FILE, programdata+"/Application Data/snow/key.pem"); assign_value(CERT_FILE, programdata+"/Application Data/snow/cert.pem"); assign_value(KNOWN_PEERS_FILE, programdata+"/Application Data/snow/known_peers"); assign_value(DH_PARAMS_FILE, programdata+"/Application Data/snow/DH_params"); assign_value(CLONE_DEVICE, "/dev/net/tun"); // (not used on windows) assign_value(VIRTUAL_INTERFACE, "auto"); // in config file, "{[GUID]}" of the interface; auto means try to find in registry assign_value(ADDRESS_ASSIGNMENT_FILE, programdata+"/Application Data/snow/address_assignments"); assign_value(PERMANENT_ADDRESS_ASSIGNMENT_FILE, programdata+"/Application Data/snow/permanent_address_assignments"); #else assign_value(CONFIG_FILE, "/etc/snow/snow.conf"); assign_value(KEY_FILE, "/etc/snow/key.pem"); assign_value(CERT_FILE, "/etc/snow/cert.pem"); assign_value(KNOWN_PEERS_FILE, "/var/lib/snow/known_peers"); assign_value(DH_PARAMS_FILE, "/etc/snow/DH_params"); assign_value(CLONE_DEVICE, "/dev/net/tun"); assign_value(VIRTUAL_INTERFACE, "snow0"); assign_value(ADDRESS_ASSIGNMENT_FILE, "/var/lib/snow/address_assignments"); assign_value(PERMANENT_ADDRESS_ASSIGNMENT_FILE, "/etc/snow/permanent_address_assignments"); assign_value(SNOW_USER, ""); #endif assign_value(NATPOOL_NETWORK, "172.16.0.0"); assign_value(PUBLIC_IPV4_ADDRS, std::vector<uint32_t>()); // unsigned integers assign_value(DTLS_BIND_PORT, 0); // 0 is not valid, must set an arbitrary value in the configuration file assign_value(DTLS_BIND6_PORT, 8); assign_value(DTLS_OUTGOING_PORT, 0); // 0 is not valid, must set an arbitrary value in the configuration file assign_value(DHT_PORT, 8); assign_value(NAMESERV_PORT, 8); assign_value(NAMESERV_TIMEOUT_SECS, 7); assign_value(DTLS_IDLE_TIMEOUT_SECS, 4000); assign_value(HEARTBEAT_SECONDS, 115); assign_value(HEARTBEAT_RETRIES, 5); assign_value(NAT_IP_GRACE_PERIOD_SECONDS, 7200); assign_value(DHT_BOOTSTRAP_TARGET, 6); assign_value(DHT_MAX_PEERS, 99); assign_value(NATPOOL_NETMASK_BITS, 12); assign_value(VIRTUAL_INTERFACE_MTU, 1419); // boolean values assign_value(DHT_RFC1918_ADDRESSES, true); assign_value(DHT_LINK_LOCAL_ADDRESSES, false); assign_value(NEVER_TRUST_PEER_VISIBLE_IPADDRS, false); }
void create_prompt(t_utils *utils) { char *pwd; int len; if ((pwd = get_env_var(utils, "PWD")) == NULL) pwd = strdup(YELLOW"[42sh] ~ >"DEFAULT); g_prompt = strdup(pwd); len = strlen(g_prompt); if ((g_prompt = realloc(g_prompt, len + 3)) == NULL) return ; g_prompt[len] = ':'; g_prompt[len + 1] = ' '; g_prompt[len + 2] = 0; }
char *get_home_via_username(t_vars *v) { char *home; char *tmp; home = NULL; tmp = get_env_var(v, "USERNAME"); if (tmp) { home = my_strcat("/home/", tmp); tmp = my_xxfree(tmp); tmp = home; home = my_strcat(tmp, "/"); tmp = my_xxfree(tmp); } return (home); }
void init_term(t_all *all, char **dupenv) { char *term_name; term_name = NULL; if ((term_name = get_env_var(dupenv, "TERM=")) == NULL) term_error("GETENV"); if (tgetent(NULL, term_name) == -1) term_error("TGETENT"); if (tcgetattr(0, &all->term) == -1) ; all->term.c_lflag &= ~(ECHO | ICANON); all->term.c_cc[VMIN] = 1; all->term.c_cc[VTIME] = 0; if (tcsetattr(0, TCSADRAIN, &all->term) == -1) ; }
char *get_home(t_vars *v) { char *home; char *tmp; home = get_env_var(v, "HOME"); if (!home) { if ((home = get_home_via_username(v))) { tmp = my_strcat("HOME=", home); v->env = add_elem_to_tab(v->env, tmp); tmp = my_xxfree(tmp); return (home); } else home = ask_home(v); } return (home); }
/*! Get a vector of paths from an environment variable. * * Reads an environment variable, which should contain a list of paths, and * returns a vector of those paths in the form of strings. * * \param var_name The environment variable name to read. * \returns The vector of paths from the environment variable. */ static std::vector<std::string> get_env_paths(const std::string &var_name){ #ifdef UHD_PLATFORM_WIN32 static const std::string env_path_sep = ";"; #else static const std::string env_path_sep = ":"; #endif /*UHD_PLATFORM_WIN32*/ #define path_tokenizer(inp) \ boost::tokenizer<boost::char_separator<char> > \ (inp, boost::char_separator<char>(env_path_sep.c_str())) std::string var_value = get_env_var(var_name); std::vector<std::string> paths; //convert to full filesystem path, filter blank paths if (var_value.empty()) return paths; for(const std::string &path_string: path_tokenizer(var_value)){ if (path_string.empty()) continue; paths.push_back(fs::system_complete(path_string).string()); } return paths; }
/* *---------------------------------------------------------------------- * * fcgi_config_set_config -- * * Implements the FastCGI FCGIConfig configuration directive. * This command adds routines to control the execution of the * dynamic FastCGI processes. * * *---------------------------------------------------------------------- */ const char *fcgi_config_set_config(cmd_parms *cmd, void *dummy, const char *arg) { pool * const p = cmd->pool; pool * const tp = cmd->temp_pool; const char *err, *option; const char * const name = cmd->cmd->name; /* Allocate temp storage for an initial environment */ unsigned int envc = 0; char **envp = (char **)ap_pcalloc(tp, sizeof(char *) * (MAX_INIT_ENV_VARS + 3)); err = ap_check_cmd_context(cmd, GLOBAL_ONLY); if (err) { return err; } /* Parse the directive arguments */ while (*arg) { option = ap_getword_conf(tp, &arg); if (strcasecmp(option, "-maxProcesses") == 0) { if ((err = get_u_int(tp, &arg, &dynamicMaxProcs, 1))) return invalid_value(tp, name, NULL, option, err); } else if (strcasecmp(option, "-minProcesses") == 0) { if ((err = get_int(tp, &arg, &dynamicMinProcs, 0))) return invalid_value(tp, name, NULL, option, err); } else if (strcasecmp(option, "-maxClassProcesses") == 0) { if ((err = get_int(tp, &arg, &dynamicMaxClassProcs, 1))) return invalid_value(tp, name, NULL, option, err); } else if (strcasecmp(option, "-killInterval") == 0) { if ((err = get_u_int(tp, &arg, &dynamicKillInterval, 1))) return invalid_value(tp, name, NULL, option, err); } else if (strcasecmp(option, "-updateInterval") == 0) { if ((err = get_u_int(tp, &arg, &dynamicUpdateInterval, 1))) return invalid_value(tp, name, NULL, option, err); } else if (strcasecmp(option, "-gainValue") == 0) { if ((err = get_float(tp, &arg, &dynamicGain, 0.0, 1.0))) return invalid_value(tp, name, NULL, option, err); } else if ((strcasecmp(option, "-singleThreshold") == 0) || (strcasecmp(option, "-singleThreshhold") == 0)) { if ((err = get_int(tp, &arg, &dynamicThreshold1, 0))) return invalid_value(tp, name, NULL, option, err); } else if ((strcasecmp(option, "-multiThreshold") == 0) || (strcasecmp(option, "-multiThreshhold") == 0)) { if ((err = get_int(tp, &arg, &dynamicThresholdN, 0))) return invalid_value(tp, name, NULL, option, err); } else if (strcasecmp(option, "-startDelay") == 0) { if ((err = get_u_int(tp, &arg, &dynamicPleaseStartDelay, 1))) return invalid_value(tp, name, NULL, option, err); } else if (strcasecmp(option, "-initial-env") == 0) { if ((err = get_env_var(p, &arg, envp, &envc))) return invalid_value(tp, name, NULL, option, err); } else if (strcasecmp(option, "-pass-header") == 0) { if ((err = get_pass_header(p, &arg, &dynamic_pass_headers))) return invalid_value(tp, name, NULL, option, err); } else if (strcasecmp(option, "-appConnTimeout") == 0) { if ((err = get_u_int(tp, &arg, &dynamicAppConnectTimeout, 0))) return invalid_value(tp, name, NULL, option, err); } else if (strcasecmp(option, "-idle-timeout") == 0) { if ((err = get_u_int(tp, &arg, &dynamic_idle_timeout, 1))) return invalid_value(tp, name, NULL, option, err); } else if (strcasecmp(option, "-listen-queue-depth") == 0) { if ((err = get_u_int(tp, &arg, &dynamicListenQueueDepth, 1))) return invalid_value(tp, name, NULL, option, err); } else if (strcasecmp(option, "-min-server-life") == 0) { if ((err = get_int(tp, &arg, &dynamicMinServerLife, 0))) return invalid_value(tp, name, NULL, option, err); } else if (strcasecmp(option, "-restart-delay") == 0) { if ((err = get_u_int(tp, &arg, &dynamicRestartDelay, 0))) return invalid_value(tp, name, NULL, option, err); } else if (strcasecmp(option, "-init-start-delay") == 0) { if ((err = get_u_int(tp, &arg, &dynamicInitStartDelay, 0))) return invalid_value(tp, name, NULL, option, err); } else if (strcasecmp(option, "-processSlack") == 0) { if ((err = get_u_int(tp, &arg, &dynamicProcessSlack, 1))) return invalid_value(tp, name, NULL, option, err); } else if (strcasecmp(option, "-restart") == 0) { dynamicAutoRestart = 1; } else if (strcasecmp(option, "-autoUpdate") == 0) { dynamicAutoUpdate = 1; } else if (strcasecmp(option, "-flush") == 0) { dynamicFlush = TRUE; } else { return ap_psprintf(tp, "%s: invalid option: %s", name, option); } } /* while */ if (dynamicProcessSlack >= dynamicMaxProcs + 1) { /* the kill policy would work unexpectedly */ return ap_psprintf(tp, "%s: processSlack (%u) must be less than maxProcesses (%u) + 1", name, dynamicProcessSlack, dynamicMaxProcs); } /* Move env array to a surviving pool, leave 2 extra slots for * WIN32 _FCGI_MUTEX_ and _FCGI_SHUTDOWN_EVENT_ */ dynamicEnvp = (char **)ap_pcalloc(p, sizeof(char *) * (envc + 4)); memcpy(dynamicEnvp, envp, sizeof(char *) * envc); return NULL; }
unsigned long get_env(const char *name) { return get_env_var(name); }
/*********************************************************************** * Get a list of special purpose paths **********************************************************************/ std::string uhd::get_pkg_path(void) { return get_env_var("UHD_PKG_PATH", UHD_PKG_PATH); }
/******************************************************************************* * Configure a static FastCGI server. */ const char *fcgi_config_new_static_server(cmd_parms *cmd, void *dummy, const char *arg) { fcgi_server *s; pool *p = cmd->pool, *tp = cmd->temp_pool; const char *name = cmd->cmd->name; char *fs_path = ap_getword_conf(p, &arg); const char *option, *err; /* Allocate temp storage for the array of initial environment variables */ char **envp = ap_pcalloc(tp, sizeof(char *) * (MAX_INIT_ENV_VARS + 3)); unsigned int envc = 0; #ifdef WIN32 HANDLE mutex; #endif err = ap_check_cmd_context(cmd, NOT_IN_LIMIT|NOT_IN_DIR_LOC_FILE); if (err) { return err; } if (*fs_path == '\0') return "AppClass requires a pathname!?"; if ((err = fcgi_config_set_fcgi_uid_n_gid(1)) != NULL) return ap_psprintf(tp, "%s %s: %s", name, fs_path, err); #ifdef APACHE2 if (apr_filepath_merge(&fs_path, "", fs_path, 0, p)) return ap_psprintf(tp, "%s %s: invalid filepath", name, fs_path); #else fs_path = ap_os_canonical_filename(p, fs_path); #endif fs_path = ap_server_root_relative(p, fs_path); ap_getparents(fs_path); ap_no2slash(fs_path); /* See if we've already got one of these configured */ s = fcgi_util_fs_get_by_id(fs_path, fcgi_util_get_server_uid(cmd->server), fcgi_util_get_server_gid(cmd->server)); if (s != NULL) { if (fcgi_wrapper) { return ap_psprintf(tp, "%s: redefinition of a previously defined FastCGI " "server \"%s\" with uid=%ld and gid=%ld", name, fs_path, (long) fcgi_util_get_server_uid(cmd->server), (long) fcgi_util_get_server_gid(cmd->server)); } else { return ap_psprintf(tp, "%s: redefinition of a previously defined FastCGI server \"%s\"", name, fs_path); } } err = fcgi_util_fs_is_path_ok(tp, fs_path, NULL); if (err != NULL) { return ap_psprintf(tp, "%s: \"%s\" %s", name, fs_path, err); } s = fcgi_util_fs_new(p); s->fs_path = fs_path; s->directive = APP_CLASS_STANDARD; s->restartOnExit = TRUE; s->numProcesses = 1; #ifdef WIN32 /* TCP FastCGI applications require SystemRoot be present in the environment * Put it in both for consistency to the application */ fcgi_config_set_env_var(p, envp, &envc, "SystemRoot"); mutex = CreateMutex(NULL, FALSE, fs_path); if (mutex == NULL) { ap_log_error(FCGI_LOG_ALERT, fcgi_apache_main_server, "FastCGI: CreateMutex() failed"); return "failed to create FastCGI application accept mutex"; } SetHandleInformation(mutex, HANDLE_FLAG_INHERIT, TRUE); s->mutex_env_string = ap_psprintf(p, "_FCGI_MUTEX_=%ld", mutex); #endif /* Parse directive arguments */ while (*arg) { option = ap_getword_conf(tp, &arg); if (strcasecmp(option, "-processes") == 0) { if ((err = get_u_int(tp, &arg, &s->numProcesses, 1))) return invalid_value(tp, name, fs_path, option, err); } else if (strcasecmp(option, "-restart-delay") == 0) { if ((err = get_u_int(tp, &arg, &s->restartDelay, 0))) return invalid_value(tp, name, fs_path, option, err); } else if (strcasecmp(option, "-init-start-delay") == 0) { if ((err = get_int(tp, &arg, &s->initStartDelay, 0))) return invalid_value(tp, name, fs_path, option, err); } else if (strcasecmp(option, "-min-server-life") == 0) { if ((err = get_u_int(tp, &arg, &s->minServerLife, 0))) return invalid_value(tp, name, NULL, option, err); } else if (strcasecmp(option, "-priority") == 0) { if ((err = get_u_int(tp, &arg, &s->processPriority, 0))) return invalid_value(tp, name, fs_path, option, err); } else if (strcasecmp(option, "-listen-queue-depth") == 0) { if ((err = get_u_int(tp, &arg, &s->listenQueueDepth, 1))) return invalid_value(tp, name, fs_path, option, err); } else if (strcasecmp(option, "-appConnTimeout") == 0) { if ((err = get_u_int(tp, &arg, &s->appConnectTimeout, 0))) return invalid_value(tp, name, fs_path, option, err); } else if (strcasecmp(option, "-idle-timeout") == 0) { if ((err = get_u_int(tp, &arg, &s->idle_timeout, 1))) return invalid_value(tp, name, fs_path, option, err); } else if (strcasecmp(option, "-port") == 0) { if ((err = get_u_short(tp, &arg, &s->port, 1))) return invalid_value(tp, name, fs_path, option, err); } else if (strcasecmp(option, "-socket") == 0) { s->socket_path = ap_getword_conf(tp, &arg); if (*s->socket_path == '\0') return invalid_value(tp, name, fs_path, option, "\"\""); } else if (strcasecmp(option, "-initial-env") == 0) { if ((err = get_env_var(p, &arg, envp, &envc))) return invalid_value(tp, name, fs_path, option, err); } else if (strcasecmp(option, "-pass-header") == 0) { if ((err = get_pass_header(p, &arg, &s->pass_headers))) return invalid_value(tp, name, fs_path, option, err); } else if (strcasecmp(option, "-flush") == 0) { s->flush = 1; } else if (strcasecmp(option, "-nph") == 0) { s->nph = 1; } else if (strcasecmp(option, "-user") == 0) { #ifdef WIN32 return ap_psprintf(tp, "%s %s: the -user option isn't supported on WIN", name, fs_path); #else s->user = ap_getword_conf(tp, &arg); if (*s->user == '\0') return invalid_value(tp, name, fs_path, option, "\"\""); #endif } else if (strcasecmp(option, "-group") == 0) { #ifdef WIN32 return ap_psprintf(tp, "%s %s: the -group option isn't supported on WIN", name, fs_path); #else s->group = ap_getword_conf(tp, &arg); if (*s->group == '\0') return invalid_value(tp, name, fs_path, option, "\"\""); #endif } else { return ap_psprintf(tp, "%s %s: invalid option: %s", name, fs_path, option); } } /* while */ #ifndef WIN32 if (fcgi_wrapper) { if (s->group == NULL) { s->group = ap_psprintf(tp, "#%ld", (long)fcgi_util_get_server_gid(cmd->server)); } if (s->user == NULL) { s->user = ap_psprintf(p, "#%ld", (long)fcgi_util_get_server_uid(cmd->server)); } s->uid = ap_uname2id(s->user); s->gid = ap_gname2id(s->group); } else if (s->user || s->group) { ap_log_error(FCGI_LOG_WARN, cmd->server, "FastCGI: there is no " "fastcgi wrapper set, user/group options are ignored"); } if ((err = fcgi_util_fs_set_uid_n_gid(p, s, s->uid, s->gid))) { return ap_psprintf(tp, "%s %s: invalid user or group: %s", name, fs_path, err); } #endif /* !WIN32 */ if (s->socket_path != NULL && s->port != 0) { return ap_psprintf(tp, "%s %s: -port and -socket are mutually exclusive options", name, fs_path); } /* Move env array to a surviving pool */ s->envp = (char **)ap_pcalloc(p, sizeof(char *) * (envc + 4)); memcpy(s->envp, envp, sizeof(char *) * envc); /* Initialize process structs */ s->procs = fcgi_util_fs_create_procs(p, s->numProcesses); /* Build the appropriate sockaddr structure */ if (s->port != 0) { err = fcgi_util_socket_make_inet_addr(p, (struct sockaddr_in **)&s->socket_addr, &s->socket_addr_len, NULL, s->port); if (err != NULL) return ap_psprintf(tp, "%s %s: %s", name, fs_path, err); #ifdef WIN32 err = fcgi_util_socket_make_inet_addr(p, (struct sockaddr_in **)&s->dest_addr, &s->socket_addr_len, "localhost", s->port); if (err != NULL) return ap_psprintf(tp, "%s %s: %s", name, fs_path, err); #endif } else { if (s->socket_path == NULL) s->socket_path = fcgi_util_socket_hash_filename(tp, fs_path, s->user, s->group); if (fcgi_socket_dir == NULL) { #ifdef WIN32 fcgi_socket_dir = DEFAULT_SOCK_DIR; #else fcgi_socket_dir = ap_server_root_relative(p, DEFAULT_SOCK_DIR); #endif } s->socket_path = fcgi_util_socket_make_path_absolute(p, s->socket_path, 0); #ifndef WIN32 err = fcgi_util_socket_make_domain_addr(p, (struct sockaddr_un **)&s->socket_addr, &s->socket_addr_len, s->socket_path); if (err != NULL) return ap_psprintf(tp, "%s %s: %s", name, fs_path, err); #endif } /* Add it to the list of FastCGI servers */ fcgi_util_fs_add(s); return NULL; }
/** * Extended internal log helper function. Use msr_log instead. If fixup is * true, the message will be stripped of any trailing newline and any * required bytes will be escaped. */ static void internal_log_ex(request_rec *r, directory_config *dcfg, modsec_rec *msr, int level, int fixup, const char *text, va_list ap) { apr_size_t nbytes, nbytes_written; apr_file_t *debuglog_fd = NULL; int filter_debug_level = 0; char *remote = NULL; char *parse_remote = NULL; char *saved = NULL; char *str = NULL; char str1[1024] = ""; char str2[1256] = ""; /* Find the logging FD and determine the logging level from configuration. */ if (dcfg != NULL) { if ((dcfg->debuglog_fd != NULL)&&(dcfg->debuglog_fd != NOT_SET_P)) { debuglog_fd = dcfg->debuglog_fd; } if (dcfg->debuglog_level != NOT_SET) { filter_debug_level = dcfg->debuglog_level; } } /* Return immediately if we don't have where to write * or if the log level of the message is higher than * wanted in the log. */ if ((level > 3)&&( (debuglog_fd == NULL) || (level > filter_debug_level) )) return; /* Construct the message. */ apr_vsnprintf(str1, sizeof(str1), text, ap); if (fixup) { int len = strlen(str1); /* Strip line ending. */ if (len && str1[len - 1] == '\n') { str1[len - 1] = '\0'; } if (len > 1 && str1[len - 2] == '\r') { str1[len - 2] = '\0'; } } /* Construct the log entry. */ apr_snprintf(str2, sizeof(str2), "[%s] [%s/sid#%pp][rid#%pp][%s][%d] %s\n", current_logtime(msr->mp), ap_get_server_name(r), (r->server), r, ((r->uri == NULL) ? "" : log_escape_nq(msr->mp, r->uri)), level, (fixup ? log_escape_nq(msr->mp, str1) : str1)); /* Write to the debug log. */ if ((debuglog_fd != NULL)&&(level <= filter_debug_level)) { nbytes = strlen(str2); apr_file_write_full(debuglog_fd, str2, nbytes, &nbytes_written); } /* Send message levels 1-3 to the Apache error log and * add it to the message list in the audit log. */ if (level <= 3) { char *unique_id = (char *)get_env_var(r, "UNIQUE_ID"); char *hostname = (char *)msr->hostname; if (unique_id != NULL) { unique_id = apr_psprintf(msr->mp, " [unique_id \"%s\"]", log_escape(msr->mp, unique_id)); } else unique_id = ""; if (hostname != NULL) { hostname = apr_psprintf(msr->mp, " [hostname \"%s\"]", log_escape(msr->mp, hostname)); } else hostname = ""; #if AP_SERVER_MAJORVERSION_NUMBER > 1 && AP_SERVER_MINORVERSION_NUMBER > 2 ap_log_rerror(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, 0, r, "[client %s] ModSecurity: %s%s [uri \"%s\"]%s", r->useragent_ip ? r->useragent_ip : r->connection->client_ip, str1, hostname, log_escape(msr->mp, r->uri), unique_id); #else ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, 0, r->server, "[client %s] ModSecurity: %s%s [uri \"%s\"]%s", msr->remote_addr ? msr->remote_addr : r->connection->remote_ip, str1, hostname, log_escape(msr->mp, r->uri), unique_id); #endif /* Add this message to the list. */ if (msr != NULL) { /* Force relevency if this is an alert */ msr->is_relevant++; *(const char **)apr_array_push(msr->alerts) = apr_pstrdup(msr->mp, str1); } } return; }