X-Git-Url: https://git.exim.org/exim.git/blobdiff_plain/f4bb363fd4d29d2fae5e6abd006c6e078679c987..1b7cf216d933b395dee691f05becca4dd44b26f7:/src/src/expand.c diff --git a/src/src/expand.c b/src/src/expand.c index 1753aa307..67b3d65de 100644 --- a/src/src/expand.c +++ b/src/src/expand.c @@ -642,7 +642,7 @@ static var_entry var_table[] = { { "received_ip_address", vtype_stringptr, &interface_address }, { "received_port", vtype_int, &interface_port }, { "received_protocol", vtype_stringptr, &received_protocol }, - { "received_time", vtype_int, &received_time }, + { "received_time", vtype_int, &received_time.tv_sec }, { "recipient_data", vtype_stringptr, &recipient_data }, { "recipient_verify_failure",vtype_stringptr,&recipient_verify_failure }, { "recipients", vtype_string_func, &fn_recipients }, @@ -680,6 +680,7 @@ static var_entry var_table[] = { { "smtp_active_hostname", vtype_stringptr, &smtp_active_hostname }, { "smtp_command", vtype_stringptr, &smtp_cmd_buffer }, { "smtp_command_argument", vtype_stringptr, &smtp_cmd_argument }, + { "smtp_command_history", vtype_string_func, &smtp_cmd_hist }, { "smtp_count_at_connection_start", vtype_int, &smtp_accept_count }, { "smtp_notquit_reason", vtype_stringptr, &smtp_notquit_reason }, { "sn0", vtype_filter_int, &filter_sn[0] }, @@ -1483,9 +1484,7 @@ while (*s != 0) /* If value2 is unset, just compute one number */ if (value2 < 0) - { s = string_sprintf("%d", total % value1); - } /* Otherwise do a div/mod hash */ @@ -1832,7 +1831,7 @@ switch (vp->type) case vtype_msgbody: /* Pointer to msgbody string */ case vtype_msgbody_end: /* Ditto, the end of the msg */ ss = (uschar **)(val); - if (*ss == NULL && deliver_datafile >= 0) /* Read body when needed */ + if (!*ss && deliver_datafile >= 0) /* Read body when needed */ { uschar *body; off_t start_offset = SPOOL_DATA_START_OFFSET; @@ -1865,7 +1864,7 @@ switch (vp->type) { if (body[--len] == '\n' || body[len] == 0) body[len] = ' '; } } } - return (*ss == NULL)? US"" : *ss; + return *ss ? *ss : US""; case vtype_todbsdin: /* BSD inbox time of day */ return tod_stamp(tod_bsdin); @@ -2378,8 +2377,10 @@ switch(cond_type) case 3: return NULL; } - *resetok = FALSE; /* eval_acl() might allocate; do not reclaim */ - if (yield != NULL) switch(eval_acl(sub, nelem(sub), &user_msg)) + if (yield != NULL) + { + *resetok = FALSE; /* eval_acl() might allocate; do not reclaim */ + switch(eval_acl(sub, nelem(sub), &user_msg)) { case OK: cond = TRUE; @@ -2400,6 +2401,7 @@ switch(cond_type) expand_string_message = string_sprintf("error from acl \"%s\"", sub[0]); return NULL; } + } return s; } @@ -4706,8 +4708,7 @@ while (*s != 0) /* Open the file and read it */ - f = Ufopen(sub_arg[0], "rb"); - if (f == NULL) + if (!(f = Ufopen(sub_arg[0], "rb"))) { expand_string_message = string_open_failed(errno, "%s", sub_arg[0]); goto EXPAND_FAILED; @@ -4718,7 +4719,8 @@ while (*s != 0) continue; } - /* Handle "readsocket" to insert data from a Unix domain socket */ + /* Handle "readsocket" to insert data from a socket, either + Inet or Unix domain */ case EITEM_READSOCK: { @@ -4726,10 +4728,10 @@ while (*s != 0) int timeout = 5; int save_ptr = ptr; FILE *f; - struct sockaddr_un sockun; /* don't call this "sun" ! */ uschar *arg; uschar *sub_arg[4]; BOOL do_shutdown = TRUE; + blob reqstr; if (expand_forbid & RDO_READSOCK) { @@ -4747,6 +4749,11 @@ while (*s != 0) case 3: goto EXPAND_FAILED; } + /* Grab the request string, if any */ + + reqstr.data = sub_arg[1]; + reqstr.len = Ustrlen(sub_arg[1]); + /* Sort out timeout, if given. The second arg is a list with the first element being a time value. Any more are options of form "name=value". Currently the only option recognised is "shutdown". */ @@ -4781,12 +4788,12 @@ while (*s != 0) if (Ustrncmp(sub_arg[0], "inet:", 5) == 0) { int port; - uschar *server_name = sub_arg[0] + 5; - uschar *port_name = Ustrrchr(server_name, ':'); + uschar * server_name = sub_arg[0] + 5; + uschar * port_name = Ustrrchr(server_name, ':'); /* Sort out the port */ - if (port_name == NULL) + if (!port_name) { expand_string_message = string_sprintf("missing port for readsocket %s", sub_arg[0]); @@ -4808,7 +4815,7 @@ while (*s != 0) else { struct servent *service_info = getservbyname(CS port_name, "tcp"); - if (service_info == NULL) + if (!service_info) { expand_string_message = string_sprintf("unknown port \"%s\"", port_name); @@ -4818,17 +4825,20 @@ while (*s != 0) } fd = ip_connectedsocket(SOCK_STREAM, server_name, port, port, - timeout, NULL, &expand_string_message); + timeout, NULL, &expand_string_message, &reqstr); callout_address = NULL; if (fd < 0) goto SOCK_FAIL; + reqstr.len = 0; } /* Handle a Unix domain socket */ else { + struct sockaddr_un sockun; /* don't call this "sun" ! */ int rc; + if ((fd = socket(PF_UNIX, SOCK_STREAM, 0)) == -1) { expand_string_message = string_sprintf("failed to create socket: %s", @@ -4862,14 +4872,13 @@ while (*s != 0) /* Allow sequencing of test actions */ if (running_in_test_harness) millisleep(100); - /* Write the request string, if not empty */ + /* Write the request string, if not empty or already done */ - if (sub_arg[1][0] != 0) + if (reqstr.len) { - int len = Ustrlen(sub_arg[1]); DEBUG(D_expand) debug_printf_indent("writing \"%s\" to socket\n", - sub_arg[1]); - if (write(fd, sub_arg[1], len) != len) + reqstr.data); + if (write(fd, reqstr.data, reqstr.len) != reqstr.len) { expand_string_message = string_sprintf("request write to socket " "failed: %s", strerror(errno)); @@ -5985,7 +5994,9 @@ while (*s != 0) { uschar * dstitem; uschar * newlist = NULL; + int size = 0, len = 0; uschar * newkeylist = NULL; + int ksize = 0, klen = 0; uschar * srcfield; DEBUG(D_expand) debug_printf_indent("%s: $item = \"%s\"\n", name, srcitem); @@ -6030,33 +6041,33 @@ while (*s != 0) /* New-item sorts before this dst-item. Append new-item, then dst-item, then remainder of dst list. */ - newlist = string_append_listele(newlist, sep, srcitem); - newkeylist = string_append_listele(newkeylist, sep, srcfield); + newlist = string_append_listele(newlist, &size, &len, sep, srcitem); + newkeylist = string_append_listele(newkeylist, &ksize, &klen, sep, srcfield); srcitem = NULL; - newlist = string_append_listele(newlist, sep, dstitem); - newkeylist = string_append_listele(newkeylist, sep, dstfield); + newlist = string_append_listele(newlist, &size, &len, sep, dstitem); + newkeylist = string_append_listele(newkeylist, &ksize, &klen, sep, dstfield); while ((dstitem = string_nextinlist(&dstlist, &sep, NULL, 0))) { if (!(dstfield = string_nextinlist(&dstkeylist, &sep, NULL, 0))) goto sort_mismatch; - newlist = string_append_listele(newlist, sep, dstitem); - newkeylist = string_append_listele(newkeylist, sep, dstfield); + newlist = string_append_listele(newlist, &size, &len, sep, dstitem); + newkeylist = string_append_listele(newkeylist, &ksize, &klen, sep, dstfield); } break; } - newlist = string_append_listele(newlist, sep, dstitem); - newkeylist = string_append_listele(newkeylist, sep, dstfield); + newlist = string_append_listele(newlist, &size, &len, sep, dstitem); + newkeylist = string_append_listele(newkeylist, &ksize, &klen, sep, dstfield); } /* If we ran out of dstlist without consuming srcitem, append it */ if (srcitem) { - newlist = string_append_listele(newlist, sep, srcitem); - newkeylist = string_append_listele(newkeylist, sep, srcfield); + newlist = string_append_listele(newlist, &size, &len, sep, srcitem); + newkeylist = string_append_listele(newkeylist, &ksize, &klen, sep, srcfield); } dstlist = newlist; @@ -6460,7 +6471,7 @@ while (*s != 0) blob b; char st[3]; - if (!exim_sha_init(&h, HASH_SHA256)) + if (!exim_sha_init(&h, HASH_SHA2_256)) { expand_string_message = US"unrecognised sha256 variant"; goto EXPAND_FAILED; @@ -6654,19 +6665,19 @@ while (*s != 0) char * cp; char tok[3]; tok[0] = sep; tok[1] = ':'; tok[2] = 0; - while ((cp= strpbrk((const char *)item, tok))) + while ((cp= strpbrk(CCS item, tok))) { - yield = string_catn(yield, &size, &ptr, item, cp-(char *)item); + yield = string_catn(yield, &size, &ptr, item, cp-CS item); if (*cp++ == ':') /* colon in a non-colon-sep list item, needs doubling */ { yield = string_catn(yield, &size, &ptr, US"::", 2); - item = (uschar *)cp; + item = US cp; } else /* sep in item; should already be doubled; emit once */ { - yield = string_catn(yield, &size, &ptr, (uschar *)tok, 1); + yield = string_catn(yield, &size, &ptr, US tok, 1); if (*cp == sep) cp++; - item = (uschar *)cp; + item = US cp; } } } @@ -6786,7 +6797,13 @@ while (*s != 0) int start, end, domain; /* Not really used */ while (isspace(*sub)) sub++; - if (*sub == '>') { *outsep = *++sub; ++sub; } + if (*sub == '>') + if (*outsep = *++sub) ++sub; + else { + expand_string_message = string_sprintf("output separator " + "missing in expanding ${addresses:%s}", --sub); + goto EXPAND_FAILED; + } parse_allow_group = TRUE; for (;;)