Skip to content

CA-412636: hostname changed to localhost with static IP and reboot #6546

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 4 additions & 22 deletions ocaml/xapi/extauth_plugin_ADwinbind.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1434,23 +1434,6 @@ module ConfigHosts = struct
|> write_string_to_file path
end

module ResolveConfig = struct
let path = "/etc/resolv.conf"

type t = Add | Remove

let handle op domain =
let open Xapi_stdext_unix.Unixext in
let config = Printf.sprintf "search %s" domain in
read_lines ~path |> List.filter (fun x -> x <> config) |> fun x ->
(match op with Add -> config :: x | Remove -> x) |> fun x ->
x @ [""] |> String.concat "\n" |> write_string_to_file path

let join ~domain = handle Add domain

let leave ~domain = handle Remove domain
end

module DNSSync = struct
let task_name = "Sync hostname with DNS"

Expand Down Expand Up @@ -1827,7 +1810,10 @@ module AuthADWinbind : Auth_signature.AUTH_MODULE = struct
ClosestKdc.trigger_update ~start:0. ;
RotateMachinePassword.trigger_rotate ~start:0. ;
ConfigHosts.join ~domain:service_name ~name:netbios_name ;
ResolveConfig.join ~domain:service_name ;
Forkhelpers.execute_command_get_output !Xapi_globs.set_hostname
[get_localhost_name ()]
|> ignore ;
(* Trigger right now *)
DNSSync.trigger_sync ~start:0. ;
Winbind.set_machine_account_encryption_type netbios_name ;
debug "Succeed to join domain %s" service_name
Expand All @@ -1836,15 +1822,13 @@ module AuthADWinbind : Auth_signature.AUTH_MODULE = struct
error "Join domain: %s error: %s" service_name stdout ;
clear_winbind_config () ;
ConfigHosts.leave ~domain:service_name ~name:netbios_name ;
ResolveConfig.leave ~domain:service_name ;
(* The configure is kept for debug purpose with max level *)
raise (Auth_service_error (stdout |> tag_from_err_msg, stdout))
| Xapi_systemctl.Systemctl_fail _ ->
let msg = Printf.sprintf "Failed to start %s" Winbind.name in
error "Start daemon error: %s" msg ;
config_winbind_daemon ~domain:None ~workgroup:None ~netbios_name:None ;
ConfigHosts.leave ~domain:service_name ~name:netbios_name ;
ResolveConfig.leave ~domain:service_name ;
raise (Auth_service_error (E_GENERIC, msg))
| e ->
let msg =
Expand All @@ -1856,7 +1840,6 @@ module AuthADWinbind : Auth_signature.AUTH_MODULE = struct
error "Enable extauth error: %s" msg ;
clear_winbind_config () ;
ConfigHosts.leave ~domain:service_name ~name:netbios_name ;
ResolveConfig.leave ~domain:service_name ;
raise (Auth_service_error (E_GENERIC, msg))

(* unit on_disable()
Expand All @@ -1871,7 +1854,6 @@ module AuthADWinbind : Auth_signature.AUTH_MODULE = struct
let user = List.assoc_opt "user" config_params in
let pass = List.assoc_opt "pass" config_params in
let {service_name; netbios_name; _} = get_domain_info_from_db () in
ResolveConfig.leave ~domain:service_name ;
DNSSync.stop_sync () ;
( match netbios_name with
| Some netbios ->
Expand Down
Loading