Author: jra
Date: 2007-07-09 21:48:33 +0000 (Mon, 09 Jul 2007)
New Revision: 23781

WebSVN: 
http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=23781

Log:
Add Volker's change to remove globals :

"Get rid of the three global variables for the case semantics. I think
this is really not worth globals."

Jeremy.

Modified:
   branches/SAMBA_3_2_0/source/smbd/nttrans.c


Changeset:
Modified: branches/SAMBA_3_2_0/source/smbd/nttrans.c
===================================================================
--- branches/SAMBA_3_2_0/source/smbd/nttrans.c  2007-07-09 19:46:27 UTC (rev 
23780)
+++ branches/SAMBA_3_2_0/source/smbd/nttrans.c  2007-07-09 21:48:33 UTC (rev 
23781)
@@ -269,49 +269,49 @@
        return (strchr_m(fname, ':') != NULL) ? True : False;
 }
 
+struct case_semantics_state {
+       connection_struct *conn;
+       BOOL case_sensitive;
+       BOOL case_preserve;
+       BOOL short_case_preserve;
+};
+
 /****************************************************************************
- Save case statics.
+ Restore case semantics.
 ****************************************************************************/
+static int restore_case_semantics(struct case_semantics_state *state)
+{
+       state->conn->case_sensitive = state->case_sensitive;
+       state->conn->case_preserve = state->case_preserve;
+       state->conn->short_case_preserve = state->short_case_preserve;
+       return 0;
+}
 
-static BOOL saved_case_sensitive;
-static BOOL saved_case_preserve;
-static BOOL saved_short_case_preserve;
-
 /****************************************************************************
  Save case semantics.
 ****************************************************************************/
