]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
Remove some smb fsp knowledge from rpc_server/
authorVolker Lendecke <vl@samba.org>
Tue, 20 Jan 2009 14:21:04 +0000 (15:21 +0100)
committerVolker Lendecke <vl@samba.org>
Tue, 20 Jan 2009 15:41:14 +0000 (16:41 +0100)
np_open/read/write don't have to know about files_struct

source3/include/proto.h
source3/rpc_server/srv_pipe_hnd.c
source3/smbd/ipc.c
source3/smbd/nttrans.c
source3/smbd/pipes.c

index 71ad2590850b1d4c74afa156497d29eb95d27e02..e3d93494ffe9e05c57691e014669841d845b87bf 100644 (file)
@@ -6226,11 +6226,13 @@ pipes_struct *get_next_internal_pipe(pipes_struct *p);
 void init_rpc_pipe_hnd(void);
 
 bool fsp_is_np(struct files_struct *fsp);
-NTSTATUS np_open(struct smb_request *smb_req, const char *name,
-                struct files_struct **pfsp);
-NTSTATUS np_write(struct files_struct *fsp, const uint8_t *data, size_t len,
-                 ssize_t *nwritten);
-NTSTATUS np_read(struct files_struct *fsp, uint8_t *data, size_t len,
+NTSTATUS np_open(TALLOC_CTX *mem_ctx, const char *name,
+                const char *client_address,
+                struct auth_serversupplied_info *server_info,
+                struct fake_file_handle **phandle);
+NTSTATUS np_write(struct fake_file_handle *handle, const uint8_t *data,
+                 size_t len, ssize_t *nwritten);
+NTSTATUS np_read(struct fake_file_handle *handle, uint8_t *data, size_t len,
                 ssize_t *nread, bool *is_data_outstanding);
 
 /* The following definitions come from rpc_server/srv_samr_util.c  */
@@ -7068,6 +7070,8 @@ bool authorise_login(int snum, fstring user, DATA_BLOB password,
 
 /* The following definitions come from smbd/pipes.c  */
 
+NTSTATUS open_np_file(struct smb_request *smb_req, const char *name,
+                     struct files_struct **pfsp);
 void reply_open_pipe_and_X(connection_struct *conn, struct smb_request *req);
 void reply_pipe_write(struct smb_request *req);
 void reply_pipe_write_and_X(struct smb_request *req);
index e574f0387dd4742ed6398b9cf63fc57064481101..cbb6a8f4bf47332470b860c32898fe6a74051d62 100644 (file)
@@ -1075,92 +1075,69 @@ static struct np_proxy_state *make_external_rpc_pipe_p(TALLOC_CTX *mem_ctx,
        return NULL;
 }
 
-NTSTATUS np_open(struct smb_request *smb_req, const char *name,
-                struct files_struct **pfsp)
+NTSTATUS np_open(TALLOC_CTX *mem_ctx, const char *name,
+                const char *client_address,
+                struct auth_serversupplied_info *server_info,
+                struct fake_file_handle **phandle)
 {
-       struct connection_struct *conn = smb_req->conn;
-       NTSTATUS status;
-       struct files_struct *fsp;
        const char **proxy_list;
+       struct fake_file_handle *handle;
 
-       proxy_list = lp_parm_string_list(SNUM(conn), "np", "proxy", NULL);
-
-       status = file_new(smb_req, conn, &fsp);
-       if (!NT_STATUS_IS_OK(status)) {
-               DEBUG(0, ("file_new failed: %s\n", nt_errstr(status)));
-               return status;
-       }
-
-       fsp->conn = conn;
-       fsp->fh->fd = -1;
-       fsp->vuid = smb_req->vuid;
-       fsp->can_lock = false;
-       fsp->access_mask = FILE_READ_DATA | FILE_WRITE_DATA;
-       string_set(&fsp->fsp_name, name);
+       proxy_list = lp_parm_string_list(-1, "np", "proxy", NULL);
 
-       fsp->fake_file_handle = talloc(NULL, struct fake_file_handle);
-       if (fsp->fake_file_handle == NULL) {
-               file_free(smb_req, fsp);
+       handle = talloc(mem_ctx, struct fake_file_handle);
+       if (handle == NULL) {
                return NT_STATUS_NO_MEMORY;
        }
 
        if ((proxy_list != NULL) && str_list_check_ci(proxy_list, name)) {
                struct np_proxy_state *p;
 
-               p = make_external_rpc_pipe_p(fsp->fake_file_handle, name,
-                                            conn->server_info);
+               p = make_external_rpc_pipe_p(handle, name, server_info);
 
-               fsp->fake_file_handle->type = FAKE_FILE_TYPE_NAMED_PIPE_PROXY;
-               fsp->fake_file_handle->private_data = p;
+               handle->type = FAKE_FILE_TYPE_NAMED_PIPE_PROXY;
+               handle->private_data = p;
        } else {
                struct pipes_struct *p;
 
                if (!is_known_pipename(name)) {
-                       file_free(smb_req, fsp);
+                       TALLOC_FREE(handle);
                        return NT_STATUS_OBJECT_NAME_NOT_FOUND;
                }
 
-               p = make_internal_rpc_pipe_p(fsp->fake_file_handle, name,
-                                            conn->client_address,
-                                            conn->server_info);
+               p = make_internal_rpc_pipe_p(handle, name, client_address,
+                                            server_info);
 
-               fsp->fake_file_handle->type = FAKE_FILE_TYPE_NAMED_PIPE;
-               fsp->fake_file_handle->private_data = p;
+               handle->type = FAKE_FILE_TYPE_NAMED_PIPE;
+               handle->private_data = p;
        }
 
-       if (fsp->fake_file_handle->private_data == NULL) {
-               file_free(smb_req, fsp);
+       if (handle->private_data == NULL) {
+               TALLOC_FREE(handle);
                return NT_STATUS_PIPE_NOT_AVAILABLE;
        }
 
-       *pfsp = fsp;
+       *phandle = handle;
 
        return NT_STATUS_OK;
 }
 
-NTSTATUS np_write(struct files_struct *fsp, const uint8_t *data, size_t len,
-                 ssize_t *nwritten)
+NTSTATUS np_write(struct fake_file_handle *handle, const uint8_t *data,
+                 size_t len, ssize_t *nwritten)
 {
-       if (!fsp_is_np(fsp)) {
-               return NT_STATUS_INVALID_HANDLE;
-       }
-
-       DEBUG(6, ("np_write: %x name: %s len: %d\n", (int)fsp->fnum,
-                 fsp->fsp_name, (int)len));
+       DEBUG(6, ("np_write: len: %d\n", (int)len));
        dump_data(50, data, len);
 
-       switch (fsp->fake_file_handle->type) {
+       switch (handle->type) {
        case FAKE_FILE_TYPE_NAMED_PIPE: {
                struct pipes_struct *p = talloc_get_type_abort(
-                       fsp->fake_file_handle->private_data,
-                       struct pipes_struct);
+                       handle->private_data, struct pipes_struct);
                *nwritten = write_to_internal_pipe(p, (char *)data, len);
                break;
        }
        case FAKE_FILE_TYPE_NAMED_PIPE_PROXY: {
                struct np_proxy_state *p = talloc_get_type_abort(
-                       fsp->fake_file_handle->private_data,
-                       struct np_proxy_state);
+                       handle->private_data, struct np_proxy_state);
                *nwritten = write_data(p->fd, (char *)data, len);
                break;
        }
@@ -1173,26 +1150,20 @@ NTSTATUS np_write(struct files_struct *fsp, const uint8_t *data, size_t len,
                ? NT_STATUS_OK : NT_STATUS_UNEXPECTED_IO_ERROR;
 }
 
-NTSTATUS np_read(struct files_struct *fsp, uint8_t *data, size_t len,
+NTSTATUS np_read(struct fake_file_handle *handle, uint8_t *data, size_t len,
                 ssize_t *nread, bool *is_data_outstanding)
 {
-       if (!fsp_is_np(fsp)) {
-               return NT_STATUS_INVALID_HANDLE;
-       }
-
-       switch (fsp->fake_file_handle->type) {
+       switch (handle->type) {
        case FAKE_FILE_TYPE_NAMED_PIPE: {
                struct pipes_struct *p = talloc_get_type_abort(
-                       fsp->fake_file_handle->private_data,
-                       struct pipes_struct);
+                       handle->private_data, struct pipes_struct);
                *nread = read_from_internal_pipe(p, (char *)data, len,
                                                 is_data_outstanding);
                break;
        }
        case FAKE_FILE_TYPE_NAMED_PIPE_PROXY: {
                struct np_proxy_state *p = talloc_get_type_abort(
-                       fsp->fake_file_handle->private_data,
-                       struct np_proxy_state);
+                       handle->private_data, struct np_proxy_state);
                int available = 0;
 
                *nread = sys_read(p->fd, (char *)data, len);
index fabc8393ce31fce4ff9b0f8d9edda012dc26edeb..7c150561b150fbb55b94115c395d44d9117cad69 100644 (file)
@@ -220,8 +220,14 @@ static void api_rpc_trans_reply(connection_struct *conn,
                return;
        }
 
-       status = np_read(fsp, rdata, max_trans_reply, &data_len,
-                        &is_data_outstanding);
+       if (!fsp_is_np(fsp)) {
+               SAFE_FREE(rdata);
+               api_no_reply(conn,req);
+               return;
+       }
+
+       status = np_read(fsp->fake_file_handle, rdata, max_trans_reply,
+                        &data_len, &is_data_outstanding);
        if (!NT_STATUS_IS_OK(status)) {
                SAFE_FREE(rdata);
                api_no_reply(conn,req);
@@ -355,7 +361,8 @@ static void api_fd_reply(connection_struct *conn, uint16 vuid,
        case TRANSACT_DCERPCCMD: {
                /* dce/rpc command */
                ssize_t nwritten;
-               status = np_write(fsp, data, tdscnt, &nwritten);
+               status = np_write(fsp->fake_file_handle, data, tdscnt,
+                                 &nwritten);
                if (!NT_STATUS_IS_OK(status)) {
                        api_no_reply(conn, req);
                        return;
index 63b4776fbc29fbb401993fcb66be250b439214ee..1ee3edbdbeaf1b2bed788f22ee11066ed2a30d68 100644 (file)
@@ -316,7 +316,7 @@ static void nt_open_pipe(char *fname, connection_struct *conn,
        /* Strip \\ off the name. */
        fname++;
 
-       status = np_open(req, fname, &fsp);
+       status = open_np_file(req, fname, &fsp);
        if (!NT_STATUS_IS_OK(status)) {
                if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
                        reply_botherror(req, NT_STATUS_OBJECT_NAME_NOT_FOUND,
index 4841882cc37e297765a88b028efff9572a0f3793..b148cff04571383a5e1d527c13ea390ee561717e 100644 (file)
 
 #define MAX_PIPE_NAME_LEN      24
 
+NTSTATUS open_np_file(struct smb_request *smb_req, const char *name,
+                     struct files_struct **pfsp)
+{
+       struct connection_struct *conn = smb_req->conn;
+       struct files_struct *fsp;
+       NTSTATUS status;
+
+       status = file_new(smb_req, conn, &fsp);
+       if (!NT_STATUS_IS_OK(status)) {
+               DEBUG(0, ("file_new failed: %s\n", nt_errstr(status)));
+               return status;
+       }
+
+       fsp->conn = conn;
+       fsp->fh->fd = -1;
+       fsp->vuid = smb_req->vuid;
+       fsp->can_lock = false;
+       fsp->access_mask = FILE_READ_DATA | FILE_WRITE_DATA;
+       string_set(&fsp->fsp_name, name);
+
+       status = np_open(NULL, name, conn->client_address,
+                        conn->server_info, &fsp->fake_file_handle);
+       if (!NT_STATUS_IS_OK(status)) {
+               DEBUG(10, ("np_open(%s) returned %s\n", name,
+                          nt_errstr(status)));
+               file_free(smb_req, fsp);
+               return status;
+       }
+
+       *pfsp = fsp;
+
+       return NT_STATUS_OK;
+}
+
 /****************************************************************************
  Reply to an open and X on a named pipe.
  This code is basically stolen from reply_open_and_X with some
@@ -77,7 +111,7 @@ void reply_open_pipe_and_X(connection_struct *conn, struct smb_request *req)
        }
 #endif
 
-       status = np_open(req, fname, &fsp);
+       status = open_np_file(req, fname, &fsp);
        if (!NT_STATUS_IS_OK(status)) {
                if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
                        reply_botherror(req, NT_STATUS_OBJECT_NAME_NOT_FOUND,
@@ -133,7 +167,14 @@ void reply_pipe_write(struct smb_request *req)
                nwritten = 0;
        } else {
                NTSTATUS status;
-               status = np_write(fsp, data, numtowrite, &nwritten);
+               if (!fsp_is_np(fsp)) {
+                       reply_nterror(req, NT_STATUS_INVALID_HANDLE);
+                       return;
+               }
+               DEBUG(6, ("reply_pipe_write: %x name: %s len: %d\n",
+                         (int)fsp->fnum, fsp->fsp_name, (int)numtowrite));
+               status = np_write(fsp->fake_file_handle, data, numtowrite,
+                                 &nwritten);
                if (!NT_STATUS_IS_OK(status)) {
                        reply_nterror(req, status);
                        return;
@@ -183,6 +224,9 @@ void reply_pipe_write_and_X(struct smb_request *req)
                return;
        }
 
+       DEBUG(6, ("reply_pipe_write_and_X: %x name: %s len: %d\n",
+                 (int)fsp->fnum, fsp->fsp_name, (int)numtowrite));
+
        data = (uint8_t *)smb_base(req->inbuf) + smb_doff;
 
        if (numtowrite == 0) {
@@ -208,7 +252,8 @@ void reply_pipe_write_and_X(struct smb_request *req)
                        data += 2;
                        numtowrite -= 2;
                }                        
-               status = np_write(fsp, data, numtowrite, &nwritten);
+               status = np_write(fsp->fake_file_handle, data, numtowrite,
+                                 &nwritten);
                if (!NT_STATUS_IS_OK(status)) {
                        reply_nterror(req, status);
                        return;
@@ -268,7 +313,8 @@ void reply_pipe_read_and_X(struct smb_request *req)
 
        data = (uint8_t *)smb_buf(req->outbuf);
 
-       status = np_read(fsp, data, smb_maxcnt, &nread, &unused);
+       status = np_read(fsp->fake_file_handle, data, smb_maxcnt, &nread,
+                        &unused);
 
        if (!NT_STATUS_IS_OK(status)) {
                reply_doserror(req, ERRDOS, ERRnoaccess);