2 Unix SMB/CIFS implementation.
3 Wrap gpfs calls in vfs functions.
5 Copyright (C) Christian Ambach <cambach1@de.ibm.com> 2006
7 Major code contributions by Chetan Shringarpure <chetan.sh@in.ibm.com>
8 and Gomati Mohanan <gomati.mohanan@in.ibm.com>
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.
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.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
30 #define DBGC_CLASS DBGC_VFS
33 #include "nfs4_acls.h"
36 static int vfs_gpfs_kernel_flock(vfs_handle_struct *handle, files_struct *fsp,
37 int fd, uint32 share_mode)
40 START_PROFILE(syscall_kernel_flock);
42 kernel_flock(fsp->fh->fd, share_mode);
44 if (!set_gpfs_sharemode(fsp, fsp->access_mask, fsp->share_access)) {
50 END_PROFILE(syscall_kernel_flock);
55 static int vfs_gpfs_setlease(vfs_handle_struct *handle, files_struct *fsp,
56 int fd, int leasetype)
60 START_PROFILE(syscall_linux_setlease);
62 if ( linux_set_lease_sighandler(fd) == -1)
65 ret = set_gpfs_lease(fd,leasetype);
68 /* This must have come from GPFS not being available */
69 /* or some other error, hence call the default */
70 ret = linux_setlease(fd, leasetype);
73 END_PROFILE(syscall_linux_setlease);
80 static void gpfs_dumpacl(int level, struct gpfs_acl *gacl)
85 DEBUG(0, ("gpfs acl is NULL\n"));
89 DEBUG(level, ("gpfs acl: nace: %d, type:%d, version:%d, level:%d, len:%d\n",
90 gacl->acl_nace, gacl->acl_type, gacl->acl_version, gacl->acl_level, gacl->acl_len));
91 for(i=0; i<gacl->acl_nace; i++)
93 struct gpfs_ace_v4 *gace = gacl->ace_v4 + i;
94 DEBUG(level, ("\tace[%d]: type:%d, flags:0x%x, mask:0x%x, iflags:0x%x, who:%u\n",
95 i, gace->aceType, gace->aceFlags, gace->aceMask,
96 gace->aceIFlags, gace->aceWho));
100 static struct gpfs_acl *gpfs_getacl_alloc(const char *fname, gpfs_aclType_t type)
102 struct gpfs_acl *acl;
105 TALLOC_CTX *mem_ctx = main_loop_talloc_get();
107 acl = (struct gpfs_acl *)talloc_size(mem_ctx, len);
115 acl->acl_version = 0;
116 acl->acl_type = type;
118 ret = smbd_gpfs_getacl((char *)fname, GPFS_GETACL_STRUCT | GPFS_ACL_SAMBA, acl);
119 if ((ret != 0) && (errno == ENOSPC)) {
120 struct gpfs_acl *new_acl = (struct gpfs_acl *)talloc_size(
121 mem_ctx, acl->acl_len + sizeof(struct gpfs_acl));
122 if (new_acl == NULL) {
127 new_acl->acl_len = acl->acl_len;
128 new_acl->acl_level = acl->acl_level;
129 new_acl->acl_version = acl->acl_version;
130 new_acl->acl_type = acl->acl_type;
133 ret = smbd_gpfs_getacl((char *)fname, GPFS_GETACL_STRUCT | GPFS_ACL_SAMBA, acl);
137 DEBUG(8, ("smbd_gpfs_getacl failed with %s\n",strerror(errno)));
144 static BOOL gpfs_get_nfs4_acl(struct files_struct *fsp, SMB4ACL_T **ppacl, BOOL *pretryPosix)
148 struct gpfs_acl *gacl = NULL;
150 mem_ctx = main_loop_talloc_get();
152 DEBUG(10, ("gpfs_get_nfs4_acl invoked for %s\n", fsp->fsp_name));
154 /* First get the real acl length */
155 gacl = gpfs_getacl_alloc(fsp->fsp_name, GPFS_ACL_TYPE_NFS4);
157 DEBUG(9, ("gpfs_getacl failed for %s with %s\n",
158 fsp->fsp_name, strerror(errno)));
162 if (gacl->acl_type != GPFS_ACL_TYPE_NFS4) {
163 DEBUG(10, ("Got non-nfsv4 acl\n"));
168 *ppacl = smb_create_smb4acl();
170 DEBUG(10, ("len: %d, level: %d, version: %d, nace: %d\n",
171 gacl->acl_len, gacl->acl_level, gacl->acl_version,
174 for (i=0; i<gacl->acl_nace; i++) {
175 struct gpfs_ace_v4 *gace = &gacl->ace_v4[i];
176 SMB_ACE4PROP_T smbace;
177 memset(&smbace, 0, sizeof(SMB4ACE_T));
179 DEBUG(10, ("type: %d, iflags: %x, flags: %x, mask: %x, "
180 "who: %d\n", gace->aceType, gace->aceIFlags,
181 gace->aceFlags, gace->aceMask, gace->aceWho));
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;
189 case ACE4_SPECIAL_GROUP:
190 smbace.who.special_id = SMB_ACE4_WHO_GROUP;
192 case ACE4_SPECIAL_EVERYONE:
193 smbace.who.special_id = SMB_ACE4_WHO_EVERYONE;
196 DEBUG(8, ("invalid special gpfs id %d "
197 "ignored\n", gace->aceWho));
198 continue; /* don't add it */
201 if (gace->aceFlags & ACE4_FLAG_GROUP_ID)
202 smbace.who.gid = gace->aceWho;
204 smbace.who.uid = gace->aceWho;
207 smbace.aceType = gace->aceType;
208 smbace.aceFlags = gace->aceFlags;
209 smbace.aceMask = gace->aceMask;
210 smbace.flags = (gace->aceIFlags&ACE4_IFLAG_SPECIAL_ID) ? SMB_ACE4_ID_SPECIAL : 0;
212 smb_add_ace4(*ppacl, &smbace);
218 static size_t gpfsacl_get_nt_acl_common(files_struct *fsp,
219 uint32 security_info, SEC_DESC **ppdesc)
221 SMB4ACL_T *pacl = NULL;
223 BOOL retryPosix = False;
226 result = gpfs_get_nfs4_acl(fsp, &pacl, &retryPosix);
229 DEBUG(10, ("retrying with posix acl...\n"));
230 return get_nt_acl(fsp, security_info, ppdesc);
235 return smb_get_nt_acl_nfs4(fsp, security_info, ppdesc, pacl);
238 size_t gpfsacl_fget_nt_acl(vfs_handle_struct *handle,
239 files_struct *fsp, int fd, uint32 security_info,
242 return gpfsacl_get_nt_acl_common(fsp, security_info, ppdesc);
245 size_t gpfsacl_get_nt_acl(vfs_handle_struct *handle,
246 files_struct *fsp, const char *name,
247 uint32 security_info, SEC_DESC **ppdesc)
249 return gpfsacl_get_nt_acl_common(fsp, security_info, ppdesc);
252 static BOOL gpfsacl_process_smbacl(files_struct *fsp, SMB4ACL_T *smbacl)
255 gpfs_aclLen_t gacl_len;
257 struct gpfs_acl *gacl;
258 TALLOC_CTX *mem_ctx = main_loop_talloc_get();
260 gacl_len = sizeof(struct gpfs_acl) +
261 (smb_get_naces(smbacl)-1)*sizeof(gpfs_ace_v4_t);
263 gacl = talloc_size(mem_ctx, gacl_len);
265 DEBUG(0, ("talloc failed\n"));
270 gacl->acl_len = gacl_len;
272 gacl->acl_version = GPFS_ACL_VERSION_NFS4;
273 gacl->acl_type = GPFS_ACL_TYPE_NFS4;
274 gacl->acl_nace = 0; /* change later... */
276 for (smbace=smb_first_ace4(smbacl); smbace!=NULL; smbace = smb_next_ace4(smbace)) {
277 struct gpfs_ace_v4 *gace = &gacl->ace_v4[gacl->acl_nace];
278 SMB_ACE4PROP_T *aceprop = smb_get_ace4(smbace);
280 gace->aceType = aceprop->aceType;
281 gace->aceFlags = aceprop->aceFlags;
282 gace->aceMask = aceprop->aceMask;
283 gace->aceIFlags = (aceprop->flags&SMB_ACE4_ID_SPECIAL) ? ACE4_IFLAG_SPECIAL_ID : 0;
285 if (aceprop->flags&SMB_ACE4_ID_SPECIAL)
287 switch(aceprop->who.special_id)
289 case SMB_ACE4_WHO_EVERYONE:
290 gace->aceWho = ACE4_SPECIAL_EVERYONE;
292 case SMB_ACE4_WHO_OWNER:
293 gace->aceWho = ACE4_SPECIAL_OWNER;
295 case SMB_ACE4_WHO_GROUP:
296 gace->aceWho = ACE4_SPECIAL_GROUP;
299 DEBUG(8, ("unsupported special_id %d\n", aceprop->who.special_id));
300 continue; /* don't add it !!! */
303 /* just only for the type safety... */
304 if (aceprop->aceFlags&SMB_ACE4_IDENTIFIER_GROUP)
305 gace->aceWho = aceprop->who.gid;
307 gace->aceWho = aceprop->who.uid;
313 ret = smbd_gpfs_putacl(fsp->fsp_name, GPFS_PUTACL_STRUCT | GPFS_ACL_SAMBA, gacl);
315 DEBUG(8, ("gpfs_putacl failed with %s\n", strerror(errno)));
316 gpfs_dumpacl(8, gacl);
320 DEBUG(10, ("gpfs_putacl succeeded\n"));
324 static BOOL gpfsacl_set_nt_acl_internal(files_struct *fsp, uint32 security_info_sent, SEC_DESC *psd)
326 struct gpfs_acl *acl;
329 acl = gpfs_getacl_alloc(fsp->fsp_name, GPFS_ACL_TYPE_ACCESS);
333 if (acl->acl_version&GPFS_ACL_VERSION_NFS4)
335 result = smb_set_nt_acl_nfs4(
336 fsp, security_info_sent, psd,
337 gpfsacl_process_smbacl);
338 } else { /* assume POSIX ACL - by default... */
339 result = set_nt_acl(fsp, security_info_sent, psd);
345 static BOOL gpfsacl_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp, int fd, uint32 security_info_sent, SEC_DESC *psd)
347 return gpfsacl_set_nt_acl_internal(fsp, security_info_sent, psd);
350 static BOOL gpfsacl_set_nt_acl(vfs_handle_struct *handle, files_struct *fsp, char *name, uint32 security_info_sent, SEC_DESC *psd)
352 return gpfsacl_set_nt_acl_internal(fsp, security_info_sent, psd);
355 static SMB_ACL_T gpfs2smb_acl(const struct gpfs_acl *pacl)
360 result = sys_acl_init(pacl->acl_nace);
361 if (result == NULL) {
366 result->count = pacl->acl_nace;
368 for (i=0; i<pacl->acl_nace; i++) {
369 struct smb_acl_entry *ace = &result->acl[i];
370 const struct gpfs_ace_v1 *g_ace = &pacl->ace_v1[i];
372 DEBUG(10, ("Converting type %d id %lu perm %x\n",
373 (int)g_ace->ace_type, (unsigned long)g_ace->ace_who,
374 (int)g_ace->ace_perm));
376 switch (g_ace->ace_type) {
378 ace->a_type = SMB_ACL_USER;
379 ace->uid = (uid_t)g_ace->ace_who;
381 case GPFS_ACL_USER_OBJ:
382 ace->a_type = SMB_ACL_USER_OBJ;
385 ace->a_type = SMB_ACL_GROUP;
386 ace->gid = (gid_t)g_ace->ace_who;
388 case GPFS_ACL_GROUP_OBJ:
389 ace->a_type = SMB_ACL_GROUP_OBJ;
392 ace->a_type = SMB_ACL_OTHER;
395 ace->a_type = SMB_ACL_MASK;
398 DEBUG(10, ("Got invalid ace_type: %d\n",
406 ace->a_perm |= (g_ace->ace_perm & ACL_PERM_READ) ?
408 ace->a_perm |= (g_ace->ace_perm & ACL_PERM_WRITE) ?
410 ace->a_perm |= (g_ace->ace_perm & ACL_PERM_EXECUTE) ?
413 DEBUGADD(10, ("Converted to %d perm %x\n",
414 ace->a_type, ace->a_perm));
420 static SMB_ACL_T gpfsacl_get_posix_acl(const char *path, gpfs_aclType_t type)
422 struct gpfs_acl *pacl;
423 SMB_ACL_T result = NULL;
425 pacl = gpfs_getacl_alloc(path, type);
428 DEBUG(10, ("gpfs_getacl failed for %s with %s\n",
429 path, strerror(errno)));
436 if (pacl->acl_version != GPFS_ACL_VERSION_POSIX) {
437 DEBUG(10, ("Got acl version %d, expected %d\n",
438 pacl->acl_version, GPFS_ACL_VERSION_POSIX));
443 DEBUG(10, ("len: %d, level: %d, version: %d, nace: %d\n",
444 pacl->acl_len, pacl->acl_level, pacl->acl_version,
447 result = gpfs2smb_acl(pacl);
448 if (result == NULL) {
460 SMB_ACL_T gpfsacl_sys_acl_get_file(vfs_handle_struct *handle,
465 gpfs_aclType_t gpfs_type;
468 case SMB_ACL_TYPE_ACCESS:
469 gpfs_type = GPFS_ACL_TYPE_ACCESS;
471 case SMB_ACL_TYPE_DEFAULT:
472 gpfs_type = GPFS_ACL_TYPE_DEFAULT;
475 DEBUG(0, ("Got invalid type: %d\n", type));
476 smb_panic("exiting");
479 return gpfsacl_get_posix_acl(path_p, gpfs_type);
482 SMB_ACL_T gpfsacl_sys_acl_get_fd(vfs_handle_struct *handle,
486 return gpfsacl_get_posix_acl(fsp->fsp_name, GPFS_ACL_TYPE_ACCESS);
489 static struct gpfs_acl *smb2gpfs_acl(const SMB_ACL_T pacl,
493 struct gpfs_acl *result;
497 gpfs_ace_v1_t ace_v1[1]; /* when GPFS_ACL_VERSION_POSIX */
498 gpfs_ace_v4_t ace_v4[1]; /* when GPFS_ACL_VERSION_NFS4 */
501 DEBUG(10, ("smb2gpfs_acl: Got ACL with %d entries\n", pacl->count));
503 len = sizeof(struct gpfs_acl) - sizeof(union gpfs_ace_union) +
504 (pacl->count)*sizeof(gpfs_ace_v1_t);
506 result = SMB_MALLOC(len);
507 if (result == NULL) {
512 result->acl_len = len;
513 result->acl_level = 0;
514 result->acl_version = GPFS_ACL_VERSION_POSIX;
515 result->acl_type = (type == SMB_ACL_TYPE_DEFAULT) ?
516 GPFS_ACL_TYPE_DEFAULT : GPFS_ACL_TYPE_ACCESS;
517 result->acl_nace = pacl->count;
519 for (i=0; i<pacl->count; i++) {
520 const struct smb_acl_entry *ace = &pacl->acl[i];
521 struct gpfs_ace_v1 *g_ace = &result->ace_v1[i];
523 DEBUG(10, ("Converting type %d perm %x\n",
524 (int)ace->a_type, (int)ace->a_perm));
528 switch(ace->a_type) {
530 g_ace->ace_type = GPFS_ACL_USER;
531 g_ace->ace_who = (gpfs_uid_t)ace->uid;
533 case SMB_ACL_USER_OBJ:
534 g_ace->ace_type = GPFS_ACL_USER_OBJ;
535 g_ace->ace_perm |= ACL_PERM_CONTROL;
539 g_ace->ace_type = GPFS_ACL_GROUP;
540 g_ace->ace_who = (gpfs_uid_t)ace->gid;
542 case SMB_ACL_GROUP_OBJ:
543 g_ace->ace_type = GPFS_ACL_GROUP_OBJ;
547 g_ace->ace_type = GPFS_ACL_MASK;
548 g_ace->ace_perm = 0x8f;
552 g_ace->ace_type = GPFS_ACL_OTHER;
556 DEBUG(10, ("Got invalid ace_type: %d\n", ace->a_type));
562 g_ace->ace_perm |= (ace->a_perm & SMB_ACL_READ) ?
564 g_ace->ace_perm |= (ace->a_perm & SMB_ACL_WRITE) ?
566 g_ace->ace_perm |= (ace->a_perm & SMB_ACL_EXECUTE) ?
567 ACL_PERM_EXECUTE : 0;
569 DEBUGADD(10, ("Converted to %d id %d perm %x\n",
570 g_ace->ace_type, g_ace->ace_who, g_ace->ace_perm));
576 int gpfsacl_sys_acl_set_file(vfs_handle_struct *handle,
582 struct gpfs_acl *gpfs_acl;
585 gpfs_acl = smb2gpfs_acl(theacl, type);
586 if (gpfs_acl == NULL) {
590 result = smbd_gpfs_putacl((char *)name, GPFS_PUTACL_STRUCT | GPFS_ACL_SAMBA, gpfs_acl);
596 int gpfsacl_sys_acl_set_fd(vfs_handle_struct *handle,
598 int fd, SMB_ACL_T theacl)
600 return gpfsacl_sys_acl_set_file(handle, fsp->fsp_name, SMB_ACL_TYPE_ACCESS, theacl);
603 int gpfsacl_sys_acl_delete_def_file(vfs_handle_struct *handle,
611 /* VFS operations structure */
613 static vfs_op_tuple gpfs_op_tuples[] = {
615 {SMB_VFS_OP(vfs_gpfs_kernel_flock),
616 SMB_VFS_OP_KERNEL_FLOCK,
617 SMB_VFS_LAYER_OPAQUE},
619 {SMB_VFS_OP(vfs_gpfs_setlease),
620 SMB_VFS_OP_LINUX_SETLEASE,
621 SMB_VFS_LAYER_OPAQUE},
623 {SMB_VFS_OP(gpfsacl_fget_nt_acl),
624 SMB_VFS_OP_FGET_NT_ACL,
625 SMB_VFS_LAYER_TRANSPARENT},
627 {SMB_VFS_OP(gpfsacl_get_nt_acl),
628 SMB_VFS_OP_GET_NT_ACL,
629 SMB_VFS_LAYER_TRANSPARENT},
631 {SMB_VFS_OP(gpfsacl_fset_nt_acl),
632 SMB_VFS_OP_FSET_NT_ACL,
633 SMB_VFS_LAYER_TRANSPARENT},
635 {SMB_VFS_OP(gpfsacl_set_nt_acl),
636 SMB_VFS_OP_SET_NT_ACL,
637 SMB_VFS_LAYER_TRANSPARENT},
639 {SMB_VFS_OP(gpfsacl_sys_acl_get_file),
640 SMB_VFS_OP_SYS_ACL_GET_FILE,
641 SMB_VFS_LAYER_TRANSPARENT},
643 {SMB_VFS_OP(gpfsacl_sys_acl_get_fd),
644 SMB_VFS_OP_SYS_ACL_GET_FD,
645 SMB_VFS_LAYER_TRANSPARENT},
647 {SMB_VFS_OP(gpfsacl_sys_acl_set_file),
648 SMB_VFS_OP_SYS_ACL_SET_FILE,
649 SMB_VFS_LAYER_TRANSPARENT},
651 {SMB_VFS_OP(gpfsacl_sys_acl_set_fd),
652 SMB_VFS_OP_SYS_ACL_SET_FD,
653 SMB_VFS_LAYER_TRANSPARENT},
655 {SMB_VFS_OP(gpfsacl_sys_acl_delete_def_file),
656 SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE,
657 SMB_VFS_LAYER_TRANSPARENT},
666 NTSTATUS vfs_gpfs_init(void);
667 NTSTATUS vfs_gpfs_init(void)
671 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "gpfs",