Commit 0db1137dbf5008d456b9cc80a5cf1222467fed9d
1 parent
1f697db9
Change -tftp option to take a root directory, by Anthony Liguori.
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@2441 c046a42c-6fe2-441c-8c8c-71466251a162
Showing
3 changed files
with
15 additions
and
10 deletions
qemu-doc.texi
@@ -444,13 +444,12 @@ Indicate that no network devices should be configured. It is used to | @@ -444,13 +444,12 @@ Indicate that no network devices should be configured. It is used to | ||
444 | override the default configuration (@option{-net nic -net user}) which | 444 | override the default configuration (@option{-net nic -net user}) which |
445 | is activated if no @option{-net} options are provided. | 445 | is activated if no @option{-net} options are provided. |
446 | 446 | ||
447 | -@item -tftp prefix | 447 | +@item -tftp dir |
448 | When using the user mode network stack, activate a built-in TFTP | 448 | When using the user mode network stack, activate a built-in TFTP |
449 | -server. All filenames beginning with @var{prefix} can be downloaded | ||
450 | -from the host to the guest using a TFTP client. The TFTP client on the | ||
451 | -guest must be configured in binary mode (use the command @code{bin} of | ||
452 | -the Unix TFTP client). The host IP address on the guest is as usual | ||
453 | -10.0.2.2. | 449 | +server. The files in @var{dir} will be exposed as the root of a TFTP server. |
450 | +The TFTP client on the guest must be configured in binary mode (use the command | ||
451 | +@code{bin} of the Unix TFTP client). The host IP address on the guest is as | ||
452 | +usual 10.0.2.2. | ||
454 | 453 | ||
455 | @item -bootp file | 454 | @item -bootp file |
456 | When using the user mode network stack, broadcast @var{file} as the BOOTP | 455 | When using the user mode network stack, broadcast @var{file} as the BOOTP |
slirp/tftp.c
@@ -102,8 +102,15 @@ static int tftp_read_data(struct tftp_session *spt, u_int16_t block_nr, | @@ -102,8 +102,15 @@ static int tftp_read_data(struct tftp_session *spt, u_int16_t block_nr, | ||
102 | { | 102 | { |
103 | int fd; | 103 | int fd; |
104 | int bytes_read = 0; | 104 | int bytes_read = 0; |
105 | + char buffer[1024]; | ||
106 | + int n; | ||
105 | 107 | ||
106 | - fd = open(spt->filename, O_RDONLY | O_BINARY); | 108 | + n = snprintf(buffer, sizeof(buffer), "%s/%s", |
109 | + tftp_prefix, spt->filename); | ||
110 | + if (n >= sizeof(buffer)) | ||
111 | + return -1; | ||
112 | + | ||
113 | + fd = open(buffer, O_RDONLY | O_BINARY); | ||
107 | 114 | ||
108 | if (fd < 0) { | 115 | if (fd < 0) { |
109 | return -1; | 116 | return -1; |
@@ -325,8 +332,7 @@ static void tftp_handle_rrq(struct tftp_t *tp, int pktlen) | @@ -325,8 +332,7 @@ static void tftp_handle_rrq(struct tftp_t *tp, int pktlen) | ||
325 | 332 | ||
326 | /* only allow exported prefixes */ | 333 | /* only allow exported prefixes */ |
327 | 334 | ||
328 | - if (!tftp_prefix | ||
329 | - || (strncmp(spt->filename, tftp_prefix, strlen(tftp_prefix)) != 0)) { | 335 | + if (!tftp_prefix) { |
330 | tftp_send_error(spt, 2, "Access violation", tp); | 336 | tftp_send_error(spt, 2, "Access violation", tp); |
331 | return; | 337 | return; |
332 | } | 338 | } |
vl.c
@@ -6402,7 +6402,7 @@ void help(void) | @@ -6402,7 +6402,7 @@ void help(void) | ||
6402 | " is provided, the default is '-net nic -net user'\n" | 6402 | " is provided, the default is '-net nic -net user'\n" |
6403 | "\n" | 6403 | "\n" |
6404 | #ifdef CONFIG_SLIRP | 6404 | #ifdef CONFIG_SLIRP |
6405 | - "-tftp prefix allow tftp access to files starting with prefix [-net user]\n" | 6405 | + "-tftp dir allow tftp access to files in dir [-net user]\n" |
6406 | "-bootp file advertise file in BOOTP replies\n" | 6406 | "-bootp file advertise file in BOOTP replies\n" |
6407 | #ifndef _WIN32 | 6407 | #ifndef _WIN32 |
6408 | "-smb dir allow SMB access to files in 'dir' [-net user]\n" | 6408 | "-smb dir allow SMB access to files in 'dir' [-net user]\n" |