Loop through user linked list twice. Put all names of users in a buffer string called buf.
char *list_users(const User *head)
{
    // First loop: add up all string lengths
    int str_len_sum = 0;
    int name_count = 0;
    const User *curr = head;
    while (curr != NULL)
    {
        str_len_sum += strlen(curr->name);
        name_count++;

        curr = curr->next;
    }

    // malloc buf: name_count * 2 means network newline after each name, 1 at end for \0
    char *buf = (char *)malloc(sizeof(char) * (str_len_sum + name_count * 2 + 1));
    if (buf == NULL)
    {
        perror("Error: failed to malloc buf");
        exit(1);
    }

    // Second loop: copy strings into buffer of sufficient size
    curr = head; // reset curr to head
    while (curr != NULL)
    {
        // append name of user to buf
        int snprintf_result = snprintf(buf, INPUT_BUFFER_SIZE, "%s\r\n", curr->name);
        if (snprintf_result < 0)
        {
            perror("Error: snprintf failed");
        }

        curr = curr->next;
    }

    //snprintf(buf, 1, "\0"); // add null terminator to the last index of the buffer

    return buf;
}