ctdb-scripts: Do not de-duplicate the interfaces list
[samba.git] / source3 / rpc_server / fss / srv_fss_agent.c
index 33cbca87d73f9196929520af2172afb82ff4e744..4de600fd06c5e39e9dbf62eec6fc079344b4aebb 100644 (file)
 #include "../lib/smbconf/smbconf.h"
 #include "smbd/proto.h"
 #include "lib/smbconf/smbconf_init.h"
-#include "librpc/gen_ndr/srv_fsrvp.h"
+#include "librpc/rpc/dcesrv_core.h"
+#include "librpc/gen_ndr/ndr_fsrvp_scompat.h"
+#include "librpc/gen_ndr/ndr_fsrvp.h"
+#include "rpc_server/rpc_server.h"
 #include "srv_fss_private.h"
-#include "srv_fss_agent.h"
+#include "lib/global_contexts.h"
 
 #undef DBGC_CLASS
 #define DBGC_CLASS DBGC_RPC_SRV
@@ -170,7 +173,12 @@ static bool snap_path_exists(TALLOC_CTX *ctx, struct messaging_context *msg_ctx,
                goto out;
        }
 
-       smb_fname = synthetic_smb_fname(service, sc->sc_path, NULL, NULL, 0);
+       smb_fname = synthetic_smb_fname(service,
+                                       sc->sc_path,
+                                       NULL,
+                                       NULL,
+                                       0,
+                                       0);
        if (smb_fname == NULL) {
                goto out;
        }
