Removed version number from file header.
[kai/samba.git] / source3 / rpcclient / 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 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 #include "rpcclient.h"
24
25 /****************************************************************************
26 convert a security permissions into a string
27 ****************************************************************************/
28 char *get_sec_mask_str(uint32 type)
29 {
30         static fstring typestr="";
31
32         typestr[0] = 0;
33
34         if (type & GENERIC_ALL_ACCESS)
35                 fstrcat(typestr, "Generic all access ");
36         if (type & GENERIC_EXECUTE_ACCESS)
37                 fstrcat(typestr, "Generic execute access ");
38         if (type & GENERIC_WRITE_ACCESS)
39                 fstrcat(typestr, "Generic write access ");
40         if (type & GENERIC_READ_ACCESS)
41                 fstrcat(typestr, "Generic read access ");
42         if (type & MAXIMUM_ALLOWED_ACCESS)
43                 fstrcat(typestr, "MAXIMUM_ALLOWED_ACCESS ");
44         if (type & SYSTEM_SECURITY_ACCESS)
45                 fstrcat(typestr, "SYSTEM_SECURITY_ACCESS ");
46         if (type & SYNCHRONIZE_ACCESS)
47                 fstrcat(typestr, "SYNCHRONIZE_ACCESS ");
48         if (type & WRITE_OWNER_ACCESS)
49                 fstrcat(typestr, "WRITE_OWNER_ACCESS ");
50         if (type & WRITE_DAC_ACCESS)
51                 fstrcat(typestr, "WRITE_DAC_ACCESS ");
52         if (type & READ_CONTROL_ACCESS)
53                 fstrcat(typestr, "READ_CONTROL_ACCESS ");
54         if (type & DELETE_ACCESS)
55                 fstrcat(typestr, "DELETE_ACCESS ");
56
57         printf("\t\tSpecific bits: 0x%lx\n", type&SPECIFIC_RIGHTS_MASK);
58
59         return typestr;
60 }
61
62 /****************************************************************************
63  display sec_access structure
64  ****************************************************************************/
65 void display_sec_access(SEC_ACCESS *info)
66 {
67         printf("\t\tPermissions: 0x%x: %s\n", info->mask, get_sec_mask_str(info->mask));
68 }
69
70 /****************************************************************************
71  display sec_ace structure
72  ****************************************************************************/
73 void display_sec_ace(SEC_ACE *ace)
74 {
75         fstring sid_str;
76
77         printf("\tACE\n\t\ttype: ");
78         switch (ace->type) {
79                 case SEC_ACE_TYPE_ACCESS_ALLOWED:
80                         printf("ACCESS ALLOWED");
81                         break;
82                 case SEC_ACE_TYPE_ACCESS_DENIED:
83                         printf("ACCESS DENIED");
84                         break;
85                 case SEC_ACE_TYPE_SYSTEM_AUDIT:
86                         printf("SYSTEM AUDIT");
87                         break;
88                 case SEC_ACE_TYPE_SYSTEM_ALARM:
89                         printf("SYSTEM ALARM");
90                         break;
91                 default:
92                         printf("????");
93                         break;
94         }
95         printf(" (%d) flags: %d\n", ace->type, ace->flags);
96         display_sec_access(&ace->info);
97         sid_to_string(sid_str, &ace->trustee);
98         printf("\t\tSID: %s\n\n", sid_str);
99 }
100
101 /****************************************************************************
102  display sec_acl structure
103  ****************************************************************************/
104 void display_sec_acl(SEC_ACL *sec_acl)
105 {
106         int i;
107
108         printf("\tACL\tNum ACEs:\t%d\trevision:\t%x\n",
109                          sec_acl->num_aces, sec_acl->revision); 
110         printf("\t---\n");
111
112         if (sec_acl->size != 0 && sec_acl->num_aces != 0)
113                 for (i = 0; i < sec_acl->num_aces; i++)
114                         display_sec_ace(&sec_acl->ace[i]);
115                                 
116 }
117
118 /****************************************************************************
119  display sec_desc structure
120  ****************************************************************************/
121 void display_sec_desc(SEC_DESC *sec)
122 {
123         fstring sid_str;
124
125         if (sec->off_sacl != 0) {
126                 printf("S-ACL\n");
127                 display_sec_acl(sec->sacl);
128         }
129
130         if (sec->off_dacl != 0) {
131                 printf("D-ACL\n");
132                 display_sec_acl(sec->dacl);
133         }
134
135         if (sec->off_owner_sid != 0) {
136                 sid_to_string(sid_str, sec->owner_sid);
137                 printf("\tOwner SID:\t%s\n", sid_str);
138         }
139
140         if (sec->off_grp_sid != 0) {
141                 sid_to_string(sid_str, sec->grp_sid);
142                 printf("\tParent SID:\t%s\n", sid_str);
143         }
144 }