@@ -56,11 +56,25 @@ impl AgentAccount {
5656 AgentAccount :: LocalService => AccountName :: new ( NT_AUTHORITY , "LocalService" ) ,
5757 AgentAccount :: NetworkService => AccountName :: new ( NT_AUTHORITY , "NetworkService" ) ,
5858 AgentAccount :: PasswordLogon { domain, user, .. }
59- | AgentAccount :: ServiceAccountLogon { domain, user } => AccountName :: new ( domain, user) ,
59+ | AgentAccount :: ServiceAccountLogon { domain, user } => {
60+ account_name_for_logon ( domain, user)
61+ }
6062 }
6163 }
6264}
6365
66+ /// Match registry-style local SAM display (`.\user`) when installer stored the computer name as domain.
67+ fn account_name_for_logon ( domain : & str , user : & str ) -> AccountName {
68+ let display_domain = match lookup_account_sid ( domain, user)
69+ . ok ( )
70+ . and_then ( |sid| is_local_account ( & sid) . ok ( ) )
71+ {
72+ Some ( true ) => String :: new ( ) ,
73+ _ => domain. to_string ( ) ,
74+ } ;
75+ AccountName :: new ( display_domain, user)
76+ }
77+
6478/// Resolve the spawn account display string for a profile on Windows.
6579pub ( crate ) fn spawn_user_for_profile (
6680 process_name : & str ,
@@ -397,6 +411,35 @@ mod tests {
397411 ) ;
398412 }
399413
414+ #[ test]
415+ fn display_name_normalizes_local_machine_domain ( ) {
416+ let username = "Administrator" ;
417+ let sid =
418+ match lookup_account_sid ( "." , username) . or_else ( |_| lookup_account_sid ( "" , username) ) {
419+ Ok ( sid) => sid,
420+ Err ( e) => {
421+ eprintln ! ( "skipping: built-in Administrator not available: {e:#}" ) ;
422+ return ;
423+ }
424+ } ;
425+ if !is_local_account ( & sid) . unwrap_or ( false ) {
426+ eprintln ! ( "skipping: Administrator is not a local SAM account on this host" ) ;
427+ return ;
428+ }
429+
430+ let computer = super :: super :: local_account:: computer_name ( ) . expect ( "computer name" ) ;
431+ assert_eq ! (
432+ AgentAccount :: PasswordLogon {
433+ domain: computer,
434+ user: username. to_string( ) ,
435+ password: "secret" . to_string( ) ,
436+ }
437+ . display_name( ) ,
438+ AccountName :: new( "" , username) . display( ) ,
439+ "installer machine-name domain should display as .\\ user for local SAM accounts"
440+ ) ;
441+ }
442+
400443 #[ test]
401444 fn passwordless_domain_account_requires_password ( ) {
402445 let err = passwordless_agent_account (
0 commit comments