184225
diff -rup libqb-1.0.3.orig/lib/ipc_int.h libqb-1.0.3/lib/ipc_int.h
184225
--- libqb-1.0.3.orig/lib/ipc_int.h	2017-11-17 13:31:14.000000000 +0000
184225
+++ libqb-1.0.3/lib/ipc_int.h	2019-05-30 14:51:44.758129831 +0100
184225
@@ -160,7 +160,7 @@ enum qb_ipcs_connection_state {
184225
 	QB_IPCS_CONNECTION_SHUTTING_DOWN,
184225
 };
184225
 
184225
-#define CONNECTION_DESCRIPTION (34) /* INT_MAX length + 3 */
184225
+#define CONNECTION_DESCRIPTION NAME_MAX
184225
 
184225
 struct qb_ipcs_connection_auth {
184225
 	uid_t uid;
184225
@@ -207,4 +207,6 @@ int32_t qb_ipc_us_sock_error_is_disconne
184225
 
184225
 int use_filesystem_sockets(void);
184225
 
184225
+void remove_tempdir(const char *name);
184225
+
184225
 #endif /* QB_IPC_INT_H_DEFINED */
184225
Only in libqb-1.0.3/lib: ipc_int.h.orig
184225
diff -rup libqb-1.0.3.orig/lib/ipcs.c libqb-1.0.3/lib/ipcs.c
184225
--- libqb-1.0.3.orig/lib/ipcs.c	2017-11-17 13:31:14.000000000 +0000
184225
+++ libqb-1.0.3/lib/ipcs.c	2019-05-30 14:51:44.759129833 +0100
184225
@@ -642,12 +642,13 @@ qb_ipcs_disconnect(struct qb_ipcs_connec
184225
 				scheduled_retry = 1;
184225
 			}
184225
 		}
184225
-
184225
+		remove_tempdir(c->description);
184225
 		if (scheduled_retry == 0) {
184225
 			/* This removes the initial alloc ref */
184225
 			qb_ipcs_connection_unref(c);
184225
 		}
184225
 	}
184225
+
184225
 }
184225
 
184225
 static void
