Revert "Fix: sessiond: erroneous user check logic in session_access_ok"
[lttng-tools.git] / src / bin / lttng-relayd / cmd-2-1.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 #include <common/compat/string.h>
16 #include <lttng/constant.h>
17
18 #include "cmd-2-1.h"
19 #include "utils.h"
20
21 /*
22 * cmd_recv_stream_2_1 allocates path_name and channel_name.
23 */
24 int cmd_recv_stream_2_1(const struct lttng_buffer_view *payload,
25 char **ret_path_name, char **ret_channel_name)
26 {
27 int ret;
28 struct lttcomm_relayd_add_stream stream_info;
29 char *path_name = NULL;
30 char *channel_name = NULL;
31 size_t len;
32
33 if (payload->size < sizeof(stream_info)) {
34 ERR("Unexpected payload size in \"cmd_recv_stream_2_1\": expected >= %zu bytes, got %zu bytes",
35 sizeof(stream_info), payload->size);
36 ret = -1;
37 goto error;
38 }
39 memcpy(&stream_info, payload->data, sizeof(stream_info));
40
41 len = lttng_strnlen(stream_info.pathname, sizeof(stream_info.pathname));
42 /* Ensure that NULL-terminated and fits in local filename length. */
43 if (len == sizeof(stream_info.pathname) || len >= LTTNG_NAME_MAX) {
44 ret = -ENAMETOOLONG;
45 ERR("Path name too long");
46 goto error;
47 }
48 path_name = strdup(stream_info.pathname);
49 if (!path_name) {
50 PERROR("Path name allocation");
51 ret = -ENOMEM;
52 goto error;
53 }
54 len = lttng_strnlen(stream_info.channel_name, sizeof(stream_info.channel_name));
55 if (len == sizeof(stream_info.channel_name) || len >= DEFAULT_STREAM_NAME_LEN) {
56 ret = -ENAMETOOLONG;
57 ERR("Channel name too long");
58 goto error;
59 }
60 channel_name = strdup(stream_info.channel_name);
61 if (!channel_name) {
62 ret = -errno;
63 PERROR("Channel name allocation");
64 goto error;
65 }
66
67 *ret_path_name = path_name;
68 *ret_channel_name = channel_name;
69 return 0;
70 error:
71 free(path_name);
72 free(channel_name);
73 return ret;
74 }
This page took 0.030636 seconds and 4 git commands to generate.