@@ -815,7 +815,6 @@ let query_domain_workgroup ~domain =
815815 with _ -> raise (Auth_service_error (E_LOOKUP , err_msg))
816816
817817let config_winbind_daemon ~workgroup ~netbios_name ~domain =
818- let open Xapi_stdext_unix in
819818 let smb_config = " /etc/samba/smb.conf" in
820819 let allow_fallback =
821820 (* `allow kerberos auth fallback` depends on our internal samba patch,
@@ -825,42 +824,41 @@ let config_winbind_daemon ~workgroup ~netbios_name ~domain =
825824 * upgrade to samba packages with this capacity *)
826825 if ! Xapi_globs. winbind_allow_kerberos_auth_fallback then " yes" else " no"
827826 in
828- let conf_contents =
829- match (workgroup, netbios_name, domain) with
830- | Some wkgroup , Some netbios , Some dom ->
831- [
832- " # autogenerated by xapi"
833- ; " [global]"
834- ; " kerberos method = secrets and keytab"
835- ; Printf. sprintf " realm = %s" dom
836- ; " security = ADS"
837- ; " template shell = /bin/bash"
838- ; " winbind refresh tickets = yes"
839- ; " winbind enum groups = no"
840- ; " winbind enum users = no"
841- ; " winbind scan trusted domains = yes"
842- ; " winbind use krb5 enterprise principals = yes"
843- ; Printf. sprintf " winbind cache time = %d"
844- ! Xapi_globs. winbind_cache_time
845- ; Printf. sprintf " machine password timeout = 0"
846- ; Printf. sprintf " kerberos encryption types = %s"
847- (Kerberos_encryption_types.Winbind. to_string
848- ! Xapi_globs. winbind_kerberos_encryption_type
849- )
850- ; Printf. sprintf " workgroup = %s" wkgroup
851- ; Printf. sprintf " netbios name = %s" netbios
852- ; " idmap config * : range = 3000000-3999999"
853- ; Printf. sprintf " idmap config %s: backend = rid" dom
854- ; Printf. sprintf " idmap config %s: range = 2000000-2999999" dom
855- ; Printf. sprintf " log level = %s" (debug_level () )
856- ; Printf. sprintf " allow kerberos auth fallback = %s" allow_fallback
857- ; " idmap config * : backend = tdb"
858- ; " " (* Empty line at the end *)
859- ]
860- | _ ->
861- [" # autogenerated by xapi" ; " [global]" ; " " (* Empty line at the end *) ]
862- in
863- Helpers.ListFile. to_path smb_config conf_contents
827+ ( match (workgroup, netbios_name, domain) with
828+ | Some wkgroup , Some netbios , Some dom ->
829+ [
830+ " # autogenerated by xapi"
831+ ; " [global]"
832+ ; " kerberos method = secrets and keytab"
833+ ; Printf. sprintf " realm = %s" dom
834+ ; " security = ADS"
835+ ; " template shell = /bin/bash"
836+ ; " winbind refresh tickets = yes"
837+ ; " winbind enum groups = no"
838+ ; " winbind enum users = no"
839+ ; " winbind scan trusted domains = yes"
840+ ; " winbind use krb5 enterprise principals = yes"
841+ ; Printf. sprintf " winbind cache time = %d" ! Xapi_globs. winbind_cache_time
842+ ; Printf. sprintf " machine password timeout = 0"
843+ ; Printf. sprintf " kerberos encryption types = %s"
844+ (Kerberos_encryption_types.Winbind. to_string
845+ ! Xapi_globs. winbind_kerberos_encryption_type
846+ )
847+ ; Printf. sprintf " workgroup = %s" wkgroup
848+ ; Printf. sprintf " netbios name = %s" netbios
849+ ; " idmap config * : range = 3000000-3999999"
850+ ; Printf. sprintf " idmap config %s: backend = rid" dom
851+ ; Printf. sprintf " idmap config %s: range = 2000000-2999999" dom
852+ ; Printf. sprintf " log level = %s" (debug_level () )
853+ ; Printf. sprintf " allow kerberos auth fallback = %s" allow_fallback
854+ ; " idmap config * : backend = tdb"
855+ ; " " (* Empty line at the end *)
856+ ]
857+ | _ ->
858+ [" # autogenerated by xapi" ; " [global]" ; " " (* Empty line at the end *) ]
859+ )
860+ |> String. concat " \n "
861+ |> Xapi_stdext_unix.Unixext. write_string_to_file smb_config
864862
865863let clear_winbind_config () =
866864 (* Keep the winbind configuration if xapi config file specified explictly,
@@ -1198,7 +1196,6 @@ module RotateMachinePassword = struct
11981196 let generate_krb5_tmp_config ~domain ~kdc_fqdn =
11991197 (* Configure which server to change the password
12001198 * https://web.mit.edu/kerberos/krb5-devel/doc/admin/conf_files/krb5_conf.html *)
1201- let open Xapi_stdext_unix in
12021199 let realm = String. uppercase_ascii domain in
12031200 let domain_netbios =
12041201 Wbinfo. domain_name_of ~target_name_type: NetbiosName ~from_name: domain
@@ -1212,22 +1209,21 @@ module RotateMachinePassword = struct
12121209 []
12131210 in
12141211
1215- let conf_contents =
1216- [
1217- " # autogenerated by xapi"
1218- ; " [libdefaults]"
1219- ; Printf. sprintf " default_realm = %s" realm
1220- ; " [realms]"
1221- ; Printf. sprintf " %s={" realm
1222- ; Printf. sprintf " kpasswd_server=%s" kdc_fqdn
1223- ; Printf. sprintf " kdc=%s" kdc_fqdn
1224- ; " }" (* include winbind generated configure if exists *)
1225- ]
1226- @ include_item
1227- @ [" " ]
1228- (* Empty line at the end *)
1229- in
1230- Helpers.ListFile. to_path tmp_krb5_conf conf_contents
1212+ [
1213+ " # autogenerated by xapi"
1214+ ; " [libdefaults]"
1215+ ; Printf. sprintf " default_realm = %s" realm
1216+ ; " [realms]"
1217+ ; Printf. sprintf " %s={" realm
1218+ ; Printf. sprintf " kpasswd_server=%s" kdc_fqdn
1219+ ; Printf. sprintf " kdc=%s" kdc_fqdn
1220+ ; " }" (* include winbind generated configure if exists *)
1221+ ]
1222+ @ include_item
1223+ @ [" " ]
1224+ (* Empty line at the end *)
1225+ |> String. concat " \n "
1226+ |> Xapi_stdext_unix.Unixext. write_string_to_file tmp_krb5_conf
12311227
12321228 let clear_tmp_krb5_conf () =
12331229 if ! Xapi_globs. winbind_keep_configuration then
@@ -1354,19 +1350,23 @@ module HostsConfIPv4 = HostsConfFunc (HostsConfTagIPv4)
13541350module HostsConfIPv6 = HostsConfFunc (HostsConfTagIPv6 )
13551351
13561352module ConfigHosts = struct
1353+ open Xapi_stdext_unix.Unixext
1354+
13571355 let path = " /etc/hosts"
13581356
13591357 let join ~name ~domain =
1360- Helpers.ListFile. of_path path
1361- |> HostsConfIPv4. join ~name ~domain
1362- |> HostsConfIPv6. join ~name ~domain
1363- |> Helpers.ListFile. to_path path
1358+ read_lines ~path |> fun lines ->
1359+ HostsConfIPv4. join ~name ~domain ~lines |> fun lines ->
1360+ HostsConfIPv6. join ~name ~domain ~lines
1361+ |> String. concat " \n "
1362+ |> write_string_to_file path
13641363
13651364 let leave ~name ~domain =
1366- Helpers.ListFile. of_path path
1367- |> HostsConfIPv4. leave ~name ~domain
1368- |> HostsConfIPv6. leave ~name ~domain
1369- |> Helpers.ListFile. to_path path
1365+ read_lines ~path |> fun lines ->
1366+ HostsConfIPv4. leave ~name ~domain ~lines |> fun lines ->
1367+ HostsConfIPv6. leave ~name ~domain ~lines
1368+ |> String. concat " \n "
1369+ |> write_string_to_file path
13701370end
13711371
13721372let build_netbios_name ~config_params =
@@ -1729,12 +1729,12 @@ module AuthADWinbind : Auth_signature.AUTH_MODULE = struct
17291729 let @ __context = Context. with_tracing ~__context __FUNCTION__ in
17301730 let user = List. assoc_opt " user" config_params in
17311731 let pass = List. assoc_opt " pass" config_params in
1732- let {service_name; workgroup; netbios_name; _} =
1733- get_domain_info_from_db ()
1734- in
1735- ( if Option. is_some netbios_name then
1736- Option. get netbios_name |> fun name ->
1732+ let {service_name; netbios_name; _} = get_domain_info_from_db () in
1733+ ( match netbios_name with
1734+ | Some name ->
17371735 ConfigHosts. leave ~domain: service_name ~name
1736+ | _ ->
1737+ ()
17381738 ) ;
17391739
17401740 (* Clean extauth config *)
@@ -1763,12 +1763,12 @@ module AuthADWinbind : Auth_signature.AUTH_MODULE = struct
17631763 RotateMachinePassword. trigger_rotate ~start: 5. ;
17641764 Winbind. check_ready_to_serve ~timeout: 300. ;
17651765
1766- let {service_name; workgroup; netbios_name; _} =
1767- get_domain_info_from_db ()
1768- in
1769- if Option. is_some netbios_name then
1770- Option. get netbios_name |> fun name ->
1771- ConfigHosts. join ~domain: service_name ~name
1766+ let {service_name; netbios_name; _} = get_domain_info_from_db () in
1767+ match netbios_name with
1768+ | Some name ->
1769+ ConfigHosts. join ~domain: service_name ~name
1770+ | _ ->
1771+ ()
17721772
17731773 (* unit on_xapi_exit()
17741774
0 commit comments