Skip to content

Commit 7d9f055

Browse files
author
Bengang Yuan
committed
CA-422272: Validate pool ref in pool SSH helpers
Pool.{enable,disable}_ssh and the shared timeout/auto-mode helpers ignored their pool ref, so an invalid handle disabled SSH pool-wide instead of raising HANDLE_INVALID. Validate self in Ssh.operate. Signed-off-by: Bengang Yuan <bengang.yuan@citrix.com>
1 parent 00cb2ac commit 7d9f055

1 file changed

Lines changed: 16 additions & 11 deletions

File tree

ocaml/xapi/xapi_pool.ml

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4522,7 +4522,12 @@ let put_bundle_handler (req : Request.t) s _ =
45224522
)
45234523

45244524
module Ssh = struct
4525-
let operate ~__context ~action ~error =
4525+
let operate ~__context ~self ~action ~error =
4526+
(* Validate the pool ref first so an invalid handle fails with
4527+
HANDLE_INVALID instead of silently operating on all hosts. *)
4528+
if not (Db.is_valid_ref __context self) then
4529+
raise
4530+
Api_errors.(Server_error (handle_invalid, ["pool"; Ref.string_of self])) ;
45264531
let hosts = Db.Host.get_all ~__context in
45274532
Helpers.call_api_functions ~__context (fun rpc session_id ->
45284533
let failed_hosts =
@@ -4542,30 +4547,30 @@ module Ssh = struct
45424547
raise (Api_errors.Server_error (error, failed_hosts))
45434548
)
45444549

4545-
let enable ~__context ~self:_ =
4546-
operate ~__context ~action:Client.Host.enable_ssh
4550+
let enable ~__context ~self =
4551+
operate ~__context ~self ~action:Client.Host.enable_ssh
45474552
~error:Api_errors.enable_ssh_partially_failed
45484553

4549-
let disable ~__context ~self:_ =
4550-
operate ~__context ~action:Client.Host.disable_ssh
4554+
let disable ~__context ~self =
4555+
operate ~__context ~self ~action:Client.Host.disable_ssh
45514556
~error:Api_errors.disable_ssh_partially_failed
45524557

4553-
let set_enabled_timeout ~__context ~self:_ ~value =
4554-
operate ~__context
4558+
let set_enabled_timeout ~__context ~self ~value =
4559+
operate ~__context ~self
45554560
~action:(fun ~rpc ~session_id ~self ->
45564561
Client.Host.set_ssh_enabled_timeout ~rpc ~session_id ~self ~value
45574562
)
45584563
~error:Api_errors.set_ssh_timeout_partially_failed
45594564

4560-
let set_console_timeout ~__context ~self:_ ~value =
4561-
operate ~__context
4565+
let set_console_timeout ~__context ~self ~value =
4566+
operate ~__context ~self
45624567
~action:(fun ~rpc ~session_id ~self ->
45634568
Client.Host.set_console_idle_timeout ~rpc ~session_id ~self ~value
45644569
)
45654570
~error:Api_errors.set_console_timeout_partially_failed
45664571

4567-
let set_ssh_auto_mode ~__context ~self:_ ~value =
4568-
operate ~__context
4572+
let set_ssh_auto_mode ~__context ~self ~value =
4573+
operate ~__context ~self
45694574
~action:(fun ~rpc ~session_id ~self ->
45704575
Client.Host.set_ssh_auto_mode ~rpc ~session_id ~self ~value
45714576
)

0 commit comments

Comments
 (0)