184225
diff -rup libqb-1.0.3.orig/lib/ipc_setup.c libqb-1.0.3/lib/ipc_setup.c
184225
--- libqb-1.0.3.orig/lib/ipc_setup.c	2017-11-17 13:31:14.000000000 +0000
184225
+++ libqb-1.0.3/lib/ipc_setup.c	2019-05-30 14:51:44.759129833 +0100
184225
@@ -620,6 +620,8 @@ handle_new_connection(struct qb_ipcs_ser
184225
 	int32_t res2 = 0;
184225
 	uint32_t max_buffer_size = QB_MAX(req->max_msg_size, s->max_buffer_size);
184225
 	struct qb_ipc_connection_response response;
184225
+	const char suffix[] = "/qb";
184225
+	int desc_len;
184225
 
184225
 	c = qb_ipcs_connection_alloc(s);
184225
 	if (c == NULL) {
184225
@@ -642,8 +644,45 @@ handle_new_connection(struct qb_ipcs_ser
184225
 	c->auth.gid = c->egid = ugp->gid;
184225
 	c->auth.mode = 0600;
184225
 	c->stats.client_pid = ugp->pid;
184225
-	snprintf(c->description, CONNECTION_DESCRIPTION,
184225
-		 "%d-%d-%d", s->pid, ugp->pid, c->setup.u.us.sock);
184225
+
184225
+#if defined(QB_LINUX) || defined(QB_CYGWIN)
184225
+	desc_len = snprintf(c->description, CONNECTION_DESCRIPTION - sizeof suffix,
184225
+			    "/dev/shm/qb-%d-%d-%d-XXXXXX", s->pid, ugp->pid, c->setup.u.us.sock);
184225
+	if (desc_len < 0) {
184225
+		res = -errno;
184225
+		goto send_response;
184225
+	}
184225
+	if (desc_len >= CONNECTION_DESCRIPTION - sizeof suffix) {
184225
+		res = -ENAMETOOLONG;
184225
+		goto send_response;
184225
+	}
184225
+	if (mkdtemp(c->description) == NULL) {
184225
+		res = -errno;
184225
+		goto send_response;
184225
+	}
184225
+	if (chmod(c->description, 0770)) {
184225
+		res = -errno;
184225
+		goto send_response;
184225
+	}
184225
+	/* chown can fail because we might not be root */
184225
+	(void)chown(c->description, c->auth.uid, c->auth.gid);
184225
+
184225
+	/* We can't pass just a directory spec to the clients */
184225
+	memcpy(c->description + desc_len, suffix, sizeof suffix);
184225
+#else
184225
+	desc_len = snprintf(c->description, CONNECTION_DESCRIPTION,
184225
+			    "%d-%d-%d", s->pid, ugp->pid, c->setup.u.us.sock);
184225
+	if (desc_len < 0) {
184225
+		res = -errno;
184225
+		goto send_response;
184225
+	}
184225
+	if (desc_len >= CONNECTION_DESCRIPTION) {
184225
+		res = -ENAMETOOLONG;
184225
+		goto send_response;
184225
+	}
184225
+#endif
184225
+
184225
+
184225
 
184225
 	if (auth_result == 0 && c->service->serv_fns.connection_accept) {
184225
 		res = c->service->serv_fns.connection_accept(c,
184225
@@ -864,3 +903,21 @@ retry_accept:
184225
 	qb_ipcs_uc_recv_and_auth(new_fd, s);
184225
 	return 0;
184225
 }
184225
+
184225
+void remove_tempdir(const char *name)
184225
+{
184225
+#if defined(QB_LINUX) || defined(QB_CYGWIN)
184225
+	char dirname[PATH_MAX];
184225
+	char *slash = strrchr(name, '/');
184225
+
184225
+	if (slash && slash - name < sizeof dirname) {
184225
+		memcpy(dirname, name, slash - name);
184225
+		dirname[slash - name] = '\0';
184225
+		/* This gets called more than it needs to be really, so we don't check
184225
+		 * the return code. It's more of a desperate attempt to clean up after ourself
184225
+		 * in either the server or client.
184225
+		 */
184225
+		(void)rmdir(dirname);
184225
+	}
184225
+#endif
184225
+}
184225
Only in libqb-1.0.3/lib: ipc_setup.c.orig
184225
diff -rup libqb-1.0.3.orig/lib/ipc_shm.c libqb-1.0.3/lib/ipc_shm.c
184225
--- libqb-1.0.3.orig/lib/ipc_shm.c	2017-11-17 13:31:14.000000000 +0000
184225
+++ libqb-1.0.3/lib/ipc_shm.c	2019-05-30 14:58:42.582211045 +0100
184225
@@ -239,6 +239,7 @@ qb_ipcs_shm_disconnect(struct qb_ipcs_co
184225
 			qb_rb_close(qb_rb_lastref_and_ret(&c->request.u.shm.rb));
184225
 		}
184225
 	}
184225
+	remove_tempdir(c->description);
184225
 }
184225
 
184225
 static int32_t
184225
@@ -285,11 +286,11 @@ qb_ipcs_shm_connect(struct qb_ipcs_servi
184225
 	qb_util_log(LOG_DEBUG, "connecting to client [%d]", c->pid);
184225
 
184225
 	snprintf(r->request, NAME_MAX, "%s-request-%s",
184225
-		 s->name, c->description);
184225
+		 c->description, s->name);
184225
 	snprintf(r->response, NAME_MAX, "%s-response-%s",
184225
-		 s->name, c->description);
184225
+		 c->description, s->name);
184225
 	snprintf(r->event, NAME_MAX, "%s-event-%s",
184225
-		 s->name, c->description);
184225
+		 c->description, s->name);
184225
 
184225
 	res = qb_ipcs_shm_rb_open(c, &c->request,
184225
 				  r->request);
184225
Only in libqb-1.0.3/lib: ipc_shm.c~
184225
Only in libqb-1.0.3/lib: ipc_shm.c.orig
184225
Only in libqb-1.0.3/lib: ipc_shm.c.rej
184225
diff -rup libqb-1.0.3.orig/lib/ipc_socket.c libqb-1.0.3/lib/ipc_socket.c
184225
--- libqb-1.0.3.orig/lib/ipc_socket.c	2017-11-17 13:31:14.000000000 +0000
184225
+++ libqb-1.0.3/lib/ipc_socket.c	2019-05-30 14:51:44.761129838 +0100
184225
@@ -374,6 +374,10 @@ qb_ipcc_us_disconnect(struct qb_ipcc_con
184225
 			free(base_name);
184225
 		}
184225
 	}
184225
+
184225
+	/* Last-ditch attempt to tidy up after ourself */
184225
+	remove_tempdir(c->request.u.us.shared_file_name);
184225
+
184225
 	qb_ipcc_us_sock_close(c->event.u.us.sock);
184225
 	qb_ipcc_us_sock_close(c->request.u.us.sock);
184225
 	qb_ipcc_us_sock_close(c->setup.u.us.sock);
