oxidize: Fix first pass of compile errors
This commit contains a multitude of fixes and some initial translation work so the first rustc pass compiles. It removes `unsafe extern "C"` declarations, so now there are a number of errors about invocations of unsafe functions that need to be addressed. They should each be scoped to an `unsafe` block so as to aid in an eventual safe translation. Some of the functions are now using the module system rather than `extern "C"` bindings, but the translation is not complete.
This commit is contained in:
@@ -6,3 +6,5 @@ edition = "2018"
|
|||||||
license = "BSD"
|
license = "BSD"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
libc = "0.2"
|
||||||
|
zeroize = "1"
|
||||||
|
|||||||
+88
-52
@@ -1,3 +1,6 @@
|
|||||||
|
// Adapted from yubico-piv-tool:
|
||||||
|
// <https://github.com/Yubico/yubico-piv-tool/>
|
||||||
|
//
|
||||||
// Copyright (c) 2014-2016 Yubico AB
|
// Copyright (c) 2014-2016 Yubico AB
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
//
|
//
|
||||||
@@ -25,72 +28,105 @@
|
|||||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
#[derive(Clone, Copy)]
|
use std::fmt;
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||||
#[repr(i32)]
|
#[repr(i32)]
|
||||||
pub enum Enum2 {
|
#[allow(non_camel_case_types)]
|
||||||
YKPIV_OK = 0i32,
|
pub enum ErrorKind {
|
||||||
YKPIV_MEMORY_ERROR = -1i32,
|
YKPIV_OK = 0,
|
||||||
YKPIV_PCSC_ERROR = -2i32,
|
YKPIV_MEMORY_ERROR = -1,
|
||||||
YKPIV_SIZE_ERROR = -3i32,
|
YKPIV_PCSC_ERROR = -2,
|
||||||
YKPIV_APPLET_ERROR = -4i32,
|
YKPIV_SIZE_ERROR = -3,
|
||||||
YKPIV_AUTHENTICATION_ERROR = -5i32,
|
YKPIV_APPLET_ERROR = -4,
|
||||||
YKPIV_RANDOMNESS_ERROR = -6i32,
|
YKPIV_AUTHENTICATION_ERROR = -5,
|
||||||
YKPIV_GENERIC_ERROR = -7i32,
|
YKPIV_RANDOMNESS_ERROR = -6,
|
||||||
YKPIV_KEY_ERROR = -8i32,
|
YKPIV_GENERIC_ERROR = -7,
|
||||||
YKPIV_PARSE_ERROR = -9i32,
|
YKPIV_KEY_ERROR = -8,
|
||||||
YKPIV_WRONG_PIN = -10i32,
|
YKPIV_PARSE_ERROR = -9,
|
||||||
YKPIV_INVALID_OBJECT = -11i32,
|
YKPIV_WRONG_PIN = -10,
|
||||||
YKPIV_ALGORITHM_ERROR = -12i32,
|
YKPIV_INVALID_OBJECT = -11,
|
||||||
YKPIV_PIN_LOCKED = -13i32,
|
YKPIV_ALGORITHM_ERROR = -12,
|
||||||
YKPIV_ARGUMENT_ERROR = -14i32,
|
YKPIV_PIN_LOCKED = -13,
|
||||||
YKPIV_RANGE_ERROR = -15i32,
|
YKPIV_ARGUMENT_ERROR = -14,
|
||||||
YKPIV_NOT_SUPPORTED = -16i32,
|
YKPIV_RANGE_ERROR = -15,
|
||||||
|
YKPIV_NOT_SUPPORTED = -16,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl ErrorKind {
|
||||||
|
/// Name of the error
|
||||||
|
pub fn name(self) -> &'static str {
|
||||||
|
match self {
|
||||||
|
ErrorKind::YKPIV_OK => "YKPIV_OK",
|
||||||
|
ErrorKind::YKPIV_MEMORY_ERROR => "YKPIV_MEMORY_ERROR",
|
||||||
|
ErrorKind::YKPIV_PCSC_ERROR => "YKPIV_PCSC_ERROR",
|
||||||
|
ErrorKind::YKPIV_SIZE_ERROR => "YKPIV_SIZE_ERROR",
|
||||||
|
ErrorKind::YKPIV_APPLET_ERROR => "YKPIV_APPLET_ERROR",
|
||||||
|
ErrorKind::YKPIV_AUTHENTICATION_ERROR => "YKPIV_AUTHENTICATION_ERROR",
|
||||||
|
ErrorKind::YKPIV_RANDOMNESS_ERROR => "YKPIV_RANDOMNESS_ERROR",
|
||||||
|
ErrorKind::YKPIV_GENERIC_ERROR => "YKPIV_GENERIC_ERROR",
|
||||||
|
ErrorKind::YKPIV_KEY_ERROR => "YKPIV_KEY_ERROR",
|
||||||
|
ErrorKind::YKPIV_PARSE_ERROR => "YKPIV_PARSE_ERROR",
|
||||||
|
ErrorKind::YKPIV_WRONG_PIN => "YKPIV_WRONG_PIN",
|
||||||
|
ErrorKind::YKPIV_INVALID_OBJECT => "YKPIV_INVALID_OBJECT",
|
||||||
|
ErrorKind::YKPIV_ALGORITHM_ERROR => "YKPIV_ALGORITHM_ERROR",
|
||||||
|
ErrorKind::YKPIV_PIN_LOCKED => "YKPIV_PIN_LOCKED",
|
||||||
|
ErrorKind::YKPIV_ARGUMENT_ERROR => "YKPIV_ARGUMENT_ERROR",
|
||||||
|
ErrorKind::YKPIV_RANGE_ERROR => "YKPIV_RANGE_ERROR",
|
||||||
|
ErrorKind::YKPIV_NOT_SUPPORTED => "YKPIV_NOT_SUPPORTED",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Error message
|
||||||
|
pub fn msg(self) -> &'static str {
|
||||||
|
match self {
|
||||||
|
ErrorKind::YKPIV_OK => "OK",
|
||||||
|
ErrorKind::YKPIV_MEMORY_ERROR => "memory error",
|
||||||
|
ErrorKind::YKPIV_PCSC_ERROR => "PCSC error",
|
||||||
|
ErrorKind::YKPIV_SIZE_ERROR => "size error",
|
||||||
|
ErrorKind::YKPIV_APPLET_ERROR => "applet error",
|
||||||
|
ErrorKind::YKPIV_AUTHENTICATION_ERROR => "authentication error",
|
||||||
|
ErrorKind::YKPIV_RANDOMNESS_ERROR => "randomness error",
|
||||||
|
ErrorKind::YKPIV_GENERIC_ERROR => "generic error",
|
||||||
|
ErrorKind::YKPIV_KEY_ERROR => "key error",
|
||||||
|
ErrorKind::YKPIV_PARSE_ERROR => "parse error",
|
||||||
|
ErrorKind::YKPIV_WRONG_PIN => "wrong pin",
|
||||||
|
ErrorKind::YKPIV_INVALID_OBJECT => "invalid object",
|
||||||
|
ErrorKind::YKPIV_ALGORITHM_ERROR => "algorithm error",
|
||||||
|
ErrorKind::YKPIV_PIN_LOCKED => "PIN locked",
|
||||||
|
ErrorKind::YKPIV_ARGUMENT_ERROR => "argument error",
|
||||||
|
ErrorKind::YKPIV_RANGE_ERROR => "range error",
|
||||||
|
ErrorKind::YKPIV_NOT_SUPPORTED => "not supported",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for ErrorKind {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
f.write_str(self.msg())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::error::Error for ErrorKind {}
|
||||||
|
|
||||||
#[derive(Copy)]
|
#[derive(Copy)]
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
pub struct Struct1 {
|
pub struct Error {
|
||||||
pub rc: Enum2,
|
pub rc: ErrorKind,
|
||||||
pub name: *const u8,
|
pub name: *const u8,
|
||||||
pub description: *const u8,
|
pub description: *const u8,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Clone for Struct1 {
|
impl Clone for Error {
|
||||||
fn clone(&self) -> Self {
|
fn clone(&self) -> Self {
|
||||||
*self
|
*self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static mut errors: *const Struct1 = Enum2::YKPIV_OK as (*const Struct1);
|
pub fn ykpiv_strerror(err: ErrorKind) -> &'static str {
|
||||||
|
err.msg()
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn ykpiv_strerror(mut err: Enum2) -> *const u8 {
|
|
||||||
static mut unknown: *const u8 = (*b"Unknown ykpiv error\0").as_ptr();
|
|
||||||
let mut p: *const u8;
|
|
||||||
if -(err as (i32)) < 0i32
|
|
||||||
|| -(err as (i32))
|
|
||||||
>= ::std::mem::size_of::<*const Struct1>()
|
|
||||||
.wrapping_div(::std::mem::size_of::<Struct1>()) as (i32)
|
|
||||||
{
|
|
||||||
unknown
|
|
||||||
} else {
|
|
||||||
p = (*errors.offset(-(err as (i32)) as (isize))).description;
|
|
||||||
if p.is_null() {
|
|
||||||
p = unknown;
|
|
||||||
}
|
|
||||||
p
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
pub fn ykpiv_strerror_name(err: ErrorKind) -> &'static str {
|
||||||
pub unsafe extern "C" fn ykpiv_strerror_name(mut err: Enum2) -> *const u8 {
|
err.name()
|
||||||
if -(err as (i32)) < 0i32
|
|
||||||
|| -(err as (i32))
|
|
||||||
>= ::std::mem::size_of::<*const Struct1>()
|
|
||||||
.wrapping_div(::std::mem::size_of::<Struct1>()) as (i32)
|
|
||||||
{
|
|
||||||
0i32 as (*mut ::std::os::raw::c_void) as (*const u8)
|
|
||||||
} else {
|
|
||||||
(*errors.offset(-(err as (i32)) as (isize))).name
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
+135
-237
@@ -1,3 +1,6 @@
|
|||||||
|
// Adapted from yubico-piv-tool:
|
||||||
|
// <https://github.com/Yubico/yubico-piv-tool/>
|
||||||
|
//
|
||||||
// Copyright (c) 2014-2016 Yubico AB
|
// Copyright (c) 2014-2016 Yubico AB
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
//
|
//
|
||||||
@@ -25,6 +28,12 @@
|
|||||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
use libc::{
|
||||||
|
c_char, c_int, fclose, feof, fgets, fopen, free, getenv, malloc, memcpy, memset, strcasecmp,
|
||||||
|
strcmp, strlen,
|
||||||
|
};
|
||||||
|
use std::ptr;
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
fn DES_ecb3_encrypt(
|
fn DES_ecb3_encrypt(
|
||||||
input: *mut [u8; 8],
|
input: *mut [u8; 8],
|
||||||
@@ -48,39 +57,13 @@ extern "C" {
|
|||||||
fn RAND_bytes(buf: *mut u8, num: i32) -> i32;
|
fn RAND_bytes(buf: *mut u8, num: i32) -> i32;
|
||||||
static mut _DefaultRuneLocale: Struct1;
|
static mut _DefaultRuneLocale: Struct1;
|
||||||
fn __maskrune(arg1: i32, arg2: usize) -> i32;
|
fn __maskrune(arg1: i32, arg2: usize) -> i32;
|
||||||
fn __swbuf(arg1: i32, arg2: *mut __sFILE) -> i32;
|
|
||||||
fn __tolower(arg1: i32) -> i32;
|
fn __tolower(arg1: i32) -> i32;
|
||||||
fn __toupper(arg1: i32) -> i32;
|
fn __toupper(arg1: i32) -> i32;
|
||||||
fn fclose(arg1: *mut __sFILE) -> i32;
|
|
||||||
fn feof(arg1: *mut __sFILE) -> i32;
|
|
||||||
fn fgets(arg1: *mut u8, arg2: i32, arg3: *mut __sFILE) -> *mut u8;
|
|
||||||
fn fopen(__filename: *const u8, __mode: *const u8) -> *mut __sFILE;
|
|
||||||
fn free(arg1: *mut ::std::os::raw::c_void);
|
|
||||||
fn getenv(arg1: *const u8) -> *mut u8;
|
|
||||||
fn malloc(__size: usize) -> *mut ::std::os::raw::c_void;
|
|
||||||
fn memcpy(
|
|
||||||
__dst: *mut ::std::os::raw::c_void,
|
|
||||||
__src: *const ::std::os::raw::c_void,
|
|
||||||
__n: usize,
|
|
||||||
) -> *mut ::std::os::raw::c_void;
|
|
||||||
fn memset(
|
|
||||||
__b: *mut ::std::os::raw::c_void,
|
|
||||||
__c: i32,
|
|
||||||
__len: usize,
|
|
||||||
) -> *mut ::std::os::raw::c_void;
|
|
||||||
fn snprintf(__str: *mut u8, __size: usize, __format: *const u8, ...) -> i32;
|
fn snprintf(__str: *mut u8, __size: usize, __format: *const u8, ...) -> i32;
|
||||||
fn sscanf(arg1: *const u8, arg2: *const u8, ...) -> i32;
|
fn sscanf(arg1: *const u8, arg2: *const u8, ...) -> i32;
|
||||||
fn strcasecmp(arg1: *const u8, arg2: *const u8) -> i32;
|
|
||||||
fn strcmp(__s1: *const u8, __s2: *const u8) -> i32;
|
|
||||||
fn strlen(__s: *const u8) -> usize;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
enum Union6 {}
|
pub fn isascii(mut _c: i32) -> i32 {
|
||||||
|
|
||||||
enum __sFILEX {}
|
|
||||||
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn isascii(mut _c: i32) -> i32 {
|
|
||||||
(_c & !0x7fi32 == 0i32) as (i32)
|
(_c & !0x7fi32 == 0i32) as (i32)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -151,8 +134,7 @@ impl Clone for Struct1 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
pub fn __istype(mut _c: i32, mut _f: usize) -> i32 {
|
||||||
pub unsafe extern "C" fn __istype(mut _c: i32, mut _f: usize) -> i32 {
|
|
||||||
if isascii(_c) != 0 {
|
if isascii(_c) != 0 {
|
||||||
!(_DefaultRuneLocale.__runetype[_c as (usize)] as (usize) & _f == 0) as (i32)
|
!(_DefaultRuneLocale.__runetype[_c as (usize)] as (usize) & _f == 0) as (i32)
|
||||||
} else {
|
} else {
|
||||||
@@ -160,8 +142,7 @@ pub unsafe extern "C" fn __istype(mut _c: i32, mut _f: usize) -> i32 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
pub fn __isctype(mut _c: i32, mut _f: usize) -> i32 {
|
||||||
pub unsafe extern "C" fn __isctype(mut _c: i32, mut _f: usize) -> i32 {
|
|
||||||
if _c < 0i32 || _c >= 256i32 {
|
if _c < 0i32 || _c >= 256i32 {
|
||||||
0i32
|
0i32
|
||||||
} else {
|
} else {
|
||||||
@@ -169,8 +150,7 @@ pub unsafe extern "C" fn __isctype(mut _c: i32, mut _f: usize) -> i32 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
pub fn __wcwidth(mut _c: i32) -> i32 {
|
||||||
pub unsafe extern "C" fn __wcwidth(mut _c: i32) -> i32 {
|
|
||||||
let mut _x: u32;
|
let mut _x: u32;
|
||||||
if _c == 0i32 {
|
if _c == 0i32 {
|
||||||
0i32
|
0i32
|
||||||
@@ -186,113 +166,91 @@ pub unsafe extern "C" fn __wcwidth(mut _c: i32) -> i32 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
pub fn isalnum(mut _c: i32) -> i32 {
|
||||||
pub unsafe extern "C" fn isalnum(mut _c: i32) -> i32 {
|
|
||||||
__istype(_c, (0x100isize | 0x400isize) as (usize))
|
__istype(_c, (0x100isize | 0x400isize) as (usize))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
pub fn isalpha(mut _c: i32) -> i32 {
|
||||||
pub unsafe extern "C" fn isalpha(mut _c: i32) -> i32 {
|
|
||||||
__istype(_c, 0x100usize)
|
__istype(_c, 0x100usize)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
pub fn isblank(mut _c: i32) -> i32 {
|
||||||
pub unsafe extern "C" fn isblank(mut _c: i32) -> i32 {
|
|
||||||
__istype(_c, 0x20000usize)
|
__istype(_c, 0x20000usize)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
pub fn iscntrl(mut _c: i32) -> i32 {
|
||||||
pub unsafe extern "C" fn iscntrl(mut _c: i32) -> i32 {
|
|
||||||
__istype(_c, 0x200usize)
|
__istype(_c, 0x200usize)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
pub fn isdigit(mut _c: i32) -> i32 {
|
||||||
pub unsafe extern "C" fn isdigit(mut _c: i32) -> i32 {
|
|
||||||
__isctype(_c, 0x400usize)
|
__isctype(_c, 0x400usize)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
pub fn isgraph(mut _c: i32) -> i32 {
|
||||||
pub unsafe extern "C" fn isgraph(mut _c: i32) -> i32 {
|
|
||||||
__istype(_c, 0x800usize)
|
__istype(_c, 0x800usize)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
pub fn islower(mut _c: i32) -> i32 {
|
||||||
pub unsafe extern "C" fn islower(mut _c: i32) -> i32 {
|
|
||||||
__istype(_c, 0x1000usize)
|
__istype(_c, 0x1000usize)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
pub fn isprint(mut _c: i32) -> i32 {
|
||||||
pub unsafe extern "C" fn isprint(mut _c: i32) -> i32 {
|
|
||||||
__istype(_c, 0x40000usize)
|
__istype(_c, 0x40000usize)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
pub fn ispunct(mut _c: i32) -> i32 {
|
||||||
pub unsafe extern "C" fn ispunct(mut _c: i32) -> i32 {
|
|
||||||
__istype(_c, 0x2000usize)
|
__istype(_c, 0x2000usize)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
pub fn isspace(mut _c: i32) -> i32 {
|
||||||
pub unsafe extern "C" fn isspace(mut _c: i32) -> i32 {
|
|
||||||
__istype(_c, 0x4000usize)
|
__istype(_c, 0x4000usize)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
pub fn isupper(mut _c: i32) -> i32 {
|
||||||
pub unsafe extern "C" fn isupper(mut _c: i32) -> i32 {
|
|
||||||
__istype(_c, 0x8000usize)
|
__istype(_c, 0x8000usize)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
pub fn isxdigit(mut _c: i32) -> i32 {
|
||||||
pub unsafe extern "C" fn isxdigit(mut _c: i32) -> i32 {
|
|
||||||
__isctype(_c, 0x10000usize)
|
__isctype(_c, 0x10000usize)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
pub fn toascii(mut _c: i32) -> i32 {
|
||||||
pub unsafe extern "C" fn toascii(mut _c: i32) -> i32 {
|
|
||||||
_c & 0x7fi32
|
_c & 0x7fi32
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
pub fn tolower(mut _c: i32) -> i32 {
|
||||||
pub unsafe extern "C" fn tolower(mut _c: i32) -> i32 {
|
|
||||||
__tolower(_c)
|
__tolower(_c)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
pub fn toupper(mut _c: i32) -> i32 {
|
||||||
pub unsafe extern "C" fn toupper(mut _c: i32) -> i32 {
|
|
||||||
__toupper(_c)
|
__toupper(_c)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
pub fn digittoint(mut _c: i32) -> i32 {
|
||||||
pub unsafe extern "C" fn digittoint(mut _c: i32) -> i32 {
|
|
||||||
__maskrune(_c, 0xfusize)
|
__maskrune(_c, 0xfusize)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
pub fn ishexnumber(mut _c: i32) -> i32 {
|
||||||
pub unsafe extern "C" fn ishexnumber(mut _c: i32) -> i32 {
|
|
||||||
__istype(_c, 0x10000usize)
|
__istype(_c, 0x10000usize)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
pub fn isideogram(mut _c: i32) -> i32 {
|
||||||
pub unsafe extern "C" fn isideogram(mut _c: i32) -> i32 {
|
|
||||||
__istype(_c, 0x80000usize)
|
__istype(_c, 0x80000usize)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
pub fn isnumber(mut _c: i32) -> i32 {
|
||||||
pub unsafe extern "C" fn isnumber(mut _c: i32) -> i32 {
|
|
||||||
__istype(_c, 0x400usize)
|
__istype(_c, 0x400usize)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
pub fn isphonogram(mut _c: i32) -> i32 {
|
||||||
pub unsafe extern "C" fn isphonogram(mut _c: i32) -> i32 {
|
|
||||||
__istype(_c, 0x200000usize)
|
__istype(_c, 0x200000usize)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
pub fn isrune(mut _c: i32) -> i32 {
|
||||||
pub unsafe extern "C" fn isrune(mut _c: i32) -> i32 {
|
|
||||||
__istype(_c, 0xfffffff0usize)
|
__istype(_c, 0xfffffff0usize)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
pub fn isspecial(mut _c: i32) -> i32 {
|
||||||
pub unsafe extern "C" fn isspecial(mut _c: i32) -> i32 {
|
|
||||||
__istype(_c, 0x100000usize)
|
__istype(_c, 0x100000usize)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -309,65 +267,11 @@ impl Clone for __sbuf {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy)]
|
|
||||||
#[repr(C)]
|
|
||||||
pub struct __sFILE {
|
|
||||||
pub _p: *mut u8,
|
|
||||||
pub _r: i32,
|
|
||||||
pub _w: i32,
|
|
||||||
pub _flags: i16,
|
|
||||||
pub _file: i16,
|
|
||||||
pub _bf: __sbuf,
|
|
||||||
pub _lbfsize: i32,
|
|
||||||
pub _cookie: *mut ::std::os::raw::c_void,
|
|
||||||
pub _close: unsafe extern "C" fn(*mut ::std::os::raw::c_void) -> i32,
|
|
||||||
pub _read: unsafe extern "C" fn(*mut ::std::os::raw::c_void, *mut u8, i32) -> i32,
|
|
||||||
pub _seek: unsafe extern "C" fn(*mut ::std::os::raw::c_void, isize, i32) -> isize,
|
|
||||||
pub _write: unsafe extern "C" fn(*mut ::std::os::raw::c_void, *const u8, i32) -> i32,
|
|
||||||
pub _ub: __sbuf,
|
|
||||||
pub _extra: *mut __sFILEX,
|
|
||||||
pub _ur: i32,
|
|
||||||
pub _ubuf: [u8; 3],
|
|
||||||
pub _nbuf: [u8; 1],
|
|
||||||
pub _lb: __sbuf,
|
|
||||||
pub _blksize: i32,
|
|
||||||
pub _offset: isize,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Clone for __sFILE {
|
|
||||||
fn clone(&self) -> Self {
|
|
||||||
*self
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn __sputc(mut _c: i32, mut _p: *mut __sFILE) -> i32 {
|
|
||||||
if {
|
|
||||||
(*_p)._w = (*_p)._w - 1;
|
|
||||||
(*_p)._w
|
|
||||||
} >= 0i32
|
|
||||||
|| (*_p)._w >= (*_p)._lbfsize && (_c as (u8) as (i32) != b'\n' as (i32))
|
|
||||||
{
|
|
||||||
({
|
|
||||||
let _rhs = _c;
|
|
||||||
let _lhs = &mut *{
|
|
||||||
let _old = (*_p)._p;
|
|
||||||
(*_p)._p = (*_p)._p.offset(1isize);
|
|
||||||
_old
|
|
||||||
};
|
|
||||||
*_lhs = _rhs as (u8);
|
|
||||||
*_lhs
|
|
||||||
}) as (i32)
|
|
||||||
} else {
|
|
||||||
__swbuf(_c, _p)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[no_mangle]
|
|
||||||
pub static mut szLOG_SOURCE: *const u8 = (*b"YubiKey PIV Library\0").as_ptr();
|
pub static mut szLOG_SOURCE: *const u8 = (*b"YubiKey PIV Library\0").as_ptr();
|
||||||
|
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy)]
|
||||||
#[repr(i32)]
|
#[repr(i32)]
|
||||||
|
#[allow(non_camel_case_types)]
|
||||||
pub enum Enum5 {
|
pub enum Enum5 {
|
||||||
DES_OK = 0i32,
|
DES_OK = 0i32,
|
||||||
DES_INVALID_PARAMETER = -1i32,
|
DES_INVALID_PARAMETER = -1i32,
|
||||||
@@ -379,7 +283,7 @@ pub enum Enum5 {
|
|||||||
#[derive(Copy)]
|
#[derive(Copy)]
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
pub struct DES_ks {
|
pub struct DES_ks {
|
||||||
pub ks: [Union6; 16],
|
pub ks: [u8; 16],
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Clone for DES_ks {
|
impl Clone for DES_ks {
|
||||||
@@ -390,24 +294,23 @@ impl Clone for DES_ks {
|
|||||||
|
|
||||||
#[derive(Copy)]
|
#[derive(Copy)]
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
pub struct des_key {
|
pub struct DesKey {
|
||||||
pub ks1: DES_ks,
|
pub ks1: DES_ks,
|
||||||
pub ks2: DES_ks,
|
pub ks2: DES_ks,
|
||||||
pub ks3: DES_ks,
|
pub ks3: DES_ks,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Clone for des_key {
|
impl Clone for DesKey {
|
||||||
fn clone(&self) -> Self {
|
fn clone(&self) -> Self {
|
||||||
*self
|
*self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
pub fn des_import_key(
|
||||||
pub unsafe extern "C" fn des_import_key(
|
|
||||||
type_: i32,
|
type_: i32,
|
||||||
mut keyraw: *const u8,
|
mut keyraw: *const u8,
|
||||||
keyrawlen: usize,
|
keyrawlen: usize,
|
||||||
mut key: *mut *mut des_key,
|
mut key: *mut *mut DesKey,
|
||||||
) -> Enum5 {
|
) -> Enum5 {
|
||||||
let mut _currentBlock;
|
let mut _currentBlock;
|
||||||
let mut rc: Enum5 = Enum5::DES_OK;
|
let mut rc: Enum5 = Enum5::DES_OK;
|
||||||
@@ -430,7 +333,7 @@ pub unsafe extern "C" fn des_import_key(
|
|||||||
rc = Enum5::DES_INVALID_PARAMETER;
|
rc = Enum5::DES_INVALID_PARAMETER;
|
||||||
_currentBlock = 15;
|
_currentBlock = 15;
|
||||||
} else if {
|
} else if {
|
||||||
*key = malloc(::std::mem::size_of::<des_key>()) as (*mut des_key);
|
*key = malloc(::std::mem::size_of::<DesKey>()) as (*mut DesKey);
|
||||||
*key
|
*key
|
||||||
}
|
}
|
||||||
.is_null()
|
.is_null()
|
||||||
@@ -441,7 +344,7 @@ pub unsafe extern "C" fn des_import_key(
|
|||||||
memset(
|
memset(
|
||||||
*key as (*mut ::std::os::raw::c_void),
|
*key as (*mut ::std::os::raw::c_void),
|
||||||
0i32,
|
0i32,
|
||||||
::std::mem::size_of::<des_key>(),
|
::std::mem::size_of::<DesKey>(),
|
||||||
);
|
);
|
||||||
memcpy(
|
memcpy(
|
||||||
key_tmp.as_mut_ptr() as (*mut ::std::os::raw::c_void),
|
key_tmp.as_mut_ptr() as (*mut ::std::os::raw::c_void),
|
||||||
@@ -480,23 +383,21 @@ pub unsafe extern "C" fn des_import_key(
|
|||||||
if _currentBlock == 15 {
|
if _currentBlock == 15 {
|
||||||
if !key.is_null() {
|
if !key.is_null() {
|
||||||
des_destroy_key(*key);
|
des_destroy_key(*key);
|
||||||
*key = 0i32 as (*mut ::std::os::raw::c_void) as (*mut des_key);
|
*key = 0i32 as (*mut ::std::os::raw::c_void) as (*mut DesKey);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rc
|
rc
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
pub fn des_destroy_key(mut key: *mut DesKey) -> Enum5 {
|
||||||
pub unsafe extern "C" fn des_destroy_key(mut key: *mut des_key) -> Enum5 {
|
|
||||||
if !key.is_null() {
|
if !key.is_null() {
|
||||||
free(key as (*mut ::std::os::raw::c_void));
|
free(key as (*mut ::std::os::raw::c_void));
|
||||||
}
|
}
|
||||||
Enum5::DES_OK
|
Enum5::DES_OK
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
pub fn des_encrypt(
|
||||||
pub unsafe extern "C" fn des_encrypt(
|
mut key: *mut DesKey,
|
||||||
mut key: *mut des_key,
|
|
||||||
mut in_: *const u8,
|
mut in_: *const u8,
|
||||||
inlen: usize,
|
inlen: usize,
|
||||||
mut out: *mut u8,
|
mut out: *mut u8,
|
||||||
@@ -518,9 +419,8 @@ pub unsafe extern "C" fn des_encrypt(
|
|||||||
rc
|
rc
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
pub fn des_decrypt(
|
||||||
pub unsafe extern "C" fn des_decrypt(
|
mut key: *mut DesKey,
|
||||||
mut key: *mut des_key,
|
|
||||||
mut in_: *const u8,
|
mut in_: *const u8,
|
||||||
inlen: usize,
|
inlen: usize,
|
||||||
mut out: *mut u8,
|
mut out: *mut u8,
|
||||||
@@ -542,21 +442,20 @@ pub unsafe extern "C" fn des_decrypt(
|
|||||||
rc
|
rc
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
pub fn yk_des_is_weak_key(mut key: *const u8, cb_key: usize) -> bool {
|
||||||
pub unsafe extern "C" fn yk_des_is_weak_key(mut key: *const u8, cb_key: usize) -> bool {
|
|
||||||
cb_key;
|
cb_key;
|
||||||
DES_is_weak_key(key as (*mut [u8; 8])) != 0
|
DES_is_weak_key(key as (*mut [u8; 8])) != 0
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy)]
|
||||||
#[repr(i32)]
|
#[repr(i32)]
|
||||||
|
#[allow(non_camel_case_types)]
|
||||||
pub enum Enum7 {
|
pub enum Enum7 {
|
||||||
PRNG_OK = 0i32,
|
PRNG_OK = 0i32,
|
||||||
PRNG_GENERAL_ERROR = -1i32,
|
PRNG_GENERAL_ERROR = -1i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
pub fn _ykpiv_prng_generate(mut buffer: *mut u8, cb_req: usize) -> Enum7 {
|
||||||
pub unsafe extern "C" fn _ykpiv_prng_generate(mut buffer: *mut u8, cb_req: usize) -> Enum7 {
|
|
||||||
let mut rc: Enum7 = Enum7::PRNG_OK;
|
let mut rc: Enum7 = Enum7::PRNG_OK;
|
||||||
if -1i32 == RAND_bytes(buffer, cb_req as (i32)) {
|
if -1i32 == RAND_bytes(buffer, cb_req as (i32)) {
|
||||||
rc = Enum7::PRNG_GENERAL_ERROR;
|
rc = Enum7::PRNG_GENERAL_ERROR;
|
||||||
@@ -566,13 +465,13 @@ pub unsafe extern "C" fn _ykpiv_prng_generate(mut buffer: *mut u8, cb_req: usize
|
|||||||
|
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy)]
|
||||||
#[repr(i32)]
|
#[repr(i32)]
|
||||||
|
#[allow(non_camel_case_types)]
|
||||||
pub enum Enum8 {
|
pub enum Enum8 {
|
||||||
PKCS5_OK = 0i32,
|
PKCS5_OK = 0i32,
|
||||||
PKCS5_GENERAL_ERROR = -1i32,
|
PKCS5_GENERAL_ERROR = -1i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
pub fn pkcs5_pbkdf2_sha1(
|
||||||
pub unsafe extern "C" fn pkcs5_pbkdf2_sha1(
|
|
||||||
mut password: *const u8,
|
mut password: *const u8,
|
||||||
cb_password: usize,
|
cb_password: usize,
|
||||||
mut salt: *const u8,
|
mut salt: *const u8,
|
||||||
@@ -594,14 +493,13 @@ pub unsafe extern "C" fn pkcs5_pbkdf2_sha1(
|
|||||||
rc
|
rc
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
pub fn _strip_ws(mut sz: *mut c_char) -> *mut c_char {
|
||||||
pub unsafe extern "C" fn _strip_ws(mut sz: *mut u8) -> *mut u8 {
|
let mut psz_head: *mut c_char = sz;
|
||||||
let mut psz_head: *mut u8 = sz;
|
let mut psz_tail: *mut c_char = sz
|
||||||
let mut psz_tail: *mut u8 = sz
|
.offset(strlen(sz as *const c_char) as (isize))
|
||||||
.offset(strlen(sz as (*const u8)) as (isize))
|
|
||||||
.offset(-1isize);
|
.offset(-1isize);
|
||||||
'loop1: loop {
|
'loop1: loop {
|
||||||
if isspace(*psz_head as (i32)) == 0 {
|
if isspace(*psz_head as i32) == 0 {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
psz_head = psz_head.offset(1isize);
|
psz_head = psz_head.offset(1isize);
|
||||||
@@ -614,150 +512,150 @@ pub unsafe extern "C" fn _strip_ws(mut sz: *mut u8) -> *mut u8 {
|
|||||||
let _old = psz_tail;
|
let _old = psz_tail;
|
||||||
psz_tail = psz_tail.offset(-1isize);
|
psz_tail = psz_tail.offset(-1isize);
|
||||||
_old
|
_old
|
||||||
} = b'\0';
|
} = 0;
|
||||||
}
|
}
|
||||||
psz_head
|
psz_head
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||||
#[repr(i32)]
|
#[allow(non_camel_case_types)]
|
||||||
pub enum _setting_source_t {
|
pub enum SettingSource {
|
||||||
SETTING_SOURCE_USER,
|
SETTING_SOURCE_USER,
|
||||||
SETTING_SOURCE_ADMIN,
|
SETTING_SOURCE_ADMIN,
|
||||||
SETTING_SOURCE_DEFAULT,
|
SETTING_SOURCE_DEFAULT,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy)]
|
#[derive(Copy)]
|
||||||
#[repr(C)]
|
pub struct SettingBool {
|
||||||
pub struct _setting_bool_t {
|
|
||||||
pub value: bool,
|
pub value: bool,
|
||||||
pub source: _setting_source_t,
|
pub source: SettingSource,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Clone for _setting_bool_t {
|
impl Clone for SettingBool {
|
||||||
fn clone(&self) -> Self {
|
fn clone(&self) -> Self {
|
||||||
*self
|
*self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
pub unsafe fn _get_bool_config(mut sz_setting: *const c_char) -> SettingBool {
|
||||||
pub unsafe extern "C" fn _get_bool_config(mut sz_setting: *const u8) -> _setting_bool_t {
|
let mut setting: SettingBool = SettingBool {
|
||||||
let mut _currentBlock;
|
|
||||||
let mut setting: _setting_bool_t = _setting_bool_t {
|
|
||||||
value: false,
|
value: false,
|
||||||
source: _setting_source_t::SETTING_SOURCE_DEFAULT,
|
source: SettingSource::SETTING_SOURCE_DEFAULT,
|
||||||
};
|
};
|
||||||
let mut sz_line: [u8; 256];
|
let mut sz_line = [0u8; 256];
|
||||||
let mut psz_name: *mut u8 = 0i32 as (*mut u8);
|
let mut psz_name: *mut c_char = ptr::null_mut();
|
||||||
let mut psz_value: *mut u8 = 0i32 as (*mut u8);
|
let mut psz_value: *mut c_char = ptr::null_mut();
|
||||||
let mut sz_name = [0u8; 256];
|
let mut sz_name = [0u8; 256];
|
||||||
let mut sz_value = [0u8; 256];
|
let mut sz_value = [0u8; 256];
|
||||||
let mut pf: *mut __sFILE = 0i32 as (*mut __sFILE);
|
|
||||||
if !{
|
let mut pf = unsafe {
|
||||||
pf = fopen(
|
fopen(
|
||||||
(*b"/etc/yubico/yubikeypiv.conf\0").as_ptr(),
|
b"/etc/yubico/yubikeypiv.conf\0".as_ptr() as *const c_char,
|
||||||
(*b"r\0").as_ptr(),
|
b"r\0".as_ptr() as *const c_char,
|
||||||
);
|
)
|
||||||
pf
|
};
|
||||||
|
|
||||||
|
if pf.is_null() {
|
||||||
|
return setting;
|
||||||
}
|
}
|
||||||
.is_null()
|
|
||||||
{
|
while feof(pf) == 0 {
|
||||||
_currentBlock = 1;
|
|
||||||
} else {
|
|
||||||
_currentBlock = 10;
|
|
||||||
}
|
|
||||||
'loop1: loop {
|
|
||||||
if _currentBlock == 1 {
|
|
||||||
if feof(pf) == 0 {
|
|
||||||
if fgets(
|
if fgets(
|
||||||
sz_line.as_mut_ptr(),
|
sz_line.as_mut_ptr() as *mut c_char,
|
||||||
::std::mem::size_of::<[u8; 256]>() as (i32),
|
sz_line.len() as c_int,
|
||||||
pf,
|
pf,
|
||||||
)
|
)
|
||||||
.is_null()
|
.is_null()
|
||||||
{
|
{
|
||||||
_currentBlock = 1;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if sz_line[0usize] as (i32) == b'#' as (i32) {
|
|
||||||
_currentBlock = 1;
|
if sz_line[0] == b'#' {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if sz_line[0usize] as (i32) == b'\r' as (i32) {
|
|
||||||
_currentBlock = 1;
|
if sz_line[0] == b'\r' {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if sz_line[0usize] as (i32) == b'\n' as (i32) {
|
|
||||||
_currentBlock = 1;
|
if sz_line[0] == b'\n' {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if !(sscanf(
|
if !(sscanf(
|
||||||
sz_line.as_mut_ptr() as (*const u8),
|
sz_line.as_mut_ptr(),
|
||||||
(*b"%255[^=]=%255s\0").as_ptr(),
|
(*b"%255[^=]=%255s\0").as_ptr(),
|
||||||
sz_name.as_mut_ptr(),
|
sz_name.as_mut_ptr(),
|
||||||
sz_value.as_mut_ptr(),
|
sz_value.as_mut_ptr(),
|
||||||
) == 2i32)
|
) == 2)
|
||||||
{
|
{
|
||||||
_currentBlock = 1;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
psz_name = _strip_ws(sz_name.as_mut_ptr());
|
|
||||||
if !(strcasecmp(psz_name as (*const u8), sz_setting) == 0) {
|
psz_name = _strip_ws(sz_name.as_mut_ptr() as *mut c_char);
|
||||||
_currentBlock = 1;
|
|
||||||
|
if !(strcasecmp(psz_name as *const c_char, sz_setting as *const c_char) == 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
psz_value = _strip_ws(sz_value.as_mut_ptr());
|
|
||||||
setting.source = _setting_source_t::SETTING_SOURCE_ADMIN;
|
psz_value = _strip_ws(sz_value.as_mut_ptr() as *mut c_char);
|
||||||
setting.value = strcmp(psz_value as (*const u8), (*b"1\0").as_ptr()) == 0
|
setting.source = SettingSource::SETTING_SOURCE_ADMIN;
|
||||||
|| strcasecmp(psz_value as (*const u8), (*b"true\0").as_ptr()) == 0;
|
setting.value = strcmp(psz_value as *const c_char, b"1\0".as_ptr() as *const c_char) == 0
|
||||||
|
|| strcasecmp(
|
||||||
|
psz_value as *const c_char,
|
||||||
|
b"true\0".as_ptr() as *const c_char,
|
||||||
|
) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(pf);
|
fclose(pf);
|
||||||
_currentBlock = 10;
|
setting
|
||||||
} else {
|
|
||||||
return setting;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
pub fn _get_bool_env(mut sz_setting: *const c_char) -> SettingBool {
|
||||||
pub unsafe extern "C" fn _get_bool_env(mut sz_setting: *const u8) -> _setting_bool_t {
|
let mut setting: SettingBool = SettingBool {
|
||||||
let mut setting: _setting_bool_t = _setting_bool_t {
|
|
||||||
value: false,
|
value: false,
|
||||||
source: _setting_source_t::SETTING_SOURCE_DEFAULT,
|
source: SettingSource::SETTING_SOURCE_DEFAULT,
|
||||||
};
|
};
|
||||||
let mut psz_value: *mut u8 = 0i32 as (*mut ::std::os::raw::c_void) as (*mut u8);
|
let mut psz_value: *mut c_char = ptr::null_mut();
|
||||||
let mut sz_name = [0u8; 256];
|
let mut sz_name = [0u8; 256];
|
||||||
|
|
||||||
snprintf(
|
snprintf(
|
||||||
sz_name.as_mut_ptr(),
|
sz_name.as_mut_ptr(),
|
||||||
::std::mem::size_of::<[u8; 256]>().wrapping_sub(1usize),
|
::std::mem::size_of::<[u8; 256]>().wrapping_sub(1usize),
|
||||||
(*b"%s%s\0").as_ptr(),
|
b"%s%s\0".as_ptr(),
|
||||||
(*b"YUBIKEY_PIV_\0").as_ptr(),
|
b"YUBIKEY_PIV_\0".as_ptr(),
|
||||||
sz_setting,
|
sz_setting,
|
||||||
);
|
);
|
||||||
psz_value = getenv(sz_name.as_mut_ptr() as (*const u8));
|
|
||||||
|
psz_value = getenv(sz_name.as_mut_ptr() as *const c_char);
|
||||||
|
|
||||||
if !psz_value.is_null() {
|
if !psz_value.is_null() {
|
||||||
setting.source = _setting_source_t::SETTING_SOURCE_USER;
|
setting.source = SettingSource::SETTING_SOURCE_USER;
|
||||||
setting.value = strcmp(psz_value as (*const u8), (*b"1\0").as_ptr()) == 0
|
setting.value = strcmp(psz_value as *const c_char, b"1\0".as_ptr() as *const c_char) == 0
|
||||||
|| strcasecmp(psz_value as (*const u8), (*b"true\0").as_ptr()) == 0;
|
|| strcasecmp(
|
||||||
|
psz_value as *const c_char,
|
||||||
|
b"true\0".as_ptr() as *const c_char,
|
||||||
|
) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
setting
|
setting
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
pub fn setting_get_bool(mut sz_setting: *const c_char, mut def: bool) -> SettingBool {
|
||||||
pub unsafe extern "C" fn setting_get_bool(
|
let mut setting: SettingBool = SettingBool {
|
||||||
mut sz_setting: *const u8,
|
|
||||||
mut def: bool,
|
|
||||||
) -> _setting_bool_t {
|
|
||||||
let mut setting: _setting_bool_t = _setting_bool_t {
|
|
||||||
value: def,
|
value: def,
|
||||||
source: _setting_source_t::SETTING_SOURCE_DEFAULT,
|
source: SettingSource::SETTING_SOURCE_DEFAULT,
|
||||||
};
|
};
|
||||||
|
|
||||||
setting = _get_bool_config(sz_setting);
|
setting = _get_bool_config(sz_setting);
|
||||||
if setting.source as (i32) == _setting_source_t::SETTING_SOURCE_DEFAULT as (i32) {
|
|
||||||
|
if setting.source == SettingSource::SETTING_SOURCE_DEFAULT {
|
||||||
setting = _get_bool_env(sz_setting);
|
setting = _get_bool_env(sz_setting);
|
||||||
}
|
}
|
||||||
if setting.source as (i32) == _setting_source_t::SETTING_SOURCE_DEFAULT as (i32) {
|
|
||||||
|
if setting.source == SettingSource::SETTING_SOURCE_DEFAULT {
|
||||||
setting.value = def;
|
setting.value = def;
|
||||||
}
|
}
|
||||||
|
|
||||||
setting
|
setting
|
||||||
}
|
}
|
||||||
|
|||||||
+883
-1206
File diff suppressed because it is too large
Load Diff
+593
-929
File diff suppressed because it is too large
Load Diff
-193
@@ -1,193 +0,0 @@
|
|||||||
// Copyright (c) 2014-2016 Yubico AB
|
|
||||||
// All rights reserved.
|
|
||||||
//
|
|
||||||
// Redistribution and use in source and binary forms, with or without
|
|
||||||
// modification, are permitted provided that the following conditions are
|
|
||||||
// met:
|
|
||||||
//
|
|
||||||
// * Redistributions of source code must retain the above copyright
|
|
||||||
// notice, this list of conditions and the following disclaimer.
|
|
||||||
//
|
|
||||||
// * Redistributions in binary form must reproduce the above
|
|
||||||
// copyright notice, this list of conditions and the following
|
|
||||||
// disclaimer in the documentation and/or other materials provided
|
|
||||||
// with the distribution.
|
|
||||||
//
|
|
||||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
|
|
||||||
extern "C" {
|
|
||||||
fn strcmp(__s1: *const u8, __s2: *const u8) -> i32;
|
|
||||||
fn strcspn(__s: *const u8, __charset: *const u8) -> usize;
|
|
||||||
fn strncmp(__s1: *const u8, __s2: *const u8, __n: usize) -> i32;
|
|
||||||
fn strspn(__s: *const u8, __charset: *const u8) -> usize;
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe extern "C" fn my_strverscmp(mut s1: *const u8, mut s2: *const u8) -> i32 {
|
|
||||||
let mut _currentBlock;
|
|
||||||
static mut digits: *const u8 = (*b"0123456789\0").as_ptr();
|
|
||||||
let mut p1: usize;
|
|
||||||
let mut p2: usize;
|
|
||||||
p1 = strcspn(s1, digits);
|
|
||||||
p2 = strcspn(s2, digits);
|
|
||||||
'loop1: loop {
|
|
||||||
if !(p1 == p2
|
|
||||||
&& (*s1.offset(p1 as (isize)) as (i32) != b'\0' as (i32))
|
|
||||||
&& (*s2.offset(p2 as (isize)) as (i32) != b'\0' as (i32)))
|
|
||||||
{
|
|
||||||
_currentBlock = 2;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
let mut ret: i32;
|
|
||||||
let mut lz1: i32;
|
|
||||||
let mut lz2: i32;
|
|
||||||
if {
|
|
||||||
ret = strncmp(s1, s2, p1);
|
|
||||||
ret
|
|
||||||
} != 0i32
|
|
||||||
{
|
|
||||||
_currentBlock = 37;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
s1 = s1.offset(p1 as (isize));
|
|
||||||
s2 = s2.offset(p2 as (isize));
|
|
||||||
lz1 = {
|
|
||||||
lz2 = 0i32;
|
|
||||||
lz2
|
|
||||||
};
|
|
||||||
if *s1 as (i32) == b'0' as (i32) {
|
|
||||||
lz1 = 1i32;
|
|
||||||
}
|
|
||||||
if *s2 as (i32) == b'0' as (i32) {
|
|
||||||
lz2 = 1i32;
|
|
||||||
}
|
|
||||||
if lz1 > lz2 {
|
|
||||||
_currentBlock = 36;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if lz1 < lz2 {
|
|
||||||
_currentBlock = 35;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if lz1 == 1i32 {
|
|
||||||
_currentBlock = 11;
|
|
||||||
} else {
|
|
||||||
_currentBlock = 23;
|
|
||||||
}
|
|
||||||
'loop11: loop {
|
|
||||||
if _currentBlock == 11 {
|
|
||||||
if *s1 as (i32) == b'0' as (i32) && (*s2 as (i32) == b'0' as (i32)) {
|
|
||||||
s1 = s1.offset(1isize);
|
|
||||||
s2 = s2.offset(1isize);
|
|
||||||
_currentBlock = 11;
|
|
||||||
} else {
|
|
||||||
p1 = strspn(s1, digits);
|
|
||||||
p2 = strspn(s2, digits);
|
|
||||||
if p1 == 0usize && (p2 > 0usize) {
|
|
||||||
_currentBlock = 33;
|
|
||||||
break 'loop1;
|
|
||||||
}
|
|
||||||
if p2 == 0usize && (p1 > 0usize) {
|
|
||||||
_currentBlock = 32;
|
|
||||||
break 'loop1;
|
|
||||||
}
|
|
||||||
if *s1 as (i32) != *s2 as (i32)
|
|
||||||
&& (*s1 as (i32) != b'0' as (i32))
|
|
||||||
&& (*s2 as (i32) != b'0' as (i32))
|
|
||||||
{
|
|
||||||
if p1 < p2 {
|
|
||||||
_currentBlock = 31;
|
|
||||||
break 'loop1;
|
|
||||||
}
|
|
||||||
if p1 > p2 {
|
|
||||||
_currentBlock = 30;
|
|
||||||
break 'loop1;
|
|
||||||
} else {
|
|
||||||
_currentBlock = 23;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if p1 < p2 {
|
|
||||||
ret = strncmp(s1, s2, p1);
|
|
||||||
} else if p1 > p2 {
|
|
||||||
ret = strncmp(s1, s2, p2);
|
|
||||||
}
|
|
||||||
if ret != 0i32 {
|
|
||||||
_currentBlock = 20;
|
|
||||||
break 'loop1;
|
|
||||||
} else {
|
|
||||||
_currentBlock = 23;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
p1 = strspn(s1, digits);
|
|
||||||
p2 = strspn(s2, digits);
|
|
||||||
if p1 < p2 {
|
|
||||||
_currentBlock = 29;
|
|
||||||
break 'loop1;
|
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if p1 > p2 {
|
|
||||||
_currentBlock = 28;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if {
|
|
||||||
ret = strncmp(s1, s2, p1);
|
|
||||||
ret
|
|
||||||
} != 0i32
|
|
||||||
{
|
|
||||||
_currentBlock = 27;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
s1 = s1.offset(p1 as (isize));
|
|
||||||
s2 = s2.offset(p2 as (isize));
|
|
||||||
p1 = strcspn(s1, digits);
|
|
||||||
p2 = strcspn(s2, digits);
|
|
||||||
}
|
|
||||||
if _currentBlock == 2 {
|
|
||||||
strcmp(s1, s2)
|
|
||||||
} else if _currentBlock == 20 {
|
|
||||||
ret
|
|
||||||
} else if _currentBlock == 27 {
|
|
||||||
ret
|
|
||||||
} else if _currentBlock == 28 {
|
|
||||||
1i32
|
|
||||||
} else if _currentBlock == 29 {
|
|
||||||
-1i32
|
|
||||||
} else if _currentBlock == 30 {
|
|
||||||
-1i32
|
|
||||||
} else if _currentBlock == 31 {
|
|
||||||
1i32
|
|
||||||
} else if _currentBlock == 32 {
|
|
||||||
-1i32
|
|
||||||
} else if _currentBlock == 33 {
|
|
||||||
1i32
|
|
||||||
} else if _currentBlock == 35 {
|
|
||||||
1i32
|
|
||||||
} else if _currentBlock == 36 {
|
|
||||||
-1i32
|
|
||||||
} else {
|
|
||||||
ret
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn ykpiv_check_version(mut req_version: *const u8) -> *const u8 {
|
|
||||||
if req_version.is_null() || my_strverscmp(req_version, (*b"@VERSION@\0").as_ptr()) <= 0i32 {
|
|
||||||
(*b"@VERSION@\0").as_ptr()
|
|
||||||
} else {
|
|
||||||
0i32 as (*mut ::std::os::raw::c_void) as (*const u8)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user