| 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 | #include "includes.h"
 | 
|---|
| 25 | #include "smbd/smbd.h"
 | 
|---|
| 26 | #include "librpc/gen_ndr/ndr_xattr.h"
 | 
|---|
| 27 | #include "include/smbprofile.h"
 | 
|---|
| 28 | 
 | 
|---|
| 29 | #undef DBGC_CLASS
 | 
|---|
| 30 | #define DBGC_CLASS DBGC_VFS
 | 
|---|
| 31 | 
 | 
|---|
| 32 | #include <gpfs_gpl.h>
 | 
|---|
| 33 | #include "nfs4_acls.h"
 | 
|---|
| 34 | #include "vfs_gpfs.h"
 | 
|---|
| 35 | #include "system/filesys.h"
 | 
|---|
| 36 | 
 | 
|---|
| 37 | struct gpfs_config_data {
 | 
|---|
| 38 |         bool sharemodes;
 | 
|---|
| 39 |         bool leases;
 | 
|---|
| 40 |         bool hsm;
 | 
|---|
| 41 | };
 | 
|---|
| 42 | 
 | 
|---|
| 43 | 
 | 
|---|
| 44 | static int vfs_gpfs_kernel_flock(vfs_handle_struct *handle, files_struct *fsp, 
 | 
|---|
| 45 |                                  uint32 share_mode, uint32 access_mask)
 | 
|---|
| 46 | {
 | 
|---|
| 47 | 
 | 
|---|
| 48 |         struct gpfs_config_data *config;
 | 
|---|
| 49 | 
 | 
|---|
| 50 |         SMB_VFS_HANDLE_GET_DATA(handle, config,
 | 
|---|
| 51 |                                 struct gpfs_config_data,
 | 
|---|
| 52 |                                 return -1);
 | 
|---|
| 53 | 
 | 
|---|
| 54 |         START_PROFILE(syscall_kernel_flock);
 | 
|---|
| 55 | 
 | 
|---|
| 56 |         kernel_flock(fsp->fh->fd, share_mode, access_mask);
 | 
|---|
| 57 | 
 | 
|---|
| 58 |         if (config->sharemodes
 | 
|---|
| 59 |                 && !set_gpfs_sharemode(fsp, access_mask, fsp->share_access)) {
 | 
|---|
| 60 |                 return -1;
 | 
|---|
| 61 |         }
 | 
|---|
| 62 | 
 | 
|---|
| 63 |         END_PROFILE(syscall_kernel_flock);
 | 
|---|
| 64 | 
 | 
|---|
| 65 |         return 0;
 | 
|---|
| 66 | }
 | 
|---|
| 67 | 
 | 
|---|
| 68 | static int vfs_gpfs_close(vfs_handle_struct *handle, files_struct *fsp)
 | 
|---|
| 69 | {
 | 
|---|
| 70 | 
 | 
|---|
| 71 |         struct gpfs_config_data *config;
 | 
|---|
| 72 | 
 | 
|---|
| 73 |         SMB_VFS_HANDLE_GET_DATA(handle, config,
 | 
|---|
| 74 |                                 struct gpfs_config_data,
 | 
|---|
| 75 |                                 return -1);
 | 
|---|
| 76 | 
 | 
|---|
| 77 |         if (config->sharemodes && (fsp->fh != NULL) && (fsp->fh->fd != -1)) {
 | 
|---|
| 78 |                 set_gpfs_sharemode(fsp, 0, 0);
 | 
|---|
| 79 |         }
 | 
|---|
| 80 | 
 | 
|---|
| 81 |         return SMB_VFS_NEXT_CLOSE(handle, fsp);
 | 
|---|
| 82 | }
 | 
|---|
| 83 | 
 | 
|---|
| 84 | static int vfs_gpfs_setlease(vfs_handle_struct *handle, files_struct *fsp, 
 | 
|---|
| 85 |                              int leasetype)
 | 
|---|
| 86 | {
 | 
|---|
| 87 |         struct gpfs_config_data *config;
 | 
|---|
| 88 |         int ret=0;
 | 
|---|
| 89 | 
 | 
|---|
| 90 |         SMB_VFS_HANDLE_GET_DATA(handle, config,
 | 
|---|
| 91 |                                 struct gpfs_config_data,
 | 
|---|
| 92 |                                 return -1);
 | 
|---|
| 93 | 
 | 
|---|
| 94 |         START_PROFILE(syscall_linux_setlease);
 | 
|---|
| 95 | 
 | 
|---|
| 96 |         if (linux_set_lease_sighandler(fsp->fh->fd) == -1)
 | 
|---|
| 97 |                 return -1;
 | 
|---|
| 98 | 
 | 
|---|
| 99 |         if (config->leases) {
 | 
|---|
| 100 |                 /*
 | 
|---|
| 101 |                  * Ensure the lease owner is root to allow
 | 
|---|
| 102 |                  * correct delivery of lease-break signals.
 | 
|---|
| 103 |                  */
 | 
|---|
| 104 |                 become_root();
 | 
|---|
| 105 |                 ret = set_gpfs_lease(fsp->fh->fd,leasetype);
 | 
|---|
| 106 |                 unbecome_root();
 | 
|---|
| 107 |         }
 | 
|---|
| 108 | 
 | 
|---|
| 109 |         if (ret < 0) {
 | 
|---|
| 110 |                 /* This must have come from GPFS not being available */
 | 
|---|
| 111 |                 /* or some other error, hence call the default */
 | 
|---|
| 112 |                 ret = linux_setlease(fsp->fh->fd, leasetype);
 | 
|---|
| 113 |         }
 | 
|---|
| 114 | 
 | 
|---|
| 115 |         END_PROFILE(syscall_linux_setlease);
 | 
|---|
| 116 | 
 | 
|---|
| 117 |         return ret;
 | 
|---|
| 118 | }
 | 
|---|
| 119 | 
 | 
|---|
| 120 | static int vfs_gpfs_get_real_filename(struct vfs_handle_struct *handle,
 | 
|---|
| 121 |                                       const char *path,
 | 
|---|
| 122 |                                       const char *name,
 | 
|---|
| 123 |                                       TALLOC_CTX *mem_ctx,
 | 
|---|
| 124 |                                       char **found_name)
 | 
|---|
| 125 | {
 | 
|---|
| 126 |         int result;
 | 
|---|
| 127 |         char *full_path;
 | 
|---|
| 128 |         char real_pathname[PATH_MAX+1];
 | 
|---|
| 129 |         int buflen;
 | 
|---|
| 130 |         bool mangled;
 | 
|---|
| 131 | 
 | 
|---|
| 132 |         mangled = mangle_is_mangled(name, handle->conn->params);
 | 
|---|
| 133 |         if (mangled) {
 | 
|---|
| 134 |                 return SMB_VFS_NEXT_GET_REAL_FILENAME(handle, path, name,
 | 
|---|
| 135 |                                                       mem_ctx, found_name);
 | 
|---|
| 136 |         }
 | 
|---|
| 137 | 
 | 
|---|
| 138 |         full_path = talloc_asprintf(talloc_tos(), "%s/%s", path, name);
 | 
|---|
| 139 |         if (full_path == NULL) {
 | 
|---|
| 140 |                 errno = ENOMEM;
 | 
|---|
| 141 |                 return -1;
 | 
|---|
| 142 |         }
 | 
|---|
| 143 | 
 | 
|---|
| 144 |         buflen = sizeof(real_pathname) - 1;
 | 
|---|
| 145 | 
 | 
|---|
| 146 |         result = smbd_gpfs_get_realfilename_path(full_path, real_pathname,
 | 
|---|
| 147 |                                                  &buflen);
 | 
|---|
| 148 | 
 | 
|---|
| 149 |         TALLOC_FREE(full_path);
 | 
|---|
| 150 | 
 | 
|---|
| 151 |         if ((result == -1) && (errno == ENOSYS)) {
 | 
|---|
| 152 |                 return SMB_VFS_NEXT_GET_REAL_FILENAME(
 | 
|---|
| 153 |                         handle, path, name, mem_ctx, found_name);
 | 
|---|
| 154 |         }
 | 
|---|
| 155 | 
 | 
|---|
| 156 |         if (result == -1) {
 | 
|---|
| 157 |                 DEBUG(10, ("smbd_gpfs_get_realfilename_path returned %s\n",
 | 
|---|
| 158 |                            strerror(errno)));
 | 
|---|
| 159 |                 return -1;
 | 
|---|
| 160 |         }
 | 
|---|
| 161 | 
 | 
|---|
| 162 |         /*
 | 
|---|
| 163 |          * GPFS does not necessarily null-terminate the returned path
 | 
|---|
| 164 |          * but instead returns the buffer length in buflen.
 | 
|---|
| 165 |          */
 | 
|---|
| 166 | 
 | 
|---|
| 167 |         if (buflen < sizeof(real_pathname)) {
 | 
|---|
| 168 |                 real_pathname[buflen] = '\0';
 | 
|---|
| 169 |         } else {
 | 
|---|
| 170 |                 real_pathname[sizeof(real_pathname)-1] = '\0';
 | 
|---|
| 171 |         }
 | 
|---|
| 172 | 
 | 
|---|
| 173 |         DEBUG(10, ("smbd_gpfs_get_realfilename_path: %s/%s -> %s\n",
 | 
|---|
| 174 |                    path, name, real_pathname));
 | 
|---|
| 175 | 
 | 
|---|
| 176 |         name = strrchr_m(real_pathname, '/');
 | 
|---|
| 177 |         if (name == NULL) {
 | 
|---|
| 178 |                 errno = ENOENT;
 | 
|---|
| 179 |                 return -1;
 | 
|---|
| 180 |         }
 | 
|---|
| 181 | 
 | 
|---|
| 182 |         *found_name = talloc_strdup(mem_ctx, name+1);
 | 
|---|
| 183 |         if (*found_name == NULL) {
 | 
|---|
| 184 |                 errno = ENOMEM;
 | 
|---|
| 185 |                 return -1;
 | 
|---|
| 186 |         }
 | 
|---|
| 187 | 
 | 
|---|
| 188 |         return 0;
 | 
|---|
| 189 | }
 | 
|---|
| 190 | 
 | 
|---|
| 191 | static void gpfs_dumpacl(int level, struct gpfs_acl *gacl)
 | 
|---|
| 192 | {
 | 
|---|
| 193 |         int     i;
 | 
|---|
| 194 |         if (gacl==NULL)
 | 
|---|
| 195 |         {
 | 
|---|
| 196 |                 DEBUG(0, ("gpfs acl is NULL\n"));
 | 
|---|
| 197 |                 return;
 | 
|---|
| 198 |         }
 | 
|---|
| 199 | 
 | 
|---|
| 200 |         DEBUG(level, ("gpfs acl: nace: %d, type:%d, version:%d, level:%d, len:%d\n",
 | 
|---|
| 201 |                 gacl->acl_nace, gacl->acl_type, gacl->acl_version, gacl->acl_level, gacl->acl_len));
 | 
|---|
| 202 |         for(i=0; i<gacl->acl_nace; i++)
 | 
|---|
| 203 |         {
 | 
|---|
| 204 |                 struct gpfs_ace_v4 *gace = gacl->ace_v4 + i;
 | 
|---|
| 205 |                 DEBUG(level, ("\tace[%d]: type:%d, flags:0x%x, mask:0x%x, iflags:0x%x, who:%u\n",
 | 
|---|
| 206 |                         i, gace->aceType, gace->aceFlags, gace->aceMask,
 | 
|---|
| 207 |                         gace->aceIFlags, gace->aceWho));
 | 
|---|
| 208 |         }
 | 
|---|
| 209 | }
 | 
|---|
| 210 | 
 | 
|---|
| 211 | static struct gpfs_acl *gpfs_getacl_alloc(const char *fname, gpfs_aclType_t type)
 | 
