@@ -89,12 +89,14 @@ let err_msg_to_tag_map =
8989
9090type domain_info = {
9191 service_name : string
92+ ; user : string
9293 ; workgroup : string option
9394 (* For upgrade case, the legacy db does not contain workgroup *)
9495 ; netbios_name : string option
9596 (* Persist netbios_name to support hostname change *)
9697 ; ldaps : bool (* Use ldaps instead of ldap *)
9798 ; machine_pwd_last_change_time : float option
99+ ; ou : string option
98100}
99101
100102let generic_error msg =
@@ -198,14 +200,24 @@ let get_domain_info_from_db () =
198200 Db.Host. get_external_auth_service_name ~__context ~self: host
199201 in
200202 let config = Db.Host. get_external_auth_configuration ~__context ~self: host in
203+ let user = List. assoc " user" config in
201204 let workgroup = List. assoc_opt " workgroup" config in
202205 let netbios_name = List. assoc_opt " netbios_name" config in
203206 let machine_pwd_last_change_time =
204207 List. assoc_opt " machine_pwd_last_change_time" config
205208 |> Option. map (fun s -> float_of_string s)
206209 in
207210 let ldaps = Helpers. ldaps_enabled_in_config ~config in
208- {service_name; workgroup; netbios_name; ldaps; machine_pwd_last_change_time}
211+ let ou = List. assoc_opt " ou" config in
212+ {
213+ service_name
214+ ; user
215+ ; workgroup
216+ ; netbios_name
217+ ; ldaps
218+ ; machine_pwd_last_change_time
219+ ; ou
220+ }
209221
210222let update_extauth_configuration ~__context ~k ~v =
211223 let self = Helpers. get_localhost ~__context in
@@ -778,7 +790,7 @@ let query_domain_workgroup ~domain =
778790 workgroup_from_server kdc |> Result. get_ok
779791 with _ -> raise (Auth_service_error (E_LOOKUP , err_msg))
780792
781- let config_winbind_daemon ~ workgroup ~ netbios_name ~ domain ~ ldaps =
793+ let config_winbind_daemon domain_info =
782794 let smb_config = " /etc/samba/smb.conf" in
783795 let extra_conf = " /etc/samba/smb.extra.conf" in
784796 (* Will change to following config after trusted certs feature
@@ -790,12 +802,17 @@ let config_winbind_daemon ~workgroup ~netbios_name ~domain ~ldaps =
790802 let scan_trusted_domains =
791803 string_of_bool ! Xapi_globs. winbind_scan_trusted_domains
792804 in
793- let ldaps_conf =
794- match ldaps with Some v when v = true -> " ldaps" | _ -> " seal"
795- in
796805
797- ( match (workgroup, netbios_name, domain) with
798- | Some wkgroup , Some netbios , Some dom ->
806+ ( match domain_info with
807+ | Some
808+ {
809+ service_name= dom
810+ ; workgroup= Some wkgroup
811+ ; netbios_name= Some netbios
812+ ; ldaps
813+ ; _
814+ } ->
815+ let ldaps_conf = match ldaps with true -> " ldaps" | _ -> " seal" in
799816 [
800817 Printf. sprintf " # This file is managed by xapi, update %s instead"
801818 extra_conf
@@ -844,8 +861,7 @@ let clear_winbind_config () =
844861 if ! Xapi_globs. winbind_keep_configuration then
845862 ()
846863 else
847- config_winbind_daemon ~workgroup: None ~netbios_name: None ~domain: None
848- ~ldaps: None
864+ config_winbind_daemon None
849865
850866let from_config ~name ~err_msg ~config_params =
851867 match List. assoc_opt name config_params with
@@ -878,33 +894,44 @@ let assert_domain_equal_service_name ~service_name ~config_params =
878894let extract_ou_config ~config_params =
879895 try
880896 let ou = from_config ~name: " ou" ~err_msg: " " ~config_params in
881- ([( " ou " , ou)] , [Printf. sprintf " createcomputer=%s" ou])
882- with Auth_service_error _ -> ([] , [] )
897+ (Some ou, [Printf. sprintf " createcomputer=%s" ou])
898+ with Auth_service_error _ -> (None , [] )
883899
884- let persist_extauth_config ~domain ~user ~ou_conf ~workgroup ~netbios_name
885- ~machine_pwd_last_change_time ~ldaps =
900+ let persist_extauth_config ~domain_info =
886901 let value =
887- match
888- ( domain
889- , user
890- , workgroup
891- , netbios_name
892- , machine_pwd_last_change_time
893- , ldaps
894- )
895- with
896- | Some dom , Some u , Some wkg , Some netbios , Some pwd_time , Some ldaps ->
902+ match domain_info with
903+ | None ->
904+ []
905+ | Some
906+ {
907+ service_name
908+ ; user
909+ ; workgroup
910+ ; netbios_name
911+ ; machine_pwd_last_change_time
912+ ; ldaps
913+ ; ou
914+ } -> (
897915 [
898- (" domain" , dom)
899- ; (" user" , u)
900- ; (" workgroup" , wkg)
901- ; (" netbios_name" , netbios)
902- ; (" machine_pwd_last_change_time" , pwd_time)
916+ (" domain" , service_name)
917+ ; (" user" , user)
903918 ; (" ldaps" , string_of_bool ldaps)
904919 ]
905- @ ou_conf
906- | _ ->
907- []
920+ @ (match workgroup with Some w -> [(" workgroup" , w)] | None -> [] )
921+ @ ( match netbios_name with
922+ | Some n ->
923+ [(" netbios_name" , n)]
924+ | None ->
925+ []
926+ )
927+ @ (match ou with Some o -> [(" ou" , o)] | None -> [] )
928+ @
929+ match machine_pwd_last_change_time with
930+ | Some t ->
931+ [(" machine_pwd_last_change_time" , string_of_float t)]
932+ | None ->
933+ []
934+ )
908935 in
909936 Server_helpers. exec_with_new_task " update external_auth_configuration"
910937 @@ fun __context ->
@@ -990,29 +1017,34 @@ module Winbind = struct
9901017 let configure ~__context =
9911018 (* Refresh winbind configuration to handle upgrade from PBIS
9921019 * The winbind configuration needs to be refreshed before start winbind daemon *)
993- let {service_name; workgroup; netbios_name; ldaps; _} =
994- get_domain_info_from_db ()
995- in
1020+ let domain_info = get_domain_info_from_db () in
9961021 let netbios_name =
997- match netbios_name with
1022+ match domain_info. netbios_name with
9981023 | None ->
9991024 Migrate_from_pbis. migrate_netbios_name ~__context
10001025 | Some name ->
10011026 name
10021027 in
10031028 let workgroup =
1004- match workgroup with
1029+ match domain_info. workgroup with
10051030 | None ->
1006- let workgroup = query_domain_workgroup ~domain: service_name in
1031+ let workgroup =
1032+ query_domain_workgroup ~domain: domain_info.service_name
1033+ in
10071034 (* Persist the workgroup to avoid lookup again on next startup *)
10081035 update_workgroup ~__context ~workgroup ;
10091036 workgroup
10101037 | Some workgroup ->
10111038 workgroup
10121039 in
1013- config_winbind_daemon ~domain: (Some service_name)
1014- ~workgroup: (Some workgroup) ~netbios_name: (Some netbios_name)
1015- ~ldaps: (Some ldaps)
1040+ let domain_info =
1041+ {
1042+ domain_info with
1043+ netbios_name= Some netbios_name
1044+ ; workgroup= Some workgroup
1045+ }
1046+ in
1047+ config_winbind_daemon (Some domain_info)
10161048
10171049 let init_service ~__context =
10181050 if is_ad_enabled ~__context then (
@@ -1548,7 +1580,10 @@ module AuthADWinbind : Auth_signature.AUTH_MODULE = struct
15481580
15491581 assert_hostname_valid ~hostname: netbios_name ;
15501582
1551- let {service_name; _} = get_domain_info_from_db () in
1583+ let service_name =
1584+ Helpers. get_localhost ~__context |> fun self ->
1585+ Db.Host. get_external_auth_service_name ~__context ~self
1586+ in
15521587 assert_domain_equal_service_name ~service_name ~config_params ;
15531588
15541589 let workgroup =
@@ -1557,11 +1592,20 @@ module AuthADWinbind : Auth_signature.AUTH_MODULE = struct
15571592 in
15581593 let ldaps = Helpers. ldaps_enabled_in_config ~config: config_params in
15591594
1560- config_winbind_daemon ~domain: (Some service_name)
1561- ~workgroup: (Some workgroup) ~netbios_name: (Some netbios_name)
1562- ~ldaps: (Some ldaps) ;
1595+ let ou, ou_param = extract_ou_config ~config_params in
1596+ let domain_info =
1597+ {
1598+ service_name
1599+ ; user
1600+ ; workgroup= Some workgroup
1601+ ; netbios_name= Some netbios_name
1602+ ; machine_pwd_last_change_time= Some (Unix. time () )
1603+ ; ldaps
1604+ ; ou
1605+ }
1606+ in
15631607
1564- let ou_conf, ou_param = extract_ou_config ~config_params in
1608+ config_winbind_daemon ( Some domain_info) ;
15651609
15661610 let args =
15671611 [
@@ -1587,11 +1631,7 @@ module AuthADWinbind : Auth_signature.AUTH_MODULE = struct
15871631 (* Need to restart to refresh cache *)
15881632 Winbind. restart ~timeout: 5. ~wait_until_success: true ;
15891633 Winbind. check_ready_to_serve ~timeout: 300. ;
1590- let machine_pwd_last_change_time = Unix. time () |> string_of_float in
1591- persist_extauth_config ~domain: (Some service_name) ~user: (Some user)
1592- ~ou_conf ~workgroup: (Some workgroup)
1593- ~machine_pwd_last_change_time: (Some machine_pwd_last_change_time)
1594- ~netbios_name: (Some netbios_name) ~ldaps: (Some ldaps) ;
1634+ persist_extauth_config ~domain_info: (Some domain_info) ;
15951635 (* Trigger right now *)
15961636 RotateMachinePassword. trigger_rotate ~start: 0. ;
15971637 ConfigHosts. join ~domain: service_name ~name: netbios_name ;
@@ -1612,8 +1652,7 @@ module AuthADWinbind : Auth_signature.AUTH_MODULE = struct
16121652 | Xapi_systemctl. Systemctl_fail _ ->
16131653 let msg = Printf. sprintf " Failed to start %s" Winbind. name in
16141654 error " Start daemon error: %s" msg ;
1615- config_winbind_daemon ~domain: None ~workgroup: None ~netbios_name: None
1616- ~ldaps: None ;
1655+ config_winbind_daemon None ;
16171656 ConfigHosts. leave ~domain: service_name ~name: netbios_name ;
16181657 raise (Auth_service_error (E_GENERIC , msg))
16191658 | e ->
@@ -1648,8 +1687,7 @@ module AuthADWinbind : Auth_signature.AUTH_MODULE = struct
16481687 ) ;
16491688
16501689 (* Clean extauth config *)
1651- persist_extauth_config ~domain: None ~user: None ~ou_conf: [] ~workgroup: None
1652- ~machine_pwd_last_change_time: None ~netbios_name: None ~ldaps: None ;
1690+ persist_extauth_config ~domain_info: None ;
16531691 RotateMachinePassword. stop_rotate () ;
16541692 (* The caller disable external auth even disable machine account failed,
16551693 * We run clear_machine_account after some necessary resources get cleared *)
0 commit comments