aboutsummaryrefslogtreecommitdiff
path: root/networking/tftp.c
diff options
context:
space:
mode:
Diffstat (limited to 'networking/tftp.c')
-rw-r--r--networking/tftp.c46
1 files changed, 43 insertions, 3 deletions
diff --git a/networking/tftp.c b/networking/tftp.c
index 35cf0dbd9..648441016 100644
--- a/networking/tftp.c
+++ b/networking/tftp.c
@@ -18,7 +18,42 @@
18 * 18 *
19 * Licensed under GPLv2 or later, see file LICENSE in this source tree. 19 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
20 */ 20 */
21
22//usage:#define tftp_trivial_usage
23//usage: "[OPTIONS] HOST [PORT]"
24//usage:#define tftp_full_usage "\n\n"
25//usage: "Transfer a file from/to tftp server\n"
26//usage: "\nOptions:"
27//usage: "\n -l FILE Local FILE"
28//usage: "\n -r FILE Remote FILE"
29//usage: IF_FEATURE_TFTP_GET(
30//usage: "\n -g Get file"
31//usage: )
32//usage: IF_FEATURE_TFTP_PUT(
33//usage: "\n -p Put file"
34//usage: )
35//usage: IF_FEATURE_TFTP_BLOCKSIZE(
36//usage: "\n -b SIZE Transfer blocks of SIZE octets"
37//usage: )
38//usage:
39//usage:#define tftpd_trivial_usage
40//usage: "[-cr] [-u USER] [DIR]"
41//usage:#define tftpd_full_usage "\n\n"
42//usage: "Transfer a file on tftp client's request\n"
43//usage: "\n"
44//usage: "tftpd should be used as an inetd service.\n"
45//usage: "tftpd's line for inetd.conf:\n"
46//usage: " 69 dgram udp nowait root tftpd tftpd -l /files/to/serve\n"
47//usage: "It also can be ran from udpsvd:\n"
48//usage: " udpsvd -vE 0.0.0.0 69 tftpd /files/to/serve\n"
49//usage: "\nOptions:"
50//usage: "\n -r Prohibit upload"
51//usage: "\n -c Allow file creation via upload"
52//usage: "\n -u Access files as USER"
53//usage: "\n -l Log to syslog (inetd mode requires this)"
54
21#include "libbb.h" 55#include "libbb.h"
56#include <syslog.h>
22 57
23#if ENABLE_FEATURE_TFTP_GET || ENABLE_FEATURE_TFTP_PUT 58#if ENABLE_FEATURE_TFTP_GET || ENABLE_FEATURE_TFTP_PUT
24 59
@@ -59,6 +94,7 @@ enum {
59 TFTPD_OPT_r = (1 << 8) * ENABLE_TFTPD, 94 TFTPD_OPT_r = (1 << 8) * ENABLE_TFTPD,
60 TFTPD_OPT_c = (1 << 9) * ENABLE_TFTPD, 95 TFTPD_OPT_c = (1 << 9) * ENABLE_TFTPD,
61 TFTPD_OPT_u = (1 << 10) * ENABLE_TFTPD, 96 TFTPD_OPT_u = (1 << 10) * ENABLE_TFTPD,
97 TFTPD_OPT_l = (1 << 11) * ENABLE_TFTPD,
62}; 98};
63 99
64#if ENABLE_FEATURE_TFTP_GET && !ENABLE_FEATURE_TFTP_PUT 100#if ENABLE_FEATURE_TFTP_GET && !ENABLE_FEATURE_TFTP_PUT
@@ -422,6 +458,7 @@ static int tftp_protocol(
422 finished = 1; 458 finished = 1;
423 } 459 }
424 cp += len; 460 cp += len;
461 IF_FEATURE_TFTP_PROGRESS_BAR(G.pos += len;)
425 } 462 }
426 send_pkt: 463 send_pkt:
427 /* Send packet */ 464 /* Send packet */
@@ -443,8 +480,6 @@ static int tftp_protocol(
443 xsendto(socket_fd, xbuf, send_len, &peer_lsa->u.sa, peer_lsa->len); 480 xsendto(socket_fd, xbuf, send_len, &peer_lsa->u.sa, peer_lsa->len);
444 481
445#if ENABLE_FEATURE_TFTP_PROGRESS_BAR 482#if ENABLE_FEATURE_TFTP_PROGRESS_BAR
446 if (ENABLE_TFTP && remote_file) /* tftp */
447 G.pos = (block_nr - 1) * (uoff_t)blksize;
448 if (is_bb_progress_inited(&G.pmt)) 483 if (is_bb_progress_inited(&G.pmt))
449 tftp_progress_update(); 484 tftp_progress_update();
450#endif 485#endif
@@ -588,6 +623,7 @@ static int tftp_protocol(
588 if (sz != blksize) { 623 if (sz != blksize) {
589 finished = 1; 624 finished = 1;
590 } 625 }
626 IF_FEATURE_TFTP_PROGRESS_BAR(G.pos += sz;)
591 continue; /* send ACK */ 627 continue; /* send ACK */
592 } 628 }
593/* Disabled to cope with servers with Sorcerer's Apprentice Syndrome */ 629/* Disabled to cope with servers with Sorcerer's Apprentice Syndrome */
@@ -749,8 +785,12 @@ int tftpd_main(int argc UNUSED_PARAM, char **argv)
749 peer_lsa->len = our_lsa->len; 785 peer_lsa->len = our_lsa->len;
750 786
751 /* Shifting to not collide with TFTP_OPTs */ 787 /* Shifting to not collide with TFTP_OPTs */
752 opt = option_mask32 = TFTPD_OPT | (getopt32(argv, "rcu:", &user_opt) << 8); 788 opt = option_mask32 = TFTPD_OPT | (getopt32(argv, "rcu:l", &user_opt) << 8);
753 argv += optind; 789 argv += optind;
790 if (opt & TFTPD_OPT_l) {
791 openlog(applet_name, LOG_PID, LOG_DAEMON);
792 logmode = LOGMODE_SYSLOG;
793 }
754 if (argv[0]) 794 if (argv[0])
755 xchdir(argv[0]); 795 xchdir(argv[0]);
756 796