Skip to content

Commit

Permalink
Slackware optimizations in launcher
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohsens22 committed Apr 6, 2021
1 parent d08b476 commit df08445
Show file tree
Hide file tree
Showing 6 changed files with 513 additions and 503 deletions.
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
<?xml version="1.0" encoding="utf-8"?>
<Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10" xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest" xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10" xmlns:uap2="http://schemas.microsoft.com/appx/manifest/uap/windows10/2" xmlns:uap3="http://schemas.microsoft.com/appx/manifest/uap/windows10/3" xmlns:desktop="http://schemas.microsoft.com/appx/manifest/desktop/windows10" xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities" IgnorableNamespaces="uap mp uap2 uap3 rescap desktop">
<Identity Name="WSLackware" Version="15.0.7.0" Publisher="CN=Mohsens22" ProcessorArchitecture="x64" />
<mp:PhoneIdentity PhoneProductId="160867c6-4e75-4e36-85c6-1543de07d5f3" PhonePublisherId="00000000-0000-0000-0000-000000000000" />
<Properties>
<DisplayName>WSLackware</DisplayName>
<PublisherDisplayName>Mohsens22</PublisherDisplayName>
<Logo>Assets\Tiles\StoreLogo.png</Logo>
</Properties>
<Dependencies>
<TargetDeviceFamily Name="Windows.Desktop" MinVersion="10.0.18362.0" MaxVersionTested="10.0.19041.0" />
</Dependencies>
<Capabilities>
<rescap:Capability Name="runFullTrust" />
</Capabilities>
<Resources>
<Resource Language="x-generate" />
</Resources>
<Applications>
<Application Id="WSLackware" Executable="WSLackware.exe" EntryPoint="Windows.FullTrustApplication">
<uap:VisualElements DisplayName="WSLackware" Square150x150Logo="Assets\Tiles\Square150x150Logo.png" Square44x44Logo="Assets\Tiles\Square44x44Logo.png" BackgroundColor="transparent" Description="Slackware for Windows">
<uap:DefaultTile Wide310x150Logo="Assets\Tiles\Wide310x150Logo.png" Square310x310Logo="Assets\Tiles\LargeTile.png" Square71x71Logo="Assets\Tiles\SmallTile.png" ShortName="WSLackware">
<uap:ShowNameOnTiles>
<uap:ShowOn Tile="square150x150Logo"/>
<uap:ShowOn Tile="wide310x150Logo"/>
<uap:ShowOn Tile="square310x310Logo"/>
</uap:ShowNameOnTiles>
</uap:DefaultTile>
<uap:SplashScreen Image="Assets\Tiles\SplashScreen.png" />
</uap:VisualElements>
<Extensions>
<uap3:Extension Category="windows.appExecutionAlias" Executable="WSLackware.exe" EntryPoint="Windows.FullTrustApplication">
<uap3:AppExecutionAlias>
<desktop:ExecutionAlias Alias="WSLackware.exe" />
</uap3:AppExecutionAlias>
</uap3:Extension>
</Extensions>
</Application>
</Applications>
<?xml version="1.0" encoding="utf-8"?>
<Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10" xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest" xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10" xmlns:uap2="http://schemas.microsoft.com/appx/manifest/uap/windows10/2" xmlns:uap3="http://schemas.microsoft.com/appx/manifest/uap/windows10/3" xmlns:desktop="http://schemas.microsoft.com/appx/manifest/desktop/windows10" xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities" IgnorableNamespaces="uap mp uap2 uap3 rescap desktop">
<Identity Name="WSLackware" Version="15.0.15.0" Publisher="CN=Mohsens22" ProcessorArchitecture="x64" />
<mp:PhoneIdentity PhoneProductId="160867c6-4e75-4e36-85c6-1543de07d5f3" PhonePublisherId="00000000-0000-0000-0000-000000000000" />
<Properties>
<DisplayName>WSLackware</DisplayName>
<PublisherDisplayName>Mohsens22</PublisherDisplayName>
<Logo>Assets\Tiles\StoreLogo.png</Logo>
</Properties>
<Dependencies>
<TargetDeviceFamily Name="Windows.Desktop" MinVersion="10.0.18362.0" MaxVersionTested="10.0.19041.0" />
</Dependencies>
<Capabilities>
<rescap:Capability Name="runFullTrust" />
</Capabilities>
<Resources>
<Resource Language="x-generate" />
</Resources>
<Applications>
<Application Id="WSLackware" Executable="WSLackware.exe" EntryPoint="Windows.FullTrustApplication">
<uap:VisualElements DisplayName="WSLackware" Square150x150Logo="Assets\Tiles\Square150x150Logo.png" Square44x44Logo="Assets\Tiles\Square44x44Logo.png" BackgroundColor="transparent" Description="Slackware for Windows">
<uap:DefaultTile Wide310x150Logo="Assets\Tiles\Wide310x150Logo.png" Square310x310Logo="Assets\Tiles\LargeTile.png" Square71x71Logo="Assets\Tiles\SmallTile.png" ShortName="WSLackware">
<uap:ShowNameOnTiles>
<uap:ShowOn Tile="square150x150Logo"/>
<uap:ShowOn Tile="wide310x150Logo"/>
<uap:ShowOn Tile="square310x310Logo"/>
</uap:ShowNameOnTiles>
</uap:DefaultTile>
<uap:SplashScreen Image="Assets\Tiles\SplashScreen.png" />
</uap:VisualElements>
<Extensions>
<uap3:Extension Category="windows.appExecutionAlias" Executable="WSLackware.exe" EntryPoint="Windows.FullTrustApplication">
<uap3:AppExecutionAlias>
<desktop:ExecutionAlias Alias="WSLackware.exe" />
</uap3:AppExecutionAlias>
</uap3:Extension>
</Extensions>
</Application>
</Applications>
</Package>
181 changes: 94 additions & 87 deletions src/WSLackwareLauncher/DistroLauncher/DistributionInfo.cpp
Original file line number Diff line number Diff line change
@@ -1,87 +1,94 @@
//
// Copyright (C) Microsoft. All rights reserved.
// Licensed under the terms described in the LICENSE file in the root of this project.
//

