glpi-project / glpi

GLPI is a Free Asset and IT Management Software package, Data center management, ITIL Service Desk, licenses tracking and software auditing.
https://glpi-project.org
GNU General Public License v3.0
4.24k stars 1.29k forks source link

9.5.2 (nightly) Empty IN are not allowed in dbmysqliterator.class.php #8275

Closed 0xdeadbit closed 3 years ago

0xdeadbit commented 3 years ago

Hello,

we have an error in a updated glpi (9.4.6 to 9.5.2) when collecting mails and when enabling debug and going into a ticket debug (mailcollector does not work either and is stalling adding tickets) an error is shown :

webpage : http://xxx/glpi/ajax/common.tabs.php?_target=/glpi/front/ticket.form.php&_itemtype=Ticket&_glpi_tab=-2&id=1755&

image

GLPI is update to nightly to check if bug was fixed.

Log shows :

[2020-11-14 15:32:41] glpiphplog.CRITICAL: *** Uncaught Exception RuntimeException: Empty IN are not allowed in /usr/share/glpi/inc/dbmysqliterator.class.php at line 558 Backtrace : inc/dbmysqliterator.class.php:530 DBmysqlIterator->analyseCriterion() inc/dbmysqliterator.class.php:289 DBmysqlIterator->analyseCrit() inc/dbmysqliterator.class.php:94 DBmysqlIterator->buildQuery() inc/dbmysql.class.php:857 DBmysqlIterator->execute() ...otificationtargetcommonitilobject.class.php:678 DBmysql->request() inc/notificationtarget.class.php:514 NotificationTargetCommonITILObject->addAdditionnalUserInfo() ...otificationtargetcommonitilobject.class.php:196 NotificationTarget->addToRecipientsList() ...otificationtargetcommonitilobject.class.php:320 NotificationTargetCommonITILObject->addLinkedUserByType() inc/notificationtarget.class.php:1145 NotificationTargetCommonITILObject->addItemAuthor() inc/notificationeventabstract.class.php:92 NotificationTarget->addForTarget() inc/notificationevent.class.php:184 NotificationEventAbstract::raise() inc/notificationevent.class.php:236 NotificationEvent::raiseEvent() inc/ticket.class.php:6567 NotificationEvent::debugEvent() inc/commonglpi.class.php:1243 Ticket->showDebug() inc/commonglpi.class.php:611 CommonGLPI->showDebugInfo() ajax/common.tabs.php:92 CommonGLPI::displayStandardTab()

When manually lauching email collector :

[2020-11-14 15:59:38] glpiphplog.NOTICE: *** PHP Notice (8): Undefined index: users_id in /usr/share/glpi/inc/mailcollector.class.php at line 783 Backtrace : front/mailcollector.form.php:77 MailCollector->collect()

[2020-11-14 15:59:38] glpiphplog.NOTICE: *** PHP Notice (8): Undefined index: _users_id_requester_notif in /usr/share/glpi/inc/mailcollector.class.php at line 788 Backtrace : front/mailcollector.form.php:77 MailCollector->collect()

[2020-11-14 15:59:38] glpiphplog.NOTICE: *** PHP Notice (8): Trying to access array offset on value of type null in /usr/share/glpi/inc/mailcollector.class.php at line 788 Backtrace : front/mailcollector.form.php:77 MailCollector->collect()

[2020-11-14 15:59:38] glpiphplog.NOTICE: *** PHP Notice (8): Trying to access array offset on value of type null in /usr/share/glpi/inc/mailcollector.class.php at line 788 Backtrace : front/mailcollector.form.php:77 MailCollector->collect()

New tickets are not collected and gives error/refused :

image

GLPI setup :

[code]

GLPI 9.5.2 (/glpi => /usr/share/glpi) Installation mode: RPM

Server

Operating system: Linux cre-vdsit2 3.10.0-1127.19.1.el7.x86_64 #1 SMP Tue Aug 25 17:23:54 UTC 2020 x86_64 PHP 7.4.12 apache2handler (Core, PDO, Phar, Reflection, SPL, SimpleXML, Zend OPcache, apache2handler, apcu, bcmath, bz2, calendar, ctype, curl, date, dom, exif, fileinfo, filter, ftp, gd, gettext, gmp, hash, iconv, imap, intl, json, ldap, libxml, mbstring, mysqli, mysqlnd, openssl, pcre, pdo_mysql, pdo_sqlite, posix, session, shmop, sockets, sodium, sqlite3, standard, sysvmsg, sysvsem, sysvshm, tidy, tokenizer, xml, xmlreader, xmlrpc, xmlwriter, xsl, zip, zlib) Setup: max_execution_time="30" memory_limit="128M" post_max_size="8M" safe_mode="" session.save_handler="files" upload_max_filesize="2M" Software: Apache/2.4.6 (CentOS) PHP/7.4.12 () Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36 Server Software: MariaDB Server Server Version: 10.4.16-MariaDB Server SQL Mode: Parameters: glpi@127.0.0.1/glpi Host info: 127.0.0.1 via TCP/IP

