summaryrefslogtreecommitdiffstats
path: root/src/util/util.h
diff options
context:
space:
mode:
authorJakub Hrozek <jhrozek@redhat.com>2015-08-12 12:41:44 +0200
committerJakub Hrozek <jhrozek@redhat.com>2015-08-14 23:44:09 +0200
commitd95bcfe23c574de7b6b7b44b52a0d4db5cc8529a (patch)
treea2429446ec26e8a5fa71561800b2c369360af39a /src/util/util.h
parent619e21ed9c7a71e35e53f38867b53ed974f1d36a (diff)
downloadsssd-d95bcfe23c574de7b6b7b44b52a0d4db5cc8529a.tar.gz
sssd-d95bcfe23c574de7b6b7b44b52a0d4db5cc8529a.tar.xz
sssd-d95bcfe23c574de7b6b7b44b52a0d4db5cc8529a.zip
UTIL: Provide a common interface to safely create temporary files
Reviewed-by: Pavel Březina <pbrezina@redhat.com>
Diffstat (limited to 'src/util/util.h')
-rw-r--r--src/util/util.h21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/util/util.h b/src/util/util.h
index 426fd8b86..e20501cbb 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__ */