void open_file(const boost::filesystem::path & file) { const std::string arg = fs::system_complete(file).normalize()._BOOST_FS_NATIVE(); SHELLEXECUTEINFO ExecuteInfo; memset(&ExecuteInfo, 0, sizeof(ExecuteInfo)); ExecuteInfo.cbSize = sizeof(ExecuteInfo); ExecuteInfo.fMask = 0; ExecuteInfo.hwnd = 0; ExecuteInfo.lpVerb = "open"; // Operation to perform ExecuteInfo.lpFile = "iexplore.exe"; //"c:\\windows\\notepad.exe"; // Application name ExecuteInfo.lpParameters = arg.c_str(); // Additional parameters ExecuteInfo.lpDirectory = 0; // Default directory ExecuteInfo.nShow = SW_SHOW; ExecuteInfo.hInstApp = 0; if(ShellExecuteEx(&ExecuteInfo) == FALSE) { // Could not start application -> call 'GetLastError()' throw get_win_last_error(); } log_stream() << std::endl << "If you have problems with the information bar in Internet Explorer," << std::endl << "follow the instructions at:" << std::endl << "http://www.phdcc.com/xpsp2.htm#securityoptions" << std::endl << std::endl; }
inline void tlog(const char *fmt, ...){ if( !log_stream() ) return; va_list argList; va_start(argList, fmt); const int BUFF_SIZES[]={1024, 16*1024, 64*1024, 256*1024, 1024*1024, 16*1024*1024}; int buffCount=sizeof(BUFF_SIZES)/sizeof(BUFF_SIZES[0]); char *ret[]={0, 0, 0, 0, 0, 0}; int buffSize=0; int err=-1; int buffIndex=0; for(; err==-1 && buffIndex < buffCount; ++buffIndex){ buffSize=BUFF_SIZES[buffIndex]; if(buffIndex!=0) delete[] ret[buffIndex-1]; ret[buffIndex]=new char[buffSize]; err=vsnprintf(ret[buffIndex], buffSize-1, fmt, argList); } fputs(ret[buffIndex-1], log_stream()); delete[] ret[buffIndex-1]; }
bool tearDownWorld(){ tlog("\n\n" ); tlog("//==========================================================\n" ); tlog("// -=[ Log end ]=- \n" ); tlog("//==========================================================\n" ); #if defined (N_LOG_FILE) fclose(log_stream()); #endif log_stream()=stdout; return true; }
/**************** * Show the revocation reason as it is stored with the given signature */ static void do_show_revocation_reason( PKT_signature *sig ) { size_t n, nn; const byte *p, *pp; int seq = 0; const char *text; while( (p = enum_sig_subpkt (sig->hashed, SIGSUBPKT_REVOC_REASON, &n, &seq, NULL )) ) { if( !n ) continue; /* invalid - just skip it */ if( *p == 0 ) text = _("No reason specified"); else if( *p == 0x01 ) text = _("Key is superseded"); else if( *p == 0x02 ) text = _("Key has been compromised"); else if( *p == 0x03 ) text = _("Key is no longer used"); else if( *p == 0x20 ) text = _("User ID is no longer valid"); else text = NULL; log_info( _("reason for revocation: ") ); if( text ) fputs( text, log_stream() ); else fprintf( log_stream(), "code=%02x", *p ); putc( '\n', log_stream() ); n--; p++; pp = NULL; do { /* We don't want any empty lines, so skip them */ while( n && *p == '\n' ) { p++; n--; } if( n ) { pp = memchr( p, '\n', n ); nn = pp? pp - p : n; log_info( _("revocation comment: ") ); print_string( log_stream(), p, nn, 0 ); putc( '\n', log_stream() ); p += nn; n -= nn; } } while( pp ); } }
void g10_log_mpidump( const char *text, MPI a ) { FILE *fp = log_stream(); g10_log_print_prefix(text); mpi_print(fp, a, 1 ); fputc('\n', fp); }
virtual Status logString(const std::string& s) { std::lock_guard<std::mutex> lock(filesystemLoggerPluginMutex); try { VLOG(3) << "filesystem logger plugin: logging to " << log_path; std::ofstream log_stream(log_path, std::ios_base::app | std::ios_base::out); if (log_stream.fail()) { return Status(1, "error opening file: " + log_path); } log_stream << s; } catch (const std::exception& e) { return Status(1, e.what()); } return Status(0, "OK"); }
nlohmann::json collection::evaluate_log(std::string const& log) { nlohmann::json json_log; std::istringstream log_stream(log); for(std::string line; std::getline(log_stream, line); ) { auto const delimiter = line.find_first_of(':'); if(delimiter != std::string::npos) { std::string key = line.substr(0, delimiter); std::string val = line.substr(delimiter + 2); std::replace(key.begin(), key.end(), ' ', '_'); std::transform(key.begin(), key.end(), key.begin(), ::tolower); nlohmann::json json_val; try { json_val = boost::lexical_cast<long>(val); } catch(boost::bad_lexical_cast const& e) { if(val == "YES") { json_val = true; } else if(val == "NO") { json_val = false; } else if(val == "'NONE'") { json_val = nullptr; } else { size_t const bson_hex_delimiter = val.find_first_of('/'); if(bson_hex_delimiter != std::string::npos) { std::string const bson_hex_string = val.substr(0, bson_hex_delimiter); std::string bson_decoded_data; boost::algorithm::unhex(bson_hex_string.begin(), bson_hex_string.end(), back_inserter(bson_decoded_data)); json_val = convert_to_json(std::shared_ptr<bson>(bson_create_from_buffer(bson_decoded_data.data(), bson_decoded_data.size()), bson_del)); } else { json_val = val; } } } if(json_log.find(key) != json_log.end()) { if(json_log[key].type() != nlohmann::json::value_t::array) { json_log[key] = nlohmann::json::array_t({ json_log[key] }); } json_log[key].push_back(json_val); } else { json_log[key] = json_val; } } } return json_log; }
PAL_HANDLE DkProcessCreate (PAL_STR uri, PAL_FLG flags, PAL_STR * args) { ENTER_PAL_CALL(DkProcessCreate); log_stream(uri); PAL_HANDLE handle = NULL; int ret = _DkProcessCreate(&handle, uri, flags, args); if (ret < 0) { _DkRaiseFailure(-ret); handle = NULL; } LEAVE_PAL_CALL_RETURN(handle); }
QString UDDBusServer::getLastMessagesLines(int lines_count){ QFile log("/var/log/messages"); log.open(QIODevice::ReadOnly); QTextStream log_stream(&log); QString line; QStringList last_lines; int current_count = 0; while (!log_stream.atEnd()){ line = log_stream.readLine(); last_lines.push_back(line); if (current_count >= lines_count) last_lines.pop_front(); else current_count++; } log.close(); QString result; result = last_lines.join("\n"); return result; }
bool setUpWorld(){ const char *logOut="stdout"; #if defined(N_LOG_FILE) // log to file logOut=N_LOG_FILE; log_stream()=fopen(logOut, "w"); #else // log to stdout. tlog("\n"); #endif time_t curr=time(NULL); tlog("//==========================================================\n" "/**\n" " \\file %s\n" " \\date: %s" "*/\n" "//==========================================================\n", logOut, ctime(&curr) ); return true; }
static int get_it( PKT_pubkey_enc *enc, DEK *dek, PKT_secret_key *sk, u32 *keyid ) { int rc; MPI plain_dek = NULL; byte *frame = NULL; unsigned n, nframe; u16 csum, csum2; int card = 0; if (sk->is_protected && sk->protect.s2k.mode == 1002) { /* Note, that we only support RSA for now. */ #ifdef ENABLE_CARD_SUPPORT unsigned char *rbuf; size_t rbuflen; char *snbuf; unsigned char *indata = NULL; unsigned int indatalen; snbuf = serialno_and_fpr_from_sk (sk->protect.iv, sk->protect.ivlen, sk); indata = mpi_get_buffer (enc->data[0], &indatalen, NULL); if (!indata) BUG (); rc = agent_scd_pkdecrypt (snbuf, indata, indatalen, &rbuf, &rbuflen); xfree (snbuf); xfree (indata); if (rc) goto leave; frame = rbuf; nframe = rbuflen; card = 1; #else rc = G10ERR_UNSUPPORTED; goto leave; #endif /*!ENABLE_CARD_SUPPORT*/ } else { rc = pubkey_decrypt(sk->pubkey_algo, &plain_dek, enc->data, sk->skey ); if( rc ) goto leave; frame = mpi_get_buffer( plain_dek, &nframe, NULL ); mpi_free( plain_dek ); plain_dek = NULL; } /* Now get the DEK (data encryption key) from the frame * * Old versions encode the DEK in in this format (msb is left): * * 0 1 DEK(16 bytes) CSUM(2 bytes) 0 RND(n bytes) 2 * * Later versions encode the DEK like this: * * 0 2 RND(n bytes) 0 A DEK(k bytes) CSUM(2 bytes) * * (mpi_get_buffer already removed the leading zero). * * RND are non-zero randow bytes. * A is the cipher algorithm * DEK is the encryption key (session key) with length k * CSUM */ if( DBG_CIPHER ) log_hexdump("DEK frame:", frame, nframe ); n=0; if (!card) { if( n + 7 > nframe ) { rc = G10ERR_WRONG_SECKEY; goto leave; } if( frame[n] == 1 && frame[nframe-1] == 2 ) { log_info(_("old encoding of the DEK is not supported\n")); rc = G10ERR_CIPHER_ALGO; goto leave; } if( frame[n] != 2 ) /* somethink is wrong */ { rc = G10ERR_WRONG_SECKEY; goto leave; } for(n++; n < nframe && frame[n]; n++ ) /* skip the random bytes */ ; n++; /* and the zero byte */ } if( n + 4 > nframe ) { rc = G10ERR_WRONG_SECKEY; goto leave; } dek->keylen = nframe - (n+1) - 2; dek->algo = frame[n++]; if( dek->algo == CIPHER_ALGO_IDEA ) write_status(STATUS_RSA_OR_IDEA); rc = check_cipher_algo( dek->algo ); if( rc ) { if( !opt.quiet && rc == G10ERR_CIPHER_ALGO ) { log_info(_("cipher algorithm %d%s is unknown or disabled\n"), dek->algo, dek->algo == CIPHER_ALGO_IDEA? " (IDEA)":""); if(dek->algo==CIPHER_ALGO_IDEA) idea_cipher_warn(0); } dek->algo = 0; goto leave; } if( (dek->keylen*8) != cipher_get_keylen( dek->algo ) ) { rc = G10ERR_WRONG_SECKEY; goto leave; } /* copy the key to DEK and compare the checksum */ csum = frame[nframe-2] << 8; csum |= frame[nframe-1]; memcpy( dek->key, frame+n, dek->keylen ); for( csum2=0, n=0; n < dek->keylen; n++ ) csum2 += dek->key[n]; if( csum != csum2 ) { rc = G10ERR_WRONG_SECKEY; goto leave; } if( DBG_CIPHER ) log_hexdump("DEK is:", dek->key, dek->keylen ); /* check that the algo is in the preferences and whether it has expired */ { PKT_public_key *pk = NULL; KBNODE pkb = get_pubkeyblock (keyid); if( !pkb ) { rc = -1; log_error("oops: public key not found for preference check\n"); } else if(pkb->pkt->pkt.public_key->selfsigversion > 3 && dek->algo != CIPHER_ALGO_3DES && !opt.quiet && !is_algo_in_prefs( pkb, PREFTYPE_SYM, dek->algo )) log_info(_("WARNING: cipher algorithm %s not found in recipient" " preferences\n"),cipher_algo_to_string(dek->algo)); if (!rc) { KBNODE k; for (k=pkb; k; k = k->next) { if (k->pkt->pkttype == PKT_PUBLIC_KEY || k->pkt->pkttype == PKT_PUBLIC_SUBKEY){ u32 aki[2]; keyid_from_pk(k->pkt->pkt.public_key, aki); if (aki[0]==keyid[0] && aki[1]==keyid[1]) { pk = k->pkt->pkt.public_key; break; } } } if (!pk) BUG (); if ( pk->expiredate && pk->expiredate <= make_timestamp() ) { log_info(_("NOTE: secret key %s expired at %s\n"), keystr(keyid), asctimestamp( pk->expiredate) ); } } if ( pk && pk->is_revoked ) { log_info( _("NOTE: key has been revoked") ); putc( '\n', log_stream() ); show_revocation_reason( pk, 1 ); } release_kbnode (pkb); rc = 0; } leave: mpi_free(plain_dek); xfree(frame); return rc; }
void print_impl() { log_stream() << '\n'; commitLog(); }
int main(int argc, char **argv) { struct stat st; char *slash; int fd; int ch; const char *tag; int log_flags = 0; int level = MSG_INFO; /* * Fingerprint executables and core dumps. */ MAIL_VERSION_STAMP_ALLOCATE; /* * Be consistent with file permissions. */ umask(022); /* * To minimize confusion, make sure that the standard file descriptors * are open before opening anything else. XXX Work around for 44BSD where * fstat can return EBADF on an open file descriptor. */ for (fd = 0; fd < 3; fd++) if (fstat(fd, &st) == -1 && (close(fd), open("/dev/null", O_RDWR, 0)) != fd) msg_fatal("open /dev/null: %m"); /* * Set up diagnostics. */ if ((slash = strrchr(argv[0], '/')) != 0 && slash[1]) tag = mail_task(slash + 1); else tag = mail_task(argv[0]); if (isatty(STDERR_FILENO)) msg_vstream_init(tag, VSTREAM_ERR); msg_syslog_init(tag, LOG_PID, LOG_FACILITY); /* * Check the Postfix library version as soon as we enable logging. */ MAIL_VERSION_CHECK; /* * Parse switches. */ while ((ch = GETOPT(argc, argv, "c:ip:t:v")) > 0) { switch (ch) { default: msg_fatal("usage: %s [-c config_dir] [-i] [-p priority] [-t tag] [-v] [text]", tag); break; case 'c': if (setenv(CONF_ENV_PATH, optarg, 1) < 0) msg_fatal("out of memory"); break; case 'i': log_flags |= LOG_PID; break; case 'p': level = level_map(optarg); break; case 't': tag = optarg; break; case 'v': msg_verbose++; break; } } /* * Process the main.cf file. This overrides any logging facility that was * specified with msg_syslog_init(); */ mail_conf_read(); if (tag == 0 && strcmp(var_syslog_name, DEF_SYSLOG_NAME) != 0) { if ((slash = strrchr(argv[0], '/')) != 0 && slash[1]) tag = mail_task(slash + 1); else tag = mail_task(argv[0]); } /* * Re-initialize the logging, this time with the tag specified in main.cf * or on the command line. */ if (tag != 0) { if (isatty(STDERR_FILENO)) msg_vstream_init(tag, VSTREAM_ERR); msg_syslog_init(tag, LOG_PID, LOG_FACILITY); } /* * Log the command line or log lines from standard input. */ if (argc > optind) { log_argv(level, argv + optind); } else { log_stream(level, VSTREAM_IN); } exit(0); }
void UnitTestOutputLog::testUnit() { // Make cout and cerr available as log stream targets. stk::register_log_ostream(std::cout, "cout"); stk::register_log_ostream(std::cerr, "cerr"); // Test registration, binding, rebinding and unregistration { std::ostringstream log1; std::ostringstream log2; std::ostream out(std::cout.rdbuf()); stk::register_ostream(out, "out"); CPPUNIT_ASSERT(stk::is_registered_ostream("out")); stk::register_log_ostream(log1, "log1"); stk::register_log_ostream(log2, "log2"); stk::bind_output_streams("out>log1"); out << "stk::bind_output_streams(\"out>log1\");" << std::endl; stk::bind_output_streams("out>+log2"); out << "stk::bind_output_streams(\"out>+log2\");" << std::endl; stk::bind_output_streams("out>-log1"); out << "stk::bind_output_streams(\"out>-log1\");" << std::endl; stk::bind_output_streams("out>-log2"); out << "stk::bind_output_streams(\"out>-log2\");" << std::endl; std::ostringstream log1_result; log1_result << "stk::bind_output_streams(\"out>log1\");" << std::endl << "stk::bind_output_streams(\"out>+log2\");" << std::endl; std::ostringstream log2_result; log2_result << "stk::bind_output_streams(\"out>+log2\");" << std::endl << "stk::bind_output_streams(\"out>-log1\");" << std::endl; CPPUNIT_ASSERT_EQUAL(log1_result.str(), log1.str()); CPPUNIT_ASSERT_EQUAL(log2_result.str(), log2.str()); stk::unregister_log_ostream(log1); stk::unregister_log_ostream(log2); stk::unregister_ostream(out); CPPUNIT_ASSERT_EQUAL(out.rdbuf(), std::cout.rdbuf()); } // Test logging to a file { std::ostream out(std::cout.rdbuf()); stk::register_ostream(out, "out"); stk::bind_output_streams("log=\"logfile\" out>log"); CPPUNIT_ASSERT_EQUAL(std::string("logfile"), stk::get_log_path("log")); out << "This is a test" << std::endl; stk::bind_output_streams("log=\"\""); stk::unregister_ostream(out); std::ostringstream log_result; log_result << "This is a test"; std::ifstream log_stream("logfile"); std::string log_string; getline(log_stream, log_string); CPPUNIT_ASSERT_EQUAL(log_result.str(), log_string); } // Test results of unregistration of an output stream bound as a log stream { std::ostringstream default_log; std::ostream out(default_log.rdbuf()); std::ostream pout(std::cout.rdbuf()); stk::register_ostream(out, "out"); stk::register_ostream(pout, "pout"); // Constructing the log streams after the registered output stream is not exception safe. std::ostringstream log; stk::register_log_ostream(log, "log"); // As a result, this try catch block must be represent to ensure the that unregistration // happens correctly. try { stk::bind_output_streams("out>pout pout>log"); out << "This is to out" << std::endl; pout << "This is to pout" << std::endl; std::ostringstream log_result; log_result << "This is to out" << std::endl << "This is to pout" << std::endl; CPPUNIT_ASSERT_EQUAL(log_result.str(), log.str()); throw std::exception(); } catch (...) { } stk::unregister_log_ostream(log); stk::unregister_ostream(pout); stk::unregister_ostream(out); out << "This is to out" << std::endl; std::ostringstream log_result; log_result << "This is to out" << std::endl; CPPUNIT_ASSERT_EQUAL(log_result.str(), default_log.str()); } // Test exception of registration with existing name { std::ostringstream log1; std::ostringstream log2; std::ostream out(std::cout.rdbuf()); std::ostream pout(std::cout.rdbuf()); stk::register_ostream(out, "out"); CPPUNIT_ASSERT_THROW(stk::register_ostream(pout, "out"), std::runtime_error); CPPUNIT_ASSERT_EQUAL(&out, stk::get_ostream_ostream("out")); stk::register_log_ostream(log1, "log"); CPPUNIT_ASSERT_THROW(stk::register_log_ostream(log2, "log"), std::runtime_error); CPPUNIT_ASSERT_THROW(stk::bind_output_streams("badout>log"), std::runtime_error); CPPUNIT_ASSERT_THROW(stk::bind_output_streams("out>badlog"), std::runtime_error); stk::unregister_log_ostream(log1); stk::unregister_ostream(out); } }