google / rrg

A Rust rewrite of the GRR agent.
MIT License
46 stars 22 forks source link

`ospect::os::fqdn` does not work on macOS #58

Open panhania opened 11 months ago

panhania commented 11 months ago

Some change recently caused the tests for ospect::os::fqdn to fail. GitHub Actions run for 34441db (run) succeeded but the following 1a39af0 (run) failed. The commit does not touch this function at all.

When testing locally the low-level function used to implement this (getaddrinfo), the same error happens:

#include <limits.h>
#include <stdio.h>
#include <unistd.h>
#include <netdb.h>

int main(void)
{
    int err;

    long host_name_max = sysconf(_SC_HOST_NAME_MAX);
    char hostname[host_name_max + 1];

    err = gethostname(hostname, sizeof(hostname));
    if (err != 0) {
        fprintf(stderr, "failed to get hostname: %d", err);
        return 1;
    }

    printf("hostname: %s\n", hostname);

    struct addrinfo hints = {0};
    hints.ai_family = PF_UNSPEC;
    hints.ai_socktype = 0;
    hints.ai_protocol = 0;
    hints.ai_flags = AI_CANONNAME;

    struct addrinfo *info;

    err = getaddrinfo(hostname, NULL, &hints, &info);
    if (err != 0) {
        fprintf(stderr, "failed to get hostname information: %s\n", gai_strerror(err));
        return 1;
    }

    printf("fqdn: %s\n", info->ai_canonname);

    freeaddrinfo(info);

    return 0;
}

When running this code, the call to getaddrinfo fails with EAI_NONAME ("nodename nor servname provided, or not known"). This indicates that we call this function incorrectly (either nodename or servname must be provided but we are clearly doing so).

The run for commit 34441db was on macOS 12.6.9 whereas the run for commit 1a39af0 was on macOS 12.7. There is a chance that some system-level change was introduced that broke us.