s4:rpc_server/srvsvc: make use dcesrv_call_session_info()
[samba.git] / source4 / rpc_server / srvsvc / srvsvc_ntvfs.c
index 8bd88e53e980d6751489aed8afbb7f06b0310b4a..fe97d60d999b4f518e19934a96fecb324a9f32fe 100644 (file)
@@ -7,7 +7,7 @@
    
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
    GNU General Public License for more details.
    
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 #include "includes.h"
-#include "rpc_server/dcerpc_server.h"
-#include "librpc/gen_ndr/ndr_srvsvc.h"
-#include "rpc_server/common/common.h"
 #include "ntvfs/ntvfs.h"
+#include "rpc_server/dcerpc_server.h"
+#include "param/param.h"
 #include "rpc_server/srvsvc/proto.h"
-#include "lib/socket/socket.h"
-
-struct socket_address *srvsvc_get_my_addr(void *p, TALLOC_CTX *mem_ctx)
-{
-       struct dcesrv_connection *conn = talloc_get_type(p, struct dcesrv_connection);
-       return dcesrv_connection_get_my_addr(conn, mem_ctx);
-}
-
-struct socket_address *srvsvc_get_peer_addr(void *p, TALLOC_CTX *mem_ctx)
-{
-       struct dcesrv_connection *conn = talloc_get_type(p, struct dcesrv_connection);
-       return dcesrv_connection_get_peer_addr(conn, mem_ctx);
-}
 
 struct srvsvc_ntvfs_ctx {
        struct ntvfs_context *ntvfs;
@@ -54,49 +39,66 @@ NTSTATUS srvsvc_create_ntvfs_context(struct dcesrv_call_state *dce_call,
                                     const char *share,
                                     struct ntvfs_context **_ntvfs)
 {
+       struct auth_session_info *session_info =
+               dcesrv_call_session_info(dce_call);
        NTSTATUS status;
        struct srvsvc_ntvfs_ctx *c;
        struct ntvfs_request *ntvfs_req;
        enum ntvfs_type type;
-       int snum;
+       struct share_context *sctx;
+       struct share_config *scfg;
+       char *sharetype;
+       union smb_tcon tcon;
+       const struct tsocket_address *local_address;
+       const struct tsocket_address *remote_address;
 
-       snum = lp_find_valid_service(share);
-       if (snum == -1) {
+       status = share_get_context_by_name(mem_ctx, lpcfg_share_backend(dce_call->conn->dce_ctx->lp_ctx), dce_call->event_ctx, dce_call->conn->dce_ctx->lp_ctx, &sctx);
+       if (!NT_STATUS_IS_OK(status)) {
+               return status;
+       }
+
+       status = share_get_config(mem_ctx, sctx, share, &scfg);
+       if (!NT_STATUS_IS_OK(status)) {
                DEBUG(0,("srvsvc_create_ntvfs_context: couldn't find service %s\n", share));
-               return NT_STATUS_BAD_NETWORK_NAME;
+               return status;
        }
 
 #if 0 /* TODO: fix access cecking */
        if (!socket_check_access(dce_call->connection->socket, 
-                                lp_servicename(snum)
-                                lp_hostsallow(snum), 
-                                lp_hostsdeny(snum))) {
+                                scfg->name
+                                share_string_list_option(scfg, SHARE_HOSTS_ALLOW), 
+                                share_string_list_option(scfg, SHARE_HOSTS_DENY))) {
                return NT_STATUS_ACCESS_DENIED;
        }
 #endif
 
        /* work out what sort of connection this is */
-       if (strcmp(lp_fstype(snum), "IPC") == 0) {
+       sharetype = share_string_option(mem_ctx, scfg, SHARE_TYPE, SHARE_TYPE_DEFAULT);
+       if (sharetype && strcmp(sharetype, "IPC") == 0) {
                type = NTVFS_IPC;
-       } else if (lp_print_ok(snum)) {
+       } else if (sharetype && strcmp(sharetype, "PRINTER")) {
                type = NTVFS_PRINT;
        } else {
                type = NTVFS_DISK;
        }
 
+       TALLOC_FREE(sharetype);
+
        c = talloc(mem_ctx, struct srvsvc_ntvfs_ctx);
        NT_STATUS_HAVE_NO_MEMORY(c);
        
        /* init ntvfs function pointers */
-       status = ntvfs_init_connection(c, snum, type,
+       status = ntvfs_init_connection(c, scfg, type,
                                       PROTOCOL_NT1,
+                                      0,/* ntvfs_client_caps */
                                       dce_call->event_ctx,
                                       dce_call->conn->msg_ctx,
+                                      dce_call->conn->dce_ctx->lp_ctx,
                                       dce_call->conn->server_id,
                                       &c->ntvfs);
        if (!NT_STATUS_IS_OK(status)) {
                DEBUG(0, ("srvsvc_create_ntvfs_context: ntvfs_init_connection failed for service %s\n", 
-                         lp_servicename(snum)));
+                         scfg->name));
                return status;
        }
        talloc_set_destructor(c, srvsvc_ntvfs_ctx_destructor);
@@ -104,21 +106,26 @@ NTSTATUS srvsvc_create_ntvfs_context(struct dcesrv_call_state *dce_call,
        /*
         * NOTE: we only set the addr callbacks as we're not interesseted in oplocks or in getting file handles
         */
-       status = ntvfs_set_addr_callbacks(c->ntvfs, srvsvc_get_my_addr, srvsvc_get_peer_addr, dce_call->conn);
+       local_address = dcesrv_connection_get_local_address(dce_call->conn);
+       remote_address = dcesrv_connection_get_remote_address(dce_call->conn);
+       status = ntvfs_set_addresses(c->ntvfs, local_address, remote_address);
        if (!NT_STATUS_IS_OK(status)) {
                DEBUG(0,("srvsvc_create_ntvfs_context: NTVFS failed to set the addr callbacks!\n"));
                return status;
        }
 
        ntvfs_req = ntvfs_request_create(c->ntvfs, mem_ctx,
-                                        dce_call->conn->auth_state.session_info,
+                                        session_info,
                                         0, /* TODO: fill in PID */
                                         dce_call->time,
                                         NULL, NULL, 0);
        NT_STATUS_HAVE_NO_MEMORY(ntvfs_req);
 
        /* Invoke NTVFS connection hook */
-       status = ntvfs_connect(ntvfs_req, lp_servicename(snum));
+       tcon.tcon.level = RAW_TCON_TCON;
+       ZERO_STRUCT(tcon.tcon.in);
+       tcon.tcon.in.service = scfg->name;
+       status = ntvfs_connect(ntvfs_req, &tcon);
        if (!NT_STATUS_IS_OK(status)) {
                DEBUG(0,("srvsvc_create_ntvfs_context: NTVFS ntvfs_connect() failed!\n"));
                return status;