The notification client does not send its credentials during
the handshake. However, the session daemon will still receive
them except in very rare, and hard to reproduce, cases.
It appears that the kernel will provide the credential cmsg
regardless of whether or not the client has actually sent them.
Inspecting the kernel source (af_unix.c) seems to indicate that
the credentials will be passed on sendmsg whenever one of the
sockets involved has set the SO_PASSCRED flag. It also seems to
maintain compatibility with applications that expect write() to
pass credentials by default. This explains why the explicit
passing didn't seem needed.
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
* Indicates whether or not credentials are expected
* from the client.
*/
* Indicates whether or not credentials are expected
* from the client.
*/
/*
* Indicates whether or not credentials were received
* from the client.
/*
* Indicates whether or not credentials were received
* from the client.
sizeof(struct lttng_notification_channel_message);
client->communication.inbound.msg_type =
LTTNG_NOTIFICATION_CHANNEL_MESSAGE_TYPE_UNKNOWN;
sizeof(struct lttng_notification_channel_message);
client->communication.inbound.msg_type =
LTTNG_NOTIFICATION_CHANNEL_MESSAGE_TYPE_UNKNOWN;
- client->communication.inbound.receive_creds = false;
LTTNG_SOCK_SET_UID_CRED(&client->communication.inbound.creds, -1);
LTTNG_SOCK_SET_GID_CRED(&client->communication.inbound.creds, -1);
ret = lttng_dynamic_buffer_set_size(
LTTNG_SOCK_SET_UID_CRED(&client->communication.inbound.creds, -1);
LTTNG_SOCK_SET_GID_CRED(&client->communication.inbound.creds, -1);
ret = lttng_dynamic_buffer_set_size(
CDS_INIT_LIST_HEAD(&client->condition_list);
lttng_dynamic_buffer_init(&client->communication.inbound.buffer);
lttng_dynamic_buffer_init(&client->communication.outbound.buffer);
CDS_INIT_LIST_HEAD(&client->condition_list);
lttng_dynamic_buffer_init(&client->communication.inbound.buffer);
lttng_dynamic_buffer_init(&client->communication.outbound.buffer);
+ client->communication.inbound.expect_creds = true;
ret = client_reset_inbound_state(client);
if (ret) {
ERR("[notification-thread] Failed to reset client communication's inbound state");
ret = client_reset_inbound_state(client);
if (ret) {
ERR("[notification-thread] Failed to reset client communication's inbound state");
client->communication.inbound.bytes_to_receive = msg->size;
client->communication.inbound.msg_type =
(enum lttng_notification_channel_message_type) msg->type;
client->communication.inbound.bytes_to_receive = msg->size;
client->communication.inbound.msg_type =
(enum lttng_notification_channel_message_type) msg->type;
- if (client->communication.inbound.msg_type ==
- LTTNG_NOTIFICATION_CHANNEL_MESSAGE_TYPE_HANDSHAKE) {
- client->communication.inbound.receive_creds = true;
- }
ret = lttng_dynamic_buffer_set_size(
&client->communication.inbound.buffer, msg->size);
if (ret) {
ret = lttng_dynamic_buffer_set_size(
&client->communication.inbound.buffer, msg->size);
if (ret) {
offset = client->communication.inbound.buffer.size -
client->communication.inbound.bytes_to_receive;
offset = client->communication.inbound.buffer.size -
client->communication.inbound.bytes_to_receive;
- if (client->communication.inbound.receive_creds) {
+ if (client->communication.inbound.expect_creds) {
recv_ret = lttcomm_recv_creds_unix_sock(socket,
client->communication.inbound.buffer.data + offset,
client->communication.inbound.bytes_to_receive,
&client->communication.inbound.creds);
if (recv_ret > 0) {
recv_ret = lttcomm_recv_creds_unix_sock(socket,
client->communication.inbound.buffer.data + offset,
client->communication.inbound.bytes_to_receive,
&client->communication.inbound.creds);
if (recv_ret > 0) {
- client->communication.inbound.receive_creds = false;
+ client->communication.inbound.expect_creds = false;
client->communication.inbound.creds_received = true;
}
} else {
client->communication.inbound.creds_received = true;
}
} else {
pthread_mutex_lock(&channel->lock);
pthread_mutex_lock(&channel->lock);
- ret = lttcomm_send_unix_sock(channel->socket, send_buffer,
+ ret = lttcomm_send_creds_unix_sock(channel->socket, send_buffer,
sizeof(send_buffer));
if (ret < 0) {
goto end_unlock;
sizeof(send_buffer));
if (ret < 0) {
goto end_unlock;