mirror of
https://github.com/clearlinux/clr-debug-info.git
synced 2026-09-06 05:41:43 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
251b7cfe3b | ||
|
|
97d255f115 | ||
|
|
1a36c33e6e | ||
|
|
b8568a3959 | ||
|
|
0cc9c4bbf1 | ||
|
|
da1a6d63ee | ||
|
|
6144b981d4 | ||
|
|
5babb4f44f | ||
|
|
aa87b16a54 | ||
|
|
91c27b1d2e | ||
|
|
e6cbc69e1b | ||
|
|
b1c8be24a2 |
@@ -0,0 +1,19 @@
|
||||
name: C/C++ CI
|
||||
|
||||
on: [push]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- name: install dependencies
|
||||
run: sudo apt-get install libsystemd-dev libcurl4-openssl-dev libfuse-dev
|
||||
- name: autogen
|
||||
run: sh autogen.sh
|
||||
- name: make
|
||||
run: make
|
||||
- name: make distcheck
|
||||
run: make distcheck
|
||||
+10
@@ -2,6 +2,9 @@
|
||||
*.o
|
||||
clr_debug_fuse
|
||||
clr_debug_daemon
|
||||
test-driver
|
||||
testing_fuse
|
||||
testing_daemon
|
||||
.deps/
|
||||
.dirstamp
|
||||
Makefile
|
||||
@@ -29,3 +32,10 @@ config.guess
|
||||
config.sub
|
||||
libtool
|
||||
ltmain.sh
|
||||
test-suite.log
|
||||
testing_fuse.log
|
||||
testing_fuse.trs
|
||||
testing_daemon.log
|
||||
testing_daemon.trs
|
||||
clr_debug_daemon.socket
|
||||
debuginfo.conf
|
||||
@@ -45,3 +45,12 @@ clr_debug_daemon_LDADD = ${curl_LIBS} libnica.la ${LIBSYSTEMD_LIBS}
|
||||
systemdsystemunit_DATA = clr_debug_fuse.service clr_debug_daemon.service clr_debug_daemon.socket
|
||||
|
||||
tmpfiles_DATA = debuginfo.conf
|
||||
|
||||
# Functional Testing
|
||||
noinst_PROGRAMS = testing_fuse testing_daemon
|
||||
|
||||
testing_fuse_SOURCES = tests/testing_fuse.c
|
||||
testing_fuse_CFLAGS = $(AM_CFLAGS)
|
||||
|
||||
testing_daemon_SOURCES = tests/testing_daemon.c
|
||||
testing_daemon_CFLAGS = $(AM_CFLAGS)
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
Description=Clear Linux OS debuginfo daemon
|
||||
|
||||
[Socket]
|
||||
ListenStream=/run/clr-debug-info
|
||||
ListenStream=@SOCKET_PATH@
|
||||
SocketMode=0600
|
||||
|
||||
[Install]
|
||||
+21
-3
@@ -2,21 +2,21 @@
|
||||
# Process this file with autoconf to produce a configure script.
|
||||
|
||||
AC_PREREQ([2.66])
|
||||
AC_INIT(clr-debug-info, 51, arjan@linux.intel.com)
|
||||
AC_INIT(clr-debug-info, 52, arjan@linux.intel.com)
|
||||
AM_INIT_AUTOMAKE([foreign -Wall -W subdir-objects])
|
||||
AM_SILENT_RULES([yes])
|
||||
AC_PROG_CC
|
||||
AM_PROG_AR
|
||||
AC_LANG(C)
|
||||
AC_CONFIG_HEADERS([config.h])
|
||||
AC_CONFIG_FILES([clr_debug_daemon.socket])
|
||||
AC_CONFIG_FILES([debuginfo.conf])
|
||||
PKG_CHECK_MODULES([curl], [libcurl])
|
||||
PKG_CHECK_MODULES([fuse], [fuse])
|
||||
PKG_CHECK_MODULES([SYSTEMD], [systemd])
|
||||
PKG_CHECK_MODULES([LIBSYSTEMD], [libsystemd])
|
||||
LT_INIT
|
||||
|
||||
AC_DEFINE([SOCKET_PATH], ["/run/clr-debug-info"], [path to communication socket])
|
||||
|
||||
dir=""
|
||||
AC_ARG_WITH([systemdsystemunitdir], AS_HELP_STRING([--with-systemdsystemunitdir=DIR],
|
||||
[path to systemd system service dir @<:@default=/usr/lib/systemd/system@:>@]), [dir=${withval}],
|
||||
@@ -38,6 +38,22 @@ else
|
||||
AC_MSG_WARN([C11 stdatomic support unavailable. Falling back to slow mutex])
|
||||
fi
|
||||
|
||||
SOCKET_PATH=""
|
||||
AC_ARG_WITH([socket-path], AS_HELP_STRING([--with-socket-path=SOCKET_PATH],
|
||||
[path to create unix socket @<:@default=/run/clr-debug-info@:>@]), [SOCKET_PATH=${withval}],
|
||||
[SOCKET_PATH="/run/clr-debug-info"])
|
||||
test -z "${SOCKET_PATH}" && SOCKET_PATH=/run/clr-debug-info
|
||||
AC_DEFINE_UNQUOTED([SOCKET_PATH], ["${SOCKET_PATH}"], [path to create unix socket @<:@default=/run/clr-debug-info@:>@])
|
||||
AC_SUBST(SOCKET_PATH, [${SOCKET_PATH}])
|
||||
|
||||
CACHE_DIR=""
|
||||
AC_ARG_WITH([cache-dir], AS_HELP_STRING([--with-cache-dir=CACHE_DIR],
|
||||
[path to cache downloaded content @<:@default=/var/cache/debuginfo@:>@]), [CACHE_DIR="${withval}"],
|
||||
[CACHE_DIR="/var/cache/debuginfo"])
|
||||
test -z "${CACHE_DIR}" && CACHE_DIR=/var/cache/debuginfo
|
||||
AC_DEFINE_UNQUOTED([CACHE_DIR], ["${CACHE_DIR}"], [path to cache downloaded content @<:@default=/var/cache/debuginfo@:>@])
|
||||
AC_SUBST(CACHE_DIR, [${CACHE_DIR}])
|
||||
|
||||
AC_CONFIG_FILES([Makefile])
|
||||
AC_OUTPUT
|
||||
|
||||
@@ -57,6 +73,8 @@ AC_MSG_RESULT([
|
||||
|
||||
systemd-unit-dir: ${systemdsystemunitdir}
|
||||
tmpfiles.d: ${tmpfilesdir}
|
||||
socket_dir: ${SOCKET_PATH}
|
||||
cache_dir: ${CACHE_DIR}
|
||||
|
||||
C11 stdatomic support: ${have_atomics}
|
||||
])
|
||||
|
||||
@@ -10,5 +10,5 @@
|
||||
# Clear tmp directories separately, to make them easier to override
|
||||
# Unfortunatly tmpfiles doesn't change the ownership for things if they
|
||||
# are not listed.
|
||||
d /var/cache/debuginfo/lib 755 dbginfo dbginfo 10d
|
||||
d /var/cache/debuginfo/src 755 dbginfo dbginfo 1d
|
||||
d @CACHE_DIR@/lib 755 dbginfo dbginfo 10d
|
||||
d @CACHE_DIR@/src 755 dbginfo dbginfo 1d
|
||||
@@ -0,0 +1,3 @@
|
||||
[Service]
|
||||
# Uncomment to use custom URLs, space separated
|
||||
#Environment="CLR_DEBUGINFO_URLS=https://cdn-alt.download.clearlinux.org/debuginfo/ https://cdn.download.clearlinux.org/debuginfo/"
|
||||
@@ -121,3 +121,16 @@ void try_to_get(const char *path, int pid, time_t timestamp)
|
||||
|
||||
close(sockfd);
|
||||
}
|
||||
|
||||
/*
|
||||
* Editor modelines - https://www.wireshark.org/tools/modelines.html
|
||||
*
|
||||
* Local variables:
|
||||
* c-basic-offset: 8
|
||||
* tab-width: 8
|
||||
* indent-tabs-mode: nil
|
||||
* End:
|
||||
*
|
||||
* vi: set shiftwidth=8 tabstop=8 expandtab:
|
||||
* :indentSize=8:tabSize=8:noTabs=true:
|
||||
*/
|
||||
|
||||
+16
-3
@@ -636,8 +636,8 @@ int main(__nc_unused__ int argc, __nc_unused__ char *argv[])
|
||||
{
|
||||
char *fake_argv[20];
|
||||
char *dir = "/usr/src/debug";
|
||||
char *shadowdir = "/var/cache/debuginfo/src";
|
||||
const char *required_paths[] = { "/var/cache/debuginfo/lib", "/var/cache/debuginfo/src" };
|
||||
char *shadowdir = CACHE_DIR "/src";
|
||||
const char *required_paths[] = { CACHE_DIR "/lib", CACHE_DIR "/src" };
|
||||
|
||||
umask(0);
|
||||
|
||||
@@ -663,7 +663,7 @@ int main(__nc_unused__ int argc, __nc_unused__ char *argv[])
|
||||
|
||||
if (fork() == 0) {
|
||||
dir = "/usr/lib/debug";
|
||||
shadowdir = "/var/cache/debuginfo/lib";
|
||||
shadowdir = CACHE_DIR "/lib";
|
||||
prefix = "lib";
|
||||
}
|
||||
|
||||
@@ -681,3 +681,16 @@ int main(__nc_unused__ int argc, __nc_unused__ char *argv[])
|
||||
|
||||
return fuse_main(9, fake_argv, &xmp_oper, NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* Editor modelines - https://www.wireshark.org/tools/modelines.html
|
||||
*
|
||||
* Local variables:
|
||||
* c-basic-offset: 8
|
||||
* tab-width: 8
|
||||
* indent-tabs-mode: nil
|
||||
* End:
|
||||
*
|
||||
* vi: set shiftwidth=8 tabstop=8 expandtab:
|
||||
* :indentSize=8:tabSize=8:noTabs=true:
|
||||
*/
|
||||
|
||||
+93
-10
@@ -28,11 +28,11 @@
|
||||
|
||||
#include <errno.h>
|
||||
#include <grp.h>
|
||||
#include <libgen.h>
|
||||
#include <linux/capability.h>
|
||||
#include <malloc.h>
|
||||
#include <pthread.h>
|
||||
#include <pwd.h>
|
||||
#include <libgen.h>
|
||||
#include <signal.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
@@ -62,9 +62,11 @@
|
||||
|
||||
static pthread_mutex_t dupes_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
char *urls[2] = { "https://cdn.download.clearlinux.org/debuginfo/",
|
||||
"https://cdn-alt.download.clearlinux.org/debuginfo/" };
|
||||
char *urls_default[] = { "https://cdn.download.clearlinux.org/debuginfo/",
|
||||
"https://cdn-alt.download.clearlinux.org/debuginfo/" };
|
||||
int urls_size = 2;
|
||||
int urlcounter = 1;
|
||||
char **urls = urls_default;
|
||||
|
||||
static NcHashmap *hash = NULL;
|
||||
|
||||
@@ -97,6 +99,60 @@ static int avoid_dupes(const char *url)
|
||||
return retval;
|
||||
}
|
||||
|
||||
/*
|
||||
* Read URLs from environment variable, space separated
|
||||
*/
|
||||
int configure_urls(void)
|
||||
{
|
||||
const char *env_var = getenv("CLR_DEBUGINFO_URLS");
|
||||
const char *token = env_var;
|
||||
int count = 0;
|
||||
char **urls_new = NULL;
|
||||
if (env_var) {
|
||||
while (1) {
|
||||
int token_len = strcspn(token, " \t\n");
|
||||
if (token_len) {
|
||||
count++;
|
||||
urls_new = realloc(urls_new, count * sizeof(char *));
|
||||
if (!urls_new) {
|
||||
perror("realloc()");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
char *url = calloc(token_len + 1, sizeof(char));
|
||||
if (!url) {
|
||||
perror("calloc()");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
urls_new[count - 1] = strncpy(url, token, token_len);
|
||||
token += token_len;
|
||||
}
|
||||
if (*token == '\0') {
|
||||
break;
|
||||
}
|
||||
token++;
|
||||
}
|
||||
}
|
||||
if (count) {
|
||||
// Abandon defaults
|
||||
urls = urls_new;
|
||||
urls_size = count;
|
||||
urlcounter = 0;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
void free_urls(void)
|
||||
{
|
||||
if (urls != urls_default) {
|
||||
for (int i = 0; i < urls_size; i++) {
|
||||
free(urls[i]);
|
||||
}
|
||||
free(urls);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef HAVE_ATOMIC_SUPPORT
|
||||
|
||||
static atomic_int current_connection_count = 0;
|
||||
@@ -265,8 +321,10 @@ static int curl_get_file(const char *url, const char *prefix, time_t timestamp)
|
||||
}
|
||||
|
||||
/* test extraction first */
|
||||
if (asprintf(&command, "tar -C /var/cache/debuginfo/%s --no-same-owner "
|
||||
if (asprintf(&command,
|
||||
"tar -C %s/%s --no-same-owner "
|
||||
"--no-same-permissions -tf %s",
|
||||
CACHE_DIR,
|
||||
prefix,
|
||||
filename) < 0) {
|
||||
ret = 418;
|
||||
@@ -280,8 +338,10 @@ static int curl_get_file(const char *url, const char *prefix, time_t timestamp)
|
||||
}
|
||||
|
||||
free(command); /* reuse */
|
||||
if (asprintf(&command, "tar -C /var/cache/debuginfo/%s --no-same-owner "
|
||||
if (asprintf(&command,
|
||||
"tar -C %s/%s --no-same-owner "
|
||||
"--no-same-permissions -xf %s",
|
||||
CACHE_DIR,
|
||||
prefix,
|
||||
filename) < 0) {
|
||||
ret = 418;
|
||||
@@ -365,7 +425,7 @@ static void *server_thread(void *arg)
|
||||
goto thread_end;
|
||||
}
|
||||
url = NULL;
|
||||
if (asprintf(&url, "%s%s%s.tar", urls[urlcounter % 2], prefix, path) < 0) {
|
||||
if (asprintf(&url, "%s%s%s.tar", urls[urlcounter % urls_size], prefix, path) < 0) {
|
||||
goto thread_end;
|
||||
}
|
||||
|
||||
@@ -414,7 +474,16 @@ int main(__nc_unused__ int argc, __nc_unused__ char **argv)
|
||||
uid_t dbg_user = 0;
|
||||
gid_t dbg_group = 0;
|
||||
struct passwd *passwdentry;
|
||||
const char *required_paths[] = { "/var/cache/debuginfo/lib", "/var/cache/debuginfo/src" };
|
||||
const char *required_paths[] = { CACHE_DIR "/lib", CACHE_DIR "/src" };
|
||||
|
||||
if (configure_urls()) {
|
||||
fprintf(stderr, "Using urls from environment\n");
|
||||
} else {
|
||||
fprintf(stderr, "Using compiled default urls\n");
|
||||
}
|
||||
for (int i = 0; i < urls_size; i++) {
|
||||
fprintf(stderr, "url: %s\n", urls[i]);
|
||||
}
|
||||
|
||||
umask(0);
|
||||
passwdentry = getpwnam("dbginfo");
|
||||
@@ -478,8 +547,8 @@ int main(__nc_unused__ int argc, __nc_unused__ char **argv)
|
||||
strcpy(sun.sun_path, SOCKET_PATH);
|
||||
|
||||
ret = bind(sockfd,
|
||||
(struct sockaddr *)&sun,
|
||||
offsetof(struct sockaddr_un, sun_path) + strlen(SOCKET_PATH) + 1);
|
||||
(struct sockaddr *)&sun,
|
||||
offsetof(struct sockaddr_un, sun_path) + strlen(SOCKET_PATH) + 1);
|
||||
if (ret < 0) {
|
||||
fprintf(stderr, "Failed to bind:%s \n", strerror(errno));
|
||||
exit(EXIT_FAILURE);
|
||||
@@ -526,7 +595,6 @@ int main(__nc_unused__ int argc, __nc_unused__ char **argv)
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
clientsock = accept(sockfd, NULL, NULL);
|
||||
|
||||
/* Too many connections, wait for the next loop/retry */
|
||||
@@ -551,4 +619,19 @@ int main(__nc_unused__ int argc, __nc_unused__ char **argv)
|
||||
if (hash) {
|
||||
nc_hashmap_free(hash);
|
||||
}
|
||||
|
||||
free_urls();
|
||||
}
|
||||
|
||||
/*
|
||||
* Editor modelines - https://www.wireshark.org/tools/modelines.html
|
||||
*
|
||||
* Local variables:
|
||||
* c-basic-offset: 8
|
||||
* tab-width: 8
|
||||
* indent-tabs-mode: nil
|
||||
* End:
|
||||
*
|
||||
* vi: set shiftwidth=8 tabstop=8 expandtab:
|
||||
* :indentSize=8:tabSize=8:noTabs=true:
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
#define _GNU_SOURCE
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stddef.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/un.h>
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#define BUFFER_LENGTH 16
|
||||
|
||||
int get_server_socket(void)
|
||||
{
|
||||
int sockfd;
|
||||
struct sockaddr_un serveraddr;
|
||||
fputs("Creating socket\n", stderr);
|
||||
sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||
if (sockfd < 0) {
|
||||
fputs("Fail creating socket\n", stderr);
|
||||
return -1;
|
||||
}
|
||||
memset(&serveraddr, 0, sizeof(serveraddr));
|
||||
serveraddr.sun_family = AF_UNIX;
|
||||
strcpy(serveraddr.sun_path, SOCKET_PATH);
|
||||
|
||||
fputs("Connecting to server\n", stderr);
|
||||
if (connect(sockfd, (struct sockaddr*)&serveraddr,
|
||||
offsetof(struct sockaddr_un, sun_path) + strlen(SOCKET_PATH) + 1) < 0) {
|
||||
fprintf(stderr, "Fail connecting to server: %s\n", strerror(errno));
|
||||
close(sockfd);
|
||||
return -1;
|
||||
}
|
||||
return sockfd;
|
||||
}
|
||||
|
||||
|
||||
int testing_daemon(void)
|
||||
{
|
||||
int sockfd;
|
||||
char buffer[BUFFER_LENGTH];
|
||||
|
||||
if((sockfd = get_server_socket()) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
fputs("Sending message to server\n", stderr);
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
strcpy(buffer, "0:lib:/lib");
|
||||
if(send(sockfd, buffer, sizeof(buffer), 0) < 0) {
|
||||
fputs("Fail sending message to socket service\n", stderr);
|
||||
close(sockfd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
fputs("Receiving message from server\n", stderr);
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
if (recv(sockfd, &buffer[0],
|
||||
BUFFER_LENGTH, 0) < 0) {
|
||||
fputs("Failing receiving message from socket service\n", stderr);
|
||||
close(sockfd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
close(sockfd);
|
||||
return strcmp(buffer, "ok") && access(CACHE_DIR "/lib/lib", F_OK) != -1;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int res = 0;
|
||||
pid_t p;
|
||||
p = fork();
|
||||
if (p == 0) {
|
||||
if (freopen("/dev/null", "w", stderr) == NULL)
|
||||
return -1;
|
||||
char *args[] = {"./clr_debug_daemon", NULL};
|
||||
execvp("./clr_debug_daemon", args);
|
||||
} else if (p > 0) {
|
||||
sleep(1);
|
||||
res = testing_daemon();
|
||||
kill(p, SIGKILL);
|
||||
} else {
|
||||
fputs("error executing fork\n", stderr);
|
||||
}
|
||||
unlink(SOCKET_PATH);
|
||||
return res;
|
||||
}
|
||||
/*
|
||||
* Editor modelines - https://www.wireshark.org/tools/modelines.html
|
||||
*
|
||||
* Local variables:
|
||||
* c-basic-offset: 8
|
||||
* tab-width: 8
|
||||
* indent-tabs-mode: nil
|
||||
* End:
|
||||
*
|
||||
* vi: set shiftwidth=8 tabstop=8 expandtab:
|
||||
* :indentSize=8:tabSize=8:noTabs=true:
|
||||
*/
|
||||
@@ -0,0 +1,171 @@
|
||||
#define _GNU_SOURCE
|
||||
|
||||
#include <errno.h>
|
||||
#include <grp.h>
|
||||
#include <linux/capability.h>
|
||||
#include <linux/limits.h>
|
||||
#include <malloc.h>
|
||||
#include <pwd.h>
|
||||
#include <signal.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/prctl.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/un.h>
|
||||
#include <sys/wait.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#define TIMEOUT 600
|
||||
#define MAX_CONNECTIONS 16
|
||||
|
||||
int check_file_request(int fd, char *expected_str)
|
||||
{
|
||||
char buf[PATH_MAX + 8];
|
||||
int clientsock;
|
||||
malloc_trim(0);
|
||||
fputs("Accepting connection\n", stderr);
|
||||
clientsock = accept(fd, NULL, NULL);
|
||||
if (clientsock < 0)
|
||||
return -1;
|
||||
|
||||
memset(buf, 0, sizeof(buf));
|
||||
fputs("Reading socket content\n", stderr);
|
||||
if (read(clientsock, buf, PATH_MAX + 8) < 0)
|
||||
return -1;
|
||||
close(clientsock);
|
||||
return strncmp(buf, expected_str, strlen(expected_str));
|
||||
}
|
||||
|
||||
int get_service_socket(void)
|
||||
{
|
||||
int sockfd;
|
||||
struct sockaddr_un sun;
|
||||
signal(SIGPIPE, SIG_IGN);
|
||||
fputs("Creating socket\n", stderr);
|
||||
sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||
if (sockfd < 0) {
|
||||
fputs("Fail creating socket\n", stderr);
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf("Socket path %s\n", SOCKET_PATH);
|
||||
sun.sun_family = AF_UNIX;
|
||||
strcpy(sun.sun_path, SOCKET_PATH);
|
||||
|
||||
fputs("Binding socket\n", stderr);
|
||||
if (bind(sockfd, (struct sockaddr*)&sun,
|
||||
offsetof(struct sockaddr_un, sun_path) + strlen(SOCKET_PATH) + 1) < 0) {
|
||||
fprintf(stderr, "fail bind: %s\n", strerror(errno));
|
||||
close(sockfd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (listen(sockfd, 16) < 0) {
|
||||
fputs("Fail listening socket \n", stderr);
|
||||
close(sockfd);
|
||||
return -1;
|
||||
}
|
||||
return sockfd;
|
||||
}
|
||||
|
||||
|
||||
int testing_fuse(void)
|
||||
{
|
||||
int sockfd;
|
||||
uid_t gdb_user = 0;
|
||||
gid_t gdb_group = 0;
|
||||
struct passwd *passwdentry;
|
||||
pid_t p2;
|
||||
int test_result = -1;
|
||||
umask(0);
|
||||
passwdentry = getpwnam("gdbinfo");
|
||||
if (passwdentry) {
|
||||
gdb_user = passwdentry->pw_uid;
|
||||
gdb_group = passwdentry->pw_gid;
|
||||
}
|
||||
endpwent();
|
||||
|
||||
if (prctl(PR_SET_DUMPABLE, 0) != 0) {
|
||||
fputs("fail prctl\n", stderr);
|
||||
}
|
||||
|
||||
if (geteuid() == 0) {
|
||||
if (prctl(PR_CAPBSET_DROP, CAP_SYS_ADMIN) !=0) {
|
||||
fprintf(stderr, "fail geteuid: %s\n", strerror(errno));
|
||||
}
|
||||
}
|
||||
|
||||
if ((sockfd = get_service_socket()) < 0) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (setgid(gdb_group)) {
|
||||
fputs("fail setgid\n", stderr);
|
||||
}
|
||||
|
||||
if (setgroups(1, &gdb_group)) {
|
||||
fputs("fail setgroups\n", stderr);
|
||||
}
|
||||
|
||||
if (setuid(gdb_user)) {
|
||||
fputs("fail setuid\n", stderr);
|
||||
}
|
||||
|
||||
p2 = fork();
|
||||
if (p2 > 0) {
|
||||
test_result = check_file_request(sockfd, "0:lib:/tmp");
|
||||
} else if (p2 == 0) {
|
||||
if (freopen("/dev/null", "w", stderr) == NULL)
|
||||
exit(1);
|
||||
char *args[] = {"/usr/bin/cat", "/usr/lib/debug/tmp", NULL};
|
||||
execvp("/usr/bin/cat", args);
|
||||
} else {
|
||||
fputs("error executing fork\n", stderr);
|
||||
return 1;
|
||||
}
|
||||
|
||||
wait(NULL);
|
||||
close(sockfd);
|
||||
return test_result;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int res = 0;
|
||||
pid_t p;
|
||||
p = fork();
|
||||
if (p == 0) {
|
||||
if (freopen("/dev/null", "w", stderr) == NULL)
|
||||
return -1;
|
||||
char *args[] = {"./clr_debug_fuse", NULL};
|
||||
execvp("./clr_debug_fuse", args);
|
||||
} else if (p > 0) {
|
||||
sleep(1);
|
||||
res = testing_fuse();
|
||||
kill(p, SIGKILL);
|
||||
} else {
|
||||
fputs("error executing fork\n", stderr);
|
||||
return 1;
|
||||
}
|
||||
unlink(SOCKET_PATH);
|
||||
return res;
|
||||
}
|
||||
/*
|
||||
* Editor modelines - https://www.wireshark.org/tools/modelines.html
|
||||
*
|
||||
* Local variables:
|
||||
* c-basic-offset: 8
|
||||
* tab-width: 8
|
||||
* indent-tabs-mode: nil
|
||||
* End:
|
||||
*
|
||||
* vi: set shiftwidth=8 tabstop=8 expandtab:
|
||||
* :indentSize=8:tabSize=8:noTabs=true:
|
||||
*/
|
||||
Reference in New Issue
Block a user