public inbox for pmg-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Dominik Csapak <d.csapak@proxmox.com>
To: pmg-devel@lists.proxmox.com
Subject: [pmg-devel] [PATCH proxmox] login: use 'PMG' as product for 'PMGQUAR' tickets
Date: Wed, 25 Jun 2025 09:38:44 +0200	[thread overview]
Message-ID: <20250625073844.609286-1-d.csapak@proxmox.com> (raw)

We derive the product name from the beginning of the ticket normally,
but this does not work with PMGQUAR tickets. Since the cookie name uses
the product name, this results in a `PMGQUARAuthCookie`, but the cookie
still has to be `PMGAuthCookie` to work. To work around that, decouple
the userid range of the ticket from the product range, and modify it so
that PMGQUAR tickets return also PMG for the product. This will result
in the correct `PMGAuthCookie` name.

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
this is actually not used anywhere yet, but is necessary when we'll want
to use rust/yew for the quarantine interface, since that uses this
ticket for setting cookies, etc.

 proxmox-login/src/ticket.rs | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/proxmox-login/src/ticket.rs b/proxmox-login/src/ticket.rs
index 4b28f26e..5e90c8cb 100644
--- a/proxmox-login/src/ticket.rs
+++ b/proxmox-login/src/ticket.rs
@@ -49,6 +49,7 @@ pub struct Ticket {
     data: Box<str>,
     timestamp: i64,
     product_len: u16,
+    userid_start: u16,
     userid_len: u16,
     // timestamp_len: u16,
 }
@@ -66,7 +67,7 @@ impl Ticket {
 
     /// The userid contained in the ticket.
     pub fn userid(&self) -> &str {
-        let start = usize::from(self.product_len) + 1;
+        let start = usize::from(self.userid_start);
         let len = usize::from(self.userid_len);
         &self.data[start..(start + len)]
     }
@@ -138,12 +139,17 @@ impl std::str::FromStr for Ticket {
         let data = s;
 
         // get product:
-        let product_len = s.find(':').ok_or(TicketError)?;
+        let mut product_len = s.find(':').ok_or(TicketError)?;
         if product_len >= 10 {
             // weird product
             return Err(TicketError);
         }
-        let s = &s[(product_len + 1)..];
+        let userid_start = product_len + 1;
+        // work around PMG quarantine tickets
+        if &s[..product_len] == "PMGQUAR" {
+            product_len = 3;
+        }
+        let s = &s[userid_start..];
 
         // get userid:
         let userid_len = s.find(':').ok_or(TicketError)?;
@@ -165,6 +171,7 @@ impl std::str::FromStr for Ticket {
 
         Ok(Self {
             product_len: u16::try_from(product_len).map_err(|_| TicketError)?,
+            userid_start: u16::try_from(userid_start).map_err(|_| TicketError)?,
             userid_len: u16::try_from(userid_len).map_err(|_| TicketError)?,
             //timestamp_len: u16::try_from(timestamp_len).map_err(|_| TicketError)?,
             timestamp,
-- 
2.39.5



_______________________________________________
pmg-devel mailing list
pmg-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pmg-devel


             reply	other threads:[~2025-06-25  7:38 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-25  7:38 Dominik Csapak [this message]
2025-07-03  7:49 ` [pmg-devel] applied: " Thomas Lamprecht

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250625073844.609286-1-d.csapak@proxmox.com \
    --to=d.csapak@proxmox.com \
    --cc=pmg-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal