makeuserdb pw2userdb vchkpw2userdb [ --vpopmailhome=dir ] [ --todir=dir ]
These commands are used to create the /etc/userdb.dat
database.
makeuserdb
creates /etc/userdb.dat
based on the
contents of /etc/userdb
. /etc/userdb.dat
is used by
maildrop, Courier, and other applications as a
substitute/complement for your system password file. The usual purpose for
/etc/userdb.dat
is to specify "virtual" accounts - accounts that do
not have an associated login. Typically all virtual accounts share the same
system userid. /etc/userdb.dat
can also be used as a replacement for
your system password file. Because the system password file is a text file,
when there's a large number of accounts it will be significantly faster to
search a binary database, instead of a text file.
The makeuserdb
command creates /etc/userdb.dat
based
on the contents of /etc/userdb
. /etc/userdb
is a plain
text file, or a directory. If it is a directory, the contents of all files in
the directory are simply concatenated together.
makeuserdb
command can be safely executed during normal system
activity.
/etc/userdb
/etc/userdb
is a plain text file that can be created using any text
editor. Blank lines are ignored. Lines that start with the # character are
comments, and are also ignored. Other lines define properties of a single
account, one line per account. If /etc/userdb
is a directory, each
file in /etc/userdb
is formatted the same way. Each line takes the
following format:name<TAB>field=value|field=value
name is the account name. If Courier is configured to treat
lowercase and uppercase account names as identical, name MUST contain
lowercase characters only. name is followed by exactly one tab
character, then a list of field/value pairs separated by vertical slashes.
field is the name of the field, value is the field value. The
field value itself cannot contain slashes or control characters. Fields can be
specified in any order. Here are all the currently defined fields. Note that
not every field is used by every application that reads
/etc/userdb.dat
.
uid
- value specifies a (possibly) unique numerical
user ID for this account.gid
- value specifies a (possibly) unique numerical
group ID for this account.home
- value specifies the account's home
directory.shell
- value specifies the account's default
shell.systempw
- value specifies the account's system
password. See userdbpw(8) for a way to set
this field.pop3pw, esmtppw, imappw...
- value specifies a
separate password used only for authenticating access via some service,
such as POP3, IMAP, or anything else. If not defined, systempw is
always used. This allows you to define separate passwords for each
service, or always use the same password for everything, your choice.mail
- value specifies the location of the account's
Maildir mailbox. If missing, the account's Maildir is expected to be
present in the default location for system accounts.quota
- value specifies the quota for the account's
Maildir. See maildirquota(8) for more information.The uid
, gid
, and home
fields MUST
be specified. The remaining fields are optional. If missing, system defaults
will be used.
=uid<TAB>name
This entry is used to specify reverse mapping from userids to names.
uid specifies the system userid, name specifies the system
username. name must point to another record in userdb
.
All fields whose name ends with 'pw' will NOT copied to
/etc/userdb.dat
. These fields will be copied to
/etc/userdbshadow.dat
. makeuserdb
will turn off all
group and world permissions on /etc/userdbshadow.dat
.
makeuserdb
will also fail if /etc/userdb
has any group
or world permissions.
The pw2userdb
script reads /etc/passwd
and
/etc/shadow
then converts all entries to the format used in
/etc/userdb
, printing the result on standard output. The output can
be redirected to /etc/userdb
, or to a file in this subdirectory.
Linear searches of /etc/passwd
can be very slow when you have
tens of thousands of accounts. Programs like maildrop always look in
/etc/userdb
first, so by having the system password file in the
/etc/userdb
it is possible to significantly reduce the amount of
time it takes to look it up.
After saving the output of pw2userdb
, you must still run
makeuserdb
to create /etc/userdb.dat
.
The vchkpw2userdb
script is used to convert vpopmail-style
directory hierarchy to the /etc/userdb
format.
vpopmail/vchkpw
is often used to implement virtual mailboxes that
share the same userid.
Generally, an account named 'vpopmail' is reserved for this purpose. In
that account the file users/vpasswd
has the same structure as
/etc/passwd
, and performs a similar function, except that all
userid in users/vpasswd
have the same userid. Additionally, the
domains
subdirectory is used to store virtual accounts for
multiple domains. For example, domains/example.com/vpasswd
contains the passwd file for domain example.com
. Additionally,
some systems implement a soft link, domains/default
, that points
to a domain that's considered a "default" domain.
The vchkpw2userdb
script takes all of this, and attempts to
convert it into the /etc/userdb
format. The
--vpopmailhost
option specifies the top level directory, if it is
not the home directory of the vpopmail account.
The vchkpw2userdb
script prints the results on standard
output. If specified, the --todir option, attempts to convert all
vpasswd
files one at a time, saving each one individually in
dir. For example:
mkdir /etc/userdb
vchkpw2userdb --todir=/etc/userdb/vpopmail
makeuserdb
It is still necessary to run makeuserdb
, of course, to create
the binary database.
NOTE: You are still required to create the /etc/userdb entry which maps
system userids back to accounts, "=uid<TAB>name"
, if that's
applicable. vchkpw2userdb
will not do it for you.
NOTE: makeuserdb
may complain about duplicate entries, if
your "default" entries in users/vpasswd
or
domains/default/vpasswd
are the same as anything in any other
/etc/userdb
file. It is also likely that you'll end up with
duplicate, but distinct, entries for every account in the default domain. For
example, if your default domain is example.com, you'll end up with duplicate
entries - you'll have entries for both user
and
user@example.com
.
If you intend to maintain the master set of accounts using vchkpw/vpopmail,
in order to avoid cleaning this up every time, you might want to consider
doing the following: run vchkpw2userdb
once, using the
--todir
option. Then, go into the resulting directory, and
replace one of the redundant files with a soft link to /dev/null
.
This allows you to run vchkpw2userdb
without having to go in and
cleaning up again, afterwards.
/etc/userdb
/etc/userdb.dat
/etc/userdbshadow.dat
/etc/userdb.tmp
- temporary file/etc/userdbshadow.tmp
- temporary file*pw
must be encrypted via crypt.
makeuserdb
is a Perl script, and uses Perl's portable locking.
Perl's documentation notes that certain combinations of locking options may
not work with some networks.
userdb(8), maildrop(1), courier(1), maildirquota(8)