conf.c (133936) | conf.c (161764) |
---|---|
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/*- | 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 | 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 */ | 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; | 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); | 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); |
|
129 CURCLASS_FLAGS_SET(modify); 130 CURCLASS_FLAGS_SET(passive); 131 CURCLASS_FLAGS_CLR(private); 132 CURCLASS_FLAGS_CLR(sanenames); 133 CURCLASS_FLAGS_SET(upload); 134} 135 136/* --- 10 unchanged lines hidden (view full) --- 147 int none, match; 148 char *endp, errbuf[100]; 149 char *class, *word, *arg, *template; 150 const char *infile; 151 size_t line; 152 struct ftpconv *conv, *cnext; 153 154 init_curclass(); | 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)); |
156 /* set more guest defaults */ 157 if (strcasecmp(findclass, "guest") == 0) { 158 CURCLASS_FLAGS_CLR(modify); 159 curclass.umask = 0707; 160 } 161 | 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); |
163 if ((f = fopen(infile, "r")) == NULL) 164 return; 165 166 line = 0; 167 template = NULL; 168 for (; 169 (buf = fparseln(f, &len, &line, NULL, FPARSELN_UNESCCOMM | 170 FPARSELN_UNESCCONT | FPARSELN_UNESCESC)) != NULL; --- 29 unchanged lines hidden (view full) --- 200 CURCLASS_FLAGS_SET(Field); \ 201 } while (0) 202 203#define CONF_STRING(Field) \ 204 do { \ 205 if (none || EMPTYSTR(arg)) \ 206 arg = NULL; \ 207 else \ | 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); \ |
209 REASSIGN(curclass.Field, arg); \ 210 } while (0) 211 212#define CONF_LL(Field,Arg,Min,Max) \ 213 do { \ 214 if (none || EMPTYSTR(Arg)) \ 215 goto nextline; \ 216 llval = strsuftollx(#Field, Arg, Min, Max, \ --- 88 unchanged lines hidden (view full) --- 305 infile, (int)line, word); 306 continue; /* need a suffix */ 307 } 308 NEXTWORD(p, types); 309 NEXTWORD(p, disable); 310 convcmd = p; 311 if (convcmd) 312 convcmd += strspn(convcmd, " \t"); | 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); |
314 if (none || EMPTYSTR(types) || 315 EMPTYSTR(disable) || EMPTYSTR(convcmd)) { 316 types = NULL; 317 disable = NULL; 318 convcmd = NULL; 319 } else { | 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); |
323 } 324 for (conv = curclass.conversions; conv != NULL; 325 conv = conv->next) { 326 if (strcmp(conv->suffix, suffix) == 0) 327 break; 328 } 329 if (conv == NULL) { 330 conv = (struct ftpconv *) --- 18 unchanged lines hidden (view full) --- 349 REASSIGN(conv->command, convcmd); 350 351 } else if (strcasecmp(word, "denyquick") == 0) { 352 CONF_FLAG(denyquick); 353 354 } else if (strcasecmp(word, "display") == 0) { 355 CONF_STRING(display); 356 | 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 |
|
357 } else if (strcasecmp(word, "homedir") == 0) { 358 CONF_STRING(homedir); 359 360 } else if (strcasecmp(word, "limit") == 0) { 361 curclass.limit = DEFAULT_LIMIT; 362 REASSIGN(curclass.limitfile, NULL); 363 CONF_LL(limit, arg, -1, LLTMAX); 364 REASSIGN(curclass.limitfile, | 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)); |
366 367 } else if (strcasecmp(word, "maxfilesize") == 0) { 368 curclass.maxfilesize = DEFAULT_MAXFILESIZE; 369 CONF_LL(maxfilesize, arg, -1, LLTMAX); 370 371 } else if (strcasecmp(word, "maxtimeout") == 0) { 372 curclass.maxtimeout = DEFAULT_MAXTIMEOUT; 373 CONF_LL(maxtimeout, arg, --- 6 unchanged lines hidden (view full) --- 380 } else if (strcasecmp(word, "readsize") == 0) { 381 curclass.readsize = 0; 382 CONF_LL(readsize, arg, 0, LLTMAX); 383 384 } else if (strcasecmp(word, "writesize") == 0) { 385 curclass.writesize = 0; 386 CONF_LL(writesize, arg, 0, LLTMAX); 387 | 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 |
|
388 } else if (strcasecmp(word, "sendbufsize") == 0) { 389 curclass.sendbufsize = 0; 390 CONF_LL(sendbufsize, arg, 0, LLTMAX); 391 392 } else if (strcasecmp(word, "sendlowat") == 0) { 393 curclass.sendlowat = 0; 394 CONF_LL(sendlowat, arg, 0, LLTMAX); 395 --- 63 unchanged lines hidden (view full) --- 459 460 } else if (strcasecmp(word, "timeout") == 0) { 461 curclass.timeout = DEFAULT_TIMEOUT; 462 CONF_LL(timeout, arg, 30, curclass.maxtimeout); 463 464 } else if (strcasecmp(word, "template") == 0) { 465 if (none) 466 continue; | 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)); |
468 469 } else if (strcasecmp(word, "umask") == 0) { 470 u_long fumask; 471 472 curclass.umask = DEFAULT_UMASK; 473 if (none || EMPTYSTR(arg)) 474 continue; 475 errno = 0; --- 66 unchanged lines hidden (view full) --- 542 /* Check if this directory has already been visited */ 543 if (getcwd(curwd, sizeof(curwd) - 1) == NULL) { 544 syslog(LOG_WARNING, "can't getcwd: %s", strerror(errno)); 545 return; 546 } 547 if (sl_find(slist, curwd) != NULL) 548 return; 549 | 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); |
551 if (sl_add(slist, cp) == -1) 552 syslog(LOG_WARNING, "can't add `%s' to stringlist", cp); 553 554 /* First check for a display file */ 555 (void)display_file(curclass.display, code); 556 557 /* Now see if there are any notify files */ 558 if (EMPTYSTR(curclass.notify)) --- 282 unchanged lines hidden (view full) --- 841 842 /* If we got through the list, no conversion */ 843 if (cp == NULL) 844 goto cleanup_do_conv; 845 846 /* Split up command into an argv */ 847 if ((sl = sl_init()) == NULL) 848 goto cleanup_do_conv; | 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); |
850 p = cmd; 851 while (p) { 852 NEXTWORD(p, lp); 853 if (strcmp(lp, "%s") == 0) 854 lp = base; | 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) |
856 goto cleanup_do_conv; 857 } 858 859 if (sl_add(sl, NULL) == -1) 860 goto cleanup_do_conv; 861 argv = sl->sl_str; 862 free(cmd); 863 free(sl); --- 78 unchanged lines hidden --- | 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 --- |