Revert "Fix: sessiond: erroneous user check logic in session_access_ok"
[lttng-tools.git] / src / bin / lttng-relayd / cmd-2-4.c
1 /*
2 * Copyright (C) 2013 Julien Desfossez <jdesfossez@efficios.com>
3 * Copyright (C) 2013 David Goulet <dgoulet@efficios.com>
4 * Copyright (C) 2015 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 *
6 * SPDX-License-Identifier: GPL-2.0-only
7 *
8 */
9
10 #define _LGPL_SOURCE
11 #include <assert.h>
12
13 #include <common/common.h>
14 #include <common/sessiond-comm/relayd.h>
15
16 #include <common/compat/endian.h>
17 #include <common/compat/string.h>
18 #include <lttng/constant.h>
19
20 #include "cmd-2-4.h"
21 #include "lttng-relayd.h"
22
23 int cmd_create_session_2_4(const struct lttng_buffer_view *payload,
24 char *session_name, char *hostname,
25 uint32_t *live_timer, bool *snapshot)
26 {
27 int ret;
28 struct lttcomm_relayd_create_session_2_4 session_info;
29 size_t len;
30
31 if (payload->size < sizeof(session_info)) {
32 ERR("Unexpected payload size in \"cmd_create_session_2_4\": expected >= %zu bytes, got %zu bytes",
33 sizeof(session_info), payload->size);
34 ret = -1;
35 goto error;
36 }
37 memcpy(&session_info, payload->data, sizeof(session_info));
38
39 len = lttng_strnlen(session_info.session_name, sizeof(session_info.session_name));
40 /* Ensure that NULL-terminated and fits in local filename length. */
41 if (len == sizeof(session_info.session_name) || len >= LTTNG_NAME_MAX) {
42 ret = -ENAMETOOLONG;
43 ERR("Session name too long");
44 goto error;
45 } else if (len == 0) {
46 ret = -EINVAL;
47 ERR("Session name can't be of length 0");
48 goto error;
49 }
50 strncpy(session_name, session_info.session_name, LTTNG_NAME_MAX);
51
52 len = lttng_strnlen(session_info.hostname, sizeof(session_info.hostname));
53 if (len == sizeof(session_info.hostname) || len >= LTTNG_HOST_NAME_MAX) {
54 ret = -ENAMETOOLONG;
55 ERR("Session name too long");
56 goto error;
57 }
58 strncpy(hostname, session_info.hostname, LTTNG_HOST_NAME_MAX);
59
60 *live_timer = be32toh(session_info.live_timer);
61 *snapshot = be32toh(session_info.snapshot);
62
63 ret = 0;
64
65 error:
66 return ret;
67 }
This page took 0.03014 seconds and 4 git commands to generate.