|---|
| 212 | {
 | 
|---|
| 213 |         struct gpfs_acl *acl;
 | 
|---|
| 214 |         size_t len = 200;
 | 
|---|
| 215 |         int ret;
 | 
|---|
| 216 |         TALLOC_CTX *mem_ctx = talloc_tos();
 | 
|---|
| 217 | 
 | 
|---|
| 218 |         acl = (struct gpfs_acl *)TALLOC_SIZE(mem_ctx, len);
 | 
|---|
| 219 |         if (acl == NULL) {
 | 
|---|
| 220 |                 errno = ENOMEM;
 | 
|---|
| 221 |                 return NULL;
 | 
|---|
| 222 |         }
 | 
|---|
| 223 | 
 | 
|---|
| 224 |         acl->acl_len = len;
 | 
|---|
| 225 |         acl->acl_level = 0;
 | 
|---|
| 226 |         acl->acl_version = 0;
 | 
|---|
| 227 |         acl->acl_type = type;
 | 
|---|
| 228 | 
 | 
|---|
| 229 |         ret = smbd_gpfs_getacl((char *)fname, GPFS_GETACL_STRUCT | GPFS_ACL_SAMBA, acl);
 | 
|---|
| 230 |         if ((ret != 0) && (errno == ENOSPC)) {
 | 
|---|
| 231 |                 struct gpfs_acl *new_acl = (struct gpfs_acl *)TALLOC_SIZE(
 | 
|---|
| 232 |                         mem_ctx, acl->acl_len + sizeof(struct gpfs_acl));
 | 
|---|
| 233 |                 if (new_acl == NULL) {
 | 
|---|
| 234 |                         errno = ENOMEM;
 | 
|---|
| 235 |                         return NULL;
 | 
|---|
| 236 |                 }
 | 
|---|
| 237 | 
 | 
|---|
| 238 |                 new_acl->acl_len = acl->acl_len;
 | 
|---|
| 239 |                 new_acl->acl_level = acl->acl_level;
 | 
|---|
| 240 |                 new_acl->acl_version = acl->acl_version;
 | 
|---|
| 241 |                 new_acl->acl_type = acl->acl_type;
 | 
|---|
| 242 |                 acl = new_acl;
 | 
|---|
| 243 | 
 | 
|---|
| 244 |                 ret = smbd_gpfs_getacl((char *)fname, GPFS_GETACL_STRUCT | GPFS_ACL_SAMBA, acl);
 | 
|---|
| 245 |         }
 | 
|---|
| 246 |         if (ret != 0)
 | 
|---|
| 247 |         {
 | 
|---|
| 248 |                 DEBUG(8, ("smbd_gpfs_getacl failed with %s\n",strerror(errno)));
 | 
|---|
| 249 |                 return NULL;
 | 
|---|
| 250 |         }
 | 
|---|
| 251 | 
 | 
|---|
| 252 |         return acl;
 | 
|---|
| 253 | }
 | 
|---|
| 254 | 
 | 
|---|
| 255 | /* Tries to get nfs4 acls and returns SMB ACL allocated.
 | 
|---|
| 256 |  * On failure returns 1 if it got non-NFSv4 ACL to prompt 
 | 
|---|
| 257 |  * retry with POSIX ACL checks.
 | 
|---|
| 258 |  * On failure returns -1 if there is system (GPFS) error, check errno.
 | 
|---|
| 259 |  * Returns 0 on success
 | 
|---|
| 260 |  */
 | 
|---|
| 261 | static int gpfs_get_nfs4_acl(const char *fname, SMB4ACL_T **ppacl)
 | 
|---|
| 262 | {
 | 
|---|
| 263 |         int i;
 | 
|---|
| 264 |         struct gpfs_acl *gacl = NULL;
 | 
|---|
| 265 |         DEBUG(10, ("gpfs_get_nfs4_acl invoked for %s\n", fname));
 | 
|---|
| 266 | 
 | 
|---|
| 267 |         /* First get the real acl length */
 | 
|---|
| 268 |         gacl = gpfs_getacl_alloc(fname, 0);
 | 
|---|
| 269 |         if (gacl == NULL) {
 | 
|---|
| 270 |                 DEBUG(9, ("gpfs_getacl failed for %s with %s\n",
 | 
|---|
| 271 |                            fname, strerror(errno)));
 | 
|---|
| 272 |                 return -1;
 | 
|---|
| 273 |         }
 | 
|---|
| 274 | 
 | 
|---|
| 275 |         if (gacl->acl_type != GPFS_ACL_TYPE_NFS4) {
 | 
|---|
| 276 |                 DEBUG(10, ("Got non-nfsv4 acl\n"));
 | 
|---|
| 277 |                 /* Retry with POSIX ACLs check */
 | 
|---|
| 278 |                 return 1;
 | 
|---|
| 279 |         }
 | 
|---|
| 280 | 
 | 
|---|
| 281 |         *ppacl = smb_create_smb4acl();
 | 
|---|
| 282 | 
 | 
|---|
| 283 |         DEBUG(10, ("len: %d, level: %d, version: %d, nace: %d\n",
 | 
|---|
| 284 |                    gacl->acl_len, gacl->acl_level, gacl->acl_version,
 | 
|---|
| 285 |                    gacl->acl_nace));
 | 
|---|
| 286 | 
 | 
|---|
| 287 |         for (i=0; i<gacl->acl_nace; i++) {
 | 
|---|
| 288 |                 struct gpfs_ace_v4 *gace = &gacl->ace_v4[i];
 | 
|---|
| 289 |                 SMB_ACE4PROP_T smbace;
 | 
|---|
| 290 |                 DEBUG(10, ("type: %d, iflags: %x, flags: %x, mask: %x, "
 | 
|---|
| 291 |                            "who: %d\n", gace->aceType, gace->aceIFlags,
 | 
|---|
| 292 |                            gace->aceFlags, gace->aceMask, gace->aceWho));
 | 
|---|
| 293 | 
 | 
|---|
| 294 |                 ZERO_STRUCT(smbace);
 | 
|---|
| 295 |                 if (gace->aceIFlags & ACE4_IFLAG_SPECIAL_ID) {
 | 
|---|
| 296 |                         smbace.flags |= SMB_ACE4_ID_SPECIAL;
 | 
|---|
| 297 |                         switch (gace->aceWho) {
 | 
|---|
| 298 |                         case ACE4_SPECIAL_OWNER:
 | 
|---|
| 299 |                                 smbace.who.special_id = SMB_ACE4_WHO_OWNER;
 | 
|---|
| 300 |                                 break;
 | 
|---|
| 301 |                         case ACE4_SPECIAL_GROUP:
 | 
|---|
| 302 |                                 smbace.who.special_id = SMB_ACE4_WHO_GROUP;
 | 
|---|
| 303 |                                 break;
 | 
|---|
| 304 |                         case ACE4_SPECIAL_EVERYONE:
 | 
|---|
| 305 |                                 smbace.who.special_id = SMB_ACE4_WHO_EVERYONE;
 | 
|---|
| 306 |                                 break;
 | 
|---|
| 307 |                         default:
 | 
|---|
| 308 |                                 DEBUG(8, ("invalid special gpfs id %d "
 | 
|---|
| 309 |                                           "ignored\n", gace->aceWho));
 | 
|---|
| 310 |                                 continue; /* don't add it */
 | 
|---|
| 311 |                         }
 | 
|---|
| 312 |                 } else {
 | 
|---|
| 313 |                         if (gace->aceFlags & ACE4_FLAG_GROUP_ID)
 | 
|---|
| 314 |                                 smbace.who.gid = gace->aceWho;
 | 
|---|
| 315 |                         else
 | 
|---|
| 316 |                                 smbace.who.uid = gace->aceWho;
 | 
|---|
| 317 |                 }
 | 
|---|
| 318 | 
 | 
|---|
| 319 |                 /* remove redundent deny entries */
 | 
|---|
| 320 |                 if (i > 0 && gace->aceType == SMB_ACE4_ACCESS_DENIED_ACE_TYPE) {
 | 
|---|
| 321 |                         struct gpfs_ace_v4 *prev = &gacl->ace_v4[i-1];
 | 
|---|
| 322 |                         if (prev->aceType == SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE &&
 | 
|---|
| 323 |                             prev->aceFlags == gace->aceFlags &&
 | 
|---|
| 324 |                             prev->aceIFlags == gace->aceIFlags &&
 | 
|---|
| 325 |                             (gace->aceMask & prev->aceMask) == 0 &&
 | 
|---|
| 326 |                             gace->aceWho == prev->aceWho) {
 | 
|---|
| 327 |                                 /* its redundent - skip it */
 | 
|---|
| 328 |                                 continue;
 | 
|---|
| 329 |                         }                                                
 | 
|---|
| 330 |                 }
 | 
|---|
| 331 | 
 | 
|---|
| 332 |                 smbace.aceType = gace->aceType;
 | 
|---|
| 333 |                 smbace.aceFlags = gace->aceFlags;
 | 
|---|
| 334 |                 smbace.aceMask = gace->aceMask;
 | 
|---|
| 335 |                 smb_add_ace4(*ppacl, &smbace);
 | 
|---|
| 336 |         }
 | 
|---|
| 337 | 
 | 
|---|
| 338 |         return 0;
 | 
|---|
| 339 | }
 | 
|---|
| 340 | 
 | 
|---|
| 341 | static NTSTATUS gpfsacl_fget_nt_acl(vfs_handle_struct *handle,
 | 
|---|
| 342 |         files_struct *fsp, uint32 security_info,
 | 
|---|
| 343 |         struct security_descriptor **ppdesc)
 | 
|---|
| 344 | {
 | 
|---|
| 345 |         SMB4ACL_T *pacl = NULL;
 | 
|---|
| 346 |         int     result;
 | 
|---|
| 347 | 
 | 
|---|
| 348 |         *ppdesc = NULL;
 | 
|---|
| 349 |         result = gpfs_get_nfs4_acl(fsp->fsp_name->base_name, &pacl);
 | 
|---|
| 350 | 
 | 
|---|
| 351 |         if (result == 0)
 | 
|---|
| 352 |                 return smb_fget_nt_acl_nfs4(fsp, security_info, ppdesc, pacl);
 | 
|---|
| 353 | 
 | 
|---|
| 354 |         if (result > 0) {
 | 
|---|
| 355 |                 DEBUG(10, ("retrying with posix acl...\n"));
 | 
|---|
| 356 |                 return posix_fget_nt_acl(fsp, security_info, ppdesc);
 | 
|---|
| 357 |         }
 | 
|---|
| 358 | 
 | 
|---|
| 359 |         /* GPFS ACL was not read, something wrong happened, error code is set in errno */
 | 
|---|
| 360 |         return map_nt_error_from_unix(errno);
 | 
|---|
| 361 | }
 | 
|---|
| 362 | 
 | 
|---|
| 363 | static NTSTATUS gpfsacl_get_nt_acl(vfs_handle_struct *handle,
 | 
|---|
| 364 |         const char *name,
 | 
|---|
| 365 |         uint32 security_info, struct security_descriptor **ppdesc)
 | 
|---|
| 366 | {
 | 
|---|
| 367 |         SMB4ACL_T *pacl = NULL;
 | 
|---|
| 368 |         int     result;
 | 
|---|
| 369 | 
 | 
|---|
| 370 |         *ppdesc = NULL;
 | 
|---|
| 371 |         result = gpfs_get_nfs4_acl(name, &pacl);
 | 
|---|
| 372 | 
 | 
|---|
| 373 |         if (result == 0)
 | 
|---|
| 374 |                 return smb_get_nt_acl_nfs4(handle->conn, name, security_info, ppdesc, pacl);
 | 
|---|
| 375 | 
 | 
|---|
| 376 |         if (result > 0) {
 | 
|---|
| 377 |                 DEBUG(10, ("retrying with posix acl...\n"));
 | 
|---|
| 378 |                 return posix_get_nt_acl(handle->conn, name, security_info, ppdesc);
 | 
|---|
| 379 |         }
 | 
|---|
| 380 | 
 | 
|---|
| 381 |         /* GPFS ACL was not read, something wrong happened, error code is set in errno */
 | 
|---|
| 382 |         return map_nt_error_from_unix(errno);
 | 
|---|
| 383 | }
 | 
