]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
librpc/rpc: add dcesrv_register_default_auth_types[_machine_principal]() helpers
authorStefan Metzmacher <metze@samba.org>
Wed, 9 Aug 2023 13:29:29 +0000 (15:29 +0200)
committerAndrew Bartlett <abartlet@samba.org>
Tue, 17 Oct 2023 19:20:38 +0000 (19:20 +0000)
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
librpc/rpc/dcesrv_core.c
librpc/rpc/dcesrv_core.h

index 8a2707912c5277ae71772ac6b10d835eafbfb6cf..ee0ac2ce7ade2c41428042bb172425b12ee5bfa3 100644 (file)
@@ -213,6 +213,64 @@ _PUBLIC_ const char *dcesrv_auth_type_principal_find(struct dcesrv_context *dce_
        return NULL;
 }
 
+_PUBLIC_ NTSTATUS dcesrv_register_default_auth_types(struct dcesrv_context *dce_ctx,
+                                                    const char *principal)
+{
+       const char *realm = lpcfg_realm(dce_ctx->lp_ctx);
+       NTSTATUS status;
+
+       status = dcesrv_auth_type_principal_register(dce_ctx,
+                                                    DCERPC_AUTH_TYPE_NTLMSSP,
+                                                    principal);
+       if (!NT_STATUS_IS_OK(status)) {
+               return status;
+       }
+       status = dcesrv_auth_type_principal_register(dce_ctx,
+                                                    DCERPC_AUTH_TYPE_SPNEGO,
+                                                    principal);
+       if (!NT_STATUS_IS_OK(status)) {
+               return status;
+       }
+
+       if (realm == NULL || realm[0] == '\0') {
+               return NT_STATUS_OK;
+       }
+
+       status = dcesrv_auth_type_principal_register(dce_ctx,
+                                                    DCERPC_AUTH_TYPE_KRB5,
+                                                    principal);
+       if (!NT_STATUS_IS_OK(status)) {
+               return status;
+       }
+
+       return NT_STATUS_OK;
+}
+
+_PUBLIC_ NTSTATUS dcesrv_register_default_auth_types_machine_principal(struct dcesrv_context *dce_ctx)
+{
+       const char *realm = lpcfg_realm(dce_ctx->lp_ctx);
+       const char *nb = lpcfg_netbios_name(dce_ctx->lp_ctx);
+       char *principal = NULL;
+       NTSTATUS status;
+
+       if (realm == NULL || realm[0] == '\0') {
+               return dcesrv_register_default_auth_types(dce_ctx, "");
+       }
+
+       principal = talloc_asprintf(talloc_tos(), "%s$@%s", nb, realm);
+       if (principal == NULL) {
+               return NT_STATUS_NO_MEMORY;
+       }
+
+       status = dcesrv_register_default_auth_types(dce_ctx, principal);
+       TALLOC_FREE(principal);
+       if (!NT_STATUS_IS_OK(status)) {
+               return status;
+       }
+
+       return NT_STATUS_OK;
+}
+
 /*
   register an interface on an endpoint
 
index 3ec9f32c93d8228e4e1ed66d1bdd4265d5c6af0e..64b8953bec248a94901879a367a8e1cdea881ede 100644 (file)
@@ -475,6 +475,9 @@ NTSTATUS dcesrv_auth_type_principal_register(struct dcesrv_context *dce_ctx,
                                             const char *principal_name);
 const char *dcesrv_auth_type_principal_find(struct dcesrv_context *dce_ctx,
                                            enum dcerpc_AuthType auth_type);
+NTSTATUS dcesrv_register_default_auth_types(struct dcesrv_context *dce_ctx,
+                                           const char *principal);
+NTSTATUS dcesrv_register_default_auth_types_machine_principal(struct dcesrv_context *dce_ctx);
 NTSTATUS dcesrv_interface_register(struct dcesrv_context *dce_ctx,
                                   const char *ep_name,
                                   const char *ncacn_np_secondary_endpoint,