1 | /*
|
---|
2 | Unix SMB/CIFS implementation.
|
---|
3 | Samba utility functions
|
---|
4 | Copyright (C) Andrew Tridgell 1992-1999
|
---|
5 | Copyright (C) Luke Kenneth Casson Leighton 1996 - 1999
|
---|
6 |
|
---|
7 | This program is free software; you can redistribute it and/or modify
|
---|
8 | it under the terms of the GNU General Public License as published by
|
---|
9 | the Free Software Foundation; either version 2 of the License, or
|
---|
10 | (at your option) any later version.
|
---|
11 |
|
---|
12 | This program is distributed in the hope that it will be useful,
|
---|
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | GNU General Public License for more details.
|
---|
16 |
|
---|
17 | You should have received a copy of the GNU General Public License
|
---|
18 | along with this program; if not, write to the Free Software
|
---|
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
20 | */
|
---|
21 |
|
---|
22 | #include "includes.h"
|
---|
23 |
|
---|
24 | /****************************************************************************
|
---|
25 | convert a security permissions into a string
|
---|
26 | ****************************************************************************/
|
---|
27 | char *get_sec_mask_str(uint32 type)
|
---|
28 | {
|
---|
29 | static fstring typestr="";
|
---|
30 |
|
---|
31 | typestr[0] = 0;
|
---|
32 |
|
---|
33 | if (type & GENERIC_ALL_ACCESS)
|
---|
34 | fstrcat(typestr, "Generic all access ");
|
---|
35 | if (type & GENERIC_EXECUTE_ACCESS)
|
---|
36 | fstrcat(typestr, "Generic execute access ");
|
---|
37 | if (type & GENERIC_WRITE_ACCESS)
|
---|
38 | fstrcat(typestr, "Generic write access ");
|
---|
39 | if (type & GENERIC_READ_ACCESS)
|
---|
40 | fstrcat(typestr, "Generic read access ");
|
---|
41 | if (type & MAXIMUM_ALLOWED_ACCESS)
|
---|
42 | fstrcat(typestr, "MAXIMUM_ALLOWED_ACCESS ");
|
---|
43 | if (type & SYSTEM_SECURITY_ACCESS)
|
---|
44 | fstrcat(typestr, "SYSTEM_SECURITY_ACCESS ");
|
---|
45 | if (type & SYNCHRONIZE_ACCESS)
|
---|
46 | fstrcat(typestr, "SYNCHRONIZE_ACCESS ");
|
---|
47 | if (type & WRITE_OWNER_ACCESS)
|
---|
48 | fstrcat(typestr, "WRITE_OWNER_ACCESS ");
|
---|
49 | if (type & WRITE_DAC_ACCESS)
|
---|
50 | fstrcat(typestr, "WRITE_DAC_ACCESS ");
|
---|
51 | if (type & READ_CONTROL_ACCESS)
|
---|
52 | fstrcat(typestr, "READ_CONTROL_ACCESS ");
|
---|
53 | if (type & DELETE_ACCESS)
|
---|
54 | fstrcat(typestr, "DELETE_ACCESS ");
|
---|
55 |
|
---|
56 | printf("\t\tSpecific bits: 0x%lx\n", (unsigned long)type&SPECIFIC_RIGHTS_MASK);
|
---|
57 |
|
---|
58 | return typestr;
|
---|
59 | }
|
---|
60 |
|
---|
61 | /****************************************************************************
|
---|
62 | display sec_access structure
|
---|
63 | ****************************************************************************/
|
---|
64 | void display_sec_access(SEC_ACCESS *info)
|
---|
65 | {
|
---|
66 | printf("\t\tPermissions: 0x%x: %s\n", *info, get_sec_mask_str(*info));
|
---|
67 | }
|
---|
68 |
|
---|
69 | /****************************************************************************
|
---|
70 | display sec_ace structure
|
---|
71 | ****************************************************************************/
|
---|
72 | void display_sec_ace(SEC_ACE *ace)
|
---|
73 | {
|
---|
74 | fstring sid_str;
|
---|
75 |
|
---|
76 | printf("\tACE\n\t\ttype: ");
|
---|
77 | switch (ace->type) {
|
---|
78 | case SEC_ACE_TYPE_ACCESS_ALLOWED:
|
---|
79 | printf("ACCESS ALLOWED");
|
---|
80 | break;
|
---|
81 | case SEC_ACE_TYPE_ACCESS_DENIED:
|
---|
82 | printf("ACCESS DENIED");
|
---|
83 | break;
|
---|
84 | case SEC_ACE_TYPE_SYSTEM_AUDIT:
|
---|
85 | printf("SYSTEM AUDIT");
|
---|
86 | break;
|
---|
87 | case SEC_ACE_TYPE_SYSTEM_ALARM:
|
---|
88 | printf("SYSTEM ALARM");
|
---|
89 | break;
|
---|
90 | default:
|
---|
91 | printf("????");
|
---|
92 | break;
|
---|
93 | }
|
---|
94 | printf(" (%d) flags: %d\n", ace->type, ace->flags);
|
---|
95 | display_sec_access(&ace->access_mask);
|
---|
96 | sid_to_string(sid_str, &ace->trustee);
|
---|
97 | printf("\t\tSID: %s\n\n", sid_str);
|
---|
98 | }
|
---|
99 |
|
---|
100 | /****************************************************************************
|
---|
101 | display sec_acl structure
|
---|
102 | ****************************************************************************/
|
---|
103 | void display_sec_acl(SEC_ACL *sec_acl)
|
---|
104 | {
|
---|
105 | int i;
|
---|
106 |
|
---|
107 | printf("\tACL\tNum ACEs:\t%d\trevision:\t%x\n",
|
---|
108 | sec_acl->num_aces, sec_acl->revision);
|
---|
109 | printf("\t---\n");
|
---|
110 |
|
---|
111 | if (sec_acl->size != 0 && sec_acl->num_aces != 0)
|
---|
112 | for (i = 0; i < sec_acl->num_aces; i++)
|
---|
113 | display_sec_ace(&sec_acl->aces[i]);
|
---|
114 |
|
---|
115 | }
|
---|
116 |
|
---|
117 | void display_acl_type(uint16 type)
|
---|
118 | {
|
---|
119 | static fstring typestr="";
|
---|
120 |
|
---|
121 | typestr[0] = 0;
|
---|
122 |
|
---|
123 | if (type & SEC_DESC_OWNER_DEFAULTED) /* 0x0001 */
|
---|
124 | fstrcat(typestr, "SEC_DESC_OWNER_DEFAULTED ");
|
---|
125 | if (type & SEC_DESC_GROUP_DEFAULTED) /* 0x0002 */
|
---|
126 | fstrcat(typestr, "SEC_DESC_GROUP_DEFAULTED ");
|
---|
127 | if (type & SEC_DESC_DACL_PRESENT) /* 0x0004 */
|
---|
128 | fstrcat(typestr, "SEC_DESC_DACL_PRESENT ");
|
---|
129 | if (type & SEC_DESC_DACL_DEFAULTED) /* 0x0008 */
|
---|
130 | fstrcat(typestr, "SEC_DESC_DACL_DEFAULTED ");
|
---|
131 | if (type & SEC_DESC_SACL_PRESENT) /* 0x0010 */
|
---|
132 | fstrcat(typestr, "SEC_DESC_SACL_PRESENT ");
|
---|
133 | if (type & SEC_DESC_SACL_DEFAULTED) /* 0x0020 */
|
---|
134 | fstrcat(typestr, "SEC_DESC_SACL_DEFAULTED ");
|
---|
135 | if (type & SEC_DESC_DACL_TRUSTED) /* 0x0040 */
|
---|
136 | fstrcat(typestr, "SEC_DESC_DACL_TRUSTED ");
|
---|
137 | if (type & SEC_DESC_SERVER_SECURITY) /* 0x0080 */
|
---|
138 | fstrcat(typestr, "SEC_DESC_SERVER_SECURITY ");
|
---|
139 | if (type & 0x0100) fstrcat(typestr, "0x0100 ");
|
---|
140 | if (type & 0x0200) fstrcat(typestr, "0x0200 ");
|
---|
141 | if (type & 0x0400) fstrcat(typestr, "0x0400 ");
|
---|
142 | if (type & 0x0800) fstrcat(typestr, "0x0800 ");
|
---|
143 | if (type & 0x1000) fstrcat(typestr, "0x1000 ");
|
---|
144 | if (type & 0x2000) fstrcat(typestr, "0x2000 ");
|
---|
145 | if (type & 0x4000) fstrcat(typestr, "0x4000 ");
|
---|
146 | if (type & SEC_DESC_SELF_RELATIVE) /* 0x8000 */
|
---|
147 | fstrcat(typestr, "SEC_DESC_SELF_RELATIVE ");
|
---|
148 |
|
---|
149 | printf("type: 0x%04x: %s\n", type, typestr);
|
---|
150 | }
|
---|
151 |
|
---|
152 | /****************************************************************************
|
---|
153 | display sec_desc structure
|
---|
154 | ****************************************************************************/
|
---|
155 | void display_sec_desc(SEC_DESC *sec)
|
---|
156 | {
|
---|
157 | fstring sid_str;
|
---|
158 |
|
---|
159 | if (!sec) {
|
---|
160 | printf("NULL\n");
|
---|
161 | return;
|
---|
162 | }
|
---|
163 |
|
---|
164 | printf("revision: %d\n", sec->revision);
|
---|
165 | display_acl_type(sec->type);
|
---|
166 |
|
---|
167 | if (sec->sacl) {
|
---|
168 | printf("SACL\n");
|
---|
169 | display_sec_acl(sec->sacl);
|
---|
170 | }
|
---|
171 |
|
---|
172 | if (sec->dacl) {
|
---|
173 | printf("DACL\n");
|
---|
174 | display_sec_acl(sec->dacl);
|
---|
175 | }
|
---|
176 |
|
---|
177 | if (sec->owner_sid) {
|
---|
178 | sid_to_string(sid_str, sec->owner_sid);
|
---|
179 | printf("\tOwner SID:\t%s\n", sid_str);
|
---|
180 | }
|
---|
181 |
|
---|
182 | if (sec->group_sid) {
|
---|
183 | sid_to_string(sid_str, sec->group_sid);
|
---|
184 | printf("\tParent SID:\t%s\n", sid_str);
|
---|
185 | }
|
---|
186 | }
|
---|