From: Shreenidhi Shedi <yesshedi@gmail.com>
To: dhowells@redhat.com, dwmw2@infradead.org, gregkh@linuxfoundation.org
Cc: linux-kernel@vger.kernel.org, Shreenidhi Shedi <sshedi@vmware.com>
Subject: [PATCH v3 2/6] sign-file: move file signing logic to its own function
Date: Tue, 14 Feb 2023 00:30:30 +0530 [thread overview]
Message-ID: <20230213190034.57097-2-sshedi@vmware.com> (raw)
In-Reply-To: <20230213190034.57097-1-sshedi@vmware.com>
Keep the main function bare minimal and do less in main function.
Signed-off-by: Shreenidhi Shedi <sshedi@vmware.com>
---
scripts/sign-file.c | 69 +++++++++++++++++++++++++--------------------
1 file changed, 39 insertions(+), 30 deletions(-)
diff --git a/scripts/sign-file.c b/scripts/sign-file.c
index cf3acbb13013..4732201feb96 100644
--- a/scripts/sign-file.c
+++ b/scripts/sign-file.c
@@ -230,7 +230,7 @@ struct cmd_opts {
#endif
};
-void parse_args(int argc, char **argv, struct cmd_opts *opts)
+static void parse_args(int argc, char **argv, struct cmd_opts *opts)
{
struct option cmd_options[] = {
/* These options set a flag. */
@@ -315,10 +315,10 @@ void parse_args(int argc, char **argv, struct cmd_opts *opts)
} while (opt != -1);
}
-int main(int argc, char **argv)
+int sign_file(int argc, char **argv, struct cmd_opts *opts)
{
struct module_signature sig_info = { .id_type = PKEY_ID_PKCS7 };
- unsigned char buf[4096];
+ unsigned char buf[4096] = {0};
unsigned long module_size, sig_size;
unsigned int use_signed_attrs;
const EVP_MD *digest_algo;
@@ -331,36 +331,20 @@ int main(int argc, char **argv)
X509 *x509;
BIO *bd, *bm;
int i, n;
- struct cmd_opts opts = {0};
- OpenSSL_add_all_algorithms();
- ERR_load_crypto_strings();
- ERR_clear_error();
-
- key_pass = getenv("KBUILD_SIGN_PIN");
+ char *hash_algo = opts->hash_algo;
+ char *dest_name = opts->dest_name;
+ char *private_key_name = opts->private_key_name;
+ char *raw_sig_name = opts->raw_sig_name;
+ char *x509_name = opts->x509_name;
+ char *module_name = opts->module_name;
+ bool save_sig = opts->save_sig;
+ bool replace_orig = opts->replace_orig;
+ bool raw_sig = opts->raw_sig;
+ bool sign_only = opts->sign_only;
#ifndef USE_PKCS7
- use_signed_attrs = CMS_NOATTR;
-#else
- use_signed_attrs = PKCS7_NOATTR;
-#endif
- parse_args(argc, argv, &opts);
- argc -= optind;
- argv += optind;
-
- char *hash_algo = opts.hash_algo;
- char *dest_name = opts.dest_name;
- char *private_key_name = opts.private_key_name;
- char *raw_sig_name = opts.raw_sig_name;
- char *x509_name = opts.x509_name;
- char *module_name = opts.module_name;
- bool save_sig = opts.save_sig;
- bool replace_orig = opts.replace_orig;
- bool raw_sig = opts.raw_sig;
- bool sign_only = opts.sign_only;
-
-#ifndef USE_PKCS7
- unsigned int use_keyid = opts.use_keyid;
+ unsigned int use_keyid = opts->use_keyid;
#endif
if (!argv[0] || argc != 1)
@@ -381,6 +365,19 @@ int main(int argc, char **argv)
exit(3);
}
#endif
+
+ OpenSSL_add_all_algorithms();
+ ERR_load_crypto_strings();
+ ERR_clear_error();
+
+ key_pass = getenv("KBUILD_SIGN_PIN");
+
+#ifndef USE_PKCS7
+ use_signed_attrs = CMS_NOATTR;
+#else
+ use_signed_attrs = PKCS7_NOATTR;
+#endif
+
/* Open the module file */
bm = BIO_new_file(module_name, "rb");
ERR(!bm, "%s", module_name);
@@ -492,3 +489,15 @@ int main(int argc, char **argv)
return 0;
}
+
+int main(int argc, char **argv)
+{
+ struct cmd_opts opts = {0};
+
+ parse_args(argc, argv, &opts);
+
+ argc -= optind;
+ argv += optind;
+
+ return sign_file(argc, argv, &opts);
+}
--
2.39.1
next prev parent reply other threads:[~2023-02-13 19:01 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-13 19:00 [PATCH v3 1/6] sign-file: refactor argument parsing logic Shreenidhi Shedi
2023-02-13 19:00 ` Shreenidhi Shedi [this message]
2023-02-14 7:05 ` [PATCH v3 2/6] sign-file: move file signing logic to its own function Greg KH
2023-02-14 10:53 ` kernel test robot
2023-02-16 14:48 ` kernel test robot
2023-02-13 19:00 ` [PATCH v3 3/6] sign-file: add support sign modules in bulk Shreenidhi Shedi
2023-02-14 7:05 ` Greg KH
2023-02-13 19:00 ` [PATCH v3 4/6] sign-file: cosmetic fix Shreenidhi Shedi
2023-02-14 7:05 ` Greg KH
2023-02-14 7:06 ` Greg KH
2023-02-13 19:00 ` [PATCH v3 5/6] sign-file: use const with a global string constant Shreenidhi Shedi
2023-02-14 7:05 ` Greg KH
2023-02-13 19:00 ` [PATCH v3 6/6] sign-file: improve help message Shreenidhi Shedi
2023-02-14 7:05 ` Greg KH
2023-02-14 7:04 ` [PATCH v3 1/6] sign-file: refactor argument parsing logic Greg KH
2023-02-14 7:06 ` Greg KH
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230213190034.57097-2-sshedi@vmware.com \
--to=yesshedi@gmail.com \
--cc=dhowells@redhat.com \
--cc=dwmw2@infradead.org \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=sshedi@vmware.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox