From d95bcfe23c574de7b6b7b44b52a0d4db5cc8529a Mon Sep 17 00:00:00 2001 From: Jakub Hrozek Date: Wed, 12 Aug 2015 12:41:44 +0200 Subject: UTIL: Provide a common interface to safely create temporary files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reviewed-by: Pavel Březina --- src/util/util.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/util/util.h') diff --git a/src/util/util.h b/src/util/util.h index 426fd8b8..e20501cb 100644 --- a/src/util/util.h +++ b/src/util/util.h @@ -659,4 +659,25 @@ int get_seuser(TALLOC_CTX *mem_ctx, const char *login_name, /* convert time from generalized form to unix time */ errno_t sss_utc_to_time_t(const char *str, const char *format, time_t *unix_time); +/* Creates a unique file using mkstemp with provided umask. The template + * must end with XXXXXX. Returns the fd, sets _err to an errno value on error. + * + * Prefer using sss_unique_file() as it uses a secure umask internally. + */ +int sss_unique_file_ex(TALLOC_CTX *mem_ctx, + char *path_tmpl, + mode_t file_umask, + errno_t *_err); +int sss_unique_file(TALLOC_CTX *owner, + char *path_tmpl, + errno_t *_err); + +/* Creates a unique filename using mkstemp with secure umask. The template + * must end with XXXXXX + * + * path_tmpl must be a talloc context. Destructor would be set on the filename + * so that it's guaranteed the file is removed. + */ +int sss_unique_filename(TALLOC_CTX *owner, char *path_tmpl); + #endif /* __SSSD_UTIL_H__ */ -- cgit