Skip to content

Commit 2901f00

Browse files
committed
Make all paths relative to socket directory
This ensures that logs from test and non-test instances don't conflict with each other. The implementation works by setting the current directory to the socket directory, which also allows relative paths to be used elsewhere.
1 parent cb99ff1 commit 2901f00

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

daemon/qrexec-daemon.c

+14-14
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,12 @@ static void unlink_qrexec_socket(void)
156156
char link_to_socket_name[strlen(remote_domain_name) + sizeof(socket_address)];
157157

158158
int v = snprintf(socket_address, sizeof(socket_address),
159-
"%s/qrexec.%d", socket_dir, remote_domain_id);
160-
if (v < (int)sizeof("/qrexec.1") || v >= (int)sizeof(socket_address))
159+
"qrexec.%d", remote_domain_id);
160+
if (v < (int)sizeof("qrexec.1") - 1 || v >= (int)sizeof(socket_address))
161161
abort();
162162
v = snprintf(link_to_socket_name, sizeof(link_to_socket_name),
163-
"%s/qrexec.%s", socket_dir, remote_domain_name);
164-
if (v < (int)sizeof("/qrexec.") || v >= (int)sizeof(link_to_socket_name))
163+
"qrexec.%s", remote_domain_name);
164+
if (v < (int)sizeof("qrexec.") - 1 || v >= (int)sizeof(link_to_socket_name))
165165
abort();
166166
v = unlink(socket_address);
167167
if (v != 0 && !(v == -1 && errno == ENOENT))
@@ -185,20 +185,19 @@ static int create_qrexec_socket(int domid, const char *domname)
185185
int res;
186186

187187
if ((unsigned)snprintf(socket_address, sizeof(socket_address),
188-
"%s/qrexec.%d", socket_dir, domid) >= sizeof(socket_address))
188+
"qrexec.%d", domid) >= sizeof(socket_address))
189189
errx(1, "socket name too long");
190190
if ((unsigned)snprintf(link_to_socket_name, sizeof link_to_socket_name,
191-
"%s/qrexec.%s", socket_dir, domname) >= sizeof link_to_socket_name)
191+
"qrexec.%s", domname) >= sizeof link_to_socket_name)
192192
errx(1, "socket link name too long");
193193
res = unlink(link_to_socket_name);
194194
if (res != 0 && !(res == -1 && errno == ENOENT))
195195
err(1, "unlink(%s)", link_to_socket_name);
196-
const char *symlink_target = socket_address + strlen(socket_dir) + 1;
197196

198197
/* When running as root, make the socket accessible; perms on /var/run/qubes still apply */
199198
umask(0);
200-
if (symlink(symlink_target, link_to_socket_name)) {
201-
PERROR("symlink(%s,%s)", symlink_target, link_to_socket_name);
199+
if (symlink(socket_address, link_to_socket_name)) {
200+
PERROR("symlink(%s,%s)", socket_address, link_to_socket_name);
202201
}
203202
int fd = get_server_socket(socket_address);
204203
umask(0077);
@@ -339,9 +338,14 @@ static void init(int xid)
339338

340339
close(0);
341340

341+
if (chdir(socket_dir) < 0) {
342+
PERROR("chdir %s failed", socket_dir);
343+
exit(1);
344+
}
345+
342346
if (!opt_direct) {
343347
if ((unsigned)snprintf(qrexec_error_log_name, sizeof(qrexec_error_log_name),
344-
"/var/log/qubes/qrexec.%s.log", remote_domain_name) >=
348+
"qrexec.%s.log", remote_domain_name) >=
345349
sizeof(qrexec_error_log_name))
346350
errx(1, "remote domain name too long");
347351
umask(0007); // make the log readable by the "qubes" group
@@ -357,10 +361,6 @@ static void init(int xid)
357361
dup2(logfd, 1);
358362
dup2(logfd, 2);
359363

360-
if (chdir("/var/run/qubes") < 0) {
361-
PERROR("chdir /var/run/qubes failed");
362-
exit(1);
363-
}
364364
if (setsid() < 0) {
365365
PERROR("setsid()");
366366
exit(1);

0 commit comments

Comments
 (0)