This repository has been archived by the owner on Jul 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathusmbthread.pas
104 lines (95 loc) · 2.41 KB
/
usmbthread.pas
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
unit USMBThread;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Process;
type
TShowStatusEvent = procedure(Status: String) of Object;
TSMBThread = class(TThread)
private
fStatusText: string;
FOnShowStatus: TShowStatusEvent;
output: boolean;
exe, options: string;
procedure showStatus;
protected
procedure execute; override;
public
constructor create(outputC: boolean; exeC, optionsC: string);
property OnShowStatus: TShowStatusEvent read FOnShowStatus write FOnShowStatus;
end;
implementation
constructor TSMBThread.create(outputC: boolean; exeC, optionsC: string);
begin
output:=outputC;
exe:=exeC;
options:=optionsC;
FreeOnTerminate:=true;
inherited create(true);
end;
procedure TSMBThread.showStatus;
begin
if Assigned(FOnShowStatus) then
begin
FOnShowStatus(fStatusText);
end;
end;
procedure TSMBThread.execute;
var
smbProcess: TProcess;
response: TStringList;
error: string;
begin
smbProcess:=TProcess.create(nil);
if (output) then begin
response:=TStringList.create;
end;
smbProcess.executable:=exe;
{$IFDEF LINUX}
smbProcess.parameters.add('-c');
{$ENDIF}
smbProcess.parameters.add(options);
smbProcess.Options:=smbProcess.Options + [poWaitOnExit, poUsePipes];
if (exe = 'cmd.exe') then begin
smbProcess.ShowWindow:=swoHIDE;
end;
smbProcess.execute;
if (output) then begin
response.LoadFromStream(smbProcess.stderr);
end;
smbProcess.free;
if (output) then begin
error:=response.commaText;
{$IFDEF WINDOWS}
if (pos('86', error) <> 0) then begin //Passwort falsch
fStatusText:='1';
end
else if (pos('85', error) <> 0) then begin //Laufwerksbuchstabe vergeben
fStatusText:='2';
end
else if (pos('53', error) <> 0) then begin //Share nicht gefunden
fStatusText:='3';
end
else if (pos('1219', error) <> 0) then begin //Mehrere Nutzer auf einem
//Server (Windows-Bug?)
fStatusText:='4';
end
else if (error = '') then begin //Alles OK
fStatusText:='0';
end;
{$ENDIF}
{$IFDEF LINUX}
if (pos('13', error) <> 0) then begin //Passwort falsch
fStatusText:='1';
end
else if (pos('6', error) <> 0) then begin //Share nicht gefunden
fStatusText:='3';
end
else if (error = '') then begin //Alles OK
fStatusText:='0';
end;
{$ENDIF}
Synchronize(@ShowStatus);
end;
end;
end.