Deleted Added
full compact
1/* $NetBSD: conf.c,v 1.52 2004-08-09 12:56:47 lukem Exp $ */
1/* $NetBSD: conf.c,v 1.57 2006/02/01 14:20:12 christos Exp $ */
2
3/*-
4 * Copyright (c) 1997-2004 The NetBSD Foundation, Inc.
4 * Copyright (c) 1997-2005 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Simon Burge and Luke Mewburn.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:

--- 20 unchanged lines hidden (view full) ---

33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39#include <sys/cdefs.h>
40#ifndef lint
41__RCSID("$NetBSD: conf.c,v 1.52 2004-08-09 12:56:47 lukem Exp $");
41__RCSID("$NetBSD: conf.c,v 1.57 2006/02/01 14:20:12 christos Exp $");
42#endif /* not lint */
43
44#include <sys/types.h>
45#include <sys/param.h>
46#include <sys/socket.h>
47#include <sys/stat.h>
48
49#include <ctype.h>

--- 22 unchanged lines hidden (view full) ---

72static int filetypematch(char *, int);
73
74
75 /* class defaults */
76#define DEFAULT_LIMIT -1 /* unlimited connections */
77#define DEFAULT_MAXFILESIZE -1 /* unlimited file size */
78#define DEFAULT_MAXTIMEOUT 7200 /* 2 hours */
79#define DEFAULT_TIMEOUT 900 /* 15 minutes */
80#define DEFAULT_UMASK 027 /* 15 minutes */
80#define DEFAULT_UMASK 027 /* rw-r----- */
81
82/*
83 * Initialise curclass to an `empty' state
84 */
85void
86init_curclass(void)
87{
88 struct ftpconv *conv, *cnext;

--- 15 unchanged lines hidden (view full) ---

104 REASSIGN(curclass.display, NULL);
105 REASSIGN(curclass.homedir, NULL);
106 curclass.limit = DEFAULT_LIMIT;
107 REASSIGN(curclass.limitfile, NULL);
108 curclass.maxfilesize = DEFAULT_MAXFILESIZE;
109 curclass.maxrateget = 0;
110 curclass.maxrateput = 0;
111 curclass.maxtimeout = DEFAULT_MAXTIMEOUT;
112 REASSIGN(curclass.motd, xstrdup(_PATH_FTPLOGINMESG));
112 REASSIGN(curclass.motd, ftpd_strdup(_NAME_FTPLOGINMESG));
113 REASSIGN(curclass.notify, NULL);
114 curclass.portmin = 0;
115 curclass.portmax = 0;
116 curclass.rateget = 0;
117 curclass.rateput = 0;
118 curclass.timeout = DEFAULT_TIMEOUT;
119 /* curclass.type is set elsewhere */
120 curclass.umask = DEFAULT_UMASK;
121 curclass.mmapsize = 0;
122 curclass.readsize = 0;
123 curclass.writesize = 0;
124 curclass.sendbufsize = 0;
125 curclass.sendlowat = 0;
126
127 CURCLASS_FLAGS_SET(checkportcmd);
128 CURCLASS_FLAGS_CLR(denyquick);
129 CURCLASS_FLAGS_CLR(hidesymlinks);
130 CURCLASS_FLAGS_SET(modify);
131 CURCLASS_FLAGS_SET(passive);
132 CURCLASS_FLAGS_CLR(private);
133 CURCLASS_FLAGS_CLR(sanenames);
134 CURCLASS_FLAGS_SET(upload);
135}
136
137/*

--- 10 unchanged lines hidden (view full) ---

148 int none, match;
149 char *endp, errbuf[100];
150 char *class, *word, *arg, *template;
151 const char *infile;
152 size_t line;
153 struct ftpconv *conv, *cnext;
154
155 init_curclass();
155 REASSIGN(curclass.classname, xstrdup(findclass));
156 REASSIGN(curclass.classname, ftpd_strdup(findclass));
157 /* set more guest defaults */
158 if (strcasecmp(findclass, "guest") == 0) {
159 CURCLASS_FLAGS_CLR(modify);
160 curclass.umask = 0707;
161 }
162
162 infile = conffilename(_PATH_FTPDCONF);
163 infile = conffilename(_NAME_FTPDCONF);
164 if ((f = fopen(infile, "r")) == NULL)
165 return;
166
167 line = 0;
168 template = NULL;
169 for (;
170 (buf = fparseln(f, &len, &line, NULL, FPARSELN_UNESCCOMM |
171 FPARSELN_UNESCCONT | FPARSELN_UNESCESC)) != NULL;

--- 29 unchanged lines hidden (view full) ---

201 CURCLASS_FLAGS_SET(Field); \
202 } while (0)
203
204#define CONF_STRING(Field) \
205 do { \
206 if (none || EMPTYSTR(arg)) \
207 arg = NULL; \
208 else \
208 arg = xstrdup(arg); \
209 arg = ftpd_strdup(arg); \
210 REASSIGN(curclass.Field, arg); \
211 } while (0)
212
213#define CONF_LL(Field,Arg,Min,Max) \
214 do { \
215 if (none || EMPTYSTR(Arg)) \
216 goto nextline; \
217 llval = strsuftollx(#Field, Arg, Min, Max, \

--- 88 unchanged lines hidden (view full) ---

306 infile, (int)line, word);
307 continue; /* need a suffix */
308 }
309 NEXTWORD(p, types);
310 NEXTWORD(p, disable);
311 convcmd = p;
312 if (convcmd)
313 convcmd += strspn(convcmd, " \t");
313 suffix = xstrdup(arg);
314 suffix = ftpd_strdup(arg);
315 if (none || EMPTYSTR(types) ||
316 EMPTYSTR(disable) || EMPTYSTR(convcmd)) {
317 types = NULL;
318 disable = NULL;
319 convcmd = NULL;
320 } else {
320 types = xstrdup(types);
321 disable = xstrdup(disable);
322 convcmd = xstrdup(convcmd);
321 types = ftpd_strdup(types);
322 disable = ftpd_strdup(disable);
323 convcmd = ftpd_strdup(convcmd);
324 }
325 for (conv = curclass.conversions; conv != NULL;
326 conv = conv->next) {
327 if (strcmp(conv->suffix, suffix) == 0)
328 break;
329 }
330 if (conv == NULL) {
331 conv = (struct ftpconv *)

--- 18 unchanged lines hidden (view full) ---

350 REASSIGN(conv->command, convcmd);
351
352 } else if (strcasecmp(word, "denyquick") == 0) {
353 CONF_FLAG(denyquick);
354
355 } else if (strcasecmp(word, "display") == 0) {
356 CONF_STRING(display);
357
358 } else if (strcasecmp(word, "hidesymlinks") == 0) {
359 CONF_FLAG(hidesymlinks);
360
361 } else if (strcasecmp(word, "homedir") == 0) {
362 CONF_STRING(homedir);
363
364 } else if (strcasecmp(word, "limit") == 0) {
365 curclass.limit = DEFAULT_LIMIT;
366 REASSIGN(curclass.limitfile, NULL);
367 CONF_LL(limit, arg, -1, LLTMAX);
368 REASSIGN(curclass.limitfile,
365 EMPTYSTR(p) ? NULL : xstrdup(p));
369 EMPTYSTR(p) ? NULL : ftpd_strdup(p));
370
371 } else if (strcasecmp(word, "maxfilesize") == 0) {
372 curclass.maxfilesize = DEFAULT_MAXFILESIZE;
373 CONF_LL(maxfilesize, arg, -1, LLTMAX);
374
375 } else if (strcasecmp(word, "maxtimeout") == 0) {
376 curclass.maxtimeout = DEFAULT_MAXTIMEOUT;
377 CONF_LL(maxtimeout, arg,

--- 6 unchanged lines hidden (view full) ---

384 } else if (strcasecmp(word, "readsize") == 0) {
385 curclass.readsize = 0;
386 CONF_LL(readsize, arg, 0, LLTMAX);
387
388 } else if (strcasecmp(word, "writesize") == 0) {
389 curclass.writesize = 0;
390 CONF_LL(writesize, arg, 0, LLTMAX);
391
392 } else if (strcasecmp(word, "recvbufsize") == 0) {
393 curclass.recvbufsize = 0;
394 CONF_LL(recvbufsize, arg, 0, LLTMAX);
395
396 } else if (strcasecmp(word, "sendbufsize") == 0) {
397 curclass.sendbufsize = 0;
398 CONF_LL(sendbufsize, arg, 0, LLTMAX);
399
400 } else if (strcasecmp(word, "sendlowat") == 0) {
401 curclass.sendlowat = 0;
402 CONF_LL(sendlowat, arg, 0, LLTMAX);
403

--- 63 unchanged lines hidden (view full) ---

467
468 } else if (strcasecmp(word, "timeout") == 0) {
469 curclass.timeout = DEFAULT_TIMEOUT;
470 CONF_LL(timeout, arg, 30, curclass.maxtimeout);
471
472 } else if (strcasecmp(word, "template") == 0) {
473 if (none)
474 continue;
467 REASSIGN(template, EMPTYSTR(arg) ? NULL : xstrdup(arg));
475 REASSIGN(template, EMPTYSTR(arg) ? NULL : ftpd_strdup(arg));
476
477 } else if (strcasecmp(word, "umask") == 0) {
478 u_long fumask;
479
480 curclass.umask = DEFAULT_UMASK;
481 if (none || EMPTYSTR(arg))
482 continue;
483 errno = 0;

--- 66 unchanged lines hidden (view full) ---

550 /* Check if this directory has already been visited */
551 if (getcwd(curwd, sizeof(curwd) - 1) == NULL) {
552 syslog(LOG_WARNING, "can't getcwd: %s", strerror(errno));
553 return;
554 }
555 if (sl_find(slist, curwd) != NULL)
556 return;
557
550 cp = xstrdup(curwd);
558 cp = ftpd_strdup(curwd);
559 if (sl_add(slist, cp) == -1)
560 syslog(LOG_WARNING, "can't add `%s' to stringlist", cp);
561
562 /* First check for a display file */
563 (void)display_file(curclass.display, code);
564
565 /* Now see if there are any notify files */
566 if (EMPTYSTR(curclass.notify))

--- 282 unchanged lines hidden (view full) ---

849
850 /* If we got through the list, no conversion */
851 if (cp == NULL)
852 goto cleanup_do_conv;
853
854 /* Split up command into an argv */
855 if ((sl = sl_init()) == NULL)
856 goto cleanup_do_conv;
849 cmd = xstrdup(cp->command);
857 cmd = ftpd_strdup(cp->command);
858 p = cmd;
859 while (p) {
860 NEXTWORD(p, lp);
861 if (strcmp(lp, "%s") == 0)
862 lp = base;
855 if (sl_add(sl, xstrdup(lp)) == -1)
863 if (sl_add(sl, ftpd_strdup(lp)) == -1)
864 goto cleanup_do_conv;
865 }
866
867 if (sl_add(sl, NULL) == -1)
868 goto cleanup_do_conv;
869 argv = sl->sl_str;
870 free(cmd);
871 free(sl);

--- 78 unchanged lines hidden ---