From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <dietmar@proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256)
 (No client certificate requested)
 by lists.proxmox.com (Postfix) with ESMTPS id 716A57778A
 for <pbs-devel@lists.proxmox.com>; Wed, 21 Jul 2021 08:12:58 +0200 (CEST)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
 by firstgate.proxmox.com (Proxmox) with ESMTP id 60F5910B68
 for <pbs-devel@lists.proxmox.com>; Wed, 21 Jul 2021 08:12:58 +0200 (CEST)
Received: from elsa.proxmox.com (unknown [94.136.29.99])
 by firstgate.proxmox.com (Proxmox) with ESMTP id 54A9C10B5E
 for <pbs-devel@lists.proxmox.com>; Wed, 21 Jul 2021 08:12:57 +0200 (CEST)
Received: by elsa.proxmox.com (Postfix, from userid 0)
 id 2EF06AE0957; Wed, 21 Jul 2021 08:12:57 +0200 (CEST)
From: Dietmar Maurer <dietmar@proxmox.com>
To: pbs-devel@lists.proxmox.com
Date: Wed, 21 Jul 2021 08:12:51 +0200
Message-Id: <20210721061251.747710-1-dietmar@proxmox.com>
X-Mailer: git-send-email 2.30.2
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-SPAM-LEVEL: Spam detection results:  0
 AWL 0.459 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
 RDNS_NONE 0.793 Delivered to internal network by a host with no rDNS
 SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_PASS               -0.001 SPF: sender matches SPF record
 URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See
 http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more
 information. [mod.rs]
Subject: [pbs-devel] [PATCH proxmox-backup] fix regression test file
 permission problems
X-BeenThere: pbs-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox Backup Server development discussion
 <pbs-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pbs-devel>, 
 <mailto:pbs-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pbs-devel/>
List-Post: <mailto:pbs-devel@lists.proxmox.com>
List-Help: <mailto:pbs-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel>, 
 <mailto:pbs-devel-request@lists.proxmox.com?subject=subscribe>
X-List-Received-Date: Wed, 21 Jul 2021 06:12:58 -0000

By simply using the current user/group instead of backup:backup
---
 src/backup/mod.rs | 22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)

diff --git a/src/backup/mod.rs b/src/backup/mod.rs
index 31bd1b3b..20b6b3ca 100644
--- a/src/backup/mod.rs
+++ b/src/backup/mod.rs
@@ -12,17 +12,27 @@ pub const BACKUP_GROUP_NAME: &str = "backup";
 
 /// Return User info for the 'backup' user (``getpwnam_r(3)``)
 pub fn backup_user() -> Result<nix::unistd::User, Error> {
-    match nix::unistd::User::from_name(BACKUP_USER_NAME)? {
-        Some(user) => Ok(user),
-        None => bail!("Unable to lookup backup user."),
+    if cfg!(test) {
+        // fix permission problems with regressions test (when run as non-root).
+        Ok(nix::unistd::User::from_uid(nix::unistd::Uid::current())?.unwrap())
+    } else {
+        match nix::unistd::User::from_name(BACKUP_USER_NAME)? {
+            Some(user) => Ok(user),
+            None => bail!("Unable to lookup backup user."),
+        }
     }
 }
 
 /// Return Group info for the 'backup' group (``getgrnam(3)``)
 pub fn backup_group() -> Result<nix::unistd::Group, Error> {
-    match nix::unistd::Group::from_name(BACKUP_GROUP_NAME)? {
-        Some(group) => Ok(group),
-        None => bail!("Unable to lookup backup user."),
+    if cfg!(test) {
+        // fix permission problems with regressions test (when run as non-root).
+        Ok(nix::unistd::Group::from_gid(nix::unistd::Gid::current())?.unwrap())
+    } else {
+        match nix::unistd::Group::from_name(BACKUP_GROUP_NAME)? {
+            Some(group) => Ok(group),
+            None => bail!("Unable to lookup backup user."),
+        }
     }
 }
 
-- 
2.30.2