Check_mk_active-mailboxes Check wrongly escapes passwords starting with "!"

CMK version: CMK Raw 2.2.0p21
OS version: Debian

Error message: Some mailboxes are not available {INBOX}

Using a password that starts with an exclamation mark like “!password” will result in a wrong escaping of the commandline call to the active mailboxes check. Due to that, the login fails.

Output of “cmk --debug -vvn hostname”:

 ./check_mailboxes  --fetch-protocol=IMAP --fetch-server=hostname --fetch-tls --fetch-port=XXX --fetch-username=redacted@domain '--fetch-password=\!password' --warn-age-oldest=30 --crit-age-oldest=21600 --debug --mailbox INBOX -vvvv
DEBUG:check_mailboxes:use protocol for fetching: 'IMAP'
INFO:check_mailboxes:connect..
DEBUG:check_mailboxes:_connect_fetcher: 'IMAP' 'hostname' XXX True
  49:22.33 imaplib version 2.58
  49:22.33 new IMAP4 connection, tag=b'HEFA'
  49:22.37 < b'* OK The Microsoft Exchange IMAP4 service is ready.'
  49:22.37 > b'HEFA0 CAPABILITY'
  49:22.37 < b'* CAPABILITY IMAP4 IMAP4rev1 AUTH=PLAIN AUTH=NTLM AUTH=GSSAPI SASL-IR UIDPLUS MOVE ID UNSELECT CHILDREN IDLE NAMESPACE LITERAL+'
  49:22.37 < b'HEFA0 OK CAPABILITY completed.'
  49:22.37 CAPABILITIES: ('IMAP4', 'IMAP4REV1', 'AUTH=PLAIN', 'AUTH=NTLM', 'AUTH=GSSAPI', 'SASL-IR', 'UIDPLUS', 'MOVE', 'ID', 'UNSELECT', 'CHILDREN', 'IDLE', 'NAMESPACE', 'LITERAL+')
  49:22.37 > b'HEFA1 LOGIN redacted@domain "\\\\!password"'
  49:22.41 < b'HEFA1 NO LOGIN failed.'
  49:22.41 NO response: b'LOGIN failed.'
Traceback (most recent call last):
  File "/omd/sites/site/lib/python3/cmk/utils/mailbox.py", line 336, in _connect_fetcher
    _connect_imap()
  File "/omd/sites/site/lib/python3/cmk/utils/mailbox.py", line 318, in _connect_imap
    verified_result(connection.login(self._args.fetch_username, self._args.fetch_password))
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/omd/sites/site/lib/python3.11/imaplib.py", line 612, in login
    raise self.error(dat[-1])
imaplib.IMAP4.error: b'LOGIN failed.'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/omd/versions/2.2.0p21.cre/lib/nagios/plugins/./check_mailboxes", line 169, in <module>
    active_check_main(create_argument_parser(), check_mailboxes)
  File "/omd/sites/site/lib/python3/cmk/utils/mailbox.py", line 944, in active_check_main
    exitcode, status, perfdata = _active_check_main_core(argument_parser, check_fn, sys.argv[1:])
                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/omd/sites/site/lib/python3/cmk/utils/mailbox.py", line 895, in _active_check_main_core
    return check_fn(args)
           ^^^^^^^^^^^^^^
  File "/opt/omd/versions/2.2.0p21.cre/lib/nagios/plugins/./check_mailboxes", line 88, in check_mailboxes
    mailbox.connect()
  File "/omd/sites/site/lib/python3/cmk/utils/mailbox.py", line 297, in connect
    self._connect_fetcher()
  File "/omd/sites/site/lib/python3/cmk/utils/mailbox.py", line 344, in _connect_fetcher
    raise ConnectError(
cmk.utils.mailbox.ConnectError: Failed to connect to fetching server exc01: b'LOGIN failed.'
1 Like

Just checked, can confirm

We have reproduced this internally as well and already opened a ticket to fix this.

Thank you for your report @randomnick773. We fixed the display of service check commands in the UI to showing unescaped exclamation marks. You can find the change in Werk #16999. It will be included in the upcoming 2.2.0p30