Commit a1cbb34 1 parent 7f07f33 commit a1cbb34 Copy full SHA for a1cbb34
File tree 4 files changed +39
-0
lines changed
4 files changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -39,6 +39,9 @@ pub enum ProtonError {
39
39
/// Could not parse into CIDR range.
40
40
CouldNotParseAsCidr ( String ) ,
41
41
42
+ /// Root permissions required.
43
+ MustHaveRootPermissions ,
44
+
42
45
/// CIDR range must contain network gateway.
43
46
CidrMustContainGateway {
44
47
/// Provided CIDR network range.
@@ -57,6 +60,7 @@ impl Display for ProtonError {
57
60
use ProtonError :: * ;
58
61
let error = match self {
59
62
MustBeEthernetInterface => "must be Ethernet interface" ,
63
+ MustHaveRootPermissions => "must execute with root permissions" ,
60
64
HotspotNotInitialized => "hotspot not initialized" ,
61
65
CouldNotFindWirelessInterface => "could not find wireless interface" ,
62
66
CouldNotGetDeviceInformation => "could not get wireless device information" ,
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ name = "proton_wap"
8
8
path = " src/lib.rs"
9
9
10
10
[dependencies ]
11
+ nix = { version = " 0.29.0" , features = [" user" ] }
11
12
12
13
[dependencies .network-manager ]
13
14
path = " ../network-manager"
Original file line number Diff line number Diff line change @@ -8,6 +8,8 @@ use network_manager::{
8
8
ConnectionState ,
9
9
} ;
10
10
11
+ use nix:: unistd:: Uid ;
12
+
11
13
use proton_cfg:: HotspotConfig ;
12
14
13
15
use proton_dev:: {
@@ -21,6 +23,14 @@ use proton_err::{
21
23
} ;
22
24
23
25
/// A wireless access point.
26
+ ///
27
+ /// **Note**: to construct and use this, you must run the associated
28
+ /// binary with root permissions. This is because some of the functionality
29
+ /// of the `AccessPoint` structure requires direct control over your
30
+ /// device's network interface.
31
+ ///
32
+ /// This is enforced by `AccessPoint::new()`, as the constructor will return
33
+ /// a `ProtonError` if you attempt to execute it without root permission.
24
34
pub struct AccessPoint {
25
35
/// Device discovery manager.
26
36
device_manager : DeviceManager ,
@@ -44,6 +54,11 @@ impl AccessPoint {
44
54
wlifname : & str ,
45
55
config : HotspotConfig ,
46
56
) -> ProtonResult < Self > {
57
+ // Check if the user is `root`
58
+ if !Uid :: effective ( ) . is_root ( ) {
59
+ return Err ( ProtonError :: MustHaveRootPermissions ) ;
60
+ }
61
+
47
62
// Initialize NetworkManager API
48
63
let network_manager = NetworkManager :: new ( ) ;
49
64
You can’t perform that action at this time.
0 commit comments