int search_findtype(const uschar *name, int len) { int bot = 0; int top = lookup_list_count; while (top > bot) { int mid = (top + bot)/2; int c = Ustrncmp(name, lookup_list[mid]->name, len); /* If c == 0 we have matched the incoming name with the start of the search type name. However, some search types are substrings of others (e.g. nis and nisplus) so we need to check that the lengths are the same. The length of the type name cannot be shorter (else c would not be 0); if it is not equal it must be longer, and in that case, the incoming name comes before the name we are testing. By leaving c == 0 when the lengths are different, and doing a > 0 test below, this all falls out correctly. */ if (c == 0 && Ustrlen(lookup_list[mid]->name) == len) { if (lookup_list[mid]->find != NULL) return mid; search_error_message = string_sprintf("lookup type \"%.*s\" is not " "available (not in the binary - check buildtime LOOKUP configuration)", len, name); return -1; } if (c > 0) bot = mid + 1; else top = mid; } search_error_message = string_sprintf("unknown lookup type \"%.*s\"",len,name); return -1; }
static uschar * checkexpand(uschar *s, address_item *addr, uschar *name, int type) { uschar *t; uschar *ss = expand_string(s); if (ss == NULL) { addr->transport_return = FAIL; addr->message = string_sprintf("Expansion of \"%s\" failed in %s transport: " "%s", s, name, expand_string_message); return NULL; } if (type != cke_text) for (t = ss; *t != 0; t++) { int c = *t; if (mac_isprint(c)) continue; if (type == cke_hdr && c == '\n' && (t[1] == ' ' || t[1] == '\t')) continue; s = string_printing(s); addr->transport_return = FAIL; addr->message = string_sprintf("Expansion of \"%s\" in %s transport " "contains non-printing character %d", s, name, c); return NULL; } return ss; }
BOOL rf_get_transport(uschar *tpname, transport_instance **tpptr, address_item *addr, uschar *router_name, uschar *require_name) { uschar *ss; BOOL expandable; transport_instance *tp; if (tpname == NULL) { if (require_name == NULL) return TRUE; addr->basic_errno = ERRNO_BADTRANSPORT; addr->message = string_sprintf("%s unset in %s router", require_name, router_name); return FALSE; } expandable = Ustrchr(tpname, '$') != NULL; if (*tpptr != NULL && !expandable) return TRUE; if (expandable) { ss = expand_string(tpname); if (ss == NULL) { addr->basic_errno = ERRNO_BADTRANSPORT; addr->message = string_sprintf("failed to expand transport " "\"%s\" in %s router: %s", tpname, router_name, expand_string_message); return FALSE; } } else ss = tpname; for (tp = transports; tp != NULL; tp = tp->next) { if (Ustrcmp(tp->name, ss) == 0) { DEBUG(D_route) debug_printf("set transport %s\n", ss); *tpptr = tp; return TRUE; } } addr->basic_errno = ERRNO_BADTRANSPORT; addr->message = string_sprintf("transport \"%s\" not found in %s router", ss, router_name); return FALSE; }
MapTileType ConfigMgr::getMapTileTypeByName(const std::string& mapTileTypeName) { if (mapTileTypeName == "ocean") { return MapTileType::OCEAN; } else if (mapTileTypeName == "fish-grounds") { return MapTileType::FISH_GROUNDS; } else if (mapTileTypeName == "shallow-water") { return MapTileType::SHALLOW_WATER; } else if (mapTileTypeName == "shore-water") { return MapTileType::SHORE_WATER; } else if (mapTileTypeName == "shore-sand") { return MapTileType::SHORE_SAND; } else if (mapTileTypeName == "shore-grass") { return MapTileType::SHORE_GRASS; } else if (mapTileTypeName == "river") { return MapTileType::RIVER; } else if (mapTileTypeName == "mountain") { return MapTileType::MOUNTAIN; } else if (mapTileTypeName == "grass") { return MapTileType::GRASS; } else { throw ErrorInConfigException(string_sprintf(_("Illegal mapTileTypeName '%s'."), mapTileTypeName.c_str())); } }
ConfigMgr::ConfigMgr(std::string configPath) { try { loadGoods(configPath + "/goods.xml"); Log::info(_("Loaded goods.")); loadCarrierMapObjectTypes(configPath + "/carriers.xml"); Log::info(_("Loaded carrier mapObjectTypes.")); loadMapObjectTypes(configPath + "/map-objects.xml"); Log::info(_("Loaded mapObjectTypes.")); loadShipMapObjectTypes(configPath + "/ships.xml"); Log::info(_("Loaded ship mapObjectTypes.")); loadPopulationTiers(configPath + "/population-tiers.xml"); Log::info(_("Loaded population tiers.")); loadTilesConfig(configPath + "/tiles.xml"); Log::info(_("Loaded tiles.")); } catch (const rapidxml::parse_error& e) { // Fehler beim Parsen einer XML. // TODO e.what() kommt immer auf Englisch zurück. Das muss übersetzt werden. Idee: künstlich Phrasen anlegen throw ErrorInConfigException(string_sprintf(_("Error while loading the configuration: %s."), e.what())); } }
bool CScriptSystem::ExecuteFile(const char* sFileName, bool forceReload) { if (strlen(sFileName) <= 0) { return false; } CPathID sTemp(sFileName); ScriptFileListItor itor = this->findFile(sTemp); if (itor == m_dqLoadedFiles.end() || forceReload) { char sRealFileName[MAX_PATH]; string_sprintf(sRealFileName, "%s_compiled", sFileName); if (!_ExecuteFile(sFileName)) { return false; } if (itor == m_dqLoadedFiles.end()) { m_dqLoadedFiles.push_back(sTemp); } } return true; }
static uschar * oracle_error(struct cda_def *oracle_handle, int rc, uschar *msg) { uschar tmp[1024]; oerhms(oracle_handle, rc, tmp, sizeof(tmp)); return string_sprintf("ORACLE %s: %s", msg, tmp); }
uschar * string_address_utf8_to_alabel(const uschar * utf8, uschar ** err) { uschar * l, * d; if (!*utf8) return string_copy(utf8); DEBUG(D_expand) debug_printf("addr from utf8 <%s>", utf8); for (const uschar * s = utf8; *s; s++) if (*s == '@') { l = string_copyn(utf8, s - utf8); if ( !(l = string_localpart_utf8_to_alabel(l, err)) || !(d = string_domain_utf8_to_alabel(++s, err)) ) return NULL; l = string_sprintf("%s@%s", l, d); DEBUG(D_expand) debug_printf(" -> <%s>\n", l); return l; } l = string_localpart_utf8_to_alabel(utf8, err); DEBUG(D_expand) debug_printf(" -> <%s>\n", l); return l; }
bool MakeStringFromXmlNodeStruct(behaviac::XmlConstNodeRef xmlNode, behaviac::string& result) { //xmlNode->getXML(result); result = "{"; for (int a = 0; a < xmlNode->getAttrCount(); ++a) { const char* tag = xmlNode->getAttrTag(a); const char* value = xmlNode->getAttr(a); char temp[1024]; string_sprintf(temp, "%s=%s;", tag, value); result += temp; } for (int c = 0; c < xmlNode->getChildCount(); ++c) { behaviac::XmlConstNodeRef childNode = xmlNode->getChild(c); behaviac::string childString; if (MakeStringFromXmlNodeStruct(childNode, childString)) { result += childString; result += ";"; } } result += "}"; return true; }
static uschar * g_err(const char * tag, const char * from, int gnutls_err) { expand_string_message = string_sprintf("%s: %s fail: %s\n", from, tag, gnutls_strerror(gnutls_err)); return NULL; }
void GameObject::setSprite(char* resource, bool bBG) { char filename[_MAX_PATH]; string_sprintf(filename, "../example/spaceship/Resources/%s.png", resource); textureResource = framework::ws->GetTextureResource(filename); }
uschar * spool_fname(const uschar * purpose, const uschar * subdir, const uschar * fname, const uschar * suffix) { return string_sprintf("%s/%s/%s/%s/%s%s", spool_directory, queue_name, purpose, subdir, fname, suffix); }
uschar * spool_sname(const uschar * purpose, uschar * subdir) { return string_sprintf("%s%s%s%s%s", queue_name, *queue_name ? "/" : "", purpose, *subdir ? "/" : "", subdir); }
static int setenv(const char * name, const char * val, int overwrite) { uschar * s; if (Ustrchr(name, '=')) return -1; if (overwrite || !getenv(name)) putenv(CS string_copy_malloc(string_sprintf("%s=%s", name, val))); return 0; }
static void dmarc_send_forensic_report(u_char **ruf) { int c; uschar *recipient, *save_sender; BOOL send_status = FALSE; error_block *eblock = NULL; FILE *message_file = NULL; /* Earlier ACL does not have *required* control=dmarc_enable_forensic */ if (!dmarc_enable_forensic) return; if ( dmarc_policy == DMARC_POLICY_REJECT && action == DMARC_RESULT_REJECT || dmarc_policy == DMARC_POLICY_QUARANTINE && action == DMARC_RESULT_QUARANTINE || dmarc_policy == DMARC_POLICY_NONE && action == DMARC_RESULT_REJECT || dmarc_policy == DMARC_POLICY_NONE && action == DMARC_RESULT_QUARANTINE ) if (ruf) { eblock = add_to_eblock(eblock, US"Sender Domain", dmarc_used_domain); eblock = add_to_eblock(eblock, US"Sender IP Address", sender_host_address); eblock = add_to_eblock(eblock, US"Received Date", tod_stamp(tod_full)); eblock = add_to_eblock(eblock, US"SPF Alignment", (sa==DMARC_POLICY_SPF_ALIGNMENT_PASS) ?US"yes":US"no"); eblock = add_to_eblock(eblock, US"DKIM Alignment", (da==DMARC_POLICY_DKIM_ALIGNMENT_PASS)?US"yes":US"no"); eblock = add_to_eblock(eblock, US"DMARC Results", dmarc_status_text); /* Set a sane default envelope sender */ dsn_from = dmarc_forensic_sender ? dmarc_forensic_sender : dsn_from ? dsn_from : string_sprintf("do-not-reply@%s",primary_hostname); for (c = 0; ruf[c]; c++) { recipient = string_copylc(ruf[c]); if (Ustrncmp(recipient, "mailto:",7)) continue; /* Move to first character past the colon */ recipient += 7; DEBUG(D_receive) debug_printf("DMARC forensic report to %s%s\n", recipient, (host_checking || running_in_test_harness) ? " (not really)" : ""); if (host_checking || running_in_test_harness) continue; save_sender = sender_address; sender_address = recipient; send_status = moan_to_sender(ERRMESS_DMARC_FORENSIC, eblock, header_list, message_file, FALSE); sender_address = save_sender; if (!send_status) log_write(0, LOG_MAIN|LOG_PANIC, "failure to send DMARC forensic report to %s", recipient); } } }
static int rda_exists(uschar *filename, uschar **error) { int rc, saved_errno; uschar *slash; struct stat statbuf; if ((rc = Ustat(filename, &statbuf)) >= 0) return FILE_EXIST; saved_errno = errno; Ustrncpy(big_buffer, filename, big_buffer_size - 3); sigalrm_seen = FALSE; if (saved_errno == ENOENT) { slash = Ustrrchr(big_buffer, '/'); Ustrcpy(slash+1, "."); alarm(30); rc = Ustat(big_buffer, &statbuf); if (rc != 0 && errno == EACCES && !sigalrm_seen) { *slash = 0; rc = Ustat(big_buffer, &statbuf); } saved_errno = errno; alarm(0); DEBUG(D_route) debug_printf("stat(%s)=%d\n", big_buffer, rc); } if (sigalrm_seen || rc != 0) { *error = string_sprintf("failed to stat %s (%s)", big_buffer, sigalrm_seen? "timeout" : strerror(saved_errno)); return FILE_EXIST_UNCLEAR; } *error = string_sprintf("%s does not exist", filename); DEBUG(D_route) debug_printf("%s\n", *error); return FILE_NOT_EXIST; }
static void * nis_open(uschar *filename, uschar **errmsg) { char *nis_domain; if (yp_get_default_domain(&nis_domain) != 0) { *errmsg = string_sprintf("failed to get default NIS domain"); return NULL; } return nis_domain; }
BOOL rf_get_ugid(router_instance *rblock, address_item *addr, ugid_block *ugid) { struct passwd *upw = NULL; /* Initialize from fixed values */ ugid->uid = rblock->uid; ugid->gid = rblock->gid; ugid->uid_set = rblock->uid_set; ugid->gid_set = rblock->gid_set; ugid->initgroups = rblock->initgroups; /* If there is no fixed uid set, see if there's a dynamic one that can be expanded and possibly looked up. */ if (!ugid->uid_set && rblock->expand_uid != NULL) { if (route_find_expanded_user(rblock->expand_uid, rblock->name, US"router", &upw, &(ugid->uid), &(addr->message))) ugid->uid_set = TRUE; else return FALSE; } /* Likewise for the gid */ if (!ugid->gid_set && rblock->expand_gid != NULL) { if (route_find_expanded_group(rblock->expand_gid, rblock->name, US"router", &(ugid->gid), &(addr->message))) ugid->gid_set = TRUE; else return FALSE; } /* If a uid is set, then a gid must also be available; use one from the passwd lookup if it happened. */ if (ugid->uid_set && !ugid->gid_set) { if (upw != NULL) { ugid->gid = upw->pw_gid; ugid->gid_set = TRUE; } else { addr->message = string_sprintf("user set without group for %s router", rblock->name); return FALSE; } } return TRUE; }
static void record_io_error(int ec, uschar *when, uschar *text) { const char *msg; if (ec == GNUTLS_E_FATAL_ALERT_RECEIVED) msg = string_sprintf("%s: %s", gnutls_strerror(ec), gnutls_alert_get_name(gnutls_alert_get(tls_session))); else msg = gnutls_strerror(ec); tls_error(when, client_host, msg); }
void CCustomMethod::LoadFromXML(behaviac::CTagObject* parent, const ISerializableNode& xmlNode) { for (uint32_t i = 0; i < this->m_paramTypes.size(); ++i) { const behaviac::string& paramTypeName = this->m_paramTypes[i]; char temp[1024]; string_sprintf(temp, "param%d", i + 1); Property* p = this->LoadFromXML(parent, xmlNode, paramTypeName.c_str(), temp); this->m_params.push_back(p); } }
static int spool_write_error(int where, uschar **errmsg, uschar *s, uschar *temp_name, FILE *f) { uschar *msg = (where == SW_RECEIVING)? string_sprintf("spool file %s error while receiving from %s: %s", s, (sender_fullhost != NULL)? sender_fullhost : sender_ident, strerror(errno)) : string_sprintf("spool file %s error while %s: %s", s, (where == SW_DELIVERING)? "delivering" : "modifying", strerror(errno)); if (temp_name != NULL) Uunlink(temp_name); if (f != NULL) (void)fclose(f); if (errmsg == NULL) log_write(0, LOG_MAIN|LOG_PANIC_DIE, "%s", msg); else *errmsg = msg; return -1; }
void rf_change_domain(address_item *addr, uschar *domain, BOOL rewrite, address_item **addr_new) { address_item *parent = store_get(sizeof(address_item)); uschar *at = Ustrrchr(addr->address, '@'); uschar *address = string_sprintf("%.*s@%s", at - addr->address, addr->address, domain); DEBUG(D_route) debug_printf("domain changed to %s\n", domain); /* The current address item is made into the parent, and a new address is set up in the old space. */ *parent = *addr; /* First copy in initializing values, to wipe out stuff such as the named domain cache. Then copy over the propagating fields from the parent. Then set up the new fields. */ *addr = address_defaults; addr->p = parent->p; addr->address = address; addr->unique = string_copy(address); addr->parent = parent; addr->next = *addr_new; *addr_new = addr; /* Rewrite header lines if requested */ if (rewrite) { header_line *h; DEBUG(D_route|D_rewrite) debug_printf("rewriting header lines\n"); for (h = header_list; h != NULL; h = h->next) { header_line *newh = rewrite_header(h, parent->domain, domain, global_rewrite_rules, rewrite_existflags, TRUE); if (newh != NULL) { h = newh; header_rewritten = TRUE; } } } }
uschar * dmarc_auth_results_header(header_line *from_header, uschar *hostname) { uschar *hdr_tmp = US""; /* Allow a server hostname to be passed to this function, but is * currently unused */ if (!hostname) hostname = primary_hostname; hdr_tmp = string_sprintf("%s %s;", DMARC_AR_HEADER, hostname); #if 0 /* I don't think this belongs here, but left it here commented out * because it was a lot of work to get working right. */ if (spf_response != NULL) { uschar *dmarc_ar_spf = US""; int sr = 0; sr = spf_response->result; dmarc_ar_spf = (sr == SPF_RESULT_NEUTRAL) ? US"neutral" : (sr == SPF_RESULT_PASS) ? US"pass" : (sr == SPF_RESULT_FAIL) ? US"fail" : (sr == SPF_RESULT_SOFTFAIL) ? US"softfail" : US"none"; hdr_tmp = string_sprintf("%s spf=%s (%s) smtp.mail=%s;", hdr_tmp, dmarc_ar_spf_result, spf_response->header_comment, expand_string(US"$sender_address") ); } #endif hdr_tmp = string_sprintf("%s dmarc=%s", hdr_tmp, dmarc_pass_fail); if (header_from_sender) hdr_tmp = string_sprintf("%s header.from=%s", hdr_tmp, header_from_sender); return hdr_tmp; }
static uschar * time_copy(time_t t, uschar * mod) { uschar * cp; struct tm * tp; size_t len; if (mod && Ustrcmp(mod, "int") == 0) return string_sprintf("%u", (unsigned)t); cp = store_get(32); tp = gmtime(&t); len = strftime(CS cp, 32, "%b %e %T %Y %Z", tp); return len > 0 ? cp : NULL; }
void CLogger::OutputLine(const char* temp) { gs_lock->Lock(); #if BEHAVIAC_CCDEFINE_MSVC #if _MSC_VER >= 1500 static BOOL s_debugger = IsDebuggerPresent(); #else static BOOL s_debugger = false; #endif//#if _MSC_VER >= 1500 if (s_debugger && (EnableMask & ELOG_VCOUTPUT)) { OutputDebugStringA(temp); } #endif// //to console window if (EnableMask & ELOG_CONSOLE) { LOGI(temp); } if (EnableMask & ELOG_FILE) { static FILE* s_file = 0; if (!s_file) { s_file = fopen("_behaviac_$_$_.log", "wt"); if (s_file) { behaviac::THREAD_ID_TYPE threadId = behaviac::GetTID(); time_t tTime = time(NULL); tm* ptmCurrent = localtime(&tTime); char buffer[1024]; string_sprintf(buffer, "[behaviac][%05d][thread %04d]CREATED ON %d-%.2d-%.2d\n\n", 0, threadId, ptmCurrent->tm_year + 1900, ptmCurrent->tm_mon + 1, ptmCurrent->tm_mday); fwrite(buffer, 1, strlen(buffer), s_file); } } if (s_file) { fwrite(temp, 1, strlen(temp), s_file); fflush(s_file); } } gs_lock->Unlock(); }
FILE* LogManager::GetFile(const behaviac::Agent* pAgent) { if (Config::IsLogging()) { BEHAVIAC_UNUSED_VAR(pAgent); FILE* fp = 0; //int agentId = pAgent->GetId(); int agentId = -1; Logs_t::iterator it = this->m_logs.find(agentId); if (it == this->m_logs.end()) { const char* pLogFile = 0; char buffer[64]; if (m_logFilePath == 0) { if (agentId == -1) { string_snprintf(buffer, 64, "_behaviac_$_.log"); } else { string_sprintf(buffer, "Agent_$_%03d.log", agentId); } pLogFile = buffer; } else { pLogFile = m_logFilePath; } fp = fopen(pLogFile, "wt"); this->m_logs[agentId] = fp; } else { fp = it->second; } return fp; } return 0; }
bool ConfigMgr::xmlAttributeToBool(rapidxml::xml_attribute<>* attribute, bool defaultValue) { // Attribut nicht da? Default-Value verwenden if (attribute == nullptr) { return defaultValue; } const char* value = attribute->value(); if (std::strcmp(value, "false") == 0) { return false; } else if (std::strcmp(value, "true") == 0) { return true; } else { throw ErrorInConfigException(string_sprintf(_("Illegal bool value '%s'."), value)); } }
uschar * rf_expand_data(address_item *addr, uschar *s, int *prc) { uschar *yield = expand_string(s); if (yield != NULL) return yield; if (expand_string_forcedfail) { DEBUG(D_route) debug_printf("forced failure for expansion of \"%s\"\n", s); *prc = DECLINE; } else { addr->message = string_sprintf("failed to expand \"%s\": %s", s, expand_string_message); *prc = DEFER; } return NULL; }
int iplsearch_find(void *handle, uschar *filename, uschar *keystring, int length, uschar **result, uschar **errmsg, BOOL *do_cache) { do_cache = do_cache; /* Keep picky compilers happy */ if ((length == 1 && keystring[0] == '*') || string_is_ip_address(keystring, NULL) != 0) { return internal_lsearch_find(handle, filename, keystring, length, result, errmsg, LSEARCH_IP); } else { *errmsg = string_sprintf("\"%s\" is not a valid iplsearch key (an IP " "address, with optional CIDR mask, is wanted): " "in a host list, use net-iplsearch as the search type", keystring); return DEFER; } }
static uschar * time_copy(time_t t, uschar * mod) { uschar * cp; size_t len = 32; if (mod && Ustrcmp(mod, "int") == 0) return string_sprintf("%u", (unsigned)t); cp = store_get(len); if (timestamps_utc) { uschar * tz = to_tz(US"GMT0"); len = strftime(CS cp, len, "%b %e %T %Y %Z", gmtime(&t)); restore_tz(tz); } else len = strftime(CS cp, len, "%b %e %T %Y %Z", localtime(&t)); return len > 0 ? cp : NULL; }