gardesk/garcard / 2138e2e

Browse files

Send username and cookie to helper socket

Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
2138e2e45bc0121f2a69c12a4b547517da0536eb
Parents
b81c372
Tree
582ff05

1 changed file

StatusFile+-
M garcard/src/polkit_helper.rs 14 8
garcard/src/polkit_helper.rsmodified
@@ -77,7 +77,7 @@ impl HelperSocketClient {
7777
         cookie: &str,
7878
         prompts: &mut P,
7979
     ) -> Result<HelperOutcome> {
80
-        let username_label = sanitize_control_line(username);
80
+        let username_line = 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,17 +87,17 @@ impl HelperSocketClient {
8787
         })?;
8888
         let cookie_preview: String = cookie_line.chars().take(16).collect();
8989
         tracing::debug!(
90
-            username = %username_label,
90
+            username = %username_line,
9191
             cookie_len = cookie_line.len(),
9292
             cookie_preview = %cookie_preview,
9393
             socket = %self.socket_path.display(),
94
-            protocol = "socket-activated-cookie-only",
94
+            protocol = "socket-activated-username-cookie",
9595
             "Connected to polkit helper socket"
9696
         );
97
-        if username_label.len() != username.len() || cookie_line.len() != cookie.len() {
97
+        if username_line.len() != username.len() || cookie_line.len() != cookie.len() {
9898
             tracing::debug!(
9999
                 original_username_len = username.len(),
100
-                normalized_username_len = username_label.len(),
100
+                normalized_username_len = username_line.len(),
101101
                 original_cookie_len = cookie.len(),
102102
                 normalized_cookie_len = cookie_line.len(),
103103
                 "Normalized helper auth control lines before send"
@@ -108,8 +108,9 @@ impl HelperSocketClient {
108108
             .context("failed to clone helper socket stream")?;
109109
         let mut reader = BufReader::new(read_stream);
110110
 
111
-        // socket-activated polkit helper resolves identity from peer credentials.
112
-        // It expects only the cookie line from the agent protocol stream.
111
+        // polkit 127 socket-activated helper reads two control lines:
112
+        // username first, then cookie.
113
+        write_line(&mut stream, &username_line).context("failed to send helper username")?;
113114
         write_line(&mut stream, &cookie_line).context("failed to send helper cookie")?;
114115
 
115116
         loop {
@@ -397,6 +398,8 @@ mod tests {
397398
             let read_stream = stream.try_clone().expect("clone");
398399
             let mut reader = BufReader::new(read_stream);
399400
 
401
+            let mut username = String::new();
402
+            reader.read_line(&mut username).expect("read username");
400403
             let mut cookie = String::new();
401404
             reader.read_line(&mut cookie).expect("read cookie");
402405
 
@@ -410,6 +413,7 @@ mod tests {
410413
 
411414
             {
412415
                 let mut lines = transcript_for_thread.lock().expect("lock transcript");
416
+                lines.push(username.trim().to_string());
413417
                 lines.push(cookie.trim().to_string());
414418
                 lines.push(secret.trim().to_string());
415419
             }
@@ -433,7 +437,7 @@ mod tests {
433437
         server.join().expect("server join");
434438
 
435439
         let lines = transcript.lock().expect("lock transcript");
436
-        assert_eq!(lines.as_slice(), ["cookie-123", "correct horse"]);
440
+        assert_eq!(lines.as_slice(), ["alice", "cookie-123", "correct horse"]);
437441
 
438442
         let _ = std::fs::remove_file(&socket_path);
439443
     }
@@ -448,6 +452,8 @@ mod tests {
448452
             let read_stream = stream.try_clone().expect("clone");
449453
             let mut reader = BufReader::new(read_stream);
450454
 
455
+            let mut username = String::new();
456
+            reader.read_line(&mut username).expect("read username");
451457
             let mut cookie = String::new();
452458
             reader.read_line(&mut cookie).expect("read cookie");
453459