bayes_toks changing ownership to root

Strator

Verified User
Joined
Jan 19, 2011
Messages
283
Hi,

A couple of months ago, I noticed that spamassassin wasn't using bayes, and eventually figured out that bayes_toks in my local mail directory was owned by root, which is why it couldn't be accessed. Changed owner and group to the mailbox owner, and the problem seemed fixed.

Now, a couple of days I noticed that bayes has stopped working again. Checked bayes_toks, and voila - it's owned by root again.

Does anbody have a clue why this is happening, and what I can do to stop it? Thanks!
 
Nice one - yes indeed. ;)

So basically I should be running a script that calls sa-learn, instead of running it via cron directly?

But what I don't understand, is why ownership only changes sometimes. I mean, I run the cronjob every day, and normally the owner stays like it should be?
 
At least crontask should not run with root permissions if you follow official guide.

We have our own approach on the matter, and here we use a crontask with root permissions and sudo in order to process all existing users at once and let them to have their own bayes files: https://help.poralix.com/articles/teaching-spamassassin-on-directadmin-servers-with-sa-learn


SpamAssassin skips processing emails which are similar to those which were already learned earlier. In this case bayes files might stay untouched with their original permissions.
 
"SpamAssassin skips processing emails which are similar to those which were already learned earlier. In this case bayes files might stay untouched with their original permissions."

Oddly that doesn't seem to be the reason. bayes_toks was updated by cron just a couple of hours ago and ownership is still like it should be.

EDIT: I did some more research, and these seem to be the facts:

- sa-learn doesn't change file owner.
- If file doesn't exist it is created with owner set to user invoking sa-learn.

So it seems like bayes_toks is created from scratch once in a while. God know why. But yeah, then of course not using root to invoke sa-learn would be the solution. Thanks!
 
I don't know how you run all the processes so I can only guess.

Actually sa-learn uses homedir of an user who calls it to store files. So if you run a crontask as root, all the bayes files will be stored in /root/.spamassassin/ (if I recall it correctly). That's why we created the set of custom scripts mentioned in previous reply.

SpamAssassin does not run under root, so it can not change ownership. Directadmin does not change it too. So probably you have some custom root-crontasks which copy bayes files from /root/.spamassassin/ across the users.... again a guess.
 
Odd - I know I typed up a reply a couple of days ago, but it isn't here. Hm...

What I run via crontask (as root) is this:

sa-learn -D --dbpath=/home/someuser/.spamassassin --spam "/home/someuser/imap/somedomain.com/somename/Maildir/.INBOX.Junk/cur/*.*"

That's it. Again, the above works smooth for months, the ownership change is a rare event. I would assume that maybe it happens when two operations collide, e.g. the cronjob colliding with some cleanup operation where bayes_toks is locked or renamed or something like that, so sa-learn recreates it with owner set to user invoking sa-learn. Just a wild guess of course.
 
Back
Top