The branch, master has been updated
       via  36ec313 s3: Slightly simplify open_file()
       via  be300b0 Coding: Add comment disproving control-flow changing macros
       via  1fa730d s3: Slightly simplify calculate_open_access_flags
       via  cc58a19 s3: Slightly simplify calculate_open_access_flags
      from  50d324b s3-smbd: Don't segfault if user specified ports out for 
range.

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 36ec31336f4547b311148f27075cdb4fc8c37609
Author: Volker Lendecke <[email protected]>
Date:   Tue Sep 4 10:36:47 2012 +0200

    s3: Slightly simplify open_file()
    
    The "else" is not necessary. In the if-branch we just returned.
    
    Autobuild-User(master): Volker Lendecke <[email protected]>
    Autobuild-Date(master): Wed Sep 26 18:08:03 CEST 2012 on sn-devel-104

commit be300b0588729c3c87f765e2737ebaccc0af02ff
Author: Volker Lendecke <[email protected]>
Date:   Wed May 30 10:14:51 2012 +0200

    Coding: Add comment disproving control-flow changing macros

commit 1fa730deba0f36947775fe490b9be98a92560b3f
Author: Volker Lendecke <[email protected]>
Date:   Tue Sep 4 09:28:26 2012 +0200

    s3: Slightly simplify calculate_open_access_flags

commit cc58a19565870d62b3d3476b4b718fcd1ff94a46
Author: Volker Lendecke <[email protected]>
Date:   Tue Sep 4 09:26:28 2012 +0200

    s3: Slightly simplify calculate_open_access_flags

-----------------------------------------------------------------------

Summary of changes:
 README.Coding       |   10 ++++++++++
 source3/smbd/open.c |   40 +++++++++++++++++++++++-----------------
 2 files changed, 33 insertions(+), 17 deletions(-)


Changeset truncated at 500 lines:

diff --git a/README.Coding b/README.Coding
index 8416290..956a733 100644
--- a/README.Coding
+++ b/README.Coding
@@ -367,3 +367,13 @@ Bad Example:
        ret = some_function_my_name(get_some_name());
        ...
 
+Control-Flow changing macros
+----------------------------
+
+Macros like NT_STATUS_NOT_OK_RETURN that change control flow
+(return/goto/etc) from within the macro are considered bad, because
+they look like function calls that never change control flow. Please
+do not use them in new code.
+
+The only exception is the test code that depends repeated use of calls
+like CHECK_STATUS, CHECK_VAL and others.
diff --git a/source3/smbd/open.c b/source3/smbd/open.c
index 2785d6f..10c855c 100644
--- a/source3/smbd/open.c
+++ b/source3/smbd/open.c
@@ -678,7 +678,8 @@ static NTSTATUS open_file(files_struct *fsp,
                        DEBUG(3,("Permission denied opening %s\n",
                                 smb_fname_str_dbg(smb_fname)));
                        return NT_STATUS_ACCESS_DENIED;
-               } else if(flags & O_CREAT) {
+               }
+               if (flags & O_CREAT) {
                        /* We don't want to write - but we must make sure that
                           O_CREAT doesn't create the file if we have write
                           access into the directory.
@@ -1873,29 +1874,34 @@ static int calculate_open_access_flags(uint32_t 
access_mask,
                                       int oplock_request,
                                       uint32_t private_flags)
 {
-       int flags;
+       bool need_write, need_read;
 
        /*
         * Note that we ignore the append flag as append does not
         * mean the same thing under DOS and Unix.
         */
 
-       if ((access_mask & (FILE_WRITE_DATA | FILE_APPEND_DATA)) ||
-           (oplock_request & FORCE_OPLOCK_BREAK_TO_NONE)) {
-               /* DENY_DOS opens are always underlying read-write on the
-                  file handle, no matter what the requested access mask
-                   says. */
-               if ((private_flags & NTCREATEX_OPTIONS_PRIVATE_DENY_DOS) ||
-                   access_mask & (FILE_READ_ATTRIBUTES|FILE_READ_DATA|
-                                  FILE_READ_EA|FILE_EXECUTE)) {
-                       flags = O_RDWR;
-               } else {
-                       flags = O_WRONLY;
-               }
-       } else {
-               flags = O_RDONLY;
+       need_write =
+               ((access_mask & (FILE_WRITE_DATA | FILE_APPEND_DATA)) ||
+                (oplock_request & FORCE_OPLOCK_BREAK_TO_NONE));
+
+       if (!need_write) {
+               return O_RDONLY;
+       }
+
+       /* DENY_DOS opens are always underlying read-write on the
+          file handle, no matter what the requested access mask
+          says. */
+
+       need_read =
+               ((private_flags & NTCREATEX_OPTIONS_PRIVATE_DENY_DOS) ||
+                access_mask & (FILE_READ_ATTRIBUTES|FILE_READ_DATA|
+                               FILE_READ_EA|FILE_EXECUTE));
+
+       if (!need_read) {
+               return O_WRONLY;
        }
-       return flags;
+       return O_RDWR;
 }
 
 /****************************************************************************


-- 
Samba Shared Repository

Reply via email to