From nobody Sat Feb 7 10:08:34 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1596822279; cv=none; d=zohomail.com; s=zohoarc; b=E1rKFosYs0hSRahmacpNiJb+fY2LvD/knYMRGs1MUx7q45My8+dALDnGUlS9c4vOR6KnEXZlbaOmn7dzQma2BUTWKr5w3YWU8K74Vzy4Bs4dWMm0IWayUWjM5WJuq/O3Y/48hApVrxDjQ/fhw0gmSLNK/DA+cLnuJpQlv5b4hrc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1596822279; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=8zfdEnfeoAXYxH+1qsYVAc9uj306NAinpkzEpyNtUVM=; b=GdE3ZJB+sMtIxsLwoX69xRd+QqmUsoLolOrYDLGO/qUKpz7wwy2776uvsUZ4sL553B8RyyjQ33TJAu+M687XOeAfE0h1ikND8CtvZqm55dd1rft2MM1wGC56jUHp5LDOnMaJimB7x5DG3pECVr+dYWDu5YKgrtRIC+dqkUSHsvE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1596822279096723.7265570730181; Fri, 7 Aug 2020 10:44:39 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-408-EpjX774rPlGCcKcv8Kl2xg-1; Fri, 07 Aug 2020 13:44:35 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id F00B158; Fri, 7 Aug 2020 17:44:29 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CBF0C1A919; Fri, 7 Aug 2020 17:44:29 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 829311800B71; Fri, 7 Aug 2020 17:44:29 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 077HfDhs017729 for ; Fri, 7 Aug 2020 13:41:13 -0400 Received: by smtp.corp.redhat.com (Postfix) id EA6415D9E8; Fri, 7 Aug 2020 17:41:13 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.36.110.44]) by smtp.corp.redhat.com (Postfix) with ESMTP id ED1C55DA30; Fri, 7 Aug 2020 17:41:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1596822277; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=8zfdEnfeoAXYxH+1qsYVAc9uj306NAinpkzEpyNtUVM=; b=B5nppzGk8urtU5cqy1ud9l7ZByG1yMY+VGM0IEcoOpuFMB6V+2ZwvZIErYlS/F3C6brtw1 GcaKAr21zGhcEWbNZ8SZUNFU+yH73DXG+CfaNZy+aDgB4NXcFdVW7xL7KhZPfSMwpqn3DS ZLGwnmKGwkrR+TThfrhhlJB43cuRoUQ= X-MC-Unique: EpjX774rPlGCcKcv8Kl2xg-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Subject: [libvirt PATCH v4 07/11] remote: extract logic for determining daemon to connect to Date: Fri, 7 Aug 2020 18:40:55 +0100 Message-Id: <20200807174059.312786-8-berrange@redhat.com> In-Reply-To: <20200807174059.312786-1-berrange@redhat.com> References: <20200807174059.312786-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) We'll shortly want to reuse code for determining whether to connect to the system or session daemon from places outside the remote driver client. Pulling it out into a self contained function facilitates reuse. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/remote/remote_driver.c | 51 ++++---------------------------- src/remote/remote_sockets.c | 59 +++++++++++++++++++++++++++++++++++++ src/remote/remote_sockets.h | 6 ++++ 3 files changed, 71 insertions(+), 45 deletions(-) diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index 6ab0d67854..df10cfaef6 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -1198,7 +1198,8 @@ remoteConnectOpen(virConnectPtr conn, struct private_data *priv; int ret =3D VIR_DRV_OPEN_ERROR; int rflags =3D 0; - const char *autostart =3D getenv("LIBVIRT_AUTOSTART"); + bool user; + bool autostart; char *driver =3D NULL; remoteDriverTransport transport; =20 @@ -1233,51 +1234,11 @@ remoteConnectOpen(virConnectPtr conn, if (flags & VIR_CONNECT_RO) rflags |=3D VIR_DRV_OPEN_REMOTE_RO; =20 - /* - * User session daemon is used for - * - * - Any URI with /session suffix - * - Test driver, if a protocol is given - * - * provided we are running non-root - */ - if (conn->uri && - conn->uri->path && - conn->uri->scheme && - (STREQ(conn->uri->path, "/session") || - STRPREFIX(conn->uri->scheme, "test+")) && - geteuid() > 0) { - VIR_DEBUG("User session daemon required"); + remoteGetURIDaemonInfo(conn->uri, transport, &user, &autostart); + if (user) rflags |=3D VIR_DRV_OPEN_REMOTE_USER; - - /* - * Furthermore if no servername is given, - * and the transport is unix, - * and uid is unprivileged then auto-spawn a daemon. - */ - if (!conn->uri->server && - (transport =3D=3D REMOTE_DRIVER_TRANSPORT_UNIX) && - (!autostart || - STRNEQ(autostart, "0"))) { - VIR_DEBUG("Try daemon autostart"); - rflags |=3D VIR_DRV_OPEN_REMOTE_AUTOSTART; - } - } - - /* - * If URI is NULL, then do a UNIX connection possibly auto-spawning - * unprivileged server and probe remote server for URI. - */ - if (!conn->uri) { - VIR_DEBUG("Auto-probe remote URI"); - if (geteuid() > 0) { - VIR_DEBUG("Auto-spawn user daemon instance"); - rflags |=3D VIR_DRV_OPEN_REMOTE_USER; - if (!autostart || - STRNEQ(autostart, "0")) - rflags |=3D VIR_DRV_OPEN_REMOTE_AUTOSTART; - } - } + if (autostart) + rflags |=3D VIR_DRV_OPEN_REMOTE_AUTOSTART; =20 ret =3D doRemoteOpen(conn, priv, driver, transport, auth, conf, rflags= ); if (ret !=3D VIR_DRV_OPEN_SUCCESS) { diff --git a/src/remote/remote_sockets.c b/src/remote/remote_sockets.c index 28e02e24d5..854775f401 100644 --- a/src/remote/remote_sockets.c +++ b/src/remote/remote_sockets.c @@ -224,3 +224,62 @@ remoteGetUNIXSocket(remoteDriverTransport transport, ro, session); return sock_name; } + + +void +remoteGetURIDaemonInfo(virURIPtr uri, + remoteDriverTransport transport, + bool *session, + bool *autostart) +{ + const char *autostart_str =3D getenv("LIBVIRT_AUTOSTART"); + + *session =3D false; + *autostart =3D false; + + /* + * User session daemon is used for + * + * - Any URI with /session suffix + * - Test driver, if a protocol is given + * + * provided we are running non-root + */ + if (uri && + uri->path && + uri->scheme && + (STREQ(uri->path, "/session") || + STRPREFIX(uri->scheme, "test+")) && + geteuid() > 0) { + VIR_DEBUG("User session daemon required"); + *session =3D true; + + /* + * Furthermore if no servername is given, + * and the transport is unix, + * and uid is unprivileged then auto-spawn a daemon. + */ + if (!uri->server && + (transport =3D=3D REMOTE_DRIVER_TRANSPORT_UNIX) && + (!autostart_str || + STRNEQ(autostart_str, "0"))) { + VIR_DEBUG("Try daemon autostart"); + *autostart =3D true; + } + } + + /* + * If URI is NULL, then do a UNIX connection possibly auto-spawning + * unprivileged server and probe remote server for URI. + */ + if (!uri) { + VIR_DEBUG("Auto-probe remote URI"); + if (geteuid() > 0) { + VIR_DEBUG("Auto-spawn user daemon instance"); + *session =3D true; + if (!autostart_str || + STRNEQ(autostart_str, "0")) + *autostart =3D true; + } + } +} diff --git a/src/remote/remote_sockets.h b/src/remote/remote_sockets.h index 64055f3d44..7526752835 100644 --- a/src/remote/remote_sockets.h +++ b/src/remote/remote_sockets.h @@ -62,3 +62,9 @@ remoteGetUNIXSocket(remoteDriverTransport transport, bool ro, bool session, char **daemon); + +void +remoteGetURIDaemonInfo(virURIPtr uri, + remoteDriverTransport transport, + bool *session, + bool *autostart); --=20 2.26.2