finger: add basic implementation for fetching utmp users
Build and test / check (push) Successful in 1m0s
Build and test / build (push) Successful in 1m38s
Build and test / test (push) Successful in 2m2s
Build and test / docs (push) Successful in 3m45s

This commit is contained in:
2026-04-27 16:06:50 +09:00
parent 9c10b395d3
commit e5f1615f75
2 changed files with 24 additions and 5 deletions
+13
View File
@@ -5,6 +5,7 @@ use std::{
};
use chrono::{DateTime, Duration, Timelike, Utc};
use itertools::Itertools;
use nix::sys::stat::stat;
use serde::{Deserialize, Serialize};
use users::all_users;
@@ -71,6 +72,18 @@ pub fn search_for_user(
.collect()
}
/// Retrieve information about all users currently logged in, based on utmpx records.
pub fn finger_utmp_users(
_request_info: &FingerRequestInfo,
) -> Vec<anyhow::Result<FingerResponseUserEntry>> {
Utmpx::iter_all_records()
.filter(|entry| entry.is_user_process())
.map(|entry| entry.user())
.dedup()
.flat_map(|username| get_local_user(&username).transpose())
.collect()
}
/// Helper function to read the content of a file if it exists and is readable,
/// returning None if the file does not exist or is not readable.
fn read_file_content_if_exists(path: &Path) -> anyhow::Result<Option<String>> {