MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / kill_user_sessions

Function kill_user_sessions

nodedb/src/control/server/pgwire/ddl/session_ddl.rs:176–216  ·  view source on GitHub ↗

KILL USER SESSIONS ' '

(
    state: &SharedState,
    identity: &AuthenticatedIdentity,
    parts: &[&str],
)

Source from the content-addressed store, hash-verified

174
175/// KILL USER SESSIONS '<auth_user_id>'
176pub fn kill_user_sessions(
177 state: &SharedState,
178 identity: &AuthenticatedIdentity,
179 parts: &[&str],
180) -> PgWireResult<Vec<Response>> {
181 if !identity.is_superuser {
182 return Err(sqlstate_error(
183 "42501",
184 "permission denied: requires superuser",
185 ));
186 }
187 if parts.len() < 4 {
188 return Err(sqlstate_error(
189 "42601",
190 "syntax: KILL USER SESSIONS '<auth_user_id>'",
191 ));
192 }
193 let user_id_str = parts[3].trim_matches('\'');
194 let user_id: u64 = user_id_str.parse().map_err(|_| {
195 sqlstate_error(
196 "22003",
197 &format!("invalid user_id '{user_id_str}': must be numeric"),
198 )
199 })?;
200
201 let killed = state.session_registry.kill_sessions_for_user(
202 user_id,
203 crate::control::security::sessions::KillReason::AdminKill,
204 );
205
206 state.audit_record(
207 crate::control::security::audit::AuditEvent::AdminAction,
208 Some(identity.tenant_id),
209 &identity.username,
210 &format!("killed {killed} sessions for user_id={user_id}"),
211 );
212
213 Ok(vec![Response::Execution(Tag::new(&format!(
214 "KILL {killed}"
215 )))])
216}
217
218/// VERIFY AUDIT CHAIN
219pub fn verify_audit_chain(

Callers 1

dispatchFunction · 0.85

Calls 5

audit_recordMethod · 0.80
sqlstate_errorFunction · 0.70
lenMethod · 0.45
parseMethod · 0.45

Tested by

no test coverage detected