#include "stdafx.h"

bool DistributionInfo::CreateUser(std::wstring_view userName)
{
// Create the user account and Add the user account to any relevant groups.
DWORD exitCode;
std::wstring commandLine = L"useradd ";
commandLine += userName;
commandLine += L" -g users -G adm,cdrom,plugdev,wheel,power,netdev,floppy,input,lp -m";
HRESULT hr = g_wslApi.WslLaunchInteractive(commandLine.c_str(), true, &exitCode);
if ((FAILED(hr)) || (exitCode != 0)) {
return false;
}

//set password
commandLine = L"passwd ";
commandLine += userName;
HRESULT hr = g_wslApi.WslLaunchInteractive(commandLine.c_str(), true, &exitCode);
if ((FAILED(hr)) || (exitCode != 0)) {
return false;
}

//
commandLine = L"echo \" % wheel ALL = (ALL)ALL\" >> /etc/sudoers";
commandLine += userName;
hr = g_wslApi.WslLaunchInteractive(commandLine.c_str(), true, &exitCode);
if ((FAILED(hr)) || (exitCode != 0)) {

// Delete the user if the group add command failed.
commandLine = L"userdel -r ";
commandLine += userName;
g_wslApi.WslLaunchInteractive(commandLine.c_str(), true, &exitCode);
return false;
}

return true;
}

ULONG DistributionInfo::QueryUid(std::wstring_view userName)
{
// Create a pipe to read the output of the launched process.
HANDLE readPipe;
HANDLE writePipe;
SECURITY_ATTRIBUTES sa{sizeof(sa), nullptr, true};
ULONG uid = UID_INVALID;
if (CreatePipe(&readPipe, &writePipe, &sa, 0)) {
// Query the UID of the supplied username.
std::wstring command = L"/usr/bin/id -u ";
command += userName;
int returnValue = 0;
HANDLE child;
HRESULT hr = g_wslApi.WslLaunch(command.c_str(), true, GetStdHandle(STD_INPUT_HANDLE), writePipe, GetStdHandle(STD_ERROR_HANDLE), &child);
if (SUCCEEDED(hr)) {
// Wait for the child to exit and ensure process exited successfully.
WaitForSingleObject(child, INFINITE);
DWORD exitCode;
if ((GetExitCodeProcess(child, &exitCode) == false) || (exitCode != 0)) {
hr = E_INVALIDARG;
}

CloseHandle(child);
if (SUCCEEDED(hr)) {
char buffer[64];
DWORD bytesRead;

// Read the output of the command from the pipe and convert to a UID.
if (ReadFile(readPipe, buffer, (sizeof(buffer) - 1), &bytesRead, nullptr)) {
buffer[bytesRead] = ANSI_NULL;
try {
uid = std::stoul(buffer, nullptr, 10);

} catch( ... ) { }
}
}
}

CloseHandle(readPipe);
CloseHandle(writePipe);
}

return uid;
}
//
// Copyright (C) Microsoft. All rights reserved.
// Licensed under the terms described in the LICENSE file in the root of this project.
//

#include "stdafx.h"

bool DistributionInfo::CreateUser(std::wstring_view userName)
{
// Create the user account and Add the user account to any relevant groups.
DWORD exitCode;
std::wstring commandLine = L"useradd ";
commandLine += userName;
commandLine += L" -g users -G adm,cdrom,plugdev,wheel,power,netdev,floppy,input,lp -m";
HRESULT hr = g_wslApi.WslLaunchInteractive(commandLine.c_str(), true, &exitCode);
if ((FAILED(hr)) || (exitCode != 0)) {
return false;
}

//set password
commandLine = L"passwd ";
commandLine += userName;
hr = g_wslApi.WslLaunchInteractive(commandLine.c_str(), true, &exitCode);
if ((FAILED(hr)) || (exitCode != 0)) {
return false;
}


if ((FAILED(hr)) || (exitCode != 0)) {

// Delete the user if the group add command failed.
commandLine = L"userdel -r ";
commandLine += userName;
g_wslApi.WslLaunchInteractive(commandLine.c_str(), true, &exitCode);
return false;
}
//set password
commandLine = L"cp /tmp/.bashrc /home/";
commandLine += userName;
commandLine += L"/.profile";
hr = g_wslApi.WslLaunchInteractive(commandLine.c_str(), true, &exitCode);
if ((FAILED(hr)) || (exitCode != 0)) {
return false;
}



return true;
}

ULONG DistributionInfo::QueryUid(std::wstring_view userName)
{
// Create a pipe to read the output of the launched process.
HANDLE readPipe;
HANDLE writePipe;
SECURITY_ATTRIBUTES sa{sizeof(sa), nullptr, true};
ULONG uid = UID_INVALID;
if (CreatePipe(&readPipe, &writePipe, &sa, 0)) {
// Query the UID of the supplied username.
std::wstring command = L"/usr/bin/id -u ";
command += userName;
int returnValue = 0;
HANDLE child;
HRESULT hr = g_wslApi.WslLaunch(command.c_str(), true, GetStdHandle(STD_INPUT_HANDLE), writePipe, GetStdHandle(STD_ERROR_HANDLE), &child);
if (SUCCEEDED(hr)) {
// Wait for the child to exit and ensure process exited successfully.
WaitForSingleObject(child, INFINITE);
DWORD exitCode;
if ((GetExitCodeProcess(child, &exitCode) == false) || (exitCode != 0)) {
hr = E_INVALIDARG;
}

CloseHandle(child);
if (SUCCEEDED(hr)) {
char buffer[64];
DWORD bytesRead;

// Read the output of the command from the pipe and convert to a UID.
if (ReadFile(readPipe, buffer, (sizeof(buffer) - 1), &bytesRead, nullptr)) {
buffer[bytesRead] = ANSI_NULL;
try {
uid = std::stoul(buffer, nullptr, 10);

} catch( ... ) { }
}
}
}

CloseHandle(readPipe);
CloseHandle(writePipe);
}

return uid;
}
50 changes: 25 additions & 25 deletions src/WSLackwareLauncher/DistroLauncher/DistributionInfo.h
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
//
// Copyright (C) Microsoft. All rights reserved.
// Licensed under the terms described in the LICENSE file in the root of this project.
//

#pragma once

namespace DistributionInfo
{
// The name of the distribution. This will be displayed to the user via
// wslconfig.exe and in other places. It must conform to the following
// regular expression: ^[a-zA-Z0-9._-]+$
//
// WARNING: This value must not change between versions of your app,
// otherwise users upgrading from older versions will see launch failures.
const std::wstring Name = L"WSLackware";

// The title bar for the console window while the distribution is installing.
const std::wstring WindowTitle = L"WSLackware";

// Create and configure a user account.
bool CreateUser(std::wstring_view userName);

// Query the UID of the user account.
ULONG QueryUid(std::wstring_view userName);
//
// Copyright (C) Microsoft. All rights reserved.
// Licensed under the terms described in the LICENSE file in the root of this project.
//

#pragma once

namespace DistributionInfo
{
// The name of the distribution. This will be displayed to the user via
// wslconfig.exe and in other places. It must conform to the following
// regular expression: ^[a-zA-Z0-9._-]+$
//
// WARNING: This value must not change between versions of your app,
// otherwise users upgrading from older versions will see launch failures.
const std::wstring Name = L"WSLackware";

// The title bar for the console window while the distribution is installing.
const std::wstring WindowTitle = L"Slackware for Windows";

// Create and configure a user account.
bool CreateUser(std::wstring_view userName);

// Query the UID of the user account.
ULONG QueryUid(std::wstring_view userName);
}
Loading

0 comments on commit df08445

Please sign in to comment.