wok-6.x annotate busybox/stuff/busybox-1.26-ris.u @ rev 19621

dhcp: vlan support
author Pascal Bellard <pascal.bellard@slitaz.org>
date Tue Jan 10 16:46:56 2017 +0100 (2017-01-10)
parents
children
rev   line source
pascal@19610 1 Add support for the Windows Remote Installation Service
pascal@19610 2 --- busybox-1.26/networking/tftp.c
pascal@19610 3 +++ busybox-1.26/networking/tftp.c
pascal@19610 4 @@ -39,6 +39,15 @@
pascal@19610 5 //config:comment "Common options for tftp/tftpd"
pascal@19610 6 //config: depends on TFTP || TFTPD
pascal@19610 7 //config:
pascal@19610 8 +//config:config FEATURE_TFTPD_RIS
pascal@19610 9 +//config: bool "Enable \"RIS\" support"
pascal@19610 10 +//config: default y
pascal@19610 11 +//config: depends on TFTPD
pascal@19610 12 +//config: help
pascal@19610 13 +//config: Add support for the Windows Remote Installation Service. This allows
pascal@19610 14 +//config: a client to get files starting with \ without respecting case.
pascal@19610 15 +//config: Each \ will be replaced by a /.
pascal@19610 16 +//config:
pascal@19610 17 //config:config FEATURE_TFTP_GET
pascal@19610 18 //config: bool "Enable 'tftp get' and/or tftpd upload code"
pascal@19610 19 //config: default y
pascal@19610 20 @@ -745,6 +754,59 @@
pascal@19610 21 #undef remote_file
pascal@19610 22 }
pascal@19610 23
pascal@19610 24 +#if ENABLE_FEATURE_TFTPD_RIS
pascal@19610 25 +#include <dirent.h>
pascal@19610 26 +
pascal@19610 27 +static int lookup_entry(const char *search, char *unixpath);
pascal@19610 28 +static void unixfilename(char *filename);
pascal@19610 29 +
pascal@19610 30 +// lookup search and concat real filename to unixpath
pascal@19610 31 +static int lookup_entry(const char *search, char *unixpath)
pascal@19610 32 +{
pascal@19610 33 + int status = 0;
pascal@19610 34 + DIR *dirp = opendir(unixpath[0] ? unixpath : ".");
pascal@19610 35 +
pascal@19610 36 + if (dirp != NULL) {
pascal@19610 37 + struct dirent *entry;
pascal@19610 38 +
pascal@19610 39 + while ((entry = readdir(dirp))) {
pascal@19610 40 + if (!strcasecmp(entry->d_name, search)) {
pascal@19610 41 + if (unixpath[0]) strcat(unixpath, "/");
pascal@19610 42 + strcat(unixpath, entry->d_name);
pascal@19610 43 + status++;
pascal@19610 44 + break;
pascal@19610 45 + }
pascal@19610 46 + }
pascal@19610 47 + closedir(dirp);
pascal@19610 48 + }
pascal@19610 49 + return status;
pascal@19610 50 +}
pascal@19610 51 +
pascal@19610 52 +// update filename with real file path found
pascal@19610 53 +static void unixfilename(char *filename)
pascal@19610 54 +{
pascal@19610 55 + char unixpath[PATH_MAX];
pascal@19610 56 + char *s = unixpath + 1;
pascal@19610 57 + char *check = filename + 1;
pascal@19610 58 + int len;
pascal@19610 59 +
pascal@19610 60 + for (unixpath[0] = 0; *check; len++, s += len, check += len) {
pascal@19610 61 + char *seek = strchr(check, '\\');
pascal@19610 62 +
pascal@19610 63 + if (!seek) { // basename of filename
pascal@19610 64 + if (lookup_entry(check, unixpath))
pascal@19610 65 + strcpy(filename, unixpath); // found
pascal@19610 66 + break;
pascal@19610 67 + }
pascal@19610 68 + len = seek - check;
pascal@19610 69 + memcpy(s, check, len);
pascal@19610 70 + s[len] = '\0';
pascal@19610 71 + if (!lookup_entry(s, unixpath))
pascal@19610 72 + break; // path mismatch
pascal@19610 73 + }
pascal@19610 74 +}
pascal@19610 75 +#endif
pascal@19610 76 +
pascal@19610 77 #if ENABLE_TFTP
pascal@19610 78
pascal@19610 79 int tftp_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
pascal@19610 80 @@ -893,6 +955,10 @@
pascal@19610 81 G.block_buf_tail[0] = '\0';
pascal@19610 82
pascal@19610 83 local_file = G.block_buf + 2;
pascal@19610 84 +#if ENABLE_FEATURE_TFTPD_RIS
pascal@19610 85 + if (local_file[0] == '\\')
pascal@19610 86 + unixfilename(local_file);
pascal@19610 87 +#endif
pascal@19610 88 if (local_file[0] == '.' || strstr(local_file, "/.")) {
pascal@19610 89 error_msg = "dot in file name";
pascal@19610 90 goto err;