From nobody Sun Feb 8 11:44:32 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DA53AC761A6 for ; Tue, 21 Mar 2023 19:35:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230338AbjCUTe6 (ORCPT ); Tue, 21 Mar 2023 15:34:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50100 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230335AbjCUTeu (ORCPT ); Tue, 21 Mar 2023 15:34:50 -0400 Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 90E1C574C4 for ; Tue, 21 Mar 2023 12:34:17 -0700 (PDT) Received: by mail-pj1-x1035.google.com with SMTP id p13-20020a17090a284d00b0023d2e945aebso2415004pjf.0 for ; Tue, 21 Mar 2023 12:34:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679427227; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=FM7lFg55AWwHloU3VtuYwjKc3tGgKt3dHUyfvh4gsro=; b=OEsme06LsrF0p1EIgKOcNvPW+Lf/MlmVl7LKGbSSJdH7Xh1xX0o9mZVN47VxGvJe5t vcvLEdc3NIZKRjoEGhvX3m4108ocAR2XL346j+6f8LgET5c4hA3LzpAo1enY+HEqhduU N1QK970nSgao7xV6Axt9ChcFBanu7L7hXG6woYEKbIYXhRaMU06GU+3Eaj3BDOFGYb0k SRnBLSYqBV7U1NDxLwG0v+PMXMASHsenRwkgxONYeSl0j7KcwHKBeBVKm5HE1Dr1EuhU cgemdv50+Rep74h0sFxor9ww+6LCXlr0ZYaCz4SNLZLq0zbDfmL9Fn8p5gHZCudCZIgP oUEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679427227; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FM7lFg55AWwHloU3VtuYwjKc3tGgKt3dHUyfvh4gsro=; b=tM7/fw89Fam4hlTKRDhgQfgwGCulshWJMjlMOCeVrLLfGrzuyGPjTqWaeHItjfl3Ke ISl2TV/qWBbMjHFa9/XTPLv8giDJM6Cs8T0HhPuGsXJ7so/dAlk7CEAeqPsirbD8gBAC EqZFLo/IWYDOikwfzdnoRyVk0PxmLu9kBHZG2BVU+I2i6lgaop10as8C4HtZXuk7m8IO VyZtDqGh/Ezkz4DuSty69iARz9YqoyLTyx/Pa8Fmy6c0xkYCWRAkh25r/xDxvmeMEK9M 53OtqI65MLHMgBDUXa7e3kcAEkWrPZFqx9fyeOEfjPmJZgwKPCcfNm/87zaqufib4Jzs jQFg== X-Gm-Message-State: AO0yUKUhWBhTOH12NZOGJfyXPJq+QzBShp96Ynm24cyqeJJF5cq6DeIZ BImZm/2vz6o08euUw49MMKwFbFDLTA1Y0Q== X-Google-Smtp-Source: AK7set/+3hnQ6QEPr3sQIY0zFpfbjrGHkfYTqKfNE1nFSbB2wvOSsZYUgcUbK2hprr3x4lAJInLPDA== X-Received: by 2002:a05:6a20:c526:b0:cb:af96:ace7 with SMTP id gm38-20020a056a20c52600b000cbaf96ace7mr2957976pzb.46.1679427227642; Tue, 21 Mar 2023 12:33:47 -0700 (PDT) Received: from f37.eng.vmware.com ([66.170.99.1]) by smtp.googlemail.com with ESMTPSA id k23-20020aa790d7000000b006247123adf1sm8843044pfk.143.2023.03.21.12.33.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Mar 2023 12:33:47 -0700 (PDT) From: Shreenidhi Shedi X-Google-Original-From: Shreenidhi Shedi To: gregkh@linuxfoundation.org, dhowells@redhat.com, dwmw2@infradead.org Cc: linux-kernel@vger.kernel.org, sshedi@vmware.com, yesshedi@gmail.com Subject: [PATCH v6 2/7] sign-file: inntroduce few new flags to make argument processing easy. Date: Wed, 22 Mar 2023 01:03:36 +0530 Message-Id: <20230321193341.87997-3-sshedi@vmware.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230321193341.87997-1-sshedi@vmware.com> References: <20230321193341.87997-1-sshedi@vmware.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Shreenidhi Shedi - Add some more options like help, x509, hashalgo to command line args - This makes it easy to handle and use command line args wherever needed Signed-off-by: Shreenidhi Shedi --- scripts/sign-file.c | 63 ++++++++++++++++++++++++++++++++------------- 1 file changed, 45 insertions(+), 18 deletions(-) diff --git a/scripts/sign-file.c b/scripts/sign-file.c index 94228865b6cc..b0f340ea629b 100644 --- a/scripts/sign-file.c +++ b/scripts/sign-file.c @@ -215,6 +215,11 @@ static X509 *read_x509(const char *x509_name) =20 struct cmd_opts { char *raw_sig_name; + char *hash_algo; + char *dest_name; + char *private_key_name; + char *x509_name; + char *module_name; bool save_sig; bool replace_orig; bool raw_sig; @@ -233,6 +238,12 @@ static void parse_args(int argc, char **argv, struct c= md_opts *opts) #ifndef USE_PKCS7 {"usekeyid", no_argument, 0, 'k'}, #endif + {"help", no_argument, 0, 'h'}, + {"privkey", required_argument, 0, 'i'}, + {"hashalgo", required_argument, 0, 'a'}, + {"x509", required_argument, 0, 'x'}, + {"dest", required_argument, 0, 'd'}, + {"replaceorig", required_argument, 0, 'r'}, {0, 0, 0, 0} }; =20 @@ -241,10 +252,10 @@ static void parse_args(int argc, char **argv, struct = cmd_opts *opts) =20 do { #ifndef USE_PKCS7 - opt =3D getopt_long_only(argc, argv, "pds:", + opt =3D getopt_long_only(argc, argv, "hpds:i:a:x:t:r:", cmd_options, &opt_index); #else - opt =3D getopt_long_only(argc, argv, "pdks:", + opt =3D getopt_long_only(argc, argv, "hpdks:i:a:x:t:r:", cmd_options, &opt_index); #endif switch (opt) { @@ -268,6 +279,30 @@ static void parse_args(int argc, char **argv, struct c= md_opts *opts) break; #endif =20 + case 'h': + format(); + break; + + case 'i': + opts->private_key_name =3D optarg; + break; + + case 'a': + opts->hash_algo =3D optarg; + break; + + case 'x': + opts->x509_name =3D optarg; + break; + + case 't': + opts->dest_name =3D optarg; + break; + + case 'r': + opts->replace_orig =3D true; + break; + case -1: break; =20 @@ -281,9 +316,6 @@ static void parse_args(int argc, char **argv, struct cm= d_opts *opts) int main(int argc, char **argv) { struct module_signature sig_info =3D { .id_type =3D PKEY_ID_PKCS7 }; - char *hash_algo =3D NULL; - char *private_key_name =3D NULL; - char *x509_name, *module_name, *dest_name; unsigned char buf[4096]; unsigned long module_size, sig_size; unsigned int use_signed_attrs; @@ -315,32 +347,27 @@ int main(int argc, char **argv) argv +=3D optind; =20 const char *raw_sig_name =3D opts.raw_sig_name; + const char *hash_algo =3D opts.hash_algo; + const char *private_key_name =3D opts.private_key_name; + const char *x509_name =3D opts.x509_name; + const char *module_name =3D opts.module_name; const bool save_sig =3D opts.save_sig; const bool raw_sig =3D opts.raw_sig; const bool sign_only =3D opts.sign_only; bool replace_orig =3D opts.replace_orig; + char *dest_name =3D opts.dest_name; #ifndef USE_PKCS7 const unsigned int use_keyid =3D opts.use_keyid; #endif =20 - if (argc < 4 || argc > 5) + if (!argv[0] || argc !=3D 1) format(); =20 - if (raw_sig) { - raw_sig_name =3D argv[0]; - hash_algo =3D argv[1]; - } else { - hash_algo =3D argv[0]; - private_key_name =3D argv[1]; - } - x509_name =3D argv[2]; - module_name =3D argv[3]; - if (argc =3D=3D 5 && strcmp(argv[3], argv[4]) !=3D 0) { - dest_name =3D argv[4]; + if (dest_name && strcmp(argv[0], dest_name)) { replace_orig =3D false; } else { ERR(asprintf(&dest_name, "%s.~signed~", module_name) < 0, - "asprintf"); + "asprintf"); replace_orig =3D true; } =20 --=20 2.39.2