{
    $OUT = '';

    # Generate qmail user assignments for system accounts. These will
    # be handled by admin. Make sure we DON'T reassign the admin or
    # alias users!

    my (undef, undef, $uid, $gid, undef, undef, undef, $dir, undef)
	= getpwnam("admin");

    # It is almost impossible to get Text::Template to output nothing
    # on failure. It can be done by removing the newline at the end of
    # this file but that is messy. Therefore, we'll simply return an
    # error message that will make qmail-newu fail. Also send a
    # warning message that will be captured in the logs.

    unless (defined $uid && defined $gid && defined $dir)
    {
	my $msg =
	    "Failed to obtain user details for \'admin\' "
	    . "while processing system assignments.";

	warn "$msg\n";
	$OUT = $msg;
	return;
    }

    my $admin_assign = "admin:${uid}:${gid}:${dir}";

    use esmith::AccountsDB;
    my $adb = esmith::AccountsDB->open_ro();

    foreach my $user ( $adb->get_all_by_prop( type => 'system' ) )
    {
	next if ($user->key eq "admin");
	next if ($user->key eq "alias");
	next if ($user->key eq "shared");

	# Assign mail for system_account@
	$OUT .= "=" . $user->key . ":${admin_assign}:::\n";

	# Assign mail for system_account-ext@
	$OUT .= "+" . $user->key . "-:${admin_assign}:-::\n";
    }

    # Need to remove the final newline character. Blank lines in
    # /var/qmail/users/assign are prohibited.

    chomp($OUT);

    # Failsafe: /var/qmail/users/assign cannot have blank lines.
    # Therefore, if $OUT is empty, simply set up an assign for the
    # admin user.

    $OUT = "=admin:${admin_assign}:::" unless $OUT;
}
