summaryrefslogtreecommitdiff
path: root/build-sqmail
blob: e41ce5660685a97a67bda65ded02b1e9c6ea3c95 (plain)
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
#!/bin/sh

set -eu

name=sqmail
version=4.3.16
upname=${name}_$version.orig.tar.gz
srcname=$name-$version
rel_project_root=$name/$name-$version
abs_project_root=$name-$version/$rel_project_root
orig_project_root=$name-$version.orig/$rel_project_root
qmail_home=etc/qmail
qmail_queue=var/lib/qmail/queue

if ! [ -e $name-$version.tgz ]
then
  wget https://www.fehcom.de/$name/$name-$version.tgz
  ln -sf $name-$version.tgz $upname
fi
tar -xf $upname
mv mail $srcname
cd $srcname
debmake --email jannis@fehcom.de --fullname 'Jannis M. Hoffmann' -b sqmail,sqmail-users

patch debian/control <<'END'
2c2
< Section: unknown
---
> Section: mail
5c5
< Build-Depends: debhelper-compat (= 13)
---
> Build-Depends: debhelper-compat (= 13), dh-exec, libqlibs, libucspissl-dev
7c7
< Homepage: <insert the upstream URL, if relevant>
---
> Homepage: https://www.fehcom.de/sqmail/sqmail.html
15c15
< Depends: ${misc:Depends}, ${shlibs:Depends}
---
> Depends: ${misc:Depends}, ${shlibs:Depends}, sqmail-users, ucspissl
15a16,18
> Provides: mail-transport-agent
> Conflicts: mail-transport-agent
> Replaces: mail-transport-agent
END

cat <<END >debian/rules
#!/usr/bin/make -f
# You must remove unused comment lines for the released package.
export DH_VERBOSE = 1
#export DEB_BUILD_MAINT_OPTIONS = hardening=+all
export DEB_CFLAGS_MAINT_APPEND  = -g
#export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed

%:
	dh \$@ --buildsystem=none

override_dh_auto_clean:
	rm -f $rel_project_root/src/ssl.lib
	rm -f $rel_project_root/conf-cc
	\$(MAKE) -C $rel_project_root/src clean

override_dh_auto_configure:
	echo "-lssl -lcrypto" >$rel_project_root/src/ssl.lib
	echo "\$(CC) -Iinclude $(pkg-config -cflags qlibs) \$(CFLAGS)" >$rel_project_root/conf-cc
	\$(MAKE) -C $rel_project_root/src auto-uid
	\$(MAKE) -C $rel_project_root/src auto-gid
	cp debian/contrib/auto_uids.c $rel_project_root/src/

override_dh_auto_build:
	\$(MAKE) -C $rel_project_root/src default

override_dh_auto_install:
	dh_installsysusers
END

