1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
|
#-*- perl -*-
#
# Copyright (C) 2003,2004,2005,2006 Ken'ichi Fukamachi
# All rights reserved. This program is free software; you can
# redistribute it and/or modify it under the same terms as Perl itself.
#
# $FML: Sendmail.pm,v 1.7 2005/08/17 10:44:47 fukachan Exp $
#
package FML::MTA::Control::Sendmail;
use strict;
use vars qw(@ISA @EXPORT @EXPORT_OK $AUTOLOAD);
use Carp;
my $debug = 0;
=head1 NAME
FML::MTA::Control::Sendmail - handle sendmail specific configurations.
=head1 SYNOPSIS
set up aliases and virtual maps for sendmail.
=head1 DESCRIPTION
=head1 METHODS
=cut
# BUGS
#XXX-TODO: We should check "Tfml" in sendmail.cf in installation.
# Descriptions: install new alias entries.
# Arguments: OBJ($self)
# OBJ($curproc) HASH_REF($params) HASH_REF($optargs)
# Side Effects: update aliases
# Return Value: none
sub sendmail_install_alias
{
my ($self, $curproc, $params, $optargs) = @_;
$self->postfix_install_alias($curproc, $params, $optargs);
}
# Descriptions: remove alias.
# Arguments: OBJ($self)
# OBJ($curproc) HASH_REF($params) HASH_REF($optargs)
# Side Effects: update aliases
# Return Value: none
sub sendmail_delete_alias
{
my ($self, $curproc, $params, $optargs) = @_;
$self->postfix_delete_alias($curproc, $params, $optargs);
}
# Descriptions: regenerate aliases.db.
# Arguments: OBJ($self)
# OBJ($curproc) HASH_REF($params) HASH_REF($optargs)
# Side Effects: update aliases
# Return Value: none
sub sendmail_update_alias
{
my ($self, $curproc, $params, $optargs) = @_;
my $config = $curproc->config();
my $prog = $config->{ path_sendmail };
my $alias = $config->{ mail_aliases_file };
$curproc->ui_message("updating $alias database");
if (-x $prog) {
system "$prog -bi -oA$alias";
}
else {
warn("sendmail='$prog' not found");
}
}
# Descriptions: find key in aliases.
# Arguments: OBJ($self)
# OBJ($curproc) HASH_REF($params) HASH_REF($optargs)
# Side Effects: none
# Return Value: NUM(1 or 0)
sub sendmail_find_key_in_alias_maps
{
my ($self, $curproc, $params, $optargs) = @_;
$self->postfix_find_key_in_alias_maps($curproc, $params, $optargs);
}
# Descriptions: get { key => value } in aliases.
# Arguments: OBJ($self)
# OBJ($curproc) HASH_REF($params) HASH_REF($optargs)
# Side Effects: none
# Return Value: HASH_REF
sub sendmail_get_aliases_as_hash_ref
{
my ($self, $curproc, $params, $optargs) = @_;
$self->postfix_get_aliases_as_hash_ref($curproc, $params, $optargs);
}
# Descriptions: return alias_maps as ARRAY_REF.
# Arguments: OBJ($self)
# OBJ($curproc) HASH_REF($params) HASH_REF($optargs)
# Side Effects: none
# Return Value: ARRAY_REF
sub sendmail_alias_maps
{
my ($self, $curproc, $params, $optargs) = @_;
# XXX-TODO: NOT IMPLEMENTED.
return [];
}
# Descriptions: install configuration templates.
# Arguments: OBJ($self)
# OBJ($curproc) HASH_REF($params) HASH_REF($optargs)
# Side Effects: create include*
# Return Value: none
sub sendmail_setup
{
my ($self, $curproc, $params, $optargs) = @_;
$self->postfix_setup($curproc, $params, $optargs);
}
# Descriptions: rewrite $params.
# Arguments: OBJ($self)
# OBJ($curproc) HASH_REF($params) HASH_REF($optargs)
# Side Effects: update $params
# Return Value: none
sub _sendmail_rewrite_virtual_params
{
my ($self, $curproc, $params, $optargs) = @_;
# XXX-TODO remove this.
}
# Descriptions: install sendmail virtual_maps.
# Arguments: OBJ($self)
# OBJ($curproc) HASH_REF($params) HASH_REF($optargs)
# Side Effects: install/udpate sendmail virtual_maps and the .db
# Return Value: none
sub sendmail_install_virtual_map
{
my ($self, $curproc, $params, $optargs) = @_;
my $template_dir = $curproc->newml_command_template_files_dir();
my $config = $curproc->config();
my $ml_name = $config->{ ml_name };
my $ml_domain = $config->{ ml_domain };
use File::Spec;
my $virtual = $config->{ sendmail_virtual_map_file };
my $src = File::Spec->catfile($template_dir, 'postfix_virtual');
my $dst = sprintf("%s.%s", $virtual, $$);
$curproc->ui_message("updating $virtual");
# at the first time
unless( -f $virtual) {
use FileHandle;
my $fh = new FileHandle ">> $virtual";
if (defined $fh) {
print $fh "#\n";
print $fh "# you need to specify $ml_domain ";
print $fh "as a destination (Class w) in sendmail.cf.\n";
print $fh "# For example, Cwlocalhost $ml_domain ...\n";
print $fh "#\n";
$fh->close();
}
}
$self->_install($src, $dst, $params);
$curproc->append($dst, $virtual);
unlink $dst;
}
# Descriptions: remove sendmail virtual_maps.
# Arguments: OBJ($self)
# OBJ($curproc) HASH_REF($params) HASH_REF($optargs)
# Side Effects: remove/udpate sendmail virtual_maps and the .db
# Return Value: none
sub sendmail_delete_virtual_map
{
my ($self, $curproc, $params, $optargs) = @_;
my $config = $curproc->config();
my $map = $config->{ sendmail_virtual_map_file };
my $key = $params->{ ml_name };
my $p = {
key => $key,
map => $map,
};
$self->delete_postfix_style_virtual($curproc, $params, $optargs, $p);
}
# Descriptions: regenerate virtual.db.
# Arguments: OBJ($self)
# OBJ($curproc) HASH_REF($params) HASH_REF($optargs)
# Side Effects: update aliases
# Return Value: none
sub sendmail_update_virtual_map
{
my ($self, $curproc, $params, $optargs) = @_;
my $config = $curproc->config();
my $makemap = $config->{ path_makemap };
my $virtual = $config->{ sendmail_virtual_map_file };
if (-f $virtual) {
$curproc->ui_message("updating $virtual database");
# XXX-TODO: oops, hash HARD CODED.
if (-x $makemap) {
system "$makemap hash $virtual < $virtual";
}
else {
warn("makemap='$makemap' not found");
}
}
}
=head1 UTILITIES
=head2 sendmail_supported_map_types
get map types supported by makemap.
=cut
# Descriptions: get map types supported by makemap.
# Arguments: OBJ($self)
# OBJ($curproc) HASH_REF($params) HASH_REF($optargs)
# Side Effects: none
# Return Value: ARRAY_REF
sub sendmail_supported_map_types
{
my ($self, $curproc, $params, $optargs) = @_;
my $config = $curproc->config();
my $makemap = $config->{ path_makemap };
if (-x $makemap) {
my $buf = `$makemap -l`;
chomp $buf;
my @maps = split(/\s+/, $buf);
return \@maps;
}
else {
return [];
}
}
=head1 CODING STYLE
See C<http://www.fml.org/software/FNF/> on fml coding style guide.
=head1 AUTHOR
Ken'ichi Fukamachi
=head1 COPYRIGHT
Copyright (C) 2003,2004,2005,2006 Ken'ichi Fukamachi
All rights reserved. This program is free software; you can
redistribute it and/or modify it under the same terms as Perl itself.
=head1 HISTORY
FML::MTA::Control first appeared in fml8 mailing list driver package.
See C<http://www.fml.org/> for more details.
=cut
1;
|