2 Unix SMB/CIFS implementation.
6 Copyright (C) Andrew Tridgell 2003
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 2 of the License, or
11 (at your option) any later version.
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.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 NTSTATUS ndr_push_dom_sid(struct ndr_push *ndr, int ndr_flags, const struct dom_sid *r)
27 uint32_t cntr_sub_auths_0;
28 if (ndr_flags & NDR_SCALARS) {
29 NDR_CHECK(ndr_push_align(ndr, 4));
30 NDR_CHECK(ndr_push_uint8(ndr, NDR_SCALARS, r->sid_rev_num));
31 NDR_CHECK(ndr_push_int8(ndr, NDR_SCALARS, r->num_auths));
32 NDR_CHECK(ndr_push_array_uint8(ndr, NDR_SCALARS, r->id_auth, 6));
33 for (cntr_sub_auths_0 = 0; cntr_sub_auths_0 < r->num_auths; cntr_sub_auths_0++) {
34 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, r->sub_auths[cntr_sub_auths_0]));
37 if (ndr_flags & NDR_BUFFERS) {
42 NTSTATUS ndr_pull_dom_sid(struct ndr_pull *ndr, int ndr_flags, struct dom_sid *r)
44 uint32_t cntr_sub_auths_0;
45 TALLOC_CTX *_mem_save_sub_auths_0;
46 if (ndr_flags & NDR_SCALARS) {
47 NDR_CHECK(ndr_pull_align(ndr, 4));
48 NDR_CHECK(ndr_pull_uint8(ndr, NDR_SCALARS, &r->sid_rev_num));
49 NDR_CHECK(ndr_pull_int8(ndr, NDR_SCALARS, &r->num_auths));
50 if (r->num_auths < 0 || r->num_auths > 15) {
51 return ndr_pull_error(ndr, NDR_ERR_RANGE, "value out of range");
53 NDR_CHECK(ndr_pull_array_uint8(ndr, NDR_SCALARS, r->id_auth, 6));
54 NDR_PULL_ALLOC_N(ndr, r->sub_auths, r->num_auths);
55 _mem_save_sub_auths_0 = NDR_PULL_GET_MEM_CTX(ndr);
56 NDR_PULL_SET_MEM_CTX(ndr, r->sub_auths, 0);
57 for (cntr_sub_auths_0 = 0; cntr_sub_auths_0 < r->num_auths; cntr_sub_auths_0++) {
58 NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &r->sub_auths[cntr_sub_auths_0]));
60 NDR_PULL_SET_MEM_CTX(ndr, _mem_save_sub_auths_0, 0);
62 if (ndr_flags & NDR_BUFFERS) {
68 convert a dom_sid to a string
70 char *dom_sid_string(TALLOC_CTX *mem_ctx, const struct dom_sid *sid)
77 return talloc_strdup(mem_ctx, "(NULL SID)");
80 maxlen = sid->num_auths * 11 + 25;
81 ret = talloc_size(mem_ctx, maxlen);
82 if (!ret) return talloc_strdup(mem_ctx, "(SID ERR)");
84 ia = (sid->id_auth[5]) +
85 (sid->id_auth[4] << 8 ) +
86 (sid->id_auth[3] << 16) +
87 (sid->id_auth[2] << 24);
89 ofs = snprintf(ret, maxlen, "S-%u-%lu",
90 (unsigned int)sid->sid_rev_num, (unsigned long)ia);
92 for (i = 0; i < sid->num_auths; i++) {
93 ofs += snprintf(ret + ofs, maxlen - ofs, "-%lu", (unsigned long)sid->sub_auths[i]);