diff --git a/CHANGELOG.md b/CHANGELOG.md index 827ee85..20c9a61 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Unreleased +- Client database ID lookup now checks the returned UID and rejects conflicting IDs instead of passing unrelated notification rows to callers. + - Group creation no longer returns an existing group or a same-name group of another type as the newly created group. Follow-up permissions require one matching new ID. - Searching a channel directory filters the loaded file names locally. Refreshing the same folder keeps the filter; opening another folder clears it. diff --git a/core/src/admin.rs b/core/src/admin.rs index 6f95c07..0ac1a7b 100644 --- a/core/src/admin.rs +++ b/core/src/admin.rs @@ -684,6 +684,7 @@ pub enum Reply { /// `channelgetdescription`: the description comes from `notifychanneledited`. Description { channel_id: u64, description: Option }, ChannelInfo { channel_id: u64 }, + DatabaseId { uid: String, id: Option, ambiguous: bool }, /// `permissionlist` refresh before answering `admin_context`. Context, } @@ -699,6 +700,7 @@ impl Reply { Reply::Rows { notify, .. } => Some(notify), Reply::Token { .. } => Some("notifytokenadd"), Reply::GroupCreated { notify, .. } => Some(notify), + Reply::DatabaseId { .. } => Some("notifyclientdbidfromuid"), Reply::ChannelInfo { .. } | Reply::Description { .. } => Some("notifychanneledited"), Reply::Created { .. } => Some("notifychannelcreated"), _ => None, @@ -739,6 +741,15 @@ impl Reply { } } }, + Reply::DatabaseId { uid, id, ambiguous } if raw.name == "notifyclientdbidfromuid" => { + for row in &raw.items { + if row.get("cluid") != Some(uid) { continue; } + if let Some(found) = row.get("cldbid").and_then(|s| s.parse::().ok()).filter(|n| *n > 0) { + if id.is_some_and(|previous| previous != found) { *ambiguous = true; } + *id = Some(found); + } + } + } Reply::Token { token } if raw.name == "notifytokenadd" => { *token = raw.items.first().and_then(|i| i.get("token")).cloned(); } @@ -769,6 +780,8 @@ pub fn finish(reply: Reply) -> Result { format!("the server returned more than {MAX_ROWS} rows; the list is not complete"), )), Reply::Rows { rows, .. } => Ok(json!({ "rows": rows })), + Reply::DatabaseId { uid, id: Some(id), ambiguous: false } => Ok(json!({"rows":[{"cluid":uid,"cldbid":id.to_string()}]})), + Reply::DatabaseId { .. } => Err(ErrorObj::new(ErrorCode::ServerError, "server did not return a unique database ID for the requested UID")), Reply::GroupCreated { group_id: Some(id), ambiguous: false, .. } => Ok(json!({ "group_id": id })), Reply::GroupCreated { .. } => Err(ErrorObj::new(ErrorCode::ServerError, "group was accepted but its ID was not uniquely returned; reload groups before continuing").with_detail(json!({"created": true}))), Reply::ChannelInfo { .. } => Err(ErrorObj::new(ErrorCode::Internal, "channel info is answered by the session")), @@ -996,6 +1009,23 @@ mod tests { Live { own_client: 7, server_uid: "srv=", channel, group_ids: &|_| Default::default() } } + #[test] + fn database_id_lookup_requires_the_requested_uid_and_one_positive_id() { + let cmd = parse_json("client_database_id", json!({"uid":"peer/one="})).unwrap(); + let lookup = |packets: &[&[u8]]| { + let (_, mut reply) = build(&cmd, &live(&|_| None)).unwrap(); + for packet in packets { reply.collect(&crate::rawcmd::parse(packet).unwrap()); } + finish(reply) + }; + let foreign = br"notifyclientdbidfromuid cluid=other cldbid=9|cldbid=10".as_slice(); + let zero = br"notifyclientdbidfromuid cluid=peer\/one= cldbid=0".as_slice(); + let found = br"notifyclientdbidfromuid cluid=other cldbid=9|cluid=peer\/one= cldbid=17|cldbid=23".as_slice(); + let conflict = br"notifyclientdbidfromuid cluid=peer\/one= cldbid=18".as_slice(); + assert_eq!(lookup(&[foreign,zero]).unwrap_err().code, ErrorCode::ServerError); + assert_eq!(lookup(&[found,foreign,found]).unwrap(), json!({"rows":[{"cluid":"peer/one=","cldbid":"17"}]})); + assert_eq!(lookup(&[found,conflict]).unwrap_err().code, ErrorCode::ServerError); + } + #[test] fn group_add_requires_a_unique_new_id_of_the_requested_type() { use extra::GroupKind; diff --git a/core/src/admin_extra.rs b/core/src/admin_extra.rs index 87c3b43..86b4657 100644 --- a/core/src/admin_extra.rs +++ b/core/src/admin_extra.rs @@ -86,7 +86,7 @@ impl Command { Self::ClientDatabaseList{start,duration}=>(menu::command("clientdblist",&[("start",start.to_string()),("duration",duration.to_string())]),Reply::rows("notifyclientdblist",None)), Self::ClientDatabaseFind{pattern,uid}=>{let mut c=menu::command("clientdbfind",&[("pattern",pattern.clone()),("-details",String::new())]);if *uid{c.write_arg("-uid",&"");}(c,Reply::rows("notifyclientdbfind",None))}, Self::ClientDatabaseDelete{client_database_id,..}=>(menu::command("clientdbdelete",&[("cldbid",s(*client_database_id))]),Reply::Ack), - Self::ClientDatabaseId{uid}=>(menu::command("clientgetdbidfromuid",&[("cluid",uid.clone())]),Reply::rows("notifyclientdbidfromuid",None)), + Self::ClientDatabaseId{uid}=>(menu::command("clientgetdbidfromuid",&[("cluid",uid.clone())]),Reply::DatabaseId{uid:uid.clone(),id:None,ambiguous:false}), Self::ServerGroupList{}=>(menu::command("servergrouplist",&[]),Reply::rows("notifyservergrouplist",None)), Self::ChannelGroupList{}=>(menu::command("channelgrouplist",&[]),Reply::rows("notifychannelgrouplist",None)), Self::GroupAdd{kind,name,group_type,..}=>{ diff --git a/core/src/admin_session.rs b/core/src/admin_session.rs index 9fbc364..ae4f148 100644 --- a/core/src/admin_session.rs +++ b/core/src/admin_session.rs @@ -191,6 +191,7 @@ impl Session { (admin::Reply::Rows { notify: "notifyserverupdated", overflow: false, .. }, Ok(())) => { self.conn.as_ref().map(|c| json!({ "rows": [c.extras.server_properties()] })).ok_or_else(not_connected) } + (admin::Reply::DatabaseId { .. }, Err(e)) if e.error.to_u32() == Some(admin::DATABASE_EMPTY_RESULT) => Ok(json!({ "rows": [] })), (admin::Reply::Rows { .. }, Err(e)) if empty(&e) => Ok(json!({ "rows": [] })), (_, Err(e)) => Err(command_error(&e)), (reply, Ok(())) => admin::finish(reply), diff --git a/docs/bridge.md b/docs/bridge.md index 5d421f0..838a4bd 100644 --- a/docs/bridge.md +++ b/docs/bridge.md @@ -693,7 +693,7 @@ For an isolated Windows beta14 fixture at `127.0.0.1:19987`, set `TEAMSPEACH_QA_ | `client_database_list` | `{start:u32,duration:1..200}` | | `client_database_find` | `{pattern,uid:bool}`; `clientdbfind -details [-uid]` | | `client_database_delete` | `{generation,client_database_id,confirm}`; confirm decimal database ID | -| `client_database_id` | `{uid}`; rows with `cluid/cldbid` | +| `client_database_id` | `{uid}`; returns one row with the exact requested `cluid` and a positive decimal-string `cldbid`. Duplicate reports of the same ID are accepted. A successful command result without a unique matching ID is an error; the server's explicit database-empty result returns an empty list. | | `server_group_list` / `channel_group_list` | `{}` | | `server_group_perm_list` / `channel_group_perm_list` | `{group_id}` | | `channel_perm_list` | `{channel_id}` | diff --git a/docs/mobile-port-progress.md b/docs/mobile-port-progress.md index 203890c..4d98f3d 100644 --- a/docs/mobile-port-progress.md +++ b/docs/mobile-port-progress.md @@ -4,6 +4,8 @@ ## Возврат к разработке на ПК, 2026-11-26 +Windows, база `25575d1`: ядро сопоставляет `client_database_id` с точным UID в уведомлении и требует один положительный ID базы. Три адресных теста прошли; живой поиск через интерфейс в этом прогоне не проверялся. + Windows, база `d841530`: для `group_add` ядро исключает ранее известные ID групп нужной категории и сверяет имя и тип ответа. Проверены нулевой ID, повтор одного нового ID и неоднозначный ответ. Прошли три теста ядра и два теста импорта снимков. Создание серверной или канальной группы на живом стенде этим прогоном не подтверждено. Windows, база `643d0e4`: поиск в браузере файлов фильтрует загруженные имена, сохраняет переход к родителю и сбрасывается при смене каталога. Тест Slint проверил обновление списка, регистр кириллицы и цель контекстного меню. Прошли три адресных теста; сетевой обмен файлами не проверялся.