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

util: add APIs to get username/domain from identity

mschaputil already had similar functionality, but ERP will need this
as well. These two functions will also handle identities with either
'@' or '\' to separate the user and domain.
This commit is contained in:
James Prestwood 2019-04-08 11:15:19 -07:00 committed by Denis Kenzior
parent 44ebf10bb9
commit abcc9f1647
2 changed files with 49 additions and 0 deletions

View File

@ -160,3 +160,49 @@ bool util_is_broadcast_address(const uint8_t *addr)
return !memcmp(addr, bcast_addr, 6);
}
const char *util_get_domain(const char *identity)
{
static char domain[256];
const char *c;
memset(domain, 0, sizeof(domain));
for (c = identity; *c; c++) {
switch (*c) {
case '\\':
strncpy(domain, identity, c - identity);
return domain;
case '@':
strcpy(domain, c + 1);
return domain;
default:
continue;
}
}
return identity;
}
const char *util_get_username(const char *identity)
{
static char username[256];
const char *c;
memset(username, 0, sizeof(username));
for (c = identity; *c; c++) {
switch (*c) {
case '\\':
strcpy(username, c + 1);
return username;
case '@':
strncpy(username, identity, c - identity);
return username;
default:
continue;
}
}
return identity;
}

View File

@ -39,6 +39,9 @@ bool util_string_to_address(const char *str, uint8_t *addr);
bool util_is_group_address(const uint8_t *addr);
bool util_is_broadcast_address(const uint8_t *addr);
const char *util_get_domain(const char *identity);
const char *util_get_username(const char *identity);
static inline uint8_t util_bit_field(const uint8_t oct, int start, int num)
{
unsigned char mask = (1 << num) - 1;