60 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
			
		
		
	
	
			60 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
{
 | 
						|
    $OUT = '';
 | 
						|
 | 
						|
    # Generate qmail user assignments for users. These will be handled by
 | 
						|
    # ~user/.qmail.
 | 
						|
 | 
						|
    use esmith::AccountsDB;
 | 
						|
    my $adb = esmith::AccountsDB->open_ro();
 | 
						|
 | 
						|
    foreach $user ( $adb->users )
 | 
						|
    {
 | 
						|
	my $user_name = $user->key;
 | 
						|
	my (undef, undef, $uid, $gid, undef, undef, undef, $dir, undef)
 | 
						|
	    = getpwnam($user_name);
 | 
						|
 | 
						|
	# 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 \'$user_name\' "
 | 
						|
		. "while processing user assignments.";
 | 
						|
 | 
						|
	    warn "$msg\n";
 | 
						|
	    $OUT = $msg;
 | 
						|
	    return;
 | 
						|
	}
 | 
						|
 | 
						|
	$user_assign = $user_name . ":${uid}:${gid}:${dir}";
 | 
						|
 | 
						|
	# Assign mail for user@
 | 
						|
	$OUT .= "=" . $user_name . ":${user_assign}:::\n";
 | 
						|
 | 
						|
	# Assign mail for user-ext@
 | 
						|
	$OUT .= "+" . $user_name . "-:${user_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
 | 
						|
    # alias user.
 | 
						|
 | 
						|
    unless ($OUT)
 | 
						|
    {
 | 
						|
	(undef, undef, $uid, $gid, undef, undef, undef, $dir, undef)
 | 
						|
		= getpwnam("alias");
 | 
						|
 | 
						|
	$alias_assign = "alias:${uid}:${gid}:${dir}";
 | 
						|
	$OUT = "=alias:${alias_assign}:::";
 | 
						|
    }
 | 
						|
}
 |