From: Stefan Metzmacher Date: Fri, 2 Aug 2024 06:25:16 +0000 (+0200) Subject: lib/util: add server_id_str_buf_unique_ex() and allow the delimiter to be passed in X-Git-Tag: tdb-1.4.13~1323 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=86952314036e5b6395f113c5968df794f5f95574;p=thirdparty%2Fsamba.git lib/util: add server_id_str_buf_unique_ex() and allow the delimiter to be passed in This way the server_id_str_buf() can just be a tiny wrapper using '\0' as delemiter. In future it also allows to specifiy another delemiter than '/' in order to use the resulting buffer as part of a file/directory name. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15693 Signed-off-by: Stefan Metzmacher Reviewed-by: Ralph Boehme --- diff --git a/lib/util/server_id.c b/lib/util/server_id.c index 799c8881f71..7ea5d7aa64e 100644 --- a/lib/util/server_id.c +++ b/lib/util/server_id.c @@ -55,20 +55,38 @@ bool server_id_equal(const struct server_id *p1, const struct server_id *p2) char *server_id_str_buf(struct server_id id, struct server_id_buf *dst) { + return server_id_str_buf_unique_ex(id, '\0', dst); +} + +char *server_id_str_buf_unique_ex(struct server_id id, + char unique_delimiter, + struct server_id_buf *dst) +{ + if (id.unique_id == SERVERID_UNIQUE_ID_NOT_TO_VERIFY) { + unique_delimiter = '\0'; + } + if (server_id_is_disconnected(&id)) { strlcpy(dst->buf, "disconnected", sizeof(dst->buf)); } else if ((id.vnn == NONCLUSTER_VNN) && (id.task_id == 0)) { - snprintf(dst->buf, sizeof(dst->buf), "%"PRIu64"", - id.pid); + snprintf(dst->buf, sizeof(dst->buf), + "%"PRIu64"%c%"PRIu64"", + id.pid, unique_delimiter, id.unique_id); } else if (id.vnn == NONCLUSTER_VNN) { - snprintf(dst->buf, sizeof(dst->buf), "%"PRIu64".%"PRIu32"", - id.pid, id.task_id); + snprintf(dst->buf, sizeof(dst->buf), + "%"PRIu64".%"PRIu32"%c%"PRIu64"", + id.pid, id.task_id, + unique_delimiter, id.unique_id); } else if (id.task_id == 0) { - snprintf(dst->buf, sizeof(dst->buf), "%"PRIu32":%"PRIu64"", - id.vnn, id.pid); + snprintf(dst->buf, sizeof(dst->buf), + "%"PRIu32":%"PRIu64"%c%"PRIu64"", + id.vnn, id.pid, + unique_delimiter, id.unique_id); } else { - snprintf(dst->buf, sizeof(dst->buf), "%"PRIu32":%"PRIu64".%"PRIu32"", - id.vnn, id.pid, id.task_id); + snprintf(dst->buf, sizeof(dst->buf), + "%"PRIu32":%"PRIu64".%"PRIu32"%c%"PRIu64"", + id.vnn, id.pid, id.task_id, + unique_delimiter, id.unique_id); } return dst->buf; } diff --git a/lib/util/server_id.h b/lib/util/server_id.h index 988dd56de65..77cbd045a28 100644 --- a/lib/util/server_id.h +++ b/lib/util/server_id.h @@ -37,9 +37,11 @@ struct server_id_buf { * * The largest has 10 + 1 + 20 + 1 + 10 + 1 = 43 chars * - * Then we align it to a multiple of 8. + * Optionally we allow :UNIQUE64 added, + * which adds 21 chars, so we are at 64 chars + * and that's 8 byte aligned. */ - char buf[48]; + char buf[64]; }; bool server_id_same_process(const struct server_id *p1, @@ -47,6 +49,9 @@ bool server_id_same_process(const struct server_id *p1, int server_id_cmp(const struct server_id *p1, const struct server_id *p2); bool server_id_equal(const struct server_id *p1, const struct server_id *p2); char *server_id_str_buf(struct server_id id, struct server_id_buf *dst); +char *server_id_str_buf_unique_ex(struct server_id id, + char unique_delimiter, + struct server_id_buf *dst); size_t server_id_str_buf_unique(struct server_id id, char *buf, size_t buflen); struct server_id server_id_from_string(uint32_t local_vnn,