@@ -286,12 +294,14 @@ static NTSTATUS fss_conn_create_tos(struct messaging_context *msg_ctx,
                                    int snum,
                                    struct connection_struct **conn_out)
 {
+       const struct loadparm_substitution *lp_sub =
+               loadparm_s3_global_substitution();
        struct conn_struct_tos *c = NULL;
        NTSTATUS status;
 
        status = create_conn_struct_tos(msg_ctx,
                                        snum,
-                                       lp_path(talloc_tos(), snum),
+                                       lp_path(talloc_tos(), lp_sub, snum),
                                        session_info,
                                        &c);
        if (!NT_STATUS_IS_OK(status)) {
@@ -378,14 +388,14 @@ static struct fss_sc_smap *sc_smap_lookup(struct fss_sc_smap *smaps_head,
        return NULL;
 }
 
-void srv_fssa_cleanup(void)
+static void srv_fssa_cleanup(void)
 {
        talloc_free(fss_global.db_path);
        talloc_free(fss_global.mem_ctx);
        ZERO_STRUCT(fss_global);
 }
 
-NTSTATUS srv_fssa_start(struct messaging_context *msg_ctx)
+static NTSTATUS srv_fssa_start(struct messaging_context *msg_ctx)
 {
        NTSTATUS status;
        fss_global.mem_ctx = talloc_named_const(NULL, 0,
@@ -394,7 +404,7 @@ NTSTATUS srv_fssa_start(struct messaging_context *msg_ctx)
                return NT_STATUS_NO_MEMORY;
        }
 
-       fss_global.db_path = lock_path(FSS_DB_NAME);
+       fss_global.db_path = lock_path(talloc_tos(), FSS_DB_NAME);
        if (fss_global.db_path == NULL) {
                talloc_free(fss_global.mem_ctx);
                return NT_STATUS_NO_MEMORY;
@@ -428,22 +438,26 @@ NTSTATUS srv_fssa_start(struct messaging_context *msg_ctx)
  */
 static bool fss_permitted(struct pipes_struct *p)
 {
-       if (p->session_info->unix_token->uid == sec_initial_uid()) {
+       struct dcesrv_call_state *dce_call = p->dce_call;
+       struct auth_session_info *session_info =
+               dcesrv_call_session_info(dce_call);
+
+       if (session_info->unix_token->uid == sec_initial_uid()) {
                DEBUG(6, ("Granting FSRVP op, user started smbd\n"));
                return true;
        }
 
        if (nt_token_check_sid(&global_sid_Builtin_Administrators,
-                              p->session_info->security_token)) {
+                              session_info->security_token)) {
                DEBUG(6, ("Granting FSRVP op, administrators group member\n"));
                return true;
        }
        if (nt_token_check_sid(&global_sid_Builtin_Backup_Operators,
-                              p->session_info->security_token)) {
+                              session_info->security_token)) {
                DEBUG(6, ("Granting FSRVP op, backup operators group member\n"));
                return true;
        }
-       if (security_token_has_privilege(p->session_info->security_token,
+       if (security_token_has_privilege(session_info->security_token,
                                         SEC_PRIV_BACKUP)) {
                DEBUG(6, ("Granting FSRVP op, backup privilege present\n"));
                return true;
@@ -527,7 +541,7 @@ static void fss_seq_tout_set(TALLOC_CTX *mem_ctx,
                memcpy(sc_set_id, &sc_set->id, sizeof(*sc_set_id));
        }
 
-       tmr = tevent_add_timer(server_event_context(),
+       tmr = tevent_add_timer(global_event_context(),
                              mem_ctx,
                              timeval_current_ofs(tout, 0),
                              fss_seq_tout_handler, sc_set_id);
@@ -718,6 +732,9 @@ static uint32_t map_share_comment(struct fss_sc_smap *sc_smap,
 uint32_t _fss_AddToShadowCopySet(struct pipes_struct *p,
                                 struct fss_AddToShadowCopySet *r)
 {
+       struct dcesrv_call_state *dce_call = p->dce_call;
+       struct auth_session_info *session_info =
+               dcesrv_call_session_info(dce_call);
        uint32_t ret;
        struct fss_sc_set *sc_set;
        struct fss_sc *sc;
@@ -730,6 +747,8 @@ uint32_t _fss_AddToShadowCopySet(struct pipes_struct *p,
        struct connection_struct *conn;
        NTSTATUS status;
        TALLOC_CTX *frame = talloc_stackframe();
+       const struct loadparm_substitution *lp_sub =
+               loadparm_s3_global_substitution();
 
        if (!fss_permitted(p)) {
                ret = HRES_ERROR_V(HRES_E_ACCESSDENIED);
@@ -755,25 +774,25 @@ uint32_t _fss_AddToShadowCopySet(struct pipes_struct *p,
                goto err_tmp_free;
        }
 
-       path_name = lp_path(frame, snum);
+       path_name = lp_path(frame, lp_sub, snum);
        if (path_name == NULL) {
                ret = HRES_ERROR_V(HRES_E_OUTOFMEMORY);
                goto err_tmp_free;
        }
 
-       status = fss_conn_create_tos(p->msg_ctx, p->session_info, snum, &conn);
+       status = fss_conn_create_tos(p->msg_ctx, session_info, snum, &conn);
        if (!NT_STATUS_IS_OK(status)) {
                ret = HRES_ERROR_V(HRES_E_ACCESSDENIED);
                goto err_tmp_free;
        }
-       if (!become_user_by_session(conn, p->session_info)) {
+       if (!become_user_without_service_by_session(conn, session_info)) {
                DEBUG(0, ("failed to become user\n"));
                ret = HRES_ERROR_V(HRES_E_ACCESSDENIED);
                goto err_tmp_free;
        }
 
        status = SMB_VFS_SNAP_CHECK_PATH(conn, frame, path_name, &base_vol);
-       unbecome_user();
+       unbecome_user_without_service();
        if (!NT_STATUS_IS_OK(status)) {
                ret = FSRVP_E_NOT_SUPPORTED;
                goto err_tmp_free;
@@ -893,7 +912,7 @@ static NTSTATUS commit_sc_with_conn(TALLOC_CTX *mem_ctx,
                return status;
        }
 
-       if (!become_user_by_session(conn, session_info)) {
+       if (!become_user_without_service_by_session(conn, session_info)) {
                DEBUG(0, ("failed to become user\n"));
                TALLOC_FREE(frame);
                return NT_STATUS_ACCESS_DENIED;
@@ -903,7 +922,7 @@ static NTSTATUS commit_sc_with_conn(TALLOC_CTX *mem_ctx,
                                     sc->volume_name,
                                     &sc->create_ts, rw,
                                     base_path, snap_path);
-       unbecome_user();
+       unbecome_user_without_service();
        if (!NT_STATUS_IS_OK(status)) {
                DEBUG(0, ("snap create failed: %s\n", nt_errstr(status)));
                TALLOC_FREE(frame);
@@ -917,6 +936,9 @@ static NTSTATUS commit_sc_with_conn(TALLOC_CTX *mem_ctx,
 uint32_t _fss_CommitShadowCopySet(struct pipes_struct *p,
                                  struct fss_CommitShadowCopySet *r)
 {
+       struct dcesrv_call_state *dce_call = p->dce_call;
+       struct auth_session_info *session_info =
+               dcesrv_call_session_info(dce_call);
        struct fss_sc_set *sc_set;
        struct fss_sc *sc;
        uint32_t commit_count;
@@ -948,8 +970,8 @@ uint32_t _fss_CommitShadowCopySet(struct pipes_struct *p,
        for (sc = sc_set->scs; sc; sc = sc->next) {
                char *base_path;
                char *snap_path;
-               status = commit_sc_with_conn(frame, server_event_context(),
-                                            p->msg_ctx, p->session_info, sc,
+               status = commit_sc_with_conn(frame, global_event_context(),
+                                            p->msg_ctx, session_info, sc,
                                             &base_path, &snap_path);
                if (!NT_STATUS_IS_OK(status)) {
                        DEBUG(0, ("snap create failed for shadow copy of "
@@ -1099,10 +1121,10 @@ static uint32_t fss_sc_expose(struct smbconf_ctx *fconf_ctx,
                        DEBUG(2, ("no share SD to clone for %s snapshot\n",
                                  sc_smap->share_name));
                } else {
-                       bool ok;
-                       ok = set_share_security(sc_smap->sc_share_name, sd);
+                       NTSTATUS status;
+                       status = set_share_security(sc_smap->sc_share_name, sd);
                        TALLOC_FREE(sd);
-                       if (!ok) {
+                       if (!NT_STATUS_IS_OK(status)) {
                                DEBUG(0, ("failed to set %s share SD\n",
                                          sc_smap->sc_share_name));
                                err = HRES_ERROR_V(HRES_E_FAIL);
@@ -1318,6 +1340,9 @@ uint32_t _fss_AbortShadowCopySet(struct pipes_struct *p,
 uint32_t _fss_IsPathSupported(struct pipes_struct *p,
                              struct fss_IsPathSupported *r)
 {
+       struct dcesrv_call_state *dce_call = p->dce_call;
+       struct auth_session_info *session_info =
+               dcesrv_call_session_info(dce_call);
        int snum;
        char *service;
        char *base_vol;
@@ -1325,6 +1350,8 @@ uint32_t _fss_IsPathSupported(struct pipes_struct *p,
        struct connection_struct *conn;
        char *share;
        TALLOC_CTX *frame = talloc_stackframe();
+       const struct loadparm_substitution *lp_sub =
+               loadparm_s3_global_substitution();
 
        if (!fss_permitted(p)) {
                TALLOC_FREE(frame);
@@ -1344,20 +1371,20 @@ uint32_t _fss_IsPathSupported(struct pipes_struct *p,
                return HRES_ERROR_V(HRES_E_INVALIDARG);
        }
 
-       status = fss_conn_create_tos(p->msg_ctx, p->session_info, snum, &conn);
+       status = fss_conn_create_tos(p->msg_ctx, session_info, snum, &conn);
        if (!NT_STATUS_IS_OK(status)) {
                TALLOC_FREE(frame);
                return HRES_ERROR_V(HRES_E_ACCESSDENIED);
        }
-       if (!become_user_by_session(conn, p->session_info)) {
+       if (!become_user_without_service_by_session(conn, session_info)) {
                DEBUG(0, ("failed to become user\n"));
                TALLOC_FREE(frame);
                return HRES_ERROR_V(HRES_E_ACCESSDENIED);
        }
        status = SMB_VFS_SNAP_CHECK_PATH(conn, frame,
-                                        lp_path(frame, snum),
+                                        lp_path(frame, lp_sub, snum),
                                         &base_vol);
-       unbecome_user();
+       unbecome_user_without_service();
        if (!NT_STATUS_IS_OK(status)) {
                TALLOC_FREE(frame);
                return FSRVP_E_NOT_SUPPORTED;
@@ -1555,6 +1582,9 @@ err_cancel:
 uint32_t _fss_DeleteShareMapping(struct pipes_struct *p,
                                 struct fss_DeleteShareMapping *r)
 {
+       struct dcesrv_call_state *dce_call = p->dce_call;
+       struct auth_session_info *session_info =
+               dcesrv_call_session_info(dce_call);
        struct fss_sc_set *sc_set;
        struct fss_sc *sc;
        struct fss_sc_smap *sc_smap;
@@ -1624,11 +1654,11 @@ uint32_t _fss_DeleteShareMapping(struct pipes_struct *p,
                goto err_tmp_free;
        }
 
-       status = fss_conn_create_tos(p->msg_ctx, p->session_info, snum, &conn);
+       status = fss_conn_create_tos(p->msg_ctx, session_info, snum, &conn);
        if (!NT_STATUS_IS_OK(status)) {
                goto err_tmp_free;
        }
-       if (!become_user_by_session(conn, p->session_info)) {
+       if (!become_user_without_service_by_session(conn, session_info)) {
                DEBUG(0, ("failed to become user\n"));
                status = NT_STATUS_ACCESS_DENIED;
                goto err_tmp_free;
@@ -1636,7 +1666,7 @@ uint32_t _fss_DeleteShareMapping(struct pipes_struct *p,
 
        status = SMB_VFS_SNAP_DELETE(conn, frame, sc->volume_name,
                                     sc->sc_path);
-       unbecome_user();
+       unbecome_user_without_service();
        if (!NT_STATUS_IS_OK(status)) {
                goto err_tmp_free;
        }
@@ -1704,3 +1734,43 @@ uint32_t _fss_PrepareShadowCopySet(struct pipes_struct *p,
 
        return 0;
 }
+
+static NTSTATUS FileServerVssAgent__op_init_server(
+               struct dcesrv_context *dce_ctx,
+               const struct dcesrv_endpoint_server *ep_server);
+
+static NTSTATUS FileServerVssAgent__op_shutdown_server(
+               struct dcesrv_context *dce_ctx,
+               const struct dcesrv_endpoint_server *ep_server);
+
+#define DCESRV_INTERFACE_FILESERVERVSSAGENT_INIT_SERVER \
+       fileservervssagent_init_server
+
+#define DCESRV_INTERFACE_FILESERVERVSSAGENT_SHUTDOWN_SERVER \
+       fileservervssagent_shutdown_server
+
+static NTSTATUS fileservervssagent_shutdown_server(
+               struct dcesrv_context *dce_ctx,
+               const struct dcesrv_endpoint_server *ep_server)
+{
+       srv_fssa_cleanup();
+       return FileServerVssAgent__op_shutdown_server(dce_ctx, ep_server);
+}
+
+static NTSTATUS fileservervssagent_init_server(
+               struct dcesrv_context *dce_ctx,
+               const struct dcesrv_endpoint_server *ep_server)
+{
+       NTSTATUS status;
+       struct messaging_context *msg_ctx = global_messaging_context();
+
+       status = srv_fssa_start(msg_ctx);
+       if (!NT_STATUS_IS_OK(status)) {
+               return status;
+       }
+
+       return FileServerVssAgent__op_init_server(dce_ctx, ep_server);
+}
+
+/* include the generated boilerplate */
+#include "librpc/gen_ndr/ndr_fsrvp_scompat.c"