int main(int unused_argc, char **unused_argv) { VSTRING *buf = vstring_alloc(100); char *junk; unsigned long ulval; int base; char ch; unsigned long ulval2; #ifdef MISSING_STRTOUL #define strtoul strtol #endif while (vstring_get_nonl(buf, VSTREAM_IN) != VSTREAM_EOF) { ch = 0; if (sscanf(STR(buf), "%lu %d%c", &ulval, &base, &ch) != 2 || ch) { msg_warn("bad input %s", STR(buf)); } else { (void) safe_ultostr(buf, ulval, base, 5, '0'); vstream_printf("%lu = %s\n", ulval, STR(buf)); ulval2 = safe_strtoul(STR(buf), &junk, base); if (*junk || (ulval2 == ULONG_MAX && errno == ERANGE)) msg_warn("%s: %m", STR(buf)); if (ulval2 != ulval) msg_warn("%lu != %lu", ulval2, ulval); } vstream_fflush(VSTREAM_OUT); } vstring_free(buf); return (0); }
const char *make_verify_sender_addr(void) { static VSTRING *verify_sender_buf; /* the complete sender address */ static VSTRING *my_epoch_buf; /* scratch space */ char *my_at_domain; /* * The null sender is always time-independent. */ if (*var_verify_sender == 0 || strcmp(var_verify_sender, "<>") == 0) return (""); /* * Sanity check. */ if (*var_verify_sender == '@') msg_fatal("parameter %s: value \"%s\" must not start with '@'", VAR_VERIFY_SENDER, var_verify_sender); if ((my_at_domain = strchr(var_verify_sender, '@')) != 0 && my_at_domain[1] == 0) msg_fatal("parameter %s: value \"%s\" must not end with '@'", VAR_VERIFY_SENDER, var_verify_sender); /* * One-time initialization. */ if (verify_sender_buf == 0) { verify_sender_buf = vstring_alloc(10); my_epoch_buf = vstring_alloc(10); } /* * Start with the bare sender address. */ vstring_strcpy(verify_sender_buf, var_verify_sender); /* * Append the time stamp to the address localpart, encoded in some * non-decimal form for obscurity. * * XXX It would be nice to have safe_ultostr() append-only support. */ if (var_verify_sender_ttl > 0) { /* Strip the @domain portion, if applicable. */ if (my_at_domain != 0) vstring_truncate(verify_sender_buf, (ssize_t) (my_at_domain - var_verify_sender)); /* Append the time stamp to the address localpart. */ vstring_sprintf_append(verify_sender_buf, "%s", safe_ultostr(my_epoch_buf, VERIFY_SENDER_ADDR_EPOCH(), VERIFY_BASE, 0, 0)); /* Add back the @domain, if applicable. */ if (my_at_domain != 0) vstring_sprintf_append(verify_sender_buf, "%s", my_at_domain); } /* * Rewrite the address to canonical form. */ rewrite_clnt_internal(MAIL_ATTR_RWR_LOCAL, STR(verify_sender_buf), verify_sender_buf); return (STR(verify_sender_buf)); }