The branch, master has been updated
       via  016a8d2 s3-printing: vfs_connect prior to driver/dfs IO
       via  09b4acf s3-printing: clean up get_correct_cversion error paths
       via  14446b5 s3-printing: fix move_driver_to_download_area() error paths
      from  9f61937 s3: remove superfluous debug messages from msg_idmap

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


- Log -----------------------------------------------------------------
commit 016a8d214ab23883e9d50c46d3a8cc18f9454368
Author: David Disseldorp <[email protected]>
Date:   Tue Mar 1 19:17:49 2011 +0100

    s3-printing: vfs_connect prior to driver/dfs IO
    
    samba3.posix_s3.rpc.spoolss.driver fails with the xattr_tdb vfs module
    loaded as a part of make test. The (now checked) create_directory() call
    in move_driver_to_download_area() fails, uncovering another bug in the
    printer driver upload code path.
    
    move_driver_to_download_area() creates a new conn_struct for
    manipulating files in [print$]. The VFS layer is plumbed through with
    the call to create_conn_struct(), however SMB_VFS_CONNECT() is never
    called. Many vfs modules expect state stored at connect time with
    SMB_VFS_HANDLE_SET_DATA() to be available on any IO operation and fail
    if this is not the case.
    
    This fix adds a call to SMB_VFS_CONNECT() in create_conn_struct() prior
    to IO.
    
    https://bugzilla.samba.org/show_bug.cgi?id=7976
    
    Autobuild-User: Jeremy Allison <[email protected]>
    Autobuild-Date: Wed Mar  2 01:16:30 CET 2011 on sn-devel-104

commit 09b4acfd81669583a38352550dc61107c72a1d42
Author: David Disseldorp <[email protected]>
Date:   Tue Mar 1 19:17:48 2011 +0100

    s3-printing: clean up get_correct_cversion error paths
    
    Remove an unneeded variable and simplify error paths.

commit 14446b528069bc27222929bb38cf72099e450018
Author: David Disseldorp <[email protected]>
Date:   Tue Mar 1 19:17:47 2011 +0100

    s3-printing: fix move_driver_to_download_area() error paths
    
    WERR_ACCESS_DENIED errors are mapped to WERR_UNKNOWN_PRINTER_DRIVER,
    resulting in incorrect error messages on Windows clients.
    
    move_driver_to_download_area() returns the same error status values
    to the caller via the *perr argument as well as the return value.
    
    The create_directory() call is not checked for error.

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

Summary of changes:
 source3/include/nt_printing.h               |    3 +-
 source3/printing/nt_printing.c              |  156 ++++++++++++---------------
 source3/rpc_server/spoolss/srv_spoolss_nt.c |    4 +-
 source3/rpc_server/srvsvc/srv_srvsvc_nt.c   |    2 +
 source3/smbd/msdfs.c                        |   34 ++++--
 5 files changed, 99 insertions(+), 100 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source3/include/nt_printing.h b/source3/include/nt_printing.h
