-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
indimail-auth.spec.in
442 lines (394 loc) · 13.8 KB
/
indimail-auth.spec.in
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
#
#
# $Id: indimail.spec.in,v 1.34 2020-05-27 12:43:42+05:30 Cprogrammer Exp mbhangui $
%undefine _missing_build_ids_terminate_build
%global _unpackaged_files_terminate_build 1
%if %{defined _project}
# define if building on openSUSE build service
%global build_on_obs 1
%global build_cflags "-DOBS_BUILD %{build_cflags}"
%else
%define _project local
%global build_on_obs 0
%global _hardened_build 1
%endif
#global nodebug 1
%if %{defined nodebug}
%global debug_package %{nil}
%endif
%global _prefix @prefix@
%global sysconfdir @sysconfdir@
%global shareddir @shareddir@
%global libexecdir @libexecdir@
%global mandir @mandir@
%global nssd_version @nssd_version@
%global pam_multi_version @pam_multi_version@
%global url https://github.com/mbhangui/indimail-virtualdomains
%global logdir @logdir@
%global servicedir @servicedir@
%global pam_confdir @pam_confdir@
%global pam_moduledir /%{_lib}/security
%global mysqlPrefix /usr
%global mysqlSocket /var/run/mysqld/mysqld.sock
%global defaultDomain @defaultDomain@
# Packages which do not use autosetup or setup macro
# in the prep section have a problem in enabling debuginfo.
# This isn't documented clearly anywhere. A workaround is
# to define buildsubdir
%if %{undefined nodebug}
%global buildsubdir %{name}-%{version}
%endif
%if %build_on_obs == 1
%global packager Manvendra Bhangui <@email@>
%endif
Summary: PAM and Name Service Switch for IndiMail
Name: indimail-auth
Version: @version@
Release: @release@%{?dist}
%if %build_on_obs == 1
License: GPL-3.0+
%else
License: GPLv3
%endif
%if %{undefined suse_version} && %{undefined sles_version}
Group: System Environment/Base
%else
Group: Productivity/Networking/Email/Servers
%endif
Source1: http:https://downloads.sourceforge.net/indimail/nssd-%{nssd_version}.tar.gz
Source2: http:https://downloads.sourceforge.net/indimail/pam-multi-%{pam_multi_version}.tar.gz
Source3: http:https://downloads.sourceforge.net/indimail/%{name}-rpmlintrc
URL: https://github.com/mbhangui/indimail-virtualdomains
AutoReqProv: Yes
# few binaries were moved to sbin and indimail >= 2.5 depends on that
BuildRequires: gcc gcc-c++ make autoconf automake libtool
BuildRequires: glibc glibc-devel procps binutils
BuildRequires: sed findutils gzip coreutils grep
BuildRequires: pam-devel libqmail-devel libqmail
%if %{defined amzn}
BuildRequires: mariadb-connector-c-devel
%else
BuildRequires: mysql-devel
%endif
################################# OBS ###############################
%if %build_on_obs == 1
%if 0%{?suse_version}
BuildRequires: -post-build-checks
#!BuildIgnore: post-build-checks
#!BuildIgnore: brp-check-suse
%endif
%endif
################################# OBS ###############################
Requires: procps /usr/bin/awk /usr/bin/which
Requires: sed findutils
Requires: coreutils grep /bin/sh glibc
Requires: /usr/bin/hostname
Requires: pam indimail-mta
Conflicts: indimail < 3.2
Requires: user(qmaill)
Requires: group(nofiles)
%if %build_on_obs == 0
Requires(pre): shadow-utils
Requires(postun): shadow-utils
%endif
%description
indimail-auth provides nssd daemon to provide name service switch
in MySQL db and pam-multi to provide multiple PAM authentication
methods
For more details visit %{url}
%prep
%{__mkdir_p} %{_builddir}/%{name}-%{version}
cd %{_builddir}/%{name}-%{version}
for i in nssd-%{nssd_version} pam-multi-%{pam_multi_version}
do
(
if [ -d $i ] ; then
%{__rm} -rf $i
fi
if [ -f ../../SOURCES/$i.tar.bz2 ] ; then
%{__bzip2} -d -c ../../SOURCES/$i.tar.bz2 | tar xf -
elif [ -f ../../SOURCES/$i.tar.xz ] ; then
xz -d -c ../../SOURCES/$i.tar.xz |tar xf -
elif [ -f ../../SOURCES/$i.tar.gz ] ; then
gunzip -c ../../SOURCES/$i.tar.gz | tar xf -
else
echo "No Source Archive for $i"
exit 1
fi
)
done
%build
cd %{_builddir}/%{name}-%{version}
(
echo "---------------- INFORMATION ------------------------"
echo target %_target
echo target_alias %_target_alias
echo target_cpu %_target_cpu
echo target_os %_target_os
echo target_vendor %_target_vendor
echo PAM Module dir %{pam_moduledir}
echo Building %{name}-%{version}-%{release} Build %{_build} OS %{_os} lib=%{_lib} libdir=%{_libdir}
echo "------------------------------------------------------"
) > %{name}-rpm.info
(
echo "NAME=%{name}"
echo "Description=\"IndiMail Authentication Package\""
echo "AUTH_version=%{version}-%{release}"
echo "ID=%{name}"
echo "HOME_URL=\"https://github.com/mbhangui/indimail-virtualdomains\""
echo "PACKAGE_BUGREPORT=\"'@email@'\""
) > %{name}-release
%if %build_on_obs == 0
if [ -x /usr/bin/uname -o -x /bin/uname ] ; then
default_domain=$(echo $([ -n "$HOSTNAME" ] && echo "$HOSTNAME" || uname -n) | sed 's/^\([^\.]*\)\.\([^\.]*\)\./\2\./')
else
default_domain=$([ -n "$HOSTNAME" ] && echo "$HOSTNAME" | sed 's/^\([^\.]*\)\.\([^\.]*\)\./\2\./' || echo %{defaultDomain})
fi
%else
default_domain=%{defaultDomain}
%endif
#### nssd ######################
if [ -d nssd-%{nssd_version} ] ; then
cd nssd-%{nssd_version}
if [ -d /run ] ; then
nssd_sock=/run/indimail/pwdlookup/nssd.sock
elif [ -d /var/run ] ; then
nssd_sock=/var/run/indimail/pwdlookup/nssd.sock
else
nssd_sock=/tmp/pwdlookup/nssd.sock
fi
%configure --prefix=%{_prefix} --libexecdir=%{libexecdir} --sysconfdir=%{sysconfdir} \
--mandir=%{mandir} --libdir=%{_libdir} --datarootdir=%{shareddir} \
--enable-nssd-socket=$nssd_sock \
--enable-nssd-config-path=%{sysconfdir}/nssd.conf \
--enable-mysqlprefix=%{mysqlPrefix} \
--enable-dlload-mysql=yes --enable-default-domain=$default_domain
cd ..
fi
#### pam-multi ######################
if [ -d pam-multi-%{pam_multi_version} ] ; then
cd pam-multi-%{pam_multi_version}
%configure --prefix=%{_prefix} --datarootdir=%{shareddir} \
--mandir=%{mandir} --enable-moduledir=%{pam_moduledir} \
--enable-controldir=%{sysconfdir}/control \
--enable-pamconfdir=%{pam_confdir} \
--enable-mysqlprefix=%{mysqlPrefix} \
--enable-dlload-mysql=yes --enable-default-domain=$default_domain
cd ..
fi
%install
cd %{_builddir}/%{name}-%{version}
for i in nssd-%{nssd_version} pam-multi-%{pam_multi_version}
do
if [ -d $i ] ; then
cd $i
%{__make} -s %{?_smp_mflags}
%if %{defined nodebug}
%{__make} -s %{?_smp_mflags} DESTDIR=%{buildroot} install-strip
%else
%{__make} -s %{?_smp_mflags} DESTDIR=%{buildroot} install
%endif
cd ..
fi
done
%{__mkdir_p} %{buildroot}%{sysconfdir}
install -m 0644 %{name}-rpm.info %{buildroot}%{sysconfdir}/%{name}-rpm.info
install -m 0644 %{name}-release %{buildroot}%{sysconfdir}/%{name}-release
/bin/rm -f %{name}-rpm.info %{name}-release
# nssd
%{__rm} -f %{buildroot}%{_libdir}/libnss_nssd.la
%{__rm} -f %{buildroot}%{_libdir}/libnss_nssd.so
# pam-multi
%{__rm} -f %{buildroot}%{pam_moduledir}/pam-multi.la
%{__rm} -f %{buildroot}%{pam_moduledir}/pam-multi.a
if [ -x /bin/touch ] ; then
touch=/bin/touch
elif [ -x /usr/bin/touch ] ; then
touch=/usr/bin/touch
else
touch=/bin/touch
fi
$touch %{buildroot}%{sysconfdir}/nssd.conf
%if %{undefined suse_version} && %{undefined sles_version}
%{__mkdir_p} %{buildroot}%{logdir}/pwdlookup
touch %{buildroot}%{logdir}/pwdlookup/current
%endif
# Compress the man pages
find %{buildroot}%{mandir} -type f -exec gzip -q {} \;
%if %{undefined nodebug}
chmod -R 755 %{buildroot}%{_prefix}/sbin %{buildroot}%{_libdir} \
%{buildroot}/%{pam_moduledir}
ln -sf %{_builddir}/%{name}-%{version}/debugsourcefiles.list %{_builddir}/debugsourcefiles.list
%endif
%files
%defattr(-, root, root,-)
#
# Directories
#
%if %{undefined suse_version} && %{undefined sles_version}
%ghost %dir %attr(0755,qmaill,nofiles) %{logdir}
%ghost %dir %attr(0755,qmaill,nofiles) %{logdir}/pwdlookup
%ghost %attr(-,qmaill,nofiles) %{logdir}/pwdlookup/*
%endif
%ghost %attr(0640,root,qmail) %config(noreplace,missingok) %{sysconfdir}/nssd.conf
%attr(644,root,root) %{sysconfdir}/%{name}-rpm.info
%attr(644,root,root) %{sysconfdir}/%{name}-release
%attr(755,root,root) %{_prefix}/sbin/nssd
%attr(755,root,root) %{libexecdir}/check_getpw
# pam-multi
%attr(755,root,root) %{_prefix}/sbin/pam-checkpwd
%attr(644,root,root) %config(noreplace) %{pam_confdir}/pam-multi
%attr(640,root,indimail) %config(noreplace) %{pam_confdir}/pop3
%attr(640,root,indimail) %config(noreplace) %{pam_confdir}/imap
%docdir %{shareddir}/doc
%docdir %{mandir}
%attr(644,root,root) %{mandir}/man[1,5,7,8]/*
%if %build_on_obs == 0
%license %attr(644,root,root) %{shareddir}/doc/COPYING-nssd
%license %attr(644,root,root) %{shareddir}/doc/COPYING-pam-multi
%else
%attr(644,root,root) %{shareddir}/doc/COPYING-nssd
%attr(644,root,root) %{shareddir}/doc/COPYING-pam-multi
%endif
%attr(644,root,root) %{shareddir}/doc/AUTHORS-nssd
%attr(644,root,root) %{shareddir}/doc/AUTHORS-pam-multi
%attr(644,root,root) %{shareddir}/doc/README-nssd.md
%attr(644,root,root) %{shareddir}/doc/README-pam-multi.md
# Shared libraries (omit for architectures that don't support them)
# pam-multi
%attr(755,root,root) /%{pam_moduledir}/pam-multi.so
%attr(755,root,root) %{_libdir}/libnss_nssd.so.2.0.0
%{_libdir}/libnss_nssd.so.2
%clean
%if %{undefined nodebug}
%{__rm} -f %{_builddir}/debugfiles.list %{_builddir}/debuglinks.list \
%{_builddir}/debugsourcefiles.list %{_builddir}/debugsources.list \
%{_builddir}/elfbins.list
%endif
### SCRIPTLET ###############################################################################
%pretrans
if [ -d /run ] ; then
rundir=/run/svscan
elif [ -d /var/run ] ; then
rundir=/var/run/svscan
else
rundir=%{servicedir}
fi
if [ ! -f %{servicedir}/pwdlookup/down ] ; then
%{_prefix}/bin/svstat %{servicedir}/pwdlookup >/dev/null 2>&1
if [ $? -eq 0 ] ; then
%{__mkdir_p} ${rundir}/pwdlookup
touch ${rundir}/pwdlookup/.down
%{_prefix}/bin/svc -d %{servicedir}/pwdlookup
fi
fi
### SCRIPTLET ###############################################################################
%post
argv1=$1
if [ -d /run ] ; then
rundir=/run/svscan
nssd_sock="/run/indimail/pwdlookup/nssd.sock"
%{__mkdir_p} /run/indimail/pwdlookup
elif [ -d /var/run ] ; then
rundir=/var/run/svscan
nssd_sock="/var/run/indimail/pwdlookup/nssd.sock"
%{__mkdir_p} /var/run/indimail/pwdlookup
else
rundir=%{servicedir}
nssd_sock="/tmp/pwdlookup/nssd.sock"
%{__mkdir_p} /tmp/pwdlookup
fi
if [ -z "$argv1" ] ; then
argv1=0
fi
if [ $argv1 -eq 2 ] ; then # upgrade
(
echo "Upgrading indimail-auth package"
if [ "%{_libdir}" != "/usr/lib64" -a "%{_libdir}" != "/usr/lib" ] ; then
/sbin/ldconfig
fi
grep "pwdlookup/nssd.sock" %{servicedir}/pwdlookup/variables/.options >/dev/null
if [ $? -ne 0 ] ; then
sed -i 's{indimail/nssd.sock{indimail/pwdlookup/nssd.sock{g' %{servicedir}/pwdlookup/variables/.options
fi
%{_prefix}/sbin/svctool --servicedir=%{servicedir} --refreshsvc="%{servicedir}/pwdlookup"
%{_prefix}/bin/svok %{servicedir}/pwdlookup
if [ $? -eq 0 -a -f ${rundir}/pwdlookup/.down ] ; then
%{__rm} -f ${rundir}/pwdlookup/.down
%{_prefix}/bin/svc -u %{servicedir}/pwdlookup
fi
) >> /var/log/indimail-auth-setup.log 2>&1
exit 0
fi
echo "Doing Post Install"
echo ""
echo " 1. Configure %{logdir} for multilog"
echo " 2. Configure %{servicedir}"
echo " 3. Configure ${_sysconfdir}/nssd.conf for nssd"
echo " 4. Configure nssd service"
echo " 5. Configure pam-multi as alternative for SMTP auth"
echo ""
(
echo "Installing indimail-auth package"
# Recreate ld.so links and cache
if [ "%{_libdir}" != "/usr/lib64" -a "%{_libdir}" != "/usr/lib" ] ; then
if [ -d %{_sysconfdir}/ld.so.conf.d ] ; then
echo %{_libdir} > %{_sysconfdir}/ld.so.conf.d/indimail-auth-%{_arch}.conf
fi
/sbin/ldconfig
fi
%{__mkdir_p} %{logdir}/pwdlookup
%{__chown} -R qmaill:nofiles %{logdir}/pwdlookup
#nssd
%{_prefix}/sbin/svctool --pwdlookup=${nssd_sock} --threads=5 --timeout=-1 \
--mysqlhost=localhost --mysqluser=indimail \
--mysqlpass=ssh-1.5- --mysqlsocket=%{mysqlSocket} --servicedir=%{servicedir}
# turn off automatic refresh for services during first time installation
%{_prefix}/sbin/svctool --servicedir=%{servicedir} --autorefresh="0 %{servicedir}/pwdlookup"
# save variables
%{_prefix}/sbin/svctool --servicedir=%{servicedir} --service-name=pwdlookup \
--export-variables=%{servicedir}/pwdlookup/variables/.variables --force
#pam-multi
%{_prefix}/sbin/svctool --config=add-alt
) >> /var/log/indimail-auth-setup.log 2>&1
### SCRIPTLET ###############################################################################
%postun
argv1=$1
if [ -z "$argv1" ] ; then
argv1=0
fi
if [ $argv1 -eq 1 ] ; then
if [ "%{_libdir}" != "/usr/lib64" -a "%{_libdir}" != "/usr/lib" ] ; then
echo "recreating ld.so cache"
/sbin/ldconfig
fi
exit 0
fi
(
echo "removing indimail-auth package"
# remove pam module for smtp
%{_prefix}/sbin/svctool --config=remove-alt
if [ -d %{servicedir}/pwdlookup -o -L %{servicedir}/pwdlookup ] ; then
touch %{servicedir}/pwdlookup/down
svc -dx %{servicedir}/pwdlookup
fi
if [ -d %{servicedir}/pwdlookup/log -o -L %{servicedir}/pwdlookup/log ] ; then
touch %{servicedir}/pwdlookup/log/down
svc -dx %{servicedir}/pwdlookup/log
fi
if [ -d %{servicedir}/pwdlookup -o -L %{servicedir}/pwdlookup ] ; then
%{__rm} -rf %{servicedir}/pwdlookup
fi
if [ -h %{logdir} ] ; then
log_dir=`/bin/ls -ld %{logdir} | /usr/bin/awk '{print $10}'`
else
log_dir=%{logdir}
fi
%{__rm} -rf $log_dir/pwdlookup
%{__rm} -f %{sysconfdir}/nssd.conf
if [ "%{_libdir}" != "/usr/lib64" -a "%{_libdir}" != "/usr/lib" ] ; then
/sbin/ldconfig
fi
) >> /var/log/indimail-auth-setup.log 2>&1
# fix changelog for openSUSE buildservice
%changelog