Since there doesn't seem to be an "official" way of controlling where the socket gets created you can go down the "sledgehammer to crack a nutshell" road by writing your own shared object that interposes on connect()
and rewrites any AF_FILE
addresses in /tmp:
#define _GNU_SOURCE
#include <sys/types.h>
#include <sys/socket.h>
#include <assert.h>
#include <linux/un.h>
#include <dlfcn.h>
#include <stdlib.h>
#include <string.h>
int connect(int sockfd, const struct sockaddr *addr,
socklen_t addrlen)
{
static int (*real_connect)(int, const struct sockaddr *, socklen_t) = NULL;
if (!real_connect)
real_connect = dlsym(RTLD_NEXT, "connect");
if (addr->sa_family == AF_FILE) {
// mutate sockaddr
assert(addrlen >= sizeof(struct sockaddr_un));
const struct sockaddr_un u = { AF_UNIX, "/foo/bar/path" };
// but only if it is in /tmp
if (!strncmp(((const struct sockaddr_un*)addr)->sun_path, "/tmp", 4)) {
return real_connect(sockfd, (const struct sockaddr*)&u, sizeof u);
}
}
return real_connect(sockfd, addr, addrlen);
}
Compile with:
gcc -Wall -Wextra test.c -ldl -shared -o interpose.so -fPIC
And then run as:
LD_PRELOAD=./interpose.so soffice -headless -invisible -nocrashreport -nodefault -nologo -nofirststartwizard -norestore -conversionmode -accept='pipe,name=marcin_OOffice;urp;StarOffice.ComponentContext'
which seems to work from reading the strace output (but I have no idea how to actually exercise the socket to prove that it really works).