diff mbox series

[11/17] storage: Remove mode argument

Message ID 20240130212137.814082-11-denkenz@gmail.com (mailing list archive)
State Superseded
Headers show
Series [01/17] umlrunner: Also mount /var/lib as tmpfs | expand

Commit Message

Denis Kenzior Jan. 30, 2024, 9:21 p.m. UTC
oFono should be making all sub-directories in STORAGEDIR (typically
/var/lib/ofono) as owner readable/writable.  No other permissions make
sense.  Remove the mode argument from the function signature to make
this explicit.
---
 src/storage.c | 10 ++++++----
 src/storage.h |  2 +-
 2 files changed, 7 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/src/storage.c b/src/storage.c
index 1c873474a927..f169195c8df7 100644
--- a/src/storage.c
+++ b/src/storage.c
@@ -37,6 +37,8 @@ 
 
 #include "storage.h"
 
+#define STORAGE_DIR_MODE (S_IRUSR | S_IWUSR | S_IXUSR)
+
 const char *ofono_config_dir(void)
 {
 	return CONFIGDIR;
@@ -47,7 +49,7 @@  const char *ofono_storage_dir(void)
 	return STORAGEDIR;
 }
 
-int create_dirs(const char *filename, const mode_t mode)
+int create_dirs(const char *filename)
 {
 	struct stat st;
 	char *dir;
@@ -71,7 +73,7 @@  int create_dirs(const char *filename, const mode_t mode)
 
 		strncat(dir, prev + 1, next - prev);
 
-		if (mkdir(dir, mode) == -1 && errno != EEXIST) {
+		if (mkdir(dir, STORAGE_DIR_MODE) == -1 && errno != EEXIST) {
 			l_free(dir);
 			return -1;
 		}
@@ -133,7 +135,7 @@  ssize_t write_file(const unsigned char *buffer, size_t len,
 	tmp_path = l_strdup_printf("%s.XXXXXX.tmp", path);
 
 	r = -1;
-	if (create_dirs(path, mode | S_IXUSR) != 0)
+	if (create_dirs(path) != 0)
 		goto error_create_dirs;
 
 	fd = L_TFR(g_mkstemp_full(tmp_path, O_WRONLY | O_CREAT | O_TRUNC, mode));
@@ -204,7 +206,7 @@  void storage_sync(const char *imsi, const char *store, GKeyFile *keyfile)
 	if (path == NULL)
 		return;
 
-	if (create_dirs(path, S_IRUSR | S_IWUSR | S_IXUSR) != 0) {
+	if (create_dirs(path) != 0) {
 		l_free(path);
 		return;
 	}
diff --git a/src/storage.h b/src/storage.h
index 76069949e747..46efd2d1a208 100644
--- a/src/storage.h
+++ b/src/storage.h
@@ -22,7 +22,7 @@ 
 #include <fcntl.h>
 #include <sys/types.h>
 
-int create_dirs(const char *filename, const mode_t mode);
+int create_dirs(const char *filename);
 
 ssize_t read_file(unsigned char *buffer, size_t len,
 			const char *path_fmt, ...)