Skip to content
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

dovecot: Fix sieve scripts #21864

Merged
merged 1 commit into from Jan 16, 2017
Merged

dovecot: Fix sieve scripts #21864

merged 1 commit into from Jan 16, 2017

Conversation

pjones
Copy link
Contributor

@pjones pjones commented Jan 13, 2017

Motivation for this change

Make sure that the output of the sieve compiler produces files that
have a newer time stamp than the source sieve script. Otherwise you
get errors in the logs about Dovecot not being able to compile do to a
permission issue.

This change is running in production via NixOps.

Things done
  • Tested using sandboxing
    (nix.useSandbox on NixOS,
    or option build-use-sandbox in nix.conf
    on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • Linux
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nox --run "nox-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Fits CONTRIBUTING.md.

Make sure that the output of the sieve compiler produces files that
have a newer time stamp than the source sieve script.  Otherwise you
get errors in the logs about Dovecot not being able to compile do to a
permission issue.
@mention-bot
Copy link

@pjones, thanks for your PR! By analyzing the history of the files in this pull request, we identified @abbradar, @peti and @hrdinka to be potential reviewers.

preStart = ''
rm -rf ${stateDir}/sieve
'' + optionalString (cfg.sieveScripts != {}) ''
mkdir -p ${stateDir}/sieve
${concatStringsSep "\n" (mapAttrsToList (to: from: ''
if [ -d '${from}' ]; then
mkdir '${stateDir}/sieve/${to}'
cp "${from}/"*.sieve '${stateDir}/sieve/${to}'
cp -p "${from}/"*.sieve '${stateDir}/sieve/${to}'
Copy link
Member

@Mic92 Mic92 Jan 14, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By newer you mean the same timestamp as their source files?

@fpletz
Copy link
Member

fpletz commented Jan 14, 2017

Does Dovecot recompile the sieve scripts based on their mtime or their content? With this change, all sieve files would have the same mtime.

@fpletz
Copy link
Member

fpletz commented Jan 14, 2017

Could manual compilation be an option? http://wiki2.dovecot.org/Pigeonhole/Sieve/Usage#scriptcompile

@pjones
Copy link
Contributor Author

pjones commented Jan 16, 2017

Dovecot compares the time stamps of the sieve source files and compiled scripts. If the source file is newer than the compiled file Dovecot will attempt to recompile. But, when it does, it's already running as another user and doesn't have permission to write to the sieve directory.

This change ensures that the source files will always have a time stamp that is older than the compiled version so Dovecot won't try to recompile on the fly. (Which isn't needed since they are compiled by the pre-start script.)

@pjones
Copy link
Contributor Author

pjones commented Jan 16, 2017

Just to be clear, the preStart script is already manually compiling the sieve scripts after copying them into the state directory. But that happens so fast that the source file and the compiled file have the same timestamp. When Dovecot goes to use the sieve script it sees they have the same timestamp and tries to automatically recompile the source file but can't due to limited permissions (when in delivery mode). This is probably a bug in Dovecot.

Another solution might be to just compile the sieve scripts from the Nix store and store the compiled output in the state directory. I haven't tested this so I don't know if Dovecot supports a directory with compiled sieve scripts where the source files are missing.

@Mic92 Mic92 merged commit 28093e4 into NixOS:master Jan 16, 2017
@Mic92
Copy link
Member

Mic92 commented Jan 16, 2017

Thanks. Now it make sense to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants