sudo apt-get install postfix
# See /usr/share/postfix/main.cf.dist for a commented, more complete version ######################################################## ## smtpd_banner = $myhostname ESMTP server biff = no # . 10Mb message_size_limit = 204800000 # myhostname = mail.yourdomain.com myorigin = $mydomain mynetworks = 127.0.0.0/8 mailbox_size_limit = 0 virtual_mailbox_limit = 0 recipient_delimiter = + inet_interfaces = all inet_protocols = ipv4 append_dot_mydomain = no readme_directory = no ########################################################## ## # , mydestination = local_recipient_maps = relay_domains = relay_recipient_maps = transport_maps = # virtual_mailbox_domains = $mydomain # ( - Dovecot) # ( ) virtual_mailbox_maps = hash:/etc/postfix/mailboxes/local-mailboxes # virtual_alias_maps = hash:/etc/postfix/mailboxes/db-aliases hash:/etc/postfix/mailboxes/local-aliases # . , Dovecot virtual_mailbox_base = /var/mail virtual_uid_maps = static:900 virtual_gid_maps = static:900 ########################################################### ## - # SASL smtpd_sasl_auth_enable = no # TLS smtpd_use_tls = no ########################################################### ## # ETRN smtpd_etrn_restrictions = reject # VRFY disable_vrfy_command = yes # EHLO (HELO) smtpd_helo_required = yes # smtpd_reject_unlisted_recipient = yes # - PTR ( ) smtpd_client_restrictions = permit_mynetworks reject_unknown_reverse_client_hostname permit # HELO. , smtpd_helo_restrictions = permit_mynetworks reject_invalid_helo_hostname reject_non_fqdn_helo_hostname reject_unknown_helo_hostname permit # MAIL FROM. , smtpd_sender_restrictions = reject_non_fqdn_sender reject_unknown_sender_domain permit # RCPT TO. smtpd_recipient_restrictions = reject_non_fqdn_recipient reject_unlisted_recipient permit_mynetworks reject_unauth_destination permit # . smtpd_data_restrictions = reject_unauth_pipelining
sudo postmap /etc/postfix/mailboxes/local-mailboxes
#!/usr/bin/perl # SMF , # postfix. # cron. /etc/cron.d/postfix-smf-sync use 5.010; use DBI; ############################################################# # (MySQL) $MYSQL_host = 'bd.yourdomain.com'; $MYSQL_port = '3306'; $MYSQL_user = 'postfix'; $MYSQL_pass = 'PASSW0RD'; $MYSQL_db = 'my_smf'; # SMF - $SMF_GID = '15'; $SMF_prefix = 'smf_'; # $domain = "yourdomain.com"; # $postfix_file = "/etc/postfix/mailboxes/db-aliases"; ############################################################# $dbh = DBI->connect("DBI:mysql:$MYSQL_db:$MYSQL_host:$MYSQL_port",$MYSQL_user,$MYSQL_pass) or die "Hey guys! We've got a big error here...\n"; # my $sth = $dbh->prepare("SELECT memberName, realName, emailAddress FROM ${SMF_prefix}members WHERE (ID_GROUP = $SMF_GID OR FIND_IN_SET($SMF_GID, additionalGroups))") or die "Hey guys! We've got big error here!\n"; $sth->execute() or die "Hey guys! We've got a big error here...\n"; # Postfix open ALIASES, ">$postfix_file" or die "Can't open $postfix_file\n"; say ALIASES <<INTRO; ################################################# # yourdomain.com # # . # # # # # # /etc/postfix/scripts/postfix-sync.pl # # SMF. # # . # ################################################# INTRO # : # $w = '[a-zA-Z0-9]'; # -: $s = '[._\-]'; # while (my $row = $sth->fetchrow_hashref()) { # lower case, my $user = lc $row->{realName}; # - # , ".", "-" "_" next unless $user =~ /^($w+$s)*$w+$/; # , my $email = lc $row->{emailAddress}; next if "$user\@$domain" eq $email; # say ALIASES "$user\@$domain\t$row->{emailAddress}"; } # postfix' close ALIASES; `/usr/sbin/postmap hash:$postfix_file`;
someuser@yourdomain.com usermail@anotherdomain.com
# Synchronize Postfix with BD 18 04 * * * root /etc/postfix/scripts/postfix-sync.pl
sudo apt-get install ejabberd
{auth_method, external}. {extauth_program, "/etc/ejabberd/auth.pl"}.
#!/usr/bin/perl use 5.010; use Digest::SHA1 qw(sha1_hex); use DBI; ############################################################# # (MySQL) $MYSQL_host = 'bd.yourdomain.com'; $MYSQL_port = '3306'; $MYSQL_user = 'postfix'; $MYSQL_pass = 'PASSW0RD'; $MYSQL_db = 'my_smf'; # SMF - $SMF_GID = '15'; $SMF_prefix = 'smf_'; # $valid_domain = "yourdomain.com"; ############################################################# # sub db_connect { my $dbh = DBI->connect("DBI:mysql:$MYSQL_db:$MYSQL_host:$MYSQL_port",$MYSQL_user,$MYSQL_pass); return $dbh; } $dbh = db_connect; # , . , . while(1) { # ejabberd my $nread = sysread STDIN, my $buf, 2; unless ($nread == 2) { exit } my $len = unpack "n", $buf; $nread = sysread STDIN, $buf, $len; my ($op,$user,$domain,$passwd) = split /:/, $buf; # , $passwd =~ s/[\n\r]//g; # ejabberd, die "_" if $valid_domain ne $domain; my $result = 0; ## : # - # , ".", "-" "_" if ($user =~ /^\w+[\w.\-_]*\w+$/) { # , unless ($dbh) { $dbh = db_connect } # . - my $sth = $dbh->prepare("SELECT memberName, realName, passwd FROM ${SMF_prefix}members WHERE (ID_GROUP = $SMF_GID OR FIND_IN_SET($SMF_GID, additionalGroups)) AND realName = '$user'") or $dbh = undef if $dbh; # . - $sth->execute() or $dbh = undef if $dbh; # if ($dbh) { # my $num = $sth->rows(); # my $row = $sth->fetchrow_hashref() if $num == 1; # if ($op =~ /auth/i and $num == 1) { my $epass = sha1_hex(lc($row->{memberName}) . $passwd); $result = $epass eq $row->{passwd} ? 1 : 0; } elsif ($op =~ /isuser/i and $num == 1) { $result = exists $row->{memberName} ? 1 : 0; } } } else { $result = 0; } # ejabberd my $out = pack "nn", 2, $result; syswrite STDOUT, $out; }
Source: https://habr.com/ru/post/104741/
All Articles