aboutsummaryrefslogtreecommitdiffstats
path: root/src/libconnect
diff options
context:
space:
mode:
authorLibravatar netblue30 <netblue30@yahoo.com>2016-10-01 16:25:36 -0400
committerLibravatar netblue30 <netblue30@yahoo.com>2016-10-01 16:25:36 -0400
commit6d2eaf548d092826017d96443b54d656f05676cf (patch)
treeed9f544c1a7fe03d3d9b2e9caf01c694f4a5e074 /src/libconnect
parentdisable x11 abstract socket for --x11=block (diff)
downloadfirejail-6d2eaf548d092826017d96443b54d656f05676cf.tar.gz
firejail-6d2eaf548d092826017d96443b54d656f05676cf.tar.zst
firejail-6d2eaf548d092826017d96443b54d656f05676cf.zip
moved libx11 to libconnect
Diffstat (limited to 'src/libconnect')
-rw-r--r--src/libconnect/Makefile.in25
-rw-r--r--src/libconnect/libconnect.c66
2 files changed, 91 insertions, 0 deletions
diff --git a/src/libconnect/Makefile.in b/src/libconnect/Makefile.in
new file mode 100644
index 000000000..5b7a8d0f1
--- /dev/null
+++ b/src/libconnect/Makefile.in
@@ -0,0 +1,25 @@
1PREFIX=@prefix@
2VERSION=@PACKAGE_VERSION@
3NAME=@PACKAGE_NAME@
4HAVE_FATAL_WARNINGS=@HAVE_FATAL_WARNINGS@
5
6H_FILE_LIST = $(sort $(wildcard *.[h]))
7C_FILE_LIST = $(sort $(wildcard *.c))
8OBJS = $(C_FILE_LIST:.c=.o)
9BINOBJS = $(foreach file, $(OBJS), $file)
10CFLAGS += -ggdb $(HAVE_FATAL_WARNINGS) -O2 -DVERSION='"$(VERSION)"' -fstack-protector-all -D_FORTIFY_SOURCE=2 -fPIC -Wformat -Wformat-security
11LDFLAGS += -pie -Wl,-z,relro -Wl,-z,now
12
13all: libconnect.so
14
15%.o : %.c $(H_FILE_LIST)
16 $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@
17
18libconnect.so: $(OBJS)
19 $(CC) $(LDFLAGS) -shared -fPIC -z relro -o $@ $(OBJS) -ldl
20
21
22clean:; rm -f $(OBJS) libconnect.so
23
24distclean: clean
25 rm -fr Makefile
diff --git a/src/libconnect/libconnect.c b/src/libconnect/libconnect.c
new file mode 100644
index 000000000..18c4d81f5
--- /dev/null
+++ b/src/libconnect/libconnect.c
@@ -0,0 +1,66 @@
1/*
2 * Copyright (C) 2014-2016 Firejail Authors
3 *
4 * This file is part of firejail project
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19*/
20#define _GNU_SOURCE
21#include <stdio.h>
22#include <stdlib.h>
23#include <string.h>
24#include <dlfcn.h>
25#include <sys/types.h>
26#include <unistd.h>
27#include <sys/socket.h>
28#include <netinet/in.h>
29#include <arpa/inet.h>
30#include <sys/un.h>
31#include <sys/stat.h>
32#include <dirent.h>
33#include <errno.h>
34
35//#define DEBUG
36
37//static int check_sockaddr(int sockfd, const char *call, const struct sockaddr *addr, int rv) {
38static int check_sockaddr(const struct sockaddr *addr) {
39 if (addr->sa_family == AF_UNIX) {
40 struct sockaddr_un *a = (struct sockaddr_un *) addr;
41 if (a->sun_path[0] == '\0' && strstr(a->sun_path + 1, "X11-unix")) {
42// printf("@%s\n", a->sun_path + 1);
43 errno = ENOENT;
44 return -1;
45 }
46 }
47
48 return 0;
49}
50
51//
52// syscalls
53//
54
55// connect
56typedef int (*orig_connect_t)(int sockfd, const struct sockaddr *addr, socklen_t addrlen);
57static orig_connect_t orig_connect = NULL;
58int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen) {
59 if (!orig_connect)
60 orig_connect = (orig_connect_t)dlsym(RTLD_NEXT, "connect");
61
62 if (check_sockaddr(addr) == -1)
63 return -1;
64
65 return orig_connect(sockfd, addr, addrlen);
66}