gardesk/garcard / e76249f

Browse files

Send cookie only to socket helper

Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
e76249f555190e1f654ea3eb87307dfcafff9366
Parents
f2eb902
Tree
3cbb92b

1 changed file

StatusFile+-
M garcard/src/polkit_helper.rs 8 11
garcard/src/polkit_helper.rsmodified
@@ -77,7 +77,7 @@ impl HelperSocketClient {
7777
         cookie: &str,
7878
         prompts: &mut P,
7979
     ) -> Result<HelperOutcome> {
80
-        let username_line = sanitize_control_line(username);
80
+        let username_label = sanitize_control_line(username);
8181
         let cookie_line = sanitize_control_line(cookie);
8282
         let mut stream = UnixStream::connect(&self.socket_path).with_context(|| {
8383
             format!(
@@ -87,16 +87,17 @@ impl HelperSocketClient {
8787
         })?;
8888
         let cookie_preview: String = cookie_line.chars().take(16).collect();
8989
         tracing::debug!(
90
-            username = %username_line,
90
+            username = %username_label,
9191
             cookie_len = cookie_line.len(),
9292
             cookie_preview = %cookie_preview,
9393
             socket = %self.socket_path.display(),
94
+            protocol = "socket-activated-cookie-only",
9495
             "Connected to polkit helper socket"
9596
         );
96
-        if username_line.len() != username.len() || cookie_line.len() != cookie.len() {
97
+        if username_label.len() != username.len() || cookie_line.len() != cookie.len() {
9798
             tracing::debug!(
9899
                 original_username_len = username.len(),
99
-                normalized_username_len = username_line.len(),
100
+                normalized_username_len = username_label.len(),
100101
                 original_cookie_len = cookie.len(),
101102
                 normalized_cookie_len = cookie_line.len(),
102103
                 "Normalized helper auth control lines before send"
@@ -107,7 +108,8 @@ impl HelperSocketClient {
107108
             .context("failed to clone helper socket stream")?;
108109
         let mut reader = BufReader::new(read_stream);
109110
 
110
-        write_line(&mut stream, &username_line).context("failed to send helper username")?;
111
+        // socket-activated polkit helper resolves identity from peer credentials.
112
+        // It expects only the cookie line from the agent protocol stream.
111113
         write_line(&mut stream, &cookie_line).context("failed to send helper cookie")?;
112114
 
113115
         loop {
@@ -395,8 +397,6 @@ mod tests {
395397
             let read_stream = stream.try_clone().expect("clone");
396398
             let mut reader = BufReader::new(read_stream);
397399
 
398
-            let mut username = String::new();
399
-            reader.read_line(&mut username).expect("read username");
400400
             let mut cookie = String::new();
401401
             reader.read_line(&mut cookie).expect("read cookie");
402402
 
@@ -410,7 +410,6 @@ mod tests {
410410
 
411411
             {
412412
                 let mut lines = transcript_for_thread.lock().expect("lock transcript");
413
-                lines.push(username.trim().to_string());
414413
                 lines.push(cookie.trim().to_string());
415414
                 lines.push(secret.trim().to_string());
416415
             }
@@ -434,7 +433,7 @@ mod tests {
434433
         server.join().expect("server join");
435434
 
436435
         let lines = transcript.lock().expect("lock transcript");
437
-        assert_eq!(lines.as_slice(), ["alice", "cookie-123", "correct horse"]);
436
+        assert_eq!(lines.as_slice(), ["cookie-123", "correct horse"]);
438437
 
439438
         let _ = std::fs::remove_file(&socket_path);
440439
     }
@@ -449,8 +448,6 @@ mod tests {
449448
             let read_stream = stream.try_clone().expect("clone");
450449
             let mut reader = BufReader::new(read_stream);
451450
 
452
-            let mut username = String::new();
453
-            reader.read_line(&mut username).expect("read username");
454451
             let mut cookie = String::new();
455452
             reader.read_line(&mut cookie).expect("read cookie");
456453