[PATCH] adapter: Fix storing the IRK on first boot.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Kai Ruhnau <kai.ruhnau@xxxxxxxxxxxxx>

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




[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux