Skip to content

Commit

Permalink
[ROBO-3631] Add support for usernames containing spaces or single quo…
Browse files Browse the repository at this point in the history
…tes (#38)

Usernames containing these character would lead to command errors when
being parsed, they have been surrounded by double quotes where possible
or explicit handling has been added.

Co-authored-by: Daniel Stanciu <[email protected]>
  • Loading branch information
daniel-stanciu and daniel-stanciu-uipath authored Mar 14, 2024
1 parent 99ee4ed commit 7253d70
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions UiPath.FreeRdpClient/UiPath.SessionTools/Processes/Commands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ public static async Task EnsureUserIsSetUp(this ProcessRunner processRunner, str

internal static async Task<bool> UserExists(this ProcessRunner processRunner, string userName, CancellationToken ct = default)
{
var report = await processRunner.Run("net", $"user {userName}", ct: ct);
var report = await processRunner.Run("net", $"user \"{userName}\"", ct: ct);
return report.exitCode is 0;
}
internal static Task CreateUser(this ProcessRunner processRunner, string userName, string password, CancellationToken ct = default)
=> processRunner.Run("net", $"user {userName} {password} /add", throwOnNonZero: true, ct: ct);
=> processRunner.Run("net", $"user \"{userName}\" {password} /add", throwOnNonZero: true, ct: ct);

internal static Task SetPassword(this ProcessRunner processRunner, string userName, string password, CancellationToken ct = default)
=> processRunner.Run("net", $"user {userName} {password}", throwOnNonZero: true, ct: ct);
=> processRunner.Run("net", $"user \"{userName}\" {password}", throwOnNonZero: true, ct: ct);

internal static async Task EnsureUserHasPassword(this ProcessRunner processRunner, string userName, string password, CancellationToken ct = default)
{
Expand All @@ -51,15 +51,15 @@ internal static async Task EnsureUserHasPassword(this ProcessRunner processRunne
}
internal static Task ActivateUserAndDisableExpiration(this ProcessRunner processRunner, string userName, CancellationToken ct = default)
=> processRunner
.Run("net", $"user {userName} /active /expires:never", throwOnNonZero: true, ct: ct);
.Run("net", $"user \"{userName}\" /active /expires:never", throwOnNonZero: true, ct: ct);

internal static Task ProhibitPasswordChange(this ProcessRunner processRunner, string userName, CancellationToken ct = default)
=> processRunner
.Run("net", $"user {userName} /passwordchg:no", throwOnNonZero: true, ct: ct);
.Run("net", $"user \"{userName}\" /passwordchg:no", throwOnNonZero: true, ct: ct);

internal static Task DisablePasswordExpiration(this ProcessRunner processRunner, string userName, CancellationToken ct = default)
=> processRunner.Run("wmic", $"useraccount WHERE Name='{userName}' set PasswordExpires=false", throwOnNonZero: true, ct: ct);
=> processRunner.Run("wmic", $"useraccount WHERE Name='{userName.Replace("'","\\'")}' set PasswordExpires=false", throwOnNonZero: true, ct: ct);

internal static Task EnsureUserIsInGroup(this ProcessRunner processRunner, string userName, string groupName, CancellationToken ct = default)
=> processRunner.Run("net", $"localgroup \"{groupName}\" {userName} /add", ct: ct);
=> processRunner.Run("net", $"localgroup \"{groupName}\" \"{userName}\" /add", ct: ct);
}

0 comments on commit 7253d70

Please sign in to comment.