|---|
| 384 | 
 | 
|---|
| 385 | static bool gpfsacl_process_smbacl(files_struct *fsp, SMB4ACL_T *smbacl)
 | 
|---|
| 386 | {
 | 
|---|
| 387 |         int ret;
 | 
|---|
| 388 |         gpfs_aclLen_t gacl_len;
 | 
|---|
| 389 |         SMB4ACE_T       *smbace;
 | 
|---|
| 390 |         struct gpfs_acl *gacl;
 | 
|---|
| 391 |         TALLOC_CTX *mem_ctx  = talloc_tos();
 | 
|---|
| 392 | 
 | 
|---|
| 393 |         gacl_len = sizeof(struct gpfs_acl) +
 | 
|---|
| 394 |                 (smb_get_naces(smbacl)-1)*sizeof(gpfs_ace_v4_t);
 | 
|---|
| 395 | 
 | 
|---|
| 396 |         gacl = (struct gpfs_acl *)TALLOC_SIZE(mem_ctx, gacl_len);
 | 
|---|
| 397 |         if (gacl == NULL) {
 | 
|---|
| 398 |                 DEBUG(0, ("talloc failed\n"));
 | 
|---|
| 399 |                 errno = ENOMEM;
 | 
|---|
| 400 |                 return False;
 | 
|---|
| 401 |         }
 | 
|---|
| 402 | 
 | 
|---|
| 403 |         gacl->acl_len = gacl_len;
 | 
|---|
| 404 |         gacl->acl_level = 0;
 | 
|---|
| 405 |         gacl->acl_version = GPFS_ACL_VERSION_NFS4;
 | 
|---|
| 406 |         gacl->acl_type = GPFS_ACL_TYPE_NFS4;
 | 
|---|
| 407 |         gacl->acl_nace = 0; /* change later... */
 | 
|---|
| 408 | 
 | 
|---|
| 409 |         for (smbace=smb_first_ace4(smbacl); smbace!=NULL; smbace = smb_next_ace4(smbace)) {
 | 
|---|
| 410 |                 struct gpfs_ace_v4 *gace = &gacl->ace_v4[gacl->acl_nace];
 | 
|---|
| 411 |                 SMB_ACE4PROP_T  *aceprop = smb_get_ace4(smbace);
 | 
|---|
| 412 | 
 | 
|---|
| 413 |                 gace->aceType = aceprop->aceType;
 | 
|---|
| 414 |                 gace->aceFlags = aceprop->aceFlags;
 | 
|---|
| 415 |                 gace->aceMask = aceprop->aceMask;
 | 
|---|
| 416 | 
 | 
|---|
| 417 |                 /*
 | 
|---|
| 418 |                  * GPFS can't distinguish between WRITE and APPEND on
 | 
|---|
| 419 |                  * files, so one being set without the other is an
 | 
|---|
| 420 |                  * error. Sorry for the many ()'s :-)
 | 
|---|
| 421 |                  */
 | 
|---|
| 422 | 
 | 
|---|
| 423 |                 if (!fsp->is_directory
 | 
|---|
| 424 |                     &&
 | 
|---|
| 425 |                     ((((gace->aceMask & ACE4_MASK_WRITE) == 0)
 | 
|---|
| 426 |                       && ((gace->aceMask & ACE4_MASK_APPEND) != 0))
 | 
|---|
| 427 |                      ||
 | 
|---|
| 428 |                      (((gace->aceMask & ACE4_MASK_WRITE) != 0)
 | 
|---|
| 429 |                       && ((gace->aceMask & ACE4_MASK_APPEND) == 0)))
 | 
|---|
| 430 |                     &&
 | 
|---|
| 431 |                     lp_parm_bool(fsp->conn->params->service, "gpfs",
 | 
|---|
| 432 |                                  "merge_writeappend", True)) {
 | 
|---|
| 433 |                         DEBUG(2, ("vfs_gpfs.c: file [%s]: ACE contains "
 | 
|---|
| 434 |                                   "WRITE^APPEND, setting WRITE|APPEND\n",
 | 
|---|
| 435 |                                   fsp_str_dbg(fsp)));
 | 
|---|
| 436 |                         gace->aceMask |= ACE4_MASK_WRITE|ACE4_MASK_APPEND;
 | 
|---|
| 437 |                 }
 | 
|---|
| 438 | 
 | 
|---|
| 439 |                 gace->aceIFlags = (aceprop->flags&SMB_ACE4_ID_SPECIAL) ? ACE4_IFLAG_SPECIAL_ID : 0;
 | 
|---|
| 440 | 
 | 
|---|
| 441 |                 if (aceprop->flags&SMB_ACE4_ID_SPECIAL)
 | 
|---|
| 442 |                 {
 | 
|---|
| 443 |                         switch(aceprop->who.special_id)
 | 
|---|
| 444 |                         {
 | 
|---|
| 445 |                         case SMB_ACE4_WHO_EVERYONE:
 | 
|---|
| 446 |                                 gace->aceWho = ACE4_SPECIAL_EVERYONE;
 | 
|---|
| 447 |                                 break;
 | 
|---|
| 448 |                         case SMB_ACE4_WHO_OWNER:
 | 
|---|
| 449 |                                 gace->aceWho = ACE4_SPECIAL_OWNER;
 | 
|---|
| 450 |                                 break;
 | 
|---|
| 451 |                         case SMB_ACE4_WHO_GROUP:
 | 
|---|
| 452 |                                 gace->aceWho = ACE4_SPECIAL_GROUP;
 | 
|---|
| 453 |                                 break;
 | 
|---|
| 454 |                         default:
 | 
|---|
| 455 |                                 DEBUG(8, ("unsupported special_id %d\n", aceprop->who.special_id));
 | 
|---|
| 456 |                                 continue; /* don't add it !!! */
 | 
|---|
| 457 |                         }
 | 
|---|
| 458 |                 } else {
 | 
|---|
| 459 |                         /* just only for the type safety... */
 | 
|---|
| 460 |                         if (aceprop->aceFlags&SMB_ACE4_IDENTIFIER_GROUP)
 | 
|---|
| 461 |                                 gace->aceWho = aceprop->who.gid;
 | 
|---|
| 462 |                         else
 | 
|---|
| 463 |                                 gace->aceWho = aceprop->who.uid;
 | 
|---|
| 464 |                 }
 | 
|---|
| 465 | 
 | 
|---|
| 466 |                 gacl->acl_nace++;
 | 
|---|
| 467 |         }
 | 
|---|
| 468 | 
 | 
|---|
| 469 |         ret = smbd_gpfs_putacl(fsp->fsp_name->base_name,
 | 
|---|
| 470 |                                GPFS_PUTACL_STRUCT | GPFS_ACL_SAMBA, gacl);
 | 
|---|
| 471 |         if (ret != 0) {
 | 
|---|
| 472 |                 DEBUG(8, ("gpfs_putacl failed with %s\n", strerror(errno)));
 | 
|---|
| 473 |                 gpfs_dumpacl(8, gacl);
 | 
|---|
| 474 |                 return False;
 | 
|---|
| 475 |         }
 | 
|---|
| 476 | 
 | 
|---|
| 477 |         DEBUG(10, ("gpfs_putacl succeeded\n"));
 | 
|---|
| 478 |         return True;
 | 
|---|
| 479 | }
 | 
|---|
| 480 | 
 | 
|---|
| 481 | static NTSTATUS gpfsacl_set_nt_acl_internal(files_struct *fsp, uint32 security_info_sent, const struct security_descriptor *psd)
 | 
|---|
| 482 | {
 | 
|---|
| 483 |         struct gpfs_acl *acl;
 | 
|---|
| 484 |         NTSTATUS result = NT_STATUS_ACCESS_DENIED;
 | 
|---|
| 485 | 
 | 
|---|
| 486 |         acl = gpfs_getacl_alloc(fsp->fsp_name->base_name, 0);
 | 
|---|
| 487 |         if (acl == NULL)
 | 
|---|
| 488 |                 return result;
 | 
|---|
| 489 | 
 | 
|---|
| 490 |         if (acl->acl_version&GPFS_ACL_VERSION_NFS4)
 | 
|---|
| 491 |         {
 | 
|---|
| 492 |                 if (lp_parm_bool(fsp->conn->params->service, "gpfs",
 | 
|---|
| 493 |                                  "refuse_dacl_protected", false)
 | 
|---|
| 494 |                     && (psd->type&SEC_DESC_DACL_PROTECTED)) {
 | 
|---|
| 495 |                         DEBUG(2, ("Rejecting unsupported ACL with DACL_PROTECTED bit set\n"));
 | 
|---|
| 496 |                         return NT_STATUS_NOT_SUPPORTED;
 | 
|---|
| 497 |                 }
 | 
|---|
| 498 | 
 | 
|---|
| 499 |                 result = smb_set_nt_acl_nfs4(
 | 
|---|
| 500 |                         fsp, security_info_sent, psd,
 | 
|---|
| 501 |                         gpfsacl_process_smbacl);
 | 
|---|
| 502 |         } else { /* assume POSIX ACL - by default... */
 | 
|---|
| 503 |                 result = set_nt_acl(fsp, security_info_sent, psd);
 | 
|---|
| 504 |         }
 | 
|---|
| 505 | 
 | 
|---|
| 506 |         return result;
 | 
|---|
| 507 | }
 | 
|---|
| 508 | 
 | 
|---|
| 509 | static NTSTATUS gpfsacl_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp, uint32 security_info_sent, const struct security_descriptor *psd)
 | 
|---|
| 510 | {
 | 
|---|
| 511 |         return gpfsacl_set_nt_acl_internal(fsp, security_info_sent, psd);
 | 
|---|
| 512 | }
 | 
|---|
| 513 | 
 | 
|---|
| 514 | static SMB_ACL_T gpfs2smb_acl(const struct gpfs_acl *pacl)
 | 
