forked from virtadpt/eBBS
-
Notifications
You must be signed in to change notification settings - Fork 1
/
uldl.c
299 lines (249 loc) · 6.6 KB
/
uldl.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
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
/*
Eagles Bulletin Board System
Copyright (C) 1995, Ray Rocker, [email protected]
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "server.h"
#include <unistd.h>
#define PROTOFILE "etc/protos"
/*
The PROTOFILE lists the available protocols for uploading/downloading.
Format is:
protoname:send-binary:receive-binary
*/
typedef struct _PROTOCOL {
NAME name;
PATH sendbin;
PATH recvbin;
SHORT flags;
} PROTOCOL;
#define PROTO_FLAG_RECV_PIPE 0x001
#define PROTO_FLAG_RECV_FILENAME 0x002
protoent_to_proto(rec, proto)
char *rec;
PROTOCOL *proto;
{
proto->flags = PROTO_FLAG_RECV_FILENAME;
rec = _extract_quoted(rec, proto->name, sizeof(proto->name));
rec = _extract_quoted(rec, proto->sendbin, sizeof proto->sendbin);
if (*rec == '|') {
proto->flags = PROTO_FLAG_RECV_PIPE;
rec++;
}
else if (*rec == '-') {
proto->flags = 0;
rec++;
}
_extract_quoted(rec, proto->recvbin, sizeof(proto->recvbin));
return S_OK;
}
_lookup_protocol(pname, proto)
char *pname;
PROTOCOL *proto;
{
int rc;
memset(proto, 0, sizeof *proto);
rc = _record_find(PROTOFILE, _match_first, pname, protoent_to_proto, proto);
return rc;
}
/*ARGSUSED*/
_fill_protonames(indx, rec, lc)
int indx;
char *rec;
struct listcomplete *lc;
{
PROTOCOL proto;
protoent_to_proto(rec, &proto);
if (!strncasecmp(proto.name, lc->str, strlen(lc->str)))
add_namelist(lc->listp, proto.name, NULL);
return S_OK;
}
local_bbs_protonames(list, complete)
NAMELIST *list;
char *complete;
{
struct listcomplete lc;
create_namelist(list);
lc.listp = list;
lc.str = complete == NULL ? "" : complete;
_record_enumerate(PROTOFILE, 0, _fill_protonames, &lc);
return S_OK;
}
#define ULDLFILE "etc/ftplist"
/*
The ULDLFILE lists the directories available for upload/download.
Format, for now, is:
boardname:directory:description
*/
#define UPLOADBOARD "UPLOAD"
/*
This is a special entry in the ULDLFILE which, if present, specifies
the directory for uploads to go to. Downloading from it is not allowed.
*/
ftpent_to_board(rec, board)
char *rec;
BOARD *board;
{
PATH bdir; /* thrown away in this function */
rec = _extract_quoted(rec, board->name, sizeof(board->name));
rec = _extract_quoted(rec, bdir, sizeof bdir);
rec = _extract_quoted(rec, board->description, sizeof(board->description));
return S_OK;
}
ftpent_to_dir(rec, dir)
char *rec;
char *dir;
{
NAME bname; /* thrown away in this function */
rec = _extract_quoted(rec, bname, sizeof(bname));
rec = _extract_quoted(rec, dir, PATHLEN+1);
return S_OK;
}
_lookup_ftpent(bname, board)
char *bname;
BOARD *board;
{
int rc;
memset(board, 0, sizeof *board);
rc = _record_find(ULDLFILE, _match_first, bname, ftpent_to_board, board);
if (!strcmp(board->name, UPLOADBOARD)) return S_NOSUCHBOARD;
return rc;
}
get_fileboard_directory(bname, dir)
char *bname;
char *dir;
{
int rc;
dir[0] = '\0';
rc = _record_find(ULDLFILE, _match_first, bname, ftpent_to_dir, dir);
return rc;
}
_enum_fileboards(indx, rec, en)
int indx;
char *rec;
struct enumstruct *en;
{
BOARD board;
memset(&board, '\0', sizeof board);
ftpent_to_board(rec, &board);
if (!strcmp(board.name, UPLOADBOARD)) return S_OK;
if (en->fn(indx, &board, en->arg) == ENUM_QUIT) return ENUM_QUIT;
return S_OK;
}
/*ARGSUSED*/
local_bbs_enum_fileboards(chunk, startrec, enumfn, arg)
SHORT chunk;
SHORT startrec;
int (*enumfn)();
void *arg;
{
struct enumstruct en;
en.fn = enumfn;
en.arg = arg;
_record_enumerate(ULDLFILE, startrec, _enum_fileboards, &en);
return S_OK;
}
_fill_fileboardnames(indx, rec, lc)
int indx;
char *rec;
struct listcomplete *lc;
{
BOARD board;
ftpent_to_board(rec, &board);
if (strcmp(board.name, UPLOADBOARD)) {
if (!strncasecmp(board.name, lc->str, strlen(lc->str)))
add_namelist(lc->listp, board.name, NULL);
}
return S_OK;
}
local_bbs_fileboardnames(list, complete)
NAMELIST *list;
char *complete;
{
struct listcomplete lc;
create_namelist(list);
lc.listp = list;
lc.str = complete == NULL ? "" : complete;
_record_enumerate(ULDLFILE, 0, _fill_fileboardnames, &lc);
return S_OK;
}
_is_valid_fname(fname)
char *fname;
{
/* To make sure no one tries to pull hanky panky, like asking to download
/etc/passwd...*/
if (strchr(fname, '/')) return 0;
if (fname[0] == '\0' || fname[0] == '.') return 0;
return 1;
}
local_bbs_upload(path, fname, protoname)
char *path;
char *fname;
char *protoname;
{
int rc;
char *outf = NULL;
PROTOCOL proto;
PATH execbuf;
PATH upldir;
if (get_fileboard_directory(UPLOADBOARD, upldir) != S_OK) {
return S_NOUPLOAD;
}
if (protoname == NULL && path != NULL) {
/* Special case -- just return the filename */
strcpy(path, upldir);
strcat(path, "/");
strcat(path, fname);
return S_OK;
}
if (_lookup_protocol(protoname, &proto) != S_OK)
return S_NOSUCHPROTO;
if (proto.recvbin[0] == '\0')
return S_PROTONOGOOD;
if (!_is_valid_fname(fname)) return S_BADFILENAME;
strcpy(execbuf, proto.recvbin);
if (proto.flags & PROTO_FLAG_RECV_FILENAME) {
strcat(execbuf, " ");
strcat(execbuf, fname);
}
if (proto.flags & PROTO_FLAG_RECV_PIPE) {
outf = fname;
}
bbslog(3, "UPLOAD %s proto %s by %s\n", fname, proto.name, my_userid());
set_real_mode(M_ULDL);
rc = execute(execbuf, upldir, NULL, outf, NULL, NULL, 0);
set_real_mode(M_UNDEFINED);
return (rc == -1 ? S_SYSERR : S_OK);
}
do_download(dir, fname, protoname)
char *dir;
char *fname;
char *protoname;
{
int rc;
PROTOCOL proto;
PATH execbuf;
if (_lookup_protocol(protoname, &proto) != S_OK)
return S_NOSUCHPROTO;
if (proto.sendbin[0] == '\0')
return S_PROTONOGOOD;
if (!_is_valid_fname(fname)) return S_BADFILENAME;
strcpy(execbuf, proto.sendbin);
strcat(execbuf, " ");
strcat(execbuf, fname);
bbslog(3, "DOWNLOAD %s proto %s by %s\n", fname, proto.name, my_userid());
set_real_mode(M_ULDL);
rc = execute(execbuf, dir, NULL, NULL, NULL, NULL, 0);
set_real_mode(M_UNDEFINED);
return (rc == -1 ? S_SYSERR : S_OK);
}