This file is indexed.

/usr/lib/x86_64-linux-gnu/perl5/5.26/Sendmail/sample.pl is in libsendmail-milter-perl 0.18-8build3.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
use ExtUtils::testlib;

use Sendmail::Milter;
use Socket;

#
#  Each of these callbacks is actually called with a first argument
#  that is blessed into the pseudo-package Sendmail::Milter::Context. You can
#  use them like object methods of package Sendmail::Milter::Context.
#
#  $ctx is a blessed reference of package Sendmail::Milter::Context to something
#  yucky, but the Mail Filter API routines are available as object methods
#  (sans the smfi_ prefix) from this
#

sub connect_callback
{
	my $ctx = shift;	# Some people think of this as $self
	my $hostname = shift;
	my $sockaddr_in = shift;
	my ($port, $iaddr);

	print "my_connect:\n";
	print "   + hostname: '$hostname'\n";

	if (defined $sockaddr_in)
	{
		($port, $iaddr) = sockaddr_in($sockaddr_in);
		print "   + port: '$port'\n";
		print "   + iaddr: '" . inet_ntoa($iaddr) . "'\n";
	}

	print "   + callback completed.\n";

	return SMFIS_CONTINUE;
}

sub helo_callback
{
	my $ctx = shift;
	my $helohost = shift;

	print "my_helo:\n";
	print "   + helohost: '$helohost'\n";

	print "   + callback completed.\n";

	return SMFIS_CONTINUE;
}

sub envfrom_callback
{
	my $ctx = shift;
	my @args = @_;
	my $message = "";

	print "my_envfrom:\n";
	print "   + args: '" . join(', ', @args) . "'\n";

	$ctx->setpriv(\$message);
	print "   + private data allocated.\n";

	print "   + callback completed.\n";

	return SMFIS_CONTINUE;
}

sub envrcpt_callback
{
	my $ctx = shift;
	my @args = @_;

	print "my_envrcpt:\n";
	print "   + args: '" . join(', ', @args) . "'\n";

	print "   + callback completed.\n";

	return SMFIS_CONTINUE;
}

sub header_callback
{
	my $ctx = shift;
	my $headerf = shift;
	my $headerv = shift;

	print "my_header:\n";
	print "   + field: '$headerf'\n";
	print "   + value: '$headerv'\n";

	print "   + callback completed.\n";

	return SMFIS_CONTINUE;
}

sub eoh_callback
{
	my $ctx = shift;

	print "my_eoh:\n";
	print "   + callback completed.\n";

	return SMFIS_CONTINUE;
}

sub body_callback
{
	my $ctx = shift;
	my $body_chunk = shift;
	my $len = shift;
	my $message_ref = $ctx->getpriv();

	# Note: You don't need $len to have a good time.
	# But it's there if you like.

	print "my_body:\n";
	print "   + chunk len: $len\n";

	${$message_ref} .= $body_chunk;

	$ctx->setpriv($message_ref);

	print "   + callback completed.\n";

	return SMFIS_CONTINUE;
}

sub eom_callback
{
	my $ctx = shift;
	my $message_ref = $ctx->getpriv();
	my $chunk;

	print "my_eom:\n";
	print "   + adding line to message body...\n";

	# Let's have some fun...
	# Note: This doesn't support messages with MIME data.

	# Pig-Latin, Babelfish, Double dutch, soo many possibilities!
	# But we're boring...

	${$message_ref} .= "---> Append me to this message body!\r\n";

	if (not $ctx->replacebody(${$message_ref}))
	{
		print "   - write error!\n";
		last;
	}

	$ctx->setpriv(undef);
	print "   + private data cleared.\n";

	print "   + callback completed.\n";

	return SMFIS_CONTINUE;
}

sub abort_callback
{
	my $ctx = shift;

	print "my_abort:\n";

	$ctx->setpriv(undef);
	print "   + private data cleared.\n";

	print "   + callback completed.\n";

	return SMFIS_CONTINUE;
}

sub close_callback
{
	my $ctx = shift;

	print "my_close:\n";
	print "   + callback completed.\n";

	return SMFIS_CONTINUE;
}

my %my_callbacks =
(
	'connect' =>	\&connect_callback,
	'helo' =>	\&helo_callback,
	'envfrom' =>	\&envfrom_callback,
	'envrcpt' =>	\&envrcpt_callback,
	'header' =>	\&header_callback,
	'eoh' =>	\&eoh_callback,
	'body' =>	\&body_callback,
	'eom' =>	\&eom_callback,
	'abort' =>	\&abort_callback,
	'close' =>	\&close_callback,
);

BEGIN:
{
	if (scalar(@ARGV) < 2)
	{
		print "Usage: perl $0 <name_of_filter> <path_to_sendmail.cf>\n";
		exit;
	}

	my $conn = Sendmail::Milter::auto_getconn($ARGV[0], $ARGV[1]);

	print "Found connection info for '$ARGV[0]': $conn\n";

	if ($conn =~ /^local:(.+)$/)
	{
		my $unix_socket = $1;

		if (-e $unix_socket)
		{
			print "Attempting to unlink UNIX socket '$conn' ... ";

			if (unlink($unix_socket) == 0)
			{
				print "failed.\n";
				exit;
			}
			print "successful.\n";
		}
	}

	if (not Sendmail::Milter::auto_setconn($ARGV[0], $ARGV[1]))
	{
		print "Failed to detect connection information.\n";
		exit;
	}

	#
	#  The flags parameter is optional. SMFI_CURR_ACTS sets all of the
	#  current version's filtering capabilities.
	#
	#  %Sendmail::Milter::DEFAULT_CALLBACKS is provided for you in getting
	#  up to speed quickly. I highly recommend creating a callback table
	#  of your own with only the callbacks that you need.
	#

	if (not Sendmail::Milter::register($ARGV[0], \%my_callbacks,
		SMFI_CURR_ACTS))
	{
		print "Failed to register callbacks for $ARGV[0].\n";
		exit;
	}

	print "Starting Sendmail::Milter $Sendmail::Milter::VERSION engine.\n";

	if (Sendmail::Milter::main())
	{
		print "Successful exit from the Sendmail::Milter engine.\n";
	}
	else
	{
		print "Unsuccessful exit from the Sendmail::Milter engine.\n";
	}
}