void handle_config_line(char *inbuf) { char *portnum, *state, *timeout, *devname, *devcfg, *comma; char *strtok_data = NULL; char *errstr; lineno++; if (working_longstr_continued) { char *str = strtok_r(inbuf, "\n", &strtok_data); if (!str) str = ""; handle_continued_longstr(str); return; } if (inbuf[0] == '#') { /* Ignore comments. */ return; } if (startswith(inbuf, "CONTROLPORT", &strtok_data)) { if (config_port) /* * The control port has already been configured either on the * command line or on a previous statement. Only take the first. */ return; config_port = strdup(strtok_r(NULL, "\n", &strtok_data)); if (!config_port) { syslog(LOG_ERR, "Could not allocate memory for CONTROLPORT"); return; } return; } if (startswith(inbuf, "BANNER", &strtok_data)) { char *name = strtok_r(NULL, ":", &strtok_data); char *str = strtok_r(NULL, "\n", &strtok_data); if (name == NULL) { syslog(LOG_ERR, "No banner name given on line %d", lineno); return; } handle_longstr(name, str, BANNER); return; } if (startswith(inbuf, "SIGNATURE", &strtok_data)) { char *name = strtok_r(NULL, ":", &strtok_data); char *str = strtok_r(NULL, "\n", &strtok_data); if (name == NULL) { syslog(LOG_ERR, "No signature given on line %d", lineno); return; } handle_longstr(name, str, SIGNATURE); return; } if (startswith(inbuf, "OPENSTR", &strtok_data)) { char *name = strtok_r(NULL, ":", &strtok_data); char *str = strtok_r(NULL, "\n", &strtok_data); if (name == NULL) { syslog(LOG_ERR, "No open string name given on line %d", lineno); return; } handle_longstr(name, str, OPENSTR); return; } if (startswith(inbuf, "CLOSESTR", &strtok_data)) { char *name = strtok_r(NULL, ":", &strtok_data); char *str = strtok_r(NULL, "\n", &strtok_data); if (name == NULL) { syslog(LOG_ERR, "No close string name given on line %d", lineno); return; } handle_longstr(name, str, CLOSESTR); return; } if (startswith(inbuf, "TRACEFILE", &strtok_data)) { char *name = strtok_r(NULL, ":", &strtok_data); char *str = strtok_r(NULL, "\n", &strtok_data); if (name == NULL) { syslog(LOG_ERR, "No tracefile name given on line %d", lineno); return; } if ((str == NULL) || (strlen(str) == 0)) { syslog(LOG_ERR, "No tracefile given on line %d", lineno); return; } handle_tracefile(name, str); return; } comma = strchr(inbuf, ','); if (comma) { if (!strtok_r(comma, ":", &strtok_data)) { syslog(LOG_ERR, "Invalid port on line %d", lineno); return; } portnum = inbuf; } else { portnum = strtok_r(inbuf, ":", &strtok_data); if (portnum == NULL) { /* An empty line is ok. */ return; } } state = strtok_r(NULL, ":", &strtok_data); if (state == NULL) { syslog(LOG_ERR, "No state given on line %d", lineno); return; } timeout = strtok_r(NULL, ":", &strtok_data); if (timeout == NULL) { syslog(LOG_ERR, "No timeout given on line %d", lineno); return; } devname = strtok_r(NULL, ":", &strtok_data); if (devname == NULL) { syslog(LOG_ERR, "No device name given on line %d", lineno); return; } devcfg = strtok_r(NULL, ":", &strtok_data); if (devcfg == NULL) { /* An empty device config is ok. */ devcfg = ""; } errstr = portconfig(portnum, state, timeout, devname, devcfg, config_num); if (errstr != NULL) { syslog(LOG_ERR, "Error on line %d, %s", lineno, errstr); } }
void handle_config_line(char *inbuf) { char *portnum, *state, *timeout, *devname, *devcfg; char *strtok_data; char *errstr; lineno++; if (banner_continued) { char *str = strtok_r(inbuf, "\n", &strtok_data); if (!str) str = ""; handle_continued_banner(str); return; } if (inbuf[0] == '#') { /* Ignore comments. */ return; } portnum = strtok_r(inbuf, ":", &strtok_data); if (portnum == NULL) { /* An empty line is ok. */ return; } if (strcmp(portnum, "BANNER") == 0) { char *name = strtok_r(NULL, ":", &strtok_data); char *str = strtok_r(NULL, "\n", &strtok_data); if (name == NULL) { syslog(LOG_ERR, "No banner name given on line %d", lineno); return; } handle_banner(name, str); return; } state = strtok_r(NULL, ":", &strtok_data); if (state == NULL) { syslog(LOG_ERR, "No state given on line %d", lineno); return; } timeout = strtok_r(NULL, ":", &strtok_data); if (timeout == NULL) { syslog(LOG_ERR, "No timeout given on line %d", lineno); return; } devname = strtok_r(NULL, ":", &strtok_data); if (devname == NULL) { syslog(LOG_ERR, "No device name given on line %d", lineno); return; } devcfg = strtok_r(NULL, ":", &strtok_data); if (devcfg == NULL) { /* An empty device config is ok. */ devcfg = ""; } errstr = portconfig(portnum, state, timeout, devname, devcfg, config_num); if (errstr != NULL) { syslog(LOG_ERR, "Error on line %d, %s", lineno, errstr); } }