184225
@@ -765,7 +769,10 @@ qb_ipcs_us_disconnect(struct qb_ipcs_con
184225
 	    c->state == QB_IPCS_CONNECTION_ACTIVE) {
184225
 		munmap(c->request.u.us.shared_data, SHM_CONTROL_SIZE);
184225
 		unlink(c->request.u.us.shared_file_name);
184225
+
184225
+
184225
 	}
184225
+	remove_tempdir(c->description);
184225
 }
184225
 
184225
 static int32_t
184225
@@ -784,13 +791,13 @@ qb_ipcs_us_connect(struct qb_ipcs_servic
184225
 	c->request.u.us.sock = c->setup.u.us.sock;
184225
 	c->response.u.us.sock = c->setup.u.us.sock;
184225
 
184225
-	snprintf(r->request, NAME_MAX, "qb-%s-control-%s",
184225
-		 s->name, c->description);
184225
-	snprintf(r->response, NAME_MAX, "qb-%s-%s", s->name, c->description);
184225
+	snprintf(r->request, NAME_MAX, "%s-control-%s",
184225
+		 c->description, s->name);
184225
+	snprintf(r->response, NAME_MAX, "%s-%s", c->description, s->name);
184225
 
184225
 	fd_hdr = qb_sys_mmap_file_open(path, r->request,
184225
 				       SHM_CONTROL_SIZE,
184225
-				       O_CREAT | O_TRUNC | O_RDWR);
184225
+				       O_CREAT | O_TRUNC | O_RDWR | O_EXCL);
184225
 	if (fd_hdr < 0) {
184225
 		res = fd_hdr;
184225
 		errno = -fd_hdr;
184225
Only in libqb-1.0.3/lib: ipc_socket.c.orig
184225
diff -rup libqb-1.0.3.orig/lib/ringbuffer.c libqb-1.0.3/lib/ringbuffer.c
184225
--- libqb-1.0.3.orig/lib/ringbuffer.c	2017-12-21 09:02:11.000000000 +0000
184225
+++ libqb-1.0.3/lib/ringbuffer.c	2019-05-30 14:51:44.761129838 +0100
184225
@@ -155,7 +155,7 @@ qb_rb_open_2(const char *name, size_t si
184225
 	    sizeof(struct qb_ringbuffer_shared_s) + shared_user_data_size;
184225
 
184225
 	if (flags & QB_RB_FLAG_CREATE) {
184225
-		file_flags |= O_CREAT | O_TRUNC;
184225
+		file_flags |= O_CREAT | O_TRUNC | O_EXCL;
184225
 	}
184225
 
184225
 	rb = calloc(1, sizeof(struct qb_ringbuffer_s));
184225
@@ -166,7 +166,7 @@ qb_rb_open_2(const char *name, size_t si
184225
 	/*
184225
 	 * Create a shared_hdr memory segment for the header.
184225
 	 */
184225
-	snprintf(filename, PATH_MAX, "qb-%s-header", name);
184225
+	snprintf(filename, PATH_MAX, "%s-header", name);
184225
 	fd_hdr = qb_sys_mmap_file_open(path, filename,
184225
 				       shared_size, file_flags);
184225
 	if (fd_hdr < 0) {
184225
@@ -217,7 +217,7 @@ qb_rb_open_2(const char *name, size_t si
184225
 	 * They have to be separate.
184225
 	 */
184225
 	if (flags & QB_RB_FLAG_CREATE) {
184225
-		snprintf(filename, PATH_MAX, "qb-%s-data", name);
184225
+		snprintf(filename, PATH_MAX, "%s-data", name);
184225
 		fd_data = qb_sys_mmap_file_open(path,
184225
 						filename,
184225
 						real_size, file_flags);
184225
diff -rup libqb-1.0.3.orig/lib/unix.c libqb-1.0.3/lib/unix.c
184225
--- libqb-1.0.3.orig/lib/unix.c	2017-11-17 13:31:14.000000000 +0000
184225
+++ libqb-1.0.3/lib/unix.c	2019-05-30 14:51:44.761129838 +0100
184225
@@ -81,7 +81,9 @@ qb_sys_mmap_file_open(char *path, const
184225
 		(void)strlcpy(path, file, PATH_MAX);
184225
 	} else {
184225
 #if defined(QB_LINUX) || defined(QB_CYGWIN)
184225
-		snprintf(path, PATH_MAX, "/dev/shm/%s", file);
184225
+		/* This is only now called when talking to an old libqb
184225
+		   where we need to add qb- to the name */
184225
+		snprintf(path, PATH_MAX, "/dev/shm/qb-%s", file);
184225
 #else
184225
 		snprintf(path, PATH_MAX, "%s/%s", SOCKETDIR, file);
184225
 		is_absolute = path;