cifs.idmap: fix endianness on SIDs before sending to kernel
[jlayton/cifs-utils.git] / cifsacl.h
1 /*
2 * Header file for getcifsacl and setcifsacl utilities
3 *
4 * Copyright (C) Shirish Pargaonkar (shirishp@us.ibm.com) 2011
5 *
6 * Has various access rights, security descriptor fields defines
7 * and data structures related to security descriptor, DACL, ACE,
8 * and SID.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
23 #ifndef _CIFSACL_H
24 #define _CIFSACL_H
25
26 #define BUFSIZE 1024
27 #define ATTRNAME "system.cifs_acl"
28
29 #define MAX_NUM_AUTHS 6
30
31 /* File specific rights */
32 #define READ_DATA       0x00000001 /* R */
33 #define WRITE_DATA      0x00000002 /* W */
34 #define APPEND_DATA     0x00000004 /* A */
35 #define READ_EA         0x00000008 /* REA */
36 #define WRITE_EA        0x00000010 /* WEA */
37 #define EXEC            0x00000020 /* E */
38 #define DELDHLD         0x00000040 /* DC */
39 #define READ_ATTR       0x00000080 /* RA */
40 #define WRITE_ATTR      0x00000100 /* WA */
41
42 /* Standard rights */
43 #define DELETE          0x00010000 /* D */
44 #define READ_CONTROL    0x00020000 /* RC */
45 #define WRITE_DAC       0x00040000 /* P */
46 #define WRITE_OWNER     0x00080000 /* O */
47 #define SYNC            0x00100000 /* S */
48
49 /* Generic rights */
50 #define SYSSEC          0x01000000
51 #define MAX             0x02000000
52 #define ALL             0x10000000
53 #define EXECUTE         0x20000000 /* GE */
54 #define WRITE           0x40000000 /* GW */
55 #define READ            0x80000000 /* GR */
56
57 /* D | RC | P | O | S | R | W | A | E | DC | REA | WEA | RA | WA  */
58 #define FULL_CONTROL    0x001f01ff
59
60 /* RC | S | R | E | REA | RA */
61 #define EREAD           0x001200a9
62
63 /* RC | S | R | E | REA | GR | GE */
64 #define OREAD           0xa01200a1
65
66 /* RC | S | R | REA | RA */
67 #define BREAD           0x00120089
68
69 /* W | A | WA | WEA| */
70 #define EWRITE          0x00000116
71
72 /* D | RC | S | R | W | A | E |REA | WEA | RA | WA */
73 #define CHANGE          0x001301bf
74
75 /* GR | RC | REA | RA | REA | R */
76 #define ALL_READ_BITS   0x80020089
77
78 /* WA | WEA | A | W */
79 #define ALL_WRITE_BITS  0x40000116
80
81 #define OBJECT_INHERIT_FLAG 0x01        /* OI */
82 #define CONTAINER_INHERIT_FLAG 0x02     /* CI */
83 #define NO_PROPAGATE_INHERIT_FLAG 0x04  /* NP */
84 #define INHERIT_ONLY_FLAG 0x08          /* IO */
85 #define INHERITED_ACE_FLAG 0x10         /* I */
86 #define VFLAGS (OBJECT_INHERIT_FLAG|CONTAINER_INHERIT_FLAG|NO_PROPAGATE_INHERIT_FLAG|INHERIT_ONLY_FLAG|INHERITED_ACE_FLAG)
87
88 #define ACCESS_ALLOWED  0               /* ALLOWED */
89 #define ACCESS_DENIED   1               /* DENIED */
90 #define ACCESS_ALLOWED_OBJECT   5       /* OBJECT_ALLOWED */
91 #define ACCESS_DENIED_OBJECT    6       /* OBJECT_DENIED */
92
93 #define COMPSID 0x1
94 #define COMPTYPE 0x2
95 #define COMPFLAG 0x4
96 #define COMPMASK 0x8
97 #define COMPALL (COMPSID|COMPTYPE|COMPFLAG|COMPMASK)
98
99 #define NUM_AUTHS (6)                   /* number of authority fields */
100 #define SID_MAX_SUB_AUTHORITIES (15)    /* max number of sub authority fields */
101
102 /*
103  * While not indicated here, the structs below represent on-the-wire data
104  * structures. Any multi-byte values are expected to be little-endian!
105  *
106  * FIXME: should we change these to use endianness annotations?
107  */
108 struct cifs_ntsd {
109         uint16_t revision; /* revision level */
110         uint16_t type;
111         uint32_t osidoffset;
112         uint32_t gsidoffset;
113         uint32_t sacloffset;
114         uint32_t dacloffset;
115 } __attribute__((packed));
116
117 struct cifs_sid {
118         uint8_t revision; /* revision level */
119         uint8_t num_subauth;
120         uint8_t authority[NUM_AUTHS];
121         uint32_t sub_auth[SID_MAX_SUB_AUTHORITIES];
122 } __attribute__((packed));
123
124 struct cifs_ctrl_acl {
125         uint16_t revision; /* revision level */
126         uint16_t size;
127         uint32_t num_aces;
128 } __attribute__((packed));
129
130 struct cifs_ace {
131         uint8_t type;
132         uint8_t flags;
133         uint16_t size;
134         uint32_t access_req;
135         struct cifs_sid sid; /* ie UUID of user or group who gets these perms */
136 } __attribute__((packed));
137
138 #endif /* CIFSACL_H */