免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2136 | 回复: 3
打印 上一主题 下一主题

请教一段perl代码 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-05-28 13:15 |只看该作者 |倒序浏览
以前没有学过perl,现在突然领导给一个任务,用mimedefang做sendmail的milter,对邮件组的发送权限进行控制,
昨天临时看了一下perl,在mimedefang-filter中加了一段代码,但是测试时,所有人都不能对all组发邮件了,
说明:我的思路是,先对收件人进行检查,如果收件人是all@rhel4.local,则再检查发件人是不是在文件all_allow内,如果不在就REJECT.
         如果收件人不是all@rhel4.local则直接放行。以是下代码:


  1. sub filter_recipient {
  2.     use strict;
  3.     my ($recipient, $sender, $ip, $hostname, $first, $helo,$rcpt_mailer, $rcpt_host, $rcpt_addr) = @_;
  4.     if ($recipient =~ /^<?all\@rhel4\.local>?$/i) {
  5.         open (FILE,'/etc/mail/all_allow') || die "Can't open file:$!\n";
  6.         while ($line = <FILE>) {
  7.                 if ($line =~ /$sender/) {
  8.                    return ('CONTINUE', "ok");
  9.                     }
  10.                 return ('REJECT', 'Sorry; you are not allowed to mail to [email]all@rhel4.local[/email]');
  11.                 }
  12.         }
  13.     return ('CONTINUE', "ok");
  14. }
复制代码

各位表我诊断一下吧,由于现在急用,不能一从新学perl了

[ 本帖最后由 sunrocs 于 2008-5-28 13:23 编辑 ]

论坛徽章:
0
2 [报告]
发表于 2008-05-28 13:22 |只看该作者
把笑脸去掉

论坛徽章:
0
3 [报告]
发表于 2008-05-28 13:24 |只看该作者
原帖由 churchmice 于 2008-5-28 13:22 发表
把笑脸去掉


谢谢回复,现在已经去掉了,帮我看看吧

论坛徽章:
0
4 [报告]
发表于 2008-05-28 13:30 |只看该作者
我觉得这代码应该这样吧

  1. sub filter_recipient {
  2.     use strict;
  3.     my ($recipient, $sender, $ip, $hostname, $first, $helo,$rcpt_mailer, $rcpt_host, $rcpt_addr) = @_;
  4.     if ($recipient =~ /^<?all\@rhel4\.local>?$/i) {
  5.         open (FILE,'/etc/mail/all_allow') || die "Can't open file:$!\n";
  6.         while ($line = <FILE>) {
  7.                 if ($line =~ /$sender/) {
  8.                    return ('CONTINUE', "ok");
  9.                     }
  10.         }
  11. return ('REJECT', 'Sorry; you are not allowed to mail to [email]all@rhel4.local[/email]');
  12. }
复制代码

照你那写法,唯一能够返回"continue ok"的情况就是/etc/mail/all_allow的第一行刚好匹配
还有返回值用1和0区分一下就可以了,然后再在主程序中加以判断
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP