use new atomic_open_or_create_file
Factor out open_backup_lockfile() method to acquire locks owned by user backup with permission 0660. Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
committed by
Thomas Lamprecht
parent
a00888e93f
commit
7526d86419
@ -3,12 +3,12 @@
|
||||
use anyhow::{bail, Error};
|
||||
|
||||
use proxmox::api::{api, Router, RpcEnvironment, Permission};
|
||||
use proxmox::tools::fs::open_file_locked;
|
||||
|
||||
use crate::api2::types::*;
|
||||
use crate::config::acl;
|
||||
use crate::config::acl::{Role, PRIV_SYS_AUDIT, PRIV_PERMISSIONS_MODIFY};
|
||||
use crate::config::cached_user_info::CachedUserInfo;
|
||||
use crate::backup::open_backup_lockfile;
|
||||
|
||||
fn extract_acl_node_data(
|
||||
node: &acl::AclTreeNode,
|
||||
@ -200,7 +200,7 @@ pub fn update_acl(
|
||||
};
|
||||
}
|
||||
|
||||
let _lock = open_file_locked(acl::ACL_CFG_LOCKFILE, std::time::Duration::new(10, 0), true)?;
|
||||
let _lock = open_backup_lockfile(acl::ACL_CFG_LOCKFILE, None, true)?;
|
||||
|
||||
let (mut tree, expected_digest) = acl::config()?;
|
||||
|
||||
|
@ -9,7 +9,6 @@ use proxmox::api::router::{Router, SubdirMap};
|
||||
use proxmox::api::{api, Permission, RpcEnvironment};
|
||||
use proxmox::{list_subdirs_api_method};
|
||||
use proxmox::{identity, sortable};
|
||||
use proxmox::tools::fs::open_file_locked;
|
||||
|
||||
use proxmox_openid::{OpenIdAuthenticator, OpenIdConfig};
|
||||
|
||||
@ -22,6 +21,8 @@ use crate::server::ticket::ApiTicket;
|
||||
use crate::config::domains::{OpenIdUserAttribute, OpenIdRealmConfig};
|
||||
use crate::config::cached_user_info::CachedUserInfo;
|
||||
|
||||
use crate::backup::open_backup_lockfile;
|
||||
|
||||
use crate::api2::types::*;
|
||||
use crate::auth_helpers::*;
|
||||
|
||||
@ -117,7 +118,7 @@ pub fn openid_login(
|
||||
if !user_info.is_active_user_id(&user_id) {
|
||||
if config.autocreate.unwrap_or(false) {
|
||||
use crate::config::user;
|
||||
let _lock = open_file_locked(user::USER_CFG_LOCKFILE, std::time::Duration::new(10, 0), true)?;
|
||||
let _lock = open_backup_lockfile(user::USER_CFG_LOCKFILE, None, true)?;
|
||||
let user = user::User {
|
||||
userid: user_id.clone(),
|
||||
comment: None,
|
||||
|
@ -8,7 +8,6 @@ use std::collections::HashMap;
|
||||
use proxmox::api::{api, ApiMethod, Router, RpcEnvironment, Permission};
|
||||
use proxmox::api::router::SubdirMap;
|
||||
use proxmox::api::schema::{Schema, StringSchema};
|
||||
use proxmox::tools::fs::open_file_locked;
|
||||
|
||||
use pbs_api_types::{
|
||||
PASSWORD_FORMAT, PROXMOX_CONFIG_DIGEST_SCHEMA, SINGLE_LINE_COMMENT_SCHEMA, Authid,
|
||||
@ -19,6 +18,7 @@ use crate::config::user;
|
||||
use crate::config::token_shadow;
|
||||
use crate::config::acl::{PRIV_SYS_AUDIT, PRIV_PERMISSIONS_MODIFY};
|
||||
use crate::config::cached_user_info::CachedUserInfo;
|
||||
use crate::backup::open_backup_lockfile;
|
||||
|
||||
pub const PBS_PASSWORD_SCHEMA: Schema = StringSchema::new("User Password.")
|
||||
.format(&PASSWORD_FORMAT)
|
||||
@ -169,7 +169,7 @@ pub fn create_user(
|
||||
rpcenv: &mut dyn RpcEnvironment
|
||||
) -> Result<(), Error> {
|
||||
|
||||
let _lock = open_file_locked(user::USER_CFG_LOCKFILE, std::time::Duration::new(10, 0), true)?;
|
||||
let _lock = open_backup_lockfile(user::USER_CFG_LOCKFILE, None, true)?;
|
||||
|
||||
let user: user::User = serde_json::from_value(param)?;
|
||||
|
||||
@ -311,7 +311,7 @@ pub fn update_user(
|
||||
rpcenv: &mut dyn RpcEnvironment,
|
||||
) -> Result<(), Error> {
|
||||
|
||||
let _lock = open_file_locked(user::USER_CFG_LOCKFILE, std::time::Duration::new(10, 0), true)?;
|
||||
let _lock = open_backup_lockfile(user::USER_CFG_LOCKFILE, None, true)?;
|
||||
|
||||
let (mut config, expected_digest) = user::config()?;
|
||||
|
||||
@ -404,7 +404,7 @@ pub fn update_user(
|
||||
pub fn delete_user(userid: Userid, digest: Option<String>) -> Result<(), Error> {
|
||||
|
||||
let _tfa_lock = crate::config::tfa::write_lock()?;
|
||||
let _lock = open_file_locked(user::USER_CFG_LOCKFILE, std::time::Duration::new(10, 0), true)?;
|
||||
let _lock = open_backup_lockfile(user::USER_CFG_LOCKFILE, None, true)?;
|
||||
|
||||
let (mut config, expected_digest) = user::config()?;
|
||||
|
||||
@ -540,7 +540,7 @@ pub fn generate_token(
|
||||
digest: Option<String>,
|
||||
) -> Result<Value, Error> {
|
||||
|
||||
let _lock = open_file_locked(user::USER_CFG_LOCKFILE, std::time::Duration::new(10, 0), true)?;
|
||||
let _lock = open_backup_lockfile(user::USER_CFG_LOCKFILE, None, true)?;
|
||||
|
||||
let (mut config, expected_digest) = user::config()?;
|
||||
|
||||
@ -621,7 +621,7 @@ pub fn update_token(
|
||||
digest: Option<String>,
|
||||
) -> Result<(), Error> {
|
||||
|
||||
let _lock = open_file_locked(user::USER_CFG_LOCKFILE, std::time::Duration::new(10, 0), true)?;
|
||||
let _lock = open_backup_lockfile(user::USER_CFG_LOCKFILE, None, true)?;
|
||||
|
||||
let (mut config, expected_digest) = user::config()?;
|
||||
|
||||
@ -689,7 +689,7 @@ pub fn delete_token(
|
||||
digest: Option<String>,
|
||||
) -> Result<(), Error> {
|
||||
|
||||
let _lock = open_file_locked(user::USER_CFG_LOCKFILE, std::time::Duration::new(10, 0), true)?;
|
||||
let _lock = open_backup_lockfile(user::USER_CFG_LOCKFILE, None, true)?;
|
||||
|
||||
let (mut config, expected_digest) = user::config()?;
|
||||
|
||||
|
@ -60,7 +60,7 @@ pub fn list_datastores(
|
||||
}
|
||||
|
||||
pub(crate) fn do_create_datastore(
|
||||
_lock: std::fs::File,
|
||||
_lock: BackupLockGuard,
|
||||
mut config: SectionConfigData,
|
||||
datastore: DataStoreConfig,
|
||||
worker: Option<&dyn TaskState>,
|
||||
|
@ -4,7 +4,6 @@ use ::serde::{Deserialize, Serialize};
|
||||
|
||||
use proxmox::api::{api, ApiMethod, Router, RpcEnvironment, Permission};
|
||||
use proxmox::http_err;
|
||||
use proxmox::tools::fs::open_file_locked;
|
||||
|
||||
use pbs_client::{HttpClient, HttpClientOptions};
|
||||
|
||||
@ -12,6 +11,7 @@ use crate::api2::types::*;
|
||||
use crate::config::cached_user_info::CachedUserInfo;
|
||||
use crate::config::remote;
|
||||
use crate::config::acl::{PRIV_REMOTE_AUDIT, PRIV_REMOTE_MODIFY};
|
||||
use crate::backup::open_backup_lockfile;
|
||||
|
||||
#[api(
|
||||
input: {
|
||||
@ -95,7 +95,7 @@ pub fn list_remotes(
|
||||
/// Create new remote.
|
||||
pub fn create_remote(password: String, param: Value) -> Result<(), Error> {
|
||||
|
||||
let _lock = open_file_locked(remote::REMOTE_CFG_LOCKFILE, std::time::Duration::new(10, 0), true)?;
|
||||
let _lock = open_backup_lockfile(remote::REMOTE_CFG_LOCKFILE, None, true)?;
|
||||
|
||||
let mut data = param;
|
||||
data["password"] = Value::from(base64::encode(password.as_bytes()));
|
||||
@ -217,7 +217,7 @@ pub fn update_remote(
|
||||
digest: Option<String>,
|
||||
) -> Result<(), Error> {
|
||||
|
||||
let _lock = open_file_locked(remote::REMOTE_CFG_LOCKFILE, std::time::Duration::new(10, 0), true)?;
|
||||
let _lock = open_backup_lockfile(remote::REMOTE_CFG_LOCKFILE, None, true)?;
|
||||
|
||||
let (mut config, expected_digest) = remote::config()?;
|
||||
|
||||
@ -291,7 +291,7 @@ pub fn delete_remote(name: String, digest: Option<String>) -> Result<(), Error>
|
||||
}
|
||||
}
|
||||
|
||||
let _lock = open_file_locked(remote::REMOTE_CFG_LOCKFILE, std::time::Duration::new(10, 0), true)?;
|
||||
let _lock = open_backup_lockfile(remote::REMOTE_CFG_LOCKFILE, None, true)?;
|
||||
|
||||
let (mut config, expected_digest) = remote::config()?;
|
||||
|
||||
|
@ -3,7 +3,6 @@ use serde_json::Value;
|
||||
use ::serde::{Deserialize, Serialize};
|
||||
|
||||
use proxmox::api::{api, Permission, Router, RpcEnvironment};
|
||||
use proxmox::tools::fs::open_file_locked;
|
||||
|
||||
use crate::api2::types::*;
|
||||
|
||||
@ -18,6 +17,7 @@ use crate::config::acl::{
|
||||
|
||||
use crate::config::cached_user_info::CachedUserInfo;
|
||||
use crate::config::sync::{self, SyncJobConfig};
|
||||
use crate::backup::open_backup_lockfile;
|
||||
|
||||
pub fn check_sync_job_read_access(
|
||||
user_info: &CachedUserInfo,
|
||||
@ -152,7 +152,7 @@ pub fn create_sync_job(
|
||||
let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?;
|
||||
let user_info = CachedUserInfo::new()?;
|
||||
|
||||
let _lock = open_file_locked(sync::SYNC_CFG_LOCKFILE, std::time::Duration::new(10, 0), true)?;
|
||||
let _lock = open_backup_lockfile(sync::SYNC_CFG_LOCKFILE, None, true)?;
|
||||
|
||||
let sync_job: sync::SyncJobConfig = serde_json::from_value(param)?;
|
||||
if !check_sync_job_modify_access(&user_info, &auth_id, &sync_job) {
|
||||
@ -296,7 +296,7 @@ pub fn update_sync_job(
|
||||
let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?;
|
||||
let user_info = CachedUserInfo::new()?;
|
||||
|
||||
let _lock = open_file_locked(sync::SYNC_CFG_LOCKFILE, std::time::Duration::new(10, 0), true)?;
|
||||
let _lock = open_backup_lockfile(sync::SYNC_CFG_LOCKFILE, None, true)?;
|
||||
|
||||
// pass/compare digest
|
||||
let (mut config, expected_digest) = sync::config()?;
|
||||
@ -379,7 +379,7 @@ pub fn delete_sync_job(
|
||||
let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?;
|
||||
let user_info = CachedUserInfo::new()?;
|
||||
|
||||
let _lock = open_file_locked(sync::SYNC_CFG_LOCKFILE, std::time::Duration::new(10, 0), true)?;
|
||||
let _lock = open_backup_lockfile(sync::SYNC_CFG_LOCKFILE, None, true)?;
|
||||
|
||||
let (mut config, expected_digest) = sync::config()?;
|
||||
|
||||
|
@ -3,7 +3,6 @@ use serde_json::Value;
|
||||
use ::serde::{Deserialize, Serialize};
|
||||
|
||||
use proxmox::api::{api, Router, RpcEnvironment, Permission};
|
||||
use proxmox::tools::fs::open_file_locked;
|
||||
|
||||
use crate::{
|
||||
api2::types::{
|
||||
@ -17,6 +16,7 @@ use crate::{
|
||||
MEDIA_POOL_NAME_SCHEMA,
|
||||
SYNC_SCHEDULE_SCHEMA,
|
||||
},
|
||||
backup::open_backup_lockfile,
|
||||
config::{
|
||||
self,
|
||||
cached_user_info::CachedUserInfo,
|
||||
@ -89,8 +89,7 @@ pub fn create_tape_backup_job(
|
||||
job: TapeBackupJobConfig,
|
||||
_rpcenv: &mut dyn RpcEnvironment,
|
||||
) -> Result<(), Error> {
|
||||
|
||||
let _lock = open_file_locked(TAPE_JOB_CFG_LOCKFILE, std::time::Duration::new(10, 0), true)?;
|
||||
let _lock = open_backup_lockfile(TAPE_JOB_CFG_LOCKFILE, None, true)?;
|
||||
|
||||
let (mut config, _digest) = config::tape_job::config()?;
|
||||
|
||||
@ -233,7 +232,7 @@ pub fn update_tape_backup_job(
|
||||
delete: Option<Vec<DeletableProperty>>,
|
||||
digest: Option<String>,
|
||||
) -> Result<(), Error> {
|
||||
let _lock = open_file_locked(TAPE_JOB_CFG_LOCKFILE, std::time::Duration::new(10, 0), true)?;
|
||||
let _lock = open_backup_lockfile(TAPE_JOB_CFG_LOCKFILE, None, true)?;
|
||||
|
||||
let (mut config, expected_digest) = config::tape_job::config()?;
|
||||
|
||||
@ -312,7 +311,7 @@ pub fn delete_tape_backup_job(
|
||||
digest: Option<String>,
|
||||
_rpcenv: &mut dyn RpcEnvironment,
|
||||
) -> Result<(), Error> {
|
||||
let _lock = open_file_locked(TAPE_JOB_CFG_LOCKFILE, std::time::Duration::new(10, 0), true)?;
|
||||
let _lock = open_backup_lockfile(TAPE_JOB_CFG_LOCKFILE, None, true)?;
|
||||
|
||||
let (mut config, expected_digest) = config::tape_job::config()?;
|
||||
|
||||
|
@ -9,7 +9,6 @@ use proxmox::{
|
||||
RpcEnvironment,
|
||||
Permission,
|
||||
},
|
||||
tools::fs::open_file_locked,
|
||||
};
|
||||
|
||||
use pbs_datastore::{KeyInfo, Kdf};
|
||||
@ -35,6 +34,7 @@ use crate::{
|
||||
PASSWORD_HINT_SCHEMA,
|
||||
},
|
||||
backup::{
|
||||
open_backup_lockfile,
|
||||
KeyConfig,
|
||||
Fingerprint,
|
||||
},
|
||||
@ -122,11 +122,7 @@ pub fn change_passphrase(
|
||||
bail!("Please specify a key derivation function (none is not allowed here).");
|
||||
}
|
||||
|
||||
let _lock = open_file_locked(
|
||||
TAPE_KEYS_LOCKFILE,
|
||||
std::time::Duration::new(10, 0),
|
||||
true,
|
||||
)?;
|
||||
let _lock = open_backup_lockfile(TAPE_KEYS_LOCKFILE, None, true)?;
|
||||
|
||||
let (mut config_map, expected_digest) = load_key_configs()?;
|
||||
|
||||
@ -261,12 +257,7 @@ pub fn delete_key(
|
||||
digest: Option<String>,
|
||||
_rpcenv: &mut dyn RpcEnvironment,
|
||||
) -> Result<(), Error> {
|
||||
|
||||
let _lock = open_file_locked(
|
||||
TAPE_KEYS_LOCKFILE,
|
||||
std::time::Duration::new(10, 0),
|
||||
true,
|
||||
)?;
|
||||
let _lock = open_backup_lockfile(TAPE_KEYS_LOCKFILE, None, true)?;
|
||||
|
||||
let (mut config_map, expected_digest) = load_key_configs()?;
|
||||
let (mut key_map, _) = load_keys()?;
|
||||
|
@ -3,7 +3,6 @@ use serde_json::Value;
|
||||
use ::serde::{Deserialize, Serialize};
|
||||
|
||||
use proxmox::api::{api, Permission, Router, RpcEnvironment};
|
||||
use proxmox::tools::fs::open_file_locked;
|
||||
|
||||
use crate::api2::types::*;
|
||||
|
||||
@ -13,8 +12,8 @@ use crate::config::acl::{
|
||||
};
|
||||
|
||||
use crate::config::cached_user_info::CachedUserInfo;
|
||||
|
||||
use crate::config::verify::{self, VerificationJobConfig};
|
||||
use crate::backup::open_backup_lockfile;
|
||||
|
||||
#[api(
|
||||
input: {
|
||||
@ -102,7 +101,7 @@ pub fn create_verification_job(
|
||||
|
||||
user_info.check_privs(&auth_id, &["datastore", &verification_job.store], PRIV_DATASTORE_VERIFY, false)?;
|
||||
|
||||
let _lock = open_file_locked(verify::VERIFICATION_CFG_LOCKFILE, std::time::Duration::new(10, 0), true)?;
|
||||
let _lock = open_backup_lockfile(verify::VERIFICATION_CFG_LOCKFILE, None, true)?;
|
||||
|
||||
let (mut config, _digest) = verify::config()?;
|
||||
|
||||
@ -230,7 +229,7 @@ pub fn update_verification_job(
|
||||
let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?;
|
||||
let user_info = CachedUserInfo::new()?;
|
||||
|
||||
let _lock = open_file_locked(verify::VERIFICATION_CFG_LOCKFILE, std::time::Duration::new(10, 0), true)?;
|
||||
let _lock = open_backup_lockfile(verify::VERIFICATION_CFG_LOCKFILE, None, true)?;
|
||||
|
||||
// pass/compare digest
|
||||
let (mut config, expected_digest) = verify::config()?;
|
||||
@ -315,7 +314,7 @@ pub fn delete_verification_job(
|
||||
let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?;
|
||||
let user_info = CachedUserInfo::new()?;
|
||||
|
||||
let _lock = open_file_locked(verify::VERIFICATION_CFG_LOCKFILE, std::time::Duration::new(10, 0), true)?;
|
||||
let _lock = open_backup_lockfile(verify::VERIFICATION_CFG_LOCKFILE, None, true)?;
|
||||
|
||||
let (mut config, expected_digest) = verify::config()?;
|
||||
|
||||
|
@ -5,7 +5,6 @@ use ::serde::{Deserialize, Serialize};
|
||||
use proxmox::api::{api, Permission, RpcEnvironment, RpcEnvironmentType};
|
||||
use proxmox::api::section_config::SectionConfigData;
|
||||
use proxmox::api::router::Router;
|
||||
use proxmox::tools::fs::open_file_locked;
|
||||
|
||||
use crate::config::acl::{PRIV_SYS_AUDIT, PRIV_SYS_MODIFY};
|
||||
use crate::tools::disks::{
|
||||
@ -18,6 +17,7 @@ use crate::server::WorkerTask;
|
||||
|
||||
use crate::api2::types::*;
|
||||
use crate::config::datastore::{self, DataStoreConfig};
|
||||
use crate::backup::open_backup_lockfile;
|
||||
|
||||
#[api(
|
||||
properties: {
|
||||
@ -180,7 +180,7 @@ pub fn create_datastore_disk(
|
||||
systemd::start_unit(&mount_unit_name)?;
|
||||
|
||||
if add_datastore {
|
||||
let lock = open_file_locked(datastore::DATASTORE_CFG_LOCKFILE, std::time::Duration::new(10, 0), true)?;
|
||||
let lock = open_backup_lockfile(datastore::DATASTORE_CFG_LOCKFILE, None, true)?;
|
||||
let datastore: DataStoreConfig =
|
||||
serde_json::from_value(json!({ "name": name, "path": mount_point }))?;
|
||||
|
||||
|
@ -4,12 +4,12 @@ use ::serde::{Deserialize, Serialize};
|
||||
|
||||
use proxmox::api::{api, ApiMethod, Router, RpcEnvironment, Permission};
|
||||
use proxmox::api::schema::parse_property_string;
|
||||
use proxmox::tools::fs::open_file_locked;
|
||||
|
||||
use crate::config::network::{self, NetworkConfig};
|
||||
use crate::config::acl::{PRIV_SYS_AUDIT, PRIV_SYS_MODIFY};
|
||||
use crate::api2::types::*;
|
||||
use crate::server::{WorkerTask};
|
||||
use crate::backup::open_backup_lockfile;
|
||||
|
||||
fn split_interface_list(list: &str) -> Result<Vec<String>, Error> {
|
||||
let value = parse_property_string(&list, &NETWORK_INTERFACE_ARRAY_SCHEMA)?;
|
||||
@ -238,7 +238,7 @@ pub fn create_interface(
|
||||
let interface_type = pbs_tools::json::required_string_param(¶m, "type")?;
|
||||
let interface_type: NetworkInterfaceType = serde_json::from_value(interface_type.into())?;
|
||||
|
||||
let _lock = open_file_locked(network::NETWORK_LOCKFILE, std::time::Duration::new(10, 0), true)?;
|
||||
let _lock = open_backup_lockfile(network::NETWORK_LOCKFILE, None, true)?;
|
||||
|
||||
let (mut config, _digest) = network::config()?;
|
||||
|
||||
@ -502,7 +502,7 @@ pub fn update_interface(
|
||||
param: Value,
|
||||
) -> Result<(), Error> {
|
||||
|
||||
let _lock = open_file_locked(network::NETWORK_LOCKFILE, std::time::Duration::new(10, 0), true)?;
|
||||
let _lock = open_backup_lockfile(network::NETWORK_LOCKFILE, None, true)?;
|
||||
|
||||
let (mut config, expected_digest) = network::config()?;
|
||||
|
||||
@ -642,8 +642,7 @@ pub fn update_interface(
|
||||
)]
|
||||
/// Remove network interface configuration.
|
||||
pub fn delete_interface(iface: String, digest: Option<String>) -> Result<(), Error> {
|
||||
|
||||
let _lock = open_file_locked(network::NETWORK_LOCKFILE, std::time::Duration::new(10, 0), true)?;
|
||||
let _lock = open_backup_lockfile(network::NETWORK_LOCKFILE, None, true)?;
|
||||
|
||||
let (mut config, expected_digest) = network::config()?;
|
||||
|
||||
|
Reference in New Issue
Block a user