fr4nk5ch31n3r / gtransfer

GridFTP transfers made easy!
GNU General Public License v3.0
7 stars 3 forks source link

gtransfer v0.2.2: problem with halias #27

Closed fr4nk5ch31n3r closed 11 years ago

fr4nk5ch31n3r commented 11 years ago

Problem

A system installed gtransfer does not work as expected. The source URL is erroneously expanded to a weird file:// URL. Example:

$ gt -s gsiftp://host1.domain.tld:2811/~/bigfile -d gsiftp://hos2.domain.tld:2812/~/
.
error: Unable to list url file:////host1.domain.tld:2811/~/bigfile:
[globus_l_gass_copy_stat_file]: file not found in dir: /host1.domain.tld:2811/~/bigfile

ERROR: "globus-url-copy" failed. Please see "tgftp_transfer_21444__step_0.log" for details.
[...]

Cause

gtransfer uses halias to check if the source or destination URLs use host aliases. A host alias mustn't contain any slashes, hence everything after and including the first / of a URL is removed and fed to halias for a possible expansion - for a gsiftp:// URL, the assumed alias is gsiftp:.

But two if clauses in halias use too lax conditions. The function halias/dealias() is affected. This function makes two calls to the library function alias/dealias(), first to check if any user aliases match and if not to check if any system aliases match.

If e.g. there is no user aliases directory - which is the default - alias/dealias() will return 1 and the variable _dealiasedString is empty. Because of that:

  1. the following if clause will be true (as an empty string differs from gsiftp:)
  2. the assumed dealiased string (which is actually empty) is printed to stdout
  3. the call to halias/dealias() will return 0 early before checking if any system aliases match.

Due to this issue gtransfer assumes gsiftp: expands to an empty string and a gsiftp:// URL like gsiftp://host1.domain.tld:2811/~/bigfile is first transformed to //host1.domain.tld:2811/~/bigfile and as it starts with a /, gtransfer adds file:// to it, as it assumes it is a path to a file and hence makes sure globus-url-copy will use file:// URLs for the transfer.

Workaround

Make sure to create $HOME/.gtransfer/aliases (either as file or as directory).

Solution

The two if clauses should also check the return value of alias/dealias(). This makes sure that halias/dealias() will print the input string instead of an empty string if an aliases directory (or file) is missing. If input string and dealiased string are identical, the input string is not a host alias and no expansion happens.