PHP version is at least 7.2.0 - Perfect!PHP version is at least 7.2.0 - Perfect! Sessions support is available - Perfect!Sessions support is available - Perfect! Allocated memory > 64 Mio - Perfect!Allocated memory > 64 Mio - Perfect! mysqli extension is installedmysqli extension is installed ctype extension is installedctype extension is installed fileinfo extension is installedfileinfo extension is installed json extension is installedjson extension is installed mbstring extension is installedmbstring extension is installed iconv extension is installediconv extension is installed zlib extension is installedzlib extension is installed curl extension is installedcurl extension is installed gd extension is installedgd extension is installed simplexml extension is installedsimplexml extension is installed intl extension is installedintl extension is installed ldap extension is installedldap extension is installed apcu extension is installedapcu extension is installed Zend OPcache extension is installedZend OPcache extension is installed xmlrpc extension is installedxmlrpc extension is installed CAS extension is installedCAS extension is installed exif extension is installedexif extension is installed zip extension is installedzip extension is installed bz2 extension is installedbz2 extension is installed sodium extension is installedsodium extension is installed Database version seems correct (10.4.16) - Perfect!Database version seems correct (10.4.16) - Perfect! Timezones seems loaded in databaseTimezones seems loaded in database The log file has been created successfully.The log file has been created successfully. Write access to /etc/glpi has been validated.Write access to /etc/glpi has been validated. Write access to /var/lib/glpi/files has been validated.Write access to /var/lib/glpi/files has been validated. Write access to /var/lib/glpi/files/_dumps has been validated.Write access to /var/lib/glpi/files/_dumps has been validated. Write access to /var/lib/glpi/files/_sessions has been validated.Write access to /var/lib/glpi/files/_sessions has been validated. Write access to /var/lib/glpi/files/_cron has been validated.Write access to /var/lib/glpi/files/_cron has been validated. Write access to /var/lib/glpi/files/_graphs has been validated.Write access to /var/lib/glpi/files/_graphs has been validated. Write access to /var/lib/glpi/files/_lock has been validated.Write access to /var/lib/glpi/files/_lock has been validated. Write access to /var/lib/glpi/files/_plugins has been validated.Write access to /var/lib/glpi/files/_plugins has been validated. Write access to /var/lib/glpi/files/_tmp has been validated.Write access to /var/lib/glpi/files/_tmp has been validated. Write access to /var/lib/glpi/files/_cache has been validated.Write access to /var/lib/glpi/files/_cache has been validated. Write access to /var/lib/glpi/files/_rss has been validated.Write access to /var/lib/glpi/files/_rss has been validated. Write access to /var/lib/glpi/files/_uploads has been validated.Write access to /var/lib/glpi/files/_uploads has been validated. Write access to /var/lib/glpi/files/_pictures has been validated.Write access to /var/lib/glpi/files/_pictures has been validated. Write access to /usr/share/glpi/marketplace has been validated.Write access to /usr/share/glpi/marketplace has been validated. For security reasons, SELinux mode should be Enforcing.For security reasons, SELinux mode should be Enforcing.

GLPI constants

