source: branches/samba-3.2.x/source/modules/vfs_gpfs.c

Last change on this file was 228, checked in by Herwig Bauernfeind, 16 years ago

Update 3.2 branch to 3.2.6

File size: 23.0 KB
Line 
1/*
2 Unix SMB/CIFS implementation.
3 Wrap gpfs calls in vfs functions.
4
5 Copyright (C) Christian Ambach <cambach1@de.ibm.com> 2006
6
7 Major code contributions by Chetan Shringarpure <chetan.sh@in.ibm.com>
8 and Gomati Mohanan <gomati.mohanan@in.ibm.com>
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 3 of the License, or
13 (at your option) any later version.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>.
22
23
24*/
25
26#include "includes.h"
27
28#undef DBGC_CLASS
29#define DBGC_CLASS DBGC_VFS
30
31#include <gpfs_gpl.h>
32#include "nfs4_acls.h"
33#include "vfs_gpfs.h"
34
35static int vfs_gpfs_kernel_flock(vfs_handle_struct *handle, files_struct *fsp,
36 uint32 share_mode)
37{
38
39 START_PROFILE(syscall_kernel_flock);
40
41 kernel_flock(fsp->fh->fd, share_mode);
42
43 if (!set_gpfs_sharemode(fsp, fsp->access_mask, fsp->share_access)) {
44
45 return -1;
46
47 }
48
49 END_PROFILE(syscall_kernel_flock);
50
51 return 0;
52}
53
54static int vfs_gpfs_setlease(vfs_handle_struct *handle, files_struct *fsp,
55 int leasetype)
56{
57 int ret;
58
59 START_PROFILE(syscall_linux_setlease);
60
61 if ( linux_set_lease_sighandler(fsp->fh->fd) == -1)
62 return -1;
63
64 ret = set_gpfs_lease(fsp->fh->fd,leasetype);
65
66 if ( ret < 0 ) {
67 /* This must have come from GPFS not being available */
68 /* or some other error, hence call the default */
69 ret = linux_setlease(fsp->fh->fd, leasetype);
70 }
71
72 END_PROFILE(syscall_linux_setlease);
73
74 return ret;
75}
76
77
78
79static void gpfs_dumpacl(int level, struct gpfs_acl *gacl)
80{
81 int i;
82 if (gacl==NULL)
83 {
84 DEBUG(0, ("gpfs acl is NULL\n"));
85 return;
86 }
87
88 DEBUG(level, ("gpfs acl: nace: %d, type:%d, version:%d, level:%d, len:%d\n",
89 gacl->acl_nace, gacl->acl_type, gacl->acl_version, gacl->acl_level, gacl->acl_len));
90 for(i=0; i<gacl->acl_nace; i++)
91 {
92 struct gpfs_ace_v4 *gace = gacl->ace_v4 + i;
93 DEBUG(level, ("\tace[%d]: type:%d, flags:0x%x, mask:0x%x, iflags:0x%x, who:%u\n",
94 i, gace->aceType, gace->aceFlags, gace->aceMask,
95 gace->aceIFlags, gace->aceWho));
96 }
97}
98
99static struct gpfs_acl *gpfs_getacl_alloc(const char *fname, gpfs_aclType_t type)
100{
101 struct gpfs_acl *acl;
102 size_t len = 200;
103 int ret;
104 TALLOC_CTX *mem_ctx = talloc_tos();
105
106 acl = (struct gpfs_acl *)TALLOC_SIZE(mem_ctx, len);
107 if (acl == NULL) {
108 errno = ENOMEM;
109 return NULL;
110 }
111
112 acl->acl_len = len;
113 acl->acl_level = 0;
114 acl->acl_version = 0;
115 acl->acl_type = type;
116
117 ret = smbd_gpfs_getacl((char *)fname, GPFS_GETACL_STRUCT | GPFS_ACL_SAMBA, acl);
118 if ((ret != 0) && (errno == ENOSPC)) {
119 struct gpfs_acl *new_acl = (struct gpfs_acl *)TALLOC_SIZE(
120 mem_ctx, acl->acl_len + sizeof(struct gpfs_acl));
121 if (new_acl == NULL) {
122 errno = ENOMEM;
123 return NULL;
124 }
125
126 new_acl->acl_len = acl->acl_len;
127 new_acl->acl_level = acl->acl_level;
128 new_acl->acl_version = acl->acl_version;
129 new_acl->acl_type = acl->acl_type;
130 acl = new_acl;
131
132 ret = smbd_gpfs_getacl((char *)fname, GPFS_GETACL_STRUCT | GPFS_ACL_SAMBA, acl);
133 }
134 if (ret != 0)
135 {
136 DEBUG(8, ("smbd_gpfs_getacl failed with %s\n",strerror(errno)));
137 return NULL;
138 }
139
140 return acl;
141}
142
143/* Tries to get nfs4 acls and returns SMB ACL allocated.
144 * On failure returns 1 if it got non-NFSv4 ACL to prompt
145 * retry with POSIX ACL checks.
146 * On failure returns -1 if there is system (GPFS) error, check errno.
147 * Returns 0 on success
148 */
149static int gpfs_get_nfs4_acl(const char *fname, SMB4ACL_T **ppacl)
150{
151 int i;
152 struct gpfs_acl *gacl = NULL;
153 DEBUG(10, ("gpfs_get_nfs4_acl invoked for %s\n", fname));
154
155 /* First get the real acl length */
156 gacl = gpfs_getacl_alloc(fname, 0);
157 if (gacl == NULL) {
158 DEBUG(9, ("gpfs_getacl failed for %s with %s\n",
159 fname, strerror(errno)));
160 return -1;
161 }
162
163 if (gacl->acl_type != GPFS_ACL_TYPE_NFS4) {
164 DEBUG(10, ("Got non-nfsv4 acl\n"));
165 /* Retry with POSIX ACLs check */
166 return 1;
167 }
168
169 *ppacl = smb_create_smb4acl();
170
171 DEBUG(10, ("len: %d, level: %d, version: %d, nace: %d\n",
172 gacl->acl_len, gacl->acl_level, gacl->acl_version,
173 gacl->acl_nace));
174
175 for (i=0; i<gacl->acl_nace; i++) {
176 struct gpfs_ace_v4 *gace = &gacl->ace_v4[i];
177 SMB_ACE4PROP_T smbace;
178 DEBUG(10, ("type: %d, iflags: %x, flags: %x, mask: %x, "
179 "who: %d\n", gace->aceType, gace->aceIFlags,
180 gace->aceFlags, gace->aceMask, gace->aceWho));
181
182 ZERO_STRUCT(smbace);
183 if (gace->aceIFlags & ACE4_IFLAG_SPECIAL_ID) {
184 smbace.flags |= SMB_ACE4_ID_SPECIAL;
185 switch (gace->aceWho) {
186 case ACE4_SPECIAL_OWNER:
187 smbace.who.special_id = SMB_ACE4_WHO_OWNER;
188 break;
189 case ACE4_SPECIAL_GROUP:
190 smbace.who.special_id = SMB_ACE4_WHO_GROUP;
191 break;
192 case ACE4_SPECIAL_EVERYONE:
193 smbace.who.special_id = SMB_ACE4_WHO_EVERYONE;
194 break;
195 default:
196 DEBUG(8, ("invalid special gpfs id %d "
197 "ignored\n", gace->aceWho));
198 continue; /* don't add it */
199 }
200 } else {
201 if (gace->aceFlags & ACE4_FLAG_GROUP_ID)
202 smbace.who.gid = gace->aceWho;
203 else
204 smbace.who.uid = gace->aceWho;
205 }
206
207 /* remove redundent deny entries */
208 if (i > 0 && gace->aceType == SMB_ACE4_ACCESS_DENIED_ACE_TYPE) {
209 struct gpfs_ace_v4 *prev = &gacl->ace_v4[i-1];
210 if (prev->aceType == SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE &&
211 prev->aceFlags == gace->aceFlags &&
212 prev->aceIFlags == gace->aceIFlags &&
213 (gace->aceMask & prev->aceMask) == 0 &&
214 gace->aceWho == prev->aceWho) {
215 /* its redundent - skip it */
216 continue;
217 }
218 }
219
220 smbace.aceType = gace->aceType;
221 smbace.aceFlags = gace->aceFlags;
222 smbace.aceMask = gace->aceMask;
223 smb_add_ace4(*ppacl, &smbace);
224 }
225
226 return 0;
227}
228
229static NTSTATUS gpfsacl_fget_nt_acl(vfs_handle_struct *handle,
230 files_struct *fsp, uint32 security_info,
231 SEC_DESC **ppdesc)
232{
233 SMB4ACL_T *pacl = NULL;
234 int result;
235
236 *ppdesc = NULL;
237 result = gpfs_get_nfs4_acl(fsp->fsp_name, &pacl);
238
239 if (result == 0)
240 return smb_fget_nt_acl_nfs4(fsp, security_info, ppdesc, pacl);
241
242 if (result > 0) {
243 DEBUG(10, ("retrying with posix acl...\n"));
244 return posix_fget_nt_acl(fsp, security_info, ppdesc);
245 }
246
247 /* GPFS ACL was not read, something wrong happened, error code is set in errno */
248 return map_nt_error_from_unix(errno);
249}
250
251static NTSTATUS gpfsacl_get_nt_acl(vfs_handle_struct *handle,
252 const char *name,
253 uint32 security_info, SEC_DESC **ppdesc)
254{
255 SMB4ACL_T *pacl = NULL;
256 int result;
257
258 *ppdesc = NULL;
259 result = gpfs_get_nfs4_acl(name, &pacl);
260
261 if (result == 0)
262 return smb_get_nt_acl_nfs4(handle->conn, name, security_info, ppdesc, pacl);
263
264 if (result > 0) {
265 DEBUG(10, ("retrying with posix acl...\n"));
266 return posix_get_nt_acl(handle->conn, name, security_info, ppdesc);
267 }
268
269 /* GPFS ACL was not read, something wrong happened, error code is set in errno */
270 return map_nt_error_from_unix(errno);
271}
272
273static bool gpfsacl_process_smbacl(files_struct *fsp, SMB4ACL_T *smbacl)
274{
275 int ret;
276 gpfs_aclLen_t gacl_len;
277 SMB4ACE_T *smbace;
278 struct gpfs_acl *gacl;
279 TALLOC_CTX *mem_ctx = talloc_tos();
280
281 gacl_len = sizeof(struct gpfs_acl) +
282 (smb_get_naces(smbacl)-1)*sizeof(gpfs_ace_v4_t);
283
284 gacl = TALLOC_SIZE(mem_ctx, gacl_len);
285 if (gacl == NULL) {
286 DEBUG(0, ("talloc failed\n"));
287 errno = ENOMEM;
288 return False;
289 }
290
291 gacl->acl_len = gacl_len;
292 gacl->acl_level = 0;
293 gacl->acl_version = GPFS_ACL_VERSION_NFS4;
294 gacl->acl_type = GPFS_ACL_TYPE_NFS4;
295 gacl->acl_nace = 0; /* change later... */
296
297 for (smbace=smb_first_ace4(smbacl); smbace!=NULL; smbace = smb_next_ace4(smbace)) {
298 struct gpfs_ace_v4 *gace = &gacl->ace_v4[gacl->acl_nace];
299 SMB_ACE4PROP_T *aceprop = smb_get_ace4(smbace);
300
301 gace->aceType = aceprop->aceType;
302 gace->aceFlags = aceprop->aceFlags;
303 gace->aceMask = aceprop->aceMask;
304
305 /*
306 * GPFS can't distinguish between WRITE and APPEND on
307 * files, so one being set without the other is an
308 * error. Sorry for the many ()'s :-)
309 */
310
311 if (!fsp->is_directory
312 &&
313 ((((gace->aceMask & ACE4_MASK_WRITE) == 0)
314 && ((gace->aceMask & ACE4_MASK_APPEND) != 0))
315 ||
316 (((gace->aceMask & ACE4_MASK_WRITE) != 0)
317 && ((gace->aceMask & ACE4_MASK_APPEND) == 0)))
318 &&
319 lp_parm_bool(fsp->conn->params->service, "gpfs",
320 "merge_writeappend", True)) {
321 DEBUG(2, ("vfs_gpfs.c: file [%s]: ACE contains "
322 "WRITE^APPEND, setting WRITE|APPEND\n",
323 fsp->fsp_name));
324 gace->aceMask |= ACE4_MASK_WRITE|ACE4_MASK_APPEND;
325 }
326
327 gace->aceIFlags = (aceprop->flags&SMB_ACE4_ID_SPECIAL) ? ACE4_IFLAG_SPECIAL_ID : 0;
328
329 if (aceprop->flags&SMB_ACE4_ID_SPECIAL)
330 {
331 switch(aceprop->who.special_id)
332 {
333 case SMB_ACE4_WHO_EVERYONE:
334 gace->aceWho = ACE4_SPECIAL_EVERYONE;
335 break;
336 case SMB_ACE4_WHO_OWNER:
337 gace->aceWho = ACE4_SPECIAL_OWNER;
338 break;
339 case SMB_ACE4_WHO_GROUP:
340 gace->aceWho = ACE4_SPECIAL_GROUP;
341 break;
342 default:
343 DEBUG(8, ("unsupported special_id %d\n", aceprop->who.special_id));
344 continue; /* don't add it !!! */
345 }
346 } else {
347 /* just only for the type safety... */
348 if (aceprop->aceFlags&SMB_ACE4_IDENTIFIER_GROUP)
349 gace->aceWho = aceprop->who.gid;
350 else
351 gace->aceWho = aceprop->who.uid;
352 }
353
354 gacl->acl_nace++;
355 }
356
357 ret = smbd_gpfs_putacl(fsp->fsp_name, GPFS_PUTACL_STRUCT | GPFS_ACL_SAMBA, gacl);
358 if (ret != 0) {
359 DEBUG(8, ("gpfs_putacl failed with %s\n", strerror(errno)));
360 gpfs_dumpacl(8, gacl);
361 return False;
362 }
363
364 DEBUG(10, ("gpfs_putacl succeeded\n"));
365 return True;
366}
367
368static NTSTATUS gpfsacl_set_nt_acl_internal(files_struct *fsp, uint32 security_info_sent, SEC_DESC *psd)
369{
370 struct gpfs_acl *acl;
371 NTSTATUS result = NT_STATUS_ACCESS_DENIED;
372
373 acl = gpfs_getacl_alloc(fsp->fsp_name, 0);
374 if (acl == NULL)
375 return result;
376
377 if (acl->acl_version&GPFS_ACL_VERSION_NFS4)
378 {
379 result = smb_set_nt_acl_nfs4(
380 fsp, security_info_sent, psd,
381 gpfsacl_process_smbacl);
382 } else { /* assume POSIX ACL - by default... */
383 result = set_nt_acl(fsp, security_info_sent, psd);
384 }
385
386 return result;
387}
388
389static NTSTATUS gpfsacl_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp, uint32 security_info_sent, SEC_DESC *psd)
390{
391 return gpfsacl_set_nt_acl_internal(fsp, security_info_sent, psd);
392}
393
394static NTSTATUS gpfsacl_set_nt_acl(vfs_handle_struct *handle, files_struct *fsp, char *name, uint32 security_info_sent, SEC_DESC *psd)
395{
396 return gpfsacl_set_nt_acl_internal(fsp, security_info_sent, psd);
397}
398
399static SMB_ACL_T gpfs2smb_acl(const struct gpfs_acl *pacl)
400{
401 SMB_ACL_T result;
402 int i;
403
404 result = sys_acl_init(pacl->acl_nace);
405 if (result == NULL) {
406 errno = ENOMEM;
407 return NULL;
408 }
409
410 result->count = pacl->acl_nace;
411
412 for (i=0; i<pacl->acl_nace; i++) {
413 struct smb_acl_entry *ace = &result->acl[i];
414 const struct gpfs_ace_v1 *g_ace = &pacl->ace_v1[i];
415
416 DEBUG(10, ("Converting type %d id %lu perm %x\n",
417 (int)g_ace->ace_type, (unsigned long)g_ace->ace_who,
418 (int)g_ace->ace_perm));
419
420 switch (g_ace->ace_type) {
421 case GPFS_ACL_USER:
422 ace->a_type = SMB_ACL_USER;
423 ace->uid = (uid_t)g_ace->ace_who;
424 break;
425 case GPFS_ACL_USER_OBJ:
426 ace->a_type = SMB_ACL_USER_OBJ;
427 break;
428 case GPFS_ACL_GROUP:
429 ace->a_type = SMB_ACL_GROUP;
430 ace->gid = (gid_t)g_ace->ace_who;
431 break;
432 case GPFS_ACL_GROUP_OBJ:
433 ace->a_type = SMB_ACL_GROUP_OBJ;
434 break;
435 case GPFS_ACL_OTHER:
436 ace->a_type = SMB_ACL_OTHER;
437 break;
438 case GPFS_ACL_MASK:
439 ace->a_type = SMB_ACL_MASK;
440 break;
441 default:
442 DEBUG(10, ("Got invalid ace_type: %d\n",
443 g_ace->ace_type));
444 errno = EINVAL;
445 SAFE_FREE(result);
446 return NULL;
447 }
448
449 ace->a_perm = 0;
450 ace->a_perm |= (g_ace->ace_perm & ACL_PERM_READ) ?
451 SMB_ACL_READ : 0;
452 ace->a_perm |= (g_ace->ace_perm & ACL_PERM_WRITE) ?
453 SMB_ACL_WRITE : 0;
454 ace->a_perm |= (g_ace->ace_perm & ACL_PERM_EXECUTE) ?
455 SMB_ACL_EXECUTE : 0;
456
457 DEBUGADD(10, ("Converted to %d perm %x\n",
458 ace->a_type, ace->a_perm));
459 }
460
461 return result;
462}
463
464static SMB_ACL_T gpfsacl_get_posix_acl(const char *path, gpfs_aclType_t type)
465{
466 struct gpfs_acl *pacl;
467 SMB_ACL_T result = NULL;
468
469 pacl = gpfs_getacl_alloc(path, type);
470
471 if (pacl == NULL) {
472 DEBUG(10, ("gpfs_getacl failed for %s with %s\n",
473 path, strerror(errno)));
474 if (errno == 0) {
475 errno = EINVAL;
476 }
477 goto done;
478 }
479
480 if (pacl->acl_version != GPFS_ACL_VERSION_POSIX) {
481 DEBUG(10, ("Got acl version %d, expected %d\n",
482 pacl->acl_version, GPFS_ACL_VERSION_POSIX));
483 errno = EINVAL;
484 goto done;
485 }
486
487 DEBUG(10, ("len: %d, level: %d, version: %d, nace: %d\n",
488 pacl->acl_len, pacl->acl_level, pacl->acl_version,
489 pacl->acl_nace));
490
491 result = gpfs2smb_acl(pacl);
492 if (result == NULL) {
493 goto done;
494 }
495
496 done:
497
498 if (errno != 0) {
499 SAFE_FREE(result);
500 }
501 return result;
502}
503
504SMB_ACL_T gpfsacl_sys_acl_get_file(vfs_handle_struct *handle,
505
506 const char *path_p,
507 SMB_ACL_TYPE_T type)
508{
509 gpfs_aclType_t gpfs_type;
510
511 switch(type) {
512 case SMB_ACL_TYPE_ACCESS:
513 gpfs_type = GPFS_ACL_TYPE_ACCESS;
514 break;
515 case SMB_ACL_TYPE_DEFAULT:
516 gpfs_type = GPFS_ACL_TYPE_DEFAULT;
517 break;
518 default:
519 DEBUG(0, ("Got invalid type: %d\n", type));
520 smb_panic("exiting");
521 }
522
523 return gpfsacl_get_posix_acl(path_p, gpfs_type);
524}
525
526SMB_ACL_T gpfsacl_sys_acl_get_fd(vfs_handle_struct *handle,
527 files_struct *fsp)
528{
529 return gpfsacl_get_posix_acl(fsp->fsp_name, GPFS_ACL_TYPE_ACCESS);
530}
531
532static struct gpfs_acl *smb2gpfs_acl(const SMB_ACL_T pacl,
533 SMB_ACL_TYPE_T type)
534{
535 gpfs_aclLen_t len;
536 struct gpfs_acl *result;
537 int i;
538 union gpfs_ace_union
539 {
540 gpfs_ace_v1_t ace_v1[1]; /* when GPFS_ACL_VERSION_POSIX */
541 gpfs_ace_v4_t ace_v4[1]; /* when GPFS_ACL_VERSION_NFS4 */
542 };
543
544 DEBUG(10, ("smb2gpfs_acl: Got ACL with %d entries\n", pacl->count));
545
546 len = sizeof(struct gpfs_acl) - sizeof(union gpfs_ace_union) +
547 (pacl->count)*sizeof(gpfs_ace_v1_t);
548
549 result = SMB_MALLOC(len);
550 if (result == NULL) {
551 errno = ENOMEM;
552 return result;
553 }
554
555 result->acl_len = len;
556 result->acl_level = 0;
557 result->acl_version = GPFS_ACL_VERSION_POSIX;
558 result->acl_type = (type == SMB_ACL_TYPE_DEFAULT) ?
559 GPFS_ACL_TYPE_DEFAULT : GPFS_ACL_TYPE_ACCESS;
560 result->acl_nace = pacl->count;
561
562 for (i=0; i<pacl->count; i++) {
563 const struct smb_acl_entry *ace = &pacl->acl[i];
564 struct gpfs_ace_v1 *g_ace = &result->ace_v1[i];
565
566 DEBUG(10, ("Converting type %d perm %x\n",
567 (int)ace->a_type, (int)ace->a_perm));
568
569 g_ace->ace_perm = 0;
570
571 switch(ace->a_type) {
572 case SMB_ACL_USER:
573 g_ace->ace_type = GPFS_ACL_USER;
574 g_ace->ace_who = (gpfs_uid_t)ace->uid;
575 break;
576 case SMB_ACL_USER_OBJ:
577 g_ace->ace_type = GPFS_ACL_USER_OBJ;
578 g_ace->ace_perm |= ACL_PERM_CONTROL;
579 g_ace->ace_who = 0;
580 break;
581 case SMB_ACL_GROUP:
582 g_ace->ace_type = GPFS_ACL_GROUP;
583 g_ace->ace_who = (gpfs_uid_t)ace->gid;
584 break;
585 case SMB_ACL_GROUP_OBJ:
586 g_ace->ace_type = GPFS_ACL_GROUP_OBJ;
587 g_ace->ace_who = 0;
588 break;
589 case SMB_ACL_MASK:
590 g_ace->ace_type = GPFS_ACL_MASK;
591 g_ace->ace_perm = 0x8f;
592 g_ace->ace_who = 0;
593 break;
594 case SMB_ACL_OTHER:
595 g_ace->ace_type = GPFS_ACL_OTHER;
596 g_ace->ace_who = 0;
597 break;
598 default:
599 DEBUG(10, ("Got invalid ace_type: %d\n", ace->a_type));
600 errno = EINVAL;
601 SAFE_FREE(result);
602 return NULL;
603 }
604
605 g_ace->ace_perm |= (ace->a_perm & SMB_ACL_READ) ?
606 ACL_PERM_READ : 0;
607 g_ace->ace_perm |= (ace->a_perm & SMB_ACL_WRITE) ?
608 ACL_PERM_WRITE : 0;
609 g_ace->ace_perm |= (ace->a_perm & SMB_ACL_EXECUTE) ?
610 ACL_PERM_EXECUTE : 0;
611
612 DEBUGADD(10, ("Converted to %d id %d perm %x\n",
613 g_ace->ace_type, g_ace->ace_who, g_ace->ace_perm));
614 }
615
616 return result;
617}
618
619int gpfsacl_sys_acl_set_file(vfs_handle_struct *handle,
620
621 const char *name,
622 SMB_ACL_TYPE_T type,
623 SMB_ACL_T theacl)
624{
625 struct gpfs_acl *gpfs_acl;
626 int result;
627
628 gpfs_acl = smb2gpfs_acl(theacl, type);
629 if (gpfs_acl == NULL) {
630 return -1;
631 }
632
633 result = smbd_gpfs_putacl((char *)name, GPFS_PUTACL_STRUCT | GPFS_ACL_SAMBA, gpfs_acl);
634
635 SAFE_FREE(gpfs_acl);
636 return result;
637}
638
639int gpfsacl_sys_acl_set_fd(vfs_handle_struct *handle,
640 files_struct *fsp,
641 SMB_ACL_T theacl)
642{
643 return gpfsacl_sys_acl_set_file(handle, fsp->fsp_name, SMB_ACL_TYPE_ACCESS, theacl);
644}
645
646int gpfsacl_sys_acl_delete_def_file(vfs_handle_struct *handle,
647
648 const char *path)
649{
650 errno = ENOTSUP;
651 return -1;
652}
653
654/*
655 * Assumed: mode bits are shiftable and standard
656 * Output: the new aceMask field for an smb nfs4 ace
657 */
658static uint32 gpfsacl_mask_filter(uint32 aceType, uint32 aceMask, uint32 rwx)
659{
660 const uint32 posix_nfs4map[3] = {
661 SMB_ACE4_EXECUTE, /* execute */
662 SMB_ACE4_WRITE_DATA | SMB_ACE4_APPEND_DATA, /* write; GPFS specific */
663 SMB_ACE4_READ_DATA /* read */
664 };
665 int i;
666 uint32_t posix_mask = 0x01;
667 uint32_t posix_bit;
668 uint32_t nfs4_bits;
669
670 for(i=0; i<3; i++) {
671 nfs4_bits = posix_nfs4map[i];
672 posix_bit = rwx & posix_mask;
673
674 if (aceType==SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE) {
675 if (posix_bit)
676 aceMask |= nfs4_bits;
677 else
678 aceMask &= ~nfs4_bits;
679 } else {
680 /* add deny bits when suitable */
681 if (!posix_bit)
682 aceMask |= nfs4_bits;
683 else
684 aceMask &= ~nfs4_bits;
685 } /* other ace types are unexpected */
686
687 posix_mask <<= 1;
688 }
689
690 return aceMask;
691}
692
693static int gpfsacl_emu_chmod(const char *path, mode_t mode)
694{
695 SMB4ACL_T *pacl = NULL;
696 int result;
697 bool haveAllowEntry[SMB_ACE4_WHO_EVERYONE + 1] = {False, False, False, False};
698 int i;
699 files_struct fake_fsp; /* TODO: rationalize parametrization */
700 SMB4ACE_T *smbace;
701
702 DEBUG(10, ("gpfsacl_emu_chmod invoked for %s mode %o\n", path, mode));
703
704 result = gpfs_get_nfs4_acl(path, &pacl);
705 if (result)
706 return result;
707
708 if (mode & ~(S_IRWXU | S_IRWXG | S_IRWXO)) {
709 DEBUG(2, ("WARNING: cutting extra mode bits %o on %s\n", mode, path));
710 }
711
712 for (smbace=smb_first_ace4(pacl); smbace!=NULL; smbace = smb_next_ace4(smbace)) {
713 SMB_ACE4PROP_T *ace = smb_get_ace4(smbace);
714 uint32_t specid = ace->who.special_id;
715
716 if (ace->flags&SMB_ACE4_ID_SPECIAL &&
717 ace->aceType<=SMB_ACE4_ACCESS_DENIED_ACE_TYPE &&
718 specid <= SMB_ACE4_WHO_EVERYONE) {
719
720 uint32_t newMask;
721
722 if (ace->aceType==SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE)
723 haveAllowEntry[specid] = True;
724
725 /* mode >> 6 for @owner, mode >> 3 for @group,
726 * mode >> 0 for @everyone */
727 newMask = gpfsacl_mask_filter(ace->aceType, ace->aceMask,
728 mode >> ((SMB_ACE4_WHO_EVERYONE - specid) * 3));
729 if (ace->aceMask!=newMask) {
730 DEBUG(10, ("ace changed for %s (%o -> %o) id=%d\n",
731 path, ace->aceMask, newMask, specid));
732 }
733 ace->aceMask = newMask;
734 }
735 }
736
737 /* make sure we have at least ALLOW entries
738 * for all the 3 special ids (@EVERYONE, @OWNER, @GROUP)
739 * - if necessary
740 */
741 for(i = SMB_ACE4_WHO_OWNER; i<=SMB_ACE4_WHO_EVERYONE; i++) {
742 SMB_ACE4PROP_T ace;
743
744 if (haveAllowEntry[i]==True)
745 continue;
746
747 ZERO_STRUCT(ace);
748 ace.aceType = SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE;
749 ace.flags |= SMB_ACE4_ID_SPECIAL;
750 ace.who.special_id = i;
751
752 if (i==SMB_ACE4_WHO_GROUP) /* not sure it's necessary... */
753 ace.aceFlags |= SMB_ACE4_IDENTIFIER_GROUP;
754
755 ace.aceMask = gpfsacl_mask_filter(ace.aceType, ace.aceMask,
756 mode >> ((SMB_ACE4_WHO_EVERYONE - i) * 3));
757
758 /* don't add unnecessary aces */
759 if (!ace.aceMask)
760 continue;
761
762 /* we add it to the END - as windows expects allow aces */
763 smb_add_ace4(pacl, &ace);
764 DEBUG(10, ("Added ALLOW ace for %s, mode=%o, id=%d, aceMask=%x\n",
765 path, mode, i, ace.aceMask));
766 }
767
768 /* don't add complementary DENY ACEs here */
769 ZERO_STRUCT(fake_fsp);
770 fake_fsp.fsp_name = (char *)path; /* no file_new is needed here */
771
772 /* put the acl */
773 if (gpfsacl_process_smbacl(&fake_fsp, pacl) == False)
774 return -1;
775 return 0; /* ok for [f]chmod */
776}
777
778static int vfs_gpfs_chmod(vfs_handle_struct *handle, const char *path, mode_t mode)
779{
780 SMB_STRUCT_STAT st;
781 int rc;
782
783 if (SMB_VFS_NEXT_STAT(handle, path, &st) != 0) {
784 return -1;
785 }
786
787 /* avoid chmod() if possible, to preserve acls */
788 if ((st.st_mode & ~S_IFMT) == mode) {
789 return 0;
790 }
791
792 rc = gpfsacl_emu_chmod(path, mode);
793 if (rc == 1)
794 return SMB_VFS_NEXT_CHMOD(handle, path, mode);
795 return rc;
796}
797
798static int vfs_gpfs_fchmod(vfs_handle_struct *handle, files_struct *fsp, mode_t mode)
799{
800 SMB_STRUCT_STAT st;
801 int rc;
802
803 if (SMB_VFS_NEXT_FSTAT(handle, fsp, &st) != 0) {
804 return -1;
805 }
806
807 /* avoid chmod() if possible, to preserve acls */
808 if ((st.st_mode & ~S_IFMT) == mode) {
809 return 0;
810 }
811
812 rc = gpfsacl_emu_chmod(fsp->fsp_name, mode);
813 if (rc == 1)
814 return SMB_VFS_NEXT_FCHMOD(handle, fsp, mode);
815 return rc;
816}
817
818/* VFS operations structure */
819
820static vfs_op_tuple gpfs_op_tuples[] = {
821
822 { SMB_VFS_OP(vfs_gpfs_kernel_flock),
823 SMB_VFS_OP_KERNEL_FLOCK,
824 SMB_VFS_LAYER_OPAQUE },
825
826 { SMB_VFS_OP(vfs_gpfs_setlease),
827 SMB_VFS_OP_LINUX_SETLEASE,
828 SMB_VFS_LAYER_OPAQUE },
829
830 { SMB_VFS_OP(gpfsacl_fget_nt_acl),
831 SMB_VFS_OP_FGET_NT_ACL,
832 SMB_VFS_LAYER_TRANSPARENT },
833
834 { SMB_VFS_OP(gpfsacl_get_nt_acl),
835 SMB_VFS_OP_GET_NT_ACL,
836 SMB_VFS_LAYER_TRANSPARENT },
837
838 { SMB_VFS_OP(gpfsacl_fset_nt_acl),
839 SMB_VFS_OP_FSET_NT_ACL,
840 SMB_VFS_LAYER_TRANSPARENT },
841
842 { SMB_VFS_OP(gpfsacl_set_nt_acl),
843 SMB_VFS_OP_SET_NT_ACL,
844 SMB_VFS_LAYER_TRANSPARENT },
845
846 { SMB_VFS_OP(gpfsacl_sys_acl_get_file),
847 SMB_VFS_OP_SYS_ACL_GET_FILE,
848 SMB_VFS_LAYER_TRANSPARENT },
849
850 { SMB_VFS_OP(gpfsacl_sys_acl_get_fd),
851 SMB_VFS_OP_SYS_ACL_GET_FD,
852 SMB_VFS_LAYER_TRANSPARENT },
853
854 { SMB_VFS_OP(gpfsacl_sys_acl_set_file),
855 SMB_VFS_OP_SYS_ACL_SET_FILE,
856 SMB_VFS_LAYER_TRANSPARENT },
857
858 { SMB_VFS_OP(gpfsacl_sys_acl_set_fd),
859 SMB_VFS_OP_SYS_ACL_SET_FD,
860 SMB_VFS_LAYER_TRANSPARENT },
861
862 { SMB_VFS_OP(gpfsacl_sys_acl_delete_def_file),
863 SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE,
864 SMB_VFS_LAYER_TRANSPARENT },
865
866 { SMB_VFS_OP(vfs_gpfs_chmod),
867 SMB_VFS_OP_CHMOD,
868 SMB_VFS_LAYER_TRANSPARENT },
869
870 { SMB_VFS_OP(vfs_gpfs_fchmod),
871 SMB_VFS_OP_FCHMOD,
872 SMB_VFS_LAYER_TRANSPARENT },
873
874 { SMB_VFS_OP(NULL), SMB_VFS_OP_NOOP, SMB_VFS_LAYER_NOOP }
875
876};
877
878
879NTSTATUS vfs_gpfs_init(void);
880NTSTATUS vfs_gpfs_init(void)
881{
882 init_gpfs();
883
884 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "gpfs",
885 gpfs_op_tuples);
886}
Note: See TracBrowser for help on using the repository browser.