Remove the "stat_open()" function, flag, and all associated code. It was only
authorJeremy Allison <jra@samba.org>
Sat, 3 May 2008 00:22:10 +0000 (17:22 -0700)
committerJeremy Allison <jra@samba.org>
Sat, 3 May 2008 00:22:10 +0000 (17:22 -0700)
being (correctly) used in the can_read/can_write checks for hide unreadable/unwritable
and this is more properly done using the functions in smbd/file_access.c.
Preparing to do NT access checks on all file access.
Jeremy.
(This used to be commit 6bfb06ad95963ae2acb67c4694a98282d3b29faa)

source3/include/smb.h
source3/locking/locking.c
source3/rpc_server/srv_srvsvc_nt.c
source3/smbd/close.c
source3/smbd/dir.c
source3/smbd/file_access.c
source3/smbd/files.c
source3/smbd/open.c

index 598708bfe34b6fb8df2037507815018650df63ea..ce91d81c2d17b5e85402e17ad019e2990c14edcb 100644 (file)
@@ -508,7 +508,6 @@ typedef struct files_struct {
        bool print_file;
        bool modified;
        bool is_directory;
-       bool is_stat;
        bool aio_write_behind;
        bool lockdb_clean;
        bool initial_delete_on_close; /* Only set at NTCreateX if file was created. */
index 5faebef1fe70b6286baf599699bcccb3eac5e3d1..17131d9194bf5ab2b2d006a28842850369ba4a3b 100644 (file)
@@ -1363,10 +1363,6 @@ bool set_delete_on_close(files_struct *fsp, bool delete_on_close, UNIX_USER_TOKE
                  delete_on_close ? "Adding" : "Removing", fsp->fnum,
                  fsp->fsp_name ));
 
