From e2acfb977e8c42976edd0a0b9b0e8fe49898d91d Mon Sep 17 00:00:00 2001 From: tomaswallentinus Date: Tue, 10 Mar 2020 13:50:03 +0100 Subject: [PATCH] Add EnableRemoteDesktop and DisableRemoteDesktop (#651) Add ability to send EnableRemoteDesktop and DisableRemoteDesktop mdm-commands: https://developer.apple.com/documentation/devicemanagement/enable_remote_desktop Add test for EnableRemoteDesktop and DisableRemoteDesktop mdm-commands: https://developer.apple.com/documentation/devicemanagement/enable_remote_desktop --- mdm/mdm/internal/mdmproto/mdm.proto | 2 ++ mdm/mdm/marshal_json.go | 2 ++ mdm/mdm/marshal_plist.go | 2 ++ mdm/mdm/marshal_proto.go | 2 ++ mdm/mdm/mdm_command_test.go | 10 ++++++++++ mdm/mdm/unmarshal_json.go | 2 ++ mdm/mdm/unmarshal_plist.go | 2 ++ mdm/mdm/unmarshal_proto.go | 2 ++ tools/api/commands/disable_remote_desktop | 10 ++++++++++ tools/api/commands/enable_remote_desktop | 10 ++++++++++ 10 files changed, 44 insertions(+) create mode 100644 tools/api/commands/disable_remote_desktop create mode 100644 tools/api/commands/enable_remote_desktop diff --git a/mdm/mdm/internal/mdmproto/mdm.proto b/mdm/mdm/internal/mdmproto/mdm.proto index 4b737210..213cc64a 100644 --- a/mdm/mdm/internal/mdmproto/mdm.proto +++ b/mdm/mdm/internal/mdmproto/mdm.proto @@ -28,6 +28,8 @@ message Command { - DeviceConfigured - AvailableOSUpdates - NSExtensionMappings + - EnableRemoteDesktop + - DisableRemoteDesktop - ActivationLockBypassCode */ oneof request { diff --git a/mdm/mdm/marshal_json.go b/mdm/mdm/marshal_json.go index f989b04b..b1d08707 100644 --- a/mdm/mdm/marshal_json.go +++ b/mdm/mdm/marshal_json.go @@ -25,6 +25,8 @@ func (c *Command) MarshalJSON() ([]byte, error) { "AvailableOSUpdates", "NSExtensionMappings", "OSUpdateStatus", + "EnableRemoteDesktop", + "DisableRemoteDesktop", "ActivationLockBypassCode": var x = struct { RequestType string `json:"request_type"` diff --git a/mdm/mdm/marshal_plist.go b/mdm/mdm/marshal_plist.go index 51842f84..95cf0143 100644 --- a/mdm/mdm/marshal_plist.go +++ b/mdm/mdm/marshal_plist.go @@ -27,6 +27,8 @@ func (c *Command) MarshalPlist() (interface{}, error) { "AvailableOSUpdates", "NSExtensionMappings", "OSUpdateStatus", + "EnableRemoteDesktop", + "DisableRemoteDesktop", "ActivationLockBypassCode": return &struct { RequestType string diff --git a/mdm/mdm/marshal_proto.go b/mdm/mdm/marshal_proto.go index ca1a8c7f..6fffbf8f 100644 --- a/mdm/mdm/marshal_proto.go +++ b/mdm/mdm/marshal_proto.go @@ -43,6 +43,8 @@ func commandToProto(cmd *Command) (*mdmproto.Command, error) { "AvailableOSUpdates", "NSExtensionMappings", "OSUpdateStatus", + "EnableRemoteDesktop", + "DisableRemoteDesktop", "ActivationLockBypassCode": case "InstallProfile": diff --git a/mdm/mdm/mdm_command_test.go b/mdm/mdm/mdm_command_test.go index 54137022..f1e3ce7d 100644 --- a/mdm/mdm/mdm_command_test.go +++ b/mdm/mdm/mdm_command_test.go @@ -52,6 +52,16 @@ func TestMarshalCommand(t *testing.T) { }, }, }, + { + Command: Command{ + RequestType: "EnableRemoteDesktop", + }, + }, + { + Command: Command{ + RequestType: "DisableRemoteDesktop", + }, + }, } for _, tt := range tests { t.Run(tt.Command.RequestType+"_json", func(t *testing.T) { diff --git a/mdm/mdm/unmarshal_json.go b/mdm/mdm/unmarshal_json.go index dce68456..5324672a 100644 --- a/mdm/mdm/unmarshal_json.go +++ b/mdm/mdm/unmarshal_json.go @@ -48,6 +48,8 @@ func (c *Command) UnmarshalJSON(data []byte) error { "AvailableOSUpdates", "NSExtensionMappings", "OSUpdateStatus", + "EnableRemoteDesktop", + "DisableRemoteDesktop", "ActivationLockBypassCode": return nil case "InstallProfile": diff --git a/mdm/mdm/unmarshal_plist.go b/mdm/mdm/unmarshal_plist.go index cfb2a0b8..706c7d3a 100644 --- a/mdm/mdm/unmarshal_plist.go +++ b/mdm/mdm/unmarshal_plist.go @@ -34,6 +34,8 @@ func (c *Command) UnmarshalPlist(unmarshal func(i interface{}) error) error { "AvailableOSUpdates", "NSExtensionMappings", "OSUpdateStatus", + "EnableRemoteDesktop", + "DisableRemoteDesktop", "ActivationLockBypassCode": return nil case "InstallProfile": diff --git a/mdm/mdm/unmarshal_proto.go b/mdm/mdm/unmarshal_proto.go index 87fa3981..25dd2d56 100644 --- a/mdm/mdm/unmarshal_proto.go +++ b/mdm/mdm/unmarshal_proto.go @@ -28,6 +28,8 @@ func protoToCommand(pb *mdmproto.Command) *Command { "AvailableOSUpdates", "NSExtensionMappings", "OSUpdateStatus", + "EnableRemoteDesktop", + "DisableRemoteDesktop", "ActivationLockBypassCode": case "InstallProfile": diff --git a/tools/api/commands/disable_remote_desktop b/tools/api/commands/disable_remote_desktop new file mode 100644 index 00000000..bcccd39b --- /dev/null +++ b/tools/api/commands/disable_remote_desktop @@ -0,0 +1,10 @@ +#!/bin/bash +source $MICROMDM_ENV_PATH +endpoint="v1/commands" +jq -n \ + --arg request_type "DisableRemoteDesktop" \ + --arg udid "$1" \ + '.udid = $udid + |.request_type = $request_type + '|\ + curl $CURL_OPTS -u "micromdm:$API_TOKEN" "$SERVER_URL/$endpoint" -d@- diff --git a/tools/api/commands/enable_remote_desktop b/tools/api/commands/enable_remote_desktop new file mode 100644 index 00000000..8fca74d1 --- /dev/null +++ b/tools/api/commands/enable_remote_desktop @@ -0,0 +1,10 @@ +#!/bin/bash +source $MICROMDM_ENV_PATH +endpoint="v1/commands" +jq -n \ + --arg request_type "EnableRemoteDesktop" \ + --arg udid "$1" \ + '.udid = $udid + |.request_type = $request_type + '|\ + curl $CURL_OPTS -u "micromdm:$API_TOKEN" "$SERVER_URL/$endpoint" -d@-