]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
lib/util: let server_id_str_buf_unique() use server_id_buf
authorStefan Metzmacher <metze@samba.org>
Fri, 2 Aug 2024 06:25:16 +0000 (08:25 +0200)
committerStefan Metzmacher <metze@samba.org>
Wed, 21 Aug 2024 08:02:30 +0000 (08:02 +0000)
BUG: https://bugzilla.samba.org/show_bug.cgi?id=15693

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
lib/util/server_id.c
lib/util/server_id.h
lib/util/server_id_db.c

index 8e72a722080704044f95b5f0c6f726ca2eb61651..2370163da80da64c6f9378ec1706177f4f76c5be 100644 (file)
@@ -91,26 +91,9 @@ char *server_id_str_buf_unique_ex(struct server_id id,
        return dst->buf;
 }
 
-size_t server_id_str_buf_unique(struct server_id id, char *buf, size_t buflen)
+char *server_id_str_buf_unique(struct server_id id, struct server_id_buf *dst)
 {
-       struct server_id_buf idbuf;
-       char unique_buf[21];    /* 2^64 is 18446744073709551616, 20 chars */
-       size_t idlen, unique_len, needed;
-
-       server_id_str_buf(id, &idbuf);
-
-       idlen = strlen(idbuf.buf);
-       unique_len = snprintf(unique_buf, sizeof(unique_buf), "%"PRIu64,
-                             id.unique_id);
-       needed = idlen + unique_len + 2;
-
-       if (buflen >= needed) {
-               memcpy(buf, idbuf.buf, idlen);
-               buf[idlen] = '/';
-               memcpy(buf + idlen + 1, unique_buf, unique_len+1);
-       }
-
-       return needed;
+       return server_id_str_buf_unique_ex(id, '/', dst);
 }
 
 struct server_id server_id_from_string(uint32_t local_vnn,
index bef2af2ad6f6e9c69de6b48597050321842ef060..c9630b7f7749f2dc0a4f6403accba1635a7f12ee 100644 (file)
@@ -52,7 +52,8 @@ 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);
+char *server_id_str_buf_unique(struct server_id id,
+                              struct server_id_buf *dst);
 
 struct server_id server_id_from_string(uint32_t local_vnn,
                                       const char *pid_string);
index 17b157706b477866226c99108fdb0f818c5f0920..c5cbdee9eef8fa171612c6c2e1b2d3db4a82b21d 100644 (file)
@@ -111,10 +111,9 @@ int server_id_db_add(struct server_id_db *db, const char *name)
        key = string_term_tdb_data(name);
 
        {
-               size_t idlen = server_id_str_buf_unique(db->pid, NULL, 0);
-               char idbuf[idlen];
-
-               server_id_str_buf_unique(db->pid, idbuf, idlen);
+               struct server_id_buf _buf;
+               char *idbuf = server_id_str_buf_unique(db->pid, &_buf);
+               size_t idlen = strlen(idbuf) + 1;
 
                ret = tdb_append(
                        tdb, key,
@@ -134,8 +133,8 @@ int server_id_db_prune_name(struct server_id_db *db, const char *name,
                            struct server_id server)
 {
        struct tdb_context *tdb = db->tdb->tdb;
-       size_t idbuf_len = server_id_str_buf_unique(server, NULL, 0);
-       char idbuf[idbuf_len];
+       struct server_id_buf _buf;
+       char *idbuf = server_id_str_buf_unique(server, &_buf);
        TDB_DATA key;
        uint8_t *data;
        size_t datalen;
@@ -143,7 +142,6 @@ int server_id_db_prune_name(struct server_id_db *db, const char *name,
        int ret;
 
        key = string_term_tdb_data(name);
-       server_id_str_buf_unique(server, idbuf, idbuf_len);
 
        ret = tdb_chainlock(tdb, key);
        if (ret == -1) {