r23784: use the GPLv3 boilerplate as recommended by the FSF and the license text
[tprouty/samba.git] / source / 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 = main_loop_talloc_get();
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 size_t gpfsacl_get_nt_acl_common(files_struct *fsp,
230         uint32 security_info, SEC_DESC **ppdesc)
231 {
232         SMB4ACL_T *pacl = NULL;
233         int     result;
234
235         *ppdesc = NULL;
236         result = gpfs_get_nfs4_acl(fsp->fsp_name, &pacl);
237
238         if (result == 0)
239                 return smb_get_nt_acl_nfs4(fsp, security_info, ppdesc, pacl);
240
241         if (result > 0) {
242                 DEBUG(10, ("retrying with posix acl...\n"));
243                 return get_nt_acl(fsp, security_info, ppdesc);
244         }
245         
246         /* GPFS ACL was not read, something wrong happened, error code is set in errno */
247         return 0;
248 }
249
250 size_t gpfsacl_fget_nt_acl(vfs_handle_struct *handle,
251         files_struct *fsp, int fd, uint32 security_info,
252         SEC_DESC **ppdesc)
253 {
254         return gpfsacl_get_nt_acl_common(fsp, security_info, ppdesc);
255 }
256
257 size_t gpfsacl_get_nt_acl(vfs_handle_struct *handle,
258         files_struct *fsp, const char *name,
259         uint32 security_info, SEC_DESC **ppdesc)
260 {
261         return gpfsacl_get_nt_acl_common(fsp, security_info, ppdesc);
262 }
263
264 static BOOL gpfsacl_process_smbacl(files_struct *fsp, SMB4ACL_T *smbacl)
265 {
266         int ret;
267         gpfs_aclLen_t gacl_len;
268         SMB4ACE_T       *smbace;
269         struct gpfs_acl *gacl;
270         TALLOC_CTX *mem_ctx  = main_loop_talloc_get();
271
272         gacl_len = sizeof(struct gpfs_acl) +
273                 (smb_get_naces(smbacl)-1)*sizeof(gpfs_ace_v4_t);
274
275         gacl = TALLOC_SIZE(mem_ctx, gacl_len);
276         if (gacl == NULL) {
277                 DEBUG(0, ("talloc failed\n"));
278                 errno = ENOMEM;
279                 return False;
280         }
281
282         gacl->acl_len = gacl_len;
283         gacl->acl_level = 0;
284         gacl->acl_version = GPFS_ACL_VERSION_NFS4;
285         gacl->acl_type = GPFS_ACL_TYPE_NFS4;
286         gacl->acl_nace = 0; /* change later... */
287
288         for (smbace=smb_first_ace4(smbacl); smbace!=NULL; smbace = smb_next_ace4(smbace)) {
289                 struct gpfs_ace_v4 *gace = &gacl->ace_v4[gacl->acl_nace];
290                 SMB_ACE4PROP_T  *aceprop = smb_get_ace4(smbace);
291
292                 gace->aceType = aceprop->aceType;
293                 gace->aceFlags = aceprop->aceFlags;
294                 gace->aceMask = aceprop->aceMask;
295                 gace->aceIFlags = (aceprop->flags&SMB_ACE4_ID_SPECIAL) ? ACE4_IFLAG_SPECIAL_ID : 0;
296
297                 if (aceprop->flags&SMB_ACE4_ID_SPECIAL)
298                 {
299                         switch(aceprop->who.special_id)
300                         {
301                         case SMB_ACE4_WHO_EVERYONE:
302                                 gace->aceWho = ACE4_SPECIAL_EVERYONE;
303                                 break;
304                         case SMB_ACE4_WHO_OWNER:
305                                 gace->aceWho = ACE4_SPECIAL_OWNER;
306                                 break;
307                         case SMB_ACE4_WHO_GROUP:
308                                 gace->aceWho = ACE4_SPECIAL_GROUP;
309                                 break;
310                         default:
311                                 DEBUG(8, ("unsupported special_id %d\n", aceprop->who.special_id));
312                                 continue; /* don't add it !!! */
313                         }
314                 } else {
315                         /* just only for the type safety... */
316                         if (aceprop->aceFlags&SMB_ACE4_IDENTIFIER_GROUP)
317                                 gace->aceWho = aceprop->who.gid;
318                         else
319                                 gace->aceWho = aceprop->who.uid;
320                 }
321
322                 gacl->acl_nace++;
323         }
324
325         ret = smbd_gpfs_putacl(fsp->fsp_name, GPFS_PUTACL_STRUCT | GPFS_ACL_SAMBA, gacl);
326         if (ret != 0) {
327                 DEBUG(8, ("gpfs_putacl failed with %s\n", strerror(errno)));
328                 gpfs_dumpacl(8, gacl);
329                 return False;
330         }
331
332         DEBUG(10, ("gpfs_putacl succeeded\n"));
333         return True;
334 }
335
336 static NTSTATUS gpfsacl_set_nt_acl_internal(files_struct *fsp, uint32 security_info_sent, SEC_DESC *psd)
337 {
338         struct gpfs_acl *acl;
339         NTSTATUS result = NT_STATUS_ACCESS_DENIED;
340
341         acl = gpfs_getacl_alloc(fsp->fsp_name, GPFS_ACL_TYPE_ACCESS);
342         if (acl == NULL)
343                 return result;
344
345         if (acl->acl_version&GPFS_ACL_VERSION_NFS4)
346         {
347                 result = smb_set_nt_acl_nfs4(
348                         fsp, security_info_sent, psd,
349                         gpfsacl_process_smbacl);
350         } else { /* assume POSIX ACL - by default... */
351                 result = set_nt_acl(fsp, security_info_sent, psd);
352         }
353
354         return result;
355 }
356
357 static NTSTATUS gpfsacl_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp, int fd, uint32 security_info_sent, SEC_DESC *psd)
358 {
359         return gpfsacl_set_nt_acl_internal(fsp, security_info_sent, psd);
360 }
361
362 static NTSTATUS gpfsacl_set_nt_acl(vfs_handle_struct *handle, files_struct *fsp, char *name, uint32 security_info_sent, SEC_DESC *psd)
363 {
364         return gpfsacl_set_nt_acl_internal(fsp, security_info_sent, psd);
365 }
366
367 static SMB_ACL_T gpfs2smb_acl(const struct gpfs_acl *pacl)
368 {
369         SMB_ACL_T result;
370         int i;
371
372         result = sys_acl_init(pacl->acl_nace);
373         if (result == NULL) {
374                 errno = ENOMEM;
375                 return NULL;
376         }
377
378         result->count = pacl->acl_nace;
379
380         for (i=0; i<pacl->acl_nace; i++) {
381                 struct smb_acl_entry *ace = &result->acl[i];
382                 const struct gpfs_ace_v1 *g_ace = &pacl->ace_v1[i];
383
384                 DEBUG(10, ("Converting type %d id %lu perm %x\n",
385                            (int)g_ace->ace_type, (unsigned long)g_ace->ace_who,
386                            (int)g_ace->ace_perm));
387
388                 switch (g_ace->ace_type) {
389                 case GPFS_ACL_USER:
390                         ace->a_type = SMB_ACL_USER;
391                         ace->uid = (uid_t)g_ace->ace_who;
392                         break;
393                 case GPFS_ACL_USER_OBJ:
394                         ace->a_type = SMB_ACL_USER_OBJ;
395                         break;
396                 case GPFS_ACL_GROUP:
397                         ace->a_type = SMB_ACL_GROUP;
398                         ace->gid = (gid_t)g_ace->ace_who;
399                         break;
400                 case GPFS_ACL_GROUP_OBJ:
401                         ace->a_type = SMB_ACL_GROUP_OBJ;
402                         break;
403                 case GPFS_ACL_OTHER:
404                         ace->a_type = SMB_ACL_OTHER;
405                         break;
406                 case GPFS_ACL_MASK:
407                         ace->a_type = SMB_ACL_MASK;
408                         break;
409                 default:
410                         DEBUG(10, ("Got invalid ace_type: %d\n",
411                                    g_ace->ace_type));
412                         errno = EINVAL;
413                         SAFE_FREE(result);
414                         return NULL;
415                 }
416
417                 ace->a_perm = 0;
418                 ace->a_perm |= (g_ace->ace_perm & ACL_PERM_READ) ?
419                         SMB_ACL_READ : 0;
420                 ace->a_perm |= (g_ace->ace_perm & ACL_PERM_WRITE) ?
421                         SMB_ACL_WRITE : 0;
422                 ace->a_perm |= (g_ace->ace_perm & ACL_PERM_EXECUTE) ?
423                         SMB_ACL_EXECUTE : 0;
424
425                 DEBUGADD(10, ("Converted to %d perm %x\n",
426                               ace->a_type, ace->a_perm));
427         }
428
429         return result;
430 }
431
432 static SMB_ACL_T gpfsacl_get_posix_acl(const char *path, gpfs_aclType_t type)
433 {
434         struct gpfs_acl *pacl;
435         SMB_ACL_T result = NULL;
436
437         pacl = gpfs_getacl_alloc(path, type);
438
439         if (pacl == NULL) {
440                 DEBUG(10, ("gpfs_getacl failed for %s with %s\n",
441                            path, strerror(errno)));
442                 if (errno == 0) {
443                         errno = EINVAL;
444                 }
445                 goto done;
446         }
447
448         if (pacl->acl_version != GPFS_ACL_VERSION_POSIX) {
449                 DEBUG(10, ("Got acl version %d, expected %d\n",
450                            pacl->acl_version, GPFS_ACL_VERSION_POSIX));
451                 errno = EINVAL;
452                 goto done;
453         }
454         
455         DEBUG(10, ("len: %d, level: %d, version: %d, nace: %d\n",
456                    pacl->acl_len, pacl->acl_level, pacl->acl_version,
457                    pacl->acl_nace));
458
459         result = gpfs2smb_acl(pacl);
460         if (result == NULL) {
461                 goto done;
462         }
463
464  done:
465
466         if (errno != 0) {
467                 SAFE_FREE(result);
468         }
469         return result;  
470 }
471
472 SMB_ACL_T gpfsacl_sys_acl_get_file(vfs_handle_struct *handle,
473                                     
474                                     const char *path_p,
475                                     SMB_ACL_TYPE_T type)
476 {
477         gpfs_aclType_t gpfs_type;
478
479         switch(type) {
480         case SMB_ACL_TYPE_ACCESS:
481                 gpfs_type = GPFS_ACL_TYPE_ACCESS;
482                 break;
483         case SMB_ACL_TYPE_DEFAULT:
484                 gpfs_type = GPFS_ACL_TYPE_DEFAULT;
485                 break;
486         default:
487                 DEBUG(0, ("Got invalid type: %d\n", type));
488                 smb_panic("exiting");
489         }
490
491         return gpfsacl_get_posix_acl(path_p, gpfs_type);
492 }
493
494 SMB_ACL_T gpfsacl_sys_acl_get_fd(vfs_handle_struct *handle,
495                                   files_struct *fsp,
496                                   int fd)
497 {
498         return gpfsacl_get_posix_acl(fsp->fsp_name, GPFS_ACL_TYPE_ACCESS);
499 }
500
501 static struct gpfs_acl *smb2gpfs_acl(const SMB_ACL_T pacl,
502                                      SMB_ACL_TYPE_T type)
503 {
504         gpfs_aclLen_t len;
505         struct gpfs_acl *result;
506         int i;
507         union gpfs_ace_union
508         {
509                 gpfs_ace_v1_t  ace_v1[1]; /* when GPFS_ACL_VERSION_POSIX */
510                 gpfs_ace_v4_t  ace_v4[1]; /* when GPFS_ACL_VERSION_NFS4  */
511         };
512
513         DEBUG(10, ("smb2gpfs_acl: Got ACL with %d entries\n", pacl->count));
514
515         len = sizeof(struct gpfs_acl) - sizeof(union gpfs_ace_union) +
516                 (pacl->count)*sizeof(gpfs_ace_v1_t);
517
518         result = SMB_MALLOC(len);
519         if (result == NULL) {
520                 errno = ENOMEM;
521                 return result;
522         }
523
524         result->acl_len = len;
525         result->acl_level = 0;
526         result->acl_version = GPFS_ACL_VERSION_POSIX;
527         result->acl_type = (type == SMB_ACL_TYPE_DEFAULT) ?
528                 GPFS_ACL_TYPE_DEFAULT : GPFS_ACL_TYPE_ACCESS;
529         result->acl_nace = pacl->count;
530
531         for (i=0; i<pacl->count; i++) {
532                 const struct smb_acl_entry *ace = &pacl->acl[i];
533                 struct gpfs_ace_v1 *g_ace = &result->ace_v1[i];
534                 
535                 DEBUG(10, ("Converting type %d perm %x\n",
536                            (int)ace->a_type, (int)ace->a_perm));
537
538                 g_ace->ace_perm = 0;
539
540                 switch(ace->a_type) {
541                 case SMB_ACL_USER:
542                         g_ace->ace_type = GPFS_ACL_USER;
543                         g_ace->ace_who = (gpfs_uid_t)ace->uid;
544                         break;
545                 case SMB_ACL_USER_OBJ:
546                         g_ace->ace_type = GPFS_ACL_USER_OBJ;
547                         g_ace->ace_perm |= ACL_PERM_CONTROL;
548                         g_ace->ace_who = 0;
549                         break;
550                 case SMB_ACL_GROUP:
551                         g_ace->ace_type = GPFS_ACL_GROUP;
552                         g_ace->ace_who = (gpfs_uid_t)ace->gid;
553                         break;
554                 case SMB_ACL_GROUP_OBJ:
555                         g_ace->ace_type = GPFS_ACL_GROUP_OBJ;
556                         g_ace->ace_who = 0;
557                         break;
558                 case SMB_ACL_MASK:
559                         g_ace->ace_type = GPFS_ACL_MASK;
560                         g_ace->ace_perm = 0x8f;
561                         g_ace->ace_who = 0;
562                         break;
563                 case SMB_ACL_OTHER:
564                         g_ace->ace_type = GPFS_ACL_OTHER;
565                         g_ace->ace_who = 0;
566                         break;
567                 default:
568                         DEBUG(10, ("Got invalid ace_type: %d\n", ace->a_type));
569                         errno = EINVAL;
570                         SAFE_FREE(result);
571                         return NULL;
572                 }
573
574                 g_ace->ace_perm |= (ace->a_perm & SMB_ACL_READ) ?
575                         ACL_PERM_READ : 0;
576                 g_ace->ace_perm |= (ace->a_perm & SMB_ACL_WRITE) ?
577                         ACL_PERM_WRITE : 0;
578                 g_ace->ace_perm |= (ace->a_perm & SMB_ACL_EXECUTE) ?
579                         ACL_PERM_EXECUTE : 0;
580
581                 DEBUGADD(10, ("Converted to %d id %d perm %x\n",
582                               g_ace->ace_type, g_ace->ace_who, g_ace->ace_perm));
583         }
584
585         return result;
586 }
587
588 int gpfsacl_sys_acl_set_file(vfs_handle_struct *handle,
589                               
590                               const char *name,
591                               SMB_ACL_TYPE_T type,
592                               SMB_ACL_T theacl)
593 {
594         struct gpfs_acl *gpfs_acl;
595         int result;
596
597         gpfs_acl = smb2gpfs_acl(theacl, type);
598         if (gpfs_acl == NULL) {
599                 return -1;
600         }
601
602         result = smbd_gpfs_putacl((char *)name, GPFS_PUTACL_STRUCT | GPFS_ACL_SAMBA, gpfs_acl);
603
604         SAFE_FREE(gpfs_acl);
605         return result;
606 }
607
608 int gpfsacl_sys_acl_set_fd(vfs_handle_struct *handle,
609                             files_struct *fsp,
610                             int fd, SMB_ACL_T theacl)
611 {
612         return gpfsacl_sys_acl_set_file(handle, fsp->fsp_name, SMB_ACL_TYPE_ACCESS, theacl);
613 }
614
615 int gpfsacl_sys_acl_delete_def_file(vfs_handle_struct *handle,
616                                      
617                                      const char *path)
618 {
619         errno = ENOTSUP;
620         return -1;
621 }
622
623 static int vfs_gpfs_chmod(vfs_handle_struct *handle, const char *path, mode_t mode)
624 {
625                  SMB_STRUCT_STAT st;
626                  if (SMB_VFS_NEXT_STAT(handle, path, &st) != 0) {
627                                  return -1;
628                  }
629                  /* avoid chmod() if possible, to preserve acls */
630                  if ((st.st_mode & ~S_IFMT) == mode) {
631                                  return 0;
632                  }
633                  return SMB_VFS_NEXT_CHMOD(handle, path, mode);
634 }
635
636 static int vfs_gpfs_fchmod(vfs_handle_struct *handle, files_struct *fsp, int fd, mode_t mode)
637 {
638                  SMB_STRUCT_STAT st;
639                  if (SMB_VFS_NEXT_FSTAT(handle, fsp, fd, &st) != 0) {
640                                  return -1;
641                  }
642                  /* avoid chmod() if possible, to preserve acls */
643                  if ((st.st_mode & ~S_IFMT) == mode) {
644                                  return 0;
645                  }
646                  return SMB_VFS_NEXT_FCHMOD(handle, fsp, fd, mode);
647 }
648
649 /* VFS operations structure */
650
651 static vfs_op_tuple gpfs_op_tuples[] = {
652
653                 { SMB_VFS_OP(vfs_gpfs_kernel_flock), SMB_VFS_OP_KERNEL_FLOCK,
654                                 SMB_VFS_LAYER_OPAQUE },
655
656         { SMB_VFS_OP(vfs_gpfs_setlease), SMB_VFS_OP_LINUX_SETLEASE,
657                         SMB_VFS_LAYER_OPAQUE },
658
659         { SMB_VFS_OP(gpfsacl_fget_nt_acl), SMB_VFS_OP_FGET_NT_ACL,
660                         SMB_VFS_LAYER_TRANSPARENT },
661
662         { SMB_VFS_OP(gpfsacl_get_nt_acl), SMB_VFS_OP_GET_NT_ACL,
663                         SMB_VFS_LAYER_TRANSPARENT },
664
665         { SMB_VFS_OP(gpfsacl_fset_nt_acl), SMB_VFS_OP_FSET_NT_ACL,
666                         SMB_VFS_LAYER_TRANSPARENT },
667
668         { SMB_VFS_OP(gpfsacl_set_nt_acl), SMB_VFS_OP_SET_NT_ACL,
669                         SMB_VFS_LAYER_TRANSPARENT },
670
671         { SMB_VFS_OP(gpfsacl_sys_acl_get_file), SMB_VFS_OP_SYS_ACL_GET_FILE,
672                         SMB_VFS_LAYER_TRANSPARENT },
673
674         { SMB_VFS_OP(gpfsacl_sys_acl_get_fd), SMB_VFS_OP_SYS_ACL_GET_FD,
675                         SMB_VFS_LAYER_TRANSPARENT },
676
677         { SMB_VFS_OP(gpfsacl_sys_acl_set_file), SMB_VFS_OP_SYS_ACL_SET_FILE,
678                         SMB_VFS_LAYER_TRANSPARENT },
679
680         { SMB_VFS_OP(gpfsacl_sys_acl_set_fd), SMB_VFS_OP_SYS_ACL_SET_FD,
681                         SMB_VFS_LAYER_TRANSPARENT },
682
683         { SMB_VFS_OP(gpfsacl_sys_acl_delete_def_file),
684                 SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE,
685                 SMB_VFS_LAYER_TRANSPARENT },
686
687         { SMB_VFS_OP(vfs_gpfs_chmod), SMB_VFS_OP_CHMOD,
688                 SMB_VFS_LAYER_TRANSPARENT },
689
690         { SMB_VFS_OP(vfs_gpfs_fchmod), SMB_VFS_OP_FCHMOD,
691                 SMB_VFS_LAYER_TRANSPARENT },
692
693         { SMB_VFS_OP(NULL), SMB_VFS_OP_NOOP, SMB_VFS_LAYER_NOOP }
694
695 };
696
697
698 NTSTATUS vfs_gpfs_init(void);
699 NTSTATUS vfs_gpfs_init(void)
700 {
701         init_gpfs();
702         
703         return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "gpfs",
704                                 gpfs_op_tuples);
705 }