std::string Timer::approximateTimeLeft(std::string name, double percentage) const { TimeTypes::TimerList::const_iterator it = timers.find(name); std::ostringstream ss; ss.precision(3); if (it != timers.end()) { double time = it->second.getRealtime(getCurrentTime()); TIME_FORMAT f1; double ctime = convertToHighest(f1, time); ss << printable(time, HIGHEST) << " "; //percentage = 0, 100 if (percentage > 0.0001) { double approx = time / percentage * (100.0 - percentage); double capprox = convertToHighest(f1, approx); ss << printable(approx, HIGHEST); } return ss.str(); } else { std::cout << "No timer called " << name << " found."; } std::cout << std::endl; return ""; }
static void xsasl_dovecot_parse_reply_args(XSASL_DOVECOT_SERVER *server, char *line, VSTRING *reply, int success) { char *next; if (server->username) { myfree(server->username); server->username = 0; } /* * Note: TAB is part of the Dovecot protocol and must not appear in * legitimate Dovecot usernames, otherwise the protocol would break. */ for (; line != NULL; line = next) { next = split_at(line, '\t'); if (strncmp(line, "user="******"reason=", 7) == 0) { if (!success) { printable(line + 7, '?'); vstring_strcpy(reply, line + 7); } } } }
void print_payload( const u_char * payload, int len ) { int line_width = 16; int count = len / line_width; int i = 0; int index = 0; char str[17] = {'\0'}; printf( "\n\n\n" ); while( count-- ){ for( i = 0; i < line_width; i++, index++ ){ printf( "%02X ", payload[index] ); str[i] = printable( payload[index] ); } str[i] = '\0'; printf( "\t%s\n", str ); } for( i = 0; i < line_width; i++, index++ ){ if( index < len ){ printf( "%02X ", payload[index] ); str[i] = printable( payload[index] ); } else printf( " " ); str[i+1] = '\0'; } printf( "\t%s\n", str ); printf( "\n\n\n" ); }
static int hexdump(FILE* out, FILE* fh, const char* filename) { int i; int count; unsigned long offset; char buf[kWidth + 1] = {0}; (void)filename; offset = 0; while(true) { count = fread(buf, sizeof(char), kWidth, fh); fprintf(out, "%07lx: ", offset); offset += kWidth; for(i=0; i<count; i++) { fprintf(out, "%02X ", (unsigned char)buf[i]); } if(count < kWidth) { for(i = 0; i < (kWidth - count); i++) { fputs(" ", out); } printable(out, buf, count); fputc('\n', out); break; } printable(out, buf, kWidth); fputc('\n', out); fflush(out); } return 0; }
int main(int argc, char *argv[]) { int opt, xfnd; char *pstr; xfnd = 0; pstr = NULL; while ((opt = getopt(argc, argv, ":p:x")) != -1) { printf("opt =%3d (%c); optind = %d", opt, printable(opt), optind); if (opt == '?' || opt == ':') printf("; optopt =%3d (%c)", optopt, printable(optopt)); printf("\n"); switch (opt) { case 'p': pstr = optarg; break; case 'x': xfnd++; break; case ':': usageError(argv[0], "Missing argument", optopt); case '?': usageError(argv[0], "Unrecognized option", optopt); default: fatal("Unexpected case in switch()"); } } if (xfnd != 0) printf("-x was specified (count=%d)\n", xfnd); if (pstr != NULL) printf("-p was specified with the value \"%s\"\n", pstr); if (optind < argc) printf("First nonoption argument is \"%s\" at argv[%d]\n", argv[optind], optind); exit(EXIT_SUCCESS); }
void test_conv_base( Instance const& conv ) { typedef typename Instance::argument_type argument_type ; typedef typename Instance::result_type result_type ; typedef typename Instance::converter converter ; argument_type source = conv.source ; try { result_type result = converter::convert(source); if ( conv.post == c_converted ) { BOOST_CHECK_MESSAGE( result == conv.result, conv.to_string() << printable(source) << ")= " << printable(result) << ". Expected:" << printable(conv.result) ) ; } else { BOOST_ERROR( conv.to_string() << printable(source) << ") = " << printable(result) << ". Expected:" << ( conv.post == c_neg_overflow ? " negative_overflow" : "positive_overflow" ) ) ; } } catch ( boost::numeric::negative_overflow const& ) { if ( conv.post == c_neg_overflow ) { BOOST_CHECK_MESSAGE( true, conv.to_string() << printable(source) << ") = negative_overflow, as expected" ) ; } else { BOOST_ERROR( conv.to_string() << printable(source) << ") = negative_overflow. Expected:" << printable(conv.result) ) ; } } catch ( boost::numeric::positive_overflow const& ) { if ( conv.post == c_pos_overflow ) { BOOST_CHECK_MESSAGE( true, conv.to_string() << printable(source) << ") = positive_overflow, as expected" ) ; } else { BOOST_ERROR( conv.to_string() << printable(source) << ") = positive_overflow. Expected:" << printable(conv.result) ) ; } } catch ( boost::numeric::bad_numeric_cast const& ) { if ( conv.post == c_overflow ) { BOOST_CHECK_MESSAGE( true, conv.to_string() << printable(source) << ") = bad_numeric_cast, as expected" ) ; } else { BOOST_ERROR( conv.to_string() << printable(source) << ") = bad_numeric_cast. Expected:" << printable(conv.result) ) ; } } }
static int bounce_verp_proto(char *service_name, VSTREAM *client) { char *myname = "bounce_verp_proto"; int flags; /* * Read and validate the client request. */ if (mail_command_server(client, ATTR_TYPE_NUM, MAIL_ATTR_FLAGS, &flags, ATTR_TYPE_STR, MAIL_ATTR_QUEUE, queue_name, ATTR_TYPE_STR, MAIL_ATTR_QUEUEID, queue_id, ATTR_TYPE_STR, MAIL_ATTR_ENCODING, encoding, ATTR_TYPE_STR, MAIL_ATTR_SENDER, sender, ATTR_TYPE_STR, MAIL_ATTR_VERPDL, verp_delims, ATTR_TYPE_END) != 6) { msg_warn("malformed request"); return (-1); } if (mail_queue_name_ok(STR(queue_name)) == 0) { msg_warn("malformed queue name: %s", printable(STR(queue_name), '?')); return (-1); } if (mail_queue_id_ok(STR(queue_id)) == 0) { msg_warn("malformed queue id: %s", printable(STR(queue_id), '?')); return (-1); } if (strlen(STR(verp_delims)) != 2) { msg_warn("malformed verp delimiter string: %s", printable(STR(verp_delims), '?')); return (-1); } if (msg_verbose) msg_info("%s: flags=0x%x service=%s queue=%s id=%s encoding=%s sender=%s delim=%s", myname, flags, service_name, STR(queue_name), STR(queue_id), STR(encoding), STR(sender), STR(verp_delims)); /* * On request by the client, set up a trap to delete the log file in case * of errors. */ if (flags & BOUNCE_FLAG_CLEAN) bounce_cleanup_register(service_name, STR(queue_id)); /* * Execute the request. Fall back to traditional notification if a bounce * was returned as undeliverable, because we don't want to VERPify those. */ if (!*STR(sender) || !strcasecmp(STR(sender), mail_addr_double_bounce())) { msg_warn("request to send VERP-style notification of bounced mail"); return (bounce_notify_service(flags, service_name, STR(queue_name), STR(queue_id), STR(encoding), STR(sender))); } else return (bounce_notify_verp(flags, service_name, STR(queue_name), STR(queue_id), STR(encoding), STR(sender), STR(verp_delims))); }
static int bounce_notify_proto(char *service_name, VSTREAM *client, int (*service) (int, char *, char *, char *, char *, char *, char *, int, BOUNCE_TEMPLATES *)) { const char *myname = "bounce_notify_proto"; int flags; int dsn_ret; /* * Read and validate the client request. */ if (mail_command_server(client, ATTR_TYPE_INT, MAIL_ATTR_FLAGS, &flags, ATTR_TYPE_STR, MAIL_ATTR_QUEUE, queue_name, ATTR_TYPE_STR, MAIL_ATTR_QUEUEID, queue_id, ATTR_TYPE_STR, MAIL_ATTR_ENCODING, encoding, ATTR_TYPE_STR, MAIL_ATTR_SENDER, sender, ATTR_TYPE_STR, MAIL_ATTR_DSN_ENVID, dsn_envid, ATTR_TYPE_INT, MAIL_ATTR_DSN_RET, &dsn_ret, ATTR_TYPE_END) != 7) { msg_warn("malformed request"); return (-1); } /* * Sanitize input. */ if (mail_queue_name_ok(STR(queue_name)) == 0) { msg_warn("malformed queue name: %s", printable(STR(queue_name), '?')); return (-1); } if (mail_queue_id_ok(STR(queue_id)) == 0) { msg_warn("malformed queue id: %s", printable(STR(queue_id), '?')); return (-1); } printable(STR(dsn_envid), '?'); if (msg_verbose) msg_info("%s: flags=0x%x service=%s queue=%s id=%s encoding=%s sender=%s envid=%s ret=0x%x", myname, flags, service_name, STR(queue_name), STR(queue_id), STR(encoding), STR(sender), STR(dsn_envid), dsn_ret); /* * On request by the client, set up a trap to delete the log file in case * of errors. */ if (flags & BOUNCE_FLAG_CLEAN) bounce_cleanup_register(service_name, STR(queue_id)); /* * Execute the request. */ return (service(flags, service_name, STR(queue_name), STR(queue_id), STR(encoding), STR(sender), STR(dsn_envid), dsn_ret, bounce_templates)); }
int smtpd_sasl_authenticate(SMTPD_STATE *state, const char *sasl_method, const char *init_response) { int status; const char *sasl_username; /* * SASL authentication protocol start-up. Process any initial client * response that was sent along in the AUTH command. */ for (status = xsasl_server_first(state->sasl_server, sasl_method, init_response, state->sasl_reply); status == XSASL_AUTH_MORE; status = xsasl_server_next(state->sasl_server, STR(state->buffer), state->sasl_reply)) { /* * Send a server challenge. */ smtpd_chat_reply(state, "334 %s", STR(state->sasl_reply)); /* * Receive the client response. "*" means that the client gives up. * XXX For now we ignore the fact that an excessively long response * will be chopped into multiple reponses. To handle such responses, * we need to change smtpd_chat_query() so that it returns an error * indication. */ smtpd_chat_query(state); if (strcmp(STR(state->buffer), "*") == 0) { msg_warn("%s: SASL %s authentication aborted", state->namaddr, sasl_method); smtpd_chat_reply(state, "501 5.7.0 Authentication aborted"); return (-1); } } if (status != XSASL_AUTH_DONE) { msg_warn("%s: SASL %s authentication failed: %s", state->namaddr, sasl_method, STR(state->sasl_reply)); /* RFC 4954 Section 6. */ smtpd_chat_reply(state, "535 5.7.8 Error: authentication failed: %s", STR(state->sasl_reply)); return (-1); } /* RFC 4954 Section 6. */ smtpd_chat_reply(state, "235 2.7.0 Authentication successful"); if ((sasl_username = xsasl_server_get_username(state->sasl_server)) == 0) msg_panic("cannot look up the authenticated SASL username"); state->sasl_username = mystrdup(sasl_username); printable(state->sasl_username, '?'); state->sasl_method = mystrdup(sasl_method); printable(state->sasl_method, '?'); return (0); }
static int bounce_one_proto(char *service_name, VSTREAM *client) { char *myname = "bounce_one_proto"; int flags; long offset; /* * Read and validate the client request. */ if (mail_command_server(client, ATTR_TYPE_NUM, MAIL_ATTR_FLAGS, &flags, ATTR_TYPE_STR, MAIL_ATTR_QUEUE, queue_name, ATTR_TYPE_STR, MAIL_ATTR_QUEUEID, queue_id, ATTR_TYPE_STR, MAIL_ATTR_ENCODING, encoding, ATTR_TYPE_STR, MAIL_ATTR_SENDER, sender, ATTR_TYPE_STR, MAIL_ATTR_ORCPT, orig_rcpt, ATTR_TYPE_STR, MAIL_ATTR_RECIP, recipient, ATTR_TYPE_LONG, MAIL_ATTR_OFFSET, &offset, ATTR_TYPE_STR, MAIL_ATTR_STATUS, dsn_status, ATTR_TYPE_STR, MAIL_ATTR_ACTION, dsn_action, ATTR_TYPE_STR, MAIL_ATTR_WHY, why, ATTR_TYPE_END) != 11) { msg_warn("malformed request"); return (-1); } if (strcmp(service_name, MAIL_SERVICE_BOUNCE) != 0) { msg_warn("wrong service name \"%s\" for one-recipient bouncing", service_name); return (-1); } if (mail_queue_name_ok(STR(queue_name)) == 0) { msg_warn("malformed queue name: %s", printable(STR(queue_name), '?')); return (-1); } if (mail_queue_id_ok(STR(queue_id)) == 0) { msg_warn("malformed queue id: %s", printable(STR(queue_id), '?')); return (-1); } if (msg_verbose) msg_info("%s: flags=0x%x queue=%s id=%s encoding=%s sender=%s orig_to=%s to=%s off=%ld stat=%s act=%s why=%s", myname, flags, STR(queue_name), STR(queue_id), STR(encoding), STR(sender), STR(orig_rcpt), STR(recipient), offset, STR(dsn_status), STR(dsn_action), STR(why)); /* * Execute the request. */ return (bounce_one_service(flags, STR(queue_name), STR(queue_id), STR(encoding), STR(sender), STR(orig_rcpt), STR(recipient), offset, STR(dsn_status), STR(dsn_action), STR(why))); }
void allprint(char c) { switch(c) { case '\n': fprintf(yyout,"\\n"); break; case '\t': fprintf(yyout,"\\t"); break; case '\b': fprintf(yyout,"\\b"); break; case ' ': fprintf(yyout,"\\\bb"); break; default: if(!printable(c)) fprintf(yyout,"\\%-3o",c); else c = putc(c,yyout); USED(c); break; } return; }
char *smtpd_sasl_mail_opt(SMTPD_STATE *state, const char *addr) { /* * Do not store raw RFC2554 protocol data. */ if (!smtpd_sasl_is_active(state)) { state->error_mask |= MAIL_ERROR_PROTOCOL; return ("503 5.5.4 Error: authentication disabled"); } #if 0 if (state->sasl_username == 0) { state->error_mask |= MAIL_ERROR_PROTOCOL; return ("503 5.5.4 Error: send AUTH command first"); } #endif if (state->sasl_sender != 0) { state->error_mask |= MAIL_ERROR_PROTOCOL; return ("503 5.5.4 Error: multiple AUTH= options"); } if (strcmp(addr, "<>") != 0) { state->sasl_sender = mystrdup(addr); printable(state->sasl_sender, '?'); } return (0); }
static void report_load_module(struct path *path, char *operation) { char *alloced = NULL, *cmdline; char *pathname; /* Pointer to either static string or "alloced". */ if (!path) pathname = "<unknown>"; else { /* We will allow 11 spaces for ' (deleted)' to be appended */ alloced = pathname = kmalloc(PATH_MAX+11, GFP_KERNEL); if (!pathname) pathname = "<no_memory>"; else { pathname = d_path(path, pathname, PATH_MAX+11); if (IS_ERR(pathname)) pathname = "<too_long>"; else { pathname = printable(pathname); kfree(alloced); alloced = pathname; } } } cmdline = printable_cmdline(current); pr_notice("init_module %s module=%s pid=%d cmdline=%s\n", operation, pathname, task_pid_nr(current), cmdline); kfree(cmdline); kfree(alloced); }
void send_nntp(const char *format, ...) { char *out, p[4]; va_list va_ptr; out = calloc(4096, sizeof(char)); va_start(va_ptr, format); vsnprintf(out, 4096, format, va_ptr); va_end(va_ptr); /* * Only log responses */ if (out[3] == ' ') { memset(&p, 0, sizeof(p)); strncpy(p, out, 3); if (atoi(p) > 0) { Syslog('n', "> \"%s\"", printable(out, 0)); } } PUTSTR(out); PUTSTR((char *)"\r\n"); FLUSHOUT(); sentbytes += (strlen(out) + 2); free(out); }
void basedump (FILE* file, node* root) { if ( root != NULL ) { int i, j; /* iterators */ basedump (file, root->right); basedump (file, root->left); fprintf (file, "%d %d \n", root->record->key, root->record->index); printable(root->record->name); fprintf (file,"%s\n",root->record->name); fprintf (file, "["); for(i=0;i<root->record->size;i++) { for(j=0;j<root->record->size;j++) { fprintf(file,"%g ",root->record->matrix[i][j]); } if (i+1 < root->record->size) fprintf(file,";"); } fprintf (file, "] \n"); fprintf (file, "%d \n", root->record->size); } }
char * format_next_process(caddr_t handle, char *(*get_userid) ()) { struct prpsinfo *pp; struct handle *hp; long cputime; /* find and remember the next proc structure */ hp = (struct handle *) handle; pp = *(hp->next_proc++); hp->remaining--; /* get the process cpu usage since startup */ cputime = pp->pr_time.tv_sec; /* format this entry */ sprintf(fmt, Proc_format, pp->pr_pid, pp->pr_pgrp, (*get_userid) (pp->pr_uid), format_prio(pp), format_k(pagetok(pp->pr_size)), format_k(pagetok(pp->pr_rssize)), format_state(pp), format_time(cputime), clip_percent(weighted_cpu(pp)), clip_percent(percent_cpu(pp)), printable(pp->pr_fname)); /* return the result */ return (fmt); }
/* Get partition names. Check against match list */ void initialize() { const char *scan_fmt = NULL; scan_fmt = "%4d %4d %31s %u"; while (fgets(buffer, sizeof(buffer), iofp)) { unsigned int reads = 0; struct part_info curr; if (sscanf(buffer, scan_fmt, &curr.major, &curr.minor, curr.name, &reads) == 4) { unsigned int p; for (p = 0; p < n_partitions && (partition[p].major != curr.major || partition[p].minor != curr.minor); p++); if (p == n_partitions && p < MAX_PARTITIONS) { if (reads && printable(curr.major,curr.minor)) { partition[p] = curr; n_partitions = p + 1; } } } } }
int tls_verify_certificate_callback(int ok, X509_STORE_CTX *ctx) { char buf[CCERT_BUFSIZ]; X509 *cert; int err; int depth; int max_depth; SSL *con; TLS_SESS_STATE *TLScontext; /* May be NULL as of OpenSSL 1.0, thanks for the API change! */ cert = X509_STORE_CTX_get_current_cert(ctx); err = X509_STORE_CTX_get_error(ctx); con = X509_STORE_CTX_get_ex_data(ctx, SSL_get_ex_data_X509_STORE_CTX_idx()); TLScontext = SSL_get_ex_data(con, TLScontext_index); depth = X509_STORE_CTX_get_error_depth(ctx); /* Don't log the internal root CA unless there's an unexpected error. */ if (ok && TLScontext->tadepth > 0 && depth > TLScontext->tadepth) return (1); /* * Certificate chain depth limit violations are mis-reported by the * OpenSSL library, from SSL_CTX_set_verify(3): * * The certificate verification depth set with SSL[_CTX]_verify_depth() * stops the verification at a certain depth. The error message produced * will be that of an incomplete certificate chain and not * X509_V_ERR_CERT_CHAIN_TOO_LONG as may be expected. * * We set a limit that is one higher than the user requested limit. If this * higher limit is reached, we raise an error even a trusted root CA is * present at this depth. This disambiguates trust chain truncation from * an incomplete trust chain. */ max_depth = SSL_get_verify_depth(con) - 1; /* * We never terminate the SSL handshake in the verification callback, * rather we allow the TLS handshake to continue, but mark the session as * unverified. The application is responsible for closing any sessions * with unverified credentials. */ if (max_depth >= 0 && depth > max_depth) { X509_STORE_CTX_set_error(ctx, err = X509_V_ERR_CERT_CHAIN_TOO_LONG); ok = 0; } if (ok == 0) update_error_state(TLScontext, depth, cert, err); if (TLScontext->log_mask & TLS_LOG_VERBOSE) { if (cert) X509_NAME_oneline(X509_get_subject_name(cert), buf, sizeof(buf)); else strcpy(buf, "<unknown>"); msg_info("%s: depth=%d verify=%d subject=%s", TLScontext->namaddr, depth, ok, printable(buf, '?')); } return (1); }
const char *tls_dns_name(const GENERAL_NAME * gn, const TLS_SESS_STATE *TLScontext) { const char *myname = "tls_dns_name"; char *cp; const char *dnsname; int len; /* * Peername checks are security sensitive, carefully scrutinize the * input! */ if (gn->type != GEN_DNS) msg_panic("%s: Non DNS input argument", myname); /* * We expect the OpenSSL library to construct GEN_DNS extesion objects as * ASN1_IA5STRING values. Check we got the right union member. */ if (ASN1_STRING_type(gn->d.ia5) != V_ASN1_IA5STRING) { msg_warn("%s: %s: invalid ASN1 value type in subjectAltName", myname, TLScontext->namaddr); return (0); } /* * Safe to treat as an ASCII string possibly holding a DNS name */ dnsname = (char *) ASN1_STRING_data(gn->d.ia5); len = ASN1_STRING_length(gn->d.ia5); TRIM0(dnsname, len); /* * Per Dr. Steven Henson of the OpenSSL development team, ASN1_IA5STRING * values can have internal ASCII NUL values in this context because * their length is taken from the decoded ASN1 buffer, a trailing NUL is * always appended to make sure that the string is terminated, but the * ASN.1 length may differ from strlen(). */ if (len != strlen(dnsname)) { msg_warn("%s: %s: internal NUL in subjectAltName", myname, TLScontext->namaddr); return 0; } /* * XXX: Should we be more strict and call valid_hostname()? So long as * the name is safe to handle, if it is not a valid hostname, it will not * compare equal to the expected peername, so being more strict than * "printable" is likely excessive... */ if (*dnsname && !allprint(dnsname)) { cp = mystrdup(dnsname); msg_warn("%s: %s: non-printable characters in subjectAltName: %.100s", myname, TLScontext->namaddr, printable(cp, '?')); myfree(cp); return 0; } return (dnsname); }
ostream &FrTextSpan::printValue(ostream &output) const { FrList *span = printable() ; output << span ; free_object(span) ; return output ; }
void FrTextSpans::_() const { FrList *printed = printable() ; cout << printed << endl ; free_object(printed) ; return ; }
static void /* Print "usage" message and exit */ usageError(char *progName, char *msg, int opt) { if (msg != NULL && opt != 0) fprintf(stderr, "%s (-%c)\n", msg, printable(opt)); fprintf(stderr, "Usage: %s [-p arg] [-x]\n", progName); exit(EXIT_FAILURE); }
/* Repurposed from fs/proc/base.c, with NULL-replacement for saner printing. * Allocates the buffer itself. */ char *printable_cmdline(struct task_struct *task) { char *buffer = NULL, *sanitized; int res, i; unsigned int len; struct mm_struct *mm; mm = get_task_mm(task); if (!mm) goto out; if (!mm->arg_end) goto out_mm; /* Shh! No looking before we're done */ buffer = kmalloc(PAGE_SIZE, GFP_KERNEL); if (!buffer) goto out_mm; len = mm->arg_end - mm->arg_start; if (len > PAGE_SIZE) len = PAGE_SIZE; res = access_process_vm(task, mm->arg_start, buffer, len, 0); /* Space-fill NULLs. */ if (res > 1) for (i = 0; i < res - 2; ++i) if (buffer[i] == '\0') buffer[i] = ' '; /* If the NULL at the end of args has been overwritten, then * assume application is using setproctitle(3). */ if (res > 0 && buffer[res-1] != '\0' && len < PAGE_SIZE) { len = strnlen(buffer, res); if (len < res) { res = len; } else { len = mm->env_end - mm->env_start; if (len > PAGE_SIZE - res) len = PAGE_SIZE - res; res += access_process_vm(task, mm->env_start, buffer+res, len, 0); res = strnlen(buffer, res); } } /* Make sure result is printable. */ sanitized = printable(buffer); kfree(buffer); buffer = sanitized; out_mm: mmput(mm); out: return buffer; }
void display(uint32 offset, uint8 *data) { printf("%08lx ", offset); printf(" %s ", hexbytes(data)); printf("%16s ", printable(data)); putchar('\n'); }
unint linechar (addr address) { unint i; for (i = 0; i < U8_LINE; i++, address++) { printf("%c", printable(r8(address))); } return U8_LINE; }
void PacketFilter_MassStorage::print_block_diff(__u8 *olddata, __u8 *newdata) { int i, j; for(i=0;i<BLOCK_SIZE;i+=16) { if(olddata != NULL) { for(j=0;j<16;j++) { if(olddata[i+j]!=newdata[i+j]) fprintf(stderr, fmt_colour, COL_RED, olddata[i+j]); else fprintf(stderr, "%02x", olddata[i+j]); if(j%2==1) fprintf(stderr, " "); } fprintf(stderr, "| "); } for(j=0;j<16;j++) { if((olddata==NULL) || (olddata[i+j]!=newdata[i+j])) fprintf(stderr, fmt_colour, COL_BLUE, newdata[i+j]); else fprintf(stderr, "%02x", newdata[i+j]); if(j%2==1) fprintf(stderr, " "); } if(olddata != NULL) { for(j=0;j<16;j++) { if(olddata[i+j]!=newdata[i+j]) fprintf(stderr, fmt_colour_chr, COL_RED, printable(olddata[i+j])); else fprintf(stderr, "%c", printable(olddata[i+j])); if(j%2==1) fprintf(stderr, " "); } fprintf(stderr, "| "); } for(j=0;j<16;j++) { if((olddata==NULL) || (olddata[i+j]!=newdata[i+j])) fprintf(stderr, fmt_colour_chr, COL_BLUE, printable(newdata[i+j])); else fprintf(stderr, "%c", printable(newdata[i+j])); if(j%2==1) fprintf(stderr, " "); } fprintf(stderr, "\n"); } }
void smtp_chat_notify(SMTP_SESSION *session) { const char *myname = "smtp_chat_notify"; VSTREAM *notice; char **cpp; /* * Sanity checks. */ if (session->history == 0) msg_panic("%s: no conversation history", myname); if (msg_verbose) msg_info("%s: notify postmaster", myname); /* * Construct a message for the postmaster, explaining what this is all * about. This is junk mail: don't send it when the mail posting service * is unavailable, and use the double bounce sender address, to prevent * mail bounce wars. Always prepend one space to message content that we * generate from untrusted data. */ #define NULL_TRACE_FLAGS 0 #define NO_QUEUE_ID ((VSTRING *) 0) #define LENGTH 78 #define INDENT 4 notice = post_mail_fopen_nowait(mail_addr_double_bounce(), var_error_rcpt, MAIL_SRC_MASK_NOTIFY, NULL_TRACE_FLAGS, SMTPUTF8_FLAG_NONE, NO_QUEUE_ID); if (notice == 0) { msg_warn("postmaster notify: %m"); return; } post_mail_fprintf(notice, "From: %s (Mail Delivery System)", mail_addr_mail_daemon()); post_mail_fprintf(notice, "To: %s (Postmaster)", var_error_rcpt); post_mail_fprintf(notice, "Subject: %s %s client: errors from %s", var_mail_name, smtp_mode ? "SMTP" : "LMTP", session->namaddrport); post_mail_fputs(notice, ""); post_mail_fprintf(notice, "Unexpected response from %s.", session->namaddrport); post_mail_fputs(notice, ""); post_mail_fputs(notice, "Transcript of session follows."); post_mail_fputs(notice, ""); argv_terminate(session->history); for (cpp = session->history->argv; *cpp; cpp++) line_wrap(printable(*cpp, '?'), LENGTH, INDENT, print_line, (void *) notice); post_mail_fputs(notice, ""); post_mail_fprintf(notice, "For other details, see the local mail logfile"); (void) post_mail_fclose(notice); }
main() /* ctrlstrip - Strip non-graphic characters */ { int c; while (EOF != (c = getchar())) { if (printable(c)) { putchar(c); } } return(0); }
static void rewrite_service(VSTREAM *stream, char *unused_service, char **argv) { int status = -1; #ifdef DETACH_AND_ASK_CLIENTS_TO_RECONNECT static time_t last; time_t now; const char *table; #endif /* * Sanity check. This service takes no command-line arguments. */ if (argv[0]) msg_fatal("unexpected command-line argument: %s", argv[0]); /* * Client connections are long-lived. Be sure to refesh timely. */ #ifdef DETACH_AND_ASK_CLIENTS_TO_RECONNECT if (server_flags == 0 && (now = event_time()) - last > 10) { if ((table = dict_changed_name()) != 0) { msg_info("table %s has changed -- restarting", table); if (multi_server_drain() == 0) server_flags = 1; } last = now; } #endif /* * This routine runs whenever a client connects to the UNIX-domain socket * dedicated to address rewriting. All connection-management stuff is * handled by the common code in multi_server.c. */ if (attr_scan(stream, ATTR_FLAG_STRICT | ATTR_FLAG_MORE, ATTR_TYPE_STR, MAIL_ATTR_REQ, command, ATTR_TYPE_END) == 1) { if (strcmp(vstring_str(command), REWRITE_ADDR) == 0) { status = rewrite_proto(stream); } else if (strcmp(vstring_str(command), RESOLVE_REGULAR) == 0) { status = resolve_proto(&resolve_regular, stream); } else if (strcmp(vstring_str(command), RESOLVE_VERIFY) == 0) { status = resolve_proto(&resolve_verify, stream); } else { msg_warn("bad command %.30s", printable(vstring_str(command), '?')); } } if (status < 0) multi_server_disconnect(stream); }
char * format_next_process(caddr_t handle, char *(*get_userid)()) { register struct handle *hp; register struct procsinfo *pi; register struct proc *p; char *uname; long cpu_time; int proc_size, proc_ress; char size_unit = 'K'; char ress_unit = 'K'; hp = (struct handle *)handle; if (hp->remaining == 0) { /* safe guard */ fmt[0] = '\0'; return fmt; } pi = *(hp->next_proc++); hp->remaining--; p = &p_proc[PROCMASK(pi->pi_pid)]; cpu_time = PROCTIME(pi); /* we disply sizes up to 10M in KiloBytes, beyond 10M in MegaBytes */ if ((proc_size = (pi->pi_tsize/1024+pi->pi_dvm)*4) > 10240) { proc_size /= 1024; size_unit = 'M'; } if ((proc_ress = (pi->pi_trss + pi->pi_drss)*4) > 10240) { proc_ress /= 1024; ress_unit = 'M'; } sprintf(fmt, Proc_format , pi->pi_pid, /* PID */ (*get_userid)(pi->pi_uid), /* login name */ getpriority(PRIO_PROCESS, pi->pi_pid), EXTRACT_NICE(p), /* fixed or vari */ proc_size, /* size */ size_unit, /* K or M */ proc_ress, /* resident */ ress_unit, /* K or M */ state_abbrev[p->p_stat], /* process state */ format_time(cpu_time), /* time used */ weighted_cpu(pi), /* WCPU */ 100.0 * double_pctcpu(p), /* CPU */ printable(pi->pi_comm), /* COMM */ (pi->pi_flags & SKPROC) == 0 ? "" : " (sys)" /* kernel process? */ ); return(fmt); }