Skip to content

Commit cda022d

Browse files
liulinCsnwoods
authored andcommitted
CP-309791: Update samba to 4.21
Microsoft Windows is doing security hardening https://bugzilla.samba.org/show_bug.cgi?id=15876 Our samba needs to update accordingly. There are some interface and configuration updates, thus xapi needs to be updated as well. This update is intended te be compatible with old and new samba, to decouple the merge of samba update. The old interface support will be dropped after samba merge. Signed-off-by: Lin Liu <Lin.Liu01@cloud.com>
1 parent 60d7da4 commit cda022d

1 file changed

Lines changed: 59 additions & 48 deletions

File tree

ocaml/xapi/extauth_plugin_ADwinbind.ml

Lines changed: 59 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,14 @@ let generic_error msg =
9191

9292
let fail fmt = Printf.ksprintf generic_error fmt
9393

94+
let is_samba_updated =
95+
(* This is temporary workaround to be compatible for old and new samba, to decouple the merge of xapi and samba *)
96+
let check_file = "/usr/lib64/samba/libxattr-tdb-private-samba.so" in
97+
Sys.file_exists check_file
98+
99+
let kerberos_opt =
100+
match is_samba_updated with true -> [] | false -> ["--kerberos"]
101+
94102
(** Kerberos Domain Controller. The current implementation does not
95103
work with non-standard ports *)
96104
module KDC : sig
@@ -413,8 +421,8 @@ module Ldap = struct
413421
; "--server"
414422
; KDC.server kdc
415423
; "--machine-pass"
416-
; "--kerberos"
417424
]
425+
@ kerberos_opt
418426
@ attrs
419427
in
420428
let stdout =
@@ -440,10 +448,9 @@ module Ldap = struct
440448
; "--server"
441449
; KDC.server kdc
442450
; "--machine-pass"
443-
; "--kerberos"
444-
; query
445-
; key
446451
]
452+
@ kerberos_opt
453+
@ [query; key]
447454
in
448455
try
449456
Helpers.call_script ~env !Xapi_globs.net_cmd args
@@ -794,7 +801,7 @@ end
794801
let kdcs_of_domain domain =
795802
try
796803
Helpers.call_script ~log_output:On_failure net_cmd
797-
["lookup"; "kdc"; domain; "-d"; debug_level (); "--kerberos"]
804+
(["lookup"; "kdc"; domain; "-d"; debug_level ()] @ kerberos_opt)
798805
(* Result like 10.71.212.25:88\n10.62.1.25:88\n*)
799806
|> String.split_on_char '\n'
800807
|> List.filter (fun x -> String.trim x <> "") (* Remove empty lines *)
@@ -808,9 +815,9 @@ let workgroup_from_server kdc =
808815
let key = "Pre-Win2k Domain" in
809816
try
810817
Helpers.call_script ~log_output:On_failure net_cmd
811-
[
812-
"ads"; "lookup"; "-S"; KDC.server kdc; "-d"; debug_level (); "--kerberos"
813-
]
818+
(["ads"; "lookup"; "-S"; KDC.server kdc; "-d"; debug_level ()]
819+
@ kerberos_opt
820+
)
814821
|> Xapi_cmd_result.of_output ~sep:':' ~key
815822
|> Result.ok
816823
with _ ->
@@ -843,36 +850,47 @@ let config_winbind_daemon ~workgroup ~netbios_name ~domain =
843850
* upgrade to samba packages with this capacity *)
844851
if !Xapi_globs.winbind_allow_kerberos_auth_fallback then "yes" else "no"
845852
in
853+
let version_conf =
854+
match is_samba_updated with
855+
| false ->
856+
[Printf.sprintf "allow kerberos auth fallback = %s" allow_fallback]
857+
| true ->
858+
[
859+
"client use kerberos = required"
860+
; "sync machine password to keytab = \
861+
/etc/krb5.keytab:account_name:sync_etypes:sync_kvno:machine_password"
862+
]
863+
in
846864
( match (workgroup, netbios_name, domain) with
847865
| Some wkgroup, Some netbios, Some dom ->
848-
[
849-
"# autogenerated by xapi"
850-
; "[global]"
851-
; "kerberos method = secrets and keytab"
852-
; Printf.sprintf "realm = %s" dom
853-
; "security = ADS"
854-
; "template shell = /bin/bash"
855-
; "winbind refresh tickets = yes"
856-
; "winbind enum groups = no"
857-
; "winbind enum users = no"
858-
; "winbind scan trusted domains = yes"
859-
; "winbind use krb5 enterprise principals = yes"
860-
; Printf.sprintf "winbind cache time = %d" !Xapi_globs.winbind_cache_time
861-
; Printf.sprintf "machine password timeout = 0"
862-
; Printf.sprintf "kerberos encryption types = %s"
863-
(Kerberos_encryption_types.Winbind.to_string
864-
!Xapi_globs.winbind_kerberos_encryption_type
865-
)
866-
; Printf.sprintf "workgroup = %s" wkgroup
867-
; Printf.sprintf "netbios name = %s" netbios
868-
; "idmap config * : range = 3000000-3999999"
869-
; Printf.sprintf "idmap config %s: backend = rid" dom
870-
; Printf.sprintf "idmap config %s: range = 2000000-2999999" dom
871-
; Printf.sprintf "log level = %s" (debug_level ())
872-
; Printf.sprintf "allow kerberos auth fallback = %s" allow_fallback
873-
; "idmap config * : backend = tdb"
874-
; "" (* Empty line at the end *)
875-
]
866+
["# autogenerated by xapi"; "[global]"]
867+
@ version_conf
868+
@ [
869+
"kerberos method = secrets and keytab"
870+
; Printf.sprintf "realm = %s" dom
871+
; "security = ADS"
872+
; "template shell = /bin/bash"
873+
; "winbind refresh tickets = yes"
874+
; "winbind enum groups = no"
875+
; "winbind enum users = no"
876+
; "winbind scan trusted domains = yes"
877+
; "winbind use krb5 enterprise principals = yes"
878+
; Printf.sprintf "winbind cache time = %d"
879+
!Xapi_globs.winbind_cache_time
880+
; Printf.sprintf "machine password timeout = 0"
881+
; Printf.sprintf "kerberos encryption types = %s"
882+
(Kerberos_encryption_types.Winbind.to_string
883+
!Xapi_globs.winbind_kerberos_encryption_type
884+
)
885+
; Printf.sprintf "workgroup = %s" wkgroup
886+
; Printf.sprintf "netbios name = %s" netbios
887+
; "idmap config * : range = 3000000-3999999"
888+
; Printf.sprintf "idmap config %s: backend = rid" dom
889+
; Printf.sprintf "idmap config %s: range = 2000000-2999999" dom
890+
; Printf.sprintf "log level = %s" (debug_level ())
891+
; "idmap config * : backend = tdb"
892+
; "" (* Empty line at the end *)
893+
]
876894
| _ ->
877895
["# autogenerated by xapi"; "[global]"; "" (* Empty line at the end *)]
878896
)
@@ -951,7 +969,7 @@ let clear_machine_account ~service_name = function
951969
(* Disable machine account in DC *)
952970
let env = [|Printf.sprintf "PASSWD=%s" p|] in
953971
let args =
954-
["ads"; "leave"; "-U"; u; "-d"; debug_level (); "--kerberos"]
972+
["ads"; "leave"; "-U"; u; "-d"; debug_level ()] @ kerberos_opt
955973
in
956974
try
957975
Helpers.call_script ~env net_cmd args |> ignore ;
@@ -1228,15 +1246,8 @@ module RotateMachinePassword = struct
12281246