# tcp-environ.5 conflicts with ucspitcp6 package
cat <<END >debian/sqmail.manpages
$rel_project_root/man/*.[13789]
$rel_project_root/man/addresses.5
$rel_project_root/man/envelopes.5
$rel_project_root/man/maildir.5
$rel_project_root/man/mbox.5
$rel_project_root/man/qmail-header.5
$rel_project_root/man/qmail-log.5
$rel_project_root/man/tai64nfrac.5
END

cat <<END >debian/sqmail.install
# base
$rel_project_root/src/qmail-clean          usr/bin
$rel_project_root/src/qmail-inject         usr/bin
$rel_project_root/src/qmail-local          usr/bin
$rel_project_root/src/qmail-lspawn         usr/bin
$rel_project_root/src/qmail-send           usr/bin
$rel_project_root/src/qmail-queue          usr/bin
$rel_project_root/src/qmail-rspawn         usr/bin
$rel_project_root/src/qmail-start          usr/bin
$rel_project_root/src/qmail-todo           usr/bin

# clients
$rel_project_root/src/mailsubj             usr/bin
$rel_project_root/src/qmail-remote         usr/bin
$rel_project_root/src/qmail-qmqpc          usr/bin
$rel_project_root/src/sendmail             usr/bin

# control
$rel_project_root/src/qmail-mfrules        usr/bin
$rel_project_root/src/qmail-showctl        usr/bin
$rel_project_root/src/qmail-badloadertypes usr/bin
$rel_project_root/src/qmail-badmimetypes   usr/bin
$rel_project_root/src/qmail-recipients     usr/bin

# dkim
$rel_project_root/src/qmail-dkim           usr/bin
$rel_project_root/src/qmail-dksign         usr/bin

# dns
$rel_project_root/src/dnscname             usr/bin
$rel_project_root/src/dnsfq                usr/bin
$rel_project_root/src/dnsip                usr/bin
$rel_project_root/src/dnsmxip              usr/bin
$rel_project_root/src/dnsptr               usr/bin
$rel_project_root/src/dnstlsa              usr/bin
$rel_project_root/src/dnstxt               usr/bin
$rel_project_root/src/hostname             usr/bin
$rel_project_root/src/ipmeprint            usr/bin
$rel_project_root/src/spfquery             usr/bin

# forward
$rel_project_root/src/fastforward          usr/bin
$rel_project_root/src/forward              usr/bin
$rel_project_root/src/setforward           usr/bin
$rel_project_root/src/newaliases           usr/bin
$rel_project_root/src/newinclude           usr/bin
$rel_project_root/src/printforward         usr/bin
$rel_project_root/src/printmaillist        usr/bin
$rel_project_root/src/setmaillist          usr/bin

# log
$rel_project_root/src/qmail-mrtg           usr/bin
$rel_project_root/src/qmail-mrtg-queue     usr/bin
$rel_project_root/src/splogger             usr/bin
$rel_project_root/src/tai64nfrac           usr/bin

# mbox
$rel_project_root/src/condredirect         usr/bin
$rel_project_root/src/bouncesaying         usr/bin
$rel_project_root/src/except               usr/bin
$rel_project_root/src/maildirmake          usr/bin
$rel_project_root/src/maildir2mbox         usr/bin
$rel_project_root/src/maildirwatch         usr/bin
$rel_project_root/src/preline              usr/bin
$rel_project_root/src/qbiff                usr/bin
$rel_project_root/src/qreceipt             usr/bin

# pam
$rel_project_root/src/qmail-authuser       usr/bin
$rel_project_root/src/qmail-smtpam         usr/bin
$rel_project_root/src/qmail-vmailuser      usr/bin
$rel_project_root/src/qmail-postgrey       usr/bin

# pop
$rel_project_root/src/qmail-pop3d          usr/bin
$rel_project_root/src/qmail-popup          usr/bin

# queue
$rel_project_root/src/qmail-qread          usr/bin
$rel_project_root/src/qmail-qstat          usr/bin
$rel_project_root/src/qmail-tcpok          usr/bin
$rel_project_root/src/qmail-tcpto          usr/bin
$rel_project_root/src/qmail-qmaint         usr/bin

# recipients
#$rel_project_root/src/qmail-alias2recipients usr/bin

# scan
#$rel_project_root/src/qmail-queue-scan     usr/bin

# server
$rel_project_root/src/qmail-qmtpd          usr/bin
$rel_project_root/src/qmail-qmqpd          usr/bin
$rel_project_root/src/qmail-smtpd          usr/bin

# srs
$rel_project_root/src/srsforward           usr/bin
$rel_project_root/src/srsreverse           usr/bin

# user
$rel_project_root/src/qmail-getpw          usr/bin
$rel_project_root/src/qmail-newu           usr/bin
$rel_project_root/src/qmail-newmrh         usr/bin
$rel_project_root/src/qmail-pw2u           usr/bin

# x509
#$rel_project_root/src/x509fingerprint      usr/bin
#$rel_project_root/src/mkdkimkey            usr/bin

# analog
$rel_project_root/src/columnt              usr/bin
$rel_project_root/src/ddist                usr/bin
$rel_project_root/src/deferrals            usr/bin
$rel_project_root/src/failures             usr/bin
$rel_project_root/src/matchup              usr/bin
$rel_project_root/src/recipients           usr/bin
$rel_project_root/src/rhosts               usr/bin
$rel_project_root/src/rxdelay              usr/bin
$rel_project_root/src/senders              usr/bin
$rel_project_root/src/successes            usr/bin
$rel_project_root/src/suids                usr/bin
$rel_project_root/src/xqp                  usr/bin
$rel_project_root/src/xrecipient           usr/bin
$rel_project_root/src/xsender              usr/bin
$rel_project_root/src/zddist               usr/bin
$rel_project_root/src/zdeferrals           usr/bin
$rel_project_root/src/zfailures            usr/bin
$rel_project_root/src/zoverall             usr/bin
$rel_project_root/src/zrecipients          usr/bin
$rel_project_root/src/zrhosts              usr/bin
$rel_project_root/src/zrxdelay             usr/bin
$rel_project_root/src/zsenders             usr/bin
$rel_project_root/src/zsendmail            usr/bin
$rel_project_root/src/zsuccesses           usr/bin
$rel_project_root/src/zsuids               usr/bin

# other
$rel_project_root/src/qmail-dkverify       usr/bin

$rel_project_root/ctl/*                    etc/qmail/control

debian/contrib/sqmail-send.service         usr/lib/systemd/system
debian/contrib/sqmail-smtpd.service        usr/lib/systemd/system
END

mkdir debian/contrib
cat <<END >debian/contrib/convert_ids.awk
# Format of sqmail/$srcname/conf-ids is 'uid:name:description:group:home'
BEGIN { FS = ":"; OFS = "\t"; print "# Generated by 'convert_ids.awk'; DO NOT EDIT!" }
/^#/ { next }
\$3 ~ /group/ { print "g", \$2, \$1; next }
\$3 ~ /user/ {
  if (\$5) print "u", \$2, \$1":"\$4, "\""\$3"\"", "/$qmail_home/"\$5
  else     print "u", \$2, \$1":"\$4, "\""\$3"\""
  next
}
{ exit 1 }
END
awk -f debian/contrib/convert_ids.awk sqmail/$srcname/conf-ids | expand -t 3,12,26,50 >debian/sqmail-users.sysusers

cat <<'END' >debian/contrib/sqmail-send.service
[Unit]
Description=qmail delivery daemon
After=network-online.target 

[Service]
ExecStart=qmail-start ./Maildir/

[Install]
WantedBy=multi-user.target
END

cat <<'END' >debian/contrib/sqmail-smtpd.service
[Unit]
Description=qmail delivery daemon
After=network-online.target

[Service]
User=qmaild
AmbientCapabilities=cap_net_bind_service
Environment=UCSPITLS="" SPF="1" DHFILE="/usr/share/ucspi-ssl/dh2048.pem"
ExecStart=sslserver -seVn -Rp -l %H -Xx /etc/qmail/control/rules.smtpd.cdb :0 smtp qmail-smtpd
ExecReload=qmail-tcpok
ExecReload=/bin/kill -ALRM $MAINPID

[Install]
WantedBy=multi-user.target
END

cat <<'END' >debian/contrib/auto_uids.c
int auto_uida = 7790;
int auto_uidd = 7791;
int auto_uidl = 7792;
int auto_uido = 0;
int auto_uidp = 7793;
int auto_uidq = 7794;
int auto_uidr = 7795;
int auto_uids = 7796;
int auto_gidq = 2109;
int auto_gidn = 2108;
END

cat <<END >debian/clean
$rel_project_root/src/auto_break.c
$rel_project_root/src/install
$rel_project_root/src/instcheck
$rel_project_root/src/libqdkim.a
$rel_project_root/src/predate
$rel_project_root/src/qmail-dksign
$rel_project_root/src/qmail-dkverify
$rel_project_root/src/srsforward
$rel_project_root/src/srsreverse
$rel_project_root/src/auto_usera.c
$rel_project_root/src/config
$rel_project_root/src/config-fast
$rel_project_root/src/datemail
$rel_project_root/src/hasspnam.h
$rel_project_root/src/hasutmp.h
END

cat <<END >debian/sqmail.links
/usr/bin/     $qmail_home/bin
END

cat <<END >debian/sqmail.postinst
#!/bin/sh
# postinst script for #PACKAGE#
#
# See: dh_installdeb(1).

set -e

# Summary of how this script can be called:
#        * <postinst> 'configure' <most-recently-configured-version>
#        * <old-postinst> 'abort-upgrade' <new version>
#        * <conflictor's-postinst> 'abort-remove' 'in-favour' <package>
#          <new-version>
#        * <postinst> 'abort-remove'
#        * <deconfigured's-postinst> 'abort-deconfigure' 'in-favour'
#          <failed-install-package> <version> 'removing'
#          <conflicting-package> <version>
# for details, see https://www.debian.org/doc/debian-policy/ or
# the debian-policy package.


case "\$1" in
    configure)
        install -d           -g sqmail  $qmail_home
        install -d           -g sqmail  $qmail_home/control
        install -d -o alias  -g sqmail  $qmail_home/alias
        install -d -o sqmtls -g nofiles $qmail_home/ssl
        install -d           -g sqmail  $qmail_home/users

        hostname >$qmail_home/control/me
        hostname >$qmail_home/control/rcpthosts

	chown       :sqmail usr/bin/qmail-authuser
	chmod ug+s          usr/bin/qmail-authuser
	chown qmailq:sqmail usr/bin/qmail-dksign
	chmod u+s           usr/bin/qmail-dksign
	chown qmailq:sqmail usr/bin/qmail-dkverify
	chmod u+s           usr/bin/qmail-dkverify
	chown       :sqmail usr/bin/qmail-postgrey
	chmod ug+s          usr/bin/qmail-postgrey
	chown qmailq:sqmail usr/bin/qmail-queue
	chmod ug+s          usr/bin/qmail-queue
	chown       :sqmail usr/bin/qmail-vmailuser
	chmod ug+s          usr/bin/qmail-vmailuser

        install -d -o qmailq -g sqmail -m 750 $qmail_queue
        install -d -o qmails -g sqmail -m 700 $qmail_queue/bounce
        install -d -o qmailq -g sqmail -m 750 $qmail_queue/dkim
        install -d -o qmails -g sqmail -m 700 $qmail_queue/info
        install -d -o qmailq -g sqmail -m 700 $qmail_queue/intd
        install -d -o qmails -g sqmail -m 700 $qmail_queue/local
        install -d -o qmailq -g sqmail -m 750 $qmail_queue/lock
        install -d -o qmailq -g sqmail -m 750 $qmail_queue/mess
        install -d -o qmailq -g sqmail -m 700 $qmail_queue/pid

	for i in \$(seq 0 22)
	do
                install -d -o qmailq -g sqmail $qmail_queue/dkim/\$i
                install -d -o qmails -g sqmail $qmail_queue/info/\$i
                install -d -o qmailq -g sqmail $qmail_queue/intd/\$i
                install -d -o qmails -g sqmail $qmail_queue/local/\$i
                install -d -o qmailq -g sqmail $qmail_queue/mess/\$i
                install -d -o qmails -g sqmail $qmail_queue/remote/\$i
                install -d -o qmailq -g sqmail $qmail_queue/todo/\$i
        done

        touch               $qmail_queue/lock/sendmutex
        chown qmails:sqmail $qmail_queue/lock/sendmutex
        chmod           600 $qmail_queue/lock/sendmutex

        touch               $qmail_queue/lock/tcpto
        chown qmailr:sqmail $qmail_queue/lock/tcpto
        chmod           644 $qmail_queue/lock/tcpto
        fallocate -l 1024   $qmail_queue/lock/tcpto

        [ -p $qmail_queue/lock/trigger ] || mkfifo $qmail_queue/lock/trigger
        chown qmails:sqmail $qmail_queue/lock/trigger
        chmod           622 $qmail_queue/lock/trigger
    ;;

    abort-upgrade|abort-remove|abort-deconfigure)
    ;;

    *)
        echo "postinst called with unknown argument '\$1'" >&2
        exit 1
    ;;
esac

# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

exit 0
END

cat <<END >debian/sqmail.postrm
#!/bin/sh
# postrm script for #PACKAGE#.
#
# See: dh_installdeb(1).

set -e

# Summary of how this script can be called:
#        * <postrm> 'remove'
#        * <postrm> 'purge'
#        * <old-postrm> 'upgrade' <new-version>
#        * <new-postrm> 'failed-upgrade' <old-version>
#        * <new-postrm> 'abort-install'
#        * <new-postrm> 'abort-install' <old-version>
#        * <new-postrm> 'abort-upgrade' <old-version>
#        * <disappearer's-postrm> 'disappear' <overwriter>
#          <overwriter-version>
# for details, see https://www.debian.org/doc/debian-policy/ or
# the debian-policy package.


case "\$1" in
    remove|upgrade|failed-upgrade|abort-install|abort-upgrade|disappear)
    ;;

    purge)
        rm -rf $qmail_home
        rm -rf ${qmail_queue%/queue}
    ;;

    *)
        echo "postrm called with unknown argument '\$1'" >&2
        exit 1
    ;;
esac

# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

exit 0
END

cat <<END >debian/patches/000-config.patch
Author: Jannis M. Hoffmann
Description: change queue directory

--- $orig_project_root/conf-queue
+++ $abs_project_root/conf-queue
@@ -1,3 +1,3 @@
-/var/qmail
+/var/lib/qmail
 
 # Note: ./queue/ is added automatically!

--- $orig_project_root/conf-home
+++ $abs_project_root/conf-home
@@ -1,4 +1,4 @@
-/var/qmail
+/etc/qmail
 
 # This is the sqmail home directory. It must be a local directory, not
 # shared among machines. The mail queue may reside at a different directory. e.g.:

END

cat <<END >debian/patches/000-make-ucspissl.patch
Author: Jannis M. Hoffmann
Description: replace direct ucspissl.a with libucspissl

--- $orig_project_root/src/Makefile
+++ $abs_project_root/src/Makefile
@@ -1051,11 +1051,11 @@ qmail-remote: \\
 load qmail-remote.o control.o tcpto.o now.o dns.o ipalloc.o ipme.o \\
 quote.o tls_timeoutio.o tls_errors.o tls_remote.o dns_tlsa.o \\
 base64.o constmap.o md5c.o hmac_md5.o auto_qmail.o auto_queue.o \\
-ssl.lib dns.lib socket.lib qlibs.lib idn2.lib ucspissl.a
+ssl.lib dns.lib socket.lib qlibs.lib idn2.lib
 	./load qmail-remote control.o tcpto.o now.o \\
 	base64.o constmap.o hmac_md5.o md5c.o ipalloc.o ipme.o \\
 	quote.o dns.o auto_qmail.o auto_queue.o dns_tlsa.o \\
-	tls_errors.o tls_remote.o tls_timeoutio.o ucspissl.a \\
+	tls_errors.o tls_remote.o tls_timeoutio.o -lucspissl \\
 	\`cat ssl.lib\` \`cat dns.lib\` \`cat socket.lib\` \`cat qlibs.lib\` \`cat idn2.lib\`
 
 qmail-remote.o: \\
@@ -1098,10 +1098,10 @@ qmail-smtpam: \\
 load qmail-smtpam.o control.o now.o dns.o constmap.o \\
 ipalloc.o ipme.o quote.o auto_qmail.o auto_queue.o tcpto.o \\
 tls_timeoutio.o tls_errors.o tls_remote.o dns_tlsa.o \\
-ssl.lib dns.lib socket.lib qlibs.lib ucspissl.a
+ssl.lib dns.lib socket.lib qlibs.lib
 	./load qmail-smtpam constmap.o control.o dns_tlsa.o \\
 	tcpto.o now.o dns.o ipalloc.o ipme.o quote.o auto_qmail.o \\
-	auto_queue.o tls_errors.o tls_remote.o tls_timeoutio.o ucspissl.a \\
+	auto_queue.o tls_errors.o tls_remote.o tls_timeoutio.o -lucspissl \\
 	\`cat ssl.lib\` \`cat dns.lib\` \`cat socket.lib\` \`cat qlibs.lib\` 
 
 qmail-smtpam.o: \\
END

printf "000-config.patch\n000-make-ucspissl.patch\n" >>debian/patches/series

rm debian/source/control debian/tests/control