[Bug]: nextcloud client failed to parse netrc
⚠️ Before submitting, please verify the following: ⚠️
- [X] This is a bug, not a question or a configuration issue.
- [X] This issue is not already reported on Github (I've searched it).
- [X] Nextcloud Server and Desktop Client are up to date. See Server Maintenance and Release Schedule and Desktop Releases for supported versions.
- [X] I agree to follow Nextcloud's Code of Conduct
Bug description
After upgrading to 3.14.0, nextcloud client commandline (nextcloudcmd) failed to parse netrc credential with -n option. As a result, nextcloud server prompt for credential.
On the other hand, using --user and --password options work.
Steps to reproduce
- Create the file ~/.netrc as:
default
login admin
password mypassword
- Run nextcloudcmd from bash.
nextcloudcmd -n --path /Documents /home/user/Nextcloud/Documents/ https://myserver.com
- nextcloudcmd failed to parse netrc and prompt for credentials.
09-20 17:27:56:193 [ debug default ] [ OCC::NetrcParser::parse ]: error fetching value for "default\nlogin admin\npassword mypassword\n"
Please enter username:
Expected behavior
nextcloudcmd should parsed netrc.
Which files are affected by this bug
netrc
Operating system
Linux
Which version of the operating system you are running.
NixOS 24.11.20240919.c04d565 (Vicuna) x86_64
Package
Distro package manager
Nextcloud Server version
29.0.4
Nextcloud Desktop Client version
3.14.0
Is this bug present after an update or on a fresh install?
Fresh desktop client install
Are you using the Nextcloud Server Encryption module?
Encryption is Disabled
Are you using an external user-backend?
- [X] Default internal user-backend
- [ ] LDAP/ Active Directory
- [ ] SSO - SAML
- [ ] Other
Nextcloud Server logs
No response
Additional info
No response
Same here, on:
- Linux, Ubuntu 22.04.5 LTS
- package version including nextcloudcmd is nextcloud-client 3.14.0-20240916.085658.d8fcb9273-1.0~jammy1
- nextcloud server 29.0.6
I have evidence that it synced normally before the latest update of nextcloudcmd, i.e. before 2024-09-16
I also had it working before, and now it is throwing an error. I'm using a NixOS package.
Nextcloud version 3.14.0
Git revision d8fcb9273729c0e70f99d6f42ed7185c2bb69779
Using Qt 6.7.2, built against Qt 6.7.2
Using 'OpenSSL 3.0.14 4 Jun 2024'
Running on NixOS 24.11 (Vicuna), x86_64
same here
Nextcloud version 3.14.1
Git revision 8b92fc33a289bf4fc7bc7cdd68d25a9ed1ae1782
Using Qt 6.7.2, built against Qt 6.7.2
Using 'OpenSSL 3.0.14 4 Jun 2024'
Running on Ubuntu 22.04.5 LTS, x86_64
Same here, running FreeBSD:
Nextcloud version 3.14.1daily
Git revision 8b92fc33a289bf4fc7bc7cdd68d25a9ed1ae1782
Using Qt 6.7.3, built against Qt 6.7.3
Using 'OpenSSL 3.0.13 30 Jan 2024'
Running on FreeBSD 14.1-RELEASE-p5, x86_6
I, too, have the same issue on FreeBSD 14.1-RELEASE-p5, following a Nextcloud upgrade.
Do we have yet a solution for this Problem? Since that day my backup is not working! :-(
Machine is Linux Ubuntu 22.04 - Nextcloud 3.14.3-20241107.180900 Server version 29.08
@Rudiberto as temporary workaround, I am using something like "nextcloudcmd -u user -p $(cat $passwordfile)".
[@Rudiberto] as temporary workaround, I am using something like "nextcloudcmd -u user -p $(cat $passwordfile)".
Thank You, very much. I will test that. I'm passing temporarily user and password inside my script. Guess it makes not that much difference to your solution. Hopefully it will work again soon. It's never a good sign, when something so essential is not working properly.
const auto sanitisedTargetUrl = options.target_url.endsWith('/') || options.target_url.endsWith('\\')
? options.target_url.chopped(1)
: options.target_url;
QUrl hostUrl = QUrl::fromUserInput(sanitisedTargetUrl);
This is my main suspect in the Source code. The function seems to catch a misconfiguration, but is probably implemented incorrectly, because when parsing the '.netrc' it becomes an '\n' filled in after the password(s) for each end of line.
Formerly it was done this way:
QUrl hostUrl = QUrl::fromUserInput((options.target_url.endsWith(QLatin1Char('/')) || options.target_url.endsWith(QLatin1Char('\\'))) ? options.target_url.chopped(1) : options.target_url);
Bump I also encountered the same problem, using nextcloudcmd version : 3.14.3
@Rudiberto as temporary workaround, I am using something like "nextcloudcmd -u user -p $(cat $passwordfile)".
Just a note that this will protect the password from being logged in shell history and such, but password will still be visible in clear text for anyone who can list the process tree on the machine (and it might still be logged in some audit logs). Maybe not a problem for everyone, but something to keep in mind.
As noted in my PR I think the problem is the tokenizing of the netrc content where it expects every field to be separated by " \n\t". I haven't tested but a "netrc-file" formated like this might actually work (space before newline and tab after):
machine
<host>
login
<username>
password
<userpassword>
I have tried different variations of my ~/.netrc file with what @fredrik-eriksson suggested, but still no luck so far.