diff options
author | Jeff Layton <jlayton@samba.org> | 2013-07-31 10:38:19 -0400 |
---|---|---|
committer | Jeremy Allison <jra@samba.org> | 2013-07-31 15:16:04 -0700 |
commit | ba9d8612e3f66fa7c8c1999c26c658167124b18f (patch) | |
tree | 861ee28a76ea5389afd40da54e0f9e253d29e221 /nsswitch/libwbclient/wbc_sid.c | |
parent | 1a4ec0b885f95b481d9df6461bd4a8e8fd175f53 (diff) | |
download | samba-ba9d8612e3f66fa7c8c1999c26c658167124b18f.tar.gz samba-ba9d8612e3f66fa7c8c1999c26c658167124b18f.tar.bz2 samba-ba9d8612e3f66fa7c8c1999c26c658167124b18f.zip |
wbclient: fix conversion logic in wbcSidToStringBuf
Might as well fix it to handle large authority values properly. Also
correct some of the formatting.
Signed-off-by: Jeff Layton <jlayton@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
Diffstat (limited to 'nsswitch/libwbclient/wbc_sid.c')
-rw-r--r-- | nsswitch/libwbclient/wbc_sid.c | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/nsswitch/libwbclient/wbc_sid.c b/nsswitch/libwbclient/wbc_sid.c index 99091c9108..471f71b084 100644 --- a/nsswitch/libwbclient/wbc_sid.c +++ b/nsswitch/libwbclient/wbc_sid.c @@ -32,7 +32,7 @@ * result if it was long enough. */ int wbcSidToStringBuf(const struct wbcDomainSid *sid, char *buf, int buflen) { - uint32_t id_auth; + uint64_t id_auth; int i, ofs; if (!sid) { @@ -40,22 +40,25 @@ int wbcSidToStringBuf(const struct wbcDomainSid *sid, char *buf, int buflen) return 10; /* strlen("(NULL SID)") */ } - /* - * BIG NOTE: this function only does SIDS where the identauth is not - * >= ^32 in a range of 2^48. - */ - - id_auth = sid->id_auth[5] + - (sid->id_auth[4] << 8) + - (sid->id_auth[3] << 16) + - (sid->id_auth[2] << 24); + id_auth = (uint64_t)sid->id_auth[5] + + ((uint64_t)sid->id_auth[4] << 8) + + ((uint64_t)sid->id_auth[3] << 16) + + ((uint64_t)sid->id_auth[2] << 24) + + ((uint64_t)sid->id_auth[1] << 32) + + ((uint64_t)sid->id_auth[0] << 40); - ofs = snprintf(buf, buflen, "S-%u-%lu", - (unsigned int)sid->sid_rev_num, (unsigned long)id_auth); + ofs = snprintf(buf, buflen, "S-%hhu-", (unsigned char)sid->sid_rev_num); + if (id_auth >= UINT32_MAX) { + ofs += snprintf(buf + ofs, MAX(buflen - ofs, 0), "0x%llx", + (unsigned long long)id_auth); + } else { + ofs += snprintf(buf + ofs, MAX(buflen - ofs, 0), "%llu", + (unsigned long long)id_auth); + } for (i = 0; i < sid->num_auths; i++) { - ofs += snprintf(buf + ofs, MAX(buflen - ofs, 0), "-%lu", - (unsigned long)sid->sub_auths[i]); + ofs += snprintf(buf + ofs, MAX(buflen - ofs, 0), "-%u", + (unsigned int)sid->sub_auths[i]); } return ofs; } |