+static struct case_semantics_state *set_posix_case_semantics(TALLOC_CTX 
*mem_ctx,
+                                                            connection_struct 
*conn)
+{
+       struct case_semantics_state *result;
 
-static uint32 set_posix_case_semantics(connection_struct *conn, uint32 
file_attributes)
-{
-       if(!(file_attributes & FILE_FLAG_POSIX_SEMANTICS)) {
-               return file_attributes;
+       if (!(result = talloc(mem_ctx, struct case_semantics_state))) {
+               DEBUG(0, ("talloc failed\n"));
+               return NULL;
        }
 
-       saved_case_sensitive = conn->case_sensitive;
-       saved_case_preserve = conn->case_preserve;
-       saved_short_case_preserve = conn->short_case_preserve;
+       result->case_sensitive = conn->case_sensitive;
+       result->case_preserve = conn->case_preserve;
+       result->short_case_preserve = conn->short_case_preserve;
 
        /* Set to POSIX. */
        conn->case_sensitive = True;
        conn->case_preserve = True;
        conn->short_case_preserve = True;
 
-       return (file_attributes & ~FILE_FLAG_POSIX_SEMANTICS);
-}
+       talloc_set_destructor(result, restore_case_semantics);
 
-/****************************************************************************
- Restore case semantics.
-****************************************************************************/
-
-static void restore_case_semantics(connection_struct *conn, uint32 
file_attributes)
-{
-       if(!(file_attributes & FILE_FLAG_POSIX_SEMANTICS)) {
-               return;
-       }
-
-       conn->case_sensitive = saved_case_sensitive;
-       conn->case_preserve = saved_case_preserve;
-       conn->short_case_preserve = saved_short_case_preserve;
+       return result;
 }
 
 /****************************************************************************
@@ -481,7 +481,6 @@
        uint32 flags = IVAL(inbuf,smb_ntcreate_Flags);
        uint32 access_mask = IVAL(inbuf,smb_ntcreate_DesiredAccess);
        uint32 file_attributes = IVAL(inbuf,smb_ntcreate_FileAttributes);
-       uint32 new_file_attributes;
        uint32 share_access = IVAL(inbuf,smb_ntcreate_ShareAccess);
        uint32 create_disposition = IVAL(inbuf,smb_ntcreate_CreateDisposition);
        uint32 create_options = IVAL(inbuf,smb_ntcreate_CreateOptions);
@@ -501,6 +500,7 @@
        BOOL extended_oplock_granted = False;
        NTSTATUS status;
        struct smb_request req;
+       struct case_semantics_state *case_state = NULL;
 
        START_PROFILE(SMBntcreateX);
 
@@ -670,18 +670,21 @@
         * Check if POSIX semantics are wanted.
         */
                
-       new_file_attributes = set_posix_case_semantics(conn, file_attributes);
+       if (file_attributes & FILE_FLAG_POSIX_SEMANTICS) {
+               case_state = set_posix_case_semantics(NULL, conn);
+               file_attributes &= ~FILE_FLAG_POSIX_SEMANTICS;
+       }
                
        status = unix_convert(conn, fname, False, NULL, &sbuf);
        if (!NT_STATUS_IS_OK(status)) {
-               restore_case_semantics(conn, file_attributes);
+               TALLOC_FREE(case_state);
                END_PROFILE(SMBntcreateX);
                return ERROR_NT(status);
        }
        /* All file access must go through check_name() */
        status = check_name(conn, fname);
        if (!NT_STATUS_IS_OK(status)) {
-               restore_case_semantics(conn, file_attributes);
+               TALLOC_FREE(case_state);
                END_PROFILE(SMBntcreateX);
                return ERROR_NT(status);
        }
@@ -700,7 +703,7 @@
            && (access_mask & DELETE_ACCESS)) {
                if ((dos_mode(conn, fname, &sbuf) & FILE_ATTRIBUTE_READONLY) ||
                                !can_delete_file_in_directory(conn, fname)) {
-                       restore_case_semantics(conn, file_attributes);
+                       TALLOC_FREE(case_state);
                        END_PROFILE(SMBntcreateX);
                        return ERROR_NT(NT_STATUS_ACCESS_DENIED);
                }
@@ -708,10 +711,10 @@
 
 #if 0
        /* We need to support SeSecurityPrivilege for this. */
-       if ((access_mask & SEC_RIGHT_SYSTEM_SECURITY)) && 
+       if ((access_mask & SEC_RIGHT_SYSTEM_SECURITY) &&
                        !user_has_privileges(current_user.nt_user_token,
                                &se_security)) {
-               restore_case_semantics(conn, file_attributes);
+               TALLOC_FREE(case_state);
                END_PROFILE(SMBntcreateX);
                return ERROR_NT(NT_STATUS_PRIVILEGE_NOT_HELD);
        }
@@ -725,7 +728,7 @@
 
                /* Can't open a temp directory. IFS kit test. */
                if (file_attributes & FILE_ATTRIBUTE_TEMPORARY) {
-                       restore_case_semantics(conn, file_attributes);
+                       TALLOC_FREE(case_state);
                        END_PROFILE(SMBntcreateX);
                        return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
                }
@@ -736,10 +739,10 @@
                                        share_access,
                                        create_disposition,
                                        create_options,
-                                       new_file_attributes,
+                                       file_attributes,
                                        &info, &fsp);
 
-               restore_case_semantics(conn, file_attributes);
+               TALLOC_FREE(case_state);
 
                if(!NT_STATUS_IS_OK(status)) {
                        if (!use_nt_status() && NT_STATUS_EQUAL(
@@ -774,7 +777,7 @@
                                        share_access,
                                        create_disposition,
                                        create_options,
-                                       new_file_attributes,
+                                       file_attributes,
                                        oplock_request,
                                        &info, &fsp);
 
@@ -806,7 +809,7 @@
                                 */
 
                                if (create_options & FILE_NON_DIRECTORY_FILE) {
-                                       restore_case_semantics(conn, 
file_attributes);
+                                       TALLOC_FREE(case_state);
                                        END_PROFILE(SMBntcreateX);
                                        return 
ERROR_FORCE_NT(NT_STATUS_FILE_IS_A_DIRECTORY);
                                }
@@ -818,11 +821,11 @@
                                                        share_access,
                                                        create_disposition,
                                                        create_options,
-                                                       new_file_attributes,
+                                                       file_attributes,
                                                        &info, &fsp);
 
                                if(!NT_STATUS_IS_OK(status)) {
-                                       restore_case_semantics(conn, 
file_attributes);
+                                       TALLOC_FREE(case_state);
                                        if (!use_nt_status() && NT_STATUS_EQUAL(
                                                    status, 
NT_STATUS_OBJECT_NAME_COLLISION)) {
                                                status = NT_STATUS_DOS(ERRDOS, 
ERRfilexists);
@@ -831,7 +834,7 @@
                                        return ERROR_NT(status);
                                }
                        } else {
-                               restore_case_semantics(conn, file_attributes);
+                               TALLOC_FREE(case_state);
                                END_PROFILE(SMBntcreateX);
                                if (open_was_deferred(SVAL(inbuf,smb_mid))) {
                                        /* We have re-scheduled this call. */
@@ -842,7 +845,7 @@
                } 
        }
                
-       restore_case_semantics(conn, file_attributes);
+       TALLOC_FREE(case_state);
 
        file_len = sbuf.st_size;
        fattr = dos_mode(conn,fname,&sbuf);
@@ -1192,7 +1195,6 @@
        uint32 flags;
        uint32 access_mask;
        uint32 file_attributes;
-       uint32 new_file_attributes;
        uint32 share_access;
        uint32 create_disposition;
        uint32 create_options;
@@ -1208,6 +1210,7 @@
        NTSTATUS status;
        size_t param_len;
        struct smb_request req;
+       struct case_semantics_state *case_state = NULL;
 
        DEBUG(5,("call_nt_transact_create\n"));
 
@@ -1366,12 +1369,15 @@
        /*
         * Check if POSIX semantics are wanted.
         */
+
+       if (file_attributes & FILE_FLAG_POSIX_SEMANTICS) {
+               case_state = set_posix_case_semantics(NULL, conn);
+               file_attributes &= ~FILE_FLAG_POSIX_SEMANTICS;
+       }
                
-       new_file_attributes = set_posix_case_semantics(conn, file_attributes);
-    
        status = resolve_dfspath(conn, SVAL(inbuf,smb_flg2) & 
FLAGS2_DFS_PATHNAMES, fname);
        if (!NT_STATUS_IS_OK(status)) {
-               restore_case_semantics(conn, file_attributes);
+               TALLOC_FREE(case_state);
                if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {
                        return ERROR_BOTH(NT_STATUS_PATH_NOT_COVERED, ERRSRV, 
ERRbadpath);
                }
@@ -1380,13 +1386,13 @@
 
        status = unix_convert(conn, fname, False, NULL, &sbuf);
        if (!NT_STATUS_IS_OK(status)) {
-               restore_case_semantics(conn, file_attributes);
+               TALLOC_FREE(case_state);
                return ERROR_NT(status);
        }
        /* All file access must go through check_name() */
        status = check_name(conn, fname);
        if (!NT_STATUS_IS_OK(status)) {
-               restore_case_semantics(conn, file_attributes);
+               TALLOC_FREE(case_state);
                return ERROR_NT(status);
        }
 
@@ -1404,7 +1410,7 @@
            && (access_mask & DELETE_ACCESS)) {
                if ((dos_mode(conn, fname, &sbuf) & FILE_ATTRIBUTE_READONLY) ||
                                !can_delete_file_in_directory(conn, fname)) {
-                       restore_case_semantics(conn, file_attributes);
+                       TALLOC_FREE(case_state);
                        return ERROR_NT(NT_STATUS_ACCESS_DENIED);
                }
        }
@@ -1414,7 +1420,6 @@
        if ((access_mask & SEC_RIGHT_SYSTEM_SECURITY)) && 
                        !user_has_privileges(current_user.nt_user_token,
                                &se_security)) {
-               restore_case_semantics(conn, file_attributes);
                END_PROFILE(SMBntcreateX);
                return ERROR_NT(NT_STATUS_PRIVILEGE_NOT_HELD);
        }
@@ -1427,7 +1432,7 @@
                ea_list = read_nttrans_ea_list(tmp_talloc_ctx(), pdata,
                                               ea_len);
                if (!ea_list ) {
-                       restore_case_semantics(conn, file_attributes);
+                       TALLOC_FREE(case_state);
                        return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
                }
        }
