gardesk/garcard / 202a73b

Browse files

Add temporary authorization revoke commands

Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
202a73b846477cab99f49e815b182fccee619909
Parents
a32a010
Tree
3b5bd26

4 changed files

StatusFile+-
M garcard-ipc/src/lib.rs 2 0
M garcard/src/agent.rs 23 0
M garcard/src/daemon.rs 21 1
M garcardctl/src/main.rs 4 0
garcard-ipc/src/lib.rsmodified
@@ -22,6 +22,8 @@ pub enum Command {
2222
     Version,
2323
     AuthSummary,
2424
     TempList,
25
+    TempRevoke { authorization_id: String },
26
+    TempRevokeAll,
2527
     Quit,
2628
 }
2729
 
garcard/src/agent.rsmodified
@@ -696,6 +696,29 @@ pub fn enumerate_temporary_authorizations() -> Result<Vec<TemporaryAuthorization
696696
     Ok(entries)
697697
 }
698698
 
699
+pub fn revoke_temporary_authorization_by_id(authorization_id: &str) -> Result<()> {
700
+    let connection = Connection::system().context("failed to connect to system bus")?;
701
+    let proxy = PolkitAgent::proxy(&connection)?;
702
+    let _: () = proxy.call("RevokeTemporaryAuthorizationById", &authorization_id)?;
703
+    Ok(())
704
+}
705
+
706
+pub fn revoke_all_temporary_authorizations() -> Result<usize> {
707
+    let connection = Connection::system().context("failed to connect to system bus")?;
708
+    let subject = build_subject();
709
+    let proxy = PolkitAgent::proxy(&connection)?;
710
+    let authorizations: Vec<TemporaryAuthorization> =
711
+        proxy.call("EnumerateTemporaryAuthorizations", &subject)?;
712
+
713
+    let mut revoked = 0_usize;
714
+    for (authorization_id, _action_id, _subject, _obtained, _expires) in authorizations {
715
+        let _: () = proxy.call("RevokeTemporaryAuthorizationById", &authorization_id)?;
716
+        revoked += 1;
717
+    }
718
+
719
+    Ok(revoked)
720
+}
721
+
699722
 fn revoke_temporary_authorizations_for_action(action_id: &str) -> Result<usize> {
700723
     let connection = Connection::system().context("failed to connect to system bus")?;
701724
     let subject = build_subject();
garcard/src/daemon.rsmodified
@@ -1,6 +1,7 @@
11
 use crate::agent::{
22
     AuthAgentBackend, PolkitAgent, PolkitBackendConfig, StubPolkitAgent,
3
-    enumerate_temporary_authorizations,
3
+    enumerate_temporary_authorizations, revoke_all_temporary_authorizations,
4
+    revoke_temporary_authorization_by_id,
45
 };
56
 use crate::config::{AgentBackendMode, Config};
67
 use crate::state::{AuthState, RuntimeState};
@@ -298,6 +299,25 @@ fn dispatch(
298299
                 err
299300
             )),
300301
         },
302
+        Command::TempRevoke { authorization_id } => {
303
+            match revoke_temporary_authorization_by_id(authorization_id.as_str()) {
304
+                Ok(()) => Response::ok_with_data(json!({
305
+                    "authorization_id": authorization_id,
306
+                    "revoked": true
307
+                })),
308
+                Err(err) => Response::err(format!(
309
+                    "failed to revoke temporary authorization {}: {}",
310
+                    authorization_id, err
311
+                )),
312
+            }
313
+        }
314
+        Command::TempRevokeAll => match revoke_all_temporary_authorizations() {
315
+            Ok(revoked_count) => Response::ok_with_data(json!({ "revoked_count": revoked_count })),
316
+            Err(err) => Response::err(format!(
317
+                "failed to revoke temporary authorizations: {}",
318
+                err
319
+            )),
320
+        },
301321
         Command::Quit => {
302322
             if shutdown_tx.send(()).is_err() {
303323
                 Response::err("daemon shutdown channel unavailable")
garcardctl/src/main.rsmodified
@@ -18,6 +18,8 @@ enum Commands {
1818
     Version,
1919
     AuthSummary,
2020
     TempList,
21
+    TempRevoke { authorization_id: String },
22
+    TempRevokeAll,
2123
     Quit,
2224
 }
2325
 
@@ -49,6 +51,8 @@ fn to_protocol_command(command: Commands) -> Command {
4951
         Commands::Version => Command::Version,
5052
         Commands::AuthSummary => Command::AuthSummary,
5153
         Commands::TempList => Command::TempList,
54
+        Commands::TempRevoke { authorization_id } => Command::TempRevoke { authorization_id },
55
+        Commands::TempRevokeAll => Command::TempRevokeAll,
5256
         Commands::Quit => Command::Quit,
5357
     }
5458
 }