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 <d.csapak@proxmox.com>
This commit is contained in:
		
				
					committed by
					
						
						Dietmar Maurer
					
				
			
			
				
	
			
			
			
						parent
						
							7d4e362993
						
					
				
				
					commit
					9c5c383bff
				
			@ -4,7 +4,6 @@ use std::sync::{Arc, RwLock};
 | 
				
			|||||||
use anyhow::{bail, Error};
 | 
					use anyhow::{bail, Error};
 | 
				
			||||||
use lazy_static::lazy_static;
 | 
					use lazy_static::lazy_static;
 | 
				
			||||||
use serde::{Serialize, Deserialize};
 | 
					use serde::{Serialize, Deserialize};
 | 
				
			||||||
use serde_json::json;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
use proxmox::api::{
 | 
					use proxmox::api::{
 | 
				
			||||||
    api,
 | 
					    api,
 | 
				
			||||||
@ -136,9 +135,15 @@ pub fn config() -> Result<(SectionConfigData, [u8;32]), Error> {
 | 
				
			|||||||
    let mut data = CONFIG.parse(USER_CFG_FILENAME, &content)?;
 | 
					    let mut data = CONFIG.parse(USER_CFG_FILENAME, &content)?;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if data.sections.get("root@pam").is_none() {
 | 
					    if data.sections.get("root@pam").is_none() {
 | 
				
			||||||
        let user: User = serde_json::from_value(json!({
 | 
					        let user: User = User {
 | 
				
			||||||
            "comment": "Superuser",
 | 
					            userid: "root@pam".to_string(),
 | 
				
			||||||
        })).unwrap();
 | 
					            comment: Some("Superuser".to_string()),
 | 
				
			||||||
 | 
					            enable: None,
 | 
				
			||||||
 | 
					            expire: None,
 | 
				
			||||||
 | 
					            firstname: None,
 | 
				
			||||||
 | 
					            lastname: None,
 | 
				
			||||||
 | 
					            email: None,
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
        data.set_data("root@pam", "user", &user).unwrap();
 | 
					        data.set_data("root@pam", "user", &user).unwrap();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user