1 // Copyright (C) 2024 Huawei Device Co., Ltd.
2 // Licensed under the Apache License, Version 2.0 (the "License");
3 // you may not use this file except in compliance with the License.
4 // You may obtain a copy of the License at
5 //
6 // http://www.apache.org/licenses/LICENSE-2.0
7 //
8 // Unless required by applicable law or agreed to in writing, software
9 // distributed under the License is distributed on an "AS IS" BASIS,
10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 // See the License for the specific language governing permissions and
12 // limitations under the License.
13
14 #![allow(unused)]
15 #![cfg(gn_test)]
16 mod basic;
17 mod mem;
18 use std::ffi::{c_char, CString};
19 use std::ptr;
20 #[repr(C)]
21 struct TokenInfoParams {
22 dcaps_num: i32,
23 perms_num: i32,
24 acls_num: i32,
25 dcaps: *const *const c_char,
26 perms: *const c_char,
27 acls: *const *const c_char,
28 process_name: *const c_char,
29 apl_str: *const c_char,
30 }
31
32 extern "C" {
GetAccessTokenId(token_info: *mut TokenInfoParams) -> u6433 fn GetAccessTokenId(token_info: *mut TokenInfoParams) -> u64;
SetSelfTokenID(token_id: u64) -> i3234 fn SetSelfTokenID(token_id: u64) -> i32;
35 }
36
init_access_token()37 pub fn init_access_token() {
38 let perms_str =
39 CString::new("ohos.permission.DISTRIBUTED_DATASYNC").expect("permission is invalid");
40 let name = CString::new("listen_test").expect("process name is invalid");
41 let apl = CString::new("system_core").expect("apl string is invalid");
42 let mut param = TokenInfoParams {
43 dcaps_num: 0,
44 perms_num: 0,
45 acls_num: 0,
46 dcaps: ptr::null(),
47 perms: perms_str.as_ptr(),
48 acls: ptr::null(),
49 process_name: name.as_ptr(),
50 apl_str: apl.as_ptr(),
51 };
52
53 unsafe {
54 let token_id = GetAccessTokenId(&mut param as *mut TokenInfoParams);
55 SetSelfTokenID(token_id);
56 }
57 }
58