| 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 2 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, write to the Free Software
|
|---|
| 22 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 | */
|
|---|
| 26 |
|
|---|
| 27 | #include "includes.h"
|
|---|
| 28 |
|
|---|
| 29 | #undef DBGC_CLASS
|
|---|
| 30 | #define DBGC_CLASS DBGC_VFS
|
|---|
| 31 |
|
|---|
| 32 | #include <gpfs_gpl.h>
|
|---|
| 33 | #include "nfs4_acls.h"
|
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 | static int vfs_gpfs_kernel_flock(vfs_handle_struct *handle, files_struct *fsp,
|
|---|
| 37 | int fd, uint32 share_mode)
|
|---|
| 38 | {
|
|---|
| 39 |
|
|---|
| 40 | START_PROFILE(syscall_kernel_flock);
|
|---|
| 41 |
|
|---|
| 42 | kernel_flock(fsp->fh->fd, share_mode);
|
|---|
| 43 |
|
|---|
| 44 | if (!set_gpfs_sharemode(fsp, fsp->access_mask, fsp->share_access)) {
|
|---|
| 45 |
|
|---|
| 46 | return -1;
|
|---|
| 47 |
|
|---|
| 48 | }
|
|---|
| 49 |
|
|---|
| 50 | END_PROFILE(syscall_kernel_flock);
|
|---|
| 51 |
|
|---|
| 52 | return 0;
|
|---|
| 53 | }
|
|---|
| 54 |
|
|---|
| 55 | static int vfs_gpfs_setlease(vfs_handle_struct *handle, files_struct *fsp,
|
|---|
| 56 | int fd, int leasetype)
|
|---|
| 57 | {
|
|---|
| 58 | int ret;
|
|---|
| 59 |
|
|---|
| 60 | START_PROFILE(syscall_linux_setlease);
|
|---|
| 61 |
|
|---|
| 62 | if ( linux_set_lease_sighandler(fd) == -1)
|
|---|
| 63 | return -1;
|
|---|
| 64 |
|
|---|
| 65 | ret = set_gpfs_lease(fd,leasetype);
|
|---|
| 66 |
|
|---|
| 67 | if ( ret < 0 ) {
|
|---|
| 68 | /* This must have come from GPFS not being available */
|
|---|
| 69 | /* or some other error, hence call the default */
|
|---|
| 70 | ret = linux_setlease(fd, leasetype);
|
|---|
| 71 | }
|
|---|
| 72 |
|
|---|
| 73 | END_PROFILE(syscall_linux_setlease);
|
|---|
| 74 |
|
|---|
| 75 | return ret;
|
|---|
| 76 | }
|
|---|
| 77 |
|
|---|
| 78 |
|
|---|
| 79 |
|
|---|
| 80 | static void gpfs_dumpacl(int level, struct gpfs_acl *gacl)
|
|---|
| 81 | {
|
|---|
| 82 | int i;
|
|---|
| 83 | if (gacl==NULL)
|
|---|
| 84 | {
|
|---|
| 85 | DEBUG(0, ("gpfs acl is NULL\n"));
|
|---|
| 86 | return;
|
|---|
| 87 | }
|
|---|
| 88 |
|
|---|
| 89 | DEBUG(level, ("gpfs acl: nace: %d, type:%d, version:%d, level:%d, len:%d\n",
|
|---|
| 90 | gacl->acl_nace, gacl->acl_type, gacl->acl_version, gacl->acl_level, gacl->acl_len));
|
|---|
| 91 | for(i=0; i<gacl->acl_nace; i++)
|
|---|
| 92 | {
|
|---|
| 93 | struct gpfs_ace_v4 *gace = gacl->ace_v4 + i;
|
|---|
| 94 | DEBUG(level, ("\tace[%d]: type:%d, flags:0x%x, mask:0x%x, iflags:0x%x, who:%u\n",
|
|---|
| 95 | i, gace->aceType, gace->aceFlags, gace->aceMask,
|
|---|
| 96 | gace->aceIFlags, gace->aceWho));
|
|---|
| 97 | }
|
|---|
| 98 | }
|
|---|
| 99 |
|
|---|
| 100 | static struct gpfs_acl *gpfs_getacl_alloc(const char *fname, gpfs_aclType_t type)
|
|---|
| 101 | {
|
|---|
| 102 | struct gpfs_acl *acl;
|
|---|
| 103 | size_t len = 200;
|
|---|
| 104 | int ret;
|
|---|
| 105 | TALLOC_CTX *mem_ctx = main_loop_talloc_get();
|
|---|
| 106 |
|
|---|
| 107 | acl = (struct gpfs_acl *)TALLOC_SIZE(mem_ctx, len);
|
|---|
| 108 | if (acl == NULL) {
|
|---|
| 109 | errno = ENOMEM;
|
|---|
| 110 | return NULL;
|
|---|
| 111 | }
|
|---|
| 112 |
|
|---|
| 113 | acl->acl_len = len;
|
|---|
| 114 | acl->acl_level = 0;
|
|---|
| 115 | acl->acl_version = 0;
|
|---|
| 116 | acl->acl_type = type;
|
|---|
| 117 |
|
|---|
| 118 | ret = smbd_gpfs_getacl((char *)fname, GPFS_GETACL_STRUCT | GPFS_ACL_SAMBA, acl);
|
|---|
| 119 | if ((ret != 0) && (errno == ENOSPC)) {
|
|---|
| 120 | struct gpfs_acl *new_acl = (struct gpfs_acl *)TALLOC_SIZE(
|
|---|
| 121 | mem_ctx, acl->acl_len + sizeof(struct gpfs_acl));
|
|---|
| 122 | if (new_acl == NULL) {
|
|---|
| 123 | errno = ENOMEM;
|
|---|
| 124 | return NULL;
|
|---|
| 125 | }
|
|---|
| 126 |
|
|---|
| 127 | new_acl->acl_len = acl->acl_len;
|
|---|
| 128 | new_acl->acl_level = acl->acl_level;
|
|---|
| 129 | new_acl->acl_version = acl->acl_version;
|
|---|
| 130 | new_acl->acl_type = acl->acl_type;
|
|---|
| 131 | acl = new_acl;
|
|---|
| 132 |
|
|---|
| 133 | ret = smbd_gpfs_getacl((char *)fname, GPFS_GETACL_STRUCT | GPFS_ACL_SAMBA, acl);
|
|---|
| 134 | }
|
|---|
| 135 | if (ret != 0)
|
|---|
| 136 | {
|
|---|
| 137 | DEBUG(8, ("smbd_gpfs_getacl failed with %s\n",strerror(errno)));
|
|---|
| 138 | return NULL;
|
|---|
| 139 | }
|
|---|
| 140 |
|
|---|
| 141 | return acl;
|
|---|
| 142 | }
|
|---|
| 143 |
|
|---|
| 144 | static BOOL gpfs_get_nfs4_acl(struct files_struct *fsp, SMB4ACL_T **ppacl, BOOL *pretryPosix)
|
|---|
| 145 | {
|
|---|
| 146 | TALLOC_CTX *mem_ctx;
|
|---|
| 147 | int i;
|
|---|
| 148 | struct gpfs_acl *gacl = NULL;
|
|---|
| 149 |
|
|---|
| 150 | mem_ctx = main_loop_talloc_get();
|
|---|
| 151 |
|
|---|
| 152 | DEBUG(10, ("gpfs_get_nfs4_acl invoked for %s\n", fsp->fsp_name));
|
|---|
| 153 |
|
|---|
| 154 | /* First get the real acl length */
|
|---|
| 155 | gacl = gpfs_getacl_alloc(fsp->fsp_name, GPFS_ACL_TYPE_NFS4);
|
|---|
| 156 | if (gacl == NULL) {
|
|---|
| 157 | DEBUG(9, ("gpfs_getacl failed for %s with %s\n",
|
|---|
| 158 | fsp->fsp_name, strerror(errno)));
|
|---|
| 159 | return False;
|
|---|
| 160 | }
|
|---|
| 161 |
|
|---|
| 162 | if (gacl->acl_type != GPFS_ACL_TYPE_NFS4) {
|
|---|
| 163 | DEBUG(10, ("Got non-nfsv4 acl\n"));
|
|---|
| 164 | *pretryPosix = True;
|
|---|
| 165 | return False;
|
|---|
| 166 | }
|
|---|
| 167 |
|
|---|
| 168 | *ppacl = smb_create_smb4acl();
|
|---|
| 169 |
|
|---|
| 170 | DEBUG(10, ("len: %d, level: %d, version: %d, nace: %d\n",
|
|---|
| 171 | gacl->acl_len, gacl->acl_level, gacl->acl_version,
|
|---|
| 172 | gacl->acl_nace));
|
|---|
| 173 |
|
|---|
| 174 | for (i=0; i<gacl->acl_nace; i++) {
|
|---|
| 175 | struct gpfs_ace_v4 *gace = &gacl->ace_v4[i];
|
|---|
| 176 | SMB_ACE4PROP_T smbace;
|
|---|
| 177 | memset(&smbace, 0, sizeof(SMB4ACE_T));
|
|---|
| 178 |
|
|---|
| 179 | DEBUG(10, ("type: %d, iflags: %x, flags: %x, mask: %x, "
|
|---|
| 180 | "who: %d\n", gace->aceType, gace->aceIFlags,
|
|---|
| 181 | gace->aceFlags, gace->aceMask, gace->aceWho));
|
|---|
| 182 |
|
|---|
| 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 | smbace.aceType = gace->aceType;
|
|---|
| 208 | smbace.aceFlags = gace->aceFlags;
|
|---|
| 209 | smbace.aceMask = gace->aceMask;
|
|---|
| 210 | smbace.flags = (gace->aceIFlags&ACE4_IFLAG_SPECIAL_ID) ? SMB_ACE4_ID_SPECIAL : 0;
|
|---|
| 211 |
|
|---|
| 212 | smb_add_ace4(*ppacl, &smbace);
|
|---|
| 213 | }
|
|---|
| 214 |
|
|---|
| 215 | return True;
|
|---|
| 216 | }
|
|---|
| 217 |
|
|---|
| 218 | static size_t gpfsacl_get_nt_acl_common(files_struct *fsp,
|
|---|
| 219 | uint32 security_info, SEC_DESC **ppdesc)
|
|---|
| 220 | {
|
|---|
| 221 | SMB4ACL_T *pacl = NULL;
|
|---|
| 222 | BOOL result;
|
|---|
| 223 | BOOL retryPosix = False;
|
|---|
| 224 |
|
|---|
| 225 | *ppdesc = NULL;
|
|---|
| 226 | result = gpfs_get_nfs4_acl(fsp, &pacl, &retryPosix);
|
|---|
| 227 | if (retryPosix)
|
|---|
| 228 | {
|
|---|
| 229 | DEBUG(10, ("retrying with posix acl...\n"));
|
|---|
| 230 | return get_nt_acl(fsp, security_info, ppdesc);
|
|---|
| 231 | }
|
|---|
| 232 | if (result==False)
|
|---|
| 233 | return 0;
|
|---|
| 234 |
|
|---|
| 235 | return smb_get_nt_acl_nfs4(fsp, security_info, ppdesc, pacl);
|
|---|
| 236 | }
|
|---|
| 237 |
|
|---|
| 238 | size_t gpfsacl_fget_nt_acl(vfs_handle_struct *handle,
|
|---|
| 239 | files_struct *fsp, int fd, uint32 security_info,
|
|---|
| 240 | SEC_DESC **ppdesc)
|
|---|
| 241 | {
|
|---|
| 242 | return gpfsacl_get_nt_acl_common(fsp, security_info, ppdesc);
|
|---|
| 243 | }
|
|---|
| 244 |
|
|---|
| 245 | size_t gpfsacl_get_nt_acl(vfs_handle_struct *handle,
|
|---|
| 246 | files_struct *fsp, const char *name,
|
|---|
| 247 | uint32 security_info, SEC_DESC **ppdesc)
|
|---|
| 248 | {
|
|---|
| 249 | return gpfsacl_get_nt_acl_common(fsp, security_info, ppdesc);
|
|---|
| 250 | }
|
|---|
| 251 |
|
|---|
| 252 | static BOOL gpfsacl_process_smbacl(files_struct *fsp, SMB4ACL_T *smbacl)
|
|---|
| 253 | {
|
|---|
| 254 | int ret;
|
|---|
| 255 | gpfs_aclLen_t gacl_len;
|
|---|
| 256 | SMB4ACE_T *smbace;
|
|---|
| 257 | struct gpfs_acl *gacl;
|
|---|
| 258 | TALLOC_CTX *mem_ctx = main_loop_talloc_get();
|
|---|
| 259 |
|
|---|
| 260 | gacl_len = sizeof(struct gpfs_acl) +
|
|---|
| 261 | (smb_get_naces(smbacl)-1)*sizeof(gpfs_ace_v4_t);
|
|---|
| 262 |
|
|---|
| 263 | gacl = TALLOC_SIZE(mem_ctx, gacl_len);
|
|---|
| 264 | if (gacl == NULL) {
|
|---|
| 265 | DEBUG(0, ("talloc failed\n"));
|
|---|
| 266 | errno = ENOMEM;
|
|---|
| 267 | return False;
|
|---|
| 268 | }
|
|---|
| 269 |
|
|---|
| 270 | gacl->acl_len = gacl_len;
|
|---|
| 271 | gacl->acl_level = 0;
|
|---|
| 272 | gacl->acl_version = GPFS_ACL_VERSION_NFS4;
|
|---|
| 273 | gacl->acl_type = GPFS_ACL_TYPE_NFS4;
|
|---|
| 274 | gacl->acl_nace = 0; /* change later... */
|
|---|
| 275 |
|
|---|
| 276 | for (smbace=smb_first_ace4(smbacl); smbace!=NULL; smbace = smb_next_ace4(smbace)) {
|
|---|
| 277 | struct gpfs_ace_v4 *gace = &gacl->ace_v4[gacl->acl_nace];
|
|---|
| 278 | SMB_ACE4PROP_T *aceprop = smb_get_ace4(smbace);
|
|---|
| 279 |
|
|---|
| 280 | gace->aceType = aceprop->aceType;
|
|---|
| 281 | gace->aceFlags = aceprop->aceFlags;
|
|---|
| 282 | gace->aceMask = aceprop->aceMask;
|
|---|
| 283 | gace->aceIFlags = (aceprop->flags&SMB_ACE4_ID_SPECIAL) ? ACE4_IFLAG_SPECIAL_ID : 0;
|
|---|
| 284 |
|
|---|
| 285 | if (aceprop->flags&SMB_ACE4_ID_SPECIAL)
|
|---|
| 286 | {
|
|---|
| 287 | switch(aceprop->who.special_id)
|
|---|
| 288 | {
|
|---|
| 289 | case SMB_ACE4_WHO_EVERYONE:
|
|---|
| 290 | gace->aceWho = ACE4_SPECIAL_EVERYONE;
|
|---|
| 291 | break;
|
|---|
| 292 | case SMB_ACE4_WHO_OWNER:
|
|---|
| 293 | gace->aceWho = ACE4_SPECIAL_OWNER;
|
|---|
| 294 | break;
|
|---|
| 295 | case SMB_ACE4_WHO_GROUP:
|
|---|
| 296 | gace->aceWho = ACE4_SPECIAL_GROUP;
|
|---|
| 297 | break;
|
|---|
| 298 | default:
|
|---|
| 299 | DEBUG(8, ("unsupported special_id %d\n", aceprop->who.special_id));
|
|---|
| 300 | continue; /* don't add it !!! */
|
|---|
| 301 | }
|
|---|
| 302 | } else {
|
|---|
| 303 | /* just only for the type safety... */
|
|---|
| 304 | if (aceprop->aceFlags&SMB_ACE4_IDENTIFIER_GROUP)
|
|---|
| 305 | gace->aceWho = aceprop->who.gid;
|
|---|
| 306 | else
|
|---|
| 307 | gace->aceWho = aceprop->who.uid;
|
|---|
| 308 | }
|
|---|
| 309 |
|
|---|
| 310 | gacl->acl_nace++;
|
|---|
| 311 | }
|
|---|
| 312 |
|
|---|
| 313 | ret = smbd_gpfs_putacl(fsp->fsp_name, GPFS_PUTACL_STRUCT | GPFS_ACL_SAMBA, gacl);
|
|---|
| 314 | if (ret != 0) {
|
|---|
| 315 | DEBUG(8, ("gpfs_putacl failed with %s\n", strerror(errno)));
|
|---|
| 316 | gpfs_dumpacl(8, gacl);
|
|---|
| 317 | return False;
|
|---|
| 318 | }
|
|---|
| 319 |
|
|---|
| 320 | DEBUG(10, ("gpfs_putacl succeeded\n"));
|
|---|
| 321 | return True;
|
|---|
| 322 | }
|
|---|
| 323 |
|
|---|
| 324 | static BOOL gpfsacl_set_nt_acl_internal(files_struct *fsp, uint32 security_info_sent, SEC_DESC *psd)
|
|---|
| 325 | {
|
|---|
| 326 | struct gpfs_acl *acl;
|
|---|
| 327 | BOOL result = False;
|
|---|
| 328 |
|
|---|
| 329 | acl = gpfs_getacl_alloc(fsp->fsp_name, GPFS_ACL_TYPE_ACCESS);
|
|---|
| 330 | if (acl == NULL)
|
|---|
| 331 | return False;
|
|---|
| 332 |
|
|---|
| 333 | if (acl->acl_version&GPFS_ACL_VERSION_NFS4)
|
|---|
| 334 | {
|
|---|
| 335 | result = smb_set_nt_acl_nfs4(
|
|---|
| 336 | fsp, security_info_sent, psd,
|
|---|
| 337 | gpfsacl_process_smbacl);
|
|---|
| 338 | } else { /* assume POSIX ACL - by default... */
|
|---|
| 339 | result = set_nt_acl(fsp, security_info_sent, psd);
|
|---|
| 340 | }
|
|---|
| 341 |
|
|---|
| 342 | return result;
|
|---|
| 343 | }
|
|---|
| 344 |
|
|---|
| 345 | static BOOL gpfsacl_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp, int fd, uint32 security_info_sent, SEC_DESC *psd)
|
|---|
| 346 | {
|
|---|
| 347 | return gpfsacl_set_nt_acl_internal(fsp, security_info_sent, psd);
|
|---|
| 348 | }
|
|---|
| 349 |
|
|---|
| 350 | static BOOL gpfsacl_set_nt_acl(vfs_handle_struct *handle, files_struct *fsp, char *name, uint32 security_info_sent, SEC_DESC *psd)
|
|---|
| 351 | {
|
|---|
| 352 | return gpfsacl_set_nt_acl_internal(fsp, security_info_sent, psd);
|
|---|
| 353 | }
|
|---|
| 354 |
|
|---|
| 355 | static SMB_ACL_T gpfs2smb_acl(const struct gpfs_acl *pacl)
|
|---|
| 356 | {
|
|---|
| 357 | SMB_ACL_T result;
|
|---|
| 358 | int i;
|
|---|
| 359 |
|
|---|
| 360 | result = sys_acl_init(pacl->acl_nace);
|
|---|
| 361 | if (result == NULL) {
|
|---|
| 362 | errno = ENOMEM;
|
|---|
| 363 | return NULL;
|
|---|
| 364 | }
|
|---|
| 365 |
|
|---|
| 366 | result->count = pacl->acl_nace;
|
|---|
| 367 |
|
|---|
| 368 | for (i=0; i<pacl->acl_nace; i++) {
|
|---|
| 369 | struct smb_acl_entry *ace = &result->acl[i];
|
|---|
| 370 | const struct gpfs_ace_v1 *g_ace = &pacl->ace_v1[i];
|
|---|
| 371 |
|
|---|
| 372 | DEBUG(10, ("Converting type %d id %lu perm %x\n",
|
|---|
| 373 | (int)g_ace->ace_type, (unsigned long)g_ace->ace_who,
|
|---|
| 374 | (int)g_ace->ace_perm));
|
|---|
| 375 |
|
|---|
| 376 | switch (g_ace->ace_type) {
|
|---|
| 377 | case GPFS_ACL_USER:
|
|---|
| 378 | ace->a_type = SMB_ACL_USER;
|
|---|
| 379 | ace->uid = (uid_t)g_ace->ace_who;
|
|---|
| 380 | break;
|
|---|
| 381 | case GPFS_ACL_USER_OBJ:
|
|---|
| 382 | ace->a_type = SMB_ACL_USER_OBJ;
|
|---|
| 383 | break;
|
|---|
| 384 | case GPFS_ACL_GROUP:
|
|---|
| 385 | ace->a_type = SMB_ACL_GROUP;
|
|---|
| 386 | ace->gid = (gid_t)g_ace->ace_who;
|
|---|
| 387 | break;
|
|---|
| 388 | case GPFS_ACL_GROUP_OBJ:
|
|---|
| 389 | ace->a_type = SMB_ACL_GROUP_OBJ;
|
|---|
| 390 | break;
|
|---|
| 391 | case GPFS_ACL_OTHER:
|
|---|
| 392 | ace->a_type = SMB_ACL_OTHER;
|
|---|
| 393 | break;
|
|---|
| 394 | case GPFS_ACL_MASK:
|
|---|
| 395 | ace->a_type = SMB_ACL_MASK;
|
|---|
| 396 | break;
|
|---|
| 397 | default:
|
|---|
| 398 | DEBUG(10, ("Got invalid ace_type: %d\n",
|
|---|
| 399 | g_ace->ace_type));
|
|---|
| 400 | errno = EINVAL;
|
|---|
| 401 | SAFE_FREE(result);
|
|---|
| 402 | return NULL;
|
|---|
| 403 | }
|
|---|
| 404 |
|
|---|
| 405 | ace->a_perm = 0;
|
|---|
| 406 | ace->a_perm |= (g_ace->ace_perm & ACL_PERM_READ) ?
|
|---|
| 407 | SMB_ACL_READ : 0;
|
|---|
| 408 | ace->a_perm |= (g_ace->ace_perm & ACL_PERM_WRITE) ?
|
|---|
| 409 | SMB_ACL_WRITE : 0;
|
|---|
| 410 | ace->a_perm |= (g_ace->ace_perm & ACL_PERM_EXECUTE) ?
|
|---|
| 411 | SMB_ACL_EXECUTE : 0;
|
|---|
| 412 |
|
|---|
| 413 | DEBUGADD(10, ("Converted to %d perm %x\n",
|
|---|
| 414 | ace->a_type, ace->a_perm));
|
|---|
| 415 | }
|
|---|
| 416 |
|
|---|
| 417 | return result;
|
|---|
| 418 | }
|
|---|
| 419 |
|
|---|
| 420 | static SMB_ACL_T gpfsacl_get_posix_acl(const char *path, gpfs_aclType_t type)
|
|---|
| 421 | {
|
|---|
| 422 | struct gpfs_acl *pacl;
|
|---|
| 423 | SMB_ACL_T result = NULL;
|
|---|
| 424 |
|
|---|
| 425 | pacl = gpfs_getacl_alloc(path, type);
|
|---|
| 426 |
|
|---|
| 427 | if (pacl == NULL) {
|
|---|
| 428 | DEBUG(10, ("gpfs_getacl failed for %s with %s\n",
|
|---|
| 429 | path, strerror(errno)));
|
|---|
| 430 | if (errno == 0) {
|
|---|
| 431 | errno = EINVAL;
|
|---|
| 432 | }
|
|---|
| 433 | goto done;
|
|---|
| 434 | }
|
|---|
| 435 |
|
|---|
| 436 | if (pacl->acl_version != GPFS_ACL_VERSION_POSIX) {
|
|---|
| 437 | DEBUG(10, ("Got acl version %d, expected %d\n",
|
|---|
| 438 | pacl->acl_version, GPFS_ACL_VERSION_POSIX));
|
|---|
| 439 | errno = EINVAL;
|
|---|
| 440 | goto done;
|
|---|
| 441 | }
|
|---|
| 442 |
|
|---|
| 443 | DEBUG(10, ("len: %d, level: %d, version: %d, nace: %d\n",
|
|---|
| 444 | pacl->acl_len, pacl->acl_level, pacl->acl_version,
|
|---|
| 445 | pacl->acl_nace));
|
|---|
| 446 |
|
|---|
| 447 | result = gpfs2smb_acl(pacl);
|
|---|
| 448 | if (result == NULL) {
|
|---|
| 449 | goto done;
|
|---|
| 450 | }
|
|---|
| 451 |
|
|---|
| 452 | done:
|
|---|
| 453 |
|
|---|
| 454 | if (errno != 0) {
|
|---|
| 455 | SAFE_FREE(result);
|
|---|
| 456 | }
|
|---|
| 457 | return result;
|
|---|
| 458 | }
|
|---|
| 459 |
|
|---|
| 460 | SMB_ACL_T gpfsacl_sys_acl_get_file(vfs_handle_struct *handle,
|
|---|
| 461 |
|
|---|
| 462 | const char *path_p,
|
|---|
| 463 | SMB_ACL_TYPE_T type)
|
|---|
| 464 | {
|
|---|
| 465 | gpfs_aclType_t gpfs_type;
|
|---|
| 466 |
|
|---|
| 467 | switch(type) {
|
|---|
| 468 | case SMB_ACL_TYPE_ACCESS:
|
|---|
| 469 | gpfs_type = GPFS_ACL_TYPE_ACCESS;
|
|---|
| 470 | break;
|
|---|
| 471 | case SMB_ACL_TYPE_DEFAULT:
|
|---|
| 472 | gpfs_type = GPFS_ACL_TYPE_DEFAULT;
|
|---|
| 473 | break;
|
|---|
| 474 | default:
|
|---|
| 475 | DEBUG(0, ("Got invalid type: %d\n", type));
|
|---|
| 476 | smb_panic("exiting");
|
|---|
| 477 | }
|
|---|
| 478 |
|
|---|
| 479 | return gpfsacl_get_posix_acl(path_p, gpfs_type);
|
|---|
| 480 | }
|
|---|
| 481 |
|
|---|
| 482 | SMB_ACL_T gpfsacl_sys_acl_get_fd(vfs_handle_struct *handle,
|
|---|
| 483 | files_struct *fsp,
|
|---|
| 484 | int fd)
|
|---|
| 485 | {
|
|---|
| 486 | return gpfsacl_get_posix_acl(fsp->fsp_name, GPFS_ACL_TYPE_ACCESS);
|
|---|
| 487 | }
|
|---|
| 488 |
|
|---|
| 489 | static struct gpfs_acl *smb2gpfs_acl(const SMB_ACL_T pacl,
|
|---|
| 490 | SMB_ACL_TYPE_T type)
|
|---|
| 491 | {
|
|---|
| 492 | gpfs_aclLen_t len;
|
|---|
| 493 | struct gpfs_acl *result;
|
|---|
| 494 | int i;
|
|---|
| 495 | union gpfs_ace_union
|
|---|
| 496 | {
|
|---|
| 497 | gpfs_ace_v1_t ace_v1[1]; /* when GPFS_ACL_VERSION_POSIX */
|
|---|
| 498 | gpfs_ace_v4_t ace_v4[1]; /* when GPFS_ACL_VERSION_NFS4 */
|
|---|
| 499 | };
|
|---|
| 500 |
|
|---|
| 501 | DEBUG(10, ("smb2gpfs_acl: Got ACL with %d entries\n", pacl->count));
|
|---|
| 502 |
|
|---|
| 503 | len = sizeof(struct gpfs_acl) - sizeof(union gpfs_ace_union) +
|
|---|
| 504 | (pacl->count)*sizeof(gpfs_ace_v1_t);
|
|---|
| 505 |
|
|---|
| 506 | result = SMB_MALLOC(len);
|
|---|
| 507 | if (result == NULL) {
|
|---|
| 508 | errno = ENOMEM;
|
|---|
| 509 | return result;
|
|---|
| 510 | }
|
|---|
| 511 |
|
|---|
| 512 | result->acl_len = len;
|
|---|
| 513 | result->acl_level = 0;
|
|---|
| 514 | result->acl_version = GPFS_ACL_VERSION_POSIX;
|
|---|
| 515 | result->acl_type = (type == SMB_ACL_TYPE_DEFAULT) ?
|
|---|
| 516 | GPFS_ACL_TYPE_DEFAULT : GPFS_ACL_TYPE_ACCESS;
|
|---|
| 517 | result->acl_nace = pacl->count;
|
|---|
| 518 |
|
|---|
| 519 | for (i=0; i<pacl->count; i++) {
|
|---|
| 520 | const struct smb_acl_entry *ace = &pacl->acl[i];
|
|---|
| 521 | struct gpfs_ace_v1 *g_ace = &result->ace_v1[i];
|
|---|
| 522 |
|
|---|
| 523 | DEBUG(10, ("Converting type %d perm %x\n",
|
|---|
| 524 | (int)ace->a_type, (int)ace->a_perm));
|
|---|
| 525 |
|
|---|
| 526 | g_ace->ace_perm = 0;
|
|---|
| 527 |
|
|---|
| 528 | switch(ace->a_type) {
|
|---|
| 529 | case SMB_ACL_USER:
|
|---|
| 530 | g_ace->ace_type = GPFS_ACL_USER;
|
|---|
| 531 | g_ace->ace_who = (gpfs_uid_t)ace->uid;
|
|---|
| 532 | break;
|
|---|
| 533 | case SMB_ACL_USER_OBJ:
|
|---|
| 534 | g_ace->ace_type = GPFS_ACL_USER_OBJ;
|
|---|
| 535 | g_ace->ace_perm |= ACL_PERM_CONTROL;
|
|---|
| 536 | g_ace->ace_who = 0;
|
|---|
| 537 | break;
|
|---|
| 538 | case SMB_ACL_GROUP:
|
|---|
| 539 | g_ace->ace_type = GPFS_ACL_GROUP;
|
|---|
| 540 | g_ace->ace_who = (gpfs_uid_t)ace->gid;
|
|---|
| 541 | break;
|
|---|
| 542 | case SMB_ACL_GROUP_OBJ:
|
|---|
| 543 | g_ace->ace_type = GPFS_ACL_GROUP_OBJ;
|
|---|
| 544 | g_ace->ace_who = 0;
|
|---|
| 545 | break;
|
|---|
| 546 | case SMB_ACL_MASK:
|
|---|
| 547 | g_ace->ace_type = GPFS_ACL_MASK;
|
|---|
| 548 | g_ace->ace_perm = 0x8f;
|
|---|
| 549 | g_ace->ace_who = 0;
|
|---|
| 550 | break;
|
|---|
| 551 | case SMB_ACL_OTHER:
|
|---|
| 552 | g_ace->ace_type = GPFS_ACL_OTHER;
|
|---|
| 553 | g_ace->ace_who = 0;
|
|---|
| 554 | break;
|
|---|
| 555 | default:
|
|---|
| 556 | DEBUG(10, ("Got invalid ace_type: %d\n", ace->a_type));
|
|---|
| 557 | errno = EINVAL;
|
|---|
| 558 | SAFE_FREE(result);
|
|---|
| 559 | return NULL;
|
|---|
| 560 | }
|
|---|
| 561 |
|
|---|
| 562 | g_ace->ace_perm |= (ace->a_perm & SMB_ACL_READ) ?
|
|---|
| 563 | ACL_PERM_READ : 0;
|
|---|
| 564 | g_ace->ace_perm |= (ace->a_perm & SMB_ACL_WRITE) ?
|
|---|
| 565 | ACL_PERM_WRITE : 0;
|
|---|
| 566 | g_ace->ace_perm |= (ace->a_perm & SMB_ACL_EXECUTE) ?
|
|---|
| 567 | ACL_PERM_EXECUTE : 0;
|
|---|
| 568 |
|
|---|
| 569 | DEBUGADD(10, ("Converted to %d id %d perm %x\n",
|
|---|
| 570 | g_ace->ace_type, g_ace->ace_who, g_ace->ace_perm));
|
|---|
| 571 | }
|
|---|
| 572 |
|
|---|
| 573 | return result;
|
|---|
| 574 | }
|
|---|
| 575 |
|
|---|
| 576 | int gpfsacl_sys_acl_set_file(vfs_handle_struct *handle,
|
|---|
| 577 |
|
|---|
| 578 | const char *name,
|
|---|
| 579 | SMB_ACL_TYPE_T type,
|
|---|
| 580 | SMB_ACL_T theacl)
|
|---|
| 581 | {
|
|---|
| 582 | struct gpfs_acl *gpfs_acl;
|
|---|
| 583 | int result;
|
|---|
| 584 |
|
|---|
| 585 | gpfs_acl = smb2gpfs_acl(theacl, type);
|
|---|
| 586 | if (gpfs_acl == NULL) {
|
|---|
| 587 | return -1;
|
|---|
| 588 | }
|
|---|
| 589 |
|
|---|
| 590 | result = smbd_gpfs_putacl((char *)name, GPFS_PUTACL_STRUCT | GPFS_ACL_SAMBA, gpfs_acl);
|
|---|
| 591 |
|
|---|
| 592 | SAFE_FREE(gpfs_acl);
|
|---|
| 593 | return result;
|
|---|
| 594 | }
|
|---|
| 595 |
|
|---|
| 596 | int gpfsacl_sys_acl_set_fd(vfs_handle_struct *handle,
|
|---|
| 597 | files_struct *fsp,
|
|---|
| 598 | int fd, SMB_ACL_T theacl)
|
|---|
| 599 | {
|
|---|
| 600 | return gpfsacl_sys_acl_set_file(handle, fsp->fsp_name, SMB_ACL_TYPE_ACCESS, theacl);
|
|---|
| 601 | }
|
|---|
| 602 |
|
|---|
| 603 | int gpfsacl_sys_acl_delete_def_file(vfs_handle_struct *handle,
|
|---|
| 604 |
|
|---|
| 605 | const char *path)
|
|---|
| 606 | {
|
|---|
| 607 | errno = ENOTSUP;
|
|---|
| 608 | return -1;
|
|---|
| 609 | }
|
|---|
| 610 |
|
|---|
| 611 | /* VFS operations structure */
|
|---|
| 612 |
|
|---|
| 613 | static vfs_op_tuple gpfs_op_tuples[] = {
|
|---|
| 614 |
|
|---|
| 615 | {SMB_VFS_OP(vfs_gpfs_kernel_flock),
|
|---|
| 616 | SMB_VFS_OP_KERNEL_FLOCK,
|
|---|
| 617 | SMB_VFS_LAYER_OPAQUE},
|
|---|
| 618 |
|
|---|
| 619 | {SMB_VFS_OP(vfs_gpfs_setlease),
|
|---|
| 620 | SMB_VFS_OP_LINUX_SETLEASE,
|
|---|
| 621 | SMB_VFS_LAYER_OPAQUE},
|
|---|
| 622 |
|
|---|
| 623 | {SMB_VFS_OP(gpfsacl_fget_nt_acl),
|
|---|
| 624 | SMB_VFS_OP_FGET_NT_ACL,
|
|---|
| 625 | SMB_VFS_LAYER_TRANSPARENT},
|
|---|
| 626 |
|
|---|
| 627 | {SMB_VFS_OP(gpfsacl_get_nt_acl),
|
|---|
| 628 | SMB_VFS_OP_GET_NT_ACL,
|
|---|
| 629 | SMB_VFS_LAYER_TRANSPARENT},
|
|---|
| 630 |
|
|---|
| 631 | {SMB_VFS_OP(gpfsacl_fset_nt_acl),
|
|---|
| 632 | SMB_VFS_OP_FSET_NT_ACL,
|
|---|
| 633 | SMB_VFS_LAYER_TRANSPARENT},
|
|---|
| 634 |
|
|---|
| 635 | {SMB_VFS_OP(gpfsacl_set_nt_acl),
|
|---|
| 636 | SMB_VFS_OP_SET_NT_ACL,
|
|---|
| 637 | SMB_VFS_LAYER_TRANSPARENT},
|
|---|
| 638 |
|
|---|
| 639 | {SMB_VFS_OP(gpfsacl_sys_acl_get_file),
|
|---|
| 640 | SMB_VFS_OP_SYS_ACL_GET_FILE,
|
|---|
| 641 | SMB_VFS_LAYER_TRANSPARENT},
|
|---|
| 642 |
|
|---|
| 643 | {SMB_VFS_OP(gpfsacl_sys_acl_get_fd),
|
|---|
| 644 | SMB_VFS_OP_SYS_ACL_GET_FD,
|
|---|
| 645 | SMB_VFS_LAYER_TRANSPARENT},
|
|---|
| 646 |
|
|---|
| 647 | {SMB_VFS_OP(gpfsacl_sys_acl_set_file),
|
|---|
| 648 | SMB_VFS_OP_SYS_ACL_SET_FILE,
|
|---|
| 649 | SMB_VFS_LAYER_TRANSPARENT},
|
|---|
| 650 |
|
|---|
| 651 | {SMB_VFS_OP(gpfsacl_sys_acl_set_fd),
|
|---|
| 652 | SMB_VFS_OP_SYS_ACL_SET_FD,
|
|---|
| 653 | SMB_VFS_LAYER_TRANSPARENT},
|
|---|
| 654 |
|
|---|
| 655 | {SMB_VFS_OP(gpfsacl_sys_acl_delete_def_file),
|
|---|
| 656 | SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE,
|
|---|
| 657 | SMB_VFS_LAYER_TRANSPARENT},
|
|---|
| 658 |
|
|---|
| 659 | {SMB_VFS_OP(NULL),
|
|---|
| 660 | SMB_VFS_OP_NOOP,
|
|---|
| 661 | SMB_VFS_LAYER_NOOP}
|
|---|
| 662 |
|
|---|
| 663 | };
|
|---|
| 664 |
|
|---|
| 665 |
|
|---|
| 666 | NTSTATUS vfs_gpfs_init(void);
|
|---|
| 667 | NTSTATUS vfs_gpfs_init(void)
|
|---|
| 668 | {
|
|---|
| 669 | init_gpfs();
|
|---|
| 670 |
|
|---|
| 671 | return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "gpfs",
|
|---|
| 672 | gpfs_op_tuples);
|
|---|
| 673 | }
|
|---|