-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPasswd.vb
More file actions
33 lines (30 loc) · 1.12 KB
/
Passwd.vb
File metadata and controls
33 lines (30 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
Imports System.IO
Imports System.Text.RegularExpressions
Module Passwd
Public Structure PasswdUserItem
Public Name As String
Public Uid As Integer
Public Overrides Function ToString() As String
Return Name
End Function
End Structure
Public Async Function LoadPasswd(DistributionName As String) As Task(Of IList(Of PasswdUserItem))
Dim lines = Await File.ReadAllLinesAsync($"\\wsl.localhost\{DistributionName}\etc\passwd")
Dim list As New List(Of PasswdUserItem)
Dim rgLine As New Regex("^(.*?):(.*?):(.*?)(?::(.*?)(?::(.*?)(?::(.*?)(?::(.*))?)?)?)?$")
For Each line In lines
Dim m = rgLine.Match(line)
If m IsNot Nothing Then
Try
Dim uid = CInt(Val(m.Groups(3).Value))
list.Add(New PasswdUserItem() With {
.Name = m.Groups(1).Value,
.Uid = uid
})
Catch
End Try
End If
Next
Return list
End Function
End Module