-       if (fsp->is_stat) {
-               return True;
-       }
-
        lck = get_share_mode_lock(talloc_tos(), fsp->file_id, NULL, NULL,
                                  NULL);
        if (lck == NULL) {
index 7188360f69747e315747c72a1e8205819bde5ea3..1b578cc9f87084c04f01c8220df5d43aac31942f 100644 (file)
@@ -2206,13 +2206,20 @@ WERROR _srvsvc_NetSetFileSecurity(pipes_struct *p,
                goto error_exit;
        }
 
-       nt_status = open_file_stat(conn, NULL, filename, &st, &fsp);
+       nt_status = open_file_ntcreate(conn, NULL, filename, &st,
+                               FILE_WRITE_ATTRIBUTES,
+                               FILE_SHARE_READ|FILE_SHARE_WRITE,
+                               FILE_OPEN,
+                               0,
+                               FILE_ATTRIBUTE_NORMAL,
+                               INTERNAL_OPEN_ONLY,
+                               NULL, &fsp);
 
        if ( !NT_STATUS_IS_OK(nt_status) ) {
                /* Perhaps it is a directory */
                if (NT_STATUS_EQUAL(nt_status, NT_STATUS_FILE_IS_A_DIRECTORY))
                        nt_status = open_directory(conn, NULL, filename, &st,
-                                               FILE_READ_ATTRIBUTES,
+                                               FILE_WRITE_ATTRIBUTES,
                                                FILE_SHARE_READ|FILE_SHARE_WRITE,
                                                FILE_OPEN,
                                                0,
index 3afc037f69cd6d50ac28c4b5cee484052a3e0b33..e27d5c44fa7650578d4794c8c8bfa7960477942e 100644 (file)
@@ -702,20 +702,6 @@ static NTSTATUS close_directory(files_struct *fsp, enum file_close_type close_ty
        return status;
 }
 
-/****************************************************************************
- Close a 'stat file' opened internally.
-****************************************************************************/
-  
-static NTSTATUS close_stat(files_struct *fsp)
-{
-       /*
-        * Do the code common to files and directories.
-        */
-       close_filestruct(fsp);
-       file_free(fsp);
-       return NT_STATUS_OK;
-}
-
 /****************************************************************************
  Close a files_struct.
 ****************************************************************************/
@@ -727,8 +713,6 @@ NTSTATUS close_file(files_struct *fsp, enum file_close_type close_type)
 
        if(fsp->is_directory) {
                status = close_directory(fsp, close_type);
-       } else if (fsp->is_stat) {
-               status = close_stat(fsp);
        } else if (fsp->fake_file_handle != NULL) {
                status = close_fake_file(fsp);
        } else {
index 6e02401e25335d0ee92fc872424be450881a6de3..7d584977df3012c94718ded45132901fbd0eab4f 100644 (file)
@@ -925,11 +925,6 @@ bool get_dir_entry(TALLOC_CTX *ctx,
 
 static bool user_can_read_file(connection_struct *conn, char *name, SMB_STRUCT_STAT *pst)
 {
-       SEC_DESC *psd = NULL;
-       files_struct *fsp;
-       NTSTATUS status;
-       uint32 access_granted;
-
        /*
         * If user is a member of the Admin group
         * we never hide files from them.
@@ -941,36 +936,7 @@ static bool user_can_read_file(connection_struct *conn, char *name, SMB_STRUCT_S
 
        SMB_ASSERT(VALID_STAT(*pst));
 
-       /* Pseudo-open the file (note - no fd's created). */
-
-       if(S_ISDIR(pst->st_mode)) {
-                status = open_directory(conn, NULL, name, pst,
-                       READ_CONTROL_ACCESS,
-                       FILE_SHARE_READ|FILE_SHARE_WRITE,
-                       FILE_OPEN,
-                       0, /* no create options. */
-                       FILE_ATTRIBUTE_DIRECTORY,
-                       NULL, &fsp);
-       } else {
-               status = open_file_stat(conn, NULL, name, pst, &fsp);
-       }
-
-       if (!NT_STATUS_IS_OK(status)) {
-               return False;
-       }
-
-       /* Get NT ACL -allocated in main loop talloc context. No free needed here. */
-       status = SMB_VFS_FGET_NT_ACL(fsp,
-                       (OWNER_SECURITY_INFORMATION|GROUP_SECURITY_INFORMATION|DACL_SECURITY_INFORMATION), &psd);
-       close_file(fsp, NORMAL_CLOSE);
-
-       /* No access if SD get failed. */
-       if (!NT_STATUS_IS_OK(status)) {
-               return False;
-       }
-
-       return se_access_check(psd, current_user.nt_user_token, FILE_READ_DATA,
-                                 &access_granted, &status);
+       return can_access_file_acl(conn, name, pst, FILE_READ_DATA);
 }
 
 /*******************************************************************
@@ -982,12 +948,6 @@ static bool user_can_read_file(connection_struct *conn, char *name, SMB_STRUCT_S
 
 static bool user_can_write_file(connection_struct *conn, char *name, SMB_STRUCT_STAT *pst)
 {
-       SEC_DESC *psd = NULL;
-       files_struct *fsp;
-       int info;
-       NTSTATUS status;
-       uint32 access_granted;
-
        /*
         * If user is a member of the Admin group
         * we never hide files from them.
@@ -1003,33 +963,9 @@ static bool user_can_write_file(connection_struct *conn, char *name, SMB_STRUCT_
 
        if(S_ISDIR(pst->st_mode)) {
                return True;
-       } else {
-               status = open_file_ntcreate(conn, NULL, name, pst,
-                       FILE_WRITE_ATTRIBUTES,
-                       FILE_SHARE_READ|FILE_SHARE_WRITE,
-                       FILE_OPEN,
-                       0,
-                       FILE_ATTRIBUTE_NORMAL,
-                       INTERNAL_OPEN_ONLY,
-                       &info, &fsp);
-       }
-
-       if (!NT_STATUS_IS_OK(status)) {
-               return False;
-       }
-
-       /* Get NT ACL -allocated in main loop talloc context. No free needed here. */
-       status = SMB_VFS_FGET_NT_ACL(fsp,
-                       (OWNER_SECURITY_INFORMATION|GROUP_SECURITY_INFORMATION|DACL_SECURITY_INFORMATION), &psd);
-       close_file(fsp, NORMAL_CLOSE);
-
-       /* No access if SD get failed. */
-       if (!NT_STATUS_IS_OK(status)) {
-               return False;
        }
 
-       return se_access_check(psd, current_user.nt_user_token, FILE_WRITE_DATA,
-                                 &access_granted, &status);
+       return can_write_to_file(conn, name, pst);
 }
 
 /*******************************************************************
index 4c07bc5a6130d32b576177eeed7f219e0fef10a4..71f3291b9ba29776c8b02b3d7cc216fcf402897b 100644 (file)
@@ -25,7 +25,7 @@ extern struct current_user current_user;
 #undef  DBGC_CLASS
 #define DBGC_CLASS DBGC_ACLS
 
-static bool can_access_file_acl(struct connection_struct *conn,
+bool can_access_file_acl(struct connection_struct *conn,
                                const char * fname, SMB_STRUCT_STAT *psbuf,
                                uint32_t access_mask)
 {
@@ -125,7 +125,7 @@ bool can_delete_file_in_directory(connection_struct *conn, const char *fname)
  Note this doesn't take into account share write permissions.
 ****************************************************************************/
 
-bool can_access_file(connection_struct *conn, const char *fname, SMB_STRUCT_STAT *psbuf, uint32 access_mask)
+bool can_access_file_data(connection_struct *conn, const char *fname, SMB_STRUCT_STAT *psbuf, uint32 access_mask)
 {
        if (!(access_mask & (FILE_READ_DATA|FILE_WRITE_DATA))) {
                return False;
@@ -134,7 +134,7 @@ bool can_access_file(connection_struct *conn, const char *fname, SMB_STRUCT_STAT
 
        /* some fast paths first */
 
-       DEBUG(10,("can_access_file: requesting 0x%x on file %s\n",
+       DEBUG(10,("can_access_file_data: requesting 0x%x on file %s\n",
                (unsigned int)access_mask, fname ));
 
        if (current_user.ut.uid == 0 || conn->admin_user) {
@@ -180,7 +180,7 @@ bool can_access_file(connection_struct *conn, const char *fname, SMB_STRUCT_STAT
 
 bool can_write_to_file(connection_struct *conn, const char *fname, SMB_STRUCT_STAT *psbuf)
 {
-       return can_access_file(conn, fname, psbuf, FILE_WRITE_DATA);
+       return can_access_file_data(conn, fname, psbuf, FILE_WRITE_DATA);
 }
 
 /****************************************************************************
index d6e91c67be12c87e92626aaca7ef15039e844e27..17c473f028bdc246de3143d3f48e9fe7bafaa346 100644 (file)
@@ -539,7 +539,6 @@ NTSTATUS dup_file_fsp(files_struct *fsp,
        dup_fsp->print_file = fsp->print_file;
        dup_fsp->modified = fsp->modified;
        dup_fsp->is_directory = fsp->is_directory;
-       dup_fsp->is_stat = fsp->is_stat;
        dup_fsp->aio_write_behind = fsp->aio_write_behind;
         string_set(&dup_fsp->fsp_name,fsp->fsp_name);
 
index dd518b90deae73d955bdb9e8f1229940575d1b32..5c860f891de7dff781059522ac30dd69dee90289 100644 (file)
@@ -391,7 +391,6 @@ static NTSTATUS open_file(files_struct *fsp,
        fsp->modified = False;
        fsp->sent_oplock_break = NO_BREAK_SENT;
        fsp->is_directory = False;
-       fsp->is_stat = False;
        if (conn->aio_write_behind_list &&
            is_in_path(path, conn->aio_write_behind_list, conn->case_sensitive)) {
                fsp->aio_write_behind = True;
@@ -1571,7 +1570,7 @@ NTSTATUS open_file_ntcreate(connection_struct *conn,
                        }
 
                        if (((can_access_mask & FILE_WRITE_DATA) && !CAN_WRITE(conn)) ||
-                           !can_access_file(conn,fname,psbuf,can_access_mask)) {
+                           !can_access_file_data(conn,fname,psbuf,can_access_mask)) {
                                can_access = False;
                        }
 
@@ -2223,7 +2222,6 @@ NTSTATUS open_directory(connection_struct *conn,
        fsp->oplock_type = NO_OPLOCK;
        fsp->sent_oplock_break = NO_BREAK_SENT;
        fsp->is_directory = True;
-       fsp->is_stat = False;
        fsp->posix_open = (file_attributes & FILE_FLAG_POSIX_SEMANTICS) ? True : False;
 
        string_set(&fsp->fsp_name,fname);
@@ -2305,58 +2303,6 @@ NTSTATUS create_directory(connection_struct *conn, struct smb_request *req, cons
        return status;
 }
 
-/****************************************************************************
- Open a pseudo-file (no locking checks - a 'stat' open).
-****************************************************************************/
-
-NTSTATUS open_file_stat(connection_struct *conn, struct smb_request *req,
-                       const char *fname, SMB_STRUCT_STAT *psbuf,
-                       files_struct **result)
-{
-       files_struct *fsp = NULL;
-       NTSTATUS status;
-
-       if (!VALID_STAT(*psbuf)) {
-               return NT_STATUS_INVALID_PARAMETER;
-       }
-
-       /* Can't 'stat' open directories. */
-       if(S_ISDIR(psbuf->st_mode)) {
-               return NT_STATUS_FILE_IS_A_DIRECTORY;
-       }
-
-       status = file_new(conn, &fsp);
-       if(!NT_STATUS_IS_OK(status)) {
-               return status;
-       }
-
-       DEBUG(5,("open_file_stat: 'opening' file %s\n", fname));
-
-       /*
-        * Setup the files_struct for it.
-        */
-       
-       fsp->mode = psbuf->st_mode;
-       fsp->file_id = vfs_file_id_from_sbuf(conn, psbuf);
-       fsp->vuid = req ? req->vuid : UID_FIELD_INVALID;
-       fsp->file_pid = req ? req->smbpid : 0;
-       fsp->can_lock = False;
-       fsp->can_read = False;
-       fsp->can_write = False;
-       fsp->print_file = False;
-       fsp->modified = False;
-       fsp->oplock_type = NO_OPLOCK;
-       fsp->sent_oplock_break = NO_BREAK_SENT;
-       fsp->is_directory = False;
-       fsp->is_stat = True;
-       string_set(&fsp->fsp_name,fname);
-
-       conn->num_files_open++;
-
-       *result = fsp;
-       return NT_STATUS_OK;
-}
-
 /****************************************************************************
  Receive notification that one of our open files has been renamed by another
  smbd process.