Project

General

Profile

Bug #5539

Changing SAT-IP Server Parameters with tvheadend running non-root causes server to bind to another port

Added by Flole Systems about 2 years ago. Updated about 2 years ago.

Status:
Fixed
Priority:
Normal
Assignee:
-
Category:
-
Target version:
-
Start date:
2019-02-13
Due date:
% Done:

100%

Estimated time:
Found in version:
4.3-1752~g797af7c78
Affected Versions:

Description

I am using the SAT-IP Server on Port 554, now when I change some parameters in the Webinterface and save it, the server reinitializes and tries to bind to port 554 again, which it can't cause it no longer has root permissions and falls back to another port then.

In the logs it looks like this:

satips: RTSP port 554 specified but no root perms, using 9983
satips: SAT>IP Server reinitialized

There should at least be some kind of warning in the webinterface if this happened. Or even better don't have the server close and re-open the port if that's somehow possible.

Associated revisions

Revision 6edc4dab (diff)
Added by Flole Systems about 2 years ago

Prevent rebinding when refreshing SAT-IP Server settings and not changing port, fixes #5539

Revision dae84676 (diff)
Added by Flole Systems about 2 years ago

Prevent rebinding when refreshing SAT-IP Server settings and not changing port, fixes #5539

History

#1

Updated by saen acro about 2 years ago

In Linux, and other UNIX-like systems, 
you have to be root (have superuser privileges) 
in order to listen to TCP or UDP ports below 1024.

https://stackoverflow.com/questions/413807/is-there-a-way-for-non-root-processes-to-bind-to-privileged-ports-on-linux

#2

Updated by Flole Systems about 2 years ago

Thats not the issue here though, tvheadend had root when it bound to that port, then it dropped the privileges. On configuration change it closed the port though, and as it's no longer root its unable to open it again.

#3

Updated by Flole Systems about 2 years ago

When I look at the code in rtsp.c it seems like everything is already setup for the kind of behavior I expected:

 if (rtsp_port != port && rtsp_server) {
    rtsp_close_sessions();
    tcp_server_delete(rtsp_server);
    rtsp_server = NULL;
    reg = 1;
  }

it seems like it's only

static void satips_rtsp_port(int def)
{
  int rtsp_port = satip_server_rtsp_port;
  if (!satip_server_rtsp_port_locked)
    rtsp_port = satip_server_conf.satip_rtsp > 0 ? satip_server_conf.satip_rtsp : def;
  if (getuid() != 0 && rtsp_port > 0 && rtsp_port < 1024) {
    tvherror(LS_SATIPS, "RTSP port %d specified but no root perms, using 9983", rtsp_port);
    rtsp_port = 9983;
  }
  satip_server_rtsp_port = rtsp_port;

}

that is preventing this from working properly, as it doesn't differentiate between already bound and not already bound.

#4

Updated by Flole Systems about 2 years ago

Proposed patch, works very well for me:

--- src/satip/server.c
+++ src/satip/server.c
@@ -36,6 +36,7 @@
 static int satip_server_rtsp_port_locked;
 static upnp_service_t *satips_upnp_discovery;
 static tvh_mutex_t satip_server_reinit;
+static int bound_port;

 static void satip_server_save(void);

@@ -556,7 +557,7 @@
   int rtsp_port = satip_server_rtsp_port;
   if (!satip_server_rtsp_port_locked)
     rtsp_port = satip_server_conf.satip_rtsp > 0 ? satip_server_conf.satip_rtsp : def;
-  if (getuid() != 0 && rtsp_port > 0 && rtsp_port < 1024) {
+  if (getuid() != 0 && rtsp_port > 0 && rtsp_port < 1024 && bound_port != rtsp_port) {
     tvherror(LS_SATIPS, "RTSP port %d specified but no root perms, using 9983", rtsp_port);
     rtsp_port = 9983;
   }
@@ -995,6 +996,7 @@
   nat_ip = strdup(satip_server_conf.satip_nat_ip ?: "");
   nat_port = satip_server_conf.satip_nat_rtsp ?: satip_server_rtsp_port;
   rtp_src_ip = strdup(satip_server_conf.satip_rtp_src_ip ?: "");
+  bound_port = satip_server_rtsp_port;

   if (announce)
     tvh_mutex_unlock(&global_lock);
#5

Updated by Flole Systems about 2 years ago

  • Status changed from New to Fixed
  • % Done changed from 0 to 100

Also available in: Atom PDF