GLPI_ROOT: /usr/share/glpi GLPI_CONFIG_DIR: /etc/glpi GLPI_VAR_DIR: /var/lib/glpi/files GLPI_LOG_DIR: /var/log/glpi GLPI_HTMLAWED: /usr/share/php/htmLawed/htmLawed.php GLPI_FONT_FREESANS: /usr/share/fonts/gnu-free/FreeSans.ttf GLPI_SYSTEM_CRON: 1 GLPI_INSTALL_MODE: RPM GLPI_MARKETPLACE_DIR: /usr/share/glpi/marketplace GLPI_USE_CSRF_CHECK: 1 GLPI_CSRF_EXPIRES: 7200 GLPI_CSRF_MAX_TOKENS: 100 GLPI_TELEMETRY_URI: https://telemetry.glpi-project.org GLPI_NETWORK_MAIL: glpi@teclib.com GLPI_NETWORK_SERVICES: https://services.glpi-network.com GLPI_MARKETPLACE_PRERELEASES: GLPI_USER_AGENT_EXTRA_COMMENTS: GLPI_AJAX_DASHBOARD: 1 GLPI_CALDAV_IMPORT_STATE: 0 GLPI_DEMO_MODE: 0 GLPI_FORCE_EMPTY_SQL_MODE: 1 GLPI_DOC_DIR: /var/lib/glpi/files GLPI_CACHE_DIR: /var/lib/glpi/files/_cache GLPI_CRON_DIR: /var/lib/glpi/files/_cron GLPI_DUMP_DIR: /var/lib/glpi/files/_dumps GLPI_GRAPH_DIR: /var/lib/glpi/files/_graphs GLPI_LOCAL_I18N_DIR: /var/lib/glpi/files/_locales GLPI_LOCK_DIR: /var/lib/glpi/files/_lock GLPI_PICTURE_DIR: /var/lib/glpi/files/_pictures GLPI_PLUGIN_DOC_DIR: /var/lib/glpi/files/_plugins GLPI_RSS_DIR: /var/lib/glpi/files/_rss GLPI_SESSION_DIR: /var/lib/glpi/files/_sessions GLPI_TMP_DIR: /var/lib/glpi/files/_tmp GLPI_UPLOAD_DIR: /var/lib/glpi/files/_uploads GLPI_NETWORK_REGISTRATION_API_URL: https://services.glpi-network.com/api/registration/ GLPI_MARKETPLACE_PLUGINS_API_URI: https://services.glpi-network.com/api/glpi-plugins/ GLPI_I18N_DIR: /usr/share/glpi/locales GLPI_VERSION: 9.5.2 GLPI_SCHEMA_VERSION: 9.5.2 GLPI_MIN_PHP: 7.2.0 GLPI_YEAR: 2020

Libraries

htmlawed/htmlawed version 1.2.5 in (/usr/share/glpi/vendor/htmlawed/htmlawed) phpmailer/phpmailer version 6.1.6 in (/usr/share/glpi/vendor/phpmailer/phpmailer/src) simplepie/simplepie version 1.5.5 in (/usr/share/glpi/vendor/simplepie/simplepie/library) tecnickcom/tcpdf version 6.3.5 in (/usr/share/glpi/vendor/tecnickcom/tcpdf) michelf/php-markdown in (/usr/share/glpi/vendor/michelf/php-markdown/Michelf) true/punycode in (/usr/share/glpi/vendor/true/punycode/src) iamcal/lib_autolink in (/usr/share/glpi/vendor/iamcal/lib_autolink) sabre/dav in (/usr/share/glpi/vendor/sabre/dav/lib/DAV) sabre/http in (/usr/share/glpi/vendor/sabre/http/lib) sabre/uri in (/usr/share/glpi/vendor/sabre/uri/lib) sabre/vobject in (/usr/share/glpi/vendor/sabre/vobject/lib) laminas/laminas-cache in (/usr/share/glpi/vendor/laminas/laminas-cache/src) laminas/laminas-i18n in (/usr/share/glpi/vendor/laminas/laminas-i18n/src) laminas/laminas-serializer in (/usr/share/glpi/vendor/laminas/laminas-serializer/src) monolog/monolog in (/usr/share/glpi/vendor/monolog/monolog/src/Monolog) sebastian/diff in (/usr/share/glpi/vendor/sebastian/diff/src) elvanto/litemoji in (/usr/share/glpi/vendor/elvanto/litemoji/src) symfony/console in (/usr/share/glpi/vendor/symfony/console) scssphp/scssphp in (/usr/share/glpi/vendor/scssphp/scssphp/src) laminas/laminas-mail in (/usr/share/glpi/vendor/laminas/laminas-mail/src/Protocol) laminas/laminas-mime in (/usr/share/glpi/vendor/laminas/laminas-mime/src) rlanvin/php-rrule in (/usr/share/glpi/vendor/rlanvin/php-rrule/src) blueimp/jquery-file-upload in (/usr/share/glpi/vendor/blueimp/jquery-file-upload/server/php) ramsey/uuid in (/usr/share/glpi/vendor/ramsey/uuid/src) psr/log in (/usr/share/glpi/vendor/psr/log/Psr/Log) psr/simple-cache in (/usr/share/glpi/vendor/psr/simple-cache/src) mexitek/phpcolors in (/usr/share/glpi/vendor/mexitek/phpcolors/src/Mexitek/PHPColors) guzzlehttp/guzzle in (/usr/share/glpi/vendor/guzzlehttp/guzzle/src) guzzlehttp/psr7 in (/usr/share/glpi/vendor/guzzlehttp/psr7/src) wapmorgan/unified-archive in (/usr/share/glpi/vendor/wapmorgan/unified-archive/src) paragonie/sodium_compat in (/usr/share/glpi/vendor/paragonie/sodium_compat/src) phpCas version 1.3.8 in (/usr/share/pear)

LDAP directories

