static void store_adapter_info(struct btd_adapter *adapter)
{
GKeyFile *key_file;
+ GError *gerr = NULL;
char filename[PATH_MAX];
char *str;
gsize length = 0;
create_file(filename, 0600);
str = g_key_file_to_data(key_file, &length, NULL);
- g_file_set_contents(filename, str, length, NULL);
+ if (!g_file_set_contents(filename, str, length, &gerr)) {
+ error("Unable set contents for %s: (%s)", filename,
+ gerr->message);
+ g_error_free(gerr);
+ }
g_free(str);
g_key_file_free(key_file);
struct bt_crypto *crypto;
char str_irk_out[33];
gsize length = 0;
+ GError *gerr = NULL;
char *str;
int i;
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);
+ if (!g_file_set_contents(filename, str, length, &gerr)) {
+ error("Unable set contents for %s: (%s)", filename,
+ gerr->message);
+ g_error_free(gerr);
+ }
g_free(str);
DBG("Generated IRK written to file");
return 0;
{
char filename[PATH_MAX];
GKeyFile *key_file;
+ GError *gerr = NULL;
char *str_irk;
int ret;
btd_adapter_get_storage_dir(adapter));
key_file = g_key_file_new();
- g_key_file_load_from_file(key_file, filename, 0, NULL);
+ if (!g_key_file_load_from_file(key_file, filename, 0, &gerr)) {
+ error("Unable to load key file from %s: (%s)", filename,
+ gerr->message);
+ g_error_free(gerr);
+ }
str_irk = g_key_file_get_string(key_file, "General",
"IdentityResolvingKey", NULL);
GSList *irks = NULL;
GSList *params = NULL;
GSList *added_devices = NULL;
+ GError *gerr = NULL;
DIR *dir;
struct dirent *entry;
entry->d_name);
key_file = g_key_file_new();
- g_key_file_load_from_file(key_file, filename, 0, NULL);
+ if (!g_key_file_load_from_file(key_file, filename, 0, &gerr)) {
+ error("Unable to load key file from %s: (%s)", filename,
+ gerr->message);
+ g_error_free(gerr);
+ }
key_info = get_key_info(key_file, entry->d_name);
char *str = key;
char filename[PATH_MAX];
GKeyFile *key_file;
+ GError *gerr = NULL;
char *data;
gsize length = 0;
create_file(filename, 0600);
key_file = g_key_file_new();
- g_key_file_load_from_file(key_file, filename, 0, NULL);
+ if (!g_key_file_load_from_file(key_file, filename, 0, &gerr)) {
+ error("Unable to load key file from %s: (%s)", filename,
+ gerr->message);
+ g_error_free(gerr);
+ }
g_key_file_set_string(key_file, "General", "Name", value);
data = g_key_file_to_data(key_file, &length, NULL);
- g_file_set_contents(filename, data, length, NULL);
+ if (!g_file_set_contents(filename, data, length, &gerr)) {
+ error("Unable set contents for %s: (%s)", filename,
+ gerr->message);
+ g_error_free(gerr);
+ }
g_free(data);
g_key_file_free(key_file);
char type = BDADDR_BREDR;
char filename[PATH_MAX];
GKeyFile *key_file;
+ GError *gerr = NULL;
char *data;
gsize length = 0;
converter->address, key);
key_file = g_key_file_new();
- g_key_file_load_from_file(key_file, filename, 0, NULL);
+ if (!g_key_file_load_from_file(key_file, filename, 0, &gerr)) {
+ error("Unable to load key file from %s: (%s)", filename,
+ gerr->message);
+ g_error_free(gerr);
+ }
set_device_type(key_file, type);
data = g_key_file_to_data(key_file, &length, NULL);
if (length > 0) {
create_file(filename, 0600);
- g_file_set_contents(filename, data, length, NULL);
+ if (!g_file_set_contents(filename, data, length, &gerr)) {
+ error("Unable set contents for %s: (%s)", filename,
+ gerr->message);
+ g_error_free(gerr);
+ }
}
g_free(data);
{
char filename[PATH_MAX];
GKeyFile *key_file;
+ GError *gerr = NULL;
char handle_str[11];
char *data;
gsize length = 0;
snprintf(filename, PATH_MAX, STORAGEDIR "/%s/cache/%s", local, peer);
key_file = g_key_file_new();
- g_key_file_load_from_file(key_file, filename, 0, NULL);
+ if (!g_key_file_load_from_file(key_file, filename, 0, &gerr)) {
+ error("Unable to load key file from %s: (%s)", filename,
+ gerr->message);
+ g_error_free(gerr);
+ }
sprintf(handle_str, "0x%8.8X", handle);
g_key_file_set_string(key_file, "ServiceRecords", handle_str, value);
data = g_key_file_to_data(key_file, &length, NULL);
if (length > 0) {
create_file(filename, 0600);
- g_file_set_contents(filename, data, length, NULL);
+ if (!g_file_set_contents(filename, data, length, &gerr)) {
+ error("Unable set contents for %s: (%s)", filename,
+ gerr->message);
+ g_error_free(gerr);
+ }
}
g_free(data);
int handle, ret;
char filename[PATH_MAX];
GKeyFile *key_file;
+ GError *gerr = NULL;
struct stat st;
sdp_record_t *rec;
uuid_t uuid;
dst_addr);
key_file = g_key_file_new();
- g_key_file_load_from_file(key_file, filename, 0, NULL);
+ if (!g_key_file_load_from_file(key_file, filename, 0, &gerr)) {
+ error("Unable to load key file from %s: (%s)", filename,
+ gerr->message);
+ g_error_free(gerr);
+ }
store_attribute_uuid(key_file, start, end, prim_uuid, uuid);
data = g_key_file_to_data(key_file, &length, NULL);
if (length > 0) {
create_file(filename, 0600);
- g_file_set_contents(filename, data, length, NULL);
+ if (!g_file_set_contents(filename, data, length, &gerr)) {
+ error("Unable set contents for %s: (%s)", filename,
+ gerr->message);
+ g_error_free(gerr);
+ }
}
g_free(data);
char **services, **service, *prim_uuid;
char filename[PATH_MAX];
GKeyFile *key_file;
+ GError *gerr = NULL;
int ret;
uint16_t start, end;
char uuid_str[MAX_LEN_UUID_STR + 1];
snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s/attributes", address,
key);
key_file = g_key_file_new();
- g_key_file_load_from_file(key_file, filename, 0, NULL);
+ if (!g_key_file_load_from_file(key_file, filename, 0, &gerr)) {
+ error("Unable to load key file from %s: (%s)", filename,
+ gerr->message);
+ g_error_free(gerr);
+ }
for (service = services; *service; service++) {
ret = sscanf(*service, "%04hX#%04hX#%s", &start, &end,
goto end;
create_file(filename, 0600);
- g_file_set_contents(filename, data, length, NULL);
+ if (!g_file_set_contents(filename, data, length, &gerr)) {
+ error("Unable set contents for %s: (%s)", filename,
+ gerr->message);
+ g_error_free(gerr);
+ }
if (device_type < 0)
goto end;
snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s/info", address, key);
key_file = g_key_file_new();
- g_key_file_load_from_file(key_file, filename, 0, NULL);
+ if (!g_key_file_load_from_file(key_file, filename, 0, &gerr)) {
+ error("Unable to load key file from %s: (%s)", filename,
+ gerr->message);
+ g_error_free(gerr);
+ }
set_device_type(key_file, device_type);
data = g_key_file_to_data(key_file, &length, NULL);
if (length > 0) {
create_file(filename, 0600);
- g_file_set_contents(filename, data, length, NULL);
+ if (!g_file_set_contents(filename, data, length, &gerr)) {
+ error("Unable set contents for %s: (%s)", filename,
+ gerr->message);
+ g_error_free(gerr);
+ }
}
end:
int ret, err;
char filename[PATH_MAX];
GKeyFile *key_file;
+ GError *gerr = NULL;
struct stat st;
char group[6];
char *data;
snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s/ccc", src_addr,
dst_addr);
key_file = g_key_file_new();
- g_key_file_load_from_file(key_file, filename, 0, NULL);
+ if (!g_key_file_load_from_file(key_file, filename, 0, &gerr)) {
+ error("Unable to load key file from %s: (%s)", filename,
+ gerr->message);
+ g_error_free(gerr);
+ }
sprintf(group, "%hu", handle);
g_key_file_set_string(key_file, group, "Value", value);
data = g_key_file_to_data(key_file, &length, NULL);
if (length > 0) {
create_file(filename, 0600);
- g_file_set_contents(filename, data, length, NULL);
+ if (!g_file_set_contents(filename, data, length, &gerr)) {
+ error("Unable set contents for %s: (%s)", filename,
+ gerr->message);
+ g_error_free(gerr);
+ }
}
g_free(data);
int ret, err;
char filename[PATH_MAX];
GKeyFile *key_file;
+ GError *gerr = NULL;
struct stat st;
char group[6];
char *data;
snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s/gatt", src_addr,
dst_addr);
key_file = g_key_file_new();
- g_key_file_load_from_file(key_file, filename, 0, NULL);
+ if (!g_key_file_load_from_file(key_file, filename, 0, &gerr)) {
+ error("Unable to load key file from %s: (%s)", filename,
+ gerr->message);
+ g_error_free(gerr);
+ }
sprintf(group, "%hu", handle);
g_key_file_set_string(key_file, group, "Value", value);
data = g_key_file_to_data(key_file, &length, NULL);
if (length > 0) {
create_file(filename, 0600);
- g_file_set_contents(filename, data, length, NULL);
+ if (!g_file_set_contents(filename, data, length, &gerr)) {
+ error("Unable set contents for %s: (%s)", filename,
+ gerr->message);
+ g_error_free(gerr);
+ }
}
g_free(data);
char *alert;
char filename[PATH_MAX];
GKeyFile *key_file;
+ GError *gerr = NULL;
struct stat st;
int err;
char *data;
snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s/proximity", src_addr,
key);
key_file = g_key_file_new();
- g_key_file_load_from_file(key_file, filename, 0, NULL);
+ if (!g_key_file_load_from_file(key_file, filename, 0, &gerr)) {
+ error("Unable to load key file from %s: (%s)", filename,
+ gerr->message);
+ g_error_free(gerr);
+ }
g_key_file_set_string(key_file, alert, "Level", value);
data = g_key_file_to_data(key_file, &length, NULL);
if (length > 0) {
create_file(filename, 0600);
- g_file_set_contents(filename, data, length, NULL);
+ if (!g_file_set_contents(filename, data, length, &gerr)) {
+ error("Unable set contents for %s: (%s)", filename,
+ gerr->message);
+ g_error_free(gerr);
+ }
}
g_free(data);
uint8_t mode;
char *data;
gsize length = 0;
+ GError *gerr = NULL;
ba2str(&adapter->bdaddr, address);
snprintf(config_path, PATH_MAX, STORAGEDIR "/%s/config", address);
create_file(filename, 0600);
data = g_key_file_to_data(key_file, &length, NULL);
- g_file_set_contents(filename, data, length, NULL);
+ if (!g_file_set_contents(filename, data, length, &gerr)) {
+ error("Unable set contents for %s: (%s)", filename,
+ gerr->message);
+ g_error_free(gerr);
+ }
g_free(data);
}
convert_device_storage(adapter);
}
- g_key_file_load_from_file(key_file, filename, 0, NULL);
+ if (!g_key_file_load_from_file(key_file, filename, 0, &gerr)) {
+ error("Unable to load key file from %s: (%s)", filename,
+ gerr->message);
+ g_error_free(gerr);
+ }
/* Get alias */
adapter->stored_alias = g_key_file_get_string(key_file, "General",
char device_addr[18];
char filename[PATH_MAX];
GKeyFile *key_file;
+ GError *gerr = NULL;
gsize length = 0;
char key_str[33];
char *str;
snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s/info",
btd_adapter_get_storage_dir(adapter), device_addr);
key_file = g_key_file_new();
- g_key_file_load_from_file(key_file, filename, 0, NULL);
+ if (!g_key_file_load_from_file(key_file, filename, 0, &gerr)) {
+ error("Unable to load key file from %s: (%s)", filename,
+ gerr->message);
+ g_error_free(gerr);
+ }
for (i = 0; i < 16; i++)
sprintf(key_str + (i * 2), "%2.2X", key[i]);
create_file(filename, 0600);
str = g_key_file_to_data(key_file, &length, NULL);
- g_file_set_contents(filename, str, length, NULL);
+ if (!g_file_set_contents(filename, str, length, &gerr)) {
+ error("Unable set contents for %s: (%s)", filename,
+ gerr->message);
+ g_error_free(gerr);
+ }
g_free(str);
g_key_file_free(key_file);
char device_addr[18];
char filename[PATH_MAX];
GKeyFile *key_file;
+ GError *gerr = NULL;
char key_str[33];
gsize length = 0;
char *str;
snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s/info",
btd_adapter_get_storage_dir(adapter), device_addr);
key_file = g_key_file_new();
- g_key_file_load_from_file(key_file, filename, 0, NULL);
+ if (!g_key_file_load_from_file(key_file, filename, 0, &gerr)) {
+ error("Unable to load key file from %s: (%s)", filename,
+ gerr->message);
+ g_error_free(gerr);
+ }
/* Old files may contain this so remove it in case it exists */
g_key_file_remove_key(key_file, "LongTermKey", "Master", NULL);
create_file(filename, 0600);
str = g_key_file_to_data(key_file, &length, NULL);
- g_file_set_contents(filename, str, length, NULL);
+ if (!g_file_set_contents(filename, str, length, &gerr)) {
+ error("Unable set contents for %s: (%s)", filename,
+ gerr->message);
+ g_error_free(gerr);
+ }
g_free(str);
g_key_file_free(key_file);
char device_addr[18];
char filename[PATH_MAX];
GKeyFile *key_file;
+ GError *gerr = NULL;
char key_str[33];
gsize length = 0;
gboolean auth;
btd_adapter_get_storage_dir(adapter), device_addr);
key_file = g_key_file_new();
- g_key_file_load_from_file(key_file, filename, 0, NULL);
+ if (!g_key_file_load_from_file(key_file, filename, 0, &gerr)) {
+ error("Unable to load key file from %s: (%s)", filename,
+ gerr->message);
+ g_error_free(gerr);
+ }
for (i = 0; i < 16; i++)
sprintf(key_str + (i * 2), "%2.2X", key[i]);
create_file(filename, 0600);
str = g_key_file_to_data(key_file, &length, NULL);
- g_file_set_contents(filename, str, length, NULL);
+ if (!g_file_set_contents(filename, str, length, &gerr)) {
+ error("Unable set contents for %s: (%s)", filename,
+ gerr->message);
+ g_error_free(gerr);
+ }
g_free(str);
g_key_file_free(key_file);
char device_addr[18];
char filename[PATH_MAX];
GKeyFile *key_file;
+ GError *gerr = NULL;
char *store_data;
char str[33];
size_t length = 0;
snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s/info",
btd_adapter_get_storage_dir(adapter), device_addr);
key_file = g_key_file_new();
- g_key_file_load_from_file(key_file, filename, 0, NULL);
+ if (!g_key_file_load_from_file(key_file, filename, 0, &gerr)) {
+ error("Unable to load key file from %s: (%s)", filename,
+ gerr->message);
+ g_error_free(gerr);
+ }
for (i = 0; i < 16; i++)
sprintf(str + (i * 2), "%2.2X", key[i]);
create_file(filename, 0600);
store_data = g_key_file_to_data(key_file, &length, NULL);
- g_file_set_contents(filename, store_data, length, NULL);
+ if (!g_file_set_contents(filename, store_data, length, &gerr)) {
+ error("Unable set contents for %s: (%s)", filename,
+ gerr->message);
+ g_error_free(gerr);
+ }
g_free(store_data);
g_key_file_free(key_file);
char device_addr[18];
char filename[PATH_MAX];
GKeyFile *key_file;
+ GError *gerr = NULL;
char *store_data;
size_t length = 0;
snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s/info",
btd_adapter_get_storage_dir(adapter), device_addr);
key_file = g_key_file_new();
- g_key_file_load_from_file(key_file, filename, 0, NULL);
+ if (!g_key_file_load_from_file(key_file, filename, 0, &gerr)) {
+ error("Unable to load key file from %s: (%s)", filename,
+ gerr->message);
+ g_error_free(gerr);
+ }
g_key_file_set_integer(key_file, "ConnectionParameters",
"MinInterval", min_interval);
create_file(filename, 0600);
store_data = g_key_file_to_data(key_file, &length, NULL);
- g_file_set_contents(filename, store_data, length, NULL);
+ if (!g_file_set_contents(filename, store_data, length, &gerr)) {
+ error("Unable set contents for %s: (%s)", filename,
+ gerr->message);
+ g_error_free(gerr);
+ }
g_free(store_data);
g_key_file_free(key_file);
char device_addr[18];
char filename[PATH_MAX];
GKeyFile *key_file;
+ GError *gerr = NULL;
gsize length = 0;
char *str;
snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s/info",
btd_adapter_get_storage_dir(adapter), device_addr);
key_file = g_key_file_new();
- g_key_file_load_from_file(key_file, filename, 0, NULL);
+ if (!g_key_file_load_from_file(key_file, filename, 0, &gerr)) {
+ error("Unable to load key file from %s: (%s)", filename,
+ gerr->message);
+ g_error_free(gerr);
+ }
if (type == BDADDR_BREDR) {
g_key_file_remove_group(key_file, "LinkKey", NULL);
}
str = g_key_file_to_data(key_file, &length, NULL);
- g_file_set_contents(filename, str, length, NULL);
+ if (!g_file_set_contents(filename, str, length, &gerr)) {
+ error("Unable set contents for %s: (%s)", filename,
+ gerr->message);
+ g_error_free(gerr);
+ }
g_free(str);
g_key_file_free(key_file);
{
struct bt_crypto *crypto;
GKeyFile *file;
+ GError *gerr = NULL;
char **addrs;
char mfg[7];
char *str;
snprintf(mfg, sizeof(mfg), "0x%04x", adapter->manufacturer);
file = g_key_file_new();
- g_key_file_load_from_file(file, STORAGEDIR "/addresses", 0, NULL);
+ if (!g_key_file_load_from_file(file, STORAGEDIR "/addresses", 0,
+ &gerr)) {
+ error("Unable to load key file from %s: (%s)",
+ STORAGEDIR "/addresses", gerr->message);
+ g_error_free(gerr);
+ }
addrs = g_key_file_get_string_list(file, "Static", mfg, &len, NULL);
if (addrs) {
for (i = 0; i < len; i++) {
(const char **)addrs, len);
str = g_key_file_to_data(file, &len, NULL);
- g_file_set_contents(STORAGEDIR "/addresses", str, len, NULL);
+ if (!g_file_set_contents(STORAGEDIR "/addresses", str, len, &gerr)) {
+ error("Unable set contents for %s: (%s)",
+ STORAGEDIR "/addresses", gerr->message);
+ g_error_free(gerr);
+ }
g_free(str);
ret = true;