X-Git-Url: https://git.exim.org/exim.git/blobdiff_plain/1d717e1c110562fd6bf28478c79f180cafeba776..7a66b3afa11a70021297c176acf56831692be89a:/src/src/functions.h diff --git a/src/src/functions.h b/src/src/functions.h index ea3cf257c..7677a3cd9 100644 --- a/src/src/functions.h +++ b/src/src/functions.h @@ -820,6 +820,12 @@ g->s[g->ptr] = '\0'; return g->s; } +static inline unsigned +gstring_length(const gstring * g) +{ +return g ? (unsigned)g->ptr : 0; +} + #define gstring_release_unused(g) \ gstring_release_unused_trc(g, __FUNCTION__, __LINE__) @@ -906,9 +912,18 @@ return string_sprintf("%s/%s/%s/%s/%s%s", static inline uschar * spool_fname(const uschar * purpose, const uschar * subdir, const uschar * fname, - const uschar * suffix) + const uschar * suffix) { +#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); +string_format(buf, len, "%s/%s/%s/%s/%s%s", + spool_directory, queue_name, purpose, subdir, fname, suffix); +return buf; +#else return spool_q_fname(purpose, queue_name, subdir, fname, suffix); +#endif } static inline void @@ -921,8 +936,10 @@ subdir_str[1] = '\0'; } /******************************************************************************/ +/* Time calculations */ + static inline void -timesince(struct timeval * diff, struct timeval * then) +timesince(struct timeval * diff, const struct timeval * then) { gettimeofday(diff, NULL); diff->tv_sec -= then->tv_sec; @@ -934,7 +951,7 @@ if ((diff->tv_usec -= then->tv_usec) < 0) } static inline uschar * -string_timediff(struct timeval * diff) +string_timediff(const struct timeval * diff) { static uschar buf[sizeof("0.000s")]; @@ -947,7 +964,7 @@ return buf; static inline uschar * -string_timesince(struct timeval * then) +string_timesince(const struct timeval * then) { struct timeval diff; timesince(&diff, then); @@ -955,7 +972,7 @@ return string_timediff(&diff); } static inline void -report_time_since(struct timeval * t0, uschar * where) +report_time_since(const struct timeval * t0, const uschar * where) { # ifdef MEASURE_TIMING struct timeval diff; @@ -974,6 +991,51 @@ if (f.running_in_test_harness) millisleep(millisec); #endif } +/******************************************************************************/ +/* Taint-checked file opens */ + +static inline int +exim_open2(const char *pathname, int flags) +{ +if (!is_tainted(pathname)) return open(pathname, flags); +log_write(0, LOG_MAIN|LOG_PANIC, "Tainted filename '%s'\n", pathname); +errno = EACCES; +return -1; +} +static inline int +exim_open(const char *pathname, int flags, mode_t mode) +{ +if (!is_tainted(pathname)) return open(pathname, flags, mode); +log_write(0, LOG_MAIN|LOG_PANIC, "Tainted filename '%s'\n", pathname); +errno = EACCES; +return -1; +} +static inline int +exim_openat(int dirfd, const char *pathname, int flags) +{ +if (!is_tainted(pathname)) return openat(dirfd, pathname, flags); +log_write(0, LOG_MAIN|LOG_PANIC, "Tainted filename '%s'\n", pathname); +errno = EACCES; +return -1; +} +static inline int +exim_openat4(int dirfd, const char *pathname, int flags, mode_t mode) +{ +if (!is_tainted(pathname)) return openat(dirfd, pathname, flags, mode); +log_write(0, LOG_MAIN|LOG_PANIC, "Tainted filename '%s'\n", pathname); +errno = EACCES; +return -1; +} + +static inline FILE * +exim_fopen(const char *pathname, const char *mode) +{ +if (!is_tainted(pathname)) return fopen(pathname, mode); +log_write(0, LOG_MAIN|LOG_PANIC, "Tainted filename '%s'\n", pathname); +errno = EACCES; +return NULL; +} + #endif /* !MACRO_PREDEF */ #endif /* _FUNCTIONS_H_ */