From 1434fd36db67bc476bb9d572bd9a0097528211bb Mon Sep 17 00:00:00 2001 From: Michael Jeanson Date: Tue, 13 Oct 2020 18:44:40 -0400 Subject: [PATCH] port: FreeBSD has no LOGIN_NAME_MAX, use sysconf instead MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Michael Jeanson Signed-off-by: Jérémie Galarneau Change-Id: Id058e15608ce0332500343ce389365a6fb1a40cc --- src/bin/lttng-sessiond/client.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/bin/lttng-sessiond/client.c b/src/bin/lttng-sessiond/client.c index 8a2ef85b7..d7db03fa7 100644 --- a/src/bin/lttng-sessiond/client.c +++ b/src/bin/lttng-sessiond/client.c @@ -31,6 +31,7 @@ #include #include #include +#include #include "client.h" #include "lttng-sessiond.h" @@ -1281,9 +1282,17 @@ error_add_context: .value_type; struct process_attr_value *value; enum lttng_error_code ret_code; + long login_name_max; + + login_name_max = sysconf(_SC_LOGIN_NAME_MAX); + if (login_name_max < 0) { + PERROR("Failed to get _SC_LOGIN_NAME_MAX system configuration"); + ret = LTTNG_ERR_INVALID; + goto error; + } /* Receive remaining variable length payload if applicable. */ - if (name_len > LOGIN_NAME_MAX) { + if (name_len > login_name_max) { /* * POSIX mandates user and group names that are at least * 8 characters long. Note that although shadow-utils @@ -1291,9 +1300,9 @@ error_add_context: * limit (from bits/utmp.h, UT_NAMESIZE), * LOGIN_NAME_MAX is defined to 256. */ - ERR("Rejecting process attribute tracker value %s as the provided exceeds the maximal allowed length: argument length = %zu, maximal length = %d", + ERR("Rejecting process attribute tracker value %s as the provided exceeds the maximal allowed length: argument length = %zu, maximal length = %ld", add_value ? "addition" : "removal", - name_len, LOGIN_NAME_MAX); + name_len, login_name_max); ret = LTTNG_ERR_INVALID; goto error; } -- 2.34.1