1SUMMARY = "Tools to change and administer password and group data"
2HOMEPAGE = "http://github.com/shadow-maint/shadow"
3DESCRIPTION = "${SUMMARY}"
4BUGTRACKER = "http://github.com/shadow-maint/shadow/issues"
5SECTION = "base/utils"
6LICENSE = "BSD-3-Clause"
7LIC_FILES_CHKSUM = "file://COPYING;md5=c9a450b7be84eac23e6353efecb60b5b \
8                    file://src/passwd.c;beginline=2;endline=30;md5=758c26751513b6795395275969dd3be1 \
9                    "
10
11DEPENDS = "virtual/crypt"
12
13UPSTREAM_CHECK_URI = "https://github.com/shadow-maint/shadow/releases"
14SRC_URI = "https://github.com/shadow-maint/shadow/releases/download/v${PV}/${BP}.tar.gz \
15           file://shadow-4.1.3-dots-in-usernames.patch \
16           ${@bb.utils.contains('PACKAGECONFIG', 'pam', '${PAM_SRC_URI}', '', d)} \
17           file://shadow-relaxed-usernames.patch \
18           file://useradd \
19           "
20
21SRC_URI:append:class-target = " \
22           file://login_defs_pam.sed \
23           file://shadow-update-pam-conf.patch \
24           "
25
26SRC_URI:append:class-native = " \
27           file://0001-Disable-use-of-syslog-for-sysroot.patch \
28           file://commonio.c-fix-unexpected-open-failure-in-chroot-env.patch \
29           "
30SRC_URI:append:class-nativesdk = " \
31           file://0001-Disable-use-of-syslog-for-sysroot.patch \
32           "
33
34SRC_URI[sha256sum] = "f262089be6a1011d50ec7849e14571b7b2e788334368f3dccb718513f17935ed"
35
36# Additional Policy files for PAM
37PAM_SRC_URI = "file://pam.d/chfn \
38               file://pam.d/chpasswd \
39               file://pam.d/chsh \
40               file://pam.d/login \
41               file://pam.d/newusers \
42               file://pam.d/passwd \
43               file://pam.d/su"
44
45inherit autotools gettext
46
47export CONFIG_SHELL="/bin/sh"
48
49EXTRA_OECONF += "--without-libcrack \
50                 --with-group-name-max-length=24 \
51                 --enable-subordinate-ids=yes \
52                 --without-sssd \
53                 ${NSCDOPT}"
54
55NSCDOPT = ""
56NSCDOPT:class-native = "--without-nscd"
57NSCDOPT:class-nativesdk = "--without-nscd"
58NSCDOPT:libc-glibc = "--with-nscd"
59
60PAM_PLUGINS = "libpam-runtime \
61               pam-plugin-faildelay \
62               pam-plugin-securetty \
63               pam-plugin-nologin \
64               pam-plugin-env \
65               pam-plugin-group \
66               pam-plugin-limits \
67               pam-plugin-lastlog \
68               pam-plugin-motd \
69               pam-plugin-mail \
70               pam-plugin-shells \
71               pam-plugin-rootok"
72
73PAM_PLUGINS:remove:libc-musl = "pam-plugin-lastlog"
74
75PACKAGECONFIG ??= "${@bb.utils.filter('DISTRO_FEATURES', 'pam', d)} \
76                   ${@bb.utils.contains('DISTRO_FEATURES', 'xattr', 'attr', '', d)}"
77PACKAGECONFIG:class-native ??= "${@bb.utils.contains('DISTRO_FEATURES', 'xattr', 'attr', '', d)}"
78PACKAGECONFIG:class-nativesdk = ""
79PACKAGECONFIG[pam] = "--with-libpam,--without-libpam,libpam,${PAM_PLUGINS}"
80PACKAGECONFIG[attr] = "--with-attr,--without-attr,attr"
81PACKAGECONFIG[acl] = "--with-acl,--without-acl,acl"
82PACKAGECONFIG[audit] = "--with-audit,--without-audit,audit"
83PACKAGECONFIG[selinux] = "--with-selinux,--without-selinux,libselinux libsemanage"
84
85RDEPENDS:${PN} = "shadow-securetty \
86                  base-passwd \
87                  util-linux-sulogin"
88RDEPENDS:${PN}:class-native = ""
89RDEPENDS:${PN}:class-nativesdk = ""
90
91do_install() {
92	oe_runmake DESTDIR="${D}" sbindir="${base_sbindir}" usbindir="${sbindir}" install
93
94	# Info dir listing isn't interesting at this point so remove it if it exists.
95	if [ -e "${D}${infodir}/dir" ]; then
96		rm -f ${D}${infodir}/dir
97	fi
98
99	# Enable CREATE_HOME by default.
100	sed -i 's/#CREATE_HOME/CREATE_HOME/g' ${D}${sysconfdir}/login.defs
101
102	# As we are on an embedded system, ensure the users mailbox is in
103	# ~/ not /var/spool/mail by default, as who knows where or how big
104	# /var is. The system MDA will set this later anyway.
105	sed -i 's/MAIL_DIR/#MAIL_DIR/g' ${D}${sysconfdir}/login.defs
106	sed -i 's/#MAIL_FILE/MAIL_FILE/g' ${D}${sysconfdir}/login.defs
107
108	# Disable checking emails.
109	sed -i 's/MAIL_CHECK_ENAB/#MAIL_CHECK_ENAB/g' ${D}${sysconfdir}/login.defs
110
111	# Comment out SU_NAME to work correctly with busybox
112	# See Bug#5359 and Bug#7173
113	sed -i 's:^SU_NAME:#SU_NAME:g' ${D}${sysconfdir}/login.defs
114
115	# Use proper encryption for passwords
116	sed -i 's/^#ENCRYPT_METHOD.*$/ENCRYPT_METHOD SHA512/' ${D}${sysconfdir}/login.defs
117
118	install -d ${D}${sysconfdir}/default
119	install -m 0644 ${WORKDIR}/useradd ${D}${sysconfdir}/default
120}
121
122do_install:append() {
123	# Ensure that the image has as a /var/spool/mail dir so shadow can
124	# put mailboxes there if the user reconfigures shadow to its
125	# defaults (see sed below).
126	install -m 0775 -d ${D}${localstatedir}/spool/mail
127	chown root:mail ${D}${localstatedir}/spool/mail
128
129	if [ -e ${WORKDIR}/pam.d ]; then
130		install -d ${D}${sysconfdir}/pam.d/
131		install -m 0644 ${WORKDIR}/pam.d/* ${D}${sysconfdir}/pam.d/
132		# Remove defaults that are not used when supporting PAM.
133		sed -i -f ${WORKDIR}/login_defs_pam.sed ${D}${sysconfdir}/login.defs
134	fi
135
136	install -d ${D}${sbindir} ${D}${base_sbindir} ${D}${base_bindir}
137
138	# Move binaries to the locations we want
139	rm ${D}${sbindir}/vigr
140	ln -sf vipw.${BPN} ${D}${base_sbindir}/vigr
141	if [ "${sbindir}" != "${base_sbindir}" ]; then
142		mv ${D}${sbindir}/vipw ${D}${base_sbindir}/vipw
143	fi
144	if [ "${bindir}" != "${base_bindir}" ]; then
145		mv ${D}${bindir}/login ${D}${base_bindir}/login
146		mv ${D}${bindir}/su ${D}${base_bindir}/su
147	fi
148
149	# Handle link properly after rename, otherwise missing files would
150	# lead rpm failed dependencies.
151	ln -sf newgrp.${BPN} ${D}${bindir}/sg
152}
153
154PACKAGES =+ "${PN}-base"
155FILES:${PN}-base = "\
156    ${base_bindir}/login.shadow \
157    ${base_bindir}/su.shadow \
158    ${bindir}/sg \
159    ${bindir}/newgrp.shadow \
160    ${bindir}/groups.shadow \
161    ${sysconfdir}/pam.d/login \
162    ${sysconfdir}/pam.d/su \
163    ${sysconfdir}/login.defs \
164"
165RDEPENDS:${PN} += "${PN}-base"
166
167inherit update-alternatives
168
169ALTERNATIVE_PRIORITY = "200"
170
171ALTERNATIVE:${PN} = "passwd chfn chsh chpasswd vipw vigr nologin"
172ALTERNATIVE_LINK_NAME[chfn] = "${bindir}/chfn"
173ALTERNATIVE_LINK_NAME[chsh] = "${bindir}/chsh"
174ALTERNATIVE_LINK_NAME[chpasswd] = "${sbindir}/chpasswd"
175ALTERNATIVE_LINK_NAME[vipw] = "${base_sbindir}/vipw"
176ALTERNATIVE_LINK_NAME[vigr] = "${base_sbindir}/vigr"
177ALTERNATIVE_LINK_NAME[nologin] = "${base_sbindir}/nologin"
178
179ALTERNATIVE:${PN}-base = "newgrp groups login su"
180ALTERNATIVE_LINK_NAME[login] = "${base_bindir}/login"
181ALTERNATIVE_LINK_NAME[su] = "${base_bindir}/su"
182
183PACKAGE_WRITE_DEPS += "shadow-native"
184pkg_postinst:${PN}:class-target () {
185	if [ "x$D" != "x" ]; then
186	  rootarg="--root $D"
187	else
188	  rootarg=""
189	fi
190
191	pwconv $rootarg || exit 1
192	grpconv $rootarg || exit 1
193}
194