From: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
To: linux-modules <linux-modules@vger.kernel.org>
Cc: Lucas De Marchi <lucas.de.marchi@gmail.com>,
Mark van Dijk <linux-modules@z.dvxs.net>
Subject: [PATCH 2/4] libkmod: modinfo: use own function for sig_key hex output
Date: Tue, 11 Apr 2017 15:15:01 +0300 [thread overview]
Message-ID: <20170411121503.26181-3-yauheni.kaliuta@redhat.com> (raw)
In-Reply-To: <20170411121503.26181-1-yauheni.kaliuta@redhat.com>
Refactor the code a bit to make it easier to extend for signature
output.
kmod_module_get_info() creats a hex string for the sig_key data
inplace. Separate it into own kmod_module_hex_to_string function
and handle the branch in the new kmod_module_info_append_hex,
keeping the same signature as the non-hex version.
Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
---
libkmod/libkmod-module.c | 79 +++++++++++++++++++++++++++++++++---------------
1 file changed, 54 insertions(+), 25 deletions(-)
diff --git a/libkmod/libkmod-module.c b/libkmod/libkmod-module.c
index 34c7f76e4db5..22c8f4c852a2 100644
--- a/libkmod/libkmod-module.c
+++ b/libkmod/libkmod-module.c
@@ -2193,6 +2193,53 @@ static struct kmod_list *kmod_module_info_append(struct kmod_list **list, const
return n;
}
+static char *kmod_module_hex_to_str(const char *hex, size_t len)
+{
+ char *str;
+ int i;
+
+ str = malloc(len * 3);
+ if (str == NULL)
+ return NULL;
+
+ for (i = 0; i < (int)len; i++) {
+ sprintf(str + i * 3, "%02X", (unsigned char)hex[i]);
+ if (i < (int)len - 1)
+ str[i * 3 + 2] = ':';
+ }
+ return str;
+}
+
+static struct kmod_list *kmod_module_info_append_hex(struct kmod_list **list,
+ const char *key,
+ size_t keylen,
+ const char *value,
+ size_t valuelen)
+{
+ char *hex;
+ struct kmod_list *n;
+
+ if (valuelen > 0) {
+ /* Display as 01:12:DE:AD:BE:EF:... */
+ hex = kmod_module_hex_to_str(value, valuelen);
+ if (hex == NULL)
+ goto list_error;
+ n = kmod_module_info_append(list, key, keylen, hex, strlen(hex));
+ free(hex);
+ if (n == NULL)
+ goto list_error;
+ } else {
+ n = kmod_module_info_append(list, key, keylen, NULL, 0);
+ if (n == NULL)
+ goto list_error;
+ }
+
+ return n;
+
+list_error:
+ return NULL;
+}
+
/**
* kmod_module_get_info:
* @mod: kmod module
@@ -2255,7 +2302,6 @@ KMOD_EXPORT int kmod_module_get_info(const struct kmod_module *mod, struct kmod_
if (kmod_module_signature_info(mod->file, &sig_info)) {
struct kmod_list *n;
- char *key_hex;
n = kmod_module_info_append(list, "sig_id", strlen("sig_id"),
sig_info.id_type, strlen(sig_info.id_type));
@@ -2269,30 +2315,13 @@ KMOD_EXPORT int kmod_module_get_info(const struct kmod_module *mod, struct kmod_
goto list_error;
count++;
- if (sig_info.key_id_len) {
- /* Display the key id as 01:12:DE:AD:BE:EF:... */
- key_hex = malloc(sig_info.key_id_len * 3);
- if (key_hex == NULL)
- goto list_error;
- for (i = 0; i < (int)sig_info.key_id_len; i++) {
- sprintf(key_hex + i * 3, "%02X",
- (unsigned char)sig_info.key_id[i]);
- if (i < (int)sig_info.key_id_len - 1)
- key_hex[i * 3 + 2] = ':';
- }
- n = kmod_module_info_append(list, "sig_key", strlen("sig_key"),
- key_hex, sig_info.key_id_len * 3 - 1);
- free(key_hex);
- if (n == NULL)
- goto list_error;
- count++;
- } else {
- n = kmod_module_info_append(list, "sig_key", strlen("sig_key"),
- NULL, 0);
- if (n == NULL)
- goto list_error;
- count++;
- }
+
+ n = kmod_module_info_append_hex(list, "sig_key", strlen("sig_key"),
+ sig_info.key_id,
+ sig_info.key_id_len);
+ if (n == NULL)
+ goto list_error;
+ count++;
n = kmod_module_info_append(list,
"sig_hashalgo", strlen("sig_hashalgo"),
--
2.9.2.368.g08bb350
next prev parent reply other threads:[~2017-04-11 12:15 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-11 12:14 [PATCH 0/4] modinfo: fix sig_id key and add signature output Yauheni Kaliuta
2017-04-11 12:15 ` [PATCH 1/4] libkmod: modinfo: fix sig_id output Yauheni Kaliuta
2017-04-11 12:15 ` Yauheni Kaliuta [this message]
2017-04-11 12:15 ` [PATCH 3/4] libkmod: modinfo: implement line splitting in hex_to_str Yauheni Kaliuta
2017-04-11 12:15 ` [PATCH 4/4] libkmod: modinfo: implement signature output Yauheni Kaliuta
2017-04-11 16:10 ` [PATCH 0/4] modinfo: fix sig_id key and add " Lucas De Marchi
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=20170411121503.26181-3-yauheni.kaliuta@redhat.com \
--to=yauheni.kaliuta@redhat.com \
--cc=linux-modules@vger.kernel.org \
--cc=linux-modules@z.dvxs.net \
--cc=lucas.de.marchi@gmail.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;
as well as URLs for NNTP newsgroup(s).