Skip to content

Commit af0769d

Browse files
authored
CA-412164: XSI-1901: uid-info does not support : (#6522)
from https://en.wikipedia.org/wiki/Passwd#Password_file uid_info as following format username:password:uid:gid:gecos:homedir:shell Regarding gecos, it is recommended as follows Typically, this is a set of comma-separated values including the user's full name and contact details. However, this information comes form AD and user may mis-configure it with `:`, which is used as seperator. In such case, the parse would failed. Enhance the parse function to support `:` in gecos, other fields does not likely contain it.
2 parents 3ceb3d2 + 6fe7c9e commit af0769d

File tree

2 files changed

+44
-4
lines changed

2 files changed

+44
-4
lines changed

ocaml/tests/test_extauth_plugin_ADwinbind.ml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,27 @@ let test_parse_wbinfo_uid_info =
219219
; gecos= {|ladmin|}
220220
}
221221
)
222+
(* XSI-1901: output of customer environment, has `:` in the gecos,
223+
other fields does not likely contain it *)
224+
; ( {|HVS\udaadmin:*:3000000:3000000:ADMIN: Dalsem, Ulric:/home/HVS/udaadmin:/bin/bash|}
225+
, Ok
226+
{
227+
user_name= {|HVS\udaadmin|}
228+
; uid= 3000000
229+
; gid= 3000000
230+
; gecos= {|ADMIN: Dalsem, Ulric|}
231+
}
232+
)
233+
(* Multiple `:` in gecos *)
234+
; ( {|HVS\udaadmin:*:3000000:3000000:ADMIN: Dalsem, Ulric, POOL OP: udaadmin:/home/HVS/udaadmin:/bin/bash|}
235+
, Ok
236+
{
237+
user_name= {|HVS\udaadmin|}
238+
; uid= 3000000
239+
; gid= 3000000
240+
; gecos= {|ADMIN: Dalsem, Ulric, POOL OP: udaadmin|}
241+
}
242+
)
222243
; ( {|CONNAPP\locked:*:3000004:3000174::/home/CONNAPP/locked:/bin/bash|}
223244
, Ok
224245
{user_name= {|CONNAPP\locked|}; uid= 3000004; gid= 3000174; gecos= ""}

ocaml/xapi/extauth_plugin_ADwinbind.ml

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -686,11 +686,30 @@ module Wbinfo = struct
686686
let parse_uid_info stdout =
687687
(* looks like one line from /etc/passwd: https://en.wikipedia.org/wiki/Passwd#Password_file *)
688688
match String.split_on_char ':' stdout with
689-
| [user_name; _passwd; uid; gid; gecos; _homedir; _shell] -> (
690-
try Ok {user_name; uid= int_of_string uid; gid= int_of_string gid; gecos}
691-
with _ -> Error ()
692-
)
689+
| user_name :: _passwd :: uid :: gid :: rest -> (
690+
(* We expect at least homedir and shell at the end *)
691+
let rest = List.rev rest in
692+
match rest with
693+
| _shell :: _homedir :: tail -> (
694+
(* Rev it back to original order *)
695+
let tail = List.rev tail in
696+
let gecos = String.concat ":" tail in
697+
try
698+
Ok
699+
{
700+
user_name
701+
; uid= int_of_string uid
702+
; gid= int_of_string gid
703+
; gecos
704+
}
705+
with _ -> Error ()
706+
)
707+
| _ ->
708+
debug "%s uid_info format error: %s" __FUNCTION__ stdout ;
709+
Error ()
710+
)
693711
| _ ->
712+
debug "%s uid_info format error: %s" __FUNCTION__ stdout ;
694713
Error ()
695714

696715
let uid_info_of_uid (uid : int) =

0 commit comments

Comments
 (0)