|
22 | 22 | open D |
23 | 23 | open Xapi_stdext_std.Xstringext |
24 | 24 | open Auth_signature |
| 25 | +module Listext = Xapi_stdext_std.Listext |
25 | 26 | module Scheduler = Xapi_stdext_threads_scheduler.Scheduler |
26 | 27 |
|
27 | 28 | let finally = Xapi_stdext_pervasives.Pervasiveext.finally |
@@ -81,9 +82,13 @@ let debug_level () = |
81 | 82 | |> string_of_int |
82 | 83 |
|
83 | 84 | let err_msg_to_tag_map = |
| 85 | + let open Auth_signature in |
84 | 86 | [ |
85 | | - ("not a properly formed account name", Auth_signature.E_INVALID_ACCOUNT) |
86 | | - ; ("bad username or authentication", Auth_signature.E_CREDENTIALS) |
| 87 | + ("not a properly formed account name", E_INVALID_ACCOUNT) |
| 88 | + ; ("bad username or authentication", E_CREDENTIALS) |
| 89 | + ; ( "Windows cannot verify the digital signature for this file" |
| 90 | + , E_INVALID_CERTS |
| 91 | + ) |
87 | 92 | (* Some other errors *) |
88 | 93 | ] |
89 | 94 |
|
@@ -265,6 +270,12 @@ let tag_from_err_msg msg = |
265 | 270 | | None -> |
266 | 271 | Auth_signature.E_GENERIC |
267 | 272 |
|
| 273 | +let auth_ex_of_msg errmsg fmt = |
| 274 | + let tag = tag_from_err_msg errmsg in |
| 275 | + Printf.ksprintf |
| 276 | + (fun msg -> Auth_signature.(Auth_service_error (tag, msg))) |
| 277 | + fmt |
| 278 | + |
268 | 279 | let update_extauth_configuration ~__context ~k ~v = |
269 | 280 | let self = Helpers.get_localhost ~__context in |
270 | 281 | Db.Host.get_external_auth_configuration ~__context ~self |> fun value -> |
@@ -549,24 +560,25 @@ module Ldap = struct |
549 | 560 | |> Xapi_cmd_result.of_output ~sep:':' ~key |
550 | 561 | |> fun x -> Ok x |
551 | 562 | with |
552 | | - | Forkhelpers.Spawn_internal_error (_, stdout, _) -> |
553 | | - Error (generic_ex "Ldap query sid failed: %s" stdout) |
| 563 | + | Forkhelpers.Spawn_internal_error (err, out, _) -> |
| 564 | + Error |
| 565 | + (auth_ex_of_msg err "Failed to do ldap(s) query for %s %s" name out) |
554 | 566 | | Not_found -> |
555 | 567 | Error (generic_ex "%s not found in ldap result" key) |
556 | 568 | | _ -> |
557 | 569 | Error (generic_ex "Failed to lookup sid from username %s" name) |
558 | 570 |
|
559 | 571 | let ping_domain domain = |
560 | | - match |
561 | | - kdcs_of_domain domain |
562 | | - |> List.find_opt (fun kdc -> |
563 | | - query_sid ~name:krbtgt ~kdc:(KDC.server kdc) |> Result.is_ok |
| 572 | + kdcs_of_domain domain |
| 573 | + |> Listext.List.try_map_any (fun kdc -> |
| 574 | + query_sid ~name:krbtgt ~kdc:(KDC.server kdc) |
| 575 | + ) |
| 576 | + |> Result.map_error (function |
| 577 | + | e :: _ -> |
| 578 | + e |
| 579 | + | [] -> |
| 580 | + generic_ex "Failed to ping domain %s" domain |
564 | 581 | ) |
565 | | - with |
566 | | - | Some _ -> |
567 | | - Ok () |
568 | | - | None -> |
569 | | - Error (generic_ex "Failed to ping domain %s: all kdcs failed" domain) |
570 | 582 | end |
571 | 583 |
|
572 | 584 | module Wbinfo = struct |
@@ -1161,24 +1173,22 @@ let set_ldaps ~__context ~ldaps ~force = |
1161 | 1173 | if old_domain_info.ldaps = Some ldaps && not force then |
1162 | 1174 | raise (generic_ex "ldaps is already %s" (string_of_bool ldaps)) ; |
1163 | 1175 |
|
| 1176 | + (* check certificate exists *) |
1164 | 1177 | let new_domain_info = {old_domain_info with ldaps= Some ldaps} in |
1165 | 1178 | (* Apply new configuration to winbind daemon for trial *) |
1166 | 1179 | Winbind.configure ~__context ~domain_info:new_domain_info () ; |
1167 | 1180 | (* Verify the new LDAP(S) setting works *) |
1168 | 1181 | match Ldap.ping_domain new_domain_info.service_name with |
1169 | | - | Ok () -> |
| 1182 | + | Ok _ -> |
1170 | 1183 | (* Ping succeeded, persist the new domain_info *) |
| 1184 | + debug "%s ping domain succeed" __FUNCTION__ ; |
1171 | 1185 | DomainInfo.to_db ~__context ~domain_info:(Some new_domain_info) |
1172 | 1186 | | Error e -> |
1173 | 1187 | (* Ping failed, restore the old configuration *) |
1174 | 1188 | Winbind.configure ~__context ~domain_info:old_domain_info () ; |
1175 | | - raise |
1176 | | - (generic_ex |
1177 | | - "ldap(s) verification failed for domain %s: %s, restored old \ |
1178 | | - configuration" |
1179 | | - new_domain_info.service_name |
1180 | | - (ExnHelper.string_of_exn e) |
1181 | | - ) |
| 1189 | + debug "%s ldap(s) verification failed, restored old configure" |
| 1190 | + __FUNCTION__ ; |
| 1191 | + raise e |
1182 | 1192 |
|
1183 | 1193 | module RotateMachinePassword = struct |
1184 | 1194 | let task_name = "Rotating machine password" |
|
0 commit comments