Skip to content

Commit

Permalink
Merge pull request #141 from asomers/no-such-user
Browse files Browse the repository at this point in the history
Better error messages if a required user is not found.
  • Loading branch information
asomers authored Feb 19, 2024
2 parents 9b88f9e + ceb0b10 commit a745bdd
Showing 1 changed file with 31 additions and 8 deletions.
39 changes: 31 additions & 8 deletions rust/src/config/auth.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::error::Error;
use std::{borrow::Cow, fmt::Display};
use std::process::exit;

use nix::unistd::{Group, User};
use serde::{de::Visitor, ser::SerializeTuple, Deserialize, Serialize};
Expand Down Expand Up @@ -110,23 +111,45 @@ pub struct DummyAuthConfig {

impl Default for DummyAuthConfig {
fn default() -> Self {
let unobody = User::from_name("nobody").unwrap().unwrap_or_else(|| {
eprintln!("error: nobody: no such user");
exit(1);
});
let gnobody = Group::from_gid(unobody.gid).unwrap().unwrap_or_else(|| {
eprintln!("error: {}: no such group", unobody.gid);
exit(1);
});
let upjdfstest = User::from_name("pjdfstest").unwrap().unwrap_or_else(|| {
eprintln!("error: pjdfstest: no such user");
exit(1);
});
let gpjdfstest = Group::from_gid(upjdfstest.gid).unwrap().unwrap_or_else(|| {
eprintln!("error: {}: no such group", upjdfstest.gid);
exit(1);
});
let utests = User::from_name("tests").unwrap().unwrap_or_else(|| {
eprintln!("error: tests: no such user");
exit(1);
});
let gtests = Group::from_gid(utests.gid).unwrap().unwrap_or_else(|| {
eprintln!("error: {}: no such group", utests.gid);
exit(1);
});
Self {
entries: [
{
let user = User::from_name("nobody").unwrap().unwrap();
let gid = user.gid;
DummyAuthEntry {
user,
group: Group::from_gid(gid).unwrap().unwrap(),
user: unobody,
group: gnobody,
}
},
DummyAuthEntry {
user: User::from_name("pjdfstest").unwrap().unwrap(),
group: Group::from_name("pjdfstest").unwrap().unwrap(),
user: upjdfstest,
group: gpjdfstest
},
DummyAuthEntry {
user: User::from_name("tests").unwrap().unwrap(),
group: Group::from_name("tests").unwrap().unwrap(),
user: utests,
group: gtests
},
],
}
Expand Down

0 comments on commit a745bdd

Please sign in to comment.