build_lib_consumer=no
build_lib_hashtable=no
build_lib_health=no
+build_lib_runas=no
build_lib_unix=no
build_lib_index=no
build_lib_kernel_consumer=no
build_lib_relayd=yes
build_lib_testpoint=yes
build_lib_health=yes
+ build_lib_runas=yes
build_lib_unix=yes
]
)
AM_CONDITIONAL([BUILD_LIB_CONSUMER], [test x$build_lib_consumer = xyes])
AM_CONDITIONAL([BUILD_LIB_HASHTABLE], [test x$build_lib_hashtable = xyes])
AM_CONDITIONAL([BUILD_LIB_HEALTH], [test x$build_lib_health = xyes])
+AM_CONDITIONAL([BUILD_LIB_RUNAS], [test x$build_lib_runas = xyes])
AM_CONDITIONAL([BUILD_LIB_UNIX], [test x$build_lib_unix = xyes])
AM_CONDITIONAL([BUILD_LIB_INDEX], [test x$build_lib_index = xyes])
AM_CONDITIONAL([BUILD_LIB_KERNEL_CONSUMER], [test x$build_lib_kernel_consumer = xyes])
noinst_LTLIBRARIES = libcommon.la
EXTRA_DIST = mi-lttng-3.0.xsd
-libcommon_la_SOURCES = error.h error.c utils.c utils.h runas.h runas.c \
+libcommon_la_SOURCES = error.h error.c utils.c utils.h runas.h \
common.h futex.c futex.h uri.c uri.h defaults.c \
pipe.c pipe.h readwrite.c readwrite.h \
mi-lttng.h mi-lttng.c \
$(top_builddir)/src/common/config/libconfig.la \
$(UUID_LIBS)
+if BUILD_LIB_RUNAS
+libcommon_la_SOURCES += runas.c lttng-elf.h lttng-elf.c
+else
+libcommon_la_SOURCES += runas-stub.c
+endif
+
if BUILD_LIB_UNIX
libcommon_la_SOURCES += unix.c
else
--- /dev/null
+#ifndef _RUNAS_STUB_H
+#define _RUNAS_STUB_H
+
+/*
+ * Copyright (C) 2018 - Francis Deslauriers <francis.deslauriers@efficios.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <sys/types.h>
+#include <stdint.h>
+
+int run_as_mkdir_recursive(const char *path, mode_t mode, uid_t uid, gid_t gid)
+{
+ return -1;
+}
+int run_as_mkdir(const char *path, mode_t mode, uid_t uid, gid_t gid)
+{
+ return -1;
+}
+int run_as_open(const char *path, int flags, mode_t mode, uid_t uid, gid_t gid)
+{
+ return -1;
+}
+int run_as_unlink(const char *path, uid_t uid, gid_t gid)
+{
+ return -1;
+}
+int run_as_rmdir_recursive(const char *path, uid_t uid, gid_t gid)
+{
+ return -1;
+}
+int lttng_elf_get_symbol_offset(int fd, char *symbol, uint64_t *offset)
+{
+ return -1;
+}
+int run_as_create_worker(char *procname)
+{
+ return -1;
+}
+void run_as_destroy_worker(void)
+{
+ return;
+}
+
+#endif /* _RUNAS_STUB_H */
#include <common/compat/prctl.h>
#include <common/unix.h>
#include <common/defaults.h>
+#include <common/lttng-elf.h>
+
+#include <lttng/constant.h>
#include "runas.h"
char path[PATH_MAX];
};
+struct run_as_extract_elf_symbol_offset_data {
+ char function[LTTNG_SYMBOL_NAME_LEN];
+};
+
struct run_as_mkdir_ret {
int ret;
};
int ret;
};
+struct run_as_extract_elf_symbol_offset_ret {
+ uint64_t offset;
+};
+
enum run_as_cmd {
RUN_AS_MKDIR,
RUN_AS_OPEN,
RUN_AS_UNLINK,
RUN_AS_RMDIR_RECURSIVE,
RUN_AS_MKDIR_RECURSIVE,
+ RUN_AS_EXTRACT_ELF_SYMBOL_OFFSET,
};
struct run_as_data {
struct run_as_open_data open;
struct run_as_unlink_data unlink;
struct run_as_rmdir_recursive_data rmdir_recursive;
+ struct run_as_extract_elf_symbol_offset_data extract_elf_symbol_offset;
} u;
uid_t uid;
gid_t gid;
struct run_as_open_ret open;
struct run_as_unlink_ret unlink;
struct run_as_rmdir_recursive_ret rmdir_recursive;
+ struct run_as_extract_elf_symbol_offset_ret extract_elf_symbol_offset;
} u;
int _errno;
bool _error;
return ret_value->u.rmdir_recursive.ret;
}
+static
+int _extract_elf_symbol_offset(struct run_as_data *data,
+ struct run_as_ret *ret_value)
+{
+ int ret = 0;
+ ret_value->_error = false;
+
+ ret = lttng_elf_get_symbol_offset(data->fd,
+ data->u.extract_elf_symbol_offset.function,
+ &ret_value->u.extract_elf_symbol_offset.offset);
+ if (ret) {
+ DBG("Failed to extract ELF function offset");
+ ret_value->_error = true;
+ }
+
+ return ret;
+}
+
+
static
run_as_fct run_as_enum_to_fct(enum run_as_cmd cmd)
{
return _rmdir_recursive;
case RUN_AS_MKDIR_RECURSIVE:
return _mkdir_recursive;
+ case RUN_AS_EXTRACT_ELF_SYMBOL_OFFSET:
+ return _extract_elf_symbol_offset;
default:
ERR("Unknown command %d", (int) cmd);
return NULL;
int ret = 0;
switch (cmd) {
+ case RUN_AS_EXTRACT_ELF_SYMBOL_OFFSET:
+ break;
default:
return 0;
}
int ret = 0;
switch (cmd) {
+ case RUN_AS_EXTRACT_ELF_SYMBOL_OFFSET:
+ break;
default:
return 0;
}
int ret = 0;
switch (cmd) {
+ case RUN_AS_EXTRACT_ELF_SYMBOL_OFFSET:
+ break;
default:
return 0;
}
return ret.u.rmdir_recursive.ret;
}
+LTTNG_HIDDEN
+int run_as_extract_elf_symbol_offset(int fd, const char* function,
+ uid_t uid, gid_t gid, uint64_t *offset)
+{
+ struct run_as_data data;
+ struct run_as_ret ret;
+
+ DBG3("extract_elf_symbol_offset() on fd=%d and function=%s "
+ "with for uid %d and gid %d", fd, function, (int) uid, (int) gid);
+
+ data.fd = fd;
+
+ strncpy(data.u.extract_elf_symbol_offset.function, function, LTTNG_SYMBOL_NAME_LEN - 1);
+
+ data.u.extract_elf_symbol_offset.function[LTTNG_SYMBOL_NAME_LEN - 1] = '\0';
+
+ run_as(RUN_AS_EXTRACT_ELF_SYMBOL_OFFSET, &data, &ret, uid, gid);
+
+ errno = ret._errno;
+
+ if (ret._error) {
+ return -1;
+ }
+
+ *offset = ret.u.extract_elf_symbol_offset.offset;
+ return 0;
+}
+
static
int reset_sighandler(void)
{
int run_as_unlink(const char *path, uid_t uid, gid_t gid);
LTTNG_HIDDEN
int run_as_rmdir_recursive(const char *path, uid_t uid, gid_t gid);
-
+LTTNG_HIDDEN
+int run_as_extract_elf_symbol_offset(int fd, const char* function,
+ uid_t uid, gid_t gid, uint64_t *offset);
LTTNG_HIDDEN
int run_as_create_worker(char *procname);
LTTNG_HIDDEN