-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsplit.c
283 lines (239 loc) · 4.45 KB
/
split.c
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
/*
* This source file is Copyright 1995 by Evan Scott.
* All rights reserved.
* Permission is granted to distribute this file provided no
* fees beyond distribution costs are levied.
*/
#include "FTPMount.h" /* 03-03-02 rri */
#include "tcp.h"
#include "site.h"
#include "split.h"
boolean collapse(unsigned char* s)
{
unsigned char *t, *u;
t = s;
u = s;
/* . & .. are illegal */
if (u[0] == '.')
{
if (u[1] == 0) return false;
if (u[1] == '/') return false;
if (u[1] == '.')
{
if (u[2] == 0) return false;
if (u[2] == '/') return false;
}
}
while (*u)
{
if (t == s && u[0] == '/')
{
// return false; // used to do this, but people didn't want it to error
u++; /* ignore it */
continue;
}
if (u[0] == '/' && u[1] == '.')
{
if (u[2] == 0) return false;
if (u[2] == '/') return false;
if (u[2] == '.')
{
if (u[3] == 0) return false;
if (u[3] == '/') return false;
}
}
if (u[0] == '/' && u[1] == '/')
{
while (--t > s)
{
if (*t == '/') break;
}
u++;
if (t == s) u++;
}
else
{
*t++ = *u++;
}
}
if (t > s && t[-1] == '/') t[-1] = 0; /* cull the trailing '/' */
*t = 0;
return true;
}
boolean split_data(lock* l, unsigned char* z, split* sd)
{
unsigned char *s, *t;
int len1, len2, len3;
/*
* sigh ... all that work to separate the libs to processes ... just
* given up and used the global DosBase here
*/
struct DevProc* dp;
truth(z != nil);
if (!l && z[0] == 0)
{
sd->port = local_port;
sd->path = nil;
sd->work = nil;
return true;
}
s = (unsigned char *)allocate(z[0] + 1, V_cstr);
if (!s)
{
sd->work = nil;
return false;
}
if (z[0])
memcpy(s, &z[1], z[0]);
s[z[0]] = 0;
sd->work = s;
for (;; s++)
{
if (!*s)
{
z = sd->work;
break;
}
if (*s == ':')
{
s++;
dp = GetDeviceProc(sd->work, nil);
if (!dp)
{
deallocate(sd->work, V_cstr);
sd->work = nil;
return false;
}
l = (lock *)(dp->dvp_Lock << 2);
FreeDeviceProc(dp);
z = s;
break;
}
}
/* have to look at lock to see where we are relative to */
if (!l || (l->port == local_port && l->rfsl == ftphosts_lock))
{
s = z;
goto resolve;
}
verify(l, V_lock);
if (l->port == local_port)
{ /* most handlers might allow this, but there's no point */
show_string("Split Fail B");
deallocate(sd->work, V_cstr);
sd->work = nil;
return false;
}
/* construct a full path name so we can collapse it sensibly */
if (l->fname[0] == 0)
{
len1 = strlen(l->port->mp_Node.ln_Name);
len2 = strlen(z);
s = (unsigned char *)allocate(len1 + len2 + 2, V_cstr);
if (!s)
{
deallocate(sd->work, V_cstr);
sd->work = nil;
return false;
}
strcpy(s, l->port->mp_Node.ln_Name);
if (sd->work[0])
{
s[len1] = '/';
strcpy(&s[len1 + 1], z);
}
else
{
s[len1] = 0;
}
deallocate(sd->work, V_cstr);
sd->work = s;
}
else
{
len1 = strlen(l->port->mp_Node.ln_Name);
len2 = strlen(l->fname);
len3 = strlen(z);
s = (unsigned char *)allocate(len1 + len2 + len3 + 3, V_cstr);
if (!s)
{
deallocate(sd->work, V_cstr);
sd->work = nil;
return false;
}
strcpy(s, l->port->mp_Node.ln_Name);
s[len1] = '/';
strcpy(&s[len1 + 1], l->fname);
if (sd->work[0])
{
s[len1 + len2 + 1] = '/';
strcpy(&s[len1 + len2 + 2], z);
}
else
{
s[len1 + len2 + 1] = 0;
}
deallocate(sd->work, V_cstr);
sd->work = s;
}
resolve:
if (!collapse(s))
{
deallocate(sd->work, V_cstr);
sd->work = nil;
return false;
}
for (t = s; *t; t++)
{
if (*t == '/')
{
*t++ = 0;
sd->port = get_site(s);
if (!sd->port)
{
deallocate(sd->work, V_cstr);
sd->work = nil;
return false;
}
if (t[0])
sd->path = t;
else
sd->path = nil;
return true;
}
}
if (s[0] == 0)
{
deallocate(sd->work, V_cstr);
sd->work = nil;
sd->path = nil;
sd->port = local_port;
return true;
}
/* ok, we don't have a '/' so check for .info or Unnamed or
Disk or Default ... they are "special" */
if (strcasecmp(s, "Disk") == 0 ||
strncasecmp(s, "Unnamed", 7) == 0 ||
strcasecmp(s, ".backdrop") == 0 ||
strcasecmp(s, "Default") == 0 ||
strcasecmp(&s[strlen(s) - 5], ".info") == 0)
{
sd->port = local_port;
sd->path = s;
return true;
}
sd->port = get_site(s);
deallocate(sd->work, V_cstr);
sd->work = nil;
sd->path = nil;
if (!sd->port) return false;
return true;
}
void end_split(split* sd)
{
if (sd->work)
{
deallocate(sd->work, V_cstr);
sd->work = nil;
}
}