lib: Add dom_sid_str_buf
authorVolker Lendecke <vl@samba.org>
Thu, 18 Oct 2018 03:46:37 +0000 (05:46 +0200)
committerJeremy Allison <jra@samba.org>
Fri, 2 Nov 2018 19:11:11 +0000 (20:11 +0100)
This is modeled after server_id_str_buf, which as an API to me is easier to
use: I can rely on the compiler to get the buffer size right.

It is designed to violate README.Coding's "Make use of helper variables", but
as this API is simple enough and the output should never be a surprise at all,
I think that's worth it.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
Autobuild-User(master): Jeremy Allison <jra@samba.org>
Autobuild-Date(master): Fri Nov  2 20:11:11 CET 2018 on sn-devel-144

libcli/security/dom_sid.c
libcli/security/dom_sid.h

index d913f2d93fb00989797511e53e10baf112a5347f..97f719f3082b78b882d6e39c4c5d2187bf14d399 100644 (file)
@@ -505,3 +505,13 @@ char *dom_sid_string(TALLOC_CTX *mem_ctx, const struct dom_sid *sid)
        talloc_set_name_const(result, result);
        return result;
 }
+
+char *dom_sid_str_buf(const struct dom_sid *sid, struct dom_sid_buf *dst)
+{
+       int ret;
+       ret = dom_sid_string_buf(sid, dst->buf, sizeof(dst->buf));
+       if ((ret < 0) || (ret >= sizeof(dst->buf))) {
+               strlcpy(dst->buf, "(INVALID SID)", sizeof(dst->buf));
+       }
+       return dst->buf;
+}
index d9f4b3fc8a6004d5d987aa82cc069c14188fa2d0..d132628da9f33dbf9505ca475d6bc25aeff4b03c 100644 (file)
@@ -102,6 +102,8 @@ bool dom_sid_is_valid_account_domain(const struct dom_sid *sid);
 int dom_sid_string_buf(const struct dom_sid *sid, char *buf, int buflen);
 char *dom_sid_string(TALLOC_CTX *mem_ctx, const struct dom_sid *sid);
 
+struct dom_sid_buf { char buf[DOM_SID_STR_BUFLEN]; };
+char *dom_sid_str_buf(const struct dom_sid *sid, struct dom_sid_buf *dst);
 
 const char *sid_type_lookup(uint32_t sid_type);
 const struct security_token *get_system_token(void);