linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] adapter: Fix storing the IRK on first boot.
@ 2018-12-07  8:40 Kai Ruhnau
  2018-12-12  9:42 ` AW: " Kai Ruhnau
  0 siblings, 1 reply; 2+ messages in thread
From: Kai Ruhnau @ 2018-12-07  8:40 UTC (permalink / raw)
  To: linux-bluetooth

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

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* AW: [PATCH] adapter: Fix storing the IRK on first boot.
  2018-12-07  8:40 [PATCH] adapter: Fix storing the IRK on first boot Kai Ruhnau
@ 2018-12-12  9:42 ` Kai Ruhnau
  0 siblings, 0 replies; 2+ messages in thread
From: Kai Ruhnau @ 2018-12-12  9:42 UTC (permalink / raw)
  To: linux-bluetooth

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

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-12-12  9:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-07  8:40 [PATCH] adapter: Fix storing the IRK on first boot Kai Ruhnau
2018-12-12  9:42 ` AW: " Kai Ruhnau

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