[PATCH] tftp: introduce CONFIG_FEATURE_TFTP_UMASK

Markus Mayer mmayer at broadcom.com
Tue Apr 30 17:22:13 UTC 2019


We allow the umask being used by TFTP to be configurable. This way it is
easy to make files transferred via TFTP executable by default if that is
desired by the user.

Signed-off-by: Markus Mayer <mmayer at broadcom.com>
---
 networking/tftp.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/networking/tftp.c b/networking/tftp.c
index d20d4ca4bd3c..c13683251a2c 100644
--- a/networking/tftp.c
+++ b/networking/tftp.c
@@ -70,6 +70,17 @@
 //config:	Allow tftp to specify block size, and tftpd to understand
 //config:	"blksize" and "tsize" options.
 //config:
+//config:config FEATURE_TFTP_UMASK
+//config:	hex "UMASK for TFTP client and server to use"
+//config:	default 0x1b6
+//config:	depends on TFTP || TFTPD
+//config:	help
+//config:	Specify the UMASK to be used for new being files transferred
+//config:	via TFTP. Defaults to 0x1b6 (0666). Use 0x1ff (0777) if you
+//config:	want execute permissions on transferred files.
+//config:	(Must be specified in hex, since Kconfig doesn't support octal
+//config:	fields.)
+//config:
 //config:config TFTP_DEBUG
 //config:	bool "Enable debug"
 //config:	default n
@@ -394,7 +405,7 @@ static int tftp_protocol(
 
 	if (!ENABLE_TFTP || our_lsa) { /* tftpd */
 		/* Open file (must be after changing user) */
-		local_fd = open(local_file, open_mode, 0666);
+		local_fd = open(local_file, open_mode, CONFIG_FEATURE_TFTP_UMASK);
 		if (local_fd < 0) {
 			G_error_pkt_reason = ERR_NOFILE;
 			strcpy(G_error_pkt_str, "can't open file");
@@ -421,7 +432,7 @@ static int tftp_protocol(
 		/* Open file (must be after changing user) */
 		local_fd = CMD_GET(option_mask32) ? STDOUT_FILENO : STDIN_FILENO;
 		if (NOT_LONE_DASH(local_file))
-			local_fd = xopen(local_file, open_mode);
+			local_fd = xopen3(local_file, open_mode, CONFIG_FEATURE_TFTP_UMASK);
 /* Removing #if, or using if() statement instead of #if may lead to
  * "warning: null argument where non-null required": */
 #if ENABLE_TFTP
-- 
2.17.1



More information about the busybox mailing list