500a6ee7722672697789d35c0122992656e025bd
[ira/wip.git] / source3 / modules / vfs_gpfs.c
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
34
35 static int vfs_gpfs_kernel_flock(vfs_handle_struct *handle, files_struct *fsp, 
36                                  int fd, 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
54 static int vfs_gpfs_setlease(vfs_handle_struct *handle, files_struct *fsp, 
55                                  int fd, int leasetype)
56 {
57         int ret;
58         
59         START_PROFILE(syscall_linux_setlease);
60         
61         if ( linux_set_lease_sighandler(fd) == -1)
62                 return -1;
63
64         ret = set_gpfs_lease(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(fd, leasetype);
70         }
71
72         END_PROFILE(syscall_linux_setlease);
73
74         return ret;
75 }
76
77
78
79 static 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
99 static 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  */
149 static 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, GPFS_ACL_TYPE_NFS4);
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                 memset(&smbace, 0, sizeof(SMB4ACE_T));
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
229 static 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
251 static 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(fsp->fsp_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
273 static 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                 gace->aceIFlags = (aceprop->flags&SMB_ACE4_ID_SPECIAL) ? ACE4_IFLAG_SPECIAL_ID : 0;
305
306                 if (aceprop->flags&SMB_ACE4_ID_SPECIAL)
307                 {
308                         switch(aceprop->who.special_id)
309                         {
310                         case SMB_ACE4_WHO_EVERYONE:
311                                 gace->aceWho = ACE4_SPECIAL_EVERYONE;
312                                 break;
313                         case SMB_ACE4_WHO_OWNER:
314                                 gace->aceWho = ACE4_SPECIAL_OWNER;
315                                 break;
316                         case SMB_ACE4_WHO_GROUP:
317                                 gace->aceWho = ACE4_SPECIAL_GROUP;
318                                 break;
319                         default:
320                                 DEBUG(8, ("unsupported special_id %d\n", aceprop->who.special_id));
321                                 continue; /* don't add it !!! */
322                         }
323                 } else {
324                         /* just only for the type safety... */
325                         if (aceprop->aceFlags&SMB_ACE4_IDENTIFIER_GROUP)
326                                 gace->aceWho = aceprop->who.gid;
327                         else
328                                 gace->aceWho = aceprop->who.uid;
329                 }
330
331                 gacl->acl_nace++;
332         }
333
334         ret = smbd_gpfs_putacl(fsp->fsp_name, GPFS_PUTACL_STRUCT | GPFS_ACL_SAMBA, gacl);
335         if (ret != 0) {
336                 DEBUG(8, ("gpfs_putacl failed with %s\n", strerror(errno)));
337                 gpfs_dumpacl(8, gacl);
338                 return False;
339         }
340
341         DEBUG(10, ("gpfs_putacl succeeded\n"));
342         return True;
343 }
344
345 static NTSTATUS gpfsacl_set_nt_acl_internal(files_struct *fsp, uint32 security_info_sent, SEC_DESC *psd)
346 {
347         struct gpfs_acl *acl;
348         NTSTATUS result = NT_STATUS_ACCESS_DENIED;
349
350         acl = gpfs_getacl_alloc(fsp->fsp_name, GPFS_ACL_TYPE_ACCESS);
351         if (acl == NULL)
352                 return result;
353
354         if (acl->acl_version&GPFS_ACL_VERSION_NFS4)
355         {
356                 result = smb_set_nt_acl_nfs4(
357                         fsp, security_info_sent, psd,
358                         gpfsacl_process_smbacl);
359         } else { /* assume POSIX ACL - by default... */
360                 result = set_nt_acl(fsp, security_info_sent, psd);
361         }
362
363         return result;
364 }
365
366 static NTSTATUS gpfsacl_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp, uint32 security_info_sent, SEC_DESC *psd)
367 {
368         return gpfsacl_set_nt_acl_internal(fsp, security_info_sent, psd);
369 }
370
371 static NTSTATUS gpfsacl_set_nt_acl(vfs_handle_struct *handle, files_struct *fsp, char *name, uint32 security_info_sent, SEC_DESC *psd)
372 {
373         return gpfsacl_set_nt_acl_internal(fsp, security_info_sent, psd);
374 }
375
376 static SMB_ACL_T gpfs2smb_acl(const struct gpfs_acl *pacl)
377 {
378         SMB_ACL_T result;
379         int i;
380
381         result = sys_acl_init(pacl->acl_nace);
382         if (result == NULL) {
383                 errno = ENOMEM;
384                 return NULL;
385         }
386
387         result->count = pacl->acl_nace;
388
389         for (i=0; i<pacl->acl_nace; i++) {
390                 struct smb_acl_entry *ace = &result->acl[i];
391                 const struct gpfs_ace_v1 *g_ace = &pacl->ace_v1[i];
392
393                 DEBUG(10, ("Converting type %d id %lu perm %x\n",
394                            (int)g_ace->ace_type, (unsigned long)g_ace->ace_who,
395                            (int)g_ace->ace_perm));
396
397                 switch (g_ace->ace_type) {
398                 case GPFS_ACL_USER:
399                         ace->a_type = SMB_ACL_USER;
400                         ace->uid = (uid_t)g_ace->ace_who;
401                         break;
402                 case GPFS_ACL_USER_OBJ:
403                         ace->a_type = SMB_ACL_USER_OBJ;
404                         break;
405                 case GPFS_ACL_GROUP:
406                         ace->a_type = SMB_ACL_GROUP;
407                         ace->gid = (gid_t)g_ace->ace_who;
408                         break;
409                 case GPFS_ACL_GROUP_OBJ:
410                         ace->a_type = SMB_ACL_GROUP_OBJ;
411                         break;
412                 case GPFS_ACL_OTHER:
413                         ace->a_type = SMB_ACL_OTHER;
414                         break;
415                 case GPFS_ACL_MASK:
416                         ace->a_type = SMB_ACL_MASK;
417                         break;
418                 default:
419                         DEBUG(10, ("Got invalid ace_type: %d\n",
420                                    g_ace->ace_type));
421                         errno = EINVAL;
422                         SAFE_FREE(result);
423                         return NULL;
424                 }
425
426                 ace->a_perm = 0;
427                 ace->a_perm |= (g_ace->ace_perm & ACL_PERM_READ) ?
428                         SMB_ACL_READ : 0;
429                 ace->a_perm |= (g_ace->ace_perm & ACL_PERM_WRITE) ?
430                         SMB_ACL_WRITE : 0;
431                 ace->a_perm |= (g_ace->ace_perm & ACL_PERM_EXECUTE) ?
432                         SMB_ACL_EXECUTE : 0;
433
434                 DEBUGADD(10, ("Converted to %d perm %x\n",
435                               ace->a_type, ace->a_perm));
436         }
437
438         return result;
439 }
440
441 static SMB_ACL_T gpfsacl_get_posix_acl(const char *path, gpfs_aclType_t type)
442 {
443         struct gpfs_acl *pacl;
444         SMB_ACL_T result = NULL;
445
446         pacl = gpfs_getacl_alloc(path, type);
447
448         if (pacl == NULL) {
449                 DEBUG(10, ("gpfs_getacl failed for %s with %s\n",
450                            path, strerror(errno)));
451                 if (errno == 0) {
452                         errno = EINVAL;
453                 }
454                 goto done;
455         }
456
457         if (pacl->acl_version != GPFS_ACL_VERSION_POSIX) {
458                 DEBUG(10, ("Got acl version %d, expected %d\n",
459                            pacl->acl_version, GPFS_ACL_VERSION_POSIX));
460                 errno = EINVAL;
461                 goto done;
462         }
463         
464         DEBUG(10, ("len: %d, level: %d, version: %d, nace: %d\n",
465                    pacl->acl_len, pacl->acl_level, pacl->acl_version,
466                    pacl->acl_nace));
467
468         result = gpfs2smb_acl(pacl);
469         if (result == NULL) {
470                 goto done;
471         }
472
473  done:
474
475         if (errno != 0) {
476                 SAFE_FREE(result);
477         }
478         return result;  
479 }
480
481 SMB_ACL_T gpfsacl_sys_acl_get_file(vfs_handle_struct *handle,
482                                     
483                                     const char *path_p,
484                                     SMB_ACL_TYPE_T type)
485 {
486         gpfs_aclType_t gpfs_type;
487
488         switch(type) {
489         case SMB_ACL_TYPE_ACCESS:
490                 gpfs_type = GPFS_ACL_TYPE_ACCESS;
491                 break;
492         case SMB_ACL_TYPE_DEFAULT:
493                 gpfs_type = GPFS_ACL_TYPE_DEFAULT;
494                 break;
495         default:
496                 DEBUG(0, ("Got invalid type: %d\n", type));
497                 smb_panic("exiting");
498         }
499
500         return gpfsacl_get_posix_acl(path_p, gpfs_type);
501 }
502
503 SMB_ACL_T gpfsacl_sys_acl_get_fd(vfs_handle_struct *handle,
504                                   files_struct *fsp,
505                                   int fd)
506 {
507         return gpfsacl_get_posix_acl(fsp->fsp_name, GPFS_ACL_TYPE_ACCESS);
508 }
509
510 static struct gpfs_acl *smb2gpfs_acl(const SMB_ACL_T pacl,
511                                      SMB_ACL_TYPE_T type)
512 {
513         gpfs_aclLen_t len;
514         struct gpfs_acl *result;
515         int i;
516         union gpfs_ace_union
517         {
518                 gpfs_ace_v1_t  ace_v1[1]; /* when GPFS_ACL_VERSION_POSIX */
519                 gpfs_ace_v4_t  ace_v4[1]; /* when GPFS_ACL_VERSION_NFS4  */
520         };
521
522         DEBUG(10, ("smb2gpfs_acl: Got ACL with %d entries\n", pacl->count));
523
524         len = sizeof(struct gpfs_acl) - sizeof(union gpfs_ace_union) +
525                 (pacl->count)*sizeof(gpfs_ace_v1_t);
526
527         result = SMB_MALLOC(len);
528         if (result == NULL) {
529                 errno = ENOMEM;
530                 return result;
531         }
532
533         result->acl_len = len;
534         result->acl_level = 0;
535         result->acl_version = GPFS_ACL_VERSION_POSIX;
536         result->acl_type = (type == SMB_ACL_TYPE_DEFAULT) ?
537                 GPFS_ACL_TYPE_DEFAULT : GPFS_ACL_TYPE_ACCESS;
538         result->acl_nace = pacl->count;
539
540         for (i=0; i<pacl->count; i++) {
541                 const struct smb_acl_entry *ace = &pacl->acl[i];
542                 struct gpfs_ace_v1 *g_ace = &result->ace_v1[i];
543                 
544                 DEBUG(10, ("Converting type %d perm %x\n",
545                            (int)ace->a_type, (int)ace->a_perm));
546
547                 g_ace->ace_perm = 0;
548
549                 switch(ace->a_type) {
550                 case SMB_ACL_USER:
551                         g_ace->ace_type = GPFS_ACL_USER;
552                         g_ace->ace_who = (gpfs_uid_t)ace->uid;
553                         break;
554                 case SMB_ACL_USER_OBJ:
555                         g_ace->ace_type = GPFS_ACL_USER_OBJ;
556                         g_ace->ace_perm |= ACL_PERM_CONTROL;
557                         g_ace->ace_who = 0;
558                         break;
559                 case SMB_ACL_GROUP:
560                         g_ace->ace_type = GPFS_ACL_GROUP;
561                         g_ace->ace_who = (gpfs_uid_t)ace->gid;
562                         break;
563                 case SMB_ACL_GROUP_OBJ:
564                         g_ace->ace_type = GPFS_ACL_GROUP_OBJ;
565                         g_ace->ace_who = 0;
566                         break;
567                 case SMB_ACL_MASK:
568                         g_ace->ace_type = GPFS_ACL_MASK;
569                         g_ace->ace_perm = 0x8f;
570                         g_ace->ace_who = 0;
571                         break;
572                 case SMB_ACL_OTHER:
573                         g_ace->ace_type = GPFS_ACL_OTHER;
574                         g_ace->ace_who = 0;
575                         break;
576                 default:
577                         DEBUG(10, ("Got invalid ace_type: %d\n", ace->a_type));
578                         errno = EINVAL;
579                         SAFE_FREE(result);
580                         return NULL;
581                 }
582
583                 g_ace->ace_perm |= (ace->a_perm & SMB_ACL_READ) ?
584                         ACL_PERM_READ : 0;
585                 g_ace->ace_perm |= (ace->a_perm & SMB_ACL_WRITE) ?
586                         ACL_PERM_WRITE : 0;
587                 g_ace->ace_perm |= (ace->a_perm & SMB_ACL_EXECUTE) ?
588                         ACL_PERM_EXECUTE : 0;
589
590                 DEBUGADD(10, ("Converted to %d id %d perm %x\n",
591                               g_ace->ace_type, g_ace->ace_who, g_ace->ace_perm));
592         }
593
594         return result;
595 }
596
597 int gpfsacl_sys_acl_set_file(vfs_handle_struct *handle,
598                               
599                               const char *name,
600                               SMB_ACL_TYPE_T type,
601                               SMB_ACL_T theacl)
602 {
603         struct gpfs_acl *gpfs_acl;
604         int result;
605
606         gpfs_acl = smb2gpfs_acl(theacl, type);
607         if (gpfs_acl == NULL) {
608                 return -1;
609         }
610
611         result = smbd_gpfs_putacl((char *)name, GPFS_PUTACL_STRUCT | GPFS_ACL_SAMBA, gpfs_acl);
612
613         SAFE_FREE(gpfs_acl);
614         return result;
615 }
616
617 int gpfsacl_sys_acl_set_fd(vfs_handle_struct *handle,
618                             files_struct *fsp,
619                             int fd, SMB_ACL_T theacl)
620 {
621         return gpfsacl_sys_acl_set_file(handle, fsp->fsp_name, SMB_ACL_TYPE_ACCESS, theacl);
622 }
623
624 int gpfsacl_sys_acl_delete_def_file(vfs_handle_struct *handle,
625                                      
626                                      const char *path)
627 {
628         errno = ENOTSUP;
629         return -1;
630 }
631
632 static int vfs_gpfs_chmod(vfs_handle_struct *handle, const char *path, mode_t mode)
633 {
634                  SMB_STRUCT_STAT st;
635                  if (SMB_VFS_NEXT_STAT(handle, path, &st) != 0) {
636                                  return -1;
637                  }
638                  /* avoid chmod() if possible, to preserve acls */
639                  if ((st.st_mode & ~S_IFMT) == mode) {
640                                  return 0;
641                  }
642                  return SMB_VFS_NEXT_CHMOD(handle, path, mode);
643 }
644
645 static int vfs_gpfs_fchmod(vfs_handle_struct *handle, files_struct *fsp, int fd, mode_t mode)
646 {
647                  SMB_STRUCT_STAT st;
648                  if (SMB_VFS_NEXT_FSTAT(handle, fsp, &st) != 0) {
649                                  return -1;
650                  }
651                  /* avoid chmod() if possible, to preserve acls */
652                  if ((st.st_mode & ~S_IFMT) == mode) {
653                                  return 0;
654                  }
655                  return SMB_VFS_NEXT_FCHMOD(handle, fsp, fd, mode);
656 }
657
658 /* VFS operations structure */
659
660 static vfs_op_tuple gpfs_op_tuples[] = {
661
662                 { SMB_VFS_OP(vfs_gpfs_kernel_flock), SMB_VFS_OP_KERNEL_FLOCK,
663                                 SMB_VFS_LAYER_OPAQUE },
664
665         { SMB_VFS_OP(vfs_gpfs_setlease), SMB_VFS_OP_LINUX_SETLEASE,
666                         SMB_VFS_LAYER_OPAQUE },
667
668         { SMB_VFS_OP(gpfsacl_fget_nt_acl), SMB_VFS_OP_FGET_NT_ACL,
669                         SMB_VFS_LAYER_TRANSPARENT },
670
671         { SMB_VFS_OP(gpfsacl_get_nt_acl), SMB_VFS_OP_GET_NT_ACL,
672                         SMB_VFS_LAYER_TRANSPARENT },
673
674         { SMB_VFS_OP(gpfsacl_fset_nt_acl), SMB_VFS_OP_FSET_NT_ACL,
675                         SMB_VFS_LAYER_TRANSPARENT },
676
677         { SMB_VFS_OP(gpfsacl_set_nt_acl), SMB_VFS_OP_SET_NT_ACL,
678                         SMB_VFS_LAYER_TRANSPARENT },
679
680         { SMB_VFS_OP(gpfsacl_sys_acl_get_file), SMB_VFS_OP_SYS_ACL_GET_FILE,
681                         SMB_VFS_LAYER_TRANSPARENT },
682
683         { SMB_VFS_OP(gpfsacl_sys_acl_get_fd), SMB_VFS_OP_SYS_ACL_GET_FD,
684                         SMB_VFS_LAYER_TRANSPARENT },
685
686         { SMB_VFS_OP(gpfsacl_sys_acl_set_file), SMB_VFS_OP_SYS_ACL_SET_FILE,
687                         SMB_VFS_LAYER_TRANSPARENT },
688
689         { SMB_VFS_OP(gpfsacl_sys_acl_set_fd), SMB_VFS_OP_SYS_ACL_SET_FD,
690                         SMB_VFS_LAYER_TRANSPARENT },
691
692         { SMB_VFS_OP(gpfsacl_sys_acl_delete_def_file),
693                 SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE,
694                 SMB_VFS_LAYER_TRANSPARENT },
695
696         { SMB_VFS_OP(vfs_gpfs_chmod), SMB_VFS_OP_CHMOD,
697                 SMB_VFS_LAYER_TRANSPARENT },
698
699         { SMB_VFS_OP(vfs_gpfs_fchmod), SMB_VFS_OP_FCHMOD,
700                 SMB_VFS_LAYER_TRANSPARENT },
701
702         { SMB_VFS_OP(NULL), SMB_VFS_OP_NOOP, SMB_VFS_LAYER_NOOP }
703
704 };
705
706
707 NTSTATUS vfs_gpfs_init(void);
708 NTSTATUS vfs_gpfs_init(void)
709 {
710         init_gpfs();
711         
712         return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "gpfs",
713                                 gpfs_op_tuples);
714 }