From f813f60a8be820c6347ad5862c72483c53129cc0 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Mon, 18 Feb 2019 12:47:30 +0100 Subject: [PATCH] Revert "HACK... https://bugzilla.samba.org/show_bug.cgi?id=12892" This reverts commit 4da2a7a9f9261ab18207699a102069040b652c24. --- selftest/target/Samba3.pm | 4 +- source3/include/vfs.h | 3 + source3/libads/ads_proto.h | 2 - source3/printing/nt_printing_migrate.h | 2 - source3/printing/printspoolss.c | 165 +++++++------------------ source3/printing/tests/vlp.c | 9 +- source3/rpc_client/cli_lsarpc.h | 2 - source3/rpc_server/rpc_ncacn_np.h | 1 - source3/rpc_server/srv_pipe.c | 6 +- source3/smbd/smb2_write.c | 25 ---- source3/utils/net.h | 1 - 11 files changed, 54 insertions(+), 166 deletions(-) diff --git a/selftest/target/Samba3.pm b/selftest/target/Samba3.pm index 044e54a47384..f11bb9312df6 100755 --- a/selftest/target/Samba3.pm +++ b/selftest/target/Samba3.pm @@ -1694,7 +1694,7 @@ sub provision($$$$$$$$$) $max_uid = $unix_uid; } - $uid_root = 0; #$max_uid - 1; + $uid_root = $max_uid - 1; $uid_nobody = $max_uid - 2; $uid_pdbtest = $max_uid - 3; $uid_pdbtest2 = $max_uid - 4; @@ -1716,7 +1716,7 @@ sub provision($$$$$$$$$) $gid_nobody = $max_gid - 1; $gid_nogroup = $max_gid - 2; - $gid_root = 0; #$max_gid - 3; + $gid_root = $max_gid - 3; $gid_domusers = $max_gid - 4; $gid_domadmins = $max_gid - 5; $gid_userdup = $max_gid - 6; diff --git a/source3/include/vfs.h b/source3/include/vfs.h index 1f5e1e547aff..8c35fa5ecc7a 100644 --- a/source3/include/vfs.h +++ b/source3/include/vfs.h @@ -481,6 +481,9 @@ typedef struct connection_struct { name_compare_entry *veto_oplock_list; /* Per-share list of files to refuse oplocks on. */ name_compare_entry *aio_write_behind_list; /* Per-share list of files to use aio write behind on. */ struct trans_state *pending_trans; + + struct rpc_pipe_client *spoolss_pipe; + } connection_struct; struct smbd_smb2_request; diff --git a/source3/libads/ads_proto.h b/source3/libads/ads_proto.h index 9c91d4e0f601..154bf67f9641 100644 --- a/source3/libads/ads_proto.h +++ b/source3/libads/ads_proto.h @@ -32,8 +32,6 @@ #ifndef _LIBADS_ADS_PROTO_H_ #define _LIBADS_ADS_PROTO_H_ -struct rpc_pipe_client; - /* The following definitions come from libads/ads_struct.c */ char *ads_build_path(const char *realm, const char *sep, const char *field, int reverse); diff --git a/source3/printing/nt_printing_migrate.h b/source3/printing/nt_printing_migrate.h index 72ad2805978c..0c9800ddcd5c 100644 --- a/source3/printing/nt_printing_migrate.h +++ b/source3/printing/nt_printing_migrate.h @@ -21,8 +21,6 @@ #ifndef _NT_PRINTING_MIGRATE_H_ #define _NT_PRINTING_MIGRATE_H_ -struct rpc_pipe_client; - NTSTATUS printing_tdb_migrate_form(TALLOC_CTX *mem_ctx, struct rpc_pipe_client *winreg_pipe, const char *key_name, diff --git a/source3/printing/printspoolss.c b/source3/printing/printspoolss.c index c6815c2f89a2..9d565de120ad 100644 --- a/source3/printing/printspoolss.c +++ b/source3/printing/printspoolss.c @@ -30,8 +30,6 @@ struct print_file_data { char *svcname; char *docname; char *filename; - uint64_t offset; - struct rpc_pipe_client *spoolss_pipe; struct policy_handle handle; uint32_t jobid; uint16_t rap_jobid; @@ -123,31 +121,30 @@ NTSTATUS print_spool_open(files_struct *fsp, lp_path(talloc_tos(), SNUM(fsp->conn)), PRINT_SPOOL_PREFIX); - pf->filename = talloc_asprintf(pf, "%s.raw", pf->docname); if (!pf->filename) { status = NT_STATUS_NO_MEMORY; goto done; } errno = 0; mask = umask(S_IRWXO | S_IRWXG); - fd = -1;// mkstemp(pf->filename); + fd = mkstemp(pf->filename); umask(mask); - //if (fd == -1) { - // if (errno == EACCES) { - // /* Common setup error, force a report. */ - // DEBUG(0, ("Insufficient permissions " - // "to open spool file %s.\n", - // pf->filename)); - // } else { - // /* Normal case, report at level 3 and above. */ - // DEBUG(3, ("can't open spool file %s,\n", - // pf->filename)); - // DEBUGADD(3, ("errno = %d (%s).\n", - // errno, strerror(errno))); - // } - // status = map_nt_error_from_unix(errno); - // goto done; - //} + if (fd == -1) { + if (errno == EACCES) { + /* Common setup error, force a report. */ + DEBUG(0, ("Insufficient permissions " + "to open spool file %s.\n", + pf->filename)); + } else { + /* Normal case, report at level 3 and above. */ + DEBUG(3, ("can't open spool file %s,\n", + pf->filename)); + DEBUGADD(3, ("errno = %d (%s).\n", + errno, strerror(errno))); + } + status = map_nt_error_from_unix(errno); + goto done; + } /* now open a document over spoolss so that it does * all printer verification, and eventually assigns @@ -159,11 +156,11 @@ NTSTATUS print_spool_open(files_struct *fsp, fsp->conn->sconn->remote_address, fsp->conn->sconn->local_address, fsp->conn->sconn->msg_ctx, - &pf->spoolss_pipe); + &fsp->conn->spoolss_pipe); if (!NT_STATUS_IS_OK(status)) { goto done; } - b = pf->spoolss_pipe->binding_handle; + b = fsp->conn->spoolss_pipe->binding_handle; ZERO_STRUCT(devmode_ctr); @@ -219,13 +216,13 @@ NTSTATUS print_spool_open(files_struct *fsp, goto done; } - //if (sys_fstat(fd, &fsp->fsp_name->st, false) != 0) { - // status = map_nt_error_from_unix(errno); - // goto done; - //} + if (sys_fstat(fd, &fsp->fsp_name->st, false) != 0) { + status = map_nt_error_from_unix(errno); + goto done; + } - //fsp->file_id = vfs_file_id_from_sbuf(fsp->conn, &fsp->fsp_name->st); - //fsp->fh->fd = fd; + fsp->file_id = vfs_file_id_from_sbuf(fsp->conn, &fsp->fsp_name->st); + fsp->fh->fd = fd; fsp->vuid = current_vuid; fsp->can_lock = false; @@ -252,7 +249,6 @@ done: if (pf && pf->jobid) { print_spool_terminate(fsp->conn, pf); } - TALLOC_FREE(pf); } talloc_free(tmp_ctx); return status; @@ -262,79 +258,12 @@ int print_spool_write(files_struct *fsp, const char *data, uint32_t size, off_t offset, uint32_t *written) { - struct print_file_data *pf = fsp->print_file; - NTSTATUS status; - TALLOC_CTX *tmp_ctx = talloc_tos(); - struct dcerpc_binding_handle *b = NULL; - DATA_BLOB buffer; - //int fd = -1; - WERROR werr; SMB_STRUCT_STAT st; ssize_t n; int ret; - uint64_t remaining; *written = 0; - if (pf == NULL) { - return EBADF; - } - if (pf->spoolss_pipe == NULL) { - return EBADF; - } - b = pf->spoolss_pipe->binding_handle; - - /* When print files go beyond 4GB, the 32-bit offset sent in - * old SMBwrite calls is relative to the current 4GB chunk - * we're writing to. - * Discovered by Sebastian Kloska . - */ - if (offset < 0xffffffff00000000LL) { - offset = (pf->offset & 0xffffffff00000000LL) + offset; - } - - if ((uint64_t)offset != pf->offset) { - // TODO: check what windows does, with non sequential - // writes. - ret = EINVAL; - goto error; - } - - remaining = UINT64_MAX - pf->offset; - if (size > remaining) { - ret = EINVAL; - goto error; - } - - buffer = data_blob_const(data, size); - - status = dcerpc_spoolss_WritePrinter(b, tmp_ctx, - &pf->handle, - buffer, - buffer.length, - written, - &werr); - if (!NT_STATUS_IS_OK(status)) { - ret = EINVAL; - goto error; - } - if (!W_ERROR_IS_OK(werr)) { - //status = werror_to_ntstatus(werr); - ret = EINVAL; - goto error; - } - - if (*written > size) { - //status = NT_STATUS_INVALID_PARAMETER; - ret = EINVAL; - goto error; - } - - pf->offset += *written; - return 0; -error: - print_spool_terminate(fsp->conn, fsp->print_file); - return ret; /* first of all stat file to find out if it is still there. * spoolss may have deleted it to signal someone has killed * the job through it's interface */ @@ -376,7 +305,6 @@ error: void print_spool_end(files_struct *fsp, enum file_close_type close_type) { - struct print_file_data *pf = fsp->print_file; NTSTATUS status; WERROR werr; struct dcerpc_binding_handle *b = NULL; @@ -398,10 +326,7 @@ void print_spool_end(files_struct *fsp, enum file_close_type close_type) } } - if (pf->spoolss_pipe == NULL) { - return; - } - b = pf->spoolss_pipe->binding_handle; + b = fsp->conn->spoolss_pipe->binding_handle; switch (close_type) { case NORMAL_CLOSE: @@ -420,7 +345,6 @@ void print_spool_end(files_struct *fsp, enum file_close_type close_type) print_spool_terminate(fsp->conn, fsp->print_file); break; } - TALLOC_FREE(fsp->print_file); } @@ -433,30 +357,29 @@ void print_spool_terminate(struct connection_struct *conn, rap_jobid_delete(print_file->svcname, print_file->jobid); - //status = rpc_pipe_open_interface(conn, - // &ndr_table_spoolss, - // conn->session_info, - // conn->sconn->remote_address, - // conn->sconn->local_address, - // conn->sconn->msg_ctx, - // &conn->spoolss_pipe); - //if (!NT_STATUS_IS_OK(status)) { - // DEBUG(0, ("print_spool_terminate: " - // "Failed to get spoolss pipe [%s]\n", - // nt_errstr(status))); - // return; - //} - if (print_file->spoolss_pipe == NULL) { + status = rpc_pipe_open_interface(conn, + &ndr_table_spoolss, + conn->session_info, + conn->sconn->remote_address, + conn->sconn->local_address, + conn->sconn->msg_ctx, + &conn->spoolss_pipe); + if (!NT_STATUS_IS_OK(status)) { + DEBUG(0, ("print_spool_terminate: " + "Failed to get spoolss pipe [%s]\n", + nt_errstr(status))); return; } - b = print_file->spoolss_pipe->binding_handle; + b = conn->spoolss_pipe->binding_handle; - status = dcerpc_spoolss_AbortPrinter(b, print_file, - &print_file->handle, - &werr); + status = dcerpc_spoolss_SetJob(b, print_file, + &print_file->handle, + print_file->jobid, + NULL, SPOOLSS_JOB_CONTROL_DELETE, + &werr); if (!NT_STATUS_IS_OK(status) || !NT_STATUS_IS_OK(status = werror_to_ntstatus(werr))) { - DEBUG(3, ("Failed to abort printer job %d [%s]\n", + DEBUG(3, ("Failed to delete job %d [%s]\n", print_file->jobid, nt_errstr(status))); return; } diff --git a/source3/printing/tests/vlp.c b/source3/printing/tests/vlp.c index aaad6af4db3e..d596c3141aba 100644 --- a/source3/printing/tests/vlp.c +++ b/source3/printing/tests/vlp.c @@ -221,7 +221,6 @@ static int print_command(int argc, char **argv) char *printer; fstring keystr; struct passwd *pw; - const char *user = NULL; TDB_DATA value, queue; struct vlp_job job; @@ -239,15 +238,11 @@ static int print_command(int argc, char **argv) slprintf(job.jobname, sizeof(job.jobname) - 1, "%s", argv[2]); if (!(pw = getpwuid(geteuid()))) { - printf("getpwuid(%d) failed, nss_wrapper_enabled[%d]\n", - geteuid(), nss_wrapper_enabled()); - user = "ignore"; + printf("getpwuid failed\n"); return 1; - } else { - user = pw->pw_name; } - slprintf(job.owner, sizeof(job.owner) - 1, "%s", user); + slprintf(job.owner, sizeof(job.owner) - 1, "%s", pw->pw_name); job.jobid = next_jobnum(printer); job.size = 666; diff --git a/source3/rpc_client/cli_lsarpc.h b/source3/rpc_client/cli_lsarpc.h index f01dcb906dfd..f716b049e127 100644 --- a/source3/rpc_client/cli_lsarpc.h +++ b/source3/rpc_client/cli_lsarpc.h @@ -29,8 +29,6 @@ /* The following definitions come from rpc_client/cli_lsarpc.c */ -struct rpc_pipe_client; - /** * @brief Open a LSA policy. * diff --git a/source3/rpc_server/rpc_ncacn_np.h b/source3/rpc_server/rpc_ncacn_np.h index 50e7330fe23c..9ba58644ec05 100644 --- a/source3/rpc_server/rpc_ncacn_np.h +++ b/source3/rpc_server/rpc_ncacn_np.h @@ -20,7 +20,6 @@ #ifndef _RPC_NCACN_NP_H_ #define _RPC_NCACN_NP_H_ -struct rpc_pipe_client; struct dcerpc_binding_handle; struct ndr_interface_table; struct tsocket_address; diff --git a/source3/rpc_server/srv_pipe.c b/source3/rpc_server/srv_pipe.c index 349458bff3db..7a1c61594678 100644 --- a/source3/rpc_server/srv_pipe.c +++ b/source3/rpc_server/srv_pipe.c @@ -1578,10 +1578,10 @@ static bool api_rpcTNP(struct pipes_struct *p, struct ncacn_packet *pkt, /* Check for buffer underflow in rpc parsing */ if ((DEBUGLEVEL >= 10) && - (pkt->frag_length < p->out_data.rdata.length)) { + (pkt->frag_length < p->in_data.data.length)) { DEBUG(10, ("api_rpcTNP: rpc input buffer underflow (parse error?)\n")); - dump_data(10, p->out_data.rdata.data + pkt->frag_length, - p->out_data.rdata.length - pkt->frag_length); + dump_data(10, p->in_data.data.data + pkt->frag_length, + p->in_data.data.length - pkt->frag_length); } return True; diff --git a/source3/smbd/smb2_write.c b/source3/smbd/smb2_write.c index d14da5b3de92..ee95bd317aef 100644 --- a/source3/smbd/smb2_write.c +++ b/source3/smbd/smb2_write.c @@ -24,7 +24,6 @@ #include "../libcli/smb/smb_common.h" #include "../lib/util/tevent_ntstatus.h" #include "rpc_server/srv_pipe_hnd.h" -#include "printing.h" #undef DBGC_CLASS #define DBGC_CLASS DBGC_SMB2 @@ -322,30 +321,6 @@ static struct tevent_req *smbd_smb2_write_send(TALLOC_CTX *mem_ctx, return req; } - if (IS_PRINT(smbreq->conn)) { - uint32_t out_count = 0; - int ret; - - if (fsp->print_file == NULL) { - tevent_req_nterror(req, NT_STATUS_FILE_CLOSED); - return tevent_req_post(req, ev); - } - - ret = print_spool_write(fsp, - (const char *)in_data.data, - in_data.length, - in_offset, - &out_count); - if (ret) { - status = map_nt_error_from_unix(ret); - tevent_req_nterror(req, status); - return tevent_req_post(req, ev); - } - state->out_count = out_count; - tevent_req_done(req); - return tevent_req_post(req, ev); - } - if (!CHECK_WRITE(fsp)) { tevent_req_nterror(req, NT_STATUS_ACCESS_DENIED); return tevent_req_post(req, ev); diff --git a/source3/utils/net.h b/source3/utils/net.h index dc4b94f546a4..0d01ad450102 100644 --- a/source3/utils/net.h +++ b/source3/utils/net.h @@ -23,7 +23,6 @@ */ struct cli_state; -struct rpc_pipe_client; #include "../librpc/gen_ndr/lsa.h" -- 2.34.1