mirror of
https://git.kernel.org/pub/scm/network/wireless/iwd.git
synced 2025-01-21 10:34:07 +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:
parent
44ebf10bb9
commit
abcc9f1647
46
src/util.c
46
src/util.c
@ -160,3 +160,49 @@ bool util_is_broadcast_address(const uint8_t *addr)
|
|||||||
|
|
||||||
return !memcmp(addr, bcast_addr, 6);
|
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;
|
||||||
|
}
|
||||||
|
@ -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_group_address(const uint8_t *addr);
|
||||||
bool util_is_broadcast_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)
|
static inline uint8_t util_bit_field(const uint8_t oct, int start, int num)
|
||||||
{
|
{
|
||||||
unsigned char mask = (1 << num) - 1;
|
unsigned char mask = (1 << num) - 1;
|
||||||
|
Loading…
Reference in New Issue
Block a user