David Harris 03/14/2006 This patch to atftp-0.7: - makes the server readonly - makes the server log to STDERR - fixes an off-by-one error in PCRE code diff -ru3 atftp-0.7.orig/logger.c atftp-0.7/logger.c --- atftp-0.7.orig/logger.c 2004-02-26 21:05:26.000000000 -0500 +++ atftp-0.7/logger.c 2006-03-14 11:34:33.000000000 -0500 @@ -65,6 +65,10 @@ if (log_filename) { + log_fd = dup(2); + log_fp = fdopen(log_fd, "w"); +/* + if ((log_fd = open(log_filename, O_WRONLY | O_APPEND)) < 0) { openlog(log_ident, LOG_PID, LOG_DAEMON); @@ -74,6 +78,7 @@ } else log_fp = fdopen(log_fd, "a"); +*/ } } diff -ru3 atftp-0.7.orig/tftpd.c atftp-0.7/tftpd.c --- atftp-0.7.orig/tftpd.c 2004-02-26 21:05:26.000000000 -0500 +++ atftp-0.7/tftpd.c 2006-03-14 11:36:52.000000000 -0500 @@ -70,6 +70,8 @@ thread id are not tracked. */ char *pidfile = NULL; /* File to write own's pid */ +int tftpd_readonly = 1; + pthread_t main_thread_id; /* Only in atftp-0.7: tftpd.c.orig diff -ru3 atftp-0.7.orig/tftpd_file.c atftp-0.7/tftpd_file.c --- atftp-0.7.orig/tftpd_file.c 2004-02-17 21:21:47.000000000 -0500 +++ atftp-0.7/tftpd_file.c 2006-03-14 11:16:16.000000000 -0500 @@ -55,6 +55,7 @@ extern char directory[MAXLEN]; /* read only except for the main thread */ extern int tftpd_cancel; +extern int tftpd_readonly; #ifdef HAVE_PCRE extern tftpd_pcre_self_t *pcre_top; @@ -131,6 +132,16 @@ logger(LOG_DEBUG, "will do netascii convertion"); } + /* deny if readonly */ + if (tftpd_readonly) + { + tftp_send_error(sockfd, sa, EACCESS, data->data_buffer, data->data_buffer_size); + if (data->trace) + logger(LOG_DEBUG, "sent ERROR ", EACCESS, + tftp_errmsg[EACCESS]); + return ERR; + } + /* file name verification */ Strncpy(filename, data->tftp_options[OPT_FILENAME].value, MAXLEN); diff -ru3 atftp-0.7.orig/tftpd_pcre.c atftp-0.7/tftpd_pcre.c --- atftp-0.7.orig/tftpd_pcre.c 2003-04-24 20:16:19.000000000 -0400 +++ atftp-0.7/tftpd_pcre.c 2006-03-14 11:06:38.000000000 -0500 @@ -213,7 +213,7 @@ /* found string */ if (rc > 0) { - Strncpy(outchp, tmpstr, rc); + Strncpy(outchp, tmpstr, rc+1); outchp += rc; pcre_free_substring(tmpstr); continue;