mirror of
https://github.com/samba-team/samba.git
synced 2025-01-11 05:18:09 +03:00
Use dom_sid_string for sid_string_talloc
Remove some code duplication, but introduce one more dependency on librpc/ndr.
Easily turned around so that librpc/ndr depends on lib/util_sid if necessary
(This used to be commit 3a0b1b2060
)
This commit is contained in:
parent
4312ad8b98
commit
79cd97cc3f
@ -174,40 +174,23 @@ const char *get_global_sam_name(void)
|
|||||||
|
|
||||||
char *sid_to_string(fstring sidstr_out, const DOM_SID *sid)
|
char *sid_to_string(fstring sidstr_out, const DOM_SID *sid)
|
||||||
{
|
{
|
||||||
char subauth[16];
|
char *str = sid_string_talloc(talloc_tos(), sid);
|
||||||
int i;
|
fstrcpy(sidstr_out, str);
|
||||||
uint32 ia;
|
TALLOC_FREE(str);
|
||||||
|
|
||||||
if (!sid) {
|
|
||||||
fstrcpy(sidstr_out, "(NULL SID)");
|
|
||||||
return sidstr_out;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* BIG NOTE: this function only does SIDS where the identauth is not >= 2^32
|
|
||||||
* in a range of 2^48.
|
|
||||||
*/
|
|
||||||
ia = (sid->id_auth[5]) +
|
|
||||||
(sid->id_auth[4] << 8 ) +
|
|
||||||
(sid->id_auth[3] << 16) +
|
|
||||||
(sid->id_auth[2] << 24);
|
|
||||||
|
|
||||||
slprintf(sidstr_out, sizeof(fstring) - 1, "S-%u-%lu", (unsigned int)sid->sid_rev_num, (unsigned long)ia);
|
|
||||||
|
|
||||||
for (i = 0; i < sid->num_auths; i++) {
|
|
||||||
slprintf(subauth, sizeof(subauth)-1, "-%lu", (unsigned long)sid->sub_auths[i]);
|
|
||||||
fstrcat(sidstr_out, subauth);
|
|
||||||
}
|
|
||||||
|
|
||||||
return sidstr_out;
|
return sidstr_out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*****************************************************************
|
||||||
|
Essentially a renamed dom_sid_string from librpc/ndr with a
|
||||||
|
panic if it didn't work
|
||||||
|
|
||||||
|
This introduces a dependency on librpc/ndr/sid.o which can easily
|
||||||
|
be turned around if necessary
|
||||||
|
*****************************************************************/
|
||||||
|
|
||||||
char *sid_string_talloc(TALLOC_CTX *mem_ctx, const DOM_SID *sid)
|
char *sid_string_talloc(TALLOC_CTX *mem_ctx, const DOM_SID *sid)
|
||||||
{
|
{
|
||||||
fstring sid_str;
|
char *result = dom_sid_string(mem_ctx, sid);
|
||||||
char *result;
|
|
||||||
sid_to_string(sid_str, sid);
|
|
||||||
result = talloc_strdup(mem_ctx, sid_str);
|
|
||||||
SMB_ASSERT(result != NULL);
|
SMB_ASSERT(result != NULL);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -75,6 +75,11 @@ char *dom_sid_string(TALLOC_CTX *mem_ctx, const struct dom_sid *sid)
|
|||||||
ret = (char *)talloc_size(mem_ctx, maxlen);
|
ret = (char *)talloc_size(mem_ctx, maxlen);
|
||||||
if (!ret) return talloc_strdup(mem_ctx, "(SID ERR)");
|
if (!ret) return talloc_strdup(mem_ctx, "(SID ERR)");
|
||||||
|
|
||||||
|
/*
|
||||||
|
* BIG NOTE: this function only does SIDS where the identauth is not
|
||||||
|
* >= ^32 in a range of 2^48.
|
||||||
|
*/
|
||||||
|
|
||||||
ia = (sid->id_auth[5]) +
|
ia = (sid->id_auth[5]) +
|
||||||
(sid->id_auth[4] << 8 ) +
|
(sid->id_auth[4] << 8 ) +
|
||||||
(sid->id_auth[3] << 16) +
|
(sid->id_auth[3] << 16) +
|
||||||
|
Loading…
Reference in New Issue
Block a user