1 ///////////////////////////////////////////////////////////////////////
2 // Copyright (C) 2006 Jari Korhonen. jarit1.korhonen@dnainternet.net.
3 // All Rights Reserved.
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
18 // USA.
19 //
20 //
21 // If the source code for the program is not available from the place
22 // from which you received this file, check
23 // http://koti.mbnet.fi/jtko
24 //
25 //////////////////////////////////////////////////////////////////////
26
27
28 #include <stdio.h>
29 #include <string.h>
30 #include <stdlib.h>
31
32 #include "openbsd_stringfuncs.h"
33 #include "iniparser.h"
34 #include "commondefines.h"
35 #include "repeaterutil.h"
36
37 //Ports where we listen
38 int viewerPort = 5900;
39 int serverPort = 5500;
40
41 //Repeater allowed modes
42 //CONN_MODE1 = Only Mode 1,
43 //CONN_MODE2 = Only Mode 2,
44 //(CONN_MODE1 | CONN_MODE2) = Both modes
45 int allowedModes = (CONN_MODE1 | CONN_MODE2);
46
47 //In mode 1, what server port we can connect() to.
48 //0=All ports
49 int allowedMode1ServerPort = 0;
50
51 //In mode 2, require listed IDs ? (0=Allow all IDs, 1=Require that ID number is in the list)
52 int requireListedId = 0;
53
54 //In Mode 2 (in case allowOnlyListedIds == 1) what IDs are allowed ?
55 //0 here does not match anything
56 int idList[ID_LIST_SIZE] = {
57 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
58 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
59 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
60 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
61 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
62 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
63 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
64 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
65 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
66 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
67
68 //if running as root, by default change to this user after all listen ports have been bound
69 char runAsUser[MY_TMP_BUF_LEN] = "uvncrep";
70
71 //if we have several ip addresses, we can choose one to listen on
72 //by default, listen on all addresses
73 char ownIpAddress[MY_TMP_BUF_LEN] = "0.0.0.0";
74
75 //In mode 1, do we require server addresses/ranges listed in ini file ?
76 //0=Allow all server addresses, 1=Only allow addresses/ranges defined in ini file
77 int requireListedServer = 0;
78
79 //Mode 1 allowed servers (255.255.255.255 = Not allowed)
80 addrParts srvListAllow[SERVERS_LIST_SIZE] = {
81 {255,255,255,255},{255,255,255,255},{255,255,255,255},{255,255,255,255},{255,255,255,255},\
82 {255,255,255,255},{255,255,255,255},{255,255,255,255},{255,255,255,255},{255,255,255,255},\
83 {255,255,255,255},{255,255,255,255},{255,255,255,255},{255,255,255,255},{255,255,255,255},\
84 {255,255,255,255},{255,255,255,255},{255,255,255,255},{255,255,255,255},{255,255,255,255},\
85 {255,255,255,255},{255,255,255,255},{255,255,255,255},{255,255,255,255},{255,255,255,255},\
86 {255,255,255,255},{255,255,255,255},{255,255,255,255},{255,255,255,255},{255,255,255,255},\
87 {255,255,255,255},{255,255,255,255},{255,255,255,255},{255,255,255,255},{255,255,255,255},\
88 {255,255,255,255},{255,255,255,255},{255,255,255,255},{255,255,255,255},{255,255,255,255},\
89 {255,255,255,255},{255,255,255,255},{255,255,255,255},{255,255,255,255},{255,255,255,255},\
90 {255,255,255,255},{255,255,255,255},{255,255,255,255},{255,255,255,255},{255,255,255,255}};
91
92 //Mode 1 denied servers (255.255.255.255 = Not denied)
93 addrParts srvListDeny[SERVERS_LIST_SIZE] = {
94 {255,255,255,255},{255,255,255,255},{255,255,255,255},{255,255,255,255},{255,255,255,255},\
95 {255,255,255,255},{255,255,255,255},{255,255,255,255},{255,255,255,255},{255,255,255,255},\
96 {255,255,255,255},{255,255,255,255},{255,255,255,255},{255,255,255,255},{255,255,255,255},\
97 {255,255,255,255},{255,255,255,255},{255,255,255,255},{255,255,255,255},{255,255,255,255},\
98 {255,255,255,255},{255,255,255,255},{255,255,255,255},{255,255,255,255},{255,255,255,255},\
99 {255,255,255,255},{255,255,255,255},{255,255,255,255},{255,255,255,255},{255,255,255,255},\
100 {255,255,255,255},{255,255,255,255},{255,255,255,255},{255,255,255,255},{255,255,255,255},\
101 {255,255,255,255},{255,255,255,255},{255,255,255,255},{255,255,255,255},{255,255,255,255},\
102 {255,255,255,255},{255,255,255,255},{255,255,255,255},{255,255,255,255},{255,255,255,255},\
103 {255,255,255,255},{255,255,255,255},{255,255,255,255},{255,255,255,255},{255,255,255,255}};
104
105
106 //How many active sessions we can have ?
107 int maxSessions = MAX_SESSIONS_DEFAULT;
108
109
110 //Logging level
111 int loggingLevel = DEFAULT_LOGGING_LEVEL;
112
113 //Use event interface ?
114 bool useEventInterface = false;
115
116 //EventListener hostname/ip address and port/http usage
117 char eventListenerHost[MY_TMP_BUF_LEN] = "localhost";
118 int eventListenerPort = 2002;
119 bool useHttpForEventListener = false;
120
readIniFile(char * iniFilePathAndName)121 bool readIniFile(char *iniFilePathAndName)
122 {
123 dictionary *dict;
124 int ii;
125 char tmpBuf[MY_TMP_BUF_LEN];
126 char tmpBuf2[MY_TMP_BUF_LEN];
127
128 dict = iniparser_new(iniFilePathAndName);
129
130 if (dict != NULL) {
131 //General settings
132 //General settings
133 viewerPort = iniparser_getint(dict, "general:viewerport", 5900);
134 serverPort = iniparser_getint(dict, "general:serverport", 5500);
135
136 maxSessions = iniparser_getint(dict, "general:maxsessions", MAX_SESSIONS_DEFAULT);
137 if (maxSessions > MAX_SESSIONS_MAX)
138 maxSessions = MAX_SESSIONS_DEFAULT;
139 if (maxSessions < MAX_SESSIONS_MIN)
140 maxSessions = MAX_SESSIONS_DEFAULT;
141
142 allowedModes = iniparser_getint(dict, "general:allowedmodes", (CONN_MODE1 | CONN_MODE2));
143
144 strlcpy(ownIpAddress, iniparser_getstring(dict, "general:ownipaddress", "0.0.0.0"), MY_TMP_BUF_LEN);
145
146 strlcpy(runAsUser, iniparser_getstring(dict, "general:runasuser", "uvncrep"), MY_TMP_BUF_LEN);
147
148 loggingLevel = iniparser_getint(dict, "general:logginglevel", DEFAULT_LOGGING_LEVEL);
149 if (loggingLevel > LEVEL_3)
150 loggingLevel = DEFAULT_LOGGING_LEVEL;
151 if (loggingLevel < LEVEL_0)
152 loggingLevel = DEFAULT_LOGGING_LEVEL;
153
154
155 //Mode 1 settings
156 //Mode 1 settings
157 allowedMode1ServerPort = iniparser_getint(dict, "mode1:allowedmode1serverport", 0);
158 requireListedServer = iniparser_getint(dict, "mode1:requirelistedserver", 0);
159 if (requireListedServer == 1) {
160 //Allowed servers
161 for(ii = 0; ii < SERVERS_LIST_SIZE; ii++) {
162 snprintf(tmpBuf, MY_TMP_BUF_LEN, "%s%d", "mode1:srvListAllow", ii);
163
164 strlcpy(tmpBuf2, iniparser_getstring(dict, tmpBuf, "255.255.255.255"), MY_TMP_BUF_LEN);
165
166 srvListAllow[ii] = getAddrPartsFromString(tmpBuf2);
167 }
168
169
170 //Denied servers
171 for(ii = 0; ii < SERVERS_LIST_SIZE; ii++) {
172 snprintf(tmpBuf, MY_TMP_BUF_LEN, "%s%d", "mode1:srvListDeny", ii);
173
174 strlcpy(tmpBuf2, iniparser_getstring(dict, tmpBuf, "255.255.255.255"), MY_TMP_BUF_LEN);
175
176 srvListDeny[ii] = getAddrPartsFromString(tmpBuf2);
177 }
178 }
179
180
181 //Mode 2 settings
182 //Mode 2 settings
183 requireListedId = iniparser_getint(dict, "mode2:requirelistedid", 0);
184 if (requireListedId == 1) {
185 for(ii = 0; ii < ID_LIST_SIZE; ii++) {
186 snprintf(tmpBuf, MY_TMP_BUF_LEN, "%s%d", "mode2:idlist", ii);
187 idList[ii] = iniparser_getint(dict, tmpBuf, 0);
188 }
189 }
190
191 //Event interface settings
192 //Event interface settings
193 useEventInterface = (bool) iniparser_getboolean(dict, "eventinterface:useeventinterface", 0);
194
195 strlcpy(eventListenerHost, iniparser_getstring(dict,
196 "eventinterface:eventlistenerhost", "localhost"), MY_TMP_BUF_LEN);
197
198 eventListenerPort = iniparser_getint(dict, "eventinterface:eventlistenerport", 2002);
199
200 useHttpForEventListener = (bool) iniparser_getboolean(dict,"eventinterface:usehttp", 0);
201
202 iniparser_free(dict);
203 return true;
204 }
205 else
206 return false;
207
208 return true;
209 }
210