@@ -93,6 +93,7 @@ type domain_info = {
9393 (* For upgrade case, the legacy db does not contain workgroup *)
9494 ; netbios_name : string option
9595 (* Persist netbios_name to support hostname change *)
96+ ; ldaps : bool (* Use ldaps instead of ldap *)
9697 ; machine_pwd_last_change_time : float option
9798}
9899
@@ -196,16 +197,15 @@ let get_domain_info_from_db () =
196197 let service_name =
197198 Db.Host. get_external_auth_service_name ~__context ~self: host
198199 in
199- let workgroup, netbios_name, machine_pwd_last_change_time =
200- Db.Host. get_external_auth_configuration ~__context ~self: host
201- |> fun config ->
202- ( List. assoc_opt " workgroup" config
203- , List. assoc_opt " netbios_name" config
204- , List. assoc_opt " machine_pwd_last_change_time" config
205- |> Option. map (fun s -> float_of_string s)
206- )
200+ let config = Db.Host. get_external_auth_configuration ~__context ~self: host in
201+ let workgroup = List. assoc_opt " workgroup" config in
202+ let netbios_name = List. assoc_opt " netbios_name" config in
203+ let machine_pwd_last_change_time =
204+ List. assoc_opt " machine_pwd_last_change_time" config
205+ |> Option. map (fun s -> float_of_string s)
207206 in
208- {service_name; workgroup; netbios_name; machine_pwd_last_change_time}
207+ let ldaps = Helpers. ldaps_enabled_in_config ~config in
208+ {service_name; workgroup; netbios_name; ldaps; machine_pwd_last_change_time}
209209
210210let update_extauth_configuration ~__context ~k ~v =
211211 let self = Helpers. get_localhost ~__context in
@@ -778,14 +778,22 @@ let query_domain_workgroup ~domain =
778778 workgroup_from_server kdc |> Result. get_ok
779779 with _ -> raise (Auth_service_error (E_LOOKUP , err_msg))
780780
781- let config_winbind_daemon ~workgroup ~netbios_name ~domain =
781+ let config_winbind_daemon ~workgroup ~netbios_name ~domain ~ ldaps =
782782 let smb_config = " /etc/samba/smb.conf" in
783783 let extra_conf = " /etc/samba/smb.extra.conf" in
784+ (* Will change to following config after trusted certs feature
785+ tls cafile = /etc/trusted-certs/ca-bundle-[ldaps|general].pem
786+ *)
787+ let certs_dir = " /etc/stunnel/certs" in
784788 let string_of_bool = function true -> " yes" | false -> " no" in
785789
786790 let scan_trusted_domains =
787791 string_of_bool ! Xapi_globs. winbind_scan_trusted_domains
788792 in
793+ let ldaps_conf =
794+ match ldaps with Some v when v = true -> " ldaps" | _ -> " seal"
795+ in
796+
789797 ( match (workgroup, netbios_name, domain) with
790798 | Some wkgroup , Some netbios , Some dom ->
791799 [
@@ -802,6 +810,10 @@ let config_winbind_daemon ~workgroup ~netbios_name ~domain =
802810 ; " winbind refresh tickets = yes"
803811 ; " winbind enum groups = no"
804812 ; " winbind enum users = no"
813+ ; Printf. sprintf " client ldap sasl wrapping= %s" ldaps_conf
814+ ; " tls trust system cas = yes"
815+ ; " tls verify peer = ca_and_name_if_available"
816+ ; Printf. sprintf " tls ca directories = %s" certs_dir
805817 ; Printf. sprintf " winbind scan trusted domains = %s"
806818 scan_trusted_domains
807819 ; " winbind use krb5 enterprise principals = yes"
@@ -833,6 +845,7 @@ let clear_winbind_config () =
833845 ()
834846 else
835847 config_winbind_daemon ~workgroup: None ~netbios_name: None ~domain: None
848+ ~ldaps: None
836849
837850let from_config ~name ~err_msg ~config_params =
838851 match List. assoc_opt name config_params with
@@ -869,18 +882,25 @@ let extract_ou_config ~config_params =
869882 with Auth_service_error _ -> ([] , [] )
870883
871884let persist_extauth_config ~domain ~user ~ou_conf ~workgroup ~netbios_name
872- ~machine_pwd_last_change_time =
885+ ~machine_pwd_last_change_time ~ ldaps =
873886 let value =
874887 match
875- (domain, user, workgroup, netbios_name, machine_pwd_last_change_time)
888+ ( domain
889+ , user
890+ , workgroup
891+ , netbios_name
892+ , machine_pwd_last_change_time
893+ , ldaps
894+ )
876895 with
877- | Some dom , Some u , Some wkg , Some netbios , Some pwd_time ->
896+ | Some dom , Some u , Some wkg , Some netbios , Some pwd_time , Some ldaps ->
878897 [
879898 (" domain" , dom)
880899 ; (" user" , u)
881900 ; (" workgroup" , wkg)
882901 ; (" netbios_name" , netbios)
883902 ; (" machine_pwd_last_change_time" , pwd_time)
903+ ; (" ldaps" , string_of_bool ldaps)
884904 ]
885905 @ ou_conf
886906 | _ ->
@@ -970,7 +990,7 @@ module Winbind = struct
970990 let configure ~__context =
971991 (* Refresh winbind configuration to handle upgrade from PBIS
972992 * The winbind configuration needs to be refreshed before start winbind daemon *)
973- let {service_name; workgroup; netbios_name; _} =
993+ let {service_name; workgroup; netbios_name; ldaps; _} =
974994 get_domain_info_from_db ()
975995 in
976996 let netbios_name =
@@ -992,6 +1012,7 @@ module Winbind = struct
9921012 in
9931013 config_winbind_daemon ~domain: (Some service_name)
9941014 ~workgroup: (Some workgroup) ~netbios_name: (Some netbios_name)
1015+ ~ldaps: (Some ldaps)
9951016
9961017 let init_service ~__context =
9971018 if is_ad_enabled ~__context then (
@@ -1534,8 +1555,11 @@ module AuthADWinbind : Auth_signature.AUTH_MODULE = struct
15341555 (* Query new domain workgroup during join domain *)
15351556 query_domain_workgroup ~domain: service_name
15361557 in
1558+ let ldaps = Helpers. ldaps_enabled_in_config ~config: config_params in
1559+
15371560 config_winbind_daemon ~domain: (Some service_name)
1538- ~workgroup: (Some workgroup) ~netbios_name: (Some netbios_name) ;
1561+ ~workgroup: (Some workgroup) ~netbios_name: (Some netbios_name)
1562+ ~ldaps: (Some ldaps) ;
15391563
15401564 let ou_conf, ou_param = extract_ou_config ~config_params in
15411565
@@ -1567,7 +1591,7 @@ module AuthADWinbind : Auth_signature.AUTH_MODULE = struct
15671591 persist_extauth_config ~domain: (Some service_name) ~user: (Some user)
15681592 ~ou_conf ~workgroup: (Some workgroup)
15691593 ~machine_pwd_last_change_time: (Some machine_pwd_last_change_time)
1570- ~netbios_name: (Some netbios_name) ;
1594+ ~netbios_name: (Some netbios_name) ~ldaps: ( Some ldaps) ;
15711595 (* Trigger right now *)
15721596 RotateMachinePassword. trigger_rotate ~start: 0. ;
15731597 ConfigHosts. join ~domain: service_name ~name: netbios_name ;
@@ -1588,7 +1612,8 @@ module AuthADWinbind : Auth_signature.AUTH_MODULE = struct
15881612 | Xapi_systemctl. Systemctl_fail _ ->
15891613 let msg = Printf. sprintf " Failed to start %s" Winbind. name in
15901614 error " Start daemon error: %s" msg ;
1591- config_winbind_daemon ~domain: None ~workgroup: None ~netbios_name: None ;
1615+ config_winbind_daemon ~domain: None ~workgroup: None ~netbios_name: None
1616+ ~ldaps: None ;
15921617 ConfigHosts. leave ~domain: service_name ~name: netbios_name ;
15931618 raise (Auth_service_error (E_GENERIC , msg))
15941619 | e ->
@@ -1624,7 +1649,7 @@ module AuthADWinbind : Auth_signature.AUTH_MODULE = struct
16241649
16251650 (* Clean extauth config *)
16261651 persist_extauth_config ~domain: None ~user: None ~ou_conf: [] ~workgroup: None
1627- ~machine_pwd_last_change_time: None ~netbios_name: None ;
1652+ ~machine_pwd_last_change_time: None ~netbios_name: None ~ldaps: None ;
16281653 RotateMachinePassword. stop_rotate () ;
16291654 (* The caller disable external auth even disable machine account failed,
16301655 * We run clear_machine_account after some necessary resources get cleared *)
0 commit comments