X-Git-Url: https://git.exim.org/exim.git/blobdiff_plain/19fdbfb4a2b6ca4a6a96ef52be848f0a23e2414f..1ed70f64c0df2c1428057c2ad5b3d43260087396:/src/src/functions.h diff --git a/src/src/functions.h b/src/src/functions.h index 4b4ff5e14..d05d87450 100644 --- a/src/src/functions.h +++ b/src/src/functions.h @@ -98,6 +98,7 @@ extern int tlsa_lookup(const host_item *, dns_answer *, BOOL); extern acl_block *acl_read(uschar *(*)(void), uschar **); extern int acl_check(int, uschar *, uschar *, uschar **, uschar **); +extern uschar *acl_current_verb(void); extern int acl_eval(int, uschar *, uschar **, uschar **); extern tree_node *acl_var_create(uschar *); @@ -131,6 +132,7 @@ extern int auth_read_input(const uschar *); extern gstring * auth_show_supported(gstring *); extern uschar *auth_xtextencode(uschar *, int); extern int auth_xtextdecode(uschar *, uschar **); +extern uschar *authenticator_current_name(void); #ifdef EXPERIMENTAL_ARC extern gstring *authres_arc(gstring *); @@ -147,7 +149,7 @@ extern gstring *authres_spf(gstring *); #endif extern uschar *b64encode(const uschar *, int); -extern uschar *b64encode_taint(const uschar *, int, BOOL); +extern uschar *b64encode_taint(const uschar *, int, const void *); extern int b64decode(const uschar *, uschar **); extern int bdat_getc(unsigned); extern uschar *bdat_getbuf(unsigned *); @@ -248,7 +250,7 @@ extern const uschar * exim_errstr(int); extern void exim_exit(int) NORETURN; extern void exim_gettime(struct timeval *); extern void exim_nullstd(void); -extern void exim_setugid(uid_t, gid_t, BOOL, uschar *); +extern void exim_setugid(uid_t, gid_t, BOOL, const uschar *); extern void exim_underbar_exit(int) NORETURN; extern void exim_wait_tick(struct timeval *, int); extern int exp_bool(address_item *addr, @@ -267,7 +269,7 @@ extern void modify_variable(uschar *, void *); extern BOOL fd_ready(int, time_t); -extern int filter_interpret(uschar *, int, address_item **, uschar **); +extern int filter_interpret(const uschar *, int, address_item **, uschar **); extern BOOL filter_personal(string_item *, BOOL); extern BOOL filter_runtest(int, uschar *, BOOL, BOOL); extern BOOL filter_system_interpret(address_item **, uschar **); @@ -378,7 +380,7 @@ extern int open_cutthrough_connection( address_item * addr ); extern uschar *parse_extract_address(const uschar *, uschar **, int *, int *, int *, BOOL); extern int parse_forward_list(const uschar *, int, address_item **, uschar **, - const uschar *, uschar *, error_block **); + const uschar *, const uschar *, error_block **); extern uschar *parse_find_address_end(const uschar *, BOOL); extern const uschar *parse_find_at(const uschar *); extern const uschar *parse_fix_phrase(const uschar *, int); @@ -405,9 +407,9 @@ extern void queue_run(uschar *, uschar *, BOOL); extern int random_number(int); extern const uschar *rc_to_string(int); -extern int rda_interpret(redirect_block *, int, uschar *, uschar *, - uschar *, uschar *, uschar *, ugid_block *, address_item **, - uschar **, error_block **, int *, uschar *); +extern int rda_interpret(redirect_block *, int, const uschar *, const uschar *, + const uschar *, const uschar *, const uschar *, const ugid_block *, address_item **, + uschar **, error_block **, int *, const uschar *); extern int rda_is_filter(const uschar *); extern BOOL readconf_depends(driver_instance *, uschar *); extern void readconf_driver_init(uschar *, driver_instance **, @@ -465,6 +467,7 @@ extern BOOL route_find_expanded_user(uschar *, uschar *, uschar *, extern void route_init(void); extern gstring * route_show_supported(gstring *); extern void route_tidyup(void); +extern uschar *router_current_name(void); extern uschar *search_args(int, uschar *, uschar *, uschar **, const uschar *); extern uschar *search_find(void *, const uschar *, uschar *, int, @@ -478,9 +481,9 @@ extern void set_process_info(const char *, ...) PRINTF_FUNCTION(1,2); extern void sha1_end(hctx *, const uschar *, int, uschar *); extern void sha1_mid(hctx *, const uschar *); extern void sha1_start(hctx *); -extern void show_string(BOOL, gstring *); -extern int sieve_interpret(uschar *, int, uschar *, uschar *, uschar *, - uschar *, address_item **, uschar **); +extern int sieve_interpret(const uschar *, int, const uschar *, + const uschar *, const uschar *, const uschar *, + address_item **, uschar **); extern void sigalrm_handler(int); extern void smtp_closedown(uschar *); extern void smtp_command_timeout_exit(void) NORETURN; @@ -590,6 +593,7 @@ extern uschar *string_nextinlist_trc(const uschar **listptr, int *separator, usc extern int strcmpic(const uschar *, const uschar *); extern int strncmpic(const uschar *, const uschar *, int); extern uschar *strstric(uschar *, uschar *, BOOL); +extern const uschar *strstric_c(const uschar *, const uschar *, BOOL); extern int test_harness_fudged_queue_time(int); extern void tcp_init(void); @@ -601,9 +605,10 @@ extern uschar *tod_stamp(int); extern BOOL transport_check_waiting(const uschar *, const uschar *, int, uschar *, oicf, void*); -extern void transport_init(void); +extern uschar *transport_current_name(void); extern void transport_do_pass_socket(const uschar *, const uschar *, const uschar *, uschar *, int); +extern void transport_init(void); extern BOOL transport_pass_socket(const uschar *, const uschar *, const uschar *, uschar *, int #ifdef EXPERIMENTAL_ESMTP_LIMITS , unsigned, unsigned, unsigned @@ -611,7 +616,7 @@ extern BOOL transport_pass_socket(const uschar *, const uschar *, const uscha ); extern uschar *transport_rcpt_address(address_item *, BOOL); extern BOOL transport_set_up_command(const uschar ***, uschar *, - BOOL, int, address_item *, uschar *, uschar **); + BOOL, int, address_item *, const uschar *, uschar **); extern void transport_update_waiting(host_item *, uschar *); extern BOOL transport_write_block(transport_ctx *, uschar *, int, BOOL); extern void transport_write_reset(int); @@ -677,6 +682,18 @@ return is_tainted_fn(p); #endif } +static inline BOOL +is_incompatible(const void * old, const void * new) +{ +#if defined(COMPILE_UTILITY) || defined(MACRO_PREDEF) || defined(EM_VERSION_C) +return FALSE; + +#else +extern BOOL is_incompatible_fn(const void *, const void *); +return is_incompatible_fn(old, new); +#endif +} + /******************************************************************************/ /* String functions */ static inline uschar * __Ustrcat(uschar * dst, const uschar * src, const char * func, int line) @@ -769,32 +786,32 @@ The result is explicitly nul-terminated. static inline uschar * string_copyn_taint_trc(const uschar * s, unsigned len, - BOOL tainted, const char * func, int line) + const void * proto_mem, const char * func, int line) { -uschar * ss = store_get_3(len + 1, tainted, func, line); +uschar * ss = store_get_3(len + 1, proto_mem, func, line); memcpy(ss, s, len); ss[len] = '\0'; return ss; } static inline uschar * -string_copy_taint_trc(const uschar * s, BOOL tainted, const char * func, int line) -{ return string_copyn_taint_trc(s, Ustrlen(s), tainted, func, line); } +string_copy_taint_trc(const uschar * s, const void * proto_mem, const char * func, int line) +{ return string_copyn_taint_trc(s, Ustrlen(s), proto_mem, func, line); } static inline uschar * string_copyn_trc(const uschar * s, unsigned len, const char * func, int line) -{ return string_copyn_taint_trc(s, len, is_tainted(s), func, line); } +{ return string_copyn_taint_trc(s, len, s, func, line); } static inline uschar * string_copy_trc(const uschar * s, const char * func, int line) -{ return string_copy_taint_trc(s, is_tainted(s), func, line); } +{ return string_copy_taint_trc(s, s, func, line); } /* String-copy functions explicitly setting the taint status */ -#define string_copyn_taint(s, len, tainted) \ - string_copyn_taint_trc((s), (len), (tainted), __FUNCTION__, __LINE__) -#define string_copy_taint(s, tainted) \ - string_copy_taint_trc((s), (tainted), __FUNCTION__, __LINE__) +#define string_copyn_taint(s, len, proto_mem) \ + string_copyn_taint_trc((s), (len), (proto_mem), __FUNCTION__, __LINE__) +#define string_copy_taint(s, proto_mem) \ + string_copy_taint_trc((s), (proto_mem), __FUNCTION__, __LINE__) /* Simple string-copy functions maintaining the taint */ @@ -816,7 +833,7 @@ Returns: copy of string in new store, with letters lowercased static inline uschar * string_copylc(const uschar * s) { -uschar * ss = store_get(Ustrlen(s) + 1, is_tainted(s)); +uschar * ss = store_get(Ustrlen(s) + 1, s); uschar * p = ss; while (*s) *p++ = tolower(*s++); *p = 0; @@ -842,8 +859,8 @@ Returns: copy of string in new store, with letters lowercased static inline uschar * string_copynlc(uschar * s, int n) { -uschar *ss = store_get(n + 1, is_tainted(s)); -uschar *p = ss; +uschar * ss = store_get(n + 1, s); +uschar * p = ss; while (n-- > 0) *p++ = tolower(*s++); *p = 0; return ss; @@ -869,7 +886,7 @@ int len = Ustrlen(s) + 1; uschar *ss; store_pool = POOL_PERM; -ss = store_get(len, force_taint || is_tainted(s)); +ss = store_get(len, force_taint ? GET_TAINTED : s); memcpy(ss, s, len); store_pool = old_pool; return ss; @@ -897,13 +914,13 @@ va_end(ap); /* Create a growable-string with some preassigned space */ -#define string_get_tainted(size, tainted) \ - string_get_tainted_trc((size), (tainted), __FUNCTION__, __LINE__) +#define string_get_tainted(size, proto_mem) \ + string_get_tainted_trc((size), (proto_mem), __FUNCTION__, __LINE__) static inline gstring * -string_get_tainted_trc(unsigned size, BOOL tainted, const char * func, unsigned line) +string_get_tainted_trc(unsigned size, const void * proto_mem, const char * func, unsigned line) { -gstring * g = store_get_3(sizeof(gstring) + size, tainted, func, line); +gstring * g = store_get_3(sizeof(gstring) + size, proto_mem, func, line); g->size = size; /*XXX would be good if we could see the actual alloc size */ g->ptr = 0; g->s = US(g + 1); @@ -916,7 +933,7 @@ return g; static inline gstring * string_get_trc(unsigned size, const char * func, unsigned line) { -return string_get_tainted_trc(size, FALSE, func, line); +return string_get_tainted_trc(size, GET_UNTAINTED, func, line); } /* NUL-terminate the C string in the growable-string, and return it. */ @@ -969,12 +986,13 @@ return g; } -/* Copy the content of a string to tainted memory */ +/* Copy the content of a string to tainted memory. The proto_mem arg +will always be tainted, and suitable as a prototype. */ static inline void -gstring_rebuffer(gstring * g) +gstring_rebuffer(gstring * g, const void * proto_mem) { -uschar * s = store_get(g->size, TRUE); +uschar * s = store_get_3(g->size, proto_mem, __FUNCTION__, __LINE__); memcpy(s, g->s, g->ptr); g->s = s; } @@ -1051,7 +1069,7 @@ spool_fname(const uschar * purpose, const uschar * subdir, const uschar * fname, #ifdef COMPILE_UTILITY /* version avoiding string-extension */ int len = Ustrlen(spool_directory) + 1 + Ustrlen(queue_name) + 1 + Ustrlen(purpose) + 1 + Ustrlen(subdir) + 1 + Ustrlen(fname) + Ustrlen(suffix) + 1; -uschar * buf = store_get(len, FALSE); +uschar * buf = store_get(len, GET_UNTAINTED); string_format(buf, len, "%s/%s/%s/%s/%s%s", spool_directory, queue_name, purpose, subdir, fname, suffix); return buf; @@ -1134,50 +1152,20 @@ if (f.running_in_test_harness && f.testsuite_delays) millisleep(millisec); /******************************************************************************/ /* Taint-checked file opens */ -static inline uschar * -is_tainted2(const void *p, int lflags, const char* fmt, ...) -{ -va_list ap; -uschar *msg; -rmark mark; - -if (!is_tainted(p)) - return NULL; - -mark = store_mark(); -va_start(ap, fmt); -msg = string_from_gstring(string_vformat(NULL, SVFMT_TAINT_NOCHK|SVFMT_EXTEND, fmt, ap)); -va_end(ap); - -#ifdef ALLOW_INSECURE_TAINTED_DATA -if (allow_insecure_tainted_data) - { - if LOGGING(tainted) log_write(0, LOG_MAIN, "Warning: %s", msg); - store_reset(mark); - return NULL; - } -#endif - -if (lflags) log_write(0, lflags, "%s", msg); -return msg; /* no store_reset(), as the message might be used afterwards and Exim - is expected to exit anyway, so we do not care about the leaked - storage */ -} static inline int exim_open2(const char *pathname, int flags) { -if (!is_tainted2(pathname, LOG_MAIN|LOG_PANIC, "Tainted filename '%s'", pathname)) - return open(pathname, flags); +if (!is_tainted(pathname)) return open(pathname, flags); +log_write(0, LOG_MAIN|LOG_PANIC, "Tainted filename '%s'", pathname); errno = EACCES; return -1; } - static inline int exim_open(const char *pathname, int flags, mode_t mode) { -if (!is_tainted2(pathname, LOG_MAIN|LOG_PANIC, "Tainted filename '%s'", pathname)) - return open(pathname, flags, mode); +if (!is_tainted(pathname)) return open(pathname, flags, mode); +log_write(0, LOG_MAIN|LOG_PANIC, "Tainted filename '%s'", pathname); errno = EACCES; return -1; } @@ -1185,16 +1173,16 @@ return -1; static inline int exim_openat(int dirfd, const char *pathname, int flags) { -if (!is_tainted2(pathname, LOG_MAIN|LOG_PANIC, "Tainted filename '%s'", pathname)) - return openat(dirfd, pathname, flags); +if (!is_tainted(pathname)) return openat(dirfd, pathname, flags); +log_write(0, LOG_MAIN|LOG_PANIC, "Tainted filename '%s'", pathname); errno = EACCES; return -1; } static inline int exim_openat4(int dirfd, const char *pathname, int flags, mode_t mode) { -if (!is_tainted2(pathname, LOG_MAIN|LOG_PANIC, "Tainted filename '%s'", pathname)) - return openat(dirfd, pathname, flags, mode); +if (!is_tainted(pathname)) return openat(dirfd, pathname, flags, mode); +log_write(0, LOG_MAIN|LOG_PANIC, "Tainted filename '%s'", pathname); errno = EACCES; return -1; } @@ -1203,8 +1191,8 @@ return -1; static inline FILE * exim_fopen(const char *pathname, const char *mode) { -if (!is_tainted2(pathname, LOG_MAIN|LOG_PANIC, "Tainted filename '%s'", pathname)) - return fopen(pathname, mode); +if (!is_tainted(pathname)) return fopen(pathname, mode); +log_write(0, LOG_MAIN|LOG_PANIC, "Tainted filename '%s'", pathname); errno = EACCES; return NULL; } @@ -1212,8 +1200,8 @@ return NULL; static inline DIR * exim_opendir(const uschar * name) { -if (!is_tainted2(name, LOG_MAIN|LOG_PANIC, "Tainted dirname '%s'", name)) - return opendir(CCS name); +if (!is_tainted(name)) return opendir(CCS name); +log_write(0, LOG_MAIN|LOG_PANIC, "Tainted dirname '%s'", name); errno = EACCES; return NULL; }