s3: VFS: Change SMB_VFS_SYMLINK to use const struct smb_filename * instead of const...
[sfrench/samba-autobuild/.git] / source3 / smbd / trans2.c
index e8346ba735a1d3790c176233302dbd981b102bb6..de6073a973fdbc35197caf5831199727b83f49f2 100644 (file)
@@ -203,9 +203,12 @@ bool samba_private_attr_name(const char *unix_ea_name)
  Get one EA value. Fill in a struct ea_struct.
 ****************************************************************************/
 
-NTSTATUS get_ea_value(TALLOC_CTX *mem_ctx, connection_struct *conn,
-                     files_struct *fsp, const char *fname,
-                     const char *ea_name, struct ea_struct *pea)
+NTSTATUS get_ea_value(TALLOC_CTX *mem_ctx,
+                       connection_struct *conn,
+                       files_struct *fsp,
+                       const struct smb_filename *smb_fname,
+                       const char *ea_name,
+                       struct ea_struct *pea)
 {
        /* Get the value of this xattr. Max size is 64k. */
        size_t attr_size = 256;
@@ -222,7 +225,8 @@ NTSTATUS get_ea_value(TALLOC_CTX *mem_ctx, connection_struct *conn,
        if (fsp && fsp->fh->fd != -1) {
                sizeret = SMB_VFS_FGETXATTR(fsp, ea_name, val, attr_size);
        } else {
-               sizeret = SMB_VFS_GETXATTR(conn, fname, ea_name, val, attr_size);
+               sizeret = SMB_VFS_GETXATTR(conn, smb_fname,
+                               ea_name, val, attr_size);
        }
 
        if (sizeret == -1 && errno == ERANGE && attr_size != 65536) {
@@ -289,7 +293,7 @@ NTSTATUS get_ea_names_from_file(TALLOC_CTX *mem_ctx,
                                             ea_namelist_size);
        } else {
                sizeret = SMB_VFS_LISTXATTR(conn,
-                                           smb_fname->base_name,
+                                           smb_fname,
                                            ea_namelist,
                                            ea_namelist_size);
        }
@@ -307,7 +311,7 @@ NTSTATUS get_ea_names_from_file(TALLOC_CTX *mem_ctx,
                                                     ea_namelist_size);
                } else {
                        sizeret = SMB_VFS_LISTXATTR(conn,
-                                                   smb_fname->base_name,
+                                                   smb_fname,
                                                    ea_namelist,
                                                    ea_namelist_size);
                }
@@ -458,7 +462,7 @@ static NTSTATUS get_ea_list_from_file_path(TALLOC_CTX *mem_ctx,
                status = get_ea_value(listp,
                                        conn,
                                        fsp,
-                                       smb_fname->base_name,
+                                       smb_fname,
                                        names[i],
                                        &listp->ea);
 
@@ -800,7 +804,7 @@ NTSTATUS set_ea(connection_struct *conn, files_struct *fsp,
                                DEBUG(10,("set_ea: deleting ea name %s on file %s.\n",
                                        unix_ea_name, smb_fname->base_name));
                                ret = SMB_VFS_REMOVEXATTR(conn,
-                                               smb_fname->base_name,
+                                               smb_fname,
                                                unix_ea_name);
                        }
 #ifdef ENOATTR
@@ -822,7 +826,7 @@ NTSTATUS set_ea(connection_struct *conn, files_struct *fsp,
                                DEBUG(10,("set_ea: setting ea name %s on file %s.\n",
                                        unix_ea_name, smb_fname->base_name));
                                ret = SMB_VFS_SETXATTR(conn,
-                                               smb_fname->base_name,
+                                               smb_fname,
                                                unix_ea_name,
                                                ea_list->ea.value.data,
                                                ea_list->ea.value.length,
@@ -1225,7 +1229,7 @@ static void call_trans2open(connection_struct *conn,
        uint32_t create_disposition;
        uint32_t create_options = 0;
        uint32_t private_flags = 0;
-       uint32_t ucf_flags = (req->posix_pathnames ? UCF_POSIX_PATHNAMES : 0);
+       uint32_t ucf_flags = ucf_flags_from_smb_request(req);
        TALLOC_CTX *ctx = talloc_tos();
 
        /*
@@ -1289,7 +1293,6 @@ static void call_trans2open(connection_struct *conn,
 
        status = filename_convert(ctx,
                                conn,
-                               req->flags2 & FLAGS2_DFS_PATHNAMES,
                                fname,
                                ucf_flags,
                                NULL,
@@ -1574,18 +1577,18 @@ static NTSTATUS unix_perms_from_wire( connection_struct *conn,
 ****************************************************************************/
 
 static bool check_msdfs_link(connection_struct *conn,
-                               const char *pathname,
-                               SMB_STRUCT_STAT *psbuf)
+                               struct smb_filename *smb_fname)
 {
        int saved_errno = errno;
        if(lp_host_msdfs() &&
                lp_msdfs_root(SNUM(conn)) &&
-               is_msdfs_link(conn, pathname, psbuf)) {
+               is_msdfs_link(conn, smb_fname)) {
 
                DEBUG(5,("check_msdfs_link: Masquerading msdfs link %s "
                        "as a directory\n",
-                       pathname));
-               psbuf->st_ex_mode = (psbuf->st_ex_mode & 0xFFF) | S_IFDIR;
+                       smb_fname->base_name));
+               smb_fname->st.st_ex_mode =
+                       (smb_fname->st.st_ex_mode & 0xFFF) | S_IFDIR;
                errno = saved_errno;
                return true;
        }
@@ -1726,8 +1729,7 @@ static bool smbd_dirptr_lanman2_mode_fn(TALLOC_CTX *ctx,
                 * directories */
 
                ms_dfs_link = check_msdfs_link(state->conn,
-                                              smb_fname->base_name,
-                                              &smb_fname->st);
+                                              smb_fname);
                if (!ms_dfs_link) {
                        DEBUG(5,("smbd_dirptr_lanman2_mode_fn: "
                                 "Couldn't stat [%s] (%s)\n",
@@ -2637,7 +2639,7 @@ static void call_trans2findfirst(connection_struct *conn,
        struct dptr_struct *dirptr = NULL;
        struct smbd_server_connection *sconn = req->sconn;
        uint32_t ucf_flags = UCF_SAVE_LCOMP | UCF_ALWAYS_ALLOW_WCARD_LCOMP |
-                       (req->posix_pathnames ? UCF_POSIX_PATHNAMES : 0);
+                       ucf_flags_from_smb_request(req);
        bool backup_priv = false;
        bool as_root = false;
 
@@ -2733,7 +2735,6 @@ close_if_end = %d requires_resume_key = %d backup_priv = %d level = 0x%x, max_da
                                &smb_dname);
        } else {
                ntstatus = filename_convert(talloc_tos(), conn,
-                                   req->flags2 & FLAGS2_DFS_PATHNAMES,
                                    directory,
                                    ucf_flags,
                                    &mask_contains_wcard,
@@ -3510,6 +3511,12 @@ NTSTATUS smbd_do_qfsinfo(struct smbXsrv_connection *xconn,
 cBytesSector=%u, cUnitTotal=%u, cUnitAvail=%d\n", (unsigned int)st.st_ex_dev, (unsigned int)bsize, (unsigned int)sectors_per_unit,
                                (unsigned int)bytes_per_sector, (unsigned int)dsize, (unsigned int)dfree));
 
+                       /*
+                        * For large drives, return max values and not modulo.
+                        */
+                       dsize = MIN(dsize, UINT32_MAX);
+                       dfree = MIN(dfree, UINT32_MAX);
+
                        SIVAL(pdata,l1_idFileSystem,st.st_ex_dev);
                        SIVAL(pdata,l1_cSectorUnit,sectors_per_unit);
                        SIVAL(pdata,l1_cUnit,dsize);
@@ -3897,7 +3904,7 @@ cBytesSector=%u, cUnitTotal=%u, cUnitAvail=%d\n", (unsigned int)bsize, (unsigned
                                return NT_STATUS_INVALID_LEVEL;
                        }
 
-                       rc = SMB_VFS_STATVFS(conn, filename, &svfs);
+                       rc = SMB_VFS_STATVFS(conn, &smb_fname, &svfs);
 
                        if (!rc) {
                                data_len = 56;
@@ -5475,7 +5482,7 @@ NTSTATUS smbd_do_qfilepathinfo(connection_struct *conn,
                                return NT_STATUS_DOS(ERRDOS, ERRbadlink);
 #endif
                                link_len = SMB_VFS_READLINK(conn,
-                                                      smb_fname->base_name,
+                                                      smb_fname,
                                                       buffer, PATH_MAX);
                                if (link_len == -1) {
                                        return map_nt_error_from_unix(errno);
@@ -5515,7 +5522,7 @@ NTSTATUS smbd_do_qfilepathinfo(connection_struct *conn,
                                } else {
                                        file_acl =
                                            SMB_VFS_SYS_ACL_GET_FILE(conn,
-                                               smb_fname->base_name,
+                                               smb_fname,
                                                SMB_ACL_TYPE_ACCESS,
                                                talloc_tos());
                                }
@@ -5533,14 +5540,14 @@ NTSTATUS smbd_do_qfilepathinfo(connection_struct *conn,
                                                def_acl =
                                                    SMB_VFS_SYS_ACL_GET_FILE(
                                                            conn,
-                                                           fsp->fsp_name->base_name,
+                                                           fsp->fsp_name,
                                                            SMB_ACL_TYPE_DEFAULT,
                                                            talloc_tos());
                                        } else {
                                                def_acl =
                                                    SMB_VFS_SYS_ACL_GET_FILE(
                                                            conn,
-                                                           smb_fname->base_name,
+                                                           smb_fname,
                                                            SMB_ACL_TYPE_DEFAULT,
                                                            talloc_tos());
                                        }
@@ -5794,8 +5801,7 @@ static void call_trans2qfilepathinfo(connection_struct *conn,
        } else {
                uint32_t name_hash;
                char *fname = NULL;
-               uint32_t ucf_flags = (req->posix_pathnames ?
-                               UCF_POSIX_PATHNAMES : 0);
+               uint32_t ucf_flags = ucf_flags_from_smb_request(req);
 
                /* qpathinfo */
                if (total_params < 7) {
@@ -5846,7 +5852,6 @@ static void call_trans2qfilepathinfo(connection_struct *conn,
 
                status = filename_convert(req,
                                        conn,
-                                       req->flags2 & FLAGS2_DFS_PATHNAMES,
                                        fname,
                                        ucf_flags,
                                        NULL,
@@ -6143,8 +6148,7 @@ NTSTATUS hardlink_internals(TALLOC_CTX *ctx,
        DEBUG(10,("hardlink_internals: doing hard link %s -> %s\n",
                  smb_fname_old->base_name, smb_fname_new->base_name));
 
-       if (SMB_VFS_LINK(conn, smb_fname_old->base_name,
-                        smb_fname_new->base_name) != 0) {
+       if (SMB_VFS_LINK(conn, smb_fname_old, smb_fname_new) != 0) {
                status = map_nt_error_from_unix(errno);
                DEBUG(3,("hardlink_internals: Error %s hard link %s -> %s\n",
                         nt_errstr(status), smb_fname_old->base_name,
@@ -6603,10 +6607,9 @@ static NTSTATUS smb_set_file_unix_link(connection_struct *conn,
                                       struct smb_request *req,
                                       const char *pdata,
                                       int total_data,
-                                      const struct smb_filename *smb_fname)
+                                      const struct smb_filename *new_smb_fname)
 {
        char *link_target = NULL;
-       const char *newname = smb_fname->base_name;
        TALLOC_CTX *ctx = talloc_tos();
 
        /* Set a symbolic link. */
@@ -6628,9 +6631,9 @@ static NTSTATUS smb_set_file_unix_link(connection_struct *conn,
        }
 
        DEBUG(10,("smb_set_file_unix_link: SMB_SET_FILE_UNIX_LINK doing symlink %s -> %s\n",
-                       newname, link_target ));
+                       new_smb_fname->base_name, link_target ));
 
-       if (SMB_VFS_SYMLINK(conn,link_target,newname) != 0) {
+       if (SMB_VFS_SYMLINK(conn,link_target,new_smb_fname) != 0) {
                return map_nt_error_from_unix(errno);
        }
 
@@ -6648,7 +6651,7 @@ static NTSTATUS smb_set_file_unix_hlink(connection_struct *conn,
 {
        char *oldname = NULL;
        struct smb_filename *smb_fname_old = NULL;
-       uint32_t ucf_flags = (req->posix_pathnames ? UCF_POSIX_PATHNAMES : 0);
+       uint32_t ucf_flags = ucf_flags_from_smb_request(req);
        TALLOC_CTX *ctx = talloc_tos();
        NTSTATUS status = NT_STATUS_OK;
 
@@ -6685,7 +6688,6 @@ static NTSTATUS smb_set_file_unix_hlink(connection_struct *conn,
 
        status = filename_convert(ctx,
                                conn,
-                               req->flags2 & FLAGS2_DFS_PATHNAMES,
                                oldname,
                                ucf_flags,
                                NULL,
@@ -6714,7 +6716,7 @@ static NTSTATUS smb2_file_rename_information(connection_struct *conn,
        char *newname = NULL;
        struct smb_filename *smb_fname_dst = NULL;
        uint32_t ucf_flags = UCF_SAVE_LCOMP |
-               (req->posix_pathnames ? UCF_POSIX_PATHNAMES : 0);
+               ucf_flags_from_smb_request(req);
        NTSTATUS status = NT_STATUS_OK;
        TALLOC_CTX *ctx = talloc_tos();
 
@@ -6761,7 +6763,6 @@ static NTSTATUS smb2_file_rename_information(connection_struct *conn,
 
        status = filename_convert(ctx,
                                conn,
-                               req->flags2 & FLAGS2_DFS_PATHNAMES,
                                newname,
                                ucf_flags,
                                NULL,
@@ -6826,7 +6827,7 @@ static NTSTATUS smb_file_link_information(connection_struct *conn,
        struct smb_filename *smb_fname_dst = NULL;
        NTSTATUS status = NT_STATUS_OK;
        uint32_t ucf_flags = UCF_SAVE_LCOMP |
-               (req->posix_pathnames ? UCF_POSIX_PATHNAMES : 0);
+               ucf_flags_from_smb_request(req);
        TALLOC_CTX *ctx = talloc_tos();
 
        if (!fsp) {
@@ -6872,7 +6873,6 @@ static NTSTATUS smb_file_link_information(connection_struct *conn,
 
        status = filename_convert(ctx,
                                conn,
-                               req->flags2 & FLAGS2_DFS_PATHNAMES,
                                newname,
                                ucf_flags,
                                NULL,
@@ -6962,15 +6962,16 @@ static NTSTATUS smb_file_rename_information(connection_struct *conn,
        DEBUG(10,("smb_file_rename_information: got name |%s|\n",
                                newname));
 
-       status = resolve_dfspath_wcard(ctx, conn,
-                                      req->flags2 & FLAGS2_DFS_PATHNAMES,
+       if (req->flags2 & FLAGS2_DFS_PATHNAMES) {
+               status = resolve_dfspath_wcard(ctx, conn,
                                       newname,
                                       UCF_COND_ALLOW_WCARD_LCOMP,
                                       !conn->sconn->using_smb2,
                                       &newname,
                                       &dest_has_wcard);
-       if (!NT_STATUS_IS_OK(status)) {
-               return status;
+               if (!NT_STATUS_IS_OK(status)) {
+                       return status;
+               }
        }
 
        /* Check the new name has no '/' characters. */
@@ -7013,6 +7014,12 @@ static NTSTATUS smb_file_rename_information(connection_struct *conn,
                 * the newname instead.
                 */
                char *base_name = NULL;
+               uint32_t ucf_flags = UCF_SAVE_LCOMP |
+                       ucf_flags_from_smb_request(req);
+
+               if (dest_has_wcard) {
+                       ucf_flags |= UCF_ALWAYS_ALLOW_WCARD_LCOMP;
+               }
 
                /* newname must *not* be a stream name. */
                if (newname[0] == ':') {
@@ -7045,10 +7052,7 @@ static NTSTATUS smb_file_rename_information(connection_struct *conn,
                }
 
                status = unix_convert(ctx, conn, base_name, &smb_fname_dst,
-                                     (UCF_SAVE_LCOMP |
-                                         (dest_has_wcard ?
-                                             UCF_ALWAYS_ALLOW_WCARD_LCOMP :
-                                             0)));
+                                       ucf_flags);
 
                /* If an error we expect this to be
                 * NT_STATUS_OBJECT_PATH_NOT_FOUND */
@@ -7148,13 +7152,13 @@ static NTSTATUS smb_set_posix_acl(connection_struct *conn,
                (unsigned int)num_def_acls));
 
        if (valid_file_acls && !set_unix_posix_acl(conn, fsp,
-               smb_fname->base_name, num_file_acls,
+               smb_fname, num_file_acls,
                pdata + SMB_POSIX_ACL_HEADER_SIZE)) {
                return map_nt_error_from_unix(errno);
        }
 
        if (valid_def_acls && !set_unix_posix_default_acl(conn,
-               smb_fname->base_name, &smb_fname->st, num_def_acls,
+               smb_fname, num_def_acls,
                pdata + SMB_POSIX_ACL_HEADER_SIZE +
                (num_file_acls*SMB_POSIX_ACL_ENTRY_SIZE))) {
                return map_nt_error_from_unix(errno);
@@ -7573,7 +7577,7 @@ static NTSTATUS smb_unix_mknod(connection_struct *conn,
                  (unsigned int)unixmode, smb_fname_str_dbg(smb_fname)));
 
        /* Ok - do the mknod. */
-       if (SMB_VFS_MKNOD(conn, smb_fname->base_name, unixmode, dev) != 0) {
+       if (SMB_VFS_MKNOD(conn, smb_fname, unixmode, dev) != 0) {
                return map_nt_error_from_unix(errno);
        }
 
@@ -7587,7 +7591,7 @@ static NTSTATUS smb_unix_mknod(connection_struct *conn,
                                    &parent, NULL)) {
                        return NT_STATUS_NO_MEMORY;
                }
-               inherit_access_posix_acl(conn, parent, smb_fname->base_name,
+               inherit_access_posix_acl(conn, parent, smb_fname,
                                         unixmode);
                TALLOC_FREE(parent);
        }
@@ -7898,7 +7902,7 @@ static NTSTATUS smb_set_file_unix_info2(connection_struct *conn,
                        /* XXX: we should be  using SMB_VFS_FCHFLAGS here. */
                        return NT_STATUS_NOT_SUPPORTED;
                } else {
-                       if (SMB_VFS_CHFLAGS(conn, smb_fname->base_name,
+                       if (SMB_VFS_CHFLAGS(conn, smb_fname,
                                            stat_fflags) != 0) {
                                return map_nt_error_from_unix(errno);
                        }
@@ -8783,8 +8787,7 @@ static void call_trans2setfilepathinfo(connection_struct *conn,
                }
        } else {
                char *fname = NULL;
-               uint32_t ucf_flags = (req->posix_pathnames ?
-                       UCF_POSIX_PATHNAMES : 0);
+               uint32_t ucf_flags = ucf_flags_from_smb_request(req);
 
                /* set path info */
                if (total_params < 7) {
@@ -8825,7 +8828,6 @@ static void call_trans2setfilepathinfo(connection_struct *conn,
                }
 
                status = filename_convert(req, conn,
-                                        req->flags2 & FLAGS2_DFS_PATHNAMES,
                                         fname,
                                         ucf_flags,
                                         NULL,
@@ -8934,7 +8936,7 @@ static void call_trans2mkdir(connection_struct *conn, struct smb_request *req,
        char *directory = NULL;
        NTSTATUS status = NT_STATUS_OK;
        struct ea_list *ea_list = NULL;
-       uint32_t ucf_flags = (req->posix_pathnames ? UCF_POSIX_PATHNAMES : 0);
+       uint32_t ucf_flags = ucf_flags_from_smb_request(req);
        TALLOC_CTX *ctx = talloc_tos();
 
        if (!CAN_WRITE(conn)) {
@@ -8975,7 +8977,6 @@ static void call_trans2mkdir(connection_struct *conn, struct smb_request *req,
 
        status = filename_convert(ctx,
                                conn,
-                               req->flags2 & FLAGS2_DFS_PATHNAMES,
                                directory,
                                ucf_flags,
                                NULL,