diff options
author | Andrew Bartlett <abartlet@samba.org> | 2004-10-29 08:31:27 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 13:05:00 -0500 |
commit | 659332794871c64470fd23b5a15e1f45fcb78a84 (patch) | |
tree | b3641918b078973c2c675d5cdf5cfe566a310a14 /source4/libcli | |
parent | dbf03959244c392073281c10badd2095397ad2f2 (diff) | |
download | samba-659332794871c64470fd23b5a15e1f45fcb78a84.tar.gz samba-659332794871c64470fd23b5a15e1f45fcb78a84.tar.bz2 samba-659332794871c64470fd23b5a15e1f45fcb78a84.zip |
r3358: Try to put all the basic struct dom_sid manipulation functions in one
place. (I always have trouble finding one half or the other).
Andrew Bartlett
(This used to be commit 224b59edba7c00ad515b4c5e3e9a886700247ad4)
Diffstat (limited to 'source4/libcli')
-rw-r--r-- | source4/libcli/util/dom_sid.c | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/source4/libcli/util/dom_sid.c b/source4/libcli/util/dom_sid.c index c2d188abec..1faf3debab 100644 --- a/source4/libcli/util/dom_sid.c +++ b/source4/libcli/util/dom_sid.c @@ -23,6 +23,39 @@ #include "includes.h" /* + convert a dom_sid to a string +*/ +char *dom_sid_string(TALLOC_CTX *mem_ctx, const struct dom_sid *sid) +{ + int i, ofs, maxlen; + uint32_t ia; + char *ret; + + if (!sid) { + return talloc_strdup(mem_ctx, "(NULL SID)"); + } + + maxlen = sid->num_auths * 11 + 25; + ret = talloc(mem_ctx, maxlen); + if (!ret) return talloc_strdup(mem_ctx, "(SID ERR)"); + + ia = (sid->id_auth[5]) + + (sid->id_auth[4] << 8 ) + + (sid->id_auth[3] << 16) + + (sid->id_auth[2] << 24); + + ofs = snprintf(ret, maxlen, "S-%u-%lu", + (uint_t)sid->sid_rev_num, (unsigned long)ia); + + for (i = 0; i < sid->num_auths; i++) { + ofs += snprintf(ret + ofs, maxlen - ofs, "-%lu", (unsigned long)sid->sub_auths[i]); + } + + return ret; +} + + +/* convert a string to a dom_sid, returning a talloc'd dom_sid */ struct dom_sid *dom_sid_parse_talloc(TALLOC_CTX *mem_ctx, const char *sidstr) @@ -121,3 +154,27 @@ struct dom_sid *dom_sid_dup(TALLOC_CTX *mem_ctx, struct dom_sid *dom_sid) return ret; } +/* + add a rid to a domain dom_sid to make a full dom_sid +*/ +struct dom_sid *dom_sid_add_rid(TALLOC_CTX *mem_ctx, + const struct dom_sid *domain_sid, + uint32_t rid) +{ + struct dom_sid *sid; + + sid = talloc_p(mem_ctx, struct dom_sid); + if (!sid) return NULL; + + *sid = *domain_sid; + /*TODO: use realloc! */ + sid->sub_auths = talloc_array_p(mem_ctx, uint32_t, sid->num_auths+1); + if (!sid->sub_auths) { + return NULL; + } + memcpy(sid->sub_auths, domain_sid->sub_auths, sid->num_auths*sizeof(uint32_t)); + sid->sub_auths[sid->num_auths] = rid; + sid->num_auths++; + return sid; +} + |