97 lines
2.2 KiB
Diff
97 lines
2.2 KiB
Diff
From a4aa0d00f588ba24484db70aeb3bdafdf618c4f6 Mon Sep 17 00:00:00 2001
|
|
From: Samuel Cabrero <scabrero@suse.de>
|
|
Date: Thu, 31 Aug 2023 13:39:12 +0200
|
|
Subject: [PATCH 01/17] disco: Add functions to extract domain GUID from LDAP
|
|
ping
|
|
|
|
Signed-off-by: Samuel Cabrero <scabrero@suse.de>
|
|
---
|
|
library/addisco.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++
|
|
1 file changed, 72 insertions(+)
|
|
|
|
diff --git a/library/addisco.c b/library/addisco.c
|
|
index b2c5553..ac073e5 100644
|
|
--- a/library/addisco.c
|
|
+++ b/library/addisco.c
|
|
@@ -335,6 +335,78 @@ get_32_le (unsigned char **at,
|
|
return 1;
|
|
}
|
|
|
|
+static int
|
|
+get_16_le (unsigned char **at,
|
|
+ unsigned char *end,
|
|
+ uint16_t *val)
|
|
+{
|
|
+ unsigned char *p = *at;
|
|
+ if (end - p < 2)
|
|
+ return 0;
|
|
+ *val = p[0] | p[1] << 8;
|
|
+ (*at) += 2;
|
|
+ return 1;
|
|
+}
|
|
+
|
|
+struct GUID {
|
|
+ uint32_t time_low;
|
|
+ uint16_t time_mid;
|
|
+ uint16_t time_hi_and_version;
|
|
+ uint8_t clock_seq[2];
|
|
+ uint8_t node[6];
|
|
+};
|
|
+
|
|
+/* Format is "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x" */
|
|
+/* 32 chars + 4 ' ' + \0 + 2 for adding {} */
|
|
+struct GUID_txt_buf {
|
|
+ char buf[39];
|
|
+};
|
|
+
|
|
+static char *GUID_buf_string(const struct GUID *guid,
|
|
+ struct GUID_txt_buf *dst)
|
|
+{
|
|
+ if (guid == NULL) {
|
|
+ return NULL;
|
|
+ }
|
|
+ snprintf(dst->buf, sizeof(dst->buf),
|
|
+ "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
|
|
+ guid->time_low, guid->time_mid,
|
|
+ guid->time_hi_and_version,
|
|
+ guid->clock_seq[0],
|
|
+ guid->clock_seq[1],
|
|
+ guid->node[0], guid->node[1],
|
|
+ guid->node[2], guid->node[3],
|
|
+ guid->node[4], guid->node[5]);
|
|
+ return dst->buf;
|
|
+}
|
|
+
|
|
+static int
|
|
+parse_guid (unsigned char **at,
|
|
+ unsigned char *end,
|
|
+ char **result)
|
|
+{
|
|
+ struct GUID g = { 0 };
|
|
+ struct GUID_txt_buf buf;
|
|
+
|
|
+ if (end - (*at) < sizeof(struct GUID)) {
|
|
+ return 0;
|
|
+ }
|
|
+
|
|
+ get_32_le(at, end, &g.time_low);
|
|
+ get_16_le(at, end, &g.time_mid);
|
|
+ get_16_le(at, end, &g.time_hi_and_version);
|
|
+
|
|
+ memcpy(&g.clock_seq, *at, sizeof(g.clock_seq));
|
|
+ (*at) += sizeof(g.clock_seq);
|
|
+
|
|
+ memcpy(&g.node, *at, sizeof(g.node));
|
|
+ (*at) += sizeof(g.node);
|
|
+
|
|
+ *result = strdup(GUID_buf_string(&g, &buf));
|
|
+
|
|
+ return 1;
|
|
+}
|
|
+
|
|
static int
|
|
skip_n (unsigned char **at,
|
|
unsigned char *end,
|
|
--
|
|
2.47.0
|
|
|