1 | /*
|
---|
2 | Unix SMB/CIFS implementation.
|
---|
3 |
|
---|
4 | libndr interface
|
---|
5 |
|
---|
6 | Copyright (C) Andrew Tridgell 2003
|
---|
7 |
|
---|
8 | This program is free software; you can redistribute it and/or modify
|
---|
9 | it under the terms of the GNU General Public License as published by
|
---|
10 | the Free Software Foundation; either version 3 of the License, or
|
---|
11 | (at your option) any later version.
|
---|
12 |
|
---|
13 | This program is distributed in the hope that it will be useful,
|
---|
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
16 | GNU General Public License for more details.
|
---|
17 |
|
---|
18 | You should have received a copy of the GNU General Public License
|
---|
19 | along with this program. If not, see <http://www.gnu.org/licenses/>.
|
---|
20 | */
|
---|
21 |
|
---|
22 | #include "includes.h"
|
---|
23 |
|
---|
24 | /*
|
---|
25 | convert a dom_sid to a string
|
---|
26 | */
|
---|
27 | char *dom_sid_string(TALLOC_CTX *mem_ctx, const struct dom_sid *sid)
|
---|
28 | {
|
---|
29 | int i, ofs, maxlen;
|
---|
30 | uint32_t ia;
|
---|
31 | char *ret;
|
---|
32 |
|
---|
33 | if (!sid) {
|
---|
34 | return talloc_strdup(mem_ctx, "(NULL SID)");
|
---|
35 | }
|
---|
36 |
|
---|
37 | maxlen = sid->num_auths * 11 + 25;
|
---|
38 | ret = (char *)talloc_size(mem_ctx, maxlen);
|
---|
39 | if (!ret) return talloc_strdup(mem_ctx, "(SID ERR)");
|
---|
40 |
|
---|
41 | /*
|
---|
42 | * BIG NOTE: this function only does SIDS where the identauth is not
|
---|
43 | * >= ^32 in a range of 2^48.
|
---|
44 | */
|
---|
45 |
|
---|
46 | ia = (sid->id_auth[5]) +
|
---|
47 | (sid->id_auth[4] << 8 ) +
|
---|
48 | (sid->id_auth[3] << 16) +
|
---|
49 | (sid->id_auth[2] << 24);
|
---|
50 |
|
---|
51 | ofs = snprintf(ret, maxlen, "S-%u-%lu",
|
---|
52 | (unsigned int)sid->sid_rev_num, (unsigned long)ia);
|
---|
53 |
|
---|
54 | for (i = 0; i < sid->num_auths; i++) {
|
---|
55 | ofs += snprintf(ret + ofs, maxlen - ofs, "-%lu", (unsigned long)sid->sub_auths[i]);
|
---|
56 | }
|
---|
57 |
|
---|
58 | return ret;
|
---|
59 | }
|
---|