Merge pull request #98 from adufray/patch-1
authorFelix Morgner <felix.morgner@gmail.com>
Thu, 26 Jan 2017 12:39:44 +0000 (13:39 +0100)
committerFelix Morgner <felix.morgner@gmail.com>
Thu, 26 Jan 2017 12:39:44 +0000 (13:39 +0100)
README.md
src/conf.c
src/conf.h
src/main.c
src/messagehandler.c
umurmur.conf.example

index e037d599b9e61f9e4566ed998238df10271e9d01..707a4798b2dce019f06b29d2104c15a9ff1760e3 100644 (file)
--- a/README.md
+++ b/README.md
@@ -19,6 +19,7 @@ Contributors
 * [fmorgner](https://github.com/fmorgner)
 * [Rawi666](https://github.com/Rawi666)
 * [snowblind](https://github.com/snowblind)
+* [c4k3](https://github.com/C4K3)
 
 Hope I didn't forget anyone... Please just send me a mail if you feel this is the case.
 
index bf21d99bb84cbe41f00caad5d82d34b07a789505..725aab6ab19bfe550ce27eb8890e0992c03dc080 100644 (file)
@@ -252,7 +252,10 @@ int getIntConf(param_t param)
                case BINDPORT6:
                        setting = config_lookup(&configuration, "bindport6");
                        if (!setting)
-                               return DEFAULT_BINDPORT;
+                               /* If bindport6 is not specified, we default
+                                * to whatever bindport is, rather than always
+                                * default to 64738 */
+                               return getIntConf(BINDPORT);
                        else {
                                return config_setting_get_int(setting);
                        }
@@ -320,6 +323,13 @@ bool_t getBoolConf(param_t param)
                        else
                                return config_setting_get_bool(setting);
                        break;
+               case SHOW_ADDRESSES:
+                       setting = config_lookup(&configuration, "show_addresses");
+                       if (!setting)
+                               return true;
+                       else
+                               return config_setting_get_bool(setting);
+                       break;
                default:
                        doAssert(false);
        }
index 9a9591c22f2c3ff553265699506b24a98adfa539..5f028d0e4debc0b635858fb6dc937f34bdfa23c4 100644 (file)
@@ -57,6 +57,7 @@ typedef enum param {
        BANFILE,
        SYNC_BANFILE,
        OPUS_THRESHOLD,
+       SHOW_ADDRESSES,
 } param_t;
 
 typedef struct {
index a18363dd721bc579bdbcd842e295d4c8b0223132..c74d9646bd71f168ee29627019a76da272ca61ba 100644 (file)
@@ -322,16 +322,25 @@ int main(int argc, char **argv)
                        Log_init(false);
                        if (pidfile != NULL)
                                lockfile(pidfile);
+#ifdef POSIX_PRIORITY_SCHEDULING
+                       /* Set the scheduling policy, has to be called after daemonizing
+                        * but before we drop privileges */
+                       if (realtime)
+                               setscheduler();
+#endif
 
-                       switch_user();
-
-                       /* Reopen log file. If user switch results in access denied, we catch
-                        * it early.
-                        */
-                       Log_reset();
                }
                else Log_init(true);
 
+#ifdef POSIX_PRIORITY_SCHEDULING
+               /* We still want to set scheduling policy if nodaemon is specified,
+                * but if we are daemonizing setscheduler() will be called above */
+               if (nodaemon) {
+                       if (realtime)
+                               setscheduler();
+               }
+#endif
+
                signal(SIGCHLD, SIG_IGN); /* ignore child */
                signal(SIGTSTP, SIG_IGN); /* ignore tty signals */
                signal(SIGTTOU, SIG_IGN);
@@ -360,10 +369,15 @@ int main(int argc, char **argv)
     Sharedmemory_init( bindport, bindport6 );
 #endif
 
-#ifdef POSIX_PRIORITY_SCHEDULING
-               if (realtime)
-                       setscheduler();
-#endif
+               if(!nodaemon) {
+                       /* SSL and scheduling is setup, we can drop privileges now */
+                       switch_user();
+
+                       /* Reopen log file. If user switch results in access denied, we catch
+                        * it early.
+                        */
+                       Log_reset();
+               }
 
                Server_run();
 
index a8472871ae86f38ad5c391266eedb2053c11e974..c9dad4a57b6858515cce1a42039617bf7e368c8b 100644 (file)
@@ -870,17 +870,21 @@ void Mh_handle_message(client_t *client, message_t *msg)
                        sendmsg->payload.userStats->opus = target->bOpus;
 
                        /* Address */
-                       sendmsg->payload.userStats->has_address = true;
-                       sendmsg->payload.userStats->address.data
-                               = Memory_safeMalloc(16, sizeof(uint8_t));
-                       memset(sendmsg->payload.userStats->address.data, 0, 16);
-                       /* ipv4 representation as ipv6 address. Supposedly correct. */
-                       memset(&sendmsg->payload.userStats->address.data[10], 0xff, 2); /* IPv4 */
-      if(target->remote_tcp.ss_family == AF_INET)
-        memcpy(&sendmsg->payload.userStats->address.data[12], &((struct sockaddr_in*)&target->remote_tcp)->sin_addr, 4);
-      else
-        memcpy(&sendmsg->payload.userStats->address.data[0], &((struct sockaddr_in6*)&target->remote_tcp)->sin6_addr, 16);
-                       sendmsg->payload.userStats->address.len = 16;
+                       if (getBoolConf(SHOW_ADDRESSES)) {
+                               sendmsg->payload.userStats->has_address = true;
+                               sendmsg->payload.userStats->address.data
+                                       = Memory_safeMalloc(16, sizeof(uint8_t));
+                               memset(sendmsg->payload.userStats->address.data, 0, 16);
+                               /* ipv4 representation as ipv6 address. Supposedly correct. */
+                               memset(&sendmsg->payload.userStats->address.data[10], 0xff, 2); /* IPv4 */
+                               if(target->remote_tcp.ss_family == AF_INET)
+                                       memcpy(&sendmsg->payload.userStats->address.data[12], &((struct sockaddr_in*)&target->remote_tcp)->sin_addr, 4);
+                               else
+                                       memcpy(&sendmsg->payload.userStats->address.data[0], &((struct sockaddr_in6*)&target->remote_tcp)->sin6_addr, 16);
+                               sendmsg->payload.userStats->address.len = 16;
+                       } else {
+                               sendmsg->payload.userStats->has_address = false;
+                       }
                }
                /* BW */
                sendmsg->payload.userStats->has_bandwidth = true;
index 8dbc18b3e5bb2a4097b7bbe4a81d64ebc5f9bb7c..1c32a7887016942a8c89472bcddf9bf7f31415c1 100644 (file)
@@ -10,6 +10,7 @@ password = "";
 # sync_banfile = false;      # Keep banfile synced. Default is false, which means it is saved to at shutdown only.
 # allow_textmessage = true;  # Default is true
 # opus_threshold = 100;      # Percentage of users supporting Opus codec for it to be chosen. Default is 100.
+# show_addresses = true;     # Whether to show client's IP addresses under user information
 max_users = 10;
 
 # bindport = 64738;