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 #![cfg(gn_test)]
15 mod c_mem;
16 mod interactive;
17 mod parcel_remote;
18 mod skeleton;
19 use std::ffi::{c_char, CString};
20 use std::ptr;
21
22 #[repr(C)]
23 struct TokenInfoParams {
24 dcaps_num: i32,
25 perms_num: i32,
26 acls_num: i32,
27 dcaps: *const *const c_char,
28 perms: *const c_char,
29 acls: *const *const c_char,
30 process_name: *const c_char,
31 apl_str: *const c_char,
32 }
33
34 extern "C" {
GetAccessTokenId(token_info: *mut TokenInfoParams) -> u6435 fn GetAccessTokenId(token_info: *mut TokenInfoParams) -> u64;
SetSelfTokenID(token_id: u64) -> i3236 fn SetSelfTokenID(token_id: u64) -> i32;
37 }
38
init_access_token()39 pub fn init_access_token() {
40 let perms_str = CString::new("ohos.permission.DISTRIBUTED_DATASYNC").unwrap();
41 let name = CString::new("listen_test").unwrap();
42 let apl = CString::new("system_core").unwrap();
43 let mut param = TokenInfoParams {
44 dcaps_num: 0,
45 perms_num: 0,
46 acls_num: 0,
47 dcaps: ptr::null(),
48 perms: perms_str.as_ptr(),
49 acls: ptr::null(),
50 process_name: name.as_ptr(),
51 apl_str: apl.as_ptr(),
52 };
53
54 unsafe {
55 let token_id = GetAccessTokenId(&mut param as *mut TokenInfoParams);
56 SetSelfTokenID(token_id);
57 }
58 }
59