@@ -77,11 +77,13 @@ let auth_ex uname =
7777 let msg = Printf. sprintf " failed to authenticate user '%s'" uname in
7878 Auth_signature. (Auth_failure msg)
7979
80- let generic_ex fmt =
80+ let gen_ex tag fmt =
8181 Printf. ksprintf
82- (fun msg -> Auth_signature. (Auth_service_error (E_GENERIC , msg)))
82+ (fun msg -> Auth_signature. (Auth_service_error (tag , msg)))
8383 fmt
8484
85+ let generic_ex fmt = gen_ex E_GENERIC fmt
86+
8587let net_cmd = ! Xapi_globs. net_cmd
8688
8789let wb_cmd = ! Xapi_globs. wb_cmd
@@ -90,6 +92,31 @@ let tdb_tool = !Xapi_globs.tdb_tool
9092
9193let domain_krb5_dir = Filename. concat Xapi_globs. samba_dir " lock/smb_krb5"
9294
95+ (* Legacy certificates folder *)
96+ let certs_dir = " /etc/stunnel/certs"
97+
98+ let ldaps_ca_bundle = " /etc/trusted-certs/ca-bundle-ldaps.pem"
99+
100+ let general_ca_bundle = " /etc/trusted-certs/ca-bundle-general.pem"
101+
102+ (* * Return the best available CA bundle/cert path, in priority order:
103+ ldaps-specific bundle > general bundle > legacy certs dir.
104+ Returns [None] if none exist. *)
105+
106+ let ca_bundle_path () =
107+ [ldaps_ca_bundle; general_ca_bundle; certs_dir]
108+ |> List. find_opt Sys. file_exists
109+
110+ let assert_ca_exists = function
111+ | true ->
112+ ca_bundle_path ()
113+ |> Option. to_result
114+ ~none: (gen_ex E_NO_CERTS " No certs to setup TLS connection to DC" )
115+ |> maybe_raise
116+ |> ignore
117+ | false ->
118+ ()
119+
93120let debug_level () =
94121 clamp
95122 ! Xapi_globs. winbind_debug_level
@@ -880,16 +907,10 @@ let query_domain_workgroup ~domain =
880907let config_winbind_daemon domain_info =
881908 let smb_config = " /etc/samba/smb.conf" in
882909 let extra_conf = " /etc/samba/smb.extra.conf" in
883- (* Will change to following config after trusted certs feature
884- tls cafile = /etc/trusted-certs/ca-bundle-[ldaps|general].pem
885- *)
886- let certs_dir = " /etc/stunnel/certs" in
887910 let string_of_bool = function true -> " yes" | false -> " no" in
888-
889911 let scan_trusted_domains =
890912 string_of_bool ! Xapi_globs. winbind_scan_trusted_domains
891913 in
892-
893914 ( match domain_info with
894915 | Some
895916 {
@@ -902,6 +923,17 @@ let config_winbind_daemon domain_info =
902923 let ldaps_conf =
903924 match ldaps with Some true -> " ldaps" | _ -> " seal"
904925 in
926+ let tls_ca =
927+ match ca_bundle_path () with
928+ | Some path when Sys. is_directory path ->
929+ Printf. sprintf " tls ca directories = %s" path
930+ | Some path ->
931+ Printf. sprintf " tls cafile = %s" path
932+ | None ->
933+ (* Presuming assert_ca_exists is called before reach here,
934+ so ldaps is not enabled here, this item does not matter *)
935+ Printf. sprintf " tls cafile = %s" ldaps_ca_bundle
936+ in
905937 [
906938 Printf. sprintf " # This file is managed by xapi, update %s instead"
907939 extra_conf
@@ -916,10 +948,10 @@ let config_winbind_daemon domain_info =
916948 ; " winbind refresh tickets = yes"
917949 ; " winbind enum groups = no"
918950 ; " winbind enum users = no"
919- ; Printf. sprintf " client ldap sasl wrapping= %s" ldaps_conf
951+ ; Printf. sprintf " client ldap sasl wrapping = %s" ldaps_conf
920952 ; " tls trust system cas = yes"
921953 ; " tls verify peer = ca_and_name_if_available"
922- ; Printf. sprintf " tls ca directories = %s " certs_dir
954+ ; tls_ca
923955 ; Printf. sprintf " winbind scan trusted domains = %s"
924956 scan_trusted_domains
925957 ; " winbind use krb5 enterprise principals = yes"
@@ -1190,7 +1222,8 @@ let set_ldaps ~__context ~ldaps ~force =
11901222 if old_domain_info.ldaps = Some ldaps && not force then
11911223 raise (generic_ex " ldaps is already %s" (string_of_bool ldaps)) ;
11921224
1193- (* check certificate exists *)
1225+ assert_ca_exists ldaps ;
1226+
11941227 let new_domain_info = {old_domain_info with ldaps= Some ldaps} in
11951228 (* Apply new configuration to winbind daemon for trial *)
11961229 Winbind. configure ~__context ~domain_info: new_domain_info () ;
@@ -1662,7 +1695,8 @@ module AuthADWinbind : Auth_signature.AUTH_MODULE = struct
16621695 (* Query new domain workgroup during join domain *)
16631696 query_domain_workgroup ~domain: service_name
16641697 in
1665- let ldaps = Some (Helpers. ldaps_enabled_in_config ~config: config_params) in
1698+ let ldaps = Helpers. ldaps_enabled_in_config ~config: config_params in
1699+ assert_ca_exists ldaps ;
16661700
16671701 let ou, ou_param = extract_ou_config ~config_params in
16681702 let domain_info =
@@ -1672,7 +1706,7 @@ module AuthADWinbind : Auth_signature.AUTH_MODULE = struct
16721706 ; workgroup= Some workgroup
16731707 ; netbios_name= Some netbios_name
16741708 ; machine_pwd_last_change_time= Some (Unix. time () )
1675- ; ldaps
1709+ ; ldaps= Some ldaps
16761710 ; ou
16771711 }
16781712 in
0 commit comments