|---|
| 515 | {
 | 
|---|
| 516 |         SMB_ACL_T result;
 | 
|---|
| 517 |         int i;
 | 
|---|
| 518 | 
 | 
|---|
| 519 |         result = sys_acl_init(pacl->acl_nace);
 | 
|---|
| 520 |         if (result == NULL) {
 | 
|---|
| 521 |                 errno = ENOMEM;
 | 
|---|
| 522 |                 return NULL;
 | 
|---|
| 523 |         }
 | 
|---|
| 524 | 
 | 
|---|
| 525 |         result->count = pacl->acl_nace;
 | 
|---|
| 526 | 
 | 
|---|
| 527 |         for (i=0; i<pacl->acl_nace; i++) {
 | 
|---|
| 528 |                 struct smb_acl_entry *ace = &result->acl[i];
 | 
|---|
| 529 |                 const struct gpfs_ace_v1 *g_ace = &pacl->ace_v1[i];
 | 
|---|
| 530 | 
 | 
|---|
| 531 |                 DEBUG(10, ("Converting type %d id %lu perm %x\n",
 | 
|---|
| 532 |                            (int)g_ace->ace_type, (unsigned long)g_ace->ace_who,
 | 
|---|
| 533 |                            (int)g_ace->ace_perm));
 | 
|---|
| 534 | 
 | 
|---|
| 535 |                 switch (g_ace->ace_type) {
 | 
|---|
| 536 |                 case GPFS_ACL_USER:
 | 
|---|
| 537 |                         ace->a_type = SMB_ACL_USER;
 | 
|---|
| 538 |                         ace->uid = (uid_t)g_ace->ace_who;
 | 
|---|
| 539 |                         break;
 | 
|---|
| 540 |                 case GPFS_ACL_USER_OBJ:
 | 
|---|
| 541 |                         ace->a_type = SMB_ACL_USER_OBJ;
 | 
|---|
| 542 |                         break;
 | 
|---|
| 543 |                 case GPFS_ACL_GROUP:
 | 
|---|
| 544 |                         ace->a_type = SMB_ACL_GROUP;
 | 
|---|
| 545 |                         ace->gid = (gid_t)g_ace->ace_who;
 | 
|---|
| 546 |                         break;
 | 
|---|
| 547 |                 case GPFS_ACL_GROUP_OBJ:
 | 
|---|
| 548 |                         ace->a_type = SMB_ACL_GROUP_OBJ;
 | 
|---|
| 549 |                         break;
 | 
|---|
| 550 |                 case GPFS_ACL_OTHER:
 | 
|---|
| 551 |                         ace->a_type = SMB_ACL_OTHER;
 | 
|---|
| 552 |                         break;
 | 
|---|
| 553 |                 case GPFS_ACL_MASK:
 | 
|---|
| 554 |                         ace->a_type = SMB_ACL_MASK;
 | 
|---|
| 555 |                         break;
 | 
|---|
| 556 |                 default:
 | 
|---|
| 557 |                         DEBUG(10, ("Got invalid ace_type: %d\n",
 | 
|---|
| 558 |                                    g_ace->ace_type));
 | 
|---|
| 559 |                         errno = EINVAL;
 | 
|---|
| 560 |                         SAFE_FREE(result);
 | 
|---|
| 561 |                         return NULL;
 | 
|---|
| 562 |                 }
 | 
|---|
| 563 | 
 | 
|---|
| 564 |                 ace->a_perm = 0;
 | 
|---|
| 565 |                 ace->a_perm |= (g_ace->ace_perm & ACL_PERM_READ) ?
 | 
|---|
| 566 |                         SMB_ACL_READ : 0;
 | 
|---|
| 567 |                 ace->a_perm |= (g_ace->ace_perm & ACL_PERM_WRITE) ?
 | 
|---|
| 568 |                         SMB_ACL_WRITE : 0;
 | 
|---|
| 569 |                 ace->a_perm |= (g_ace->ace_perm & ACL_PERM_EXECUTE) ?
 | 
|---|
| 570 |                         SMB_ACL_EXECUTE : 0;
 | 
|---|
| 571 | 
 | 
|---|
| 572 |                 DEBUGADD(10, ("Converted to %d perm %x\n",
 | 
|---|
| 573 |                               ace->a_type, ace->a_perm));
 | 
|---|
| 574 |         }
 | 
|---|
| 575 | 
 | 
|---|
| 576 |         return result;
 | 
|---|
| 577 | }
 | 
|---|
| 578 | 
 | 
|---|
| 579 | static SMB_ACL_T gpfsacl_get_posix_acl(const char *path, gpfs_aclType_t type)
 | 
|---|
| 580 | {
 | 
|---|
| 581 |         struct gpfs_acl *pacl;
 | 
|---|
| 582 |         SMB_ACL_T result = NULL;
 | 
|---|
| 583 | 
 | 
|---|
| 584 |         pacl = gpfs_getacl_alloc(path, type);
 | 
|---|
| 585 | 
 | 
|---|
| 586 |         if (pacl == NULL) {
 | 
|---|
| 587 |                 DEBUG(10, ("gpfs_getacl failed for %s with %s\n",
 | 
|---|
| 588 |                            path, strerror(errno)));
 | 
|---|
| 589 |                 if (errno == 0) {
 | 
|---|
| 590 |                         errno = EINVAL;
 | 
|---|
| 591 |                 }
 | 
|---|
| 592 |                 goto done;
 | 
|---|
| 593 |         }
 | 
|---|
| 594 | 
 | 
|---|
| 595 |         if (pacl->acl_version != GPFS_ACL_VERSION_POSIX) {
 | 
|---|
| 596 |                 DEBUG(10, ("Got acl version %d, expected %d\n",
 | 
|---|
| 597 |                            pacl->acl_version, GPFS_ACL_VERSION_POSIX));
 | 
|---|
| 598 |                 errno = EINVAL;
 | 
|---|
| 599 |                 goto done;
 | 
|---|
| 600 |         }
 | 
|---|
| 601 | 
 | 
|---|
| 602 |         DEBUG(10, ("len: %d, level: %d, version: %d, nace: %d\n",
 | 
|---|
| 603 |                    pacl->acl_len, pacl->acl_level, pacl->acl_version,
 | 
|---|
| 604 |                    pacl->acl_nace));
 | 
|---|
| 605 | 
 | 
|---|
| 606 |         result = gpfs2smb_acl(pacl);
 | 
|---|
| 607 |         if (result != NULL) {
 | 
|---|
| 608 |                 errno = 0;
 | 
|---|
| 609 |         }
 | 
|---|
| 610 | 
 | 
|---|
| 611 |  done:
 | 
|---|
| 612 | 
 | 
|---|
| 613 |         if (errno != 0) {
 | 
|---|
| 614 |                 SAFE_FREE(result);
 | 
|---|
| 615 |         }
 | 
|---|
| 616 |         return result;  
 | 
|---|
| 617 | }
 | 
|---|
| 618 | 
 | 
|---|
| 619 | static SMB_ACL_T gpfsacl_sys_acl_get_file(vfs_handle_struct *handle,
 | 
|---|
| 620 |                                           const char *path_p,
 | 
|---|
| 621 |                                           SMB_ACL_TYPE_T type)
 | 
|---|
| 622 | {
 | 
|---|
| 623 |         gpfs_aclType_t gpfs_type;
 | 
|---|
| 624 | 
 | 
|---|
| 625 |         switch(type) {
 | 
|---|
| 626 |         case SMB_ACL_TYPE_ACCESS:
 | 
|---|
| 627 |                 gpfs_type = GPFS_ACL_TYPE_ACCESS;
 | 
|---|
| 628 |                 break;
 | 
|---|
| 629 |         case SMB_ACL_TYPE_DEFAULT:
 | 
|---|
| 630 |                 gpfs_type = GPFS_ACL_TYPE_DEFAULT;
 | 
|---|
| 631 |                 break;
 | 
|---|
| 632 |         default:
 | 
|---|
| 633 |                 DEBUG(0, ("Got invalid type: %d\n", type));
 | 
|---|
| 634 |                 smb_panic("exiting");
 | 
|---|
| 635 |         }
 | 
|---|
| 636 | 
 | 
|---|
| 637 |         return gpfsacl_get_posix_acl(path_p, gpfs_type);
 | 
|---|
| 638 | }
 | 
|---|
| 639 | 
 | 
|---|
| 640 | static SMB_ACL_T gpfsacl_sys_acl_get_fd(vfs_handle_struct *handle,
 | 
|---|
| 641 |                                         files_struct *fsp)
 | 
|---|
| 642 | {
 | 
|---|
| 643 |         return gpfsacl_get_posix_acl(fsp->fsp_name->base_name,
 | 
|---|
| 644 |                                      GPFS_ACL_TYPE_ACCESS);
 | 
|---|
| 645 | }
 | 
|---|
| 646 | 
 | 
|---|
| 647 | static struct gpfs_acl *smb2gpfs_acl(const SMB_ACL_T pacl,
 | 
|---|
| 648 |                                      SMB_ACL_TYPE_T type)
 | 
|---|
| 649 | {
 | 
|---|
| 650 |         gpfs_aclLen_t len;
 | 
|---|
| 651 |         struct gpfs_acl *result;
 | 
|---|
| 652 |         int i;
 | 
|---|
| 653 |         union gpfs_ace_union
 | 
|---|
| 654 |         {
 | 
|---|
| 655 |                 gpfs_ace_v1_t  ace_v1[1]; /* when GPFS_ACL_VERSION_POSIX */
 | 
|---|
| 656 |                 gpfs_ace_v4_t  ace_v4[1]; /* when GPFS_ACL_VERSION_NFS4  */
 | 
|---|
| 657 |         };
 | 
|---|
| 658 | 
 | 
|---|
| 659 |         DEBUG(10, ("smb2gpfs_acl: Got ACL with %d entries\n", pacl->count));
 | 
|---|
| 660 | 
 | 
|---|
| 661 |         len = sizeof(struct gpfs_acl) - sizeof(union gpfs_ace_union) +
 | 
|---|
| 662 |                 (pacl->count)*sizeof(gpfs_ace_v1_t);
 | 
|---|
| 663 | 
 | 
|---|
| 664 |         result = (struct gpfs_acl *)SMB_MALLOC(len);
 | 
|---|
| 665 |         if (result == NULL) {
 | 
|---|
| 666 |                 errno = ENOMEM;
 | 
|---|
| 667 |                 return result;
 | 
|---|
| 668 |         }
 | 
|---|
| 669 | 
 | 
|---|
| 670 |         result->acl_len = len;
 | 
|---|
| 671 |         result->acl_level = 0;
 | 
|---|
| 672 |         result->acl_version = GPFS_ACL_VERSION_POSIX;
 | 
|---|
| 673 |         result->acl_type = (type == SMB_ACL_TYPE_DEFAULT) ?
 | 
|---|
| 674 |                 GPFS_ACL_TYPE_DEFAULT : GPFS_ACL_TYPE_ACCESS;
 | 
|---|
| 675 |         result->acl_nace = pacl->count;
 | 
|---|
| 676 | 
 | 
|---|
| 677 |         for (i=0; i<pacl->count; i++) {
 | 
|---|
| 678 |                 const struct smb_acl_entry *ace = &pacl->acl[i];
 | 
|---|
| 679 |                 struct gpfs_ace_v1 *g_ace = &result->ace_v1[i];
 | 
|---|
| 680 | 
 | 
|---|
| 681 |                 DEBUG(10, ("Converting type %d perm %x\n",
 | 
|---|
| 682 |                            (int)ace->a_type, (int)ace->a_perm));
 | 
|---|
| 683 | 
 | 
|---|
| 684 |                 g_ace->ace_perm = 0;
 | 
|---|
| 685 | 
 | 
|---|
| 686 |                 switch(ace->a_type) {
 | 
|---|
| 687 |                 case SMB_ACL_USER:
 | 
|---|
| 688 |                         g_ace->ace_type = GPFS_ACL_USER;
 | 
|---|
| 689 |                         g_ace->ace_who = (gpfs_uid_t)ace->uid;
 | 
|---|
| 690 |                         break;
 | 
|---|
| 691 |                 case SMB_ACL_USER_OBJ:
 | 
|---|
| 692 |                         g_ace->ace_type = GPFS_ACL_USER_OBJ;
 | 
|---|
| 693 |                         g_ace->ace_perm |= ACL_PERM_CONTROL;
 | 
|---|
| 694 |                         g_ace->ace_who = 0;
 | 
|---|
| 695 |                         break;
 | 
|---|
| 696 |                 case SMB_ACL_GROUP:
 | 
|---|
| 697 |                         g_ace->ace_type = GPFS_ACL_GROUP;
 | 
|---|
| 698 |                         g_ace->ace_who = (gpfs_uid_t)ace->gid;
 | 
|---|
| 699 |                         break;
 | 
|---|
| 700 |                 case SMB_ACL_GROUP_OBJ:
 | 
|---|
| 701 |                         g_ace->ace_type = GPFS_ACL_GROUP_OBJ;
 | 
|---|
| 702 |                         g_ace->ace_who = 0;
 | 
|---|
| 703 |                         break;
 | 
|---|
| 704 |                 case SMB_ACL_MASK:
 | 
|---|
| 705 |                         g_ace->ace_type = GPFS_ACL_MASK;
 | 
|---|
| 706 |                         g_ace->ace_perm = 0x8f;
 | 
|---|
| 707 |                         g_ace->ace_who = 0;
 | 
|---|
| 708 |                         break;
 | 
|---|
| 709 |                 case SMB_ACL_OTHER:
 | 
|---|
| 710 |                         g_ace->ace_type = GPFS_ACL_OTHER;
 | 
|---|
| 711 |                         g_ace->ace_who = 0;
 | 
|---|
| 712 |                         break;
 | 
|---|
| 713 |                 default:
 | 
|---|
| 714 |                         DEBUG(10, ("Got invalid ace_type: %d\n", ace->a_type));
 | 
|---|
| 715 |                         errno = EINVAL;
 | 
|---|
| 716 |                         SAFE_FREE(result);
 | 
|---|
| 717 |                         return NULL;
 | 
|---|
| 718 |                 }
 | 
|---|
| 719 | 
 | 
|---|
| 720 |                 g_ace->ace_perm |= (ace->a_perm & SMB_ACL_READ) ?
 | 
|---|
| 721 |                         ACL_PERM_READ : 0;
 | 
|---|
| 722 |                 g_ace->ace_perm |= (ace->a_perm & SMB_ACL_WRITE) ?
 | 
|---|
| 723 |                         ACL_PERM_WRITE : 0;
 | 
|---|
| 724 |                 g_ace->ace_perm |= (ace->a_perm & SMB_ACL_EXECUTE) ?
 | 
|---|
| 725 |                         ACL_PERM_EXECUTE : 0;
 | 
|---|
| 726 | 
 | 
|---|
| 727 |                 DEBUGADD(10, ("Converted to %d id %d perm %x\n",
 | 
|---|
| 728 |                               g_ace->ace_type, g_ace->ace_who, g_ace->ace_perm));
 | 
|---|
| 729 |         }
 | 
|---|
| 730 | 
 | 
|---|
| 731 |         return result;
 | 
|---|
| 732 | }
 | 
