mirror of
https://git.proxmox.com/git/proxmox-backup-qemu
synced 2025-10-04 16:07:54 +00:00
proxmox_backup_connect: make password optional
This commit is contained in:
parent
574e020389
commit
7dfc23db39
@ -2,7 +2,6 @@ use failure::*;
|
|||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use std::sync::{Mutex, Arc};
|
use std::sync::{Mutex, Arc};
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
use std::ffi::CString;
|
|
||||||
|
|
||||||
use futures::future::{Future, TryFutureExt};
|
use futures::future::{Future, TryFutureExt};
|
||||||
use serde_json::{json, Value};
|
use serde_json::{json, Value};
|
||||||
@ -24,7 +23,7 @@ pub(crate) struct BackupSetup {
|
|||||||
pub chunk_size: u64,
|
pub chunk_size: u64,
|
||||||
pub backup_id: String,
|
pub backup_id: String,
|
||||||
pub backup_time: DateTime<Utc>,
|
pub backup_time: DateTime<Utc>,
|
||||||
pub password: CString,
|
pub password: Option<String>,
|
||||||
pub crypt_config: Option<Arc<CryptConfig>>,
|
pub crypt_config: Option<Arc<CryptConfig>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
55
src/lib.rs
55
src/lib.rs
@ -66,34 +66,43 @@ pub extern "C" fn proxmox_backup_connect(
|
|||||||
error: * mut * mut c_char,
|
error: * mut * mut c_char,
|
||||||
) -> *mut ProxmoxBackupHandle {
|
) -> *mut ProxmoxBackupHandle {
|
||||||
|
|
||||||
let repo = unsafe { CStr::from_ptr(repo).to_string_lossy().into_owned() };
|
let setup: Result<_, Error> = try_block!({
|
||||||
let repo: BackupRepository = match repo.parse() {
|
let repo = unsafe { CStr::from_ptr(repo).to_str()?.to_owned() };
|
||||||
Ok(repo) => repo,
|
let repo: BackupRepository = repo.parse()?;
|
||||||
Err(err) => raise_error_null!(error, err),
|
|
||||||
};
|
|
||||||
let backup_id = unsafe { CStr::from_ptr(backup_id).to_string_lossy().into_owned() };
|
|
||||||
|
|
||||||
let backup_time = Utc.timestamp(backup_time as i64, 0);
|
let backup_id = unsafe { CStr::from_ptr(backup_id).to_str()?.to_owned() };
|
||||||
|
|
||||||
let password = unsafe { CStr::from_ptr(password).to_owned() };
|
let backup_time = Utc.timestamp(backup_time as i64, 0);
|
||||||
|
|
||||||
let crypt_config: Option<Arc<CryptConfig>> = None; //fixme:
|
let password = if password == std::ptr::null() {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
Some(unsafe { CStr::from_ptr(password).to_str()?.to_owned() })
|
||||||
|
};
|
||||||
|
|
||||||
let setup = BackupSetup {
|
let crypt_config: Option<Arc<CryptConfig>> = None; //fixme:
|
||||||
host: repo.host().to_owned(),
|
|
||||||
user: repo.user().to_owned(),
|
|
||||||
store: repo.store().to_owned(),
|
|
||||||
chunk_size: 4*1024*1024,
|
|
||||||
backup_id,
|
|
||||||
password,
|
|
||||||
backup_time,
|
|
||||||
crypt_config,
|
|
||||||
};
|
|
||||||
|
|
||||||
match BackupTask::new(setup) {
|
Ok(BackupSetup {
|
||||||
Ok(task) => {
|
host: repo.host().to_owned(),
|
||||||
let boxed_task = Box::new(task);
|
user: repo.user().to_owned(),
|
||||||
Box::into_raw(boxed_task) as * mut ProxmoxBackupHandle
|
store: repo.store().to_owned(),
|
||||||
|
chunk_size: 4*1024*1024,
|
||||||
|
backup_id,
|
||||||
|
password,
|
||||||
|
backup_time,
|
||||||
|
crypt_config,
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
match setup {
|
||||||
|
Ok(setup) => {
|
||||||
|
match BackupTask::new(setup) {
|
||||||
|
Ok(task) => {
|
||||||
|
let boxed_task = Box::new(task);
|
||||||
|
Box::into_raw(boxed_task) as * mut ProxmoxBackupHandle
|
||||||
|
}
|
||||||
|
Err(err) => raise_error_null!(error, err),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Err(err) => raise_error_null!(error, err),
|
Err(err) => raise_error_null!(error, err),
|
||||||
}
|
}
|
||||||
|
@ -51,8 +51,7 @@ impl BackupTask {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn connect(runtime: &mut Runtime, setup: &BackupSetup) -> Result<Arc<BackupWriter>, Error> {
|
fn connect(runtime: &mut Runtime, setup: &BackupSetup) -> Result<Arc<BackupWriter>, Error> {
|
||||||
let password = setup.password.to_str()?.to_owned();
|
let client = HttpClient::new(&setup.host, &setup.user, setup.password.clone())?;
|
||||||
let client = HttpClient::new(&setup.host, &setup.user, Some(password))?;
|
|
||||||
|
|
||||||
let client = runtime.block_on(
|
let client = runtime.block_on(
|
||||||
BackupWriter::start(client, &setup.store, "vm", &setup.backup_id, setup.backup_time, false)
|
BackupWriter::start(client, &setup.store, "vm", &setup.backup_id, setup.backup_time, false)
|
||||||
|
Loading…
Reference in New Issue
Block a user