Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions ocaml/tests/test_extauth_plugin_ADwinbind.ml
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,27 @@ let test_parse_wbinfo_uid_info =
; gecos= {|ladmin|}
}
)
(* XSI-1901: output of customer environment, has `:` in the gecos,
other fields does not likely contain it *)
; ( {|HVS\udaadmin:*:3000000:3000000:ADMIN: Dalsem, Ulric:/home/HVS/udaadmin:/bin/bash|}
, Ok
{
user_name= {|HVS\udaadmin|}
; uid= 3000000
; gid= 3000000
; gecos= {|ADMIN: Dalsem, Ulric|}
}
)
(* Multiple `:` in gecos *)
; ( {|HVS\udaadmin:*:3000000:3000000:ADMIN: Dalsem, Ulric, POOL OP: udaadmin:/home/HVS/udaadmin:/bin/bash|}
, Ok
{
user_name= {|HVS\udaadmin|}
; uid= 3000000
; gid= 3000000
; gecos= {|ADMIN: Dalsem, Ulric, POOL OP: udaadmin|}
}
)
; ( {|CONNAPP\locked:*:3000004:3000174::/home/CONNAPP/locked:/bin/bash|}
, Ok
{user_name= {|CONNAPP\locked|}; uid= 3000004; gid= 3000174; gecos= ""}
Expand Down
27 changes: 23 additions & 4 deletions ocaml/xapi/extauth_plugin_ADwinbind.ml
Original file line number Diff line number Diff line change
Expand Up @@ -686,11 +686,30 @@ module Wbinfo = struct
let parse_uid_info stdout =
(* looks like one line from /etc/passwd: https://en.wikipedia.org/wiki/Passwd#Password_file *)
match String.split_on_char ':' stdout with
| [user_name; _passwd; uid; gid; gecos; _homedir; _shell] -> (
try Ok {user_name; uid= int_of_string uid; gid= int_of_string gid; gecos}
with _ -> Error ()
)
| user_name :: _passwd :: uid :: gid :: rest -> (
(* We expect at least homedir and shell at the end *)
let rest = List.rev rest in
match rest with
| _shell :: _homedir :: tail -> (
(* Rev it back to original order *)
let tail = List.rev tail in
let gecos = String.concat ":" tail in
try
Ok
{
user_name
; uid= int_of_string uid
; gid= int_of_string gid
; gecos
}
with _ -> Error ()
)
| _ ->
debug "%s uid_info format error: %s" __FUNCTION__ stdout ;
Error ()
)
| _ ->
debug "%s uid_info format error: %s" __FUNCTION__ stdout ;
Error ()

let uid_info_of_uid (uid : int) =
Expand Down
Loading