summaryrefslogtreecommitdiffstats
path: root/rust/src/rfb/detect.rs
blob: 1cf0887c4fdaba1cd61b7544246b29db59645e21 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/* Copyright (C) 2020 Open Information Security Foundation
 *
 * You can copy, redistribute or modify this Program under the terms of
 * the GNU General Public License version 2 as published by the Free
 * Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * version 2 along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 * 02110-1301, USA.
 */

// Author: Frank Honza <frank.honza@dcso.de>

use crate::rfb::rfb::*;
use std::ptr;

#[no_mangle]
pub unsafe extern "C" fn rs_rfb_tx_get_name(
    tx: &mut RFBTransaction, buffer: *mut *const u8, buffer_len: *mut u32,
) -> u8 {
    if let Some(ref r) = tx.tc_server_init {
        let p = &r.name;
        if !p.is_empty() {
            *buffer = p.as_ptr();
            *buffer_len = p.len() as u32;
            return 1;
        }
    }

    *buffer = ptr::null();
    *buffer_len = 0;

    return 0;
}

#[no_mangle]
pub unsafe extern "C" fn rs_rfb_tx_get_sectype(tx: &mut RFBTransaction, sectype: *mut u32) -> u8 {
    if let Some(ref r) = tx.chosen_security_type {
        *sectype = *r;
        return 1;
    }

    *sectype = 0;

    return 0;
}

#[no_mangle]
pub unsafe extern "C" fn rs_rfb_tx_get_secresult(
    tx: &mut RFBTransaction, secresult: *mut u32,
) -> u8 {
    if let Some(ref r) = tx.tc_security_result {
        *secresult = r.status;
        return 1;
    }

    return 0;
}