|---|
| 733 | 
 | 
|---|
| 734 | static int gpfsacl_sys_acl_set_file(vfs_handle_struct *handle,
 | 
|---|
| 735 |                                     const char *name,
 | 
|---|
| 736 |                                     SMB_ACL_TYPE_T type,
 | 
|---|
| 737 |                                     SMB_ACL_T theacl)
 | 
|---|
| 738 | {
 | 
|---|
| 739 |         struct gpfs_acl *gpfs_acl;
 | 
|---|
| 740 |         int result;
 | 
|---|
| 741 | 
 | 
|---|
| 742 |         gpfs_acl = smb2gpfs_acl(theacl, type);
 | 
|---|
| 743 |         if (gpfs_acl == NULL) {
 | 
|---|
| 744 |                 return -1;
 | 
|---|
| 745 |         }
 | 
|---|
| 746 | 
 | 
|---|
| 747 |         result = smbd_gpfs_putacl((char *)name, GPFS_PUTACL_STRUCT | GPFS_ACL_SAMBA, gpfs_acl);
 | 
|---|
| 748 | 
 | 
|---|
| 749 |         SAFE_FREE(gpfs_acl);
 | 
|---|
| 750 |         return result;
 | 
|---|
| 751 | }
 | 
|---|
| 752 | 
 | 
|---|
| 753 | static int gpfsacl_sys_acl_set_fd(vfs_handle_struct *handle,
 | 
|---|
| 754 |                                   files_struct *fsp,
 | 
|---|
| 755 |                                   SMB_ACL_T theacl)
 | 
|---|
| 756 | {
 | 
|---|
| 757 |         return gpfsacl_sys_acl_set_file(handle, fsp->fsp_name->base_name,
 | 
|---|
| 758 |                                         SMB_ACL_TYPE_ACCESS, theacl);
 | 
|---|
| 759 | }
 | 
|---|
| 760 | 
 | 
|---|
| 761 | static int gpfsacl_sys_acl_delete_def_file(vfs_handle_struct *handle,
 | 
|---|
| 762 |                                            const char *path)
 | 
|---|
| 763 | {
 | 
|---|
| 764 |         errno = ENOTSUP;
 | 
|---|
| 765 |         return -1;
 | 
|---|
| 766 | }
 | 
|---|
| 767 | 
 | 
|---|
| 768 | /*
 | 
|---|
| 769 |  * Assumed: mode bits are shiftable and standard
 | 
|---|
| 770 |  * Output: the new aceMask field for an smb nfs4 ace
 | 
|---|
| 771 |  */
 | 
|---|
| 772 | static uint32 gpfsacl_mask_filter(uint32 aceType, uint32 aceMask, uint32 rwx)
 | 
|---|
| 773 | {
 | 
|---|
| 774 |         const uint32 posix_nfs4map[3] = {
 | 
|---|
| 775 |                 SMB_ACE4_EXECUTE, /* execute */
 | 
|---|
| 776 |                 SMB_ACE4_WRITE_DATA | SMB_ACE4_APPEND_DATA, /* write; GPFS specific */
 | 
|---|
| 777 |                 SMB_ACE4_READ_DATA /* read */
 | 
|---|
| 778 |         };
 | 
|---|
| 779 |         int     i;
 | 
|---|
| 780 |         uint32_t        posix_mask = 0x01;
 | 
|---|
| 781 |         uint32_t        posix_bit;
 | 
|---|
| 782 |         uint32_t        nfs4_bits;
 | 
|---|
| 783 | 
 | 
|---|
| 784 |         for(i=0; i<3; i++) {
 | 
|---|
| 785 |                 nfs4_bits = posix_nfs4map[i];
 | 
|---|
| 786 |                 posix_bit = rwx & posix_mask;
 | 
|---|
| 787 | 
 | 
|---|
| 788 |                 if (aceType==SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE) {
 | 
|---|
| 789 |                         if (posix_bit)
 | 
|---|
| 790 |                                 aceMask |= nfs4_bits;
 | 
|---|
| 791 |                         else
 | 
|---|
| 792 |                                 aceMask &= ~nfs4_bits;
 | 
|---|
| 793 |                 } else {
 | 
|---|
| 794 |                         /* add deny bits when suitable */
 | 
|---|
| 795 |                         if (!posix_bit)
 | 
|---|
| 796 |                                 aceMask |= nfs4_bits;
 | 
|---|
| 797 |                         else
 | 
|---|
| 798 |                                 aceMask &= ~nfs4_bits;
 | 
|---|
| 799 |                 } /* other ace types are unexpected */
 | 
|---|
| 800 | 
 | 
|---|
| 801 |                 posix_mask <<= 1;
 | 
|---|
| 802 |         }
 | 
|---|
| 803 | 
 | 
|---|
| 804 |         return aceMask;
 | 
|---|
| 805 | }
 | 
|---|
| 806 | 
 | 
|---|
| 807 | static int gpfsacl_emu_chmod(const char *path, mode_t mode)
 | 
|---|
| 808 | {
 | 
|---|
| 809 |         SMB4ACL_T *pacl = NULL;
 | 
|---|
| 810 |         int     result;
 | 
|---|
| 811 |         bool    haveAllowEntry[SMB_ACE4_WHO_EVERYONE + 1] = {False, False, False, False};
 | 
|---|
| 812 |         int     i;
 | 
|---|
| 813 |         files_struct    fake_fsp; /* TODO: rationalize parametrization */
 | 
|---|
| 814 |         SMB4ACE_T       *smbace;
 | 
|---|
| 815 |         NTSTATUS status;
 | 
|---|
| 816 | 
 | 
|---|
| 817 |         DEBUG(10, ("gpfsacl_emu_chmod invoked for %s mode %o\n", path, mode));
 | 
|---|
| 818 | 
 | 
|---|
| 819 |         result = gpfs_get_nfs4_acl(path, &pacl);
 | 
|---|
| 820 |         if (result)
 | 
|---|
| 821 |                 return result;
 | 
|---|
| 822 | 
 | 
|---|
| 823 |         if (mode & ~(S_IRWXU | S_IRWXG | S_IRWXO)) {
 | 
|---|
| 824 |                 DEBUG(2, ("WARNING: cutting extra mode bits %o on %s\n", mode, path));
 | 
|---|
| 825 |         }
 | 
|---|
| 826 | 
 | 
|---|
| 827 |         for (smbace=smb_first_ace4(pacl); smbace!=NULL; smbace = smb_next_ace4(smbace)) {
 | 
|---|
| 828 |                 SMB_ACE4PROP_T  *ace = smb_get_ace4(smbace);
 | 
|---|
| 829 |                 uint32_t        specid = ace->who.special_id;
 | 
|---|
| 830 | 
 | 
|---|
| 831 |                 if (ace->flags&SMB_ACE4_ID_SPECIAL &&
 | 
|---|
| 832 |                     ace->aceType<=SMB_ACE4_ACCESS_DENIED_ACE_TYPE &&
 | 
|---|
| 833 |                     specid <= SMB_ACE4_WHO_EVERYONE) {
 | 
|---|
| 834 | 
 | 
|---|
| 835 |                         uint32_t newMask;
 | 
|---|
| 836 | 
 | 
|---|
| 837 |                         if (ace->aceType==SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE)
 | 
|---|
| 838 |                                 haveAllowEntry[specid] = True;
 | 
|---|
| 839 | 
 | 
|---|
| 840 |                         /* mode >> 6 for @owner, mode >> 3 for @group,
 | 
|---|
| 841 |                          * mode >> 0 for @everyone */
 | 
|---|
| 842 |                         newMask = gpfsacl_mask_filter(ace->aceType, ace->aceMask,
 | 
|---|
| 843 |                                                       mode >> ((SMB_ACE4_WHO_EVERYONE - specid) * 3));
 | 
|---|
| 844 |                         if (ace->aceMask!=newMask) {
 | 
|---|
| 845 |                                 DEBUG(10, ("ace changed for %s (%o -> %o) id=%d\n",
 | 
|---|
| 846 |                                            path, ace->aceMask, newMask, specid));
 | 
|---|
| 847 |                         }
 | 
|---|
| 848 |                         ace->aceMask = newMask;
 | 
|---|
| 849 |                 }
 | 
|---|
| 850 |         }
 | 
|---|
| 851 | 
 | 
|---|
| 852 |         /* make sure we have at least ALLOW entries
 | 
|---|
| 853 |          * for all the 3 special ids (@EVERYONE, @OWNER, @GROUP)
 | 
|---|
| 854 |          * - if necessary
 | 
|---|
| 855 |          */
 | 
|---|
| 856 |         for(i = SMB_ACE4_WHO_OWNER; i<=SMB_ACE4_WHO_EVERYONE; i++) {
 | 
|---|
| 857 |                 SMB_ACE4PROP_T  ace;
 | 
|---|
| 858 | 
 | 
|---|
| 859 |                 if (haveAllowEntry[i]==True)
 | 
|---|
| 860 |                         continue;
 | 
|---|
| 861 | 
 | 
|---|
| 862 |                 ZERO_STRUCT(ace);
 | 
|---|
| 863 |                 ace.aceType = SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE;
 | 
|---|
| 864 |                 ace.flags |= SMB_ACE4_ID_SPECIAL;
 | 
|---|
| 865 |                 ace.who.special_id = i;
 | 
|---|
| 866 | 
 | 
|---|
| 867 |                 if (i==SMB_ACE4_WHO_GROUP) /* not sure it's necessary... */
 | 
|---|
| 868 |                         ace.aceFlags |= SMB_ACE4_IDENTIFIER_GROUP;
 | 
|---|
| 869 | 
 | 
|---|
| 870 |                 ace.aceMask = gpfsacl_mask_filter(ace.aceType, ace.aceMask,
 | 
|---|
| 871 |                                                   mode >> ((SMB_ACE4_WHO_EVERYONE - i) * 3));
 | 
|---|
| 872 | 
 | 
|---|
| 873 |                 /* don't add unnecessary aces */
 | 
|---|
| 874 |                 if (!ace.aceMask)
 | 
|---|
| 875 |                         continue;
 | 
|---|
| 876 | 
 | 
|---|
| 877 |                 /* we add it to the END - as windows expects allow aces */
 | 
|---|
| 878 |                 smb_add_ace4(pacl, &ace);
 | 
|---|
| 879 |                 DEBUG(10, ("Added ALLOW ace for %s, mode=%o, id=%d, aceMask=%x\n",
 | 
|---|
| 880 |                            path, mode, i, ace.aceMask));
 | 
|---|
| 881 |         }
 | 
|---|
| 882 | 
 | 
|---|
| 883 |         /* don't add complementary DENY ACEs here */
 | 
|---|
| 884 |         ZERO_STRUCT(fake_fsp);
 | 
|---|
| 885 |         status = create_synthetic_smb_fname(talloc_tos(), path, NULL, NULL,
 | 
|---|
| 886 |                                             &fake_fsp.fsp_name);
 | 
|---|
| 887 |         if (!NT_STATUS_IS_OK(status)) {
 | 
|---|
| 888 |                 errno = map_errno_from_nt_status(status);
 | 
|---|
| 889 |                 return -1;
 | 
|---|
| 890 |         }
 | 
|---|
| 891 |         /* put the acl */
 | 
|---|
| 892 |         if (gpfsacl_process_smbacl(&fake_fsp, pacl) == False) {
 | 
|---|
| 893 |                 TALLOC_FREE(fake_fsp.fsp_name);
 | 
|---|
| 894 |                 return -1;
 | 
|---|
| 895 |         }
 | 
|---|
| 896 | 
 | 
|---|
| 897 |         TALLOC_FREE(fake_fsp.fsp_name);
 | 
|---|
| 898 |         return 0; /* ok for [f]chmod */
 | 
|---|
| 899 | }
 | 
|---|
| 900 | 
 | 
|---|
| 901 | static int vfs_gpfs_chmod(vfs_handle_struct *handle, const char *path, mode_t mode)
 | 
|---|
| 902 | {
 | 
|---|
| 903 |         struct smb_filename *smb_fname_cpath;
 | 
|---|
| 904 |         int rc;
 | 
|---|
| 905 |         NTSTATUS status;
 | 
|---|
| 906 | 
 | 
|---|
| 907 |         status = create_synthetic_smb_fname(
 | 
|---|
| 908 |                 talloc_tos(), path, NULL, NULL, &smb_fname_cpath);
 | 
|---|
| 909 | 
 | 
|---|
| 910 |         if (SMB_VFS_NEXT_STAT(handle, smb_fname_cpath) != 0) {
 | 
|---|
| 911 |                 return -1;
 | 
|---|
| 912 |         }
 | 
|---|
| 913 | 
 | 
|---|
| 914 |         /* avoid chmod() if possible, to preserve acls */
 | 
|---|
| 915 |         if ((smb_fname_cpath->st.st_ex_mode & ~S_IFMT) == mode) {
 | 
|---|
| 916 |                 return 0;
 | 
|---|
| 917 |         }
 | 
|---|
| 918 | 
 | 
|---|
| 919 |         rc = gpfsacl_emu_chmod(path, mode);
 | 
|---|
| 920 |         if (rc == 1)
 | 
|---|
| 921 |                 return SMB_VFS_NEXT_CHMOD(handle, path, mode);
 | 
|---|
| 922 |         return rc;
 | 
|---|
| 923 | }
 | 
|---|
| 924 | 
 | 
|---|
| 925 | static int vfs_gpfs_fchmod(vfs_handle_struct *handle, files_struct *fsp, mode_t mode)
 | 
|---|
| 926 | {
 | 
|---|
| 927 |                  SMB_STRUCT_STAT st;
 | 
|---|
| 928 |                  int rc;
 | 
|---|
| 929 | 
 | 
|---|
| 930 |                  if (SMB_VFS_NEXT_FSTAT(handle, fsp, &st) != 0) {
 | 
|---|
| 931 |                          return -1;
 | 
|---|
| 932 |                  }
 | 
|---|
| 933 | 
 | 
|---|
| 934 |                  /* avoid chmod() if possible, to preserve acls */
 | 
|---|
| 935 |                  if ((st.st_ex_mode & ~S_IFMT) == mode) {
 | 
|---|
| 936 |                          return 0;
 | 
|---|
| 937 |                  }
 | 
|---|
| 938 | 
 | 
|---|
| 939 |                  rc = gpfsacl_emu_chmod(fsp->fsp_name->base_name, mode);
 | 
|---|
| 940 |                  if (rc == 1)
 | 
|---|
| 941 |                          return SMB_VFS_NEXT_FCHMOD(handle, fsp, mode);
 | 
|---|
| 942 |                  return rc;
 | 
|---|
| 943 | }
 | 
|---|
| 944 | 
 | 
|---|
| 945 | static int gpfs_set_xattr(struct vfs_handle_struct *handle,  const char *path,
 | 
|---|
| 946 |                            const char *name, const void *value, size_t size,  int flags){
 | 
|---|
| 947 |         struct xattr_DOSATTRIB dosattrib;
 | 
|---|
| 948 |         enum ndr_err_code ndr_err;
 | 
|---|
| 949 |         DATA_BLOB blob;
 | 
|---|
| 950 |         const char *attrstr = value;
 | 
|---|
| 951 |         unsigned int dosmode=0;
 | 
|---|
| 952 |         struct gpfs_winattr attrs;
 | 
|---|
| 953 |         int ret = 0;
 | 
|---|
| 954 | 
 | 
|---|
| 955 |         DEBUG(10, ("gpfs_set_xattr: %s \n",path));
 | 
|---|
| 956 | 
 | 
|---|
| 957 |         /* Only handle DOS Attributes */
 | 
|---|
| 958 |         if (strcmp(name,SAMBA_XATTR_DOS_ATTRIB) != 0){
 | 
|---|
| 959 |                 DEBUG(5, ("gpfs_set_xattr:name is %s\n",name));
 | 
|---|
| 960 |                 return SMB_VFS_NEXT_SETXATTR(handle,path,name,value,size,flags);
 | 
|---|
| 961 |         }
 | 
|---|
| 962 | 
 | 
|---|
| 963 |         blob.data = (uint8_t *)attrstr;
 | 
|---|
| 964 |         blob.length = size;
 | 
|---|
| 965 | 
 | 
|---|
| 966 |         ndr_err = ndr_pull_struct_blob(&blob, talloc_tos(), &dosattrib,
 | 
|---|
| 967 |                         (ndr_pull_flags_fn_t)ndr_pull_xattr_DOSATTRIB);
 | 
|---|
| 968 | 
 | 
|---|
| 969 |         if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
 | 
|---|
| 970 |                 DEBUG(1, ("gpfs_set_xattr: bad ndr decode "
 | 
|---|
| 971 |                           "from EA on file %s: Error = %s\n",
 | 
|---|
| 972 |                           path, ndr_errstr(ndr_err)));
 | 
|---|
| 973 |                 return false;
 | 
|---|
| 974 |         }
 | 
|---|
| 975 | 
 | 
|---|
| 976 |         if (dosattrib.version != 3) {
 | 
|---|
| 977 |                 DEBUG(1, ("gpfs_set_xattr: expected dosattrib version 3, got "
 | 
|---|
| 978 |                           "%d\n", (int)dosattrib.version));
 | 
|---|
| 979 |                 return false;
 | 
|---|
| 980 |         }
 | 
|---|
| 981 |         if (!(dosattrib.info.info3.valid_flags & XATTR_DOSINFO_ATTRIB)) {
 | 
|---|
| 982 |                 DEBUG(10, ("gpfs_set_xattr: XATTR_DOSINFO_ATTRIB not "
 | 
|---|
| 983 |                            "valid, ignoring\n"));
 | 
|---|
| 984 |                 return true;
 | 
|---|
| 985 |         }
 | 
|---|
| 986 | 
 | 
|---|
| 987 |         dosmode = dosattrib.info.info3.attrib;
 | 
|---|
| 988 | 
 | 
|---|
| 989 |         attrs.winAttrs = 0;
 | 
|---|
| 990 |         /*Just map RD_ONLY, ARCHIVE, SYSTEM HIDDEN and SPARSE. Ignore the others*/
 | 
|---|
| 991 |         if (dosmode & FILE_ATTRIBUTE_ARCHIVE){
 | 
|---|
| 992 |                 attrs.winAttrs |= GPFS_WINATTR_ARCHIVE;
 | 
|---|
| 993 |         }
 | 
|---|
| 994 |         if (dosmode & FILE_ATTRIBUTE_HIDDEN){
 | 
|---|
| 995 |                         attrs.winAttrs |= GPFS_WINATTR_HIDDEN;
 | 
|---|
| 996 |                 }
 | 
|---|
| 997 |         if (dosmode & FILE_ATTRIBUTE_SYSTEM){
 | 
|---|
| 998 |                         attrs.winAttrs |= GPFS_WINATTR_SYSTEM;
 | 
|---|
| 999 |                 }
 | 
|---|
| 1000 |         if (dosmode & FILE_ATTRIBUTE_READONLY){
 | 
|---|
| 1001 |                         attrs.winAttrs |= GPFS_WINATTR_READONLY;
 | 
|---|
| 1002 |         }
 | 
|---|
| 1003 |         if (dosmode & FILE_ATTRIBUTE_SPARSE) {
 | 
|---|
| 1004 |                 attrs.winAttrs |= GPFS_WINATTR_SPARSE_FILE;
 | 
|---|
| 1005 |         }
 | 
|---|
| 1006 | 
 | 
|---|
| 1007 | 
 | 
|---|
| 1008 |         ret = set_gpfs_winattrs(CONST_DISCARD(char *, path),
 | 
|---|
| 1009 |                                 GPFS_WINATTR_SET_ATTRS, &attrs);
 | 
|---|
| 1010 |         if ( ret == -1){
 | 
|---|
| 1011 |                 if (errno == ENOSYS) {
 | 
|---|
| 1012 |                         return SMB_VFS_NEXT_SETXATTR(handle, path, name, value,
 | 
|---|
| 1013 |                                                      size, flags);
 | 
|---|
| 1014 |                 }
 | 
|---|
| 1015 | 
 | 
|---|
| 1016 |                 DEBUG(1, ("gpfs_set_xattr:Set GPFS attributes failed %d\n",ret));
 | 
|---|
| 1017 |                 return -1;
 | 
|---|
| 1018 |         }
 | 
|---|
| 1019 | 
 | 
|---|
| 1020 |         DEBUG(10, ("gpfs_set_xattr:Set attributes: 0x%x\n",attrs.winAttrs));
 | 
|---|
| 1021 |         return 0;
 | 
|---|
| 1022 | }
 | 
|---|
| 1023 | 
 | 
