Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#81 fix config parsing #83

Merged
merged 2 commits into from
Nov 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion smf-spf.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ static sfsistat smf_envrcpt(SMFICTX *, char **);
static sfsistat smf_header(SMFICTX *, char *, char *);
static sfsistat smf_eom(SMFICTX *);
static sfsistat smf_close(SMFICTX *);
static char * trim_space(char *str);

static void log_init() {
if ( conf.syslog_facility != SYSLOG_DISABLE)
Expand Down Expand Up @@ -466,11 +467,13 @@ static int load_config(void) {
while (fgets(buf, sizeof(buf) - 1, fp)) {
char key[MAXLINE];
char val[MAXLINE];
char value[MAXLINE];
char *p = NULL;

if ((p = strchr(buf, '#'))) *p = '\0';
if (!(strlen(buf))) continue;
if (sscanf(buf, "%127s %127s", key, val) != 2) continue;
if (sscanf(buf, "%127s %[^\n]s", key, value) != 2) continue;
strcpy(val , trim_space(value));
if (!strcasecmp(key, "whitelistip")) {
char *slash = NULL;
unsigned short int mask = 32;
Expand Down Expand Up @@ -758,7 +761,19 @@ static int to_check(const char *to) {
}
return 0;
}
static char * trim_space(char *str) {
char *end;
while (isspace(*str)) { // skip leading whitespace
str = str + 1;
}
end = str + strlen(str) - 1;
while (end > str && isspace(*end)) { // remove trailing whitespace
end = end - 1;
}

*(end+1) = '\0'; // write null character*/
return str;
}
// LCOV_EXCL_START
static void die(const char *reason) {

Expand Down
2 changes: 1 addition & 1 deletion tests/conf/smf-spf-tests-fixedip-fail.conf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
WhitelistIP 192.168.0.0/16
relaxedlocalpart on
tagsubject off
RejectReason "Rejeitado"
RejectReason Rejected - Please configure your SPF record
User nobody
Socket inet:2424@127.0.0.1
Syslog mail # (daemon|mail|local0...local7)
Expand Down