xref: /OK3568_Linux_fs/yocto/poky/meta/recipes-extended/shadow/shadow.inc (revision 4882a59341e53eb6f0b4789bf948001014eff981)
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           file://0001-Drop-nsswitch.conf-message-when-not-in-place-eg.-musl.patch \
30           "
31SRC_URI:append:class-nativesdk = " \
32           file://0001-Disable-use-of-syslog-for-sysroot.patch \
33           "
34
35SRC_URI[sha256sum] = "f262089be6a1011d50ec7849e14571b7b2e788334368f3dccb718513f17935ed"
36
37
38# Additional Policy files for PAM
39PAM_SRC_URI = "file://pam.d/chfn \
40               file://pam.d/chpasswd \
41               file://pam.d/chsh \
42               file://pam.d/login \
43               file://pam.d/newusers \
44               file://pam.d/passwd \
45               file://pam.d/su"
46
47inherit autotools gettext
48
49export CONFIG_SHELL="/bin/sh"
50
51EXTRA_OECONF += "--without-libcrack \
52                 --with-group-name-max-length=24 \
53                 --enable-subordinate-ids=yes \
54                 --without-sssd \
55                 ${NSCDOPT}"
56
57NSCDOPT = ""
58NSCDOPT:class-native = "--without-nscd"
59NSCDOPT:class-nativesdk = "--without-nscd"
60NSCDOPT:libc-glibc = "--with-nscd"
61
62PAM_PLUGINS = "libpam-runtime \
63               pam-plugin-faildelay \
64               pam-plugin-securetty \
65               pam-plugin-nologin \
66               pam-plugin-env \
67               pam-plugin-group \
68               pam-plugin-limits \
69               pam-plugin-lastlog \
70               pam-plugin-motd \
71               pam-plugin-mail \
72               pam-plugin-shells \
73               pam-plugin-rootok"
74
75PAM_PLUGINS:remove:libc-musl = "pam-plugin-lastlog"
76
77PACKAGECONFIG ??= "${@bb.utils.filter('DISTRO_FEATURES', 'pam', d)} \
78                   ${@bb.utils.contains('DISTRO_FEATURES', 'xattr', 'attr', '', d)}"
79PACKAGECONFIG:class-native ??= "${@bb.utils.contains('DISTRO_FEATURES', 'xattr', 'attr', '', d)}"
80PACKAGECONFIG:class-nativesdk = ""
81PACKAGECONFIG[pam] = "--with-libpam,--without-libpam,libpam,${PAM_PLUGINS}"
82PACKAGECONFIG[attr] = "--with-attr,--without-attr,attr"
83PACKAGECONFIG[acl] = "--with-acl,--without-acl,acl"
84PACKAGECONFIG[audit] = "--with-audit,--without-audit,audit"
85PACKAGECONFIG[selinux] = "--with-selinux,--without-selinux,libselinux libsemanage"
86
87RDEPENDS:${PN} = "shadow-securetty \
88                  base-passwd \
89                  util-linux-sulogin"
90RDEPENDS:${PN}:class-native = ""
91RDEPENDS:${PN}:class-nativesdk = ""
92
93do_install() {
94	oe_runmake DESTDIR="${D}" sbindir="${base_sbindir}" usbindir="${sbindir}" install
95
96	# Info dir listing isn't interesting at this point so remove it if it exists.
97	if [ -e "${D}${infodir}/dir" ]; then
98		rm -f ${D}${infodir}/dir
99	fi
100
101	# Enable CREATE_HOME by default.
102	sed -i 's/#CREATE_HOME/CREATE_HOME/g' ${D}${sysconfdir}/login.defs
103
104	# As we are on an embedded system, ensure the users mailbox is in
105	# ~/ not /var/spool/mail by default, as who knows where or how big
106	# /var is. The system MDA will set this later anyway.
107	sed -i 's/MAIL_DIR/#MAIL_DIR/g' ${D}${sysconfdir}/login.defs
108	sed -i 's/#MAIL_FILE/MAIL_FILE/g' ${D}${sysconfdir}/login.defs
109
110	# Disable checking emails.
111	sed -i 's/MAIL_CHECK_ENAB/#MAIL_CHECK_ENAB/g' ${D}${sysconfdir}/login.defs
112
113	# Comment out SU_NAME to work correctly with busybox
114	# See Bug#5359 and Bug#7173
115	sed -i 's:^SU_NAME:#SU_NAME:g' ${D}${sysconfdir}/login.defs
116
117	# Use proper encryption for passwords
118	sed -i 's/^#ENCRYPT_METHOD.*$/ENCRYPT_METHOD SHA512/' ${D}${sysconfdir}/login.defs
119
120	install -d ${D}${sysconfdir}/default
121	install -m 0644 ${WORKDIR}/useradd ${D}${sysconfdir}/default
122}
123
124do_install:append() {
125	# Ensure that the image has as a /var/spool/mail dir so shadow can
126	# put mailboxes there if the user reconfigures shadow to its
127	# defaults (see sed below).
128	install -m 0775 -d ${D}${localstatedir}/spool/mail
129	chown root:mail ${D}${localstatedir}/spool/mail
130
131	if [ -e ${WORKDIR}/pam.d ]; then
132		install -d ${D}${sysconfdir}/pam.d/
133		install -m 0644 ${WORKDIR}/pam.d/* ${D}${sysconfdir}/pam.d/
134		# Remove defaults that are not used when supporting PAM.
135		sed -i -f ${WORKDIR}/login_defs_pam.sed ${D}${sysconfdir}/login.defs
136	fi
137
138	install -d ${D}${sbindir} ${D}${base_sbindir} ${D}${base_bindir}
139
140	# Move binaries to the locations we want
141	rm ${D}${sbindir}/vigr
142	ln -sf vipw.${BPN} ${D}${base_sbindir}/vigr
143	if [ "${sbindir}" != "${base_sbindir}" ]; then
144		mv ${D}${sbindir}/vipw ${D}${base_sbindir}/vipw
145	fi
146	if [ "${bindir}" != "${base_bindir}" ]; then
147		mv ${D}${bindir}/login ${D}${base_bindir}/login
148		mv ${D}${bindir}/su ${D}${base_bindir}/su
149	fi
150
151	# Handle link properly after rename, otherwise missing files would
152	# lead rpm failed dependencies.
153	ln -sf newgrp.${BPN} ${D}${bindir}/sg
154
155	# usermod requires the subuid/subgid files to be in place before being
156	# able to use the -v/-V flags otherwise it fails:
157	# usermod: /etc/subuid does not exist, you cannot use the flags -v or -V
158	install -d ${D}${sysconfdir}
159	touch ${D}${sysconfdir}/subuid
160	touch ${D}${sysconfdir}/subgid
161}
162
163PACKAGES =+ "${PN}-base"
164FILES:${PN}-base = "\
165    ${base_bindir}/login.shadow \
166    ${base_bindir}/su.shadow \
167    ${bindir}/sg \
168    ${bindir}/newgrp.shadow \
169    ${bindir}/groups.shadow \
170    ${sysconfdir}/pam.d/login \
171    ${sysconfdir}/pam.d/su \
172    ${sysconfdir}/login.defs \
173"
174RDEPENDS:${PN} += "${PN}-base"
175
176inherit update-alternatives
177
178ALTERNATIVE_PRIORITY = "200"
179
180ALTERNATIVE:${PN} = "passwd chfn chsh chpasswd vipw vigr nologin"
181ALTERNATIVE_LINK_NAME[chfn] = "${bindir}/chfn"
182ALTERNATIVE_LINK_NAME[chsh] = "${bindir}/chsh"
183ALTERNATIVE_LINK_NAME[chpasswd] = "${sbindir}/chpasswd"
184ALTERNATIVE_LINK_NAME[vipw] = "${base_sbindir}/vipw"
185ALTERNATIVE_LINK_NAME[vigr] = "${base_sbindir}/vigr"
186ALTERNATIVE_LINK_NAME[nologin] = "${base_sbindir}/nologin"
187
188ALTERNATIVE:${PN}-base = "newgrp groups login su"
189ALTERNATIVE_LINK_NAME[login] = "${base_bindir}/login"
190ALTERNATIVE_LINK_NAME[su] = "${base_bindir}/su"
191
192PACKAGE_WRITE_DEPS += "shadow-native"
193pkg_postinst:${PN}:class-target () {
194	if [ "x$D" != "x" ]; then
195	  rootarg="--root $D"
196	else
197	  rootarg=""
198	fi
199
200	pwconv $rootarg || exit 1
201	grpconv $rootarg || exit 1
202}
203