From: Kai Ruhnau <kai.ruhnau@target-sg.com>
To: "linux-bluetooth@vger.kernel.org" <linux-bluetooth@vger.kernel.org>
Subject: AW: [PATCH] adapter: Fix storing the IRK on first boot.
Date: Wed, 12 Dec 2018 09:42:30 +0000 [thread overview]
Message-ID: <AM0PR02MB3841F981781246B5E2C3BD17C5A70@AM0PR02MB3841.eurprd02.prod.outlook.com> (raw)
In-Reply-To: <VI1PR02MB3856F0C3AED16B014F91C0D9C5AA0@VI1PR02MB3856.eurprd02.prod.outlook.com>
Hi,
Well, this is a bit embarrassing, but let me try again without the breaking exclamation mark.
Cheers,
Kai
From: Kai Ruhnau <kai.ruhnau@target-sg.com>
generate_and_write_irk doesn't create the adapter directory and
doesn't check for errors when persisting the IRK which currently
fails on first boot. This fixes both.
Signed-off-by: Kai Ruhnau <kai.ruhnau@target-sg.com>
---
src/adapter.c | 24 ++++++++++++++++++++++--
1 file changed, 22 insertions(+), 2 deletions(-)
diff --git a/src/adapter.c b/src/adapter.c
index c24432125..d93ae2618 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -3623,6 +3623,7 @@ static int generate_and_write_irk(uint8_t *irk, GKeyFile *key_file,
gsize length = 0;
char *str;
int i;
+ GError *gerr = NULL;
crypto = bt_crypto_new();
if (!crypto) {
@@ -3646,9 +3647,28 @@ static int generate_and_write_irk(uint8_t *irk, GKeyFile *key_file,
g_key_file_set_string(key_file, "General", "IdentityResolvingKey",
str_irk_out);
- str = g_key_file_to_data(key_file, &length, NULL);
- g_file_set_contents(filename, str, length, NULL);
+ str = g_key_file_to_data(key_file, &length, &gerr);
+ if (gerr)
+ {
+ error("Failed to create IRK file contents: %s", gerr->message);
+ g_error_free(gerr);
+ return -1;
+ }
+ if (create_file(filename, S_IRUSR | S_IWUSR))
+ {
+ error("Failed to create IRK file");
+ g_free(str);
+ return -1;
+ }
+ g_file_set_contents(filename, str, length, &gerr);
g_free(str);
+ if (gerr)
+ {
+ error("Failed to store IRK file contents: %s", gerr->message);
+ g_error_free(gerr);
+ return -1;
+ }
+
DBG("Generated IRK written to file");
return 0;
}
--
2.19.1
--
Kai Ruhnau
Software Manager
T:+49 202 769302 19
Target Systemelektronik GmbH & Co. KG
Heinz-Fangman-Straße 4
42287 Wuppertal
Amtsgericht Wuppertal HRA 23898
Persönlich haftende Gesellschafterin
Target Systemelektronik Beteiligungs GmbH
Heinz-Fangman-Straße 4, 42287 Wuppertal
Amtsgericht Wuppertal HRB 25346
Geschäftsführer: Jürgen Stein
--
prev parent reply other threads:[~2018-12-12 9:43 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-07 8:40 [PATCH] adapter: Fix storing the IRK on first boot Kai Ruhnau
2018-12-12 9:42 ` Kai Ruhnau [this message]
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=AM0PR02MB3841F981781246B5E2C3BD17C5A70@AM0PR02MB3841.eurprd02.prod.outlook.com \
--to=kai.ruhnau@target-sg.com \
--cc=linux-bluetooth@vger.kernel.org \
/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).