3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-11-23 07:29:28 +01:00

storage: Add storage_network_ssid_from_path

The operation opposite to get_network_file_path.
This commit is contained in:
Andrew Zaborowski 2016-06-09 19:55:24 +02:00 committed by Denis Kenzior
parent 11f23d500c
commit b6c9508912
2 changed files with 61 additions and 0 deletions

View File

@ -37,6 +37,7 @@
#include <ell/ell.h> #include <ell/ell.h>
#include "common.h"
#include "storage.h" #include "storage.h"
#ifdef TEMP_FAILURE_RETRY #ifdef TEMP_FAILURE_RETRY
@ -191,6 +192,63 @@ static char *get_network_file_path(const char *type, const char *ssid)
return path; return path;
} }
char *storage_network_ssid_from_path(const char *path, enum security *type)
{
const char *filename = strrchr(path, '/');
const char *c, *end;
char *decoded;
static char buf[67];
if (filename)
filename++; /* Skip the / */
else
filename = path;
end = strchr(filename, '.');
if (!end || !security_from_str(end + 1, type))
return NULL;
if (filename[0] != '=') {
if (end == filename || end - filename > 32)
return NULL;
for (c = filename; c < end; c++)
if (!isalnum(*c) && !strchr("-_ ", *c))
break;
if (c < end)
return NULL;
memcpy(buf, filename, end - filename);
buf[end - filename] = '\0';
return buf;
}
if (end - filename <= 1 || end - filename > 65)
return NULL;
memcpy(buf, filename + 1, end - filename - 1);
buf[end - filename - 1] = '0';
buf[end - filename + 0] = '0';
buf[end - filename + 1] = '\0';
decoded = (char *) l_util_from_hexstring(buf, NULL);
if (!decoded)
return NULL;
if (!l_utf8_validate(decoded, (end - filename) / 2, NULL)) {
l_free(decoded);
return NULL;
}
strcpy(buf, decoded);
l_free(decoded);
return buf;
}
struct l_settings *storage_network_open(const char *type, const char *ssid) struct l_settings *storage_network_open(const char *type, const char *ssid)
{ {
struct l_settings *settings; struct l_settings *settings;

View File

@ -21,6 +21,7 @@
*/ */
struct l_settings; struct l_settings;
enum security;
int create_dirs(const char *filename); int create_dirs(const char *filename);
@ -30,6 +31,8 @@ ssize_t read_file(void *buffer, size_t len, const char *path_fmt, ...)
ssize_t write_file(const void *buffer, size_t len, const char *path_fmt, ...) ssize_t write_file(const void *buffer, size_t len, const char *path_fmt, ...)
__attribute__((format(printf, 3, 4))); __attribute__((format(printf, 3, 4)));
char *storage_network_ssid_from_path(const char *path, enum security *type);
struct l_settings *storage_network_open(const char *type, const char *ssid); struct l_settings *storage_network_open(const char *type, const char *ssid);
int storage_network_touch(const char *type, const char *ssid); int storage_network_touch(const char *type, const char *ssid);
int storage_network_get_mtime(const char *type, const char *ssid, int storage_network_get_mtime(const char *type, const char *ssid,