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 {
22
     Version,
22
     Version,
23
     AuthSummary,
23
     AuthSummary,
24
     TempList,
24
     TempList,
25
+    TempRevoke { authorization_id: String },
26
+    TempRevokeAll,
25
     Quit,
27
     Quit,
26
 }
28
 }
27
 
29
 
garcard/src/agent.rsmodified
@@ -696,6 +696,29 @@ pub fn enumerate_temporary_authorizations() -> Result<Vec<TemporaryAuthorization
696
     Ok(entries)
696
     Ok(entries)
697
 }
697
 }
698
 
698
 
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
+
699
 fn revoke_temporary_authorizations_for_action(action_id: &str) -> Result<usize> {
722
 fn revoke_temporary_authorizations_for_action(action_id: &str) -> Result<usize> {
700
     let connection = Connection::system().context("failed to connect to system bus")?;
723
     let connection = Connection::system().context("failed to connect to system bus")?;
701
     let subject = build_subject();
724
     let subject = build_subject();
garcard/src/daemon.rsmodified
@@ -1,6 +1,7 @@
1
 use crate::agent::{
1
 use crate::agent::{
2
     AuthAgentBackend, PolkitAgent, PolkitBackendConfig, StubPolkitAgent,
2
     AuthAgentBackend, PolkitAgent, PolkitBackendConfig, StubPolkitAgent,
3
-    enumerate_temporary_authorizations,
3
+    enumerate_temporary_authorizations, revoke_all_temporary_authorizations,
4
+    revoke_temporary_authorization_by_id,
4
 };
5
 };
5
 use crate::config::{AgentBackendMode, Config};
6
 use crate::config::{AgentBackendMode, Config};
6
 use crate::state::{AuthState, RuntimeState};
7
 use crate::state::{AuthState, RuntimeState};
@@ -298,6 +299,25 @@ fn dispatch(
298
                 err
299
                 err
299
             )),
300
             )),
300
         },
301
         },
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
+        },
301
         Command::Quit => {
321
         Command::Quit => {
302
             if shutdown_tx.send(()).is_err() {
322
             if shutdown_tx.send(()).is_err() {
303
                 Response::err("daemon shutdown channel unavailable")
323
                 Response::err("daemon shutdown channel unavailable")
garcardctl/src/main.rsmodified
@@ -18,6 +18,8 @@ enum Commands {
18
     Version,
18
     Version,
19
     AuthSummary,
19
     AuthSummary,
20
     TempList,
20
     TempList,
21
+    TempRevoke { authorization_id: String },
22
+    TempRevokeAll,
21
     Quit,
23
     Quit,
22
 }
24
 }
23
 
25
 
@@ -49,6 +51,8 @@ fn to_protocol_command(command: Commands) -> Command {
49
         Commands::Version => Command::Version,
51
         Commands::Version => Command::Version,
50
         Commands::AuthSummary => Command::AuthSummary,
52
         Commands::AuthSummary => Command::AuthSummary,
51
         Commands::TempList => Command::TempList,
53
         Commands::TempList => Command::TempList,
54
+        Commands::TempRevoke { authorization_id } => Command::TempRevoke { authorization_id },
55
+        Commands::TempRevokeAll => Command::TempRevokeAll,
52
         Commands::Quit => Command::Quit,
56
         Commands::Quit => Command::Quit,
53
     }
57
     }
54
 }
58
 }