@@ -63,42 +63,13 @@ HRESULT new_user(void)
63
63
hr = _WslLaunchInteractive (DISTOR_NAME , command , FALSE, & exit_code );
64
64
} while (FAILED (hr ) || exit_code != 0 );
65
65
66
- HANDLE read_pipe , write_pipe ;
67
- SECURITY_ATTRIBUTES sec_attr ;
68
- sec_attr .nLength = sizeof (SECURITY_ATTRIBUTES );
69
- sec_attr .lpSecurityDescriptor = NULL ;
70
- sec_attr .bInheritHandle = TRUE;
66
+ wchar_t username_w [33 ];
67
+ for (int i = 0 ; i < ARRAYSIZE (username_w ) && username [i ]; i ++ )
68
+ username_w [i ] = username [i ];
71
69
72
- if (CreatePipe (& read_pipe , & write_pipe , & sec_attr , 0 ))
73
- {
74
- swprintf (command , ARRAYSIZE (command ), L"id -u %hs" , username );
75
-
76
- HANDLE handle_stdin = GetStdHandle (STD_INPUT_HANDLE );
77
- HANDLE handle_stderr = GetStdHandle (STD_ERROR_HANDLE );
78
- HANDLE process_handle ;
79
- hr = _WslLaunch (DISTOR_NAME , command , FALSE, handle_stdin , write_pipe , handle_stderr , & process_handle );
80
- if (SUCCEEDED (hr ))
81
- {
82
- WaitForSingleObject (process_handle , INFINITE );
83
- GetExitCodeProcess (process_handle , & exit_code );
84
- CloseHandle (process_handle );
85
-
86
- if (exit_code == 0 )
87
- {
88
- char uid_string [16 ];
89
- DWORD byte_read ;
90
- if (ReadFile (read_pipe , uid_string , 15 , & byte_read , NULL ))
91
- {
92
- CloseHandle (read_pipe );
93
- CloseHandle (write_pipe );
94
-
95
- uid_string [byte_read ] = '\0' ;
96
- ULONG uid = strtoul (uid_string , NULL , 10 );
97
- hr = _WslConfigureDistribution (DISTOR_NAME , uid , WSL_DISTRIBUTION_FLAGS_DEFAULT );
98
- }
99
- }
100
- }
101
- }
70
+ ULONG uid = uid_from_username (DISTOR_NAME , username_w );
71
+ if (uid != ULONG_MAX )
72
+ hr = _WslConfigureDistribution (DISTOR_NAME , uid , WSL_DISTRIBUTION_FLAGS_DEFAULT );
102
73
}
103
74
return hr ;
104
75
}
0 commit comments