From 20b85c03e751b4876fa3c92040464e483172b746 Mon Sep 17 00:00:00 2001 From: Jannis Hoffmann Date: Wed, 3 Jul 2024 19:03:11 +0200 Subject: manual format adjustment --- src/newaliases.c | 77 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 38 insertions(+), 39 deletions(-) (limited to 'src/newaliases.c') diff --git a/src/newaliases.c b/src/newaliases.c index 08106a4..c48f354 100644 --- a/src/newaliases.c +++ b/src/newaliases.c @@ -23,22 +23,27 @@ void nomem() { logmsg(WHO, 111, FATAL, "out of memory"); } + void nulbyte() { logmsg(WHO, 100, FATAL, "NUL bytes are not permitted"); } + void longaddress() { logmsg(WHO, 100, FATAL, "addresses over 800 bytes are not permitted"); } + void writeerr() { logmsg(WHO, 111, FATAL, "unable to write to /etc/aliases.tmp"); } + void readerr() { logmsg(WHO, 111, FATAL, "unable to read /etc/aliases"); } + void die_control() { logmsg(WHO, 111, FATAL, "unable to read controls"); @@ -61,23 +66,19 @@ void readcontrols() r = control_readline(&me, "control/me"); if (r == -1) die_control(); - if (!r) - if (!stralloc_copys(&me, "me")) nomem(); + if (!r && !stralloc_copys(&me, "me")) nomem(); r = control_readline(&defaultdomain, "control/defaultdomain"); if (r == -1) die_control(); - if (!r) - if (!stralloc_copy(&defaultdomain, &me)) nomem(); + if (!r && !stralloc_copy(&defaultdomain, &me)) nomem(); r = control_readline(&defaulthost, "control/defaulthost"); if (r == -1) die_control(); - if (!r) - if (!stralloc_copy(&defaulthost, &me)) nomem(); + if (!r && !stralloc_copy(&defaulthost, &me)) nomem(); r = control_readline(&plusdomain, "control/plusdomain"); if (r == -1) die_control(); - if (!r) - if (!stralloc_copy(&plusdomain, &me)) nomem(); + if (!r && !stralloc_copy(&plusdomain, &me)) nomem(); if (fchdir(fddir) == -1) logmsg(WHO, 111, FATAL, "unable to set current directory"); } @@ -127,21 +128,20 @@ void gotaddr() if (!address.len) return; - if (!flaghasat) + if (!flaghasat) { if (address.s[0] == '/') { if (!stralloc_0(&address)) nomem(); logmsg(WHO, 111, FATAL, B("file delivery for ", address.s, " not supported")); } - if (!flaghasat) - if (address.s[0] == '|') { - if (byte_chr(address.s, address.len, '\0') < address.len) - logmsg(WHO, 111, FATAL, "NUL not permitted in program names"); - if (!stralloc_cats(&instr, "!")) nomem(); - if (!stralloc_catb(&instr, address.s + 1, address.len - 1)) nomem(); - if (!stralloc_0(&instr)) nomem(); - return; - } - + } + if (!flaghasat && address.s[0] == '|') { + if (byte_chr(address.s, address.len, '\0') < address.len) + logmsg(WHO, 111, FATAL, "NUL not permitted in program names"); + if (!stralloc_cats(&instr, "!")) nomem(); + if (!stralloc_catb(&instr, address.s + 1, address.len - 1)) nomem(); + if (!stralloc_0(&instr)) nomem(); + return; + } if (target.len) { if (!stralloc_cats(&instr, "&")) nomem(); @@ -205,18 +205,16 @@ void parseline() if (!token822_readyplus(&tokaddr, 1)) nomem(); tokaddr.len = 0; - while (t > beginning) switch ((--t)->type) - { + while (t > beginning) { + switch ((--t)->type) { case TOKEN822_SEMI: break; /*XXX*/ case TOKEN822_COLON: - if (t >= beginning + 2) - if (t[-2].type == TOKEN822_COLON) - if (t[-1].type == TOKEN822_ATOM) - if (t[-1].slen == 7) - if (!byte_diff(t[-1].s, 7, "include")) { - gotincl(); - t -= 2; - } + if (t >= beginning + 2 && t[-2].type == TOKEN822_COLON && t[-1].type == TOKEN822_ATOM + && t[-1].slen == 7 && !byte_diff(t[-1].s, 7, "include")) + { + gotincl(); + t -= 2; + } break; /*XXX*/ case TOKEN822_RIGHT: if (tokaddr.len) gotaddr(); @@ -229,14 +227,15 @@ void parseline() && ((t[-1].type == TOKEN822_COMMENT) || (t[-1].type == TOKEN822_ATOM) || (t[-1].type == TOKEN822_QUOTE) || (t[-1].type == TOKEN822_AT) || (t[-1].type == TOKEN822_DOT))) + { --t; + } wordok = 0; continue; case TOKEN822_ATOM: case TOKEN822_QUOTE: case TOKEN822_LITERAL: - if (!wordok) - if (tokaddr.len) gotaddr(); + if (!wordok && tokaddr.len) gotaddr(); wordok = 0; if (!token822_append(&tokaddr, t)) nomem(); continue; @@ -252,6 +251,7 @@ void parseline() if (!token822_append(&tokaddr, t)) nomem(); continue; } + } if (tokaddr.len) gotaddr(); } @@ -309,14 +309,13 @@ int main() continue; } - if (line.len) - if (line.s[0] != '#') { - if (!stralloc_copys(&target, "")) nomem(); - if (!stralloc_copys(&fulltarget, "")) nomem(); - if (!stralloc_copys(&instr, "")) nomem(); - parseline(); - doit(); - } + if (line.len && line.s[0] != '#') { + if (!stralloc_copys(&target, "")) nomem(); + if (!stralloc_copys(&fulltarget, "")) nomem(); + if (!stralloc_copys(&instr, "")) nomem(); + parseline(); + doit(); + } if (!match) break; if (!stralloc_copy(&line, &newline)) nomem(); -- cgit v1.2.3