|---|
| 1024 | static ssize_t gpfs_get_xattr(struct vfs_handle_struct *handle,  const char *path,
 | 
|---|
| 1025 |                               const char *name, void *value, size_t size){
 | 
|---|
| 1026 |         char *attrstr = value;
 | 
|---|
| 1027 |         unsigned int dosmode = 0;
 | 
|---|
| 1028 |         struct gpfs_winattr attrs;
 | 
|---|
| 1029 |         int ret = 0;
 | 
|---|
| 1030 | 
 | 
|---|
| 1031 |         DEBUG(10, ("gpfs_get_xattr: %s \n",path));
 | 
|---|
| 1032 | 
 | 
|---|
| 1033 |         /* Only handle DOS Attributes */
 | 
|---|
| 1034 |         if (strcmp(name,SAMBA_XATTR_DOS_ATTRIB) != 0){
 | 
|---|
| 1035 |                 DEBUG(5, ("gpfs_get_xattr:name is %s\n",name));
 | 
|---|
| 1036 |                 return SMB_VFS_NEXT_GETXATTR(handle,path,name,value,size);
 | 
|---|
| 1037 |         }
 | 
|---|
| 1038 | 
 | 
|---|
| 1039 |         ret = get_gpfs_winattrs(CONST_DISCARD(char *, path), &attrs);
 | 
|---|
| 1040 |         if ( ret == -1){
 | 
|---|
| 1041 |                 if (errno == ENOSYS) {
 | 
|---|
| 1042 |                         return SMB_VFS_NEXT_GETXATTR(handle, path, name, value,
 | 
|---|
| 1043 |                                                      size);
 | 
|---|
| 1044 |                 }
 | 
|---|
| 1045 | 
 | 
|---|
| 1046 |                 DEBUG(1, ("gpfs_get_xattr: Get GPFS attributes failed: "
 | 
|---|
| 1047 |                           "%d (%s)\n", ret, strerror(errno)));
 | 
|---|
| 1048 |                 return -1;
 | 
|---|
| 1049 |         }
 | 
|---|
| 1050 | 
 | 
|---|
| 1051 |         DEBUG(10, ("gpfs_get_xattr:Got attributes: 0x%x\n",attrs.winAttrs));
 | 
|---|
| 1052 | 
 | 
|---|
| 1053 |         /*Just map RD_ONLY, ARCHIVE, SYSTEM, HIDDEN and SPARSE. Ignore the others*/
 | 
|---|
| 1054 |         if (attrs.winAttrs & GPFS_WINATTR_ARCHIVE){
 | 
|---|
| 1055 |                 dosmode |= FILE_ATTRIBUTE_ARCHIVE;
 | 
|---|
| 1056 |         }
 | 
|---|
| 1057 |         if (attrs.winAttrs & GPFS_WINATTR_HIDDEN){
 | 
|---|
| 1058 |                 dosmode |= FILE_ATTRIBUTE_HIDDEN;
 | 
|---|
| 1059 |         }
 | 
|---|
| 1060 |         if (attrs.winAttrs & GPFS_WINATTR_SYSTEM){
 | 
|---|
| 1061 |                 dosmode |= FILE_ATTRIBUTE_SYSTEM;
 | 
|---|
| 1062 |         }
 | 
|---|
| 1063 |         if (attrs.winAttrs & GPFS_WINATTR_READONLY){
 | 
|---|
| 1064 |                 dosmode |= FILE_ATTRIBUTE_READONLY;
 | 
|---|
| 1065 |         }
 | 
|---|
| 1066 |         if (attrs.winAttrs & GPFS_WINATTR_SPARSE_FILE) {
 | 
|---|
| 1067 |                 dosmode |= FILE_ATTRIBUTE_SPARSE;
 | 
|---|
| 1068 |         }
 | 
|---|
| 1069 | 
 | 
|---|
| 1070 |         snprintf(attrstr, size, "0x%2.2x",
 | 
|---|
| 1071 |                  (unsigned int)(dosmode & SAMBA_ATTRIBUTES_MASK));
 | 
|---|
| 1072 |         DEBUG(10, ("gpfs_get_xattr: returning %s\n",attrstr));
 | 
|---|
| 1073 |         return 4;
 | 
|---|
| 1074 | }
 | 
|---|
| 1075 | 
 | 
|---|
| 1076 | static int vfs_gpfs_stat(struct vfs_handle_struct *handle,
 | 
|---|
| 1077 |                          struct smb_filename *smb_fname)
 | 
|---|
| 1078 | {
 | 
|---|
| 1079 |         struct gpfs_winattr attrs;
 | 
|---|
| 1080 |         char *fname = NULL;
 | 
|---|
| 1081 |         NTSTATUS status;
 | 
|---|
| 1082 |         int ret;
 | 
|---|
| 1083 | 
 | 
|---|
| 1084 |         ret = SMB_VFS_NEXT_STAT(handle, smb_fname);
 | 
|---|
| 1085 |         if (ret == -1) {
 | 
|---|
| 1086 |                 return -1;
 | 
|---|
| 1087 |         }
 | 
|---|
| 1088 |         status = get_full_smb_filename(talloc_tos(), smb_fname, &fname);
 | 
|---|
| 1089 |         if (!NT_STATUS_IS_OK(status)) {
 | 
|---|
| 1090 |                 errno = map_errno_from_nt_status(status);
 | 
|---|
| 1091 |                 return -1;
 | 
|---|
| 1092 |         }
 | 
|---|
| 1093 |         ret = get_gpfs_winattrs(CONST_DISCARD(char *, fname), &attrs);
 | 
|---|
| 1094 |         TALLOC_FREE(fname);
 | 
|---|
| 1095 |         if (ret == 0) {
 | 
|---|
| 1096 |                 smb_fname->st.st_ex_btime.tv_sec = attrs.creationTime.tv_sec;
 | 
|---|
| 1097 |                 smb_fname->st.st_ex_btime.tv_nsec = attrs.creationTime.tv_nsec;
 | 
|---|
| 1098 |                 smb_fname->st.vfs_private = attrs.winAttrs;
 | 
|---|
| 1099 |         }
 | 
|---|
| 1100 |         return 0;
 | 
|---|
| 1101 | }
 | 
|---|
| 1102 | 
 | 
|---|
| 1103 | static int vfs_gpfs_fstat(struct vfs_handle_struct *handle,
 | 
|---|
| 1104 |                           struct files_struct *fsp, SMB_STRUCT_STAT *sbuf)
 | 
|---|
| 1105 | {
 | 
|---|
| 1106 |         struct gpfs_winattr attrs;
 | 
|---|
| 1107 |         int ret;
 | 
|---|
| 1108 | 
 | 
|---|
| 1109 |         ret = SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf);
 | 
|---|
| 1110 |         if (ret == -1) {
 | 
|---|
| 1111 |                 return -1;
 | 
|---|
| 1112 |         }
 | 
|---|
| 1113 |         if ((fsp->fh == NULL) || (fsp->fh->fd == -1)) {
 | 
|---|
| 1114 |                 return 0;
 | 
|---|
| 1115 |         }
 | 
|---|
| 1116 |         ret = smbd_fget_gpfs_winattrs(fsp->fh->fd, &attrs);
 | 
|---|
| 1117 |         if (ret == 0) {
 | 
|---|
| 1118 |                 sbuf->st_ex_btime.tv_sec = attrs.creationTime.tv_sec;
 | 
|---|
| 1119 |                 sbuf->st_ex_btime.tv_nsec = attrs.creationTime.tv_nsec;
 | 
|---|
| 1120 |         }
 | 
|---|
| 1121 |         return 0;
 | 
|---|
| 1122 | }
 | 
|---|
| 1123 | 
 | 
|---|
| 1124 | static int vfs_gpfs_lstat(struct vfs_handle_struct *handle,
 | 
|---|
| 1125 |                           struct smb_filename *smb_fname)
 | 
|---|
| 1126 | {
 | 
|---|
| 1127 |         struct gpfs_winattr attrs;
 | 
|---|
| 1128 |         char *path = NULL;
 | 
|---|
| 1129 |         NTSTATUS status;
 | 
|---|
| 1130 |         int ret;
 | 
|---|
| 1131 | 
 | 
|---|
| 1132 |         ret = SMB_VFS_NEXT_LSTAT(handle, smb_fname);
 | 
|---|
| 1133 |         if (ret == -1) {
 | 
|---|
| 1134 |                 return -1;
 | 
|---|
| 1135 |         }
 | 
|---|
| 1136 |         status = get_full_smb_filename(talloc_tos(), smb_fname, &path);
 | 
|---|
| 1137 |         if (!NT_STATUS_IS_OK(status)) {
 | 
|---|
| 1138 |                 errno = map_errno_from_nt_status(status);
 | 
|---|
| 1139 |                 return -1;
 | 
|---|
| 1140 |         }
 | 
|---|
| 1141 |         ret = get_gpfs_winattrs(CONST_DISCARD(char *, path), &attrs);
 | 
|---|
| 1142 |         TALLOC_FREE(path);
 | 
|---|
| 1143 |         if (ret == 0) {
 | 
|---|
| 1144 |                 smb_fname->st.st_ex_btime.tv_sec = attrs.creationTime.tv_sec;
 | 
|---|
| 1145 |                 smb_fname->st.st_ex_btime.tv_nsec = attrs.creationTime.tv_nsec;
 | 
|---|
| 1146 |                 smb_fname->st.vfs_private = attrs.winAttrs;
 | 
|---|
| 1147 |         }
 | 
|---|
| 1148 |         return 0;
 | 
|---|
| 1149 | }
 | 
|---|
| 1150 | 
 | 
|---|
| 1151 | static int vfs_gpfs_ntimes(struct vfs_handle_struct *handle,
 | 
|---|
| 1152 |                         const struct smb_filename *smb_fname,
 | 
|---|
| 1153 |                         struct smb_file_time *ft)
 | 
|---|
| 1154 | {
 | 
|---|
| 1155 | 
 | 
|---|
| 1156 |         struct gpfs_winattr attrs;
 | 
|---|
| 1157 |         int ret;
 | 
|---|
| 1158 |         char *path = NULL;
 | 
|---|
| 1159 |         NTSTATUS status;
 | 
|---|
| 1160 | 
 | 
|---|
| 1161 |         ret = SMB_VFS_NEXT_NTIMES(handle, smb_fname, ft);
 | 
|---|
| 1162 |         if(ret == -1){
 | 
|---|
| 1163 |                 DEBUG(1,("vfs_gpfs_ntimes: SMB_VFS_NEXT_NTIMES failed\n"));
 | 
|---|
| 1164 |                 return -1;
 | 
|---|
| 1165 |         }
 | 
|---|
| 1166 | 
 | 
|---|
| 1167 |         if(null_timespec(ft->create_time)){
 | 
|---|
| 1168 |                 DEBUG(10,("vfs_gpfs_ntimes:Create Time is NULL\n"));
 | 
|---|
| 1169 |                 return 0;
 | 
|---|
| 1170 |         }
 | 
|---|
| 1171 | 
 | 
|---|
| 1172 |         status = get_full_smb_filename(talloc_tos(), smb_fname, &path);
 | 
|---|
| 1173 |         if (!NT_STATUS_IS_OK(status)) {
 | 
|---|
| 1174 |                 errno = map_errno_from_nt_status(status);
 | 
|---|
| 1175 |                 return -1;
 | 
|---|
| 1176 |         }
 | 
|---|
| 1177 | 
 | 
|---|
| 1178 |         attrs.winAttrs = 0;
 | 
|---|
| 1179 |         attrs.creationTime.tv_sec = ft->create_time.tv_sec;
 | 
|---|
| 1180 |         attrs.creationTime.tv_nsec = ft->create_time.tv_nsec;
 | 
|---|
| 1181 | 
 | 
|---|
| 1182 |         ret = set_gpfs_winattrs(CONST_DISCARD(char *, path),
 | 
|---|
| 1183 |                                 GPFS_WINATTR_SET_CREATION_TIME, &attrs);
 | 
|---|
| 1184 |         if(ret == -1 && errno != ENOSYS){
 | 
|---|
| 1185 |                 DEBUG(1,("vfs_gpfs_ntimes: set GPFS ntimes failed %d\n",ret));
 | 
|---|
| 1186 |                 return -1;
 | 
|---|
| 1187 |         }
 | 
|---|
| 1188 |         return 0;
 | 
|---|
| 1189 | 
 | 
|---|
| 1190 | }
 | 
|---|
| 1191 | 
 | 
|---|
| 1192 | static int vfs_gpfs_ftruncate(vfs_handle_struct *handle, files_struct *fsp,
 | 
|---|
| 1193 |                                 SMB_OFF_T len)
 | 
