Linux-Bluetooth Archive on lore.kernel.org
 help / 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	[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	[flat|nested] 2+ messages in thread

end of thread, back to index

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

Linux-Bluetooth Archive on lore.kernel.org

Archives are clonable: git clone --mirror https://lore.kernel.org/linux-bluetooth/0 linux-bluetooth/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-bluetooth linux-bluetooth/ https://lore.kernel.org/linux-bluetooth \
		linux-bluetooth@vger.kernel.org linux-bluetooth@archiver.kernel.org
	public-inbox-index linux-bluetooth


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-bluetooth


AGPL code for this site: git clone https://public-inbox.org/ public-inbox