Blame SOURCES/bz2144530-fence_virtd-warn-files-not-mode-600.patch

84ce09
diff --color -uNr a/config/Makefile.am b/config/Makefile.am
84ce09
--- a/config/Makefile.am	2019-11-20 14:13:42.000000000 +0100
84ce09
+++ b/config/Makefile.am	2022-11-22 10:12:51.764545658 +0100
84ce09
@@ -37,5 +37,8 @@
84ce09
 config.c: y.tab.c config.l
84ce09
 	$(LEX) -oconfig.c $(srcdir)/config.l
84ce09
 
84ce09
+install-exec-hook:
84ce09
+	chmod 600 $(DESTDIR)$(sysconfdir)/fence_virt.conf
84ce09
+
84ce09
 clean-local:
84ce09
 	rm -f config.tab.c config.tab.h config.c y.tab.c y.tab.h
84ce09
diff --color -uNr a/include/simpleconfig.h b/include/simpleconfig.h
84ce09
--- a/include/simpleconfig.h	2018-01-15 15:02:31.000000000 +0100
84ce09
+++ b/include/simpleconfig.h	2022-11-22 10:15:06.440335062 +0100
84ce09
@@ -49,4 +49,8 @@
84ce09
 /* Frees a previously-allocated copy of our simple config object */
84ce09
 void sc_release(config_object_t *c);
84ce09
 
84ce09
+int check_file_permissions(const char *fname);
84ce09
+
84ce09
+int do_configure(config_object_t *config, const char *filename);
84ce09
+
84ce09
 #endif
84ce09
diff --color -uNr a/include/simpleconfig.h.rej b/include/simpleconfig.h.rej
84ce09
--- a/include/simpleconfig.h.rej	1970-01-01 01:00:00.000000000 +0100
84ce09
+++ b/include/simpleconfig.h.rej	2022-11-22 10:12:51.764545658 +0100
84ce09
@@ -0,0 +1,11 @@
84ce09
+--- include/simpleconfig.h
84ce09
++++ include/simpleconfig.h
84ce09
+@@ -49,6 +49,8 @@ config_object_t *sc_init(void);
84ce09
+ /* Frees a previously-allocated copy of our simple config object */
84ce09
+ void sc_release(config_object_t *c);
84ce09
+ 
84ce09
++int check_file_permissions(const char *fname);
84ce09
++
84ce09
+ int do_configure(config_object_t *config, const char *filename);
84ce09
+ 
84ce09
+ #endif
84ce09
diff --color -uNr a/server/config.c b/server/config.c
84ce09
--- a/server/config.c	2019-11-20 14:13:42.000000000 +0100
84ce09
+++ b/server/config.c	2022-11-22 10:17:25.539150364 +0100
84ce09
@@ -11,6 +11,7 @@
84ce09
 #include <fcntl.h>
84ce09
 #include <net/if.h>
84ce09
 #include <arpa/inet.h>
84ce09
+#include <errno.h>
84ce09
 
84ce09
 #include "simpleconfig.h"
84ce09
 #include "static_map.h"
84ce09
@@ -590,6 +591,31 @@
84ce09
 
84ce09
 
84ce09
 int
84ce09
+check_file_permissions(const char *fname)
84ce09
+{
84ce09
+	struct stat st;
84ce09
+	mode_t file_perms = 0600;
84ce09
+	int ret;
84ce09
+
84ce09
+	ret = stat(fname, &st);
84ce09
+	if (ret != 0) {
84ce09
+		printf("stat failed on file '%s': %s\n",
84ce09
+			 fname, strerror(errno));
84ce09
+		return 1;
84ce09
+	}
84ce09
+
84ce09
+	if ((st.st_mode & 0777) != file_perms) {
84ce09
+		printf("WARNING: invalid permissions on file "
84ce09
+			 "'%s': has 0%o should be 0%o\n", fname,
84ce09
+			 (unsigned int)(st.st_mode & 0777),
84ce09
+			 (unsigned int)file_perms);
84ce09
+		return 1;
84ce09
+	}
84ce09
+
84ce09
+	return 0;
84ce09
+}
84ce09
+
84ce09
+int
84ce09
 do_configure(config_object_t *config, const char *config_file)
84ce09
 {
84ce09
 	FILE *fp = NULL;
84ce09
diff --color -uNr a/server/main.c b/server/main.c
84ce09
--- a/server/main.c	2019-11-27 09:19:52.000000000 +0100
84ce09
+++ b/server/main.c	2022-11-22 10:19:06.647742990 +0100
84ce09
@@ -14,11 +14,12 @@
84ce09
 /* Local includes */
84ce09
 #include "simpleconfig.h"
84ce09
 #include "static_map.h"
84ce09
+#include "xvm.h"
84ce09
 #include "server_plugin.h"
84ce09
+#include "simple_auth.h"
84ce09
 #include "debug.h"
84ce09
 
84ce09
 /* configure.c */
84ce09
-int do_configure(config_object_t *config, const char *filename);
84ce09
 int daemon_init(const char *prog, const char *pid_file, int nofork);
84ce09
 int daemon_cleanup(void);
84ce09
 
84ce09
@@ -206,6 +207,18 @@
84ce09
 		snprintf(pid_file, PATH_MAX, "/var/run/%s.pid", basename(argv[0]));
84ce09
 	}
84ce09
 
84ce09
+	check_file_permissions(config_file);
84ce09
+
84ce09
+	sprintf(val, "listeners/%s/@key_file", listener_name);
84ce09
+	if (sc_get(config, val,
84ce09
+		   val, sizeof(val)-1) == 0) {
84ce09
+		dbg_printf(1, "Got %s for key_file\n", val);
84ce09
+	} else {
84ce09
+		snprintf(val, sizeof(val), "%s", DEFAULT_KEY_FILE);
84ce09
+	}
84ce09
+
84ce09
+	check_file_permissions(val);
84ce09
+
84ce09
 	openlog(basename(argv[0]), LOG_NDELAY | LOG_PID, LOG_DAEMON);
84ce09
 
84ce09
 	daemon_init(basename(argv[0]), pid_file, foreground);