@@ -1440,7 +1445,7 @@
 
                /* Can't open a temp directory. IFS kit test. */
                if (file_attributes & FILE_ATTRIBUTE_TEMPORARY) {
-                       restore_case_semantics(conn, file_attributes);
+                       TALLOC_FREE(case_state);
                        return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
                }
 
@@ -1456,10 +1461,10 @@
                                        share_access,
                                        create_disposition,
                                        create_options,
-                                       new_file_attributes,
+                                       file_attributes,
                                        &info, &fsp);
                if(!NT_STATUS_IS_OK(status)) {
-                       restore_case_semantics(conn, file_attributes);
+                       TALLOC_FREE(case_state);
                        return ERROR_NT(status);
                }
 
@@ -1474,7 +1479,7 @@
                                        share_access,
                                        create_disposition,
                                        create_options,
-                                       new_file_attributes,
+                                       file_attributes,
                                        oplock_request,
                                        &info, &fsp);
 
@@ -1487,7 +1492,7 @@
                                 */
 
                                if (create_options & FILE_NON_DIRECTORY_FILE) {
-                                       restore_case_semantics(conn, 
file_attributes);
+                                       TALLOC_FREE(case_state);
                                        return 
ERROR_FORCE_NT(NT_STATUS_FILE_IS_A_DIRECTORY);
                                }
        
@@ -1498,14 +1503,14 @@
                                                        share_access,
                                                        create_disposition,
                                                        create_options,
-                                                       new_file_attributes,
+                                                       file_attributes,
                                                        &info, &fsp);
                                if(!NT_STATUS_IS_OK(status)) {
-                                       restore_case_semantics(conn, 
file_attributes);
+                                       TALLOC_FREE(case_state);
                                        return ERROR_NT(status);
                                }
                        } else {
-                               restore_case_semantics(conn, file_attributes);
+                               TALLOC_FREE(case_state);
                                if (open_was_deferred(SVAL(inbuf,smb_mid))) {
                                        /* We have re-scheduled this call. */
                                        return -1;
@@ -1537,7 +1542,7 @@
                if (!NT_STATUS_IS_OK(status)) {
                        talloc_destroy(ctx);
                        close_file(fsp,ERROR_CLOSE);
-                       restore_case_semantics(conn, file_attributes);
+                       TALLOC_FREE(case_state);
                        return ERROR_NT(status);
                }
                fsp->access_mask = saved_access_mask;
@@ -1547,12 +1552,12 @@
                status = set_ea(conn, fsp, fname, ea_list);
                if (!NT_STATUS_IS_OK(status)) {
                        close_file(fsp,ERROR_CLOSE);
-                       restore_case_semantics(conn, file_attributes);
+                       TALLOC_FREE(case_state);
                        return ERROR_NT(status);
                }
        }
 
-       restore_case_semantics(conn, file_attributes);
+       TALLOC_FREE(case_state);
 
        file_len = sbuf.st_size;
        fattr = dos_mode(conn,fname,&sbuf);

Reply via email to