Bugzilla – Bug 1191624
useradd always create user mail spool
Last modified: 2023-08-03 09:53:16 UTC
YaST Users is being partially rewritten to rely on the tools of the shadow packages (useradd & friends) as much as possible. When a user is created by useradd, the user's mail spool (i.e., /var/mail/username) is always created, too. But userdel only removes the mail spool is it is explicitly indicated with userdel -r. Note that the home is differently treated. The home directory is neither created nor removed by default. The -m and -r options have to be passed to useradd and userdel respectively in order to create and remove the home. This behavior of useradd with the mail spool can lead to situations where userdel could fail later. For example in this use case: * Create user test1: useradd test1 * Delete user test1: userdel test1 (note that /var/mail/test1 is not deleted) * Create user test2: useradd test2 * Rename user test2: usermod --login test1 test2 * Remove user test1 (formerly test2): userdel --remove test1 (exit status 12) Note that userdel will return exit status 12 because /var/mail/test1 is not owned by test1 (it belongs to the previous test1 user). Now that YaST is delegating all operations to the shadow tools, this exit status different to 0 is making YaST to bother users with warnings when deleting users. It would be nice if useradd does not add the user's mail spool if that is not explicitly asked. Another option could be that userdel always remove the mail spool.
In Factory, the users home directory is meanwhile always created.
In fact, in YaST we don't care much about the default value for CREATE_HOME is. We always force the behavior in one direction or the other by passing "--create-home" or "--no-create-home". The case of the mail spool is different because there are no equivalent parameters to specify whether it should be created or not for a particular useradd invocation. In short, useradd offers a fine-grained control over the creation of the home per user, but basically no control over the creation of the mail spool. It's always created for all users[1]. So far, so good. > useradd --create-home username => creates both mail spool and home > useradd --no-create-home username => creates mail spool but not home The inconvenience is that userdel then offers just one parameter to decide what to do with both home and the mail spool. > userdel username => does not remove home nor mail spool > userdel --remove username => removes both home and mail spool Since the admin (or YaST) can freely decide whether to create a home or not when creating the user, it makes sense for the same admin (or YaST) to decide whether to remove the home or not when deleting the user. BUT this is not symmetric with "--(no)-create-home". The useradd parameter has no implications for the mail spool, while the userdel one does. Is not a tragedy but is inconvenient. What's the correct fix? I don't know. I would say that offering separate parameters in userdel to delete only the home and/or only the mail spool. But I guess there are more options. Just my 2 cents. [1] "Is always created for all users" may not be accurate, but is close enough to reality in practice. In fact, the value of CREATE_MAIL_SPOOL at /etc/default/useradd is still honored by the tool, but is not documented at the manpage and there is no option to modify it via "useradd -D". Taking into account the default value for CREATE_MAIL_SPOOL is "yes", we can say that useradd will always create the spool (unless the admin really tries to avoid it by manually modifying /etc/default/useradd).