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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
|
#-*- perl -*-
#
# Copyright (C) 2004,2005,2006,2008 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: State.pm,v 1.28 2008/07/03 20:49:57 fukachan Exp $
#
package FML::Process::State;
use strict;
use vars qw(@ISA @EXPORT @EXPORT_OK $AUTOLOAD);
use Carp;
my $debug = 0;
=head1 NAME
FML::Process::State - interface to handle states within current process.
=head1 SYNOPSIS
=head1 DESCRIPTION
=head1 METHODS
=head1 CURRENT MAILING LIST
=cut
# Descriptions: dummy.
# Arguments: OBJ($curproc)
# Side Effects: none
# Return Value: none
sub current_process_init
{
my ($curproc) = @_;
}
# Descriptions: set ml_name to handle currently.
# Arguments: OBJ($curproc) STR($ml_name)
# Side Effects: update pcb.
# Return Value: none
sub current_process_set_ml_name
{
my ($curproc, $ml_name) = @_;
my $pcb = $curproc->pcb();
return $pcb->get("current_process", "ml_name", $ml_name);
}
# Descriptions: get ml_name to handle currently.
# Arguments: OBJ($curproc)
# Side Effects: none
# Return Value: STR
sub current_process_get_ml_name
{
my ($curproc) = @_;
my $pcb = $curproc->pcb();
return $pcb->get("current_process", "ml_name");
}
=head1 BASIC RESTRICTION STATES
CAUTION: restriction_state_*() is reset each command.
=cut
# Descriptions: dummy.
# Arguments: OBJ($curproc)
# Side Effects: none
# Return Value: none
sub restriction_state_init
{
my ($curproc) = @_;
}
# Descriptions: save reason on denial.
# Arguments: OBJ($curproc) STR($reason)
# Side Effects: none
# Return Value: none
sub restriction_state_set_deny_reason
{
my ($curproc, $reason) = @_;
my $pcb = $curproc->pcb();
$pcb->set("check_restrictions", "deny_reason", $reason);
$curproc->logdebug("restriction_state_set_deny_reason: $reason") if $debug;
}
# Descriptions: return the latest reason on denial.
# Arguments: OBJ($curproc)
# Side Effects: none
# Return Value: none
sub restriction_state_get_deny_reason
{
my ($curproc) = @_;
my $pcb = $curproc->pcb();
return $pcb->get("check_restrictions", "deny_reason");
}
# Descriptions: save reason on ignore.
# Arguments: OBJ($curproc) STR($reason)
# Side Effects: none
# Return Value: none
sub restriction_state_set_ignore_reason
{
my ($curproc, $reason) = @_;
my $pcb = $curproc->pcb();
$pcb->set("check_restrictions", "ignore_reason", $reason);
if ($debug) {
$curproc->logdebug("restriction_state_set_ignore_reason: $reason");
}
}
# Descriptions: return the latest reason on ignore.
# Arguments: OBJ($curproc)
# Side Effects: none
# Return Value: none
sub restriction_state_get_ignore_reason
{
my ($curproc) = @_;
my $pcb = $curproc->pcb();
return $pcb->get("check_restrictions", "ignore_reason");
}
# Descriptions: save reason on hold.
# Arguments: OBJ($curproc) STR($reason)
# Side Effects: none
# Return Value: none
sub restriction_state_set_hold_reason
{
my ($curproc, $reason) = @_;
my $pcb = $curproc->pcb();
$pcb->set("check_restrictions", "hold_reason", $reason);
if ($debug) {
$curproc->logdebug("restriction_state_set_hold_reason: $reason");
}
}
# Descriptions: return the latest reason on hold.
# Arguments: OBJ($curproc)
# Side Effects: none
# Return Value: none
sub restriction_state_get_hold_reason
{
my ($curproc) = @_;
my $pcb = $curproc->pcb();
return $pcb->get("check_restrictions", "hold_reason");
}
# Descriptions: save reason on isolate.
# Arguments: OBJ($curproc) STR($reason)
# Side Effects: none
# Return Value: none
sub restriction_state_set_isolate_reason
{
my ($curproc, $reason) = @_;
my $pcb = $curproc->pcb();
$pcb->set("check_restrictions", "isolate_reason", $reason);
if ($debug) {
$curproc->logdebug("restriction_state_set_isolate_reason: $reason");
}
}
# Descriptions: return the latest reason on isolate.
# Arguments: OBJ($curproc)
# Side Effects: none
# Return Value: none
sub restriction_state_get_isolate_reason
{
my ($curproc) = @_;
my $pcb = $curproc->pcb();
return $pcb->get("check_restrictions", "isolate_reason");
}
# Descriptions: send message on the latest reason on denial.
# Arguments: OBJ($curproc) STR($type) HASH_REF($msg_args)
# Side Effects: none
# Return Value: none
sub restriction_state_reply_reason
{
my ($curproc, $type, $msg_args) = @_;
my $rule = $curproc->restriction_state_get_deny_reason();
$curproc->logdebug("restriction_state_reply_reason: $rule") if $debug;
if ($rule eq 'reject_system_special_accounts') {
my $r = "deny request from a system account";
$curproc->reply_message_nl("error.system_special_accounts",
$r, $msg_args);
}
elsif ($rule eq 'permit_member_maps') {
my $r = "denied since you are not a member";
if ($type eq 'command_mail') {
$curproc->reply_message_nl("command.deny", $r, $msg_args);
}
my $count = $curproc->error_message_get_count("error.not_member");
unless ($count) {
$curproc->reply_message_nl("error.not_member", $r, $msg_args);
$curproc->error_message_set_count("error.not_member");
}
}
elsif ($rule eq 'permit_user_command') {
my $r = "you are not allowed to use this command.";
$curproc->reply_message_nl("command.deny", $r, $msg_args);
}
elsif ($rule eq 'reject') {
my $r = "deny your request";
if ($type eq 'article_post') {
$curproc->reply_message_nl("error.reject_post", $r, $msg_args);
}
elsif ($type eq 'command_mail') {
$curproc->reply_message_nl("error.reject_command", $r, $msg_args);
}
}
else {
my $r = "deny your request due to an unknown reason";
if ($type eq 'article_post') {
$curproc->reply_message_nl("error.reject_post", $r, $msg_args);
}
elsif ($type eq 'command_mail') {
$curproc->reply_message_nl("error.reject_command", $r, $msg_args);
}
}
}
=head1 ARTICLE STATES
=cut
# Descriptions: set the current article id on current process.
# Arguments: OBJ($curproc) NUM($id)
# Side Effects: update pcb.
# Return Value: NUM
sub article_set_id
{
my ($curproc, $id) = @_;
my $pcb = $curproc->pcb();
$pcb->set("article_message", "id", $id);
}
# Descriptions: get the current article id on current process.
# Arguments: OBJ($curproc)
# Side Effects: none
# Return Value: NUM
sub article_get_id
{
my ($curproc) = @_;
my $pcb = $curproc->pcb();
return $pcb->get("article_message", "id");
}
=head1 COMMAND PROCESSOER STATES
command_context_init() called for each command, so
restriction_state_*() is reset each time.
But in the case of emulatation of listserv/majordomo emulation, we
should pay attention for handlings of $command_mail_restrictions and
$admin_command_mail_restrictions. The restrictions must differ among
mailing lists. So, we do not cache the return value and always check
it each command mail line.
=cut
# Descriptions: parse $orig_command and set up HASH_REF as
# base information for command processing.
# Arguments: OBJ($curproc) STR($orig_command)
# Side Effects: none
# Return Value: OBJ
sub command_context_init
{
my ($curproc, $orig_command) = @_;
# Example: if orig_command = "# help", comname = "help"
use FML::Context::Command;
my $context = new FML::Context::Command $curproc;
$context->set_command($orig_command);
# reset error reason
$curproc->restriction_state_set_deny_reason('');
# declare current mailing list.
my $ml_name = $curproc->ml_name();
$curproc->command_context_set_ml_name($ml_name);
# check if command is valid.
my $found = 0;
my $name = $context->get_cooked_command() || '';
if ($name) {
my $config = $curproc->config();
LIST:
for my $list (qw(anonymous_command_mail_allowed_commands
user_command_mail_allowed_commands)) {
if ($config->has_attribute($list, $name)) {
$found = 1;
last LIST;
}
}
}
# if valid, return the current context (HASH_REF).
if ($found) {
return $context;
}
else {
# return dummy object.
use FML::Context::Command;
my $context = new FML::Context::Command $curproc;
return $context;
}
}
# Descriptions: set the current $ml_name.
# Arguments: OBJ($curproc) STR($ml_name)
# Side Effects: update pcb.
# Return Value: STR
sub command_context_set_ml_name
{
my ($curproc, $ml_name) = @_;
my $pcb = $curproc->pcb();
$pcb->set("process_command", "ml_name", $ml_name);
}
# Descriptions: return the current $ml_name.
# Arguments: OBJ($curproc)
# Side Effects: none
# Return Value: STR
sub command_context_get_ml_name
{
my ($curproc) = @_;
my $pcb = $curproc->pcb();
return( $pcb->get("process_command", "ml_name") || '' );
}
# Descriptions: declare no more further command processing needed
# due to critical error.
# Arguments: OBJ($curproc)
# Side Effects: update pcb.
# Return Value: NUM
sub command_context_set_stop_process
{
my ($curproc) = @_;
my $pcb = $curproc->pcb();
$pcb->set("process_command", "stop_now", 1);
}
# Descriptions: we stop here or not ?
# Arguments: OBJ($curproc)
# Side Effects: none
# Return Value: NUM
sub command_context_get_stop_process
{
my ($curproc) = @_;
my $pcb = $curproc->pcb();
return( $pcb->get("process_command", "stop_now") || 0 );
}
# Descriptions: declare no more further command processing needed.
# Arguments: OBJ($curproc)
# Side Effects: update pcb.
# Return Value: NUM
sub command_context_set_normal_stop
{
my ($curproc) = @_;
my $pcb = $curproc->pcb();
$pcb->set("process_command", "normal_stop", 1);
}
# Descriptions: we stop here or not ?
# Arguments: OBJ($curproc)
# Side Effects: none
# Return Value: NUM
sub command_context_get_normal_stop
{
my ($curproc) = @_;
my $pcb = $curproc->pcb();
return( $pcb->get("process_command", "normal_stop") || 0 );
}
# Descriptions: set "we need to send back confirmation".
# usually, this flag means we send back the original message.
# hence, this flag is universal over plural ML's.
# Arguments: OBJ($curproc)
# Side Effects: update pcb.
# Return Value: NUM
sub command_context_set_need_confirm
{
my ($curproc) = @_;
my $pcb = $curproc->pcb();
# XXX-TODO: correct ? this flag is universal over plural ML's.
$pcb->set("process_command", "need_confirm", 1);
}
# Descriptions: check if we need to send back confirmation ?
# usually, this flag means we send back the original message.
# hence, this flag is universal over plural ML's.
# Arguments: OBJ($curproc)
# Side Effects: none
# Return Value: NUM
sub command_context_get_need_confirm
{
my ($curproc) = @_;
my $pcb = $curproc->pcb();
# XXX-TODO: correct ? this flag is universal over plural ML's.
return( $pcb->get("process_command", "need_confirm") || 0 );
}
# Descriptions: remote administrator is authenticated.
# state is ml specific.
# Arguments: OBJ($curproc)
# Side Effects: update pcb.
# Return Value: NUM
sub command_context_set_admin_auth
{
my ($curproc) = @_;
my $pcb = $curproc->pcb();
my $cur_ml = $curproc->command_context_get_ml_name();
my $class = sprintf("admin_auth_ml_name=%s", $cur_ml);
$pcb->set("process_command", $class, 1);
}
# Descriptions: check if remote administrator is authenticated.
# state is ml specific.
# Arguments: OBJ($curproc)
# Side Effects: none
# Return Value: NUM
sub command_context_get_admin_auth
{
my ($curproc) = @_;
my $pcb = $curproc->pcb();
my $cur_ml = $curproc->command_context_get_ml_name();
my $class = sprintf("admin_auth_ml_name=%s", $cur_ml);
return( $pcb->get("process_command", $class) || 0 );
}
# Descriptions: store password on memory for later use.
# Arguments: OBJ($curproc) STR($password)
# Side Effects: update pcb.
# Return Value: STR
sub command_context_set_admin_password
{
my ($curproc, $password) = @_;
my $pcb = $curproc->pcb();
my $cur_ml = $curproc->command_context_get_ml_name();
my $class = sprintf("admin_password_ml_name=%s", $cur_ml);
$pcb->set("process_command", "admin_password", $password);
}
# Descriptions: retrive stored password on memory.
# Arguments: OBJ($curproc)
# Side Effects: none
# Return Value: STR
sub command_context_get_admin_password
{
my ($curproc) = @_;
my $pcb = $curproc->pcb();
my $cur_ml = $curproc->command_context_get_ml_name();
my $class = sprintf("admin_password_ml_name=%s", $cur_ml);
return( $pcb->get("process_command", "admin_password") || '' );
}
# Descriptions: remote administrator is authenticated.
# state is ml specific.
# Arguments: OBJ($curproc) NUM($req)
# Side Effects: update pcb.
# Return Value: NUM
sub command_context_set_try_admin_auth_request
{
my ($curproc, $req) = @_;
my $pcb = $curproc->pcb();
my $cur_ml = $curproc->command_context_get_ml_name();
my $class = sprintf("try_admin_auth_request_ml_name=%s", $cur_ml);
$pcb->set("process_command", $class, 1);
}
# Descriptions: remote administrator is authenticated.
# state is ml specific.
# Arguments: OBJ($curproc) NUM($req)
# Side Effects: update pcb.
# Return Value: NUM
sub command_context_reset_try_admin_auth_request
{
my ($curproc, $req) = @_;
my $pcb = $curproc->pcb();
my $cur_ml = $curproc->command_context_get_ml_name();
my $class = sprintf("try_admin_auth_request_ml_name=%s", $cur_ml);
$pcb->set("process_command", $class, 0);
}
# Descriptions: check if remote administrator is authenticated.
# state is ml specific.
# Arguments: OBJ($curproc)
# Side Effects: none
# Return Value: NUM
sub command_context_get_try_admin_auth_request
{
my ($curproc) = @_;
my $pcb = $curproc->pcb();
my $cur_ml = $curproc->command_context_get_ml_name();
my $class = sprintf("try_admin_auth_request_ml_name=%s", $cur_ml);
return( $pcb->get("process_command", $class) || 0 );
}
=head1 FILTER STATE
=head2 filter_state_set_error($category, $code)
save the filter error for later use.
=head2 filter_state_get_error($category)
get the filter error.
=cut
# Descriptions: save the filter error for later use.
# Arguments: OBJ($curproc) STR($category) STR($code)
# Side Effects: update pcb.
# Return Value: none
sub filter_state_set_error
{
my ($curproc, $category, $code) = @_;
my $pcb = $curproc->pcb();
$pcb->set("filter_state", $category, $code || 0);
}
# Descriptions: get the filter error.
# Arguments: OBJ($curproc) STR($category)
# Side Effects: update pcb.
# Return Value: none
sub filter_state_get_error
{
my ($curproc, $category) = @_;
my $pcb = $curproc->pcb();
return( $pcb->get("filter_state", $category) || 0 );
}
# Descriptions: save the spam filter error for later use.
# Arguments: OBJ($curproc) STR($code)
# Side Effects: update pcb.
# Return Value: none
sub filter_state_spam_checker_set_error
{
my ($curproc, $code) = @_;
my $category = "spam_checker";
my $pcb = $curproc->pcb();
$pcb->set("filter_state", $category, $code || 0);
}
# Descriptions: get the spam filter error.
# Arguments: OBJ($curproc)
# Side Effects: update pcb.
# Return Value: none
sub filter_state_spam_checker_get_error
{
my ($curproc) = @_;
my $category = "spam_checker";
my $pcb = $curproc->pcb();
return( $pcb->get("filter_state", $category) || 0 );
}
# Descriptions: save the virus filter error for later use.
# Arguments: OBJ($curproc) STR($code)
# Side Effects: update pcb.
# Return Value: none
sub filter_state_virus_checker_set_error
{
my ($curproc, $code) = @_;
my $category = "virus_checker";
my $pcb = $curproc->pcb();
$pcb->set("filter_state", $category, $code || 0);
}
# Descriptions: get the virus filter error.
# Arguments: OBJ($curproc)
# Side Effects: update pcb.
# Return Value: none
sub filter_state_virus_checker_get_error
{
my ($curproc) = @_;
my $category = "virus_checker";
my $pcb = $curproc->pcb();
return( $pcb->get("filter_state", $category) || 0 );
}
# Descriptions: we need to exit as EX_TEMPFAIL.
# Arguments: OBJ($curproc)
# Side Effects: update pcb.
# Return Value: none
sub filter_state_set_tempfail_request
{
my ($curproc) = @_;
my $category = "exit_tempfail";
my $pcb = $curproc->pcb();
$pcb->set("filter_state", $category, 1);
}
# Descriptions: check if we need to exit as EX_TEMPFAIL.
# Arguments: OBJ($curproc)
# Side Effects: none.
# Return Value: NUM
sub filter_state_get_tempfail_request
{
my ($curproc) = @_;
my $category = "exit_tempfail";
my $pcb = $curproc->pcb();
return( $pcb->get("filter_state", $category) || 0 );
}
=head1 SMTP STATE
=head2 smtp_server_state_set_error($mta)
set $mta as error for later hint.
=head2 smtp_server_state_get_error()
check if $mta as error for later hint.
=cut
# Descriptions: set $mta as error for later hint.
# implies "all servers" unless $mta specified.
# Arguments: OBJ($curproc) STR($mta)
# Side Effects: update pcb.
# Return Value: none
sub smtp_server_state_set_error
{
my ($curproc, $mta) = @_;
my $pcb = $curproc->pcb();
$pcb->set("smtp_transaction", $mta || "ALL", "error");
}
# Descriptions: check if $mta as error for later hint.
# implies "all servers" unless $mta specified.
# Arguments: OBJ($curproc) STR($mta)
# Side Effects: update pcb.
# Return Value: NUM(1 or 0)
sub smtp_server_state_get_error
{
my ($curproc, $mta) = @_;
my $pcb = $curproc->pcb();
return( $pcb->get("smtp_transaction", $mta || "ALL") ? 1 : 0 );
}
=head1 UTILITY
=head2 error_message_set_count($class)
increment error count on this class $class to avoid duplicated error
messages.
=head2 error_message_get_count($class)
get error count on this class $class to avoid duplicated error
messages.
=cut
# Descriptions: increment error count on this class $class
# to avoid duplicated error messages.
# hence, this flag is universal over plural ML's.
# Arguments: OBJ($curproc) STR($class)
# Side Effects: none
# Return Value: none
sub error_message_set_count
{
my ($curproc, $class) = @_;
my $pcb = $curproc->pcb();
my $count = $pcb->get("reply_message_count", $class) || 0;
$pcb->set("reply_message_count", $class, $count + 1);
}
# Descriptions: get error count on this class $class
# to avoid duplicated error messages.
# hence, this flag is universal over plural ML's.
# Arguments: OBJ($curproc) STR($class)
# Side Effects: none
# Return Value: none
sub error_message_get_count
{
my ($curproc, $class) = @_;
my $pcb = $curproc->pcb();
return $pcb->get("reply_message_count", $class) || 0;
}
=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) 2004,2005,2006,2008 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::Process::State appeared in fml8 mailing list driver package.
See C<http://www.fml.org/> for more details.
=cut
1;
|