mirror of
https://github.com/ibm-s390-linux/s390-tools.git
synced 2026-08-05 02:14:52 +00:00
rust/pv: Replace libc wherever possible
Replace all libc references to rust-std references if available. This eliminates the need to include libc in the pv crate. However, pv_base still refers to libc::ioctl and libc::ENOTTY. Reviewed-by: Marc Hartmayer <mhartmay@linux.ibm.com> Signed-off-by: Steffen Eiden <seiden@linux.ibm.com> Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
This commit is contained in:
committed by
Jan Höppner
parent
b71279cda5
commit
02dded11a5
1
rust/Cargo.lock
generated
1
rust/Cargo.lock
generated
@@ -780,7 +780,6 @@ dependencies = [
|
||||
"clap",
|
||||
"curl",
|
||||
"lazy_static",
|
||||
"libc",
|
||||
"log",
|
||||
"mockito",
|
||||
"openssl",
|
||||
|
||||
@@ -8,7 +8,6 @@ license.workspace = true
|
||||
byteorder = "1.3"
|
||||
clap = { version ="4", features = ["derive", "wrap_help"] }
|
||||
curl = "0.4.7"
|
||||
libc = "0.2.49"
|
||||
log = { version = "0.4.6", features = ["std", "release_max_level_debug"] }
|
||||
openssl = "0.10.49"
|
||||
serde = { version = "1.0.139", features = ["derive"] }
|
||||
|
||||
@@ -5,15 +5,15 @@
|
||||
use std::fmt;
|
||||
|
||||
use foreign_types::{foreign_type, ForeignType, ForeignTypeRef};
|
||||
use libc::c_int;
|
||||
use openssl::x509::{X509CrlRef, X509Ref};
|
||||
use std::ffi::c_int;
|
||||
|
||||
mod ffi {
|
||||
extern "C" {
|
||||
pub fn X509_check_akid(
|
||||
issuer: *const openssl_sys::X509,
|
||||
akid: *const openssl_sys::AUTHORITY_KEYID,
|
||||
) -> ::libc::c_int;
|
||||
) -> super::c_int;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ mod ffi {
|
||||
pub fn X509_STORE_add_crl(
|
||||
xs: *mut openssl_sys::X509_STORE,
|
||||
x: *mut openssl_sys::X509_CRL,
|
||||
) -> libc::c_int;
|
||||
) -> std::ffi::c_int;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,13 +5,13 @@
|
||||
use std::{marker::PhantomData, ptr};
|
||||
|
||||
use foreign_types::{ForeignType, ForeignTypeRef};
|
||||
use libc::c_int;
|
||||
use openssl::{
|
||||
error::ErrorStack,
|
||||
stack::Stackable,
|
||||
x509::{X509Crl, X509CrlRef},
|
||||
};
|
||||
use openssl_sys::BIO_new_mem_buf;
|
||||
use std::ffi::c_int;
|
||||
|
||||
pub struct StackableX509Crl(*mut openssl_sys::X509_CRL);
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@ use crate::misc::read_crls;
|
||||
use crate::HkdVerifyErrorType::*;
|
||||
use crate::{Error, Result};
|
||||
use curl::easy::{Easy2, Handler, WriteError};
|
||||
use libc::c_int;
|
||||
use log::debug;
|
||||
use openssl::{
|
||||
asn1::{Asn1Time, Asn1TimeRef},
|
||||
@@ -26,9 +25,7 @@ use openssl_extensions::{
|
||||
akid::{AkidCheckResult, AkidExtension},
|
||||
crl::X509StoreExtension,
|
||||
};
|
||||
use std::cmp::Ordering;
|
||||
use std::time::Duration;
|
||||
use std::usize;
|
||||
use std::{cmp::Ordering, ffi::c_int, time::Duration, usize};
|
||||
|
||||
/// Minimum security level for the keys/certificates used to establish a chain of
|
||||
/// trust (see https://www.openssl.org/docs/man1.1.1/man3/X509_VERIFY_PARAM_set_auth_level.html
|
||||
|
||||
@@ -8,6 +8,7 @@ use super::{helper, helper::*, *};
|
||||
use crate::{Error, HkdVerifyErrorType::*};
|
||||
use core::slice;
|
||||
use openssl::stack::Stack;
|
||||
use std::ffi::c_int;
|
||||
|
||||
use crate::test_utils::*;
|
||||
|
||||
@@ -23,10 +24,10 @@ pub fn mock_endpt(res: &str) -> mockito::Mock {
|
||||
}
|
||||
|
||||
#[track_caller]
|
||||
fn verify_sign_error(exp_raw: libc::c_int, obs: Error) {
|
||||
fn verify_sign_error(exp_raw: c_int, obs: Error) {
|
||||
verify_sign_error_slice(&[exp_raw], obs)
|
||||
}
|
||||
fn verify_sign_error_slice(exp_raw: &[libc::c_int], obs: Error) {
|
||||
fn verify_sign_error_slice(exp_raw: &[c_int], obs: Error) {
|
||||
if exp_raw
|
||||
.iter()
|
||||
.filter(|e| match &obs {
|
||||
|
||||
@@ -5,10 +5,10 @@
|
||||
#![allow(non_camel_case_types)]
|
||||
use crate::FileAccessErrorType;
|
||||
use crate::{Error, Result};
|
||||
use libc::c_ulong;
|
||||
use log::debug;
|
||||
use std::{
|
||||
convert::TryInto,
|
||||
ffi::c_ulong,
|
||||
fs::File,
|
||||
os::unix::prelude::{AsRawFd, RawFd},
|
||||
};
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#![cfg(test)]
|
||||
|
||||
use std::{
|
||||
ffi::{c_int, c_ulong},
|
||||
os::unix::prelude::FromRawFd,
|
||||
sync::{Mutex, MutexGuard},
|
||||
};
|
||||
@@ -28,18 +29,18 @@ fn get_lock<T>(m: &'static Mutex<T>) -> MutexGuard<'static, T> {
|
||||
|
||||
struct IoctlCtx {
|
||||
modify: Box<dyn FnMut(&mut ffi::uvio_ioctl_cb) -> i32 + Send + Sync>,
|
||||
exp_cmd: ::libc::c_ulong,
|
||||
exp_cmd: c_ulong,
|
||||
called: bool,
|
||||
}
|
||||
|
||||
impl IoctlCtx {
|
||||
pub fn exp_cmd(&mut self, cmd: ::libc::c_ulong) -> &mut Self {
|
||||
pub fn exp_cmd(&mut self, cmd: c_ulong) -> &mut Self {
|
||||
self.exp_cmd = cmd;
|
||||
self
|
||||
}
|
||||
pub fn set_mdfy<F>(&mut self, mdfy: F) -> &mut Self
|
||||
where
|
||||
F: FnMut(&mut ffi::uvio_ioctl_cb) -> ::libc::c_int + 'static + Send + Sync,
|
||||
F: FnMut(&mut ffi::uvio_ioctl_cb) -> c_int + 'static + Send + Sync,
|
||||
{
|
||||
self.modify = Box::new(mdfy);
|
||||
self
|
||||
@@ -62,11 +63,7 @@ impl IoctlCtx {
|
||||
pub mod mock_libc {
|
||||
use super::*;
|
||||
|
||||
pub unsafe fn ioctl(
|
||||
fd: ::libc::c_int,
|
||||
cmd: ::libc::c_ulong,
|
||||
data: *mut ffi::uvio_ioctl_cb,
|
||||
) -> ::libc::c_int {
|
||||
pub unsafe fn ioctl(fd: c_int, cmd: c_ulong, data: *mut ffi::uvio_ioctl_cb) -> c_int {
|
||||
let mut ctx = get_lock(&IOCTL_MTX);
|
||||
assert!(!ctx.called, "IOCTL called more than once");
|
||||
ctx.called = true;
|
||||
|
||||
Reference in New Issue
Block a user