bool send_push_reply (struct context *c) { struct gc_arena gc = gc_new (); struct buffer buf = alloc_buf_gc (MAX_PUSH_LIST_LEN + 256, &gc); bool ret = false; buf_printf (&buf, "PUSH_REPLY"); if (c->options.push_list && strlen (c->options.push_list->options)) buf_printf (&buf, ",%s", c->options.push_list->options); if (c->c2.push_ifconfig_defined && c->c2.push_ifconfig_local && c->c2.push_ifconfig_remote_netmask) buf_printf (&buf, ",ifconfig %s %s", print_in_addr_t (c->c2.push_ifconfig_local, 0, &gc), print_in_addr_t (c->c2.push_ifconfig_remote_netmask, 0, &gc)); if (strlen (BSTR (&buf)) < MAX_PUSH_LIST_LEN) ret = send_control_channel_string (c, BSTR (&buf), D_PUSH); else msg (M_WARN, "Maximum length of --push buffer (%d) has been exceeded", MAX_PUSH_LIST_LEN); gc_free (&gc); return ret; }
static void handleRequestFromChild(struct Admin* admin, uint8_t buffer[MAX_API_REQUEST_SIZE], size_t amount, struct Allocator* allocator) { String* txid = NULL; int skip = 0; if (!memcmp(buffer, "0123", 4)) { // out of band txid txid = &(String) { .len = 4, .bytes = (char*) buffer + 4 }; skip = 8; } struct Reader* reader = ArrayReader_new(buffer + skip, amount - skip, allocator); Dict message; if (List_getStandardBencSerializer()->parseDictionary(reader, allocator, &message)) { return; } String* query = Dict_getString(&message, CJDHTConstants_QUERY); if (!query) { return; } // If they're asking for a cookie then lets give them one. String* cookie = BSTR("cookie"); if (String_equals(query, cookie)) { Dict* d = Dict_new(allocator); char bytes[32]; snprintf(bytes, 32, "%u", (uint32_t) Time_currentTimeSeconds(admin->eventBase)); String* theCookie = &(String) { .len = strlen(bytes), .bytes = bytes }; Dict_putString(d, cookie, theCookie, allocator); Admin_sendMessage(d, txid, admin); return; } // If this is a permitted query, make sure the cookie is right. String* auth = BSTR("auth"); bool authed = false; if (String_equals(query, auth)) { if (!authValid(&message, buffer + skip, reader->bytesRead(reader), admin)) { Dict* d = Dict_new(allocator); Dict_putString(d, BSTR("error"), BSTR("Auth failed."), allocator); Admin_sendMessage(d, txid, admin); return; } query = Dict_getString(&message, BSTR("aq")); authed = true; } for (int i = 0; i < admin->functionCount; i++) { if (String_equals(query, admin->functions[i].name) && (authed || !admin->functions[i].needsAuth)) { admin->functions[i].call(&message, admin->functions[i].context, txid); } } return; }
//------------------------------------------------------------------------------ // This function determines the current project and calls StartCodeRover // with the appropriate arguments. //------------------------------------------------------------------------------ STDMETHODIMP CCommands::CodeRoverBuildMethod() { AFX_MANAGE_STATE(AfxGetStaticModuleState()); /* VERIFY_OK(m_pApplication->EnableModeless(VARIANT_FALSE)); ::MessageBox(NULL, "VSAddIn Command invoked.", "VSAddIn", MB_OK | MB_ICONINFORMATION); VERIFY_OK(m_pApplication->EnableModeless(VARIANT_TRUE)); */ CComPtr<IDispatch> pProject; m_pApplication->get_ActiveProject(&pProject); if(pProject != NULL) { IGenericProject *p = NULL; pProject.QueryInterface(&p); CComBSTR bszProjectName(""); CComBSTR bszProjectFileName(""); p->get_Name(&bszProjectName); p->get_FullName(&bszProjectFileName); p->Release(); StartCodeRover(CString(BSTR(bszProjectName)), CString(BSTR(bszProjectFileName))); } else { StartCodeRover(NULL, NULL); } return S_OK; }
static inline bool authValid(Dict* message, uint8_t* buffer, uint32_t length, struct Admin* admin) { String* cookieStr = Dict_getString(message, BSTR("cookie")); uint32_t cookie = (cookieStr != NULL) ? strtoll(cookieStr->bytes, NULL, 10) : 0; uint64_t nowSecs = Time_currentTimeSeconds(admin->eventBase); String* submittedHash = Dict_getString(message, BSTR("hash")); if (cookie > nowSecs || cookie < nowSecs - 20 || !submittedHash || submittedHash->len != 64) { return false; } uint8_t* hashPtr = (uint8_t*) strstr((char*) buffer, submittedHash->bytes); if (!hashPtr || !admin->password) { return false; } uint8_t passAndCookie[64]; snprintf((char*) passAndCookie, 64, "%s%u", admin->password->bytes, cookie); uint8_t hash[32]; crypto_hash_sha256(hash, passAndCookie, strlen((char*) passAndCookie)); Hex_encode(hashPtr, 64, hash, 32); crypto_hash_sha256(hash, buffer, length); Hex_encode(hashPtr, 64, hash, 32); return memcmp(hashPtr, submittedHash->bytes, 64) == 0; }
/* * Handle incoming configuration * messages on the control channel. */ void check_incoming_control_channel_dowork (struct context *c) { const int len = tls_test_payload_len (c->c2.tls_multi); if (len) { struct gc_arena gc = gc_new (); struct buffer buf = alloc_buf_gc (len, &gc); if (tls_rec_payload (c->c2.tls_multi, &buf)) { /* force null termination of message */ buf_null_terminate (&buf); /* enforce character class restrictions */ string_mod (BSTR (&buf), CC_PRINT, CC_CRLF, 0); if (buf_string_match_head_str (&buf, "AUTH_FAILED")) receive_auth_failed (c, &buf); else if (buf_string_match_head_str (&buf, "PUSH_")) incoming_push_message (c, &buf); else if (buf_string_match_head_str (&buf, "RESTART")) server_pushed_signal (c, &buf, true, 7); else if (buf_string_match_head_str (&buf, "HALT")) server_pushed_signal (c, &buf, false, 4); else msg (D_PUSH_ERRORS, "WARNING: Received unknown control message: %s", BSTR (&buf)); } else { msg (D_PUSH_ERRORS, "WARNING: Receive control message failed"); } gc_free (&gc); } }
void incoming_push_message (struct context *c, const struct buffer *buffer) { struct gc_arena gc = gc_new (); unsigned int option_types_found = 0; int status; msg (D_PUSH, "PUSH: Received control message: '%s'", BSTR (buffer)); status = process_incoming_push_msg (c, buffer, c->options.pull, pull_permission_mask (c), &option_types_found); if (status == PUSH_MSG_ERROR) msg (D_PUSH_ERRORS, "WARNING: Received bad push/pull message: %s", BSTR (buffer)); else if (status == PUSH_MSG_REPLY || status == PUSH_MSG_CONTINUATION) { if (status == PUSH_MSG_REPLY) do_up (c, true, option_types_found); /* delay bringing tun/tap up until --push parms received from remote */ event_timeout_clear (&c->c2.push_request_interval); } gc_free (&gc); }
static int getcmds(Dict* config) { uint8_t privateKey[32]; struct Address addr; parsePrivateKey(config, &addr, privateKey); uint8_t myIp[40]; Address_printIp(myIp, &addr); Dict* router = Dict_getDict(config, BSTR("router")); Dict* iface = Dict_getDict(router, BSTR("interface")); String* type = Dict_getString(iface, BSTR("type")); String* tunDevice = Dict_getString(iface, BSTR("tunDevice")); if (!String_equals(type, BSTR("TUNInterface"))) { fprintf(stderr, "router.interface.type is not recognized.\n"); return -1; } char* tunDev = tunDevice ? tunDevice->bytes : "tun0"; if (strrchr(tunDev, '/') != NULL) { tunDev = strrchr(tunDev, '/') + 1; } printf("#!/bin/bash\n" "# Run these commands as root now and every time the system is rebooted\n" "# in order to get the interfaces setup properly.\n\n"); printf("/sbin/ip addr add %s dev %s\n", myIp, tunDev); printf("/sbin/ip -6 route add fc00::/8 dev %s\n", tunDev); printf("/sbin/ip link set %s up\n", tunDev); return 0; }
BOOL CVCAMetaParserMSXML::ParseCounts() { // Find all the events CComBSTR bsTag; MSXML2::IXMLDOMNodePtr pNode, pSubNode, pSubSubNode, pSubSubSubNode; // Great names eh ;~) MSXML2::IXMLDOMNodeListPtr pNodeList, pSubNodeList; // See if we have any objects this time round bsTag = CComBSTR( _XML_VCA ) += CComBSTR("/") += CComBSTR( _XML_COUNTS ); pNode = m_pDOMDoc->selectSingleNode( bsTag.operator BSTR() ); if( pNode ) { // There are some event specified in this packet... take a look... //m_vcaCounts.clear(); m_vcaCounts.ulTotalCounter = 0; // Select all events bsTag = CComBSTR( _XML_COUNT ); pNodeList = pNode->selectNodes( bsTag.operator BSTR() ); pNode = pNodeList->nextNode(); while( pNode ) { VCA5_PACKET_COUNT vcaCount; memset( &vcaCount, 0, sizeof( vcaCount ) ); bsTag = CComBSTR( _XML_ID ); pSubNode = pNode->selectSingleNode( bsTag.operator BSTR() ); if( pSubNode ) { VarUI4FromStr( pSubNode->text, LCID_ENGLISH, LOCALE_NOUSEROVERRIDE, (unsigned long *)&vcaCount.ulId ); } bsTag = CComBSTR( _XML_VAL ); pSubNode = pNode->selectSingleNode( bsTag.operator BSTR() ); if( pSubNode ) { VarI4FromStr( pSubNode->text, LCID_ENGLISH, LOCALE_NOUSEROVERRIDE, (long *)&vcaCount.iVal ); } pNode = pNodeList->nextNode(); //m_vcaCounts.ph_back( vcaCount ); m_vcaCounts.Counters[m_vcaCounts.ulTotalCounter] = vcaCount; m_vcaCounts.ulTotalCounter++; } } return TRUE; }
void ifconfig_pool_read(struct ifconfig_pool_persist *persist, struct ifconfig_pool *pool) { const int buf_size = 128; update_time(); if (persist && persist->file && pool) { struct gc_arena gc = gc_new(); struct buffer in = alloc_buf_gc(256, &gc); char *cn_buf; char *ip_buf; int line = 0; ALLOC_ARRAY_CLEAR_GC(cn_buf, char, buf_size, &gc); ALLOC_ARRAY_CLEAR_GC(ip_buf, char, buf_size, &gc); while (true) { ASSERT(buf_init(&in, 0)); if (!status_read(persist->file, &in)) { break; } ++line; if (BLEN(&in)) { int c = *BSTR(&in); if (c == '#' || c == ';') { continue; } msg( M_INFO, "ifconfig_pool_read(), in='%s', TODO: IPv6", BSTR(&in) ); if (buf_parse(&in, ',', cn_buf, buf_size) && buf_parse(&in, ',', ip_buf, buf_size)) { bool succeeded; const in_addr_t addr = getaddr(GETADDR_HOST_ORDER, ip_buf, 0, &succeeded, NULL); if (succeeded) { msg( M_INFO, "succeeded -> ifconfig_pool_set()"); ifconfig_pool_set(pool, cn_buf, addr, persist->fixed); } } } } ifconfig_pool_msg(pool, D_IFCONFIG_POOL); gc_free(&gc); } }
//============================================================================= // METHOD: SPELLvariableMonitor::retrieveLocalVariables() //============================================================================= void SPELLvariableMonitor::retrieveLocalVariables(std::vector<SPELLvarInfo>& vars) { DEBUG("[VM] Retrieve Locals"); /* * Bottom stack frame is discarded, * as globals and locals are the same dictionary */ if (m_frame->f_back == NULL) return; /* * Get the names defined in the current code, including arguments */ std::vector<std::string> varNames = retrieveNames(); /* * Iterate over the locals dictionary, retrieving the names contained in * varNames */ PyFrame_FastToLocals(m_frame); PyObject* dict = m_frame->f_locals; DEBUG("[VM] Frame: " + PYCREPR(m_frame)); for( unsigned int index = 0; index< varNames.size(); index++) { std::string varName = varNames[index]; PyObject* pyVarName = SSTRPY(varName); if (PyDict_Contains( dict, pyVarName )) { PyObject* object = PyDict_GetItem( dict, pyVarName ); if (!SPELLpythonHelper::instance().isInstance(object, "Database", "spell.lib.adapter.databases.database")) { if (PyCallable_Check(object)) continue; if (PyClass_Check(object)) continue; if (PyModule_Check(object)) continue; if (PyInstance_Check(object)) continue; } DEBUG("[VM] Processing " + varName); std::string type = PYSSTR( PyObject_Type(object) ); DEBUG("[VM] Type : " + type); std::string value = PYREPR( object ); DEBUG("[VM] Value : " + value); DEBUG("[VM] Global : " + BSTR(false)); DEBUG("[VM] Registered: " + BSTR(isRegistered(varName))); // Mark empty values (empty strings) as "<empty>" if (value == "") value = EMPTY_STRING; vars.push_back( SPELLvarInfo(varName, type, value, false, isRegistered(varName)) ); } } PyFrame_LocalsToFast(m_frame,0); }
/* * Auth username/password * * Client received an authentication failed message from server. * Runs on client. */ void receive_auth_failed(struct context *c, const struct buffer *buffer) { msg(M_VERB0, "AUTH: Received control message: %s", BSTR(buffer)); c->options.no_advance = true; if (c->options.pull) { switch (auth_retry_get()) { case AR_NONE: c->sig->signal_received = SIGTERM; /* SOFT-SIGTERM -- Auth failure error */ break; case AR_INTERACT: ssl_purge_auth(false); case AR_NOINTERACT: c->sig->signal_received = SIGUSR1; /* SOFT-SIGUSR1 -- Auth failure error */ break; default: ASSERT(0); } c->sig->signal_text = "auth-failure"; #ifdef ENABLE_MANAGEMENT if (management) { const char *reason = NULL; struct buffer buf = *buffer; if (buf_string_compare_advance(&buf, "AUTH_FAILED,") && BLEN(&buf)) { reason = BSTR(&buf); } management_auth_failure(management, UP_TYPE_AUTH, reason); } #endif /* * Save the dynamic-challenge text even when management is defined */ { #ifdef ENABLE_CLIENT_CR struct buffer buf = *buffer; if (buf_string_match_head_str(&buf, "AUTH_FAILED,CRV1:") && BLEN(&buf)) { buf_advance(&buf, 12); /* Length of "AUTH_FAILED," substring */ ssl_put_auth_challenge(BSTR(&buf)); } #endif } } }
static void registerRouter(Dict* config, uint8_t myPubKey[32], struct Context* context) { Dict* iface = Dict_getDict(config, BSTR("interface")); if (String_equals(Dict_getString(iface, BSTR("type")), BSTR("TUNInterface"))) { String* tunPath = Dict_getString(iface, BSTR("tunDevice")); context->routerIf = TUNInterface_new(tunPath, context->base, context->allocator); } context->routerModule = RouterModule_register(context->registry, context->allocator, myPubKey, context->base, context->logger, context->admin); }
static void authorizedPasswords(List* list, struct Context* ctx) { uint32_t count = List_size(list); for (uint32_t i = 0; i < count; i++) { Dict* d = List_getDict(list, i); if (!d) { fprintf(stderr, "authorizedPasswords[%u] is not a dictionary type.\n", i); exit(-1); } String* passwd = Dict_getString(d, BSTR("password")); int64_t* authType = Dict_getInt(d, BSTR("authType")); int64_t* trust = Dict_getInt(d, BSTR("trust")); authorizedPassword(passwd, authType, trust, i, ctx); } }
struct Admin* Admin_new(Dict* config, char* user, struct event_base* eventBase, struct ExceptionHandler* eh, struct Allocator* allocator) { errno = 0; int pipes[2][2]; if (pipe(pipes[0]) || pipe(pipes[1])) { eh->exception(__FILE__ " Failed to create pipes.", errno, eh); } int pgid = getpid(); int pid = fork(); if (pid < 0) { eh->exception(__FILE__ " Failed to fork()", errno, eh); } bool isChild = (pid == 0); int inFd = pipes[isChild][0]; close(pipes[!isChild][0]); int outFd = pipes[!isChild][1]; close(pipes[isChild][1]); if (isChild) { // Set the process group so that children will not // become orphaned if the parent gets signal 11 err um 9. setpgid(0, pgid); if (user) { Security_setUser(user, NULL, AbortHandler_INSTANCE); } struct ChildContext context; memset(&context, 0, sizeof(struct ChildContext)); context.inFd = inFd; context.outFd = outFd; context.allocator = allocator; event_reinit(eventBase); context.eventBase = eventBase; child(config, &context); exit(0); } setpgid(pid, pgid); struct Admin* admin = allocator->calloc(sizeof(struct Admin), 1, allocator); admin->inFd = inFd; admin->outFd = outFd; admin->allocator = allocator; admin->functionCount = 0; admin->eventBase = eventBase; admin->password = Dict_getString(config, BSTR("password")); admin->pipeEv = event_new(eventBase, inFd, EV_READ | EV_PERSIST, inFromChild, admin); event_add(admin->pipeEv, NULL); return admin; }
/* print a reliable ACK record coming off the wire */ const char * reliable_ack_print (struct buffer *buf, bool verbose, struct gc_arena *gc) { int i; uint8_t n_ack; struct session_id sid_ack; packet_id_type pid; struct buffer out = alloc_buf_gc (256, gc); buf_printf (&out, "["); if (!buf_read (buf, &n_ack, sizeof (n_ack))) goto done; for (i = 0; i < n_ack; ++i) { if (!buf_read (buf, &pid, sizeof (pid))) goto done; pid = ntohpid (pid); buf_printf (&out, " " packet_id_format, (packet_id_print_type)pid); } if (n_ack) { if (!session_id_read (&sid_ack, buf)) goto done; if (verbose) buf_printf (&out, " sid=%s", session_id_print (&sid_ack, gc)); } done: buf_printf (&out, " ]"); return BSTR (&out); }
/* * Send auth failed message from server to client. */ void send_auth_failed(struct context *c, const char *client_reason) { struct gc_arena gc = gc_new(); static const char auth_failed[] = "AUTH_FAILED"; size_t len; schedule_exit(c, c->options.scheduled_exit_interval, SIGTERM); len = (client_reason ? strlen(client_reason)+1 : 0) + sizeof(auth_failed); if (len > PUSH_BUNDLE_SIZE) { len = PUSH_BUNDLE_SIZE; } { struct buffer buf = alloc_buf_gc(len, &gc); buf_printf(&buf, auth_failed); if (client_reason) { buf_printf(&buf, ",%s", client_reason); } send_control_channel_string(c, BSTR(&buf), D_PUSH); } gc_free(&gc); }
//1 STDMETHODIMP CDirectSerialCSO::CollectParametersForNewCSO( /*[out]*/ BSTR *pbstrNameOut, /*[out]*/ VARIANT_BOOL *pvbHaveNewCSO) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) CString csNameOut; bool bHaveNewCSO = m_pcomm->CollectParametersForNewCSO(csNameOut); if (bHaveNewCSO) { *pvbHaveNewCSO = VARIANT_TRUE; const char *string_in = LPCTSTR(csNameOut); BSTR bstr_out; Convert_Character_String_to_BSTR((char *)string_in, bstr_out); *pbstrNameOut = bstr_out; } else { *pvbHaveNewCSO = VARIANT_FALSE; *pbstrNameOut = BSTR(""); } return S_OK; }
HRESULT XMLPaser::ND_hrOpenMemory( LPCTSTR strFile ) { try { ND_TESTHR( CoInitialize(NULL) ); ND_TESTHR( m_docPtr.CreateInstance("msxml2.domdocument") ); // load a document _variant_t varOut(true); // BOOL 이 없다.. _bstr_t bsXML(strFile); varOut = m_docPtr->loadXML( BSTR(bsXML) ); if ((bool)varOut == false) throw(0); BSTR bstrItem; LPOLESTR pszDataW; AnsiToUnicode( _T("Worksheet"), &pszDataW ); bstrItem = SysAllocString( pszDataW ); m_pNodeList = m_docPtr->getElementsByTagName( bstrItem ); if ( FAILED( m_pNodeList->get_length( &m_lTableCount ) ) ) throw (0); } catch (...) { return ( E_FAIL ); } return ( S_OK ); }
const char * time_string (time_t t, int usec, bool show_usec, struct gc_arena *gc) { struct buffer out = alloc_buf_gc (64, gc); struct timeval tv; if (t) { tv.tv_sec = t; tv.tv_usec = usec; } else { gettimeofday (&tv, NULL); } t = tv.tv_sec; buf_printf (&out, "%s", ctime(&t)); buf_rmtail (&out, '\n'); if (show_usec && tv.tv_usec) buf_printf (&out, " us=%d", (int)tv.tv_usec); return BSTR (&out); }
/* * Auth username/password * * Client received an authentication failed message from server. * Runs on client. */ void receive_auth_failed (struct context *c, const struct buffer *buffer) { msg (M_VERB0, "AUTH: Received AUTH_FAILED control message"); connection_list_set_no_advance(&c->options); if (c->options.pull) { switch (auth_retry_get ()) { case AR_NONE: c->sig->signal_received = SIGTERM; /* SOFT-SIGTERM -- Auth failure error */ break; case AR_INTERACT: ssl_purge_auth (); case AR_NOINTERACT: c->sig->signal_received = SIGUSR1; /* SOFT-SIGUSR1 -- Auth failure error */ break; default: ASSERT (0); } c->sig->signal_text = "auth-failure"; #ifdef ENABLE_MANAGEMENT if (management) { const char *reason = NULL; struct buffer buf = *buffer; if (buf_string_compare_advance (&buf, "AUTH_FAILED,") && BLEN (&buf)) reason = BSTR (&buf); management_auth_failure (management, UP_TYPE_AUTH, reason); } #endif } }
//============================================================================= // METHOD : SPELLcontroller::doStep //============================================================================= void SPELLcontroller::doStep( bool stepOver ) { switch(getStatus()) { case STATUS_PAUSED: // Allowed status case STATUS_INTERRUPTED: // Allowed status break; default: return; } if (m_error) return; // Do not continue on error DEBUG("[C] Do step ( stepping over: " + BSTR(stepOver) + ")" ); SPELLexecutor::instance().getScheduler().restartWait(); // A step will disable the step over if (stepOver) { SPELLexecutor::instance().getCallstack().stepOver( SO_ONCE_OVER ); } else { SPELLexecutor::instance().getCallstack().stepOver( SO_ONCE_INTO ); } setMode( MODE_STEP ); doContinue(); }
/* * Put a directory and filename together. */ const char * gen_path (const char *directory, const char *filename, struct gc_arena *gc) { #if WIN32 const int CC_PATH_RESERVED = CC_LESS_THAN|CC_GREATER_THAN|CC_COLON| CC_DOUBLE_QUOTE|CC_SLASH|CC_BACKSLASH|CC_PIPE|CC_QUESTION_MARK|CC_ASTERISK; #else const int CC_PATH_RESERVED = CC_SLASH; #endif const char *safe_filename = string_mod_const (filename, CC_PRINT, CC_PATH_RESERVED, '_', gc); if (safe_filename && strcmp (safe_filename, ".") && strcmp (safe_filename, "..") #ifdef WIN32 && win_safe_filename (safe_filename) #endif ) { const size_t outsize = strlen(safe_filename) + (directory ? strlen (directory) : 0) + 16; struct buffer out = alloc_buf_gc (outsize, gc); char dirsep[2]; dirsep[0] = OS_SPECIFIC_DIRSEP; dirsep[1] = '\0'; if (directory) buf_printf (&out, "%s%s", directory, dirsep); buf_printf (&out, "%s", safe_filename); return BSTR (&out); } else return NULL; }
static void pidfile(Dict* config) { String* pidFile = Dict_getString(config, BSTR("pidFile")); if (pidFile) { printf("%s", pidFile->bytes); } }
static const char * print_str_int (const char *str, const int i, struct gc_arena *gc) { struct buffer out = alloc_buf_gc (128, gc); buf_printf (&out, "%s %d", str, i); return BSTR (&out); }
static void mroute_helper_regenerate (struct mroute_helper *mh) { int i, j = 0; for (i = MR_HELPER_NET_LEN - 1; i >= 0; --i) { if (mh->net_len_refcount[i] > 0) mh->net_len[j++] = (uint8_t) i; } mh->n_net_len = j; #ifdef ENABLE_DEBUG if (check_debug_level (D_MULTI_DEBUG)) { struct gc_arena gc = gc_new (); struct buffer out = alloc_buf_gc (256, &gc); buf_printf (&out, "MROUTE CIDR netlen:"); for (i = 0; i < mh->n_net_len; ++i) { buf_printf (&out, " /%d", mh->net_len[i]); } dmsg (D_MULTI_DEBUG, "%s", BSTR (&out)); gc_free (&gc); } #endif }
static const char * print_opt_route_gateway_dhcp (struct gc_arena *gc) { struct buffer out = alloc_buf_gc (32, gc); buf_printf (&out, "route-gateway dhcp"); return BSTR (&out); }
/* * Act on received restart message from server */ void server_pushed_signal(struct context *c, const struct buffer *buffer, const bool restart, const int adv) { if (c->options.pull) { struct buffer buf = *buffer; const char *m = ""; if (buf_advance(&buf, adv) && buf_read_u8(&buf) == ',' && BLEN(&buf)) { m = BSTR(&buf); } /* preserve cached passwords? */ /* advance to next server? */ { bool purge = true; if (m[0] == '[') { int i; for (i = 1; m[i] != '\0' && m[i] != ']'; ++i) { if (m[i] == 'P') { purge = false; } else if (m[i] == 'N') { /* next server? */ c->options.no_advance = false; } } } if (purge) { ssl_purge_auth(true); } } if (restart) { msg(D_STREAM_ERRORS, "Connection reset command was pushed by server ('%s')", m); c->sig->signal_received = SIGUSR1; /* SOFT-SIGUSR1 -- server-pushed connection reset */ c->sig->signal_text = "server-pushed-connection-reset"; } else { msg(D_STREAM_ERRORS, "Halt command was pushed by server ('%s')", m); c->sig->signal_received = SIGTERM; /* SOFT-SIGTERM -- server-pushed halt */ c->sig->signal_text = "server-pushed-halt"; } #ifdef ENABLE_MANAGEMENT if (management) { management_notify(management, "info", c->sig->signal_text, m); } #endif } }
const char * mroute_addr_print_ex (const struct mroute_addr *ma, const unsigned int flags, struct gc_arena *gc) { struct buffer out = alloc_buf_gc (64, gc); if (ma) { struct mroute_addr maddr = *ma; switch (maddr.type & MR_ADDR_MASK) { case MR_ADDR_ETHER: buf_printf (&out, "%s", format_hex_ex (ma->addr, 6, 0, 1, ":", gc)); break; case MR_ADDR_IPV4: { struct buffer buf; in_addr_t addr; int port; bool status; buf_set_read (&buf, maddr.addr, maddr.len); addr = buf_read_u32 (&buf, &status); if (status) { if ((flags & MAPF_SHOW_ARP) && (maddr.type & MR_ARP)) buf_printf (&out, "ARP/"); buf_printf (&out, "%s", print_in_addr_t (addr, (flags & MAPF_IA_EMPTY_IF_UNDEF) ? IA_EMPTY_IF_UNDEF : 0, gc)); if (maddr.type & MR_WITH_NETBITS) { if (flags & MAPF_SUBNET) { const in_addr_t netmask = netbits_to_netmask (maddr.netbits); buf_printf (&out, "/%s", print_in_addr_t (netmask, 0, gc)); } else buf_printf (&out, "/%d", maddr.netbits); } } if (maddr.type & MR_WITH_PORT) { port = buf_read_u16 (&buf); if (port >= 0) buf_printf (&out, ":%d", port); } } break; case MR_ADDR_IPV6: buf_printf (&out, "IPV6"); break; default: buf_printf (&out, "UNKNOWN"); break; } return BSTR (&out); } else return "[NULL]"; }
static const char * print_opt_route_gateway (const in_addr_t route_gateway, struct gc_arena *gc) { struct buffer out = alloc_buf_gc (128, gc); ASSERT (route_gateway); buf_printf (&out, "route-gateway %s", print_in_addr_t (route_gateway, 0, gc)); return BSTR (&out); }
static const char * headc (const struct buffer *buf) { static char foo[16]; strncpy (foo, BSTR(buf), 15); foo[15] = 0; return foo; }