| 91 | | debug(D_LOG_DEBUG, "Setting default config parameters"); |
| 92 | | config.configfile = (char *)malloc(255); |
| 93 | | strcpy(config.configfile, DEFAULT_CONFIGFILE); |
| 94 | | config.daemon = 1; |
| 95 | | config.debuglevel = DEFAULT_DEBUGLEVEL; |
| 96 | | config.httpdmaxconn = DEFAULT_HTTPDMAXCONN; |
| 97 | | config.gw_id = DEFAULT_GATEWAYID; |
| 98 | | config.gw_interface = NULL; |
| 99 | | config.gw_address = NULL; |
| 100 | | config.gw_port = DEFAULT_GATEWAYPORT; |
| 101 | | config.authserv_hostname = NULL; |
| 102 | | config.authserv_port = DEFAULT_AUTHSERVPORT; |
| 103 | | config.authserv_path = NULL; |
| 104 | | config.authserv_loginurl = NULL; |
| 105 | | config.httpdname = NULL; |
| 106 | | config.clienttimeout = DEFAULT_CLIENTTIMEOUT; |
| 107 | | config.checkinterval = DEFAULT_CHECKINTERVAL; |
| 108 | | config.fwscripts_path = DEFAULT_FWSCRIPTS_PATH; |
| 109 | | config.fwtype = DEFAULT_FWTYPE; |
| | 91 | debug(D_LOG_DEBUG, "Setting default config parameters"); |
| | 92 | config.configfile = (char *)malloc(255); |
| | 93 | strcpy(config.configfile, DEFAULT_CONFIGFILE); |
| | 94 | config.daemon = 1; |
| | 95 | config.debuglevel = DEFAULT_DEBUGLEVEL; |
| | 96 | config.httpdmaxconn = DEFAULT_HTTPDMAXCONN; |
| | 97 | config.gw_id = DEFAULT_GATEWAYID; |
| | 98 | config.gw_interface = NULL; |
| | 99 | config.gw_address = NULL; |
| | 100 | config.gw_port = DEFAULT_GATEWAYPORT; |
| | 101 | config.authserv_hostname = NULL; |
| | 102 | config.authserv_port = DEFAULT_AUTHSERVPORT; |
| | 103 | config.authserv_path = NULL; |
| | 104 | config.authserv_loginurl = NULL; |
| | 105 | config.httpdname = NULL; |
| | 106 | config.clienttimeout = DEFAULT_CLIENTTIMEOUT; |
| | 107 | config.checkinterval = DEFAULT_CHECKINTERVAL; |
| | 108 | config.fwscripts_path = DEFAULT_FWSCRIPTS_PATH; |
| | 109 | config.fwtype = DEFAULT_FWTYPE; |
| 128 | | FILE *fd; |
| 129 | | char line[MAX_BUF], *s, *p1, *p2; |
| 130 | | int linenum = 0, opcode, value; |
| 131 | | |
| 132 | | debug(D_LOG_INFO, "Reading configuration file '%s'", filename); |
| 133 | | |
| 134 | | if (!(fd = fopen(filename, "r"))) { |
| 135 | | debug(D_LOG_ERR, "Could not open configuration file '%s', exiting...", filename); |
| 136 | | exit(1); |
| 137 | | } |
| 138 | | |
| 139 | | while (!feof(fd) && fgets(line, MAX_BUF, fd)) { |
| 140 | | s = line; |
| 141 | | |
| 142 | | if (s[strlen(s) - 1] == '\n') |
| 143 | | s[strlen(s) - 1] = '\0'; |
| 144 | | |
| 145 | | if ((p1 = strchr(s, ' '))) { |
| 146 | | p1[0] = '\0'; |
| 147 | | } else if ((p1 = strchr(s, '\t'))) { |
| 148 | | p1[0] = '\0'; |
| 149 | | } |
| 150 | | |
| 151 | | if (p1) { |
| 152 | | p1++; |
| 153 | | |
| 154 | | if ((p2 = strchr(p1, ' '))) { |
| 155 | | p2[0] = '\0'; |
| 156 | | } else if ((p2 = strstr(p1, "\r\n"))) { |
| 157 | | p2[0] = '\0'; |
| 158 | | } else if ((p2 = strchr(p1, '\n'))) { |
| 159 | | p2[0] = '\0'; |
| 160 | | } |
| 161 | | } |
| 162 | | |
| 163 | | if (p1 && p1[0] != '\0') { |
| 164 | | /* Strip trailing spaces */ |
| 165 | | /* Strip tailing spaces */ |
| 166 | | |
| 167 | | if ((strncmp(s, "#", 1)) != 0) { |
| 168 | | debug(D_LOG_DEBUG, "Parsing token: %s, value: %s", s, p1); |
| 169 | | opcode = parse_token(s, filename, linenum); |
| 170 | | |
| 171 | | switch(opcode) { |
| 172 | | case oDaemon: |
| 173 | | if (((value = parse_value(p1)) != -1)) { |
| 174 | | config.daemon = value; |
| 175 | | } |
| 176 | | break; |
| 177 | | case oGatewayID: |
| 178 | | config.gw_id = get_string(p1); |
| 179 | | break; |
| 180 | | case oGatewayInterface: |
| 181 | | config.gw_interface = get_string(p1); |
| 182 | | break; |
| 183 | | case oGatewayAddress: |
| 184 | | config.gw_address = get_string(p1); |
| 185 | | break; |
| 186 | | case oGatewayPort: |
| 187 | | sscanf(p1, "%d", &config.gw_port); |
| 188 | | break; |
| 189 | | case oAuthservHostname: |
| 190 | | config.authserv_hostname = get_string(p1); |
| 191 | | break; |
| 192 | | case oHTTPDName: |
| 193 | | config.httpdname = get_string(p1); |
| 194 | | break; |
| 195 | | case oHTTPDMaxConn: |
| 196 | | sscanf(p1, "%d", &config.httpdmaxconn); |
| 197 | | break; |
| 198 | | case oAuthservPath: |
| 199 | | config.authserv_path = get_string(p1); |
| 200 | | break; |
| 201 | | case oAuthservLoginUrl: |
| 202 | | config.authserv_loginurl = get_string(p1); |
| 203 | | break; |
| 204 | | case oBadOption: |
| 205 | | exit(-1); |
| 206 | | break; |
| 207 | | case oCheckInterval: |
| 208 | | sscanf(p1, "%d", &config.checkinterval); |
| 209 | | break; |
| 210 | | case oClientTimeout: |
| 211 | | sscanf(p1, "%d", &config.clienttimeout); |
| 212 | | break; |
| 213 | | } |
| 214 | | } |
| 215 | | } |
| 216 | | } |
| 217 | | |
| 218 | | fclose(fd); |
| | 129 | FILE *fd; |
| | 130 | char line[MAX_BUF], *s, *p1, *p2; |
| | 131 | int linenum = 0, opcode, value; |
| | 132 | |
| | 133 | debug(D_LOG_INFO, "Reading configuration file '%s'", filename); |
| | 134 | |
| | 135 | if (!(fd = fopen(filename, "r"))) { |
| | 136 | debug(D_LOG_ERR, "Could not open configuration file '%s', " |
| | 137 | "exiting...", filename); |
| | 138 | exit(1); |
| | 139 | } |
| | 140 | |
| | 141 | while (!feof(fd) && fgets(line, MAX_BUF, fd)) { |
| | 142 | s = line; |
| | 143 | |
| | 144 | if (s[strlen(s) - 1] == '\n') |
| | 145 | s[strlen(s) - 1] = '\0'; |
| | 146 | |
| | 147 | if ((p1 = strchr(s, ' '))) { |
| | 148 | p1[0] = '\0'; |
| | 149 | } else if ((p1 = strchr(s, '\t'))) { |
| | 150 | p1[0] = '\0'; |
| | 151 | } |
| | 152 | |
| | 153 | if (p1) { |
| | 154 | p1++; |
| | 155 | |
| | 156 | if ((p2 = strchr(p1, ' '))) { |
| | 157 | p2[0] = '\0'; |
| | 158 | } else if ((p2 = strstr(p1, "\r\n"))) { |
| | 159 | p2[0] = '\0'; |
| | 160 | } else if ((p2 = strchr(p1, '\n'))) { |
| | 161 | p2[0] = '\0'; |
| | 162 | } |
| | 163 | } |
| | 164 | |
| | 165 | if (p1 && p1[0] != '\0') { |
| | 166 | /* Strip trailing spaces */ |
| | 167 | /* Strip tailing spaces */ |
| | 168 | |
| | 169 | if ((strncmp(s, "#", 1)) != 0) { |
| | 170 | debug(D_LOG_DEBUG, "Parsing token: %s, " |
| | 171 | "value: %s", s, p1); |
| | 172 | opcode = parse_token(s, filename, linenum); |
| | 173 | |
| | 174 | switch(opcode) { |
| | 175 | case oDaemon: |
| | 176 | if (((value = parse_value(p1)) != -1)) { |
| | 177 | config.daemon = value; |
| | 178 | } |
| | 179 | break; |
| | 180 | case oGatewayID: |
| | 181 | config.gw_id = get_string(p1); |
| | 182 | break; |
| | 183 | case oGatewayInterface: |
| | 184 | config.gw_interface = get_string(p1); |
| | 185 | break; |
| | 186 | case oGatewayAddress: |
| | 187 | config.gw_address = get_string(p1); |
| | 188 | break; |
| | 189 | case oGatewayPort: |
| | 190 | sscanf(p1, "%d", &config.gw_port); |
| | 191 | break; |
| | 192 | case oAuthservHostname: |
| | 193 | config.authserv_hostname = |
| | 194 | get_string(p1); |
| | 195 | break; |
| | 196 | case oHTTPDName: |
| | 197 | config.httpdname = get_string(p1); |
| | 198 | break; |
| | 199 | case oHTTPDMaxConn: |
| | 200 | sscanf(p1, "%d", &config.httpdmaxconn); |
| | 201 | break; |
| | 202 | case oAuthservPath: |
| | 203 | config.authserv_path = get_string(p1); |
| | 204 | break; |
| | 205 | case oAuthservLoginUrl: |
| | 206 | config.authserv_loginurl = |
| | 207 | get_string(p1); |
| | 208 | break; |
| | 209 | case oBadOption: |
| | 210 | exit(-1); |
| | 211 | break; |
| | 212 | case oCheckInterval: |
| | 213 | sscanf(p1, "%d", &config.checkinterval); |
| | 214 | break; |
| | 215 | case oClientTimeout: |
| | 216 | sscanf(p1, "%d", &config.clienttimeout); |
| | 217 | break; |
| | 218 | } |
| | 219 | } |
| | 220 | } |
| | 221 | } |
| | 222 | |
| | 223 | fclose(fd); |
| 254 | | config_notnull(config.gw_id, "GatewayID"); |
| 255 | | config_notnull(config.gw_interface, "GatewayInterface"); |
| 256 | | config_notnull(config.gw_address, "GatewayAddress"); |
| 257 | | config_notnull(config.authserv_hostname, "AuthservHostname"); |
| 258 | | config_notnull(config.authserv_path, "AuthservPath"); |
| 259 | | config_notnull(config.authserv_loginurl, "AuthservLoginUrl"); |
| 260 | | |
| 261 | | if (missing_parms) { |
| 262 | | debug(D_LOG_ERR, "Configuration is not complete, exiting..."); |
| 263 | | exit(-1); |
| 264 | | } |
| | 259 | config_notnull(config.gw_id, "GatewayID"); |
| | 260 | config_notnull(config.gw_interface, "GatewayInterface"); |
| | 261 | config_notnull(config.gw_address, "GatewayAddress"); |
| | 262 | config_notnull(config.authserv_hostname, "AuthservHostname"); |
| | 263 | config_notnull(config.authserv_path, "AuthservPath"); |
| | 264 | config_notnull(config.authserv_loginurl, "AuthservLoginUrl"); |
| | 265 | |
| | 266 | if (missing_parms) { |
| | 267 | debug(D_LOG_ERR, "Configuration is not complete, exiting..."); |
| | 268 | exit(-1); |
| | 269 | } |