231 Commits

Author SHA1 Message Date
Tim Rühsen
ba6b44f674 Fix heap overflow in HTTP protocol handling (CVE-2017-13090)
* src/retr.c (fd_read_body): Stop processing on negative chunk size

Reported-by: Antti Levomäki, Christian Jalio, Joonas Pihlaja from Forcepoint
Reported-by: Juhani Eronen from Finnish National Cyber Security Centre
2017-10-26 17:29:38 +02:00
Tim Rühsen
d892291fb8 Fix stack overflow in HTTP protocol handling (CVE-2017-13089)
* src/http.c (skip_short_body): Return error on negative chunk size

Reported-by: Antti Levomäki, Christian Jalio, Joonas Pihlaja from Forcepoint
Reported-by: Juhani Eronen from Finnish National Cyber Security Centre
2017-10-26 17:29:38 +02:00
Tim Rühsen
bec4c215a8 Update for release 1.19.2
* NEWS: Add news for 1.19.2
* doc/wget.texi: Fix 1.20 to 1.19.2
2017-10-26 16:31:57 +02:00
YX Hao
27d78d944f Avoid unnecessary UTF-8 encoded fallback (trivial change)
* src/retr.c (retrieve_url): Check for changed URL on redirect
2017-10-25 14:26:36 +02:00
Tim Rühsen
60f033426f Add GNU extensions to .netrc parsing
src/netrc.c (parse_netrc): Add 'port' and 'force' extensions

Reported-by: September 20Tim Landscheidt
2017-09-27 12:42:06 +02:00
Josef Moellers
6f3b995993 Bail out on unexpected 416 server errors
* src/http.c (gethttp): Stop on 416 if file is incomplete
2017-09-18 16:45:49 +02:00
Tim Schlueter
c451eec155 Add gzip Content-Encoding decompression
* src/http.c (struct http_stat): Add remote_encoding field.
(read_response_body): Enable gzip decompression.
(initialize_request): Send gzip Accept-Encoding header.
(gethttp): Decompress files with gzip Content-Encoding.
* src/retr.c: include zlib.h.
(zalloc): New function.
(zfree): New function.
(fd_read_body): Decompress gzip data.
* src/retr.h (fd_read_body enum): Add rb_compressed_gzip flag.
2017-08-04 14:34:53 +02:00
Tim Schlueter
b543dfe783 Add --compression option
* doc/wget.texi: Add --compression documentation.
* src/init.c (cmd_spec_compression): New function.
(commands[]): Add opt.compression.
(defaults): Set default opt.compression value.
* src/main.c (option_data[]): Add struct for --compression.
(print_help, help[]): Add description for --compression.
(main): Add incompatibility checks for --compression.
* src/options.h (struct options): Add compression enum and field.
2017-08-04 14:34:53 +02:00
Tim Schlueter
08ed2a5530 Adjust Extension based on Content-Encoding
* doc/wget.texi (--adjust-extension, adjust_extension): Updated documentation.
* src/http.c (encoding_t): New enum.
(struct http_stat): Add local_encoding field.
(gethttp): --adjust-extension based on Content-Encoding.
2017-08-04 14:34:53 +02:00
Darshit Shah
951d3e4cdd Document gperf as a requirement 2017-07-31 14:56:32 +02:00
Tim Rühsen
3ad3b3e36c * src/url.c (url_scheme): Use ASCII version of strncasecmp 2017-07-28 17:11:26 +02:00
Tim Rühsen
5fb6b6bd68 Fix misuse of strncasecmp
* src/http.c (set_content_type): Use c_strcasecmp instead of strncasecmp

See issue bug #51576
2017-07-28 16:56:27 +02:00
Tim Rühsen
f42229b1fd Fix python test suite for GnuTLS 3.5.12+
* testenv/Test-*.py: Replace 127.0.0.1 by localhost
* testenv/certs/server-template.cfg: Likewise
* testenv/certs/server-cert.pem: Regenerate
* testenv/certs/server-crl.pem: Likewise
* testenv/test/base_test.py: Hardcode 'localhost' as server domain

Reported-by: Ludovic Courtès <ludo@gnu.org>
2017-07-09 11:39:05 +02:00
Tim Rühsen
21154bdc36 Check for 304 response before applying --adjust-extension
* src/http.c (gethttp): Move 304 code before --adjust-extension code

This fixes applying --adjust-extension in combination with 304
HTTP responses. It could lead to .html extensions to arbitrary
files.

Reported-by: anfractuosity
2017-06-13 11:25:20 +02:00
Tim Rühsen
ae293c945a Fix buffer overflow in Public Key Pinning
* src/utils.c (wget_base64_decode): Add param for destination size,
  (wg_pubkey_pem_to_der): Amend call to wget_base64_decode(),
  (wg_pin_peer_pubkey): Likewise and fix code style.
* src/utils.h: Add param to wget_base64_decode()
* src/http-ntlm.c (ntlm_input): Amend call to wget_base64_decode()
* src/http.c (skip_content_type): Likewise

Fixes #51227
2017-06-13 10:23:04 +02:00
Tim Rühsen
407c1f990a * doc/wget.texi: Mention --no-config 2017-06-02 10:13:22 +02:00
Tim Rühsen
86b46a34a5 * testenv/Test-recursive-basic.py: Check crawled files 2017-05-16 11:20:57 +02:00
Tim Rühsen
5d4ada1b7b Fix two Metalink tests if $HOME is changed
* conf/expected_files.py (gen_local_fs_snapshot): Skip processing
  of 'pubring.kbx'
2017-05-16 10:24:52 +02:00
Tomas Hozza
876def8ebe Add command line option to disable use of .netrc
Although internally code uses option for (not) reading .netrc for
credentials, it was not possible to turn this behavior off on command
line. Note that it was possible to turn it off using wgetrc.

Idea for this change came from Bruce Jerrick (bmj001@gmail.com).
Reference: https://bugzilla.redhat.com/show_bug.cgi?id=1425097

Signed-off-by: Tomas Hozza <thozza@redhat.com>
2017-05-15 16:06:50 +02:00
Tomas Hozza
f8c3df1f40 Fixed getting of credentials from .netrc
There seemed to be a copy&paste error in http.c code, which decides
whether to get credentials from .netrc. In ftp.c "user" and "pass"
variables are char*, while in http.c, these are char**. For this reason
they should be dereferenced when determining if password and user login
is set to some value.

Also since both variables are dereferenced on lines above the changed
code, it does not really make sense to check if they are NULL.

This patch is based on fix from Bruce Jerrick <bmj001@gmail.com>.
Fedora bug: https://bugzilla.redhat.com/show_bug.cgi?id=1425097

Signed-off-by: Tomas Hozza <thozza@redhat.com>
2017-05-15 16:06:50 +02:00
Tomas Hozza
17960b57d5 Added tests for HTTP authentication using credentials from .netrc
Getting credentials from .netrc has been broken from time to time, thus
adding a test coverage to prevent regressions.

Also added setting of "HOME" environment variable when executing wget,
to make sure LocalFiles like .netrc, which are created just for the
test, are actually used.

Signed-off-by: Tomas Hozza <thozza@redhat.com>
2017-05-15 16:06:50 +02:00
Tim Rühsen
40c0d30f5c Fix Test-https-badcerts.px
* util/createcerts.sh: Set date of invalid cert to +20 years
* tests/certs/invalid.crt: Re-generated
* tests/certs/invalid.key: Re-generated
2017-05-15 15:46:11 +02:00
Tim Rühsen
e2c702571f * util/createcerts.sh: Fix double equal (syntax-check) 2017-05-14 21:35:34 +02:00
Tim Rühsen
269fb6201d Fix Test-https-badcerts.px to work with GnuTLS
* tests/Test-https-badcerts.px: Remove OpenSSL requirement
* tests/certs/expired.crt: Re-created with valid dates
* tests/certs/expired.key: Likewise
* tests/certs/invalid.crt: Likewise
* tests/certs/invalid.key: Likewise
2017-05-14 11:10:15 +02:00
Vijo Cherian
c08778aeb3 New shell script to create the certs and keys required for TLS tests
* util/createcerts.sh: New file
2017-05-14 11:07:43 +02:00
Tim Rühsen
297c1e2ac3 Fix HTTPS testing for stricter OpenSSL
* testenv/certs/README: Amend cert creation extensions
* testenv/certs/ca-cert.pem: Created without OCSP signing purpose

Having the OCSP signing purpose set made newer versions of OpenSSL
fail due to stricter checking. Test version of OpenSSL was 1.1.0e.
2017-05-11 12:38:19 +02:00
Tim Rühsen
936efc3564 * src/iri.c (idn_encode): Better IDNA 2003 compatibility 2017-05-11 11:56:26 +02:00
Tim Rühsen
11d3de74ca * .gitlab-ci.yml: Also test OpenSSL build 2017-05-10 12:12:42 +02:00
Tim Rühsen
35d5b67cc1 * .gitlab-ci.yml: Remove installation of texlive 2017-05-10 10:41:42 +02:00
Tim Rühsen
da50a1ecc3 Add certs/wotca.pem to avoid temp. file creation
* tests/certs/wotca.pem: New file
* tests/Test-https-weboftrust.px: Remove creation of wotca.pem

This change let Test-https-weboftrust.px survive VPATH builds.
2017-05-10 10:34:42 +02:00
Tim Rühsen
1068ca07d3 * cfg.mk: Exclude ^tests/certs/.* from syntax-check 2017-05-10 10:05:18 +02:00
Tim Rühsen
0666e0f375 * po/POTFILES.in: Remove spider.c (syntax-check) 2017-05-10 10:04:34 +02:00
Tim Rühsen
0d9f8280e0 * tests/Test-https-selfsigned.px: Add newline at EOF (syntax-check) 2017-05-10 10:04:30 +02:00
Vijo Cherian
17f0e16ecc Removed all uses of temp files.
Added needed files to GIT
2017-05-09 16:45:13 -07:00
Vijo Cherian
cc74f8b7e2 Made CRL related files in the repo, instead of trying to generate them 2017-05-09 15:37:28 -07:00
Tim Rühsen
2894a37189 Cleanup on exit in Test-https-*.px
* tests/Test-https-*.px: Cleanup on exit
2017-05-09 16:58:33 +02:00
Tim Rühsen
4669ba5e0c Auto-generate interca.conf and rootca.conf
* configure.ac: Add interca.conf.in and rootca.conf.in to AC_CONFIG_FILES
* tests/certs/interca.conf: Removed
* tests/certs/rootca.conf: Removed
* tests/certs/interca.conf.in: New file
* tests/certs/rootca.conf.in: New file
2017-05-09 16:04:48 +02:00
Tim Rühsen
b5c2d083ea Fix path and VPATH issues of new https/TLS tests
* tests/SSLTest.pm: Use $srcdir in read-only files,
  (_setup_server): Remove unneeded path fixation code
* tests/Test-https-*.px: Use $srcdir for read-only files,
  use $cdir for writable files
* tests/certs/interca.conf: Adjust paths
* tests/certs/rootca.conf: Adjust paths
2017-05-09 15:21:23 +02:00
Tim Rühsen
466afc62b0 Check for test server name resolution in tests
* tests/Test-https-*.px: Skip if test server name resolution fails
2017-05-09 11:16:30 +02:00
Tim Rühsen
f68d001626 * tests/Makefile.am: Enable Test-https-badcerts again 2017-05-09 11:16:30 +02:00
Tim Rühsen
ffe75d0867 Fix WgetFeature.pm to allow multiple required features
* tests/WgetFeature.cfg: Remove file
* tests/WgetFeature.pm: Extend to multiple features, cleanup
2017-05-09 11:16:30 +02:00
Tim Rühsen
9aa894853f * .gitlab-ci.yml: Add wgettestingserver to /etc/hosts 2017-05-09 11:08:32 +02:00
Tim Rühsen
5337b94ce5 * tests/SSLServer.pm: Check for IO::Socket::SSL 2017-05-09 11:08:32 +02:00
Tim Rühsen
a26e6f3527 * tests/Test-https-*: Change server port to <= 32767 2017-05-09 11:08:32 +02:00
Tim Rühsen
b9fb74ddfa Move https test server ports from >32767 to <= 32767
* Test-https-badcerts.px: Change port
* Test-https-crl.px: Likewise
* Test-https-weboftrust.px: Likewise
2017-05-09 11:08:32 +02:00
Tim Rühsen
3132049ae4 * tests/Makefile.am: Add SSLTest.pm and SSLServer.pm to EXTRA_DIST 2017-05-09 11:08:32 +02:00
Tim Rühsen
c0c42da653 * tests//Makefile.am: Disable Test-https-badcerts.px 2017-05-09 11:08:32 +02:00
Tim Rühsen
888cc82c9d Add Gitlab CI (Debian)
* .gitlab-ci.yml: New file
2017-05-09 11:08:32 +02:00
Tim Rühsen
fce1b689e8 * .travis.yml: Use trusty for libidn2-dev 2017-05-06 13:03:28 +02:00
Tim Rühsen
580067d1e6 * tests/certs/test-ca-key.pem: Add newline at EOF 2017-05-04 16:51:49 +02:00
Tim Rühsen
5c4cc011fe Add static HOSTSALIAS file
* tests/certs/wgethosts: New file
* tests/Test-https-*.px: Remove creation of wgethosts file
2017-05-04 16:51:49 +02:00
Vijo Cherian
2a96249469 Added new tests for SSL
* tests/Test-https-badcerts.px : New file
* tests/Test-https-clientcert.px : New file
* tests/Test-https-crl.px : New file
* tests/Test-https-weboftrust.px : New file
* tests/certs/interca.conf : New file
* tests/certs/rootca.conf : New file
* tests/certs/test-ca-key.pem : New file

Added all new SSL / HTTPS tests to make check
Added Test for SSL Web of Trust, accept only if CA chain of trust is intact.
Added a test script for client certificate
Added Test for crlfile option of wget
Added test to make sure that wget doesn't accept expired or invalid certs

Some clean up : 1, Removed cause of warnings from perl & other cosmetic changes
                2, Fix  make -j 4 check such that it passes all tests
2017-05-04 16:51:49 +02:00
Tomas Hozza
0b41c7543a Mention TLSv1_1 and TLSv1_2 as secure-protocol values in help
* src/main.c: The --secure-protocol option accepts also values TLSv1_1
and TLSv1_2, as mentioned in the man page. However the help message
doesn't mention these two values. This patch adds TLSv1_1 and TLSv1_2 as
possible values to the help message.

Signed-off-by: Tomas Hozza <thozza@redhat.com>
2017-05-04 14:51:54 +02:00
Tim Rühsen
c4a2b2e77e * src/http.c (gethttp): Support Wayback Machine's X-Archive-Orig-last-modified 2017-05-03 16:37:11 +02:00
Vijo Cherian
f6376ac0dc Added new tests for SSL
* tests/Test-https-badcerts.px : New file
* tests/Test-https-clientcert.px : New file
* tests/Test-https-crl.px : New file
* tests/Test-https-weboftrust.px : New file
* tests/certs/interca.conf : New file
* tests/certs/rootca.conf : New file
* tests/certs/test-ca-key.pem : New file

Added all new SSL / HTTPS tests to make check
Added Test for SSL Web of Trust, accept only if CA chain of trust is intact.
Added a test script for client certificate
Added Test for crlfile option of wget
Added test to make sure that wget doesn't accept expired or invalid certs

Some clean up : Removed cause of warnings from perl & other cosmetic changes
2017-04-28 12:22:54 +02:00
Vijo Cherian
ac519c041e Added new tests for SSL
* tests/SSLServer.pm: New file
* tests/SSLTest.pm: New file
* tests/Test-https-pfs.px: New file
* tests/Test-https-selfsigned.px: New file
* tests/Test-https-tlsv1.px: New file
* tests/Test-https-tlsv1x.px: New file
* tests/certs/server.crt: New file
* tests/certs/server.key: New file
* tests/certs/test-ca-cert.pem: New file

Added 4 new test scripts all for SSL.
Added base pm for SSL testing.
Added SSL tests for TLSv1, TLSv1_1 and PFS.
Added test for self signed cert : check that it fails without
--no-check-certificate and passes with that flag.
2017-04-19 12:59:27 +02:00
Tim Rühsen
56c78c4b09 * src/utils.c: Remove non-portable __builtin_unreachable() 2017-04-18 13:22:25 +02:00
Tim Rühsen
0ec46cb109 Skip iconv() usage if HAVE_ICONV is not defined
This helps on broken iconv implementations, e.g. Solaris.

Reported-by: Mojca Miklavec
2017-04-18 13:17:19 +02:00
Tim Rühsen
67cb37ce5a Mention 'bash' for executing ./bootstrap
Reported-by: Mojca Miklavec
2017-04-18 10:47:15 +02:00
Tim Rühsen
0004d3ec22 * bootstrap.conf: Make 'sed' options more portable
'sed -i' works differently on FreeBSD.

Reported-by: Mojca Miklavec
2017-04-18 10:44:06 +02:00
Tim Rühsen
92bfe2a2e4 Fix charset transcoding issue for non-reversible codepoints
* src/url.c: Check iconv() against 0, not -1

On some libiconv implementations, unknown codepoints become
encoded as ?, e.g. when converting a non-ascii codepoint to ASCII.
This results in ambigious file names which also fails our tests.
2017-04-16 19:55:14 +02:00
Tim Rühsen
fc2f4233ed * src/iri.c: Fix WIN32 idn2_free, forgotten code 2017-04-16 19:50:10 +02:00
Darshit Shah
b2c38d33e1 * src/init.c: Set flstats correctly when using WGETRC env var 2017-04-14 01:16:49 +02:00
Tim Rühsen
6ef493b19e Fix use of idn2_free()
* src/connect.c (connect_to_ip): Use xfree() instead of idn2_free()
* src/host.c (lookup_host): Use xfree() instead of idn2_free()
* src/iri.h: Do not include idn2.h
* src/url.c (url_free): Use xfree() instead of idn2_free()
* src/url.h (struct url): Remove 'idn_allocated' from struct

Reported-by: Gisle Vanem
2017-04-08 11:05:55 +02:00
Anton Yuzhaninov
7ffe93cabb Fix perl warnings in tests
* tests/FTPServer.pm: Escape '{' in RE to fix warnings
* tests/FTPTest.pm: Likewise
* tests/HTTPServer.pm: Likewise
* tests/HTTPTest.pm: Likewise
* tests/Test-proxied-https-auth-keepalive.px: Likewise
* tests/Test-proxied-https-auth.px: Likewise
Escape '{' in RE to fix warnings:
Unescaped left brace in regex is deprecated, passed through in regex;
marked by <-- HERE in m/{{ <-- HERE port}}/
2017-04-05 20:04:12 +02:00
klemens
f381831d88 Fix typos in comments 2017-04-01 19:38:09 +02:00
Tim Rühsen
02d40a4676 * src/metalink.c (retrieve_from_metalink): Fix len in memset() 2017-03-31 13:15:27 +02:00
Tim Rühsen
e89267fbbc Add gnulib module group-member 2017-03-24 11:36:01 +01:00
Vijo Cherian
400b8eba6c Safeguards against TOCTTOU
* src/utils.h: Add struct file_stat_s declaration,
  change prototypes of file_exists_p(),
  add prototypes for fopen_stat() and open_stat().
* src/utils.c: Extend file_exists_p(),
  new function fopen_stat() and open_stat(),
  add new param for file_exists_p().
* src/init.h: Add param file_stats_t to run_wgetrc().
* src/ftp.c: Amend calls to extended functions.
* src/hsts.c: Likewise.
* src/http.c: Likewise.
* src/init.c: Likewise.
* src/main.c: Likewise.
* src/metalink.c: Likewise.
* src/retr.c: Likewise.
* src/url.c: Likewise.

Added fopen_stat() and open_stat() that checks to makes sure the file didn't
change underneath us.
Return error from file_exists_p().
Added a way to return error from this file without major surgery to the
callers.

Fixes: #20369
2017-03-24 09:39:09 +01:00
Tim Rühsen
90a0a7499c Update gnulib 2017-03-24 09:19:52 +01:00
Christof Horschitz
1d71645c06 * src/warc.c (warc_write_cdx_record): Escape URLs 2017-03-22 15:01:04 +01:00
Mike Frysinger
e249844143 Include libunistring headers only when used
* src/iri.c: Check for libidn2 < 0.14 to include libunistring headers

The unistring functions are used only when an older version of libidn2
is used, so don't include its headers either w/newer libdin2 versions.
2017-03-20 09:39:20 +01:00
Tim Rühsen
84a93f4127 Fix links to www.robotstxt.org
* NEWS: Fix links
* doc/wget.texi: Likewise
* src/res.c: Likewise

Reported-by: Noël Köthe
2017-03-18 19:05:38 +01:00
Tim Rühsen
f31b93424b * tests/WgetTests.pm: Add -d to Wget test options 2017-03-13 21:31:09 +01:00
Tim Rühsen
90b487369a Include <arpa/inet.h> for Windows
Reported-by: Gisle Vanem
2017-03-08 13:00:54 +01:00
Tim Rühsen
57d748117f Fix updating HSTS entries
* src/hsts.c (hsts_store_entry): Always update 'created' field

Fixes: #50490
Reported-by: Deian Stefan, Atyansh Jaiswal, Jonathan Luck
2017-03-08 10:56:12 +01:00
Tim Rühsen
4d729e322f Fix CRLF injection in Wget host part
* src/url.c (url_parse): Reject control characters in host part of URL

Reported-by: Orange Tsai
2017-03-06 10:04:22 +01:00
Benjamin Esham
63c2aea255 * src/warc.c: Use warc_write_header_uri for all WARC-Target-URI fields
The WARC spec requires that all URIs be enclosed in angle brackets. This
was being done in most cases, but not for "WARC-Target-URI" fields in
WARC blocks of type "response", "resource", "revisit", and "metadata".
2017-03-04 12:51:39 +01:00
Tim Rühsen
ac4fed3220 Fix 504 status handling
* src/http.c (gethttp): Move 504 handling to correct place.
  (http_loop): Fix memeory leak.
* testenv/server/http/http_server.py: Add Content-Length header on non-2xx
  status codes with a body

Reported-by: Adam Sampson
2017-02-16 15:53:56 +01:00
YX Hao
cf5df5593d * src/url.c (url_file_name): Do not charset convert local directory
In a non-ASCII environment, the local path may contain non-ASCII
characters. The server responded file name must be converted before
it is concatenated to the local path. Conversion after concatenation
may result in 'iconv' errors.
2017-02-16 12:52:16 +01:00
Tim Rühsen
2215ee8d10 * configure.ac: Remove manually resetting of LIBICONV variable
Fixes: #48193
Reported-by: ilovezfs
Reported-by: Charles
2017-02-15 20:03:58 +01:00
Tim Rühsen
32e26dc199 * bootstrap.conf: Call gperf to create lib/unicase/special-casing-table.h 2017-02-15 14:45:23 +01:00
Tim Rühsen
21ac4ae356 * bootstrap.conf: Fix latest gnulib to work with gperf < 3.1 2017-02-15 13:03:10 +01:00
Darshit Shah
838c185ca9 Pull GNULib to latest.
* gnulib: Pull to latest commit. This fixes an issue with Gperf 3.1
2017-02-14 15:08:50 +01:00
Tim Rühsen
ac9be9b756 * src/main.c: Remove double 'verbose' option
Fixes: #50290
2017-02-12 21:18:23 +01:00
Tim Rühsen
6620c5156f * NEWS: update 2017-02-11 12:03:54 +01:00
Tim Rühsen
aebd49d9d4 isrc/http.c (check_retry_on_http_error): Fix gcc warning 2017-02-11 11:54:21 +01:00
Tom Szilagyi
d6d00006a0 Add support for --retry-on-http-error
* doc/wget.text: Add documentation
* src/http.c: Add function check_retry_on_http_error ()
* src/init.c: Add opt.retry_on_http_error
* src/main.c: Add struct for retry-on-http-error to option_data[]
* src/options.h: Add retry_on_http_error to struct options
2017-02-11 11:50:24 +01:00
Tim Rühsen
05acf5d3f6 Revert "Add support for --retry-on-http-error"
This reverts commit 977276374d.
2017-02-11 11:45:11 +01:00
Tim Rühsen
80c62c238e Change libtool library deps to non-libtool deps
Reported-by: Yousong Zhou
Fixes: #50260
2017-02-10 17:20:42 +01:00
Tom Szilagyi
977276374d Add support for --retry-on-http-error
* doc/wget.texi: Add description for --retry-on-http-error
* src/http.c (gethttp):
Consider given HTTP response codes as non-fatal, transient errors.
Supply a comma-separated list of 3-digit HTTP response codes as
argument. Useful to work around special circumstances where retries
are required, but the server responds with an error code normally not
retried by Wget. Such errors might be 503 (Service Unavailable) and
429 (Too Many Requests). Retries enabled by this option are performed
subject to the normal retry timing and retry count limitations of
Wget.

Using this option is intended to support special use cases only and is
generally not recommended, as it can force retries even in cases where
the server is actually trying to decrease its load. Please use it
wisely and only if you know what you are doing.

Example use and a starting point for manual testing:
  wget --retry-on-http-error=429,503 http://httpbin.org/status/503
2017-02-09 21:17:20 +01:00
Tim Rühsen
785c4b92dd * tests/WgetTests.pm: Add --no-config to wget invocation
Without --no-config, wgetrc commands may disturb the tests.

Reported-by: Dagobert Michelsen
2017-02-09 16:34:27 +01:00
Tim Rühsen
d7c34dc0a8 * tests/WgetTests.pm (_verify_download): Fix failure message
Reported-by: Zhiming Wang
2017-02-06 23:01:08 +01:00
Tim Rühsen
d061e553a1 * src/http.c (initialize_request): Fix regression in .netrc auth
Reported-by: Axel Reinhold
2017-02-06 21:44:18 +01:00
Tim Rühsen
2ddd2b69e4 * src/iri.c (idn_encode): Fix memory leak 2017-02-06 21:39:44 +01:00
Tim Rühsen
990f3d67d3 Remove skipping libunistring with --disable-iri
* configure.ac: Remove checking for IRI=no

On certain systems, gnulib falls back to libunistring
for mbtowc() and wcwidth() (used in src/progress.c).

Reported-by: Zhiming Wang
2017-02-06 11:25:48 +01:00
Tim Rühsen
d680b0b551 * bootstrap.conf: Add gnulib module wcwidth 2017-02-04 19:30:38 +01:00
Tim Rühsen
31ac36e170 Fix include/define clash with gnulib's unlink module
* src/options.h: Rename options.unlink to options.unlink_requested
* src/init.c: Replace options unlink member by unlink_requested
* src/http.c: Likewise
* src/ftp.c: Likewise
2017-02-04 18:02:54 +01:00
Tim Rühsen
51b401f5c4 * bootstrap.conf: Specify unicode modules more exact 2017-02-04 18:01:44 +01:00
Tim Rühsen
f2c4289557 * src/xattr.h: Fix #define fsetxattr for MacOS and FreeBSD
Reported-by: Zhiming Wang
2017-02-04 15:29:44 +01:00
Tim Rühsen
58546e52e2 * contrib/release: New release helper script 2017-02-03 16:16:30 +01:00
Tim Rühsen
820f3fc2b4 * cfg.mk: Fix syntax-check 2017-02-03 16:16:30 +01:00
Tim Rühsen
cc8464206d * doc/announcement_1.19.txt: Add new file 2017-02-03 15:19:05 +01:00
Tim Rühsen
366d82f349 * src/utils.c: Move macro FMT_MAX_LENGTH into scope 2017-02-03 12:35:49 +01:00
Tim Rühsen
f2574e90b7 * src/utils.c: Fix -Wformat= warnings 2017-02-03 12:33:38 +01:00
Tim Rühsen
81b3aaf75c * src/gnutls.c: Fix -Wformat= warnings 2017-02-03 12:31:51 +01:00
Tim Rühsen
17d2f42a3d * src/iri.c: Remove unused macro IDNA_FLAGS 2017-02-03 12:28:37 +01:00
Tim Rühsen
638df40476 * src/iri.c: Remove use of __func__ macros 2017-02-03 12:28:05 +01:00
Tim Rühsen
00bafe72f1 * src/http.c: Fix -Wformat= warnings 2017-02-03 12:24:41 +01:00
Tim Rühsen
e777c01f43 * src/progress.c: Remove unused macro move_to_end 2017-02-03 12:18:14 +01:00
Tim Rühsen
3ba112ea57 * src/html-parse.c: Remove unused macro SKIP_NON_WS 2017-02-03 12:15:24 +01:00
Tim Rühsen
485fcfcc20 * src/hsts.c: Remove unused macro CHECK_EXPLICIT_PORT 2017-02-03 12:09:18 +01:00
Tim Rühsen
a5094731cd * src/hsts.c: Fix -Wformat= warnings 2017-02-03 12:08:08 +01:00
Tim Rühsen
3186eb2976 * src/hash.c: Explicitly convert float to int 2017-02-03 12:03:50 +01:00
Tim Rühsen
9947663af8 * src/ftp-ls.c: Fix -Wformat= warnings 2017-02-03 11:59:33 +01:00
Tim Rühsen
cfae085665 * src/ftp.c (ftp_retrieve_list): Add default to switch 2017-02-03 11:57:02 +01:00
Tim Rühsen
e69808256b * src/css-url.h: Remove redundant declaration 2017-02-03 11:53:28 +01:00
Tim Rühsen
11989ef669 * src/ftp.c: Fix -Wformat= warning 2017-02-03 11:52:08 +01:00
Tim Rühsen
5fceab6cb9 * src/http.c (test_parse_range_header): Fix constants 2017-02-03 10:32:42 +01:00
Dale R. Worley
d6eead1794 Improve documentation of --trust-server-names. 2017-02-02 12:10:43 +01:00
Tim Rühsen
d0e02a54ae * src/url.c (mkalldirs): Add newline to log message 2017-02-02 11:11:50 +01:00
Tim Rühsen
2e70409844 * src/cookies.c (check_domain_match): Add newline to DEBUG lines 2017-02-02 11:11:07 +01:00
Tim Rühsen
4734e8d4d7 * NEWS: update 2017-01-17 15:16:40 +01:00
Tim Rühsen
0fe8a5c40e * README.checkout: Link HTTPS where possible, update flex homepage 2017-01-17 14:25:15 +01:00
Tim Rühsen
1b9374ee59 * README.checkout: Fix libidn to libidn2 2017-01-17 14:07:16 +01:00
Tim Rühsen
6de24fe3c0 * src/iri.c: Use TR46 non-transitional for toASCII conversion 2017-01-13 15:53:03 +01:00
Tim Rühsen
0ab3d92c85 * src/main.c: Fix _Noreturn compiler warnings 2017-01-13 15:50:19 +01:00
Tim Rühsen
4cf8af84e0 * src/utils.c: Fix _Noreturn compiler warning 2017-01-13 15:49:05 +01:00
Tim Rühsen
42b8761cbc * src/init.c (setval_internal): Fix sign compare warning 2017-01-13 15:47:02 +01:00
Tim Rühsen
fd0f759597 Replace home-grown portability code by gnulib modules
* bootstrap.conf: Add intprops, inttypes, limits-h, signal-h,
  stat, sys_types
* src/ftp.c: Replace 'struct_stat' by 'struct stat'
* src/hsts.c: Likewise
* src/http.c: Likewise
* src/main.c: Likewise
* src/netrc.c: Likewise
* src/retr.c: Likewise
* src/url.c: Likewise
* src/utils.c: Likewise
* src/sysdep.h: Remove old portability code

Further portability issues should be addressed by gnulib.
2017-01-13 15:38:15 +01:00
Tim Rühsen
a384f5e2e9 Replace WGET_* m4 macros by gnulib modules
* bootstrap.conf: Add hostent, inet_ntop, nanosleep, utimens
* configure.ac: Remove WGET_STRUCT_UTIMBUF, WGET_FNMATCH,
  WGET_NANOSLEEP, WGET_POSIX_CLOCK, WGET_NSL_SOCKET
* m4/wget.m4: Likewise
* src/Makefile.am: Add $(LIB_NANOSLEEP) $(LIB_POSIX_SPAWN) to LDADD
* tests/Makefile.am: Likewise
* src/host.c (print_address): Use inet_ntop also for IPV4
2017-01-13 12:54:35 +01:00
Tim Rühsen
5ae1f37902 Remove libidn vulnerability work-around
* src/iri.c (_utf8_is_valid): Removed

Since we are using libidn2 for IDNs, we no longer need
this work-around.
2017-01-13 12:03:47 +01:00
Tim Rühsen
0eb4a21b6c * src/iri.c (idn_encode): Use TR46 transitional if available 2017-01-13 11:45:18 +01:00
Tim Rühsen
60dc3c21b2 * gnulibx: Update 2017-01-13 10:59:25 +01:00
Tim Rühsen
1a01a6b2d0 Fix previous commit 2427ca4ac0 2017-01-07 15:59:11 +01:00
vijeth-aradhya
2427ca4ac0 Fix http.c and ftp.c passwd logic error
* src/ftp.c (getftp): Fix password/user selection
* src/http.c (initialize_request): Likewise

Before, netrc password won over interactive
--ask-password but now --ask-password wins
after change of program logic

Fixes Issue #48811
2017-01-06 16:18:40 +01:00
Giuseppe Scrivano
42c2ce71bc * src/main.c (main): Add missing \n in error message 2016-12-31 17:11:01 +01:00
Giuseppe Scrivano
def133f26f Check that fd_set has not fds bigger than FD_SETSIZE
* src/connect.c: check that the fd is not bigger than FD_SETSIZE
  before using FD_SET.  An fd_set cannot hold fds bigger than
  FD_SETSIZE, causing out-of-bounds write to a buffer on the stack.

Reported by: Jann Horn <jannh@google.com>
2016-12-28 12:24:19 +01:00
Nikos Mavrogiannopoulos
b9ed06afd8 Avoid calling the gnutls priority functions multiple times
* src/gnutls.c (ssl_connect_wget): Call gnutls_set_default_priority()
  for --secure-protocol=auto (default).

The patch fixes a behavior that may have unintended side-effects in
certain gnutls versions. Instead use the default priorities when no
options are given.

Signed-off-by: Nikos Mavrogiannopoulos <nmav@gnutls.org>
2016-12-20 14:48:31 +01:00
Tim Rühsen
1bdc20d774 Print debug message when skipping certain recursive downloads
* src/recur.c (retrieve_tree): Print debug message instead silently
  skipping recursive downloads.
2016-12-19 12:19:52 +01:00
Rahul Bedarkar
e4e9d3c1c8 Rename base64_{encode,decode} (trivial patch)
* src/http-ntlm.c: Rename base64_{encode,decode}
* src/http.c: Likewise
* src/utils.c: Likewise
* src/utils.h: Likewise

When statically linking with gnutls, we get definition clash error for
base64_encode which is also defined by gnutls.

To prevent definition clash, rename base64_{encode,decode}

Signed-off-by: Rahul Bedarkar <rahul.bedarkar@imgtec.com>
2016-12-14 15:52:52 +01:00
Tim Rühsen
dcdd618b18 Add support for psl_latest()
* configure.ac: Add check for psl_latest(),
  remove --with-psl-file
* src/cookies.c (check_domain_match): Use psl_latest() if available
2016-12-11 21:04:40 +01:00
Piotr Wajda
3c796b9a85 Respect -o parameter again
* log.c: don't choose log output dynamically when opt.lfilename is set

 Regression introduced by dd5c549f6a
 Reported-by: Dale R. Worley
2016-11-09 13:32:14 +01:00
Tim Rühsen
00ae9b4ee2 Move Wget from IDN2003 (libidn) to IDN2008 (libidn2)
* .travis.yml: Install libidn2-dev instead libidn11-dev.
* bootstrap.conf: Add modules libunistring-optional, unistr/base,
  unicase/tolower.
* configure.ac: Check for libidn2.
* src/Makefile.am: Add $(LTLIBUNISTRING) to LDADD.
* tests/Makefile.am: Set LDADD similar to LDADD in src/Makefile.am
* src/connect.c: Use libidn2 code instead of libidn.
* src/host.c: Likewise.
* src/iri.c: Likewise.
* src/iri.h: Likewise.
* src/options.h: Likewise.
* src/url.c: Likewise.
* src/url.h: Likewise.
* src/log.c: Fix C99 comment.

IDN2003 should not be used any more due to security concerns.
We use libunistring (resp. the unicode code from gnulib) for
lowercasing UTF-8 before we give data to libidn2.
TR#46 is missing, no support in libidn2 nor in libunistring.
2016-11-07 11:03:42 +01:00
Tim Rühsen
2242d5aee4 Use -O0 in contrib scripts
* contrib/check-hard: Use -O0 instead of -O2 to speed up script.
* contrib/travis-ci: Likewise.
2016-11-03 15:47:41 +01:00
Tim Rühsen
77a546348c Update gnulib 2016-11-03 13:28:17 +01:00
Tim Rühsen
be5517f98f * src/metalink.c: Fix typo 'suceeded' -> 'succeeded'
Reported-by: Göran Uddeborg <goeran@uddeborg.se>,
             Anders Jonsson <anders.jonsson@norsjovallen.se>
2016-10-22 22:21:39 +02:00
losgrandes
dd5c549f6a Fixes #45790: wget prints it's progress even when background
* src/log.c: Use tcgetpgrp(STDIN_FILENO) != getpgrp() to determine when to print to STD* or logfile.
  Deprecate log_request_redirect_output function.
  Use different file handles for STD* and logfile, to easily switch between them when changing fg/bg.
* src/log.h: Make redirect_output function externally linked.
* src/main.c: Don't use deprecated log_request_redirect_output function. Use redirect_output instead.
* src/mswindows.c: Don't use deprecated log_request_redirect_output function. Use redirect_output instead.
2016-10-21 19:33:29 +02:00
losgrandes
78e0ec5f03 Fixes #46584: wget --spider always returns zero exit status
* src/ftp.c: Return error as exit value if even one file doesn't exist
2016-10-21 10:24:28 +02:00
Tim Rühsen
807d1c7d94 * src/http.c (gethttp): Accept 206 for request w/o Range header
Fixes: #49319
2016-10-12 14:59:36 +02:00
Tim Rühsen
3d1d5b317b * tests/Makefile.am: Let WGETRC work on *nix and Windows 2016-10-07 13:27:07 +02:00
Tim Rühsen
517d799b6f Properly include iconv.h
* src/iri.c: Check HAVE_ICONV to include iconv.h
* src/url.c: Same
2016-10-07 13:24:15 +02:00
Tim Rühsen
f79bb20f1b * bootstrap.conf: Add pipe-posix for pipe() 2016-10-07 13:23:27 +02:00
Tim Rühsen
e5164a8260 Amend redirection behavior
* src/recur.c (descend_redirect): Ignore WG_RR_LIST and WG_RR_REGEX
  for redirections.
* testenv/Makefile.am: Add Test-recursive-redirect.py
* testenv/Test-recursive-redirect.py: New test

Test-recursive-redirect.py written by Dale R. Worley.

Reported-by: "Dale R. Worley" <worley@ariadne.com>
2016-10-07 11:49:07 +02:00
Matthew White
a35f3dd4f6 New: Metalink/XML v3 python class, update tests to use this class
* testenv/misc/metalinkv3_xml.py: New Metalink/XML v3 python class
* testenv/Test-metalink-xml-abspath-trust.py: Update test to use the
  new Metalink/XML v3 python class
* testenv/Test-metalink-xml-abspath.py: Update test to use the new
  Metalink/XML v3 python class
* testenv/Test-metalink-xml-absprefix-trust.py: Update test to use the
  new Metalink/XML v3 python class
* testenv/Test-metalink-xml-absprefix.py: Update test to use the new
  Metalink/XML v3 python class
* testenv/Test-metalink-xml-continue.py: Update test to use the new
  Metalink/XML v3 python class
* testenv/Test-metalink-xml-emptyprefix-trust.py: Update test to use
  the new Metalink/XML v3 python class
* testenv/Test-metalink-xml-homepath-trust.py: Update test to use the
  new Metalink/XML v3 python class
* testenv/Test-metalink-xml-homepath.py: Update test to use the new
  Metalink/XML v3 python class
* testenv/Test-metalink-xml-homeprefix-trust.py: Update test to use
  the new Metalink/XML v3 python class
* testenv/Test-metalink-xml-homeprefix.py: Update test to use the new
  Metalink/XML v3 python class
* testenv/Test-metalink-xml-nohash.py: Update test to use the new
  Metalink/XML v3 python class
* testenv/Test-metalink-xml-nourls.py: Update test to use the new
  Metalink/XML v3 python class
* testenv/Test-metalink-xml-prefix-trust.py: Update test to use the
  new Metalink/XML v3 python class
* testenv/Test-metalink-xml-prefix.py: Update test to use the new
  Metalink/XML v3 python class
* testenv/Test-metalink-xml-relpath-trust.py: Update test to use the
  new Metalink/XML v3 python class
* testenv/Test-metalink-xml-relpath.py: Update test to use the new
  Metalink/XML v3 python class
* testenv/Test-metalink-xml-relprefix-trust.py: Update test to use the
  new Metalink/XML v3 python class
* testenv/Test-metalink-xml-relprefix.py: Update test to use the new
  Metalink/XML v3 python class
* testenv/Test-metalink-xml-size.py: Update test to use the new
  Metalink/XML v3 python class
* testenv/Test-metalink-xml-trust.py: Update test to use the new
  Metalink/XML v3 python class
* testenv/Test-metalink-xml.py: Update test to use the new
  Metalink/XML v3 python class
2016-09-30 19:44:06 +02:00
Matthew White
c403e67935 New: --metalink-over-http Content-Type/Disposition Metalink/XML processing
* src/http.c (metalink_from_http): Process the Content-Type header.
  Add an application/metalink4+xml URL as metalink metaurl.  If the
  option opt.content_disposition is true, the Content-Disposition's
  filename is the metaurl's name
* doc/wget.texi: Update --content-disposition and --metalink-over-http
* doc/metalink-standard.txt: Update doc. Content-Type/Disposition
  processing through --metalink-over-http. Update download naming
  system about --trust-server-names and --content-disposition
* testenv/Makefile.am: Add new files
* testenv/Test-metalink-http-xml-type.py: New file. Metalink/HTTP
  Content-Type/Disposition header automated Metalink/XML tests
* testenv/Test-metalink-http-xml-type-trust.py: New file. Metalink/HTTP
  Content-Type/Disposition header with --trust-server-names automated
  Metalink/XML tests
* testenv/Test-metalink-http-xml-type-content.py: New file. Metalink/HTTP
  Content-Type/Disposition header with --content-disposition automated
  Metalink/XML tests
* testenv/Test-metalink-http-xml-type-trust-content.py: New file.
  Metalink/HTTP Content-Type/Disposition header with --trust-server-names
  and --content-disposition automated Metalink/XML tests

Process the Content-Type header, identify an application/metalink4+xml
file.  The Content-Disposition could provide an alternate name through
the "filename" field for the metalink xml file.  Respectively, the cli
options --metalink-over-http and --content-disposition are required.

When Metalink/XML auto-processing, to use the Content-Disposition's
filename, the cli option --trust-server-names is also required.
2016-09-30 19:44:06 +02:00
Matthew White
3021466817 Bugfix: Set NULL variable due to --content-disposition to Metalink origin
* src/http.c (http_loop): Prevent SIGSEGV when hstat.local_file is
  NULL, opt.content_disposition has a role in leaving the value unset
* src/http.c (gethttp): If hs->local_file is NULL (aka http_loop()'s
  hstat.local_file), set it to the value of hs->metalink->origin
2016-09-30 19:44:06 +02:00
Matthew White
c89767d8d1 New: --trust-server-names saves Metalink/HTTP xml files using the "name" field
* src/metalink.c (retrieve_from_metalink): If opt.trustservernames is
  true, use the basename of the metaurl's name to save the xml file
* doc/metalink-standard.txt: Update doc. With --trust-server-names any
  Metalink/HTTP Link application/metalink4+xml file is saved using the
  basename of the "name" field, if any. Update Metalink/HTTP examples
* testenv/Makefile.am: Add new file
* testenv/Test-metalink-http-xml-trust-name.py: New file. Metalink/HTTP
  automated Metalink/XML, save xml files using the "name" field tests
2016-09-30 19:44:06 +02:00
Matthew White
f030cdf8e2 Bugfix: Detect when a metalink:file doesn't have any hash
* src/metalink.c (retrieve_from_metalink): Reject any metalink:file
  without hashes. Prompt the error and switch to the next file
* testenv/Makefile.am: Add new file
* testenv/Test-metalink-xml-nohash.py: New file. Metalink/XML with no
  hashes tests

Prevent SIGSEGV.
2016-09-30 19:44:06 +02:00
Matthew White
5dccb2a9ce Bugfix: Detect malformed base64 Metalink/HTTP Digest header
* src/http.c (metalink_from_http): Fix hash_bin_len type. Use ssize_t
  instead than size_t. Reject -1 as base64_decode() return value
* testenv/Makefile.am: Add new file
* testenv/Test-metalink-http-baddigest.py: New file. Metalink/HTTP
  malformed base64 Digest header tests

On malformed base64 input, ssize_t base64_decode() returns -1. Such
value is too big for a size_t variable, and used as xmalloc() value
will exaust all the memory.
2016-09-30 19:44:06 +02:00
Matthew White
0538e791fb New option --metalink-index to process Metalink application/metalink4+xml
* NEWS: Mention the effect of --metalink-index over Metalink
* src/init.c: Add new option metalinkindex (opt.metalink_index),
  initialize to -1
* src/main.c: Add new option metalink-index (--metalink-index=NUMBER)
* src/options.h: Add new option metalink_index (int)
* src/metalink.h: Add declaration of functions fetch_metalink_file(),
  replace_metalink_basename()
* src/metalink.c: Add functions fetch_metalink_file() simple file
  fetch, replace_metalink_basename() replace file basename
* src/metalink.c (retrieve_from_metalink): New. Process Metalink
  application/metalink4+xml of opt.metalink_index ordinal number
* doc/wget.texi: Add new option metalink-index (--metalink-index)
  documentation
* doc/metalink-standard.txt: Updated doc. Add documentation about
  Metalink application/metalink4+xml metaurls download naming system
* doc/metalink-standard.txt: Update Metalink/XML and HTTP examples
* testenv/Makefile.am: Add new files
* testenv/Test-metalink-http-xml.py: New file. Metalink/HTTP automated
  Metalink/XML "application/metalink4+xml" --metalink-index tests
* testenv/Test-metalink-http-xml-trust.py: New file. Metalink/HTTP
  automated Metalink/XML "application/metalink4+xml" --metalink-index
  retrieval with --trust-server-names tests

WARNING: Do not use lib/dirname.c (dir_name) to get the directory
name, it may append a dot '.' character to the directory name.
2016-09-30 19:44:06 +02:00
Matthew White
acb1d1a668 Bugfix: Prevent sorting when there are less than two elements
* src/utils.c (stable_sort): Add condition nmemb > 1, sort only when
  there is more than one element

Prevent SIGSEGV.
2016-09-30 19:44:06 +02:00
Matthew White
628fb565c7 New: Parse Metalink/HTTP header for application/metalink4+xml
* src/http.c (metalink_from_http): Parse Metalink/HTTP header for
  metaurls application/metalink4+xml media types
* src/metalink.h: Add function declaration metalink_meta_cmp()
* src/metalink.c: Add function metalink_meta_cmp() compare metalink
  metaurls priorities

Add Metalink/HTTP application/metalink4+xml media types as metaurls to
the metalink variable that will be used to download the files.
2016-09-30 19:44:05 +02:00
Matthew White
64ab90ee66 New test: Metalink shall not concatenate '/' to an empty directory prefix
* testenv/Makefile.am: Add new file
* testenv/Test-metalink-xml-emptyprefix-trust.py: New file.
  Metalink/XML empty directory prefix (--directory-prefix '') tests

Detect a '/' character wrongfully concatenated to an empty directory
prefix '' (not NULL), resulting in an absolute path as '/dir/file',
instead than 'dir/file'.
2016-09-30 19:44:05 +02:00
Matthew White
9532861aef Bugfix: Remove surrounding quotes from Metalink/HTTP key's value
* src/metalink.h: Add declaration of function dequote_metalink_string()
* src/metalink.c: Add function dequote_metalink_string() remove
  surrounding quotes from string, \' or \"
* src/metalink.c (find_key_value, find_key_values): Call dequote_metalink_string()
  to remove the surrounding quotes from the parsed value
* src/metalink.c (test_find_key_value, test_find_key_values): Add
  quoted key's values for unit-tests
* testenv/Makefile.am: Add new file
* testenv/Test-metalink-http-quoted.py: New file. Metalink/HTTP quoted
  values tests

Some Metalink/HTTP keys, like "type" [2], may have a quoted value [1]:
Link: <http://example.com/example.ext.meta4>; rel=describedby;
type="application/metalink4+xml"

Wget was expecting a dequoted value from the Metalink module. This
patch addresses this problem.

References:
 [1] Metalink/HTTP: Mirrors and Hashes
     1.1. Example Metalink Server Response
     https://tools.ietf.org/html/rfc6249#section-1.1

 [2] Additional Link Relations
     6. "type"
     https://tools.ietf.org/html/rfc6903#section-6
2016-09-30 19:44:05 +02:00
Matthew White
8aca8fc80d Bugfix: Process Metalink/XML url strings containing white spaces and CRLF
* src/metalink.h: Add declaration of function clean_metalink_string()
* src/metalink.c: Add directive #include "xmemdup0.h"
* src/metalink.c: Add function clean_metalink_string() remove leading
  and trailing white spaces and CRLF from string
* src/metalink.c (retrieve_from_metalink): Remove leading and trailing
  white spaces and CRLF from url resource mres->url
* testenv/Makefile.am: Add new file
* testenv/Test-metalink-xml-urlbreak.py: New test. Metalink/XML white
  spaces and CRLF in url resources tests

White spaces and CRLF are not automatically removed by libmetalink
from url strings. The Wget's Metalink module was unable to process
such url strings. This patch implements the processing of such url
strings cleaning off leading and trailing white spaces and CRLF.

If a parsed Metalink/XML url string contains strings separated by
CRLF, only the first of the series is accepted.
2016-09-30 19:44:05 +02:00
Matthew White
ba82a47173 New test: Detect when there are no good Metalink url resources
* testenv/Makefile.am: Add new file
* testenv/Test-metalink-xml-nourls.py: New file. Metalink/XML unknown
  urls tests

Test if when there are no good Metalink url resources there is any
segmentation fault.
2016-09-30 19:44:05 +02:00
Matthew White
70360b3eab New: Metalink file size mismatch returns error code METALINK_SIZE_ERROR
* src/wget.h (uerr_t): Add error code METALINK_SIZE_ERROR to enum
* src/metalink.c (retrieve_from_metalink): Use boolean variable
  size_ok, when false set retr_err to METALINK_SIZE_ERROR
* testenv/Makefile.am: Add new file
* testenv/Test-metalink-xml-size.py: New file. Metalink/XML file size
  tests (<size></size>)

Before this patch, no appropriate error code was returned to inform a
file size mismatch.

This patch introduces the error code METALINK_SIZE_ERROR to inform a
file size mismatch.
2016-09-30 19:44:05 +02:00
Matthew White
c29983a044 New: Metalink/XML and Metalink/HTTP file naming safety rules
* NEWS: Mention the effect of --trust-server-names over Metalink
* src/metalink.h: Add declaration of function append_suffix_number()
* src/metalink.c: Add function append_suffix_number() append number to
  string
* src/metalink.c (retrieve_from_metalink): Safer Metalink/XML and
  Metalink/HTTP download naming system, opt.trustservernames based
* doc/metalink-standard.txt: Update doc. Explain new Metalink/XML and
  Metalin/HTTP download naming system and --trust-server-names role
* testenv/Makefile.am: Add new files
* testenv/Test-metalink-xml-continue.py: Update test. Metalink/XML
  continue/keep existing files (HTTP 416) with --continue tests
* testenv/Test-metalink-xml.py: Update test. Metalink/XML naming tests
* testenv/Test-metalink-xml-trust.py: New file. Metalink/XML naming
  tests with --trust-server-names
* testenv/Test-metalink-xml-abspath.py: Update test. Metalink/XML
  absolute path tests
* testenv/Test-metalink-xml-abspath-trust.py: New file. Metalink/XML
  absolute path tests with --trust-server-names
* testenv/Test-metalink-xml-relpath.py: Update test. Metalink/XML
  relative path tests
* testenv/Test-metalink-xml-relpath-trust.py: New file. Metalink/XML
  relative path tests with --trust-server-names
* testenv/Test-metalink-xml-homepath.py: Update test. Metalink/XML
  home path and ~ (tilde) tests
* testenv/Test-metalink-xml-homepath-trust.py: New file. Metalink/XML
  home path and ~ (tilde) tests with --trust-server-names
* testenv/Test-metalink-xml-prefix.py: New file. Metalink/XML naming
  tests with --directory-prefix
* testenv/Test-metalink-xml-prefix-trust.py: New file. Metalink/XML
  naming tests with --directory-prefix and --trust-server-names
* testenv/Test-metalink-xml-absprefix.py: New file. Metalink/XML
  absolute --directory-prefix tests
* testenv/Test-metalink-xml-absprefix-trust.py: New file. Metalink/XML
  absolute --directory-prefix tests with --trust-server-names
* testenv/Test-metalink-xml-relprefix.py: New file. Metalink/XML
  relative --directory-prefix tests
* testenv/Test-metalink-xml-relprefix-trust.py: New file. Metalink/XML
  relative --directory-prefix tests with --trust-server-names
* testenv/Test-metalink-xml-homeprefix.py: New file. Metalink/XML home
  --directory-prefix tests
* testenv/Test-metalink-xml-homeprefix-trust.py: New file. Metalink/XML
  home --directory-prefix tests with --trust-server-names

The option --trust-server-names allows to use the file names parsed
from a Metalink/XML file.  Without --trust-server-names, the safety
mechanism provides secure and predictable file names.
2016-09-30 19:44:05 +02:00
Matthew White
5f3ed5eec8 New document: Metalink/XML and Metalink/HTTP standard reference
* doc/metalink-standard.txt: New doc. Implemented and recommended
  Metalink/XML and Metalink/HTTP standard features
2016-09-30 19:44:05 +02:00
Matthew White
43ec7008f2 Enforce Metalink file name verification, strip directory if necessary
* NEWS: Mention the use of a safe Metalink destination path
* src/metalink.h: Add declaration of functions get_metalink_basename(),
  last_component(), metalink_check_safe_path()
* src/metalink.c: Add directive #include "dosname.h"
* src/metalink.c: Add function get_metalink_basename() to return the
  basename of a file name, strip w32's drive letter prefixes
* src/metalink.c (retrieve_from_metalink): Enforce Metalink file name
  verification, if the file name is unsafe try its basename
* doc/metalink.txt: Update document. Explain --directory-prefix

The function get_metalink_basename() uses FILE_SYSTEM_PREFIX_LEN to
catch any 'C:D:file' (w32 environment), then it removes each drive
letter prefix, i.e. 'C:' and 'D:'.

Unsafe file names contain an absolute, relative, or home path.  Safe
paths can be verified by libmetalink's metalink_check_safe_path().
2016-09-30 19:44:03 +02:00
Matthew White
7d4942864b Implement Metalink/XML --directory-prefix option in Metalink module
* NEWS: Mention the effect of --directory-prefix over Metalink
* src/metalink.c (retrieve_from_metalink): Add opt.dir_prefix as
  prefix to the metalink:file name mfile->name
* doc/metalink.txt: Update document. Explain --directory-prefix

When --directory-prefix=<prefix> is used, set the top of the retrieval
tree to prefix. The default is . (the current directory). Metalink/XML
and Metalink/HTTP files will be downloaded under prefix.
2016-09-27 20:29:03 +02:00
Matthew White
666b7862bf Change mfile->name to filename in Metalink module's messages
* src/metalink.c (retrieve_from_metalink): Change mfile->name to
  filename when referring to the downloaded file

The file name could have been changed by unique_create() (or by any
other mean) before downloading. Use the name of the downloaded file
(filename) when printing output which refer to it.
2016-09-27 20:29:03 +02:00
Matthew White
f3f349a0cf Add file size computation in Metalink module
* NEWS: Mention Metalink's file size verification
* src/metalink.c (retrieve_from_metalink): Add file size computation
* doc/metalink.txt: Update document. Remove resolved bugs

Reject downloaded files when they do not agree with their Metalink/XML
metalink:size: https://tools.ietf.org/html/rfc5854#section-4.2.14

At the moment of writing, Metalink/HTTP headers do not provide a file
size field. This information could be obtained from the Content-Length
header field: https://tools.ietf.org/html/rfc6249#section-7
2016-09-27 20:29:03 +02:00
Matthew White
6b1860da37 Update Metalink/XML tests and add a new test for home paths
* testenv/Test-metalink-xml-relpath.py: Update test
* testenv/Test-metalink-xml-homepath.py: New file. Reject home paths
* testenv/Makefile.am: Add new file

When --input-metalink=<file> is used, each metalink:file name is
verified by libmetalink's metalink_check_safe_path(). By design,
absolute, relative and home paths are rejected.

At the moment of writing, when --metalink-over-http is used, absolute,
relative, and home paths aren't a concern. The destination file name
is a combination of URL's file name and cli's "Directory Options"
handled by src/url.c (url_file_name).
2016-09-27 20:29:03 +02:00
Matthew White
ff444ebc2a Bugfix: Keep the download progress when alternating metalink:url
* NEWS: Mention the effects of --continue over Metalink
* src/metalink.c (retrieve_from_metalink): On download error, resume
  output_stream with the next mres->url. Keep fully downloaded files
  started with --continue, otherwise rename/remove the file
* testenv/Makefile.am: Add new file
* testenv/Test-metalink-xml-continue.py: New file. Metalink/XML
  continue/keep existing files (HTTP 416) with --continue tests

Before this patch, with --continue, existing and/or fully retrieved
files which fail the sanity tests were renamed (--keep-badhash), or
removed.

This patch ensures that --continue doesn't rename/remove existing
and/or fully retrieved files (HTTP 416) which fail the sanity tests.
2016-09-27 20:28:50 +02:00
Matthew White
96554861f9 Bugfix: Fix NULL filename and output_stream in Metalink module
* NEWS: Mention the Metalink "path/file" name format handling
* src/metalink.c (retrieve_from_metalink): Fix NULL filename, set
  filename to the right "path/file" value
* src/metalink.c (retrieve_from_metalink): Fix NULL output_stream, set
  output_stream to filename when it is created by retrieve_url()
* src/metalink.c (retrieve_from_metalink): Add RFC5854 comments about
  proper metalink:file "path/file" name format handling
* doc/metalink.txt: Update document. Remove resolved bugs

If unique_create() cannot create/open the destination file, filename
and output_stream remain NULL. If fopen() is used instead, filename
always remains NULL. Both functions cannot create "path/file" trees.

Setting filename to the right value is sufficient to prevent SIGSEGV
generating from testing a NULL value. This also allows retrieve_url()
to create a "path/file" tree through opt.output_document.

Reading NULL as output_stream, when it shall not be, leads to wrong
results. For instance, a non-NULL output_stream tells when a stream
was interrupted, reading NULL instead means to assume the contrary.

This patch conforms to the RFC5854 specification:
  The Metalink Download Description Format
  4.1.2.1.  The "name" Attribute
  https://tools.ietf.org/html/rfc5854#section-4.1.2.1
2016-09-27 20:17:08 +02:00
Matthew White
bcb9bf7ae4 Add metalink description
* doc/metalink.txt

Evaluation of "Directory Options" on the command line interacting with
the option '--input-metalink=file':

$ wget --input-metalink=file <directory options>
2016-09-19 05:56:40 +02:00
Matthew White
ea038006d1 Use python .replace instead than re.sub in Metalink tests
* testenv/Test-metalink-http.py: Use python .replace
* testenv/Test-metalink-xml.py: Use python .replace
* testenv/Test-metalink-xml-abspath.py: Use python .replace
* testenv/Test-metalink-xml-relpath.py: Use python .replace

Use python .replace instead than re.sub, remove 'import re'.
2016-09-19 05:56:40 +02:00
Matthew White
77e2c54991 Fix: Change Metalink/XML v3 file name into test.metalink
* testenv/Test-metalink-xml-abspath.py: Change Metalink/XML v3 file
  name from test.meta4 into test.metalink
* testenv/Test-metalink-xml-relpath.py: Change Metalink/XML v3 file
  name from test.meta4 into test.metalink
* testenv/Test-metalink-xml.py: Change Metalink/XML v3 file name from
  test.meta4 into test.metalink
2016-09-19 05:55:04 +02:00
Tim Rühsen
7ffbccec4c Add two Metalink/XML tests
* testenv/Test-metalink-xml-abspath.py: Reject absolute paths
* testenv/Test-metalink-xml-relpath.py: Reject relative paths
* testenv/Makefile.am: Add both new files to metalink tests
2016-09-13 11:45:02 +02:00
Tim Rühsen
a2c4849900 Fix crash on 'srcset' inline URIs
* src/html-url.c (tag_handle_img): Check append_url() for NULL
  return value before dereference.

Crashed reproducable with parsing srcset="data:..." inline data.
Reported-by: Coverity
2016-09-09 11:44:02 +02:00
Tim Rühsen
40870e1271 * src/hsts.c (hsts_store_open): NULL check param for fclose().
Reported-by: Coverity
2016-09-09 10:22:58 +02:00
Tim Rühsen
15c1e0eb7b * src/ftp-ls.c (ftp_parse_winnt_ls): Fix memset params 2016-09-09 10:22:58 +02:00
Tim Rühsen
eba724a128 * src/utils.c (stable_sort): Use xmalloc instead of malloc 2016-09-09 10:22:58 +02:00
Tim Rühsen
66a9883c8f * src/ftp-ls.c (ftp_parse_winnt_ls): Initialize struct fileinfo cur
Reported-by: Coverity
2016-09-08 16:51:15 +02:00
Tim Rühsen
4febe72bd2 Add const to url param of some functions
* src/http.c: Add const to first param of initialize_request(),
  initialize_proxy_configuration(), establish_connection(),
  check_file_output(), check_auth(), gethttp(), http_loop().
* src/http.h: Add const to first param of http_loop().
2016-09-08 16:13:54 +02:00
Tim Rühsen
c629ec7fd1 * Makefile.am: Remove trailing empty line 2016-09-08 14:20:33 +02:00
Tim Rühsen
03da900c5b * src/recur.c (retrieve_tree): Fix possible NULL dereference
Reported-by: Coverity
2016-09-08 13:04:37 +02:00
Tim Rühsen
b7b67e23cd * src/http.c (initialize_request): Fix check for user
Reported-by: Coverity
2016-09-08 12:48:32 +02:00
Tim Rühsen
22aed3ed4b * src/retr.c (retrieve_url): NULL check mynewloc
Reported-by: Coverity
2016-09-08 12:46:25 +02:00
Tim Rühsen
b4465afa8a * src/utils.c (stable_sort): Reduce tmp allocation size
Reported-by: Coverity
2016-09-08 12:44:17 +02:00
Tim Rühsen
a232835fd1 * Makefile.am: Add target 'check-valgrind' 2016-09-08 11:20:25 +02:00
Tim Rühsen
a78b83b1e9 Fix some issues detected by Coverity
* src/connect.c (connect_to_ip): Check return value of setsockopt.
* src/ftp.c (ftp_retrieve_list): Check return value of chmod.
* src/http.c (digest_authentication_encode): Cleanup code.
* src/init.c (setval_internal): Explicitely check comind range.
* src/main.c (main): Explicitely check optarg.
* src/retr.c (retr_rate): Use snprintf instead sprintf,
  (retrieve_from_file): More verbose error message,
  (rotate_backups): Use snprintf instead sprintf, check return
  value of rename().
* src/url.c (mkalldirs): Check return value of unlink().
* src/utils.c (strdupdelim): Explicitely check beg and end for NULL,
  (merge_vecs): Fix sizeof argument to char *,
  (stable_sort): Use malloc instead of alloca.
2016-09-08 10:12:02 +02:00
Tim Rühsen
37a5257c66 Code cleanup for --use-askpass
* bootstrap.conf: Add xmemdup0 and strpbrk.
* src/init.c (cmd_use_askpass): Add 'const' to char *,
  remove check for file existence.
* src/main.c (run_use_askpass): C89 compat init of argv,
  added \n to error messages,
  fixed stripping of \n and \r from input,
  make run_use_askpass and use_askpass static.
2016-09-08 09:07:32 +02:00
Tim Rühsen
49af22ca94 * src/http.c (check_file_output): Replace asprintf by aprint 2016-09-07 09:31:43 +02:00
Tim Rühsen
d505714a32 * testenv/README: Remove obsolete references to TEST_NAME 2016-09-04 14:56:06 +02:00
Liam R. Howlett
21e1725e12 Add --use-askpass=COMMAND support
* doc/wget.texi: Add --use-askpass to documentation.
* src/init.c: Add cmd_use_askpasss to set opt.use_askpass based on
argument, WGET_ASKPASS, and SSH_ASKPASS environment variables.
opt.wget-askpass is freed in cleanup ()
* src/main.c: Update options & add spawn process of opt.use_askpass
command.
* src/options.h: Addition of string use_askpass.
* src/url.c: Function scheme_leading_string to access the leading
string of a parsed url.
* src/url.h: Prototype for scheme_leading_string for returning the
leading string.
* bootstrap.conf: Add posix_spawn to gnulib_modules

This adds the --use-askpass option which is disabled by default.

--use-askpass=COMMAND will request the username and password for a given
URL by executing the external program COMMAND.  If COMMAND is left
blank, then the external program in the environment variable
WGET_ASKPASS will be used.  If WGET_ASKPASS is not set then the
environment variable SSH_ASKPASS is used.  If there is no value set, an
error is returned.  If an error occurs requesting the username or
password, wget will exit.

Signed-off-by: Liam R. Howlett <Liam.Howlett@WindRiver.com>
2016-09-03 21:01:24 +02:00
Dale R. Worley
796e30dcea Add tests for recursion and redirection.
* testenv/Test-recursive-basic.py: New file. Test basic recursion
    * testenv/Test-recursive-include.py: New File. Recursion test with
    include directories
    * testenv/Test-redirect.py: New File. Basic redirection tests
    * testenv/Makefile.am: Add new tests to makefile
2016-09-02 17:46:36 +02:00
Dale R. Worley
b919f988f2 Sort test names into order.
* testenv/Makefile.am: Sort all the python tests in alphabetical
    order
2016-09-02 17:45:19 +02:00
Dale R. Worley
ca1ee7d32f Corrections and amplifications to test documentation
* testenv/README: Update documentation to meet current project
    status
    * testenv/Test-Proto.py: Same
2016-09-02 17:44:10 +02:00
Giuseppe Scrivano
690c47e3b1 Append .tmp to temporary files
* src/http.c (struct http_stat): Add `temporary` flag.
(check_file_output): Append .tmp to temporary files.
(open_output_stream): Refactor condition to use hs->temporary instead.

Reported-by: "Misra, Deapesh" <dmisra@verisign.com>
Discovered by: Dawid Golunski (http://legalhackers.com)
2016-08-24 12:29:01 +02:00
Tim Rühsen
9ffb64ba6a Limit file mode to u=rw on temp. downloaded files
* bootstrap.conf: Add gnulib modules fopen, open.
* src/http.c (open_output_stream): Limit file mode to u=rw
on temporary downloaded files.

Reported-by: "Misra, Deapesh" <dmisra@verisign.com>
Discovered by: Dawid Golunski (http://legalhackers.com)
2016-08-24 12:28:55 +02:00
Giuseppe Scrivano
6698260f15 Fix some make syntax-check issues
cfg.mk: Skip .der files.
testenv/certs/server-template.cfg: Remove empty final line.
testenv/certs/ca-template.cfg: Likewise.
2016-08-21 15:35:36 +02:00
Tim Rühsen
0787d7253e * src/css-url.c (get_urls_css): Fix memory leak 2016-08-17 23:13:27 +02:00
Tim Rühsen
964f4646da * src/html-url.c (get_urls_html): Fix memory leak 2016-08-17 23:12:25 +02:00
Tim Rühsen
262baeb113 Improve PSL cookie checking
* configure.ac: Add --with-psl-file to set a PSL file
* src/cookies.c (check_domain_match): Load PSL_FILE with
  fallback to built-in data.

This change allows package maintainers to make Wget use the latest
PSL (DAFSA or plain text), without updating libpsl itself.

E.g. Debian now comes with a DAFSA binary within the 'publicsuffix'
package which allows very fast loading (no parsing or processing needed).
2016-08-17 16:32:26 +02:00
Tobias Stoeckmann
f4aeb41899 Fix stack overflow with way too many cookies
* src/cookies.c (cookie_header): Use heap instead of stack.
* src/http.c (request_send): Likewise.

If wget has to handle an insanely large amount of cookies (~700,000 on
32 bit systems or ~530,000 on 64 bit systems), the stack is not large
enough to hold these pointers, leading to undefined behaviour according
to POSIX; expect a segmentation fault in real life. ;)

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2016-08-10 19:59:25 +02:00
Tobias Stoeckmann
a9d49e5b15 Fix signal race condition
The signal handler for SIGALRM calls longjmp, but the handler is
installed before the jump target has been initialized. If another
process sends SIGALRM right between handler installation and target
initialization, the jump leads to undefined behavior.

This can easily be fixed by moving the signal handler installation
into the "SETJMP == 0" conditional block, which means that the target
has just been initialized.

* src/utils.c: call signal after SETJMP.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2016-08-09 17:38:29 +02:00
Jeffery To
0fe79eeacb Remove hyphens from command names
* src/init.c: Remove hyphens from command names
* src/main.c: Likewise

Options with hyphens (or underscores) in their command name cannot be
set in a wgetrc file.

Signed-off-by: Jeffery To <jeffery.to@gmail.com>
2016-08-05 09:45:09 +02:00
Tim Rühsen
e3fb4c3859 * src/metalink.c (badhash_suffix): Fix quoting 2016-08-04 13:09:28 +02:00
Matthew White
943a6d585f Add new option --keep-badhash to keep Metalink's files with a bad hash
* src/init.c: Add keepbadhash
* src/main.c: Add keep-badhash
* src/options.h: Add keep_badhash
* doc/wget.texi: Add docs for --keep-badhash
* src/metalink.h: Add prototypes badhash_suffix(), badhash_or_remove()
* src/metalink.c: New functions badhash_suffix(), badhash_or_remove().
  (retrieve_from_metalink): Call badhash_or_remove() on download error

With --keep-badhash, append .badhash to Metalink's files with checksum
mismatch. (retrieve_from_metalink): unique_create() may append another
suffix to avoid overwriting existing files.

Without --keep-badhash, remove downloaded files with checksum mismatch
(this conforms to the old behaviour).
2016-08-04 12:03:49 +02:00
Tim Rühsen
7fad76db4c * src/metalink.c: Remove C++ style comments 2016-08-03 13:48:07 +02:00
Matthew White
3e7e29f358 Add gnulib modules 'link', 'unlink' and 'symlink'
* bootstrap.conf: Add 'link', 'unlink' and 'symlink'
2016-08-03 13:44:34 +02:00
Matthew White
e0b60fd073 New: --continue continues partially downloaded Metalink's files
* src/metalink.c (retrieve_from_metalink): Continue file download if
  opt.always_rest is true

Without --continue, download as a new file with an unique name (this
conforms to the old behaviour).
2016-08-03 13:37:27 +02:00
Matthew White
9db02a0c46 Add support for Metalink's md2, and md4 hashes
* bootstrap.conf: Add crypto/md2, and crypto/md4
* src/metalink.c (retrieve_from_metalink): Add md2, and md4 support

This patch adds support for the deprecated (insecure) md2, and md4
Message-Digest algorithms to the Metalink module.
2016-08-03 12:58:43 +02:00
Matthew White
edad3c1df3 Add support for Metalink's md5, sha1, sha224, sha384, and sha512 hashes
* bootstrap.conf: Add crypto/sha512
* src/metalink.c (retrieve_from_metalink): Add md5, sha1, sha224,
  sha384, and sha512 support

Metalink's checksum verification was limited to sha256. This patch
adds support for md5, sha1, sha224, sha384, and sha512.
2016-08-03 12:49:26 +02:00
Sean Burford
20cac2c5ab Style fixes and DEBUG on setxattr failure.
* src/ftp.c: Fix style.
* src/http.c: Likewise.
* src/xattr.h: Likewise.
* src/xattr.c: Likewise,
  (write_xattr_metadata): Print debug msg on error.
2016-07-27 17:05:57 +02:00
Sean Burford
a933bdd31e Keep fetched URLs in POSIX extended attributes
* configure.ac: Check for xattr availability
* src/Makefile.am: Add xattr.c
* src/ftp.c: Include xattr.h.
  (getftp): Set attributes if enabled.
* src/http.c: Include xattr.h.
  (gethttp): Add parameter 'original_url',
  set attributes if enabled.
  (http_loop): Add 'original_url' to call of gethttp().
* src/init.c: Add new option --xattr.
* src/main.c: Add new option --xattr, add description to help text.
* src/options.h: Add new config member 'enable_xattr'.
* src/xatrr.c: New file.
* src/xattr.h: New file.

These attributes provide a lightweight method of later determining
where a file was downloaded from.

This patch changes:
*   autoconf detects whether extended attributes are available and
    enables the code if they are.
*   The new flags --xattr and --no-xattr control whether xattr is enabled.
*   The new command "xattr = (on|off)" can be used in ~/.wgetrc or /etc/wgetrc
*   The original and redirected URLs are recorded as shown below.
*   This works for both single fetches and recursive mode.

The attributes that are set are:
user.xdg.origin.url: The URL that the content was fetched from.
user.xdg.referrer.url: The URL that was originally requested.

Here is an example, where http://archive.org redirects to https://archive.org:
$ wget --xattr http://archive.org
...
$ getfattr -d index.html
user.xdg.origin.url="https://archive.org/"
user.xdg.referrer.url="http://archive.org/"

These attributes were chosen based on those stored by Google Chrome
https://bugs.chromium.org/p/chromium/issues/detail?id=45903
and curl https://github.com/curl/curl/blob/master/src/tool_xattr.c
2016-07-22 13:42:23 +02:00
Noël Köthe
ef372a4f27 Fix typos
* ChangeLog-2014-12-10: invokation -> invocation
* doc/wget.texi: invokation -> invocation
* src/main.c: seperated -> separated
* src/options.h: seperated -> separated
* testenv/README: invokation -> invocation
* testenv/conf/wget_commands.py: invokation -> invocation
2016-07-02 19:01:24 +02:00
Tim Rühsen
0b151f51eb Fix creating docs when make uses 'sh -e'
* doc/Makefile.am: Save fallback for pod2man --utf8

Reported-by: Jérémie Courrèges-Anglas <jca@wxcvbn.org>
2016-06-30 15:19:26 +02:00
Tim Rühsen
309e72c74f Fix compilation for OpenSSL 1.1.0
* src/openssl.c (ssl_init): Use SSL_is_init_finished() instead of
  SSL_state(), conditionally skip SSLeay function calls

The python test suite makes SSL_peek() hang, consuming 100% CPU time.
This does not happen on real world TLS connections, though, but needs
investigations.
2016-06-30 13:24:33 +02:00
Tim Rühsen
2318c309d4 Add script to generate test certs non-interactive
* Test-pinnedpubkey-hash-https.py: Read hashed pubkey from file
* Test-pinnedpubkey-hash-no-check-fail-https.py: Use invalid hash
* certs/make_ca.sh: New script to generate test certs non-interactive
* certs/ca-template.cfg: New file (template for CA cert)
* certs/server-template.cfg: New file (template for server cert)
* certs/server-pubkey-sha256.base64: New file (pubkey sha256 hash)
2016-06-29 12:54:06 +02:00
Ander Juaristi
cdc3e28d8e Bypass world-writable checks on Windows
* src/hsts.c (hsts_file_access_valid): we should check for "world-writable"
   files only on Unix-based systems. It's difficult to mimic the same behavior
   on Windows, so it's better to just not do it.

Reported-by: Gisle Vanem <gvanem@yahoo.no>
Reported-by: Eli Zaretskii <eliz@gnu.org>
2016-06-27 09:54:32 +02:00
Tim Rühsen
43359f47c4 Update gnulib and bootstrap
* gnulib: Sync gnulib submodule with upstream
* bootstrap: Update to latest version from gnulib/build-aux/
2016-06-14 09:27:58 +02:00
Tim Rühsen
e1e7afb210 Use ICONV_CONST to avoid type warning for iconv()
* src/iri.c (do_conversion): Cast 2. param of iconv() to
 'ICONV_CONST char **'
* src/url.c (convert_fname): Likewise
2016-06-12 21:51:34 +02:00
Tim Rühsen
7e585fe23d Remove check for HAVE_ICONV in src/url.c
* src/url.c: Remove check for HAVE_ICONV
2016-06-12 21:49:23 +02:00
Tim Rühsen
526e98f7c4 Add gnulib module 'langinfo'
* bootstrap.conf: Add 'langinfo'
2016-06-12 20:55:03 +02:00
Tim Rühsen
d75f43f083 Include gnulib fcntl.h instead of sys/fcntl.h
* src/gnutls.c: Include gnulib fcntl.h
2016-06-12 17:06:31 +02:00
Tim Rühsen
d4f97dc9af Add libraries to LDADD for wget
* src/Makefile.am: Add $(GETADDRINFO_LIB) $(HOSTENT_LIB) $(INET_NTOP_LIB)
 $(LIBSOCKET) $(LIB_CLOCK_GETTIME) $(LIB_CRYPTO) $(LIB_SELECT)
 $(LTLIBICONV) $(LTLIBINTL) $(LTLIBTHREAD) $(SERVENT_LIB) to LDADD
2016-06-12 17:02:12 +02:00
Tim Rühsen
ade62eb400 Explicitely mention Python3 in README.checkout
* README.checkout: Python test suite needs Python3
2016-06-10 15:14:43 +02:00
174 changed files with 12767 additions and 1232 deletions

124
.gitlab-ci.yml Normal file
View File

@@ -0,0 +1,124 @@
variables:
BUILD_IMAGES_PROJECT: gnuwget/build-images
DEBIAN_BUILD: buildenv-debian-stretch
FEDORA_BUILD: buildenv-f25
CENTOS7_BUILD: buildenv-centos7
GET_SOURCES_ATTEMPTS: "3"
# In this build we combine
# * syntax-check
# * abi-check
# * build/valgrind-check
# * build/asan-check
# * build w/Werror and ubsan-check
Debian GNU/Linux build:
image: $CI_REGISTRY/$BUILD_IMAGES_PROJECT:$DEBIAN_BUILD
script:
- echo "127.0.0.1 wgettestingserver" >>/etc/hosts
- cat /etc/hosts
- touch .manywarnings
- alias make="make -j$(nproc)"
- ./bootstrap
- ./configure -C
- make syntax-check
- make check
# - make abi-check
- make distcheck
- make check-valgrind
- ./configure -C --with-ssl=openssl
- make clean
- make check
# - ./configure -C --enable-fsanitize-asan
# - make clean
# - make check
# - ./configure -C --enable-fsanitize-ubsan
# - make clean
# - make check
# - ./configure -C --enable-fsanitize-msan
# - make clean
# - make check
tags:
- shared
artifacts:
expire_in: 2 weeks
when: on_failure
paths:
- tests/*.log
# - compat_reports/
#Centos7 build:
# image: $CI_REGISTRY/$BUILD_IMAGES_PROJECT:$CENTOS7_BUILD
# script:
# - sed -i 's/AM_GNU_GETTEXT_VERSION(0.19.3)/AM_GNU_GETTEXT_VERSION(0.18.2)/g' configure.ac
# - ./bootstrap && ./configure --enable-gcc-warnings --disable-doc && make -j$(nproc) check
# tags:
# - shared
# artifacts:
# expire_in: 2 weeks
# when: on_failure
# paths:
# - tests/*.log
# - compat_reports/
#clang-analyzer/Fedora:
# image: $CI_REGISTRY/$BUILD_IMAGES_PROJECT:$FEDORA_BUILD
# script:
# - ./bootstrap
# - scan-build ./configure --disable-doc --enable-gcc-warnings
# - make -j$(nproc) -C gl
# - scan-build --status-bugs -o scan-build-lib make -j$(nproc) -C lib
# tags:
# - shared
# except:
# - tags
# artifacts:
# expire_in: 2 weeks
# when: on_failure
# paths:
# - scan-build-lib/*
#pages:
# image: $CI_REGISTRY/$BUILD_IMAGES_PROJECT:$DEBIAN_BUILD
# script:
# - ./bootstrap
# - CFLAGS="-g -O0" ./configure --enable-gtk-doc --enable-code-coverage --disable-gcc-warnings
# - make -j$(nproc) check
# - make local-code-coverage-output
# - mkdir -p public
# - rm -rf public/coverage
# - mv libidn2-*-coverage public/coverage
# - rm -rf public/reference
# - mv doc/reference/html public/reference
# - make -C doc manual
# - rm -rf public/manual
# - mv doc/manual public/manual
# tags:
# - shared
# artifacts:
# when: on_success
# paths:
# - public
# only:
# - master
#MinGW64:
# image: $CI_REGISTRY/$BUILD_IMAGES_PROJECT:$FEDORA_BUILD
# before_script:
# - mount -t binfmt_misc binfmt_misc /proc/sys/fs/binfmt_misc &&
# echo ':DOSWin:M::MZ::/usr/bin/wine64:' > /proc/sys/fs/binfmt_misc/register
# script:
# - ./bootstrap
# - mingw64-configure --disable-valgrind-tests --disable-doc
# - mingw64-make -j$(nproc)
# - mingw64-make -j$(nproc) check
# tags:
# - shared
# - docker
# except:
# - tags
# artifacts:
# expire_in: 2 weeks
# when: on_failure
# paths:
# - ./*.log
# - tests/*.log

View File

@@ -1,4 +1,5 @@
sudo: no
dist: trusty
language: c
@@ -36,7 +37,7 @@ addons:
- make
- libhttp-daemon-perl
- libio-socket-ssl-perl
- libidn11-dev
- libidn2-dev
- gettext
- texlive
- python3

View File

@@ -729,7 +729,7 @@
* testenv/Makefile.am: Run the tests in Python's Optimizedmode
* testenv/conf/__init__.py (gen_hook): Use try..except instead of if..else
* testenv/misc/color_terminal.py: System and check will not change while a test is
run. Do not test for them on every invokation of printer()
run. Do not test for them on every invocation of printer()
* testenv/server/http/http_server.py: The ssl and re modules are required by
specific functions. Load them lazily
(HTTPSServer.__init__): Lazy load ssl module here

View File

@@ -77,3 +77,6 @@ gen-ChangeLog:
{ rm -f $(distdir)/ChangeLog && \
mv $(distdir)/cl-t $(distdir)/ChangeLog; } \
fi
check-valgrind:
TESTS_ENVIRONMENT="VALGRIND_TESTS=1" $(MAKE) check

83
NEWS
View File

@@ -1,12 +1,87 @@
GNU Wget NEWS -- history of user-visible changes.
Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 Free
Software Foundation, Inc.
Copyright (C) 1997-2017 Free Software Foundation, Inc.
See the end for copying conditions.
Please send GNU Wget bug reports to <bug-wget@gnu.org>.
* Changes in Wget 1.19.2
* Fix CVE-2017-13089 (Stack overflow in HTTP protocol handling)
* Fix CVE-2017-13090 (Heap overflow in HTTP protocol handling)
* New option --compression for gzip Content-Encoding
* New option --[no]-netrc to control .netrc parsing
* Added GNU extensions to .netrc parsing
* Improved IDNA 2003 compatibility
* Fix VPATH issues
* Improved and extended the test suite
* Support Wayback Machine's X-Archive-Orig-last-modified
* Several bug fixes
* Changes in Wget 1.19.1
* Fix bugs, a regression, portability/build issues
* Add new option --retry-on-http-error
* Changes in Wget 1.19
* New option --use-askpass=COMMAND. Fetch user/password by calling
an external program.
* Use IDNA2008 (+ TR46 if available) through libidn2
* When processing a Metalink header, --metalink-index=<number> allows
to process the header's application/metalink4+xml files.
* When processing a Metalink file, --trust-server-names enables the
use of the destination file names specified in the Metalink file,
otherwise a safe destination file name is computed.
* When processing a Metalink file, enforce a safe destination path.
Remove any drive letter prefix under w32, i.e. 'C:D:file'. Call
libmetalink's metalink_check_safe_path() to prevent absolute,
relative, or home paths:
https://tools.ietf.org/html/rfc5854#section-4.1.2.1
https://tools.ietf.org/html/rfc5854#section-4.2.8.3
* When processing a Metalink file, --directory-prefix=<prefix> sets
the top of the retrieval tree to prefix for Metalink downloads.
* When processing a Metalink file, reject downloaded files which don't
agree with their own metalink:size value:
https://tools.ietf.org/html/rfc5854#section-4.2.16
* When processing a Metalink file, with --continue resume partially
downloaded files and keep fully downloaded files even if they fail
the verification.
* When processing a Metalink file, create the parent directories of a
"path/file" destination file name:
https://tools.ietf.org/html/rfc5854#section-4.1.2.1
https://tools.ietf.org/html/rfc5854#section-4.2.8.3
* On a recursive download, append a .tmp suffix to temporary files
that will be deleted after being parsed, and create them
readable/writable only by the owner.
* New make target 'check-valgrind'
* Fix several bugs
* Fix compatibility issues
* Changes in Wget 1.18
* By default, on server redirects to a FTP resource, use the original
@@ -646,7 +721,7 @@ addresses when accessing the first one fails.
non-standard port.
** Wget now supports the robots.txt directives specified in
<http://www.robotstxt.org/wc/norobots-rfc.txt>.
<http://www.robotstxt.org/norobots-rfc.txt>.
** URL parser has been fixed, especially the infamous overzealous
quoting. Wget no longer dequotes reserved characters, e.g. `%3F' is

View File

@@ -4,7 +4,7 @@ Compiling From Repository Sources
does not contain automatically-generated files, even when these are
normally present in the distribution tarballs. Therefore, to build GNU
Wget from the sources in the repository, you'll need to have one or
more of the following (note that gettext, OpenSSL, GnuTLS, libidn,
more of the following (note that gettext, OpenSSL, GnuTLS, libidn2,
libiconv, libpsl, libpcre, pkg-config, libmetalink and GnuPG are not
absolutely required):
@@ -32,8 +32,8 @@ Compiling From Repository Sources
First download [25]CPAN and [26]install it, then try again the above command.
Now "make check" should pass most of the tests in the test suite.
* [45]Python, if you want to run the tests in the testenv/ subdirectory.
Keep in mind that "make check" will try to run all the perl and python
* [45]Python3, if you want to run the tests in the testenv/ subdirectory.
Keep in mind that "make check" will try to run all the Perl and Python3
tests. More information about the test suite below in the section
"Testing and development".
@@ -69,7 +69,7 @@ Compiling From Repository Sources
If you want to compile+link a non-system library version use
--with-libssl-prefix (or if having pkg-config: see description below).
* [31]libidn is required for IDN/IRI support (non-ASCII characters
* [31]libidn2 is required for IDN/IRI support (non-ASCII characters
within what would otherwise be URLs).
* [32]libiconv is required on non-GNU systems, for IDN/IRI support.
@@ -104,6 +104,10 @@ Compiling From Repository Sources
The command line options --dns-servers and --bind-dns-address are
only available when configured with --with-cares.
* [49]Gpef is required by some gnulib modules, most notably "unicase". You
need the application installed on the machine to compile Wget from git.
For those who might be confused as to what to do once they check out
the source code, considering configure and Makefile do not yet exist at
that point, a shell script called bootstrap has been provided. After
@@ -116,7 +120,7 @@ Compiling From Repository Sources
$ cd wget # assumes you've cloned a repository to "./wget"
2. Generate all the automatically-generated files required prior to
configuring the package:
$ ./bootstrap
$ ./bootstrap (or: bash ./bootstrap)
3. Configure the package and compile it:
$ ./configure --enable-assert [some_parameters]
$ make
@@ -159,7 +163,7 @@ Testing and development
Copyright (C) 2008,2010,2014,2015 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
<http://www.gnu.org/licenses/gpl.html>.
<https://www.gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
@@ -183,32 +187,33 @@ Testing and development
References
20. http://www.gnu.org/software/autoconf/
21. http://www.gnu.org/software/automake/
22. http://flex.sourceforge.net/
23. http://www.perl.org/
20. https://www.gnu.org/software/autoconf/
21. https://www.gnu.org/software/automake/
22. https://github.com/westes/flex
23. https://www.perl.org/
24. http://search.cpan.org/dist/libwww-perl/lib/Bundle/LWP.pm
25. http://search.cpan.org/CPAN/authors/id/A/AN/ANDK/CPAN-1.9402.tar.gz
26. http://apthorpe.cynistar.net/code/configuring_cpan.html
27. http://www.gnu.org/software/texinfo/
28. http://www.gnu.org/software/gettext/
29. http://www.gnu.org/software/gnutls/
30. http://www.openssl.org/
31. http://www.gnu.org/software/libidn/
32. http://www.gnu.org/software/libiconv/
33. http://git-scm.com/
27. https://www.gnu.org/software/texinfo/
28. https://www.gnu.org/software/gettext/
29. https://www.gnu.org/software/gnutls/
30. https://www.openssl.org/
31. https://www.gnu.org/software/libidn/#libidn2
32. https://www.gnu.org/software/libiconv/
33. https://git-scm.com/
34. https://github.com/rockdaboot/libpsl
35. http://www.pcre.org
36. http://wget.addictivecode.org/CompilingRepoSources?action=edit&editor=text
37. http://wget.addictivecode.org/CompilingRepoSources
38. http://wget.addictivecode.org/CompilingRepoSources?action=info
39. http://wget.addictivecode.org/CompilingRepoSources?action=AttachFile
40. http://moinmo.in/
41. http://moinmo.in/Python
42. http://moinmo.in/GPL
43. http://validator.w3.org/check?uri=referer
40. https://moinmo.in/
41. https://moinmo.in/Python
42. https://moinmo.in/GPL
43. https://validator.w3.org/check?uri=referer
44. http://wget.addictivecode.org/WikiLicense
45. https://www.python.org/
46. https://launchpad.net/libmetalink
47. https://www.gnupg.org
48. http://c-ares.haxx.se/
48. https://c-ares.haxx.se/
49. https://www.gnu.org/software/gperf/

View File

@@ -1,10 +1,10 @@
#! /bin/sh
# Print a version string.
scriptversion=2013-12-05.23; # UTC
scriptversion=2016-01-24.06; # UTC
# Bootstrap this package from checked-out sources.
# Copyright (C) 2003-2014 Free Software Foundation, Inc.
# Copyright (C) 2003-2016 Free Software Foundation, Inc.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -42,6 +42,9 @@ export LC_ALL
local_gl_dir=gl
# Honor $PERL, but work even if there is none.
PERL="${PERL-perl}"
me=$0
usage() {
@@ -456,6 +459,7 @@ check_versions() {
test "$appvar" = TAR && appvar=AMTAR
case $appvar in
GZIP) ;; # Do not use $GZIP: it contains gzip options.
PERL::*) ;; # Keep perl modules as-is
*) eval "app=\${$appvar-$app}" ;;
esac
@@ -473,6 +477,17 @@ check_versions() {
ret=1
continue
} ;;
# Another check is for perl modules. These can be written as
# e.g. perl::XML::XPath in case of XML::XPath module, etc.
perl::*)
# Extract module name
app="${app#perl::}"
if ! $PERL -m"$app" -e 'exit 0' >/dev/null 2>&1; then
warn_ "Error: perl module '$app' not found"
ret=1
fi
continue
;;
esac
if [ "$req_ver" = "-" ]; then
# Merely require app to exist; not all prereq apps are well-behaved
@@ -900,7 +915,8 @@ if test $use_libtool = 1; then
esac
fi
echo "$0: $gnulib_tool $gnulib_tool_options --import ..."
$gnulib_tool $gnulib_tool_options --import $gnulib_modules &&
$gnulib_tool $gnulib_tool_options --import $gnulib_modules \
|| die "gnulib-tool failed"
for file in $gnulib_files; do
symlink_to_dir "$GNULIB_SRCDIR" $file \
@@ -1005,6 +1021,6 @@ echo "$0: done. Now you can run './configure'."
# eval: (add-hook 'write-file-hooks 'time-stamp)
# time-stamp-start: "scriptversion="
# time-stamp-format: "%:y-%02m-%02d.%02H"
# time-stamp-time-zone: "UTC"
# time-stamp-time-zone: "UTC0"
# time-stamp-end: "; # UTC"
# End:

View File

@@ -40,6 +40,7 @@ dirname
fcntl
flock
fnmatch
fopen
futimens
ftello
getaddrinfo
@@ -52,9 +53,17 @@ gettext
gitlog-to-changelog
git-version-gen
gnupload
group-member
hostent
ioctl
iconv
iconv-h
inet_ntop
intprops
inttypes
langinfo
limits-h
link
listen
maintainer-makefile
mbiter
@@ -63,9 +72,16 @@ memrchr
mkdir
mkstemp
mkostemp
nanosleep
crypto/md2
crypto/md4
crypto/md5
crypto/sha1
crypto/sha256
crypto/sha512
open
pipe-posix
posix_spawn
quote
quotearg
recv
@@ -73,24 +89,37 @@ regex
select
send
setsockopt
signal-h
sigprocmask
sigpipe
snprintf
socket
spawn-pipe
stat
stdbool
stdint
strcase
strerror_r-posix
strpbrk
strptime
strtok_r
strtoll
symlink
sys_types
timegm
tmpdir
unlink
unlocked-io
update-copyright
libunistring-optional
unistr/u8-strlen
unicase/u8-tolower
utimens
vasprintf
vsnprintf
wcwidth
write
xmemdup0
xstrndup
"
@@ -118,4 +147,21 @@ rsync -
tar -
xz -
flex -
gperf -
"
bootstrap_post_import_hook ()
{
# We need to patch unicase/special-casing-table.h for gperf < 3.1
GPERF_VER=$(gperf --version | {
IFS=' .' read x y major minor bugfix _
printf "%d%02d%02d" $major $minor $bugfix
})
if [ $GPERF_VER -lt 30100 ]; then
echo "Creating lib/unicase/special-casing-table.h for gperf < 3.1"
gperf -m 10 lib/unicase/special-casing-table.gperf | \
sed -e "s/gl_unicase_special_lookup.*/gl_unicase_special_lookup\ \(const char \*str, size_t len\)/g" \
> lib/unicase/special-casing-table.h
fi
}

8
cfg.mk
View File

@@ -1,4 +1,7 @@
export VC_LIST_EXCEPT_DEFAULT=^(lib/.*|m4/.*|md5/.*|build-aux/.*|src/gettext\.h|.*ChangeLog)$$
# Explicit syntax-check exceptions.
exclude_file_name_regexp--sc_trailing_blank = ^doc/annou.*$$
export VC_LIST_EXCEPT_DEFAULT=^(lib/.*|m4/.*|md5/.*|build-aux/.*|src/gettext\.h|.*ChangeLog|tests/certs/.*)$$
local-checks-to-skip = \
sc_const_long_option \
@@ -21,9 +24,10 @@ local-checks-to-skip = \
sc_program_name \
sc_makefile_at_at_check \
sc_cast_of_argument_to_free \
sc_prohibit_undesirable_word_seq
#SHELL=bash -x
show-vc-list-except:
@$(VC_LIST_EXCEPT)
VC_LIST_ALWAYS_EXCLUDE_REGEX = ^ABOUT-NLS|((msdos|vms)/.*)|ChangeLog-2014-12-10$$
VC_LIST_ALWAYS_EXCLUDE_REGEX = ^ABOUT-NLS|((msdos|vms)/.*)|ChangeLog-2014-12-10|/.*.der|^tests/certs/.*$$

View File

@@ -290,15 +290,6 @@ AC_DEFINE([HAVE_STRNCASECMP], 1, [Define to 1 if you have the `strncasecmp' func
AC_DEFINE([HAVE_STRDUP], 1, [Define to 1 if you have the `strdup' function.])
AC_DEFINE([HAVE_ISATTY], 1, [Define to 1 if you have the `isatty' function.])
dnl
dnl Call Wget-specific macros defined in aclocal.
dnl
WGET_STRUCT_UTIMBUF
WGET_FNMATCH
WGET_NANOSLEEP
WGET_POSIX_CLOCK
WGET_NSL_SOCKET
dnl Deal with specific hosts
case $host_os in
*mingw32* )
@@ -329,6 +320,10 @@ AS_IF([test "x$with_libpsl" != xno], [
])
])
AS_IF([test x"$with_libpsl" = xyes], [
AC_CHECK_FUNCS(psl_latest)
])
AS_IF([test x"$with_zlib" != xno], [
with_zlib=yes
PKG_CHECK_MODULES([ZLIB], zlib, [
@@ -635,9 +630,6 @@ AC_ARG_ENABLE(iri,
]
)
AC_ARG_WITH(libidn, AC_HELP_STRING([--with-libidn=[DIR]],
[Support IDN/IRIs (needs GNU Libidn)]),
libidn=$withval, libidn="")
AS_IF([test "X$iri" != "Xno"],[
AM_ICONV
@@ -649,39 +641,23 @@ AS_IF([test "X$iri" != "Xno"],[
AC_MSG_NOTICE([disabling IRIs because libiconv wasn't found])
fi
fi
],[ # else
# For some reason, this seems to be set even when we don't check.
# Explicitly unset.
LIBICONV=
])
AC_ARG_WITH(libidn, AC_HELP_STRING([--with-libidn=[DIR]],
[Support IDN2008/IRIs (needs GNU libidn2 + libunicode)]),
libidn=$withval, libidn="")
if test "X$iri" != "Xno"; then
if test "$libidn" != ""; then
LDFLAGS="${LDFLAGS} -L$libidn/lib"
CPPFLAGS="${CPPFLAGS} -I$libidn/include"
fi
AS_IF([test "x$with_libidn2" != xno], [
AC_SEARCH_LIBS(idn2_lookup_u8, idn2,
[with_libidn2=yes; AC_DEFINE([ENABLE_IRI], 1, [Define if IRI support is enabled.])],
[with_libidn2=no; iri=no; AC_MSG_WARN(*** LIBIDN2 was not found. You will not be able to use IDN2008 support)])
# If idna.h can't be found, check to see if it was installed under
# /usr/include/idn (OpenSolaris, at least, places it there).
# Check for idn-int.h in that case, because idna.h won't find
# idn-int.h until we've decided to add -I/usr/include/idn.
AC_CHECK_HEADER(idna.h, ,
[AC_CHECK_HEADER(idn/idn-int.h,
[CPPFLAGS="${CPPFLAGS} -I/usr/include/idn"],
[iri=no])]
)
if test "X$iri" != "Xno"; then
AC_CHECK_LIB(idn, stringprep_check_version,
[iri=yes LIBS="${LIBS} -lidn"], iri=no)
fi
if test "X$iri" != "Xno" ; then
AC_DEFINE([ENABLE_IRI], 1, [Define if IRI support is enabled.])
AC_MSG_NOTICE([Enabling support for IRI.])
else
AC_MSG_WARN([Libidn not found])
fi
# AS_IF([test "x$with_libidn2" = xyes], [
# AC_SEARCH_LIBS(u8_tolower, unistring,
# [AC_DEFINE([ENABLE_IRI], 1, [Define if IRI support is enabled.])],
# [iri=no; AC_MSG_WARN(*** LIBUNISTRING was not found. You will not be able to use IDN2008 support)])
# ])
])
fi
dnl
@@ -750,7 +726,7 @@ dnl
dnl Check for libcares (resolver library)
dnl
AS_IF([test "X$with_cares" == "Xyes"],[
AS_IF([test "X$with_cares" = "Xyes"],[
PKG_CHECK_MODULES([CARES], libcares, [
CFLAGS="$CARES_CFLAGS $CFLAGS"
AC_CHECK_HEADER(ares.h, [
@@ -771,18 +747,45 @@ AS_IF([test "X$with_cares" == "Xyes"],[
RESOLVER_INFO="libc, --bind-dns-address and --dns-servers not available"
])
dnl
dnl Extended Attribute support
dnl
AC_ARG_ENABLE([xattr],
[AS_HELP_STRING([--disable-xattr], [disable support for POSIX Extended Attributes])],
[ENABLE_XATTR=$enableval],
[ENABLE_XATTR=yes])
case "$host_os" in
*linux* | *darwin*) xattr_syscalls="fsetxattr" ;;
freebsd*) xattr_syscalls="extattr_set_fd" ;;
*) AC_MSG_NOTICE([Disabling Extended Attribute support: your system is not known to support extended attributes.])
ENABLE_XATTR=no
esac
if test "X${ENABLE_XATTR}" = "Xyes"; then
AC_CHECK_FUNCS([$xattr_syscalls], [], [
AC_MSG_NOTICE([Disabling Extended Attribute support: your system does not support $xattr_syscalls])
ENABLE_XATTR=no
])
fi
test "X${ENABLE_XATTR}" = "Xyes" && AC_DEFINE([ENABLE_XATTR], 1,
[Define if you want file meta-data storing into POSIX Extended Attributes compiled in.])
dnl Needed by src/Makefile.am
AM_CONDITIONAL([IRI_IS_ENABLED], [test "X$iri" != "Xno"])
AM_CONDITIONAL([WITH_SSL], [test "X$with_ssl" != "Xno"])
AM_CONDITIONAL([METALINK_IS_ENABLED], [test "X$with_metalink" != "Xno"])
AM_CONDITIONAL([WITH_XATTR], [test "X$ENABLE_XATTR" != "Xno"])
dnl
dnl Create output
dnl
AC_CONFIG_FILES([Makefile src/Makefile doc/Makefile util/Makefile
po/Makefile.in tests/Makefile
lib/Makefile testenv/Makefile])
lib/Makefile testenv/Makefile
tests/certs/interca.conf tests/certs/rootca.conf])
AC_CONFIG_HEADERS([src/config.h])
AC_OUTPUT
@@ -801,10 +804,12 @@ AC_MSG_NOTICE([Summary of build options:
Digest: $ENABLE_DIGEST
NTLM: $ENABLE_NTLM
OPIE: $ENABLE_OPIE
POSIX xattr: $ENABLE_XATTR
Debugging: $ENABLE_DEBUG
Assertions: $ENABLE_ASSERTION
Valgrind: $VALGRIND_INFO
Metalink: $with_metalink
Resolver: $RESOLVER_INFO
GPGME: $have_gpg
IRI: $iri
])

View File

@@ -12,7 +12,8 @@ if [ $CORES -lt 1 ]; then CORES=1; fi
echo "Running: make distclean"
make distclean > /dev/null || true
CFLAGS="-std=c89 -pedantic -O2 -g -Wall -Wextra -Wstrict-prototypes -Wold-style-definition -Wwrite-strings -Wshadow -Wformat -Wformat-security -Wunreachable-code -Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition"
#CFLAGS="-std=c89 -pedantic -O0 -g -Wall -Wextra -Wstrict-prototypes -Wold-style-definition -Wwrite-strings -Wshadow -Wformat -Wformat-security -Wunreachable-code -Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition"
CFLAGS="-Wall -Wextra -O2 -g"
CACHEFILE=$PWD/config_check.cache
@@ -30,7 +31,7 @@ for CC in gcc clang; do
# the compiler changed, so we have to remove the cache file here
rm -f $CACHEFILE
for options in "" "--with-ssl=openssl"; do
for options in "" "--with-ssl=openssl" "--disable-iri"; do
export DISTCHECK_CONFIGURE_FLAGS="-C --cache-file=$CACHEFILE $options"
echo " ./configure $DISTCHECK_CONFIGURE_FLAGS"
./configure $DISTCHECK_CONFIGURE_FLAGS CFLAGS="$CFLAGS" > /dev/null

112
contrib/release Executable file
View File

@@ -0,0 +1,112 @@
#!/bin/bash -e
#
# Written 2016 by Tim Ruehsen
extensions="gz xz"
app_name=$(grep "^PACKAGE_NAME='" configure|cut -d "'" -f2)
app_ver=$(grep "^PACKAGE_VERSION='" configure|cut -d "'" -f2)
echo "Current version of $app_name is $app_ver"
echo
echo -n "Enter Y if that is OK, else enter N and edit configure.ac: "
read x
[ "$x" != "y" -a "$x" != "Y" ] && exit 0
echo
grep -i "Changes in $app_name" NEWS|head -1
echo -n "Did you edit the NEWS file ? [y/N] "
read x
[ "$x" != "y" -a "$x" != "Y" ] && exit 0
echo
export CFLAGS="-g -O2 -Wall"
echo "* Bootstrap"
./bootstrap >/dev/null
echo "* Configure"
./configure -q
echo "* Make"
make -s clean
make -s
echo "* Make distcheck"
make -s distcheck >/dev/null
echo "* Make dist"
make -s dist >/dev/null
make -s dist-xz >/dev/null
while true; do
echo "Alpha or Regular release ? [r/A] "
read x
if test "$x" = "r" || test "$x" = "R"; then
directory="/incoming/ftp"
break
elif test "$x" = "a" || test "$x" = "A"; then
directory="/incoming/alpha"
break
fi
done
x=$(gpg --list-secret-keys 2>/dev/null|grep ^sec|awk '{ print $2 }')
echo $x
if [ "$x" = "" ]; then
echo No signing key found - please check with 'gpg --list-secret-keys'
exit 1
fi
# arrays just work in Bash
keys=($x)
if [ ${#keys[@]} -eq 1 ]; then
IFS='/' arr=($x)
signing_key=${arr[1]}
else
for ((i=0; i < ${#keys[@]}; i++)); do
echo "$((i+1))) ${keys[i]}"
done
while true; do
echo -n "Enter 1-${#keys[@]}: "
read x
# check for digits only
if [ -n "${i//[0-9]/}" ]; then continue; fi
if test $x -ge 1 || test $x -le ${#keys[@]}; then
IFS='/' arr=(${keys[$((x-1))]})
signing_key=${arr[1]}
break
fi
done
fi
unset IFS
echo $signing_key
# fetch app_version again, just in case
app_ver=$(grep "^PACKAGE_VERSION='" configure|cut -d "'" -f2)
for ext in $extensions; do
app_tarball="${app_name}-${app_ver}.tar.$ext"
gpg --default-key $signing_key --yes -b $app_tarball
echo -e "version: 1.2\nfilename: ${app_tarball}\ndirectory: ${app_name}\n" >${app_tarball}.directive
gpg --default-key $signing_key --yes --clearsign ${app_tarball}.directive
ftp -v -n -i -p ftp-upload.gnu.org <<EOF
user anonymous
cd $directory
put ${app_tarball}
put ${app_tarball}.sig
put ${app_tarball}.directive.asc
EOF
done
prev_tag=`git tag|tail -2|head -1`
echo "Don't forget to mention the following contributors in the announcement:"
(
git log ${prev_tag}.. --format="%aN" --reverse
git log ${prev_tag}.. --reverse|grep -i reported|cut -d':' -f2|cut -d'<' -f1|cut -d' ' -f2-|tr -d '"'
) | sort -u

View File

@@ -21,7 +21,7 @@ CORES=3
# Define a large number of Warning flags for the compiler. Hopefully, someone
# will sit and analyze the output to clean the warnings from the codebase.
CFLAGS="-std=c89 -pedantic -O2 -Wall -Wextra -Wstrict-prototypes -Wold-style-definition -Wwrite-strings -Wshadow -Wformat -Wformat-security -Wunreachable-code -Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition"
CFLAGS="-std=c89 -pedantic -O0 -Wall -Wextra -Wstrict-prototypes -Wold-style-definition -Wwrite-strings -Wshadow -Wformat -Wformat-security -Wunreachable-code -Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition"
# A cachefile for ./configure. Saves significant time when reconfiguring
CACHEFILE=$PWD/config_check.cache

View File

@@ -57,10 +57,8 @@ wget.pod: $(srcdir)/wget.texi version.texi
$(TEXI2POD) -D VERSION="$(VERSION)" $(srcdir)/wget.texi $@
$(MAN): wget.pod
$(POD2MAN) --center="GNU Wget" --release="GNU Wget @VERSION@" --utf8 $? > $@; \
if [ $? != 0 ]; then \
$(POD2MAN) --center="GNU Wget" --release="GNU Wget @VERSION@" $? > $@; \
fi
$(POD2MAN) --center="GNU Wget" --release="GNU Wget @VERSION@" --utf8 $? > $@ || \
$(POD2MAN) --center="GNU Wget" --release="GNU Wget @VERSION@" $? > $@
#wget.cat: $(MAN)
# nroff -man $? > $@

104
doc/announcement_1.19.txt Normal file
View File

@@ -0,0 +1,104 @@
Hello,
we are pleased to announce the new version of GNU wget 1.19.
It comes with major improvements for Metalink, IDNA2008 for
international domain names, an option to call external tools
for fetching user/password, several bugfixes and improvements.
Many thanks go to all the contributors and list activists !
Contributors (from the git log):
Ander Juaristi
Dale R. Worley
Eli Zaretskii
Gisle Vanem
Giuseppe Scrivano
Göran Uddeborg
Jann Horn
Jeffery To
Jérémie Courrèges-Anglas
Liam R. Howlett
losgrandes
Matthew White
Misra, Deapesh
Nikos Mavrogiannopoulos
Noël Köthe
Piotr Wajda
Rahul Bedarkar
Sean Burford
Tim Rühsen
Tobias Stoeckmann
vijeth-aradhya
The new version is available for download here:
https://ftp.gnu.org/gnu/wget/wget-1.19.tar.gz
https://ftp.gnu.org/gnu/wget/wget-1.19.tar.xz
and the GPG detached signatures using the key 0x08302DB6A2670428:
https://ftp.gnu.org/gnu/wget/wget-1.19.tar.gz.sig
https://ftp.gnu.org/gnu/wget/wget-1.19.tar.xz.sig
To reduce load on the main server, you can use this redirector service
which automatically redirects you to a mirror:
http://ftpmirror.gnu.org/wget/wget-1.19.tar.gz
http://ftpmirror.gnu.org/wget/wget-1.19.tar.xz
Noteworthy changes:
* New option --use-askpass=COMMAND. Fetch user/password by calling
an external program.
* Use IDNA2008 (+ TR46 if available) through libidn2
* When processing a Metalink header, --metalink-index=<number> allows
to process the header's application/metalink4+xml files.
* When processing a Metalink file, --trust-server-names enables the
use of the destination file names specified in the Metalink file,
otherwise a safe destination file name is computed.
* When processing a Metalink file, enforce a safe destination path.
Remove any drive letter prefix under w32, i.e. 'C:D:file'. Call
libmetalink's metalink_check_safe_path() to prevent absolute,
relative, or home paths:
https://tools.ietf.org/html/rfc5854#section-4.1.2.1
https://tools.ietf.org/html/rfc5854#section-4.2.8.3
* When processing a Metalink file, --directory-prefix=<prefix> sets
the top of the retrieval tree to prefix for Metalink downloads.
* When processing a Metalink file, reject downloaded files which don't
agree with their own metalink:size value:
https://tools.ietf.org/html/rfc5854#section-4.2.16
* When processing a Metalink file, with --continue resume partially
downloaded files and keep fully downloaded files even if they fail
the verification.
* When processing a Metalink file, create the parent directories of a
"path/file" destination file name:
https://tools.ietf.org/html/rfc5854#section-4.1.2.1
https://tools.ietf.org/html/rfc5854#section-4.2.8.3
* On a recursive download, append a .tmp suffix to temporary files
that will be deleted after being parsed, and create them
readable/writable only by the owner.
* New make target 'check-valgrind'
* Fix several bugs
* Fix compatibility issues
Please report any problem you may experience to the bug-wget@gnu.org
mailing list.
For the maintainers of Wget,
Tim

233
doc/metalink-standard.txt Normal file
View File

@@ -0,0 +1,233 @@
GNU Wget Metalink recommended behaviour
Metalink/XML and Metalink/HTTP standard reference
1. Security features
********************
Only metalink:file elements with safe "name" fields shall be accepted
[1 #section-4.1.2.1]. If unsafe metalink:file elements are saved, any
related test shall fail (see '2. Tests').
By design, libmetalink rejects unsafe metalink:file elements [3]:
* lib/metalink_helper.c (metalink_check_safe_path): Verify path
1.1 Exceptions
==============
The option --directory-prefix could allow to use an absolute, relative
or home path.
2. Tests
********
Saving a file to an unexpected path poses a security problem. We must
ensure that Wget's automated tests never modify the root and the home
paths or descend/escalate to a relative path unexpectedly.
2.1 Metalink/XML implemented tests
==================================
See testenv/Makefile.am (METALINK_TESTS).
2.2 Metalink/HTTP implemented tests
===================================
See testenv/Makefile.am (METALINK_TESTS).
3. Download file name
*********************
The download file name shall be decided by precise rules which prevent
any naming uncertainty and security issues.
3.1 Naming rules
================
The final name of downloaded files is computed starting from a trusted
name, which is then combined with the "Directory Options". The result
is verified and eventually made safer following security rules. If the
final name isn't found safe enough, then the file isn't downloaded.
Depending on the options used, a suffix could be appended to the final
name to not overwrite existing files.
3.1.1 The trusted name
======================
The option --trust-server-names decides what is the trusted name.
Any Metalink/XML element with an unsafe metalink:file "name" field is
ignored, see '1. Security features'.
3.1.1.1 Without --trust-server-names
====================================
When --trust-server-names is off, the basename of the --input-metalink
file, if available, or of the mother URL is trusted. This trusted name
is the radix of any subsequent file name.
When a Metalink/HTTP in encountered, any fetched Metalink/XML file has
its own ordinal number appended as suffix to the trusted name. In this
case scenario, an unique Metalink/XML file is saved each time applying
an additional suffix to the currently computed name when necessary.
The files described by a Metalink/XML file will be named sequentially
applying an additional suffix to the currently trusted/computed name.
3.1.1.2 With --trust-server-names
=================================
When --trust-server-names is on, the metalink:file "name" field parsed
from Metalink/XML files is trusted. When no Metalink/XML is available,
the mother URL is trusted.
Any Metalink/HTTP application/metalink4+xml file is saved using the
basename of its own Link header "name" field, if available.
In conjunction with the option --content-disposition, a 'Content-Type:
application/metalink4+xml' file is saved using the basename of its own
Content-Disposition header "filename" field, if available.
3.1.2 The final name
====================
The "Directory Options" are combined with the trusted name. The result
is evaluated again by the '1. Security features'. If the path is found
unsafe, only the basename of the final name is considered. If this is
found unsafe too, the file is not downloaded.
4. Metalink/XML
***************
4.1 Example files
=================
See [1 #section-1.1].
cat > bugus.meta4 << EOF
<?xml version="1.0" encoding="UTF-8"?>
<metalink xmlns="urn:ietf:params:xml:ns:metalink">
<file name="/dir/A/File1">
<size>1617</size>
<hash type="sha256">ecb3dff2648667513e31554b3ad054ccd89fce38e33367c9459ac3a285153742</hash>
<url>http://another.url/common_name</url>
<url>http://ftpmirror.gnu.org/bash/bash-4.3-patches/bash43-001</url>
</file>
<file name="dir/B/File2">
<size>1594</size>
<hash type="sha256">eee7cd7062ab29a9e4f02924d9c367264dcb8b162703f74ff6eb8f175a91502b</hash>
<url>http://another.url/again/common_name</url>
<url>http://ftpmirror.gnu.org/bash/bash-4.3-patches/bash43-002</url>
</file>
</metalink>
EOF
4.2 Command line example
========================
$ wget --input-metalink=bogus.meta4
4.3 Metalink/XML file parsing
=============================
The metalink xml file is parsed by one of the following libmetalink's
functions [3], depending upon the library configured to use:
* lib/libexpat_metalink_parser.c (metalink_parse_file): Expat [4]
* lib/libxml2_metalink_parser.c (metalink_parse_file): Libxml2 [5]
The result returned doesn't include unsafe metalink:file elements, as
stated at point '1. Security features'.
An empty result shall not be considered an error. Parsing errors will
be informed to the caller of libmetalink's metalink_parse_file().
4.4 Saving files
================
Fetched metalink:file elements shall be wrote using the unique "name"
field as file name [1 #section-4.1.2.1].
A metalink:file url's file name shall not substitute the "name" field.
Security exceptions are explained in '3. Download file name'.
4.5 Multi-Source download
=========================
Parallel range requests are allowed [1 #section-1].
5. Metalink/HTTP
****************
5.1 HTTP server
===============
The local server http://127.0.0.1 is used as reference in the course
of this chapter. Any server service capable of sending Metalink/HTTP
header answers may be used.
5.2 Command line example
========================
$ wget --metalink-over-http http://127.0.0.1/dir/file.ext
5.3 Metalink/HTTP header answer
===============================
See [2 #section-1.1].
Etag: "thvDyvhfIqlvFe+A9MYgxAfm1q5="
Link: <http://www2.example.com/example.ext>; rel=duplicate
Link: <ftp://ftp.example.com/example.ext>; rel=duplicate
Link: <http://example.com/example.ext.torrent>; rel=describedby;
type="application/x-bittorrent"
Link: <http://example.com/example.ext.meta4>; rel=describedby;
type="application/metalink4+xml"
Link: <http://example.com/example.ext.asc>; rel=describedby;
type="application/pgp-signature"
Digest: SHA-256=MWVkMWQxYTRiMzk5MDQ0MzI3NGU5NDEyZTk5OWY1ZGFmNzgyZTJlO
DYzYjRjYzFhOTlmNTQwYzI2M2QwM2U2MQ==
See [2 #section-4].
Link: <http://example.com/example.ext.torrent>; rel=describedby;
type="application/x-bittorrent"; name="differentname.ext"
Link: <http://example.com/example.ext.meta4>; rel=describedby;
type="application/metalink4+xml"
5.4 Saving files
================
When none of --output-document and/or --content-disposition is used,
the file name to wrote is computed from the cli's url hierarchy. The
purpose of the "Directory Options" is as usual, and the file name is
the cli's url file name, see wget(1).
The url followed to download the file shall not substitute the cli's
url to compute the file name to wrote, except when it redirects to a
Metalink/XML file, following the rules in '3. Download file name'.
5.5 Multi-Source download
=========================
Parallel range requests are allowed [2 #section-7].
4. References
*************
[1] The Metalink Download Description Format
https://tools.ietf.org/html/rfc5854
[2] Metalink/HTTP: Mirrors and Hashes
https://tools.ietf.org/html/rfc6249
[3] Libmetalink
https://github.com/metalink-dev/libmetalink
[4] Expat
http://www.libexpat.org
[5] Libxml2
http://xmlsoft.org

165
doc/metalink.txt Normal file
View File

@@ -0,0 +1,165 @@
GNU Wget Metalink module
Evaluation of the Metalink/XML and Metalink/HTTP implementations
1. Introduction
***************
This document, and the results contained in it, is focused over the
evaluation of the Metalink/XML and Metalink/HTTP implementations.
The "Directory Options" mentioned here are used on the command line in
conjunction with the option '--input-metalink=file' for Metalink/XML,
and '--metalink-over-http' for Metalink/HTTP.
$ wget --input-metalink=<file> [directory options]
$ wget --metalink-over-http [directory options] <url>
2. Notes
********
Tests for metalink:file names beginning with '/', '~/', './', or '../'
(e.g. "/path/file") shall be run manually due to security concerns.
3. Metalink files used as reference
***********************************
3.1 Test: metalink:file with "path/file" name format
====================================================
cat > test.meta4 << EOF
<?xml version="1.0" encoding="UTF-8"?>
<metalink xmlns="urn:ietf:params:xml:ns:metalink">
<file name="path/file">
<size>543</size>
<hash type="sha256">d37d3965f8e1a7b16504b4273b09c392776b7e4dd17e601256c7b2fd9ce5f56e</hash>
<hash type="md5">0f6ff5cdc15603f1b81227b5a296f001</hash>
<url>http://wrongurl.really/gnu/wget/wget-1.18.tar.xz.sig</url>
<url>http://ftpmirror.gnu.org/wget/wget-1.18.tar.xz.sig</url>
<url>http://ftp.gnu.org/gnu/wget/wget-1.18.tar.xz.sig</url>
<url>http://nl.mirror.babylon.network/gnu/wget/wget-1.18.tar.xz.sig</url>
</file>
</metalink>
EOF
4. `wget --input-metalink=test.meta4`
*************************************
4.1 Implemented safety features
===============================
Any metalink:file name containing an absolute, relative, or home path
(see '2. Notes') parsed from Metalink/XML files is rejected.
This is a libmetalink's design decision implemented in the function
metalink_check_safe_path(). This feature shall not be modified.
All the above conform to the RFC5854 standard.
References:
https://tools.ietf.org/html/rfc5854#section-4.1.2.1
https://tools.ietf.org/html/rfc5854#section-4.2.8.3
4.2 File download behaviour
===========================
When a Metalink/XML file is parsed:
1. create the metalink:file "path/file" tree;
2. download the metalink:url file as "path/file";
3. verify the "path/file" size, if declared;
4. verify the "path/file" checksum.
All the above conform to the RFC5854 standard.
References:
https://tools.ietf.org/html/rfc5854
4.3 Questionable behaviours
===========================
If more metalink:file elements are the same, wget downloads them all.
5. `wget --metalink-over-http`
******************************
5.1 Implemented safety features
===============================
The function url_file_name() is responsible of parsing the url's file
name and mixing in the "Directory Options" wrote on the command line.
The use of libmetalink's metalink_check_safe_path() shouldn't be
necessary (see '4.1 Implemented safety features').
All the above comform to the usual Wget's download behaviour.
References:
wget(1)
5.2 File download behaviour
===========================
When a Metalink/HTTP header is parsed:
1. extract metalink metadata from the header;
2. download the file from the mirror with the highest priority;
3. verify the file's size, if declared;
4. verify the file's checksum.
All the above comform to the usual Wget's download behaviour and to
the RFC6249 standard.
References:
wget(1)
https://tools.ietf.org/html/rfc6249
6. Directory Options
********************
'-nd'
'--no-directories'
Do not apply to Metalink/XML files (aka --input-metalink=<file>).
Apply to Metalink/HTTP urls as described in the Wget's manual, see
wget(1). The target url is the url wrote on the command line.
'-x'
'--force-directories'
Do not apply to Metalink/XML files (aka --input-metalink=<file>).
Apply to Metalink/HTTP urls as described in the Wget's manual, see
wget(1). The target url is the url wrote on the command line.
'-nH'
'--no-host-directories'
Do not apply to Metalink/XML files (aka --input-metalink=<file>).
Apply to Metalink/HTTP urls as described in the Wget's manual, see
wget(1). The target url is the url wrote on the command line.
'--protocol-directories'
Do not apply to Metalink/XML files (aka --input-metalink=<file>).
Apply to Metalink/HTTP urls as described in the Wget's manual, see
wget(1). The target url is the url wrote on the command line.
'--cut-dirs=number'
Do not apply to Metalink/XML files (aka --input-metalink=<file>).
Apply to Metalink/HTTP urls as described in the Wget's manual, see
wget(1). The target url is the url wrote on the command line.
'-P prefix'
'--directory-prefix=prefix'
Set the top of the retrieval tree to prefix for both Metalink/XML
and Metalink/HTTP downloads, see wget(1).
If combining the prefix with the file name results in an absolute,
relative, or home path, the directory components are stripped and
only the basename is used. See '4.1 Implemented safety features'.

View File

@@ -193,6 +193,8 @@ options, or via the initialization file @file{.wgetrc} (@pxref{Startup
File}). Wget allows you to define @dfn{global} startup files
(@file{/usr/local/etc/wgetrc} by default) for site settings. You can also
specify the location of a startup file with the --config option.
To disable the reading of config files, use --no-config.
If both --config and --no-config are given, --no-config is ignored.
@ignore
@@ -512,11 +514,27 @@ href if none was specified.
Downloads files covered in local Metalink @var{file}. Metalink version 3
and 4 are supported.
@cindex keep-badhash
@item --keep-badhash
Keeps downloaded Metalink's files with a bad hash. It appends .badhash
to the name of Metalink's files which have a checksum mismatch, except
without overwriting existing files.
@cindex metalink-over-http
@item --metalink-over-http
Issues HTTP HEAD request instead of GET and extracts Metalink metadata
from response headers. Then it switches to Metalink download.
If no valid Metalink metadata is found, it falls back to ordinary HTTP download.
Enables @samp{Content-Type: application/metalink4+xml} files download/processing.
@cindex metalink-index
@item --metalink-index=@var{number}
Set the Metalink @samp{application/metalink4+xml} metaurl ordinal
NUMBER. From 1 to the total number of ``application/metalink4+xml''
available. Specify 0 or @samp{inf} to choose the first good one.
Metaurls, such as those from a @samp{--metalink-over-http}, may have
been sorted by priority key's value; keep this in mind to choose the
right NUMBER.
@cindex preferred-location
@item --preferred-location
@@ -550,7 +568,10 @@ would be resolved to @samp{http://foo/baz/b.html}.
@cindex specify config
@item --config=@var{FILE}
Specify the location of a startup file you wish to use.
Specify the location of a startup file you wish to use instead of the
default one(s). Use --no-config to disable reading of config files.
If both --config and --no-config are given, --no-config is ignored.
@item --rejected-log=@var{logfile}
Logs all URL rejections to @var{logfile} as comma separated values. The values
@@ -687,6 +708,12 @@ Before (over)writing a file, back up an existing file by adding a
files are rotated to @samp{.2}, @samp{.3}, and so on, up to
@var{backups} (and lost beyond that).
@cindex authentication credentials
@item --no-netrc
Do not try to obtain credentials from @file{.netrc} file. By default
@file{.netrc} file is searched for credentials in case none have been
passed on command line and authentication is required.
@cindex continue retrieval
@cindex incomplete downloads
@cindex resume download
@@ -802,7 +829,7 @@ With @samp{--progress=bar}, there are currently two possible parameters,
@var{force} and @var{noscroll}.
When the output is not a TTY, the progress bar always falls back to ``dot'',
even if @samp{--progress=bar} was passed to Wget during invokation. This
even if @samp{--progress=bar} was passed to Wget during invocation. This
behaviour can be overridden and the ``bar'' output forced by using the ``force''
parameter as @samp{--progress=bar:force}.
@@ -1154,6 +1181,15 @@ options for @sc{http} connections.
Prompt for a password for each connection established. Cannot be specified
when @samp{--password} is being used, because they are mutually exclusive.
@item --use-askpass=@var{command}
Prompt for a user and password using the specified command. If no command is
specified then the command in the environment variable WGET_ASKPASS is used.
If WGET_ASKPASS is not set then the command in the environment variable
SSH_ASKPASS is used.
You can set the default command for use-askpass in the @file{.wgetrc}. That
setting may be overridden from the command line.
@cindex iri support
@cindex idn support
@item --no-iri
@@ -1310,6 +1346,11 @@ renamed from @samp{--html-extension}, to better reflect its new
behavior. The old option name is still acceptable, but should now be
considered deprecated.
As of version 1.19.2, Wget will also ensure that any downloaded files with
a @code{Content-Encoding} of @samp{br}, @samp{compress}, @samp{deflate}
or @samp{gzip} end in the suffix @samp{.br}, @samp{.Z}, @samp{.zlib}
and @samp{.gz} respectively.
At some point in the future, this option may well be expanded to
include suffixes for other types of content, including content types
that are not parsed by Wget.
@@ -1327,10 +1368,10 @@ the @code{digest}, or the Windows @code{NTLM} authentication scheme.
Another way to specify username and password is in the @sc{url} itself
(@pxref{URL Format}). Either method reveals your password to anyone who
bothers to run @code{ps}. To prevent the passwords from being seen,
store them in @file{.wgetrc} or @file{.netrc}, and make sure to protect
those files from other users with @code{chmod}. If the passwords are
really important, do not leave them lying in those files either---edit
the files and delete them after Wget has started the download.
use the @samp{--use-askpass} or store them in @file{.wgetrc} or @file{.netrc},
and make sure to protect those files from other users with @code{chmod}. If
the passwords are really important, do not leave them lying in those files
either---edit the files and delete them after Wget has started the download.
@iftex
@xref{Security Considerations}, for more information about security
@@ -1494,6 +1535,20 @@ wget --header="Host: foo.bar" http://localhost/
In versions of Wget prior to 1.10 such use of @samp{--header} caused
sending of duplicate headers.
@cindex Content-Encoding, choose
@item --compression=@var{type}
Choose the type of compression to be used. Legal values are
@samp{auto}, @samp{gzip} and @samp{none}.
If @samp{auto} or @samp{gzip} are specified, Wget asks the server to
compress the file using the gzip compression format. If the server
compresses the file and responds with the @code{Content-Encoding}
header field set appropriately, the file will be decompressed
automatically. This is the default.
If @samp{none} is specified, wget will not ask the server to compress
the file and will not decompress any server responses.
@cindex redirect
@item --max-redirect=@var{number}
Specifies the maximum number of redirections to follow for a resource.
@@ -1662,6 +1717,10 @@ This option is useful for some file-downloading CGI programs that use
@code{Content-Disposition} headers to describe what the name of a
downloaded file should be.
When combined with @samp{--metalink-over-http} and @samp{--trust-server-names},
a @samp{Content-Type: application/metalink4+xml} file is named using the
@code{Content-Disposition} filename field, if available.
@cindex Content On Error
@item --content-on-error
@@ -1671,9 +1730,11 @@ with a http status code that indicates error.
@cindex Trust server names
@item --trust-server-names
If this is set to on, on a redirect the last component of the
redirection URL will be used as the local file name. By default it is
used the last component in the original URL.
If this is set, on a redirect, the local file name will be based
on the redirection URL. By default the local file name is based on
the original URL. When doing recursive retrieving this can be helpful
because in many web sites redirected URLs correspond to an underlying
file structure, while link URLs do not.
@cindex authentication
@item --auth-no-challenge
@@ -1687,6 +1748,21 @@ some few obscure servers, which never send HTTP authentication
challenges, but accept unsolicited auth info, say, in addition to
form-based authentication.
@item --retry-on-http-error=@var{code[,code,...]}
Consider given HTTP response codes as non-fatal, transient errors.
Supply a comma-separated list of 3-digit HTTP response codes as
argument. Useful to work around special circumstances where retries
are required, but the server responds with an error code normally not
retried by Wget. Such errors might be 503 (Service Unavailable) and
429 (Too Many Requests). Retries enabled by this option are performed
subject to the normal retry timing and retry count limitations of
Wget.
Using this option is intended to support special use cases only and is
generally not recommended, as it can force retries even in cases where
the server is actually trying to decrease its load. Please use wisely
and only if you know what you are doing.
@end table
@node HTTPS (SSL/TLS) Options, FTP Options, HTTP Options, Invoking
@@ -3199,8 +3275,8 @@ Turn on recognition of the (non-standard) @samp{Content-Disposition}
HTTP header---if set to @samp{on}, the same as @samp{--content-disposition}.
@item trust_server_names = on/off
If set to on, use the last component of a redirection URL for the local
file name.
If set to on, construct the local file name from redirection URLs
rather than original URLs.
@item continue = on/off
If set to on, force continuation of preexistent partially retrieved
@@ -3306,10 +3382,16 @@ Turn globbing on/off---the same as @samp{--glob} and @samp{--no-glob}.
Define a header for HTTP downloads, like using
@samp{--header=@var{string}}.
@item compression = @var{string}
Choose the compression type to be used. Legal values are @samp{auto}
(the default), @samp{gzip}, and @samp{none}. The same as
@samp{--compression=@var{string}}.
@item adjust_extension = on/off
Add a @samp{.html} extension to @samp{text/html} or
@samp{application/xhtml+xml} files that lack one, or a @samp{.css}
extension to @samp{text/css} files that lack one, like
@samp{application/xhtml+xml} files that lack one, a @samp{.css}
extension to @samp{text/css} files that lack one, and a @samp{.br},
@samp{.Z}, @samp{.zlib} or @samp{.gz} to compressed files like
@samp{-E}. Previously named @samp{html_extension} (still acceptable,
but deprecated).
@@ -4220,7 +4302,7 @@ server.
Until version 1.8, Wget supported the first version of the standard,
written by Martijn Koster in 1994 and available at
@url{http://www.robotstxt.org/robotstxt.html}. As of version 1.8,
@url{http://www.robotstxt.org/orig.html}. As of version 1.8,
Wget has supported the additional directives specified in the internet
draft @samp{<draft-koster-robots-00.txt>} titled ``A Method for Web
Robots Control''. The draft, which has as far as I know never made to
@@ -4239,7 +4321,7 @@ this:
@end example
This is explained in some detail at
@url{http://www.robotstxt.org/wc/meta-user.html}. Wget supports this
@url{http://www.robotstxt.org/meta.html}. Wget supports this
method of robot exclusion in addition to the usual @file{/robots.txt}
exclusion.

2
gnulib

Submodule gnulib updated: 55c6f22b80...f497bc109a

View File

@@ -27,89 +27,6 @@ dnl Corresponding Source for a non-source form of such a combination
dnl shall include the source code for the parts of OpenSSL used as well
dnl as that of the covered work.
dnl
dnl Check for `struct utimbuf'.
dnl
AC_DEFUN([WGET_STRUCT_UTIMBUF], [
AC_CHECK_TYPES([struct utimbuf], [], [], [
#include <stdio.h>
#if HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif
#if HAVE_UTIME_H
# include <utime.h>
#endif
])
])
dnl Check whether fnmatch.h can be included. This doesn't use
dnl AC_FUNC_FNMATCH because Wget is already careful to only use
dnl fnmatch on certain OS'es. However, fnmatch.h is sometimes broken
dnl even on those because Apache installs its own fnmatch.h to
dnl /usr/local/include (!), which GCC uses before /usr/include.
AC_DEFUN([WGET_FNMATCH], [
AC_MSG_CHECKING([for working fnmatch.h])
AC_COMPILE_IFELSE([AC_LANG_SOURCE([#include <fnmatch.h>
])], [
AC_MSG_RESULT(yes)
AC_DEFINE([HAVE_WORKING_FNMATCH_H], 1,
[Define if fnmatch.h can be included.])
], [
AC_MSG_RESULT(no)
])
])
dnl Check for nanosleep. For nanosleep to work on Solaris, we must
dnl link with -lrt (recently) or with -lposix4 (older releases).
AC_DEFUN([WGET_NANOSLEEP], [
AC_CHECK_FUNCS(nanosleep, [], [
AC_CHECK_LIB(rt, nanosleep, [
AC_DEFINE([HAVE_NANOSLEEP], 1,
[Define if you have the nanosleep function.])
LIBS="-lrt $LIBS"
], [
AC_CHECK_LIB(posix4, nanosleep, [
AC_DEFINE([HAVE_NANOSLEEP], 1,
[Define if you have the nanosleep function.])
LIBS="-lposix4 $LIBS"
])
])
])
])
AC_DEFUN([WGET_POSIX_CLOCK], [
AC_CHECK_FUNCS(clock_gettime, [], [
AC_CHECK_LIB(rt, clock_gettime)
])
])
dnl Check whether we need to link with -lnsl and -lsocket, as is the
dnl case on e.g. Solaris.
AC_DEFUN([WGET_NSL_SOCKET], [
dnl On Solaris, -lnsl is needed to use gethostbyname. But checking
dnl for gethostbyname is not enough because on "NCR MP-RAS 3.0"
dnl gethostbyname is in libc, but -lnsl is still needed to use
dnl -lsocket, as well as for functions such as inet_ntoa. We look
dnl for such known offenders and if one of them is not found, we
dnl check if -lnsl is needed.
wget_check_in_nsl=NONE
AC_CHECK_FUNCS(gethostbyname, [], [
wget_check_in_nsl=gethostbyname
])
AC_CHECK_FUNCS(inet_ntoa, [], [
wget_check_in_nsl=inet_ntoa
])
if test $wget_check_in_nsl != NONE; then
AC_CHECK_LIB(nsl, $wget_check_in_nsl)
fi
AC_CHECK_LIB(socket, socket)
])
dnl ************************************************************
dnl START OF IPv6 AUTOCONFIGURATION SUPPORT MACROS
dnl ************************************************************

View File

@@ -35,7 +35,6 @@ src/ptimer.c
src/recur.c
src/res.c
src/retr.c
src/spider.c
src/url.c
src/utils.c
src/warc.c

View File

@@ -39,9 +39,12 @@ if METALINK_IS_ENABLED
METALINK_OBJ = metalink.c
endif
if WITH_XATTR
XATTR_OBJ = xattr.c
endif
# The following line is losing on some versions of make!
DEFS = @DEFS@ -DSYSTEM_WGETRC=\"$(sysconfdir)/wgetrc\" -DLOCALEDIR=\"$(localedir)\"
LIBS = @LIBICONV@ @LIBINTL@ @LIBS@ $(LIB_CLOCK_GETTIME)
EXTRA_DIST = css.l css.c css_.c build_info.c.in
@@ -50,17 +53,20 @@ wget_SOURCES = connect.c convert.c cookies.c ftp.c \
css_.c css-url.c \
ftp-basic.c ftp-ls.c hash.c host.c hsts.c html-parse.c html-url.c \
http.c init.c log.c main.c netrc.c progress.c ptimer.c \
recur.c res.c retr.c spider.c url.c warc.c \
recur.c res.c retr.c spider.c url.c warc.c $(XATTR_OBJ) \
utils.c exits.c build_info.c $(IRI_OBJ) $(METALINK_OBJ) \
css-url.h css-tokens.h connect.h convert.h cookies.h \
ftp.h hash.h host.h hsts.h html-parse.h html-url.h \
http.h http-ntlm.h init.h log.h mswindows.h netrc.h \
options.h progress.h ptimer.h recur.h res.h retr.h \
spider.h ssl.h sysdep.h url.h warc.h utils.h wget.h iri.h \
exits.h version.h metalink.h
exits.h version.h metalink.h xattr.h
nodist_wget_SOURCES = version.c
EXTRA_wget_SOURCES = iri.c
LDADD = $(LIBOBJS) ../lib/libgnu.a
LDADD = $(LIBOBJS) ../lib/libgnu.a $(GETADDRINFO_LIB) $(HOSTENT_LIB)\
$(INET_NTOP_LIB) $(LIBSOCKET) $(LIB_CLOCK_GETTIME) $(LIB_CRYPTO)\
$(LIB_NANOSLEEP) $(LIB_POSIX_SPAWN) $(LIB_SELECT) $(LIBICONV) $(LIBINTL)\
$(LIBTHREAD) $(LIBUNISTRING) $(SERVENT_LIB)
AM_CPPFLAGS = -I$(top_builddir)/lib -I$(top_srcdir)/lib

View File

@@ -31,6 +31,7 @@ as that of the covered work. */
#include "wget.h"
#include "exits.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
@@ -55,10 +56,6 @@ as that of the covered work. */
#include <string.h>
#include <sys/time.h>
#ifdef ENABLE_IRI
#include <idn-free.h>
#endif
#include "utils.h"
#include "host.h"
#include "connect.h"
@@ -279,11 +276,8 @@ connect_to_ip (const ip_address *ip, int port, const char *print)
if (opt.enable_iri && (name = idn_decode ((char *) print)) != NULL)
{
int len = strlen (print) + strlen (name) + 4;
str = xmalloc (len);
snprintf (str, len, "%s (%s)", name, print);
str[len-1] = '\0';
idn_free (name);
str = aprintf ("%s (%s)", name, print);
xfree (name);
}
logprintf (LOG_VERBOSE, _("Connecting to %s|%s|:%d... "),
@@ -331,8 +325,10 @@ connect_to_ip (const ip_address *ip, int port, const char *print)
if (bufsize < 512)
bufsize = 512; /* avoid pathologically small values */
#ifdef SO_RCVBUF
setsockopt (sock, SOL_SOCKET, SO_RCVBUF,
(void *)&bufsize, (socklen_t)sizeof (bufsize));
if (setsockopt (sock, SOL_SOCKET, SO_RCVBUF,
(void *) &bufsize, (socklen_t) sizeof (bufsize)))
logprintf (LOG_NOTQUIET, _("setsockopt SO_RCVBUF failed: %s\n"),
strerror (errno));
#endif
/* When we add limit_rate support for writing, which is useful
for POST, we should also set SO_SNDBUF here. */
@@ -471,7 +467,9 @@ bind_local (const ip_address *bind_address, int *port)
return -1;
#ifdef SO_REUSEADDR
setsockopt (sock, SOL_SOCKET, SO_REUSEADDR, setopt_ptr, setopt_size);
if (setsockopt (sock, SOL_SOCKET, SO_REUSEADDR, setopt_ptr, setopt_size))
logprintf (LOG_NOTQUIET, _("setsockopt SO_REUSEADDR failed: %s\n"),
strerror (errno));
#endif
xzero (ss);
@@ -689,6 +687,11 @@ select_fd (int fd, double maxtime, int wait_for)
struct timeval tmout;
int result;
if (fd >= FD_SETSIZE)
{
logprintf (LOG_NOTQUIET, _("Too many fds open. Cannot use select on a fd >= %d\n"), FD_SETSIZE);
exit (WGET_EXIT_GENERIC_ERROR);
}
FD_ZERO (&fdset);
FD_SET (fd, &fdset);
if (wait_for & WAIT_FOR_READ)
@@ -731,6 +734,11 @@ test_socket_open (int sock)
struct timeval to;
int ret = 0;
if (sock >= FD_SETSIZE)
{
logprintf (LOG_NOTQUIET, _("Too many fds open. Cannot use select on a fd >= %d\n"), FD_SETSIZE);
exit (WGET_EXIT_GENERIC_ERROR);
}
/* Check if we still have a valid (non-EOF) connection. From Andrew
* Maholski's code in the Unix Socket FAQ. */

View File

@@ -1024,7 +1024,7 @@ convert_cleanup (void)
/* This table should really be merged with dl_file_url_map and
downloaded_html_files. This was originally a list, but I changed
it to a hash table beause it was actually taking a lot of time to
it to a hash table because it was actually taking a lot of time to
find things in it. */
static struct hash_table *downloaded_files_hash;

View File

@@ -45,6 +45,7 @@ as that of the covered work. */
#include "wget.h"
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
@@ -484,7 +485,7 @@ parse_set_cookie (const char *set_cookie, bool silent)
/* Check whether ADDR matches <digits>.<digits>.<digits>.<digits>.
We don't want to call network functions like inet_addr() because
all we need is a check, preferrably one that is small, fast, and
all we need is a check, preferably one that is small, fast, and
well-defined. */
static bool
@@ -515,7 +516,7 @@ numeric_address_p (const char *addr)
psl on our own, if libpsl is compiled without a public suffix list,
fall back to using the original "tail matching" heuristic. Also if
libpsl is unable to convert the domain to lowercase, which means that
it doesnt have any runtime conversion support, we again fall back to
it doesn't have any runtime conversion support, we again fall back to
"tail matching" since libpsl states the results are unpredictable with
upper case strings.
*/
@@ -525,19 +526,51 @@ check_domain_match (const char *cookie_domain, const char *host)
{
#ifdef HAVE_LIBPSL
static int init_psl;
static const psl_ctx_t *psl;
char *cookie_domain_lower = NULL;
char *host_lower = NULL;
const psl_ctx_t *psl;
int is_acceptable;
DEBUGP (("cdm: 1"));
if (!(psl = psl_builtin()))
DEBUGP (("cdm: 1\n"));
if (!init_psl)
{
DEBUGP (("\nlibpsl not built with a public suffix list. "
"Falling back to simple heuristics.\n"));
goto no_psl;
}
init_psl = 1;
#ifdef HAVE_PSL_LATEST
if ((psl = psl_latest (NULL)))
goto have_psl;
DEBUGP (("\nPSL: Failed to load any PSL data. "
"Falling back to insecure heuristics.\n"));
#else
if ((psl = psl_builtin ()) && !psl_builtin_outdated ())
goto have_psl;
DEBUGP (("\nPSL: built-in data outdated. "
"Trying to load data from %s.\n",
quote (psl_builtin_filename ())));
if ((psl = psl_load_file (psl_builtin_filename ())))
goto have_psl;
DEBUGP (("\nPSL: %s not found or not readable. "
"Falling back to built-in data.\n",
quote (psl_builtin_filename ())));
if (!(psl = psl_builtin ()))
{
DEBUGP (("\nPSL: libpsl not built with a public suffix list. "
"Falling back to insecure heuristics.\n"));
goto no_psl;
}
#endif
}
else if (!psl)
goto no_psl;
have_psl:
if (psl_str_to_utf8lower (cookie_domain, NULL, NULL, &cookie_domain_lower) == PSL_SUCCESS &&
psl_str_to_utf8lower (host, NULL, NULL, &host_lower) == PSL_SUCCESS)
{
@@ -562,13 +595,13 @@ no_psl:
#endif
/* For efficiency make some elementary checks first */
DEBUGP (("cdm: 2"));
DEBUGP (("cdm: 2\n"));
/* For the sake of efficiency, check for exact match first. */
if (0 == strcasecmp (cookie_domain, host))
return true;
DEBUGP ((" 3"));
DEBUGP (("cdm: 3\n"));
/* HOST must match the tail of cookie_domain. */
if (!match_tail (host, cookie_domain, true))
@@ -608,7 +641,7 @@ no_psl:
if (*p == '.')
/* Ignore leading period in this calculation. */
++p;
DEBUGP ((" 4"));
DEBUGP (("cdm: 4\n"));
for (out = 0; !out; p++)
switch (*p)
{
@@ -634,12 +667,12 @@ no_psl:
++ldcl;
}
DEBUGP ((" 5"));
DEBUGP (("cdm: 5\n"));
if (dccount < 2)
return false;
DEBUGP ((" 6"));
DEBUGP (("cdm: 6\n"));
if (dccount == 2)
{
@@ -659,7 +692,7 @@ no_psl:
}
}
DEBUGP ((" 7"));
DEBUGP (("cdm: 7\n"));
/* Don't allow the host "foobar.com" to set a cookie for domain
"bar.com". */
@@ -674,7 +707,7 @@ no_psl:
return false;
}
DEBUGP ((" 8"));
DEBUGP (("cdm: 8\n"));
return true;
}
@@ -1018,7 +1051,7 @@ cookie_header (struct cookie_jar *jar, const char *host,
struct cookie *cookie;
struct weighed_cookie *outgoing;
int count, i, ocnt;
size_t count, i, ocnt;
char *result;
int result_size, pos;
PREPEND_SLASH (path); /* see cookie_handle_set_cookie */
@@ -1032,7 +1065,7 @@ cookie_header (struct cookie_jar *jar, const char *host,
chain_count = find_chains_of_host (jar, host, chains);
/* No cookies for this host. */
if (!chain_count)
if (chain_count <= 0)
return NULL;
cookies_now = time (NULL);
@@ -1043,7 +1076,7 @@ cookie_header (struct cookie_jar *jar, const char *host,
/* Count the number of matching cookies. */
count = 0;
for (i = 0; i < chain_count; i++)
for (i = 0; i < (unsigned) chain_count; i++)
for (cookie = chains[i]; cookie; cookie = cookie->next)
if (cookie_matches_url (cookie, host, port, path, secflag, NULL))
++count;
@@ -1051,12 +1084,14 @@ cookie_header (struct cookie_jar *jar, const char *host,
return NULL; /* no cookies matched */
/* Allocate the array. */
outgoing = alloca_array (struct weighed_cookie, count);
if (count > SIZE_MAX / sizeof (struct weighed_cookie))
return NULL; /* unable to process so many cookies */
outgoing = xmalloc (count * sizeof (struct weighed_cookie));
/* Fill the array with all the matching cookies from the chains that
match HOST. */
ocnt = 0;
for (i = 0; i < chain_count; i++)
for (i = 0; i < (unsigned) chain_count; i++)
for (cookie = chains[i]; cookie; cookie = cookie->next)
{
int pg;
@@ -1111,6 +1146,7 @@ cookie_header (struct cookie_jar *jar, const char *host,
}
}
result[pos++] = '\0';
xfree (outgoing);
assert (pos == result_size);
return result;
}

View File

@@ -59,6 +59,7 @@ extern char *yytext;
extern int yyleng;
typedef struct yy_buffer_state *YY_BUFFER_STATE;
extern YY_BUFFER_STATE yy_scan_bytes (const char *bytes,int len );
extern void yy_delete_buffer (YY_BUFFER_STATE b);
extern int yylex (void);
/*
@@ -109,9 +110,10 @@ get_urls_css (struct map_context *ctx, int offset, int buf_length)
int buffer_pos = 0;
int pos, length;
char *uri;
YY_BUFFER_STATE b;
/* tell flex to scan from this buffer */
yy_scan_bytes (ctx->text + offset, buf_length);
b = yy_scan_bytes (ctx->text + offset, buf_length);
while((token = yylex()) != CSSEOF)
{
@@ -188,6 +190,9 @@ get_urls_css (struct map_context *ctx, int offset, int buf_length)
}
buffer_pos += yyleng;
}
yy_delete_buffer(b);
DEBUGP (("\n"));
}

View File

@@ -31,7 +31,6 @@ as that of the covered work. */
#ifndef CSS_URL_H
#define CSS_URL_H
void get_urls_css (struct map_context *, int, int);
void get_urls_css (struct map_context *, int, int);
struct urlpos *get_urls_css_file (const char *, const char *);

View File

@@ -167,12 +167,12 @@ ftp_parse_unix_ls (const char *file, int ignore_perms)
/*cur.perms = 1023;*/ /* #### What is this? --hniksic */
cur.perms = 0644;
}
DEBUGP (("implicit perms %0o; ", cur.perms));
DEBUGP (("implicit perms %0o; ", (unsigned) cur.perms));
}
else
{
cur.perms = symperms (tok + 1);
DEBUGP (("perms %0o; ", cur.perms));
DEBUGP (("perms %0o; ", (unsigned) cur.perms));
}
error = ignore = 0; /* Erroneous and ignoring entries are
@@ -478,6 +478,7 @@ ftp_parse_winnt_ls (const char *file)
}
/* Now it is possible to determine the position of the first symbol in
filename. */
memset(&cur, 0, sizeof (cur));
cur.name = xstrdup(filename);
DEBUGP (("Name: '%s'\n", cur.name));
@@ -931,7 +932,7 @@ ftp_parse_vms_ls (const char *file)
}
}
cur.perms = perms;
DEBUGP (("Prot. perms = %0o.\n", cur.perms));
DEBUGP (("Prot. perms = %0o.\n", (unsigned) cur.perms));
}
else
{

View File

@@ -52,6 +52,9 @@ as that of the covered work. */
#include "recur.h" /* for INFINITE_RECURSION */
#include "warc.h"
#include "c-strcase.h"
#ifdef ENABLE_XATTR
#include "xattr.h"
#endif
#ifdef __VMS
# include "vms.h"
@@ -239,7 +242,7 @@ print_length (wgint size, wgint start, bool authoritative)
static uerr_t ftp_get_listing (struct url *, struct url *, ccon *, struct fileinfo **);
static uerr_t
get_ftp_greeting(int csock, ccon *con)
get_ftp_greeting (int csock, ccon *con)
{
uerr_t err = 0;
@@ -356,12 +359,35 @@ getftp (struct url *u, struct url *original_url,
*qtyread = restval;
user = u->user;
passwd = u->passwd;
search_netrc (u->host, (const char **)&user, (const char **)&passwd, 1);
user = user ? user : (opt.ftp_user ? opt.ftp_user : opt.user);
/* Find the username with priority */
if (u->user)
user = u->user;
else if (opt.user && (opt.use_askpass || opt.ask_passwd))
user = opt.user;
else if (opt.ftp_user)
user = opt.ftp_user;
else if (opt.user)
user = opt.user;
else
user = NULL;
/* Find the password with priority */
if (u->passwd)
passwd = u->passwd;
else if (opt.passwd && (opt.use_askpass || opt.ask_passwd))
passwd = opt.passwd;
else if (opt.ftp_passwd)
passwd = opt.ftp_passwd;
else if (opt.passwd)
passwd = opt.passwd;
else
passwd = NULL;
/* Check for ~/.netrc if none of the above match */
if (opt.netrc && (!user || !passwd))
search_netrc (u->host, (const char **) &user, (const char **) &passwd, 1);
if (!user) user = "anonymous";
passwd = passwd ? passwd : (opt.ftp_passwd ? opt.ftp_passwd : opt.passwd);
if (!passwd) passwd = "-wget@";
dtsock = -1;
@@ -535,10 +561,10 @@ Error in server response, closing control connection.\n"));
logputs (LOG_VERBOSE, "done.");
if (!opt.server_response)
logprintf (LOG_VERBOSE, " ==> PROT %c ... ", prot);
logprintf (LOG_VERBOSE, " ==> PROT %c ... ", (int) prot);
if ((err = ftp_prot (csock, prot)) == FTPNOPROT)
{
logprintf (LOG_NOTQUIET, _("Server did not accept the 'PROT %c' command.\n"), prot);
logprintf (LOG_NOTQUIET, _("Server did not accept the 'PROT %c' command.\n"), (int) prot);
return err;
}
if (!opt.server_response)
@@ -872,7 +898,7 @@ Error in server response, closing control connection.\n"));
Unlike the rest of this block, this particular behavior
_is_ VMS-specific, so it gets its own VMS test.
*/
if ((con->rs == ST_VMS) && (strchr( target, '/') != NULL))
if ((con->rs == ST_VMS) && (strchr (target, '/') != NULL))
{
cwd_end = 3;
DEBUGP (("Using extra \"CWD []\" step for VMS server.\n"));
@@ -1188,6 +1214,7 @@ Error in server response, closing control connection.\n"));
if (opt.spider)
{
bool exists = false;
bool all_exist = true;
struct fileinfo *f;
uerr_t _res = ftp_get_listing (u, original_url, con, &f);
/* Set the DO_RETR command flag again, because it gets unset when
@@ -1203,6 +1230,8 @@ Error in server response, closing control connection.\n"));
{
exists = true;
break;
} else {
all_exist = false;
}
f = f->next;
}
@@ -1223,7 +1252,11 @@ Error in server response, closing control connection.\n"));
con->csock = -1;
fd_close (dtsock);
fd_close (local_sock);
return RETRFINISHED;
if (all_exist) {
return RETRFINISHED;
} else {
return FTPNSFOD;
}
}
if (opt.verbose)
@@ -1430,7 +1463,7 @@ Error in server response, closing control connection.\n"));
else if (opt.noclobber || opt.always_rest || opt.timestamping || opt.dirstruct
|| opt.output_document || count > 0)
{
if (opt.unlink && file_exists_p (con->target))
if (opt.unlink_requested && file_exists_p (con->target, NULL))
{
if (unlink (con->target) < 0)
{
@@ -1546,6 +1579,11 @@ Error in server response, closing control connection.\n"));
tmrate = retr_rate (rd_size, con->dltime);
total_download_time += con->dltime;
#ifdef ENABLE_XATTR
if (opt.enable_xattr)
set_file_metadata (u->url, NULL, fp);
#endif
fd_close (local_sock);
/* Close the local file. */
if (!output_stream || con->cmd & DO_LIST)
@@ -1641,10 +1679,10 @@ Error in server response, closing control connection.\n"));
#ifdef __VMS
char *targ;
targ = ods_conform( con->target);
targ = ods_conform (con->target);
if (targ != con->target)
{
xfree( con->target);
xfree (con->target);
con->target = targ;
}
#endif /* def __VMS */
@@ -1788,7 +1826,7 @@ ftp_loop_internal (struct url *u, struct url *original_url, struct fileinfo *f,
char *tms, *locf;
const char *tmrate = NULL;
uerr_t err;
struct_stat st;
struct stat st;
/* Declare WARC variables. */
bool warc_enabled = (opt.warc_filename != NULL);
@@ -1819,7 +1857,7 @@ ftp_loop_internal (struct url *u, struct url *original_url, struct fileinfo *f,
/* If we receive .listing file it is necessary to determine system type of the ftp
server even if opn.noclobber is given. Thus we must ignore opt.noclobber in
order to establish connection with the server and get system type. */
if (opt.noclobber && !opt.output_document && file_exists_p (con->target)
if (opt.noclobber && !opt.output_document && file_exists_p (con->target, NULL)
&& !((con->cmd & DO_LIST) && !(con->cmd & DO_RETR)))
{
logprintf (LOG_VERBOSE,
@@ -2091,7 +2129,7 @@ Removing file due to --delete-after in ftp_loop_internal():\n"));
}
/* Return the directory listing in a reusable format. The directory
is specifed in u->dir. */
is specified in u->dir. */
static uerr_t
ftp_get_listing (struct url *u, struct url *original_url, ccon *con,
struct fileinfo **f)
@@ -2211,7 +2249,7 @@ ftp_retrieve_list (struct url *u, struct url *original_url,
dlthis = true;
if (opt.timestamping && f->type == FT_PLAINFILE)
{
struct_stat st;
struct stat st;
/* If conversion of HTML files retrieved via FTP is ever implemented,
we'll need to stat() <file>.orig here when -K has been specified.
I'm not implementing it now since files on an FTP server are much
@@ -2274,7 +2312,7 @@ The sizes do not match (local %s) -- retrieving.\n\n"),
_("Invalid name of the symlink, skipping.\n"));
else
{
struct_stat st;
struct stat st;
/* Check whether we already have the correct
symbolic link. */
int rc = lstat (con->target, &st);
@@ -2334,6 +2372,7 @@ Already have correct symlink %s -> %s\n\n"),
}
break;
case FT_UNKNOWN:
default:
logprintf (LOG_NOTQUIET, _("%s: unknown/unsupported file type.\n"),
quote (f->name));
break;
@@ -2355,7 +2394,12 @@ Already have correct symlink %s -> %s\n\n"),
(f->type == FT_PLAINFILE) && opt.preserve_perm)
{
if (f->perms)
chmod (actual_target, f->perms);
{
if (chmod (actual_target, f->perms))
logprintf (LOG_NOTQUIET,
_("Failed to set permissions for %s.\n"),
actual_target);
}
else
DEBUGP (("Unrecognized permissions for %s.\n", actual_target));
}
@@ -2369,7 +2413,7 @@ Already have correct symlink %s -> %s\n\n"),
&& !(f->type == FT_SYMLINK && !opt.retr_symlinks)
&& f->tstamp != -1
&& dlthis
&& file_exists_p (con->target))
&& file_exists_p (con->target, NULL))
{
touch (actual_target, f->tstamp);
}
@@ -2503,7 +2547,7 @@ is_invalid_entry (struct fileinfo *f)
while (cur->next)
{
cur = cur->next;
if (strcmp(f_name, cur->name) == 0)
if (strcmp (f_name, cur->name) == 0)
return true;
}
return false;
@@ -2697,7 +2741,7 @@ ftp_loop (struct url *u, struct url *original_url, char **local_file, int *dt,
{
if (!opt.output_document)
{
struct_stat st;
struct stat st;
wgint sz;
if (stat (filename, &st) == 0)
sz = st.st_size;

View File

@@ -50,7 +50,7 @@ as that of the covered work. */
#include "hash.h"
#include "ssl.h"
#include <sys/fcntl.h>
#include <fcntl.h>
#ifdef WIN32
# include "w32sock.h"
@@ -498,7 +498,7 @@ _do_handshake (gnutls_session_t session, int fd, double timeout)
{
gnutls_alert_description_t alert = gnutls_alert_get (session);
const char *str = gnutls_alert_get_name (alert);
logprintf (LOG_NOTQUIET, "GnuTLS: received alert [%d]: %s\n",
logprintf (LOG_NOTQUIET, "GnuTLS: received alert [%u]: %s\n",
alert, str ? str : "(unknown)");
}
}
@@ -556,7 +556,6 @@ ssl_connect_wget (int fd, const char *hostname, int *continue_session)
xfree(sni_hostname);
}
gnutls_set_default_priority (session);
gnutls_credentials_set (session, GNUTLS_CRD_CERTIFICATE, credentials);
#ifndef FD_TO_SOCKET
# define FD_TO_SOCKET(X) (X)
@@ -571,7 +570,8 @@ ssl_connect_wget (int fd, const char *hostname, int *continue_session)
switch (opt.secure_protocol)
{
case secure_protocol_auto:
err = gnutls_priority_set_direct (session, "NORMAL:%COMPAT:-VERS-SSL3.0", NULL);
err = gnutls_set_default_priority (session);
gnutls_session_enable_compatibility_mode(session);
break;
case secure_protocol_sslv2:
@@ -599,7 +599,8 @@ ssl_connect_wget (int fd, const char *hostname, int *continue_session)
break;
default:
logprintf (LOG_NOTQUIET, _("GnuTLS: unimplemented 'secure-protocol' option value %d\n"), opt.secure_protocol);
logprintf (LOG_NOTQUIET, _("GnuTLS: unimplemented 'secure-protocol' option value %u\n"),
(unsigned) opt.secure_protocol);
logprintf (LOG_NOTQUIET, _("Please report this issue to bug-wget@gnu.org\n"));
abort ();
}
@@ -608,6 +609,7 @@ ssl_connect_wget (int fd, const char *hostname, int *continue_session)
switch (opt.secure_protocol)
{
case secure_protocol_auto:
err = gnutls_set_default_priority (session);
break;
case secure_protocol_sslv2:

View File

@@ -283,10 +283,10 @@ hash_table_new (int items,
/* Calculate the size that ensures that the table will store at
least ITEMS keys without the need to resize. */
size = 1 + items / HASH_MAX_FULLNESS;
size = (int) (1 + items / HASH_MAX_FULLNESS);
size = prime_size (size, &ht->prime_offset);
ht->size = size;
ht->resize_threshold = size * HASH_MAX_FULLNESS;
ht->resize_threshold = (int) (size * HASH_MAX_FULLNESS);
/*assert (ht->resize_threshold >= items);*/
ht->cells = xnew_array (struct cell, ht->size);
@@ -394,7 +394,7 @@ grow_hash_table (struct hash_table *ht)
#endif
ht->size = newsize;
ht->resize_threshold = newsize * HASH_MAX_FULLNESS;
ht->resize_threshold = (int) (newsize * HASH_MAX_FULLNESS);
cells = xnew_array (struct cell, newsize);
memset (cells, INVALID_PTR_CHAR, newsize * sizeof (struct cell));

View File

@@ -57,10 +57,6 @@ as that of the covered work. */
#include <errno.h>
#ifdef ENABLE_IRI
#include <idn-free.h>
#endif
#include "utils.h"
#include "host.h"
#include "url.h"
@@ -428,14 +424,12 @@ getaddrinfo_with_timeout (const char *node, const char *service,
const char *
print_address (const ip_address *addr)
{
#ifdef ENABLE_IPV6
static char buf[64];
if (!inet_ntop (addr->family, IP_INADDR_DATA (addr), buf, sizeof buf))
snprintf (buf, sizeof buf, "<error: %s>", strerror (errno));
return buf;
#else
return inet_ntoa (addr->data.d4);
#endif
}
/* The following two functions were adapted from glibc's
@@ -848,11 +842,8 @@ lookup_host (const char *host, int flags)
if (opt.enable_iri && (name = idn_decode ((char *) host)) != NULL)
{
int len = strlen (host) + strlen (name) + 4;
str = xmalloc (len);
snprintf (str, len, "%s (%s)", name, host);
str[len-1] = '\0';
idn_free (name);
str = aprintf ("%s (%s)", name, host);
xfree (name);
}
logprintf (LOG_VERBOSE, _("Resolving %s... "),

View File

@@ -32,9 +32,9 @@ as that of the covered work. */
#ifdef HAVE_HSTS
#include "hsts.h"
#include "utils.h"
#include "host.h" /* for is_valid_ip_address() */
#include "init.h" /* for home_dir() */
#include "utils.h"
#include "hash.h"
#include "c-ctype.h"
#ifdef TESTING
@@ -80,7 +80,6 @@ enum hsts_kh_match {
#define DEFAULT_HTTP_PORT 80
#define DEFAULT_SSL_PORT 443
#define CHECK_EXPLICIT_PORT(p1, p2) (p1 == 0 || p1 == p2)
#define MAKE_EXPLICIT_PORT(s, p) (s == SCHEME_HTTPS ? (p == DEFAULT_SSL_PORT ? 0 : p) \
: (p == DEFAULT_HTTP_PORT ? 0 : p))
@@ -327,7 +326,8 @@ hsts_store_dump (hsts_store_t store, FILE *fp)
if (fprintf (fp, "%s\t%d\t%d\t%lu\t%lu\n",
kh->host, kh->explicit_port, khi->include_subdomains,
khi->created, khi->max_age) < 0)
(unsigned long) khi->created,
(unsigned long) khi->max_age) < 0)
{
logprintf (LOG_ALWAYS, "Could not write the HSTS database correctly.\n");
break;
@@ -343,12 +343,20 @@ hsts_store_dump (hsts_store_t store, FILE *fp)
static bool
hsts_file_access_valid (const char *filename)
{
struct_stat st;
struct stat st;
if (stat (filename, &st) == -1)
return false;
return !(st.st_mode & S_IWOTH) && S_ISREG (st.st_mode);
return
#ifndef WINDOWS
/*
* The world-writable concept is a Unix-centric notion.
* We bypass this test on Windows.
*/
!(st.st_mode & S_IWOTH) &&
#endif
S_ISREG (st.st_mode);
}
/* HSTS API */
@@ -435,7 +443,6 @@ hsts_store_entry (hsts_store_t store,
enum hsts_kh_match match = NO_MATCH;
struct hsts_kh *kh = xnew(struct hsts_kh);
struct hsts_kh_info *entry = NULL;
time_t t = 0;
if (hsts_is_host_eligible (scheme, host))
{
@@ -450,17 +457,18 @@ hsts_store_entry (hsts_store_t store,
}
else if (max_age > 0)
{
if (entry->max_age != max_age ||
entry->include_subdomains != include_subdomains)
/* RFC 6797 states that 'max_age' is a TTL relative to the
* reception of the STS header so we have to update the
* 'created' field too. The RFC also states that we have to
* update the entry each time we see HSTS header.
* See also Section 11.2. */
time_t t = time (NULL);
if (t != -1 && t != entry->created)
{
/* RFC 6797 states that 'max_age' is a TTL relative to the reception of the STS header
so we have to update the 'created' field too */
t = time (NULL);
if (t != -1)
entry->created = t;
entry->created = t;
entry->max_age = max_age;
entry->include_subdomains = include_subdomains;
store->changed = true;
}
}
@@ -492,25 +500,27 @@ hsts_store_t
hsts_store_open (const char *filename)
{
hsts_store_t store = NULL;
file_stats_t fstats;
store = xnew0 (struct hsts_store);
store->table = hash_table_new (0, hsts_hash_func, hsts_cmp_func);
store->last_mtime = 0;
store->changed = false;
if (file_exists_p (filename))
if (file_exists_p (filename, &fstats))
{
if (hsts_file_access_valid (filename))
{
struct_stat st;
FILE *fp = fopen (filename, "r");
struct stat st;
FILE *fp = fopen_stat (filename, "r", &fstats);
if (!fp || !hsts_read_database (store, fp, false))
{
/* abort! */
hsts_store_close (store);
xfree (store);
fclose (fp);
if (fp)
fclose (fp);
goto out;
}
@@ -540,7 +550,7 @@ out:
void
hsts_store_save (hsts_store_t store, const char *filename)
{
struct_stat st;
struct stat st;
FILE *fp = NULL;
int fd = 0;
@@ -790,9 +800,9 @@ test_hsts_read_database (void)
if (fp)
{
fputs ("# dummy comment\n", fp);
fprintf (fp, "foo.example.com\t0\t1\t%ld\t123\n",(long) created);
fprintf (fp, "bar.example.com\t0\t0\t%ld\t456\n", (long) created);
fprintf (fp, "test.example.com\t8080\t0\t%ld\t789\n", (long) created);
fprintf (fp, "foo.example.com\t0\t1\t%lu\t123\n",(unsigned long) created);
fprintf (fp, "bar.example.com\t0\t0\t%lu\t456\n", (unsigned long) created);
fprintf (fp, "test.example.com\t8080\t0\t%lu\t789\n", (unsigned long) created);
fclose (fp);
table = hsts_store_open (file);

View File

@@ -176,8 +176,8 @@ struct pool {
P->orig_size = P->size; \
} while (0)
/* Grow the pool to accomodate at least SIZE new bytes. If the pool
already has room to accomodate SIZE bytes of data, this is a no-op. */
/* Grow the pool to accommodate at least SIZE new bytes. If the pool
already has room to accommodate SIZE bytes of data, this is a no-op. */
#define POOL_GROW(p, increase) \
GROW_ARRAY ((p)->contents, (p)->size, (p)->tail + (increase), \
@@ -801,14 +801,6 @@ name_allowed (const struct hash_table *ht, const char *b, const char *e)
} \
} while (0)
/* Skip non-whitespace, if any. */
#define SKIP_NON_WS(p) do { \
while (!c_isspace (*p)) { \
ADVANCE (p); \
} \
} while (0)
#ifdef STANDALONE
static int tag_backout_count;
#endif

View File

@@ -729,8 +729,11 @@ tag_handle_img (int tagid, struct taginfo *tag, struct map_context *ctx) {
srcset + url_end);
struct urlpos *up = append_url (url_text, base_ind + url_start,
url_end - url_start, ctx);
up->link_inline_p = 1;
up->link_noquote_html_p = 1;
if (up)
{
up->link_inline_p = 1;
up->link_noquote_html_p = 1;
}
xfree (url_text);
}
@@ -842,6 +845,7 @@ get_urls_html (const char *file, const char *url, bool *meta_disallow_follow,
if (iri && !iri->content_encoding && meta_charset)
set_content_encoding (iri, meta_charset);
#endif
xfree (meta_charset);
DEBUGP (("no-follow in %s: %d\n", file, ctx.nofollow));
if (meta_disallow_follow)

View File

@@ -122,7 +122,7 @@ ntlm_input (struct ntlmdata *ntlm, const char *header)
DEBUGP (("Received a type-2 NTLM message.\n"));
size = base64_decode (header, buffer);
size = wget_base64_decode (header, buffer, strlen (header));
if (size < 0)
return false; /* malformed base64 from server */
@@ -411,7 +411,7 @@ ntlm_output (struct ntlmdata *ntlm, const char *user, const char *passwd,
size = 32 + hostlen + domlen;
base64 = (char *) alloca (BASE64_LENGTH (size) + 1);
base64_encode (ntlmbuf, size, base64);
wget_base64_encode (ntlmbuf, size, base64);
output = concat_strings ("NTLM ", base64, (char *) 0);
break;
@@ -584,7 +584,7 @@ ntlm_output (struct ntlmdata *ntlm, const char *user, const char *passwd,
/* convert the binary blob into base64 */
base64 = (char *) alloca (BASE64_LENGTH (size) + 1);
base64_encode (ntlmbuf, size, base64);
wget_base64_encode (ntlmbuf, size, base64);
output = concat_strings ("NTLM ", base64, (char *) 0);

File diff suppressed because it is too large Load Diff

View File

@@ -35,7 +35,7 @@ as that of the covered work. */
struct url;
uerr_t http_loop (struct url *, struct url *, char **, char **, const char *,
uerr_t http_loop (const struct url *, struct url *, char **, char **, const char *,
int *, struct url *, struct iri *);
void save_cookies (void);
void http_cleanup (void);

View File

@@ -97,6 +97,11 @@ CMD_DECLARE (cmd_directory);
CMD_DECLARE (cmd_time);
CMD_DECLARE (cmd_vector);
CMD_DECLARE (cmd_use_askpass);
#ifdef HAVE_LIBZ
CMD_DECLARE (cmd_spec_compression);
#endif
CMD_DECLARE (cmd_spec_dirstruct);
CMD_DECLARE (cmd_spec_header);
CMD_DECLARE (cmd_spec_warc_header);
@@ -159,6 +164,9 @@ static const struct {
{ "checkcertificate", &opt.check_cert, cmd_check_cert },
#endif
{ "chooseconfig", &opt.choose_config, cmd_file },
#ifdef HAVE_LIBZ
{ "compression", &opt.compression, cmd_spec_compression },
#endif
{ "connecttimeout", &opt.connect_timeout, cmd_time },
{ "contentdisposition", &opt.content_disposition, cmd_boolean },
{ "contentonerror", &opt.content_on_error, cmd_boolean },
@@ -210,7 +218,7 @@ static const struct {
{ "header", NULL, cmd_spec_header },
#ifdef HAVE_HSTS
{ "hsts", &opt.hsts, cmd_boolean },
{ "hsts-file", &opt.hsts_file, cmd_file },
{ "hstsfile", &opt.hsts_file, cmd_file },
#endif
{ "htmlextension", &opt.adjust_extension, cmd_boolean }, /* deprecated */
{ "htmlify", NULL, cmd_spec_htmlify },
@@ -223,7 +231,7 @@ static const struct {
#endif
{ "httpsproxy", &opt.https_proxy, cmd_string },
{ "httpuser", &opt.http_user, cmd_string },
{ "if-modified-since", &opt.if_modified_since, cmd_boolean },
{ "ifmodifiedsince", &opt.if_modified_since, cmd_boolean },
{ "ignorecase", &opt.ignore_case, cmd_boolean },
{ "ignorelength", &opt.ignore_length, cmd_boolean },
{ "ignoretags", &opt.ignore_tags, cmd_vector },
@@ -234,9 +242,10 @@ static const struct {
#endif
{ "input", &opt.input_filename, cmd_file },
#ifdef HAVE_METALINK
{ "input-metalink", &opt.input_metalink, cmd_file },
{ "inputmetalink", &opt.input_metalink, cmd_file },
#endif
{ "iri", &opt.enable_iri, cmd_boolean },
{ "keepbadhash", &opt.keep_badhash, cmd_boolean },
{ "keepsessioncookies", &opt.keep_session_cookies, cmd_boolean },
{ "limitrate", &opt.limit_rate, cmd_bytes },
{ "loadcookies", &opt.cookies_input, cmd_file },
@@ -245,7 +254,8 @@ static const struct {
{ "login", &opt.ftp_user, cmd_string },/* deprecated*/
{ "maxredirect", &opt.max_redirect, cmd_number },
#ifdef HAVE_METALINK
{ "metalink-over-http", &opt.metalink_over_http, cmd_boolean },
{ "metalinkindex", &opt.metalink_index, cmd_number_inf },
{ "metalinkoverhttp", &opt.metalink_over_http, cmd_boolean },
#endif
{ "method", &opt.method, cmd_string_uppercase },
{ "mirror", NULL, cmd_spec_mirror },
@@ -267,7 +277,7 @@ static const struct {
{ "postfile", &opt.post_file_name, cmd_file },
{ "preferfamily", NULL, cmd_spec_prefer_family },
#ifdef HAVE_METALINK
{ "preferred-location", &opt.preferred_location, cmd_string },
{ "preferredlocation", &opt.preferred_location, cmd_string },
#endif
{ "preservepermissions", &opt.preserve_perm, cmd_boolean },
#ifdef HAVE_SSL
@@ -300,6 +310,7 @@ static const struct {
{ "restrictfilenames", NULL, cmd_spec_restrict_file_names },
{ "retrsymlinks", &opt.retr_symlinks, cmd_boolean },
{ "retryconnrefused", &opt.retry_connrefused, cmd_boolean },
{ "retryonhttperror", &opt.retry_on_http_error, cmd_string },
{ "robots", &opt.use_robots, cmd_boolean },
{ "savecookies", &opt.cookies_output, cmd_file },
{ "saveheaders", &opt.save_headers, cmd_boolean },
@@ -317,7 +328,8 @@ static const struct {
{ "timestamping", &opt.timestamping, cmd_boolean },
{ "tries", &opt.ntry, cmd_number_inf },
{ "trustservernames", &opt.trustservernames, cmd_boolean },
{ "unlink", &opt.unlink, cmd_boolean },
{ "unlink", &opt.unlink_requested, cmd_boolean },
{ "useaskpass" , &opt.use_askpass, cmd_use_askpass },
{ "useproxy", &opt.use_proxy, cmd_boolean },
{ "user", &opt.user, cmd_string },
{ "useragent", NULL, cmd_spec_useragent },
@@ -339,6 +351,9 @@ static const struct {
#ifdef USE_WATT32
{ "wdebug", &opt.wdebug, cmd_boolean },
#endif
#ifdef ENABLE_XATTR
{ "xattr", &opt.enable_xattr, cmd_boolean },
#endif
};
/* Look up CMDNAME in the commands[] and return its position in the
@@ -378,6 +393,10 @@ defaults (void)
bit pattern will be the least of the implementors' worries. */
xzero (opt);
#ifdef HAVE_METALINK
opt.metalink_index = -1;
#endif
opt.cookies = true;
opt.verbose = -1;
opt.ntry = 20;
@@ -432,6 +451,10 @@ defaults (void)
opt.ftps_clear_data_connection = false;
#endif
#ifdef HAVE_LIBZ
opt.compression = compression_auto;
#endif
/* The default for file name restriction defaults to the OS type. */
#if defined(WINDOWS) || defined(MSDOS) || defined(__CYGWIN__)
opt.restrict_files_os = restrict_windows;
@@ -482,6 +505,12 @@ defaults (void)
/* HSTS is enabled by default */
opt.hsts = true;
#endif
#ifdef ENABLE_XATTR
opt.enable_xattr = true;
#else
opt.enable_xattr = false;
#endif
}
/* Return the user's home directory (strdup-ed), or NULL if none is
@@ -547,10 +576,11 @@ wgetrc_env_file_name (void)
char *env = getenv ("WGETRC");
if (env && *env)
{
if (!file_exists_p (env))
file_stats_t flstat;
if (!file_exists_p (env, &flstat))
{
fprintf (stderr, _("%s: WGETRC points to %s, which doesn't exist.\n"),
exec_name, env);
fprintf (stderr, _("%s: WGETRC points to %s, which couldn't be accessed because of error: %s.\n"),
exec_name, env, strerror(flstat.access_err));
exit (WGET_EXIT_GENERIC_ERROR);
}
return xstrdup (env);
@@ -558,7 +588,7 @@ wgetrc_env_file_name (void)
return NULL;
}
/* Check for the existance of '$HOME/.wgetrc' and return its path
/* Check for the existence of '$HOME/.wgetrc' and return its path
if it exists and is set. */
char *
wgetrc_user_file_name (void)
@@ -578,7 +608,7 @@ wgetrc_user_file_name (void)
if (!file)
return NULL;
if (!file_exists_p (file))
if (!file_exists_p (file, NULL))
{
xfree (file);
return NULL;
@@ -611,7 +641,7 @@ wgetrc_file_name (void)
if (home)
{
file = aprintf ("%s/wget.ini", home);
if (!file_exists_p (file))
if (!file_exists_p (file, NULL))
{
xfree (file);
}
@@ -639,7 +669,7 @@ static bool setval_internal_tilde (int, const char *, const char *);
there were errors in the file. */
bool
run_wgetrc (const char *file)
run_wgetrc (const char *file, file_stats_t *flstats)
{
FILE *fp;
char *line = NULL;
@@ -647,7 +677,7 @@ run_wgetrc (const char *file)
int ln;
int errcnt = 0;
fp = fopen (file, "r");
fp = fopen_stat (file, "r", flstats);
if (!fp)
{
fprintf (stderr, _("%s: Cannot read %s (%s).\n"), exec_name,
@@ -703,14 +733,16 @@ void
initialize (void)
{
char *file, *env_sysrc;
file_stats_t flstats;
bool ok = true;
memset(&flstats, 0, sizeof(flstats));
/* Run a non-standard system rc file when the according environment
variable has been set. For internal testing purposes only! */
env_sysrc = getenv ("SYSTEM_WGETRC");
if (env_sysrc && file_exists_p (env_sysrc))
if (env_sysrc && file_exists_p (env_sysrc, &flstats))
{
ok &= run_wgetrc (env_sysrc);
ok &= run_wgetrc (env_sysrc, &flstats);
/* If there are any problems parsing the system wgetrc file, tell
the user and exit */
if (! ok)
@@ -724,8 +756,8 @@ or specify a different file using --config.\n"), env_sysrc);
}
/* Otherwise, if SYSTEM_WGETRC is defined, use it. */
#ifdef SYSTEM_WGETRC
else if (file_exists_p (SYSTEM_WGETRC))
ok &= run_wgetrc (SYSTEM_WGETRC);
else if (file_exists_p (SYSTEM_WGETRC, &flstats))
ok &= run_wgetrc (SYSTEM_WGETRC, &flstats);
/* If there are any problems parsing the system wgetrc file, tell
the user and exit */
if (! ok)
@@ -752,7 +784,8 @@ or specify a different file using --config.\n"), SYSTEM_WGETRC);
}
else
#endif
ok &= run_wgetrc (file);
if (file_exists_p (file, &flstats))
ok &= run_wgetrc (file, &flstats);
/* If there were errors processing either `.wgetrc', abort. */
if (!ok)
@@ -859,6 +892,10 @@ static bool
setval_internal (int comind, const char *com, const char *val)
{
assert (0 <= comind && ((size_t) comind) < countof (commands));
if ((unsigned) comind >= countof (commands))
return NULL;
DEBUGP (("Setting %s (%s) to %s\n", com, commands[comind].name, val));
return commands[comind].action (com, val, commands[comind].place);
}
@@ -1371,6 +1408,32 @@ cmd_time (const char *com, const char *val, void *place)
return true;
}
static bool
cmd_use_askpass (const char *com _GL_UNUSED, const char *val, void *place)
{
const char *env_name = "WGET_ASKPASS";
const char *env;
if (val && *val)
return cmd_string (com, val, place);
env = getenv (env_name);
if (!(env && *env))
{
env_name = "SSH_ASKPASS";
env = getenv (env_name);
}
if (!(env && *env))
{
fprintf (stderr, _("use-askpass requires a string or either environment variable WGET_ASKPASS or SSH_ASKPASS to be set.\n"));
exit (WGET_EXIT_GENERIC_ERROR);
}
return cmd_string (com, env, place);
}
#ifdef HAVE_SSL
static bool
cmd_cert_type (const char *com, const char *val, void *place)
@@ -1392,6 +1455,25 @@ cmd_cert_type (const char *com, const char *val, void *place)
static bool check_user_specified_header (const char *);
#ifdef HAVE_LIBZ
static bool
cmd_spec_compression (const char *com, const char *val, void *place)
{
static const struct decode_item choices[] = {
{ "auto", compression_auto },
{ "gzip", compression_gzip },
{ "none", compression_none },
};
int ok = decode_string (val, choices, countof (choices), place);
if (!ok)
{
fprintf (stderr, _("%s: %s: Invalid value %s.\n"), exec_name, com,
quote (val));
}
return ok;
}
#endif
static bool
cmd_spec_dirstruct (const char *com, const char *val, void *place_ignored _GL_UNUSED)
{
@@ -1930,6 +2012,8 @@ cleanup (void)
xfree (opt.body_data);
xfree (opt.body_file);
xfree (opt.rejected_log);
xfree (opt.use_askpass);
xfree (opt.retry_on_http_error);
#ifdef HAVE_LIBCARES
#include <ares.h>

View File

@@ -41,6 +41,6 @@ void setoptval (const char *, const char *, const char *);
char *home_dir (void);
void cleanup (void);
void defaults (void);
bool run_wgetrc (const char *file);
bool run_wgetrc (const char *file, file_stats_t *);
#endif /* INIT_H */

151
src/iri.c
View File

@@ -33,11 +33,16 @@ as that of the covered work. */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iconv.h>
#include <stringprep.h>
#include <idna.h>
#include <idn-free.h>
#include <langinfo.h>
#include <errno.h>
#ifdef HAVE_ICONV
# include <iconv.h>
#endif
#include <idn2.h>
#if IDN2_VERSION_NUMBER < 0x00140000
# include <unicase.h>
# include <unistr.h>
#endif
#include "utils.h"
#include "url.h"
@@ -45,9 +50,6 @@ as that of the covered work. */
#include "c-strcasestr.h"
#include "xstrndup.h"
/* RFC3987 section 3.1 mandates STD3 ASCII RULES */
#define IDNA_FLAGS IDNA_USE_STD3_ASCII_RULES
/* Note: locale encoding is kept in options struct (opt.locale) */
/* Given a string containing "charset=XXX", return the encoding if found,
@@ -88,10 +90,15 @@ parse_charset (const char *str)
}
/* Find the locale used, or fall back on a default value */
char *
const char *
find_locale (void)
{
return (char *) stringprep_locale_charset ();
const char *encoding = nl_langinfo(CODESET);
if (!encoding || !*encoding)
return "ASCII";
return encoding;
}
/* Basic check of an encoding name. */
@@ -114,6 +121,7 @@ check_encoding_name (const char *encoding)
return true;
}
#ifdef HAVE_ICONV
/* Do the conversion according to the passed conversion descriptor cd. *out
will contain the transcoded string on success. *out content is
unspecified otherwise. */
@@ -146,7 +154,7 @@ do_conversion (const char *tocode, const char *fromcode, char const *in_org, siz
for (;;)
{
if (iconv (cd, &in, &inlen, out, &outlen) != (size_t)(-1) &&
if (iconv (cd, (ICONV_CONST char **) &in, &inlen, out, &outlen) != (size_t)(-1) &&
iconv (cd, NULL, NULL, out, &outlen) != (size_t)(-1))
{
*out = s;
@@ -159,7 +167,7 @@ do_conversion (const char *tocode, const char *fromcode, char const *in_org, siz
if (!strchr(in_org, '@') && !strchr(*out, '@'))
debug_logprintf ("converted '%s' (%s) -> '%s' (%s)\n", in_org, fromcode, *out, tocode);
else
debug_logprintf ("%s: logging suppressed, strings may contain password\n", __func__);
debug_logprintf ("logging suppressed, strings may contain password\n");
}
return true;
}
@@ -201,10 +209,19 @@ do_conversion (const char *tocode, const char *fromcode, char const *in_org, siz
if (!strchr(in_org, '@') && !strchr(*out, '@'))
debug_logprintf ("converted '%s' (%s) -> '%s' (%s)\n", in_org, fromcode, *out, tocode);
else
debug_logprintf ("%s: logging suppressed, strings may contain password\n", __func__);
debug_logprintf ("logging suppressed, strings may contain password\n");
}
return false;
}
#else
static bool
do_conversion (const char *tocode _GL_UNUSED, const char *fromcode _GL_UNUSED,
char const *in_org _GL_UNUSED, size_t inlen _GL_UNUSED, char **out)
{
*out = NULL;
return false;
}
#endif
/* Try converting string str from locale to UTF-8. Return a new string
on success, or str on error or if conversion isn't needed. */
@@ -230,50 +247,6 @@ locale_to_utf8 (const char *str)
return str;
}
/*
* Work around a libidn <= 1.30 vulnerability.
*
* The function checks for a valid UTF-8 character sequence before
* passing it to idna_to_ascii_8z().
*
* [1] http://lists.gnu.org/archive/html/help-libidn/2015-05/msg00002.html
* [2] https://lists.gnu.org/archive/html/bug-wget/2015-06/msg00002.html
* [3] http://curl.haxx.se/mail/lib-2015-06/0143.html
*/
static bool
_utf8_is_valid(const char *utf8)
{
const unsigned char *s = (const unsigned char *) utf8;
while (*s)
{
if ((*s & 0x80) == 0) /* 0xxxxxxx ASCII char */
s++;
else if ((*s & 0xE0) == 0xC0) /* 110xxxxx 10xxxxxx */
{
if ((s[1] & 0xC0) != 0x80)
return false;
s+=2;
}
else if ((*s & 0xF0) == 0xE0) /* 1110xxxx 10xxxxxx 10xxxxxx */
{
if ((s[1] & 0xC0) != 0x80 || (s[2] & 0xC0) != 0x80)
return false;
s+=3;
}
else if ((*s & 0xF8) == 0xF0) /* 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx */
{
if ((s[1] & 0xC0) != 0x80 || (s[2] & 0xC0) != 0x80 || (s[3] & 0xC0) != 0x80)
return false;
s+=4;
}
else
return false;
}
return true;
}
/* Try to "ASCII encode" UTF-8 host. Return the new domain on success or NULL
on error. */
char *
@@ -282,34 +255,62 @@ idn_encode (const struct iri *i, const char *host)
int ret;
char *ascii_encoded;
char *utf8_encoded = NULL;
const char *src;
#if IDN2_VERSION_NUMBER < 0x00140000
uint8_t *lower;
size_t len = 0;
#endif
/* Encode to UTF-8 if not done */
if (!i->utf8_encode)
{
if (!remote_to_utf8 (i, host, &utf8_encoded))
return NULL; /* Nothing to encode or an error occured */
return NULL; /* Nothing to encode or an error occurred */
src = utf8_encoded;
}
else
src = host;
if (!_utf8_is_valid(utf8_encoded ? utf8_encoded : host))
#if IDN2_VERSION_NUMBER >= 0x00140000
/* IDN2_TRANSITIONAL implies input NFC encoding */
ret = idn2_lookup_u8 ((uint8_t *) src, (uint8_t **) &ascii_encoded, IDN2_NONTRANSITIONAL);
if (ret != IDN2_OK)
/* fall back to TR46 Transitional mode, max IDNA2003 compatibility */
ret = idn2_lookup_u8 ((uint8_t *) src, (uint8_t **) &ascii_encoded, IDN2_TRANSITIONAL);
if (ret != IDN2_OK)
logprintf (LOG_VERBOSE, _("idn_encode failed (%d): %s\n"), ret,
quote (idn2_strerror (ret)));
#else
/* we need a conversion to lowercase */
lower = u8_tolower ((uint8_t *) src, u8_strlen ((uint8_t *) src) + 1, 0, UNINORM_NFKC, NULL, &len);
if (!lower)
{
logprintf (LOG_VERBOSE, _("Invalid UTF-8 sequence: %s\n"),
quote(utf8_encoded ? utf8_encoded : host));
logprintf (LOG_VERBOSE, _("Failed to convert to lower: %d: %s\n"),
errno, quote (src));
xfree (utf8_encoded);
return NULL;
}
/* Store in ascii_encoded the ASCII UTF-8 NULL terminated string */
ret = idna_to_ascii_8z (utf8_encoded ? utf8_encoded : host, &ascii_encoded, IDNA_FLAGS);
xfree (utf8_encoded);
if (ret != IDNA_SUCCESS)
if ((ret = idn2_lookup_u8 (lower, (uint8_t **) &ascii_encoded, IDN2_NFC_INPUT)) != IDN2_OK)
{
logprintf (LOG_VERBOSE, _("idn_encode failed (%d): %s\n"), ret,
quote (idna_strerror (ret)));
return NULL;
quote (idn2_strerror (ret)));
}
return ascii_encoded;
xfree (lower);
#endif
xfree (utf8_encoded);
if (ret == IDN2_OK && ascii_encoded)
{
char *tmp = xstrdup (ascii_encoded);
idn2_free (ascii_encoded);
ascii_encoded = tmp;
}
return ret == IDN2_OK ? ascii_encoded : NULL;
}
/* Try to decode an "ASCII encoded" host. Return the new domain in the locale
@@ -317,18 +318,24 @@ idn_encode (const struct iri *i, const char *host)
char *
idn_decode (const char *host)
{
/*
char *new;
int ret;
ret = idna_to_unicode_8zlz (host, &new, IDNA_FLAGS);
if (ret != IDNA_SUCCESS)
ret = idn2_register_u8 (NULL, host, (uint8_t **) &new, 0);
if (ret != IDN2_OK)
{
logprintf (LOG_VERBOSE, _("idn_decode failed (%d): %s\n"), ret,
quote (idna_strerror (ret)));
logprintf (LOG_VERBOSE, _("idn2_register_u8 failed (%d): %s: %s\n"), ret,
quote (idn2_strerror (ret)), host);
return NULL;
}
return new;
*/
/* idn2_register_u8() just works label by label.
* That is pretty much overhead for just displaying the original ulabels.
* To keep at least the debug output format, return a cloned host. */
return xstrdup(host);
}
/* Try to transcode string str from remote encoding to UTF-8. On success, *new

View File

@@ -40,11 +40,8 @@ struct iri {
#ifdef ENABLE_IRI
# include <idna.h>
# include <idn-free.h>
char *parse_charset (const char *str);
char *find_locale (void);
const char *find_locale (void);
bool check_encoding_name (const char *encoding);
const char *locale_to_utf8 (const char *str);
char *idn_encode (const struct iri *i, const char *host);
@@ -66,7 +63,7 @@ extern struct iri dummy_iri;
#define locale_to_utf8(str) (str)
#define idn_encode(a,b) NULL
#define idn_decode(str) NULL
#define idn_free(str) ((void)0)
#define idn2_free(str) ((void)0)
#define remote_to_utf8(a,b,c) false
#define iri_new() (&dummy_iri)
#define iri_dup(a) (&dummy_iri)

129
src/log.c
View File

@@ -80,6 +80,18 @@ as that of the covered work. */
logging is inhibited, logfp is set back to NULL. */
static FILE *logfp;
/* Descriptor of the stdout|stderr */
static FILE *stdlogfp;
/* Descriptor of the wget.log* file (if created) */
static FILE *filelogfp;
/* Name of log file */
static char *logfile;
/* Is interactive shell ? */
static int shell_is_interactive;
/* A second file descriptor pointing to the temporary log file for the
WARC writer. If WARC writing is disabled, this is NULL. */
static FILE *warclogfp;
@@ -520,7 +532,7 @@ log_set_flush (bool flush)
}
else
{
/* Reenable flushing. If anything was printed in no-flush mode,
/* Re-enable flushing. If anything was printed in no-flush mode,
flush the log now. */
if (needs_flushing)
logflush ();
@@ -611,16 +623,18 @@ log_init (const char *file, bool appendp)
{
if (HYPHENP (file))
{
logfp = stdout;
stdlogfp = stdout;
logfp = stdlogfp;
}
else
{
logfp = fopen (file, appendp ? "a" : "w");
if (!logfp)
filelogfp = fopen (file, appendp ? "a" : "w");
if (!filelogfp)
{
fprintf (stderr, "%s: %s: %s\n", exec_name, file, strerror (errno));
exit (WGET_EXIT_GENERIC_ERROR);
}
logfp = filelogfp;
}
}
else
@@ -631,7 +645,8 @@ log_init (const char *file, bool appendp)
stderr only if the user actually specifies `-O -'. He says
this inconsistency is harder to document, but is overall
easier on the user. */
logfp = stderr;
stdlogfp = stderr;
logfp = stdlogfp;
if (1
#ifdef HAVE_ISATTY
@@ -646,6 +661,11 @@ log_init (const char *file, bool appendp)
save_context_p = true;
}
}
#ifndef WINDOWS
/* Initialize this values so we don't have to ask every time we print line */
shell_is_interactive = isatty (STDIN_FILENO);
#endif
}
/* Close LOGFP (only if we opened it, not if it's stderr), inhibit
@@ -880,59 +900,78 @@ log_cleanup (void)
/* When SIGHUP or SIGUSR1 are received, the output is redirected
elsewhere. Such redirection is only allowed once. */
static enum { RR_NONE, RR_REQUESTED, RR_DONE } redirect_request = RR_NONE;
static const char *redirect_request_signal_name;
/* Redirect output to `wget-log'. */
/* Redirect output to `wget-log' or back to stdout/stderr. */
static void
redirect_output (void)
void
redirect_output (bool to_file, const char *signal_name)
{
char *logfile;
logfp = unique_create (DEFAULT_LOGFILE, false, &logfile);
if (logfp)
if (to_file && logfp != filelogfp)
{
fprintf (stderr, _("\n%s received, redirecting output to %s.\n"),
redirect_request_signal_name, quote (logfile));
xfree (logfile);
/* Dump the context output to the newly opened log. */
if (signal_name)
{
fprintf (stderr, "\n%s received.", signal_name);
}
if (!filelogfp)
{
filelogfp = unique_create (DEFAULT_LOGFILE, false, &logfile);
if (filelogfp)
{
fprintf (stderr, _("\nRedirecting output to %s.\n"),
quote (logfile));
/* Store signal name to tell wget it's permanent redirect to log file */
redirect_request_signal_name = signal_name;
logfp = filelogfp;
/* Dump the context output to the newly opened log. */
log_dump_context ();
}
else
{
/* Eek! Opening the alternate log file has failed. Nothing we
can do but disable printing completely. */
fprintf (stderr, _("%s: %s; disabling logging.\n"),
(logfile) ? logfile : DEFAULT_LOGFILE, strerror (errno));
inhibit_logging = true;
}
}
else
{
fprintf (stderr, _("\nRedirecting output to %s.\n"),
quote (logfile));
logfp = filelogfp;
log_dump_context ();
}
}
else if (!to_file && logfp != stdlogfp)
{
logfp = stdlogfp;
log_dump_context ();
}
else
{
/* Eek! Opening the alternate log file has failed. Nothing we
can do but disable printing completely. */
fprintf (stderr, _("\n%s received.\n"), redirect_request_signal_name);
fprintf (stderr, _("%s: %s; disabling logging.\n"),
(logfile) ? logfile : DEFAULT_LOGFILE, strerror (errno));
inhibit_logging = true;
}
save_context_p = false;
}
/* Check whether a signal handler requested the output to be
redirected. */
/* Check whether there's a need to redirect output. */
static void
check_redirect_output (void)
{
if (redirect_request == RR_REQUESTED)
#ifndef WINDOWS
/* If it was redirected already to log file by SIGHUP, SIGUSR1 or -o parameter,
* it was permanent.
* If there was no SIGHUP or SIGUSR1 and shell is interactive
* we check if process is fg or bg before every line is printed.*/
if (!redirect_request_signal_name && shell_is_interactive && !opt.lfilename)
{
redirect_request = RR_DONE;
redirect_output ();
if (tcgetpgrp (STDIN_FILENO) != getpgrp ())
{
/* Process backgrounded */
redirect_output (true,NULL);
}
else
{
/* Process foregrounded */
redirect_output (false,NULL);
}
}
}
/* Request redirection at a convenient time. This may be called from
a signal handler. */
void
log_request_redirect_output (const char *signal_name)
{
if (redirect_request == RR_NONE && save_context_p)
/* Request output redirection. The request will be processed by
check_redirect_output(), which is called from entry point log
functions. */
redirect_request = RR_REQUESTED;
redirect_request_signal_name = signal_name;
#endif /* WINDOWS */
}

View File

@@ -52,6 +52,7 @@ void log_init (const char *, bool);
void log_close (void);
void log_cleanup (void);
void log_request_redirect_output (const char *);
void redirect_output (bool, const char *);
const char *escnonprint (const char *);
const char *escnonprint_uri (const char *);

View File

@@ -36,6 +36,7 @@ as that of the covered work. */
#include <unistd.h>
#include <string.h>
#include <signal.h>
#include <spawn.h>
#ifdef ENABLE_NLS
# include <locale.h>
#endif
@@ -60,6 +61,7 @@ as that of the covered work. */
#include "version.h"
#include "c-strcase.h"
#include "dirname.h"
#include "xmemdup0.h"
#include <getopt.h>
#include <getpass.h>
#include <quote.h>
@@ -130,7 +132,7 @@ redirect_output_signal (int sig)
signal_name = "SIGUSR1";
#endif
log_request_redirect_output (signal_name);
redirect_output (true,signal_name);
progress_schedule_redirect ();
signal (sig, redirect_output_signal);
}
@@ -219,8 +221,8 @@ save_hsts (void)
/* Definition of command-line options. */
static void _Noreturn print_help (void);
static void _Noreturn print_version (void);
_Noreturn static void print_help (void);
_Noreturn static void print_version (void);
#ifdef HAVE_SSL
# define IF_SSL(x) x
@@ -273,6 +275,9 @@ static struct cmdline_option option_data[] =
{ IF_SSL ("certificate-type"), 0, OPT_VALUE, "certificatetype", -1 },
{ IF_SSL ("check-certificate"), 0, OPT_BOOLEAN, "checkcertificate", -1 },
{ "clobber", 0, OPT__CLOBBER, NULL, optional_argument },
#ifdef HAVE_LIBZ
{ "compression", 0, OPT_VALUE, "compression", -1 },
#endif
{ "config", 0, OPT_VALUE, "chooseconfig", -1 },
{ "connect-timeout", 0, OPT_VALUE, "connecttimeout", -1 },
{ "continue", 'c', OPT_BOOLEAN, "continue", -1 },
@@ -321,7 +326,7 @@ static struct cmdline_option option_data[] =
{ "host-directories", 0, OPT_BOOLEAN, "addhostdir", -1 },
#ifdef HAVE_HSTS
{ "hsts", 0, OPT_BOOLEAN, "hsts", -1},
{ "hsts-file", 0, OPT_VALUE, "hsts-file", -1 },
{ "hsts-file", 0, OPT_VALUE, "hstsfile", -1 },
#endif
{ "html-extension", 'E', OPT_BOOLEAN, "adjustextension", -1 }, /* deprecated */
{ "htmlify", 0, OPT_BOOLEAN, "htmlify", -1 },
@@ -340,9 +345,10 @@ static struct cmdline_option option_data[] =
#endif
{ "input-file", 'i', OPT_VALUE, "input", -1 },
#ifdef HAVE_METALINK
{ "input-metalink", 0, OPT_VALUE, "input-metalink", -1 },
{ "input-metalink", 0, OPT_VALUE, "inputmetalink", -1 },
#endif
{ "iri", 0, OPT_BOOLEAN, "iri", -1 },
{ "keep-badhash", 0, OPT_BOOLEAN, "keepbadhash", -1 },
{ "keep-session-cookies", 0, OPT_BOOLEAN, "keepsessioncookies", -1 },
{ "level", 'l', OPT_VALUE, "reclevel", -1 },
{ "limit-rate", 0, OPT_VALUE, "limitrate", -1 },
@@ -351,10 +357,12 @@ static struct cmdline_option option_data[] =
{ "rejected-log", 0, OPT_VALUE, "rejectedlog", -1 },
{ "max-redirect", 0, OPT_VALUE, "maxredirect", -1 },
#ifdef HAVE_METALINK
{ "metalink-over-http", 0, OPT_BOOLEAN, "metalink-over-http", -1 },
{ "metalink-index", 0, OPT_VALUE, "metalinkindex", -1 },
{ "metalink-over-http", 0, OPT_BOOLEAN, "metalinkoverhttp", -1 },
#endif
{ "method", 0, OPT_VALUE, "method", -1 },
{ "mirror", 'm', OPT_BOOLEAN, "mirror", -1 },
{ "netrc", 0, OPT_BOOLEAN, "netrc", -1 },
{ "no", 'n', OPT__NO, NULL, required_argument },
{ "no-clobber", 0, OPT_BOOLEAN, "noclobber", -1 },
{ "no-config", 0, OPT_BOOLEAN, "noconfig", -1},
@@ -370,7 +378,7 @@ static struct cmdline_option option_data[] =
{ "post-file", 0, OPT_VALUE, "postfile", -1 },
{ "prefer-family", 0, OPT_VALUE, "preferfamily", -1 },
#ifdef HAVE_METALINK
{ "preferred-location", 0, OPT_VALUE, "preferred-location", -1 },
{ "preferred-location", 0, OPT_VALUE, "preferredlocation", -1 },
#endif
{ "preserve-permissions", 0, OPT_BOOLEAN, "preservepermissions", -1 },
{ IF_SSL ("private-key"), 0, OPT_VALUE, "privatekey", -1 },
@@ -400,6 +408,7 @@ static struct cmdline_option option_data[] =
{ "restrict-file-names", 0, OPT_BOOLEAN, "restrictfilenames", -1 },
{ "retr-symlinks", 0, OPT_BOOLEAN, "retrsymlinks", -1 },
{ "retry-connrefused", 0, OPT_BOOLEAN, "retryconnrefused", -1 },
{ "retry-on-http-error", 0, OPT_VALUE, "retryonhttperror", -1 },
{ "save-cookies", 0, OPT_VALUE, "savecookies", -1 },
{ "save-headers", 0, OPT_BOOLEAN, "saveheaders", -1 },
{ IF_SSL ("secure-protocol"), 0, OPT_VALUE, "secureprotocol", -1 },
@@ -410,15 +419,15 @@ static struct cmdline_option option_data[] =
{ "strict-comments", 0, OPT_BOOLEAN, "strictcomments", -1 },
{ "timeout", 'T', OPT_VALUE, "timeout", -1 },
{ "timestamping", 'N', OPT_BOOLEAN, "timestamping", -1 },
{ "if-modified-since", 0, OPT_BOOLEAN, "if-modified-since", -1 },
{ "if-modified-since", 0, OPT_BOOLEAN, "ifmodifiedsince", -1 },
{ "tries", 't', OPT_VALUE, "tries", -1 },
{ "unlink", 0, OPT_BOOLEAN, "unlink", -1 },
{ "trust-server-names", 0, OPT_BOOLEAN, "trustservernames", -1 },
{ "use-askpass", 0, OPT_VALUE, "useaskpass", -1},
{ "use-server-timestamps", 0, OPT_BOOLEAN, "useservertimestamps", -1 },
{ "user", 0, OPT_VALUE, "user", -1 },
{ "user-agent", 'U', OPT_VALUE, "useragent", -1 },
{ "verbose", 'v', OPT_BOOLEAN, "verbose", -1 },
{ "verbose", 0, OPT_BOOLEAN, "verbose", -1 },
{ "version", 'V', OPT_FUNCALL, (void *) print_version, no_argument },
{ "wait", 'w', OPT_VALUE, "wait", -1 },
{ "waitretry", 0, OPT_VALUE, "waitretry", -1 },
@@ -435,6 +444,9 @@ static struct cmdline_option option_data[] =
{ "warc-tempdir", 0, OPT_VALUE, "warctempdir", -1 },
#ifdef USE_WATT32
{ "wdebug", 0, OPT_BOOLEAN, "wdebug", -1 },
#endif
#ifdef ENABLE_XATTR
{ "xattr", 0, OPT_BOOLEAN, "xattr", -1 },
#endif
};
@@ -547,7 +559,7 @@ print_usage (int error)
/* Print the help message, describing all the available options. If
you add an option, be sure to update this list. */
static void _Noreturn
_Noreturn static void
print_help (void)
{
/* We split the help text this way to ease translation of individual
@@ -620,6 +632,8 @@ Download:\n"),
N_("\
-nc, --no-clobber skip downloads that would download to\n\
existing files (overwriting them)\n"),
N_("\
--no-netrc don't try to obtain credentials from .netrc\n"),
N_("\
-c, --continue resume getting a partially-downloaded file\n"),
N_("\
@@ -690,6 +704,11 @@ Download:\n"),
--password=PASS set both ftp and http password to PASS\n"),
N_("\
--ask-password prompt for passwords\n"),
N_("\
--use-askpass=COMMAND specify credential handler for requesting \n\
username and password. If no COMMAND is \n\
specified the WGET_ASKPASS or the SSH_ASKPASS \n\
environment variable is used.\n"),
N_("\
--no-iri turn off IRI support\n"),
N_("\
@@ -699,10 +718,18 @@ Download:\n"),
N_("\
--unlink remove file before clobber\n"),
#ifdef HAVE_METALINK
N_("\
--keep-badhash keep files with checksum mismatch (append .badhash)\n"),
N_("\
--metalink-index=NUMBER Metalink application/metalink4+xml metaurl ordinal NUMBER\n"),
N_("\
--metalink-over-http use Metalink metadata from HTTP response headers\n"),
N_("\
--preferred-location preferred location for Metalink resources\n"),
#endif
#ifdef ENABLE_XATTR
N_("\
--no-xattr turn off storage of metadata in extended file attributes\n"),
#endif
"\n",
@@ -739,6 +766,10 @@ HTTP options:\n"),
--ignore-length ignore 'Content-Length' header field\n"),
N_("\
--header=STRING insert STRING among the headers\n"),
#ifdef HAVE_LIBZ
N_("\
--compression=TYPE choose compression, one of auto, gzip and none\n"),
#endif
N_("\
--max-redirect maximum redirections allowed per page\n"),
N_("\
@@ -787,7 +818,7 @@ HTTP options:\n"),
HTTPS (SSL/TLS) options:\n"),
N_("\
--secure-protocol=PR choose secure protocol, one of auto, SSLv2,\n\
SSLv3, TLSv1 and PFS\n"),
SSLv3, TLSv1, TLSv1_1, TLSv1_2 and PFS\n"),
N_("\
--https-only only follow secure HTTPS links\n"),
N_("\
@@ -809,7 +840,7 @@ HTTPS (SSL/TLS) options:\n"),
N_("\
--pinnedpubkey=FILE/HASHES Public key (PEM/DER) file, or any number\n\
of base64 encoded sha256 hashes preceded by\n\
\'sha256//\' and seperated by \';\', to verify\n\
\'sha256//\' and separated by \';\', to verify\n\
peer against\n"),
#if defined(HAVE_LIBSSL) || defined(HAVE_LIBSSL32)
N_("\
@@ -1019,6 +1050,103 @@ prompt_for_password (void)
return getpass("");
}
/* Execute external application opt.use_askpass */
static void
run_use_askpass (char *question, char **answer)
{
char tmp[1024];
pid_t pid;
int status;
int com[2];
ssize_t bytes = 0;
char *argv[3], *p;
posix_spawn_file_actions_t fa;
if (pipe (com) == -1)
{
fprintf (stderr, _("Cannot create pipe\n"));
exit (WGET_EXIT_GENERIC_ERROR);
}
status = posix_spawn_file_actions_init (&fa);
if (status)
{
fprintf (stderr,
_("Error initializing spawn file actions for use-askpass: %d\n"),
status);
exit (WGET_EXIT_GENERIC_ERROR);
}
status = posix_spawn_file_actions_adddup2 (&fa, com[1], STDOUT_FILENO);
if (status)
{
fprintf (stderr,
_("Error setting spawn file actions for use-askpass: %d\n"),
status);
exit (WGET_EXIT_GENERIC_ERROR);
}
/* C89 initializer lists must be computable at load time,
* thus this explicit initialization. */
argv[0] = opt.use_askpass;
argv[1] = question;
argv[2] = NULL;
status = posix_spawnp (&pid, opt.use_askpass, &fa, NULL, argv, environ);
if (status)
{
fprintf (stderr, "Error spawning %s: %d\n", opt.use_askpass, status);
exit (WGET_EXIT_GENERIC_ERROR);
}
/* Parent process reads from child. */
close (com[1]);
bytes = read (com[0], tmp, sizeof (tmp) - 1);
if (bytes <= 0)
{
fprintf (stderr,
_("Error reading response from command \"%s %s\": %s\n"),
opt.use_askpass, question, strerror (errno));
exit (WGET_EXIT_GENERIC_ERROR);
}
/* Make sure there is a trailing 0 */
tmp[bytes] = '\0';
/* Remove a possible new line */
if ((p = strpbrk (tmp, "\r\n")))
bytes = p - tmp;
*answer = xmemdup0 (tmp, bytes);
}
/* set the user name and password*/
static void
use_askpass (struct url *u)
{
static char question[1024];
if (u->user == NULL || u->user[0] == '\0')
{
snprintf (question, sizeof (question), _("Username for '%s%s': "),
scheme_leading_string(u->scheme), u->host);
/* Prompt for username */
run_use_askpass (question, &u->user);
if (opt.recursive)
opt.user = xstrdup (u->user);
}
if (u->passwd == NULL || u->passwd[0] == '\0')
{
snprintf(question, sizeof (question), _("Password for '%s%s@%s': "),
scheme_leading_string (u->scheme), u->user, u->host);
/* Prompt for password */
run_use_askpass (question, &u->passwd);
if (opt.recursive)
opt.passwd = xstrdup (u->passwd);
}
}
/* Function that prints the line argument while limiting it
to at most line_length. prefix is printed on the first line
and an appropriate number of spaces are added on subsequent
@@ -1080,7 +1208,7 @@ format_and_print_line (const char *prefix, const char *line,
return 0;
}
static void _Noreturn
_Noreturn static void
print_version (void)
{
const char *wgetrc_title = _("Wgetrc: ");
@@ -1263,10 +1391,10 @@ main (int argc, char **argv)
}
else if (strcmp (config_opt->long_name, "config") == 0)
{
bool userrc_ret = true;
userrc_ret &= run_wgetrc (optarg);
file_stats_t flstats;
use_userconfig = true;
if (userrc_ret)
memset(&flstats, 0, sizeof(flstats));
if (file_exists_p(optarg, &flstats) && run_wgetrc (optarg, &flstats))
break;
else
{
@@ -1339,7 +1467,8 @@ main (int argc, char **argv)
append_to_log = true;
break;
case OPT__EXECUTE:
run_command (optarg);
if (optarg) /* check silences static analyzer */
run_command (optarg);
break;
case OPT__NO:
{
@@ -1501,7 +1630,7 @@ WARNING: timestamping does nothing in combination with -O. See the manual\n\
for details.\n\n"));
opt.timestamping = false;
}
if (opt.noclobber && file_exists_p(opt.output_document))
if (opt.noclobber && file_exists_p(opt.output_document, NULL))
{
/* Check if output file exists; if it does, exit. */
logprintf (LOG_VERBOSE,
@@ -1553,6 +1682,26 @@ for details.\n\n"));
}
}
#ifdef HAVE_LIBZ
if (opt.always_rest || opt.start_pos >= 0)
{
if (opt.compression == compression_auto)
{
/* Compression does not work with --continue or --start-pos.
Since compression was not explicitly set, it will be disabled. */
opt.compression = compression_none;
}
else if (opt.compression != compression_none)
{
fprintf (stderr,
_("Compression does not work with --continue or"
" --start-pos, they will be disabled.\n"));
opt.always_rest = false;
opt.start_pos = -1;
}
}
#endif
if (opt.ask_passwd && opt.passwd)
{
fprintf (stderr,
@@ -1623,7 +1772,7 @@ for details.\n\n"));
else if (opt.method)
{
fprintf (stderr, _("You cannot use --post-data or --post-file along with --method. "
"--method expects data through --body-data and --body-file options"));
"--method expects data through --body-data and --body-file options\n"));
exit (WGET_EXIT_GENERIC_ERROR);
}
}
@@ -1702,6 +1851,16 @@ for details.\n\n"));
exit (WGET_EXIT_GENERIC_ERROR);
}
if (opt.use_askpass)
{
if (opt.use_askpass[0] == '\0')
{
fprintf (stderr,
_("use-askpass requires a string or either environment variable WGET_ASKPASS or SSH_ASKPASS to be set.\n"));
exit (WGET_EXIT_GENERIC_ERROR);
}
}
#ifdef USE_WATT32
if (opt.wdebug)
dbug_init();
@@ -1764,7 +1923,7 @@ for details.\n\n"));
}
else
{
struct_fstat st;
struct stat st;
#ifdef __VMS
/* Common fopen() optional arguments:
@@ -1920,6 +2079,10 @@ only if outputting to a regular file.\n"));
}
else
{
/* Request credentials if use_askpass is set. */
if (opt.use_askpass)
use_askpass (url_parsed);
if ((opt.recursive || opt.page_requisites)
&& ((url_scheme (*t) != SCHEME_FTP
#ifdef HAVE_SSL
@@ -1948,7 +2111,7 @@ only if outputting to a regular file.\n"));
&dt, opt.recursive, iri, true);
}
if (opt.delete_after && filename != NULL && file_exists_p (filename))
if (opt.delete_after && filename != NULL && file_exists_p (filename, NULL))
{
DEBUGP (("Removing file due to --delete-after in main():\n"));
logprintf (LOG_VERBOSE, _("Removing %s.\n"), filename);

File diff suppressed because it is too large Load Diff

View File

@@ -46,6 +46,21 @@ as that of the covered work. */
uerr_t retrieve_from_metalink (const metalink_t *metalink);
int metalink_res_cmp (const void *res1, const void *res2);
int metalink_meta_cmp (const void* meta1, const void* meta2);
int metalink_check_safe_path (const char *path);
char *last_component (char const *name);
void replace_metalink_basename (char **name, char *ref);
char *get_metalink_basename (char *name);
void append_suffix_number (char **str, const char *sep, wgint num);
void clean_metalink_string (char **str);
void dequote_metalink_string (char **str);
void badhash_suffix (char *name);
void badhash_or_remove (char *name);
uerr_t fetch_metalink_file (const char *url_str,
bool resume, bool metalink_http,
const char *filename, char **destname);
bool find_key_value (const char *start,
const char *end,

View File

@@ -53,9 +53,6 @@ as that of the covered work. */
#endif
/* Defined in log.c. */
void log_request_redirect_output (const char *);
/* Windows version of xsleep in utils.c. */
void
@@ -98,7 +95,7 @@ static void
ws_hangup (const char *reason)
{
fprintf (stderr, _("Continuing in background.\n"));
log_request_redirect_output (reason);
redirect_output (true, reason);
/* Detach process from the current console. Under Windows 9x, if we
were launched from a 16-bit process (which is usually the case;
@@ -583,7 +580,7 @@ run_with_timeout (double seconds, void (*fun) (void *), void *arg)
const char *
inet_ntop (int af, const void *src, char *dst, socklen_t cnt)
{
/* struct sockaddr can't accomodate struct sockaddr_in6. */
/* struct sockaddr can't accommodate struct sockaddr_in6. */
union {
struct sockaddr_in6 sin6;
struct sockaddr_in sin;

View File

@@ -57,6 +57,9 @@ as that of the covered work. */
/* Declares getpid(). */
#include <process.h>
/* Declares inet_ntop() and inet_pton(). */
#include <arpa/inet.h>
/* We have strcasecmp and strncasecmp, just under different names. */
#ifndef HAVE_STRCASECMP
# define strcasecmp stricmp
@@ -85,11 +88,6 @@ typedef __int64 wgint;
#define PATH_SEPARATOR '\\'
/* Additional declarations needed for IPv6: */
#ifdef ENABLE_IPV6
const char *inet_ntop (int, const void *, char *, socklen_t);
#endif
/* ioctl needed by set_windows_fd_as_blocking_socket() */
#include <sys/ioctl.h>

View File

@@ -75,7 +75,7 @@ search_netrc (const char *host, const char **acc, const char **passwd,
#ifdef __VMS
int err;
struct_stat buf;
struct stat buf;
char *path = "SYS$LOGIN:.netrc";
netrc_list = NULL;
@@ -94,7 +94,7 @@ search_netrc (const char *host, const char **acc, const char **passwd,
if (home)
{
int err;
struct_stat buf;
struct stat buf;
char *path = (char *)alloca (strlen (home) + 1
+ strlen (NETRC_FILE_NAME) + 1);
sprintf (path, "%s/%s", home, NETRC_FILE_NAME);
@@ -235,7 +235,7 @@ parse_netrc (const char *path)
/* The latest token we've seen in the file. */
enum
{
tok_nothing, tok_account, tok_login, tok_macdef, tok_machine, tok_password
tok_nothing, tok_account, tok_login, tok_macdef, tok_machine, tok_password, tok_port, tok_force
} last_token = tok_nothing;
current = retval = NULL;
@@ -344,6 +344,18 @@ parse_netrc (const char *path)
premature_token = "account";
break;
/* We don't handle the port keyword at all. */
case tok_port:
if (!current)
premature_token = "port";
break;
/* We don't handle the force keyword at all. */
case tok_force:
if (!current)
premature_token = "force";
break;
/* We handle tok_nothing below this switch. */
case tok_nothing:
break;
@@ -365,10 +377,10 @@ parse_netrc (const char *path)
/* Fetch the next token. */
if (!strcmp (tok, "account"))
last_token = tok_account;
else if (!strcmp (tok, "default"))
{
maybe_add_to_list (&current, &retval);
}
else if (!strcmp (tok, "login"))
last_token = tok_login;
@@ -381,6 +393,16 @@ parse_netrc (const char *path)
else if (!strcmp (tok, "password"))
last_token = tok_password;
/* GNU extensions 'port' and 'force', not operational
* see https://www.gnu.org/software/emacs/manual/html_node/gnus/NNTP.html#index-nntp_002dauthinfo_002dfunction-2003
* see https://savannah.gnu.org/bugs/index.php?52066
*/
else if (!strcmp (tok, "port"))
last_token = tok_port;
else if (!strcmp (tok, "force"))
last_token = tok_force;
else
fprintf (stderr, _("%s: %s:%d: unknown token \"%s\"\n"),
exec_name, path, ln, tok);
@@ -439,7 +461,7 @@ free_netrc(acc_t *l)
int
main (int argc, char **argv)
{
struct_stat sb;
struct stat sb;
char *program_name, *file, *target;
acc_t *head, *a;

View File

@@ -204,18 +204,20 @@ ssl_init (void)
#endif
SSL_library_init ();
SSL_load_error_strings ();
#if OPENSSL_VERSION_NUMBER < 0x10100000L
SSLeay_add_all_algorithms ();
SSLeay_add_ssl_algorithms ();
#endif
switch (opt.secure_protocol)
{
#ifndef OPENSSL_NO_SSL2
#if !defined OPENSSL_NO_SSL2 && OPENSSL_VERSION_NUMBER < 0x10100000L
case secure_protocol_sslv2:
meth = SSLv2_client_method ();
break;
#endif
#ifndef OPENSSL_NO_SSL3
#ifndef OPENSSL_NO_SSL3_METHOD
case secure_protocol_sslv3:
meth = SSLv3_client_method ();
break;
@@ -583,7 +585,7 @@ ssl_connect_wget (int fd, const char *hostname, int *continue_session)
DEBUGP (("SSL handshake timed out.\n"));
goto timeout;
}
if (scwt_ctx.result <= 0 || SSL_state(conn) != SSL_ST_OK)
if (scwt_ctx.result <= 0 || !SSL_is_init_finished(conn))
goto error;
ctx = xnew0 (struct openssl_transport_context);

View File

@@ -43,6 +43,7 @@ struct options
bool quiet; /* Are we quiet? */
int ntry; /* Number of tries per URL */
bool retry_connrefused; /* Treat CONNREFUSED as non-fatal. */
char *retry_on_http_error; /* Treat given HTTP errors as non-fatal. */
bool background; /* Whether we should work in background. */
bool ignore_length; /* Do we heed content-length at all? */
bool recursive; /* Are we recursive? */
@@ -61,12 +62,13 @@ struct options
bool add_hostdir; /* Do we add hostname directory? */
bool protocol_directories; /* Whether to prepend "http"/"ftp" to dirs. */
bool noclobber; /* Disables clobbering of existing data. */
bool unlink; /* remove file before clobbering */
bool unlink_requested; /* remove file before clobbering */
char *dir_prefix; /* The top of directory tree */
char *lfilename; /* Log filename */
char *input_filename; /* Input filename */
#ifdef HAVE_METALINK
char *input_metalink; /* Input metalink file */
int metalink_index; /* Metalink application/metalink4+xml metaurl ordinal number. */
bool metalink_over_http; /* Use Metalink if present in HTTP response */
char *preferred_location; /* Preferred location for Metalink resources */
#endif
@@ -127,9 +129,12 @@ struct options
bool warc_keep_log; /* Store the log file in a WARC record. */
char **warc_user_headers; /* User-defined WARC header(s). */
bool enable_xattr; /* Store metadata in POSIX extended attributes. */
char *user; /* Generic username */
char *passwd; /* Generic password */
bool ask_passwd; /* Ask for password? */
char *use_askpass; /* value to use for use-askpass if WGET_ASKPASS is not set */
bool always_rest; /* Always use REST. */
wgint start_pos; /* Start position of a download. */
@@ -243,7 +248,7 @@ struct options
char *pinnedpubkey; /* Public key (PEM/DER) file, or any number
of base64 encoded sha256 hashes preceded by
\'sha256//\' and seperated by \';\', to verify
\'sha256//\' and separated by \';\', to verify
peer against */
char *random_file; /* file with random data to seed the PRNG */
@@ -258,6 +263,7 @@ struct options
bool cookies; /* whether cookies are used. */
char *cookies_input; /* file we're loading the cookies from. */
char *cookies_output; /* file we're saving the cookies to. */
bool keep_badhash; /* Keep files with checksum mismatch. */
bool keep_session_cookies; /* whether session cookies should be
saved and loaded. */
@@ -306,7 +312,7 @@ struct options
bool enable_iri;
char *encoding_remote;
char *locale;
const char *locale;
bool trustservernames;
#ifdef __VMS
@@ -320,6 +326,14 @@ struct options
name. */
bool report_bps; /*Output bandwidth in bits format*/
#ifdef HAVE_LIBZ
enum compression_options {
compression_auto,
compression_gzip,
compression_none
} compression; /* type of HTTP compression to use */
#endif
char *rejected_log; /* The file to log rejected URLS to. */
#ifdef HAVE_HSTS

View File

@@ -75,7 +75,7 @@ static struct progress_implementation implementations[] = {
static struct progress_implementation *current_impl;
static int current_impl_locked;
/* Progress implementation used by default. Can be overriden in
/* Progress implementation used by default. Can be overridden in
wgetrc or by the fallback one. */
#define DEFAULT_PROGRESS_IMPLEMENTATION "bar"
@@ -892,11 +892,6 @@ get_eta (int *bcd)
p += sizeof (s) - 1; \
} while (0)
/* Use move_to_end (s) to get S to point the end of the string (the
terminating \0). This is faster than s+=strlen(s), but some people
are confused when they see strchr (s, '\0') in the code. */
#define move_to_end(s) s = strchr (s, '\0');
static void
create_image (struct bar_progress *bp, double dl_total_time, bool done)
{

View File

@@ -438,10 +438,15 @@ retrieve_tree (struct url *start_url_parsed, struct iri *pi)
struct url *url_parsed = url_parse (url, NULL, i, true);
struct iri *ci;
char *referer_url = url;
bool strip_auth = (url_parsed != NULL
&& url_parsed->user != NULL);
bool strip_auth;
assert (url_parsed != NULL);
if (!url_parsed)
continue;
strip_auth = (url_parsed && url_parsed->user);
/* Strip auth info if present */
if (strip_auth)
referer_url = url_string (url_parsed, URL_AUTH_HIDE);
@@ -451,9 +456,16 @@ retrieve_tree (struct url *start_url_parsed, struct iri *pi)
reject_reason r;
if (child->ignore_when_downloading)
continue;
{
DEBUGP (("Not following due to 'ignore' flag: %s\n", child->url->url));
continue;
}
if (dash_p_leaf_HTML && !child->link_inline_p)
continue;
{
DEBUGP (("Not following due to 'link inline' flag: %s\n", child->url->url));
continue;
}
r = download_child (child, url_parsed, depth,
start_url_parsed, blacklist, i);
@@ -485,7 +497,7 @@ retrieve_tree (struct url *start_url_parsed, struct iri *pi)
if (file
&& (opt.delete_after
|| opt.spider /* opt.recursive is implicitely true */
|| opt.spider /* opt.recursive is implicitly true */
|| !acceptable (file)))
{
/* Either --delete-after was specified, or we loaded this
@@ -686,7 +698,7 @@ download_child (const struct urlpos *upos, struct url *parent, int depth,
for directories (no file name to match) and for non-leaf HTMLs,
which can lead to other files that do need to be downloaded. (-p
automatically implies non-leaf because with -p we can, if
necesary, overstep the maximum depth to get the page requisites.) */
necessary, overstep the maximum depth to get the page requisites.) */
if (u->file[0] != '\0'
&& !(has_html_suffix_p (u->file)
/* The exception only applies to non-leaf HTMLs (but -p
@@ -801,6 +813,12 @@ descend_redirect (const char *redirected, struct url *orig_parsed, int depth,
if (reason == WG_RR_SUCCESS)
blacklist_add (blacklist, upos->url->url);
else if (reason == WG_RR_LIST || reason == WG_RR_REGEX)
{
DEBUGP (("Ignoring decision for redirects, decided to load it.\n"));
blacklist_add (blacklist, upos->url->url);
reason = WG_RR_SUCCESS;
}
else
DEBUGP (("Redirection \"%s\" failed the test.\n", redirected));

View File

@@ -37,12 +37,12 @@ as that of the covered work. */
disallow access to certain parts of the site.
The first specification was written by Martijn Koster in 1994, and
is still available at <http://www.robotstxt.org/wc/norobots.html>.
is still available at <http://www.robotstxt.org/orig.html>.
In 1996, Martijn wrote an Internet Draft specifying an improved RES
specification; however, that work was apparently abandoned since
the draft has expired in 1997 and hasn't been replaced since. The
draft is available at
<http://www.robotstxt.org/wc/norobots-rfc.html>.
<http://www.robotstxt.org/norobots-rfc.txt>.
This file implements RES as specified by the draft. Note that this
only handles the "robots.txt" support. The META tag that controls
@@ -428,7 +428,7 @@ free_specs (struct robot_specs *specs)
/* The inner matching engine: return true if RECORD_PATH matches
URL_PATH. The rules for matching are described at
<http://www.robotstxt.org/wc/norobots-rfc.txt>, section 3.2.2. */
<http://www.robotstxt.org/norobots-rfc.txt>, section 3.2.2. */
static bool
matches (const char *record_path, const char *url_path)

View File

@@ -41,6 +41,10 @@ as that of the covered work. */
# include <unixio.h> /* For delete(). */
#endif
#ifdef HAVE_LIBZ
# include <zlib.h>
#endif
#include "exits.h"
#include "utils.h"
#include "retr.h"
@@ -84,6 +88,22 @@ limit_bandwidth_reset (void)
xzero (limit_data);
}
#ifdef HAVE_LIBZ
static voidpf
zalloc (voidpf opaque, unsigned int items, unsigned int size)
{
(void) opaque;
return (voidpf) xcalloc (items, size);
}
static void
zfree (voidpf opaque, voidpf address)
{
(void) opaque;
xfree (address);
}
#endif
/* Limit the bandwidth by pausing the download for an amount of time.
BYTES is the number of bytes received from the network, and TIMER
is the timer that started at the beginning of download. */
@@ -257,6 +277,44 @@ fd_read_body (const char *downloaded_filename, int fd, FILE *out, wgint toread,
wgint sum_written = 0;
wgint remaining_chunk_size = 0;
#ifdef HAVE_LIBZ
/* try to minimize the number of calls to inflate() and write_data() per
call to fd_read() */
unsigned int gzbufsize = dlbufsize * 4;
char *gzbuf = NULL;
z_stream gzstream;
if (flags & rb_compressed_gzip)
{
gzbuf = xmalloc (gzbufsize);
if (gzbuf != NULL)
{
gzstream.zalloc = zalloc;
gzstream.zfree = zfree;
gzstream.opaque = Z_NULL;
gzstream.next_in = Z_NULL;
gzstream.avail_in = 0;
#define GZIP_DETECT 32 /* gzip format detection */
#define GZIP_WINDOW 15 /* logarithmic window size (default: 15) */
ret = inflateInit2 (&gzstream, GZIP_DETECT | GZIP_WINDOW);
if (ret != Z_OK)
{
xfree (gzbuf);
errno = (ret == Z_MEM_ERROR) ? ENOMEM : EINVAL;
ret = -1;
goto out;
}
}
else
{
errno = ENOMEM;
ret = -1;
goto out;
}
}
#endif
if (flags & rb_skip_startpos)
skip = startpos;
@@ -320,6 +378,12 @@ fd_read_body (const char *downloaded_filename, int fd, FILE *out, wgint toread,
remaining_chunk_size = strtol (line, &endl, 16);
xfree (line);
if (remaining_chunk_size < 0)
{
ret = -1;
break;
}
if (remaining_chunk_size == 0)
{
ret = 0;
@@ -383,12 +447,64 @@ fd_read_body (const char *downloaded_filename, int fd, FILE *out, wgint toread,
int write_res;
sum_read += ret;
write_res = write_data (out, out2, dlbuf, ret, &skip, &sum_written);
if (write_res < 0)
#ifdef HAVE_LIBZ
if (gzbuf != NULL)
{
ret = (write_res == -3) ? -3 : -2;
goto out;
int err;
int towrite;
gzstream.avail_in = ret;
gzstream.next_in = (unsigned char *) dlbuf;
do
{
gzstream.avail_out = gzbufsize;
gzstream.next_out = (unsigned char *) gzbuf;
err = inflate (&gzstream, Z_NO_FLUSH);
switch (err)
{
case Z_MEM_ERROR:
errno = ENOMEM;
ret = -1;
goto out;
case Z_NEED_DICT:
case Z_DATA_ERROR:
errno = EINVAL;
ret = -1;
goto out;
case Z_STREAM_END:
if (exact && sum_read != toread)
{
DEBUGP(("zlib stream ended unexpectedly after "
"%ld/%ld bytes\n", sum_read, toread));
}
}
towrite = gzbufsize - gzstream.avail_out;
write_res = write_data (out, out2, gzbuf, towrite, &skip,
&sum_written);
if (write_res < 0)
{
ret = (write_res == -3) ? -3 : -2;
goto out;
}
}
while (gzstream.avail_out == 0);
}
else
#endif
{
write_res = write_data (out, out2, dlbuf, ret, &skip,
&sum_written);
if (write_res < 0)
{
ret = (write_res == -3) ? -3 : -2;
goto out;
}
}
if (chunked)
{
remaining_chunk_size -= ret;
@@ -433,6 +549,31 @@ fd_read_body (const char *downloaded_filename, int fd, FILE *out, wgint toread,
if (timer)
ptimer_destroy (timer);
#ifdef HAVE_LIBZ
if (gzbuf != NULL)
{
int err = inflateEnd (&gzstream);
if (ret >= 0)
{
/* with compression enabled, ret must be 0 if successful */
if (err == Z_OK)
ret = 0;
else
{
errno = EINVAL;
ret = -1;
}
}
xfree (gzbuf);
if (gzstream.total_in != sum_read)
{
DEBUGP(("zlib read size differs from raw read size (%lu/%lu)\n",
gzstream.total_in, sum_read));
}
}
#endif
if (qtyread)
*qtyread += sum_read;
if (qtywritten)
@@ -634,7 +775,7 @@ retr_rate (wgint bytes, double secs)
double dlrate = calc_rate (bytes, secs, &units);
/* Use more digits for smaller numbers (regardless of unit used),
e.g. "1022", "247", "12.5", "2.38". */
sprintf (res, "%.*f %s",
snprintf (res, sizeof(res), "%.*f %s",
dlrate >= 99.95 ? 0 : dlrate >= 9.995 ? 1 : 2,
dlrate, !opt.report_bps ? rate_names[units]: rate_names_bits[units]);
@@ -869,7 +1010,7 @@ retrieve_url (struct url * orig_parsed, const char *origurl, char **file,
redirects, but a ton of boneheaded webservers and CGIs out
there break the rules and use relative URLs, and popular
browsers are lenient about this, so wget should be too. */
construced_newloc = uri_merge (url, mynewloc);
construced_newloc = uri_merge (url, mynewloc ? mynewloc : "");
xfree (mynewloc);
mynewloc = construced_newloc;
@@ -963,11 +1104,16 @@ retrieve_url (struct url * orig_parsed, const char *origurl, char **file,
u = url_parse (origurl, NULL, iri, true);
if (u)
{
DEBUGP (("[IRI fallbacking to non-utf8 for %s\n", quote (url)));
xfree (url);
url = xstrdup (u->url);
iri_fallbacked = 1;
goto redirected;
if (strcmp(u->url, orig_parsed->url))
{
DEBUGP (("[IRI fallbacking to non-utf8 for %s\n", quote (url)));
xfree (url);
url = xstrdup (u->url);
iri_fallbacked = 1;
goto redirected;
}
else
DEBUGP (("[Needn't fallback to non-utf8 for %s\n", quote (url)));
}
else
DEBUGP (("[Couldn't fallback to non-utf8 for %s\n", quote (url)));
@@ -1141,13 +1287,13 @@ retrieve_from_file (const char *file, bool html, int *count)
if (parsed_url)
url_free (parsed_url);
if (filename && opt.delete_after && file_exists_p (filename))
if (filename && opt.delete_after && file_exists_p (filename, NULL))
{
DEBUGP (("\
Removing file due to --delete-after in retrieve_from_file():\n"));
logprintf (LOG_VERBOSE, _("Removing %s.\n"), filename);
if (unlink (filename))
logprintf (LOG_NOTQUIET, "unlink: %s\n", strerror (errno));
logprintf (LOG_NOTQUIET, "Failed to unlink %s: (%d) %s\n", filename, errno, strerror (errno));
dt &= ~RETROKF;
}
@@ -1248,9 +1394,9 @@ rotate_backups(const char *fname)
#endif
int maxlen = strlen (fname) + sizeof (SEP) + numdigit (opt.backups) + AVSL;
char *from = (char *)alloca (maxlen);
char *to = (char *)alloca (maxlen);
struct_stat sb;
char *from = alloca (maxlen);
char *to = alloca (maxlen);
struct stat sb;
int i;
if (stat (fname, &sb) == 0)
@@ -1267,17 +1413,21 @@ rotate_backups(const char *fname)
*/
if (i == opt.backups)
{
sprintf (to, "%s%s%d%s", fname, SEP, i, AVS);
snprintf (to, sizeof(to), "%s%s%d%s", fname, SEP, i, AVS);
delete (to);
}
#endif
sprintf (to, "%s%s%d", fname, SEP, i);
sprintf (from, "%s%s%d", fname, SEP, i - 1);
rename (from, to);
snprintf (to, maxlen, "%s%s%d", fname, SEP, i);
snprintf (from, maxlen, "%s%s%d", fname, SEP, i - 1);
if (rename (from, to))
logprintf (LOG_NOTQUIET, "Failed to rename %s to %s: (%d) %s\n",
from, to, errno, strerror (errno));
}
sprintf (to, "%s%s%d", fname, SEP, 1);
rename(fname, to);
snprintf (to, maxlen, "%s%s%d", fname, SEP, 1);
if (rename(fname, to))
logprintf (LOG_NOTQUIET, "Failed to rename %s to %s: (%d) %s\n",
fname, to, errno, strerror (errno));
}
static bool no_proxy_match (const char *, const char **);

View File

@@ -49,7 +49,9 @@ enum {
rb_skip_startpos = 2,
/* Used by HTTP/HTTPS*/
rb_chunked_transfer_encoding = 4
rb_chunked_transfer_encoding = 4,
rb_compressed_gzip = 8
};
int fd_read_body (const char *, int, FILE *, wgint, wgint, wgint *, wgint *, double *, int, FILE *);

View File

@@ -35,53 +35,11 @@ as that of the covered work. */
#ifndef SYSDEP_H
#define SYSDEP_H
/* Testing for __sun is not enough because it's also defined on SunOS. */
#ifdef __sun
# ifdef __SVR4
# define solaris
# endif
#endif
#if defined(__INTERIX) && !defined(_ALL_SOURCE)
# define _ALL_SOURCE
#endif
/* The "namespace tweaks" below attempt to set a friendly "compilation
environment" under popular operating systems. Default compilation
environment often means that some functions that are "extensions"
are not declared -- `strptime' is one example.
But non-default environments can expose bugs in the system header
files, crippling compilation in _very_ non-obvious ways. Because
of that, we define them only on well-tested architectures where we
know they will work. */
#undef NAMESPACE_TWEAKS
#ifdef solaris
# define NAMESPACE_TWEAKS
#endif
#if defined(__linux__) || defined(__GLIBC__)
# define NAMESPACE_TWEAKS
#endif
#ifdef NAMESPACE_TWEAKS
#endif /* NAMESPACE_TWEAKS */
/* Alloca declaration, based on recommendation in the Autoconf manual.
These have to be after the above namespace tweaks, but before any
non-preprocessor code. */
/* Provided by gnulib on systems that don't have it: */
#include <alloca.h>
/* Must include these, so we can test for the missing stat macros and
define them as necessary. */
#include <sys/types.h>
#include <sys/stat.h>
#include <stdint.h>
#include <inttypes.h>
@@ -95,98 +53,9 @@ as that of the covered work. */
# include "mswindows.h"
#endif
/* Provided by gnulib on systems that don't have it: */
# include <stdbool.h>
#ifndef struct_stat
# define struct_stat struct stat
#endif
#ifndef struct_fstat
# define struct_fstat struct stat
#endif
#include <intprops.h>
/* For CHAR_BIT, LONG_MAX, etc. */
#include <stdbool.h>
#include <limits.h>
#ifndef CHAR_BIT
# define CHAR_BIT 8
#endif
/* These are defined in cmpt.c if missing, so we must declare
them. */
#ifndef HAVE_STRCASECMP
int strcasecmp ();
#endif
#ifndef HAVE_STRNCASECMP
int strncasecmp ();
#endif
#ifndef HAVE_STRPTIME
char *strptime ();
#endif
#ifndef HAVE_TIMEGM
# include <time.h>
time_t timegm (struct tm *);
#endif
#ifndef HAVE_MEMRCHR
void *memrchr (const void *, int, size_t);
#endif
/* These are defined in snprintf.c. It would be nice to have an
snprintf.h, though. */
#ifndef HAVE_SNPRINTF
int snprintf (char *str, size_t count, const char *fmt, ...);
#endif
#ifndef HAVE_VSNPRINTF
#include <stdarg.h>
int vsnprintf (char *str, size_t count, const char *fmt, va_list arg);
#endif
/* Enable system fnmatch only on systems where fnmatch.h is usable.
If the fnmatch on your system is buggy, undef this symbol and a
replacement implementation will be used instead. */
#ifdef HAVE_WORKING_FNMATCH_H
# define SYSTEM_FNMATCH
#endif
#include <fnmatch.h>
/* Provide sig_atomic_t if the system doesn't. */
#ifndef HAVE_SIG_ATOMIC_T
typedef int sig_atomic_t;
#endif
/* Provide uint32_t on the platforms that don't define it. Although
most code should be agnostic about integer sizes, some code really
does need a 32-bit integral type. Such code should use uint32_t.
(The exception is gnu-md5.[ch], which uses its own detection for
portability across platforms.) */
#ifndef HAVE_UINT32_T
# if SIZEOF_INT == 4
typedef unsigned int uint32_t;
# else
# if SIZEOF_LONG == 4
typedef unsigned long uint32_t;
# else
# if SIZEOF_SHORT == 4
typedef unsigned short uint32_t;
# else
#error "Cannot determine a 32-bit unsigned integer type"
# endif
# endif
# endif
#endif
/* If uintptr_t isn't defined, simply typedef it to unsigned long. */
#ifndef HAVE_UINTPTR_T
typedef unsigned long uintptr_t;
#endif
/* If intptr_t isn't defined, simply typedef it to long. */
#ifndef HAVE_INTPTR_T
typedef long intptr_t;
#endif
#include "intprops.h"
#endif /* SYSDEP_H */

141
src/url.c
View File

@@ -43,10 +43,10 @@ as that of the covered work. */
#include "host.h" /* for is_valid_ipv6_address */
#include "c-strcase.h"
#if HAVE_ICONV
#include <iconv.h>
#include <langinfo.h>
#ifdef HAVE_ICONV
# include <iconv.h>
#endif
#include <langinfo.h>
#ifdef __VMS
#include "vms.h"
@@ -459,7 +459,7 @@ url_scheme (const char *url)
int i;
for (i = 0; supported_schemes[i].leading_string; i++)
if (0 == strncasecmp (url, supported_schemes[i].leading_string,
if (0 == c_strncasecmp (url, supported_schemes[i].leading_string,
strlen (supported_schemes[i].leading_string)))
{
if (!(supported_schemes[i].flags & scm_disabled))
@@ -512,6 +512,12 @@ scheme_disable (enum url_scheme scheme)
supported_schemes[scheme].flags |= scm_disabled;
}
const char *
scheme_leading_string (enum url_scheme scheme)
{
return supported_schemes[scheme].leading_string;
}
/* Skip the username and password, if present in the URL. The
function should *not* be called with the complete URL, but with the
portion after the scheme.
@@ -919,6 +925,17 @@ url_parse (const char *url, int *error, struct iri *iri, bool percent_encode)
url_unescape (u->host);
host_modified = true;
/* check for invalid control characters in host name */
for (p = u->host; *p; p++)
{
if (c_iscntrl(*p))
{
url_free(u);
error_code = PE_INVALID_HOST_NAME;
goto error;
}
}
/* Apply IDNA regardless of iri->utf8_encode status */
if (opt.enable_iri && iri)
{
@@ -927,7 +944,6 @@ url_parse (const char *url, int *error, struct iri *iri, bool percent_encode)
{
xfree (u->host);
u->host = new;
u->idn_allocated = true;
host_modified = true;
}
}
@@ -1206,12 +1222,7 @@ url_free (struct url *url)
{
if (url)
{
if (url->idn_allocated) {
idn_free (url->host); /* A dummy if !defined(ENABLE_IRI) */
url->host = NULL;
}
else
xfree (url->host);
xfree (url->host);
xfree (url->path);
xfree (url->url);
@@ -1236,7 +1247,7 @@ mkalldirs (const char *path)
{
const char *p;
char *t;
struct_stat st;
struct stat st;
int res;
p = path + strlen (path);
@@ -1271,12 +1282,14 @@ mkalldirs (const char *path)
name exists, we just remove it and create the directory
anyway. */
DEBUGP (("Removing %s because of directory danger!\n", t));
unlink (t);
if (unlink (t))
logprintf (LOG_NOTQUIET, "Failed to unlink %s (%d): %s\n",
t, errno, strerror(errno));
}
}
res = make_directory (t);
if (res != 0)
logprintf (LOG_NOTQUIET, "%s: %s", t, strerror (errno));
logprintf (LOG_NOTQUIET, "%s: %s\n", t, strerror (errno));
xfree (t);
return res;
}
@@ -1536,11 +1549,11 @@ append_uri_pathel (const char *b, const char *e, bool escaped,
append_null (dest);
}
#ifdef HAVE_ICONV
static char *
convert_fname (char *fname)
{
char *converted_fname = fname;
#if HAVE_ICONV
const char *from_encoding = opt.encoding_remote;
const char *to_encoding = opt.locale;
iconv_t cd;
@@ -1555,9 +1568,9 @@ convert_fname (char *fname)
to_encoding = nl_langinfo (CODESET);
cd = iconv_open (to_encoding, from_encoding);
if (cd == (iconv_t)(-1))
logprintf (LOG_VERBOSE, _("Conversion from %s to %s isn't supported\n"),
quote (from_encoding), quote (to_encoding));
if (cd == (iconv_t) (-1))
logprintf (LOG_VERBOSE, _ ("Conversion from %s to %s isn't supported\n"),
quote (from_encoding), quote (to_encoding));
else
{
inlen = strlen (fname);
@@ -1566,51 +1579,62 @@ convert_fname (char *fname)
done = 0;
for (;;)
{
if (iconv (cd, &fname, &inlen, &s, &outlen) != (size_t)(-1)
&& iconv (cd, NULL, NULL, &s, &outlen) != (size_t)(-1))
{
*(converted_fname + len - outlen - done) = '\0';
iconv_close(cd);
DEBUGP (("Converted file name '%s' (%s) -> '%s' (%s)\n",
orig_fname, from_encoding, converted_fname, to_encoding));
xfree (orig_fname);
return converted_fname;
}
{
errno = 0;
if (iconv (cd, (ICONV_CONST char **) &fname, &inlen, &s, &outlen) == 0
&& iconv (cd, NULL, NULL, &s, &outlen) == 0)
{
*(converted_fname + len - outlen - done) = '\0';
iconv_close (cd);
DEBUGP (("Converted file name '%s' (%s) -> '%s' (%s)\n",
orig_fname, from_encoding, converted_fname, to_encoding));
xfree (orig_fname);
return converted_fname;
}
/* Incomplete or invalid multibyte sequence */
if (errno == EINVAL || errno == EILSEQ)
{
logprintf (LOG_VERBOSE,
_("Incomplete or invalid multibyte sequence encountered\n"));
xfree (converted_fname);
converted_fname = (char *)orig_fname;
break;
}
else if (errno == E2BIG) /* Output buffer full */
{
done = len;
len = outlen = done + inlen * 2;
converted_fname = xrealloc (converted_fname, outlen + 1);
s = converted_fname + done;
}
else /* Weird, we got an unspecified error */
{
logprintf (LOG_VERBOSE, _("Unhandled errno %d\n"), errno);
xfree (converted_fname);
converted_fname = (char *)orig_fname;
break;
}
}
/* Incomplete or invalid multibyte sequence */
if (errno == EINVAL || errno == EILSEQ || errno == 0)
{
if (errno)
logprintf (LOG_VERBOSE,
_ ("Incomplete or invalid multibyte sequence encountered\n"));
else
logprintf (LOG_VERBOSE,
_ ("Unconvertable multibyte sequence encountered\n"));
xfree (converted_fname);
converted_fname = (char *) orig_fname;
break;
}
else if (errno == E2BIG) /* Output buffer full */
{
done = len;
len = outlen = done + inlen * 2;
converted_fname = xrealloc (converted_fname, outlen + 1);
s = converted_fname + done;
}
else /* Weird, we got an unspecified error */
{
logprintf (LOG_VERBOSE, _ ("Unhandled errno %d\n"), errno);
xfree (converted_fname);
converted_fname = (char *) orig_fname;
break;
}
}
DEBUGP (("Failed to convert file name '%s' (%s) -> '?' (%s)\n",
orig_fname, from_encoding, to_encoding));
orig_fname, from_encoding, to_encoding));
}
iconv_close(cd);
#endif
return converted_fname;
}
#else
static char *
convert_fname (char *fname)
{
return fname;
}
#endif
/* Append to DEST the directory structure that corresponds the
directory part of URL's path. For example, if the URL is
@@ -1726,6 +1750,9 @@ url_file_name (const struct url *u, char *replaced_filename)
fname_len_check = concat_strings (u_file, FN_QUERY_SEP_STR, u->query, NULL);
else
fname_len_check = strdupdelim (u_file, u_file + strlen (u_file));
/* convert before concat with local path */
fname_len_check = convert_fname (fname_len_check);
}
else
{
@@ -1787,8 +1814,6 @@ url_file_name (const struct url *u, char *replaced_filename)
xfree (temp_fnres.base);
fname = convert_fname (fname);
/* Check the cases in which the unique extensions are not used:
1) Clobbering is turned off (-nc).
2) Retrieval with regetting.
@@ -1800,7 +1825,7 @@ url_file_name (const struct url *u, char *replaced_filename)
directory (see `mkalldirs' for explanation). */
if (ALLOW_CLOBBER
&& !(file_exists_p (fname) && !file_non_directory_p (fname)))
&& !(file_exists_p (fname, NULL) && !file_non_directory_p (fname)))
{
unique = fname;
}

View File

@@ -99,10 +99,6 @@ struct url
/* Username and password (unquoted). */
char *user;
char *passwd;
/* 'host' is allocated by idna_to_ascii_8z() via idn_encode().
* Call 'idn_free()' to free this memory. */
bool idn_allocated;
};
/* Function declarations */
@@ -124,6 +120,7 @@ bool url_has_scheme (const char *);
bool url_valid_scheme (const char *);
int scheme_default_port (enum url_scheme);
void scheme_disable (enum url_scheme);
const char *scheme_leading_string (enum url_scheme);
char *url_string (const struct url *, enum url_auth_mode);
char *url_file_name (const struct url *, char *);

View File

@@ -45,6 +45,7 @@ as that of the covered work. */
#include <assert.h>
#include <stdarg.h>
#include <locale.h>
#include <errno.h>
#if HAVE_UTIME
# include <sys/types.h>
@@ -113,7 +114,7 @@ as that of the covered work. */
#include "exits.h"
#include "c-strcase.h"
static void _Noreturn
_Noreturn static void
memfatal (const char *context, long attempted_size)
{
/* Make sure we don't try to store part of the log line, and thus
@@ -235,14 +236,20 @@ xstrdup_lower (const char *s)
/* Copy the string formed by two pointers (one on the beginning, other
on the char after the last char) to a new, malloc-ed location.
0-terminate it. */
0-terminate it.
If both pointers are NULL, the function returns an empty string. */
char *
strdupdelim (const char *beg, const char *end)
{
char *res = xmalloc (end - beg + 1);
memcpy (res, beg, end - beg);
res[end - beg] = '\0';
return res;
if (beg && beg <= end)
{
char *res = xmalloc (end - beg + 1);
memcpy (res, beg, end - beg);
res[end - beg] = '\0';
return res;
}
return xstrdup("");
}
/* Parse a string containing comma-separated elements, and return a
@@ -292,13 +299,6 @@ sepstring (const char *s)
vsnprintf until the correct size is found. Since Wget also ships a
fallback implementation of vsnprintf, this should be portable. */
/* Constant is using for limits memory allocation for text buffer.
Applicable in situation when: vasprintf is not available in the system
and vsnprintf return -1 when long line is truncated (in old versions of
glibc and in other system where C99 doesn`t support) */
#define FMT_MAX_LENGTH 1048576
char *
aprintf (const char *fmt, ...)
{
@@ -318,6 +318,13 @@ aprintf (const char *fmt, ...)
return str;
#else /* not HAVE_VASPRINTF */
/* Constant is using for limits memory allocation for text buffer.
Applicable in situation when: vasprintf is not available in the system
and vsnprintf return -1 when long line is truncated (in old versions of
glibc and in other system where C99 doesn`t support) */
#define FMT_MAX_LENGTH 1048576
/* vasprintf is unavailable. snprintf into a small buffer and
resize it as necessary. */
int size = 32;
@@ -567,7 +574,7 @@ int
remove_link (const char *file)
{
int err = 0;
struct_stat st;
struct stat st;
if (lstat (file, &st) == 0 && S_ISLNK (st.st_mode))
{
@@ -580,21 +587,42 @@ remove_link (const char *file)
return err;
}
/* Does FILENAME exist? This is quite a lousy implementation, since
it supplies no error codes -- only a yes-or-no answer. Thus it
will return that a file does not exist if, e.g., the directory is
unreadable. I don't mind it too much currently, though. The
proper way should, of course, be to have a third, error state,
other than true/false, but that would introduce uncalled-for
additional complexity to the callers. */
/* Does FILENAME exist? */
bool
file_exists_p (const char *filename)
file_exists_p (const char *filename, file_stats_t *fstats)
{
#ifdef HAVE_ACCESS
return access (filename, F_OK) >= 0;
struct stat buf;
#if defined(WINDOWS) || defined(__VMS)
int ret = stat (filename, &buf);
if (ret >= 0)
{
if (fstats != NULL)
fstats->access_err = errno;
}
return ret >= 0;
#else
struct_stat buf;
return stat (filename, &buf) >= 0;
errno = 0;
if (stat (filename, &buf) == 0 && S_ISREG(buf.st_mode) &&
(((S_IRUSR & buf.st_mode) && (getuid() == buf.st_uid)) ||
((S_IRGRP & buf.st_mode) && group_member(buf.st_gid)) ||
(S_IROTH & buf.st_mode))) {
if (fstats != NULL)
{
fstats->access_err = 0;
fstats->st_ino = buf.st_ino;
fstats->st_dev = buf.st_dev;
}
return true;
}
else
{
if (fstats != NULL)
fstats->access_err = (errno == 0 ? EACCES : errno);
errno = 0;
return false;
}
/* NOTREACHED */
#endif
}
@@ -603,7 +631,7 @@ file_exists_p (const char *filename)
bool
file_non_directory_p (const char *path)
{
struct_stat buf;
struct stat buf;
/* Use lstat() rather than stat() so that symbolic links pointing to
directories can be identified correctly. */
if (lstat (path, &buf) != 0)
@@ -630,7 +658,7 @@ file_size (const char *filename)
fclose (fp);
return size;
#else
struct_stat st;
struct stat st;
if (stat (filename, &st) < 0)
return -1;
return st.st_size;
@@ -662,7 +690,7 @@ unique_name_1 (const char *prefix)
do
number_to_string (template_tail, count++);
while (file_exists_p (template));
while (file_exists_p (template, NULL));
return xstrdup (template);
}
@@ -690,7 +718,7 @@ unique_name (const char *file, bool allow_passthrough)
{
/* If the FILE itself doesn't exist, return it without
modification. */
if (!file_exists_p (file))
if (!file_exists_p (file, NULL))
return allow_passthrough ? (char *)file : xstrdup (file);
/* Otherwise, find a numeric suffix that results in unused file name
@@ -819,7 +847,7 @@ fopen_excl (const char *fname, int binary)
/* Manually check whether the file exists. This is prone to race
conditions, but systems without O_EXCL haven't deserved
better. */
if (file_exists_p (fname))
if (file_exists_p (fname, NULL))
{
errno = EEXIST;
return NULL;
@@ -828,6 +856,113 @@ fopen_excl (const char *fname, int binary)
#endif /* not O_EXCL */
}
/* fopen_stat() assumes that file_exists_p() was called earlier.
file_stats_t passed to this function was returned from file_exists_p()
This is to prevent TOCTTOU race condition.
Details : FIO45-C from https://www.securecoding.cert.org/
Note that for creating a new file, this check is not useful
Input:
fname => Name of file to open
mode => File open mode
fstats => Saved file_stats_t about file that was checked for existence
Returns:
NULL if there was an error
FILE * of opened file stream
*/
FILE *
fopen_stat(const char *fname, const char *mode, file_stats_t *fstats)
{
int fd;
FILE *fp;
struct stat fdstats;
fp = fopen (fname, mode);
if (fp == NULL)
{
logprintf (LOG_NOTQUIET, _("Failed to Fopen file %s\n"), fname);
return NULL;
}
fd = fileno (fp);
if (fd < 0)
{
logprintf (LOG_NOTQUIET, _("Failed to get FD for file %s\n"), fname);
fclose (fp);
return NULL;
}
memset(&fdstats, 0, sizeof(fdstats));
if (fstat (fd, &fdstats) == -1)
{
logprintf (LOG_NOTQUIET, _("Failed to stat file %s, (check permissions)\n"), fname);
fclose (fp);
return NULL;
}
#if !(defined(WINDOWS) || defined(__VMS))
if (fstats != NULL &&
(fdstats.st_dev != fstats->st_dev ||
fdstats.st_ino != fstats->st_ino))
{
/* File changed since file_exists_p() : NOT SAFE */
logprintf (LOG_NOTQUIET, _("File %s changed since the last check. Security check failed."), fname);
fclose (fp);
return NULL;
}
#endif
return fp;
}
/* open_stat assumes that file_exists_p() was called earlier to save file_stats
file_stats_t passed to this function was returned from file_exists_p()
This is to prevent TOCTTOU race condition.
Details : FIO45-C from https://www.securecoding.cert.org/
Note that for creating a new file, this check is not useful
Input:
fname => Name of file to open
flags => File open flags
mode => File open mode
fstats => Saved file_stats_t about file that was checked for existence
Returns:
-1 if there was an error
file descriptor of opened file stream
*/
int
open_stat(const char *fname, int flags, mode_t mode, file_stats_t *fstats)
{
int fd;
struct stat fdstats;
fd = open (fname, flags, mode);
if (fd < 0)
{
logprintf (LOG_NOTQUIET, _("Failed to open file %s, reason :%s\n"), fname, strerror(errno));
return -1;
}
memset(&fdstats, 0, sizeof(fdstats));
if (fstat (fd, &fdstats) == -1)
{
logprintf (LOG_NOTQUIET, _("Failed to stat file %s, error: %s\n"), fname, strerror(errno));
return -1;
}
#if !(defined(WINDOWS) || defined(__VMS))
if (fstats != NULL &&
(fdstats.st_dev != fstats->st_dev ||
fdstats.st_ino != fstats->st_ino))
{
/* File changed since file_exists_p() : NOT SAFE */
logprintf (LOG_NOTQUIET, _("Trying to open file %s but it changed since last check. Security check failed."), fname);
close (fd);
return -1;
}
#endif
return fd;
}
/* Create DIRECTORY. If some of the pathname components of DIRECTORY
are missing, create them first. In case any mkdir() call fails,
return its error status. Returns 0 on successful completion.
@@ -856,7 +991,7 @@ make_directory (const char *directory)
/* Check whether the directory already exists. Allow creation of
of intermediate directories to fail, as the initial path components
are not necessarily directories! */
if (!file_exists_p (dir))
if (!file_exists_p (dir, NULL))
ret = mkdir (dir, 0777);
else
ret = 0;
@@ -1184,7 +1319,7 @@ wget_read_file (const char *file)
#ifdef HAVE_MMAP
{
struct_fstat buf;
struct stat buf;
if (fstat (fd, &buf) < 0)
goto mmap_lose;
fm->length = buf.st_size;
@@ -1327,7 +1462,7 @@ merge_vecs (char **v1, char **v2)
for (j = 0; v2[j]; j++)
;
/* Reallocate v1. */
v1 = xrealloc (v1, (i + j + 1) * sizeof (char **));
v1 = xrealloc (v1, (i + j + 1) * sizeof (char *));
memcpy (v1 + i, v2, (j + 1) * sizeof (char *));
xfree (v2);
return v1;
@@ -1600,7 +1735,7 @@ numdigit (wgint number)
{
int cnt = 1;
if (number < 0)
++cnt; /* accomodate '-' */
++cnt; /* accommodate '-' */
while ((number /= 10) != 0)
++cnt;
return cnt;
@@ -1930,7 +2065,7 @@ random_float (void)
static sigjmp_buf run_with_timeout_env;
static void _Noreturn
_Noreturn static void
abort_run_with_timeout (int sig _GL_UNUSED)
{
assert (sig == SIGALRM);
@@ -2045,13 +2180,16 @@ run_with_timeout (double timeout, void (*fun) (void *), void *arg)
return false;
}
signal (SIGALRM, abort_run_with_timeout);
if (SETJMP (run_with_timeout_env) != 0)
{
/* Longjumped out of FUN with a timeout. */
signal (SIGALRM, SIG_DFL);
return true;
}
else
{
signal (SIGALRM, abort_run_with_timeout);
}
alarm_set (timeout);
fun (arg);
@@ -2140,7 +2278,7 @@ xsleep (double seconds)
base64 data. */
size_t
base64_encode (const void *data, size_t length, char *dest)
wget_base64_encode (const void *data, size_t length, char *dest)
{
/* Conversion table. */
static const char tbl[64] = {
@@ -2197,7 +2335,7 @@ base64_encode (const void *data, size_t length, char *dest)
/* Decode data from BASE64 (a null-terminated string) into memory
pointed to by DEST. DEST is assumed to be large enough to
accomodate the decoded data, which is guaranteed to be no more than
accommodate the decoded data, which is guaranteed to be no more than
3/4*strlen(base64).
Since DEST is assumed to contain binary data, it is not
@@ -2208,7 +2346,7 @@ base64_encode (const void *data, size_t length, char *dest)
This function originates from Free Recode. */
ssize_t
base64_decode (const char *base64, void *dest)
wget_base64_decode (const char *base64, void *dest, size_t size)
{
/* Table of base64 values for first 128 characters. Note that this
assumes ASCII (but so does Wget in other places). */
@@ -2232,7 +2370,8 @@ base64_decode (const char *base64, void *dest)
#define IS_BASE64(c) ((IS_ASCII (c) && BASE64_CHAR_TO_VALUE (c) >= 0) || c == '=')
const char *p = base64;
char *q = dest;
unsigned char *q = dest;
ssize_t n = 0;
while (1)
{
@@ -2254,7 +2393,12 @@ base64_decode (const char *base64, void *dest)
if (c == '=' || !IS_BASE64 (c))
return -1; /* illegal char while decoding base64 */
value |= BASE64_CHAR_TO_VALUE (c) << 12;
*q++ = value >> 16;
if (size)
{
*q++ = value >> 16;
size--;
}
n++;
/* Process third byte of a quadruplet. */
NEXT_CHAR (c, p);
@@ -2274,7 +2418,12 @@ base64_decode (const char *base64, void *dest)
}
value |= BASE64_CHAR_TO_VALUE (c) << 6;
*q++ = 0xff & value >> 8;
if (size)
{
*q++ = 0xff & value >> 8;
size--;
}
n++;
/* Process fourth byte of a quadruplet. */
NEXT_CHAR (c, p);
@@ -2286,12 +2435,17 @@ base64_decode (const char *base64, void *dest)
return -1; /* illegal char while decoding base64 */
value |= BASE64_CHAR_TO_VALUE (c);
*q++ = 0xff & value;
if (size)
{
*q++ = 0xff & value;
size--;
}
n++;
}
#undef IS_BASE64
#undef BASE64_CHAR_TO_VALUE
return q - (char *) dest;
return n;
}
#ifdef HAVE_LIBPCRE
@@ -2413,17 +2567,17 @@ mergesort_internal (void *base, void *temp, size_t size, size_t from, size_t to,
}
/* Stable sort with interface exactly like standard library's qsort.
Uses mergesort internally, allocating temporary storage with
alloca. */
Uses mergesort internally. */
void
stable_sort (void *base, size_t nmemb, size_t size,
int (*cmpfun) (const void *, const void *))
{
if (size > 1)
if (nmemb > 1 && size > 1)
{
void *temp = alloca (nmemb * size * sizeof (void *));
void *temp = xmalloc (nmemb * size);
mergesort_internal (base, temp, size, 0, nmemb - 1, cmpfun);
xfree(temp);
}
}
@@ -2524,7 +2678,7 @@ wg_hex_to_string (char *str_buffer, const char *hex_buffer, size_t hex_len)
for (i = 0; i < hex_len; i++)
{
/* Each byte takes 2 characters. */
sprintf (str_buffer + 2 * i, "%02x", hex_buffer[i] & 0xFF);
sprintf (str_buffer + 2 * i, "%02x", (unsigned) (hex_buffer[i] & 0xFF));
}
/* Null-terminate result. */
@@ -2588,7 +2742,7 @@ wg_pubkey_pem_to_der (const char *pem, unsigned char **der, size_t *der_len)
base64data = xmalloc (BASE64_LENGTH(stripped_pem_count));
size = base64_decode (stripped_pem, base64data);
size = wget_base64_decode (stripped_pem, base64data, BASE64_LENGTH(stripped_pem_count));
if (size < 0) {
xfree (base64data); /* malformed base64 from server */
@@ -2627,54 +2781,65 @@ wg_pin_peer_pubkey (const char *pinnedpubkey, const char *pubkey, size_t pubkeyl
return result;
/* only do this if pinnedpubkey starts with "sha256//", length 8 */
if (strncmp (pinnedpubkey, "sha256//", 8) == 0) {
/* compute sha256sum of public key */
sha256sumdigest = xmalloc (SHA256_DIGEST_SIZE);
sha256_buffer (pubkey, pubkeylen, sha256sumdigest);
expectedsha256sumdigest = xmalloc (SHA256_DIGEST_SIZE + 1);
if (strncmp (pinnedpubkey, "sha256//", 8) == 0)
{
/* compute sha256sum of public key */
sha256sumdigest = xmalloc (SHA256_DIGEST_SIZE);
sha256_buffer (pubkey, pubkeylen, sha256sumdigest);
expectedsha256sumdigest = xmalloc (SHA256_DIGEST_SIZE);
/* it starts with sha256//, copy so we can modify it */
pinkeylen = strlen (pinnedpubkey) + 1;
pinkeycopy = xmalloc (pinkeylen);
memcpy (pinkeycopy, pinnedpubkey, pinkeylen);
/* it starts with sha256//, copy so we can modify it */
pinkeylen = strlen (pinnedpubkey) + 1;
pinkeycopy = xmalloc (pinkeylen);
memcpy (pinkeycopy, pinnedpubkey, pinkeylen);
/* point begin_pos to the copy, and start extracting keys */
begin_pos = pinkeycopy;
do
{
end_pos = strstr (begin_pos, ";sha256//");
/*
* if there is an end_pos, null terminate,
* otherwise it'll go to the end of the original string
*/
if (end_pos)
end_pos[0] = '\0';
/* point begin_pos to the copy, and start extracting keys */
begin_pos = pinkeycopy;
do
{
end_pos = strstr (begin_pos, ";sha256//");
/*
* if there is an end_pos, null terminate,
* otherwise it'll go to the end of the original string
*/
if (end_pos)
end_pos[0] = '\0';
/* decode base64 pinnedpubkey, 8 is length of "sha256//" */
decoded_hash_length = base64_decode (begin_pos + 8, expectedsha256sumdigest);
/* if valid base64, compare sha256 digests directly */
if (SHA256_DIGEST_SIZE == decoded_hash_length &&
!memcmp (sha256sumdigest, expectedsha256sumdigest, SHA256_DIGEST_SIZE)) {
result = true;
break;
/* decode base64 pinnedpubkey, 8 is length of "sha256//" */
decoded_hash_length = wget_base64_decode (begin_pos + 8, expectedsha256sumdigest, SHA256_DIGEST_SIZE);
/* if valid base64, compare sha256 digests directly */
if (SHA256_DIGEST_SIZE == decoded_hash_length)
{
if (!memcmp (sha256sumdigest, expectedsha256sumdigest, SHA256_DIGEST_SIZE))
{
result = true;
break;
}
}
else
logprintf (LOG_VERBOSE, _ ("Skipping key with wrong size (%d/%d): %s\n"),
(strlen (begin_pos + 8) * 3) / 4, SHA256_DIGEST_SIZE,
quote (begin_pos + 8));
/*
* change back the null-terminator we changed earlier,
* and look for next begin
*/
if (end_pos)
{
end_pos[0] = ';';
begin_pos = strstr (end_pos, "sha256//");
}
}
while (end_pos && begin_pos);
/*
* change back the null-terminator we changed earlier,
* and look for next begin
*/
if (end_pos) {
end_pos[0] = ';';
begin_pos = strstr (end_pos, "sha256//");
}
} while (end_pos && begin_pos);
xfree (sha256sumdigest);
xfree (expectedsha256sumdigest);
xfree (pinkeycopy);
xfree (sha256sumdigest);
xfree (expectedsha256sumdigest);
xfree (pinkeycopy);
return result;
}
return result;
}
/* fall back to assuming this is a file path */
fm = wget_read_file (pinnedpubkey);
@@ -2694,11 +2859,12 @@ wg_pin_peer_pubkey (const char *pinnedpubkey, const char *pubkey, size_t pubkeyl
goto cleanup;
/* If the sizes are the same, it can't be base64 encoded, must be der */
if (pubkeylen == size) {
if (!memcmp (pubkey, fm->content, pubkeylen))
result = true;
goto cleanup;
}
if (pubkeylen == size)
{
if (!memcmp (pubkey, fm->content, pubkeylen))
result = true;
goto cleanup;
}
/*
* Otherwise we will assume it's PEM and try to decode it
@@ -2720,7 +2886,7 @@ wg_pin_peer_pubkey (const char *pinnedpubkey, const char *pubkey, size_t pubkeyl
if (pubkeylen == pem_len && !memcmp (pubkey, pem_ptr, pubkeylen))
result = true;
cleanup:
cleanup:
xfree (buf);
xfree (pem_ptr);
wget_read_file_free (fm);

View File

@@ -78,15 +78,23 @@ void fork_to_background (void);
char *aprintf (const char *, ...) GCC_FORMAT_ATTR (1, 2);
char *concat_strings (const char *, ...);
typedef struct file_stat_s {
int access_err; /* Error in accecssing file : Not present vs permission */
ino_t st_ino; /* st_ino from stats() on the file before open() */
dev_t st_dev; /* st_dev from stats() on the file before open() */
} file_stats_t;
void touch (const char *, time_t);
int remove_link (const char *);
bool file_exists_p (const char *);
bool file_exists_p (const char *, file_stats_t *);
bool file_non_directory_p (const char *);
wgint file_size (const char *);
int make_directory (const char *);
char *unique_name (const char *, bool);
FILE *unique_create (const char *, bool, char **);
FILE *fopen_excl (const char *, int);
FILE *fopen_stat (const char *, const char *, file_stats_t *);
int open_stat (const char *, int, mode_t, file_stats_t *);
char *file_merge (const char *, const char *);
int fnmatch_nocase (const char *, const char *, int);
@@ -140,8 +148,8 @@ void xsleep (double);
/* How many bytes it will take to store LEN bytes in base64. */
#define BASE64_LENGTH(len) (4 * (((len) + 2) / 3))
size_t base64_encode (const void *, size_t, char *);
ssize_t base64_decode (const char *, void *);
size_t wget_base64_encode (const void *, size_t, char *);
ssize_t wget_base64_decode (const char *, void *, size_t);
#ifdef HAVE_LIBPCRE
void *compile_pcre_regex (const char *);

View File

@@ -32,6 +32,7 @@ as that of the covered work. */
#include "utils.h"
#include "version.h"
#include "dirname.h"
#include "url.h"
#include <stdio.h>
#include <stdlib.h>
@@ -1365,6 +1366,8 @@ warc_write_cdx_record (const char *url, const char *timestamp_str,
mime_type = "-";
if (redirect_location == NULL || strlen(redirect_location) == 0)
redirect_location = "-";
else
redirect_location = url_escape(redirect_location);
number_to_string (offset_string, offset);
@@ -1413,7 +1416,7 @@ warc_write_revisit_record (const char *url, const char *timestamp_str,
warc_write_header ("WARC-Refers-To", refers_to);
warc_write_header ("WARC-Profile", "http://netpreserve.org/warc/1.0/revisit/identical-payload-digest");
warc_write_header ("WARC-Truncated", "length");
warc_write_header ("WARC-Target-URI", url);
warc_write_header_uri ("WARC-Target-URI", url);
warc_write_date_header (timestamp_str);
warc_write_ip_header (ip);
warc_write_header ("Content-Type", "application/http;msgtype=response");
@@ -1505,7 +1508,7 @@ warc_write_response_record (const char *url, const char *timestamp_str,
warc_write_header ("WARC-Record-ID", response_uuid);
warc_write_header ("WARC-Warcinfo-ID", warc_current_warcinfo_uuid_str);
warc_write_header ("WARC-Concurrent-To", concurrent_to_uuid);
warc_write_header ("WARC-Target-URI", url);
warc_write_header_uri ("WARC-Target-URI", url);
warc_write_date_header (timestamp_str);
warc_write_ip_header (ip);
warc_write_header ("WARC-Block-Digest", block_digest);
@@ -1562,7 +1565,7 @@ warc_write_record (const char *record_type, const char *resource_uuid,
warc_write_header ("WARC-Record-ID", resource_uuid);
warc_write_header ("WARC-Warcinfo-ID", warc_current_warcinfo_uuid_str);
warc_write_header ("WARC-Concurrent-To", concurrent_to_uuid);
warc_write_header ("WARC-Target-URI", url);
warc_write_header_uri ("WARC-Target-URI", url);
warc_write_date_header (timestamp_str);
warc_write_ip_header (ip);
warc_write_digest_headers (body, payload_offset);

View File

@@ -361,7 +361,8 @@ typedef enum
TIMECONV_ERR,
METALINK_PARSE_ERROR, METALINK_RETR_ERROR,
METALINK_CHKSUM_ERROR, METALINK_SIG_ERROR, METALINK_MISSING_RESOURCE,
RETR_WITH_METALINK
RETR_WITH_METALINK,
METALINK_SIZE_ERROR
} uerr_t;
/* 2005-02-19 SMS.

79
src/xattr.c Normal file
View File

@@ -0,0 +1,79 @@
/* xattr.h -- POSIX Extended Attribute support.
Copyright (C) 2016 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, see <http://www.gnu.org/licenses/>. */
#include "wget.h"
#include <stdio.h>
#include <string.h>
#include "log.h"
#include "xattr.h"
#ifdef USE_XATTR
static int
write_xattr_metadata (const char *name, const char *value, FILE *fp)
{
int retval = -1;
if (name && value && fp)
{
retval = fsetxattr (fileno (fp), name, value, strlen (value), 0);
/* FreeBSD's extattr_set_fd returns the length of the extended attribute. */
retval = (retval < 0) ? retval : 0;
if (retval)
DEBUGP (("Failed to set xattr %s.\n", quote(name)));
}
return retval;
}
#else /* USE_XATTR */
static int
write_xattr_metadata (const char *name, const char *value, FILE *fp)
{
(void)name;
(void)value;
(void)fp;
return 0;
}
#endif /* USE_XATTR */
int
set_file_metadata (const char *origin_url, const char *referrer_url, FILE *fp)
{
/* Save metadata about where the file came from (requested, final URLs) to
* user POSIX Extended Attributes of retrieved file.
*
* For more details about the user namespace see
* [http://freedesktop.org/wiki/CommonExtendedAttributes] and
* [http://0pointer.de/lennart/projects/mod_mime_xattr/].
*/
int retval = -1;
if (!origin_url || !fp)
return retval;
retval = write_xattr_metadata ("user.xdg.origin.url", escnonprint_uri (origin_url), fp);
if ((!retval) && referrer_url)
retval = write_xattr_metadata ("user.xdg.referrer.url", escnonprint_uri (referrer_url), fp);
return retval;
}

45
src/xattr.h Normal file
View File

@@ -0,0 +1,45 @@
/* xattr.h -- POSIX Extended Attribute function mappings.
Copyright (C) 2016 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, see <http://www.gnu.org/licenses/>. */
#include <stdio.h>
#ifndef _XATTR_H
#define _XATTR_H
/* Store metadata name/value attributes against fp. */
int set_file_metadata (const char *origin_url, const char *referrer_url, FILE *fp);
#if defined(__linux)
/* libc on Linux has fsetxattr (5 arguments). */
# include <sys/xattr.h>
# define USE_XATTR
#elif defined(__APPLE__)
/* libc on OS/X has fsetxattr (6 arguments). */
# include <sys/xattr.h>
# define fsetxattr(file, name, buffer, size, flags) \
fsetxattr ((file), (name), (buffer), (size), 0, (flags))
# define USE_XATTR
#elif defined(__FreeBSD_version) && (__FreeBSD_version > 500000)
/* FreeBSD */
# include <sys/types.h>
# include <sys/extattr.h>
# define fsetxattr(file, name, buffer, size, flags) \
extattr_set_fd ((file), EXTATTR_NAMESPACE_USER, (name), (buffer), (size))
# define USE_XATTR
#endif
#endif /* _XATTR_H */

View File

@@ -27,8 +27,38 @@
if METALINK_IS_ENABLED
METALINK_TESTS = Test-metalink-xml.py \
Test-metalink-http.py
METALINK_TESTS = Test-metalink-http.py \
Test-metalink-http-quoted.py \
Test-metalink-http-baddigest.py \
Test-metalink-http-xml.py \
Test-metalink-http-xml-trust.py \
Test-metalink-http-xml-trust-name.py \
Test-metalink-http-xml-type.py \
Test-metalink-http-xml-type-trust.py \
Test-metalink-http-xml-type-content.py \
Test-metalink-http-xml-type-trust-content.py \
Test-metalink-xml.py \
Test-metalink-xml-continue.py \
Test-metalink-xml-relpath.py \
Test-metalink-xml-abspath.py \
Test-metalink-xml-homepath.py \
Test-metalink-xml-trust.py \
Test-metalink-xml-relpath-trust.py \
Test-metalink-xml-abspath-trust.py \
Test-metalink-xml-homepath-trust.py \
Test-metalink-xml-prefix.py \
Test-metalink-xml-relprefix.py \
Test-metalink-xml-absprefix.py \
Test-metalink-xml-homeprefix.py \
Test-metalink-xml-prefix-trust.py \
Test-metalink-xml-relprefix-trust.py \
Test-metalink-xml-absprefix-trust.py \
Test-metalink-xml-homeprefix-trust.py \
Test-metalink-xml-emptyprefix-trust.py \
Test-metalink-xml-size.py \
Test-metalink-xml-nohash.py \
Test-metalink-xml-nourls.py \
Test-metalink-xml-urlbreak.py
else
METALINK_TESTS =
endif
@@ -42,8 +72,13 @@ if WITH_SSL
endif
if HAVE_PYTHON3
TESTS = Test-auth-basic-fail.py \
TESTS = Test-504.py \
Test-auth-basic-fail.py \
Test-auth-basic.py \
Test-auth-basic-netrc.py \
Test-auth-basic-netrc-user-given.py \
Test-auth-basic-netrc-pass-given.py \
Test-auth-basic-no-netrc-fail.py \
Test-auth-both.py \
Test-auth-digest.py \
Test-auth-no-challenge.py \
@@ -51,6 +86,7 @@ if HAVE_PYTHON3
Test-auth-retcode.py \
Test-auth-with-content-disposition.py \
Test-c-full.py \
Test-condget.py \
Test-Content-disposition-2.py \
Test-Content-disposition.py \
Test--convert-links--content-on-error.py \
@@ -59,24 +95,26 @@ if HAVE_PYTHON3
Test-cookie-expires.py \
Test-cookie.py \
Test-Head.py \
Test-hsts.py \
Test--https.py \
Test--https-crl.py \
Test-missing-scheme-retval.py \
Test-O.py \
Test-pinnedpubkey-der-https.py \
Test-pinnedpubkey-der-no-check-https.py \
Test-pinnedpubkey-hash-https.py \
Test-pinnedpubkey-hash-no-check-fail-https.py \
Test-pinnedpubkey-pem-fail-https.py \
Test-pinnedpubkey-pem-https.py \
Test-hsts.py \
Test-O.py \
Test-Post.py \
Test-504.py \
Test--spider-r.py \
Test--rejected-log.py \
Test-recursive-basic.py \
Test-recursive-include.py \
Test-recursive-redirect.py \
Test-redirect.py \
Test-redirect-crash.py \
Test--rejected-log.py \
Test-reserved-chars.py \
Test-condget.py \
Test--spider-r.py \
$(METALINK_TESTS)
endif

View File

@@ -4,7 +4,7 @@ Install Instructions:
================================================================================
This Test Suite exploits the Parallel Test Harness available in GNU Autotools.
Since it uses features from a relatively recent verion of Autotools, the minimum
Since it uses features from a relatively recent version of Autotools, the minimum
required version as been bumped up to 1.11.
Run the './configure' command to generate the Makefile and then run 'make check'
to execute the Test Suite. Use the '-j n' option with 'make check' to execute
@@ -43,7 +43,8 @@ Working:
================================================================================
The Test Files are valid Python scripts and the default mask for them is 755.
A singular Test must be invoked in the following manner:
A singular Test must be invoked in the following manner, with the current
directory being the testenv directory:
$ ./python3 <Name of Test File> OR
$ ./<Name of Test File>
The script will then initialize the various elements and pass them to an object
@@ -117,12 +118,11 @@ from misc.wget_file import WgetFile
It is recommended that a small description of the Test Case is provided next.
This would be very helpful to future contributors.
Next, is the const variable, TEST_NAME that defines the name of the Test.
Each File in the Test must be represented as a WgetFile object. The WgetFile
Class has the following prototype:
WgetFile (str name, str contents, str timestamp, dict rules)
None except name is a mandatory paramter, one may pass only those parameters
None except name is a mandatory parameter, one may pass only those parameters
that are required by the File object.
The timestamp string should be in a format: "YYYY-MM-DD HH:MM:SS" in UTC zone.
@@ -130,14 +130,15 @@ The rules object is a dictionary element, with the key as the Rule Name and
value as the Rule Data. In most cases, the Rule Data is another dictionary.
Various variables used consistently across all tests are:
* WGET_OPTIONS: The command line string passed to Wget upon invokation. This
* WGET_OPTIONS: The command line string passed to Wget upon invocation. This
string may contain URLs, like in the case where in-URL authentication is
used. Variable names passed like {{var_name}} will be replaced by the
contents of the variable self.var_name before being passed to Wget
* WGET_URLS: This is a list of filenames which will be appended as the URLs
to Wget during invokation. This is a list of lists, where WGET_URLS[0]
to Wget during invocation. This is a list of lists, where WGET_URLS[0]
represents the list of Filenames called from Server[0], WGET_URLS[1] is a
list of files downloaded from Server[2], etc.
list of files downloaded from Server[2], etc. They must be relative URLs,
i.e., not start with "/".
* Files: This variable defines the files that exist in the Server's
filesystem. The Files variable is a list of lists of WgetFile objects.
This means that File[0] is a list of WgetFile objects that lie on Server[0],
@@ -154,13 +155,11 @@ Various variables used consistently across all tests are:
Both, the HTTPTest and FTPTest modules have the same prototype:
{
name,
pre_hook,
test_options,
post_hook,
protocols
}
name should be a string, and is usually passed to the TEST_NAME variable,
the three hooks should be Python dict objects and protocols should be a list of
protocols, like [HTTP, HTTPS].
@@ -215,7 +214,7 @@ executed. The currently supported options are:
download. The complete URL will be created and passed to Wget
automatically. (alias URLs)
* WgetCommands : A string consisting of the various commandline switches
sent to Wget upon invokation. Any data placed between {{ }} in this string
sent to Wget upon invocation. Any data placed between {{ }} in this string
will be replaced with the contents of self.<data> before being passed to
Wget. This is particularly useful for getting the hostname and port for a
file. While all Download URL's are passed to Urls, a notable exception is
@@ -281,13 +280,6 @@ red-flagged as a XPASS. Currently, tests expected to fail under valgrind are not
explicitly marked as XFAIL. Tests failing under valgrind must always be
considered a blocking error.
Remember to always name the Test correctly using the TEST_NAME variable. This
is essential since a directory with the Test Name is created and this can
cause synchronization problems when the Parallel Test Harness is used.
One can use the following command on Unix systems to check for TEST_NAME
clashes:
$ grep -r -h "TEST_NAME =" | cut -c13- | uniq -c -d
Work Remaining:
================================================================================
@@ -296,7 +288,7 @@ Some amount of work still remains to be done.
* Support parallel-wget branch
* Support to spawn multiple servers is already in place. Need to handle
multiple requests to a server simultaneously. Use THreading MixIn.
* SSL Tests. Use xyne's HTTPS server implemention
* SSL Tests. Use xyne's HTTPS server implementation
* Complete support for FTP Tests
* IRI Support. This shouldn't require much effort

View File

@@ -14,7 +14,7 @@ mainpage = """
</head>
<body>
<p>
Recurse to a <a href="http://127.0.0.1:{{port}}/secondpage.html">second page</a>.
Recurse to a <a href="http://localhost:{{port}}/secondpage.html">second page</a>.
</p>
</body>
</html>
@@ -27,8 +27,8 @@ secondpage = """
</head>
<body>
<p>
Recurse to a <a href="http://127.0.0.1:{{port}}/thirdpage.html">third page</a>.
Try the blacklisted <a href="http://127.0.0.1:{{port}}/index.html">main page</a>.
Recurse to a <a href="http://localhost:{{port}}/thirdpage.html">third page</a>.
Try the blacklisted <a href="http://localhost:{{port}}/index.html">main page</a>.
</p>
</body>
</html>
@@ -41,7 +41,7 @@ thirdpage = """
</head>
<body>
<p>
Try a hidden <a href="http://127.0.0.1:{{port}}/dummy.txt">dummy file</a>.
Try a hidden <a href="http://localhost:{{port}}/dummy.txt">dummy file</a>.
Try to leave to <a href="http://no.such.domain/">another domain</a>.
</p>
</body>
@@ -55,9 +55,9 @@ Disallow: /dummy.txt
log = """\
REASON\tU_URL\tU_SCHEME\tU_HOST\tU_PORT\tU_PATH\tU_PARAMS\tU_QUERY\tU_FRAGMENT\tP_URL\tP_SCHEME\tP_HOST\tP_PORT\tP_PATH\tP_PARAMS\tP_QUERY\tP_FRAGMENT
BLACKLIST\thttp%3A//127.0.0.1%3A{{port}}/index.html\tSCHEME_HTTP\t127.0.0.1\t{{port}}\tindex.html\t\t\t\thttp%3A//127.0.0.1%3A{{port}}/secondpage.html\tSCHEME_HTTP\t127.0.0.1\t{{port}}\tsecondpage.html\t\t\t
ROBOTS\thttp%3A//127.0.0.1%3A{{port}}/dummy.txt\tSCHEME_HTTP\t127.0.0.1\t{{port}}\tdummy.txt\t\t\t\thttp%3A//127.0.0.1%3A{{port}}/thirdpage.html\tSCHEME_HTTP\t127.0.0.1\t{{port}}\tthirdpage.html\t\t\t
SPANNEDHOST\thttp%3A//no.such.domain/\tSCHEME_HTTP\tno.such.domain\t80\t\t\t\t\thttp%3A//127.0.0.1%3A{{port}}/thirdpage.html\tSCHEME_HTTP\t127.0.0.1\t{{port}}\tthirdpage.html\t\t\t
BLACKLIST\thttp%3A//localhost%3A{{port}}/index.html\tSCHEME_HTTP\tlocalhost\t{{port}}\tindex.html\t\t\t\thttp%3A//localhost%3A{{port}}/secondpage.html\tSCHEME_HTTP\tlocalhost\t{{port}}\tsecondpage.html\t\t\t
ROBOTS\thttp%3A//localhost%3A{{port}}/dummy.txt\tSCHEME_HTTP\tlocalhost\t{{port}}\tdummy.txt\t\t\t\thttp%3A//localhost%3A{{port}}/thirdpage.html\tSCHEME_HTTP\tlocalhost\t{{port}}\tthirdpage.html\t\t\t
SPANNEDHOST\thttp%3A//no.such.domain/\tSCHEME_HTTP\tno.such.domain\t80\t\t\t\t\thttp%3A//localhost%3A{{port}}/thirdpage.html\tSCHEME_HTTP\tlocalhost\t{{port}}\tthirdpage.html\t\t\t
"""
dummyfile = "Don't care."

View File

@@ -14,8 +14,8 @@ mainpage = """
</head>
<body>
<p>
Some text and a link to a <a href="http://127.0.0.1:{{port}}/secondpage.html">second page</a>.
Also, a <a href="http://127.0.0.1:{{port}}/nonexistent">broken link</a>.
Some text and a link to a <a href="http://localhost:{{port}}/secondpage.html">second page</a>.
Also, a <a href="http://localhost:{{port}}/nonexistent">broken link</a>.
</p>
</body>
</html>
@@ -29,8 +29,8 @@ secondpage = """
</head>
<body>
<p>
Some text and a link to a <a href="http://127.0.0.1:{{port}}/thirdpage.html">third page</a>.
Also, a <a href="http://127.0.0.1:{{port}}/nonexistent">broken link</a>.
Some text and a link to a <a href="http://localhost:{{port}}/thirdpage.html">third page</a>.
Also, a <a href="http://localhost:{{port}}/nonexistent">broken link</a>.
</p>
</body>
</html>
@@ -43,8 +43,8 @@ thirdpage = """
</head>
<body>
<p>
Some text and a link to a <a href="http://127.0.0.1:{{port}}/dummy.txt">text file</a>.
Also, another <a href="http://127.0.0.1:{{port}}/againnonexistent">broken link</a>.
Some text and a link to a <a href="http://localhost:{{port}}/dummy.txt">text file</a>.
Also, another <a href="http://localhost:{{port}}/againnonexistent">broken link</a>.
</p>
</body>
</html>

View File

@@ -1,7 +1,7 @@
#!/usr/bin/env python3
from sys import exit
from test.http_test import HTTPTest
from misc.constants import HTTP, HTTPS
from test.base_test import HTTP, HTTPS
from misc.wget_file import WgetFile
"""

View File

@@ -0,0 +1,68 @@
#!/usr/bin/env python3
from sys import exit
from test.http_test import HTTPTest
from misc.wget_file import WgetFile
"""
This test ensures Wget uses credentials from .netrc for Basic Authorization Negotiation.
In this case we test that .netrc credentials are used in case only
password is given on the command line.
Also, we ensure that Wget saves the host after a successful auth and
doesn't wait for a challenge the second time.
"""
############# File Definitions ###############################################
File1 = "I am an invisble man."
File2 = "I too am an invisible man."
User = "Sauron"
Password = "TheEye"
File1_rules = {
"Authentication" : {
"Type" : "Basic",
"User" : User,
"Pass" : Password
}
}
File2_rules = {
"ExpectHeader" : {
"Authorization" : "Basic U2F1cm9uOlRoZUV5ZQ=="
}
}
Netrc = "machine localhost\n\tlogin {0}".format(User)
A_File = WgetFile ("File1", File1, rules=File1_rules)
B_File = WgetFile ("File2", File2, rules=File2_rules)
Netrc_File = WgetFile (".netrc", Netrc)
WGET_OPTIONS = "--password={0}".format(Password)
WGET_URLS = [["File1", "File2"]]
Files = [[A_File, B_File]]
LocalFiles = [Netrc_File]
ExpectedReturnCode = 0
ExpectedDownloadedFiles = [A_File, B_File, Netrc_File]
################ Pre and Post Test Hooks #####################################
pre_test = {
"ServerFiles" : Files,
"LocalFiles" : LocalFiles
}
test_options = {
"WgetCommands" : WGET_OPTIONS,
"Urls" : WGET_URLS
}
post_test = {
"ExpectedFiles" : ExpectedDownloadedFiles,
"ExpectedRetcode" : ExpectedReturnCode
}
err = HTTPTest (
pre_hook=pre_test,
test_params=test_options,
post_hook=post_test
).begin ()
exit (err)

View File

@@ -0,0 +1,68 @@
#!/usr/bin/env python3
from sys import exit
from test.http_test import HTTPTest
from misc.wget_file import WgetFile
"""
This test ensures Wget uses credentials from .netrc for Basic Authorization Negotiation.
In this case we test that .netrc credentials are used in case only
user login is given on the command line.
Also, we ensure that Wget saves the host after a successful auth and
doesn't wait for a challenge the second time.
"""
############# File Definitions ###############################################
File1 = "I am an invisble man."
File2 = "I too am an invisible man."
User = "Sauron"
Password = "TheEye"
File1_rules = {
"Authentication" : {
"Type" : "Basic",
"User" : User,
"Pass" : Password
}
}
File2_rules = {
"ExpectHeader" : {
"Authorization" : "Basic U2F1cm9uOlRoZUV5ZQ=="
}
}
Netrc = "machine localhost\n\tlogin {0}\n\tpassword {1}".format(User, Password)
A_File = WgetFile ("File1", File1, rules=File1_rules)
B_File = WgetFile ("File2", File2, rules=File2_rules)
Netrc_File = WgetFile (".netrc", Netrc)
WGET_OPTIONS = "--user={0}".format(User)
WGET_URLS = [["File1", "File2"]]
Files = [[A_File, B_File]]
LocalFiles = [Netrc_File]
ExpectedReturnCode = 0
ExpectedDownloadedFiles = [A_File, B_File, Netrc_File]
################ Pre and Post Test Hooks #####################################
pre_test = {
"ServerFiles" : Files,
"LocalFiles" : LocalFiles
}
test_options = {
"WgetCommands" : WGET_OPTIONS,
"Urls" : WGET_URLS
}
post_test = {
"ExpectedFiles" : ExpectedDownloadedFiles,
"ExpectedRetcode" : ExpectedReturnCode
}
err = HTTPTest (
pre_hook=pre_test,
test_params=test_options,
post_hook=post_test
).begin ()
exit (err)

View File

@@ -0,0 +1,66 @@
#!/usr/bin/env python3
from sys import exit
from test.http_test import HTTPTest
from misc.wget_file import WgetFile
"""
This test ensures Wget uses credentials from .netrc for Basic Authorization Negotiation.
In this case we test that .netrc credentials are used in case no user
login and no password is given on the command line.
Also, we ensure that Wget saves the host after a successful auth and
doesn't wait for a challenge the second time.
"""
############# File Definitions ###############################################
File1 = "I am an invisble man."
File2 = "I too am an invisible man."
User = "Sauron"
Password = "TheEye"
File1_rules = {
"Authentication" : {
"Type" : "Basic",
"User" : User,
"Pass" : Password
}
}
File2_rules = {
"ExpectHeader" : {
"Authorization" : "Basic U2F1cm9uOlRoZUV5ZQ=="
}
}
Netrc = "machine localhost\n\tlogin {0}\n\tpassword {1}".format(User, Password)
A_File = WgetFile ("File1", File1, rules=File1_rules)
B_File = WgetFile ("File2", File2, rules=File2_rules)
Netrc_File = WgetFile (".netrc", Netrc)
WGET_URLS = [["File1", "File2"]]
Files = [[A_File, B_File]]
LocalFiles = [Netrc_File]
ExpectedReturnCode = 0
ExpectedDownloadedFiles = [A_File, B_File, Netrc_File]
################ Pre and Post Test Hooks #####################################
pre_test = {
"ServerFiles" : Files,
"LocalFiles" : LocalFiles
}
test_options = {
"Urls" : WGET_URLS
}
post_test = {
"ExpectedFiles" : ExpectedDownloadedFiles,
"ExpectedRetcode" : ExpectedReturnCode
}
err = HTTPTest (
pre_hook=pre_test,
test_params=test_options,
post_hook=post_test
).begin ()
exit (err)

View File

@@ -0,0 +1,59 @@
#!/usr/bin/env python3
from sys import exit
from test.http_test import HTTPTest
from misc.wget_file import WgetFile
"""
This test ensures that Wget will not use credentials from .netrc
when --no-netrc option is specified and Basic authentication is required
and fails.
"""
############# File Definitions ###############################################
File1 = "I am an invisble man."
User = "Sauron"
Password = "TheEye"
File1_rules = {
"Authentication" : {
"Type" : "Basic",
"User" : User,
"Pass" : Password
}
}
Netrc = "machine 127.0.0.1\n\tlogin {0}\n\tpassword {1}".format(User, Password)
A_File = WgetFile ("File1", File1, rules=File1_rules)
Netrc_File = WgetFile (".netrc", Netrc)
WGET_OPTIONS = "--no-netrc"
WGET_URLS = [["File1"]]
Files = [[A_File]]
LocalFiles = [Netrc_File]
ExpectedReturnCode = 6
ExpectedDownloadedFiles = [Netrc_File]
################ Pre and Post Test Hooks #####################################
pre_test = {
"ServerFiles" : Files,
"LocalFiles" : LocalFiles
}
test_options = {
"WgetCommands" : WGET_OPTIONS,
"Urls" : WGET_URLS
}
post_test = {
"ExpectedFiles" : ExpectedDownloadedFiles,
"ExpectedRetcode" : ExpectedReturnCode
}
err = HTTPTest (
pre_hook=pre_test,
test_params=test_options,
post_hook=post_test
).begin ()
exit (err)

View File

@@ -5,7 +5,7 @@ from misc.wget_file import WgetFile
"""
This test ensures Wget's Basic Authorization Negotiation.
Also, we ensure that Wget saves the host after a successfull auth and
Also, we ensure that Wget saves the host after a successful auth and
doesn't wait for a challenge the second time.
"""
############# File Definitions ###############################################

View File

@@ -5,7 +5,7 @@ from misc.wget_file import WgetFile
"""
This test ensures Wget's Basic Authorization Negotiation.
Also, we ensure that Wget saves the host after a successfull auth and
Also, we ensure that Wget saves the host after a successful auth and
doesn't wait for a challenge the second time.
"""
############# File Definitions ###############################################

View File

@@ -0,0 +1,93 @@
#!/usr/bin/env python3
from sys import exit
from test.http_test import HTTPTest
from misc.wget_file import WgetFile
import hashlib
from base64 import b64encode
"""
This is to test Metalink/HTTP with a malformed base64 Digest header.
With --trust-server-names, trust the metalink:file names.
Without --trust-server-names, don't trust the metalink:file names:
use the basename of --input-metalink, and add a sequential number
(e.g. .#1, .#2, etc.).
Strip the directory from unsafe paths.
"""
############# File Definitions ###############################################
bad = "Ouch!"
bad_sha256 = b64encode (hashlib.sha256 (bad.encode ('UTF-8')).digest ()).decode ('ascii')
LinkHeaders = ["<http://{{SRV_HOST}}:{{SRV_PORT}}/wrong_file>; rel=duplicate; pri=1"]
DigestHeader = "SHA-256=bad_base64,SHA-256={{BAD_HASH}}"
# This will be filled as soon as we know server hostname and port
MetaHTTPRules = {'SendHeader' : {}}
MetaHTTP = WgetFile ("main.metalink", rules=MetaHTTPRules)
wrong_file = WgetFile ("wrong_file", bad)
wrong_file_down = WgetFile ("main.metalink", bad)
WGET_OPTIONS = "--metalink-over-http"
WGET_URLS = [["main.metalink"]]
RequestList = [[
"HEAD /main.metalink",
"GET /wrong_file"
]]
Files = [[
MetaHTTP,
wrong_file
]]
Existing_Files = []
ExpectedReturnCode = 0
ExpectedDownloadedFiles = [wrong_file_down]
################ Pre and Post Test Hooks #####################################
pre_test = {
"ServerFiles" : Files,
"LocalFiles" : Existing_Files
}
test_options = {
"WgetCommands" : WGET_OPTIONS,
"Urls" : WGET_URLS
}
post_test = {
"ExpectedFiles" : ExpectedDownloadedFiles,
"ExpectedRetcode" : ExpectedReturnCode,
"FilesCrawled" : RequestList
}
http_test = HTTPTest (
pre_hook=pre_test,
test_params=test_options,
post_hook=post_test
)
http_test.server_setup()
### Get and use dynamic server sockname
srv_host, srv_port = http_test.servers[0].server_inst.socket.getsockname ()
DigestHeader = DigestHeader.replace('{{BAD_HASH}}', bad_sha256)
# Helper function for hostname, port and digest substitution
def SubstituteServerInfo (text, host, port):
text = text.replace('{{SRV_HOST}}', host)
text = text.replace('{{SRV_PORT}}', str (port))
return text
MetaHTTPRules["SendHeader"] = {
'Link': [ SubstituteServerInfo (LinkHeader, srv_host, srv_port)
for LinkHeader in LinkHeaders ],
'Digest': DigestHeader
}
err = http_test.begin ()
exit (err)

View File

@@ -0,0 +1,126 @@
#!/usr/bin/env python3
from sys import exit
from test.http_test import HTTPTest
from misc.wget_file import WgetFile
import hashlib
from base64 import b64encode
"""
This is to test Metalink/HTTP quoted values support in Wget.
"""
# Helper function for hostname, port and digest substitution
def SubstituteServerInfo (text, host, port, digest):
text = text.replace('{{FILE1_HASH}}', digest)
text = text.replace('{{SRV_HOST}}', host)
text = text.replace('{{SRV_PORT}}', str (port))
return text
############# File Definitions ###############################################
File1 = "Would you like some Tea?"
File1_corrupted = "Would you like some Coffee?"
File1_lowPref = "Do not take this"
File1_sha256 = b64encode (hashlib.sha256 (File1.encode ('UTF-8')).digest ()).decode ('ascii')
Signature = '''-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)
This is no valid signature. But it should be downloaded.
The attempt to verify should fail but should not prevent
a successful metalink resource retrieval (the sig failure
should not be fatal).
-----END PGP SIGNATURE-----
'''
File2 = "No meta data for this file."
LinkHeaders = [
# This file has low priority and should not be picked.
"<http://{{SRV_HOST}}:{{SRV_PORT}}/File1_lowPref>; rel=\"duplicate\"; pri=\"9\"; geo=\"pl\"",
# This file should be picked second, after hash failure.
"<http://0.0.0.0/File1_try2_badconnection>; rel =\"duplicate\";pref; pri=\"7\"",
# This signature download will fail.
"<http://{{SRV_HOST}}:{{SRV_PORT}}/Sig2.asc>; rel=\"describedby\"; type=\"application/pgp-signature\"",
# Two good signatures
"<http://{{SRV_HOST}}:{{SRV_PORT}}/Sig.asc>; rel=\"describedby\"; type=\"application/pgp-signature\"",
"<http://{{SRV_HOST}}:{{SRV_PORT}}/Sig.asc>; rel=\"describedby\"; type=\"application/pgp-signature\"",
# Bad URL scheme
"<invalid_url>; rel=\"duplicate\"; pri=\"4\"",
# rel missing
"<http://{{SRV_HOST}}:{{SRV_PORT}}/File1>; pri=\"1\"; pref",
# invalid rel
"<http://{{SRV_HOST}}:{{SRV_PORT}}/File1>; rel=\"strange\"; pri=\"4\"",
# This file should be picked first, because it has the lowest pri among preferred.
"<http://{{SRV_HOST}}:{{SRV_PORT}}/File1_try1_corrupted>; rel=\"duplicate\"; geo=\"su\"; pri=\"4\"; pref",
# This file should NOT be picked third due to preferred location set to 'uk'
"<http://{{SRV_HOST}}:{{SRV_PORT}}/File1_badgeo>; rel =\"duplicate\";pri=\"5\"",
# This file should be picked as third try, and it should succeed
"<http://{{SRV_HOST}}:{{SRV_PORT}}/File1_try3_ok>; rel=\'duplicate\'; pri=\"5\";geo=\"uk\""
]
DigestHeader = "SHA-256=\'{{FILE1_HASH}}\'"
# This will be filled as soon as we know server hostname and port
MetaFileRules = {'SendHeader' : {}}
FileOkServer = WgetFile ("File1_try3_ok", File1)
FileBadPref = WgetFile ("File1_lowPref", File1_lowPref)
FileBadHash = WgetFile ("File1_try1_corrupted", File1_corrupted)
MetaFile = WgetFile ("test.meta", rules=MetaFileRules)
# In case of Metalink over HTTP, the local file name is
# derived from the URL suffix.
FileOkLocal = WgetFile ("test.meta", File1)
SigFile = WgetFile ("Sig.asc", Signature)
FileNoMeta = WgetFile ("File2", File2)
WGET_OPTIONS = "--metalink-over-http --preferred-location=uk"
WGET_URLS = [["test.meta", "File2"]]
Files = [[FileOkServer, FileBadPref, FileBadHash, MetaFile, SigFile, FileNoMeta]]
Existing_Files = []
ExpectedReturnCode = 0
ExpectedDownloadedFiles = [FileNoMeta, FileOkLocal]
RequestList = [
[
"HEAD /test.meta",
"GET /Sig2.asc",
"GET /Sig.asc",
"GET /File1_try1_corrupted",
"GET /File1_try3_ok",
"HEAD /File2",
"GET /File2",
]
]
################ Pre and Post Test Hooks #####################################
pre_test = {
"ServerFiles" : Files,
"LocalFiles" : Existing_Files
}
test_options = {
"WgetCommands" : WGET_OPTIONS,
"Urls" : WGET_URLS
}
post_test = {
"ExpectedFiles" : ExpectedDownloadedFiles,
"ExpectedRetcode" : ExpectedReturnCode,
"FilesCrawled" : RequestList,
}
http_test = HTTPTest (
pre_hook=pre_test,
test_params=test_options,
post_hook=post_test,
)
http_test.server_setup()
srv_host, srv_port = http_test.servers[0].server_inst.socket.getsockname ()
MetaFileRules["SendHeader"] = {
'Link': [ SubstituteServerInfo (LinkHeader, srv_host, srv_port, File1_sha256)
for LinkHeader in LinkHeaders ],
'Digest': SubstituteServerInfo (DigestHeader, srv_host, srv_port, File1_sha256),
}
err = http_test.begin ()
exit (err)

View File

@@ -0,0 +1,272 @@
#!/usr/bin/env python3
from sys import exit
from test.http_test import HTTPTest
from misc.wget_file import WgetFile
import hashlib
from base64 import b64encode
"""
This is to test Metalink/HTTP with Metalink/XML Link headers.
With --trust-server-names, trust the metalink:file names.
Without --trust-server-names, don't trust the metalink:file names:
use the basename of --input-metalink, and add a sequential number
(e.g. .#1, .#2, etc.).
Strip the directory from unsafe paths.
"""
############# File Definitions ###############################################
bad = "Ouch!"
bad_sha256 = hashlib.sha256 (bad.encode ('UTF-8')).hexdigest ()
File1 = "Would you like some Tea?"
File1_lowPref = "Do not take this"
File1_sha256 = hashlib.sha256 (File1.encode ('UTF-8')).hexdigest ()
File2 = "This is gonna be good"
File2_lowPref = "Not this one too"
File2_sha256 = hashlib.sha256 (File2.encode ('UTF-8')).hexdigest ()
File3 = "A little more, please"
File3_lowPref = "That's just too much"
File3_sha256 = hashlib.sha256 (File3.encode ('UTF-8')).hexdigest ()
File4 = "Maybe a biscuit?"
File4_lowPref = "No, thanks"
File4_sha256 = hashlib.sha256 (File4.encode ('UTF-8')).hexdigest ()
File5 = "More Tea...?"
File5_lowPref = "I have to go..."
File5_sha256 = hashlib.sha256 (File5.encode ('UTF-8')).hexdigest ()
MetaXml1 = \
"""<?xml version="1.0" encoding="utf-8"?>
<metalink version="3.0" xmlns="http://www.metalinker.org/">
<publisher>
<name>GNU Wget</name>
</publisher>
<license>
<name>GNU GPL</name>
<url>http://www.gnu.org/licenses/gpl.html</url>
</license>
<identity>Wget Test Files</identity>
<version>1.2.3</version>
<description>Wget Test Files description</description>
<files>
<file name="dir/File1">
<verification>
<hash type="sha256">{{FILE1_HASH}}</hash>
</verification>
<resources>
<url type="http" preference="35">http://{{SRV_HOST}}:{{SRV_PORT}}/wrong_file</url>
<url type="http" preference="40">http://{{SRV_HOST}}:{{SRV_PORT}}/404</url>
<url type="http" preference="25">http://{{SRV_HOST}}:{{SRV_PORT}}/File1_lowPref</url>
<url type="http" preference="30">http://{{SRV_HOST}}:{{SRV_PORT}}/File1</url>
</resources>
</file>
<file name="dir/File2">
<verification>
<hash type="sha256">{{FILE2_HASH}}</hash>
</verification>
<resources>
<url type="http" preference="35">http://{{SRV_HOST}}:{{SRV_PORT}}/wrong_file</url>
<url type="http" preference="40">http://{{SRV_HOST}}:{{SRV_PORT}}/404</url>
<url type="http" preference="25">http://{{SRV_HOST}}:{{SRV_PORT}}/File2_lowPref</url>
<url type="http" preference="30">http://{{SRV_HOST}}:{{SRV_PORT}}/File2</url>
</resources>
</file>
<file name="/dir/File3"> <!-- rejected by libmetalink -->
<verification>
<hash type="sha256">{{FILE3_HASH}}</hash>
</verification>
<resources>
<url type="http" preference="35">http://{{SRV_HOST}}:{{SRV_PORT}}/wrong_file</url>
<url type="http" preference="40">http://{{SRV_HOST}}:{{SRV_PORT}}/404</url>
<url type="http" preference="25">http://{{SRV_HOST}}:{{SRV_PORT}}/File3_lowPref</url>
<url type="http" preference="30">http://{{SRV_HOST}}:{{SRV_PORT}}/File3</url>
</resources>
</file>
<file name="dir/File4">
<verification>
<hash type="sha256">{{FILE4_HASH}}</hash>
</verification>
<resources>
<url type="http" preference="35">http://{{SRV_HOST}}:{{SRV_PORT}}/wrong_file</url>
<url type="http" preference="40">http://{{SRV_HOST}}:{{SRV_PORT}}/404</url>
<url type="http" preference="25">http://{{SRV_HOST}}:{{SRV_PORT}}/File4_lowPref</url>
<url type="http" preference="30">http://{{SRV_HOST}}:{{SRV_PORT}}/File4</url>
</resources>
</file>
<file name="dir/File5">
<verification>
<hash type="sha256">{{FILE5_HASH}}</hash>
</verification>
<resources>
<url type="http" preference="35">http://{{SRV_HOST}}:{{SRV_PORT}}/wrong_file</url>
<url type="http" preference="40">http://{{SRV_HOST}}:{{SRV_PORT}}/404</url>
<url type="http" preference="25">http://{{SRV_HOST}}:{{SRV_PORT}}/File5_lowPref</url>
<url type="http" preference="30">http://{{SRV_HOST}}:{{SRV_PORT}}/File5</url>
</resources>
</file>
</files>
</metalink>
"""
MetaXml2 = \
"""<?xml version="1.0" encoding="utf-8"?>
<metalink version="3.0" xmlns="http://www.metalinker.org/">
<publisher>
<name>GNU Wget</name>
</publisher>
<license>
<name>GNU GPL</name>
<url>http://www.gnu.org/licenses/gpl.html</url>
</license>
<identity>Wget Test Files</identity>
<version>1.2.3</version>
<description>Wget Test Files description</description>
<files>
<file name="bad">
<verification>
<hash type="sha256">{{BAD_HASH}}</hash>
</verification>
<resources>
<url type="http" preference="35">http://{{SRV_HOST}}:{{SRV_PORT}}/wrong_file</url>
<url type="http" preference="40">http://{{SRV_HOST}}:{{SRV_PORT}}/404</url>
<url type="http" preference="30">http://{{SRV_HOST}}:{{SRV_PORT}}/bad</url>
</resources>
</file>
</files>
</metalink>
"""
LinkHeaders = [
# This file has the lowest priority, and should go last
"<http://{{SRV_HOST}}:{{SRV_PORT}}/test1.metalink>; rel=describedby; pri=2; type=\"application/metalink4+xml\"; name=\"newname.metalink\"",
# This file has the highest priority, and should go first
"<http://{{SRV_HOST}}:{{SRV_PORT}}/test2.metalink>; rel=describedby; pri=1; type=\"application/metalink4+xml\""
]
# This will be filled as soon as we know server hostname and port
MetaHTTPRules = {'SendHeader' : {}}
MetaHTTP = WgetFile ("main.metalink", rules=MetaHTTPRules)
wrong_file = WgetFile ("wrong_file", bad)
File1_orig = WgetFile ("File1", File1)
File1_down = WgetFile ("dir/File1", File1)
File1_nono = WgetFile ("File1_lowPref", File1_lowPref)
File2_orig = WgetFile ("File2", File2)
File2_down = WgetFile ("dir/File2", File2)
File2_nono = WgetFile ("File2_lowPref", File2_lowPref)
# rejected by libmetalink
File3_orig = WgetFile ("File3", File3)
File3_nono = WgetFile ("File3_lowPref", File3_lowPref)
File4_orig = WgetFile ("File4", File4)
File4_down = WgetFile ("dir/File4", File4)
File4_nono = WgetFile ("File4_lowPref", File4_lowPref)
File5_orig = WgetFile ("File5", File5)
File5_down = WgetFile ("dir/File5", File5)
File5_nono = WgetFile ("File5_lowPref", File5_lowPref)
MetaFile1 = WgetFile ("test1.metalink", MetaXml1)
MetaFile1_down = WgetFile ("newname.metalink", MetaXml1)
MetaFile2 = WgetFile ("test2.metalink", MetaXml2)
WGET_OPTIONS = "--trust-server-names --metalink-over-http --metalink-index=2"
WGET_URLS = [["main.metalink"]]
RequestList = [[
"HEAD /main.metalink",
"GET /404",
"GET /wrong_file",
"GET /test1.metalink",
"GET /File1",
"GET /File2",
"GET /File4",
"GET /File5"
]]
Files = [[
MetaHTTP,
wrong_file,
MetaFile1, MetaFile2,
File1_orig, File1_nono,
File2_orig, File2_nono,
File3_orig, File3_nono,
File4_orig, File4_nono,
File5_orig, File5_nono
]]
Existing_Files = []
ExpectedReturnCode = 0
ExpectedDownloadedFiles = [
MetaFile1_down,
File1_down,
File2_down,
File4_down,
File5_down
]
################ Pre and Post Test Hooks #####################################
pre_test = {
"ServerFiles" : Files,
"LocalFiles" : Existing_Files
}
test_options = {
"WgetCommands" : WGET_OPTIONS,
"Urls" : WGET_URLS
}
post_test = {
"ExpectedFiles" : ExpectedDownloadedFiles,
"ExpectedRetcode" : ExpectedReturnCode,
"FilesCrawled" : RequestList
}
http_test = HTTPTest (
pre_hook=pre_test,
test_params=test_options,
post_hook=post_test
)
http_test.server_setup()
### Get and use dynamic server sockname
srv_host, srv_port = http_test.servers[0].server_inst.socket.getsockname ()
MetaXml1 = MetaXml1.replace('{{FILE1_HASH}}', File1_sha256)
MetaXml1 = MetaXml1.replace('{{FILE2_HASH}}', File2_sha256)
MetaXml1 = MetaXml1.replace('{{FILE3_HASH}}', File3_sha256)
MetaXml1 = MetaXml1.replace('{{FILE4_HASH}}', File4_sha256)
MetaXml1 = MetaXml1.replace('{{FILE5_HASH}}', File5_sha256)
MetaXml1 = MetaXml1.replace('{{SRV_HOST}}', srv_host)
MetaXml1 = MetaXml1.replace('{{SRV_PORT}}', str (srv_port))
MetaFile1.content = MetaXml1
MetaFile1_down.content = MetaXml1
MetaXml2 = MetaXml2.replace('{{BAD_HASH}}', bad_sha256)
MetaXml2 = MetaXml2.replace('{{SRV_HOST}}', srv_host)
MetaXml2 = MetaXml2.replace('{{SRV_PORT}}', str (srv_port))
MetaFile2.content = MetaXml2
# Helper function for hostname, port and digest substitution
def SubstituteServerInfo (text, host, port):
text = text.replace('{{SRV_HOST}}', host)
text = text.replace('{{SRV_PORT}}', str (port))
return text
MetaHTTPRules["SendHeader"] = {
'Link': [ SubstituteServerInfo (LinkHeader, srv_host, srv_port)
for LinkHeader in LinkHeaders ]
}
err = http_test.begin ()
exit (err)

View File

@@ -0,0 +1,272 @@
#!/usr/bin/env python3
from sys import exit
from test.http_test import HTTPTest
from misc.wget_file import WgetFile
import hashlib
from base64 import b64encode
"""
This is to test Metalink/HTTP with Metalink/XML Link headers.
With --trust-server-names, trust the metalink:file names.
Without --trust-server-names, don't trust the metalink:file names:
use the basename of --input-metalink, and add a sequential number
(e.g. .#1, .#2, etc.).
Strip the directory from unsafe paths.
"""
############# File Definitions ###############################################
bad = "Ouch!"
bad_sha256 = hashlib.sha256 (bad.encode ('UTF-8')).hexdigest ()
File1 = "Would you like some Tea?"
File1_lowPref = "Do not take this"
File1_sha256 = hashlib.sha256 (File1.encode ('UTF-8')).hexdigest ()
File2 = "This is gonna be good"
File2_lowPref = "Not this one too"
File2_sha256 = hashlib.sha256 (File2.encode ('UTF-8')).hexdigest ()
File3 = "A little more, please"
File3_lowPref = "That's just too much"
File3_sha256 = hashlib.sha256 (File3.encode ('UTF-8')).hexdigest ()
File4 = "Maybe a biscuit?"
File4_lowPref = "No, thanks"
File4_sha256 = hashlib.sha256 (File4.encode ('UTF-8')).hexdigest ()
File5 = "More Tea...?"
File5_lowPref = "I have to go..."
File5_sha256 = hashlib.sha256 (File5.encode ('UTF-8')).hexdigest ()
MetaXml1 = \
"""<?xml version="1.0" encoding="utf-8"?>
<metalink version="3.0" xmlns="http://www.metalinker.org/">
<publisher>
<name>GNU Wget</name>
</publisher>
<license>
<name>GNU GPL</name>
<url>http://www.gnu.org/licenses/gpl.html</url>
</license>
<identity>Wget Test Files</identity>
<version>1.2.3</version>
<description>Wget Test Files description</description>
<files>
<file name="dir/File1">
<verification>
<hash type="sha256">{{FILE1_HASH}}</hash>
</verification>
<resources>
<url type="http" preference="35">http://{{SRV_HOST}}:{{SRV_PORT}}/wrong_file</url>
<url type="http" preference="40">http://{{SRV_HOST}}:{{SRV_PORT}}/404</url>
<url type="http" preference="25">http://{{SRV_HOST}}:{{SRV_PORT}}/File1_lowPref</url>
<url type="http" preference="30">http://{{SRV_HOST}}:{{SRV_PORT}}/File1</url>
</resources>
</file>
<file name="dir/File2">
<verification>
<hash type="sha256">{{FILE2_HASH}}</hash>
</verification>
<resources>
<url type="http" preference="35">http://{{SRV_HOST}}:{{SRV_PORT}}/wrong_file</url>
<url type="http" preference="40">http://{{SRV_HOST}}:{{SRV_PORT}}/404</url>
<url type="http" preference="25">http://{{SRV_HOST}}:{{SRV_PORT}}/File2_lowPref</url>
<url type="http" preference="30">http://{{SRV_HOST}}:{{SRV_PORT}}/File2</url>
</resources>
</file>
<file name="/dir/File3"> <!-- rejected by libmetalink -->
<verification>
<hash type="sha256">{{FILE3_HASH}}</hash>
</verification>
<resources>
<url type="http" preference="35">http://{{SRV_HOST}}:{{SRV_PORT}}/wrong_file</url>
<url type="http" preference="40">http://{{SRV_HOST}}:{{SRV_PORT}}/404</url>
<url type="http" preference="25">http://{{SRV_HOST}}:{{SRV_PORT}}/File3_lowPref</url>
<url type="http" preference="30">http://{{SRV_HOST}}:{{SRV_PORT}}/File3</url>
</resources>
</file>
<file name="dir/File4">
<verification>
<hash type="sha256">{{FILE4_HASH}}</hash>
</verification>
<resources>
<url type="http" preference="35">http://{{SRV_HOST}}:{{SRV_PORT}}/wrong_file</url>
<url type="http" preference="40">http://{{SRV_HOST}}:{{SRV_PORT}}/404</url>
<url type="http" preference="25">http://{{SRV_HOST}}:{{SRV_PORT}}/File4_lowPref</url>
<url type="http" preference="30">http://{{SRV_HOST}}:{{SRV_PORT}}/File4</url>
</resources>
</file>
<file name="dir/File5">
<verification>
<hash type="sha256">{{FILE5_HASH}}</hash>
</verification>
<resources>
<url type="http" preference="35">http://{{SRV_HOST}}:{{SRV_PORT}}/wrong_file</url>
<url type="http" preference="40">http://{{SRV_HOST}}:{{SRV_PORT}}/404</url>
<url type="http" preference="25">http://{{SRV_HOST}}:{{SRV_PORT}}/File5_lowPref</url>
<url type="http" preference="30">http://{{SRV_HOST}}:{{SRV_PORT}}/File5</url>
</resources>
</file>
</files>
</metalink>
"""
MetaXml2 = \
"""<?xml version="1.0" encoding="utf-8"?>
<metalink version="3.0" xmlns="http://www.metalinker.org/">
<publisher>
<name>GNU Wget</name>
</publisher>
<license>
<name>GNU GPL</name>
<url>http://www.gnu.org/licenses/gpl.html</url>
</license>
<identity>Wget Test Files</identity>
<version>1.2.3</version>
<description>Wget Test Files description</description>
<files>
<file name="bad">
<verification>
<hash type="sha256">{{BAD_HASH}}</hash>
</verification>
<resources>
<url type="http" preference="35">http://{{SRV_HOST}}:{{SRV_PORT}}/wrong_file</url>
<url type="http" preference="40">http://{{SRV_HOST}}:{{SRV_PORT}}/404</url>
<url type="http" preference="30">http://{{SRV_HOST}}:{{SRV_PORT}}/bad</url>
</resources>
</file>
</files>
</metalink>
"""
LinkHeaders = [
# This file has the lowest priority, and should go last
"<http://{{SRV_HOST}}:{{SRV_PORT}}/test1.metalink>; rel=describedby; pri=2; type=\"application/metalink4+xml\"",
# This file has the highest priority, and should go first
"<http://{{SRV_HOST}}:{{SRV_PORT}}/test2.metalink>; rel=describedby; pri=1; type=\"application/metalink4+xml\""
]
# This will be filled as soon as we know server hostname and port
MetaHTTPRules = {'SendHeader' : {}}
MetaHTTP = WgetFile ("main.metalink", rules=MetaHTTPRules)
wrong_file = WgetFile ("wrong_file", bad)
File1_orig = WgetFile ("File1", File1)
File1_down = WgetFile ("dir/File1", File1)
File1_nono = WgetFile ("File1_lowPref", File1_lowPref)
File2_orig = WgetFile ("File2", File2)
File2_down = WgetFile ("dir/File2", File2)
File2_nono = WgetFile ("File2_lowPref", File2_lowPref)
# rejected by libmetalink
File3_orig = WgetFile ("File3", File3)
File3_nono = WgetFile ("File3_lowPref", File3_lowPref)
File4_orig = WgetFile ("File4", File4)
File4_down = WgetFile ("dir/File4", File4)
File4_nono = WgetFile ("File4_lowPref", File4_lowPref)
File5_orig = WgetFile ("File5", File5)
File5_down = WgetFile ("dir/File5", File5)
File5_nono = WgetFile ("File5_lowPref", File5_lowPref)
MetaFile1 = WgetFile ("test1.metalink", MetaXml1)
MetaFile1_down = WgetFile ("test1.metalink", MetaXml1)
MetaFile2 = WgetFile ("test2.metalink", MetaXml2)
WGET_OPTIONS = "--trust-server-names --metalink-over-http --metalink-index=2"
WGET_URLS = [["main.metalink"]]
RequestList = [[
"HEAD /main.metalink",
"GET /404",
"GET /wrong_file",
"GET /test1.metalink",
"GET /File1",
"GET /File2",
"GET /File4",
"GET /File5"
]]
Files = [[
MetaHTTP,
wrong_file,
MetaFile1, MetaFile2,
File1_orig, File1_nono,
File2_orig, File2_nono,
File3_orig, File3_nono,
File4_orig, File4_nono,
File5_orig, File5_nono
]]
Existing_Files = []
ExpectedReturnCode = 0
ExpectedDownloadedFiles = [
MetaFile1_down,
File1_down,
File2_down,
File4_down,
File5_down
]
################ Pre and Post Test Hooks #####################################
pre_test = {
"ServerFiles" : Files,
"LocalFiles" : Existing_Files
}
test_options = {
"WgetCommands" : WGET_OPTIONS,
"Urls" : WGET_URLS
}
post_test = {
"ExpectedFiles" : ExpectedDownloadedFiles,
"ExpectedRetcode" : ExpectedReturnCode,
"FilesCrawled" : RequestList
}
http_test = HTTPTest (
pre_hook=pre_test,
test_params=test_options,
post_hook=post_test
)
http_test.server_setup()
### Get and use dynamic server sockname
srv_host, srv_port = http_test.servers[0].server_inst.socket.getsockname ()
MetaXml1 = MetaXml1.replace('{{FILE1_HASH}}', File1_sha256)
MetaXml1 = MetaXml1.replace('{{FILE2_HASH}}', File2_sha256)
MetaXml1 = MetaXml1.replace('{{FILE3_HASH}}', File3_sha256)
MetaXml1 = MetaXml1.replace('{{FILE4_HASH}}', File4_sha256)
MetaXml1 = MetaXml1.replace('{{FILE5_HASH}}', File5_sha256)
MetaXml1 = MetaXml1.replace('{{SRV_HOST}}', srv_host)
MetaXml1 = MetaXml1.replace('{{SRV_PORT}}', str (srv_port))
MetaFile1.content = MetaXml1
MetaFile1_down.content = MetaXml1
MetaXml2 = MetaXml2.replace('{{BAD_HASH}}', bad_sha256)
MetaXml2 = MetaXml2.replace('{{SRV_HOST}}', srv_host)
MetaXml2 = MetaXml2.replace('{{SRV_PORT}}', str (srv_port))
MetaFile2.content = MetaXml2
# Helper function for hostname, port and digest substitution
def SubstituteServerInfo (text, host, port):
text = text.replace('{{SRV_HOST}}', host)
text = text.replace('{{SRV_PORT}}', str (port))
return text
MetaHTTPRules["SendHeader"] = {
'Link': [ SubstituteServerInfo (LinkHeader, srv_host, srv_port)
for LinkHeader in LinkHeaders ]
}
err = http_test.begin ()
exit (err)

View File

@@ -0,0 +1,221 @@
#!/usr/bin/env python3
from sys import exit
from test.http_test import HTTPTest
from misc.wget_file import WgetFile
import hashlib
from base64 import b64encode
"""
This is to test Metalink/HTTP with Content-Type Metalink/XML.
With --trust-server-names, trust the metalink:file names.
Without --trust-server-names, don't trust the metalink:file names:
use the basename of --input-metalink, and add a sequential number
(e.g. .#1, .#2, etc.).
Strip the directory from unsafe paths.
"""
############# File Definitions ###############################################
bad = "Ouch!"
File1 = "Would you like some Tea?"
File1_lowPref = "Do not take this"
File1_sha256 = hashlib.sha256 (File1.encode ('UTF-8')).hexdigest ()
File2 = "This is gonna be good"
File2_lowPref = "Not this one too"
File2_sha256 = hashlib.sha256 (File2.encode ('UTF-8')).hexdigest ()
File3 = "A little more, please"
File3_lowPref = "That's just too much"
File3_sha256 = hashlib.sha256 (File3.encode ('UTF-8')).hexdigest ()
File4 = "Maybe a biscuit?"
File4_lowPref = "No, thanks"
File4_sha256 = hashlib.sha256 (File4.encode ('UTF-8')).hexdigest ()
File5 = "More Tea...?"
File5_lowPref = "I have to go..."
File5_sha256 = hashlib.sha256 (File5.encode ('UTF-8')).hexdigest ()
MetaXml = \
"""<?xml version="1.0" encoding="utf-8"?>
<metalink version="3.0" xmlns="http://www.metalinker.org/">
<publisher>
<name>GNU Wget</name>
</publisher>
<license>
<name>GNU GPL</name>
<url>http://www.gnu.org/licenses/gpl.html</url>
</license>
<identity>Wget Test Files</identity>
<version>1.2.3</version>
<description>Wget Test Files description</description>
<files>
<file name="dir/File1">
<verification>
<hash type="sha256">{{FILE1_HASH}}</hash>
</verification>
<resources>
<url type="http" preference="35">http://{{SRV_HOST}}:{{SRV_PORT}}/wrong_file</url>
<url type="http" preference="40">http://{{SRV_HOST}}:{{SRV_PORT}}/404</url>
<url type="http" preference="25">http://{{SRV_HOST}}:{{SRV_PORT}}/File1_lowPref</url>
<url type="http" preference="30">http://{{SRV_HOST}}:{{SRV_PORT}}/File1</url>
</resources>
</file>
<file name="dir/File2">
<verification>
<hash type="sha256">{{FILE2_HASH}}</hash>
</verification>
<resources>
<url type="http" preference="35">http://{{SRV_HOST}}:{{SRV_PORT}}/wrong_file</url>
<url type="http" preference="40">http://{{SRV_HOST}}:{{SRV_PORT}}/404</url>
<url type="http" preference="25">http://{{SRV_HOST}}:{{SRV_PORT}}/File2_lowPref</url>
<url type="http" preference="30">http://{{SRV_HOST}}:{{SRV_PORT}}/File2</url>
</resources>
</file>
<file name="/dir/File3"> <!-- rejected by libmetalink -->
<verification>
<hash type="sha256">{{FILE3_HASH}}</hash>
</verification>
<resources>
<url type="http" preference="35">http://{{SRV_HOST}}:{{SRV_PORT}}/wrong_file</url>
<url type="http" preference="40">http://{{SRV_HOST}}:{{SRV_PORT}}/404</url>
<url type="http" preference="25">http://{{SRV_HOST}}:{{SRV_PORT}}/File3_lowPref</url>
<url type="http" preference="30">http://{{SRV_HOST}}:{{SRV_PORT}}/File3</url>
</resources>
</file>
<file name="dir/File4">
<verification>
<hash type="sha256">{{FILE4_HASH}}</hash>
</verification>
<resources>
<url type="http" preference="35">http://{{SRV_HOST}}:{{SRV_PORT}}/wrong_file</url>
<url type="http" preference="40">http://{{SRV_HOST}}:{{SRV_PORT}}/404</url>
<url type="http" preference="25">http://{{SRV_HOST}}:{{SRV_PORT}}/File4_lowPref</url>
<url type="http" preference="30">http://{{SRV_HOST}}:{{SRV_PORT}}/File4</url>
</resources>
</file>
<file name="dir/File5">
<verification>
<hash type="sha256">{{FILE5_HASH}}</hash>
</verification>
<resources>
<url type="http" preference="35">http://{{SRV_HOST}}:{{SRV_PORT}}/wrong_file</url>
<url type="http" preference="40">http://{{SRV_HOST}}:{{SRV_PORT}}/404</url>
<url type="http" preference="25">http://{{SRV_HOST}}:{{SRV_PORT}}/File5_lowPref</url>
<url type="http" preference="30">http://{{SRV_HOST}}:{{SRV_PORT}}/File5</url>
</resources>
</file>
</files>
</metalink>
"""
# This will be filled as soon as we know server hostname and port
MetaHTTPRules = {'SendHeader' : {}}
MetaHTTP = WgetFile ("main.metalink", rules=MetaHTTPRules)
MetaHTTP_down = WgetFile ("main.metalink.meta#1", MetaXml)
wrong_file = WgetFile ("wrong_file", bad)
File1_orig = WgetFile ("File1", File1)
File1_down = WgetFile ("main.metalink.meta#1.#1", File1)
File1_nono = WgetFile ("File1_lowPref", File1_lowPref)
File2_orig = WgetFile ("File2", File2)
File2_down = WgetFile ("main.metalink.meta#1.#2", File2)
File2_nono = WgetFile ("File2_lowPref", File2_lowPref)
# rejected by libmetalink
File3_orig = WgetFile ("File3", File3)
File3_nono = WgetFile ("File3_lowPref", File3_lowPref)
File4_orig = WgetFile ("File4", File4)
File4_down = WgetFile ("main.metalink.meta#1.#3", File4)
File4_nono = WgetFile ("File4_lowPref", File4_lowPref)
File5_orig = WgetFile ("File5", File5)
File5_down = WgetFile ("main.metalink.meta#1.#4", File5)
File5_nono = WgetFile ("File5_lowPref", File5_lowPref)
WGET_OPTIONS = "--metalink-over-http --content-disposition --metalink-index=0"
WGET_URLS = [["main.metalink"]]
RequestList = [[
"HEAD /main.metalink",
"GET /main.metalink",
"GET /404",
"GET /wrong_file",
"GET /File1",
"GET /File2",
"GET /File4",
"GET /File5"
]]
Files = [[
MetaHTTP,
wrong_file,
File1_orig, File1_nono,
File2_orig, File2_nono,
File3_orig, File3_nono,
File4_orig, File4_nono,
File5_orig, File5_nono
]]
Existing_Files = []
ExpectedReturnCode = 0
ExpectedDownloadedFiles = [
MetaHTTP_down,
File1_down,
File2_down,
File4_down,
File5_down
]
################ Pre and Post Test Hooks #####################################
pre_test = {
"ServerFiles" : Files,
"LocalFiles" : Existing_Files
}
test_options = {
"WgetCommands" : WGET_OPTIONS,
"Urls" : WGET_URLS
}
post_test = {
"ExpectedFiles" : ExpectedDownloadedFiles,
"ExpectedRetcode" : ExpectedReturnCode,
"FilesCrawled" : RequestList
}
http_test = HTTPTest (
pre_hook=pre_test,
test_params=test_options,
post_hook=post_test
)
http_test.server_setup()
### Get and use dynamic server sockname
srv_host, srv_port = http_test.servers[0].server_inst.socket.getsockname ()
MetaXml = MetaXml.replace('{{FILE1_HASH}}', File1_sha256)
MetaXml = MetaXml.replace('{{FILE2_HASH}}', File2_sha256)
MetaXml = MetaXml.replace('{{FILE3_HASH}}', File3_sha256)
MetaXml = MetaXml.replace('{{FILE4_HASH}}', File4_sha256)
MetaXml = MetaXml.replace('{{FILE5_HASH}}', File5_sha256)
MetaXml = MetaXml.replace('{{SRV_HOST}}', srv_host)
MetaXml = MetaXml.replace('{{SRV_PORT}}', str (srv_port))
MetaHTTP_down.content = MetaXml
MetaHTTP.content = MetaXml
MetaHTTPRules["SendHeader"] = {
'Content-Type': 'application/metalink4+xml',
'Content-Disposition': 'filename="newname.metalink"'
}
err = http_test.begin ()
exit (err)

View File

@@ -0,0 +1,221 @@
#!/usr/bin/env python3
from sys import exit
from test.http_test import HTTPTest
from misc.wget_file import WgetFile
import hashlib
from base64 import b64encode
"""
This is to test Metalink/HTTP with Content-Type Metalink/XML.
With --trust-server-names, trust the metalink:file names.
Without --trust-server-names, don't trust the metalink:file names:
use the basename of --input-metalink, and add a sequential number
(e.g. .#1, .#2, etc.).
Strip the directory from unsafe paths.
"""
############# File Definitions ###############################################
bad = "Ouch!"
File1 = "Would you like some Tea?"
File1_lowPref = "Do not take this"
File1_sha256 = hashlib.sha256 (File1.encode ('UTF-8')).hexdigest ()
File2 = "This is gonna be good"
File2_lowPref = "Not this one too"
File2_sha256 = hashlib.sha256 (File2.encode ('UTF-8')).hexdigest ()
File3 = "A little more, please"
File3_lowPref = "That's just too much"
File3_sha256 = hashlib.sha256 (File3.encode ('UTF-8')).hexdigest ()
File4 = "Maybe a biscuit?"
File4_lowPref = "No, thanks"
File4_sha256 = hashlib.sha256 (File4.encode ('UTF-8')).hexdigest ()
File5 = "More Tea...?"
File5_lowPref = "I have to go..."
File5_sha256 = hashlib.sha256 (File5.encode ('UTF-8')).hexdigest ()
MetaXml = \
"""<?xml version="1.0" encoding="utf-8"?>
<metalink version="3.0" xmlns="http://www.metalinker.org/">
<publisher>
<name>GNU Wget</name>
</publisher>
<license>
<name>GNU GPL</name>
<url>http://www.gnu.org/licenses/gpl.html</url>
</license>
<identity>Wget Test Files</identity>
<version>1.2.3</version>
<description>Wget Test Files description</description>
<files>
<file name="dir/File1">
<verification>
<hash type="sha256">{{FILE1_HASH}}</hash>
</verification>
<resources>
<url type="http" preference="35">http://{{SRV_HOST}}:{{SRV_PORT}}/wrong_file</url>
<url type="http" preference="40">http://{{SRV_HOST}}:{{SRV_PORT}}/404</url>
<url type="http" preference="25">http://{{SRV_HOST}}:{{SRV_PORT}}/File1_lowPref</url>
<url type="http" preference="30">http://{{SRV_HOST}}:{{SRV_PORT}}/File1</url>
</resources>
</file>
<file name="dir/File2">
<verification>
<hash type="sha256">{{FILE2_HASH}}</hash>
</verification>
<resources>
<url type="http" preference="35">http://{{SRV_HOST}}:{{SRV_PORT}}/wrong_file</url>
<url type="http" preference="40">http://{{SRV_HOST}}:{{SRV_PORT}}/404</url>
<url type="http" preference="25">http://{{SRV_HOST}}:{{SRV_PORT}}/File2_lowPref</url>
<url type="http" preference="30">http://{{SRV_HOST}}:{{SRV_PORT}}/File2</url>
</resources>
</file>
<file name="/dir/File3"> <!-- rejected by libmetalink -->
<verification>
<hash type="sha256">{{FILE3_HASH}}</hash>
</verification>
<resources>
<url type="http" preference="35">http://{{SRV_HOST}}:{{SRV_PORT}}/wrong_file</url>
<url type="http" preference="40">http://{{SRV_HOST}}:{{SRV_PORT}}/404</url>
<url type="http" preference="25">http://{{SRV_HOST}}:{{SRV_PORT}}/File3_lowPref</url>
<url type="http" preference="30">http://{{SRV_HOST}}:{{SRV_PORT}}/File3</url>
</resources>
</file>
<file name="dir/File4">
<verification>
<hash type="sha256">{{FILE4_HASH}}</hash>
</verification>
<resources>
<url type="http" preference="35">http://{{SRV_HOST}}:{{SRV_PORT}}/wrong_file</url>
<url type="http" preference="40">http://{{SRV_HOST}}:{{SRV_PORT}}/404</url>
<url type="http" preference="25">http://{{SRV_HOST}}:{{SRV_PORT}}/File4_lowPref</url>
<url type="http" preference="30">http://{{SRV_HOST}}:{{SRV_PORT}}/File4</url>
</resources>
</file>
<file name="dir/File5">
<verification>
<hash type="sha256">{{FILE5_HASH}}</hash>
</verification>
<resources>
<url type="http" preference="35">http://{{SRV_HOST}}:{{SRV_PORT}}/wrong_file</url>
<url type="http" preference="40">http://{{SRV_HOST}}:{{SRV_PORT}}/404</url>
<url type="http" preference="25">http://{{SRV_HOST}}:{{SRV_PORT}}/File5_lowPref</url>
<url type="http" preference="30">http://{{SRV_HOST}}:{{SRV_PORT}}/File5</url>
</resources>
</file>
</files>
</metalink>
"""
# This will be filled as soon as we know server hostname and port
MetaHTTPRules = {'SendHeader' : {}}
MetaHTTP = WgetFile ("main.metalink", rules=MetaHTTPRules)
MetaHTTP_down = WgetFile ("newname.metalink", MetaXml)
wrong_file = WgetFile ("wrong_file", bad)
File1_orig = WgetFile ("File1", File1)
File1_down = WgetFile ("dir/File1", File1)
File1_nono = WgetFile ("File1_lowPref", File1_lowPref)
File2_orig = WgetFile ("File2", File2)
File2_down = WgetFile ("dir/File2", File2)
File2_nono = WgetFile ("File2_lowPref", File2_lowPref)
# rejected by libmetalink
File3_orig = WgetFile ("File3", File3)
File3_nono = WgetFile ("File3_lowPref", File3_lowPref)
File4_orig = WgetFile ("File4", File4)
File4_down = WgetFile ("dir/File4", File4)
File4_nono = WgetFile ("File4_lowPref", File4_lowPref)
File5_orig = WgetFile ("File5", File5)
File5_down = WgetFile ("dir/File5", File5)
File5_nono = WgetFile ("File5_lowPref", File5_lowPref)
WGET_OPTIONS = "--trust-server-names --metalink-over-http --content-disposition --metalink-index=0"
WGET_URLS = [["main.metalink"]]
RequestList = [[
"HEAD /main.metalink",
"GET /main.metalink",
"GET /404",
"GET /wrong_file",
"GET /File1",
"GET /File2",
"GET /File4",
"GET /File5"
]]
Files = [[
MetaHTTP,
wrong_file,
File1_orig, File1_nono,
File2_orig, File2_nono,
File3_orig, File3_nono,
File4_orig, File4_nono,
File5_orig, File5_nono
]]
Existing_Files = []
ExpectedReturnCode = 0
ExpectedDownloadedFiles = [
MetaHTTP_down,
File1_down,
File2_down,
File4_down,
File5_down
]
################ Pre and Post Test Hooks #####################################
pre_test = {
"ServerFiles" : Files,
"LocalFiles" : Existing_Files
}
test_options = {
"WgetCommands" : WGET_OPTIONS,
"Urls" : WGET_URLS
}
post_test = {
"ExpectedFiles" : ExpectedDownloadedFiles,
"ExpectedRetcode" : ExpectedReturnCode,
"FilesCrawled" : RequestList
}
http_test = HTTPTest (
pre_hook=pre_test,
test_params=test_options,
post_hook=post_test
)
http_test.server_setup()
### Get and use dynamic server sockname
srv_host, srv_port = http_test.servers[0].server_inst.socket.getsockname ()
MetaXml = MetaXml.replace('{{FILE1_HASH}}', File1_sha256)
MetaXml = MetaXml.replace('{{FILE2_HASH}}', File2_sha256)
MetaXml = MetaXml.replace('{{FILE3_HASH}}', File3_sha256)
MetaXml = MetaXml.replace('{{FILE4_HASH}}', File4_sha256)
MetaXml = MetaXml.replace('{{FILE5_HASH}}', File5_sha256)
MetaXml = MetaXml.replace('{{SRV_HOST}}', srv_host)
MetaXml = MetaXml.replace('{{SRV_PORT}}', str (srv_port))
MetaHTTP_down.content = MetaXml
MetaHTTP.content = MetaXml
MetaHTTPRules["SendHeader"] = {
'Content-Type': 'application/metalink4+xml',
'Content-Disposition': 'filename="newname.metalink"'
}
err = http_test.begin ()
exit (err)

View File

@@ -0,0 +1,221 @@
#!/usr/bin/env python3
from sys import exit
from test.http_test import HTTPTest
from misc.wget_file import WgetFile
import hashlib
from base64 import b64encode
"""
This is to test Metalink/HTTP with Content-Type Metalink/XML.
With --trust-server-names, trust the metalink:file names.
Without --trust-server-names, don't trust the metalink:file names:
use the basename of --input-metalink, and add a sequential number
(e.g. .#1, .#2, etc.).
Strip the directory from unsafe paths.
"""
############# File Definitions ###############################################
bad = "Ouch!"
File1 = "Would you like some Tea?"
File1_lowPref = "Do not take this"
File1_sha256 = hashlib.sha256 (File1.encode ('UTF-8')).hexdigest ()
File2 = "This is gonna be good"
File2_lowPref = "Not this one too"
File2_sha256 = hashlib.sha256 (File2.encode ('UTF-8')).hexdigest ()
File3 = "A little more, please"
File3_lowPref = "That's just too much"
File3_sha256 = hashlib.sha256 (File3.encode ('UTF-8')).hexdigest ()
File4 = "Maybe a biscuit?"
File4_lowPref = "No, thanks"
File4_sha256 = hashlib.sha256 (File4.encode ('UTF-8')).hexdigest ()
File5 = "More Tea...?"
File5_lowPref = "I have to go..."
File5_sha256 = hashlib.sha256 (File5.encode ('UTF-8')).hexdigest ()
MetaXml = \
"""<?xml version="1.0" encoding="utf-8"?>
<metalink version="3.0" xmlns="http://www.metalinker.org/">
<publisher>
<name>GNU Wget</name>
</publisher>
<license>
<name>GNU GPL</name>
<url>http://www.gnu.org/licenses/gpl.html</url>
</license>
<identity>Wget Test Files</identity>
<version>1.2.3</version>
<description>Wget Test Files description</description>
<files>
<file name="dir/File1">
<verification>
<hash type="sha256">{{FILE1_HASH}}</hash>
</verification>
<resources>
<url type="http" preference="35">http://{{SRV_HOST}}:{{SRV_PORT}}/wrong_file</url>
<url type="http" preference="40">http://{{SRV_HOST}}:{{SRV_PORT}}/404</url>
<url type="http" preference="25">http://{{SRV_HOST}}:{{SRV_PORT}}/File1_lowPref</url>
<url type="http" preference="30">http://{{SRV_HOST}}:{{SRV_PORT}}/File1</url>
</resources>
</file>
<file name="dir/File2">
<verification>
<hash type="sha256">{{FILE2_HASH}}</hash>
</verification>
<resources>
<url type="http" preference="35">http://{{SRV_HOST}}:{{SRV_PORT}}/wrong_file</url>
<url type="http" preference="40">http://{{SRV_HOST}}:{{SRV_PORT}}/404</url>
<url type="http" preference="25">http://{{SRV_HOST}}:{{SRV_PORT}}/File2_lowPref</url>
<url type="http" preference="30">http://{{SRV_HOST}}:{{SRV_PORT}}/File2</url>
</resources>
</file>
<file name="/dir/File3"> <!-- rejected by libmetalink -->
<verification>
<hash type="sha256">{{FILE3_HASH}}</hash>
</verification>
<resources>
<url type="http" preference="35">http://{{SRV_HOST}}:{{SRV_PORT}}/wrong_file</url>
<url type="http" preference="40">http://{{SRV_HOST}}:{{SRV_PORT}}/404</url>
<url type="http" preference="25">http://{{SRV_HOST}}:{{SRV_PORT}}/File3_lowPref</url>
<url type="http" preference="30">http://{{SRV_HOST}}:{{SRV_PORT}}/File3</url>
</resources>
</file>
<file name="dir/File4">
<verification>
<hash type="sha256">{{FILE4_HASH}}</hash>
</verification>
<resources>
<url type="http" preference="35">http://{{SRV_HOST}}:{{SRV_PORT}}/wrong_file</url>
<url type="http" preference="40">http://{{SRV_HOST}}:{{SRV_PORT}}/404</url>
<url type="http" preference="25">http://{{SRV_HOST}}:{{SRV_PORT}}/File4_lowPref</url>
<url type="http" preference="30">http://{{SRV_HOST}}:{{SRV_PORT}}/File4</url>
</resources>
</file>
<file name="dir/File5">
<verification>
<hash type="sha256">{{FILE5_HASH}}</hash>
</verification>
<resources>
<url type="http" preference="35">http://{{SRV_HOST}}:{{SRV_PORT}}/wrong_file</url>
<url type="http" preference="40">http://{{SRV_HOST}}:{{SRV_PORT}}/404</url>
<url type="http" preference="25">http://{{SRV_HOST}}:{{SRV_PORT}}/File5_lowPref</url>
<url type="http" preference="30">http://{{SRV_HOST}}:{{SRV_PORT}}/File5</url>
</resources>
</file>
</files>
</metalink>
"""
# This will be filled as soon as we know server hostname and port
MetaHTTPRules = {'SendHeader' : {}}
MetaHTTP = WgetFile ("main.metalink", rules=MetaHTTPRules)
MetaHTTP_down = WgetFile ("main.metalink", MetaXml)
wrong_file = WgetFile ("wrong_file", bad)
File1_orig = WgetFile ("File1", File1)
File1_down = WgetFile ("dir/File1", File1)
File1_nono = WgetFile ("File1_lowPref", File1_lowPref)
File2_orig = WgetFile ("File2", File2)
File2_down = WgetFile ("dir/File2", File2)
File2_nono = WgetFile ("File2_lowPref", File2_lowPref)
# rejected by libmetalink
File3_orig = WgetFile ("File3", File3)
File3_nono = WgetFile ("File3_lowPref", File3_lowPref)
File4_orig = WgetFile ("File4", File4)
File4_down = WgetFile ("dir/File4", File4)
File4_nono = WgetFile ("File4_lowPref", File4_lowPref)
File5_orig = WgetFile ("File5", File5)
File5_down = WgetFile ("dir/File5", File5)
File5_nono = WgetFile ("File5_lowPref", File5_lowPref)
WGET_OPTIONS = "--trust-server-names --metalink-over-http --metalink-index=0"
WGET_URLS = [["main.metalink"]]
RequestList = [[
"HEAD /main.metalink",
"GET /main.metalink",
"GET /404",
"GET /wrong_file",
"GET /File1",
"GET /File2",
"GET /File4",
"GET /File5"
]]
Files = [[
MetaHTTP,
wrong_file,
File1_orig, File1_nono,
File2_orig, File2_nono,
File3_orig, File3_nono,
File4_orig, File4_nono,
File5_orig, File5_nono
]]
Existing_Files = []
ExpectedReturnCode = 0
ExpectedDownloadedFiles = [
MetaHTTP_down,
File1_down,
File2_down,
File4_down,
File5_down
]
################ Pre and Post Test Hooks #####################################
pre_test = {
"ServerFiles" : Files,
"LocalFiles" : Existing_Files
}
test_options = {
"WgetCommands" : WGET_OPTIONS,
"Urls" : WGET_URLS
}
post_test = {
"ExpectedFiles" : ExpectedDownloadedFiles,
"ExpectedRetcode" : ExpectedReturnCode,
"FilesCrawled" : RequestList
}
http_test = HTTPTest (
pre_hook=pre_test,
test_params=test_options,
post_hook=post_test
)
http_test.server_setup()
### Get and use dynamic server sockname
srv_host, srv_port = http_test.servers[0].server_inst.socket.getsockname ()
MetaXml = MetaXml.replace('{{FILE1_HASH}}', File1_sha256)
MetaXml = MetaXml.replace('{{FILE2_HASH}}', File2_sha256)
MetaXml = MetaXml.replace('{{FILE3_HASH}}', File3_sha256)
MetaXml = MetaXml.replace('{{FILE4_HASH}}', File4_sha256)
MetaXml = MetaXml.replace('{{FILE5_HASH}}', File5_sha256)
MetaXml = MetaXml.replace('{{SRV_HOST}}', srv_host)
MetaXml = MetaXml.replace('{{SRV_PORT}}', str (srv_port))
MetaHTTP_down.content = MetaXml
MetaHTTP.content = MetaXml
MetaHTTPRules["SendHeader"] = {
'Content-Type': 'application/metalink4+xml',
'Content-Disposition': 'filename="newname.metalink"'
}
err = http_test.begin ()
exit (err)

View File

@@ -0,0 +1,221 @@
#!/usr/bin/env python3
from sys import exit
from test.http_test import HTTPTest
from misc.wget_file import WgetFile
import hashlib
from base64 import b64encode
"""
This is to test Metalink/HTTP with Content-Type Metalink/XML.
With --trust-server-names, trust the metalink:file names.
Without --trust-server-names, don't trust the metalink:file names:
use the basename of --input-metalink, and add a sequential number
(e.g. .#1, .#2, etc.).
Strip the directory from unsafe paths.
"""
############# File Definitions ###############################################
bad = "Ouch!"
File1 = "Would you like some Tea?"
File1_lowPref = "Do not take this"
File1_sha256 = hashlib.sha256 (File1.encode ('UTF-8')).hexdigest ()
File2 = "This is gonna be good"
File2_lowPref = "Not this one too"
File2_sha256 = hashlib.sha256 (File2.encode ('UTF-8')).hexdigest ()
File3 = "A little more, please"
File3_lowPref = "That's just too much"
File3_sha256 = hashlib.sha256 (File3.encode ('UTF-8')).hexdigest ()
File4 = "Maybe a biscuit?"
File4_lowPref = "No, thanks"
File4_sha256 = hashlib.sha256 (File4.encode ('UTF-8')).hexdigest ()
File5 = "More Tea...?"
File5_lowPref = "I have to go..."
File5_sha256 = hashlib.sha256 (File5.encode ('UTF-8')).hexdigest ()
MetaXml = \
"""<?xml version="1.0" encoding="utf-8"?>
<metalink version="3.0" xmlns="http://www.metalinker.org/">
<publisher>
<name>GNU Wget</name>
</publisher>
<license>
<name>GNU GPL</name>
<url>http://www.gnu.org/licenses/gpl.html</url>
</license>
<identity>Wget Test Files</identity>
<version>1.2.3</version>
<description>Wget Test Files description</description>
<files>
<file name="dir/File1">
<verification>
<hash type="sha256">{{FILE1_HASH}}</hash>
</verification>
<resources>
<url type="http" preference="35">http://{{SRV_HOST}}:{{SRV_PORT}}/wrong_file</url>
<url type="http" preference="40">http://{{SRV_HOST}}:{{SRV_PORT}}/404</url>
<url type="http" preference="25">http://{{SRV_HOST}}:{{SRV_PORT}}/File1_lowPref</url>
<url type="http" preference="30">http://{{SRV_HOST}}:{{SRV_PORT}}/File1</url>
</resources>
</file>
<file name="dir/File2">
<verification>
<hash type="sha256">{{FILE2_HASH}}</hash>
</verification>
<resources>
<url type="http" preference="35">http://{{SRV_HOST}}:{{SRV_PORT}}/wrong_file</url>
<url type="http" preference="40">http://{{SRV_HOST}}:{{SRV_PORT}}/404</url>
<url type="http" preference="25">http://{{SRV_HOST}}:{{SRV_PORT}}/File2_lowPref</url>
<url type="http" preference="30">http://{{SRV_HOST}}:{{SRV_PORT}}/File2</url>
</resources>
</file>
<file name="/dir/File3"> <!-- rejected by libmetalink -->
<verification>
<hash type="sha256">{{FILE3_HASH}}</hash>
</verification>
<resources>
<url type="http" preference="35">http://{{SRV_HOST}}:{{SRV_PORT}}/wrong_file</url>
<url type="http" preference="40">http://{{SRV_HOST}}:{{SRV_PORT}}/404</url>
<url type="http" preference="25">http://{{SRV_HOST}}:{{SRV_PORT}}/File3_lowPref</url>
<url type="http" preference="30">http://{{SRV_HOST}}:{{SRV_PORT}}/File3</url>
</resources>
</file>
<file name="dir/File4">
<verification>
<hash type="sha256">{{FILE4_HASH}}</hash>
</verification>
<resources>
<url type="http" preference="35">http://{{SRV_HOST}}:{{SRV_PORT}}/wrong_file</url>
<url type="http" preference="40">http://{{SRV_HOST}}:{{SRV_PORT}}/404</url>
<url type="http" preference="25">http://{{SRV_HOST}}:{{SRV_PORT}}/File4_lowPref</url>
<url type="http" preference="30">http://{{SRV_HOST}}:{{SRV_PORT}}/File4</url>
</resources>
</file>
<file name="dir/File5">
<verification>
<hash type="sha256">{{FILE5_HASH}}</hash>
</verification>
<resources>
<url type="http" preference="35">http://{{SRV_HOST}}:{{SRV_PORT}}/wrong_file</url>
<url type="http" preference="40">http://{{SRV_HOST}}:{{SRV_PORT}}/404</url>
<url type="http" preference="25">http://{{SRV_HOST}}:{{SRV_PORT}}/File5_lowPref</url>
<url type="http" preference="30">http://{{SRV_HOST}}:{{SRV_PORT}}/File5</url>
</resources>
</file>
</files>
</metalink>
"""
# This will be filled as soon as we know server hostname and port
MetaHTTPRules = {'SendHeader' : {}}
MetaHTTP = WgetFile ("main.metalink", rules=MetaHTTPRules)
MetaHTTP_down = WgetFile ("main.metalink.meta#1", MetaXml)
wrong_file = WgetFile ("wrong_file", bad)
File1_orig = WgetFile ("File1", File1)
File1_down = WgetFile ("main.metalink.meta#1.#1", File1)
File1_nono = WgetFile ("File1_lowPref", File1_lowPref)
File2_orig = WgetFile ("File2", File2)
File2_down = WgetFile ("main.metalink.meta#1.#2", File2)
File2_nono = WgetFile ("File2_lowPref", File2_lowPref)
# rejected by libmetalink
File3_orig = WgetFile ("File3", File3)
File3_nono = WgetFile ("File3_lowPref", File3_lowPref)
File4_orig = WgetFile ("File4", File4)
File4_down = WgetFile ("main.metalink.meta#1.#3", File4)
File4_nono = WgetFile ("File4_lowPref", File4_lowPref)
File5_orig = WgetFile ("File5", File5)
File5_down = WgetFile ("main.metalink.meta#1.#4", File5)
File5_nono = WgetFile ("File5_lowPref", File5_lowPref)
WGET_OPTIONS = "--metalink-over-http --metalink-index=0"
WGET_URLS = [["main.metalink"]]
RequestList = [[
"HEAD /main.metalink",
"GET /main.metalink",
"GET /404",
"GET /wrong_file",
"GET /File1",
"GET /File2",
"GET /File4",
"GET /File5"
]]
Files = [[
MetaHTTP,
wrong_file,
File1_orig, File1_nono,
File2_orig, File2_nono,
File3_orig, File3_nono,
File4_orig, File4_nono,
File5_orig, File5_nono
]]
Existing_Files = []
ExpectedReturnCode = 0
ExpectedDownloadedFiles = [
MetaHTTP_down,
File1_down,
File2_down,
File4_down,
File5_down
]
################ Pre and Post Test Hooks #####################################
pre_test = {
"ServerFiles" : Files,
"LocalFiles" : Existing_Files
}
test_options = {
"WgetCommands" : WGET_OPTIONS,
"Urls" : WGET_URLS
}
post_test = {
"ExpectedFiles" : ExpectedDownloadedFiles,
"ExpectedRetcode" : ExpectedReturnCode,
"FilesCrawled" : RequestList
}
http_test = HTTPTest (
pre_hook=pre_test,
test_params=test_options,
post_hook=post_test
)
http_test.server_setup()
### Get and use dynamic server sockname
srv_host, srv_port = http_test.servers[0].server_inst.socket.getsockname ()
MetaXml = MetaXml.replace('{{FILE1_HASH}}', File1_sha256)
MetaXml = MetaXml.replace('{{FILE2_HASH}}', File2_sha256)
MetaXml = MetaXml.replace('{{FILE3_HASH}}', File3_sha256)
MetaXml = MetaXml.replace('{{FILE4_HASH}}', File4_sha256)
MetaXml = MetaXml.replace('{{FILE5_HASH}}', File5_sha256)
MetaXml = MetaXml.replace('{{SRV_HOST}}', srv_host)
MetaXml = MetaXml.replace('{{SRV_PORT}}', str (srv_port))
MetaHTTP_down.content = MetaXml
MetaHTTP.content = MetaXml
MetaHTTPRules["SendHeader"] = {
'Content-Type': 'application/metalink4+xml',
'Content-Disposition': 'filename="newname.metalink"'
}
err = http_test.begin ()
exit (err)

272
testenv/Test-metalink-http-xml.py Executable file
View File

@@ -0,0 +1,272 @@
#!/usr/bin/env python3
from sys import exit
from test.http_test import HTTPTest
from misc.wget_file import WgetFile
import hashlib
from base64 import b64encode
"""
This is to test Metalink/HTTP with Metalink/XML Link headers.
With --trust-server-names, trust the metalink:file names.
Without --trust-server-names, don't trust the metalink:file names:
use the basename of --input-metalink, and add a sequential number
(e.g. .#1, .#2, etc.).
Strip the directory from unsafe paths.
"""
############# File Definitions ###############################################
bad = "Ouch!"
bad_sha256 = hashlib.sha256 (bad.encode ('UTF-8')).hexdigest ()
File1 = "Would you like some Tea?"
File1_lowPref = "Do not take this"
File1_sha256 = hashlib.sha256 (File1.encode ('UTF-8')).hexdigest ()
File2 = "This is gonna be good"
File2_lowPref = "Not this one too"
File2_sha256 = hashlib.sha256 (File2.encode ('UTF-8')).hexdigest ()
File3 = "A little more, please"
File3_lowPref = "That's just too much"
File3_sha256 = hashlib.sha256 (File3.encode ('UTF-8')).hexdigest ()
File4 = "Maybe a biscuit?"
File4_lowPref = "No, thanks"
File4_sha256 = hashlib.sha256 (File4.encode ('UTF-8')).hexdigest ()
File5 = "More Tea...?"
File5_lowPref = "I have to go..."
File5_sha256 = hashlib.sha256 (File5.encode ('UTF-8')).hexdigest ()
MetaXml1 = \
"""<?xml version="1.0" encoding="utf-8"?>
<metalink version="3.0" xmlns="http://www.metalinker.org/">
<publisher>
<name>GNU Wget</name>
</publisher>
<license>
<name>GNU GPL</name>
<url>http://www.gnu.org/licenses/gpl.html</url>
</license>
<identity>Wget Test Files</identity>
<version>1.2.3</version>
<description>Wget Test Files description</description>
<files>
<file name="dir/File1">
<verification>
<hash type="sha256">{{FILE1_HASH}}</hash>
</verification>
<resources>
<url type="http" preference="35">http://{{SRV_HOST}}:{{SRV_PORT}}/wrong_file</url>
<url type="http" preference="40">http://{{SRV_HOST}}:{{SRV_PORT}}/404</url>
<url type="http" preference="25">http://{{SRV_HOST}}:{{SRV_PORT}}/File1_lowPref</url>
<url type="http" preference="30">http://{{SRV_HOST}}:{{SRV_PORT}}/File1</url>
</resources>
</file>
<file name="dir/File2">
<verification>
<hash type="sha256">{{FILE2_HASH}}</hash>
</verification>
<resources>
<url type="http" preference="35">http://{{SRV_HOST}}:{{SRV_PORT}}/wrong_file</url>
<url type="http" preference="40">http://{{SRV_HOST}}:{{SRV_PORT}}/404</url>
<url type="http" preference="25">http://{{SRV_HOST}}:{{SRV_PORT}}/File2_lowPref</url>
<url type="http" preference="30">http://{{SRV_HOST}}:{{SRV_PORT}}/File2</url>
</resources>
</file>
<file name="/dir/File3"> <!-- rejected by libmetalink -->
<verification>
<hash type="sha256">{{FILE3_HASH}}</hash>
</verification>
<resources>
<url type="http" preference="35">http://{{SRV_HOST}}:{{SRV_PORT}}/wrong_file</url>
<url type="http" preference="40">http://{{SRV_HOST}}:{{SRV_PORT}}/404</url>
<url type="http" preference="25">http://{{SRV_HOST}}:{{SRV_PORT}}/File3_lowPref</url>
<url type="http" preference="30">http://{{SRV_HOST}}:{{SRV_PORT}}/File3</url>
</resources>
</file>
<file name="dir/File4">
<verification>
<hash type="sha256">{{FILE4_HASH}}</hash>
</verification>
<resources>
<url type="http" preference="35">http://{{SRV_HOST}}:{{SRV_PORT}}/wrong_file</url>
<url type="http" preference="40">http://{{SRV_HOST}}:{{SRV_PORT}}/404</url>
<url type="http" preference="25">http://{{SRV_HOST}}:{{SRV_PORT}}/File4_lowPref</url>
<url type="http" preference="30">http://{{SRV_HOST}}:{{SRV_PORT}}/File4</url>
</resources>
</file>
<file name="dir/File5">
<verification>
<hash type="sha256">{{FILE5_HASH}}</hash>
</verification>
<resources>
<url type="http" preference="35">http://{{SRV_HOST}}:{{SRV_PORT}}/wrong_file</url>
<url type="http" preference="40">http://{{SRV_HOST}}:{{SRV_PORT}}/404</url>
<url type="http" preference="25">http://{{SRV_HOST}}:{{SRV_PORT}}/File5_lowPref</url>
<url type="http" preference="30">http://{{SRV_HOST}}:{{SRV_PORT}}/File5</url>
</resources>
</file>
</files>
</metalink>
"""
MetaXml2 = \
"""<?xml version="1.0" encoding="utf-8"?>
<metalink version="3.0" xmlns="http://www.metalinker.org/">
<publisher>
<name>GNU Wget</name>
</publisher>
<license>
<name>GNU GPL</name>
<url>http://www.gnu.org/licenses/gpl.html</url>
</license>
<identity>Wget Test Files</identity>
<version>1.2.3</version>
<description>Wget Test Files description</description>
<files>
<file name="bad">
<verification>
<hash type="sha256">{{BAD_HASH}}</hash>
</verification>
<resources>
<url type="http" preference="35">http://{{SRV_HOST}}:{{SRV_PORT}}/wrong_file</url>
<url type="http" preference="40">http://{{SRV_HOST}}:{{SRV_PORT}}/404</url>
<url type="http" preference="30">http://{{SRV_HOST}}:{{SRV_PORT}}/bad</url>
</resources>
</file>
</files>
</metalink>
"""
LinkHeaders = [
# This file has the lowest priority, and should go last
"<http://{{SRV_HOST}}:{{SRV_PORT}}/test1.metalink>; rel=describedby; pri=2; type=\"application/metalink4+xml\"",
# This file has the highest priority, and should go first
"<http://{{SRV_HOST}}:{{SRV_PORT}}/test2.metalink>; rel=describedby; pri=1; type=\"application/metalink4+xml\""
]
# This will be filled as soon as we know server hostname and port
MetaHTTPRules = {'SendHeader' : {}}
MetaHTTP = WgetFile ("main.metalink", rules=MetaHTTPRules)
wrong_file = WgetFile ("wrong_file", bad)
File1_orig = WgetFile ("File1", File1)
File1_down = WgetFile ("main.metalink.meta#2.#1", File1)
File1_nono = WgetFile ("File1_lowPref", File1_lowPref)
File2_orig = WgetFile ("File2", File2)
File2_down = WgetFile ("main.metalink.meta#2.#2", File2)
File2_nono = WgetFile ("File2_lowPref", File2_lowPref)
# rejected by libmetalink
File3_orig = WgetFile ("File3", File3)
File3_nono = WgetFile ("File3_lowPref", File3_lowPref)
File4_orig = WgetFile ("File4", File4)
File4_down = WgetFile ("main.metalink.meta#2.#3", File4)
File4_nono = WgetFile ("File4_lowPref", File4_lowPref)
File5_orig = WgetFile ("File5", File5)
File5_down = WgetFile ("main.metalink.meta#2.#4", File5)
File5_nono = WgetFile ("File5_lowPref", File5_lowPref)
MetaFile1 = WgetFile ("test1.metalink", MetaXml1)
MetaFile1_down = WgetFile ("main.metalink.meta#2", MetaXml1)
MetaFile2 = WgetFile ("test2.metalink", MetaXml2)
WGET_OPTIONS = "--metalink-over-http --metalink-index=2"
WGET_URLS = [["main.metalink"]]
RequestList = [[
"HEAD /main.metalink",
"GET /404",
"GET /wrong_file",
"GET /test1.metalink",
"GET /File1",
"GET /File2",
"GET /File4",
"GET /File5"
]]
Files = [[
MetaHTTP,
wrong_file,
MetaFile1, MetaFile2,
File1_orig, File1_nono,
File2_orig, File2_nono,
File3_orig, File3_nono,
File4_orig, File4_nono,
File5_orig, File5_nono
]]
Existing_Files = []
ExpectedReturnCode = 0
ExpectedDownloadedFiles = [
MetaFile1_down,
File1_down,
File2_down,
File4_down,
File5_down
]
################ Pre and Post Test Hooks #####################################
pre_test = {
"ServerFiles" : Files,
"LocalFiles" : Existing_Files
}
test_options = {
"WgetCommands" : WGET_OPTIONS,
"Urls" : WGET_URLS
}
post_test = {
"ExpectedFiles" : ExpectedDownloadedFiles,
"ExpectedRetcode" : ExpectedReturnCode,
"FilesCrawled" : RequestList
}
http_test = HTTPTest (
pre_hook=pre_test,
test_params=test_options,
post_hook=post_test
)
http_test.server_setup()
### Get and use dynamic server sockname
srv_host, srv_port = http_test.servers[0].server_inst.socket.getsockname ()
MetaXml1 = MetaXml1.replace('{{FILE1_HASH}}', File1_sha256)
MetaXml1 = MetaXml1.replace('{{FILE2_HASH}}', File2_sha256)
MetaXml1 = MetaXml1.replace('{{FILE3_HASH}}', File3_sha256)
MetaXml1 = MetaXml1.replace('{{FILE4_HASH}}', File4_sha256)
MetaXml1 = MetaXml1.replace('{{FILE5_HASH}}', File5_sha256)
MetaXml1 = MetaXml1.replace('{{SRV_HOST}}', srv_host)
MetaXml1 = MetaXml1.replace('{{SRV_PORT}}', str (srv_port))
MetaFile1.content = MetaXml1
MetaFile1_down.content = MetaXml1
MetaXml2 = MetaXml2.replace('{{BAD_HASH}}', bad_sha256)
MetaXml2 = MetaXml2.replace('{{SRV_HOST}}', srv_host)
MetaXml2 = MetaXml2.replace('{{SRV_PORT}}', str (srv_port))
MetaFile2.content = MetaXml2
# Helper function for hostname, port and digest substitution
def SubstituteServerInfo (text, host, port):
text = text.replace('{{SRV_HOST}}', host)
text = text.replace('{{SRV_PORT}}', str (port))
return text
MetaHTTPRules["SendHeader"] = {
'Link': [ SubstituteServerInfo (LinkHeader, srv_host, srv_port)
for LinkHeader in LinkHeaders ]
}
err = http_test.begin ()
exit (err)

View File

@@ -2,7 +2,6 @@
from sys import exit
from test.http_test import HTTPTest
from misc.wget_file import WgetFile
import re
import hashlib
from base64 import b64encode
@@ -12,9 +11,9 @@ from base64 import b64encode
# Helper function for hostname, port and digest substitution
def SubstituteServerInfo (text, host, port, digest):
text = re.sub (r'{{FILE1_HASH}}', digest, text)
text = re.sub (r'{{SRV_HOST}}', host, text)
text = re.sub (r'{{SRV_PORT}}', str (port), text)
text = text.replace('{{FILE1_HASH}}', digest)
text = text.replace('{{SRV_HOST}}', host)
text = text.replace('{{SRV_PORT}}', str (port))
return text
############# File Definitions ###############################################

View File

@@ -0,0 +1,101 @@
#!/usr/bin/env python3
from sys import exit
from misc.metalinkv3_xml import Metalinkv3_XML
"""
This is to test if Metalink/XML forbids absolute paths.
With --trust-server-names, trust the metalink:file names.
Without --trust-server-names, don't trust the metalink:file names:
use the basename of --input-metalink, and add a sequential number
(e.g. .#1, .#2, etc.).
Strip the directory from unsafe paths.
"""
############# File Definitions ###############################################
wrong_file = "Ouch!"
File1 = "Would you like some Tea?"
File1_lowPref = "Do not take this"
File2 = "This is gonna be good"
File2_lowPref = "Not this one too"
File3 = "A little more, please"
File3_lowPref = "That's just too much"
File4 = "Maybe a biscuit?"
File4_lowPref = "No, thanks"
File5 = "More Tea...?"
File5_lowPref = "I have to go..."
############# Metalink/XML ###################################################
Meta = Metalinkv3_XML()
# file_name: metalink:file "name" field
# save_name: metalink:file save name, if None the file is rejected
# content : metalink:file content
#
# size:
# True auto-compute size
# None no <size></size>
# any use this size
#
# hash_sha256:
# False no <verification></verification>
# True auto-compute sha256
# None no <hash></hash>
# any use this hash
#
# srv_file : metalink:url server file
# srv_content: metalink:url server file content, if None the file doesn't exist
# utype : metalink:url type
# location : metalink:url location (default 'no location field')
# preference : metalink:url preference (default 999999)
XmlName = "test.metalink"
Meta.xml (
# Metalink/XML file name
XmlName,
# file_name, save_name, content, size, hash_sha256
["/File1", None, File1, None, True,
# srv_file, srv_content, utype, location, preference
["wrong_file", wrong_file, "http", None, 35],
["404", None, "http", None, 40],
["File1_lowPref", File1_lowPref, "http", None, 25],
["File1", File1, "http", None, 30]],
["File2", "File2", File2, None, True,
["wrong_file", wrong_file, "http", None, 35],
["404", None, "http", None, 40],
["File2_lowPref", File2_lowPref, "http", None, 25],
["File2", File2, "http", None, 30]],
["/File3", None, File3, None, True,
["wrong_file", wrong_file, "http", None, 35],
["404", None, "http", None, 40],
["File3_lowPref", File3_lowPref, "http", None, 25],
["File3", File3, "http", None, 30]],
["/File4", None, File4, None, True,
["wrong_file", wrong_file, "http", None, 35],
["404", None, "http", None, 40],
["File4_lowPref", File4_lowPref, "http", None, 25],
["File4", File4, "http", None, 30]],
["File5", "File5", File5, None, True,
["wrong_file", wrong_file, "http", None, 35],
["404", None, "http", None, 40],
["File5_lowPref", File5_lowPref, "http", None, 25],
["File5", File5, "http", None, 30]],
)
Meta.print_meta ()
err = Meta.http_test (
"--trust-server-names " + \
"--input-metalink " + XmlName, 0
)
exit (err)

View File

@@ -0,0 +1,100 @@
#!/usr/bin/env python3
from sys import exit
from misc.metalinkv3_xml import Metalinkv3_XML
"""
This is to test if Metalink/XML forbids absolute paths.
With --trust-server-names, trust the metalink:file names.
Without --trust-server-names, don't trust the metalink:file names:
use the basename of --input-metalink, and add a sequential number
(e.g. .#1, .#2, etc.).
Strip the directory from unsafe paths.
"""
############# File Definitions ###############################################
wrong_file = "Ouch!"
File1 = "Would you like some Tea?"
File1_lowPref = "Do not take this"
File2 = "This is gonna be good"
File2_lowPref = "Not this one too"
File3 = "A little more, please"
File3_lowPref = "That's just too much"
File4 = "Maybe a biscuit?"
File4_lowPref = "No, thanks"
File5 = "More Tea...?"
File5_lowPref = "I have to go..."
############# Metalink/XML ###################################################
Meta = Metalinkv3_XML()
# file_name: metalink:file "name" field
# save_name: metalink:file save name, if None the file is rejected
# content : metalink:file content
#
# size:
# True auto-compute size
# None no <size></size>
# any use this size
#
# hash_sha256:
# False no <verification></verification>
# True auto-compute sha256
# None no <hash></hash>
# any use this hash
#
# srv_file : metalink:url server file
# srv_content: metalink:url server file content, if None the file doesn't exist
# utype : metalink:url type
# location : metalink:url location (default 'no location field')
# preference : metalink:url preference (default 999999)
XmlName = "test.metalink"
Meta.xml (
# Metalink/XML file name
XmlName,
# file_name, save_name, content, size, hash_sha256
["/File1", None, File1, None, True,
# srv_file, srv_content, utype, location, preference
["wrong_file", wrong_file, "http", None, 35],
["404", None, "http", None, 40],
["File1_lowPref", File1_lowPref, "http", None, 25],
["File1", File1, "http", None, 30]],
["File2", XmlName + ".#1", File2, None, True,
["wrong_file", wrong_file, "http", None, 35],
["404", None, "http", None, 40],
["File2_lowPref", File2_lowPref, "http", None, 25],
["File2", File2, "http", None, 30]],
["/File3", None, File3, None, True,
["wrong_file", wrong_file, "http", None, 35],
["404", None, "http", None, 40],
["File3_lowPref", File3_lowPref, "http", None, 25],
["File3", File3, "http", None, 30]],
["/File4", None, File4, None, True,
["wrong_file", wrong_file, "http", None, 35],
["404", None, "http", None, 40],
["File4_lowPref", File4_lowPref, "http", None, 25],
["File4", File4, "http", None, 30]],
["File5", XmlName + ".#2", File5, None, True,
["wrong_file", wrong_file, "http", None, 35],
["404", None, "http", None, 40],
["File5_lowPref", File5_lowPref, "http", None, 25],
["File5", File5, "http", None, 30]],
)
Meta.print_meta ()
err = Meta.http_test (
"--input-metalink " + XmlName, 0
)
exit (err)

View File

@@ -0,0 +1,102 @@
#!/usr/bin/env python3
from sys import exit
from misc.metalinkv3_xml import Metalinkv3_XML
"""
This is to test Metalink/XML absolute directory prefix support in Wget.
With --trust-server-names, trust the metalink:file names.
Without --trust-server-names, don't trust the metalink:file names:
use the basename of --input-metalink, and add a sequential number
(e.g. .#1, .#2, etc.).
Strip the directory from unsafe paths.
"""
############# File Definitions ###############################################
wrong_file = "Ouch!"
File1 = "Would you like some Tea?"
File1_lowPref = "Do not take this"
File2 = "This is gonna be good"
File2_lowPref = "Not this one too"
File3 = "A little more, please"
File3_lowPref = "That's just too much"
File4 = "Maybe a biscuit?"
File4_lowPref = "No, thanks"
File5 = "More Tea...?"
File5_lowPref = "I have to go..."
############# Metalink/XML ###################################################
Meta = Metalinkv3_XML()
# file_name: metalink:file "name" field
# save_name: metalink:file save name, if None the file is rejected
# content : metalink:file content
#
# size:
# True auto-compute size
# None no <size></size>
# any use this size
#
# hash_sha256:
# False no <verification></verification>
# True auto-compute sha256
# None no <hash></hash>
# any use this hash
#
# srv_file : metalink:url server file
# srv_content: metalink:url server file content, if None the file doesn't exist
# utype : metalink:url type
# location : metalink:url location (default 'no location field')
# preference : metalink:url preference (default 999999)
XmlName = "test.metalink"
Meta.xml (
# Metalink/XML file name
XmlName,
# file_name, save_name, content, size, hash_sha256
["subdir/File1", "File1", File1, None, True,
# srv_file, srv_content, utype, location, preference
["wrong_file", wrong_file, "http", None, 35],
["404", None, "http", None, 40],
["File1_lowPref", File1_lowPref, "http", None, 25],
["File1", File1, "http", None, 30]],
["/subdir/File2", None, File2, None, True,
["wrong_file", wrong_file, "http", None, 35],
["404", None, "http", None, 40],
["File2_lowPref", File2_lowPref, "http", None, 25],
["File2", File2, "http", None, 30]],
["~/subdir/File3", None, File3, None, True,
["wrong_file", wrong_file, "http", None, 35],
["404", None, "http", None, 40],
["File3_lowPref", File3_lowPref, "http", None, 25],
["File3", File3, "http", None, 30]],
["../subdir/File4", None, File4, None, True,
["wrong_file", wrong_file, "http", None, 35],
["404", None, "http", None, 40],
["File4_lowPref", File4_lowPref, "http", None, 25],
["File4", File4, "http", None, 30]],
["subdir/File5", "File5", File5, None, True,
["wrong_file", wrong_file, "http", None, 35],
["404", None, "http", None, 40],
["File5_lowPref", File5_lowPref, "http", None, 25],
["File5", File5, "http", None, 30]],
)
Meta.print_meta ()
err = Meta.http_test (
"--trust-server-names " + \
"--directory-prefix /dir " + \
"--input-metalink " + XmlName, 0
)
exit (err)

View File

@@ -0,0 +1,101 @@
#!/usr/bin/env python3
from sys import exit
from misc.metalinkv3_xml import Metalinkv3_XML
"""
This is to test Metalink/XML absolute directory prefix support in Wget.
With --trust-server-names, trust the metalink:file names.
Without --trust-server-names, don't trust the metalink:file names:
use the basename of --input-metalink, and add a sequential number
(e.g. .#1, .#2, etc.).
Strip the directory from unsafe paths.
"""
############# File Definitions ###############################################
wrong_file = "Ouch!"
File1 = "Would you like some Tea?"
File1_lowPref = "Do not take this"
File2 = "This is gonna be good"
File2_lowPref = "Not this one too"
File3 = "A little more, please"
File3_lowPref = "That's just too much"
File4 = "Maybe a biscuit?"
File4_lowPref = "No, thanks"
File5 = "More Tea...?"
File5_lowPref = "I have to go..."
############# Metalink/XML ###################################################
Meta = Metalinkv3_XML()
# file_name: metalink:file "name" field
# save_name: metalink:file save name, if None the file is rejected
# content : metalink:file content
#
# size:
# True auto-compute size
# None no <size></size>
# any use this size
#
# hash_sha256:
# False no <verification></verification>
# True auto-compute sha256
# None no <hash></hash>
# any use this hash
#
# srv_file : metalink:url server file
# srv_content: metalink:url server file content, if None the file doesn't exist
# utype : metalink:url type
# location : metalink:url location (default 'no location field')
# preference : metalink:url preference (default 999999)
XmlName = "test.metalink"
Meta.xml (
# Metalink/XML file name
XmlName,
# file_name, save_name, content, size, hash_sha256
["subdir/File1", XmlName + ".#1", File1, None, True,
# srv_file, srv_content, utype, location, preference
["wrong_file", wrong_file, "http", None, 35],
["404", None, "http", None, 40],
["File1_lowPref", File1_lowPref, "http", None, 25],
["File1", File1, "http", None, 30]],
["/subdir/File2", None, File2, None, True,
["wrong_file", wrong_file, "http", None, 35],
["404", None, "http", None, 40],
["File2_lowPref", File2_lowPref, "http", None, 25],
["File2", File2, "http", None, 30]],
["~/subdir/File3", None, File3, None, True,
["wrong_file", wrong_file, "http", None, 35],
["404", None, "http", None, 40],
["File3_lowPref", File3_lowPref, "http", None, 25],
["File3", File3, "http", None, 30]],
["../subdir/File4", None, File4, None, True,
["wrong_file", wrong_file, "http", None, 35],
["404", None, "http", None, 40],
["File4_lowPref", File4_lowPref, "http", None, 25],
["File4", File4, "http", None, 30]],
["subdir/File5", XmlName + ".#2", File5, None, True,
["wrong_file", wrong_file, "http", None, 35],
["404", None, "http", None, 40],
["File5_lowPref", File5_lowPref, "http", None, 25],
["File5", File5, "http", None, 30]],
)
Meta.print_meta ()
err = Meta.http_test (
"--directory-prefix /dir " + \
"--input-metalink " + XmlName, 0
)
exit (err)

View File

@@ -0,0 +1,107 @@
#!/usr/bin/env python3
from sys import exit
from misc.metalinkv3_xml import Metalinkv3_XML
"""
This is to test Metalink/XML --continue support in Wget.
With --trust-server-names, trust the metalink:file names.
Without --trust-server-names, don't trust the metalink:file names:
use the basename of --input-metalink, and add a sequential number
(e.g. .#1, .#2, etc.).
Strip the directory from unsafe paths.
"""
############# File Definitions ###############################################
wrong_file = "Ouch!"
File1 = "Would you like some Tea?"
File1_lowPref = "Do not take this"
File2 = "This is gonna be good"
File2_lowPref = "Not this one too"
File3 = "A little more, please"
File3_lowPref = "That's just too much"
File4 = "Maybe a biscuit?"
File4_lowPref = "No, thanks"
File5 = "More Tea...?"
File5_lowPref = "I have to go..."
############# Metalink/XML ###################################################
Meta = Metalinkv3_XML()
# file_name: metalink:file "name" field
# save_name: metalink:file save name, if None the file is rejected
# content : metalink:file content
#
# size:
# True auto-compute size
# None no <size></size>
# any use this size
#
# hash_sha256:
# False no <verification></verification>
# True auto-compute sha256
# None no <hash></hash>
# any use this hash
#
# srv_file : metalink:url server file
# srv_content: metalink:url server file content, if None the file doesn't exist
# utype : metalink:url type (http, ftp, etc.)
# location : metalink:url location (default 'no location field')
# preference : metalink:url preference (default 999999)
XmlName = "test.metalink"
Meta.add_LocalFiles (
[XmlName + ".#1", File1[0:14]], # File1 to continue from partial file
[XmlName + ".#2", File2], # File2 to keep, different from server
[XmlName + ".#3", File3], # File3 to keep, already fully retrieved
[XmlName + ".#4", File4], # File4 to keep, different from server
)
Meta.add_ExpectedFiles (
[XmlName + ".#2", File2], # File2 to keep, different from server
[XmlName + ".#3", File3], # File3 to keep, already fully retrieved
[XmlName + ".#4", File4], # File4 to keep, different from server
)
Meta.print_meta ()
Meta.xml (
# Metalink/XML file name
XmlName,
# file_name, save_name, content, size, hash_sha256
["File1", XmlName + ".#1", File1, None, True,
# srv_file, srv_content, utype, location, preference
["File1_lowPref", File1_lowPref, "http", None, 25],
["File1", File1, "http", None, 30]],
["File2", XmlName + ".#2", wrong_file, None, True,
["wrong_file", wrong_file, "http", None, 35],
["404", None, "http", None, 40],
["File2_lowPref", File2_lowPref, "http", None, 25],
["File2", File2, "http", None, 30]],
["File3", XmlName + ".#3", File3, None, True,
["File3_lowPref", File3_lowPref, "http", None, 25],
["File3", File3, "http", None, 30]],
["File4", XmlName + ".#4", File4_lowPref, None, True,
["wrong_file", wrong_file, "http", None, 35]],
["File5", XmlName + ".#5", File5, None, True,
["File5_lowPref", File5_lowPref, "http", None, 25],
["File5", File5, "http", None, 30]],
)
Meta.print_meta ()
err = Meta.http_test (
"--continue " + \
"--input-metalink " + XmlName, 1
)
exit (err)

View File

@@ -0,0 +1,102 @@
#!/usr/bin/env python3
from sys import exit
from misc.metalinkv3_xml import Metalinkv3_XML
"""
This is to test Metalink/XML with an empty directory prefix.
With --trust-server-names, trust the metalink:file names.
Without --trust-server-names, don't trust the metalink:file names:
use the basename of --input-metalink, and add a sequential number
(e.g. .#1, .#2, etc.).
Strip the directory from unsafe paths.
"""
############# File Definitions ###############################################
wrong_file = "Ouch!"
File1 = "Would you like some Tea?"
File1_lowPref = "Do not take this"
File2 = "This is gonna be good"
File2_lowPref = "Not this one too"
File3 = "A little more, please"
File3_lowPref = "That's just too much"
File4 = "Maybe a biscuit?"
File4_lowPref = "No, thanks"
File5 = "More Tea...?"
File5_lowPref = "I have to go..."
############# Metalink/XML ###################################################
Meta = Metalinkv3_XML()
# file_name: metalink:file "name" field
# save_name: metalink:file save name, if None the file is rejected
# content : metalink:file content
#
# size:
# True auto-compute size
# None no <size></size>
# any use this size
#
# hash_sha256:
# False no <verification></verification>
# True auto-compute sha256
# None no <hash></hash>
# any use this hash
#
# srv_file : metalink:url server file
# srv_content: metalink:url server file content, if None the file doesn't exist
# utype : metalink:url type
# location : metalink:url location (default 'no location field')
# preference : metalink:url preference (default 999999)
XmlName = "test.metalink"
Meta.xml (
# Metalink/XML file name
XmlName,
# file_name, save_name, content, size, hash_sha256
["subdir/File1", "subdir/File1", File1, None, True,
# srv_file, srv_content, utype, location, preference
["wrong_file", wrong_file, "http", None, 35],
["404", None, "http", None, 40],
["File1_lowPref", File1_lowPref, "http", None, 25],
["File1", File1, "http", None, 30]],
["/subdir/File2", None, File2, None, True,
["wrong_file", wrong_file, "http", None, 35],
["404", None, "http", None, 40],
["File2_lowPref", File2_lowPref, "http", None, 25],
["File2", File2, "http", None, 30]],
["~/subdir/File3", None, File3, None, True,
["wrong_file", wrong_file, "http", None, 35],
["404", None, "http", None, 40],
["File3_lowPref", File3_lowPref, "http", None, 25],
["File3", File3, "http", None, 30]],
["../subdir/File4", None, File4, None, True,
["wrong_file", wrong_file, "http", None, 35],
["404", None, "http", None, 40],
["File4_lowPref", File4_lowPref, "http", None, 25],
["File4", File4, "http", None, 30]],
["subdir/File5", "subdir/File5", File5, None, True,
["wrong_file", wrong_file, "http", None, 35],
["404", None, "http", None, 40],
["File5_lowPref", File5_lowPref, "http", None, 25],
["File5", File5, "http", None, 30]],
)
Meta.print_meta ()
err = Meta.http_test (
"--trust-server-names " + \
"--directory-prefix '' " + \
"--input-metalink " + XmlName, 0
)
exit (err)

View File

@@ -0,0 +1,102 @@
#!/usr/bin/env python3
from sys import exit
from misc.metalinkv3_xml import Metalinkv3_XML
"""
This is to test if Metalink/XML forbids the home path and names
beginning with the ~ (tilde) character.
With --trust-server-names, trust the metalink:file names.
Without --trust-server-names, don't trust the metalink:file names:
use the basename of --input-metalink, and add a sequential number
(e.g. .#1, .#2, etc.).
Strip the directory from unsafe paths.
"""
############# File Definitions ###############################################
wrong_file = "Ouch!"
File1 = "Would you like some Tea?"
File1_lowPref = "Do not take this"
File2 = "This is gonna be good"
File2_lowPref = "Not this one too"
File3 = "A little more, please"
File3_lowPref = "That's just too much"
File4 = "Maybe a biscuit?"
File4_lowPref = "No, thanks"
File5 = "More Tea...?"
File5_lowPref = "I have to go..."
############# Metalink/XML ###################################################
Meta = Metalinkv3_XML()
# file_name: metalink:file "name" field
# save_name: metalink:file save name, if None the file is rejected
# content : metalink:file content
#
# size:
# True auto-compute size
# None no <size></size>
# any use this size
#
# hash_sha256:
# False no <verification></verification>
# True auto-compute sha256
# None no <hash></hash>
# any use this hash
#
# srv_file : metalink:url server file
# srv_content: metalink:url server file content, if None the file doesn't exist
# utype : metalink:url type
# location : metalink:url location (default 'no location field')
# preference : metalink:url preference (default 999999)
XmlName = "test.metalink"
Meta.xml (
# Metalink/XML file name
XmlName,
# file_name, save_name, content, size, hash_sha256
["~File1", None, File1, None, True,
# srv_file, srv_content, utype, location, preference
["wrong_file", wrong_file, "http", None, 35],
["404", None, "http", None, 40],
["File1_lowPref", File1_lowPref, "http", None, 25],
["File1", File1, "http", None, 30]],
["~/File2", None, File2, None, True,
["wrong_file", wrong_file, "http", None, 35],
["404", None, "http", None, 40],
["File2_lowPref", File2_lowPref, "http", None, 25],
["File2", File2, "http", None, 30]],
["dir/~File3", None, File3, None, True,
["wrong_file", wrong_file, "http", None, 35],
["404", None, "http", None, 40],
["File3_lowPref", File3_lowPref, "http", None, 25],
["File3", File3, "http", None, 30]],
["dir/File4~", "dir/File4~", File4, None, True,
["wrong_file", wrong_file, "http", None, 35],
["404", None, "http", None, 40],
["File4_lowPref", File4_lowPref, "http", None, 25],
["File4", File4, "http", None, 30]],
["dir/~/File5", "dir/~/File5", File5, None, True,
["wrong_file", wrong_file, "http", None, 35],
["404", None, "http", None, 40],
["File5_lowPref", File5_lowPref, "http", None, 25],
["File5", File5, "http", None, 30]],
)
Meta.print_meta ()
err = Meta.http_test (
"--trust-server-names " + \
"--input-metalink " + XmlName, 0
)
exit (err)

View File

@@ -0,0 +1,101 @@
#!/usr/bin/env python3
from sys import exit
from misc.metalinkv3_xml import Metalinkv3_XML
"""
This is to test if Metalink/XML forbids the home path and names
beginning with the ~ (tilde) character.
With --trust-server-names, trust the metalink:file names.
Without --trust-server-names, don't trust the metalink:file names:
use the basename of --input-metalink, and add a sequential number
(e.g. .#1, .#2, etc.).
Strip the directory from unsafe paths.
"""
############# File Definitions ###############################################
wrong_file = "Ouch!"
File1 = "Would you like some Tea?"
File1_lowPref = "Do not take this"
File2 = "This is gonna be good"
File2_lowPref = "Not this one too"
File3 = "A little more, please"
File3_lowPref = "That's just too much"
File4 = "Maybe a biscuit?"
File4_lowPref = "No, thanks"
File5 = "More Tea...?"
File5_lowPref = "I have to go..."
############# Metalink/XML ###################################################
Meta = Metalinkv3_XML()
# file_name: metalink:file "name" field
# save_name: metalink:file save name, if None the file is rejected
# content : metalink:file content
#
# size:
# True auto-compute size
# None no <size></size>
# any use this size
#
# hash_sha256:
# False no <verification></verification>
# True auto-compute sha256
# None no <hash></hash>
# any use this hash
#
# srv_file : metalink:url server file
# srv_content: metalink:url server file content, if None the file doesn't exist
# utype : metalink:url type
# location : metalink:url location (default 'no location field')
# preference : metalink:url preference (default 999999)
XmlName = "test.metalink"
Meta.xml (
# Metalink/XML file name
XmlName,
# file_name, save_name, content, size, hash_sha256
["~File1", None, File1, None, True,
# srv_file, srv_content, utype, location, preference
["wrong_file", wrong_file, "http", None, 35],
["404", None, "http", None, 40],
["File1_lowPref", File1_lowPref, "http", None, 25],
["File1", File1, "http", None, 30]],
["~/File2", None, File2, None, True,
["wrong_file", wrong_file, "http", None, 35],
["404", None, "http", None, 40],
["File2_lowPref", File2_lowPref, "http", None, 25],
["File2", File2, "http", None, 30]],
["dir/~File3", None, File3, None, True,
["wrong_file", wrong_file, "http", None, 35],
["404", None, "http", None, 40],
["File3_lowPref", File3_lowPref, "http", None, 25],
["File3", File3, "http", None, 30]],
["dir/File4~", XmlName + ".#1", File4, None, True,
["wrong_file", wrong_file, "http", None, 35],
["404", None, "http", None, 40],
["File4_lowPref", File4_lowPref, "http", None, 25],
["File4", File4, "http", None, 30]],
["dir/~/File5", XmlName + ".#2", File5, None, True,
["wrong_file", wrong_file, "http", None, 35],
["404", None, "http", None, 40],
["File5_lowPref", File5_lowPref, "http", None, 25],
["File5", File5, "http", None, 30]],
)
Meta.print_meta ()
err = Meta.http_test (
"--input-metalink " + XmlName, 0
)
exit (err)

View File

@@ -0,0 +1,102 @@
#!/usr/bin/env python3
from sys import exit
from misc.metalinkv3_xml import Metalinkv3_XML
"""
This is to test Metalink/XML home directory prefix support in Wget.
With --trust-server-names, trust the metalink:file names.
Without --trust-server-names, don't trust the metalink:file names:
use the basename of --input-metalink, and add a sequential number
(e.g. .#1, .#2, etc.).
Strip the directory from unsafe paths.
"""
############# File Definitions ###############################################
wrong_file = "Ouch!"
File1 = "Would you like some Tea?"
File1_lowPref = "Do not take this"
File2 = "This is gonna be good"
File2_lowPref = "Not this one too"
File3 = "A little more, please"
File3_lowPref = "That's just too much"
File4 = "Maybe a biscuit?"
File4_lowPref = "No, thanks"
File5 = "More Tea...?"
File5_lowPref = "I have to go..."
############# Metalink/XML ###################################################
Meta = Metalinkv3_XML()
# file_name: metalink:file "name" field
# save_name: metalink:file save name, if None the file is rejected
# content : metalink:file content
#
# size:
# True auto-compute size
# None no <size></size>
# any use this size
#
# hash_sha256:
# False no <verification></verification>
# True auto-compute sha256
# None no <hash></hash>
# any use this hash
#
# srv_file : metalink:url server file
# srv_content: metalink:url server file content, if None the file doesn't exist
# utype : metalink:url type
# location : metalink:url location (default 'no location field')
# preference : metalink:url preference (default 999999)
XmlName = "test.metalink"
Meta.xml (
# Metalink/XML file name
XmlName,
# file_name, save_name, content, size, hash_sha256
["subdir/File1", "File1", File1, None, True,
# srv_file, srv_content, utype, location, preference
["wrong_file", wrong_file, "http", None, 35],
["404", None, "http", None, 40],
["File1_lowPref", File1_lowPref, "http", None, 25],
["File1", File1, "http", None, 30]],
["/subdir/File2", None, File2, None, True,
["wrong_file", wrong_file, "http", None, 35],
["404", None, "http", None, 40],
["File2_lowPref", File2_lowPref, "http", None, 25],
["File2", File2, "http", None, 30]],
["~/subdir/File3", None, File3, None, True,
["wrong_file", wrong_file, "http", None, 35],
["404", None, "http", None, 40],
["File3_lowPref", File3_lowPref, "http", None, 25],
["File3", File3, "http", None, 30]],
["../subdir/File4", None, File4, None, True,
["wrong_file", wrong_file, "http", None, 35],
["404", None, "http", None, 40],
["File4_lowPref", File4_lowPref, "http", None, 25],
["File4", File4, "http", None, 30]],
["subdir/File5", "File5", File5, None, True,
["wrong_file", wrong_file, "http", None, 35],
["404", None, "http", None, 40],
["File5_lowPref", File5_lowPref, "http", None, 25],
["File5", File5, "http", None, 30]],
)
Meta.print_meta ()
err = Meta.http_test (
"--trust-server-names " + \
"--directory-prefix ~/dir " + \
"--input-metalink " + XmlName, 0
)
exit (err)

View File

@@ -0,0 +1,101 @@
#!/usr/bin/env python3
from sys import exit
from misc.metalinkv3_xml import Metalinkv3_XML
"""
This is to test Metalink/XML home directory prefix support in Wget.
With --trust-server-names, trust the metalink:file names.
Without --trust-server-names, don't trust the metalink:file names:
use the basename of --input-metalink, and add a sequential number
(e.g. .#1, .#2, etc.).
Strip the directory from unsafe paths.
"""
############# File Definitions ###############################################
wrong_file = "Ouch!"
File1 = "Would you like some Tea?"
File1_lowPref = "Do not take this"
File2 = "This is gonna be good"
File2_lowPref = "Not this one too"
File3 = "A little more, please"
File3_lowPref = "That's just too much"
File4 = "Maybe a biscuit?"
File4_lowPref = "No, thanks"
File5 = "More Tea...?"
File5_lowPref = "I have to go..."
############# Metalink/XML ###################################################
Meta = Metalinkv3_XML()
# file_name: metalink:file "name" field
# save_name: metalink:file save name, if None the file is rejected
# content : metalink:file content
#
# size:
# True auto-compute size
# None no <size></size>
# any use this size
#
# hash_sha256:
# False no <verification></verification>
# True auto-compute sha256
# None no <hash></hash>
# any use this hash
#
# srv_file : metalink:url server file
# srv_content: metalink:url server file content, if None the file doesn't exist
# utype : metalink:url type
# location : metalink:url location (default 'no location field')
# preference : metalink:url preference (default 999999)
XmlName = "test.metalink"
Meta.xml (
# Metalink/XML file name
XmlName,
# file_name, save_name, content, size, hash_sha256
["subdir/File1", XmlName + ".#1", File1, None, True,
# srv_file, srv_content, utype, location, preference
["wrong_file", wrong_file, "http", None, 35],
["404", None, "http", None, 40],
["File1_lowPref", File1_lowPref, "http", None, 25],
["File1", File1, "http", None, 30]],
["/subdir/File2", None, File2, None, True,
["wrong_file", wrong_file, "http", None, 35],
["404", None, "http", None, 40],
["File2_lowPref", File2_lowPref, "http", None, 25],
["File2", File2, "http", None, 30]],
["~/subdir/File3", None, File3, None, True,
["wrong_file", wrong_file, "http", None, 35],
["404", None, "http", None, 40],
["File3_lowPref", File3_lowPref, "http", None, 25],
["File3", File3, "http", None, 30]],
["../subdir/File4", None, File4, None, True,
["wrong_file", wrong_file, "http", None, 35],
["404", None, "http", None, 40],
["File4_lowPref", File4_lowPref, "http", None, 25],
["File4", File4, "http", None, 30]],
["subdir/File5", XmlName + ".#2", File5, None, True,
["wrong_file", wrong_file, "http", None, 35],
["404", None, "http", None, 40],
["File5_lowPref", File5_lowPref, "http", None, 25],
["File5", File5, "http", None, 30]],
)
Meta.print_meta ()
err = Meta.http_test (
"--directory-prefix ~/dir " + \
"--input-metalink " + XmlName, 0
)
exit (err)

View File

@@ -0,0 +1,100 @@
#!/usr/bin/env python3
from sys import exit
from misc.metalinkv3_xml import Metalinkv3_XML
"""
This is to test if Metalink/XML with no hashes generates a SIGSEGV.
With --trust-server-names, trust the metalink:file names.
Without --trust-server-names, don't trust the metalink:file names:
use the basename of --input-metalink, and add a sequential number
(e.g. .#1, .#2, etc.).
Strip the directory from unsafe paths.
"""
############# File Definitions ###############################################
wrong_file = "Ouch!"
File1 = "Would you like some Tea?"
File1_lowPref = "Do not take this"
File2 = "This is gonna be good"
File2_lowPref = "Not this one too"
File3 = "A little more, please"
File3_lowPref = "That's just too much"
File4 = "Maybe a biscuit?"
File4_lowPref = "No, thanks"
File5 = "More Tea...?"
File5_lowPref = "I have to go..."
############# Metalink/XML ###################################################
Meta = Metalinkv3_XML()
# file_name: metalink:file "name" field
# save_name: metalink:file save name, if None the file is rejected
# content : metalink:file content
#
# size:
# True auto-compute size
# None no <size></size>
# any use this size
#
# hash_sha256:
# False no <verification></verification>
# True auto-compute sha256
# None no <hash></hash>
# any use this hash
#
# srv_file : metalink:url server file
# srv_content: metalink:url server file content, if None the file doesn't exist
# utype : metalink:url type (http, ftp, etc.)
# location : metalink:url location (default 'no location field')
# preference : metalink:url preference (default 999999)
XmlName = "test.metalink"
Meta.xml (
# Metalink/XML file name
XmlName,
# file_name, save_name, content, size, hash_sha256
["File1", None, File1, None, False,
# srv_file, srv_content, utype, location, preference
["wrong_file", wrong_file, "http", None, 35],
["404", None, "http", None, 40],
["File1_lowPref", File1_lowPref, "http", None, 25],
["File1", File1, "http", None, 30]],
["File2", XmlName + ".#2", File2, None, True,
["wrong_file", wrong_file, "http", None, 35],
["404", None, "http", None, 40],
["File2_lowPref", File2_lowPref, "http", None, 25],
["File2", File2, "http", None, 30]],
["File3", None, File3, None, None,
["wrong_file", wrong_file, "http", None, 35],
["404", None, "http", None, 40],
["File3_lowPref", File3_lowPref, "http", None, 25],
["File3", File3, "http", None, 30]],
["File4", XmlName + ".#4", File4, None, True,
["wrong_file", wrong_file, "http", None, 35],
["404", None, "http", None, 40],
["File4_lowPref", File4_lowPref, "http", None, 25],
["File4", File4, "http", None, 30]],
["File5", None, File5, None, "",
["wrong_file", wrong_file, "http", None, 35],
["404", None, "http", None, 40],
["File5_lowPref", File5_lowPref, "http", None, 25],
["File5", File5, "http", None, 30]],
)
Meta.print_meta ()
err = Meta.http_test (
"--input-metalink " + XmlName, 1
)
exit (err)

View File

@@ -0,0 +1,100 @@
#!/usr/bin/env python3
from sys import exit
from misc.metalinkv3_xml import Metalinkv3_XML
"""
This is to test Metalink/XML with unknown url types.
With --trust-server-names, trust the metalink:file names.
Without --trust-server-names, don't trust the metalink:file names:
use the basename of --input-metalink, and add a sequential number
(e.g. .#1, .#2, etc.).
Strip the directory from unsafe paths.
"""
############# File Definitions ###############################################
wrong_file = "Ouch!"
File1 = "Would you like some Tea?"
File1_lowPref = "Do not take this"
File2 = "This is gonna be good"
File2_lowPref = "Not this one too"
File3 = "A little more, please"
File3_lowPref = "That's just too much"
File4 = "Maybe a biscuit?"
File4_lowPref = "No, thanks"
File5 = "More Tea...?"
File5_lowPref = "I have to go..."
############# Metalink/XML ###################################################
Meta = Metalinkv3_XML()
# file_name: metalink:file "name" field
# save_name: metalink:file save name, if None the file is rejected
# content : metalink:file content
#
# size:
# True auto-compute size
# None no <size></size>
# any use this size
#
# hash_sha256:
# False no <verification></verification>
# True auto-compute sha256
# None no <hash></hash>
# any use this hash
#
# srv_file : metalink:url server file
# srv_content: metalink:url server file content, if None the file doesn't exist
# utype : metalink:url type (http, ftp, etc.)
# location : metalink:url location (default 'no location field')
# preference : metalink:url preference (default 999999)
XmlName = "test.metalink"
Meta.xml (
# Metalink/XML file name
XmlName,
# file_name, save_name, content, size, hash_sha256
["File1", XmlName + ".#1", File1, None, True,
# srv_file, srv_content, utype, location, preference
["wrong_file", wrong_file, "http", None, 35],
["404", None, "http", None, 40],
["File1_lowPref", File1_lowPref, "http", None, 25],
["File1", File1, "http", None, 30]],
["File2", None, File2, None, True,
["wrong_file", wrong_file, "unknown", None, 35],
["404", None, "unknown", None, 40],
["File2_lowPref", File2_lowPref, "unknown", None, 25],
["File2", File2, "unknown", None, 30]],
["File3", XmlName + ".#3", File3, None, True,
["wrong_file", wrong_file, "http", None, 35],
["404", None, "http", None, 40],
["File3_lowPref", File3_lowPref, "http", None, 25],
["File3", File3, "http", None, 30]],
["File4", XmlName + ".#4", File4, None, True,
["wrong_file", wrong_file, "unknown", None, 35],
["404", None, "unknown", None, 40],
["File4_lowPref", File4_lowPref, "unknown", None, 25],
["File4", File4, "http", None, 30]],
["File5", XmlName + ".#5", File5, None, True,
["wrong_file", wrong_file, "http", None, 35],
["404", None, "http", None, 40],
["File5_lowPref", File5_lowPref, "http", None, 25],
["File5", File5, "http", None, 30]],
)
Meta.print_meta ()
err = Meta.http_test (
"--input-metalink " + XmlName, 1
)
exit (err)

View File

@@ -0,0 +1,102 @@
#!/usr/bin/env python3
from sys import exit
from misc.metalinkv3_xml import Metalinkv3_XML
"""
This is to test Metalink/XML directory prefix support in Wget.
With --trust-server-names, trust the metalink:file names.
Without --trust-server-names, don't trust the metalink:file names:
use the basename of --input-metalink, and add a sequential number
(e.g. .#1, .#2, etc.).
Strip the directory from unsafe paths.
"""
############# File Definitions ###############################################
wrong_file = "Ouch!"
File1 = "Would you like some Tea?"
File1_lowPref = "Do not take this"
File2 = "This is gonna be good"
File2_lowPref = "Not this one too"
File3 = "A little more, please"
File3_lowPref = "That's just too much"
File4 = "Maybe a biscuit?"
File4_lowPref = "No, thanks"
File5 = "More Tea...?"
File5_lowPref = "I have to go..."
############# Metalink/XML ###################################################
Meta = Metalinkv3_XML()
# file_name: metalink:file "name" field
# save_name: metalink:file save name, if None the file is rejected
# content : metalink:file content
#
# size:
# True auto-compute size
# None no <size></size>
# any use this size
#
# hash_sha256:
# False no <verification></verification>
# True auto-compute sha256
# None no <hash></hash>
# any use this hash
#
# srv_file : metalink:url server file
# srv_content: metalink:url server file content, if None the file doesn't exist
# utype : metalink:url type
# location : metalink:url location (default 'no location field')
# preference : metalink:url preference (default 999999)
XmlName = "test.metalink"
Meta.xml (
# Metalink/XML file name
XmlName,
# file_name, save_name, content, size, hash_sha256
["subdir/File1", "dir/" + "subdir/File1", File1, None, True,
# srv_file, srv_content, utype, location, preference
["wrong_file", wrong_file, "http", None, 35],
["404", None, "http", None, 40],
["File1_lowPref", File1_lowPref, "http", None, 25],
["File1", File1, "http", None, 30]],
["/subdir/File2", None, File2, None, True,
["wrong_file", wrong_file, "http", None, 35],
["404", None, "http", None, 40],
["File2_lowPref", File2_lowPref, "http", None, 25],
["File2", File2, "http", None, 30]],
["~/subdir/File3", None, File3, None, True,
["wrong_file", wrong_file, "http", None, 35],
["404", None, "http", None, 40],
["File3_lowPref", File3_lowPref, "http", None, 25],
["File3", File3, "http", None, 30]],
["../subdir/File4", None, File4, None, True,
["wrong_file", wrong_file, "http", None, 35],
["404", None, "http", None, 40],
["File4_lowPref", File4_lowPref, "http", None, 25],
["File4", File4, "http", None, 30]],
["subdir/File5", "dir/" + "subdir/File5", File5, None, True,
["wrong_file", wrong_file, "http", None, 35],
["404", None, "http", None, 40],
["File5_lowPref", File5_lowPref, "http", None, 25],
["File5", File5, "http", None, 30]],
)
Meta.print_meta ()
err = Meta.http_test (
"--trust-server-names " + \
"--directory-prefix dir " + \
"--input-metalink " + XmlName, 0
)
exit (err)

Some files were not shown because too many files have changed in this diff Show More