linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Kai Ruhnau <kai.ruhnau@target-sg.com>
To: "linux-bluetooth@vger.kernel.org" <linux-bluetooth@vger.kernel.org>
Subject: [PATCH] adapter: Fix storing the IRK on first boot.
Date: Fri, 7 Dec 2018 08:40:02 +0000	[thread overview]
Message-ID: <VI1PR02MB3856F0C3AED16B014F91C0D9C5AA0@VI1PR02MB3856.eurprd02.prod.outlook.com> (raw)

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
--

             reply	other threads:[~2018-12-07  8:40 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-07  8:40 Kai Ruhnau [this message]
2018-12-12  9:42 ` AW: [PATCH] adapter: Fix storing the IRK on first boot Kai Ruhnau

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=VI1PR02MB3856F0C3AED16B014F91C0D9C5AA0@VI1PR02MB3856.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).