From patchwork Thu Oct 13 09:23:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alexander Ivanov X-Patchwork-Id: 13005844 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E23F7C433FE for ; Thu, 13 Oct 2022 10:20:05 +0000 (UTC) Received: from localhost ([::1]:36852 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oivJs-0001xN-Bv for qemu-devel@archiver.kernel.org; Thu, 13 Oct 2022 06:20:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34352) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oiuRU-0002JP-AU for qemu-devel@nongnu.org; Thu, 13 Oct 2022 05:23:52 -0400 Received: from mail-eopbgr140123.outbound.protection.outlook.com ([40.107.14.123]:28929 helo=EUR01-VE1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oiuRR-0004g6-Ls for qemu-devel@nongnu.org; Thu, 13 Oct 2022 05:23:52 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Vhq04hOu6D+c6O9EgvoX1ej9HudCtb4N/r4Yg84op78mjkbJ/I0kZKyS7/TmTTCE7R8mp6S0Htl3nVv0SjLisQGWtdDgjSB2tUq7gx8XBtL4I1iu576z7ZZvKG0KRPwUmFp5m5h1m8dgN3Zzl/cJkiaqmoFI6IeuwEzdMFjC9O+H+q2vH/Nv6pJlawASYIulX19q5jrwV2NkjdneyPQaGNvAvb6cXh3CzqHYTJY3wY7K7/iZXeMyeVteJ8XX/PIz1sb8tg051vwggCDCGbt21FyqeUPgp4Fmt8HsFH1lj0S4xmXYQi6FuuOVJ1x2n65Bh9tOMO8tEt31HlwEtDuhEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=iT73yPip7Y9KrhTJdJ9NiMxOTh3MLqVE4NRIId7eC2U=; b=enHoBXEIPQHoDzy4bVnPsrnjiu+BFd5jQ1dkT+TJyxIHgXR3zBEwI1qsZDTHpJt4/KocHeFEQqsCU/cOgRWGAyZp9BhqHqCFPYGj0pkxTeHQtdkOT/AgfEG6staokZ8stpXJ/kvWzirmbL+gEUTAifVfbkqMUf5AbF/omDdFj57BoxRjm1+ZNTgfq7+v+64NSA4dacUxYuYgtOm+NbeJ5uh6V1ZD+MWcq22BeNQkILO6JVrG0iRJVfF7Jb5SNAokYJ+i9afXnZfbx5G49I3wBdRyB6cTBXNIF8NMLCuEmwuW9I45jL6Wvo3AJu9OtDFqcFjJa3foLJUAilNK9/RSgQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=virtuozzo.com; dmarc=pass action=none header.from=virtuozzo.com; dkim=pass header.d=virtuozzo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=iT73yPip7Y9KrhTJdJ9NiMxOTh3MLqVE4NRIId7eC2U=; b=ezCB8nJ/LYIT52E/QBt8tHX+n0OvbZsKX/pZVCZYex30nU5Ac496vGw4kAJ9gnuk1sfcMnR0T33IUMhdEEEYOIGjOy76+C4BNKjvdOnAUz+yFTm2SQBKFW9nYfLoxAxgAhuFezhlMFbANMvz8dxPATfbe7mhxK+7NR9biz+YUwXmfi9TzFz97MGdTY4qUrgMfGHOlv5jSAMtjya6E3ymlHeo4xoNc2UIYvLDx+CmIo/eec1mTn19WeYYZf3PR8ipx6wRD/HM8DRGGnHSZqEhiMqP/EbAx9gPn403zL4/AH0NIiY3Yfz5+1JqfTJX6QwEZnC9uS1Jsr/StVmAeFZiow== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=virtuozzo.com; Received: from AS8PR08MB7095.eurprd08.prod.outlook.com (2603:10a6:20b:402::11) by AM8PR08MB6466.eurprd08.prod.outlook.com (2603:10a6:20b:363::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5709.21; Thu, 13 Oct 2022 09:23:39 +0000 Received: from AS8PR08MB7095.eurprd08.prod.outlook.com ([fe80::5174:25c7:6df8:741b]) by AS8PR08MB7095.eurprd08.prod.outlook.com ([fe80::5174:25c7:6df8:741b%8]) with mapi id 15.20.5676.040; Thu, 13 Oct 2022 09:23:39 +0000 From: Alexander Ivanov To: qemu-devel@nongnu.org Cc: den@virtuozzo.com, michael.roth@amd.com, kkostiuk@redhat.com, marcandre.lureau@gmail.com Subject: [PATCH v4 5/7] qga: Add support for user password setting in FreeBSD Date: Thu, 13 Oct 2022 11:23:24 +0200 Message-Id: <20221013092326.2194646-6-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221013092326.2194646-1-alexander.ivanov@virtuozzo.com> References: <20221013092326.2194646-1-alexander.ivanov@virtuozzo.com> X-ClientProxiedBy: FR0P281CA0069.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:49::22) To AS8PR08MB7095.eurprd08.prod.outlook.com (2603:10a6:20b:402::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR08MB7095:EE_|AM8PR08MB6466:EE_ X-MS-Office365-Filtering-Correlation-Id: 12e30ef2-abff-45d3-f99c-08daacfc9caf X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: we0cty67ycuD4aWo5jy2KqzPy4HD/Gvi/gmEsPC+GCTOWbTMXRdbELGD9tw8ZTt9MYRLuzaT1EuGAR3zIkbxlGJiI3XsTK8bSUO00OLbtOvgsLjB68DQmKypt3/METrFY4v+zSLPqUiUn3m45P3GYvM4nDhTYizWUaMb7QdzKd53tq7QjbMz0fg7vJ25fGWJNbFBM6gI+tcQvlaPvE3PsM2a+9POtqazTszQJSIywslqXnWFJRKjXMP7VvGZ+nh+4tNCtrLCMXXZnPZ5xVJKCJjC4zch5tvghxXySPt5tSquJS0KtxjBU3Tb1YMsj5ZO9LZ9cm6zddReCVC8MTqwvvmCYJKnwPopYr19CNbWqVbOC+lvYHHk104g1RPcDe9pjBgndip7YUU1Bd5Mi5A5eB/5IaENyQSXTsHcReaXNwraU5Rbvn2R90gJRDW3tcQOmVMLebc8K0aZuxFDiGkjUp7ts40mzq6stObPsO9+L3W97H6+/KJYtcxNhzlRhY/r+YOaQULDxwlOKaY4YFjg4oS2/dpM488INr8jzN8gToBi3xY1wl+zlHYM6HY2qPFUeTvR6r5oXPHlYZJTe9cwM0wcz6RVbYi9Arx1KVWaAqrdqVk7ypwJ9eZPCs573tLGMQoSpn5q7u3A2MJIzhB68sGec0fsvG2b83laq2MG+33Gl/8NWdzWuGHHV/8U8/Pv8EMBlyGBOoGRwPH8dYTzmmhPUhwCND+pMCf3yoHvEnRtft04S5SAwmj65K7z/1jk X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AS8PR08MB7095.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230022)(4636009)(366004)(376002)(346002)(136003)(39850400004)(396003)(451199015)(36756003)(2906002)(44832011)(4326008)(6512007)(5660300002)(41300700001)(8676002)(66556008)(316002)(86362001)(6916009)(66946007)(66476007)(8936002)(38100700002)(478600001)(6486002)(6666004)(38350700002)(83380400001)(26005)(6506007)(52116002)(2616005)(186003)(1076003); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?/YJOmn+GNXSqKe2ZxXFG53KyjDI/?= =?utf-8?q?6F6lMODvVUiIhTYJNMwP94NBSExcB/Hx+N3oipRXnyO0iqFr+74TNu33o3ApRUxRq?= =?utf-8?q?xgtOJ8vH5ITGXfxI8kYWzm1HeCzltCZr/ymDWhpGXMjn3oG9W5zqiCQNwgz2d7WmD?= =?utf-8?q?8x4n8ikoll0Q0tjvTEHBBPoD3lm8Obj6EW382B2Hj2JzC4leZXlb4TvH2UgVIXV8e?= =?utf-8?q?j5lgSYb48a/KXipr8Kj6HIMip8yzCLVQKGllO2Cms8AGes+yqRs+AjdvQG9rOijDk?= =?utf-8?q?4V8F3CxcE6A0U9Zn/LgbP2kNpTQ/0Lqm2u5/FICXAUevvEjZ9p5Wg/aolZEs5QZBS?= =?utf-8?q?hhr8VRibcec2gXxQskUeD0ctPXiyE0SdtxX1KybPnZipIFJiu1VSdlBMfiCBZUGEq?= =?utf-8?q?0MgQBgIhL8j4u4XyYhnlTt7gDKvDypOkXw7J9jfPW/iiC7uRQIGVgZWTcjbgjMMw9?= =?utf-8?q?ZPH52IvtUU8ULJJUt7/HGk33kwu5yDjUD5oSkstv94Yk1vAYJKTTjigdxg/6HwQGG?= =?utf-8?q?lAASh+F7qD5MxUEtSNKHQVsPDNUmknBrj8ufIis5UHytCIsXWcZUhT4ZapRCfQarS?= =?utf-8?q?Dpu6RmgPYaYIM/uMEufehn9kn2u/vjbDUR15yWqnihfmxEVjFWO4H+2XY0IguiwNV?= =?utf-8?q?J9AU23yth62ES2O2uXTn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6v7t1jBKunVaHtwhrBA=3D=3D?= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 12e30ef2-abff-45d3-f99c-08daacfc9caf X-MS-Exchange-CrossTenant-AuthSource: AS8PR08MB7095.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Oct 2022 09:23:38.9675 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: gx3+qW/IhZv1NTGFlZC3EajunSxJ5IB0skIl4Fnnbn4ZKuzrS4qeedMqs4oE1h6OnjseWSbeyNTLi63eMU0OkcnsYBtLYIPVZgvaqYYK8oc= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM8PR08MB6466 Received-SPF: pass client-ip=40.107.14.123; envelope-from=alexander.ivanov@virtuozzo.com; helo=EUR01-VE1-obe.outbound.protection.outlook.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Move qmp_guest_set_user_password() from __linux__ condition to (__linux__ || __FreeBSD__) condition. Add command and arguments for password setting in FreeBSD. Reviewed-by: Konstantin Kostiuk Reviewed-by: Marc-André Lureau Signed-off-by: Alexander Ivanov --- qga/commands-posix.c | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/qga/commands-posix.c b/qga/commands-posix.c index 88e0d0fe24..f5b9e5c530 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -2122,7 +2122,9 @@ int64_t qmp_guest_set_vcpus(GuestLogicalProcessorList *vcpus, Error **errp) return processed; } +#endif /* __linux__ */ +#if defined(__linux__) || defined(__FreeBSD__) void qmp_guest_set_user_password(const char *username, const char *password, bool crypted, @@ -2156,10 +2158,15 @@ void qmp_guest_set_user_password(const char *username, goto out; } +#ifdef __FreeBSD__ + chpasswddata = g_strdup(rawpasswddata); + passwd_path = g_find_program_in_path("pw"); +#else chpasswddata = g_strdup_printf("%s:%s\n", username, rawpasswddata); - chpasswdlen = strlen(chpasswddata); - passwd_path = g_find_program_in_path("chpasswd"); +#endif + + chpasswdlen = strlen(chpasswddata); if (!passwd_path) { error_setg(errp, "cannot find 'passwd' program in PATH"); @@ -2180,11 +2187,17 @@ void qmp_guest_set_user_password(const char *username, reopen_fd_to_null(1); reopen_fd_to_null(2); +#ifdef __FreeBSD__ + const char *h_arg; + h_arg = (crypted) ? "-H" : "-h"; + execl(passwd_path, "pw", "usermod", "-n", username, h_arg, "0", NULL); +#else if (crypted) { execl(passwd_path, "chpasswd", "-e", NULL); } else { execl(passwd_path, "chpasswd", NULL); } +#endif _exit(EXIT_FAILURE); } else if (pid < 0) { error_setg_errno(errp, errno, "failed to create child process"); @@ -2227,7 +2240,17 @@ out: close(datafd[1]); } } +#else /* __linux__ || __FreeBSD__ */ +void qmp_guest_set_user_password(const char *username, + const char *password, + bool crypted, + Error **errp) +{ + error_setg(errp, QERR_UNSUPPORTED); +} +#endif /* __linux__ || __FreeBSD__ */ +#ifdef __linux__ static void ga_read_sysfs_file(int dirfd, const char *pathname, char *buf, int size, Error **errp) { @@ -2764,14 +2787,6 @@ int64_t qmp_guest_set_vcpus(GuestLogicalProcessorList *vcpus, Error **errp) return -1; } -void qmp_guest_set_user_password(const char *username, - const char *password, - bool crypted, - Error **errp) -{ - error_setg(errp, QERR_UNSUPPORTED); -} - GuestMemoryBlockList *qmp_guest_get_memory_blocks(Error **errp) { error_setg(errp, QERR_UNSUPPORTED);