|
4 | 4 | //!
|
5 | 5 | //! C header: [`include/linux/security.h`](../../../../include/linux/security.h).
|
6 | 6 |
|
7 |
| -use crate::{file::File, task::Task, Result}; |
| 7 | +use crate::{bindings, cred::Credential, file::File, to_result, Result}; |
8 | 8 |
|
9 | 9 | /// Calls the security modules to determine if the given task can become the manager of a binder
|
10 | 10 | /// context.
|
11 |
| -pub fn binder_set_context_mgr(_mgr: &Task) -> Result { |
12 |
| - // TODO |
13 |
| - // |
14 |
| - // // SAFETY: By the `Task` invariants, `mgr.ptr` is valid. |
15 |
| - // let ret = unsafe { bindings::security_binder_set_context_mgr(mgr.ptr) }; |
16 |
| - // if ret != 0 { |
17 |
| - // Err(Error::from_kernel_errno(ret)) |
18 |
| - // } else { |
19 |
| - // Ok(()) |
20 |
| - // } |
21 |
| - |
22 |
| - Ok(()) |
| 11 | +pub fn binder_set_context_mgr(mgr: &Credential) -> Result { |
| 12 | + // SAFETY: By the `Credential` invariants, `mgr.ptr` is valid. |
| 13 | + to_result(|| unsafe { bindings::security_binder_set_context_mgr(mgr.ptr) }) |
23 | 14 | }
|
24 | 15 |
|
25 | 16 | /// Calls the security modules to determine if binder transactions are allowed from task `from` to
|
26 | 17 | /// task `to`.
|
27 |
| -pub fn binder_transaction(_from: &Task, _to: &Task) -> Result { |
28 |
| - // TODO |
29 |
| - // |
30 |
| - // // SAFETY: By the `Task` invariants, `from.ptr` and `to.ptr` are valid. |
31 |
| - // let ret = unsafe { bindings::security_binder_transaction(from.ptr, to.ptr) }; |
32 |
| - // if ret != 0 { |
33 |
| - // Err(Error::from_kernel_errno(ret)) |
34 |
| - // } else { |
35 |
| - // Ok(()) |
36 |
| - // } |
37 |
| - |
38 |
| - Ok(()) |
| 18 | +pub fn binder_transaction(from: &Credential, to: &Credential) -> Result { |
| 19 | + // SAFETY: By the `Credential` invariants, `from.ptr` and `to.ptr` are valid. |
| 20 | + to_result(|| unsafe { bindings::security_binder_transaction(from.ptr, to.ptr) }) |
39 | 21 | }
|
40 | 22 |
|
41 | 23 | /// Calls the security modules to determine if task `from` is allowed to send binder objects
|
42 | 24 | /// (owned by itself or other processes) to task `to` through a binder transaction.
|
43 |
| -pub fn binder_transfer_binder(_from: &Task, _to: &Task) -> Result { |
44 |
| - // TODO |
45 |
| - // |
46 |
| - // // SAFETY: By the `Task` invariants, `from.ptr` and `to.ptr` are valid. |
47 |
| - // let ret = unsafe { bindings::security_binder_transfer_binder(from.ptr, to.ptr) }; |
48 |
| - // if ret != 0 { |
49 |
| - // Err(Error::from_kernel_errno(ret)) |
50 |
| - // } else { |
51 |
| - // Ok(()) |
52 |
| - // } |
53 |
| - |
54 |
| - Ok(()) |
| 25 | +pub fn binder_transfer_binder(from: &Credential, to: &Credential) -> Result { |
| 26 | + // SAFETY: By the `Credential` invariants, `from.ptr` and `to.ptr` are valid. |
| 27 | + to_result(|| unsafe { bindings::security_binder_transfer_binder(from.ptr, to.ptr) }) |
55 | 28 | }
|
56 | 29 |
|
57 | 30 | /// Calls the security modules to determine if task `from` is allowed to send the given file to
|
58 | 31 | /// task `to` (which would get its own file descriptor) through a binder transaction.
|
59 |
| -pub fn binder_transfer_file(_from: &Task, _to: &Task, _file: &File) -> Result { |
60 |
| - // TODO |
61 |
| - // |
62 |
| - // // SAFETY: By the `Task` invariants, `from.ptr` and `to.ptr` are valid. Similarly, by the |
63 |
| - // // `File` invariants, `file.ptr` is also valid. |
64 |
| - // let ret = unsafe { bindings::security_binder_transfer_file(from.ptr, to.ptr, file.ptr) }; |
65 |
| - // if ret != 0 { |
66 |
| - // Err(Error::from_kernel_errno(ret)) |
67 |
| - // } else { |
68 |
| - // Ok(()) |
69 |
| - // } |
70 |
| - |
71 |
| - Ok(()) |
| 32 | +pub fn binder_transfer_file(from: &Credential, to: &Credential, file: &File) -> Result { |
| 33 | + // SAFETY: By the `Credential` invariants, `from.ptr` and `to.ptr` are valid. Similarly, by the |
| 34 | + // `File` invariants, `file.ptr` is also valid. |
| 35 | + to_result(|| unsafe { bindings::security_binder_transfer_file(from.ptr, to.ptr, file.ptr) }) |
72 | 36 | }
|
0 commit comments