Fix for locking issues in redmine/6334

Please split line; I would do so after each `&&` so that the strcmp()s line up and make clear what similarities there are between the three checks.