|---|
| 1194 | {
 | 
|---|
| 1195 |         int result;
 | 
|---|
| 1196 | 
 | 
|---|
| 1197 |         result = smbd_gpfs_ftruncate(fsp->fh->fd, len);
 | 
|---|
| 1198 |         if ((result == -1) && (errno == ENOSYS)) {
 | 
|---|
| 1199 |                 return SMB_VFS_NEXT_FTRUNCATE(handle, fsp, len);
 | 
|---|
| 1200 |         }
 | 
|---|
| 1201 |         return result;
 | 
|---|
| 1202 | }
 | 
|---|
| 1203 | 
 | 
|---|
| 1204 | static bool vfs_gpfs_is_offline(struct vfs_handle_struct *handle,
 | 
|---|
| 1205 |                                 const struct smb_filename *fname,
 | 
|---|
| 1206 |                                 SMB_STRUCT_STAT *sbuf)
 | 
|---|
| 1207 | {
 | 
|---|
| 1208 |         struct gpfs_winattr attrs;
 | 
|---|
| 1209 |         char *path = NULL;
 | 
|---|
| 1210 |         NTSTATUS status;
 | 
|---|
| 1211 | 
 | 
|---|
| 1212 |         status = get_full_smb_filename(talloc_tos(), fname, &path);
 | 
|---|
| 1213 |         if (!NT_STATUS_IS_OK(status)) {
 | 
|---|
| 1214 |                 errno = map_errno_from_nt_status(status);
 | 
|---|
| 1215 |                 return -1;
 | 
|---|
| 1216 |         }
 | 
|---|
| 1217 | 
 | 
|---|
| 1218 |         if (VALID_STAT(*sbuf)) {
 | 
|---|
| 1219 |                 attrs.winAttrs = sbuf->vfs_private;
 | 
|---|
| 1220 |         } else {
 | 
|---|
| 1221 |                 int ret;
 | 
|---|
| 1222 |                 ret = get_gpfs_winattrs(path, &attrs);
 | 
|---|
| 1223 | 
 | 
|---|
| 1224 |                 if (ret == -1) {
 | 
|---|
| 1225 |                         TALLOC_FREE(path);
 | 
|---|
| 1226 |                         return false;
 | 
|---|
| 1227 |                 }
 | 
|---|
| 1228 |         }
 | 
|---|
| 1229 |         if ((attrs.winAttrs & GPFS_WINATTR_OFFLINE) != 0) {
 | 
|---|
| 1230 |                 DEBUG(10, ("%s is offline\n", path));
 | 
|---|
| 1231 |                 TALLOC_FREE(path);
 | 
|---|
| 1232 |                 return true;
 | 
|---|
| 1233 |         }
 | 
|---|
| 1234 |         DEBUG(10, ("%s is online\n", path));
 | 
|---|
| 1235 |         TALLOC_FREE(path);
 | 
|---|
| 1236 |         return SMB_VFS_NEXT_IS_OFFLINE(handle, fname, sbuf);
 | 
|---|
| 1237 | }
 | 
|---|
| 1238 | 
 | 
|---|
| 1239 | static bool vfs_gpfs_aio_force(struct vfs_handle_struct *handle,
 | 
|---|
| 1240 |                                struct files_struct *fsp)
 | 
|---|
| 1241 | {
 | 
|---|
| 1242 |         return vfs_gpfs_is_offline(handle, fsp->fsp_name, &fsp->fsp_name->st);
 | 
|---|
| 1243 | }
 | 
|---|
| 1244 | 
 | 
|---|
| 1245 | static ssize_t vfs_gpfs_sendfile(vfs_handle_struct *handle, int tofd,
 | 
|---|
| 1246 |                                  files_struct *fsp, const DATA_BLOB *hdr,
 | 
|---|
| 1247 |                                  SMB_OFF_T offset, size_t n)
 | 
|---|
| 1248 | {
 | 
|---|
| 1249 |         if ((fsp->fsp_name->st.vfs_private & GPFS_WINATTR_OFFLINE) != 0) {
 | 
|---|
| 1250 |                 errno = ENOSYS;
 | 
|---|
| 1251 |                 return -1;
 | 
|---|
| 1252 |         }
 | 
|---|
| 1253 |         return SMB_VFS_NEXT_SENDFILE(handle, tofd, fsp, hdr, offset, n);
 | 
|---|
| 1254 | }
 | 
|---|
| 1255 | 
 | 
|---|
| 1256 | int vfs_gpfs_connect(struct vfs_handle_struct *handle, const char *service,
 | 
|---|
| 1257 |                         const char *user)
 | 
|---|
| 1258 | {
 | 
|---|
| 1259 |         struct gpfs_config_data *config;
 | 
|---|
| 1260 | 
 | 
|---|
| 1261 |         smbd_gpfs_lib_init();
 | 
|---|
| 1262 | 
 | 
|---|
| 1263 |         int ret = SMB_VFS_NEXT_CONNECT(handle, service, user);
 | 
|---|
| 1264 | 
 | 
|---|
| 1265 |         if (ret < 0) {
 | 
|---|
| 1266 |                 return ret;
 | 
|---|
| 1267 |         }
 | 
|---|
| 1268 | 
 | 
|---|
| 1269 |         config = talloc_zero(handle->conn, struct gpfs_config_data);
 | 
|---|
| 1270 |         if (!config) {
 | 
|---|
| 1271 |                 SMB_VFS_NEXT_DISCONNECT(handle);
 | 
|---|
| 1272 |                 DEBUG(0, ("talloc_zero() failed\n")); return -1;
 | 
|---|
| 1273 |         }
 | 
|---|
| 1274 | 
 | 
|---|
| 1275 |         config->sharemodes = lp_parm_bool(SNUM(handle->conn), "gpfs",
 | 
|---|
| 1276 |                                         "sharemodes", true);
 | 
|---|
| 1277 | 
 | 
|---|
| 1278 |         config->leases = lp_parm_bool(SNUM(handle->conn), "gpfs",
 | 
|---|
| 1279 |                                         "leases", true);
 | 
|---|
| 1280 | 
 | 
|---|
| 1281 |         config->hsm = lp_parm_bool(SNUM(handle->conn), "gpfs",
 | 
|---|
| 1282 |                                    "hsm", false);
 | 
|---|
| 1283 | 
 | 
|---|
| 1284 |         SMB_VFS_HANDLE_SET_DATA(handle, config,
 | 
|---|
| 1285 |                                 NULL, struct gpfs_config_data,
 | 
|---|
| 1286 |                                 return -1);
 | 
|---|
| 1287 | 
 | 
|---|
| 1288 |         return 0;
 | 
|---|
| 1289 | }
 | 
|---|
| 1290 | 
 | 
|---|
| 1291 | static uint32_t vfs_gpfs_capabilities(struct vfs_handle_struct *handle,
 | 
|---|
| 1292 |                                       enum timestamp_set_resolution *p_ts_res)
 | 
|---|
| 1293 | {
 | 
|---|
| 1294 |         struct gpfs_config_data *config;
 | 
|---|
| 1295 |         uint32_t next;
 | 
|---|
| 1296 | 
 | 
|---|
| 1297 |         next = SMB_VFS_NEXT_FS_CAPABILITIES(handle, p_ts_res);
 | 
|---|
| 1298 | 
 | 
|---|
| 1299 |         SMB_VFS_HANDLE_GET_DATA(handle, config,
 | 
|---|
| 1300 |                                 struct gpfs_config_data,
 | 
|---|
| 1301 |                                 return next);
 | 
|---|
| 1302 | 
 | 
|---|
| 1303 |         if (config->hsm) {
 | 
|---|
| 1304 |                 next |= FILE_SUPPORTS_REMOTE_STORAGE;
 | 
|---|
| 1305 |         }
 | 
|---|
| 1306 |         return next;
 | 
|---|
| 1307 | }
 | 
|---|
| 1308 | 
 | 
|---|
| 1309 | static int vfs_gpfs_open(struct vfs_handle_struct *handle,
 | 
|---|
| 1310 |                          struct smb_filename *smb_fname, files_struct *fsp,
 | 
|---|
| 1311 |                          int flags, mode_t mode)
 | 
|---|
| 1312 | {
 | 
|---|
| 1313 |         if (lp_parm_bool(fsp->conn->params->service, "gpfs", "syncio",
 | 
|---|
| 1314 |                          false)) {
 | 
|---|
| 1315 |                 flags |= O_SYNC;
 | 
|---|
| 1316 |         }
 | 
|---|
| 1317 |         return SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
 | 
|---|
| 1318 | }
 | 
|---|
| 1319 | 
 | 
|---|
| 1320 | 
 | 
|---|
| 1321 | static struct vfs_fn_pointers vfs_gpfs_fns = {
 | 
|---|
| 1322 |         .connect_fn = vfs_gpfs_connect,
 | 
|---|
| 1323 |         .fs_capabilities = vfs_gpfs_capabilities,
 | 
|---|
| 1324 |         .kernel_flock = vfs_gpfs_kernel_flock,
 | 
|---|
| 1325 |         .linux_setlease = vfs_gpfs_setlease,
 | 
|---|
| 1326 |         .get_real_filename = vfs_gpfs_get_real_filename,
 | 
|---|
| 1327 |         .fget_nt_acl = gpfsacl_fget_nt_acl,
 | 
|---|
| 1328 |         .get_nt_acl = gpfsacl_get_nt_acl,
 | 
|---|
| 1329 |         .fset_nt_acl = gpfsacl_fset_nt_acl,
 | 
|---|
| 1330 |         .sys_acl_get_file = gpfsacl_sys_acl_get_file,
 | 
|---|
| 1331 |         .sys_acl_get_fd = gpfsacl_sys_acl_get_fd,
 | 
|---|
| 1332 |         .sys_acl_set_file = gpfsacl_sys_acl_set_file,
 | 
|---|
| 1333 |         .sys_acl_set_fd = gpfsacl_sys_acl_set_fd,
 | 
|---|
| 1334 |         .sys_acl_delete_def_file = gpfsacl_sys_acl_delete_def_file,
 | 
|---|
| 1335 |         .chmod = vfs_gpfs_chmod,
 | 
|---|
| 1336 |         .fchmod = vfs_gpfs_fchmod,
 | 
|---|
| 1337 |         .close_fn = vfs_gpfs_close,
 | 
|---|
| 1338 |         .setxattr = gpfs_set_xattr,
 | 
|---|
| 1339 |         .getxattr = gpfs_get_xattr,
 | 
|---|
| 1340 |         .stat = vfs_gpfs_stat,
 | 
|---|
| 1341 |         .fstat = vfs_gpfs_fstat,
 | 
|---|
| 1342 |         .lstat = vfs_gpfs_lstat,
 | 
|---|
| 1343 |         .ntimes = vfs_gpfs_ntimes,
 | 
|---|
| 1344 |         .is_offline = vfs_gpfs_is_offline,
 | 
|---|
| 1345 |         .aio_force = vfs_gpfs_aio_force,
 | 
|---|
| 1346 |         .sendfile = vfs_gpfs_sendfile,
 | 
|---|
| 1347 |         .open_fn = vfs_gpfs_open,
 | 
|---|
| 1348 |         .ftruncate = vfs_gpfs_ftruncate
 | 
|---|
| 1349 | };
 | 
|---|
| 1350 | 
 | 
|---|
| 1351 | NTSTATUS vfs_gpfs_init(void);
 | 
|---|
| 1352 | NTSTATUS vfs_gpfs_init(void)
 | 
|---|
| 1353 | {
 | 
|---|
| 1354 |         init_gpfs();
 | 
|---|
| 1355 | 
 | 
|---|
| 1356 |         return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "gpfs",
 | 
|---|
| 1357 |                                 &vfs_gpfs_fns);
 | 
|---|
| 1358 | }
 | 
|---|