From da12bf93ba40301050bf333a0849703ea5e9dd01 Mon Sep 17 00:00:00 2001 From: Rodolphe Breard Date: Fri, 12 Jun 2020 11:27:31 +0200 Subject: [PATCH] Add support for user and groups names --- CHANGELOG.md | 6 ++++++ CONTRIBUTING.md | 6 ------ acmed/src/storage.rs | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dc250ee..e32be96 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [Unreleased] + +### Added +- System users and groups can now be specified by name in addition to uid/gid. + + ## [0.8.0] - 2020-06-12 ### Changed diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 62b840b..84c5e08 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -13,12 +13,6 @@ Since the author is not a native English speaker, some of the texts used in this ## Fix issues in dependencies -### nix - -The [nix](https://crates.io/crates/nix) crate does not currently allow to retrieve an UID or GID from a user or group name, which prevents ACMEd to do so. A pull request has been made to `nix` in early 2018 but has not been merged yet. - -- https://github.com/nix-rust/nix/pull/864 - ### rust-openssl The [openssl](https://crates.io/crates/openssl) crate does not expose the Asn1Time in a usable way, which requires ACMEd to parse certificates using an external library in order to get the `not after` field. This is sub-optimal. diff --git a/acmed/src/storage.rs b/acmed/src/storage.rs index 2d6b728..67c2f39 100644 --- a/acmed/src/storage.rs +++ b/acmed/src/storage.rs @@ -97,8 +97,8 @@ fn set_owner(cert: &Certificate, path: &PathBuf, file_type: FileType) -> Result< let nix_uid = nix::unistd::Uid::from_raw(raw_uid); Some(nix_uid) } else { - // TODO: handle username - None + let user = nix::unistd::User::from_name(&u)?; + user.map(|u| u.uid) } } None => None, @@ -110,8 +110,8 @@ fn set_owner(cert: &Certificate, path: &PathBuf, file_type: FileType) -> Result< let nix_gid = nix::unistd::Gid::from_raw(raw_gid); Some(nix_gid) } else { - // TODO: handle group name - None + let grp = nix::unistd::Group::from_name(&g)?; + grp.map(|g| g.gid) } } None => None,