Steve French | bcb0203 | 2007-09-25 16:17:24 +0000 | [diff] [blame] | 1 | /* |
| 2 | * fs/cifs/cifsacl.c |
| 3 | * |
Steve French | 8b1327f | 2008-03-14 22:37:16 +0000 | [diff] [blame] | 4 | * Copyright (C) International Business Machines Corp., 2007,2008 |
Steve French | bcb0203 | 2007-09-25 16:17:24 +0000 | [diff] [blame] | 5 | * Author(s): Steve French (sfrench@us.ibm.com) |
| 6 | * |
| 7 | * Contains the routines for mapping CIFS/NTFS ACLs |
| 8 | * |
| 9 | * This library is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU Lesser General Public License as published |
| 11 | * by the Free Software Foundation; either version 2.1 of the License, or |
| 12 | * (at your option) any later version. |
| 13 | * |
| 14 | * This library 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 |
| 17 | * the GNU Lesser General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU Lesser General Public License |
| 20 | * along with this library; if not, write to the Free Software |
| 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 22 | */ |
| 23 | |
Steve French | 6587400 | 2007-09-25 19:53:44 +0000 | [diff] [blame] | 24 | #include <linux/fs.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 25 | #include <linux/slab.h> |
Steve French | 6587400 | 2007-09-25 19:53:44 +0000 | [diff] [blame] | 26 | #include "cifspdu.h" |
| 27 | #include "cifsglob.h" |
Shirish Pargaonkar | d0d66c4 | 2007-10-03 18:22:19 +0000 | [diff] [blame] | 28 | #include "cifsacl.h" |
Steve French | 6587400 | 2007-09-25 19:53:44 +0000 | [diff] [blame] | 29 | #include "cifsproto.h" |
| 30 | #include "cifs_debug.h" |
Steve French | 6587400 | 2007-09-25 19:53:44 +0000 | [diff] [blame] | 31 | |
Steve French | 297647c | 2007-10-12 04:11:59 +0000 | [diff] [blame] | 32 | |
Steve French | af6f461 | 2007-10-16 18:40:37 +0000 | [diff] [blame] | 33 | static struct cifs_wksid wksidarr[NUM_WK_SIDS] = { |
Steve French | 297647c | 2007-10-12 04:11:59 +0000 | [diff] [blame] | 34 | {{1, 0, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0} }, "null user"}, |
| 35 | {{1, 1, {0, 0, 0, 0, 0, 1}, {0, 0, 0, 0, 0} }, "nobody"}, |
Jeff Layton | 536abdb | 2008-07-12 13:48:00 -0700 | [diff] [blame] | 36 | {{1, 1, {0, 0, 0, 0, 0, 5}, {__constant_cpu_to_le32(11), 0, 0, 0, 0} }, "net-users"}, |
| 37 | {{1, 1, {0, 0, 0, 0, 0, 5}, {__constant_cpu_to_le32(18), 0, 0, 0, 0} }, "sys"}, |
| 38 | {{1, 2, {0, 0, 0, 0, 0, 5}, {__constant_cpu_to_le32(32), __constant_cpu_to_le32(544), 0, 0, 0} }, "root"}, |
| 39 | {{1, 2, {0, 0, 0, 0, 0, 5}, {__constant_cpu_to_le32(32), __constant_cpu_to_le32(545), 0, 0, 0} }, "users"}, |
| 40 | {{1, 2, {0, 0, 0, 0, 0, 5}, {__constant_cpu_to_le32(32), __constant_cpu_to_le32(546), 0, 0, 0} }, "guest"} } |
Steve French | 44093ca | 2007-10-23 21:22:55 +0000 | [diff] [blame] | 41 | ; |
Steve French | 297647c | 2007-10-12 04:11:59 +0000 | [diff] [blame] | 42 | |
| 43 | |
Shirish Pargaonkar | 2fbc2f1 | 2010-12-06 14:56:46 -0600 | [diff] [blame] | 44 | /* security id for everyone/world system group */ |
Shirish Pargaonkar | e01b640 | 2007-10-30 04:45:14 +0000 | [diff] [blame] | 45 | static const struct cifs_sid sid_everyone = { |
| 46 | 1, 1, {0, 0, 0, 0, 0, 1}, {0} }; |
Shirish Pargaonkar | 2fbc2f1 | 2010-12-06 14:56:46 -0600 | [diff] [blame] | 47 | /* security id for Authenticated Users system group */ |
| 48 | static const struct cifs_sid sid_authusers = { |
| 49 | 1, 1, {0, 0, 0, 0, 0, 5}, {11} }; |
Steve French | bcb0203 | 2007-09-25 16:17:24 +0000 | [diff] [blame] | 50 | /* group users */ |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 51 | static const struct cifs_sid sid_user = {1, 2 , {0, 0, 0, 0, 0, 5}, {} }; |
Shirish Pargaonkar | d0d66c4 | 2007-10-03 18:22:19 +0000 | [diff] [blame] | 52 | |
Steve French | 297647c | 2007-10-12 04:11:59 +0000 | [diff] [blame] | 53 | |
| 54 | int match_sid(struct cifs_sid *ctsid) |
| 55 | { |
| 56 | int i, j; |
| 57 | int num_subauth, num_sat, num_saw; |
| 58 | struct cifs_sid *cwsid; |
| 59 | |
| 60 | if (!ctsid) |
Shirish Pargaonkar | ef571ca | 2008-07-24 15:56:05 +0000 | [diff] [blame] | 61 | return -1; |
Steve French | 297647c | 2007-10-12 04:11:59 +0000 | [diff] [blame] | 62 | |
| 63 | for (i = 0; i < NUM_WK_SIDS; ++i) { |
| 64 | cwsid = &(wksidarr[i].cifssid); |
| 65 | |
| 66 | /* compare the revision */ |
| 67 | if (ctsid->revision != cwsid->revision) |
| 68 | continue; |
| 69 | |
| 70 | /* compare all of the six auth values */ |
| 71 | for (j = 0; j < 6; ++j) { |
| 72 | if (ctsid->authority[j] != cwsid->authority[j]) |
| 73 | break; |
| 74 | } |
| 75 | if (j < 6) |
| 76 | continue; /* all of the auth values did not match */ |
| 77 | |
| 78 | /* compare all of the subauth values if any */ |
Dave Kleikamp | ce51ae1 | 2007-10-16 21:35:39 +0000 | [diff] [blame] | 79 | num_sat = ctsid->num_subauth; |
| 80 | num_saw = cwsid->num_subauth; |
Steve French | 297647c | 2007-10-12 04:11:59 +0000 | [diff] [blame] | 81 | num_subauth = num_sat < num_saw ? num_sat : num_saw; |
| 82 | if (num_subauth) { |
| 83 | for (j = 0; j < num_subauth; ++j) { |
| 84 | if (ctsid->sub_auth[j] != cwsid->sub_auth[j]) |
| 85 | break; |
| 86 | } |
| 87 | if (j < num_subauth) |
| 88 | continue; /* all sub_auth values do not match */ |
| 89 | } |
| 90 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 91 | cFYI(1, "matching sid: %s\n", wksidarr[i].sidname); |
Shirish Pargaonkar | ef571ca | 2008-07-24 15:56:05 +0000 | [diff] [blame] | 92 | return 0; /* sids compare/match */ |
Steve French | 297647c | 2007-10-12 04:11:59 +0000 | [diff] [blame] | 93 | } |
| 94 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 95 | cFYI(1, "No matching sid"); |
Shirish Pargaonkar | ef571ca | 2008-07-24 15:56:05 +0000 | [diff] [blame] | 96 | return -1; |
Steve French | 297647c | 2007-10-12 04:11:59 +0000 | [diff] [blame] | 97 | } |
| 98 | |
Steve French | a750e77 | 2007-10-17 22:50:39 +0000 | [diff] [blame] | 99 | /* if the two SIDs (roughly equivalent to a UUID for a user or group) are |
| 100 | the same returns 1, if they do not match returns 0 */ |
Steve French | 630f3f0 | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 101 | int compare_sids(const struct cifs_sid *ctsid, const struct cifs_sid *cwsid) |
Steve French | 297647c | 2007-10-12 04:11:59 +0000 | [diff] [blame] | 102 | { |
| 103 | int i; |
| 104 | int num_subauth, num_sat, num_saw; |
| 105 | |
| 106 | if ((!ctsid) || (!cwsid)) |
Shirish Pargaonkar | ef571ca | 2008-07-24 15:56:05 +0000 | [diff] [blame] | 107 | return 0; |
Steve French | 297647c | 2007-10-12 04:11:59 +0000 | [diff] [blame] | 108 | |
| 109 | /* compare the revision */ |
| 110 | if (ctsid->revision != cwsid->revision) |
Shirish Pargaonkar | ef571ca | 2008-07-24 15:56:05 +0000 | [diff] [blame] | 111 | return 0; |
Steve French | 297647c | 2007-10-12 04:11:59 +0000 | [diff] [blame] | 112 | |
| 113 | /* compare all of the six auth values */ |
| 114 | for (i = 0; i < 6; ++i) { |
| 115 | if (ctsid->authority[i] != cwsid->authority[i]) |
Shirish Pargaonkar | ef571ca | 2008-07-24 15:56:05 +0000 | [diff] [blame] | 116 | return 0; |
Steve French | 297647c | 2007-10-12 04:11:59 +0000 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | /* compare all of the subauth values if any */ |
Steve French | adbc035 | 2007-10-17 02:12:46 +0000 | [diff] [blame] | 120 | num_sat = ctsid->num_subauth; |
Steve French | adddd49 | 2007-10-17 02:48:17 +0000 | [diff] [blame] | 121 | num_saw = cwsid->num_subauth; |
Steve French | 297647c | 2007-10-12 04:11:59 +0000 | [diff] [blame] | 122 | num_subauth = num_sat < num_saw ? num_sat : num_saw; |
| 123 | if (num_subauth) { |
| 124 | for (i = 0; i < num_subauth; ++i) { |
| 125 | if (ctsid->sub_auth[i] != cwsid->sub_auth[i]) |
Shirish Pargaonkar | ef571ca | 2008-07-24 15:56:05 +0000 | [diff] [blame] | 126 | return 0; |
Steve French | 297647c | 2007-10-12 04:11:59 +0000 | [diff] [blame] | 127 | } |
| 128 | } |
| 129 | |
Shirish Pargaonkar | ef571ca | 2008-07-24 15:56:05 +0000 | [diff] [blame] | 130 | return 1; /* sids compare/match */ |
Steve French | 297647c | 2007-10-12 04:11:59 +0000 | [diff] [blame] | 131 | } |
| 132 | |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 133 | |
| 134 | /* copy ntsd, owner sid, and group sid from a security descriptor to another */ |
| 135 | static void copy_sec_desc(const struct cifs_ntsd *pntsd, |
| 136 | struct cifs_ntsd *pnntsd, __u32 sidsoffset) |
| 137 | { |
| 138 | int i; |
| 139 | |
| 140 | struct cifs_sid *owner_sid_ptr, *group_sid_ptr; |
| 141 | struct cifs_sid *nowner_sid_ptr, *ngroup_sid_ptr; |
| 142 | |
| 143 | /* copy security descriptor control portion */ |
| 144 | pnntsd->revision = pntsd->revision; |
| 145 | pnntsd->type = pntsd->type; |
| 146 | pnntsd->dacloffset = cpu_to_le32(sizeof(struct cifs_ntsd)); |
| 147 | pnntsd->sacloffset = 0; |
| 148 | pnntsd->osidoffset = cpu_to_le32(sidsoffset); |
| 149 | pnntsd->gsidoffset = cpu_to_le32(sidsoffset + sizeof(struct cifs_sid)); |
| 150 | |
| 151 | /* copy owner sid */ |
| 152 | owner_sid_ptr = (struct cifs_sid *)((char *)pntsd + |
| 153 | le32_to_cpu(pntsd->osidoffset)); |
| 154 | nowner_sid_ptr = (struct cifs_sid *)((char *)pnntsd + sidsoffset); |
| 155 | |
| 156 | nowner_sid_ptr->revision = owner_sid_ptr->revision; |
| 157 | nowner_sid_ptr->num_subauth = owner_sid_ptr->num_subauth; |
| 158 | for (i = 0; i < 6; i++) |
| 159 | nowner_sid_ptr->authority[i] = owner_sid_ptr->authority[i]; |
| 160 | for (i = 0; i < 5; i++) |
| 161 | nowner_sid_ptr->sub_auth[i] = owner_sid_ptr->sub_auth[i]; |
| 162 | |
| 163 | /* copy group sid */ |
| 164 | group_sid_ptr = (struct cifs_sid *)((char *)pntsd + |
| 165 | le32_to_cpu(pntsd->gsidoffset)); |
| 166 | ngroup_sid_ptr = (struct cifs_sid *)((char *)pnntsd + sidsoffset + |
| 167 | sizeof(struct cifs_sid)); |
| 168 | |
| 169 | ngroup_sid_ptr->revision = group_sid_ptr->revision; |
| 170 | ngroup_sid_ptr->num_subauth = group_sid_ptr->num_subauth; |
| 171 | for (i = 0; i < 6; i++) |
| 172 | ngroup_sid_ptr->authority[i] = group_sid_ptr->authority[i]; |
| 173 | for (i = 0; i < 5; i++) |
Shirish Pargaonkar | b1910ad | 2008-07-24 14:53:20 +0000 | [diff] [blame] | 174 | ngroup_sid_ptr->sub_auth[i] = group_sid_ptr->sub_auth[i]; |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 175 | |
| 176 | return; |
| 177 | } |
| 178 | |
| 179 | |
Steve French | 630f3f0 | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 180 | /* |
| 181 | change posix mode to reflect permissions |
| 182 | pmode is the existing mode (we only want to overwrite part of this |
| 183 | bits to set can be: S_IRWXU, S_IRWXG or S_IRWXO ie 00700 or 00070 or 00007 |
| 184 | */ |
Al Viro | 9b5e685 | 2007-12-05 08:24:38 +0000 | [diff] [blame] | 185 | static void access_flags_to_mode(__le32 ace_flags, int type, umode_t *pmode, |
Steve French | 15b0395 | 2007-11-08 17:57:40 +0000 | [diff] [blame] | 186 | umode_t *pbits_to_set) |
Steve French | 4879b44 | 2007-10-19 21:57:39 +0000 | [diff] [blame] | 187 | { |
Al Viro | 9b5e685 | 2007-12-05 08:24:38 +0000 | [diff] [blame] | 188 | __u32 flags = le32_to_cpu(ace_flags); |
Steve French | 15b0395 | 2007-11-08 17:57:40 +0000 | [diff] [blame] | 189 | /* the order of ACEs is important. The canonical order is to begin with |
Steve French | ce06c9f | 2007-11-08 21:12:01 +0000 | [diff] [blame] | 190 | DENY entries followed by ALLOW, otherwise an allow entry could be |
Steve French | 15b0395 | 2007-11-08 17:57:40 +0000 | [diff] [blame] | 191 | encountered first, making the subsequent deny entry like "dead code" |
Steve French | ce06c9f | 2007-11-08 21:12:01 +0000 | [diff] [blame] | 192 | which would be superflous since Windows stops when a match is made |
Steve French | 15b0395 | 2007-11-08 17:57:40 +0000 | [diff] [blame] | 193 | for the operation you are trying to perform for your user */ |
| 194 | |
| 195 | /* For deny ACEs we change the mask so that subsequent allow access |
| 196 | control entries do not turn on the bits we are denying */ |
| 197 | if (type == ACCESS_DENIED) { |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 198 | if (flags & GENERIC_ALL) |
Steve French | 15b0395 | 2007-11-08 17:57:40 +0000 | [diff] [blame] | 199 | *pbits_to_set &= ~S_IRWXUGO; |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 200 | |
Al Viro | 9b5e685 | 2007-12-05 08:24:38 +0000 | [diff] [blame] | 201 | if ((flags & GENERIC_WRITE) || |
| 202 | ((flags & FILE_WRITE_RIGHTS) == FILE_WRITE_RIGHTS)) |
Steve French | 15b0395 | 2007-11-08 17:57:40 +0000 | [diff] [blame] | 203 | *pbits_to_set &= ~S_IWUGO; |
Al Viro | 9b5e685 | 2007-12-05 08:24:38 +0000 | [diff] [blame] | 204 | if ((flags & GENERIC_READ) || |
| 205 | ((flags & FILE_READ_RIGHTS) == FILE_READ_RIGHTS)) |
Steve French | 15b0395 | 2007-11-08 17:57:40 +0000 | [diff] [blame] | 206 | *pbits_to_set &= ~S_IRUGO; |
Al Viro | 9b5e685 | 2007-12-05 08:24:38 +0000 | [diff] [blame] | 207 | if ((flags & GENERIC_EXECUTE) || |
| 208 | ((flags & FILE_EXEC_RIGHTS) == FILE_EXEC_RIGHTS)) |
Steve French | 15b0395 | 2007-11-08 17:57:40 +0000 | [diff] [blame] | 209 | *pbits_to_set &= ~S_IXUGO; |
| 210 | return; |
| 211 | } else if (type != ACCESS_ALLOWED) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 212 | cERROR(1, "unknown access control type %d", type); |
Steve French | 15b0395 | 2007-11-08 17:57:40 +0000 | [diff] [blame] | 213 | return; |
| 214 | } |
| 215 | /* else ACCESS_ALLOWED type */ |
Steve French | 44093ca | 2007-10-23 21:22:55 +0000 | [diff] [blame] | 216 | |
Al Viro | 9b5e685 | 2007-12-05 08:24:38 +0000 | [diff] [blame] | 217 | if (flags & GENERIC_ALL) { |
Steve French | 15b0395 | 2007-11-08 17:57:40 +0000 | [diff] [blame] | 218 | *pmode |= (S_IRWXUGO & (*pbits_to_set)); |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 219 | cFYI(DBG2, "all perms"); |
Steve French | d61e580 | 2007-10-26 04:32:43 +0000 | [diff] [blame] | 220 | return; |
| 221 | } |
Al Viro | 9b5e685 | 2007-12-05 08:24:38 +0000 | [diff] [blame] | 222 | if ((flags & GENERIC_WRITE) || |
| 223 | ((flags & FILE_WRITE_RIGHTS) == FILE_WRITE_RIGHTS)) |
Steve French | 15b0395 | 2007-11-08 17:57:40 +0000 | [diff] [blame] | 224 | *pmode |= (S_IWUGO & (*pbits_to_set)); |
Al Viro | 9b5e685 | 2007-12-05 08:24:38 +0000 | [diff] [blame] | 225 | if ((flags & GENERIC_READ) || |
| 226 | ((flags & FILE_READ_RIGHTS) == FILE_READ_RIGHTS)) |
Steve French | 15b0395 | 2007-11-08 17:57:40 +0000 | [diff] [blame] | 227 | *pmode |= (S_IRUGO & (*pbits_to_set)); |
Al Viro | 9b5e685 | 2007-12-05 08:24:38 +0000 | [diff] [blame] | 228 | if ((flags & GENERIC_EXECUTE) || |
| 229 | ((flags & FILE_EXEC_RIGHTS) == FILE_EXEC_RIGHTS)) |
Steve French | 15b0395 | 2007-11-08 17:57:40 +0000 | [diff] [blame] | 230 | *pmode |= (S_IXUGO & (*pbits_to_set)); |
Steve French | d61e580 | 2007-10-26 04:32:43 +0000 | [diff] [blame] | 231 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 232 | cFYI(DBG2, "access flags 0x%x mode now 0x%x", flags, *pmode); |
Steve French | 630f3f0 | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 233 | return; |
| 234 | } |
| 235 | |
Steve French | ce06c9f | 2007-11-08 21:12:01 +0000 | [diff] [blame] | 236 | /* |
| 237 | Generate access flags to reflect permissions mode is the existing mode. |
| 238 | This function is called for every ACE in the DACL whose SID matches |
| 239 | with either owner or group or everyone. |
| 240 | */ |
| 241 | |
| 242 | static void mode_to_access_flags(umode_t mode, umode_t bits_to_use, |
| 243 | __u32 *pace_flags) |
| 244 | { |
| 245 | /* reset access mask */ |
| 246 | *pace_flags = 0x0; |
| 247 | |
| 248 | /* bits to use are either S_IRWXU or S_IRWXG or S_IRWXO */ |
| 249 | mode &= bits_to_use; |
| 250 | |
| 251 | /* check for R/W/X UGO since we do not know whose flags |
| 252 | is this but we have cleared all the bits sans RWX for |
| 253 | either user or group or other as per bits_to_use */ |
| 254 | if (mode & S_IRUGO) |
| 255 | *pace_flags |= SET_FILE_READ_RIGHTS; |
| 256 | if (mode & S_IWUGO) |
| 257 | *pace_flags |= SET_FILE_WRITE_RIGHTS; |
| 258 | if (mode & S_IXUGO) |
| 259 | *pace_flags |= SET_FILE_EXEC_RIGHTS; |
| 260 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 261 | cFYI(DBG2, "mode: 0x%x, access flags now 0x%x", mode, *pace_flags); |
Steve French | ce06c9f | 2007-11-08 21:12:01 +0000 | [diff] [blame] | 262 | return; |
| 263 | } |
| 264 | |
Al Viro | 2b210ad | 2008-03-29 03:09:18 +0000 | [diff] [blame] | 265 | static __u16 fill_ace_for_sid(struct cifs_ace *pntace, |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 266 | const struct cifs_sid *psid, __u64 nmode, umode_t bits) |
| 267 | { |
| 268 | int i; |
| 269 | __u16 size = 0; |
| 270 | __u32 access_req = 0; |
| 271 | |
| 272 | pntace->type = ACCESS_ALLOWED; |
| 273 | pntace->flags = 0x0; |
| 274 | mode_to_access_flags(nmode, bits, &access_req); |
| 275 | if (!access_req) |
| 276 | access_req = SET_MINIMUM_RIGHTS; |
| 277 | pntace->access_req = cpu_to_le32(access_req); |
| 278 | |
| 279 | pntace->sid.revision = psid->revision; |
| 280 | pntace->sid.num_subauth = psid->num_subauth; |
| 281 | for (i = 0; i < 6; i++) |
| 282 | pntace->sid.authority[i] = psid->authority[i]; |
| 283 | for (i = 0; i < psid->num_subauth; i++) |
| 284 | pntace->sid.sub_auth[i] = psid->sub_auth[i]; |
| 285 | |
| 286 | size = 1 + 1 + 2 + 4 + 1 + 1 + 6 + (psid->num_subauth * 4); |
| 287 | pntace->size = cpu_to_le16(size); |
| 288 | |
Shirish Pargaonkar | ef571ca | 2008-07-24 15:56:05 +0000 | [diff] [blame] | 289 | return size; |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 290 | } |
| 291 | |
Steve French | 297647c | 2007-10-12 04:11:59 +0000 | [diff] [blame] | 292 | |
Steve French | 953f868 | 2007-10-31 04:54:42 +0000 | [diff] [blame] | 293 | #ifdef CONFIG_CIFS_DEBUG2 |
| 294 | static void dump_ace(struct cifs_ace *pace, char *end_of_acl) |
Shirish Pargaonkar | d0d66c4 | 2007-10-03 18:22:19 +0000 | [diff] [blame] | 295 | { |
Shirish Pargaonkar | d0d66c4 | 2007-10-03 18:22:19 +0000 | [diff] [blame] | 296 | int num_subauth; |
Shirish Pargaonkar | d0d66c4 | 2007-10-03 18:22:19 +0000 | [diff] [blame] | 297 | |
| 298 | /* validate that we do not go past end of acl */ |
Steve French | 297647c | 2007-10-12 04:11:59 +0000 | [diff] [blame] | 299 | |
Steve French | 44093ca | 2007-10-23 21:22:55 +0000 | [diff] [blame] | 300 | if (le16_to_cpu(pace->size) < 16) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 301 | cERROR(1, "ACE too small %d", le16_to_cpu(pace->size)); |
Steve French | 44093ca | 2007-10-23 21:22:55 +0000 | [diff] [blame] | 302 | return; |
| 303 | } |
| 304 | |
| 305 | if (end_of_acl < (char *)pace + le16_to_cpu(pace->size)) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 306 | cERROR(1, "ACL too small to parse ACE"); |
Shirish Pargaonkar | d0d66c4 | 2007-10-03 18:22:19 +0000 | [diff] [blame] | 307 | return; |
Steve French | 44093ca | 2007-10-23 21:22:55 +0000 | [diff] [blame] | 308 | } |
Shirish Pargaonkar | d0d66c4 | 2007-10-03 18:22:19 +0000 | [diff] [blame] | 309 | |
Steve French | 44093ca | 2007-10-23 21:22:55 +0000 | [diff] [blame] | 310 | num_subauth = pace->sid.num_subauth; |
Shirish Pargaonkar | d0d66c4 | 2007-10-03 18:22:19 +0000 | [diff] [blame] | 311 | if (num_subauth) { |
Steve French | 8f18c13 | 2007-10-12 18:54:12 +0000 | [diff] [blame] | 312 | int i; |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 313 | cFYI(1, "ACE revision %d num_auth %d type %d flags %d size %d", |
Steve French | 44093ca | 2007-10-23 21:22:55 +0000 | [diff] [blame] | 314 | pace->sid.revision, pace->sid.num_subauth, pace->type, |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 315 | pace->flags, le16_to_cpu(pace->size)); |
Steve French | d12fd12 | 2007-10-03 19:43:19 +0000 | [diff] [blame] | 316 | for (i = 0; i < num_subauth; ++i) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 317 | cFYI(1, "ACE sub_auth[%d]: 0x%x", i, |
| 318 | le32_to_cpu(pace->sid.sub_auth[i])); |
Steve French | d12fd12 | 2007-10-03 19:43:19 +0000 | [diff] [blame] | 319 | } |
Shirish Pargaonkar | d0d66c4 | 2007-10-03 18:22:19 +0000 | [diff] [blame] | 320 | |
Steve French | d12fd12 | 2007-10-03 19:43:19 +0000 | [diff] [blame] | 321 | /* BB add length check to make sure that we do not have huge |
| 322 | num auths and therefore go off the end */ |
Steve French | d12fd12 | 2007-10-03 19:43:19 +0000 | [diff] [blame] | 323 | } |
Shirish Pargaonkar | d0d66c4 | 2007-10-03 18:22:19 +0000 | [diff] [blame] | 324 | |
Steve French | d12fd12 | 2007-10-03 19:43:19 +0000 | [diff] [blame] | 325 | return; |
| 326 | } |
Steve French | 953f868 | 2007-10-31 04:54:42 +0000 | [diff] [blame] | 327 | #endif |
Shirish Pargaonkar | d0d66c4 | 2007-10-03 18:22:19 +0000 | [diff] [blame] | 328 | |
Shirish Pargaonkar | d0d66c4 | 2007-10-03 18:22:19 +0000 | [diff] [blame] | 329 | |
Steve French | a750e77 | 2007-10-17 22:50:39 +0000 | [diff] [blame] | 330 | static void parse_dacl(struct cifs_acl *pdacl, char *end_of_acl, |
Steve French | d61e580 | 2007-10-26 04:32:43 +0000 | [diff] [blame] | 331 | struct cifs_sid *pownersid, struct cifs_sid *pgrpsid, |
Jeff Layton | 0b8f18e | 2009-07-09 01:46:37 -0400 | [diff] [blame] | 332 | struct cifs_fattr *fattr) |
Shirish Pargaonkar | d0d66c4 | 2007-10-03 18:22:19 +0000 | [diff] [blame] | 333 | { |
| 334 | int i; |
| 335 | int num_aces = 0; |
| 336 | int acl_size; |
| 337 | char *acl_base; |
Shirish Pargaonkar | d0d66c4 | 2007-10-03 18:22:19 +0000 | [diff] [blame] | 338 | struct cifs_ace **ppace; |
| 339 | |
| 340 | /* BB need to add parm so we can store the SID BB */ |
| 341 | |
Steve French | 2b83457 | 2007-11-25 10:01:00 +0000 | [diff] [blame] | 342 | if (!pdacl) { |
| 343 | /* no DACL in the security descriptor, set |
| 344 | all the permissions for user/group/other */ |
Jeff Layton | 0b8f18e | 2009-07-09 01:46:37 -0400 | [diff] [blame] | 345 | fattr->cf_mode |= S_IRWXUGO; |
Steve French | 2b83457 | 2007-11-25 10:01:00 +0000 | [diff] [blame] | 346 | return; |
| 347 | } |
| 348 | |
Shirish Pargaonkar | d0d66c4 | 2007-10-03 18:22:19 +0000 | [diff] [blame] | 349 | /* validate that we do not go past end of acl */ |
Steve French | af6f461 | 2007-10-16 18:40:37 +0000 | [diff] [blame] | 350 | if (end_of_acl < (char *)pdacl + le16_to_cpu(pdacl->size)) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 351 | cERROR(1, "ACL too small to parse DACL"); |
Shirish Pargaonkar | d0d66c4 | 2007-10-03 18:22:19 +0000 | [diff] [blame] | 352 | return; |
| 353 | } |
| 354 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 355 | cFYI(DBG2, "DACL revision %d size %d num aces %d", |
Steve French | af6f461 | 2007-10-16 18:40:37 +0000 | [diff] [blame] | 356 | le16_to_cpu(pdacl->revision), le16_to_cpu(pdacl->size), |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 357 | le32_to_cpu(pdacl->num_aces)); |
Shirish Pargaonkar | d0d66c4 | 2007-10-03 18:22:19 +0000 | [diff] [blame] | 358 | |
Steve French | 7505e05 | 2007-11-01 18:03:01 +0000 | [diff] [blame] | 359 | /* reset rwx permissions for user/group/other. |
| 360 | Also, if num_aces is 0 i.e. DACL has no ACEs, |
| 361 | user/group/other have no permissions */ |
Jeff Layton | 0b8f18e | 2009-07-09 01:46:37 -0400 | [diff] [blame] | 362 | fattr->cf_mode &= ~(S_IRWXUGO); |
Steve French | 7505e05 | 2007-11-01 18:03:01 +0000 | [diff] [blame] | 363 | |
Shirish Pargaonkar | d0d66c4 | 2007-10-03 18:22:19 +0000 | [diff] [blame] | 364 | acl_base = (char *)pdacl; |
| 365 | acl_size = sizeof(struct cifs_acl); |
| 366 | |
Steve French | adbc035 | 2007-10-17 02:12:46 +0000 | [diff] [blame] | 367 | num_aces = le32_to_cpu(pdacl->num_aces); |
Shirish Pargaonkar | d0d66c4 | 2007-10-03 18:22:19 +0000 | [diff] [blame] | 368 | if (num_aces > 0) { |
Steve French | 15b0395 | 2007-11-08 17:57:40 +0000 | [diff] [blame] | 369 | umode_t user_mask = S_IRWXU; |
| 370 | umode_t group_mask = S_IRWXG; |
Shirish Pargaonkar | 2fbc2f1 | 2010-12-06 14:56:46 -0600 | [diff] [blame] | 371 | umode_t other_mask = S_IRWXU | S_IRWXG | S_IRWXO; |
Steve French | 15b0395 | 2007-11-08 17:57:40 +0000 | [diff] [blame] | 372 | |
Shirish Pargaonkar | d0d66c4 | 2007-10-03 18:22:19 +0000 | [diff] [blame] | 373 | ppace = kmalloc(num_aces * sizeof(struct cifs_ace *), |
| 374 | GFP_KERNEL); |
Stanislav Fomichev | 8132b65 | 2011-02-06 02:05:28 +0300 | [diff] [blame] | 375 | if (!ppace) { |
| 376 | cERROR(1, "DACL memory allocation error"); |
| 377 | return; |
| 378 | } |
Shirish Pargaonkar | d0d66c4 | 2007-10-03 18:22:19 +0000 | [diff] [blame] | 379 | |
Shirish Pargaonkar | d0d66c4 | 2007-10-03 18:22:19 +0000 | [diff] [blame] | 380 | for (i = 0; i < num_aces; ++i) { |
Steve French | 44093ca | 2007-10-23 21:22:55 +0000 | [diff] [blame] | 381 | ppace[i] = (struct cifs_ace *) (acl_base + acl_size); |
Steve French | 953f868 | 2007-10-31 04:54:42 +0000 | [diff] [blame] | 382 | #ifdef CONFIG_CIFS_DEBUG2 |
| 383 | dump_ace(ppace[i], end_of_acl); |
| 384 | #endif |
Shirish Pargaonkar | e01b640 | 2007-10-30 04:45:14 +0000 | [diff] [blame] | 385 | if (compare_sids(&(ppace[i]->sid), pownersid)) |
| 386 | access_flags_to_mode(ppace[i]->access_req, |
Steve French | 15b0395 | 2007-11-08 17:57:40 +0000 | [diff] [blame] | 387 | ppace[i]->type, |
Jeff Layton | 0b8f18e | 2009-07-09 01:46:37 -0400 | [diff] [blame] | 388 | &fattr->cf_mode, |
Steve French | 15b0395 | 2007-11-08 17:57:40 +0000 | [diff] [blame] | 389 | &user_mask); |
Shirish Pargaonkar | e01b640 | 2007-10-30 04:45:14 +0000 | [diff] [blame] | 390 | if (compare_sids(&(ppace[i]->sid), pgrpsid)) |
| 391 | access_flags_to_mode(ppace[i]->access_req, |
Steve French | 15b0395 | 2007-11-08 17:57:40 +0000 | [diff] [blame] | 392 | ppace[i]->type, |
Jeff Layton | 0b8f18e | 2009-07-09 01:46:37 -0400 | [diff] [blame] | 393 | &fattr->cf_mode, |
Steve French | 15b0395 | 2007-11-08 17:57:40 +0000 | [diff] [blame] | 394 | &group_mask); |
Shirish Pargaonkar | e01b640 | 2007-10-30 04:45:14 +0000 | [diff] [blame] | 395 | if (compare_sids(&(ppace[i]->sid), &sid_everyone)) |
| 396 | access_flags_to_mode(ppace[i]->access_req, |
Steve French | 15b0395 | 2007-11-08 17:57:40 +0000 | [diff] [blame] | 397 | ppace[i]->type, |
Jeff Layton | 0b8f18e | 2009-07-09 01:46:37 -0400 | [diff] [blame] | 398 | &fattr->cf_mode, |
Steve French | 15b0395 | 2007-11-08 17:57:40 +0000 | [diff] [blame] | 399 | &other_mask); |
Shirish Pargaonkar | 2fbc2f1 | 2010-12-06 14:56:46 -0600 | [diff] [blame] | 400 | if (compare_sids(&(ppace[i]->sid), &sid_authusers)) |
| 401 | access_flags_to_mode(ppace[i]->access_req, |
| 402 | ppace[i]->type, |
| 403 | &fattr->cf_mode, |
| 404 | &other_mask); |
| 405 | |
Shirish Pargaonkar | e01b640 | 2007-10-30 04:45:14 +0000 | [diff] [blame] | 406 | |
Steve French | 44093ca | 2007-10-23 21:22:55 +0000 | [diff] [blame] | 407 | /* memcpy((void *)(&(cifscred->aces[i])), |
Steve French | d12fd12 | 2007-10-03 19:43:19 +0000 | [diff] [blame] | 408 | (void *)ppace[i], |
| 409 | sizeof(struct cifs_ace)); */ |
Shirish Pargaonkar | d0d66c4 | 2007-10-03 18:22:19 +0000 | [diff] [blame] | 410 | |
Steve French | 44093ca | 2007-10-23 21:22:55 +0000 | [diff] [blame] | 411 | acl_base = (char *)ppace[i]; |
| 412 | acl_size = le16_to_cpu(ppace[i]->size); |
Shirish Pargaonkar | d0d66c4 | 2007-10-03 18:22:19 +0000 | [diff] [blame] | 413 | } |
| 414 | |
| 415 | kfree(ppace); |
Shirish Pargaonkar | d0d66c4 | 2007-10-03 18:22:19 +0000 | [diff] [blame] | 416 | } |
| 417 | |
| 418 | return; |
| 419 | } |
| 420 | |
Steve French | bcb0203 | 2007-09-25 16:17:24 +0000 | [diff] [blame] | 421 | |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 422 | static int set_chmod_dacl(struct cifs_acl *pndacl, struct cifs_sid *pownersid, |
| 423 | struct cifs_sid *pgrpsid, __u64 nmode) |
| 424 | { |
Al Viro | 2b210ad | 2008-03-29 03:09:18 +0000 | [diff] [blame] | 425 | u16 size = 0; |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 426 | struct cifs_acl *pnndacl; |
| 427 | |
| 428 | pnndacl = (struct cifs_acl *)((char *)pndacl + sizeof(struct cifs_acl)); |
| 429 | |
| 430 | size += fill_ace_for_sid((struct cifs_ace *) ((char *)pnndacl + size), |
| 431 | pownersid, nmode, S_IRWXU); |
| 432 | size += fill_ace_for_sid((struct cifs_ace *)((char *)pnndacl + size), |
| 433 | pgrpsid, nmode, S_IRWXG); |
| 434 | size += fill_ace_for_sid((struct cifs_ace *)((char *)pnndacl + size), |
| 435 | &sid_everyone, nmode, S_IRWXO); |
| 436 | |
| 437 | pndacl->size = cpu_to_le16(size + sizeof(struct cifs_acl)); |
Shirish Pargaonkar | d9f382e | 2008-02-12 20:46:26 +0000 | [diff] [blame] | 438 | pndacl->num_aces = cpu_to_le32(3); |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 439 | |
Shirish Pargaonkar | ef571ca | 2008-07-24 15:56:05 +0000 | [diff] [blame] | 440 | return 0; |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 441 | } |
| 442 | |
| 443 | |
Steve French | bcb0203 | 2007-09-25 16:17:24 +0000 | [diff] [blame] | 444 | static int parse_sid(struct cifs_sid *psid, char *end_of_acl) |
| 445 | { |
| 446 | /* BB need to add parm so we can store the SID BB */ |
| 447 | |
Steve French | b9c7a2b | 2007-10-26 23:40:20 +0000 | [diff] [blame] | 448 | /* validate that we do not go past end of ACL - sid must be at least 8 |
| 449 | bytes long (assuming no sub-auths - e.g. the null SID */ |
| 450 | if (end_of_acl < (char *)psid + 8) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 451 | cERROR(1, "ACL too small to parse SID %p", psid); |
Steve French | bcb0203 | 2007-09-25 16:17:24 +0000 | [diff] [blame] | 452 | return -EINVAL; |
| 453 | } |
Steve French | bcb0203 | 2007-09-25 16:17:24 +0000 | [diff] [blame] | 454 | |
Steve French | af6f461 | 2007-10-16 18:40:37 +0000 | [diff] [blame] | 455 | if (psid->num_subauth) { |
Shirish Pargaonkar | d0d66c4 | 2007-10-03 18:22:19 +0000 | [diff] [blame] | 456 | #ifdef CONFIG_CIFS_DEBUG2 |
Steve French | 8f18c13 | 2007-10-12 18:54:12 +0000 | [diff] [blame] | 457 | int i; |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 458 | cFYI(1, "SID revision %d num_auth %d", |
| 459 | psid->revision, psid->num_subauth); |
Shirish Pargaonkar | d0d66c4 | 2007-10-03 18:22:19 +0000 | [diff] [blame] | 460 | |
Steve French | af6f461 | 2007-10-16 18:40:37 +0000 | [diff] [blame] | 461 | for (i = 0; i < psid->num_subauth; i++) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 462 | cFYI(1, "SID sub_auth[%d]: 0x%x ", i, |
| 463 | le32_to_cpu(psid->sub_auth[i])); |
Shirish Pargaonkar | d0d66c4 | 2007-10-03 18:22:19 +0000 | [diff] [blame] | 464 | } |
| 465 | |
Steve French | d12fd12 | 2007-10-03 19:43:19 +0000 | [diff] [blame] | 466 | /* BB add length check to make sure that we do not have huge |
Shirish Pargaonkar | d0d66c4 | 2007-10-03 18:22:19 +0000 | [diff] [blame] | 467 | num auths and therefore go off the end */ |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 468 | cFYI(1, "RID 0x%x", |
| 469 | le32_to_cpu(psid->sub_auth[psid->num_subauth-1])); |
Steve French | bcb0203 | 2007-09-25 16:17:24 +0000 | [diff] [blame] | 470 | #endif |
Shirish Pargaonkar | d0d66c4 | 2007-10-03 18:22:19 +0000 | [diff] [blame] | 471 | } |
| 472 | |
Steve French | bcb0203 | 2007-09-25 16:17:24 +0000 | [diff] [blame] | 473 | return 0; |
| 474 | } |
| 475 | |
Shirish Pargaonkar | d0d66c4 | 2007-10-03 18:22:19 +0000 | [diff] [blame] | 476 | |
Steve French | bcb0203 | 2007-09-25 16:17:24 +0000 | [diff] [blame] | 477 | /* Convert CIFS ACL to POSIX form */ |
Steve French | 630f3f0 | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 478 | static int parse_sec_desc(struct cifs_ntsd *pntsd, int acl_len, |
Jeff Layton | 0b8f18e | 2009-07-09 01:46:37 -0400 | [diff] [blame] | 479 | struct cifs_fattr *fattr) |
Steve French | bcb0203 | 2007-09-25 16:17:24 +0000 | [diff] [blame] | 480 | { |
Shirish Pargaonkar | d0d66c4 | 2007-10-03 18:22:19 +0000 | [diff] [blame] | 481 | int rc; |
Steve French | bcb0203 | 2007-09-25 16:17:24 +0000 | [diff] [blame] | 482 | struct cifs_sid *owner_sid_ptr, *group_sid_ptr; |
| 483 | struct cifs_acl *dacl_ptr; /* no need for SACL ptr */ |
Steve French | bcb0203 | 2007-09-25 16:17:24 +0000 | [diff] [blame] | 484 | char *end_of_acl = ((char *)pntsd) + acl_len; |
Steve French | 7505e05 | 2007-11-01 18:03:01 +0000 | [diff] [blame] | 485 | __u32 dacloffset; |
Steve French | bcb0203 | 2007-09-25 16:17:24 +0000 | [diff] [blame] | 486 | |
Jeff Layton | 0b8f18e | 2009-07-09 01:46:37 -0400 | [diff] [blame] | 487 | if (pntsd == NULL) |
Steve French | b9c7a2b | 2007-10-26 23:40:20 +0000 | [diff] [blame] | 488 | return -EIO; |
| 489 | |
Steve French | bcb0203 | 2007-09-25 16:17:24 +0000 | [diff] [blame] | 490 | owner_sid_ptr = (struct cifs_sid *)((char *)pntsd + |
Steve French | af6f461 | 2007-10-16 18:40:37 +0000 | [diff] [blame] | 491 | le32_to_cpu(pntsd->osidoffset)); |
Steve French | bcb0203 | 2007-09-25 16:17:24 +0000 | [diff] [blame] | 492 | group_sid_ptr = (struct cifs_sid *)((char *)pntsd + |
Steve French | af6f461 | 2007-10-16 18:40:37 +0000 | [diff] [blame] | 493 | le32_to_cpu(pntsd->gsidoffset)); |
Steve French | 7505e05 | 2007-11-01 18:03:01 +0000 | [diff] [blame] | 494 | dacloffset = le32_to_cpu(pntsd->dacloffset); |
Steve French | 63d2583 | 2007-11-05 21:46:10 +0000 | [diff] [blame] | 495 | dacl_ptr = (struct cifs_acl *)((char *)pntsd + dacloffset); |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 496 | cFYI(DBG2, "revision %d type 0x%x ooffset 0x%x goffset 0x%x " |
Steve French | bcb0203 | 2007-09-25 16:17:24 +0000 | [diff] [blame] | 497 | "sacloffset 0x%x dacloffset 0x%x", |
Steve French | af6f461 | 2007-10-16 18:40:37 +0000 | [diff] [blame] | 498 | pntsd->revision, pntsd->type, le32_to_cpu(pntsd->osidoffset), |
| 499 | le32_to_cpu(pntsd->gsidoffset), |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 500 | le32_to_cpu(pntsd->sacloffset), dacloffset); |
Steve French | b9c7a2b | 2007-10-26 23:40:20 +0000 | [diff] [blame] | 501 | /* cifs_dump_mem("owner_sid: ", owner_sid_ptr, 64); */ |
Steve French | bcb0203 | 2007-09-25 16:17:24 +0000 | [diff] [blame] | 502 | rc = parse_sid(owner_sid_ptr, end_of_acl); |
| 503 | if (rc) |
| 504 | return rc; |
| 505 | |
| 506 | rc = parse_sid(group_sid_ptr, end_of_acl); |
| 507 | if (rc) |
| 508 | return rc; |
| 509 | |
Steve French | 7505e05 | 2007-11-01 18:03:01 +0000 | [diff] [blame] | 510 | if (dacloffset) |
| 511 | parse_dacl(dacl_ptr, end_of_acl, owner_sid_ptr, |
Jeff Layton | 0b8f18e | 2009-07-09 01:46:37 -0400 | [diff] [blame] | 512 | group_sid_ptr, fattr); |
Steve French | 7505e05 | 2007-11-01 18:03:01 +0000 | [diff] [blame] | 513 | else |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 514 | cFYI(1, "no ACL"); /* BB grant all or default perms? */ |
Shirish Pargaonkar | d0d66c4 | 2007-10-03 18:22:19 +0000 | [diff] [blame] | 515 | |
Steve French | bcb0203 | 2007-09-25 16:17:24 +0000 | [diff] [blame] | 516 | /* cifscred->uid = owner_sid_ptr->rid; |
| 517 | cifscred->gid = group_sid_ptr->rid; |
| 518 | memcpy((void *)(&(cifscred->osid)), (void *)owner_sid_ptr, |
Steve French | 630f3f0 | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 519 | sizeof(struct cifs_sid)); |
Steve French | bcb0203 | 2007-09-25 16:17:24 +0000 | [diff] [blame] | 520 | memcpy((void *)(&(cifscred->gsid)), (void *)group_sid_ptr, |
Steve French | 630f3f0 | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 521 | sizeof(struct cifs_sid)); */ |
Steve French | bcb0203 | 2007-09-25 16:17:24 +0000 | [diff] [blame] | 522 | |
Shirish Pargaonkar | ef571ca | 2008-07-24 15:56:05 +0000 | [diff] [blame] | 523 | return 0; |
Steve French | bcb0203 | 2007-09-25 16:17:24 +0000 | [diff] [blame] | 524 | } |
Steve French | b9c7a2b | 2007-10-26 23:40:20 +0000 | [diff] [blame] | 525 | |
| 526 | |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 527 | /* Convert permission bits from mode to equivalent CIFS ACL */ |
| 528 | static int build_sec_desc(struct cifs_ntsd *pntsd, struct cifs_ntsd *pnntsd, |
Steve French | cce246e | 2008-04-09 20:55:31 +0000 | [diff] [blame] | 529 | struct inode *inode, __u64 nmode) |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 530 | { |
| 531 | int rc = 0; |
| 532 | __u32 dacloffset; |
| 533 | __u32 ndacloffset; |
| 534 | __u32 sidsoffset; |
| 535 | struct cifs_sid *owner_sid_ptr, *group_sid_ptr; |
| 536 | struct cifs_acl *dacl_ptr = NULL; /* no need for SACL ptr */ |
| 537 | struct cifs_acl *ndacl_ptr = NULL; /* no need for SACL ptr */ |
| 538 | |
| 539 | if ((inode == NULL) || (pntsd == NULL) || (pnntsd == NULL)) |
Shirish Pargaonkar | ef571ca | 2008-07-24 15:56:05 +0000 | [diff] [blame] | 540 | return -EIO; |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 541 | |
| 542 | owner_sid_ptr = (struct cifs_sid *)((char *)pntsd + |
| 543 | le32_to_cpu(pntsd->osidoffset)); |
| 544 | group_sid_ptr = (struct cifs_sid *)((char *)pntsd + |
| 545 | le32_to_cpu(pntsd->gsidoffset)); |
| 546 | |
| 547 | dacloffset = le32_to_cpu(pntsd->dacloffset); |
| 548 | dacl_ptr = (struct cifs_acl *)((char *)pntsd + dacloffset); |
| 549 | |
| 550 | ndacloffset = sizeof(struct cifs_ntsd); |
| 551 | ndacl_ptr = (struct cifs_acl *)((char *)pnntsd + ndacloffset); |
| 552 | ndacl_ptr->revision = dacl_ptr->revision; |
| 553 | ndacl_ptr->size = 0; |
| 554 | ndacl_ptr->num_aces = 0; |
| 555 | |
| 556 | rc = set_chmod_dacl(ndacl_ptr, owner_sid_ptr, group_sid_ptr, nmode); |
| 557 | |
| 558 | sidsoffset = ndacloffset + le16_to_cpu(ndacl_ptr->size); |
| 559 | |
| 560 | /* copy security descriptor control portion and owner and group sid */ |
| 561 | copy_sec_desc(pntsd, pnntsd, sidsoffset); |
| 562 | |
Shirish Pargaonkar | ef571ca | 2008-07-24 15:56:05 +0000 | [diff] [blame] | 563 | return rc; |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 564 | } |
| 565 | |
Christoph Hellwig | 1bf4072 | 2009-05-27 09:37:33 -0400 | [diff] [blame] | 566 | static struct cifs_ntsd *get_cifs_acl_by_fid(struct cifs_sb_info *cifs_sb, |
| 567 | __u16 fid, u32 *pacllen) |
Steve French | b9c7a2b | 2007-10-26 23:40:20 +0000 | [diff] [blame] | 568 | { |
Steve French | b9c7a2b | 2007-10-26 23:40:20 +0000 | [diff] [blame] | 569 | struct cifs_ntsd *pntsd = NULL; |
Christoph Hellwig | 1bf4072 | 2009-05-27 09:37:33 -0400 | [diff] [blame] | 570 | int xid, rc; |
Jeff Layton | 7ffec37 | 2010-09-29 19:51:11 -0400 | [diff] [blame] | 571 | struct tcon_link *tlink = cifs_sb_tlink(cifs_sb); |
| 572 | |
| 573 | if (IS_ERR(tlink)) |
Shirish Pargaonkar | 987b21d | 2010-11-10 07:50:35 -0600 | [diff] [blame] | 574 | return ERR_CAST(tlink); |
Steve French | b9c7a2b | 2007-10-26 23:40:20 +0000 | [diff] [blame] | 575 | |
| 576 | xid = GetXid(); |
Jeff Layton | 7ffec37 | 2010-09-29 19:51:11 -0400 | [diff] [blame] | 577 | rc = CIFSSMBGetCIFSACL(xid, tlink_tcon(tlink), fid, &pntsd, pacllen); |
Christoph Hellwig | 1bf4072 | 2009-05-27 09:37:33 -0400 | [diff] [blame] | 578 | FreeXid(xid); |
Steve French | 8b1327f | 2008-03-14 22:37:16 +0000 | [diff] [blame] | 579 | |
Jeff Layton | 7ffec37 | 2010-09-29 19:51:11 -0400 | [diff] [blame] | 580 | cifs_put_tlink(tlink); |
Steve French | b9c7a2b | 2007-10-26 23:40:20 +0000 | [diff] [blame] | 581 | |
Shirish Pargaonkar | 987b21d | 2010-11-10 07:50:35 -0600 | [diff] [blame] | 582 | cFYI(1, "%s: rc = %d ACL len %d", __func__, rc, *pacllen); |
| 583 | if (rc) |
| 584 | return ERR_PTR(rc); |
Christoph Hellwig | 1bf4072 | 2009-05-27 09:37:33 -0400 | [diff] [blame] | 585 | return pntsd; |
| 586 | } |
| 587 | |
| 588 | static struct cifs_ntsd *get_cifs_acl_by_path(struct cifs_sb_info *cifs_sb, |
| 589 | const char *path, u32 *pacllen) |
| 590 | { |
| 591 | struct cifs_ntsd *pntsd = NULL; |
| 592 | int oplock = 0; |
| 593 | int xid, rc; |
| 594 | __u16 fid; |
Jeff Layton | 7ffec37 | 2010-09-29 19:51:11 -0400 | [diff] [blame] | 595 | struct cifsTconInfo *tcon; |
| 596 | struct tcon_link *tlink = cifs_sb_tlink(cifs_sb); |
Christoph Hellwig | 1bf4072 | 2009-05-27 09:37:33 -0400 | [diff] [blame] | 597 | |
Jeff Layton | 7ffec37 | 2010-09-29 19:51:11 -0400 | [diff] [blame] | 598 | if (IS_ERR(tlink)) |
Shirish Pargaonkar | 987b21d | 2010-11-10 07:50:35 -0600 | [diff] [blame] | 599 | return ERR_CAST(tlink); |
Jeff Layton | 7ffec37 | 2010-09-29 19:51:11 -0400 | [diff] [blame] | 600 | |
| 601 | tcon = tlink_tcon(tlink); |
Christoph Hellwig | 1bf4072 | 2009-05-27 09:37:33 -0400 | [diff] [blame] | 602 | xid = GetXid(); |
| 603 | |
Jeff Layton | 7ffec37 | 2010-09-29 19:51:11 -0400 | [diff] [blame] | 604 | rc = CIFSSMBOpen(xid, tcon, path, FILE_OPEN, READ_CONTROL, 0, |
Christoph Hellwig | 1bf4072 | 2009-05-27 09:37:33 -0400 | [diff] [blame] | 605 | &fid, &oplock, NULL, cifs_sb->local_nls, |
| 606 | cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR); |
Shirish Pargaonkar | 987b21d | 2010-11-10 07:50:35 -0600 | [diff] [blame] | 607 | if (!rc) { |
| 608 | rc = CIFSSMBGetCIFSACL(xid, tcon, fid, &pntsd, pacllen); |
| 609 | CIFSSMBClose(xid, tcon, fid); |
Steve French | b9c7a2b | 2007-10-26 23:40:20 +0000 | [diff] [blame] | 610 | } |
| 611 | |
Jeff Layton | 7ffec37 | 2010-09-29 19:51:11 -0400 | [diff] [blame] | 612 | cifs_put_tlink(tlink); |
Steve French | b9c7a2b | 2007-10-26 23:40:20 +0000 | [diff] [blame] | 613 | FreeXid(xid); |
Shirish Pargaonkar | 987b21d | 2010-11-10 07:50:35 -0600 | [diff] [blame] | 614 | |
| 615 | cFYI(1, "%s: rc = %d ACL len %d", __func__, rc, *pacllen); |
| 616 | if (rc) |
| 617 | return ERR_PTR(rc); |
Steve French | 7505e05 | 2007-11-01 18:03:01 +0000 | [diff] [blame] | 618 | return pntsd; |
| 619 | } |
| 620 | |
Christoph Hellwig | 1bf4072 | 2009-05-27 09:37:33 -0400 | [diff] [blame] | 621 | /* Retrieve an ACL from the server */ |
Shirish Pargaonkar | fbeba8b | 2010-11-27 11:37:54 -0600 | [diff] [blame] | 622 | struct cifs_ntsd *get_cifs_acl(struct cifs_sb_info *cifs_sb, |
Christoph Hellwig | 1bf4072 | 2009-05-27 09:37:33 -0400 | [diff] [blame] | 623 | struct inode *inode, const char *path, |
| 624 | u32 *pacllen) |
| 625 | { |
| 626 | struct cifs_ntsd *pntsd = NULL; |
| 627 | struct cifsFileInfo *open_file = NULL; |
| 628 | |
| 629 | if (inode) |
Jeff Layton | 6508d90 | 2010-09-29 19:51:11 -0400 | [diff] [blame] | 630 | open_file = find_readable_file(CIFS_I(inode), true); |
Christoph Hellwig | 1bf4072 | 2009-05-27 09:37:33 -0400 | [diff] [blame] | 631 | if (!open_file) |
| 632 | return get_cifs_acl_by_path(cifs_sb, path, pacllen); |
| 633 | |
| 634 | pntsd = get_cifs_acl_by_fid(cifs_sb, open_file->netfid, pacllen); |
Dave Kleikamp | 6ab409b | 2009-08-31 11:07:12 -0400 | [diff] [blame] | 635 | cifsFileInfo_put(open_file); |
Christoph Hellwig | 1bf4072 | 2009-05-27 09:37:33 -0400 | [diff] [blame] | 636 | return pntsd; |
| 637 | } |
| 638 | |
Christoph Hellwig | b96d31a | 2009-05-27 09:37:33 -0400 | [diff] [blame] | 639 | static int set_cifs_acl_by_fid(struct cifs_sb_info *cifs_sb, __u16 fid, |
| 640 | struct cifs_ntsd *pnntsd, u32 acllen) |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 641 | { |
Christoph Hellwig | b96d31a | 2009-05-27 09:37:33 -0400 | [diff] [blame] | 642 | int xid, rc; |
Jeff Layton | 7ffec37 | 2010-09-29 19:51:11 -0400 | [diff] [blame] | 643 | struct tcon_link *tlink = cifs_sb_tlink(cifs_sb); |
| 644 | |
| 645 | if (IS_ERR(tlink)) |
| 646 | return PTR_ERR(tlink); |
Christoph Hellwig | b96d31a | 2009-05-27 09:37:33 -0400 | [diff] [blame] | 647 | |
| 648 | xid = GetXid(); |
Jeff Layton | 7ffec37 | 2010-09-29 19:51:11 -0400 | [diff] [blame] | 649 | rc = CIFSSMBSetCIFSACL(xid, tlink_tcon(tlink), fid, pnntsd, acllen); |
Christoph Hellwig | b96d31a | 2009-05-27 09:37:33 -0400 | [diff] [blame] | 650 | FreeXid(xid); |
Jeff Layton | 7ffec37 | 2010-09-29 19:51:11 -0400 | [diff] [blame] | 651 | cifs_put_tlink(tlink); |
Christoph Hellwig | b96d31a | 2009-05-27 09:37:33 -0400 | [diff] [blame] | 652 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 653 | cFYI(DBG2, "SetCIFSACL rc = %d", rc); |
Christoph Hellwig | b96d31a | 2009-05-27 09:37:33 -0400 | [diff] [blame] | 654 | return rc; |
| 655 | } |
| 656 | |
| 657 | static int set_cifs_acl_by_path(struct cifs_sb_info *cifs_sb, const char *path, |
| 658 | struct cifs_ntsd *pnntsd, u32 acllen) |
| 659 | { |
| 660 | int oplock = 0; |
| 661 | int xid, rc; |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 662 | __u16 fid; |
Jeff Layton | 7ffec37 | 2010-09-29 19:51:11 -0400 | [diff] [blame] | 663 | struct cifsTconInfo *tcon; |
| 664 | struct tcon_link *tlink = cifs_sb_tlink(cifs_sb); |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 665 | |
Jeff Layton | 7ffec37 | 2010-09-29 19:51:11 -0400 | [diff] [blame] | 666 | if (IS_ERR(tlink)) |
| 667 | return PTR_ERR(tlink); |
| 668 | |
| 669 | tcon = tlink_tcon(tlink); |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 670 | xid = GetXid(); |
| 671 | |
Jeff Layton | 7ffec37 | 2010-09-29 19:51:11 -0400 | [diff] [blame] | 672 | rc = CIFSSMBOpen(xid, tcon, path, FILE_OPEN, WRITE_DAC, 0, |
Christoph Hellwig | b96d31a | 2009-05-27 09:37:33 -0400 | [diff] [blame] | 673 | &fid, &oplock, NULL, cifs_sb->local_nls, |
| 674 | cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR); |
| 675 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 676 | cERROR(1, "Unable to open file to set ACL"); |
Christoph Hellwig | b96d31a | 2009-05-27 09:37:33 -0400 | [diff] [blame] | 677 | goto out; |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 678 | } |
| 679 | |
Jeff Layton | 7ffec37 | 2010-09-29 19:51:11 -0400 | [diff] [blame] | 680 | rc = CIFSSMBSetCIFSACL(xid, tcon, fid, pnntsd, acllen); |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 681 | cFYI(DBG2, "SetCIFSACL rc = %d", rc); |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 682 | |
Jeff Layton | 7ffec37 | 2010-09-29 19:51:11 -0400 | [diff] [blame] | 683 | CIFSSMBClose(xid, tcon, fid); |
| 684 | out: |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 685 | FreeXid(xid); |
Jeff Layton | 7ffec37 | 2010-09-29 19:51:11 -0400 | [diff] [blame] | 686 | cifs_put_tlink(tlink); |
Christoph Hellwig | b96d31a | 2009-05-27 09:37:33 -0400 | [diff] [blame] | 687 | return rc; |
| 688 | } |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 689 | |
Christoph Hellwig | b96d31a | 2009-05-27 09:37:33 -0400 | [diff] [blame] | 690 | /* Set an ACL on the server */ |
| 691 | static int set_cifs_acl(struct cifs_ntsd *pnntsd, __u32 acllen, |
| 692 | struct inode *inode, const char *path) |
| 693 | { |
| 694 | struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); |
| 695 | struct cifsFileInfo *open_file; |
| 696 | int rc; |
| 697 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 698 | cFYI(DBG2, "set ACL for %s from mode 0x%x", path, inode->i_mode); |
Christoph Hellwig | b96d31a | 2009-05-27 09:37:33 -0400 | [diff] [blame] | 699 | |
Jeff Layton | 6508d90 | 2010-09-29 19:51:11 -0400 | [diff] [blame] | 700 | open_file = find_readable_file(CIFS_I(inode), true); |
Christoph Hellwig | b96d31a | 2009-05-27 09:37:33 -0400 | [diff] [blame] | 701 | if (!open_file) |
| 702 | return set_cifs_acl_by_path(cifs_sb, path, pnntsd, acllen); |
| 703 | |
| 704 | rc = set_cifs_acl_by_fid(cifs_sb, open_file->netfid, pnntsd, acllen); |
Dave Kleikamp | 6ab409b | 2009-08-31 11:07:12 -0400 | [diff] [blame] | 705 | cifsFileInfo_put(open_file); |
Shirish Pargaonkar | ef571ca | 2008-07-24 15:56:05 +0000 | [diff] [blame] | 706 | return rc; |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 707 | } |
| 708 | |
Steve French | 7505e05 | 2007-11-01 18:03:01 +0000 | [diff] [blame] | 709 | /* Translate the CIFS ACL (simlar to NTFS ACL) for a file into mode bits */ |
Shirish Pargaonkar | 987b21d | 2010-11-10 07:50:35 -0600 | [diff] [blame] | 710 | int |
Jeff Layton | 0b8f18e | 2009-07-09 01:46:37 -0400 | [diff] [blame] | 711 | cifs_acl_to_fattr(struct cifs_sb_info *cifs_sb, struct cifs_fattr *fattr, |
| 712 | struct inode *inode, const char *path, const __u16 *pfid) |
Steve French | 7505e05 | 2007-11-01 18:03:01 +0000 | [diff] [blame] | 713 | { |
| 714 | struct cifs_ntsd *pntsd = NULL; |
| 715 | u32 acllen = 0; |
| 716 | int rc = 0; |
| 717 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 718 | cFYI(DBG2, "converting ACL to mode for %s", path); |
Christoph Hellwig | 1bf4072 | 2009-05-27 09:37:33 -0400 | [diff] [blame] | 719 | |
| 720 | if (pfid) |
| 721 | pntsd = get_cifs_acl_by_fid(cifs_sb, *pfid, &acllen); |
| 722 | else |
| 723 | pntsd = get_cifs_acl(cifs_sb, inode, path, &acllen); |
Steve French | 7505e05 | 2007-11-01 18:03:01 +0000 | [diff] [blame] | 724 | |
| 725 | /* if we can retrieve the ACL, now parse Access Control Entries, ACEs */ |
Shirish Pargaonkar | 987b21d | 2010-11-10 07:50:35 -0600 | [diff] [blame] | 726 | if (IS_ERR(pntsd)) { |
| 727 | rc = PTR_ERR(pntsd); |
| 728 | cERROR(1, "%s: error %d getting sec desc", __func__, rc); |
| 729 | } else { |
Jeff Layton | 0b8f18e | 2009-07-09 01:46:37 -0400 | [diff] [blame] | 730 | rc = parse_sec_desc(pntsd, acllen, fattr); |
Shirish Pargaonkar | 987b21d | 2010-11-10 07:50:35 -0600 | [diff] [blame] | 731 | kfree(pntsd); |
| 732 | if (rc) |
| 733 | cERROR(1, "parse sec desc failed rc = %d", rc); |
| 734 | } |
Steve French | 7505e05 | 2007-11-01 18:03:01 +0000 | [diff] [blame] | 735 | |
Shirish Pargaonkar | 987b21d | 2010-11-10 07:50:35 -0600 | [diff] [blame] | 736 | return rc; |
Steve French | b9c7a2b | 2007-10-26 23:40:20 +0000 | [diff] [blame] | 737 | } |
Steve French | 953f868 | 2007-10-31 04:54:42 +0000 | [diff] [blame] | 738 | |
Steve French | 7505e05 | 2007-11-01 18:03:01 +0000 | [diff] [blame] | 739 | /* Convert mode bits to an ACL so we can update the ACL on the server */ |
Shirish Pargaonkar | 78415d2 | 2010-11-27 11:37:26 -0600 | [diff] [blame] | 740 | int mode_to_cifs_acl(struct inode *inode, const char *path, __u64 nmode) |
Steve French | 953f868 | 2007-10-31 04:54:42 +0000 | [diff] [blame] | 741 | { |
| 742 | int rc = 0; |
Steve French | cce246e | 2008-04-09 20:55:31 +0000 | [diff] [blame] | 743 | __u32 secdesclen = 0; |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 744 | struct cifs_ntsd *pntsd = NULL; /* acl obtained from server */ |
| 745 | struct cifs_ntsd *pnntsd = NULL; /* modified acl to be sent to server */ |
Steve French | 953f868 | 2007-10-31 04:54:42 +0000 | [diff] [blame] | 746 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 747 | cFYI(DBG2, "set ACL from mode for %s", path); |
Steve French | 953f868 | 2007-10-31 04:54:42 +0000 | [diff] [blame] | 748 | |
| 749 | /* Get the security descriptor */ |
Christoph Hellwig | 1bf4072 | 2009-05-27 09:37:33 -0400 | [diff] [blame] | 750 | pntsd = get_cifs_acl(CIFS_SB(inode->i_sb), inode, path, &secdesclen); |
Steve French | 953f868 | 2007-10-31 04:54:42 +0000 | [diff] [blame] | 751 | |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 752 | /* Add three ACEs for owner, group, everyone getting rid of |
| 753 | other ACEs as chmod disables ACEs and set the security descriptor */ |
Steve French | 953f868 | 2007-10-31 04:54:42 +0000 | [diff] [blame] | 754 | |
Shirish Pargaonkar | 987b21d | 2010-11-10 07:50:35 -0600 | [diff] [blame] | 755 | if (IS_ERR(pntsd)) { |
| 756 | rc = PTR_ERR(pntsd); |
| 757 | cERROR(1, "%s: error %d getting sec desc", __func__, rc); |
| 758 | } else { |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 759 | /* allocate memory for the smb header, |
| 760 | set security descriptor request security descriptor |
| 761 | parameters, and secuirty descriptor itself */ |
Steve French | 953f868 | 2007-10-31 04:54:42 +0000 | [diff] [blame] | 762 | |
Steve French | cce246e | 2008-04-09 20:55:31 +0000 | [diff] [blame] | 763 | secdesclen = secdesclen < DEFSECDESCLEN ? |
| 764 | DEFSECDESCLEN : secdesclen; |
| 765 | pnntsd = kmalloc(secdesclen, GFP_KERNEL); |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 766 | if (!pnntsd) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 767 | cERROR(1, "Unable to allocate security descriptor"); |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 768 | kfree(pntsd); |
Shirish Pargaonkar | ef571ca | 2008-07-24 15:56:05 +0000 | [diff] [blame] | 769 | return -ENOMEM; |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 770 | } |
Steve French | 7505e05 | 2007-11-01 18:03:01 +0000 | [diff] [blame] | 771 | |
Steve French | cce246e | 2008-04-09 20:55:31 +0000 | [diff] [blame] | 772 | rc = build_sec_desc(pntsd, pnntsd, inode, nmode); |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 773 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 774 | cFYI(DBG2, "build_sec_desc rc: %d", rc); |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 775 | |
| 776 | if (!rc) { |
| 777 | /* Set the security descriptor */ |
Steve French | cce246e | 2008-04-09 20:55:31 +0000 | [diff] [blame] | 778 | rc = set_cifs_acl(pnntsd, secdesclen, inode, path); |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 779 | cFYI(DBG2, "set_cifs_acl rc: %d", rc); |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 780 | } |
| 781 | |
| 782 | kfree(pnntsd); |
| 783 | kfree(pntsd); |
| 784 | } |
| 785 | |
Shirish Pargaonkar | ef571ca | 2008-07-24 15:56:05 +0000 | [diff] [blame] | 786 | return rc; |
Steve French | 953f868 | 2007-10-31 04:54:42 +0000 | [diff] [blame] | 787 | } |