GUAC-847: Handle parse errors in callback. Actually parse config file.
This commit is contained in:
parent
318bcff5b5
commit
4f5760af94
@ -40,8 +40,67 @@
|
||||
* errors as necessary.
|
||||
*/
|
||||
static int guacd_conf_callback(const char* section, const char* param, const char* value, void* data) {
|
||||
fprintf(stderr, "%s: %s: %s\n", section, param, value);
|
||||
return 0;
|
||||
|
||||
guacd_config* config = (guacd_config*) data;
|
||||
|
||||
/* Network server options */
|
||||
if (strcmp(section, "server") == 0) {
|
||||
|
||||
/* Bind host */
|
||||
if (strcmp(param, "bind_host") == 0) {
|
||||
free(config->bind_host);
|
||||
config->bind_host = strdup(value);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Bind port */
|
||||
else if (strcmp(param, "bind_port") == 0) {
|
||||
free(config->bind_port);
|
||||
config->bind_port = strdup(value);
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* Options related to daemon startup */
|
||||
else if (strcmp(section, "daemon") == 0) {
|
||||
|
||||
/* PID file */
|
||||
if (strcmp(param, "pid_file") == 0) {
|
||||
free(config->pidfile);
|
||||
config->pidfile = strdup(value);
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* SSL-specific options */
|
||||
else if (strcmp(section, "ssl") == 0) {
|
||||
#ifdef ENABLE_SSL
|
||||
/* SSL certificate */
|
||||
if (strcmp(param, "server_certificate") == 0) {
|
||||
free(config->cert_file);
|
||||
config->cert_file = strdup(value);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* SSL key */
|
||||
else if (strcmp(param, "server_key") == 0) {
|
||||
free(config->key_file);
|
||||
config->key_file = strdup(value);
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
guacd_conf_parse_error = "SSL support not compiled in";
|
||||
return 1;
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
/* If still unhandled, the parameter/section is invalid */
|
||||
guacd_conf_parse_error = "Invalid parameter or section name";
|
||||
return 1;
|
||||
|
||||
}
|
||||
|
||||
int guacd_conf_parse_file(guacd_config* conf, int fd) {
|
||||
|
@ -261,6 +261,8 @@ static int guacd_parse_parameter(guacd_param_callback* callback, char* buffer, i
|
||||
int retval;
|
||||
int chars_read = 0;
|
||||
|
||||
char* param_start = buffer;
|
||||
|
||||
retval = guacd_parse_name(buffer, length, param_name);
|
||||
if (retval < 0)
|
||||
return -1;
|
||||
@ -316,8 +318,10 @@ static int guacd_parse_parameter(guacd_param_callback* callback, char* buffer, i
|
||||
chars_read += retval;
|
||||
|
||||
/* Call callback, handling error code */
|
||||
if (callback(__guacd_current_section, param_name, param_value, data))
|
||||
if (callback(__guacd_current_section, param_name, param_value, data)) {
|
||||
guacd_conf_parse_error_location = param_start;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return chars_read;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user