/* * Initialize timezone library * * This is called after initial loading of postgresql.conf. If no TimeZone * setting was found therein, we try to derive one from the environment. * Likewise for log_timezone. */ void pg_timezone_initialize(void) { pg_tz *def_tz = NULL; /* Do we need to try to figure the session timezone? */ if (pg_strcasecmp(GetConfigOption("timezone", false), "UNKNOWN") == 0) { /* Select setting */ def_tz = select_default_timezone(); session_timezone = def_tz; /* Tell GUC about the value. Will redundantly call pg_tzset() */ SetConfigOption("timezone", pg_get_timezone_name(def_tz), PGC_POSTMASTER, PGC_S_ARGV); } /* What about the log timezone? */ if (pg_strcasecmp(GetConfigOption("log_timezone", false), "UNKNOWN") == 0) { /* Select setting, but don't duplicate work */ if (!def_tz) def_tz = select_default_timezone(); log_timezone = def_tz; /* Tell GUC about the value. Will redundantly call pg_tzset() */ SetConfigOption("log_timezone", pg_get_timezone_name(def_tz), PGC_POSTMASTER, PGC_S_ARGV); } }
SYMBOL_EXPORT const char* GetConfigOptionDefault(struct Game* game, char* section, char* name, const char* def) { const char* ret = GetConfigOption(game, section, name); if (!ret) { return def; } return ret; }
bool GetConfigOption_UInt32(const char * section, const char * key, UInt32 * dataOut) { std::string data = GetConfigOption(section, key); if(data.empty()) return false; return (sscanf_s(data.c_str(), "%u", dataOut) == 1); }
mDNSexport void ReadDDNSSettingsFromConfFile(mDNS *const m, const char *const filename, domainname *const hostname, domainname *const domain, mDNSBool *DomainDiscoveryDisabled) { char buf[MAX_ESCAPED_DOMAIN_NAME] = ""; mStatus err; FILE *f = fopen(filename, "r"); if (hostname) hostname->c[0] = 0; if (domain) domain->c[0] = 0; if (DomainDiscoveryDisabled) *DomainDiscoveryDisabled = mDNSfalse; if (f) { if (DomainDiscoveryDisabled && GetConfigOption(buf, "DomainDiscoveryDisabled", f) && !strcasecmp(buf, "true")) *DomainDiscoveryDisabled = mDNStrue; if (hostname && GetConfigOption(buf, "hostname", f) && !MakeDomainNameFromDNSNameString(hostname, buf)) goto badf; if (domain && GetConfigOption(buf, "zone", f) && !MakeDomainNameFromDNSNameString(domain, buf)) goto badf; buf[0] = 0; GetConfigOption(buf, "secret-64", f); // failure means no authentication fclose(f); f = NULL; } else { if (errno != ENOENT) LogMsg("ERROR: Config file exists, but cannot be opened."); return; } if (domain && domain->c[0] && buf[0]) { DomainAuthInfo *info = (DomainAuthInfo*)mDNSPlatformMemAllocate(sizeof(*info)); // for now we assume keyname = service reg domain and we use same key for service and hostname registration err = mDNS_SetSecretForDomain(m, info, domain, domain, buf, NULL, 0, mDNSfalse); if (err) LogMsg("ERROR: mDNS_SetSecretForDomain returned %d for domain %##s", err, domain->c); } return; badf: LogMsg("ERROR: malformatted config file"); if (f) fclose(f); }
/* * Initialize timezone library * * This is called after initial loading of postgresql.conf. If no TimeZone * setting was found therein, we try to derive one from the environment. * Likewise for log_timezone. */ void pg_timezone_initialize(void) { pg_tz *def_tz = NULL; /* * Make sure that session_timezone and log_timezone are set. * (session_timezone could still be NULL even if a timezone value was set * in postgresql.conf, if that setting was interval-based rather than * timezone-based.) */ if (!session_timezone) { def_tz = select_default_timezone(); session_timezone = def_tz; } if (!log_timezone) { /* Don't duplicate work */ if (!def_tz) def_tz = select_default_timezone(); log_timezone = def_tz; } /* Now, set the timezone GUC if it's not already set */ if (GetConfigOption("timezone", false) == NULL) { /* Tell GUC about the value. Will redundantly call pg_tzset() */ SetConfigOption("timezone", pg_get_timezone_name(session_timezone), PGC_POSTMASTER, PGC_S_ENV_VAR); } /* Likewise for log timezone */ if (GetConfigOption("log_timezone", false) == NULL) { /* Tell GUC about the value. Will redundantly call pg_tzset() */ SetConfigOption("log_timezone", pg_get_timezone_name(log_timezone), PGC_POSTMASTER, PGC_S_ENV_VAR); } }
/* * Initialize timezone library * * This is called after initial loading of postgresql.conf. If no TimeZone * setting was found therein, we try to derive one from the environment. */ void pg_timezone_initialize(void) { /* Do we need to try to figure the timezone? */ if (pg_strcasecmp(GetConfigOption("timezone"), "UNKNOWN") == 0) { const char *def_tz; /* Select setting */ def_tz = select_default_timezone(); /* Tell GUC about the value. Will redundantly call pg_tzset() */ SetConfigOption("timezone", def_tz, PGC_POSTMASTER, PGC_S_ARGV); } }
/* * Convert TLS protocol version GUC enum to OpenSSL values * * This is a straightforward one-to-one mapping, but doing it this way makes * guc.c independent of OpenSSL availability and version. * * If a version is passed that is not supported by the current OpenSSL * version, then we throw an error, so that subsequent code can assume it's * working with a supported version. */ static int ssl_protocol_version_to_openssl(int v, const char *guc_name) { switch (v) { case PG_TLS_ANY: return 0; case PG_TLS1_VERSION: return TLS1_VERSION; case PG_TLS1_1_VERSION: #ifdef TLS1_1_VERSION return TLS1_1_VERSION; #else goto error; #endif case PG_TLS1_2_VERSION: #ifdef TLS1_2_VERSION return TLS1_2_VERSION; #else goto error; #endif case PG_TLS1_3_VERSION: #ifdef TLS1_3_VERSION return TLS1_3_VERSION; #else goto error; #endif } error: pg_attribute_unused(); ereport(ERROR, (errmsg("%s setting %s not supported by this build", guc_name, GetConfigOption(guc_name, false, false)))); return -1; }
const char* GetConfigOptionDefault(char* section, char* name, const char* def) { const char* ret = GetConfigOption(section, name); if (!ret) return def; else return ret; }
static PGconn * connect_to_localhost(void) { PGconn *conn; char sql[1024]; char *host; char dbName[1024]; /* Also ensure backend isn't confused by this environment var. */ setenv("PGCLIENTENCODING", GetDatabaseEncodingName(), 1); #ifdef HAVE_UNIX_SOCKETS host = (UnixSocketDir == NULL || UnixSocketDir[0] == '\0') ? DEFAULT_PGSOCKET_DIR : UnixSocketDir; #else host = "localhost"; #endif /* set dbname and disable hostaddr */ snprintf(dbName, lengthof(dbName), "dbname='%s' hostaddr=''", escape_param_str(get_database_name(MyDatabaseId))); conn = PQsetdbLogin( host, GetConfigOption("port", false, false), NULL, NULL, dbName, GetUserNameFromId(GetUserId()), NULL); if (PQstatus(conn) == CONNECTION_BAD) { ParallelWriter wr; wr.conn = conn; ereport(ERROR, (errcode(ERRCODE_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION), errmsg("could not establish connection to parallel writer"), errdetail("%s", finish_and_get_message(&wr)), errhint("Refer to the following if it is an authentication " "error. Specifies the authentication method to " "without the need for a password in pg_hba.conf (ex. " "trust or ident), or specify the password to the " "password file of the operating system user who ran " "PostgreSQL server. If cannot use these solution, " "specify WRITER=DIRECT."))); } /* attempt to set default datestyle */ snprintf(sql, lengthof(sql), "SET datestyle = '%s'", GetConfigOption("datestyle", false, false)); PQexec(conn, sql); /* attempt to set default datestyle */ snprintf(sql, lengthof(sql), "SET timezone = '%s'", show_timezone()); PQexec(conn, sql); /* set message receiver */ PQsetNoticeReceiver(conn, transfer_message, NULL); return conn; }
Datum verify_row_visible_current_setting(PG_FUNCTION_ARGS) { const VarChar *vis_base64 = PG_GETARG_VARCHAR_P(0); const char *token_base64 = GetConfigOption(EZBAKE_TOKEN_SETTING, false, false); if (!token_base64) { ereport(ERROR, (errmsg("Could not read serialized security token from session " "config with key " EZBAKE_TOKEN_SETTING))); PG_RETURN_BOOL(false); } char *error = NULL; token_handle_t *token = ezbake_deserialize_token_base64(token_base64, &error); if (error) { ereport(ERROR, (errmsg("Error deserializing the security token: %s", error))); free(error); PG_RETURN_BOOL(false); } authorizations_handle_t *auths = ezbake_get_authorizations_from_token(token, &error); if (error) { ereport(ERROR, (errmsg("Error extracting auths from security token: %s", error))); ezbake_token_handle_free(token); free(error); PG_RETURN_BOOL(false); } visibility_handle_t *vis = deserialize_vis(vis_base64); if (!vis) { ereport(ERROR, (errmsg("There was an error deserializing the visibility!"))); ezbake_token_handle_free(token); ezbake_authorizations_handle_free(auths); PG_RETURN_BOOL(false); } uint32_t permissions = ezbake_get_user_permissions(auths, vis, &error); if (error) { ereport(ERROR, (errmsg("Error evaluating permissions: %s", error))); ezbake_token_handle_free(token); ezbake_authorizations_handle_free(auths); ezbake_visibility_handle_free(vis); free(error); PG_RETURN_BOOL(false); } ezbake_token_handle_free(token); ezbake_authorizations_handle_free(auths); ezbake_visibility_handle_free(vis); bool is_authorized = (permissions & EZBAKE_USER_PERM_READ) && (permissions & EZBAKE_USER_PERM_WRITE) && (permissions & EZBAKE_USER_PERM_MANAGE_VISIBILITY); PG_RETURN_BOOL(is_authorized); }
/* Send info about the list of server restart required GUCs */ char* restart_gucs(void) { char* result; char blk_size[10]; StringInfoData resultbuf; sprintf(blk_size, "%d", BLCKSZ); //elog(LOG, "PRMGUC"); initStringInfo(&resultbuf); appendStringInfo(&resultbuf, "PRMGUC;"); appendStringInfoString(&resultbuf, GetConfigOption("shared_buffers", true, true)); appendStringInfo(&resultbuf, FIELD_DELIMIT); appendStringInfoString(&resultbuf, GetConfigOption("max_connections", true, true)); appendStringInfo(&resultbuf, FIELD_DELIMIT); appendStringInfoString(&resultbuf, GetConfigOption("wal_level", true, true)); appendStringInfo(&resultbuf, FIELD_DELIMIT); appendStringInfoString(&resultbuf, blk_size); appendStringInfo(&resultbuf, FIELD_DELIMIT); appendStringInfoString(&resultbuf, GetConfigOption("listen_addresses", true, true)); appendStringInfo(&resultbuf, FIELD_DELIMIT); appendStringInfoString(&resultbuf, GetConfigOption("wal_buffers", true, true)); appendStringInfo(&resultbuf, FIELD_DELIMIT); appendStringInfoString(&resultbuf, GetConfigOption("max_wal_senders", true, true)); appendStringInfo(&resultbuf, FIELD_DELIMIT); appendStringInfoString(&resultbuf, GetConfigOption("autovacuum_max_workers", true, true)); appendStringInfo(&resultbuf, FIELD_DELIMIT); appendStringInfoString(&resultbuf, GetConfigOption("autovacuum_freeze_max_age", true, true)); appendStringInfo(&resultbuf, FIELD_DELIMIT); appendStringInfoString(&resultbuf, GetConfigOption("autovacuum_multixact_freeze_max_age", true, true)); appendStringInfo(&resultbuf, FIELD_DELIMIT); appendStringInfoString(&resultbuf, GetConfigOption("max_locks_per_transaction", true, true)); appendStringInfo(&resultbuf, FIELD_DELIMIT); appendStringInfoString(&resultbuf, GetConfigOption("max_pred_locks_per_transaction", true, true)); appendStringInfo(&resultbuf, FIELD_DELIMIT); appendStringInfoString(&resultbuf, GetConfigOption("wal_segment_size", true, true)); appendStringInfo(&resultbuf, FIELD_DELIMIT); appendStringInfoString(&resultbuf, GetConfigOption("data_directory", true, true)); appendStringInfo(&resultbuf, FIELD_DELIMIT); appendStringInfoString(&resultbuf, CDELIMIT); result = palloc(strlen(resultbuf.data) + 1); strcpy(result, resultbuf.data); return result; }