2 Unix SMB/CIFS implementation.
4 fast routines for getting the wire size of security objects
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.
27 return the wire size of a dom_sid
29 size_t ndr_size_dom_sid(const struct dom_sid *sid)
32 return 8 + 4*sid->num_auths;
36 return the wire size of a dom_sid
38 size_t ndr_length_dom_sid(const struct dom_sid *sid)
41 if (sid->sid_rev_num == 0) return 0;
42 return 8 + 4*sid->num_auths;
46 return the wire size of a security_ace
48 size_t ndr_size_security_ace(const struct security_ace *ace)
51 return 8 + ndr_size_dom_sid(&ace->trustee);
56 return the wire size of a security_acl
58 size_t ndr_size_security_acl(const struct security_acl *acl)
64 for (i=0;i<acl->num_aces;i++) {
65 ret += ndr_size_security_ace(&acl->aces[i]);
71 return the wire size of a security descriptor
73 size_t ndr_size_security_descriptor(const struct security_descriptor *sd)
79 ret += ndr_size_dom_sid(sd->owner_sid);
80 ret += ndr_size_dom_sid(sd->group_sid);
81 ret += ndr_size_security_acl(sd->dacl);
82 ret += ndr_size_security_acl(sd->sacl);
89 void ndr_print_dom_sid(struct ndr_print *ndr, const char *name, const struct dom_sid *sid)
91 ndr->print(ndr, "%-25s: %s", name, dom_sid_string(ndr, sid));
94 void ndr_print_dom_sid2(struct ndr_print *ndr, const char *name, const struct dom_sid *sid)
96 ndr_print_dom_sid(ndr, name, sid);
99 void ndr_print_dom_sid28(struct ndr_print *ndr, const char *name, const struct dom_sid *sid)
101 ndr_print_dom_sid(ndr, name, sid);
105 convert a dom_sid to a string
107 char *dom_sid_string(TALLOC_CTX *mem_ctx, const struct dom_sid *sid)
114 return talloc_strdup(mem_ctx, "(NULL SID)");
117 maxlen = sid->num_auths * 11 + 25;
118 ret = talloc_size(mem_ctx, maxlen);
119 if (!ret) return talloc_strdup(mem_ctx, "(SID ERR)");
121 ia = (sid->id_auth[5]) +
122 (sid->id_auth[4] << 8 ) +
123 (sid->id_auth[3] << 16) +
124 (sid->id_auth[2] << 24);
126 ofs = snprintf(ret, maxlen, "S-%u-%lu",
127 (uint_t)sid->sid_rev_num, (unsigned long)ia);
129 for (i = 0; i < sid->num_auths; i++) {
130 ofs += snprintf(ret + ofs, maxlen - ofs, "-%lu", (unsigned long)sid->sub_auths[i]);