int pakfire_client_create(struct pakfire_client** client,
struct pakfire_ctx* ctx, sd_event* loop, const char* url, const char* principal) {
struct pakfire_client* self = NULL;
+ char hostname[HOST_NAME_MAX];
int r;
// Allocate some memory
if (r < 0)
goto ERROR;
+ // Use the hostname if no principal given
+ if (!principal) {
+ r = gethostname(hostname, sizeof(hostname));
+ if (r < 0) {
+ ERROR(self->ctx, "Failed to fetch hostname: %m\n");
+ r = -errno;
+ goto ERROR;
+ }
+
+ // Use the hostname as principal
+ principal = hostname;
+ }
+
// Store the principal
r = pakfire_string_set(self->principal, principal);
if (r < 0)