2

I am making use of PDFTK to watermark PDF files using the following command:

pdftk /tmp/55180af7c8c88.pdf stamp /tmp/stamp55180af7c95b84.58412952.pdf output /tmp/55180af7c95c81.06110501.pdf

However the above results in:

Error: Failed to open output file:
   /tmp/55180af7c95c81.06110501.pdf
   No output created.
Error: unable to open file for output: /tmp/55180af7c95c81.06110501.pdf

The above is a strange error because PDFTK should be creating that output file!

If I put sudo infront of the command, no error is thrown. But I am writing to the tmp folder and this is writeable by all I thought?

I am running PDFTK from PHP's exec command. To be 100% sure that this isn't a permissions issue, I made the /tmp folder owner and group to be www-data, which is the apache user but the same error is thrown.

I now have no idea what is going on, I appreciate any help!

Abs
  • 1,559
  • 5
  • 19
  • 32

2 Answers2

1

You should not be fiddling around with the permissions for /tmp. It's an important part of the system. I suspect that the reason your pdftk command is failing is because /tmp is incorrectly set up. To restore the permissions on tmp run the following commands as root:

chown root:root /tmp
chmod 1777 /tmp

The result will leave the permissions and owner/group of /tmp looking like this:

ls -ld /tmp
drwxrwxrwt 6 root root 12288 Mar 29 18:05 /tmp

Based on further investigation, I suspect that now we have got /tmp sorted out, the reason that the pdftk is failing is that the output file already exists but is not writeable by the application. (Awaiting update via comments.)

roaima
  • 1,591
  • 14
  • 28
  • This was the state of permissions in the first place. I have changed it back. But this doesn't solve the initial problem. – Abs Mar 29 '15 at 18:30
  • Maybe not, but at least `/tmp` is now in a sane state. – roaima Mar 29 '15 at 19:12
0

Have you got selinux enabled? Have a look at this previous question and answer, please.

I am editing this after your kind comment about SELinux/AppArmor not being relevant. If I were you, and this a long shot, I would take a look at the filesystem you are using for /tmp. If it is not tmpfs and it is get close to be full, you may experience issues similar to the one you describe. As you are probably aware of, once a filesystem gets close to be full, it only allows root to write on it.

Again, hope it helps!

c-garcia
  • 166
  • 1
  • 6
  • I used `sestatus` to check if is selniux is enabled but it is disabled. In addition, `apparmor` is enabled but it's just the basic setup and it isn't blocking pdftk as it isn't in any of the profiles. – Abs Apr 04 '15 at 18:07