team-ljyzipelo

공개

Merge pull request #148 from Team-LJY/fix/pr144-private-group-check

개인 그룹의 기본 구성원 검증 보완
작성자
LeeJunyoung
작성 시각
커밋
c6b247cf876ff11d3f59a1da32803146a8245f5b
이 시점의 파일 보기

변경된 파일 14개

+1,767-40
수정experiments/rust-archive-worker/Cargo.lock+97-0
@@ -200,6 +200,12 @@ dependencies = [
200200 "generic-array",
201201]
202202
203추가: [[package]]
204추가: name = "itoa"
205추가: version = "1.0.19"
206추가: source = "registry+https://github.com/rust-lang/crates.io-index"
207추가: checksum = "3bd1574e617a9a6c1f8f8181bd7e841e1f20e4277607ef28945765188d6284d4"
208추가:
203209[[package]]
204210name = "libbz2-rs-sys"
205211version = "0.2.6"
@@ -221,6 +227,12 @@ dependencies = [
221227 "sha2 0.11.1",
222228]
223229
230추가: [[package]]
231추가: name = "memchr"
232추가: version = "2.8.3"
233추가: source = "registry+https://github.com/rust-lang/crates.io-index"
234추가: checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98"
235추가:
224236[[package]]
225237name = "miniz_oxide"
226238version = "0.8.9"
@@ -264,6 +276,66 @@ dependencies = [
264276 "miniz_oxide 0.8.9",
265277]
266278
279추가: [[package]]
280추가: name = "proc-macro2"
281추가: version = "1.0.107"
282추가: source = "registry+https://github.com/rust-lang/crates.io-index"
283추가: checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9"
284추가: dependencies = [
285추가: "unicode-ident",
286추가: ]
287추가:
288추가: [[package]]
289추가: name = "quote"
290추가: version = "1.0.47"
291추가: source = "registry+https://github.com/rust-lang/crates.io-index"
292추가: checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001"
293추가: dependencies = [
294추가: "proc-macro2",
295추가: ]
296추가:
297추가: [[package]]
298추가: name = "serde"
299추가: version = "1.0.229"
300추가: source = "registry+https://github.com/rust-lang/crates.io-index"
301추가: checksum = "4148590afebada386688f18773da617792bf2ef03ffc1e4cbd2b1d45b023e0ba"
302추가: dependencies = [
303추가: "serde_core",
304추가: ]
305추가:
306추가: [[package]]
307추가: name = "serde_core"
308추가: version = "1.0.229"
309추가: source = "registry+https://github.com/rust-lang/crates.io-index"
310추가: checksum = "67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48"
311추가: dependencies = [
312추가: "serde_derive",
313추가: ]
314추가:
315추가: [[package]]
316추가: name = "serde_derive"
317추가: version = "1.0.229"
318추가: source = "registry+https://github.com/rust-lang/crates.io-index"
319추가: checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348"
320추가: dependencies = [
321추가: "proc-macro2",
322추가: "quote",
323추가: "syn",
324추가: ]
325추가:
326추가: [[package]]
327추가: name = "serde_json"
328추가: version = "1.0.154"
329추가: source = "registry+https://github.com/rust-lang/crates.io-index"
330추가: checksum = "e7e9cc8b1b85264074fbcc02a88680c4096b1e47df8f739dceb03bf482f04bd6"
331추가: dependencies = [
332추가: "itoa",
333추가: "memchr",
334추가: "serde",
335추가: "serde_core",
336추가: "zmij",
337추가: ]
338추가:
267339[[package]]
268340name = "sha1"
269341version = "0.10.7"
@@ -309,12 +381,29 @@ version = "2.6.1"
309381source = "registry+https://github.com/rust-lang/crates.io-index"
310382checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292"
311383
384추가: [[package]]
385추가: name = "syn"
386추가: version = "3.0.10"
387추가: source = "registry+https://github.com/rust-lang/crates.io-index"
388추가: checksum = "4ae9ccbea3a7b0b09443036490c8f34a8b1b760fd345e5c0dae0aac718faea79"
389추가: dependencies = [
390추가: "proc-macro2",
391추가: "quote",
392추가: "unicode-ident",
393추가: ]
394추가:
312395[[package]]
313396name = "typenum"
314397version = "1.20.1"
315398source = "registry+https://github.com/rust-lang/crates.io-index"
316399checksum = "b6f5e870be6c3b371b77fe0ee0bafb859fa4964b4404c27de1d380043c4dda20"
317400
401추가: [[package]]
402추가: name = "unicode-ident"
403추가: version = "1.0.27"
404추가: source = "registry+https://github.com/rust-lang/crates.io-index"
405추가: checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563"
406추가:
318407[[package]]
319408name = "version_check"
320409version = "0.9.5"
@@ -337,6 +426,8 @@ dependencies = [
337426 "lzma-rust2",
338427 "pbkdf2",
339428 "png",
429추가: "serde",
430추가: "serde_json",
340431 "sha1",
341432 "sha2 0.10.9",
342433 "subtle",
@@ -359,6 +450,12 @@ version = "0.6.8"
359450source = "registry+https://github.com/rust-lang/crates.io-index"
360451checksum = "b268e58e7c693d7c271f93ffc4ba3b380412554231c85bf61ca7af91042a4112"
361452
453추가: [[package]]
454추가: name = "zmij"
455추가: version = "1.0.23"
456추가: source = "registry+https://github.com/rust-lang/crates.io-index"
457추가: checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b"
458추가:
362459[[package]]
363460name = "zune-core"
364461version = "0.5.3"
수정experiments/rust-archive-worker/Cargo.toml+4-0
@@ -21,6 +21,10 @@ zeroize = "=1.9.1"
2121sha2 = "=0.10.9"
2222zlib-rs = { version = "=0.6.8", default-features = false, features = ["rust-allocator"] }
2323
24추가: [target.'cfg(target_os = "linux")'.dependencies]
25추가: serde = "=1.0.229"
26추가: serde_json = "=1.0.154"
27추가:
2428[workspace]
2529exclude = ["vendor/zune-jpeg"]
2630
수정experiments/rust-archive-worker/src/filesystem.rs+123-5
@@ -210,11 +210,127 @@ mod platform {
210210 gid: u32,
211211 members: *mut *mut i8,
212212 }
213삭제: /// 현재 계정의 기본 그룹이 따로 등록된 구성원이 없는 개인 그룹인지 확인함.
214삭제: /// Ubuntu는 계정마다 같은 이름의 개인 그룹을 만들고 umask 002를 써서,
215삭제: /// 파일 관리자나 폴더 선택 창에서 새로 만든 폴더가 그룹 쓰기 권한(775)을 가짐.
213추가: // 없는 경로만 허용하며 중간 심볼릭 링크와 확인 오류는 거부함.
214추가: fn path_is_absent(path: &Path) -> bool {
215추가: let mut prefix = std::path::PathBuf::new();
216추가: for component in path.components() {
217추가: prefix.push(component.as_os_str());
218추가: match std::fs::symlink_metadata(&prefix) {
219추가: Ok(metadata) if metadata.is_dir() => {}
220추가: Ok(_) => return false,
221추가: Err(error) if error.kind() == std::io::ErrorKind::NotFound => return true,
222추가: Err(_) => return false,
223추가: }
224추가: }
225추가: false
226추가: }
227추가:
228추가: fn sss_is_unused(socket: &Path, cache: &Path) -> bool {
229추가: path_is_absent(socket)
230추가: && ["passwd", "group", "initgr"]
231추가: .iter()
232추가: .all(|name| path_is_absent(&cache.join(name)))
233추가: }
234추가:
235추가: // sss는 소켓과 캐시가 모두 없을 때만 빈 소스로 취급함.
236추가: fn primary_group_is_private(gid: u32) -> bool {
237추가: let Ok(policy) = std::fs::read_to_string("/etc/nsswitch.conf") else {
238추가: return false;
239추가: };
240추가: let mut databases = [None, None, None];
241추가: for line in policy.lines() {
242추가: let line = line.split('#').next().unwrap_or_default();
243추가: let Some((database, sources)) = line.split_once(':') else {
244추가: continue;
245추가: };
246추가: let index = match database.trim() {
247추가: "passwd" => 0,
248추가: "group" => 1,
249추가: "initgroups" => 2,
250추가: _ => continue,
251추가: };
252추가: if databases[index]
253추가: .replace(sources.split_whitespace().collect::<Vec<_>>())
254추가: .is_some()
255추가: {
256추가: return false;
257추가: }
258추가: }
259추가: let [Some(passwd), Some(group), initgroups] = databases else {
260추가: return false;
261추가: };
262추가: let mut has_systemd = false;
263추가: let mut has_sss = false;
264추가: // initgroups가 생략되어도 기본값인 group 소스를 검사함.
265추가: for source in [Some(passwd), Some(group), initgroups]
266추가: .into_iter()
267추가: .flatten()
268추가: {
269추가: if !matches!(
270추가: source.as_slice(),
271추가: ["files"] | ["files", "systemd"] | ["files", "sss"] | ["files", "systemd", "sss"]
272추가: ) {
273추가: return false;
274추가: }
275추가: has_systemd |= source.contains(&"systemd");
276추가: has_sss |= source.contains(&"sss");
277추가: }
278추가: if has_sss
279추가: && !sss_is_unused(
280추가: Path::new("/var/lib/sss/pipes/nss"),
281추가: Path::new("/var/lib/sss/mc"),
282추가: )
283추가: {
284추가: return false;
285추가: }
286추가: let Ok(accounts) = std::fs::read_to_string("/etc/passwd") else {
287추가: return false;
288추가: };
289추가: let current_uid = unsafe { geteuid() };
290추가: let mut current_name = None;
291추가: for account in accounts.lines() {
292추가: if account.trim().is_empty() || account.starts_with('#') {
293추가: continue;
294추가: }
295추가: let fields: Vec<_> = account.split(':').collect();
296추가: if fields.len() != 7 || fields[0].is_empty() {
297추가: return false;
298추가: }
299추가: let (Ok(uid), Ok(primary_gid)) = (fields[2].parse::<u32>(), fields[3].parse::<u32>())
300추가: else {
301추가: return false;
302추가: };
303추가: if primary_gid == gid {
304추가: if uid != current_uid {
305추가: return false;
306추가: }
307추가: if current_name.replace(fields[0]).is_some() {
308추가: return false;
309추가: }
310추가: }
311추가: }
312추가: let Some(current_name) = current_name else {
313추가: return false;
314추가: };
315추가: !has_systemd
316추가: || crate::systemd_userdb::group_is_private(
317추가: gid,
318추가: current_uid,
319추가: current_name,
320추가: Path::new("/run/systemd/userdb/"),
321추가: &[
322추가: Path::new("/etc/userdb"),
323추가: Path::new("/run/userdb"),
324추가: Path::new("/run/host/userdb"),
325추가: Path::new("/usr/local/lib/userdb"),
326추가: Path::new("/usr/lib/userdb"),
327추가: ],
328추가: )
329추가: }
330추가:
331추가: // 기본 구성원과 보조 구성원을 모두 확인함.
216332 fn private_group(gid: u32) -> bool {
217삭제: if gid != unsafe { getegid() } {
333추가: if gid != unsafe { getegid() } || !primary_group_is_private(gid) {
218334 return false;
219335 }
220336 let mut group = Group {
@@ -237,7 +353,9 @@ mod platform {
237353 // 그룹 정보를 읽지 못하면 안전하다고 볼 근거가 없으므로 거부함.
238354 status == 0
239355 && !result.is_null()
240삭제: && (group.members.is_null() || unsafe { *group.members }.is_null())
356추가: && group.gid == gid
357추가: && !group.members.is_null()
358추가: && unsafe { *group.members }.is_null()
241359 }
242360 pub struct Dir {
243361 file: File,
수정experiments/rust-archive-worker/src/lib.rs+3-0
@@ -18,3 +18,6 @@ mod spool;
1818mod streaming;
1919pub mod wire;
2020mod zip_recovery;
21추가:
22추가: #[cfg(target_os = "linux")]
23추가: mod systemd_userdb;
추가experiments/rust-archive-worker/src/systemd_userdb.rs+363-0
@@ -0,0 +1,363 @@
1추가: use serde::de::{self, Deserialize, Deserializer, MapAccess, SeqAccess, Visitor};
2추가: use serde_json::{Map, Value};
3추가: use std::collections::BTreeMap;
4추가: use std::fs;
5추가: use std::io::{BufRead, BufReader, Write};
6추가: use std::os::unix::{ffi::OsStrExt, fs::FileTypeExt, io::FromRawFd, net::UnixStream};
7추가: use std::path::Path;
8추가: use std::time::{Duration, Instant};
9추가:
10추가: // 중복 키는 해석 순서에 따라 판정이 달라질 수 있어 모든 깊이에서 거부함.
11추가: struct Strict(Value);
12추가: impl<'de> Deserialize<'de> for Strict {
13추가: fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
14추가: struct Json;
15추가: impl<'de> Visitor<'de> for Json {
16추가: type Value = Strict;
17추가: fn expecting(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
18추가: f.write_str("unambiguous JSON")
19추가: }
20추가: fn visit_bool<E: de::Error>(self, v: bool) -> Result<Strict, E> {
21추가: Ok(Strict(Value::Bool(v)))
22추가: }
23추가: fn visit_i64<E: de::Error>(self, v: i64) -> Result<Strict, E> {
24추가: Ok(Strict(v.into()))
25추가: }
26추가: fn visit_u64<E: de::Error>(self, v: u64) -> Result<Strict, E> {
27추가: Ok(Strict(v.into()))
28추가: }
29추가: fn visit_f64<E: de::Error>(self, v: f64) -> Result<Strict, E> {
30추가: serde_json::Number::from_f64(v)
31추가: .map(|v| Strict(Value::Number(v)))
32추가: .ok_or_else(|| E::custom("invalid number"))
33추가: }
34추가: fn visit_str<E: de::Error>(self, v: &str) -> Result<Strict, E> {
35추가: Ok(Strict(Value::String(v.into())))
36추가: }
37추가: fn visit_unit<E: de::Error>(self) -> Result<Strict, E> {
38추가: Ok(Strict(Value::Null))
39추가: }
40추가: fn visit_seq<A: SeqAccess<'de>>(self, mut seq: A) -> Result<Strict, A::Error> {
41추가: let mut values = Vec::new();
42추가: while let Some(Strict(v)) = seq.next_element()? {
43추가: values.push(v);
44추가: }
45추가: Ok(Strict(Value::Array(values)))
46추가: }
47추가: fn visit_map<A: MapAccess<'de>>(self, mut map: A) -> Result<Strict, A::Error> {
48추가: let mut values = Map::new();
49추가: while let Some((key, Strict(v))) = map.next_entry::<String, Strict>()? {
50추가: if values.insert(key, v).is_some() {
51추가: return Err(de::Error::custom("duplicate key"));
52추가: }
53추가: }
54추가: Ok(Strict(Value::Object(values)))
55추가: }
56추가: }
57추가: deserializer.deserialize_any(Json)
58추가: }
59추가: }
60추가:
61추가: type Check<T> = Result<T, ()>;
62추가: const MAX_FRAME: usize = 1024 * 1024;
63추가: const MAX_TOTAL: usize = 16 * MAX_FRAME;
64추가: const MAX_RECORDS: usize = 65_536;
65추가:
66추가: fn directory(path: &Path) -> Check<bool> {
67추가: let mut prefix = std::path::PathBuf::new();
68추가: for part in path.components() {
69추가: prefix.push(part.as_os_str());
70추가: match fs::symlink_metadata(&prefix) {
71추가: Ok(m) if m.is_dir() => {}
72추가: Err(e) if e.kind() == std::io::ErrorKind::NotFound => return Ok(false),
73추가: _ => return Err(()),
74추가: }
75추가: }
76추가: Ok(true)
77추가: }
78추가:
79추가: fn name(value: &Value) -> Check<&str> {
80추가: value
81추가: .as_str()
82추가: .filter(|s| !s.is_empty() && !s.chars().any(char::is_control))
83추가: .ok_or(())
84추가: }
85추가: fn id(value: &Value) -> Check<u32> {
86추가: value
87추가: .as_u64()
88추가: .and_then(|v| u32::try_from(v).ok())
89추가: .filter(|v| *v != u32::MAX)
90추가: .ok_or(())
91추가: }
92추가: fn strings(value: Option<&Value>) -> Check<Vec<&str>> {
93추가: match value {
94추가: None => Ok(Vec::new()),
95추가: Some(Value::Array(values)) => values.iter().map(name).collect(),
96추가: _ => Err(()),
97추가: }
98추가: }
99추가: fn record(parameters: &Value) -> Check<&Value> {
100추가: match parameters.get("incomplete") {
101추가: None | Some(Value::Bool(false)) => {}
102추가: _ => return Err(()),
103추가: }
104추가: let record = parameters
105추가: .get("record")
106추가: .filter(|v| v.is_object())
107추가: .ok_or(())?;
108추가: // 기기별 덮어쓰기를 해석하지 않은 상태에서는 거부함.
109추가: for key in ["binding", "perMachine"] {
110추가: match record.get(key) {
111추가: None => {}
112추가: Some(Value::Object(v)) if key == "binding" && v.is_empty() => {}
113추가: Some(Value::Array(v)) if key == "perMachine" && v.is_empty() => {}
114추가: _ => return Err(()),
115추가: }
116추가: }
117추가: Ok(record)
118추가: }
119추가:
120추가: struct Budget {
121추가: deadline: Instant,
122추가: bytes: usize,
123추가: records: usize,
124추가: }
125추가: impl Budget {
126추가: fn remaining(&self) -> Check<Duration> {
127추가: self.deadline
128추가: .checked_duration_since(Instant::now())
129추가: .filter(|d| !d.is_zero())
130추가: .ok_or(())
131추가: }
132추가: }
133추가:
134추가: // Unix 소켓의 대기열이 가득 차도 연결 단계에서 무한히 기다리지 않음.
135추가: fn connect(path: &Path) -> Check<UnixStream> {
136추가: #[repr(C)]
137추가: struct Address {
138추가: family: u16,
139추가: path: [u8; 108],
140추가: }
141추가: unsafe extern "C" {
142추가: fn socket(domain: i32, kind: i32, protocol: i32) -> i32;
143추가: fn connect(fd: i32, address: *const Address, size: u32) -> i32;
144추가: }
145추가: let bytes = path.as_os_str().as_bytes();
146추가: if bytes.contains(&0) || bytes.len() >= 108 {
147추가: return Err(());
148추가: }
149추가: let mut address = Address {
150추가: family: 1,
151추가: path: [0; 108],
152추가: };
153추가: address.path[..bytes.len()].copy_from_slice(bytes);
154추가: let fd = unsafe { socket(1, 1 | 0x80000 | 0x800, 0) };
155추가: if fd < 0 {
156추가: return Err(());
157추가: }
158추가: let stream = unsafe { UnixStream::from_raw_fd(fd) };
159추가: if unsafe { connect(fd, &address, (2 + bytes.len() + 1) as u32) } != 0 {
160추가: return Err(());
161추가: }
162추가: stream.set_nonblocking(false).map_err(|_| ())?;
163추가: Ok(stream)
164추가: }
165추가:
166추가: fn query(
167추가: path: &Path,
168추가: service: &str,
169추가: method: &str,
170추가: budget: &mut Budget,
171추가: mut check: impl FnMut(&Value) -> Check<()>,
172추가: ) -> Check<()> {
173추가: let mut stream = connect(path)?;
174추가: stream
175추가: .set_write_timeout(Some(budget.remaining()?))
176추가: .map_err(|_| ())?;
177추가: let request = serde_json::json!({
178추가: "method": format!("io.systemd.UserDatabase.{method}"),
179추가: "parameters": {"service": service}, "more": true,
180추가: });
181추가: stream
182추가: .write_all(request.to_string().as_bytes())
183추가: .map_err(|_| ())?;
184추가: stream.write_all(&[0]).map_err(|_| ())?;
185추가: let mut reader = BufReader::new(stream);
186추가: loop {
187추가: let mut frame = Vec::new();
188추가: loop {
189추가: reader
190추가: .get_ref()
191추가: .set_read_timeout(Some(budget.remaining()?))
192추가: .map_err(|_| ())?;
193추가: let chunk = reader.fill_buf().map_err(|_| ())?;
194추가: if chunk.is_empty() {
195추가: return Err(());
196추가: }
197추가: let end = chunk.iter().position(|b| *b == 0);
198추가: let n = end.map_or(chunk.len(), |i| i + 1);
199추가: budget.bytes = budget
200추가: .bytes
201추가: .checked_add(n)
202추가: .filter(|n| *n <= MAX_TOTAL)
203추가: .ok_or(())?;
204추가: if frame.len() + n > MAX_FRAME {
205추가: return Err(());
206추가: }
207추가: frame.extend_from_slice(&chunk[..n]);
208추가: reader.consume(n);
209추가: if end.is_some() {
210추가: frame.pop();
211추가: break;
212추가: }
213추가: }
214추가: budget.records += 1;
215추가: if budget.records > MAX_RECORDS {
216추가: return Err(());
217추가: }
218추가: let Strict(reply) = serde_json::from_slice::<Strict>(&frame).map_err(|_| ())?;
219추가: let object = reply.as_object().ok_or(())?;
220추가: if object
221추가: .keys()
222추가: .any(|key| !matches!(key.as_str(), "parameters" | "error" | "continues"))
223추가: {
224추가: return Err(());
225추가: }
226추가: let continues = match reply.get("continues") {
227추가: None | Some(Value::Bool(false)) => false,
228추가: Some(Value::Bool(true)) => true,
229추가: _ => return Err(()),
230추가: };
231추가: if let Some(error) = reply.get("error") {
232추가: return if error.as_str() == Some("io.systemd.UserDatabase.NoRecordFound")
233추가: && !continues
234추가: && reply
235추가: .get("parameters")
236추가: .is_none_or(|v| v.as_object().is_some_and(|v| v.is_empty()))
237추가: {
238추가: Ok(())
239추가: } else {
240추가: Err(())
241추가: };
242추가: }
243추가: let parameters = reply
244추가: .get("parameters")
245추가: .filter(|v| v.is_object())
246추가: .ok_or(())?;
247추가: check(parameters)?;
248추가: if !continues {
249추가: return Ok(());
250추가: }
251추가: }
252추가: }
253추가:
254추가: fn inspect(gid: u32, uid: u32, owner: &str, sockets: &Path, dropins: &[&Path]) -> Check<()> {
255추가: for path in dropins {
256추가: if directory(path)? && fs::read_dir(path).map_err(|_| ())?.next().is_some() {
257추가: return Err(());
258추가: }
259추가: }
260추가: let mut groups = BTreeMap::<String, u32>::new();
261추가: let local = fs::read_to_string("/etc/group").map_err(|_| ())?;
262추가: for line in local
263추가: .lines()
264추가: .filter(|v| !v.is_empty() && !v.starts_with('#'))
265추가: {
266추가: let fields: Vec<_> = line.split(':').collect();
267추가: if fields.len() != 4 || fields[0].is_empty() {
268추가: return Err(());
269추가: }
270추가: let group_gid = fields[2].parse::<u32>().map_err(|_| ())?;
271추가: if group_gid == gid && fields[3].split(',').any(|v| !v.is_empty() && v != owner) {
272추가: return Err(());
273추가: }
274추가: if groups.insert(fields[0].into(), group_gid).is_some() {
275추가: return Err(());
276추가: }
277추가: }
278추가: let mut services = Vec::new();
279추가: if directory(sockets)? {
280추가: for entry in fs::read_dir(sockets).map_err(|_| ())? {
281추가: let entry = entry.map_err(|_| ())?;
282추가: let service = entry.file_name().into_string().map_err(|_| ())?;
283추가: // 중계 서비스도 소켓 형식인지는 확인함.
284추가: if !entry.file_type().map_err(|_| ())?.is_socket() {
285추가: return Err(());
286추가: }
287추가: if matches!(
288추가: service.as_str(),
289추가: "io.systemd.Multiplexer" | "io.systemd.NameServiceSwitch"
290추가: ) {
291추가: continue;
292추가: }
293추가: services.push((service, entry.path()));
294추가: if services.len() > 256 {
295추가: return Err(());
296추가: }
297추가: }
298추가: }
299추가: let mut budget = Budget {
300추가: deadline: Instant::now() + Duration::from_secs(5),
301추가: bytes: 0,
302추가: records: 0,
303추가: };
304추가: // 모든 서비스의 그룹 이름을 먼저 모아 서비스 간 구성원도 검사함.
305추가: for (service, path) in &services {
306추가: query(path, service, "GetGroupRecord", &mut budget, |p| {
307추가: let r = record(p)?;
308추가: let group_name = name(&r["groupName"])?;
309추가: let group_gid = id(&r["gid"])?;
310추가: let members = strings(r.get("members"))?;
311추가: if group_gid == gid && members.iter().any(|v| *v != owner) {
312추가: return Err(());
313추가: }
314추가: if groups
315추가: .insert(group_name.into(), group_gid)
316추가: .is_some_and(|v| v != group_gid)
317추가: {
318추가: return Err(());
319추가: }
320추가: Ok(())
321추가: })?;
322추가: }
323추가: for (service, path) in &services {
324추가: query(path, service, "GetUserRecord", &mut budget, |p| {
325추가: let r = record(p)?;
326추가: let user = name(&r["userName"])?;
327추가: let user_uid = id(&r["uid"])?;
328추가: let primary = id(&r["gid"])?;
329추가: let is_owner = user_uid == uid && user == owner;
330추가: if primary == gid && !is_owner {
331추가: return Err(());
332추가: }
333추가: for group in strings(r.get("memberOf"))? {
334추가: let target = groups.get(group).ok_or(())?;
335추가: if *target == gid && !is_owner {
336추가: return Err(());
337추가: }
338추가: }
339추가: Ok(())
340추가: })?;
341추가: query(path, service, "GetMemberships", &mut budget, |p| {
342추가: let user = name(&p["userName"])?;
343추가: let group = name(&p["groupName"])?;
344추가: let target = groups.get(group).ok_or(())?;
345추가: if *target == gid && user != owner {
346추가: Err(())
347추가: } else {
348추가: Ok(())
349추가: }
350추가: })?;
351추가: }
352추가: Ok(())
353추가: }
354추가:
355추가: pub(crate) fn group_is_private(
356추가: gid: u32,
357추가: uid: u32,
358추가: owner: &str,
359추가: sockets: &Path,
360추가: dropins: &[&Path],
361추가: ) -> bool {
362추가: inspect(gid, uid, owner, sockets, dropins).is_ok()
363추가: }
수정experiments/rust-ui-memory-app/Cargo.lock+27-0
@@ -1744,6 +1744,12 @@ dependencies = [
17441744 "either",
17451745]
17461746
1747추가: [[package]]
1748추가: name = "itoa"
1749추가: version = "1.0.19"
1750추가: source = "registry+https://github.com/rust-lang/crates.io-index"
1751추가: checksum = "3bd1574e617a9a6c1f8f8181bd7e841e1f20e4277607ef28945765188d6284d4"
1752추가:
17471753[[package]]
17481754name = "jni"
17491755version = "0.22.4"
@@ -3025,6 +3031,19 @@ dependencies = [
30253031 "syn 3.0.10",
30263032]
30273033
3034추가: [[package]]
3035추가: name = "serde_json"
3036추가: version = "1.0.154"
3037추가: source = "registry+https://github.com/rust-lang/crates.io-index"
3038추가: checksum = "e7e9cc8b1b85264074fbcc02a88680c4096b1e47df8f739dceb03bf482f04bd6"
3039추가: dependencies = [
3040추가: "itoa",
3041추가: "memchr",
3042추가: "serde",
3043추가: "serde_core",
3044추가: "zmij",
3045추가: ]
3046추가:
30283047[[package]]
30293048name = "serde_repr"
30303049version = "0.1.21"
@@ -4657,6 +4676,8 @@ dependencies = [
46574676 "lzma-rust2",
46584677 "pbkdf2",
46594678 "png",
4679추가: "serde",
4680추가: "serde_json",
46604681 "sha1",
46614682 "sha2 0.10.9",
46624683 "subtle",
@@ -4715,6 +4736,12 @@ version = "0.6.8"
47154736source = "registry+https://github.com/rust-lang/crates.io-index"
47164737checksum = "b268e58e7c693d7c271f93ffc4ba3b380412554231c85bf61ca7af91042a4112"
47174738
4739추가: [[package]]
4740추가: name = "zmij"
4741추가: version = "1.0.23"
4742추가: source = "registry+https://github.com/rust-lang/crates.io-index"
4743추가: checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b"
4744추가:
47184745[[package]]
47194746name = "zune-core"
47204747version = "0.5.3"
수정packaging/licenses.py+4-0
@@ -13,6 +13,10 @@ ROOT = Path(__file__).resolve().parents[1]
1313
1414# 미리보기 디코더는 MIT 조건을 선택하며 원문 고지를 함께 수집함.
1515LICENSE_CHOICES = {
16추가: # userdb 응답은 직접 파서를 만들지 않고 검증된 JSON 해석기를 사용함.
17추가: ("serde", "1.0.229"): "MIT",
18추가: ("serde_core", "1.0.229"): "MIT",
19추가: ("serde_json", "1.0.154"): "MIT",
1620 ("png", "0.18.1"): "MIT",
1721 ("zune-jpeg", "0.5.15"): "MIT",
1822 ("zipelo-jpeg", "0.5.15"): "MIT",
추가tests/release-packages/test_userdb_licenses.py+32-0
@@ -0,0 +1,32 @@
1추가: """userdb JSON 해석기의 배포 고지 원문을 검증함."""
2추가:
3추가: import importlib.util
4추가: from pathlib import Path
5추가: import unittest
6추가:
7추가: ROOT = Path(__file__).resolve().parents[2]
8추가: SPEC = importlib.util.spec_from_file_location("userdb_licenses", ROOT / "packaging/licenses.py")
9추가: LICENSES = importlib.util.module_from_spec(SPEC)
10추가: SPEC.loader.exec_module(LICENSES)
11추가:
12추가:
13추가: class UserdbLicenses(unittest.TestCase):
14추가: def test_json_dependencies_preserve_selected_mit_notices(self):
15추가: records = LICENSES.inventory([ROOT / "experiments/rust-archive-worker/Cargo.toml"])
16추가: selected = {record["name"]: record for record in records}
17추가: for name, version in [("serde", "1.0.229"), ("serde_core", "1.0.229"), ("serde_json", "1.0.154")]:
18추가: with self.subTest(name=name):
19추가: record = selected[name]
20추가: self.assertEqual(record["version"], version)
21추가: self.assertEqual(record["selected_license"], "MIT")
22추가: self.assertIn("MIT", record["license"].split(" OR "))
23추가: self.assertTrue(record["files"])
24추가: notice = LICENSES.render([record])
25추가: for original in record["files"]:
26추가: self.assertIn(original["text"], notice)
27추가: self.assertIn(original["sha256"], notice)
28추가: self.assertTrue({"itoa", "memchr", "zmij"}.issubset(selected))
29추가:
30추가:
31추가: if __name__ == "__main__":
32추가: unittest.main()
수정tests/rust-app-real-worker/Cargo.lock+97-0
@@ -200,6 +200,12 @@ dependencies = [
200200 "generic-array",
201201]
202202
203추가: [[package]]
204추가: name = "itoa"
205추가: version = "1.0.19"
206추가: source = "registry+https://github.com/rust-lang/crates.io-index"
207추가: checksum = "3bd1574e617a9a6c1f8f8181bd7e841e1f20e4277607ef28945765188d6284d4"
208추가:
203209[[package]]
204210name = "libbz2-rs-sys"
205211version = "0.2.6"
@@ -221,6 +227,12 @@ dependencies = [
221227 "sha2 0.11.1",
222228]
223229
230추가: [[package]]
231추가: name = "memchr"
232추가: version = "2.8.3"
233추가: source = "registry+https://github.com/rust-lang/crates.io-index"
234추가: checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98"
235추가:
224236[[package]]
225237name = "miniz_oxide"
226238version = "0.8.9"
@@ -264,6 +276,66 @@ dependencies = [
264276 "miniz_oxide 0.8.9",
265277]
266278
279추가: [[package]]
280추가: name = "proc-macro2"
281추가: version = "1.0.107"
282추가: source = "registry+https://github.com/rust-lang/crates.io-index"
283추가: checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9"
284추가: dependencies = [
285추가: "unicode-ident",
286추가: ]
287추가:
288추가: [[package]]
289추가: name = "quote"
290추가: version = "1.0.47"
291추가: source = "registry+https://github.com/rust-lang/crates.io-index"
292추가: checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001"
293추가: dependencies = [
294추가: "proc-macro2",
295추가: ]
296추가:
297추가: [[package]]
298추가: name = "serde"
299추가: version = "1.0.229"
300추가: source = "registry+https://github.com/rust-lang/crates.io-index"
301추가: checksum = "4148590afebada386688f18773da617792bf2ef03ffc1e4cbd2b1d45b023e0ba"
302추가: dependencies = [
303추가: "serde_core",
304추가: ]
305추가:
306추가: [[package]]
307추가: name = "serde_core"
308추가: version = "1.0.229"
309추가: source = "registry+https://github.com/rust-lang/crates.io-index"
310추가: checksum = "67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48"
311추가: dependencies = [
312추가: "serde_derive",
313추가: ]
314추가:
315추가: [[package]]
316추가: name = "serde_derive"
317추가: version = "1.0.229"
318추가: source = "registry+https://github.com/rust-lang/crates.io-index"
319추가: checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348"
320추가: dependencies = [
321추가: "proc-macro2",
322추가: "quote",
323추가: "syn",
324추가: ]
325추가:
326추가: [[package]]
327추가: name = "serde_json"
328추가: version = "1.0.154"
329추가: source = "registry+https://github.com/rust-lang/crates.io-index"
330추가: checksum = "e7e9cc8b1b85264074fbcc02a88680c4096b1e47df8f739dceb03bf482f04bd6"
331추가: dependencies = [
332추가: "itoa",
333추가: "memchr",
334추가: "serde",
335추가: "serde_core",
336추가: "zmij",
337추가: ]
338추가:
267339[[package]]
268340name = "sha1"
269341version = "0.10.7"
@@ -309,12 +381,29 @@ version = "2.6.1"
309381source = "registry+https://github.com/rust-lang/crates.io-index"
310382checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292"
311383
384추가: [[package]]
385추가: name = "syn"
386추가: version = "3.0.10"
387추가: source = "registry+https://github.com/rust-lang/crates.io-index"
388추가: checksum = "4ae9ccbea3a7b0b09443036490c8f34a8b1b760fd345e5c0dae0aac718faea79"
389추가: dependencies = [
390추가: "proc-macro2",
391추가: "quote",
392추가: "unicode-ident",
393추가: ]
394추가:
312395[[package]]
313396name = "typenum"
314397version = "1.20.1"
315398source = "registry+https://github.com/rust-lang/crates.io-index"
316399checksum = "b6f5e870be6c3b371b77fe0ee0bafb859fa4964b4404c27de1d380043c4dda20"
317400
401추가: [[package]]
402추가: name = "unicode-ident"
403추가: version = "1.0.27"
404추가: source = "registry+https://github.com/rust-lang/crates.io-index"
405추가: checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563"
406추가:
318407[[package]]
319408name = "version_check"
320409version = "0.9.5"
@@ -337,6 +426,8 @@ dependencies = [
337426 "lzma-rust2",
338427 "pbkdf2",
339428 "png",
429추가: "serde",
430추가: "serde_json",
340431 "sha1",
341432 "sha2 0.10.9",
342433 "subtle",
@@ -366,6 +457,12 @@ version = "0.6.8"
366457source = "registry+https://github.com/rust-lang/crates.io-index"
367458checksum = "b268e58e7c693d7c271f93ffc4ba3b380412554231c85bf61ca7af91042a4112"
368459
460추가: [[package]]
461추가: name = "zmij"
462추가: version = "1.0.23"
463추가: source = "registry+https://github.com/rust-lang/crates.io-index"
464추가: checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b"
465추가:
369466[[package]]
370467name = "zune-core"
371468version = "0.5.3"
수정tests/rust-archive-worker/main.rs+7-35
@@ -519,44 +519,13 @@ fn symlink_parent_escape_is_rejected() {
519519 assert_eq!(fs::read_dir(s.0.join("outside")).unwrap().count(), 0);
520520}
521521
522삭제: // umask 002에서 폴더 선택 창으로 새로 만든 폴더(775)에도 풀 수 있어야 함.
523삭제: // 다른 계정이 쓸 수 있는 폴더(777)는 계속 거부함.
522추가: // 개인 그룹의 압축 해제만 허용하고 공유 쓰기는 거부함.
524523#[cfg(target_os = "linux")]
525524#[test]
526525fn private_group_writable_output_is_accepted() {
527삭제: use std::os::unix::fs::{MetadataExt, PermissionsExt};
528삭제: for (mode, other) in [(0o775, false), (0o777, true)] {
529삭제: let s = Scratch::new();
530삭제: fs::create_dir(s.0.join("output")).unwrap();
531삭제: fs::set_permissions(s.0.join("output"), fs::Permissions::from_mode(mode)).unwrap();
532삭제: let gid = fs::metadata(s.0.join("output")).unwrap().gid();
533삭제: let entry = Command::new("getent")
534삭제: .args(["group", &gid.to_string()])
535삭제: .output()
536삭제: .unwrap();
537삭제: let entry = String::from_utf8_lossy(&entry.stdout);
538삭제: let egid = Command::new("id").arg("-g").output().unwrap();
539삭제: let private = String::from_utf8_lossy(&egid.stdout).trim() == gid.to_string()
540삭제: && entry.trim_end().ends_with(':');
541삭제: let e = extract(
542삭제: &s,
543삭제: include_bytes!("fixtures/store.zip"),
544삭제: None,
545삭제: Selection::All,
546삭제: None,
547삭제: Limits::default(),
548삭제: );
549삭제: if other || !private {
550삭제: assert_eq!(terminal(&e).error, ErrorCode::UnsafePath, "{mode:o}");
551삭제: assert!(!s.0.join("output/folder").exists());
552삭제: } else {
553삭제: assert_eq!(terminal(&e).outcome, Outcome::Completed, "{e:?}");
554삭제: assert_eq!(
555삭제: fs::read(s.0.join("output/folder/hello.txt")).unwrap(),
556삭제: PAYLOAD
557삭제: );
558삭제: }
559삭제: }
526추가: private_group::check_extraction("personal", true);
527추가: private_group::check_extraction("shared-primary", false);
528추가: private_group::check_extraction("world-writable", false);
560529}
561530
562531#[test]
@@ -1676,3 +1645,6 @@ mod spool_location;
16761645
16771646#[cfg(target_os = "linux")]
16781647mod spool_fallback;
1648추가:
1649추가: #[cfg(target_os = "linux")]
1650추가: mod private_group;
추가tests/rust-archive-worker/private_group.rs+677-0
@@ -0,0 +1,677 @@
1추가: use super::*;
2추가: use std::os::unix::fs::{MetadataExt, PermissionsExt};
3추가:
4추가: fn check_case(case: &str, safe: bool) {
5추가: run_case(case, safe, false);
6추가: }
7추가:
8추가: pub(super) fn check_extraction(case: &str, safe: bool) {
9추가: run_case(case, safe, true);
10추가: }
11추가:
12추가: fn run_case(case: &str, safe: bool, extraction: bool) {
13추가: run_case_with_policy(case, safe, extraction, None);
14추가: }
15추가:
16추가: fn run_case_with_policy(case: &str, safe: bool, extraction: bool, policy: Option<&str>) {
17추가: let scratch = Scratch::new();
18추가: let output = scratch.0.join("output");
19추가: fs::create_dir(&output).unwrap();
20추가: let mode = if case == "world-writable" {
21추가: 0o777
22추가: } else {
23추가: 0o775
24추가: };
25추가: fs::set_permissions(&output, fs::Permissions::from_mode(mode)).unwrap();
26추가: if extraction {
27추가: fs::write(
28추가: scratch.0.join("input"),
29추가: include_bytes!("fixtures/store.zip"),
30추가: )
31추가: .unwrap();
32추가: }
33추가: let metadata = fs::metadata(&output).unwrap();
34추가: let uid = metadata.uid();
35추가: let gid = metadata.gid();
36추가: let mut passwd = format!("owner:x:{uid}:{gid}::/:/bin/sh\n");
37추가: match case {
38추가: "shared-primary" => passwd.push_str(&format!(
39추가: "other:x:{}:{gid}::/:/bin/sh\n",
40추가: uid.wrapping_add(1)
41추가: )),
42추가: "unrelated-primary" => passwd.push_str(&format!(
43추가: "other:x:{}:{}::/:/bin/sh\n",
44추가: uid.wrapping_add(1),
45추가: gid.wrapping_add(1)
46추가: )),
47추가: "missing-owner" => passwd.clear(),
48추가: "malformed-passwd" => passwd.push_str("broken:x:not-a-uid:1000::/:/bin/sh\n"),
49추가: "nis-passwd" => passwd.push_str("+::::::\n"),
50추가: _ => {}
51추가: }
52추가: let passwd_path = scratch.0.join("passwd");
53추가: fs::write(&passwd_path, passwd).unwrap();
54추가: if case == "passwd-unavailable" {
55추가: fs::remove_file(&passwd_path).unwrap();
56추가: }
57추가: let nss = match case {
58추가: "remote-accounts" | "sss-files-only" => "passwd: files sss\n",
59추가: "ldap-accounts" => "passwd: files ldap\n",
60추가: "winbind-accounts" => "passwd: files winbind\n",
61추가: "unknown-accounts" => "passwd: files unknown\n",
62추가: "short-circuit-policy" => "passwd: files [SUCCESS=return] systemd\n",
63추가: "duplicate-policy" => "passwd: files\npasswd: files\n",
64추가: "missing-policy" => "group: files\n",
65추가: _ if case.starts_with("sss-") || case == "systemd-remote" => "passwd: files systemd sss\n",
66추가: _ if case.starts_with("systemd-") || case.starts_with("userdb-") => {
67추가: "passwd: files systemd\n"
68추가: }
69추가: _ => "# fixture\npasswd: files # local accounts\n",
70추가: };
71추가: let nss = if case == "missing-policy" {
72추가: nss.to_owned()
73추가: } else {
74추가: format!("{nss}group: files\n")
75추가: };
76추가: let nss_path = scratch.0.join("nsswitch.conf");
77추가: fs::write(&nss_path, policy.unwrap_or(&nss)).unwrap();
78추가: if case == "nss-unavailable" {
79추가: fs::remove_file(&nss_path).unwrap();
80추가: }
81추가: let sss = scratch.0.join("sss");
82추가: fs::create_dir_all(sss.join("pipes")).unwrap();
83추가: fs::create_dir_all(sss.join("mc")).unwrap();
84추가: let _socket = match case {
85추가: "sss-socket" | "remote-accounts" | "systemd-remote" => {
86추가: use std::os::fd::AsRawFd;
87추가: let pipes = fs::File::open(sss.join("pipes")).unwrap();
88추가: let path = format!("/proc/self/fd/{}/nss", pipes.as_raw_fd());
89추가: Some(std::os::unix::net::UnixListener::bind(path).unwrap())
90추가: }
91추가: _ => None,
92추가: };
93추가: match case {
94추가: "sss-passwd-cache" => fs::write(sss.join("mc/passwd"), b"").unwrap(),
95추가: "sss-group-cache" => fs::write(sss.join("mc/group"), b"").unwrap(),
96추가: "sss-initgr-cache" => fs::write(sss.join("mc/initgr"), b"").unwrap(),
97추가: "sss-dangling-socket" => {
98추가: std::os::unix::fs::symlink("missing", sss.join("pipes/nss")).unwrap();
99추가: }
100추가: "sss-dangling-cache" => {
101추가: std::os::unix::fs::symlink("missing", sss.join("mc/passwd")).unwrap();
102추가: }
103추가: "sss-cache-symlink" => {
104추가: fs::remove_dir(sss.join("mc")).unwrap();
105추가: std::os::unix::fs::symlink("missing", sss.join("mc")).unwrap();
106추가: }
107추가: "sss-invalid-parent" => {
108추가: fs::remove_dir(sss.join("mc")).unwrap();
109추가: fs::write(sss.join("mc"), b"").unwrap();
110추가: }
111추가: "sss-missing-directories" => fs::remove_dir_all(&sss).unwrap(),
112추가: _ => {}
113추가: }
114추가: let userdb = scratch.0.join("userdb");
115추가: let _services = FakeUserdb::new(&userdb, case, uid, gid);
116추가: let library = shim();
117추가: let result = Command::new(std::env::current_exe().unwrap())
118추가: .args([
119추가: "--exact",
120추가: "private_group::probe_child",
121추가: "--test-threads=1",
122추가: "--nocapture",
123추가: ])
124추가: .env("LD_PRELOAD", library)
125추가: .env("ZIPELO_GROUP_CASE", case)
126추가: .env("ZIPELO_GROUP_PASSWD", passwd_path)
127추가: .env("ZIPELO_GROUP_NSS", nss_path)
128추가: .env("ZIPELO_GROUP_SSS", sss)
129추가: .env("ZIPELO_GROUP_USERDB", &userdb)
130추가: .env("ZIPELO_GROUP_OUTPUT", &output)
131추가: .env("ZIPELO_GROUP_SAFE", if safe { "1" } else { "0" })
132추가: .env("ZIPELO_GROUP_EXTRACT", if extraction { "1" } else { "0" })
133추가: .output()
134추가: .unwrap();
135추가: assert!(
136추가: result.status.success(),
137추가: "{case} policy={policy:?}: {} {}",
138추가: String::from_utf8_lossy(&result.stdout),
139추가: String::from_utf8_lossy(&result.stderr)
140추가: );
141추가: if extraction && safe {
142추가: assert_eq!(fs::read(output.join("folder/hello.txt")).unwrap(), PAYLOAD);
143추가: } else {
144추가: assert_eq!(fs::read_dir(&output).unwrap().count(), 0);
145추가: }
146추가: assert_eq!(fs::metadata(&output).unwrap().mode() & 0o777, mode);
147추가: }
148추가:
149추가: #[test]
150추가: fn probe_child() {
151추가: let Some(path) = std::env::var_os("ZIPELO_GROUP_OUTPUT") else {
152추가: return;
153추가: };
154추가: let path = std::path::Path::new(&path);
155추가: let actual = zipelo_archive_worker::filesystem::Dir::root(path);
156추가: if std::env::var("ZIPELO_GROUP_SAFE").unwrap() == "1" {
157추가: assert!(actual.is_ok());
158추가: } else {
159추가: assert!(matches!(actual, Err(ErrorCode::UnsafePath)));
160추가: }
161추가: if std::env::var("ZIPELO_GROUP_EXTRACT").unwrap() == "1" {
162추가: let events = execute(Start {
163추가: action: Action::Extract {
164추가: archive: NativePath::from_path(&path.parent().unwrap().join("input")),
165추가: destination: NativePath::from_path(path),
166추가: selection: Selection::All,
167추가: list_id: None,
168추가: gzip_output_name: None,
169추가: },
170추가: limits: Limits::default(),
171추가: });
172추가: if std::env::var("ZIPELO_GROUP_SAFE").unwrap() == "1" {
173추가: assert_eq!(terminal(&events).outcome, Outcome::Completed, "{events:?}");
174추가: } else {
175추가: assert_eq!(terminal(&events).error, ErrorCode::UnsafePath, "{events:?}");
176추가: }
177추가: }
178추가: }
179추가:
180추가: #[test]
181추가: fn private_group_accepts_only_current_primary_member() {
182추가: for case in ["personal", "unrelated-primary"] {
183추가: check_case(case, true);
184추가: }
185추가: }
186추가:
187추가: #[test]
188추가: fn private_group_rejects_another_primary_member() {
189추가: check_case("shared-primary", false);
190추가: }
191추가:
192추가: #[test]
193추가: fn private_group_rejects_incomplete_account_information() {
194추가: for case in [
195추가: "missing-owner",
196추가: "malformed-passwd",
197추가: "nis-passwd",
198추가: "passwd-unavailable",
199추가: "nss-unavailable",
200추가: "remote-accounts",
201추가: "unknown-accounts",
202추가: "ldap-accounts",
203추가: "winbind-accounts",
204추가: "systemd-remote",
205추가: "short-circuit-policy",
206추가: "duplicate-policy",
207추가: "missing-policy",
208추가: "group-error",
209추가: "group-missing",
210추가: "group-null-members",
211추가: "group-wrong-gid",
212추가: "supplementary-member",
213추가: ] {
214추가: check_case(case, false);
215추가: }
216추가: }
217추가:
218추가: #[test]
219추가: fn private_group_checks_varlink_records_and_completion() {
220추가: for case in [
221추가: "systemd-personal",
222추가: "systemd-unrelated",
223추가: "systemd-large-record",
224추가: "systemd-ignored-relays",
225추가: "systemd-multipart-empty",
226추가: "systemd-fragmented",
227추가: ] {
228추가: check_extraction(case, true);
229추가: }
230추가: for case in [
231추가: "systemd-dynamic-shared",
232추가: "systemd-homed-shared",
233추가: "systemd-large-shared",
234추가: "systemd-partial-error",
235추가: "systemd-group-error",
236추가: "systemd-membership-error",
237추가: "systemd-enumeration-error",
238추가: "systemd-disconnect",
239추가: "systemd-invalid-json",
240추가: "systemd-duplicate-key",
241추가: "systemd-missing-gid",
242추가: "systemd-wrong-type",
243추가: "systemd-group-member",
244추가: "systemd-membership-member",
245추가: "systemd-user-member",
246추가: "systemd-incomplete",
247추가: "systemd-overrides",
248추가: "systemd-non-socket",
249추가: "systemd-connect-error",
250추가: "systemd-buffer-limit",
251추가: "systemd-final-shared",
252추가: "systemd-unknown-membership",
253추가: "systemd-malformed-membership",
254추가: "systemd-second-service-error",
255추가: "systemd-socket-symlink",
256추가: "systemd-deep-json",
257추가: "systemd-invalid-utf8",
258추가: "systemd-negative-gid",
259추가: "systemd-float-gid",
260추가: "systemd-nested-duplicate",
261추가: "systemd-bad-continues",
262추가: ] {
263추가: check_extraction(case, false);
264추가: }
265추가: }
266추가:
267추가: #[test]
268추가: fn private_group_checks_systemd_in_group_and_initgroups_policies() {
269추가: for policy in [
270추가: "passwd: files\ngroup: files systemd\n",
271추가: "passwd: files\ngroup: files systemd\ninitgroups: files\n",
272추가: "passwd: files\ngroup: files\ninitgroups: files systemd\n",
273추가: ] {
274추가: for case in ["systemd-personal", "systemd-unrelated"] {
275추가: run_case_with_policy(case, true, true, Some(policy));
276추가: }
277추가: for case in [
278추가: "systemd-dynamic-shared",
279추가: "systemd-group-member",
280추가: "systemd-membership-member",
281추가: "systemd-user-member",
282추가: "systemd-partial-error",
283추가: "userdb-d0",
284추가: ] {
285추가: run_case_with_policy(case, false, true, Some(policy));
286추가: }
287추가: }
288추가: }
289추가:
290추가: #[test]
291추가: fn private_group_checks_sss_in_group_and_initgroups_policies() {
292추가: for policy in [
293추가: "passwd: files\ngroup: files sss\n",
294추가: "passwd: files\ngroup: files sss\ninitgroups: files\n",
295추가: "passwd: files\ngroup: files\ninitgroups: files sss\n",
296추가: ] {
297추가: run_case_with_policy("sss-empty", true, true, Some(policy));
298추가: for case in [
299추가: "sss-socket",
300추가: "sss-passwd-cache",
301추가: "sss-group-cache",
302추가: "sss-initgr-cache",
303추가: "sss-probe-error",
304추가: ] {
305추가: run_case_with_policy(case, false, true, Some(policy));
306추가: }
307추가: }
308추가: }
309추가:
310추가: #[test]
311추가: fn private_group_rejects_incomplete_group_and_initgroups_policies() {
312추가: for policy in [
313추가: "passwd: files\n",
314추가: "passwd: files\ngroup: files\ngroup: files\n",
315추가: "passwd: files\ngroup: files\ninitgroups: files\ninitgroups: files\n",
316추가: ] {
317추가: run_case_with_policy("personal", false, true, Some(policy));
318추가: }
319추가: for source in [
320추가: "",
321추가: "files ldap",
322추가: "files winbind",
323추가: "files unknown",
324추가: "files [SUCCESS=return] systemd",
325추가: "files systemd [UNAVAIL=continue]",
326추가: "files files",
327추가: ] {
328추가: for policy in [
329추가: format!("passwd: files\ngroup: {source}\n"),
330추가: format!("passwd: files\ngroup: files\ninitgroups: {source}\n"),
331추가: ] {
332추가: run_case_with_policy("personal", false, true, Some(&policy));
333추가: }
334추가: }
335추가: run_case_with_policy(
336추가: "personal",
337추가: true,
338추가: true,
339추가: Some("passwd: files\ngroup: files\ninitgroups: files # local groups\n"),
340추가: );
341추가: }
342추가:
343추가: #[test]
344추가: fn private_group_rejects_consumed_systemd_record_on_erange() {
345추가: // NSS 버퍼 재시도 대신 완전한 varlink 레코드를 직접 검사함.
346추가: check_extraction("systemd-large-record", true);
347추가: check_extraction("systemd-large-shared", false);
348추가: }
349추가:
350추가: #[test]
351추가: fn private_group_rejects_userdb_dropins_and_probe_failures() {
352추가: for case in ["userdb-empty", "userdb-missing"] {
353추가: check_extraction(case, true);
354추가: }
355추가: for case in [
356추가: "userdb-d0",
357추가: "userdb-d1",
358추가: "userdb-host",
359추가: "userdb-d3",
360추가: "userdb-d4",
361추가: "userdb-probe-error",
362추가: "userdb-symlink",
363추가: "userdb-invalid-parent",
364추가: ] {
365추가: check_extraction(case, false);
366추가: }
367추가: }
368추가:
369추가: #[test]
370추가: fn private_group_accepts_sss_only_without_socket_and_caches() {
371추가: for case in ["sss-empty", "sss-files-only", "sss-missing-directories"] {
372추가: check_extraction(case, true);
373추가: }
374추가: for case in [
375추가: "sss-socket",
376추가: "sss-passwd-cache",
377추가: "sss-group-cache",
378추가: "sss-initgr-cache",
379추가: "sss-dangling-socket",
380추가: "sss-dangling-cache",
381추가: "sss-cache-symlink",
382추가: "sss-invalid-parent",
383추가: "sss-probe-error",
384추가: ] {
385추가: check_extraction(case, false);
386추가: }
387추가: }
388추가:
389추가: fn shim() -> &'static PathBuf {
390추가: static LIBRARY: std::sync::OnceLock<(Scratch, PathBuf)> = std::sync::OnceLock::new();
391추가: &LIBRARY
392추가: .get_or_init(|| {
393추가: let scratch = Scratch::new();
394추가: let library = scratch.0.join("private-group.so");
395추가: assert!(
396추가: Command::new("cc")
397추가: .args(["-shared", "-fPIC", "-O2", "-Wall", "-Wextra", "-Werror"])
398추가: .arg(
399추가: PathBuf::from(env!("CARGO_MANIFEST_DIR"))
400추가: .join("../../tests/rust-archive-worker/private_group_nss.c")
401추가: )
402추가: .args(["-ldl", "-o"])
403추가: .arg(&library)
404추가: .status()
405추가: .unwrap()
406추가: .success()
407추가: );
408추가: (scratch, library)
409추가: })
410추가: .1
411추가: }
412추가:
413추가: struct FakeUserdb {
414추가: stop: std::sync::Arc<std::sync::atomic::AtomicBool>,
415추가: thread: Option<std::thread::JoinHandle<()>>,
416추가: }
417추가: impl FakeUserdb {
418추가: fn new(root: &std::path::Path, case: &str, uid: u32, gid: u32) -> Self {
419추가: use std::os::fd::AsRawFd;
420추가: let sockets = root.join("s");
421추가: fs::create_dir_all(&sockets).unwrap();
422추가: for d in ["d0", "d1", "host/userdb", "d3", "d4"] {
423추가: fs::create_dir_all(root.join(d)).unwrap();
424추가: }
425추가: if case == "userdb-missing" {
426추가: fs::remove_dir_all(root.join("host")).unwrap();
427추가: }
428추가: if let Some(d) = case.strip_prefix("userdb-") {
429추가: let d = if d == "host" { "host/userdb" } else { d };
430추가: if root.join(d).is_dir() {
431추가: fs::write(root.join(d).join("fixture.user"), b"{}").unwrap();
432추가: }
433추가: }
434추가: if case == "userdb-symlink" {
435추가: fs::remove_dir(root.join("d0")).unwrap();
436추가: std::os::unix::fs::symlink("missing", root.join("d0")).unwrap();
437추가: }
438추가: if case == "userdb-invalid-parent" {
439추가: fs::remove_dir(root.join("d0")).unwrap();
440추가: fs::write(root.join("d0"), b"").unwrap();
441추가: }
442추가: let stop = std::sync::Arc::new(std::sync::atomic::AtomicBool::new(false));
443추가: let mut result = Self {
444추가: stop: stop.clone(),
445추가: thread: None,
446추가: };
447추가: if case == "systemd-non-socket" {
448추가: fs::write(sockets.join("io.zipelo.Fixture"), b"").unwrap();
449추가: return result;
450추가: }
451추가: let parent = fs::File::open(&sockets).unwrap();
452추가: let path = format!("/proc/self/fd/{}/io.zipelo.Fixture", parent.as_raw_fd());
453추가: let listener = std::os::unix::net::UnixListener::bind(path).unwrap();
454추가: if case == "systemd-connect-error" {
455추가: return result;
456추가: }
457추가: if case == "systemd-second-service-error" {
458추가: drop(
459추가: std::os::unix::net::UnixListener::bind(format!(
460추가: "/proc/self/fd/{}/io.zipelo.Failed",
461추가: parent.as_raw_fd()
462추가: ))
463추가: .unwrap(),
464추가: );
465추가: }
466추가: if case == "systemd-socket-symlink" {
467추가: std::os::unix::fs::symlink("io.zipelo.Fixture", sockets.join("io.zipelo.Link"))
468추가: .unwrap();
469추가: }
470추가: let _relays = if case == "systemd-ignored-relays" {
471추가: Some(
472추가: ["io.systemd.Multiplexer", "io.systemd.NameServiceSwitch"].map(|v| {
473추가: std::os::unix::net::UnixListener::bind(format!(
474추가: "/proc/self/fd/{}/{v}",
475추가: parent.as_raw_fd()
476추가: ))
477추가: .unwrap()
478추가: }),
479추가: )
480추가: } else {
481추가: None
482추가: };
483추가: // 중계 소켓은 연결 불가 상태로 남겨 실제로 건너뛰는지 확인함.
484추가: drop(_relays);
485추가: listener.set_nonblocking(true).unwrap();
486추가: let case = case.to_owned();
487추가: result.thread = Some(std::thread::spawn(move || {
488추가: use serde_json::{Value, json};
489추가: use std::io::{Read, Write};
490추가: while !stop.load(Ordering::Relaxed) {
491추가: let (mut stream, _) = match listener.accept() {
492추가: Ok(v) => v,
493추가: Err(e) if e.kind() == std::io::ErrorKind::WouldBlock => {
494추가: std::thread::sleep(std::time::Duration::from_millis(1));
495추가: continue;
496추가: }
497추가: Err(e) => panic!("{e}"),
498추가: };
499추가: stream
500추가: .set_read_timeout(Some(std::time::Duration::from_secs(5)))
501추가: .unwrap();
502추가: let mut request = Vec::new();
503추가: loop {
504추가: let mut byte = [0];
505추가: stream.read_exact(&mut byte).unwrap();
506추가: if byte == [0] {
507추가: break;
508추가: }
509추가: request.push(byte[0]);
510추가: }
511추가: let request: Value = serde_json::from_slice(&request).unwrap();
512추가: assert_eq!(request["parameters"]["service"], "io.zipelo.Fixture");
513추가: assert_eq!(request["more"], true);
514추가: let method = request["method"]
515추가: .as_str()
516추가: .unwrap()
517추가: .rsplit('.')
518추가: .next()
519추가: .unwrap();
520추가: let no_record = json!({"error":"io.systemd.UserDatabase.NoRecordFound"});
521추가: let failure = json!({"error":"io.systemd.UserDatabase.ServiceNotAvailable"});
522추가: let mut reply = match method {
523추가: "GetGroupRecord" => {
524추가: json!({"parameters":{"record":{"groupName":"test-personal","gid":gid,"members":[]}}})
525추가: }
526추가: "GetUserRecord" => {
527추가: json!({"parameters":{"record":{"userName":"other","uid":uid+1,"gid":gid+1}}})
528추가: }
529추가: "GetMemberships" => no_record.clone(),
530추가: _ => panic!("unexpected method"),
531추가: };
532추가: if method == "GetGroupRecord" {
533추가: if case == "systemd-group-member" {
534추가: reply["parameters"]["record"]["members"] = json!(["other"]);
535추가: }
536추가: if case == "systemd-group-error" {
537추가: reply = failure.clone();
538추가: }
539추가: }
540추가: if method == "GetMemberships" {
541추가: if case == "systemd-membership-member" {
542추가: reply =
543추가: json!({"parameters":{"userName":"other","groupName":"test-personal"}});
544추가: }
545추가: if case == "systemd-unknown-membership" {
546추가: reply = json!({"parameters":{"userName":"other","groupName":"unknown"}});
547추가: }
548추가: if case == "systemd-malformed-membership" {
549추가: reply = json!({"parameters":{"userName":123,"groupName":"test-personal"}});
550추가: }
551추가: if case == "systemd-membership-error" {
552추가: reply = failure.clone();
553추가: }
554추가: }
555추가: if method == "GetUserRecord" {
556추가: if [
557추가: "systemd-dynamic-shared",
558추가: "systemd-homed-shared",
559추가: "systemd-large-shared",
560추가: ]
561추가: .contains(&case.as_str())
562추가: {
563추가: reply["parameters"]["record"]["gid"] = json!(gid);
564추가: }
565추가: if case == "systemd-large-record" || case == "systemd-large-shared" {
566추가: reply["parameters"]["record"]["realName"] = json!("x".repeat(32768));
567추가: }
568추가: if case == "systemd-buffer-limit" {
569추가: reply["parameters"]["record"]["realName"] = json!("x".repeat(1024 * 1024));
570추가: }
571추가: if case == "systemd-incomplete" {
572추가: reply["parameters"]["incomplete"] = json!(true);
573추가: }
574추가: if case == "systemd-overrides" {
575추가: reply["parameters"]["record"]["binding"] = json!({"machine":{"gid":gid}});
576추가: }
577추가: if case == "systemd-missing-gid" {
578추가: reply["parameters"]["record"]
579추가: .as_object_mut()
580추가: .unwrap()
581추가: .remove("gid");
582추가: }
583추가: if case == "systemd-wrong-type" {
584추가: reply["parameters"]["record"]["gid"] = json!("1000");
585추가: }
586추가: if case == "systemd-user-member" {
587추가: reply["parameters"]["record"]["memberOf"] = json!(["test-personal"]);
588추가: }
589추가: if case == "systemd-personal" {
590추가: reply = no_record.clone();
591추가: }
592추가: if case == "systemd-enumeration-error" {
593추가: reply = failure.clone();
594추가: }
595추가: if [
596추가: "systemd-partial-error",
597추가: "systemd-disconnect",
598추가: "systemd-final-shared",
599추가: ]
600추가: .contains(&case.as_str())
601추가: {
602추가: reply["continues"] = json!(true);
603추가: }
604추가: if case == "systemd-invalid-json" {
605추가: let _ = stream.write_all(b"{not-json}\0");
606추가: continue;
607추가: }
608추가: if case == "systemd-duplicate-key" {
609추가: let _ = stream.write_all(b"{\"error\":\"failure\",\"error\":\"io.systemd.UserDatabase.NoRecordFound\"}\0");
610추가: continue;
611추가: }
612추가: }
613추가: if method == "GetUserRecord" {
614추가: if case == "systemd-negative-gid" {
615추가: reply["parameters"]["record"]["gid"] = json!(-1);
616추가: }
617추가: if case == "systemd-float-gid" {
618추가: reply["parameters"]["record"]["gid"] = json!(1000.0);
619추가: }
620추가: if case == "systemd-bad-continues" {
621추가: reply["continues"] = json!("true");
622추가: }
623추가: if case == "systemd-multipart-empty" {
624추가: reply["continues"] = json!(true);
625추가: }
626추가: if case == "systemd-invalid-utf8" {
627추가: let _ = stream.write_all(b"\xff\0");
628추가: continue;
629추가: }
630추가: if case == "systemd-nested-duplicate" {
631추가: let _ = stream.write_all(b"{\"parameters\":{\"record\":{\"userName\":\"other\",\"uid\":1001,\"gid\":1000,\"gid\":1001}}}\0");
632추가: continue;
633추가: }
634추가: if case == "systemd-deep-json" {
635추가: let data = format!("{}0{}\0", "[".repeat(140), "]".repeat(140));
636추가: let _ = stream.write_all(data.as_bytes());
637추가: continue;
638추가: }
639추가: }
640추가: let mut bytes = serde_json::to_vec(&reply).unwrap();
641추가: bytes.push(0);
642추가: if method == "GetUserRecord" && case == "systemd-partial-error" {
643추가: bytes.extend(serde_json::to_vec(&failure).unwrap());
644추가: bytes.push(0);
645추가: }
646추가: if method == "GetUserRecord" && case == "systemd-final-shared" {
647추가: reply["parameters"]["record"]["gid"] = json!(gid);
648추가: reply["continues"] = json!(false);
649추가: bytes.extend(serde_json::to_vec(&reply).unwrap());
650추가: bytes.push(0);
651추가: }
652추가: if method == "GetUserRecord" && case == "systemd-multipart-empty" {
653추가: bytes.extend(serde_json::to_vec(&no_record).unwrap());
654추가: bytes.push(0);
655추가: }
656추가: if case == "systemd-fragmented" {
657추가: for byte in bytes {
658추가: if stream.write_all(&[byte]).is_err() {
659추가: break;
660추가: }
661추가: }
662추가: } else {
663추가: let _ = stream.write_all(&bytes);
664추가: }
665추가: }
666추가: }));
667추가: result
668추가: }
669추가: }
670추가: impl Drop for FakeUserdb {
671추가: fn drop(&mut self) {
672추가: self.stop.store(true, Ordering::Relaxed);
673추가: if let Some(thread) = self.thread.take() {
674추가: thread.join().unwrap();
675추가: }
676추가: }
677추가: }
추가tests/rust-archive-worker/private_group_nss.c+139-0
@@ -0,0 +1,139 @@
1추가: #define _GNU_SOURCE
2추가: #include <dlfcn.h>
3추가: #include <errno.h>
4추가: #include <fcntl.h>
5추가: #include <grp.h>
6추가: #include <pwd.h>
7추가: #include <unistd.h>
8추가: #include <stdarg.h>
9추가: #include <stdlib.h>
10추가: #include <string.h>
11추가:
12추가: int open64(const char *path, int flags, ...) {
13추가: int (*original)(const char *, int, ...) = dlsym(RTLD_NEXT, "open64");
14추가: mode_t mode = 0;
15추가: if (flags & O_CREAT) {
16추가: va_list args;
17추가: va_start(args, flags);
18추가: mode = va_arg(args, unsigned int);
19추가: va_end(args);
20추가: }
21추가: if (!strcmp(path, "/etc/passwd")) {
22추가: path = getenv("ZIPELO_GROUP_PASSWD");
23추가: } else if (!strcmp(path, "/etc/nsswitch.conf")) {
24추가: path = getenv("ZIPELO_GROUP_NSS");
25추가: }
26추가: if (!path) {
27추가: errno = EACCES;
28추가: return -1;
29추가: }
30추가: return original(path, flags, mode);
31추가: }
32추가:
33추가: int getgrgid_r(gid_t gid, struct group *group, char *buffer, size_t length,
34추가: struct group **result) {
35추가: (void)buffer;
36추가: (void)length;
37추가: const char *phase = getenv("ZIPELO_GROUP_CASE");
38추가: *result = NULL;
39추가: if (!phase || !strcmp(phase, "group-error")) {
40추가: return EIO;
41추가: }
42추가: if (!strcmp(phase, "group-missing")) {
43추가: return 0;
44추가: }
45추가: static char *empty[] = {NULL};
46추가: static char *shared[] = {"other", NULL};
47추가: *group = (struct group){
48추가: .gr_name = "fixture",
49추가: .gr_passwd = "x",
50추가: .gr_gid = !strcmp(phase, "group-wrong-gid") ? gid + 1 : gid,
51추가: .gr_mem = !strcmp(phase, "group-null-members") ? NULL :
52추가: (!strcmp(phase, "supplementary-member") ? shared : empty)
53추가: };
54추가: *result = group;
55추가: return 0;
56추가: }
57추가: #include <dirent.h>
58추가: #include <limits.h>
59추가: #include <stddef.h>
60추가: #include <stdio.h>
61추가: #include <sys/socket.h>
62추가: #include <sys/stat.h>
63추가: #include <sys/un.h>
64추가:
65추가: static const char *redirect(const char *path, char *buffer, size_t length) {
66추가: const char *base = NULL;
67추가: const char *tail = NULL;
68추가: if (!strncmp(path, "/var/lib/sss", 12) && (!path[12] || path[12] == '/')) {
69추가: base = getenv("ZIPELO_GROUP_SSS");
70추가: tail = path + 12;
71추가: } else {
72추가: const char *paths[] = {"/etc/userdb", "/run/userdb", "/run/host/userdb",
73추가: "/usr/local/lib/userdb", "/usr/lib/userdb", "/run/host", "/run/systemd/userdb"};
74추가: const char *names[] = {"/d0", "/d1", "/host/userdb", "/d3", "/d4", "/host", "/s"};
75추가: for (size_t i = 0; i < sizeof(paths) / sizeof(paths[0]); i++) {
76추가: size_t n = strlen(paths[i]);
77추가: if (!strncmp(path, paths[i], n) && (!path[n] || path[n] == '/')) {
78추가: base = getenv("ZIPELO_GROUP_USERDB");
79추가: int size = snprintf(buffer, length, "%s%s%s", base ? base : "", names[i], path + n);
80추가: if (!base || size < 0 || (size_t)size >= length) {
81추가: errno = EACCES;
82추가: return NULL;
83추가: }
84추가: return buffer;
85추가: }
86추가: }
87추가: return path;
88추가: }
89추가: int n = snprintf(buffer, length, "%s%s", base ? base : "", tail);
90추가: if (!base || n < 0 || (size_t)n >= length) {
91추가: errno = EACCES;
92추가: return NULL;
93추가: }
94추가: return buffer;
95추가: }
96추가:
97추가: int statx(int fd, const char *path, int flags, unsigned int mask, struct statx *info) {
98추가: int (*original)(int, const char *, int, unsigned int, struct statx *) = dlsym(RTLD_NEXT, "statx");
99추가: const char *phase = getenv("ZIPELO_GROUP_CASE");
100추가: if (phase && ((!strcmp(phase, "sss-probe-error") && !strncmp(path, "/var/lib/sss", 12)) ||
101추가: (!strcmp(phase, "userdb-probe-error") && !strcmp(path, "/etc/userdb")))) {
102추가: errno = EACCES;
103추가: return -1;
104추가: }
105추가: char buffer[PATH_MAX];
106추가: const char *mapped = redirect(path, buffer, sizeof(buffer));
107추가: return mapped ? original(fd, mapped, flags, mask, info) : -1;
108추가: }
109추가:
110추가: DIR *opendir(const char *path) {
111추가: DIR *(*original)(const char *) = dlsym(RTLD_NEXT, "opendir");
112추가: char buffer[PATH_MAX];
113추가: const char *mapped = redirect(path, buffer, sizeof(buffer));
114추가: return mapped ? original(mapped) : NULL;
115추가: }
116추가:
117추가: int connect(int fd, const struct sockaddr *address, socklen_t length) {
118추가: int (*original)(int, const struct sockaddr *, socklen_t) = dlsym(RTLD_NEXT, "connect");
119추가: const struct sockaddr_un *un = (const struct sockaddr_un *)address;
120추가: if (address->sa_family != AF_UNIX || strncmp(un->sun_path, "/run/systemd/userdb/", 20)) {
121추가: return original(fd, address, length);
122추가: }
123추가: char buffer[PATH_MAX];
124추가: const char *mapped = redirect(un->sun_path, buffer, sizeof(buffer));
125추가: if (!mapped) return -1;
126추가: char *slash = strrchr(buffer, '/');
127추가: if (!slash) return -1;
128추가: *slash = 0;
129추가: int parent = open(buffer, O_RDONLY | O_DIRECTORY | O_CLOEXEC);
130추가: if (parent < 0) return -1;
131추가: struct sockaddr_un redirected = {.sun_family = AF_UNIX};
132추가: int n = snprintf(redirected.sun_path, sizeof(redirected.sun_path), "/proc/self/fd/%d/%s", parent, slash + 1);
133추가: int result = -1;
134추가: if (n >= 0 && (size_t)n < sizeof(redirected.sun_path)) {
135추가: result = original(fd, (const struct sockaddr *)&redirected, offsetof(struct sockaddr_un, sun_path) + n + 1);
136추가: }
137추가: close(parent);
138추가: return result;
139추가: }
수정tests/rust-large-archive-fixtures/Cargo.lock+97-0
@@ -200,6 +200,12 @@ dependencies = [
200200 "generic-array",
201201]
202202
203추가: [[package]]
204추가: name = "itoa"
205추가: version = "1.0.19"
206추가: source = "registry+https://github.com/rust-lang/crates.io-index"
207추가: checksum = "3bd1574e617a9a6c1f8f8181bd7e841e1f20e4277607ef28945765188d6284d4"
208추가:
203209[[package]]
204210name = "libbz2-rs-sys"
205211version = "0.2.6"
@@ -221,6 +227,12 @@ dependencies = [
221227 "sha2 0.11.1",
222228]
223229
230추가: [[package]]
231추가: name = "memchr"
232추가: version = "2.8.3"
233추가: source = "registry+https://github.com/rust-lang/crates.io-index"
234추가: checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98"
235추가:
224236[[package]]
225237name = "miniz_oxide"
226238version = "0.8.9"
@@ -264,6 +276,66 @@ dependencies = [
264276 "miniz_oxide 0.8.9",
265277]
266278
279추가: [[package]]
280추가: name = "proc-macro2"
281추가: version = "1.0.107"
282추가: source = "registry+https://github.com/rust-lang/crates.io-index"
283추가: checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9"
284추가: dependencies = [
285추가: "unicode-ident",
286추가: ]
287추가:
288추가: [[package]]
289추가: name = "quote"
290추가: version = "1.0.47"
291추가: source = "registry+https://github.com/rust-lang/crates.io-index"
292추가: checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001"
293추가: dependencies = [
294추가: "proc-macro2",
295추가: ]
296추가:
297추가: [[package]]
298추가: name = "serde"
299추가: version = "1.0.229"
300추가: source = "registry+https://github.com/rust-lang/crates.io-index"
301추가: checksum = "4148590afebada386688f18773da617792bf2ef03ffc1e4cbd2b1d45b023e0ba"
302추가: dependencies = [
303추가: "serde_core",
304추가: ]
305추가:
306추가: [[package]]
307추가: name = "serde_core"
308추가: version = "1.0.229"
309추가: source = "registry+https://github.com/rust-lang/crates.io-index"
310추가: checksum = "67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48"
311추가: dependencies = [
312추가: "serde_derive",
313추가: ]
314추가:
315추가: [[package]]
316추가: name = "serde_derive"
317추가: version = "1.0.229"
318추가: source = "registry+https://github.com/rust-lang/crates.io-index"
319추가: checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348"
320추가: dependencies = [
321추가: "proc-macro2",
322추가: "quote",
323추가: "syn",
324추가: ]
325추가:
326추가: [[package]]
327추가: name = "serde_json"
328추가: version = "1.0.154"
329추가: source = "registry+https://github.com/rust-lang/crates.io-index"
330추가: checksum = "e7e9cc8b1b85264074fbcc02a88680c4096b1e47df8f739dceb03bf482f04bd6"
331추가: dependencies = [
332추가: "itoa",
333추가: "memchr",
334추가: "serde",
335추가: "serde_core",
336추가: "zmij",
337추가: ]
338추가:
267339[[package]]
268340name = "sha1"
269341version = "0.10.7"
@@ -309,12 +381,29 @@ version = "2.6.1"
309381source = "registry+https://github.com/rust-lang/crates.io-index"
310382checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292"
311383
384추가: [[package]]
385추가: name = "syn"
386추가: version = "3.0.10"
387추가: source = "registry+https://github.com/rust-lang/crates.io-index"
388추가: checksum = "4ae9ccbea3a7b0b09443036490c8f34a8b1b760fd345e5c0dae0aac718faea79"
389추가: dependencies = [
390추가: "proc-macro2",
391추가: "quote",
392추가: "unicode-ident",
393추가: ]
394추가:
312395[[package]]
313396name = "typenum"
314397version = "1.20.1"
315398source = "registry+https://github.com/rust-lang/crates.io-index"
316399checksum = "b6f5e870be6c3b371b77fe0ee0bafb859fa4964b4404c27de1d380043c4dda20"
317400
401추가: [[package]]
402추가: name = "unicode-ident"
403추가: version = "1.0.27"
404추가: source = "registry+https://github.com/rust-lang/crates.io-index"
405추가: checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563"
406추가:
318407[[package]]
319408name = "version_check"
320409version = "0.9.5"
@@ -337,6 +426,8 @@ dependencies = [
337426 "lzma-rust2",
338427 "pbkdf2",
339428 "png",
429추가: "serde",
430추가: "serde_json",
340431 "sha1",
341432 "sha2 0.10.9",
342433 "subtle",
@@ -366,6 +457,12 @@ version = "0.6.8"
366457source = "registry+https://github.com/rust-lang/crates.io-index"
367458checksum = "b268e58e7c693d7c271f93ffc4ba3b380412554231c85bf61ca7af91042a4112"
368459
460추가: [[package]]
461추가: name = "zmij"
462추가: version = "1.0.23"
463추가: source = "registry+https://github.com/rust-lang/crates.io-index"
464추가: checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b"
465추가:
369466[[package]]
370467name = "zune-core"
371468version = "0.5.3"
수정tests/rust-zip64-compat/Cargo.lock+97-0
@@ -200,6 +200,12 @@ dependencies = [
200200 "generic-array",
201201]
202202
203추가: [[package]]
204추가: name = "itoa"
205추가: version = "1.0.19"
206추가: source = "registry+https://github.com/rust-lang/crates.io-index"
207추가: checksum = "3bd1574e617a9a6c1f8f8181bd7e841e1f20e4277607ef28945765188d6284d4"
208추가:
203209[[package]]
204210name = "libbz2-rs-sys"
205211version = "0.2.6"
@@ -221,6 +227,12 @@ dependencies = [
221227 "sha2 0.11.1",
222228]
223229
230추가: [[package]]
231추가: name = "memchr"
232추가: version = "2.8.3"
233추가: source = "registry+https://github.com/rust-lang/crates.io-index"
234추가: checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98"
235추가:
224236[[package]]
225237name = "miniz_oxide"
226238version = "0.8.9"
@@ -264,6 +276,66 @@ dependencies = [
264276 "miniz_oxide 0.8.9",
265277]
266278
279추가: [[package]]
280추가: name = "proc-macro2"
281추가: version = "1.0.107"
282추가: source = "registry+https://github.com/rust-lang/crates.io-index"
283추가: checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9"
284추가: dependencies = [
285추가: "unicode-ident",
286추가: ]
287추가:
288추가: [[package]]
289추가: name = "quote"
290추가: version = "1.0.47"
291추가: source = "registry+https://github.com/rust-lang/crates.io-index"
292추가: checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001"
293추가: dependencies = [
294추가: "proc-macro2",
295추가: ]
296추가:
297추가: [[package]]
298추가: name = "serde"
299추가: version = "1.0.229"
300추가: source = "registry+https://github.com/rust-lang/crates.io-index"
301추가: checksum = "4148590afebada386688f18773da617792bf2ef03ffc1e4cbd2b1d45b023e0ba"
302추가: dependencies = [
303추가: "serde_core",
304추가: ]
305추가:
306추가: [[package]]
307추가: name = "serde_core"
308추가: version = "1.0.229"
309추가: source = "registry+https://github.com/rust-lang/crates.io-index"
310추가: checksum = "67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48"
311추가: dependencies = [
312추가: "serde_derive",
313추가: ]
314추가:
315추가: [[package]]
316추가: name = "serde_derive"
317추가: version = "1.0.229"
318추가: source = "registry+https://github.com/rust-lang/crates.io-index"
319추가: checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348"
320추가: dependencies = [
321추가: "proc-macro2",
322추가: "quote",
323추가: "syn",
324추가: ]
325추가:
326추가: [[package]]
327추가: name = "serde_json"
328추가: version = "1.0.154"
329추가: source = "registry+https://github.com/rust-lang/crates.io-index"
330추가: checksum = "e7e9cc8b1b85264074fbcc02a88680c4096b1e47df8f739dceb03bf482f04bd6"
331추가: dependencies = [
332추가: "itoa",
333추가: "memchr",
334추가: "serde",
335추가: "serde_core",
336추가: "zmij",
337추가: ]
338추가:
267339[[package]]
268340name = "sha1"
269341version = "0.10.7"
@@ -309,12 +381,29 @@ version = "2.6.1"
309381source = "registry+https://github.com/rust-lang/crates.io-index"
310382checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292"
311383
384추가: [[package]]
385추가: name = "syn"
386추가: version = "3.0.10"
387추가: source = "registry+https://github.com/rust-lang/crates.io-index"
388추가: checksum = "4ae9ccbea3a7b0b09443036490c8f34a8b1b760fd345e5c0dae0aac718faea79"
389추가: dependencies = [
390추가: "proc-macro2",
391추가: "quote",
392추가: "unicode-ident",
393추가: ]
394추가:
312395[[package]]
313396name = "typenum"
314397version = "1.20.1"
315398source = "registry+https://github.com/rust-lang/crates.io-index"
316399checksum = "b6f5e870be6c3b371b77fe0ee0bafb859fa4964b4404c27de1d380043c4dda20"
317400
401추가: [[package]]
402추가: name = "unicode-ident"
403추가: version = "1.0.27"
404추가: source = "registry+https://github.com/rust-lang/crates.io-index"
405추가: checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563"
406추가:
318407[[package]]
319408name = "version_check"
320409version = "0.9.5"
@@ -337,6 +426,8 @@ dependencies = [
337426 "lzma-rust2",
338427 "pbkdf2",
339428 "png",
429추가: "serde",
430추가: "serde_json",
340431 "sha1",
341432 "sha2 0.10.9",
342433 "subtle",
@@ -366,6 +457,12 @@ version = "0.6.8"
366457source = "registry+https://github.com/rust-lang/crates.io-index"
367458checksum = "b268e58e7c693d7c271f93ffc4ba3b380412554231c85bf61ca7af91042a4112"
368459
460추가: [[package]]
461추가: name = "zmij"
462추가: version = "1.0.23"
463추가: source = "registry+https://github.com/rust-lang/crates.io-index"
464추가: checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b"
465추가:
369466[[package]]
370467name = "zune-core"
371468version = "0.5.3"