Server: 'xxxxxx', Port: '389', BaseDN: 'ou=mes users,DC=xxxxx,DC=LOCAL', Connection filter: '(&(objectClass=user)(objectCategory=person)(!(userAccountControl:1.2.840.113556.1.4.803:=2)))', RootDN: 'xxxxxxx', Use TLS: none Server: 'xxxxx', Port: '389', BaseDN: 'ou=acso,DC=xxxxx,DC=fr', Connection filter: '(&(objectClass=user)(objectCategory=person)(!(userAccountControl:1.2.840.113556.1.4.803:=2)))', RootDN: 'xxxxxx', Use TLS: none

SQL replicas

Not active

Notifications

Way of sending emails: SMTP (glpi@xxxxxxxx)

Mails receivers

Name: 'support.informatique@xxxxxxx' Active: Yes Server: '{xxxxxxx/imap/ssl/novalidate-cert}' Login: 'xxxxxxx' Password: Yes

Plugins list

activity             Name: Activités quotidiennes         Version: 3.0.0      State: To update
news                 Name: Alertes                        Version: 1.7.0      State: Installed / not activated
appliances           Name: Applicatifs                    Version: 3.0.0      State: Not installed
webapplications      Name: Applications Web               Version: 3.0.0      State: Not installed
archires             Name: Architectures réseau           Version: 2.7.0      State: Installed / not activated
badges               Name: Badges                         Version: 2.6.0      State: To update
barcode              Name: Barcode                        Version: 2.5.0      State: Installed / not activated
accounts             Name: Comptes                        Version: 2.6.0      State: Not installed
datainjection        Name: Data Injection                 Version: 2.8.0      State: Installed / not activated
domains              Name: Domaines                       Version: 2.2.1      State: Installed / not activated
environment          Name: Environnement                  Version: 2.4.1      State: Installed / not activated
useditemsexport      Name: Export des éléments utilisés   Version: 2.4.0      State: Installed / not activated
formcreator          Name: Form Creator                   Version: 2.10.3     State: Installed / not activated
fusioninventory      Name: FusionInventory                Version: 9.5.0+1.0  State: Installed / not activated
geninventorynumber   Name: Génération de numéros d'invent Version: 2.5.0      State: Installed / not activated
order                Name: Gestion des commandes          Version: 2.6.0      State: Installed / not activated
mod                  Name: GLPI Modifications             Version: 1.5.1      State: Installed / not activated
pdf                  Name: Impression pdf                 Version: 1.6.0      State: Not installed
ldapcomputers        Name: LDAP computers                 Version: 0.3        State: Not installed
dporegister          Name: Registre DPO                   Version: 1.4        State: Not installed
dashboard            Name: Tableau de bord                Version: 0.9.8      State: Installed / not activated

[/code]

0xdeadbit commented 3 years ago

Looking in /front/notimportedemail.php it seems that the "self-service" profile had no rights at all for users ?! so tickets were not added (no permission) ... Adding some rights allowed the tickets to appear correctly.

The other error in php error log is because the user does not exist in ldap (external users, no email adress so collector can't send notification).

0xdeadbit commented 3 years ago

Well that worked because I disabled the notifications, enabling them back and the problem is back ... mailcollector is executing and I can't reply to a ticket (same empty in error).

So the problem seems to be tied with notifications as well.

0xdeadbit commented 3 years ago

Follow up :

I traced back the problem to the notificationtargetcommonitilobject.class.php : addAdditionnalUserInfo function.

At one moment we had 2 entities for tests, not really configured and we then removed it and only have "root", now it seems "getEntitiesRestrictCriteria('glpi_profiles_users', 'entities_id', $this->getEntity(), true)" creates an exception, the workaround I added was to always "return ['show_private' => 1];" not good but now collector and notifications are ok.


   function addAdditionnalUserInfo(array $data) {
      global $DB;

      if (!isset($data['users_id'])) {
         return ['show_private' => 0];
      }

/* workaround */
return ['show_private' => 1];

      $result = $DB->request([
         'COUNT'  => 'cpt',
         'FROM'   => 'glpi_profiles_users',
         'WHERE'  => [
            'users_id'     => $data['users_id'],
            'profiles_id'  => $this->private_profiles
         ] + getEntitiesRestrictCriteria('glpi_profiles_users', 'entities_id', $this->getEntity(), true)
      ])->next();

      if ($result['cpt']) {
         return ['show_private' => 1];
      }
      return ['show_private' => 0];
   }
trasher commented 3 years ago

now it seems "getEntitiesRestrictCriteria('glpi_profiles_users', 'entities_id', $this->getEntity(), true)" creates an exception,

Then, please provide backtrace.

Also, defaulting something like show_private to 1 seems a bad idea.

cedric-anne commented 3 years ago

Hi,

Could you check #8278 ?

Regards

0xdeadbit commented 3 years ago

Hi,

fix applied, no problem with the debug page, collector is collecting email as well.

👍

trasher commented 3 years ago

Thanks for the feedback