Skip to content

Commit

Permalink
FIX: NTP Issues, SMB issues (#1073)
Browse files Browse the repository at this point in the history
Disabled guest SMB access as it was causing issues because [Microsoft
disabled guest SMB login per
default](https://learn.microsoft.com/en-us/troubleshoot/windows-server/networking/guest-access-in-smb2-is-disabled-by-default)

change curl timeouts from --connect-timeout to --max-time (-m) 

Fix the endless wait on startup when no IP address was assigned.
_Someone_ <sub><sup><sub><sup><sub>(me)</sub></sup></sub></sup></sub>
forgot to break out of the loop.
Add a check to make sure update_networking isn't run multiple times
simultaneously.

TESTS:

- [ ] Enable SMB, connect to it. Observe that it asks for credentials
(unless you've saved them)
- [ ] Enable NTP and wait for NTP on boot
- [ ] reboot the device on functioning network. observe the time syncs
- [ ] make your internet connection not working (e.g. pull dsl cable)
but the wifi still available
- [ ] reboot the device, observe that the sync times out in a reasonable
time
- [ ] disable your wifi all together (or pull the router plug etc)
- [ ] reboot the device again, observe that the sync times out in a
reasonable time

---------

Co-authored-by: tGecko <[email protected]>
Co-authored-by: Aemiii91 <[email protected]>
  • Loading branch information
3 people authored Jul 27, 2023
1 parent d22f2ce commit a506420
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 64 deletions.
22 changes: 1 addition & 21 deletions src/tweaks/network.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ void network_loadState(void)
network_state.hotspot = config_flag_get(".hotspotState");
network_state.ntp = config_flag_get(".ntpState");
network_state.ntp_wait = config_flag_get(".ntpWait");
network_state.auth_smbd = config_flag_get(".authsmbdState");
network_state.auth_ftp = config_flag_get(".authftpState");
network_state.auth_http = config_flag_get(".authhttpState");
network_state.auth_ssh = config_flag_get(".authsshState");
Expand Down Expand Up @@ -297,12 +296,6 @@ void network_keepServicesAlive(void *pt)
network_setState(&network_state.keep_alive, ".keepServicesAlive", !((ListItem *)pt)->value);
}

void network_setSmbdAuthState(void *pt)
{
network_setState(&network_state.auth_smbd, ".authsmbdState", ((ListItem *)pt)->value);
network_execServiceAuth("smbd");
}

void network_setFtpAuthState(void *pt)
{
network_setState(&network_state.auth_ftp, ".authftpState", ((ListItem *)pt)->value);
Expand Down Expand Up @@ -375,7 +368,7 @@ void menu_smbd(void *pt)
if (!_menu_smbd._created) {
network_getSmbShares();

_menu_smbd = list_createWithSticky(2 + network_numShares, "Samba");
_menu_smbd = list_createWithSticky(1 + network_numShares, "Samba");

list_addItemWithInfoNote(&_menu_smbd,
(ListItem){
Expand All @@ -385,19 +378,6 @@ void menu_smbd(void *pt)
.value = (int)network_state.smbd,
.action = network_setSmbdState},
item->info_note);
list_addItemWithInfoNote(&_menu_smbd,
(ListItem){
.label = "Enable authentication",
.sticky_note = "Enable password authentication",
.item_type = TOGGLE,
.disabled = !network_state.smbd,
.value = (int)network_state.auth_smbd,
.action = network_setSmbdAuthState},
"Username: onion\n"
"Password: onion\n"
" \n"
"We're using a new auth system. User defined\n"
"passwords will come in a future update.");

for (int i = 0; i < network_numShares; i++) {
ListItem shareItem = {
Expand Down
10 changes: 7 additions & 3 deletions static/build/.tmp_update/runtime.sh
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ main() {
}

state_change() {
log "state change: $1"
runifnecessary "keymon" keymon
check_networking
touch /tmp/state_changed
Expand Down Expand Up @@ -583,9 +584,12 @@ check_networking() {
return
fi

rm /tmp/network_changed

$sysdir/script/network/update_networking.sh check
if pgrep -f update_networking.sh; then
log "update_networking already running"
else
rm /tmp/network_changed
$sysdir/script/network/update_networking.sh check
fi

check_timezone
}
Expand Down
35 changes: 14 additions & 21 deletions static/build/.tmp_update/script/network/update_networking.sh
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,8 @@ check_smbdstate() {
/var/private \
/var/log/

update_smbconf
$netscript/start_smbd.sh $PASS &
log "Samba: Starting smbd at exit of tweaks.."
log "Samba: Starting smbd.."
else
disable_flag smbdState
fi
Expand All @@ -165,14 +164,6 @@ check_smbdstate() {
fi
}

update_smbconf() {
if flag_enabled authsmbdState; then
sed -i -e '/guest only/s/1/0/g' -e 's/#alid users = onion/valid users = onion/g' $sysdir/config/smb.conf
else
sed -i -e '/guest only/s/0/1/g' -e 's/valid users = onion/#alid users = onion/g' $sysdir/config/smb.conf
fi
}

smbd_authed() {
if flag_enabled smbdState; then
update_smbconf
Expand Down Expand Up @@ -436,11 +427,6 @@ check_ntpstate() {
return 1
fi

# Try once for good luck (this is faster - when it works)
if get_time; then
return 0
fi

attempts=0
max_wait_ip=10
max_attempts=3
Expand All @@ -456,6 +442,7 @@ check_ntpstate() {
log "NTPwait: Could not aquire an IP address"
ret_val=1
got_ip=0
break
fi
else
log "NTPwait: IP address aquired: $ip"
Expand Down Expand Up @@ -493,35 +480,41 @@ check_ntpstate() {
get_time() { # handles 2 types of network time, instant from an API or longer from an NTP server, if the instant API checks fails it will fallback to the longer ntp
log "NTP: started time update"

response=$(curl -s --connect-timeout 3 http://worldtimeapi.org/api/ip.txt)
response=$(curl -s -m 3 http://worldtimeapi.org/api/ip.txt)
utc_datetime=$(echo "$response" | grep -o 'utc_datetime: [^.]*' | cut -d ' ' -f2 | sed "s/T/ /")
if ! flag_enabled "manual_tz"; then
utc_offset="UTC$(echo "$response" | grep -o 'utc_offset: [^.]*' | cut -d ' ' -f2)"
fi

if [ -z "$utc_datetime" ]; then
log "NTP: Failed to get time from worldtimeapi.org, trying timeapi.io"
utc_datetime=$(curl -s -k --connect-timeout 5 https://timeapi.io/api/Time/current/zone?timeZone=UTC | grep -o '"dateTime":"[^.]*' | cut -d '"' -f4 | sed 's/T/ /')
utc_datetime=$(curl -s -k -m 5 https://timeapi.io/api/Time/current/zone?timeZone=UTC | grep -o '"dateTime":"[^.]*' | cut -d '"' -f4 | sed 's/T/ /')
if ! flag_enabled "manual_tz"; then
ip_address=$(curl -s -k --connect-timeout 5 https://api.ipify.org)
utc_offset_seconds=$(curl -s -k --connect-timeout 5 https://timeapi.io/api/TimeZone/ip?ipAddress=$ip_address | jq '.currentUtcOffset.seconds')
ip_address=$(curl -s -k -m 5 https://api.ipify.org)
utc_offset_seconds=$(curl -s -k -m 5 https://timeapi.io/api/TimeZone/ip?ipAddress=$ip_address | jq '.currentUtcOffset.seconds')
utc_offset="$(convert_seconds_to_utc_offset $utc_offset_seconds)"
fi
fi

if [ ! -z "$utc_datetime" ]; then
if [ ! -z "$utc_offset" ]; then
if [ -n "$utc_datetime" ]; then
playActivity stop_all

if [ -n "$utc_offset" ]; then
echo "$utc_offset" | sed 's/\+/_/' | sed 's/-/+/' | sed 's/_/-/' > $sysdir/config/.tz
cp $sysdir/config/.tz $sysdir/config/.tz_sync
sync
set_tzid
fi

if date -u -s "$utc_datetime" > /dev/null 2>&1; then
hwclock -w
log "NTP: Time successfully aquired using API"
touch /tmp/ntp_synced
playActivity resume
return 0
fi

playActivity resume
fi

log "NTP: Failed to get time via timeapi.io as well, falling back to NTP."
Expand Down
29 changes: 10 additions & 19 deletions static/configs/.tmp_update/config/smb.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## Onion smb.conf

[global]

workgroup = workgroup
client min protocol = SMB2
client max protocol = SMB3
Expand All @@ -17,96 +18,86 @@ cache directory = /var/run/samba/locks/cache
ntp signd socket directory = /var/lib/ntp_signd
pid directory = /var/run/

map to guest = Bad User
server role = standalone server

## Edit your shares below

[BIOS]
#alid users = onion
valid users = onion
path = /mnt/SDCARD/BIOS
public = 1
guest only = 1
writable = 1
force create mode = 0666
force directory mode = 0777
available = 1

[Media]
#alid users = onion
valid users = onion
path = /mnt/SDCARD/Media
public = 1
guest only = 1
writable = 1
force create mode = 0666
force directory mode = 0777
available = 1

[Overlays]
#alid users = onion
valid users = onion
path = /mnt/SDCARD/RetroArch/.retroarch/overlay
public = 1
guest only = 1
writable = 1
force create mode = 0666
force directory mode = 0777
available = 1

[Roms]
#alid users = onion
valid users = onion
path = /mnt/SDCARD/Roms
public = 1
guest only = 1
writable = 1
force create mode = 0666
force directory mode = 0777
available = 1

[Saves]
#alid users = onion
valid users = onion
path = /mnt/SDCARD/Saves/CurrentProfile/saves
public = 1
guest only = 1
writable = 1
force create mode = 0666
force directory mode = 0777
available = 1

[Screenshots]
#alid users = onion
valid users = onion
path = /mnt/SDCARD/Screenshots
public = 1
guest only = 1
writable = 1
force create mode = 0666
force directory mode = 0777
available = 1

[Themes]
#alid users = onion
valid users = onion
path = /mnt/SDCARD/Themes
public = 1
guest only = 1
writable = 1
force create mode = 0666
force directory mode = 0777
available = 1

[Video filters]
#alid users = onion
valid users = onion
path = /mnt/SDCARD/RetroArch/.retroarch/filters/video
public = 1
guest only = 1
writable = 1
force create mode = 0666
force directory mode = 0777
available = 1

[__SDCARD]
#alid users = onion
valid users = onion
path = /mnt/SDCARD/
public = 0
guest only = 1
writable = 1
force create mode = 0666
force directory mode = 0777
Expand Down

0 comments on commit a506420

Please sign in to comment.