Skip to content

Commit 6e24ca4

Browse files
author
Marcello Seri
committed
xapi/xapi_session: make safe-string-compliant
Signed-off-by: Marcello Seri <[email protected]>
1 parent 1e81d28 commit 6e24ca4

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

ocaml/xapi/xapi_session.ml

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,21 @@ let xapi_internal_originator = "xapi"
3232

3333
let serialize_auth = Mutex.create()
3434

35-
let wipe_string_contents str = for i = 0 to String.length str - 1 do str.[i] <- '\000' done
35+
let wipe_string_contents str =
36+
for i = 0 to Bytes.length str - 1 do (Bytes.set str i '\000') done
3637
let wipe ss = List.iter (fun s -> wipe_string_contents s) ss
3738
(* wrapper that erases sensitive string parameters from functions *)
3839
let wipe_params_after_fn params fn =
3940
try (let r=fn () in wipe params; r) with e -> (wipe params; raise e)
4041

4142
let do_external_auth uname pwd =
42-
Mutex.execute serialize_auth (fun () -> (Ext_auth.d()).authenticate_username_password uname pwd)
43+
Mutex.execute serialize_auth (fun () -> (Ext_auth.d()).authenticate_username_password uname (Bytes.unsafe_to_string pwd))
4344

4445
let do_local_auth uname pwd =
45-
Mutex.execute serialize_auth (fun () -> Pam.authenticate uname pwd)
46+
Mutex.execute serialize_auth (fun () -> Pam.authenticate uname (Bytes.unsafe_to_string pwd))
4647

4748
let do_local_change_password uname newpwd =
48-
Mutex.execute serialize_auth (fun () -> Pam.change_password uname newpwd)
49+
Mutex.execute serialize_auth (fun () -> Pam.change_password uname (Bytes.unsafe_to_string newpwd))
4950

5051
let trackid session_id = (Context.trackid_of_session (Some session_id))
5152

@@ -348,7 +349,9 @@ let slave_local_login ~__context ~psecret =
348349
Xapi_local_session.create ~__context ~pool:true
349350

350351
(* Emergency mode login, uses local storage *)
351-
let slave_local_login_with_password ~__context ~uname ~pwd = wipe_params_after_fn [pwd] (fun () ->
352+
let slave_local_login_with_password ~__context ~uname ~pwd =
353+
let pwd = Bytes.of_string pwd in
354+
wipe_params_after_fn [pwd] (fun () ->
352355
if not (Context.preauth ~__context)
353356
then
354357
(try
@@ -367,7 +370,9 @@ let slave_local_login_with_password ~__context ~uname ~pwd = wipe_params_after_f
367370
- try and authenticate remotely, passing the supplied username/password to the external auth/directory service. (Note: see below for definition of 'authenticate remotely')
368371
2. otherwise, Session.login_with_password will only attempt to authenticate against the local superuser credentials
369372
*)
370-
let login_with_password ~__context ~uname ~pwd ~version ~originator = wipe_params_after_fn [pwd] (fun () ->
373+
let login_with_password ~__context ~uname ~pwd ~version ~originator =
374+
let pwd = Bytes.of_string pwd in
375+
wipe_params_after_fn [pwd] (fun () ->
371376
(* !!! Do something with the version number *)
372377
if (Context.preauth ~__context) then
373378
begin
@@ -595,7 +600,10 @@ let login_with_password ~__context ~uname ~pwd ~version ~originator = wipe_param
595600
)
596601
)
597602

598-
let change_password ~__context ~old_pwd ~new_pwd = wipe_params_after_fn [old_pwd;new_pwd] (fun () ->
603+
let change_password ~__context ~old_pwd ~new_pwd =
604+
let old_pwd = Bytes.of_string old_pwd in
605+
let new_pwd = Bytes.of_string new_pwd in
606+
wipe_params_after_fn [old_pwd;new_pwd] (fun () ->
599607
let session_id = Context.get_session_id __context in
600608
(*let user = Db.Session.get_this_user ~__context ~self:session_id in
601609
let uname = Db.User.get_short_name ~__context ~self:user in*)

0 commit comments

Comments
 (0)