index 6db306e..02a72b3 100644
--- a/source3/include/nt_printing.h
+++ b/source3/include/nt_printing.h
@@ -170,8 +170,7 @@ bool delete_driver_files(const struct 
auth_serversupplied_info *server_info,
                         const struct spoolss_DriverInfo8 *r);
 
 WERROR move_driver_to_download_area(struct pipes_struct *p,
-                                   struct spoolss_AddDriverInfoCtr *r,
-                                   WERROR *perr);
+                                   struct spoolss_AddDriverInfoCtr *r);
 
 WERROR clean_up_driver_struct(TALLOC_CTX *mem_ctx,
                              struct pipes_struct *rpc_pipe,
diff --git a/source3/printing/nt_printing.c b/source3/printing/nt_printing.c
index 869fcad..d77320c 100644
--- a/source3/printing/nt_printing.c
+++ b/source3/printing/nt_printing.c
@@ -579,13 +579,12 @@ static uint32 get_correct_cversion(struct pipes_struct *p,
                                   const char *driverpath_in,
                                   WERROR *perr)
 {
-       int               cversion;
+       int cversion = -1;
        NTSTATUS          nt_status;
        struct smb_filename *smb_fname = NULL;
        char *driverpath = NULL;
        files_struct      *fsp = NULL;
        connection_struct *conn = NULL;
-       NTSTATUS status;
        char *oldcwd;
        char *printdollar = NULL;
        int printdollar_snum;
@@ -650,7 +649,7 @@ static uint32 get_correct_cversion(struct pipes_struct *p,
                goto error_exit;
        }
 
-       status = SMB_VFS_CREATE_FILE(
+       nt_status = SMB_VFS_CREATE_FILE(
                conn,                                   /* conn */
                NULL,                                   /* req */
                0,                                      /* root_dir_fid */
@@ -668,7 +667,7 @@ static uint32 get_correct_cversion(struct pipes_struct *p,
                &fsp,                                   /* result */
                NULL);                                  /* pinfo */
 
-       if (!NT_STATUS_IS_OK(status)) {
+       if (!NT_STATUS_IS_OK(nt_status)) {
                DEBUG(3,("get_correct_cversion: Can't open file [%s], errno = "
                         "%d\n", smb_fname_str_dbg(smb_fname), errno));
                *perr = WERR_ACCESS_DENIED;
@@ -679,12 +678,14 @@ static uint32 get_correct_cversion(struct pipes_struct *p,
                int    ret;
 
                ret = get_file_version(fsp, smb_fname->base_name, &major, 
&minor);
-               if (ret == -1) goto error_exit;
-
-               if (!ret) {
+               if (ret == -1) {
+                       *perr = WERR_INVALID_PARAM;
+                       goto error_exit;
+               } else if (!ret) {
                        DEBUG(6,("get_correct_cversion: Version info not "
                                 "found [%s]\n",
                                 smb_fname_str_dbg(smb_fname)));
+                       *perr = WERR_INVALID_PARAM;
                        goto error_exit;
                }
 
@@ -716,23 +717,22 @@ static uint32 get_correct_cversion(struct pipes_struct *p,
 
        DEBUG(10,("get_correct_cversion: Driver file [%s] cversion = %d\n",
                  smb_fname_str_dbg(smb_fname), cversion));
-
-       goto done;
+       *perr = WERR_OK;
 
  error_exit:
-       cversion = -1;
- done:
        TALLOC_FREE(smb_fname);
        if (fsp != NULL) {
                close_file(NULL, fsp, NORMAL_CLOSE);
        }
        if (conn != NULL) {
                vfs_ChDir(conn, oldcwd);
+               SMB_VFS_DISCONNECT(conn);
                conn_free(conn);
        }
-       if (cversion != -1) {
-               *perr = WERR_OK;
+       if (!NT_STATUS_IS_OK(*perr)) {
+               cversion = -1;
        }
+
        return cversion;
 }
 
@@ -940,8 +940,7 @@ static WERROR move_driver_file_to_download_area(TALLOC_CTX 
*mem_ctx,
 }
 
 WERROR move_driver_to_download_area(struct pipes_struct *p,
-                                   struct spoolss_AddDriverInfoCtr *r,
-                                   WERROR *perr)
+                                   struct spoolss_AddDriverInfoCtr *r)
 {
        struct spoolss_AddDriverInfo3 *driver;
        struct spoolss_AddDriverInfo3 converted_driver;
@@ -956,8 +955,7 @@ WERROR move_driver_to_download_area(struct pipes_struct *p,
        char *oldcwd;
        char *printdollar = NULL;
        int printdollar_snum;
-
-       *perr = WERR_OK;
+       WERROR err = WERR_OK;
 
        switch (r->level) {
        case 3:
@@ -979,11 +977,9 @@ WERROR move_driver_to_download_area(struct pipes_struct *p,
 
        printdollar_snum = find_service(ctx, "print$", &printdollar);
        if (!printdollar) {
-               *perr = WERR_NOMEM;
                return WERR_NOMEM;
        }
        if (printdollar_snum == -1) {
-               *perr = WERR_NO_SUCH_SHARE;
                return WERR_NO_SUCH_SHARE;
        }
 
@@ -993,8 +989,8 @@ WERROR move_driver_to_download_area(struct pipes_struct *p,
        if (!NT_STATUS_IS_OK(nt_status)) {
                DEBUG(0,("move_driver_to_download_area: create_conn_struct "
                         "returned %s\n", nt_errstr(nt_status)));
-               *perr = ntstatus_to_werror(nt_status);
-               return *perr;
+               err = ntstatus_to_werror(nt_status);
+               return err;
        }
 
        new_dir = talloc_asprintf(ctx,
@@ -1002,18 +998,25 @@ WERROR move_driver_to_download_area(struct pipes_struct 
*p,
                                short_architecture,
                                driver->version);
        if (!new_dir) {
-               *perr = WERR_NOMEM;
+               err = WERR_NOMEM;
                goto err_exit;
        }
        nt_status = driver_unix_convert(conn, new_dir, &smb_dname);
        if (!NT_STATUS_IS_OK(nt_status)) {
-               *perr = WERR_NOMEM;
+               err = WERR_NOMEM;
                goto err_exit;
        }
 
        DEBUG(5,("Creating first directory: %s\n", smb_dname->base_name));
 
-       create_directory(conn, NULL, smb_dname);
+       nt_status = create_directory(conn, NULL, smb_dname);
+       if (!NT_STATUS_IS_OK(nt_status)
+        && !NT_STATUS_EQUAL(nt_status, NT_STATUS_OBJECT_NAME_COLLISION)) {
+               DEBUG(0, ("failed to create driver destination directory: %s\n",
+                         nt_errstr(nt_status)));
+               err = ntstatus_to_werror(nt_status);
+               goto err_exit;
+       }
 
        /* For each driver file, archi\filexxx.yyy, if there is a duplicate file
         * listed for this driver which has already been moved, skip it (note:
@@ -1036,16 +1039,13 @@ WERROR move_driver_to_download_area(struct pipes_struct 
*p,
 
        if (driver->driver_path && strlen(driver->driver_path)) {
 
-               *perr = move_driver_file_to_download_area(ctx,
-                                                         conn,
-                                                         driver->driver_path,
-                                                         short_architecture,
-                                                         driver->version,
-                                                         ver);
-               if (!W_ERROR_IS_OK(*perr)) {
-                       if (W_ERROR_EQUAL(*perr, WERR_ACCESS_DENIED)) {
-                               ver = -1;
-                       }
+               err = move_driver_file_to_download_area(ctx,
+                                                       conn,
+                                                       driver->driver_path,
+                                                       short_architecture,
+                                                       driver->version,
+                                                       ver);
+               if (!W_ERROR_IS_OK(err)) {
                        goto err_exit;
                }
        }
@@ -1053,16 +1053,13 @@ WERROR move_driver_to_download_area(struct pipes_struct 
*p,
        if (driver->data_file && strlen(driver->data_file)) {
                if (!strequal(driver->data_file, driver->driver_path)) {
 
-                       *perr = move_driver_file_to_download_area(ctx,
-                                                                 conn,
-                                                                 
driver->data_file,
-                                                                 
short_architecture,
-                                                                 
driver->version,
-                                                                 ver);
-                       if (!W_ERROR_IS_OK(*perr)) {
-                               if (W_ERROR_EQUAL(*perr, WERR_ACCESS_DENIED)) {
-                                       ver = -1;
-                               }
+                       err = move_driver_file_to_download_area(ctx,
+                                                               conn,
+                                                               
driver->data_file,
+                                                               
short_architecture,
+                                                               driver->version,
+                                                               ver);
+                       if (!W_ERROR_IS_OK(err)) {
                                goto err_exit;
                        }
                }
@@ -1072,16 +1069,13 @@ WERROR move_driver_to_download_area(struct pipes_struct 
*p,
                if (!strequal(driver->config_file, driver->driver_path) &&
                    !strequal(driver->config_file, driver->data_file)) {
 
-                       *perr = move_driver_file_to_download_area(ctx,
-                                                                 conn,
-                                                                 
driver->config_file,
-                                                                 
short_architecture,
-                                                                 
driver->version,
-                                                                 ver);
-                       if (!W_ERROR_IS_OK(*perr)) {
-                               if (W_ERROR_EQUAL(*perr, WERR_ACCESS_DENIED)) {
-                                       ver = -1;
-                               }
+                       err = move_driver_file_to_download_area(ctx,
+                                                               conn,
+                                                               
driver->config_file,
+                                                               
short_architecture,
+                                                               driver->version,
+                                                               ver);
+                       if (!W_ERROR_IS_OK(err)) {
                                goto err_exit;
                        }
                }
@@ -1092,16 +1086,13 @@ WERROR move_driver_to_download_area(struct pipes_struct 
*p,
                    !strequal(driver->help_file, driver->data_file) &&
                    !strequal(driver->help_file, driver->config_file)) {
 
-                       *perr = move_driver_file_to_download_area(ctx,
-                                                                 conn,
-                                                                 
driver->help_file,
-                                                                 
short_architecture,
-                                                                 
driver->version,
-                                                                 ver);
-                       if (!W_ERROR_IS_OK(*perr)) {
-                               if (W_ERROR_EQUAL(*perr, WERR_ACCESS_DENIED)) {
-                                       ver = -1;
-                               }
+                       err = move_driver_file_to_download_area(ctx,
+                                                               conn,
+                                                               
driver->help_file,
+                                                               
short_architecture,
+                                                               driver->version,
+                                                               ver);
+                       if (!W_ERROR_IS_OK(err)) {
                                goto err_exit;
                        }
                }
@@ -1120,16 +1111,13 @@ WERROR move_driver_to_download_area(struct pipes_struct 
*p,
                                        }
                                }
 
-                               *perr = move_driver_file_to_download_area(ctx,
-                                                                         conn,
-                                                                         
driver->dependent_files->string[i],
-                                                                         
short_architecture,
-                                                                         
driver->version,
-                                                                         ver);
-                               if (!W_ERROR_IS_OK(*perr)) {
-                                       if (W_ERROR_EQUAL(*perr, 
WERR_ACCESS_DENIED)) {
-                                               ver = -1;
-                                       }
+                               err = move_driver_file_to_download_area(ctx,
+                                                                       conn,
+                                                                       
driver->dependent_files->string[i],
+                                                                       
short_architecture,
+                                                                       
driver->version,
+                                                                       ver);
+                               if (!W_ERROR_IS_OK(err)) {
                                        goto err_exit;
                                }
                        }
@@ -1137,21 +1125,17 @@ WERROR move_driver_to_download_area(struct pipes_struct 
*p,
                }
        }
 
+       err = WERR_OK;
   err_exit:
        TALLOC_FREE(smb_dname);
 
        if (conn != NULL) {
                vfs_ChDir(conn, oldcwd);
+               SMB_VFS_DISCONNECT(conn);
                conn_free(conn);
        }
 
-       if (W_ERROR_EQUAL(*perr, WERR_OK)) {
-               return WERR_OK;
-       }
-       if (ver == -1) {
-               return WERR_UNKNOWN_PRINTER_DRIVER;
-       }
-       return (*perr);
+       return err;
 }
 
 /****************************************************************************
@@ -1925,7 +1909,8 @@ bool delete_driver_files(const struct 
auth_serversupplied_info *session_info,
 
        if ( !CAN_WRITE(conn) ) {
                DEBUG(3,("delete_driver_files: Cannot delete print driver when 
[print$] is read-only\n"));
-               goto fail;
+               ret = false;
+               goto err_out;
        }
 
        /* now delete the files; must strip the '\print$' string from
@@ -1981,12 +1966,11 @@ bool delete_driver_files(const struct 
auth_serversupplied_info *session_info,
                }
        }
 
-       goto done;
- fail:
-       ret = false;
- done:
+       ret = true;
+ err_out:
        if (conn != NULL) {
                vfs_ChDir(conn, oldcwd);
+               SMB_VFS_DISCONNECT(conn);
                conn_free(conn);
        }
        return ret;
diff --git a/source3/rpc_server/spoolss/srv_spoolss_nt.c 
b/source3/rpc_server/spoolss/srv_spoolss_nt.c
index 828d06a..510dde2 100644
--- a/source3/rpc_server/spoolss/srv_spoolss_nt.c
+++ b/source3/rpc_server/spoolss/srv_spoolss_nt.c
@@ -8003,8 +8003,8 @@ WERROR _spoolss_AddPrinterDriverEx(struct pipes_struct *p,
                goto done;
 
        DEBUG(5,("Moving driver to final destination\n"));
-       if( !W_ERROR_IS_OK(err = move_driver_to_download_area(p, r->in.info_ctr,
-                                                             &err)) ) {
+       err = move_driver_to_download_area(p, r->in.info_ctr);
+       if (!W_ERROR_IS_OK(err)) {
                goto done;
        }
 
diff --git a/source3/rpc_server/srvsvc/srv_srvsvc_nt.c 
b/source3/rpc_server/srvsvc/srv_srvsvc_nt.c
index 31df488..40687a0 100644
--- a/source3/rpc_server/srvsvc/srv_srvsvc_nt.c
+++ b/source3/rpc_server/srvsvc/srv_srvsvc_nt.c
@@ -2231,6 +2231,7 @@ error_exit:
        }
 
        if (conn) {
+               SMB_VFS_DISCONNECT(conn);
                conn_free(conn);
        }
 
@@ -2374,6 +2375,7 @@ error_exit:
        }
 
        if (conn) {
+               SMB_VFS_DISCONNECT(conn);
                conn_free(conn);
        }
 
diff --git a/source3/smbd/msdfs.c b/source3/smbd/msdfs.c
index 07b0933..c11e66e 100644
--- a/source3/smbd/msdfs.c
+++ b/source3/smbd/msdfs.c
@@ -212,7 +212,7 @@ static NTSTATUS parse_dfs_path(connection_struct *conn,
 
 /********************************************************
  Fake up a connection struct for the VFS layer.
- Note this CHANGES CWD !!!! JRA.
+ Note: this performs a vfs connect and CHANGES CWD !!!! JRA.
 *********************************************************/
 
 NTSTATUS create_conn_struct(TALLOC_CTX *ctx,
@@ -225,6 +225,7 @@ NTSTATUS create_conn_struct(TALLOC_CTX *ctx,
        connection_struct *conn;
        char *connpath;
        char *oldcwd;
+       const char *vfs_user;
 
        conn = TALLOC_ZERO_P(ctx, connection_struct);
        if (conn == NULL) {
@@ -265,6 +266,10 @@ NTSTATUS create_conn_struct(TALLOC_CTX *ctx,
                        TALLOC_FREE(conn);
                        return NT_STATUS_NO_MEMORY;
                }
+               vfs_user = conn->session_info->unix_name;
+       } else {
+               /* use current authenticated user in absence of session_info */
+               vfs_user = get_current_username();
        }
 
        set_conn_connectpath(conn, connpath);
@@ -276,6 +281,13 @@ NTSTATUS create_conn_struct(TALLOC_CTX *ctx,
                return status;
        }
 
+       /* this must be the first filesystem operation that we do */
+       if (SMB_VFS_CONNECT(conn, lp_servicename(snum), vfs_user) < 0) {
+               DEBUG(0,("VFS connect failed!\n"));
+               conn_free(conn);
+               return NT_STATUS_UNSUCCESSFUL;
+       }
+
        conn->fs_capabilities = SMB_VFS_FS_CAPABILITIES(conn, &conn->ts_res);
 
        /*
@@ -937,10 +949,7 @@ NTSTATUS get_referred_path(TALLOC_CTX *ctx,
        if (!NT_STATUS_EQUAL(status, NT_STATUS_PATH_NOT_COVERED)) {
                DEBUG(3,("get_referred_path: No valid referrals for path %s\n",
                        dfs_path));
-               vfs_ChDir(conn, oldpath);
-               conn_free(conn);
-               TALLOC_FREE(pdp);
-               return status;
+               goto err_exit;
        }
 
        /* We know this is a valid dfs link. Parse the targetpath. */
@@ -949,16 +958,17 @@ NTSTATUS get_referred_path(TALLOC_CTX *ctx,
                                &jucn->referral_count)) {
                DEBUG(3,("get_referred_path: failed to parse symlink "
                        "target %s\n", targetpath ));
-               vfs_ChDir(conn, oldpath);
-               conn_free(conn);
-               TALLOC_FREE(pdp);
-               return NT_STATUS_NOT_FOUND;
+               status = NT_STATUS_NOT_FOUND;
+               goto err_exit;
        }
 
+       status = NT_STATUS_OK;
+ err_exit:
        vfs_ChDir(conn, oldpath);
+       SMB_VFS_DISCONNECT(conn);
        conn_free(conn);
        TALLOC_FREE(pdp);
-       return NT_STATUS_OK;
+       return status;
 }
 
 static int setup_ver2_dfs_referral(const char *pathname,
@@ -1373,6 +1383,7 @@ static bool junction_to_local_path(const struct 
junction_map *jucn,
                        jucn->volume_name);
        if (!*pp_path_out) {
                vfs_ChDir(*conn_out, *oldpath);
+               SMB_VFS_DISCONNECT(*conn_out);
                conn_free(*conn_out);
                return False;
        }
@@ -1461,6 +1472,7 @@ bool create_msdfs_link(const struct junction_map *jucn)
 
 out:
        vfs_ChDir(conn, cwd);
+       SMB_VFS_DISCONNECT(conn);
        conn_free(conn);
        return ret;
 }
@@ -1492,6 +1504,7 @@ bool remove_msdfs_link(const struct junction_map *jucn)
 
        TALLOC_FREE(smb_fname);
        vfs_ChDir(conn, cwd);
+       SMB_VFS_DISCONNECT(conn);
        conn_free(conn);
        return ret;
 }
@@ -1556,6 +1569,7 @@ static int count_dfs_links(TALLOC_CTX *ctx, int snum)
 
 out:
        vfs_ChDir(conn, cwd);
+       SMB_VFS_DISCONNECT(conn);
        conn_free(conn);
        return cnt;
 }


-- 
Samba Shared Repository

Reply via email to