# Copyright 2024 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

# Autogenerated by pycargoebuild 0.13.3

EAPI=8

CRATES="
	base64@0.22.1
	bitflags@2.6.0
	byteorder@1.5.0
	cc@1.1.15
	cfg-if@1.0.0
	deranged@0.3.11
	foreign-types-shared@0.1.1
	foreign-types@0.3.2
	futures@0.1.31
	hostname@0.4.0
	itoa@1.0.11
	libc@0.2.158
	log@0.4.22
	memchr@2.7.4
	multisock@1.0.0
	num-conv@0.1.0
	num_threads@0.1.7
	once_cell@1.19.0
	openssl-macros@0.1.1
	openssl-sys@0.9.103
	openssl@0.10.66
	pam-bindings@0.1.1
	pkg-config@0.3.30
	powerfmt@0.2.0
	proc-macro2@1.0.86
	pwd@1.4.0
	quote@1.0.37
	serde@1.0.209
	serde_derive@1.0.209
	shlex@1.3.0
	subst@0.3.3
	syn@2.0.77
	syslog@7.0.0
	thiserror-impl@1.0.63
	thiserror@1.0.63
	time-core@0.1.2
	time-macros@0.2.18
	time@0.3.36
	unicode-ident@1.0.12
	unicode-width@0.1.13
	vcpkg@0.2.15
	windows-core@0.52.0
	windows-targets@0.52.6
	windows@0.52.0
	windows_aarch64_gnullvm@0.52.6
	windows_aarch64_msvc@0.52.6
	windows_i686_gnu@0.52.6
	windows_i686_gnullvm@0.52.6
	windows_i686_msvc@0.52.6
	windows_x86_64_gnu@0.52.6
	windows_x86_64_gnullvm@0.52.6
	windows_x86_64_msvc@0.52.6
"

inherit cargo pam rust-toolchain
DESCRIPTION="This PAM module provides ssh-agent based authentication"
HOMEPAGE="https://github.com/z4yx/pam_rssh"

SSH_AGENT_COMMIT="802b94ccf2e00ac33a3863300d0769f02b62d807"
MY_PN="${PN/_rc2/-rc2/}"
MY_PV="${PV/_/-}"
MY_P="${MY_PN}-${MY_PV}"
SRC_URI="${CARGO_CRATE_URIS}"
SRC_URI+="https://github.com/z4yx/pam_rssh/archive/refs/tags/v${MY_PV}.tar.gz -> ${P}.tar.gz
	https://github.com/z4yx/ssh-agent.rs/archive/${SSH_AGENT_COMMIT}.tar.gz -> ssh-agent.rs-${SSH_AGENT_COMMIT}.tar.gz"

S="${WORKDIR}/${MY_P}"

LICENSE="MIT"
# Dependent crate licenses
LICENSE+=" Apache-2.0 BSD-2 CC-PD MIT Unicode-DFS-2016 Unlicense"
SLOT="0"
KEYWORDS="~amd64 ~arm64"

DEPEND="
	sys-libs/pam
	dev-libs/openssl
"
RDEPEND="${DEPEND}"

QA_FLAGS_IGNORED="usr/bin/${PN}"

src_unpack() {
	cargo_src_unpack

	rmdir "${WORKDIR}/${MY_P}/dep/ssh-agent.rs"
	cp -r "${WORKDIR}/ssh-agent.rs-${SSH_AGENT_COMMIT}" "${WORKDIR}/${MY_P}/dep/ssh-agent.rs" \
		|| die "Failed to copy ssh-agent.rs into workdir"
}

src_install() {
	dopammod "target/$(rust_abi)/release/libpam_rssh.so"
}

pkg_postinst() {
	ewarn "Default parameter auth_key_file is insecure"
	ewarn "Reference: https://github.com/z4yx/pam_rssh/issues/17 and linked issue"

	einfo "Suggestion is to set auth_key_file to a location not writeable by users"
	einfo "such as /etc/ssh/authorized_keys.d/\$user"
}