2 * Copyright (C) 2018 - Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License, version 2 only, as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * You should have received a copy of the GNU General Public License along with
14 * this program; if not, write to the Free Software Foundation, Inc., 51
15 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include <common/common.h>
23 #include <common/sessiond-comm/relayd.h>
25 #include <common/compat/endian.h>
26 #include <common/compat/string.h>
27 #include <lttng/constant.h>
30 #include "lttng-relayd.h"
32 int cmd_create_session_2_11(const struct lttng_buffer_view
*payload
,
33 char *session_name
, char *hostname
,
34 uint32_t *live_timer
, bool *snapshot
)
37 struct lttcomm_relayd_create_session_2_11 header
;
38 size_t header_len
, received_names_size
;
39 struct lttng_buffer_view session_name_view
;
40 struct lttng_buffer_view hostname_view
;
42 header_len
= sizeof(header
);
44 if (payload
->size
< header_len
) {
45 ERR("Unexpected payload size in \"cmd_create_session_2_11\": expected >= %zu bytes, got %zu bytes",
46 header_len
, payload
->size
);
50 memcpy(&header
, payload
->data
, header_len
);
52 header
.session_name_len
= be32toh(header
.session_name_len
);
53 header
.hostname_len
= be32toh(header
.hostname_len
);
54 header
.live_timer
= be32toh(header
.live_timer
);
56 received_names_size
= header
.session_name_len
+ header
.hostname_len
;
57 if (payload
->size
< header_len
+ received_names_size
) {
58 ERR("Unexpected payload size in \"cmd_create_session_2_11\": expected >= %zu bytes, got %zu bytes",
59 header_len
+ received_names_size
, payload
->size
);
64 /* Validate length against defined constant. */
65 if (header
.session_name_len
> LTTNG_NAME_MAX
) {
67 ERR("Length of session name (%" PRIu32
" bytes) received in create_session command exceeds maximum length (%d bytes)", header
.session_name_len
, LTTNG_NAME_MAX
);
70 if (header
.hostname_len
> LTTNG_HOST_NAME_MAX
) {
72 ERR("Length of hostname (%" PRIu32
" bytes) received in create_session command exceeds maximum length (%d bytes)", header
.hostname_len
, LTTNG_HOST_NAME_MAX
);
76 session_name_view
= lttng_buffer_view_from_view(payload
, header_len
,
77 header
.session_name_len
);
78 hostname_view
= lttng_buffer_view_from_view(payload
,
79 header_len
+ header
.session_name_len
, header
.hostname_len
);
81 /* Validate that names are NULL terminated. */
82 if (session_name_view
.data
[session_name_view
.size
- 1] != '\0') {
83 ERR("cmd_create_session_2_11 session_name is invalid (not NULL terminated)");
88 if (hostname_view
.data
[hostname_view
.size
- 1] != '\0') {
89 ERR("cmd_create_session_2_11 hostname is invalid (not NULL terminated)");
95 * Length and null-termination check are already performed.
96 * LTTNG_NAME_MAX and LTTNG_HOST_NAME_MAX max size are expected.
98 strcpy(session_name
, session_name_view
.data
);
99 strcpy(hostname
, hostname_view
.data
);
101 *live_timer
= header
.live_timer
;
102 *snapshot
= !!header
.snapshot
;