r23784: use the GPLv3 boilerplate as recommended by the FSF and the license text
[samba.git] / source3 / lib / display_sec.c
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 3 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, see <http://www.gnu.org/licenses/>.
19 */
20
21 #include "includes.h"
22
23 /****************************************************************************
24 convert a security permissions into a string
25 ****************************************************************************/
26 char *get_sec_mask_str(uint32 type)
27 {
28         static fstring typestr="";
29
30         typestr[0] = 0;
31
32         if (type & GENERIC_ALL_ACCESS)
33                 fstrcat(typestr, "Generic all access ");
34         if (type & GENERIC_EXECUTE_ACCESS)
35                 fstrcat(typestr, "Generic execute access ");
36         if (type & GENERIC_WRITE_ACCESS)
37                 fstrcat(typestr, "Generic write access ");
38         if (type & GENERIC_READ_ACCESS)
39                 fstrcat(typestr, "Generic read access ");
40         if (type & MAXIMUM_ALLOWED_ACCESS)
41                 fstrcat(typestr, "MAXIMUM_ALLOWED_ACCESS ");
42         if (type & SYSTEM_SECURITY_ACCESS)
43                 fstrcat(typestr, "SYSTEM_SECURITY_ACCESS ");
44         if (type & SYNCHRONIZE_ACCESS)
45                 fstrcat(typestr, "SYNCHRONIZE_ACCESS ");
46         if (type & WRITE_OWNER_ACCESS)
47                 fstrcat(typestr, "WRITE_OWNER_ACCESS ");
48         if (type & WRITE_DAC_ACCESS)
49                 fstrcat(typestr, "WRITE_DAC_ACCESS ");
50         if (type & READ_CONTROL_ACCESS)
51                 fstrcat(typestr, "READ_CONTROL_ACCESS ");
52         if (type & DELETE_ACCESS)
53                 fstrcat(typestr, "DELETE_ACCESS ");
54
55         printf("\t\tSpecific bits: 0x%lx\n", (unsigned long)type&SPECIFIC_RIGHTS_MASK);
56
57         return typestr;
58 }
59
60 /****************************************************************************
61  display sec_access structure
62  ****************************************************************************/
63 void display_sec_access(SEC_ACCESS *info)
64 {
65         printf("\t\tPermissions: 0x%x: %s\n", *info, get_sec_mask_str(*info));
66 }
67
68 /****************************************************************************
69  display sec_ace structure
70  ****************************************************************************/
71 void display_sec_ace(SEC_ACE *ace)
72 {
73         fstring sid_str;
74
75         printf("\tACE\n\t\ttype: ");
76         switch (ace->type) {
77                 case SEC_ACE_TYPE_ACCESS_ALLOWED:
78                         printf("ACCESS ALLOWED");
79                         break;
80                 case SEC_ACE_TYPE_ACCESS_DENIED:
81                         printf("ACCESS DENIED");
82                         break;
83                 case SEC_ACE_TYPE_SYSTEM_AUDIT:
84                         printf("SYSTEM AUDIT");
85                         break;
86                 case SEC_ACE_TYPE_SYSTEM_ALARM:
87                         printf("SYSTEM ALARM");
88                         break;
89                 default:
90                         printf("????");
91                         break;
92         }
93         printf(" (%d) flags: %d\n", ace->type, ace->flags);
94         display_sec_access(&ace->access_mask);
95         sid_to_string(sid_str, &ace->trustee);
96         printf("\t\tSID: %s\n\n", sid_str);
97 }
98
99 /****************************************************************************
100  display sec_acl structure
101  ****************************************************************************/
102 void display_sec_acl(SEC_ACL *sec_acl)
103 {
104         int i;
105
106         printf("\tACL\tNum ACEs:\t%d\trevision:\t%x\n",
107                          sec_acl->num_aces, sec_acl->revision); 
108         printf("\t---\n");
109
110         if (sec_acl->size != 0 && sec_acl->num_aces != 0)
111                 for (i = 0; i < sec_acl->num_aces; i++)
112                         display_sec_ace(&sec_acl->aces[i]);
113                                 
114 }
115
116 void display_acl_type(uint16 type)
117 {
118         static fstring typestr="";
119
120         typestr[0] = 0;
121
122         if (type & SEC_DESC_OWNER_DEFAULTED)    /* 0x0001 */
123                 fstrcat(typestr, "SEC_DESC_OWNER_DEFAULTED ");
124         if (type & SEC_DESC_GROUP_DEFAULTED)    /* 0x0002 */
125                 fstrcat(typestr, "SEC_DESC_GROUP_DEFAULTED ");
126         if (type & SEC_DESC_DACL_PRESENT)       /* 0x0004 */
127                 fstrcat(typestr, "SEC_DESC_DACL_PRESENT ");
128         if (type & SEC_DESC_DACL_DEFAULTED)     /* 0x0008 */
129                 fstrcat(typestr, "SEC_DESC_DACL_DEFAULTED ");
130         if (type & SEC_DESC_SACL_PRESENT)       /* 0x0010 */
131                 fstrcat(typestr, "SEC_DESC_SACL_PRESENT ");
132         if (type & SEC_DESC_SACL_DEFAULTED)     /* 0x0020 */
133                 fstrcat(typestr, "SEC_DESC_SACL_DEFAULTED ");
134         if (type & SEC_DESC_DACL_TRUSTED)       /* 0x0040 */
135                 fstrcat(typestr, "SEC_DESC_DACL_TRUSTED ");
136         if (type & SEC_DESC_SERVER_SECURITY)    /* 0x0080 */
137                 fstrcat(typestr, "SEC_DESC_SERVER_SECURITY ");
138         if (type & 0x0100) fstrcat(typestr, "0x0100 ");
139         if (type & 0x0200) fstrcat(typestr, "0x0200 ");
140         if (type & 0x0400) fstrcat(typestr, "0x0400 ");
141         if (type & 0x0800) fstrcat(typestr, "0x0800 ");
142         if (type & 0x1000) fstrcat(typestr, "0x1000 ");
143         if (type & 0x2000) fstrcat(typestr, "0x2000 ");
144         if (type & 0x4000) fstrcat(typestr, "0x4000 ");
145         if (type & SEC_DESC_SELF_RELATIVE)      /* 0x8000 */
146                 fstrcat(typestr, "SEC_DESC_SELF_RELATIVE ");
147         
148         printf("type: 0x%04x: %s\n", type, typestr);
149 }
150
151 /****************************************************************************
152  display sec_desc structure
153  ****************************************************************************/
154 void display_sec_desc(SEC_DESC *sec)
155 {
156         fstring sid_str;
157
158         if (!sec) {
159                 printf("NULL\n");
160                 return;
161         }
162
163         printf("revision: %d\n", sec->revision);
164         display_acl_type(sec->type);
165
166         if (sec->sacl) {
167                 printf("SACL\n");
168                 display_sec_acl(sec->sacl);
169         }
170
171         if (sec->dacl) {
172                 printf("DACL\n");
173                 display_sec_acl(sec->dacl);
174         }
175
176         if (sec->owner_sid) {
177                 sid_to_string(sid_str, sec->owner_sid);
178                 printf("\tOwner SID:\t%s\n", sid_str);
179         }
180
181         if (sec->group_sid) {
182                 sid_to_string(sid_str, sec->group_sid);
183                 printf("\tParent SID:\t%s\n", sid_str);
184         }
185 }