From 9c5c383bff76786a6f0a2d1ed8b453e93ae03ba3 Mon Sep 17 00:00:00 2001 From: Dominik Csapak Date: Tue, 19 May 2020 16:24:54 +0200 Subject: [PATCH] user: create default root user as typed struct we added a userid attribute to the User struct, but missed that we created the default user without that attribuet via the json! macro which lead to a runtime panic on the deserialization by using the struct directly, such errors will be caught by the compiler in the future with this change, we can remove the serde_json import here Signed-off-by: Dominik Csapak --- src/config/user.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/config/user.rs b/src/config/user.rs index 261b1d21..b280ecc8 100644 --- a/src/config/user.rs +++ b/src/config/user.rs @@ -4,7 +4,6 @@ use std::sync::{Arc, RwLock}; use anyhow::{bail, Error}; use lazy_static::lazy_static; use serde::{Serialize, Deserialize}; -use serde_json::json; use proxmox::api::{ api, @@ -136,9 +135,15 @@ pub fn config() -> Result<(SectionConfigData, [u8;32]), Error> { let mut data = CONFIG.parse(USER_CFG_FILENAME, &content)?; if data.sections.get("root@pam").is_none() { - let user: User = serde_json::from_value(json!({ - "comment": "Superuser", - })).unwrap(); + let user: User = User { + userid: "root@pam".to_string(), + comment: Some("Superuser".to_string()), + enable: None, + expire: None, + firstname: None, + lastname: None, + email: None, + }; data.set_data("root@pam", "user", &user).unwrap(); }