-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
occ command interprets leading dash values as keys #26109
Comments
cc @nextcloud/server-triage |
It is also a problem with certificates that begins with php occ config:app:set user_saml idp-x509cert --value " -----BEGIN CERTIFICATE----- ......" The only workaround I found is to prepend a space before the argument like in my example. I the case of OP, this would give something like |
Anyone who uses "occ maintenance:install" with generated passwords that might have "-" will easily run into this bug, as I have. The workaround is to generate passwords that don't begin with a dash, so I removed dashes from my password-generating code. I'm using: |
this is normal/common behaviour. leading dashes have to be escaped. |
Escaping is done via slash? |
yes, for example: $ ack '\--headless' --type=php lib/private/
lib/private/Preview/Office.php
56: $defaultParameters = ' -env:UserInstallation=file://' . escapeshellarg($tmpDir . '/owncloud-' . \OC_Util::getInstanceId() . '/') . ' --headless --nologo --nofirststartwizard --invisible --norestore --convert-to png --outdir ';
$ ack '--headless' --type=php lib/private/
Unknown option: headless
ack: Invalid option on command line |
In the example you gave, the argument --headless needs to be escaped because ack does not know if it should expect an option or a program argument at that point, since both are expected there. Another common mechanism is to put "--" in the command line to indicate that any arguments following the dashes are not option names but program arguments. In cases of options that expect arguments, the expected behavior is to allow option arguments with leading dashes, without escaping. Examples:
"man grep" even documents for the -e option that: This option can be used to protect a pattern beginning with “-”. |
The solution is to use the --admin-pass="password" version of the options, as documented in occ help maintenance:install
With this usage, there is no problem with leading dashes in passwords or any other option arguments. However, the manual incorrectly uses the defective version of the options:
I suggest not changing the code, but changing the manual to use the --option=value version of the command line. |
Ah wow, that actually makes sense, as usually the long from of CLI options uses equal sign for the value while short forms use spaces, even that parsers are usually relaxed about that. Makes sense to adjust the docs then and keep it as common/known limitation of space-separated key-value pairs for CLI in general. |
The `--option=value` version of passing options to the `occ maintenance:install` command is now used in the documentation, instead of the `--option value` variant. This solves issues with leading dashes in values, especially passwords. It also matches the `occ help maintenance:install` output. Solves: - nextcloud/server#26109 - #8190 Furthermore values are now single quoted, which is important to avoid variable expansion and special treatment of the backlash character in random passwords, and a doubled space was removed. Signed-off-by: MichaIng <[email protected]>
PR up for the documentation change: nextcloud/documentation#9571 If I'm not mistaken, the error output of the |
Hmm, generally in case of an argument error, the command is shown with # ncc config:app:get -J
The "-J" option does not exist.
config:app:get [--output [OUTPUT]] [--default-value [DEFAULT-VALUE]] [--] <app> <name>
# ncc help config:app:get
Description:
Get an app config value
Usage:
config:app:get [options] [--] <app> <name>
Arguments:
app Name of the app
name Name of the config to get
Options:
--output[=OUTPUT] Output format (plain, json or json_pretty, default is plain) [default: "plain"]
--default-value[=DEFAULT-VALUE] If no default value is set and the config does not exist, the command will exit with 1
-h, --help Display this help message
-q, --quiet Do not output any message
-V, --version Display this application version
--ansi Force ANSI output
--no-ansi Disable ANSI output
-n, --no-interaction Do not ask any interactive question
--no-warnings Skip global warnings, show command output only
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug Funnily, this particular error is exactly caused by the printed syntax, while with I just couldn't find it in Nextcloud code, so I guess this is part of Symfony console command component? At least the |
The `--option=value` version of passing options to the `occ maintenance:install` command is now used in the documentation, instead of the `--option value` variant. This solves issues with leading dashes in values, especially passwords. It also matches the `occ help maintenance:install` output. Solves: - nextcloud/server#26109 - #8190 Furthermore values are now single quoted, which is important to avoid variable expansion and special treatment of the backlash character in random passwords, and a doubled space was removed. Signed-off-by: MichaIng <[email protected]>
The `--option=value` version of passing options to the `occ maintenance:install` command is now used in the documentation, instead of the `--option value` variant. This solves issues with leading dashes in values, especially passwords. It also matches the `occ help maintenance:install` output. Solves: - nextcloud/server#26109 - #8190 Furthermore values are now single quoted, which is important to avoid variable expansion and special treatment of the backlash character in random passwords, and a doubled space was removed. Signed-off-by: MichaIng <[email protected]>
The `--option=value` version of passing options to the `occ maintenance:install` command is now used in the documentation, instead of the `--option value` variant. This solves issues with leading dashes in values, especially passwords. It also matches the `occ help maintenance:install` output. Solves: - nextcloud/server#26109 - #8190 Furthermore values are now single quoted, which is important to avoid variable expansion and special treatment of the backlash character in random passwords, and a doubled space was removed. Signed-off-by: MichaIng <[email protected]>
Reopened as of above inconsistency with |
How to use GitHub
Steps to reproduce
Expected behaviour
The input argument that follows
--admin-pass
(or any other key that requires a value) is interpreted as value and not as another key.Actual behaviour
Or if
--database-name
has the leading dash, as it does not require a value:Server configuration
Operating system: irrelevant
Web server: irrelevant
Database: MariaDB v10.3+
PHP version: 7.0+
Nextcloud version: 21.0.0
Updated from an older Nextcloud/ownCloud or fresh install: fresh
Where did you install Nextcloud from: https://download.nextcloud.com/server/releases/latest.tar.bz2
Investigations
getOption
function definition, or where exactly the input is parsed and the error generated, so I'm not sure if this can be easily accomplished or not.They get a
VALUE_REQUIRED
orVALUE_OPTIONAL
flag, which probably can be used to decide whether to take the next argument as value for that option or as new key.--database-pass
value is marked as optional which does not make much sense to me: Either the key is given, then a value must be present, or the key is not given, e.g. in case of SQLite where no password is required, or if an interactive input is wanted. Or what is the purpose when the key is given but no value?Another thing I recognised which is slightly related: https://github.com/nextcloud/server/blob/master/core/Command/Maintenance/Install.php#L130-L146
$dbPass = $input->getOption('database-pass');
is used to get the password.($input->hasParameterOption('--database-pass'))
, hence if a value is given, or if the key itself is given?The text was updated successfully, but these errors were encountered: