dsdb: Put password lockout support in samdb_result_passwords()
[Samba.git] / source3 / modules / vfs_gpfs.c
blob73ab4a463d9655dab4812148c0b8d48797a2f15d
1 /*
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 3 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, see <http://www.gnu.org/licenses/>.
24 #include "includes.h"
25 #include "smbd/smbd.h"
26 #include "librpc/gen_ndr/ndr_xattr.h"
27 #include "include/smbprofile.h"
28 #include "modules/non_posix_acls.h"
30 #undef DBGC_CLASS
31 #define DBGC_CLASS DBGC_VFS
33 #include <gpfs_gpl.h>
34 #include "nfs4_acls.h"
35 #include "vfs_gpfs.h"
36 #include "system/filesys.h"
37 #include "auth.h"
38 #include "lib/util/tevent_unix.h"
40 struct gpfs_config_data {
41 bool sharemodes;
42 bool leases;
43 bool hsm;
44 bool syncio;
45 bool winattr;
46 bool ftruncate;
47 bool getrealfilename;
48 bool dfreequota;
49 bool prealloc;
50 bool acl;
51 bool settimes;
52 bool recalls;
56 static int vfs_gpfs_kernel_flock(vfs_handle_struct *handle, files_struct *fsp,
57 uint32 share_mode, uint32 access_mask)
60 struct gpfs_config_data *config;
61 int ret = 0;
63 SMB_VFS_HANDLE_GET_DATA(handle, config,
64 struct gpfs_config_data,
65 return -1);
67 if(!config->sharemodes) {
68 return 0;
71 START_PROFILE(syscall_kernel_flock);
73 kernel_flock(fsp->fh->fd, share_mode, access_mask);
75 if (!set_gpfs_sharemode(fsp, access_mask, fsp->share_access)) {
76 ret = -1;
79 END_PROFILE(syscall_kernel_flock);
81 return ret;
84 static int vfs_gpfs_close(vfs_handle_struct *handle, files_struct *fsp)
87 struct gpfs_config_data *config;
89 SMB_VFS_HANDLE_GET_DATA(handle, config,
90 struct gpfs_config_data,
91 return -1);
93 if (config->sharemodes && (fsp->fh != NULL) && (fsp->fh->fd != -1)) {
94 set_gpfs_sharemode(fsp, 0, 0);
97 return SMB_VFS_NEXT_CLOSE(handle, fsp);
100 static int vfs_gpfs_setlease(vfs_handle_struct *handle, files_struct *fsp,
101 int leasetype)
103 struct gpfs_config_data *config;
104 int ret=0;
106 SMB_VFS_HANDLE_GET_DATA(handle, config,
107 struct gpfs_config_data,
108 return -1);
110 if (linux_set_lease_sighandler(fsp->fh->fd) == -1)
111 return -1;
113 START_PROFILE(syscall_linux_setlease);
115 if (config->leases) {
117 * Ensure the lease owner is root to allow
118 * correct delivery of lease-break signals.
120 become_root();
121 ret = set_gpfs_lease(fsp->fh->fd,leasetype);
122 unbecome_root();
125 END_PROFILE(syscall_linux_setlease);
127 return ret;
130 static int vfs_gpfs_get_real_filename(struct vfs_handle_struct *handle,
131 const char *path,
132 const char *name,
133 TALLOC_CTX *mem_ctx,
134 char **found_name)
136 int result;
137 char *full_path;
138 char real_pathname[PATH_MAX+1];
139 int buflen;
140 bool mangled;
141 struct gpfs_config_data *config;
143 SMB_VFS_HANDLE_GET_DATA(handle, config,
144 struct gpfs_config_data,
145 return -1);
147 if (!config->getrealfilename) {
148 return SMB_VFS_NEXT_GET_REAL_FILENAME(handle, path, name,
149 mem_ctx, found_name);
152 mangled = mangle_is_mangled(name, handle->conn->params);
153 if (mangled) {
154 return SMB_VFS_NEXT_GET_REAL_FILENAME(handle, path, name,
155 mem_ctx, found_name);
158 full_path = talloc_asprintf(talloc_tos(), "%s/%s", path, name);
159 if (full_path == NULL) {
160 errno = ENOMEM;
161 return -1;
164 buflen = sizeof(real_pathname) - 1;
166 result = smbd_gpfs_get_realfilename_path(full_path, real_pathname,
167 &buflen);
169 TALLOC_FREE(full_path);
171 if ((result == -1) && (errno == ENOSYS)) {
172 return SMB_VFS_NEXT_GET_REAL_FILENAME(
173 handle, path, name, mem_ctx, found_name);
176 if (result == -1) {
177 DEBUG(10, ("smbd_gpfs_get_realfilename_path returned %s\n",
178 strerror(errno)));
179 return -1;
183 * GPFS does not necessarily null-terminate the returned path
184 * but instead returns the buffer length in buflen.
187 if (buflen < sizeof(real_pathname)) {
188 real_pathname[buflen] = '\0';
189 } else {
190 real_pathname[sizeof(real_pathname)-1] = '\0';
193 DEBUG(10, ("smbd_gpfs_get_realfilename_path: %s/%s -> %s\n",
194 path, name, real_pathname));
196 name = strrchr_m(real_pathname, '/');
197 if (name == NULL) {
198 errno = ENOENT;
199 return -1;
202 *found_name = talloc_strdup(mem_ctx, name+1);
203 if (*found_name == NULL) {
204 errno = ENOMEM;
205 return -1;
208 return 0;
211 static void gpfs_dumpacl(int level, struct gpfs_acl *gacl)
213 gpfs_aclCount_t i;
214 if (gacl==NULL)
216 DEBUG(0, ("gpfs acl is NULL\n"));
217 return;
220 DEBUG(level, ("gpfs acl: nace: %d, type:%d, version:%d, level:%d, len:%d\n",
221 gacl->acl_nace, gacl->acl_type, gacl->acl_version, gacl->acl_level, gacl->acl_len));
222 for(i=0; i<gacl->acl_nace; i++)
224 struct gpfs_ace_v4 *gace = gacl->ace_v4 + i;
225 DEBUG(level, ("\tace[%d]: type:%d, flags:0x%x, mask:0x%x, iflags:0x%x, who:%u\n",
226 i, gace->aceType, gace->aceFlags, gace->aceMask,
227 gace->aceIFlags, gace->aceWho));
232 * get the ACL from GPFS, allocated on the specified mem_ctx
233 * internally retries when initial buffer was too small
235 * caller needs to cast result to either
236 * raw = yes: struct gpfs_opaque_acl
237 * raw = no: struct gpfs_acl
240 static void *vfs_gpfs_getacl(TALLOC_CTX *mem_ctx,
241 const char *fname,
242 const bool raw,
243 const gpfs_aclType_t type)
246 void *aclbuf;
247 size_t size = 512;
248 int ret, flags;
249 unsigned int *len;
250 size_t struct_size;
252 again:
254 aclbuf = talloc_zero_size(mem_ctx, size);
255 if (aclbuf == NULL) {
256 errno = ENOMEM;
257 return NULL;
260 if (raw) {
261 struct gpfs_opaque_acl *buf = (struct gpfs_opaque_acl *) aclbuf;
262 buf->acl_type = type;
263 flags = GPFS_GETACL_NATIVE;
264 len = (unsigned int *) &(buf->acl_buffer_len);
265 struct_size = sizeof(struct gpfs_opaque_acl);
266 } else {
267 struct gpfs_acl *buf = (struct gpfs_acl *) aclbuf;
268 buf->acl_type = type;
269 flags = GPFS_GETACL_STRUCT;
270 len = &(buf->acl_len);
271 struct_size = sizeof(struct gpfs_acl);
274 /* set the length of the buffer as input value */
275 *len = size;
277 errno = 0;
278 ret = smbd_gpfs_getacl((char *)fname, flags, aclbuf);
279 if ((ret != 0) && (errno == ENOSPC)) {
281 * get the size needed to accommodate the complete buffer
283 * the value returned only applies to the ACL blob in the
284 * struct so make sure to also have headroom for the first
285 * struct members by adding room for the complete struct
286 * (might be a few bytes too much then)
288 size = *len + struct_size;
289 talloc_free(aclbuf);
290 DEBUG(10, ("Increasing ACL buffer size to %zu\n", size));
291 goto again;
294 if (ret != 0) {
295 DEBUG(5, ("smbd_gpfs_getacl failed with %s\n",
296 strerror(errno)));
297 talloc_free(aclbuf);
298 return NULL;
301 return aclbuf;
304 /* Tries to get nfs4 acls and returns SMB ACL allocated.
305 * On failure returns 1 if it got non-NFSv4 ACL to prompt
306 * retry with POSIX ACL checks.
307 * On failure returns -1 if there is system (GPFS) error, check errno.
308 * Returns 0 on success
310 static int gpfs_get_nfs4_acl(TALLOC_CTX *mem_ctx, const char *fname, SMB4ACL_T **ppacl)
312 gpfs_aclCount_t i;
313 struct gpfs_acl *gacl = NULL;
314 DEBUG(10, ("gpfs_get_nfs4_acl invoked for %s\n", fname));
316 /* Get the ACL */
317 gacl = (struct gpfs_acl*) vfs_gpfs_getacl(talloc_tos(), fname,
318 false, 0);
319 if (gacl == NULL) {
320 DEBUG(9, ("gpfs_getacl failed for %s with %s\n",
321 fname, strerror(errno)));
322 return -1;
325 if (gacl->acl_type != GPFS_ACL_TYPE_NFS4) {
326 DEBUG(10, ("Got non-nfsv4 acl\n"));
327 /* Retry with POSIX ACLs check */
328 talloc_free(gacl);
329 return 1;
332 *ppacl = smb_create_smb4acl(mem_ctx);
334 DEBUG(10, ("len: %d, level: %d, version: %d, nace: %d\n",
335 gacl->acl_len, gacl->acl_level, gacl->acl_version,
336 gacl->acl_nace));
338 for (i=0; i<gacl->acl_nace; i++) {
339 struct gpfs_ace_v4 *gace = &gacl->ace_v4[i];
340 SMB_ACE4PROP_T smbace;
341 DEBUG(10, ("type: %d, iflags: %x, flags: %x, mask: %x, "
342 "who: %d\n", gace->aceType, gace->aceIFlags,
343 gace->aceFlags, gace->aceMask, gace->aceWho));
345 ZERO_STRUCT(smbace);
346 if (gace->aceIFlags & ACE4_IFLAG_SPECIAL_ID) {
347 smbace.flags |= SMB_ACE4_ID_SPECIAL;
348 switch (gace->aceWho) {
349 case ACE4_SPECIAL_OWNER:
350 smbace.who.special_id = SMB_ACE4_WHO_OWNER;
351 break;
352 case ACE4_SPECIAL_GROUP:
353 smbace.who.special_id = SMB_ACE4_WHO_GROUP;
354 break;
355 case ACE4_SPECIAL_EVERYONE:
356 smbace.who.special_id = SMB_ACE4_WHO_EVERYONE;
357 break;
358 default:
359 DEBUG(8, ("invalid special gpfs id %d "
360 "ignored\n", gace->aceWho));
361 continue; /* don't add it */
363 } else {
364 if (gace->aceFlags & ACE4_FLAG_GROUP_ID)
365 smbace.who.gid = gace->aceWho;
366 else
367 smbace.who.uid = gace->aceWho;
370 /* remove redundant deny entries */
371 if (i > 0 && gace->aceType == SMB_ACE4_ACCESS_DENIED_ACE_TYPE) {
372 struct gpfs_ace_v4 *prev = &gacl->ace_v4[i-1];
373 if (prev->aceType == SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE &&
374 prev->aceFlags == gace->aceFlags &&
375 prev->aceIFlags == gace->aceIFlags &&
376 (gace->aceMask & prev->aceMask) == 0 &&
377 gace->aceWho == prev->aceWho) {
378 /* it's redundant - skip it */
379 continue;
383 smbace.aceType = gace->aceType;
384 smbace.aceFlags = gace->aceFlags;
385 smbace.aceMask = gace->aceMask;
386 smb_add_ace4(*ppacl, &smbace);
389 talloc_free(gacl);
391 return 0;
394 static NTSTATUS gpfsacl_fget_nt_acl(vfs_handle_struct *handle,
395 files_struct *fsp, uint32 security_info,
396 TALLOC_CTX *mem_ctx,
397 struct security_descriptor **ppdesc)
399 SMB4ACL_T *pacl = NULL;
400 int result;
401 struct gpfs_config_data *config;
402 TALLOC_CTX *frame = talloc_stackframe();
403 NTSTATUS status;
405 *ppdesc = NULL;
407 SMB_VFS_HANDLE_GET_DATA(handle, config,
408 struct gpfs_config_data,
409 return NT_STATUS_INTERNAL_ERROR);
411 if (!config->acl) {
412 status = SMB_VFS_NEXT_FGET_NT_ACL(handle, fsp, security_info,
413 mem_ctx, ppdesc);
414 TALLOC_FREE(frame);
415 return status;
418 result = gpfs_get_nfs4_acl(frame, fsp->fsp_name->base_name, &pacl);
420 if (result == 0) {
421 status = smb_fget_nt_acl_nfs4(fsp, security_info, mem_ctx,
422 ppdesc, pacl);
423 TALLOC_FREE(frame);
424 return status;
427 if (result > 0) {
428 DEBUG(10, ("retrying with posix acl...\n"));
429 status = posix_fget_nt_acl(fsp, security_info,
430 mem_ctx, ppdesc);
431 TALLOC_FREE(frame);
432 return status;
435 TALLOC_FREE(frame);
437 /* GPFS ACL was not read, something wrong happened, error code is set in errno */
438 return map_nt_error_from_unix(errno);
441 static NTSTATUS gpfsacl_get_nt_acl(vfs_handle_struct *handle,
442 const char *name,
443 uint32 security_info,
444 TALLOC_CTX *mem_ctx, struct security_descriptor **ppdesc)
446 SMB4ACL_T *pacl = NULL;
447 int result;
448 struct gpfs_config_data *config;
449 TALLOC_CTX *frame = talloc_stackframe();
450 NTSTATUS status;
452 *ppdesc = NULL;
454 SMB_VFS_HANDLE_GET_DATA(handle, config,
455 struct gpfs_config_data,
456 return NT_STATUS_INTERNAL_ERROR);
458 if (!config->acl) {
459 status = SMB_VFS_NEXT_GET_NT_ACL(handle, name, security_info,
460 mem_ctx, ppdesc);
461 TALLOC_FREE(frame);
462 return status;
465 result = gpfs_get_nfs4_acl(frame, name, &pacl);
467 if (result == 0) {
468 status = smb_get_nt_acl_nfs4(handle->conn, name, security_info,
469 mem_ctx, ppdesc, pacl);
470 TALLOC_FREE(frame);
471 return status;
474 if (result > 0) {
475 DEBUG(10, ("retrying with posix acl...\n"));
476 status = posix_get_nt_acl(handle->conn, name, security_info,
477 mem_ctx, ppdesc);
478 TALLOC_FREE(frame);
479 return status;
482 /* GPFS ACL was not read, something wrong happened, error code is set in errno */
483 TALLOC_FREE(frame);
484 return map_nt_error_from_unix(errno);
487 static bool gpfsacl_process_smbacl(vfs_handle_struct *handle, files_struct *fsp, SMB4ACL_T *smbacl)
489 int ret;
490 gpfs_aclLen_t gacl_len;
491 SMB4ACE_T *smbace;
492 struct gpfs_acl *gacl;
493 TALLOC_CTX *mem_ctx = talloc_tos();
495 gacl_len = offsetof(gpfs_acl_t, ace_v4) + smb_get_naces(smbacl) *
496 sizeof(gpfs_ace_v4_t);
498 gacl = (struct gpfs_acl *)TALLOC_SIZE(mem_ctx, gacl_len);
499 if (gacl == NULL) {
500 DEBUG(0, ("talloc failed\n"));
501 errno = ENOMEM;
502 return False;
505 gacl->acl_len = gacl_len;
506 gacl->acl_level = 0;
507 gacl->acl_version = GPFS_ACL_VERSION_NFS4;
508 gacl->acl_type = GPFS_ACL_TYPE_NFS4;
509 gacl->acl_nace = 0; /* change later... */
511 for (smbace=smb_first_ace4(smbacl); smbace!=NULL; smbace = smb_next_ace4(smbace)) {
512 struct gpfs_ace_v4 *gace = &gacl->ace_v4[gacl->acl_nace];
513 SMB_ACE4PROP_T *aceprop = smb_get_ace4(smbace);
515 gace->aceType = aceprop->aceType;
516 gace->aceFlags = aceprop->aceFlags;
517 gace->aceMask = aceprop->aceMask;
520 * GPFS can't distinguish between WRITE and APPEND on
521 * files, so one being set without the other is an
522 * error. Sorry for the many ()'s :-)
525 if (!fsp->is_directory
527 ((((gace->aceMask & ACE4_MASK_WRITE) == 0)
528 && ((gace->aceMask & ACE4_MASK_APPEND) != 0))
530 (((gace->aceMask & ACE4_MASK_WRITE) != 0)
531 && ((gace->aceMask & ACE4_MASK_APPEND) == 0)))
533 lp_parm_bool(fsp->conn->params->service, "gpfs",
534 "merge_writeappend", True)) {
535 DEBUG(2, ("vfs_gpfs.c: file [%s]: ACE contains "
536 "WRITE^APPEND, setting WRITE|APPEND\n",
537 fsp_str_dbg(fsp)));
538 gace->aceMask |= ACE4_MASK_WRITE|ACE4_MASK_APPEND;
541 gace->aceIFlags = (aceprop->flags&SMB_ACE4_ID_SPECIAL) ? ACE4_IFLAG_SPECIAL_ID : 0;
543 if (aceprop->flags&SMB_ACE4_ID_SPECIAL)
545 switch(aceprop->who.special_id)
547 case SMB_ACE4_WHO_EVERYONE:
548 gace->aceWho = ACE4_SPECIAL_EVERYONE;
549 break;
550 case SMB_ACE4_WHO_OWNER:
551 gace->aceWho = ACE4_SPECIAL_OWNER;
552 break;
553 case SMB_ACE4_WHO_GROUP:
554 gace->aceWho = ACE4_SPECIAL_GROUP;
555 break;
556 default:
557 DEBUG(8, ("unsupported special_id %d\n", aceprop->who.special_id));
558 continue; /* don't add it !!! */
560 } else {
561 /* just only for the type safety... */
562 if (aceprop->aceFlags&SMB_ACE4_IDENTIFIER_GROUP)
563 gace->aceWho = aceprop->who.gid;
564 else
565 gace->aceWho = aceprop->who.uid;
568 gacl->acl_nace++;
571 ret = smbd_gpfs_putacl(fsp->fsp_name->base_name,
572 GPFS_PUTACL_STRUCT | GPFS_ACL_SAMBA, gacl);
573 if (ret != 0) {
574 DEBUG(8, ("gpfs_putacl failed with %s\n", strerror(errno)));
575 gpfs_dumpacl(8, gacl);
576 return False;
579 DEBUG(10, ("gpfs_putacl succeeded\n"));
580 return True;
583 static NTSTATUS gpfsacl_set_nt_acl_internal(vfs_handle_struct *handle, files_struct *fsp, uint32 security_info_sent, const struct security_descriptor *psd)
585 struct gpfs_acl *acl;
586 NTSTATUS result = NT_STATUS_ACCESS_DENIED;
588 acl = (struct gpfs_acl*) vfs_gpfs_getacl(talloc_tos(),
589 fsp->fsp_name->base_name,
590 false, 0);
591 if (acl == NULL) {
592 return map_nt_error_from_unix(errno);
595 if (acl->acl_version == GPFS_ACL_VERSION_NFS4) {
596 if (lp_parm_bool(fsp->conn->params->service, "gpfs",
597 "refuse_dacl_protected", false)
598 && (psd->type&SEC_DESC_DACL_PROTECTED)) {
599 DEBUG(2, ("Rejecting unsupported ACL with DACL_PROTECTED bit set\n"));
600 talloc_free(acl);
601 return NT_STATUS_NOT_SUPPORTED;
604 result = smb_set_nt_acl_nfs4(handle,
605 fsp, security_info_sent, psd,
606 gpfsacl_process_smbacl);
607 } else { /* assume POSIX ACL - by default... */
608 result = set_nt_acl(fsp, security_info_sent, psd);
611 talloc_free(acl);
612 return result;
615 static NTSTATUS gpfsacl_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp, uint32 security_info_sent, const struct security_descriptor *psd)
617 struct gpfs_config_data *config;
619 SMB_VFS_HANDLE_GET_DATA(handle, config,
620 struct gpfs_config_data,
621 return NT_STATUS_INTERNAL_ERROR);
623 if (!config->acl) {
624 return SMB_VFS_NEXT_FSET_NT_ACL(handle, fsp, security_info_sent, psd);
627 return gpfsacl_set_nt_acl_internal(handle, fsp, security_info_sent, psd);
630 static SMB_ACL_T gpfs2smb_acl(const struct gpfs_acl *pacl, TALLOC_CTX *mem_ctx)
632 SMB_ACL_T result;
633 gpfs_aclCount_t i;
635 result = sys_acl_init(mem_ctx);
636 if (result == NULL) {
637 errno = ENOMEM;
638 return NULL;
641 result->count = pacl->acl_nace;
642 result->acl = talloc_realloc(result, result->acl, struct smb_acl_entry,
643 result->count);
644 if (result->acl == NULL) {
645 TALLOC_FREE(result);
646 errno = ENOMEM;
647 return NULL;
650 for (i=0; i<pacl->acl_nace; i++) {
651 struct smb_acl_entry *ace = &result->acl[i];
652 const struct gpfs_ace_v1 *g_ace = &pacl->ace_v1[i];
654 DEBUG(10, ("Converting type %d id %lu perm %x\n",
655 (int)g_ace->ace_type, (unsigned long)g_ace->ace_who,
656 (int)g_ace->ace_perm));
658 switch (g_ace->ace_type) {
659 case GPFS_ACL_USER:
660 ace->a_type = SMB_ACL_USER;
661 ace->info.user.uid = (uid_t)g_ace->ace_who;
662 break;
663 case GPFS_ACL_USER_OBJ:
664 ace->a_type = SMB_ACL_USER_OBJ;
665 break;
666 case GPFS_ACL_GROUP:
667 ace->a_type = SMB_ACL_GROUP;
668 ace->info.group.gid = (gid_t)g_ace->ace_who;
669 break;
670 case GPFS_ACL_GROUP_OBJ:
671 ace->a_type = SMB_ACL_GROUP_OBJ;
672 break;
673 case GPFS_ACL_OTHER:
674 ace->a_type = SMB_ACL_OTHER;
675 break;
676 case GPFS_ACL_MASK:
677 ace->a_type = SMB_ACL_MASK;
678 break;
679 default:
680 DEBUG(10, ("Got invalid ace_type: %d\n",
681 g_ace->ace_type));
682 TALLOC_FREE(result);
683 errno = EINVAL;
684 return NULL;
687 ace->a_perm = 0;
688 ace->a_perm |= (g_ace->ace_perm & ACL_PERM_READ) ?
689 SMB_ACL_READ : 0;
690 ace->a_perm |= (g_ace->ace_perm & ACL_PERM_WRITE) ?
691 SMB_ACL_WRITE : 0;
692 ace->a_perm |= (g_ace->ace_perm & ACL_PERM_EXECUTE) ?
693 SMB_ACL_EXECUTE : 0;
695 DEBUGADD(10, ("Converted to %d perm %x\n",
696 ace->a_type, ace->a_perm));
699 return result;
702 static SMB_ACL_T gpfsacl_get_posix_acl(const char *path, gpfs_aclType_t type,
703 TALLOC_CTX *mem_ctx)
705 struct gpfs_acl *pacl;
706 SMB_ACL_T result = NULL;
708 pacl = vfs_gpfs_getacl(talloc_tos(), path, false, type);
710 if (pacl == NULL) {
711 DEBUG(10, ("vfs_gpfs_getacl failed for %s with %s\n",
712 path, strerror(errno)));
713 if (errno == 0) {
714 errno = EINVAL;
716 goto done;
719 if (pacl->acl_version != GPFS_ACL_VERSION_POSIX) {
720 DEBUG(10, ("Got acl version %d, expected %d\n",
721 pacl->acl_version, GPFS_ACL_VERSION_POSIX));
722 errno = EINVAL;
723 goto done;
726 DEBUG(10, ("len: %d, level: %d, version: %d, nace: %d\n",
727 pacl->acl_len, pacl->acl_level, pacl->acl_version,
728 pacl->acl_nace));
730 result = gpfs2smb_acl(pacl, mem_ctx);
731 if (result != NULL) {
732 errno = 0;
735 done:
737 if (pacl != NULL) {
738 talloc_free(pacl);
740 if (errno != 0) {
741 TALLOC_FREE(result);
743 return result;
746 static SMB_ACL_T gpfsacl_sys_acl_get_file(vfs_handle_struct *handle,
747 const char *path_p,
748 SMB_ACL_TYPE_T type,
749 TALLOC_CTX *mem_ctx)
751 gpfs_aclType_t gpfs_type;
752 struct gpfs_config_data *config;
754 SMB_VFS_HANDLE_GET_DATA(handle, config,
755 struct gpfs_config_data,
756 return NULL);
758 if (!config->acl) {
759 return SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle, path_p,
760 type, mem_ctx);
763 switch(type) {
764 case SMB_ACL_TYPE_ACCESS:
765 gpfs_type = GPFS_ACL_TYPE_ACCESS;
766 break;
767 case SMB_ACL_TYPE_DEFAULT:
768 gpfs_type = GPFS_ACL_TYPE_DEFAULT;
769 break;
770 default:
771 DEBUG(0, ("Got invalid type: %d\n", type));
772 smb_panic("exiting");
775 return gpfsacl_get_posix_acl(path_p, gpfs_type, mem_ctx);
778 static SMB_ACL_T gpfsacl_sys_acl_get_fd(vfs_handle_struct *handle,
779 files_struct *fsp,
780 TALLOC_CTX *mem_ctx)
782 struct gpfs_config_data *config;
784 SMB_VFS_HANDLE_GET_DATA(handle, config,
785 struct gpfs_config_data,
786 return NULL);
788 if (!config->acl) {
789 return SMB_VFS_NEXT_SYS_ACL_GET_FD(handle, fsp, mem_ctx);
792 return gpfsacl_get_posix_acl(fsp->fsp_name->base_name,
793 GPFS_ACL_TYPE_ACCESS, mem_ctx);
796 static int gpfsacl_sys_acl_blob_get_file(vfs_handle_struct *handle,
797 const char *path_p,
798 TALLOC_CTX *mem_ctx,
799 char **blob_description,
800 DATA_BLOB *blob)
802 struct gpfs_config_data *config;
803 struct gpfs_opaque_acl *acl = NULL;
804 DATA_BLOB aclblob;
805 int result;
807 SMB_VFS_HANDLE_GET_DATA(handle, config,
808 struct gpfs_config_data,
809 return -1);
811 if (!config->acl) {
812 return SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FILE(handle, path_p,
813 mem_ctx,
814 blob_description,
815 blob);
818 errno = 0;
819 acl = (struct gpfs_opaque_acl *)
820 vfs_gpfs_getacl(mem_ctx,
821 path_p,
822 true,
823 GPFS_ACL_TYPE_NFS4);
825 if (errno) {
826 DEBUG(5, ("vfs_gpfs_getacl finished with errno %d: %s\n",
827 errno, strerror(errno)));
829 /* EINVAL means POSIX ACL, bail out on other cases */
830 if (errno != EINVAL) {
831 return -1;
835 if (acl != NULL) {
837 * file has NFSv4 ACL
839 * we only need the actual ACL blob here
840 * acl_version will always be NFS4 because we asked
841 * for NFS4
842 * acl_type is only used for POSIX ACLs
844 aclblob.data = (uint8_t*) acl->acl_var_data;
845 aclblob.length = acl->acl_buffer_len;
847 *blob_description = talloc_strdup(mem_ctx, "gpfs_nfs4_acl");
848 if (!*blob_description) {
849 talloc_free(acl);
850 errno = ENOMEM;
851 return -1;
854 result = non_posix_sys_acl_blob_get_file_helper(handle, path_p,
855 aclblob,
856 mem_ctx, blob);
858 talloc_free(acl);
859 return result;
862 /* fall back to POSIX ACL */
863 return posix_sys_acl_blob_get_file(handle, path_p, mem_ctx,
864 blob_description, blob);
867 static int gpfsacl_sys_acl_blob_get_fd(vfs_handle_struct *handle,
868 files_struct *fsp,
869 TALLOC_CTX *mem_ctx,
870 char **blob_description,
871 DATA_BLOB *blob)
873 struct gpfs_config_data *config;
874 struct gpfs_opaque_acl *acl = NULL;
875 DATA_BLOB aclblob;
876 int result;
878 SMB_VFS_HANDLE_GET_DATA(handle, config,
879 struct gpfs_config_data,
880 return -1);
882 if (!config->acl) {
883 return SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FD(handle, fsp, mem_ctx,
884 blob_description, blob);
887 errno = 0;
888 acl = (struct gpfs_opaque_acl *) vfs_gpfs_getacl(mem_ctx,
889 fsp->fsp_name->base_name,
890 true,
891 GPFS_ACL_TYPE_NFS4);
893 if (errno) {
894 DEBUG(5, ("vfs_gpfs_getacl finished with errno %d: %s\n",
895 errno, strerror(errno)));
897 /* EINVAL means POSIX ACL, bail out on other cases */
898 if (errno != EINVAL) {
899 return -1;
903 if (acl != NULL) {
905 * file has NFSv4 ACL
907 * we only need the actual ACL blob here
908 * acl_version will always be NFS4 because we asked
909 * for NFS4
910 * acl_type is only used for POSIX ACLs
912 aclblob.data = (uint8_t*) acl->acl_var_data;
913 aclblob.length = acl->acl_buffer_len;
915 *blob_description = talloc_strdup(mem_ctx, "gpfs_nfs4_acl");
916 if (!*blob_description) {
917 talloc_free(acl);
918 errno = ENOMEM;
919 return -1;
922 result = non_posix_sys_acl_blob_get_fd_helper(handle, fsp,
923 aclblob, mem_ctx,
924 blob);
926 talloc_free(acl);
927 return result;
930 /* fall back to POSIX ACL */
931 return posix_sys_acl_blob_get_fd(handle, fsp, mem_ctx,
932 blob_description, blob);
935 static struct gpfs_acl *smb2gpfs_acl(const SMB_ACL_T pacl,
936 SMB_ACL_TYPE_T type)
938 gpfs_aclLen_t len;
939 struct gpfs_acl *result;
940 int i;
942 DEBUG(10, ("smb2gpfs_acl: Got ACL with %d entries\n", pacl->count));
944 len = offsetof(gpfs_acl_t, ace_v1) + (pacl->count) *
945 sizeof(gpfs_ace_v1_t);
947 result = (struct gpfs_acl *)SMB_MALLOC(len);
948 if (result == NULL) {
949 errno = ENOMEM;
950 return result;
953 result->acl_len = len;
954 result->acl_level = 0;
955 result->acl_version = GPFS_ACL_VERSION_POSIX;
956 result->acl_type = (type == SMB_ACL_TYPE_DEFAULT) ?
957 GPFS_ACL_TYPE_DEFAULT : GPFS_ACL_TYPE_ACCESS;
958 result->acl_nace = pacl->count;
960 for (i=0; i<pacl->count; i++) {
961 const struct smb_acl_entry *ace = &pacl->acl[i];
962 struct gpfs_ace_v1 *g_ace = &result->ace_v1[i];
964 DEBUG(10, ("Converting type %d perm %x\n",
965 (int)ace->a_type, (int)ace->a_perm));
967 g_ace->ace_perm = 0;
969 switch(ace->a_type) {
970 case SMB_ACL_USER:
971 g_ace->ace_type = GPFS_ACL_USER;
972 g_ace->ace_who = (gpfs_uid_t)ace->info.user.uid;
973 break;
974 case SMB_ACL_USER_OBJ:
975 g_ace->ace_type = GPFS_ACL_USER_OBJ;
976 g_ace->ace_perm |= ACL_PERM_CONTROL;
977 g_ace->ace_who = 0;
978 break;
979 case SMB_ACL_GROUP:
980 g_ace->ace_type = GPFS_ACL_GROUP;
981 g_ace->ace_who = (gpfs_uid_t)ace->info.group.gid;
982 break;
983 case SMB_ACL_GROUP_OBJ:
984 g_ace->ace_type = GPFS_ACL_GROUP_OBJ;
985 g_ace->ace_who = 0;
986 break;
987 case SMB_ACL_MASK:
988 g_ace->ace_type = GPFS_ACL_MASK;
989 g_ace->ace_perm = 0x8f;
990 g_ace->ace_who = 0;
991 break;
992 case SMB_ACL_OTHER:
993 g_ace->ace_type = GPFS_ACL_OTHER;
994 g_ace->ace_who = 0;
995 break;
996 default:
997 DEBUG(10, ("Got invalid ace_type: %d\n", ace->a_type));
998 errno = EINVAL;
999 SAFE_FREE(result);
1000 return NULL;
1003 g_ace->ace_perm |= (ace->a_perm & SMB_ACL_READ) ?
1004 ACL_PERM_READ : 0;
1005 g_ace->ace_perm |= (ace->a_perm & SMB_ACL_WRITE) ?
1006 ACL_PERM_WRITE : 0;
1007 g_ace->ace_perm |= (ace->a_perm & SMB_ACL_EXECUTE) ?
1008 ACL_PERM_EXECUTE : 0;
1010 DEBUGADD(10, ("Converted to %d id %d perm %x\n",
1011 g_ace->ace_type, g_ace->ace_who, g_ace->ace_perm));
1014 return result;
1017 static int gpfsacl_sys_acl_set_file(vfs_handle_struct *handle,
1018 const char *name,
1019 SMB_ACL_TYPE_T type,
1020 SMB_ACL_T theacl)
1022 struct gpfs_acl *gpfs_acl;
1023 int result;
1024 struct gpfs_config_data *config;
1026 SMB_VFS_HANDLE_GET_DATA(handle, config,
1027 struct gpfs_config_data,
1028 return -1);
1030 if (!config->acl) {
1031 return SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle, name, type, theacl);
1034 gpfs_acl = smb2gpfs_acl(theacl, type);
1035 if (gpfs_acl == NULL) {
1036 return -1;
1039 result = smbd_gpfs_putacl((char *)name, GPFS_PUTACL_STRUCT | GPFS_ACL_SAMBA, gpfs_acl);
1041 SAFE_FREE(gpfs_acl);
1042 return result;
1045 static int gpfsacl_sys_acl_set_fd(vfs_handle_struct *handle,
1046 files_struct *fsp,
1047 SMB_ACL_T theacl)
1049 struct gpfs_config_data *config;
1051 SMB_VFS_HANDLE_GET_DATA(handle, config,
1052 struct gpfs_config_data,
1053 return -1);
1055 if (!config->acl) {
1056 return SMB_VFS_NEXT_SYS_ACL_SET_FD(handle, fsp, theacl);
1059 return gpfsacl_sys_acl_set_file(handle, fsp->fsp_name->base_name,
1060 SMB_ACL_TYPE_ACCESS, theacl);
1063 static int gpfsacl_sys_acl_delete_def_file(vfs_handle_struct *handle,
1064 const char *path)
1066 struct gpfs_config_data *config;
1068 SMB_VFS_HANDLE_GET_DATA(handle, config,
1069 struct gpfs_config_data,
1070 return -1);
1072 if (!config->acl) {
1073 return SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle, path);
1076 errno = ENOTSUP;
1077 return -1;
1081 * Assumed: mode bits are shiftable and standard
1082 * Output: the new aceMask field for an smb nfs4 ace
1084 static uint32 gpfsacl_mask_filter(uint32 aceType, uint32 aceMask, uint32 rwx)
1086 const uint32 posix_nfs4map[3] = {
1087 SMB_ACE4_EXECUTE, /* execute */
1088 SMB_ACE4_WRITE_DATA | SMB_ACE4_APPEND_DATA, /* write; GPFS specific */
1089 SMB_ACE4_READ_DATA /* read */
1091 int i;
1092 uint32_t posix_mask = 0x01;
1093 uint32_t posix_bit;
1094 uint32_t nfs4_bits;
1096 for(i=0; i<3; i++) {
1097 nfs4_bits = posix_nfs4map[i];
1098 posix_bit = rwx & posix_mask;
1100 if (aceType==SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE) {
1101 if (posix_bit)
1102 aceMask |= nfs4_bits;
1103 else
1104 aceMask &= ~nfs4_bits;
1105 } else {
1106 /* add deny bits when suitable */
1107 if (!posix_bit)
1108 aceMask |= nfs4_bits;
1109 else
1110 aceMask &= ~nfs4_bits;
1111 } /* other ace types are unexpected */
1113 posix_mask <<= 1;
1116 return aceMask;
1119 static int gpfsacl_emu_chmod(vfs_handle_struct *handle,
1120 const char *path, mode_t mode)
1122 SMB4ACL_T *pacl = NULL;
1123 int result;
1124 bool haveAllowEntry[SMB_ACE4_WHO_EVERYONE + 1] = {False, False, False, False};
1125 int i;
1126 files_struct fake_fsp; /* TODO: rationalize parametrization */
1127 SMB4ACE_T *smbace;
1128 TALLOC_CTX *frame = talloc_stackframe();
1129 NTSTATUS status;
1131 DEBUG(10, ("gpfsacl_emu_chmod invoked for %s mode %o\n", path, mode));
1133 result = gpfs_get_nfs4_acl(frame, path, &pacl);
1134 if (result) {
1135 TALLOC_FREE(frame);
1136 return result;
1139 if (mode & ~(S_IRWXU | S_IRWXG | S_IRWXO)) {
1140 DEBUG(2, ("WARNING: cutting extra mode bits %o on %s\n", mode, path));
1143 for (smbace=smb_first_ace4(pacl); smbace!=NULL; smbace = smb_next_ace4(smbace)) {
1144 SMB_ACE4PROP_T *ace = smb_get_ace4(smbace);
1145 uint32_t specid = ace->who.special_id;
1147 if (ace->flags&SMB_ACE4_ID_SPECIAL &&
1148 ace->aceType<=SMB_ACE4_ACCESS_DENIED_ACE_TYPE &&
1149 specid <= SMB_ACE4_WHO_EVERYONE) {
1151 uint32_t newMask;
1153 if (ace->aceType==SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE)
1154 haveAllowEntry[specid] = True;
1156 /* mode >> 6 for @owner, mode >> 3 for @group,
1157 * mode >> 0 for @everyone */
1158 newMask = gpfsacl_mask_filter(ace->aceType, ace->aceMask,
1159 mode >> ((SMB_ACE4_WHO_EVERYONE - specid) * 3));
1160 if (ace->aceMask!=newMask) {
1161 DEBUG(10, ("ace changed for %s (%o -> %o) id=%d\n",
1162 path, ace->aceMask, newMask, specid));
1164 ace->aceMask = newMask;
1168 /* make sure we have at least ALLOW entries
1169 * for all the 3 special ids (@EVERYONE, @OWNER, @GROUP)
1170 * - if necessary
1172 for(i = SMB_ACE4_WHO_OWNER; i<=SMB_ACE4_WHO_EVERYONE; i++) {
1173 SMB_ACE4PROP_T ace;
1175 if (haveAllowEntry[i]==True)
1176 continue;
1178 ZERO_STRUCT(ace);
1179 ace.aceType = SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE;
1180 ace.flags |= SMB_ACE4_ID_SPECIAL;
1181 ace.who.special_id = i;
1183 if (i==SMB_ACE4_WHO_GROUP) /* not sure it's necessary... */
1184 ace.aceFlags |= SMB_ACE4_IDENTIFIER_GROUP;
1186 ace.aceMask = gpfsacl_mask_filter(ace.aceType, ace.aceMask,
1187 mode >> ((SMB_ACE4_WHO_EVERYONE - i) * 3));
1189 /* don't add unnecessary aces */
1190 if (!ace.aceMask)
1191 continue;
1193 /* we add it to the END - as windows expects allow aces */
1194 smb_add_ace4(pacl, &ace);
1195 DEBUG(10, ("Added ALLOW ace for %s, mode=%o, id=%d, aceMask=%x\n",
1196 path, mode, i, ace.aceMask));
1199 /* don't add complementary DENY ACEs here */
1200 ZERO_STRUCT(fake_fsp);
1201 fake_fsp.fsp_name = synthetic_smb_fname(
1202 frame, path, NULL, NULL);
1203 if (fake_fsp.fsp_name == NULL) {
1204 errno = ENOMEM;
1205 TALLOC_FREE(frame);
1206 return -1;
1208 /* put the acl */
1209 if (gpfsacl_process_smbacl(handle, &fake_fsp, pacl) == False) {
1210 TALLOC_FREE(frame);
1211 return -1;
1214 TALLOC_FREE(frame);
1215 return 0; /* ok for [f]chmod */
1218 static int vfs_gpfs_chmod(vfs_handle_struct *handle, const char *path, mode_t mode)
1220 struct smb_filename *smb_fname_cpath;
1221 int rc;
1223 smb_fname_cpath = synthetic_smb_fname(talloc_tos(), path, NULL, NULL);
1224 if (smb_fname_cpath == NULL) {
1225 errno = ENOMEM;
1226 return -1;
1229 if (SMB_VFS_NEXT_STAT(handle, smb_fname_cpath) != 0) {
1230 return -1;
1233 /* avoid chmod() if possible, to preserve acls */
1234 if ((smb_fname_cpath->st.st_ex_mode & ~S_IFMT) == mode) {
1235 return 0;
1238 rc = gpfsacl_emu_chmod(handle, path, mode);
1239 if (rc == 1)
1240 return SMB_VFS_NEXT_CHMOD(handle, path, mode);
1241 return rc;
1244 static int vfs_gpfs_fchmod(vfs_handle_struct *handle, files_struct *fsp, mode_t mode)
1246 SMB_STRUCT_STAT st;
1247 int rc;
1249 if (SMB_VFS_NEXT_FSTAT(handle, fsp, &st) != 0) {
1250 return -1;
1253 /* avoid chmod() if possible, to preserve acls */
1254 if ((st.st_ex_mode & ~S_IFMT) == mode) {
1255 return 0;
1258 rc = gpfsacl_emu_chmod(handle, fsp->fsp_name->base_name,
1259 mode);
1260 if (rc == 1)
1261 return SMB_VFS_NEXT_FCHMOD(handle, fsp, mode);
1262 return rc;
1265 static int gpfs_set_xattr(struct vfs_handle_struct *handle, const char *path,
1266 const char *name, const void *value, size_t size, int flags){
1267 struct xattr_DOSATTRIB dosattrib;
1268 enum ndr_err_code ndr_err;
1269 DATA_BLOB blob;
1270 const char *attrstr = value;
1271 unsigned int dosmode=0;
1272 struct gpfs_winattr attrs;
1273 int ret = 0;
1274 struct gpfs_config_data *config;
1276 SMB_VFS_HANDLE_GET_DATA(handle, config,
1277 struct gpfs_config_data,
1278 return -1);
1280 if (!config->winattr) {
1281 DEBUG(10, ("gpfs_set_xattr:name is %s -> next\n",name));
1282 return SMB_VFS_NEXT_SETXATTR(handle,path,name,value,size,flags);
1285 DEBUG(10, ("gpfs_set_xattr: %s \n",path));
1287 /* Only handle DOS Attributes */
1288 if (strcmp(name,SAMBA_XATTR_DOS_ATTRIB) != 0){
1289 DEBUG(5, ("gpfs_set_xattr:name is %s\n",name));
1290 return SMB_VFS_NEXT_SETXATTR(handle,path,name,value,size,flags);
1293 blob.data = (uint8_t *)attrstr;
1294 blob.length = size;
1296 ndr_err = ndr_pull_struct_blob(&blob, talloc_tos(), &dosattrib,
1297 (ndr_pull_flags_fn_t)ndr_pull_xattr_DOSATTRIB);
1299 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
1300 DEBUG(1, ("gpfs_set_xattr: bad ndr decode "
1301 "from EA on file %s: Error = %s\n",
1302 path, ndr_errstr(ndr_err)));
1303 return false;
1306 if (dosattrib.version != 3) {
1307 DEBUG(1, ("gpfs_set_xattr: expected dosattrib version 3, got "
1308 "%d\n", (int)dosattrib.version));
1309 return false;
1311 if (!(dosattrib.info.info3.valid_flags & XATTR_DOSINFO_ATTRIB)) {
1312 DEBUG(10, ("gpfs_set_xattr: XATTR_DOSINFO_ATTRIB not "
1313 "valid, ignoring\n"));
1314 return true;
1317 dosmode = dosattrib.info.info3.attrib;
1319 attrs.winAttrs = 0;
1320 /*Just map RD_ONLY, ARCHIVE, SYSTEM HIDDEN and SPARSE. Ignore the others*/
1321 if (dosmode & FILE_ATTRIBUTE_ARCHIVE){
1322 attrs.winAttrs |= GPFS_WINATTR_ARCHIVE;
1324 if (dosmode & FILE_ATTRIBUTE_HIDDEN){
1325 attrs.winAttrs |= GPFS_WINATTR_HIDDEN;
1327 if (dosmode & FILE_ATTRIBUTE_SYSTEM){
1328 attrs.winAttrs |= GPFS_WINATTR_SYSTEM;
1330 if (dosmode & FILE_ATTRIBUTE_READONLY){
1331 attrs.winAttrs |= GPFS_WINATTR_READONLY;
1333 if (dosmode & FILE_ATTRIBUTE_SPARSE) {
1334 attrs.winAttrs |= GPFS_WINATTR_SPARSE_FILE;
1338 ret = set_gpfs_winattrs(discard_const_p(char, path),
1339 GPFS_WINATTR_SET_ATTRS, &attrs);
1340 if ( ret == -1){
1341 if (errno == ENOSYS) {
1342 return SMB_VFS_NEXT_SETXATTR(handle, path, name, value,
1343 size, flags);
1346 DEBUG(1, ("gpfs_set_xattr:Set GPFS attributes failed %d\n",ret));
1347 return -1;
1350 DEBUG(10, ("gpfs_set_xattr:Set attributes: 0x%x\n",attrs.winAttrs));
1351 return 0;
1354 static ssize_t gpfs_get_xattr(struct vfs_handle_struct *handle, const char *path,
1355 const char *name, void *value, size_t size){
1356 char *attrstr = value;
1357 unsigned int dosmode = 0;
1358 struct gpfs_winattr attrs;
1359 int ret = 0;
1360 struct gpfs_config_data *config;
1362 SMB_VFS_HANDLE_GET_DATA(handle, config,
1363 struct gpfs_config_data,
1364 return -1);
1366 if (!config->winattr) {
1367 DEBUG(10, ("gpfs_get_xattr:name is %s -> next\n",name));
1368 return SMB_VFS_NEXT_GETXATTR(handle,path,name,value,size);
1371 DEBUG(10, ("gpfs_get_xattr: %s \n",path));
1373 /* Only handle DOS Attributes */
1374 if (strcmp(name,SAMBA_XATTR_DOS_ATTRIB) != 0){
1375 DEBUG(5, ("gpfs_get_xattr:name is %s\n",name));
1376 return SMB_VFS_NEXT_GETXATTR(handle,path,name,value,size);
1379 ret = get_gpfs_winattrs(discard_const_p(char, path), &attrs);
1380 if ( ret == -1){
1381 if (errno == ENOSYS) {
1382 return SMB_VFS_NEXT_GETXATTR(handle, path, name, value,
1383 size);
1386 DEBUG(1, ("gpfs_get_xattr: Get GPFS attributes failed: "
1387 "%d (%s)\n", ret, strerror(errno)));
1388 return -1;
1391 DEBUG(10, ("gpfs_get_xattr:Got attributes: 0x%x\n",attrs.winAttrs));
1393 /*Just map RD_ONLY, ARCHIVE, SYSTEM, HIDDEN and SPARSE. Ignore the others*/
1394 if (attrs.winAttrs & GPFS_WINATTR_ARCHIVE){
1395 dosmode |= FILE_ATTRIBUTE_ARCHIVE;
1397 if (attrs.winAttrs & GPFS_WINATTR_HIDDEN){
1398 dosmode |= FILE_ATTRIBUTE_HIDDEN;
1400 if (attrs.winAttrs & GPFS_WINATTR_SYSTEM){
1401 dosmode |= FILE_ATTRIBUTE_SYSTEM;
1403 if (attrs.winAttrs & GPFS_WINATTR_READONLY){
1404 dosmode |= FILE_ATTRIBUTE_READONLY;
1406 if (attrs.winAttrs & GPFS_WINATTR_SPARSE_FILE) {
1407 dosmode |= FILE_ATTRIBUTE_SPARSE;
1410 snprintf(attrstr, size, "0x%2.2x",
1411 (unsigned int)(dosmode & SAMBA_ATTRIBUTES_MASK));
1412 DEBUG(10, ("gpfs_get_xattr: returning %s\n",attrstr));
1413 return 4;
1416 #if defined(HAVE_FSTATAT)
1417 static int stat_with_capability(struct vfs_handle_struct *handle,
1418 struct smb_filename *smb_fname, int flag)
1420 int fd = -1;
1421 bool b;
1422 char *dir_name;
1423 const char *rel_name = NULL;
1424 struct stat st;
1425 int ret = -1;
1427 b = parent_dirname(talloc_tos(), smb_fname->base_name,
1428 &dir_name, &rel_name);
1429 if (!b) {
1430 errno = ENOMEM;
1431 return -1;
1434 fd = open(dir_name, O_RDONLY, 0);
1435 TALLOC_FREE(dir_name);
1436 if (fd == -1) {
1437 return -1;
1440 set_effective_capability(DAC_OVERRIDE_CAPABILITY);
1441 ret = fstatat(fd, rel_name, &st, flag);
1442 drop_effective_capability(DAC_OVERRIDE_CAPABILITY);
1444 close(fd);
1446 if (ret == 0) {
1447 init_stat_ex_from_stat(
1448 &smb_fname->st, &st,
1449 lp_fake_directory_create_times(SNUM(handle->conn)));
1452 return ret;
1454 #endif
1456 static int vfs_gpfs_stat(struct vfs_handle_struct *handle,
1457 struct smb_filename *smb_fname)
1459 struct gpfs_winattr attrs;
1460 char *fname = NULL;
1461 NTSTATUS status;
1462 int ret;
1463 struct gpfs_config_data *config;
1465 SMB_VFS_HANDLE_GET_DATA(handle, config,
1466 struct gpfs_config_data,
1467 return -1);
1469 ret = SMB_VFS_NEXT_STAT(handle, smb_fname);
1470 #if defined(HAVE_FSTATAT)
1471 if (ret == -1 && errno == EACCES) {
1472 DEBUG(10, ("Trying stat with capability for %s\n",
1473 smb_fname->base_name));
1474 ret = stat_with_capability(handle, smb_fname, 0);
1476 #endif
1477 if (ret == -1) {
1478 return -1;
1481 if (!config->winattr) {
1482 return 0;
1485 status = get_full_smb_filename(talloc_tos(), smb_fname, &fname);
1486 if (!NT_STATUS_IS_OK(status)) {
1487 errno = map_errno_from_nt_status(status);
1488 return -1;
1490 ret = get_gpfs_winattrs(discard_const_p(char, fname), &attrs);
1491 TALLOC_FREE(fname);
1492 if (ret == 0) {
1493 smb_fname->st.st_ex_calculated_birthtime = false;
1494 smb_fname->st.st_ex_btime.tv_sec = attrs.creationTime.tv_sec;
1495 smb_fname->st.st_ex_btime.tv_nsec = attrs.creationTime.tv_nsec;
1496 smb_fname->st.vfs_private = attrs.winAttrs;
1498 return 0;
1501 static int vfs_gpfs_fstat(struct vfs_handle_struct *handle,
1502 struct files_struct *fsp, SMB_STRUCT_STAT *sbuf)
1504 struct gpfs_winattr attrs;
1505 int ret;
1506 struct gpfs_config_data *config;
1508 SMB_VFS_HANDLE_GET_DATA(handle, config,
1509 struct gpfs_config_data,
1510 return -1);
1512 ret = SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf);
1513 if (ret == -1) {
1514 return -1;
1516 if ((fsp->fh == NULL) || (fsp->fh->fd == -1)) {
1517 return 0;
1519 if (!config->winattr) {
1520 return 0;
1523 ret = smbd_fget_gpfs_winattrs(fsp->fh->fd, &attrs);
1524 if (ret == 0) {
1525 sbuf->st_ex_calculated_birthtime = false;
1526 sbuf->st_ex_btime.tv_sec = attrs.creationTime.tv_sec;
1527 sbuf->st_ex_btime.tv_nsec = attrs.creationTime.tv_nsec;
1529 return 0;
1532 static int vfs_gpfs_lstat(struct vfs_handle_struct *handle,
1533 struct smb_filename *smb_fname)
1535 struct gpfs_winattr attrs;
1536 char *path = NULL;
1537 NTSTATUS status;
1538 int ret;
1539 struct gpfs_config_data *config;
1541 SMB_VFS_HANDLE_GET_DATA(handle, config,
1542 struct gpfs_config_data,
1543 return -1);
1545 ret = SMB_VFS_NEXT_LSTAT(handle, smb_fname);
1546 #if defined(HAVE_FSTATAT)
1547 if (ret == -1 && errno == EACCES) {
1548 DEBUG(10, ("Trying lstat with capability for %s\n",
1549 smb_fname->base_name));
1550 ret = stat_with_capability(handle, smb_fname,
1551 AT_SYMLINK_NOFOLLOW);
1553 #endif
1555 if (ret == -1) {
1556 return -1;
1558 if (!config->winattr) {
1559 return 0;
1562 status = get_full_smb_filename(talloc_tos(), smb_fname, &path);
1563 if (!NT_STATUS_IS_OK(status)) {
1564 errno = map_errno_from_nt_status(status);
1565 return -1;
1567 ret = get_gpfs_winattrs(discard_const_p(char, path), &attrs);
1568 TALLOC_FREE(path);
1569 if (ret == 0) {
1570 smb_fname->st.st_ex_calculated_birthtime = false;
1571 smb_fname->st.st_ex_btime.tv_sec = attrs.creationTime.tv_sec;
1572 smb_fname->st.st_ex_btime.tv_nsec = attrs.creationTime.tv_nsec;
1573 smb_fname->st.vfs_private = attrs.winAttrs;
1575 return 0;
1578 static int vfs_gpfs_ntimes(struct vfs_handle_struct *handle,
1579 const struct smb_filename *smb_fname,
1580 struct smb_file_time *ft)
1583 struct gpfs_winattr attrs;
1584 int ret;
1585 char *path = NULL;
1586 NTSTATUS status;
1587 struct gpfs_config_data *config;
1589 SMB_VFS_HANDLE_GET_DATA(handle, config,
1590 struct gpfs_config_data,
1591 return -1);
1593 status = get_full_smb_filename(talloc_tos(), smb_fname, &path);
1594 if (!NT_STATUS_IS_OK(status)) {
1595 errno = map_errno_from_nt_status(status);
1596 return -1;
1599 /* Try to use gpfs_set_times if it is enabled and available */
1600 if (config->settimes) {
1601 ret = smbd_gpfs_set_times_path(path, ft);
1603 if (ret == 0 || (ret == -1 && errno != ENOSYS)) {
1604 return ret;
1608 DEBUG(10,("gpfs_set_times() not available or disabled, "
1609 "use ntimes and winattr\n"));
1611 ret = SMB_VFS_NEXT_NTIMES(handle, smb_fname, ft);
1612 if(ret == -1){
1613 /* don't complain if access was denied */
1614 if (errno != EPERM && errno != EACCES) {
1615 DEBUG(1,("vfs_gpfs_ntimes: SMB_VFS_NEXT_NTIMES failed:"
1616 "%s", strerror(errno)));
1618 return -1;
1621 if(null_timespec(ft->create_time)){
1622 DEBUG(10,("vfs_gpfs_ntimes:Create Time is NULL\n"));
1623 return 0;
1626 if (!config->winattr) {
1627 return 0;
1630 attrs.winAttrs = 0;
1631 attrs.creationTime.tv_sec = ft->create_time.tv_sec;
1632 attrs.creationTime.tv_nsec = ft->create_time.tv_nsec;
1634 ret = set_gpfs_winattrs(discard_const_p(char, path),
1635 GPFS_WINATTR_SET_CREATION_TIME, &attrs);
1636 if(ret == -1 && errno != ENOSYS){
1637 DEBUG(1,("vfs_gpfs_ntimes: set GPFS ntimes failed %d\n",ret));
1638 return -1;
1640 return 0;
1644 static int vfs_gpfs_fallocate(struct vfs_handle_struct *handle,
1645 struct files_struct *fsp, enum vfs_fallocate_mode mode,
1646 off_t offset, off_t len)
1648 int ret;
1649 struct gpfs_config_data *config;
1651 SMB_VFS_HANDLE_GET_DATA(handle, config,
1652 struct gpfs_config_data,
1653 return -1);
1655 if (!config->prealloc) {
1656 /* you should better not run fallocate() on GPFS at all */
1657 errno = ENOTSUP;
1658 return -1;
1661 if (mode == VFS_FALLOCATE_KEEP_SIZE) {
1662 DEBUG(10, ("Unsupported VFS_FALLOCATE_KEEP_SIZE\n"));
1663 errno = ENOTSUP;
1664 return -1;
1667 ret = smbd_gpfs_prealloc(fsp->fh->fd, offset, len);
1669 if (ret == -1 && errno != ENOSYS) {
1670 DEBUG(0, ("GPFS prealloc failed: %s\n", strerror(errno)));
1671 } else if (ret == -1 && errno == ENOSYS) {
1672 DEBUG(10, ("GPFS prealloc not supported.\n"));
1673 } else {
1674 DEBUG(10, ("GPFS prealloc succeeded.\n"));
1677 return ret;
1680 static int vfs_gpfs_ftruncate(vfs_handle_struct *handle, files_struct *fsp,
1681 off_t len)
1683 int result;
1684 struct gpfs_config_data *config;
1686 SMB_VFS_HANDLE_GET_DATA(handle, config,
1687 struct gpfs_config_data,
1688 return -1);
1690 if (!config->ftruncate) {
1691 return SMB_VFS_NEXT_FTRUNCATE(handle, fsp, len);
1694 result = smbd_gpfs_ftruncate(fsp->fh->fd, len);
1695 if ((result == -1) && (errno == ENOSYS)) {
1696 return SMB_VFS_NEXT_FTRUNCATE(handle, fsp, len);
1698 return result;
1701 static bool vfs_gpfs_is_offline(struct vfs_handle_struct *handle,
1702 const struct smb_filename *fname,
1703 SMB_STRUCT_STAT *sbuf)
1705 struct gpfs_winattr attrs;
1706 char *path = NULL;
1707 NTSTATUS status;
1708 struct gpfs_config_data *config;
1710 SMB_VFS_HANDLE_GET_DATA(handle, config,
1711 struct gpfs_config_data,
1712 return -1);
1714 if (!config->winattr) {
1715 return SMB_VFS_NEXT_IS_OFFLINE(handle, fname, sbuf);
1718 status = get_full_smb_filename(talloc_tos(), fname, &path);
1719 if (!NT_STATUS_IS_OK(status)) {
1720 errno = map_errno_from_nt_status(status);
1721 return -1;
1724 if (VALID_STAT(*sbuf)) {
1725 attrs.winAttrs = sbuf->vfs_private;
1726 } else {
1727 int ret;
1728 ret = get_gpfs_winattrs(path, &attrs);
1730 if (ret == -1) {
1731 TALLOC_FREE(path);
1732 return false;
1735 if ((attrs.winAttrs & GPFS_WINATTR_OFFLINE) != 0) {
1736 DEBUG(10, ("%s is offline\n", path));
1737 TALLOC_FREE(path);
1738 return true;
1740 DEBUG(10, ("%s is online\n", path));
1741 TALLOC_FREE(path);
1742 return SMB_VFS_NEXT_IS_OFFLINE(handle, fname, sbuf);
1745 static bool vfs_gpfs_aio_force(struct vfs_handle_struct *handle,
1746 struct files_struct *fsp)
1748 return vfs_gpfs_is_offline(handle, fsp->fsp_name, &fsp->fsp_name->st);
1751 static ssize_t vfs_gpfs_sendfile(vfs_handle_struct *handle, int tofd,
1752 files_struct *fsp, const DATA_BLOB *hdr,
1753 off_t offset, size_t n)
1755 if ((fsp->fsp_name->st.vfs_private & GPFS_WINATTR_OFFLINE) != 0) {
1756 errno = ENOSYS;
1757 return -1;
1759 return SMB_VFS_NEXT_SENDFILE(handle, tofd, fsp, hdr, offset, n);
1762 static int vfs_gpfs_connect(struct vfs_handle_struct *handle,
1763 const char *service, const char *user)
1765 struct gpfs_config_data *config;
1766 int ret;
1768 smbd_gpfs_lib_init();
1770 config = talloc_zero(handle->conn, struct gpfs_config_data);
1771 if (!config) {
1772 DEBUG(0, ("talloc_zero() failed\n"));
1773 errno = ENOMEM;
1774 return -1;
1777 ret = SMB_VFS_NEXT_CONNECT(handle, service, user);
1778 if (ret < 0) {
1779 TALLOC_FREE(config);
1780 return ret;
1783 config->sharemodes = lp_parm_bool(SNUM(handle->conn), "gpfs",
1784 "sharemodes", true);
1786 config->leases = lp_parm_bool(SNUM(handle->conn), "gpfs",
1787 "leases", true);
1789 config->hsm = lp_parm_bool(SNUM(handle->conn), "gpfs",
1790 "hsm", false);
1792 config->syncio = lp_parm_bool(SNUM(handle->conn), "gpfs",
1793 "syncio", false);
1795 config->winattr = lp_parm_bool(SNUM(handle->conn), "gpfs",
1796 "winattr", false);
1798 config->ftruncate = lp_parm_bool(SNUM(handle->conn), "gpfs",
1799 "ftruncate", true);
1801 config->getrealfilename = lp_parm_bool(SNUM(handle->conn), "gpfs",
1802 "getrealfilename", true);
1804 config->dfreequota = lp_parm_bool(SNUM(handle->conn), "gpfs",
1805 "dfreequota", false);
1807 config->prealloc = lp_parm_bool(SNUM(handle->conn), "gpfs",
1808 "prealloc", true);
1810 config->acl = lp_parm_bool(SNUM(handle->conn), "gpfs", "acl", true);
1812 config->settimes = lp_parm_bool(SNUM(handle->conn), "gpfs",
1813 "settimes", true);
1814 config->recalls = lp_parm_bool(SNUM(handle->conn), "gpfs",
1815 "recalls", true);
1817 SMB_VFS_HANDLE_SET_DATA(handle, config,
1818 NULL, struct gpfs_config_data,
1819 return -1);
1821 if (config->leases) {
1823 * GPFS lease code is based on kernel oplock code
1824 * so make sure it is turned on
1826 if (!lp_kernel_oplocks(SNUM(handle->conn))) {
1827 DEBUG(5, ("Enabling kernel oplocks for "
1828 "gpfs:leases to work\n"));
1829 lp_do_parameter(SNUM(handle->conn), "kernel oplocks",
1830 "true");
1834 * as the kernel does not properly support Level II oplocks
1835 * and GPFS leases code is based on kernel infrastructure, we
1836 * need to turn off Level II oplocks if gpfs:leases is enabled
1838 if (lp_level2_oplocks(SNUM(handle->conn))) {
1839 DEBUG(5, ("gpfs:leases are enabled, disabling "
1840 "Level II oplocks\n"));
1841 lp_do_parameter(SNUM(handle->conn), "level2 oplocks",
1842 "false");
1846 return 0;
1849 static int vfs_gpfs_get_quotas(const char *path, uid_t uid, gid_t gid,
1850 int *fset_id,
1851 struct gpfs_quotaInfo *qi_user,
1852 struct gpfs_quotaInfo *qi_group,
1853 struct gpfs_quotaInfo *qi_fset)
1855 int err;
1856 char *dir_path;
1857 bool b;
1860 * We want to always use the directory to get the fileset id,
1861 * because files might have a share mode. We also do not want
1862 * to get the parent directory when there is already a
1863 * directory to avoid stepping in a different fileset. The
1864 * path passed here is currently either "." or a filename, so
1865 * this is ok. The proper solution would be having a way to
1866 * query the fileset id without opening the file.
1868 b = parent_dirname(talloc_tos(), path, &dir_path, NULL);
1869 if (!b) {
1870 errno = ENOMEM;
1871 return -1;
1874 DEBUG(10, ("path %s, directory %s\n", path, dir_path));
1876 err = get_gpfs_fset_id(dir_path, fset_id);
1877 if (err) {
1878 DEBUG(0, ("Get fset id failed path %s, dir %s, errno %d.\n",
1879 path, dir_path, errno));
1880 return err;
1883 err = get_gpfs_quota(path, GPFS_USRQUOTA, uid, qi_user);
1884 if (err) {
1885 return err;
1888 err = get_gpfs_quota(path, GPFS_GRPQUOTA, gid, qi_group);
1889 if (err) {
1890 return err;
1893 err = get_gpfs_quota(path, GPFS_FILESETQUOTA, *fset_id, qi_fset);
1894 if (err) {
1895 return err;
1898 return 0;
1901 static void vfs_gpfs_disk_free_quota(struct gpfs_quotaInfo qi, time_t cur_time,
1902 uint64_t *dfree, uint64_t *dsize)
1904 uint64_t usage, limit;
1907 * The quota reporting is done in units of 1024 byte blocks, but
1908 * sys_fsusage uses units of 512 byte blocks, adjust the block number
1909 * accordingly. Also filter possibly negative usage counts from gpfs.
1911 usage = qi.blockUsage < 0 ? 0 : (uint64_t)qi.blockUsage * 2;
1912 limit = (uint64_t)qi.blockHardLimit * 2;
1915 * When the grace time for the exceeded soft block quota has been
1916 * exceeded, the soft block quota becomes an additional hard limit.
1918 if (qi.blockSoftLimit &&
1919 qi.blockGraceTime && cur_time > qi.blockGraceTime) {
1920 /* report disk as full */
1921 *dfree = 0;
1922 *dsize = MIN(*dsize, usage);
1925 if (!qi.blockHardLimit)
1926 return;
1928 if (usage >= limit) {
1929 /* report disk as full */
1930 *dfree = 0;
1931 *dsize = MIN(*dsize, usage);
1933 } else {
1934 /* limit has not been reached, determine "free space" */
1935 *dfree = MIN(*dfree, limit - usage);
1936 *dsize = MIN(*dsize, limit);
1940 static uint64_t vfs_gpfs_disk_free(vfs_handle_struct *handle, const char *path,
1941 bool small_query, uint64_t *bsize,
1942 uint64_t *dfree, uint64_t *dsize)
1944 struct security_unix_token *utok;
1945 struct gpfs_quotaInfo qi_user, qi_group, qi_fset;
1946 struct gpfs_config_data *config;
1947 int err, fset_id;
1948 time_t cur_time;
1950 SMB_VFS_HANDLE_GET_DATA(handle, config, struct gpfs_config_data,
1951 return (uint64_t)-1);
1952 if (!config->dfreequota) {
1953 return SMB_VFS_NEXT_DISK_FREE(handle, path, small_query,
1954 bsize, dfree, dsize);
1957 err = sys_fsusage(path, dfree, dsize);
1958 if (err) {
1959 DEBUG (0, ("Could not get fs usage, errno %d\n", errno));
1960 return SMB_VFS_NEXT_DISK_FREE(handle, path, small_query,
1961 bsize, dfree, dsize);
1964 /* sys_fsusage returns units of 512 bytes */
1965 *bsize = 512;
1967 DEBUG(10, ("fs dfree %llu, dsize %llu\n",
1968 (unsigned long long)*dfree, (unsigned long long)*dsize));
1970 utok = handle->conn->session_info->unix_token;
1971 err = vfs_gpfs_get_quotas(path, utok->uid, utok->gid, &fset_id,
1972 &qi_user, &qi_group, &qi_fset);
1973 if (err) {
1974 return SMB_VFS_NEXT_DISK_FREE(handle, path, small_query,
1975 bsize, dfree, dsize);
1978 cur_time = time(NULL);
1980 /* Adjust free space and size according to quota limits. */
1981 vfs_gpfs_disk_free_quota(qi_user, cur_time, dfree, dsize);
1982 vfs_gpfs_disk_free_quota(qi_group, cur_time, dfree, dsize);
1984 /* Id 0 indicates the default quota, not an actual quota */
1985 if (fset_id != 0) {
1986 vfs_gpfs_disk_free_quota(qi_fset, cur_time, dfree, dsize);
1989 disk_norm(small_query, bsize, dfree, dsize);
1990 return *dfree;
1993 static uint32_t vfs_gpfs_capabilities(struct vfs_handle_struct *handle,
1994 enum timestamp_set_resolution *p_ts_res)
1996 struct gpfs_config_data *config;
1997 uint32_t next;
1999 next = SMB_VFS_NEXT_FS_CAPABILITIES(handle, p_ts_res);
2001 SMB_VFS_HANDLE_GET_DATA(handle, config,
2002 struct gpfs_config_data,
2003 return next);
2005 if (config->hsm) {
2006 next |= FILE_SUPPORTS_REMOTE_STORAGE;
2008 return next;
2011 static int vfs_gpfs_open(struct vfs_handle_struct *handle,
2012 struct smb_filename *smb_fname, files_struct *fsp,
2013 int flags, mode_t mode)
2015 struct gpfs_config_data *config;
2017 SMB_VFS_HANDLE_GET_DATA(handle, config,
2018 struct gpfs_config_data,
2019 return -1);
2021 if (config->hsm && !config->recalls) {
2022 if (VALID_STAT(smb_fname->st) &&
2023 (smb_fname->st.vfs_private & GPFS_WINATTR_OFFLINE)) {
2024 DEBUG(10, ("Refusing access to offline file %s\n",
2025 fsp_str_dbg(fsp)));
2026 errno = EACCES;
2027 return -1;
2031 if (config->syncio) {
2032 flags |= O_SYNC;
2034 return SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
2037 static ssize_t vfs_gpfs_pread(vfs_handle_struct *handle, files_struct *fsp,
2038 void *data, size_t n, off_t offset)
2040 ssize_t ret;
2042 ret = SMB_VFS_NEXT_PREAD(handle, fsp, data, n, offset);
2044 DEBUG(10, ("vfs_private = %x\n",
2045 (unsigned int)fsp->fsp_name->st.vfs_private));
2047 if ((ret != -1) &&
2048 ((fsp->fsp_name->st.vfs_private & GPFS_WINATTR_OFFLINE) != 0)) {
2049 fsp->fsp_name->st.vfs_private &= ~GPFS_WINATTR_OFFLINE;
2050 notify_fname(handle->conn, NOTIFY_ACTION_MODIFIED,
2051 FILE_NOTIFY_CHANGE_ATTRIBUTES,
2052 fsp->fsp_name->base_name);
2055 return ret;
2058 struct vfs_gpfs_pread_state {
2059 struct files_struct *fsp;
2060 ssize_t ret;
2061 int err;
2064 static void vfs_gpfs_pread_done(struct tevent_req *subreq);
2066 static struct tevent_req *vfs_gpfs_pread_send(struct vfs_handle_struct *handle,
2067 TALLOC_CTX *mem_ctx,
2068 struct tevent_context *ev,
2069 struct files_struct *fsp,
2070 void *data, size_t n,
2071 off_t offset)
2073 struct tevent_req *req, *subreq;
2074 struct vfs_gpfs_pread_state *state;
2076 req = tevent_req_create(mem_ctx, &state, struct vfs_gpfs_pread_state);
2077 if (req == NULL) {
2078 return NULL;
2080 state->fsp = fsp;
2081 subreq = SMB_VFS_NEXT_PREAD_SEND(state, ev, handle, fsp, data,
2082 n, offset);
2083 if (tevent_req_nomem(subreq, req)) {
2084 return tevent_req_post(req, ev);
2086 tevent_req_set_callback(subreq, vfs_gpfs_pread_done, req);
2087 return req;
2090 static void vfs_gpfs_pread_done(struct tevent_req *subreq)
2092 struct tevent_req *req = tevent_req_callback_data(
2093 subreq, struct tevent_req);
2094 struct vfs_gpfs_pread_state *state = tevent_req_data(
2095 req, struct vfs_gpfs_pread_state);
2097 state->ret = SMB_VFS_PREAD_RECV(subreq, &state->err);
2098 TALLOC_FREE(subreq);
2099 tevent_req_done(req);
2102 static ssize_t vfs_gpfs_pread_recv(struct tevent_req *req, int *err)
2104 struct vfs_gpfs_pread_state *state = tevent_req_data(
2105 req, struct vfs_gpfs_pread_state);
2106 struct files_struct *fsp = state->fsp;
2108 if (tevent_req_is_unix_error(req, err)) {
2109 return -1;
2111 *err = state->err;
2113 DEBUG(10, ("vfs_private = %x\n",
2114 (unsigned int)fsp->fsp_name->st.vfs_private));
2116 if ((state->ret != -1) &&
2117 ((fsp->fsp_name->st.vfs_private & GPFS_WINATTR_OFFLINE) != 0)) {
2118 fsp->fsp_name->st.vfs_private &= ~GPFS_WINATTR_OFFLINE;
2119 DEBUG(10, ("sending notify\n"));
2120 notify_fname(fsp->conn, NOTIFY_ACTION_MODIFIED,
2121 FILE_NOTIFY_CHANGE_ATTRIBUTES,
2122 fsp->fsp_name->base_name);
2125 return state->ret;
2128 static ssize_t vfs_gpfs_pwrite(vfs_handle_struct *handle, files_struct *fsp,
2129 const void *data, size_t n, off_t offset)
2131 ssize_t ret;
2133 ret = SMB_VFS_NEXT_PWRITE(handle, fsp, data, n, offset);
2135 DEBUG(10, ("vfs_private = %x\n",
2136 (unsigned int)fsp->fsp_name->st.vfs_private));
2138 if ((ret != -1) &&
2139 ((fsp->fsp_name->st.vfs_private & GPFS_WINATTR_OFFLINE) != 0)) {
2140 fsp->fsp_name->st.vfs_private &= ~GPFS_WINATTR_OFFLINE;
2141 notify_fname(handle->conn, NOTIFY_ACTION_MODIFIED,
2142 FILE_NOTIFY_CHANGE_ATTRIBUTES,
2143 fsp->fsp_name->base_name);
2146 return ret;
2149 struct vfs_gpfs_pwrite_state {
2150 struct files_struct *fsp;
2151 ssize_t ret;
2152 int err;
2155 static void vfs_gpfs_pwrite_done(struct tevent_req *subreq);
2157 static struct tevent_req *vfs_gpfs_pwrite_send(
2158 struct vfs_handle_struct *handle,
2159 TALLOC_CTX *mem_ctx,
2160 struct tevent_context *ev,
2161 struct files_struct *fsp,
2162 const void *data, size_t n,
2163 off_t offset)
2165 struct tevent_req *req, *subreq;
2166 struct vfs_gpfs_pwrite_state *state;
2168 req = tevent_req_create(mem_ctx, &state, struct vfs_gpfs_pwrite_state);
2169 if (req == NULL) {
2170 return NULL;
2172 state->fsp = fsp;
2173 subreq = SMB_VFS_NEXT_PWRITE_SEND(state, ev, handle, fsp, data,
2174 n, offset);
2175 if (tevent_req_nomem(subreq, req)) {
2176 return tevent_req_post(req, ev);
2178 tevent_req_set_callback(subreq, vfs_gpfs_pwrite_done, req);
2179 return req;
2182 static void vfs_gpfs_pwrite_done(struct tevent_req *subreq)
2184 struct tevent_req *req = tevent_req_callback_data(
2185 subreq, struct tevent_req);
2186 struct vfs_gpfs_pwrite_state *state = tevent_req_data(
2187 req, struct vfs_gpfs_pwrite_state);
2189 state->ret = SMB_VFS_PWRITE_RECV(subreq, &state->err);
2190 TALLOC_FREE(subreq);
2191 tevent_req_done(req);
2194 static ssize_t vfs_gpfs_pwrite_recv(struct tevent_req *req, int *err)
2196 struct vfs_gpfs_pwrite_state *state = tevent_req_data(
2197 req, struct vfs_gpfs_pwrite_state);
2198 struct files_struct *fsp = state->fsp;
2200 if (tevent_req_is_unix_error(req, err)) {
2201 return -1;
2203 *err = state->err;
2205 DEBUG(10, ("vfs_private = %x\n",
2206 (unsigned int)fsp->fsp_name->st.vfs_private));
2208 if ((state->ret != -1) &&
2209 ((fsp->fsp_name->st.vfs_private & GPFS_WINATTR_OFFLINE) != 0)) {
2210 fsp->fsp_name->st.vfs_private &= ~GPFS_WINATTR_OFFLINE;
2211 DEBUG(10, ("sending notify\n"));
2212 notify_fname(fsp->conn, NOTIFY_ACTION_MODIFIED,
2213 FILE_NOTIFY_CHANGE_ATTRIBUTES,
2214 fsp->fsp_name->base_name);
2217 return state->ret;
2221 static struct vfs_fn_pointers vfs_gpfs_fns = {
2222 .connect_fn = vfs_gpfs_connect,
2223 .disk_free_fn = vfs_gpfs_disk_free,
2224 .fs_capabilities_fn = vfs_gpfs_capabilities,
2225 .kernel_flock_fn = vfs_gpfs_kernel_flock,
2226 .linux_setlease_fn = vfs_gpfs_setlease,
2227 .get_real_filename_fn = vfs_gpfs_get_real_filename,
2228 .fget_nt_acl_fn = gpfsacl_fget_nt_acl,
2229 .get_nt_acl_fn = gpfsacl_get_nt_acl,
2230 .fset_nt_acl_fn = gpfsacl_fset_nt_acl,
2231 .sys_acl_get_file_fn = gpfsacl_sys_acl_get_file,
2232 .sys_acl_get_fd_fn = gpfsacl_sys_acl_get_fd,
2233 .sys_acl_blob_get_file_fn = gpfsacl_sys_acl_blob_get_file,
2234 .sys_acl_blob_get_fd_fn = gpfsacl_sys_acl_blob_get_fd,
2235 .sys_acl_set_file_fn = gpfsacl_sys_acl_set_file,
2236 .sys_acl_set_fd_fn = gpfsacl_sys_acl_set_fd,
2237 .sys_acl_delete_def_file_fn = gpfsacl_sys_acl_delete_def_file,
2238 .chmod_fn = vfs_gpfs_chmod,
2239 .fchmod_fn = vfs_gpfs_fchmod,
2240 .close_fn = vfs_gpfs_close,
2241 .setxattr_fn = gpfs_set_xattr,
2242 .getxattr_fn = gpfs_get_xattr,
2243 .stat_fn = vfs_gpfs_stat,
2244 .fstat_fn = vfs_gpfs_fstat,
2245 .lstat_fn = vfs_gpfs_lstat,
2246 .ntimes_fn = vfs_gpfs_ntimes,
2247 .is_offline_fn = vfs_gpfs_is_offline,
2248 .aio_force_fn = vfs_gpfs_aio_force,
2249 .sendfile_fn = vfs_gpfs_sendfile,
2250 .fallocate_fn = vfs_gpfs_fallocate,
2251 .open_fn = vfs_gpfs_open,
2252 .pread_fn = vfs_gpfs_pread,
2253 .pread_send_fn = vfs_gpfs_pread_send,
2254 .pread_recv_fn = vfs_gpfs_pread_recv,
2255 .pwrite_fn = vfs_gpfs_pwrite,
2256 .pwrite_send_fn = vfs_gpfs_pwrite_send,
2257 .pwrite_recv_fn = vfs_gpfs_pwrite_recv,
2258 .ftruncate_fn = vfs_gpfs_ftruncate
2261 NTSTATUS vfs_gpfs_init(void);
2262 NTSTATUS vfs_gpfs_init(void)
2264 init_gpfs();
2266 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "gpfs",
2267 &vfs_gpfs_fns);