|
|
1e5fc9 |
diff -rup libqb-1.0.1.orig/lib/ipc_int.h libqb-1.0.1/lib/ipc_int.h
|
|
|
1e5fc9 |
--- libqb-1.0.1.orig/lib/ipc_int.h 2019-05-29 11:17:36.156450341 +0100
|
|
|
1e5fc9 |
+++ libqb-1.0.1/lib/ipc_int.h 2019-05-29 11:20:19.561840335 +0100
|
|
|
1e5fc9 |
@@ -161,7 +161,7 @@ enum qb_ipcs_connection_state {
|
|
|
1e5fc9 |
QB_IPCS_CONNECTION_SHUTTING_DOWN,
|
|
|
1e5fc9 |
};
|
|
|
1e5fc9 |
|
|
|
1e5fc9 |
-#define CONNECTION_DESCRIPTION (34) /* INT_MAX length + 3 */
|
|
|
1e5fc9 |
+#define CONNECTION_DESCRIPTION NAME_MAX
|
|
|
1e5fc9 |
|
|
|
1e5fc9 |
struct qb_ipcs_connection_auth {
|
|
|
1e5fc9 |
uid_t uid;
|
|
|
1e5fc9 |
@@ -208,4 +208,6 @@ int32_t qb_ipc_us_sock_error_is_disconne
|
|
|
1e5fc9 |
|
|
|
1e5fc9 |
int use_filesystem_sockets(void);
|
|
|
1e5fc9 |
|
|
|
1e5fc9 |
+void remove_tempdir(const char *name);
|
|
|
1e5fc9 |
+
|
|
|
1e5fc9 |
#endif /* QB_IPC_INT_H_DEFINED */
|
|
|
1e5fc9 |
Only in libqb-1.0.1/lib: ipc_int.h.orig
|
|
|
1e5fc9 |
diff -rup libqb-1.0.1.orig/lib/ipcs.c libqb-1.0.1/lib/ipcs.c
|
|
|
1e5fc9 |
--- libqb-1.0.1.orig/lib/ipcs.c 2016-11-08 10:10:23.000000000 +0000
|
|
|
1e5fc9 |
+++ libqb-1.0.1/lib/ipcs.c 2019-05-29 11:20:19.563840340 +0100
|
|
|
1e5fc9 |
@@ -642,12 +642,13 @@ qb_ipcs_disconnect(struct qb_ipcs_connec
|
|
|
1e5fc9 |
scheduled_retry = 1;
|
|
|
1e5fc9 |
}
|
|
|
1e5fc9 |
}
|
|
|
1e5fc9 |
-
|
|
|
1e5fc9 |
+ remove_tempdir(c->description);
|
|
|
1e5fc9 |
if (scheduled_retry == 0) {
|
|
|
1e5fc9 |
/* This removes the initial alloc ref */
|
|
|
1e5fc9 |
qb_ipcs_connection_unref(c);
|
|
|
1e5fc9 |
}
|
|
|
1e5fc9 |
}
|
|
|
1e5fc9 |
+
|
|
|
1e5fc9 |
}
|
|
|
1e5fc9 |
|
|
|
1e5fc9 |
static void
|
|
|
1e5fc9 |
diff -rup libqb-1.0.1.orig/lib/ipc_setup.c libqb-1.0.1/lib/ipc_setup.c
|
|
|
1e5fc9 |
--- libqb-1.0.1.orig/lib/ipc_setup.c 2019-05-29 11:17:36.156450341 +0100
|
|
|
1e5fc9 |
+++ libqb-1.0.1/lib/ipc_setup.c 2019-05-29 11:20:19.562840338 +0100
|
|
|
1e5fc9 |
@@ -621,6 +621,8 @@ handle_new_connection(struct qb_ipcs_ser
|
|
|
1e5fc9 |
int32_t res2 = 0;
|
|
|
1e5fc9 |
uint32_t max_buffer_size = QB_MAX(req->max_msg_size, s->max_buffer_size);
|
|
|
1e5fc9 |
struct qb_ipc_connection_response response;
|
|
|
1e5fc9 |
+ const char suffix[] = "/qb";
|
|
|
1e5fc9 |
+ int desc_len;
|
|
|
1e5fc9 |
|
|
|
1e5fc9 |
c = qb_ipcs_connection_alloc(s);
|
|
|
1e5fc9 |
if (c == NULL) {
|
|
|
1e5fc9 |
@@ -643,8 +645,45 @@ handle_new_connection(struct qb_ipcs_ser
|
|
|
1e5fc9 |
c->auth.gid = c->egid = ugp->gid;
|
|
|
1e5fc9 |
c->auth.mode = 0600;
|
|
|
1e5fc9 |
c->stats.client_pid = ugp->pid;
|
|
|
1e5fc9 |
- snprintf(c->description, CONNECTION_DESCRIPTION,
|
|
|
1e5fc9 |
- "%d-%d-%d", s->pid, ugp->pid, c->setup.u.us.sock);
|
|
|
1e5fc9 |
+
|
|
|
1e5fc9 |
+#if defined(QB_LINUX) || defined(QB_CYGWIN)
|
|
|
1e5fc9 |
+ desc_len = snprintf(c->description, CONNECTION_DESCRIPTION - sizeof suffix,
|
|
|
1e5fc9 |
+ "/dev/shm/qb-%d-%d-%d-XXXXXX", s->pid, ugp->pid, c->setup.u.us.sock);
|
|
|
1e5fc9 |
+ if (desc_len < 0) {
|
|
|
1e5fc9 |
+ res = -errno;
|
|
|
1e5fc9 |
+ goto send_response;
|
|
|
1e5fc9 |
+ }
|
|
|
1e5fc9 |
+ if (desc_len >= CONNECTION_DESCRIPTION - sizeof suffix) {
|
|
|
1e5fc9 |
+ res = -ENAMETOOLONG;
|
|
|
1e5fc9 |
+ goto send_response;
|
|
|
1e5fc9 |
+ }
|
|
|
1e5fc9 |
+ if (mkdtemp(c->description) == NULL) {
|
|
|
1e5fc9 |
+ res = -errno;
|
|
|
1e5fc9 |
+ goto send_response;
|
|
|
1e5fc9 |
+ }
|
|
|
1e5fc9 |
+ if (chmod(c->description, 0770)) {
|
|
|
1e5fc9 |
+ res = -errno;
|
|
|
1e5fc9 |
+ goto send_response;
|
|
|
1e5fc9 |
+ }
|
|
|
1e5fc9 |
+ /* chown can fail because we might not be root */
|
|
|
1e5fc9 |
+ (void)chown(c->description, c->auth.uid, c->auth.gid);
|
|
|
1e5fc9 |
+
|
|
|
1e5fc9 |
+ /* We can't pass just a directory spec to the clients */
|
|
|
1e5fc9 |
+ memcpy(c->description + desc_len, suffix, sizeof suffix);
|
|
|
1e5fc9 |
+#else
|
|
|
1e5fc9 |
+ desc_len = snprintf(c->description, CONNECTION_DESCRIPTION,
|
|
|
1e5fc9 |
+ "%d-%d-%d", s->pid, ugp->pid, c->setup.u.us.sock);
|
|
|
1e5fc9 |
+ if (desc_len < 0) {
|
|
|
1e5fc9 |
+ res = -errno;
|
|
|
1e5fc9 |
+ goto send_response;
|
|
|
1e5fc9 |
+ }
|
|
|
1e5fc9 |
+ if (desc_len >= CONNECTION_DESCRIPTION) {
|
|
|
1e5fc9 |
+ res = -ENAMETOOLONG;
|
|
|
1e5fc9 |
+ goto send_response;
|
|
|
1e5fc9 |
+ }
|
|
|
1e5fc9 |
+#endif
|
|
|
1e5fc9 |
+
|
|
|
1e5fc9 |
+
|
|
|
1e5fc9 |
|
|
|
1e5fc9 |
if (auth_result == 0 && c->service->serv_fns.connection_accept) {
|
|
|
1e5fc9 |
res = c->service->serv_fns.connection_accept(c,
|
|
|
1e5fc9 |
@@ -865,3 +904,21 @@ retry_accept:
|
|
|
1e5fc9 |
qb_ipcs_uc_recv_and_auth(new_fd, s);
|
|
|
1e5fc9 |
return 0;
|
|
|
1e5fc9 |
}
|
|
|
1e5fc9 |
+
|
|
|
1e5fc9 |
+void remove_tempdir(const char *name)
|
|
|
1e5fc9 |
+{
|
|
|
1e5fc9 |
+#if defined(QB_LINUX) || defined(QB_CYGWIN)
|
|
|
1e5fc9 |
+ char dirname[PATH_MAX];
|
|
|
1e5fc9 |
+ char *slash = strrchr(name, '/');
|
|
|
1e5fc9 |
+
|
|
|
1e5fc9 |
+ if (slash && slash - name < sizeof dirname) {
|
|
|
1e5fc9 |
+ memcpy(dirname, name, slash - name);
|
|
|
1e5fc9 |
+ dirname[slash - name] = '\0';
|
|
|
1e5fc9 |
+ /* This gets called more than it needs to be really, so we don't check
|
|
|
1e5fc9 |
+ * the return code. It's more of a desperate attempt to clean up after ourself
|
|
|
1e5fc9 |
+ * in either the server or client.
|
|
|
1e5fc9 |
+ */
|
|
|
1e5fc9 |
+ (void)rmdir(dirname);
|
|
|
1e5fc9 |
+ }
|
|
|
1e5fc9 |
+#endif
|
|
|
1e5fc9 |
+}
|
|
|
1e5fc9 |
Only in libqb-1.0.1/lib: ipc_setup.c.orig
|
|
|
1e5fc9 |
diff -rup libqb-1.0.1.orig/lib/ipc_shm.c libqb-1.0.1/lib/ipc_shm.c
|
|
|
1e5fc9 |
--- libqb-1.0.1.orig/lib/ipc_shm.c 2019-05-29 11:17:36.156450341 +0100
|
|
|
1e5fc9 |
+++ libqb-1.0.1/lib/ipc_shm.c 2019-05-29 11:21:38.135028190 +0100
|
|
|
1e5fc9 |
@@ -267,6 +267,7 @@ qb_ipcs_shm_disconnect(struct qb_ipcs_co
|
|
|
1e5fc9 |
}
|
|
|
1e5fc9 |
end_disconnect:
|
|
|
1e5fc9 |
sigaction(SIGBUS, &old_sa, NULL);
|
|
|
1e5fc9 |
+ remove_tempdir(c->description);
|
|
|
1e5fc9 |
}
|
|
|
1e5fc9 |
|
|
|
1e5fc9 |
static int32_t
|
|
|
1e5fc9 |
@@ -313,11 +314,11 @@ qb_ipcs_shm_connect(struct qb_ipcs_servi
|
|
|
1e5fc9 |
qb_util_log(LOG_DEBUG, "connecting to client [%d]", c->pid);
|
|
|
1e5fc9 |
|
|
|
1e5fc9 |
snprintf(r->request, NAME_MAX, "%s-request-%s",
|
|
|
1e5fc9 |
- s->name, c->description);
|
|
|
1e5fc9 |
+ c->description, s->name);
|
|
|
1e5fc9 |
snprintf(r->response, NAME_MAX, "%s-response-%s",
|
|
|
1e5fc9 |
- s->name, c->description);
|
|
|
1e5fc9 |
+ c->description, s->name);
|
|
|
1e5fc9 |
snprintf(r->event, NAME_MAX, "%s-event-%s",
|
|
|
1e5fc9 |
- s->name, c->description);
|
|
|
1e5fc9 |
+ c->description, s->name);
|
|
|
1e5fc9 |
|
|
|
1e5fc9 |
res = qb_ipcs_shm_rb_open(c, &c->request,
|
|
|
1e5fc9 |
r->request);
|
|
|
1e5fc9 |
Only in libqb-1.0.1/lib: ipc_shm.c~
|
|
|
1e5fc9 |
Only in libqb-1.0.1/lib: ipc_shm.c.orig
|
|
|
1e5fc9 |
Only in libqb-1.0.1/lib: ipc_shm.c.rej
|
|
|
1e5fc9 |
diff -rup libqb-1.0.1.orig/lib/ipc_socket.c libqb-1.0.1/lib/ipc_socket.c
|
|
|
1e5fc9 |
--- libqb-1.0.1.orig/lib/ipc_socket.c 2019-05-29 11:17:36.150450327 +0100
|
|
|
1e5fc9 |
+++ libqb-1.0.1/lib/ipc_socket.c 2019-05-29 11:20:19.563840340 +0100
|
|
|
1e5fc9 |
@@ -364,6 +364,10 @@ qb_ipcc_us_disconnect(struct qb_ipcc_con
|
|
|
1e5fc9 |
unlink(sock_name);
|
|
|
1e5fc9 |
}
|
|
|
1e5fc9 |
}
|
|
|
1e5fc9 |
+
|
|
|
1e5fc9 |
+ /* Last-ditch attempt to tidy up after ourself */
|
|
|
1e5fc9 |
+ remove_tempdir(c->request.u.us.shared_file_name);
|
|
|
1e5fc9 |
+
|
|
|
1e5fc9 |
qb_ipcc_us_sock_close(c->event.u.us.sock);
|
|
|
1e5fc9 |
qb_ipcc_us_sock_close(c->request.u.us.sock);
|
|
|
1e5fc9 |
qb_ipcc_us_sock_close(c->setup.u.us.sock);
|
|
|
1e5fc9 |
@@ -742,7 +746,10 @@ qb_ipcs_us_disconnect(struct qb_ipcs_con
|
|
|
1e5fc9 |
c->state == QB_IPCS_CONNECTION_ACTIVE) {
|
|
|
1e5fc9 |
munmap(c->request.u.us.shared_data, SHM_CONTROL_SIZE);
|
|
|
1e5fc9 |
unlink(c->request.u.us.shared_file_name);
|
|
|
1e5fc9 |
+
|
|
|
1e5fc9 |
+
|
|
|
1e5fc9 |
}
|
|
|
1e5fc9 |
+ remove_tempdir(c->description);
|
|
|
1e5fc9 |
}
|
|
|
1e5fc9 |
|
|
|
1e5fc9 |
static int32_t
|
|
|
1e5fc9 |
@@ -761,13 +768,13 @@ qb_ipcs_us_connect(struct qb_ipcs_servic
|
|
|
1e5fc9 |
c->request.u.us.sock = c->setup.u.us.sock;
|
|
|
1e5fc9 |
c->response.u.us.sock = c->setup.u.us.sock;
|
|
|
1e5fc9 |
|
|
|
1e5fc9 |
- snprintf(r->request, NAME_MAX, "qb-%s-control-%s",
|
|
|
1e5fc9 |
- s->name, c->description);
|
|
|
1e5fc9 |
- snprintf(r->response, NAME_MAX, "qb-%s-%s", s->name, c->description);
|
|
|
1e5fc9 |
+ snprintf(r->request, NAME_MAX, "%s-control-%s",
|
|
|
1e5fc9 |
+ c->description, s->name);
|
|
|
1e5fc9 |
+ snprintf(r->response, NAME_MAX, "%s-%s", c->description, s->name);
|
|
|
1e5fc9 |
|
|
|
1e5fc9 |
fd_hdr = qb_sys_mmap_file_open(path, r->request,
|
|
|
1e5fc9 |
SHM_CONTROL_SIZE,
|
|
|
1e5fc9 |
- O_CREAT | O_TRUNC | O_RDWR);
|
|
|
1e5fc9 |
+ O_CREAT | O_TRUNC | O_RDWR | O_EXCL);
|
|
|
1e5fc9 |
if (fd_hdr < 0) {
|
|
|
1e5fc9 |
res = fd_hdr;
|
|
|
1e5fc9 |
errno = -fd_hdr;
|
|
|
1e5fc9 |
Only in libqb-1.0.1/lib: ipc_socket.c.orig
|
|
|
1e5fc9 |
diff -rup libqb-1.0.1.orig/lib/ringbuffer.c libqb-1.0.1/lib/ringbuffer.c
|
|
|
1e5fc9 |
--- libqb-1.0.1.orig/lib/ringbuffer.c 2019-05-29 11:17:36.147450320 +0100
|
|
|
1e5fc9 |
+++ libqb-1.0.1/lib/ringbuffer.c 2019-05-29 11:20:19.563840340 +0100
|
|
|
1e5fc9 |
@@ -155,7 +155,7 @@ qb_rb_open_2(const char *name, size_t si
|
|
|
1e5fc9 |
sizeof(struct qb_ringbuffer_shared_s) + shared_user_data_size;
|
|
|
1e5fc9 |
|
|
|
1e5fc9 |
if (flags & QB_RB_FLAG_CREATE) {
|
|
|
1e5fc9 |
- file_flags |= O_CREAT | O_TRUNC;
|
|
|
1e5fc9 |
+ file_flags |= O_CREAT | O_TRUNC | O_EXCL;
|
|
|
1e5fc9 |
}
|
|
|
1e5fc9 |
|
|
|
1e5fc9 |
rb = calloc(1, sizeof(struct qb_ringbuffer_s));
|
|
|
1e5fc9 |
@@ -166,7 +166,7 @@ qb_rb_open_2(const char *name, size_t si
|
|
|
1e5fc9 |
/*
|
|
|
1e5fc9 |
* Create a shared_hdr memory segment for the header.
|
|
|
1e5fc9 |
*/
|
|
|
1e5fc9 |
- snprintf(filename, PATH_MAX, "qb-%s-header", name);
|
|
|
1e5fc9 |
+ snprintf(filename, PATH_MAX, "%s-header", name);
|
|
|
1e5fc9 |
fd_hdr = qb_sys_mmap_file_open(path, filename,
|
|
|
1e5fc9 |
shared_size, file_flags);
|
|
|
1e5fc9 |
if (fd_hdr < 0) {
|
|
|
1e5fc9 |
@@ -217,7 +217,7 @@ qb_rb_open_2(const char *name, size_t si
|
|
|
1e5fc9 |
* They have to be separate.
|
|
|
1e5fc9 |
*/
|
|
|
1e5fc9 |
if (flags & QB_RB_FLAG_CREATE) {
|
|
|
1e5fc9 |
- snprintf(filename, PATH_MAX, "qb-%s-data", name);
|
|
|
1e5fc9 |
+ snprintf(filename, PATH_MAX, "%s-data", name);
|
|
|
1e5fc9 |
fd_data = qb_sys_mmap_file_open(path,
|
|
|
1e5fc9 |
filename,
|
|
|
1e5fc9 |
real_size, file_flags);
|
|
|
1e5fc9 |
diff -rup libqb-1.0.1.orig/lib/unix.c libqb-1.0.1/lib/unix.c
|
|
|
1e5fc9 |
--- libqb-1.0.1.orig/lib/unix.c 2016-11-08 11:15:16.000000000 +0000
|
|
|
1e5fc9 |
+++ libqb-1.0.1/lib/unix.c 2019-05-29 11:20:19.564840342 +0100
|
|
|
1e5fc9 |
@@ -81,7 +81,9 @@ qb_sys_mmap_file_open(char *path, const
|
|
|
1e5fc9 |
(void)strlcpy(path, file, PATH_MAX);
|
|
|
1e5fc9 |
} else {
|
|
|
1e5fc9 |
#if defined(QB_LINUX) || defined(QB_CYGWIN)
|
|
|
1e5fc9 |
- snprintf(path, PATH_MAX, "/dev/shm/%s", file);
|
|
|
1e5fc9 |
+ /* This is only now called when talking to an old libqb
|
|
|
1e5fc9 |
+ where we need to add qb- to the name */
|
|
|
1e5fc9 |
+ snprintf(path, PATH_MAX, "/dev/shm/qb-%s", file);
|
|
|
1e5fc9 |
#else
|
|
|
1e5fc9 |
snprintf(path, PATH_MAX, "%s/%s", SOCKETDIR, file);
|
|
|
1e5fc9 |
is_absolute = path;
|