commit abcc9f16474898de076168e023eb8f17c7ed8d11
parent 44ebf10bb9471473323ef6d7cfbf8c9e5ae46dc8
Author: James Prestwood <james.prestwood@linux.intel.com>
Date: Mon, 8 Apr 2019 11:15:19 -0700
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.
Diffstat:
2 files changed, 49 insertions(+), 0 deletions(-)
diff --git a/src/util.c b/src/util.c
@@ -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;
+}
diff --git a/src/util.h b/src/util.h
@@ -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;