12291247
let kdc_fqdn_of_ip kdc =
12301248
let args =
1231-
[
1232-
"ads"
1233-
; "lookup"
1234-
; "--server"
1235-
; KDC.server kdc
1236-
; "--kerberos"
1237-
; "-d"
1238-
; debug_level ()
1239-
]
1249+
["ads"; "lookup"; "--server"; KDC.server kdc; "-d"; debug_level ()]
1250+
@ kerberos_opt
12401251
in
12411252
Helpers.call_script !Xapi_globs.net_cmd args ~log_output:On_failure
12421253
|> Xapi_cmd_result.of_output ~sep:':' ~key:"Domain Controller"
@@ -1303,12 +1314,12 @@ module RotateMachinePassword = struct
13031314
[
13041315
"ads"
13051316
; "changetrustpw"
1306-
; "--kerberos"
13071317
; "--server"
13081318
; kdc_fqdn
13091319
; "-d"
13101320
; debug_level ()
13111321
]
1322+
@ kerberos_opt
13121323
in
13131324
finally
13141325
(fun () ->
@@ -1786,8 +1797,8 @@ module AuthADWinbind : Auth_signature.AUTH_MODULE = struct
17861797
; "-d"
17871798
; debug_level ()
17881799
; "--no-dns-updates"
1789-
; "--kerberos"
17901800
]
1801+
@ kerberos_opt
17911802
; ou_param
17921803
; dns_hostname_option
17931804
]

0 commit comments

Comments
 (0)