-
Notifications
You must be signed in to change notification settings - Fork 0
/
check.pas
326 lines (283 loc) · 7.47 KB
/
check.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
UNIT Check;
INTERFACE
Uses
Use32,
Parser,Incl,Logger,Objects,Dos,StrUnit,MCommon,FileIO;
Var
InvalidFile,
InvalidPath:Boolean;
Function CheckFileNamesAndPath:Boolean;
Procedure RemoveDupeSlash(Var S:String);
IMPLEMENTATION
{function DriveValid(Drive: Char): Boolean; near; assembler;
asm
MOV AH,19H
INT 21H
MOV BL,AL
MOV DL,Drive
SUB DL,'A'
MOV AH,0EH
INT 21H
MOV AH,19H
INT 21H
MOV CX,0
CMP AL,DL
JNE @@1
MOV CX,1
MOV DL,BL
MOV AH,0EH
INT 21H
@@1: XCHG AX,CX
end;
function PathValid(Path: PathStr): Boolean;
var
ExpPath: PathStr;
SR: SearchRec;
Dir: DirStr;
Name: NameStr;
Ext: ExtStr;
begin
FSplit(Path,Dir,Name,Ext);
Path:=Dir;
ExpPath := FExpand(Path);
if Length(ExpPath) <= 3 then PathValid := DriveValid(ExpPath[1])
else
begin
if ExpPath[Length(ExpPath)] = '\' then Dec(ExpPath[0]);
FindFirst(ExpPath, Directory, SR);
PathValid := (DosError = 0) and (SR.Attr and Directory <> 0);
end;
end;
function ValidFileName(FileName: PathStr): Boolean;
const
IllegalChars = ';,=+<>|"[] \';
var
Dir: DirStr;
Name: NameStr;
Ext: ExtStr;
function Contains(S1, S2: String): Boolean; near; assembler;
asm
PUSH DS
CLD
LDS SI,S1
LES DI,S2
MOV DX,DI
XOR AH,AH
LODSB
MOV BX,AX
OR BX,BX
JZ @@2
MOV AL,ES:[DI]
XCHG AX,CX
@@1: PUSH CX
MOV DI,DX
LODSB
REPNE SCASB
POP CX
JE @@3
DEC BX
JNZ @@1
@@2: XOR AL,AL
JMP @@4
@@3: MOV AL,1
@@4: POP DS
end;
{Function FileExist(Name:String):Boolean;
Var
SR:SearchRec;
Begin
FileExist:=True;
FindFirst(Name,AnyFile-Directory,Sr);
FileExist:=DosError=0;
End;}
{
begin
ValidFileName := True;
FSplit(FileName, Dir, Name, Ext);
if not ((Dir = '') or PathValid(Dir)) {or (Not FileExist(FExpand(FileName)))} {or Contains(Name, IllegalChars) or
{ Contains(Dir, IllegalChars) then ValidFileName := False;
end;}
{Procedure ForEachFile(Point:Pointer);
Var
PStr:PString absolute Point;
Begin
If InvalidFile Then
Exit;
If Not (ValidFileName(PStr^)) Then
Begin
InvalidFile:=True;
LogWriteLn(GetMakingString(_logInvalidFileName+' '+PStr^));
End;
End;}
Procedure ReportInvalidDir(Path:String);
Begin
LogWriteLn(GetExpandedString(_logInvalidPath+' '+Path));
End;
Procedure ReportInvalidFile(Path:String);
Begin
LogWriteLn(GetExpandedString(_logInvalidFileName+' '+Path));
End;
Procedure RemoveDupeSlash(Var S:String);
Var
SlashPos:Word;
Begin
If S='' Then
Exit;
{$IFDEF LINUX}
SlashPos:=Pos('//',S);
While SlashPos>0 Do
Begin
Delete(S,SlashPos,1);
SlashPos:=Pos('//',S);
End;
SlashPos:=Pos('\',S);
While SlashPos>0 Do
Begin
Delete(S,SlashPos,1);
Insert('/',S,SlashPos);
SlashPos:=Pos('\',S);
End;
{$ELSE}
SlashPos:=Pos('\\',S);
While SlashPos>0 Do
Begin
Delete(S,SlashPos,1);
SlashPos:=Pos('\\',S);
End;
SlashPos:=Pos('/',S);
While SlashPos>0 Do
Begin
Delete(S,SlashPos,1);
Insert('\',S,SlashPos);
SlashPos:=Pos('/',S);
End;
{$ENDIF}
End;
Procedure AddBackSlash(Var S:String);
Begin
{$IFDEF LINUX}
If S[Length(S)]<>'/' Then
S:=S+'/';
{$ELSE}
If S[Length(S)]<>'\' Then
S:=S+'\';
{$ENDIF}
End;
Procedure ForEachFile(Point:Pointer);
Var
PStr:PString;
Begin
If InvalidFile Then
Exit;
PStr:=PString(Point);
PStr^:=StrTrim(PStr^);
RemoveDupeSlash(PStr^);
If Not (IsFileExist(PStr^)) Then
Begin
InvalidFile:=True;
ReportInvalidFile(PStr^);
Exit;
End;
End;
Procedure PreForEachPath(Point:Pointer);
Var
PStr:PString;
Begin
PStr:=PString(Point);
PStr^:=StrTrim(PStr^);
AddBackSlash(PStr^);
End;
Procedure ForEachPath(Point:Pointer);
Var
PStr:PString;
Dir:DirStr;
Name:NameStr;
Ext:ExtStr;
Begin
If InvalidPath Then
Exit;
PStr:=PString(Point);
PStr^:=StrTrim(PStr^);
RemoveDupeSlash(PStr^);
If PStr^[Length(PStr^)]='\' Then
Begin
If Not (IsDirectoryExist(Copy(PStr^,1,Length(PStr^)-1))) Then
Begin
InvalidPath:=True;
ReportInvalidDir(PStr^);
Exit;
End;
Exit;
End;
FSplit(PStr^,Dir,Name,Ext);
If Not (IsDirectoryExist(Copy(Dir,1,Length(Dir)-1))) Then
Begin
InvalidPath:=True;
ReportInvalidDir(Copy(Dir,1,Length(Dir)-1));
Exit;
End;
{ If Not (IsFileExist(Dir+Name+Ext)) Then
Begin
InvalidPath:=True;
ReportInvalidFile(Dir+Name+Ext);
Exit;
End;}
{ InvalidPath:=True;
LogWriteLn(GetExpandedString(_logInvalidPath+' '+PStr^));}
End;
Function CheckFileNamesAndPath:Boolean;
Begin
CheckFileNamesAndPath:=True;
{InvalidFile:=False;}
InvalidPath:=False;
ForEachVar(MasterLogNameTag.Tag,ForEachPath);
{ ForEachVar(MasterLogNameTag.Tag,ForEachFile);}
ForEachVar(StatFileNameTag.Tag,ForEachPath);
{ ForEachVar(StatFileNameTag.Tag,ForEachFile);}
ForEachVar(NetMailPathTag.Tag,PreForEachPath);
ForEachVar(NetMailPathTag.Tag,ForEachPath);
ForEachVar(BusyFlagNameTag.Tag,ForEachPath);
{ ForEachVar(BusyFlagNameTag.Tag,ForEachFile);}
If StrTrim(GetVar(FileAttachPathTag.Tag,_varNONE))<>'' Then
Begin
ForEachVar(FileAttachPathTag.Tag,PreForEachPath);
ForEachVar(FileAttachPathTag.Tag,ForEachPath);
{ ForEachVar(FileAttachPathTag.Tag,ForEachFile);}
End;
If StrTrim(GetVar(ProcessedMessagePathTag.Tag,_varNONE))<>'' Then
Begin
ForEachVar(ProcessedMessagePathTag.Tag,PreForEachPath);
ForEachVar(ProcessedMessagePathTag.Tag,ForEachPath);
End;
{ ForEachVar(ProcessedMessagePathTag.Tag,ForEachPath);}
ForEachVar(_tplAllDone.Tag,ForEachPath);
ForEachVar(_tplAllDone.Tag,ForEachFile);
ForEachVar(_tplNotAllowForPoint.Tag,ForEachPath);
ForEachVar(_tplNotAllowForPoint.Tag,ForEachFile);
ForEachVar(_tplCantChangeAnotherBoss.Tag,ForEachPath);
ForEachVar(_tplCantChangeAnotherBoss.Tag,ForEachFile);
ForEachVar(_tplDoneSegRequest.Tag,ForEachPath);
ForEachVar(_tplDoneSegRequest.Tag,ForEachFile);
ForEachVar(_tplDoneHelpRequest.Tag,ForEachPath);
ForEachVar(_tplDoneHelpRequest.Tag,ForEachFile);
ForEachVar(_tplStatisticRequest.Tag,ForEachPath);
ForEachVar(_tplStatisticRequest.Tag,ForEachFile);
ForEachVar(_tplErrorsInMessage.Tag,ForEachPath);
ForEachVar(_tplErrorsInMessage.Tag,ForEachFile);
ForEachVar(_tplErrorsInPointList.Tag,ForEachPath);
ForEachVar(_tplErrorsInPointList.Tag,ForEachFile);
ForEachVar(_tplBadPassword.Tag,ForEachPath);
ForEachVar(_tplBadPassword.Tag,ForEachFile);
ForEachVar(_tplInBounceList.Tag,ForEachPath);
ForEachVar(_tplInBounceList.Tag,ForEachFile);
ForEachVar(_tplReRoute.Tag,ForEachPath);
ForEachVar(_tplReRoute.Tag,ForEachFile);
ForEachVar(_tplInExcludeList.Tag,ForEachPath);
ForEachVar(_tplInExcludeList.Tag,ForEachFile);
ForEachVar(_tplErrorsInSegment.Tag,ForEachPath);
ForEachVar(_tplErrorsInSegment.Tag,ForEachFile);
If InvalidPath or InvalidFile Then
CheckFileNamesAndPath:=False;
End;
Begin
End.