diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2019-06-09 11:12:02 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2019-06-09 11:12:02 +0200 |
commit | 3b8025f1327c86b7252855b60b303e44aca9adbc (patch) | |
tree | f5dc968f9cd59f95650f7b2e246c142fae12076b | |
parent | 48eebc8d5c43c204941abb467d412bd58d845e72 (diff) | |
download | busybox-w32-3b8025f1327c86b7252855b60b303e44aca9adbc.tar.gz busybox-w32-3b8025f1327c86b7252855b60b303e44aca9adbc.tar.bz2 busybox-w32-3b8025f1327c86b7252855b60b303e44aca9adbc.zip |
tftp: optional tftp-hpa compat
function old new delta
tftp_main 276 394 +118
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | libbb/xconnect.c | 1 | ||||
-rw-r--r-- | networking/tftp.c | 45 |
2 files changed, 43 insertions, 3 deletions
diff --git a/libbb/xconnect.c b/libbb/xconnect.c index ea5fe173f..eb2871cb1 100644 --- a/libbb/xconnect.c +++ b/libbb/xconnect.c | |||
@@ -133,6 +133,7 @@ unsigned FAST_FUNC bb_lookup_port(const char *port, const char *protocol, unsign | |||
133 | port_nr = default_port; | 133 | port_nr = default_port; |
134 | if (tserv) | 134 | if (tserv) |
135 | port_nr = ntohs(tserv->s_port); | 135 | port_nr = ntohs(tserv->s_port); |
136 | //FIXME: else: port string was garbage, but we don't report that??? | ||
136 | } | 137 | } |
137 | errno = old_errno; | 138 | errno = old_errno; |
138 | } | 139 | } |
diff --git a/networking/tftp.c b/networking/tftp.c index 5ebd22105..30232ef8e 100644 --- a/networking/tftp.c +++ b/networking/tftp.c | |||
@@ -31,6 +31,11 @@ | |||
31 | //config: default y | 31 | //config: default y |
32 | //config: depends on TFTP | 32 | //config: depends on TFTP |
33 | //config: | 33 | //config: |
34 | //config:config FEATURE_TFTP_HPA_COMPAT | ||
35 | //config: bool "tftp-hpa compat (support -c get/put FILE)" | ||
36 | //config: default y | ||
37 | //config: depends on TFTP | ||
38 | //config: | ||
34 | //config:config TFTPD | 39 | //config:config TFTPD |
35 | //config: bool "tftpd (10 kb)" | 40 | //config: bool "tftpd (10 kb)" |
36 | //config: default y | 41 | //config: default y |
@@ -101,9 +106,10 @@ | |||
101 | //usage: IF_FEATURE_TFTP_BLOCKSIZE( | 106 | //usage: IF_FEATURE_TFTP_BLOCKSIZE( |
102 | //usage: "\n -b SIZE Transfer blocks of SIZE octets" | 107 | //usage: "\n -b SIZE Transfer blocks of SIZE octets" |
103 | //usage: ) | 108 | //usage: ) |
109 | ///////: "\n -m STR Accepted and ignored ('-m binary' compat with tftp-hpa 5.2)" | ||
104 | //usage: | 110 | //usage: |
105 | //usage:#define tftpd_trivial_usage | 111 | //usage:#define tftpd_trivial_usage |
106 | //usage: "[-cr] [-u USER] [DIR]" | 112 | //usage: "[-crl] [-u USER] [DIR]" |
107 | //usage:#define tftpd_full_usage "\n\n" | 113 | //usage:#define tftpd_full_usage "\n\n" |
108 | //usage: "Transfer a file on tftp client's request\n" | 114 | //usage: "Transfer a file on tftp client's request\n" |
109 | //usage: "\n" | 115 | //usage: "\n" |
@@ -759,15 +765,46 @@ int tftp_main(int argc UNUSED_PARAM, char **argv) | |||
759 | 765 | ||
760 | INIT_G(); | 766 | INIT_G(); |
761 | 767 | ||
768 | if (ENABLE_FEATURE_TFTP_HPA_COMPAT) { | ||
769 | /* As of 2019, common tftp client in Linux distros | ||
770 | * is one maintained by H. Peter Anvin: | ||
771 | * I've seen "tftp-hpa 5.2" version. | ||
772 | * Make the following command work: | ||
773 | * "tftp HOST [PORT] -m binary -c get/put FILE" | ||
774 | * by mangling it into "....... -g/-p -r FILE" | ||
775 | * and accepting and ignoring -m STR option. | ||
776 | */ | ||
777 | unsigned i = 1; | ||
778 | while (argv[i]) { | ||
779 | if (strcmp(argv[i], "-c") == 0) { | ||
780 | if (!argv[++i]) | ||
781 | break; | ||
782 | if (strcmp(argv[i], "get") == 0) { | ||
783 | argv[i-1] = (char*)"-g"; | ||
784 | argv[i] = (char*)"-r"; | ||
785 | break; | ||
786 | } | ||
787 | if (strcmp(argv[i], "put") == 0) { | ||
788 | argv[i-1] = (char*)"-p"; | ||
789 | argv[i] = (char*)"-r"; | ||
790 | break; | ||
791 | } | ||
792 | } | ||
793 | i++; | ||
794 | } | ||
795 | } | ||
796 | |||
762 | IF_GETPUT(opt =) getopt32(argv, "^" | 797 | IF_GETPUT(opt =) getopt32(argv, "^" |
763 | IF_FEATURE_TFTP_GET("g") IF_FEATURE_TFTP_PUT("p") | 798 | IF_FEATURE_TFTP_GET("g") IF_FEATURE_TFTP_PUT("p") |
764 | "l:r:" IF_FEATURE_TFTP_BLOCKSIZE("b:") | 799 | "l:r:" IF_FEATURE_TFTP_BLOCKSIZE("b:") |
800 | IF_FEATURE_TFTP_HPA_COMPAT("m:") | ||
765 | "\0" | 801 | "\0" |
766 | /* -p or -g is mandatory, and they are mutually exclusive */ | 802 | /* -p or -g is mandatory, and they are mutually exclusive */ |
767 | IF_FEATURE_TFTP_GET("g:") IF_FEATURE_TFTP_PUT("p:") | 803 | IF_FEATURE_TFTP_GET("g:") IF_FEATURE_TFTP_PUT("p:") |
768 | IF_GETPUT("g--p:p--g:"), | 804 | IF_GETPUT("g--p:p--g:"), |
769 | &local_file, &remote_file | 805 | &local_file, &remote_file |
770 | IF_FEATURE_TFTP_BLOCKSIZE(, &blksize_str) | 806 | IF_FEATURE_TFTP_BLOCKSIZE(, &blksize_str) |
807 | IF_FEATURE_TFTP_HPA_COMPAT(, NULL) | ||
771 | ); | 808 | ); |
772 | argv += optind; | 809 | argv += optind; |
773 | 810 | ||
@@ -851,7 +888,7 @@ int tftpd_main(int argc UNUSED_PARAM, char **argv) | |||
851 | peer_lsa->len = our_lsa->len; | 888 | peer_lsa->len = our_lsa->len; |
852 | 889 | ||
853 | /* Shifting to not collide with TFTP_OPTs */ | 890 | /* Shifting to not collide with TFTP_OPTs */ |
854 | opt = option_mask32 = TFTPD_OPT | (getopt32(argv, "rcu:l", &user_opt) << 8); | 891 | opt = option_mask32 = TFTPD_OPT | (getopt32(argv, "rcu:lm:", &user_opt, NULL) << 8); |
855 | argv += optind; | 892 | argv += optind; |
856 | if (opt & TFTPD_OPT_l) { | 893 | if (opt & TFTPD_OPT_l) { |
857 | openlog(applet_name, LOG_PID, LOG_DAEMON); | 894 | openlog(applet_name, LOG_PID, LOG_DAEMON); |
@@ -897,6 +934,7 @@ int tftpd_main(int argc UNUSED_PARAM, char **argv) | |||
897 | mode = local_file + strlen(local_file) + 1; | 934 | mode = local_file + strlen(local_file) + 1; |
898 | /* RFC 1350 says mode string is case independent */ | 935 | /* RFC 1350 says mode string is case independent */ |
899 | if (mode >= G.block_buf + result || strcasecmp(mode, "octet") != 0) { | 936 | if (mode >= G.block_buf + result || strcasecmp(mode, "octet") != 0) { |
937 | error_msg = "mode is not 'octet'"; | ||
900 | goto err; | 938 | goto err; |
901 | } | 939 | } |
902 | # if ENABLE_FEATURE_TFTP_BLOCKSIZE | 940 | # if ENABLE_FEATURE_TFTP_BLOCKSIZE |
@@ -944,7 +982,8 @@ int tftpd_main(int argc UNUSED_PARAM, char **argv) | |||
944 | /* tftp_protocol() will create new one, bound to particular local IP */ | 982 | /* tftp_protocol() will create new one, bound to particular local IP */ |
945 | result = tftp_protocol( | 983 | result = tftp_protocol( |
946 | our_lsa, peer_lsa, | 984 | our_lsa, peer_lsa, |
947 | local_file IF_TFTP(, NULL /*remote_file*/) | 985 | local_file |
986 | IF_TFTP(, NULL /*remote_file*/) | ||
948 | IF_FEATURE_TFTP_BLOCKSIZE(, want_transfer_size) | 987 | IF_FEATURE_TFTP_BLOCKSIZE(, want_transfer_size) |
949 | IF_FEATURE_TFTP_BLOCKSIZE(, blksize) | 988 | IF_FEATURE_TFTP_BLOCKSIZE(, blksize) |
950 | ); | 989 | ); |