@@ -22,7 +22,6 @@ const HOSTAPD_TMP_CONF: &'static str = "/tmp/hostapd.conf";
2222const WPA_SUPPLICANT_CONF : & ' static str = "/etc/wpa_supplicant.conf" ;
2323const WPA_SUPPLICANT_TMP_CONF : & ' static str = "/tmp/wpa_supplicant.conf" ;
2424const SMB_CONF : & ' static str = "/etc/samba/smb.conf" ;
25- const SMB_TMP_CONF : & ' static str = "/tmp/smb.conf" ;
2625const PURE_FTPD_CONF : & ' static str = "/etc/pure-ftpd.conf" ;
2726
2827#[ derive( PartialEq ) ]
@@ -46,6 +45,10 @@ impl WifiManager {
4645 } ) )
4746 }
4847
48+ fn is_enabled ( & self ) -> bool {
49+ self . state != WifiState :: Uninitialized
50+ }
51+
4952 fn enable_wifi ( & mut self ) -> error:: Result < ( ) > {
5053 if self . state != WifiState :: Uninitialized {
5154 return Ok ( ( ) ) ;
@@ -87,13 +90,55 @@ impl WifiManager {
8790 & [ & self . config . user . name , & self . config . user . password ] ,
8891 ) ?;
8992
90- fs:: copy ( SMB_CONF , SMB_TMP_CONF ) ?;
91- utils:: run_check_output ( "smbd" , & [ "-D" , "-s" , SMB_TMP_CONF ] ) ?;
92- utils:: run_check_output ( "nmbd" , & [ "-D" , "-s" , SMB_TMP_CONF ] ) ?;
93+ // Setup usershare folder
94+ fs:: create_dir_all ( "/var/lib/samba/usershares" ) ?;
95+ utils:: run_check_output ( "chmod" , & [ "1770" , "/var/lib/samba/usershares" ] ) ?;
96+
97+ utils:: run_check_output ( "smbd" , & [ "-D" , "-s" , SMB_CONF ] ) ?;
98+ utils:: run_check_output ( "nmbd" , & [ "-D" , "-s" , SMB_CONF ] ) ?;
9399
94100 utils:: run_check_output ( "pure-ftpd" , & [ PURE_FTPD_CONF ] ) ?;
95101
96102 self . state = WifiState :: Inactive ;
103+
104+ for entry in fs:: read_dir ( "/mnt" ) ? {
105+ let entry = entry?;
106+ let path = entry. path ( ) ;
107+ let name = path. file_name ( )
108+ . expect ( "Partition has no name" )
109+ . to_string_lossy ( )
110+ . into_owned ( ) ;
111+ self . share_mounted_partition ( & name) ?;
112+ }
113+
114+ Ok ( ( ) )
115+ }
116+
117+ fn share_mounted_partition ( & mut self , name : & str ) -> error:: Result < ( ) > {
118+ if !self . is_enabled ( ) {
119+ return Ok ( ( ) ) ;
120+ }
121+
122+ let path = "/user-mnt/" . to_owned ( ) + name;
123+ utils:: run_check_output (
124+ "net" ,
125+ & [
126+ "usershare" ,
127+ "add" ,
128+ name,
129+ & path,
130+ "" ,
131+ & format ! ( "piso\\ {}:F" , & self . config. user. name) ,
132+ ] ,
133+ ) ?;
134+ Ok ( ( ) )
135+ }
136+
137+ fn remove_shared_partition ( & mut self , name : & str ) -> error:: Result < ( ) > {
138+ if !self . is_enabled ( ) {
139+ return Ok ( ( ) ) ;
140+ }
141+ utils:: run_check_output ( "net" , & [ "usershare" , "delete" , & name] ) ?;
97142 Ok ( ( ) )
98143 }
99144
@@ -262,6 +307,14 @@ impl input::Input for WifiMenu {
262307 disp. shift_focus ( self ) ;
263308 Ok ( ( true , vec ! [ ] ) )
264309 }
310+ action:: Action :: SmbSharePartition ( ref name) => {
311+ self . manager . lock ( ) ?. share_mounted_partition ( name) ?;
312+ Ok ( ( true , vec ! [ ] ) )
313+ }
314+ action:: Action :: SmbRemoveShare ( ref name) => {
315+ self . manager . lock ( ) ?. remove_shared_partition ( name) ?;
316+ Ok ( ( true , vec ! [ ] ) )
317+ }
265318 _ => Ok ( ( false , vec ! [ ] ) ) ,
266319 }
267320 }
0 commit comments