diff options
author | Jannis Hoffmann <jannis@fehcom.de> | 2024-07-03 19:03:11 +0200 |
---|---|---|
committer | Jannis Hoffmann <jannis@fehcom.de> | 2024-07-03 19:03:11 +0200 |
commit | 20b85c03e751b4876fa3c92040464e483172b746 (patch) | |
tree | 734fadbfdbc143ec4465093857f4c239448715e0 /src | |
parent | a6a7d6ce079cabdaf2fa502b2e2cf15e5428ac6f (diff) |
manual format adjustment
Diffstat (limited to 'src')
104 files changed, 1275 insertions, 1017 deletions
diff --git a/src/chkspawn.c b/src/chkspawn.c index 2023a9e..0760ff4 100644 --- a/src/chkspawn.c +++ b/src/chkspawn.c @@ -34,14 +34,14 @@ int main() buffer_put(buffer_2, num, fmt_ulong(num, hiddenlimit)); buffer_puts( buffer_2, - " descriptors.\n\ -This means that the qmail daemons could crash if you set the run-time\n\ -concurrency higher than "); + " descriptors.\n" + "This means that the qmail daemons could crash if you set the run-time\n" + "concurrency higher than "); buffer_put(buffer_2, num, fmt_ulong(num, maxnumd)); buffer_puts( buffer_2, - ". So I'm going to insist that the concurrency\n\ -limit in conf-spawn be at most "); + ". So I'm going to insist that the concurrency\n" + "limit in conf-spawn be at most "); buffer_put(buffer_2, num, fmt_ulong(num, maxnumd)); buffer_puts(buffer_2, ". Right now it's "); buffer_put(buffer_2, num, fmt_ulong(num, (unsigned long)auto_spawn)); diff --git a/src/columnt.c b/src/columnt.c index 638c078..d02b7ed 100644 --- a/src/columnt.c +++ b/src/columnt.c @@ -31,10 +31,7 @@ stralloc file = {0}; int *width; int maxfield = 0; -void nothing() -{ - ; -} +void nothing() {} void printline() { diff --git a/src/commands.c b/src/commands.c index 8cb81de..24d6c0d 100644 --- a/src/commands.c +++ b/src/commands.c @@ -23,8 +23,7 @@ int commands(buffer *b, struct commands *c) ++cmd.len; } - if (cmd.len > 0) - if (cmd.s[cmd.len - 1] == '\r') --cmd.len; + if (cmd.len > 0 && cmd.s[cmd.len - 1] == '\r') --cmd.len; cmd.s[cmd.len] = 0; diff --git a/src/constmap.c b/src/constmap.c index decc42e..72b8d79 100644 --- a/src/constmap.c +++ b/src/constmap.c @@ -3,6 +3,7 @@ #include "alloc.h" #include "case.h" + static constmap_hash hash(char *s, int len) { unsigned char ch; @@ -104,9 +105,7 @@ int constmap_init_char(struct constmap *cm, char *s, int len, int flagcolon, cha int pos; constmap_hash h; - if (!flagchar || flagchar == 0 || flagchar == '\0') { - flagchar = ':'; - } + if (!flagchar || flagchar == 0 || flagchar == '\0') flagchar = ':'; cm->num = 0; for (j = 0; j < len; ++j) diff --git a/src/control.c b/src/control.c index a40030d..d595c0f 100644 --- a/src/control.c +++ b/src/control.c @@ -11,6 +11,7 @@ #include "scan.h" #include "stralloc.h" + static char inbuf[2048]; static stralloc line = {0}; static stralloc me = {0}; @@ -21,13 +22,14 @@ static int meok = 0; static void striptrailingwhitespace(stralloc *sa) { - while (sa->len > 0) switch (sa->s[sa->len - 1]) - { + while (sa->len > 0) { + switch (sa->s[sa->len - 1]) { case '\n': case ' ': case '\t': --sa->len; break; default: return; } + } } int control_init(void) @@ -45,8 +47,7 @@ int control_rldef(stralloc *sa, char *fn, int flagme, char *def) r = control_readline(sa, fn); if (r) return r; - if (flagme) - if (meok) return stralloc_copy(sa, &me) ? 1 : -1; + if (flagme && meok) return stralloc_copy(sa, &me) ? 1 : -1; if (def) return stralloc_copys(sa, def) ? 1 : -1; return r; } diff --git a/src/date822fmt.c b/src/date822fmt.c index 7e0333a..93456b4 100644 --- a/src/date822fmt.c +++ b/src/date822fmt.c @@ -4,6 +4,7 @@ #include "datetime.h" + static char *montab[12] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; @@ -13,39 +14,51 @@ unsigned int date822fmt(char *s, struct datetime *dt) unsigned int len; len = 0; + i = fmt_uint(s, dt->mday); len += i; if (s) s += i; + i = fmt_str(s, " "); len += i; if (s) s += i; + i = fmt_str(s, montab[dt->mon]); len += i; if (s) s += i; + i = fmt_str(s, " "); len += i; if (s) s += i; + i = fmt_uint(s, dt->year + 1900); len += i; if (s) s += i; + i = fmt_str(s, " "); len += i; if (s) s += i; + i = fmt_uint0(s, dt->hour, 2); len += i; if (s) s += i; + i = fmt_str(s, ":"); len += i; if (s) s += i; + i = fmt_uint0(s, dt->min, 2); len += i; if (s) s += i; + i = fmt_str(s, ":"); len += i; if (s) s += i; + i = fmt_uint0(s, dt->sec, 2); len += i; if (s) s += i; + i = fmt_str(s, " -0000\n"); len += i; if (s) s += i; diff --git a/src/datetime.c b/src/datetime.c index 5f5d9bf..4b4cdbc 100644 --- a/src/datetime.c +++ b/src/datetime.c @@ -1,6 +1,6 @@ -/* 19950925 */ #include "datetime.h" + void datetime_tai(struct datetime *dt, datetime_sec t) { int day; diff --git a/src/datetime_un.c b/src/datetime_un.c index f8d24f2..5211642 100644 --- a/src/datetime_un.c +++ b/src/datetime_un.c @@ -1,7 +1,7 @@ #include "datetime.h" -/* roughly 100x faster than mktime() */ +/* roughly 100x faster than mktime() */ datetime_sec datetime_untai(struct datetime *dt) { int year; diff --git a/src/dkim.cpp b/src/dkim.cpp index 1ce8eee..8f07519 100644 --- a/src/dkim.cpp +++ b/src/dkim.cpp @@ -26,7 +26,9 @@ #include "dkimsign.h" #include "dkimverify.h" + #define DKIMID ('D' | 'K' << 8 | 'I' << 16 | 'M' << 24) + /* taken from removed file "ressource.h" */ #ifdef VERSION #define VERSION_STRING VERSION @@ -34,6 +36,7 @@ #define VERSION_STRING "1.4.0" #endif + static void InitContext(DKIMContext *pContext, bool bSign, void *pObject) { pContext->reserved1 = DKIMID; @@ -61,9 +64,7 @@ int DKIM_CALL DKIMSignInit(DKIMContext *pSignContext, DKIMSignOptions *pOptions) if (nRet != DKIM_SUCCESS) delete pSign; } - if (nRet == DKIM_SUCCESS) { - InitContext(pSignContext, true, pSign); - } + if (nRet == DKIM_SUCCESS) InitContext(pSignContext, true, pSign); return nRet; } @@ -71,9 +72,7 @@ int DKIM_CALL DKIMSignProcess(DKIMContext *pSignContext, char *szBuffer, int nBu { CDKIMSign *pSign = (CDKIMSign *)ValidateContext(pSignContext, true); - if (pSign) { - return pSign->Process(szBuffer, nBufLength, false); - } + if (pSign) return pSign->Process(szBuffer, nBufLength, false); return DKIM_INVALID_CONTEXT; } @@ -82,9 +81,7 @@ int DKIM_CALL DKIMSignGetSig2( { CDKIMSign *pSign = (CDKIMSign *)ValidateContext(pSignContext, true); - if (pSign) { - return pSign->GetSig2(szRSAPrivKey, szECCPrivKey, pszSignature); - } + if (pSign) return pSign->GetSig2(szRSAPrivKey, szECCPrivKey, pszSignature); return DKIM_INVALID_CONTEXT; } @@ -109,9 +106,7 @@ int DKIM_CALL DKIMVerifyInit(DKIMContext *pVerifyContext, DKIMVerifyOptions *pOp if (nRet != DKIM_SUCCESS) delete pVerify; } - if (nRet == DKIM_SUCCESS) { - InitContext(pVerifyContext, false, pVerify); - } + if (nRet == DKIM_SUCCESS) InitContext(pVerifyContext, false, pVerify); return nRet; } @@ -121,9 +116,7 @@ int DKIM_CALL DKIMVerifyProcess(DKIMContext *pVerifyContext, const char *const s { CDKIMVerify *pVerify = (CDKIMVerify *)ValidateContext(pVerifyContext, false); - if (pVerify) { - return pVerify->Process(szBuffer, nBufLength, false); - } + if (pVerify) return pVerify->Process(szBuffer, nBufLength, false); return DKIM_INVALID_CONTEXT; } @@ -132,9 +125,7 @@ int DKIM_CALL DKIMVerifyResults(DKIMContext *pVerifyContext) { CDKIMVerify *pVerify = (CDKIMVerify *)ValidateContext(pVerifyContext, false); - if (pVerify) { - return pVerify->GetResults(); - } + if (pVerify) return pVerify->GetResults(); return DKIM_INVALID_CONTEXT; } diff --git a/src/dkimbase.cpp b/src/dkimbase.cpp index c27e767..0361d8e 100644 --- a/src/dkimbase.cpp +++ b/src/dkimbase.cpp @@ -1,19 +1,19 @@ /***************************************************************************** -* Copyright 2005 Alt-N Technologies, Ltd. +* Copyright 2005 Alt-N Technologies, Ltd. * -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at * -* http://www.apache.org/licenses/LICENSE-2.0 +* http://www.apache.org/licenses/LICENSE-2.0 * -* This code incorporates intellectual property owned by Yahoo! and licensed +* This code incorporates intellectual property owned by Yahoo! and licensed * pursuant to the Yahoo! DomainKeys Patent License Agreement. * -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and * limitations under the License. * * Changes done by ¢feh@fehcom.de obeying the above license @@ -28,18 +28,17 @@ #include "dkim.h" -CDKIMBase::CDKIMBase() -{ - m_From = NULL; - m_Sender = NULL; - m_hTag = NULL; - m_hTagSize = 0; - m_hTagPos = 0; - m_Line = NULL; - m_LineSize = 0; - m_LinePos = 0; - m_InHeaders = true; -} +CDKIMBase::CDKIMBase() : + m_From(nullptr), + m_Sender(nullptr), + m_hTag(nullptr), + m_hTagSize(0), + m_hTagPos(0), + m_Line(nullptr), + m_LineSize(0), + m_LinePos(0), + m_InHeaders(true) +{} CDKIMBase::~CDKIMBase() // delete { @@ -168,9 +167,7 @@ int CDKIMBase::Process(const char *szBuffer, int nBufLength, bool bEOF) //////////////////////////////////////////////////////////////////////////////// int CDKIMBase::ProcessFinal(void) { - if (m_LinePos > 0) { - Process("\r\n", 2, true); - } + if (m_LinePos > 0) Process("\r\n", 2, true); if (m_InHeaders) { m_InHeaders = false; diff --git a/src/dkimsign.cpp b/src/dkimsign.cpp index 8be3fc6..fbdc001 100644 --- a/src/dkimsign.cpp +++ b/src/dkimsign.cpp @@ -20,11 +20,6 @@ * *****************************************************************************/ -#define _strnicmp strncasecmp -#define _stricmp strcasecmp -#define LOWORD(l) ((unsigned)(l) & 0xffff) -#define HIWORD(l) ((unsigned)(l) >> 16) - #include "dkimsign.h" #include <string.h> @@ -33,6 +28,11 @@ #include "dkim.h" +#define _strnicmp strncasecmp +#define _stricmp strcasecmp +#define LOWORD(l) ((unsigned)(l) & 0xffff) +#define HIWORD(l) ((unsigned)(l) >> 16) + /***************************************************************************** * * Generating Ed25519 signed message: @@ -52,16 +52,16 @@ * 3. Public keys * The 'public keys' need to be deployed in the DNS: * - The RSA public key is DER-header enriched base64-encoded; thus is 9 byte larger -* than the 'naked' public key, which size depends on the given parameters. +* than the 'naked' public key, which size depends on the given parameters. * - The Ed25519 public key is also base64-encoded with a constant length of 60 byte. * -* 4. DKIM message preparation scheme +* 4. DKIM message preparation scheme * According to RFC 6376 Sec. 3.7, we have a conducted hash for -* - the previously available headers in the message; +* - the previously available headers in the message; * selected and given in order by h=..., * - any existing DKIM signature fields b=..., * - except for previous added 'X-Authentication ...' header fields, -* - and all (new) synthezised DKIM header tokens; except of course for the +* - and all (new) synthezised DKIM header tokens; except of course for the * signature itself - treated as 'null string': b="". * All this is subject of canonicalization (adding/removing CRLF, whitespaces ...). + As a result, the input for further calculations depends on this order given. @@ -75,13 +75,13 @@ * 5. Generating (ECC) signatures * According to RFC 8032 Sect 4., we have two possible Ed25519 signature schemes: * -* a) PureEd25519, as a one shot signature calculation swallowing the +* a) PureEd25519, as a one shot signature calculation swallowing the * complete message and employing a shortened SHA-512 hash input. -* b) HashEd25519 working again in 'streaming mode' and permitting a choice +* b) HashEd25519 working again in 'streaming mode' and permitting a choice * for the hash function - which is in RFC 8463 - defined to be SHA-256. * * RFC 8463 in Sect 3 is a bit ambiguous about the signing function: -* Ed25519-256 vs. PureEd25519. +* Ed25519-256 vs. PureEd25519. * In fact (after consulting John Levine), it is PureEd25519. * * In order to allow parallel RSA/Ed25519 processing, we need to generate: @@ -98,7 +98,7 @@ * having a length of 512 bits => 64 bytes. * * 6. Hybrid signatures (RSA and Ed25519) -* They involve +* They involve * m_Hdr_sha256ctx => Used for RSA signatures * m_Hdr_ed25519ctx => PureED25519 signature * m_Bdy_sha256ctx => SHA256 digest of the message (BodyHash) for RSA @@ -110,10 +110,10 @@ * * ------ * -* The particular function and variable names chosen here do not obviously match -* what they are intended to do. However, in order to keep traceablility of the +* The particular function and variable names chosen here do not obviously match +* what they are intended to do. However, in order to keep traceablility of the * changes, I left those untouched. -* +* *****************************************************************************/ CDKIMSign::CDKIMSign() @@ -218,7 +218,7 @@ int CDKIMSign::Init(DKIMSignOptions *pOptions) m_sCopiedHeaders.erase(); // Initializes ED25519 header fields SigHdrs -#if ((OPENSSL_VERSION_NUMBER > 0x10101000L)) +#if (OPENSSL_VERSION_NUMBER > 0x10101000L) SigHdrs.assign(""); m_SigHdrs = 0; #endif @@ -350,12 +350,8 @@ bool ConvertHeaderToQuotedPrintable(const char *source, char *dest) void CDKIMSign::GetHeaderParams(const string& sHdr) { if (_strnicmp(sHdr.c_str(), "X", 1) == 0) return; - if (_strnicmp(sHdr.c_str(), "From:", 5) == 0) { - sFrom.assign(sHdr.c_str() + 5); - } - if (_strnicmp(sHdr.c_str(), "Sender:", 7) == 0) { - sSender.assign(sHdr.c_str() + 7); - } + if (_strnicmp(sHdr.c_str(), "From:", 5) == 0) sFrom.assign(sHdr.c_str() + 5); + if (_strnicmp(sHdr.c_str(), "Sender:", 7) == 0) sSender.assign(sHdr.c_str() + 7); if (m_nIncludeCopiedHeaders) { string::size_type pos = sHdr.find(':'); @@ -368,9 +364,7 @@ void CDKIMSign::GetHeaderParams(const string& sHdr) sValue.assign(sHdr.substr(pos + 1, string::npos)); ConvertHeaderToQuotedPrintable(sTag.c_str(), workBuffer); - if (!m_sCopiedHeaders.empty()) { - m_sCopiedHeaders.append("|"); - } + if (!m_sCopiedHeaders.empty()) m_sCopiedHeaders.append("|"); m_sCopiedHeaders.append(workBuffer); m_sCopiedHeaders.append(":"); ConvertHeaderToQuotedPrintable(sValue.c_str(), workBuffer); @@ -546,8 +540,9 @@ int CDKIMSign::ProcessBody(char *szBuffer, int nBufLength, bool bEOF) Hash("\r\n", 2, false); m_nBodyLength += 2; } - } else + } else { m_EmptyLineCount++; + } break; } @@ -695,9 +690,7 @@ void CDKIMSign::AddFoldedValueToSig(const string& sValue, char cbrk) if (brkpos == string::npos || brkpos < pos) { brkpos = sValue.find(cbrk, pos); - if (brkpos == string::npos) { - brkpos = sValue.size(); - } + if (brkpos == string::npos) brkpos = sValue.size(); } len = brkpos - pos + 1; @@ -723,13 +716,9 @@ void CDKIMSign::AddFoldedValueToSig(const string& sValue, char cbrk) //////////////////////////////////////////////////////////////////////////////// int CDKIMSign::GetSig2(char *szRSAKey, char *szECCKey, char **pszSignature) { - if (szRSAKey == NULL && szECCKey == NULL) { - return DKIM_BAD_PRIVATE_KEY; - } + if (szRSAKey == NULL && szECCKey == NULL) return DKIM_BAD_PRIVATE_KEY; - if (pszSignature == NULL) { - return DKIM_BUFFER_TOO_SMALL; - } + if (pszSignature == NULL) return DKIM_BUFFER_TOO_SMALL; int nRet = AssembleReturnedSig(szRSAKey, szECCKey); @@ -815,28 +804,18 @@ int CDKIMSign::ConstructSignature(char *szPrivKey, int nSigAlg) AddTagToSig("s", eSelector, 0, false); else AddTagToSig("s", sSelector, 0, false); - if (m_IncludeBodyLengthTag) { - AddTagToSig("l", m_nBodyLength); - } + if (m_IncludeBodyLengthTag) AddTagToSig("l", m_nBodyLength); if (m_nIncludeTimeStamp != 0) { time_t t; time(&t); AddTagToSig("t", t); } - if (m_ExpireTime != 0) { - AddTagToSig("x", m_ExpireTime); - } - if (!sIdentity.empty()) { - AddTagToSig("i", sIdentity, 0, false); - } - if (m_nIncludeQueryMethod) { - AddTagToSig("q", "dns/txt", 0, false); - } + if (m_ExpireTime != 0) AddTagToSig("x", m_ExpireTime); + if (!sIdentity.empty()) AddTagToSig("i", sIdentity, 0, false); + if (m_nIncludeQueryMethod) AddTagToSig("q", "dns/txt", 0, false); AddTagToSig("h", hParam, ':', true); // copied headers follow the ':' - if (m_nIncludeCopiedHeaders) { - AddTagToSig("z", m_sCopiedHeaders, 0, true); - } + if (m_nIncludeCopiedHeaders) AddTagToSig("z", m_sCopiedHeaders, 0, true); /* Set up context for (body) hash */ @@ -962,9 +941,7 @@ int CDKIMSign::ConstructSignature(char *szPrivKey, int nSigAlg) pkey = PEM_read_bio_PrivateKey(bio, NULL, NULL, NULL); // FIXME - done BIO_free(bio); - if (!pkey) { - return DKIM_BAD_PRIVATE_KEY; - } + if (!pkey) return DKIM_BAD_PRIVATE_KEY; siglen = EVP_PKEY_size(pkey); sig = (unsigned char *)OPENSSL_malloc(siglen); @@ -1018,9 +995,7 @@ int CDKIMSign::ConstructSignature(char *szPrivKey, int nSigAlg) } bio = BIO_new(BIO_s_mem()); - if (!bio) { - return DKIM_OUT_OF_MEMORY; - } + if (!bio) return DKIM_OUT_OF_MEMORY; b64 = BIO_new(BIO_f_base64()); if (!b64) { @@ -1078,9 +1053,7 @@ int CDKIMSign::AssembleReturnedSig(char *szRSAKey, char *szECCKey) ProcessFinal(); - if (ParseFromAddress() == false) { - return DKIM_NO_SENDER; - } + if (ParseFromAddress() == false) return DKIM_NO_SENDER; string ed25519Sig, sha256Sig, sha1Sig; @@ -1113,8 +1086,8 @@ int CDKIMSign::AssembleReturnedSig(char *szRSAKey, char *szECCKey) } } - // fclose(fpdebug); - // fpdebug = NULL; + // fclose(fpdebug); + // fpdebug = NULL; if (!ed25519Sig.empty()) { /* if (!m_sReturnedSig.empty()) { @@ -1125,16 +1098,12 @@ int CDKIMSign::AssembleReturnedSig(char *szRSAKey, char *szECCKey) } if (!sha1Sig.empty()) { - if (!m_sReturnedSig.empty()) { - m_sReturnedSig.append("\r\n"); - } + if (!m_sReturnedSig.empty()) m_sReturnedSig.append("\r\n"); m_sReturnedSig.append(sha1Sig); } if (!sha256Sig.empty()) { - if (!m_sReturnedSig.empty()) { - m_sReturnedSig.append("\r\n"); - } + if (!m_sReturnedSig.empty()) m_sReturnedSig.append("\r\n"); m_sReturnedSig.append(sha256Sig); } diff --git a/src/dkimverify.cpp b/src/dkimverify.cpp index 6693d8e..334e1b4 100644 --- a/src/dkimverify.cpp +++ b/src/dkimverify.cpp @@ -1,23 +1,24 @@ /***************************************************************************** * -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at * -* http://www.apache.org/licenses/LICENSE-2.0 +* http://www.apache.org/licenses/LICENSE-2.0 * -* This code incorporates intellectual property owned by Yahoo! and licensed +* This code incorporates intellectual property owned by Yahoo! and licensed * pursuant to the Yahoo! DomainKeys Patent License Agreement. * -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and * limitations under the License. * * Changes done by ¢feh@fehcom.de obeying the above license * *****************************************************************************/ + #include "dkimverify.h" #include <assert.h> @@ -29,6 +30,7 @@ #include "dkim.h" #include "dnsgettxt.h" + extern "C" { #include "stralloc.h" @@ -44,10 +46,10 @@ extern "C" { * a) The 'body hash' => bh=[sha1|sha256] * b) The signature => b=[RSA-SHA1|RSA-SHA256|PureEd25519] * -* Several DKIM headers (=signatures) may be present in the email. +* Several DKIM headers (=signatures) may be present in the email. * Here, it is limited to max. Shall we really evaluate all? * -* Caution: Using hybrid signatures, calling the destructor will core dump +* Caution: Using hybrid signatures, calling the destructor will core dump * given EVP_MD_CTX_free() upon the next call of EVP_DigestInit. * Using the destructor with EVP_MD_CTX_reset() however works. * @@ -55,8 +57,8 @@ extern "C" { #define _strnicmp strncasecmp #define _stricmp strcasecmp -#define MAX_SIGNATURES 10 // maximum number of DKIM signatures to process/message -#define FDLOG stderr /* writing to another FD requires a method */ +#define MAX_SIGNATURES 10 // maximum number of DKIM signatures to process/message +#define FDLOG stderr // writing to another FD requires a method string SigHdr; size_t m_SigHdr; @@ -309,13 +311,13 @@ bool ParseTagValueList(char *tagvaluelist, const char *wanted[], char *values[]) //////////////////////////////////////////////////////////////////////////////// char Tohex(char ch) { - if (ch >= '0' && ch <= '9') + if (ch >= '0' && ch <= '9') { return (ch - '0'); - else if (ch >= 'A' && ch <= 'F') + } else if (ch >= 'A' && ch <= 'F') { return (ch - 'A' + 10); - else if (ch >= 'a' && ch <= 'f') + } else if (ch >= 'a' && ch <= 'f') { return (ch - 'a' + 10); - else { + } else { assert(0); return 0; } @@ -350,18 +352,18 @@ void DecodeQuotedPrintable(char *ptr) //////////////////////////////////////////////////////////////////////////////// unsigned DecodeBase64(char *ptr) { + // clang-format off static const char base64_table[256] = { - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63, - 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, - 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, - -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, - 49, 50, 51, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}; + -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, + -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,62,-1,-1,-1,63,52,53,54,55,56,57,58,59,60,61,-1,-1,-1,-1,-1,-1, + -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,-1,-1,-1,-1,-1, + -1,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,-1,-1,-1,-1,-1, + -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, + -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, + -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, + -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, + }; + // clang-format on unsigned char *s = (unsigned char *)ptr; unsigned char *d = (unsigned char *)ptr; @@ -1194,9 +1196,7 @@ SelectorInfo::SelectorInfo(const string& sSelector, const string& sDomain) : SelectorInfo::~SelectorInfo() { - if (PublicKey != NULL) { - EVP_PKEY_free(PublicKey); - } + if (PublicKey != NULL) EVP_PKEY_free(PublicKey); } //////////////////////////////////////////////////////////////////////////////// @@ -1373,8 +1373,9 @@ SelectorInfo& CDKIMVerify::GetSelector(const string& sSelector, const string& sD if (m_pfnSelectorCallback) { DNSResult = m_pfnSelectorCallback(sFQDN.c_str(), Buffer, BufLen); - } else + } else { DNSResult = _DNSGetTXT(sFQDN.c_str(), Buffer, BufLen); + } // Buffer++; BufLen--; @@ -22,8 +22,8 @@ #include "ipalloc.h" /** - @file dns.c - @brief DNS helpers: dns_ipplus, dns_ipalloc, dns_ip (IPv4+IPv6), dns_mxip + * @file dns.c + * @brief DNS helpers: dns_ipplus, dns_ipalloc, dns_ip (IPv4+IPv6), dns_mxip */ static stralloc glue = {0}; diff --git a/src/dns_tlsa.c b/src/dns_tlsa.c index 52f7d83..612c6b3 100644 --- a/src/dns_tlsa.c +++ b/src/dns_tlsa.c @@ -30,11 +30,12 @@ int dns_tlsa_packet(stralloc *out, const char *buf, unsigned int len) pos = dns_packet_copy(buf, len, pos, header, 10); if (!pos) return DNS_ERR; uint16_unpack_big(header + 8, &datalen); - if (byte_equal(header, 2, DNS_T_TLSA)) + if (byte_equal(header, 2, DNS_T_TLSA)) { if (byte_equal(header + 2, 2, DNS_C_IN)) { if (pos + datalen > len) return DNS_ERR; if (!stralloc_catb(out, buf + pos, datalen)) return DNS_MEM; } + } pos += datalen; ++ranswers; } diff --git a/src/dnsfq.c b/src/dnsfq.c index 65c49fe..751e909 100644 --- a/src/dnsfq.c +++ b/src/dnsfq.c @@ -38,8 +38,9 @@ int main(int argc, char **argv) buffer_puts(buffer_1, "-> "); buffer_put(buffer_1, sa.s, sa.len); buffer_puts(buffer_1, " "); - } else + } else { break; + } } buffer_putsflush(buffer_1, "\n"); diff --git a/src/dnsip.c b/src/dnsip.c index bbb2557..d6e3c0d 100644 --- a/src/dnsip.c +++ b/src/dnsip.c @@ -28,18 +28,20 @@ int main(int argc, char **argv) if (!stralloc_copys(&sa, argv[1])) logmsg(WHO, 111, FATAL, "out of memory"); DNS_INIT - if (dns_ip6(&out, &sa) > 0) /* IPv6 first */ + if (dns_ip6(&out, &sa) > 0) { /* IPv6 first */ for (i = 0; i + 16 <= out.len; i += 16) { if (ip6_isv4mapped(out.s + i)) continue; buffer_put(buffer_1, ip6str, ip6_fmt(ip6str, out.s + i)); buffer_puts(buffer_1, "\n"); } + } - if (dns_ip4(&out, &sa) > 0) + if (dns_ip4(&out, &sa) > 0) { for (i = 0; i + 4 <= out.len; i += 4) { buffer_put(buffer_1, ip4str, ip4_fmt(ip4str, out.s + i)); buffer_puts(buffer_1, "\n"); } + } buffer_putsflush(buffer_1, ""); _exit(0); diff --git a/src/dnstlsa.c b/src/dnstlsa.c index 284f7d1..715bde1 100644 --- a/src/dnstlsa.c +++ b/src/dnstlsa.c @@ -52,8 +52,9 @@ int main(int argc, char **argv) DNS_INIT if (dns_cname(&cn, &sa) > 0) { if ((r = dns_tlsa(&out, &cn)) < 0) _exit(1); - } else if ((r = dns_tlsa(&out, &sa)) < 0) + } else if ((r = dns_tlsa(&out, &sa)) < 0) { _exit(1); + } if (!stralloc_0(&sa)) logmsg(WHO, 111, FATAL, "out of memory"); if (verbose) logmsg(WHO, 0, INFO, B("checking for TLSA records: ", sa.s, "\n")); @@ -76,7 +77,7 @@ int main(int argc, char **argv) if (type == 2) buffer_puts(buffer_1, "Type: [2] "); // sha512 /* Staff of Ra - "(is) six kadams high." However, the builder (h)as + "(is) six kadams high." However, the builder (h)as to subtract one kadam out of respect for the Hebrew God. */ for (j = i + 3, k = 0; j <= out.len; ++j) { diff --git a/src/fastforward.c b/src/fastforward.c index a702d41..731ada8 100644 --- a/src/fastforward.c +++ b/src/fastforward.c @@ -95,7 +95,7 @@ void dofile(char *fn) if (readclose_append(fd, &mailinglist, 1024) == -1) logmsg(WHO, 111, FATAL, B("unable to read: ", fn)); i = 0; - for (j = 0; j < mailinglist.len; ++j) + for (j = 0; j < mailinglist.len; ++j) { if (!mailinglist.s[j]) { if ((mailinglist.s[i] == '.') || (mailinglist.s[i] == '/')) { if (!stralloc_cats(&todo, mailinglist.s + i)) nomem(); @@ -106,6 +106,7 @@ void dofile(char *fn) } i = j + 1; } + } } char *fncdb; @@ -227,11 +228,11 @@ void dodata() int j; i = 0; - for (j = 0; j < data.len; ++j) + for (j = 0; j < data.len; ++j) { if (!data.s[j]) { - if ((data.s[i] == '|') || (data.s[i] == '!')) + if ((data.s[i] == '|') || (data.s[i] == '!')) { doprogram(data.s + i); - else if ((data.s[i] == '.') || (data.s[i] == '/')) { + } else if ((data.s[i] == '.') || (data.s[i] == '/')) { if (!stralloc_cats(&todo, data.s + i)) nomem(); if (!stralloc_0(&todo)) nomem(); } else if ((data.s[i] == '&') && (j - i < 900)) { @@ -240,16 +241,18 @@ void dodata() } i = j + 1; } + } } void dorecip(char *addr) { - if (!findtarget(0, "?", addr)) + if (!findtarget(0, "?", addr)) { if (gettarget(0, ":", addr)) { dodata(); return; } + } if (!stralloc_cats(&forward, addr)) nomem(); if (!stralloc_0(&forward)) nomem(); } @@ -260,11 +263,12 @@ void doorigrecip(char *addr) if ((sender.len != 4) || byte_diff(sender.s, 4, "#@[]")) if (gettarget(1, "?", addr)) if (!stralloc_copy(&sender, &data)) nomem(); - if (!gettarget(1, ":", addr)) + if (!gettarget(1, ":", addr)) { if (flagpassthrough) _exit(0); else logmsg(WHO, 100, ERROR, "Sorry, no mailbox here by that name. (#5.1.1)"); + } dodata(); } @@ -289,8 +293,8 @@ int main(int argc, char **argv) if (!stralloc_copys(&forward, "")) nomem(); if (!strset_init(&done)) nomem(); - while ((opt = getopt(argc, argv, "nNpPdD")) != opteof) switch (opt) - { + while ((opt = getopt(argc, argv, "nNpPdD")) != opteof) { + switch (opt) { case 'n': flagdeliver = 0; break; case 'N': flagdeliver = 1; break; case 'p': flagpassthrough = 1; break; @@ -299,6 +303,7 @@ int main(int argc, char **argv) case 'D': flagdefault = 0; break; default: usage(); } + } argv += optind; fncdb = *argv; diff --git a/src/headerbody.c b/src/headerbody.c index 4173824..58458cf 100644 --- a/src/headerbody.c +++ b/src/headerbody.c @@ -70,10 +70,11 @@ void (*dobl)(); flaglineok = 1; } - for (;;) switch (getsa(b, &nextline, &match)) - { + for (;;) { + switch (getsa(b, &nextline, &match)) { case -1: return -1; case 0: return 0; case 1: dobl(&nextline); } + } } diff --git a/src/include/date822fmt.h b/src/include/date822fmt.h index fc721a0..44a26e8 100644 --- a/src/include/date822fmt.h +++ b/src/include/date822fmt.h @@ -1,6 +1,8 @@ #ifndef DATE822FMT_H #define DATE822FMT_H +#include "datetime.h" + unsigned int date822fmt(char *, struct datetime *); #define DATE822FMT 60 diff --git a/src/include/dkim.h b/src/include/dkim.h index dd2a70d..27c3b73 100644 --- a/src/include/dkim.h +++ b/src/include/dkim.h @@ -1,19 +1,19 @@ /***************************************************************************** -* Copyright 2005 Alt-N Technologies, Ltd. +* Copyright 2005 Alt-N Technologies, Ltd. * -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at * -* http://www.apache.org/licenses/LICENSE-2.0 +* http://www.apache.org/licenses/LICENSE-2.0 * -* This code incorporates intellectual property owned by Yahoo! and licensed +* This code incorporates intellectual property owned by Yahoo! and licensed * pursuant to the Yahoo! DomainKeys Patent License Agreement. * -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and * limitations under the License. * * Changes done by ¢feh@fehcom.de obeying the above license @@ -43,8 +43,9 @@ extern "C" { #define DKIM_SIGN_RELAXED MAKELONG(DKIM_CANON_RELAXED, DKIM_CANON_RELAXED) #define DKIM_SIGN_RELAXED_SIMPLE MAKELONG(DKIM_CANON_SIMPLE, DKIM_CANON_RELAXED) +// clang-format off // DKIM Error codes -#define DKIM_SUCCESS 0 // operation successful +#define DKIM_SUCCESS 0 // operation successful #define DKIM_FAIL -1 // verify error: message is suspicious #define DKIM_BAD_SYNTAX -2 // signature error: DKIM-Signature could not parse or has bad tags/values #define DKIM_SIGNATURE_BAD -3 // signature error: RSA/ED25519 verify failed @@ -53,40 +54,37 @@ extern "C" { #define DKIM_SELECTOR_INVALID -6 // signature error: selector doesn't parse or contains invalid values #define DKIM_SELECTOR_GRANULARITY_MISMATCH -7 // signature error: selector g= doesn't match i= #define DKIM_SELECTOR_KEY_REVOKED -8 // signature error: selector p= empty -#define DKIM_SELECTOR_DOMAIN_NAME_TOO_LONG \ - -9 // signature error: selector domain name too long to request -#define DKIM_SELECTOR_DNS_TEMP_FAILURE -10 // signature error: temporary dns failure requesting selector -#define DKIM_SELECTOR_DNS_PERM_FAILURE -11 // signature error: permanent dns failure requesting selector -#define DKIM_SELECTOR_PUBLIC_KEY_INVALID \ - -12 // signature error: selector p= value invalid or wrong format -#define DKIM_NO_SIGNATURES -13 // process error, no sigs -#define DKIM_NO_VALID_SIGNATURES -14 // process error, no valid sigs -#define DKIM_BODY_HASH_MISMATCH -15 // sigature verify error: message body does not hash to bh value -#define DKIM_SELECTOR_ALGORITHM_MISMATCH -16 // signature error: selector h= doesn't match signature a= -#define DKIM_STAT_INCOMPAT -17 // signature error: incompatible v= -#define DKIM_UNSIGNED_FROM -18 // signature error: not all message's From headers in signature -#define DKIM_OUT_OF_MEMORY -20 // memory allocation failed -#define DKIM_INVALID_CONTEXT -21 // DKIMContext structure invalid for this operation -#define DKIM_NO_SENDER -22 // signing error: Could not find From: or Sender: header in message -#define DKIM_BAD_PRIVATE_KEY -23 // signing error: Could not parse private key -#define DKIM_BUFFER_TOO_SMALL -24 // signing error: Buffer passed in is not large enough -#define DKIM_MAX_ERROR -25 // set this to 1 greater than the highest error code (but negative) - -// DKIM_SUCCESS // verify result: all signatures verified +#define DKIM_SELECTOR_DOMAIN_NAME_TOO_LONG -9 // signature error: selector domain name too long to request +#define DKIM_SELECTOR_DNS_TEMP_FAILURE -10 // signature error: temporary dns failure requesting selector +#define DKIM_SELECTOR_DNS_PERM_FAILURE -11 // signature error: permanent dns failure requesting selector +#define DKIM_SELECTOR_PUBLIC_KEY_INVALID -12 // signature error: selector p= value invalid or wrong format +#define DKIM_NO_SIGNATURES -13 // process error, no sigs +#define DKIM_NO_VALID_SIGNATURES -14 // process error, no valid sigs +#define DKIM_BODY_HASH_MISMATCH -15 // sigature verify error: message body does not hash to bh value +#define DKIM_SELECTOR_ALGORITHM_MISMATCH -16 // signature error: selector h= doesn't match signature a= +#define DKIM_STAT_INCOMPAT -17 // signature error: incompatible v= +#define DKIM_UNSIGNED_FROM -18 // signature error: not all message's From headers in signature +#define DKIM_OUT_OF_MEMORY -20 // memory allocation failed +#define DKIM_INVALID_CONTEXT -21 // DKIMContext structure invalid for this operation +#define DKIM_NO_SENDER -22 // signing error: Could not find From: or Sender: header in message +#define DKIM_BAD_PRIVATE_KEY -23 // signing error: Could not parse private key +#define DKIM_BUFFER_TOO_SMALL -24 // signing error: Buffer passed in is not large enough +#define DKIM_MAX_ERROR -25 // set this to 1 greater than the highest error code (but negative) + +// DKIM_SUCCESS // verify result: all signatures verified // signature result: signature verified -#define DKIM_FINISHED_BODY 1 // process result: no more message body is needed -#define DKIM_PARTIAL_SUCCESS 2 // verify result: at least one but not all signatures verified -#define DKIM_NEUTRAL 3 // verify result: no signatures verified but message is not suspicous -#define DKIM_SUCCESS_BUT_EXTRA \ - 4 // signature result: signature verified but it did not include all of the body - +#define DKIM_FINISHED_BODY 1 // process result: no more message body is needed +#define DKIM_PARTIAL_SUCCESS 2 // verify result: at least one but not all signatures verified +#define DKIM_NEUTRAL 3 // verify result: no signatures verified but message is not suspicous +#define DKIM_SUCCESS_BUT_EXTRA 4 // signature result: signature verified but it did not include all of the body +// clang-format on // This function is called once for each header in the message // return 1 to include this header in the signature and 0 to exclude. -typedef int(DKIM_CALL *DKIMHEADERCALLBACK)(const char *szHeader); +typedef int (*DKIMHEADERCALLBACK)(const char *szHeader); // This function is called to retrieve a TXT record from DNS -typedef int(DKIM_CALL *DKIMDNSCALLBACK)(const char *szFQDN, char *szBuffer, int nBufLen); +typedef int (*DKIMDNSCALLBACK)(const char *szFQDN, char *szBuffer, int nBufLen); typedef struct DKIMContext_t { unsigned int reserved1; @@ -111,15 +109,17 @@ typedef struct DKIMSignOptions_t { int nIncludeCopiedHeaders; // 0 = don't include z= tag, 1 = include z= tag } DKIMSignOptions; +// clang-format off typedef struct DKIMVerifyOptions_t { DKIMDNSCALLBACK pfnSelectorCallback; // selector record callback DKIMDNSCALLBACK pfnPracticesCallback; // ADSP record callback - int nHonorBodyLengthTag; // 0 = ignore l= tag, 1 = use l= tag to limit the amount of body verified - int nCheckPractices; // 0 = use default (unknown) practices, 1 = request and use author domain signing practices - int nSubjectRequired; // 0 = subject is required to be signed, 1 = not required - int nSaveCanonicalizedData; // 0 = canonicalized data is not saved, 1 = canonicalized data is saved - int nAllowUnsignedFromHeaders; // 0 = From headers not included in the signature are not allowed, 1 = allowed + int nHonorBodyLengthTag; // 0 = ignore l= tag, 1 = use l= tag to limit the amount of body verified + int nCheckPractices; // 0 = use default (unknown) practices, 1 = request and use author domain signing practices + int nSubjectRequired; // 0 = subject is required to be signed, 1 = not required + int nSaveCanonicalizedData; // 0 = canonicalized data is not saved, 1 = canonicalized data is saved + int nAllowUnsignedFromHeaders; // 0 = From headers not included in the signature are not allowed, 1 = allowed } DKIMVerifyOptions; +// clang-format on typedef struct DKIMVerifyDetails_t { char *szSignature; diff --git a/src/include/dkimbase.h b/src/include/dkimbase.h index bfecb5d..ddded67 100644 --- a/src/include/dkimbase.h +++ b/src/include/dkimbase.h @@ -1,19 +1,19 @@ /***************************************************************************** -* Copyright 2005 Alt-N Technologies, Ltd. +* Copyright 2005 Alt-N Technologies, Ltd. * -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at * -* http://www.apache.org/licenses/LICENSE-2.0 +* http://www.apache.org/licenses/LICENSE-2.0 * -* This code incorporates intellectual property owned by Yahoo! and licensed +* This code incorporates intellectual property owned by Yahoo! and licensed * pursuant to the Yahoo! DomainKeys Patent License Agreement. * -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and * limitations under the License. * * Changes done by ¢feh@fehcom.de obeying the above license diff --git a/src/include/dkimsign.h b/src/include/dkimsign.h index af1dd70..75d33de 100644 --- a/src/include/dkimsign.h +++ b/src/include/dkimsign.h @@ -62,22 +62,22 @@ protected: #if ( \ (OPENSSL_VERSION_NUMBER < 0x10100000L) \ || (LIBRESSL_VERSION_NUMBER > 0 && LIBRESSL_VERSION_NUMBER < 0x20700000L)) - EVP_MD_CTX m_Hdr_sha1ctx; /* the RSA SHA1 signature */ - EVP_MD_CTX m_Hdr_sha256ctx; /* the RSA SHA256 signature */ + EVP_MD_CTX m_Hdr_sha1ctx; // the RSA SHA1 signature + EVP_MD_CTX m_Hdr_sha256ctx; // the RSA SHA256 signature - EVP_MD_CTX m_Bdy_sha1ctx; /* the SHA1 digest */ - EVP_MD_CTX m_Bdy_sha256ctx; /* the SHA256 digest */ + EVP_MD_CTX m_Bdy_sha1ctx; // the SHA1 digest + EVP_MD_CTX m_Bdy_sha256ctx; // the SHA256 digest #else - EVP_MD_CTX *m_Hdr_sha1ctx; /* the RSA SHA1 signature */ - EVP_MD_CTX *m_Hdr_sha256ctx; /* the RSA SHA256 signature */ - EVP_MD_CTX *m_Hdr_ed25519ctx; /* the PureEd25519 signature */ + EVP_MD_CTX *m_Hdr_sha1ctx; // the RSA SHA1 signature + EVP_MD_CTX *m_Hdr_sha256ctx; // the RSA SHA256 signature + EVP_MD_CTX *m_Hdr_ed25519ctx; // the PureEd25519 signature - EVP_MD_CTX *m_Bdy_sha1ctx; /* the SHA1 digest */ - EVP_MD_CTX *m_Bdy_sha256ctx; /* the SHA256 digest for RSA */ - EVP_MD_CTX *m_Edy_sha256ctx; /* the SHA256 digest for Ed25519 */ + EVP_MD_CTX *m_Bdy_sha1ctx; // the SHA1 digest + EVP_MD_CTX *m_Bdy_sha256ctx; // the SHA256 digest for RSA + EVP_MD_CTX *m_Edy_sha256ctx; // the SHA256 digest for Ed25519 #endif - int m_Canon; /* canonization method */ + int m_Canon; // canonization method int m_EmptyLineCount; @@ -85,9 +85,9 @@ protected: string sFrom; string sSender; string sSelector; - string eSelector; /* Used for Ed25519 signatures */ + string eSelector; // Used for Ed25519 signatures string sDomain; - string sIdentity; /* for i= tag, if empty tag will not be included in sig */ + string sIdentity; // for i= tag, if empty tag will not be included in sig string sRequiredHeaders; bool m_IncludeBodyLengthTag; diff --git a/src/include/dkimverify.h b/src/include/dkimverify.h index 685426b..fb7d564 100644 --- a/src/include/dkimverify.h +++ b/src/include/dkimverify.h @@ -1,19 +1,19 @@ /***************************************************************************** -* Copyright 2005 Alt-N Technologies, Ltd. +* Copyright 2005 Alt-N Technologies, Ltd. * -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at * -* http://www.apache.org/licenses/LICENSE-2.0 +* http://www.apache.org/licenses/LICENSE-2.0 * -* This code incorporates intellectual property owned by Yahoo! and licensed +* This code incorporates intellectual property owned by Yahoo! and licensed * pursuant to the Yahoo! DomainKeys Patent License Agreement. * -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and * limitations under the License. * * Changes done by ¢feh@fehcom.de obeying the above license @@ -27,9 +27,9 @@ #include "dkimbase.h" /* not used anymore -#define DKIM_ADSP_UNKNOWN 1 -#define DKIM_ADSP_ALL 2 -#define DKIM_ADSP_DISCARDABLE 3 +#define DKIM_ADSP_UNKNOWN 1 +#define DKIM_ADSP_ALL 2 +#define DKIM_ADSP_DISCARDABLE 3 */ #define DKIM_POLICY_DOMAIN_NAME_TOO_LONG -50 // internal error @@ -38,8 +38,8 @@ #define DKIM_POLICY_INVALID -53 // internal error /* dito -#define DKIM_SIG_VERSION_PRE_02 0 -#define DKIM_SIG_VERSION_02_PLUS 1 +#define DKIM_SIG_VERSION_PRE_02 0 +#define DKIM_SIG_VERSION_02_PLUS 1 */ class SelectorInfo { @@ -111,13 +111,13 @@ class CDKIMVerify : public CDKIMBase { public: CDKIMVerify(); ~CDKIMVerify(); - // virtual ~CDKIMVerify() = 0; + // virtual ~CDKIMVerify() = 0; int Init(DKIMVerifyOptions *pOptions); int GetResults(void); int GetDetails(int *nSigCount, DKIMVerifyDetails **pDetails); - // int _DNSGetTXT(const char* szFQDN,char* Buffer,int nBufLen); + // int _DNSGetTXT(const char* szFQDN,char* Buffer,int nBufLen); virtual int ProcessHeaders(void); virtual int ProcessBody(char *szBuffer, int nBufLength, bool bEOF); @@ -132,13 +132,13 @@ protected: SelectorInfo& GetSelector(const string& sSelector, const string& sDomain); - // int GetADSP(const string &sDomain,int &iADSP); + // int GetADSP(const std::string& sDomain, int& iADSP); list<SignatureInfo> Signatures; list<SelectorInfo> Selectors; DKIMDNSCALLBACK m_pfnSelectorCallback; // selector record callback - // DKIMDNSCALLBACK m_pfnPracticesCallback; // ADSP record callback + // DKIMDNSCALLBACK m_pfnPracticesCallback; // ADSP record callback bool m_HonorBodyLengthTag; bool m_CheckPractices; diff --git a/src/include/global.h b/src/include/global.h index 7e9b673..a35999c 100644 --- a/src/include/global.h +++ b/src/include/global.h @@ -5,7 +5,7 @@ #include "uint_t.h" /* Copyright (C) RSA Laboratories, a division of RSA Data Security, - Inc., created 1991. All rights reserved. + * Inc., created 1991. All rights reserved. */ #ifndef _GLOBAL_H_ diff --git a/src/include/ipalloc.h b/src/include/ipalloc.h index 6626ecc..cec29a9 100644 --- a/src/include/ipalloc.h +++ b/src/include/ipalloc.h @@ -15,7 +15,8 @@ struct ip_mx { char mxh[NAME_LEN]; }; -GEN_ALLOC_typedef(ipalloc, struct ip_mx, ix, len, a) int ipalloc_readyplus(); +GEN_ALLOC_typedef(ipalloc, struct ip_mx, ix, len, a); +int ipalloc_readyplus(); int ipalloc_append(); #endif diff --git a/src/include/maildir.h b/src/include/maildir.h index 69e679b..9659989 100644 --- a/src/include/maildir.h +++ b/src/include/maildir.h @@ -2,6 +2,7 @@ #define MAILDIR_H #include "logmsg.h" +#include "stralloc.h" #include "prioq.h" diff --git a/src/include/prioq.h b/src/include/prioq.h index cbddd9b..31c99ac 100644 --- a/src/include/prioq.h +++ b/src/include/prioq.h @@ -10,9 +10,9 @@ struct prioq_elt { unsigned long id; }; -GEN_ALLOC_typedef(prioq, struct prioq_elt, p, len, a) +GEN_ALLOC_typedef(prioq, struct prioq_elt, p, len, a); - int prioq_insert(); +int prioq_insert(); int prioq_min(); void prioq_delmin(); diff --git a/src/include/recipients.h b/src/include/recipients.h index e666bd1..34542d5 100644 --- a/src/include/recipients.h +++ b/src/include/recipients.h @@ -1,6 +1,8 @@ #ifndef RECIPIENTS_H #define RECIPIENTS_H +#include <sys/types.h> + int recipients_init(void); int recipients(char *, int); ssize_t safewrite(); diff --git a/src/include/tcpto.h b/src/include/tcpto.h index ca4f97a..678d12a 100644 --- a/src/include/tcpto.h +++ b/src/include/tcpto.h @@ -4,17 +4,17 @@ #define TCPTO_BUFSIZ 1024 /* persistency structure: record -struct tcpto { +struct tcpto { unsigned char af; -- 1 byte -- IPv4: x'2' / IPv6: x'a' (10) unsigned char nul[3]; -- 3 byte unsigned char errorcount -- 1 byte -- if err_timeout || err_conrefused || err_proto (TLS) unsigned char nul[3]; -- 3 byte - unsigned long when; -- 8 byte + unsigned long when; -- 8 byte union { struct ip_address ip; struct ip6_address ip6; unsigned char nul[16]; -- 16 byte -- IPv4: filled up with '.' = x'2e' - } addr; + } addr; }; total: 32 byte */ diff --git a/src/include/tls_remote.h b/src/include/tls_remote.h index 7df0776..fe55d22 100644 --- a/src/include/tls_remote.h +++ b/src/include/tls_remote.h @@ -3,6 +3,8 @@ #include <openssl/ssl.h> +#include "stralloc.h" + /* the version is like this: 0xMNNFFPPS: major minor fix patch status */ #if OPENSSL_VERSION_NUMBER < 0x00908000L #error "Need OpenSSL version at least 0.9.8" diff --git a/src/include/token822.h b/src/include/token822.h index e1cef4a..73ef0be 100644 --- a/src/include/token822.h +++ b/src/include/token822.h @@ -9,9 +9,9 @@ struct token822 { int slen; }; -GEN_ALLOC_typedef(token822_alloc, struct token822, t, len, a) +GEN_ALLOC_typedef(token822_alloc, struct token822, t, len, a); - int token822_parse(); +int token822_parse(); int token822_addrlist(); int token822_unquote(); int token822_unparse(); diff --git a/src/ipalloc.c b/src/ipalloc.c index c90a1d3..3cb363e 100644 --- a/src/ipalloc.c +++ b/src/ipalloc.c @@ -4,5 +4,5 @@ #include "genalloc.h" #include "ip.h" -GEN_ALLOC_readyplus(ipalloc, struct ip_mx, ix, len, a, i, n, x, 22, ipalloc_readyplus) - GEN_ALLOC_append(ipalloc, struct ip_mx, ix, len, a, i, n, x, 22, ipalloc_readyplus, ipalloc_append) +GEN_ALLOC_readyplus(ipalloc, struct ip_mx, ix, len, a, i, n, x, 22, ipalloc_readyplus); +GEN_ALLOC_append(ipalloc, struct ip_mx, ix, len, a, i, n, x, 22, ipalloc_readyplus, ipalloc_append); @@ -1,3 +1,5 @@ +#include "ipme.h" + #include <ifaddrs.h> #include <net/if.h> @@ -7,16 +9,17 @@ #include <sys/socket.h> #include <sys/time.h> #include <sys/types.h> -#ifndef SIOCGIFCONF /* whatever works */ - #include <sys/sockio.h> -#endif + #include "byte.h" #include "ip.h" #include "stralloc.h" #include "hassalen.h" #include "ipalloc.h" -#include "ipme.h" + +#ifndef SIOCGIFCONF /* whatever works */ + #include <sys/sockio.h> +#endif /** @file ipme.c @brief ipme_is4, ipme_is6, ipme_is46, ipme_init diff --git a/src/maildir.c b/src/maildir.c index c360bc2..a755177 100644 --- a/src/maildir.c +++ b/src/maildir.c @@ -66,12 +66,13 @@ static int append(prioq *pq, stralloc *filenames, char *subdir, datetime_sec tim if (!stralloc_cats(filenames, "/")) break; if (!stralloc_cats(filenames, d->d_name)) break; if (!stralloc_0(filenames)) break; - if (stat(filenames->s + pos, &st) == 0) + if (stat(filenames->s + pos, &st) == 0) { if (st.st_mtime < time) { /* don't want to mix up the order */ pe.dt = st.st_mtime; pe.id = pos; if (!prioq_insert(pq, &pe)) break; } + } } closedir(dir); @@ -89,9 +90,7 @@ int maildir_scan(prioq *pq, stralloc *filenames, int flagnew, int flagcur) time = now(); - if (flagnew) - if (append(pq, filenames, "new", time) == -1) return -1; - if (flagcur) - if (append(pq, filenames, "cur", time) == -1) return -1; + if (flagnew && append(pq, filenames, "new", time) == -1) return -1; + if (flagcur && append(pq, filenames, "cur", time) == -1) return -1; return 0; } diff --git a/src/maildir2mbox.c b/src/maildir2mbox.c index 5e31951..7678969 100644 --- a/src/maildir2mbox.c +++ b/src/maildir2mbox.c @@ -1,6 +1,8 @@ #include <sys/stat.h> #include <unistd.h> +#include <stdio.h> + #include "buffer.h" #include "env.h" #include "exit.h" @@ -20,8 +22,6 @@ char *mbox; char *mboxtmp; -int rename(const char *, const char *); // stdio.h - stralloc filenames = {0}; prioq pq = {0}; prioq pq2 = {0}; diff --git a/src/maildirwatch.c b/src/maildirwatch.c index 1496e20..0fe479f 100644 --- a/src/maildirwatch.c +++ b/src/maildirwatch.c @@ -59,10 +59,7 @@ void doheader(stralloc *h) break; } } -void finishheader() -{ - ; -} +void finishheader() {} stralloc filenames = {0}; prioq pq = {0}; diff --git a/src/matchup.c b/src/matchup.c index 06cd481..d68d5f8 100644 --- a/src/matchup.c +++ b/src/matchup.c @@ -19,14 +19,17 @@ void nomem() { logmsg(WHO, 111, FATAL, "out of memory"); } + void die_read() { logmsg(WHO, 110, ERROR, "unable to read input: "); } + void die_write() { logmsg(WHO, 110, ERROR, "unable to write output: "); } + void die_write5() { logmsg(WHO, 111, FATAL, "unable to write fd 5: "); @@ -36,6 +39,7 @@ void out(char *buf, int len) { if (buffer_put(buffer_1, buf, len) == -1) die_write(); } + void outs(char *buf) { if (buffer_puts(buffer_1, buf) == -1) die_write(); @@ -48,16 +52,17 @@ void out5(char *buf, int len) { if (buffer_put(&bo5, buf, len) == -1) die_write5(); } + void outs5(char *buf) { if (buffer_puts(&bo5, buf) == -1) die_write5(); } -GEN_ALLOC_typedef(ulongalloc, unsigned long, u, len, a) - GEN_ALLOC_ready(ulongalloc, unsigned long, u, len, a, i, n, x, 30, ulongalloc_ready) - GEN_ALLOC_readyplus(ulongalloc, unsigned long, u, len, a, i, n, x, 30, ulongalloc_readyplus) +GEN_ALLOC_typedef(ulongalloc, unsigned long, u, len, a); +GEN_ALLOC_ready(ulongalloc, unsigned long, u, len, a, i, n, x, 30, ulongalloc_ready); +GEN_ALLOC_readyplus(ulongalloc, unsigned long, u, len, a, i, n, x, 30, ulongalloc_readyplus); - char strnum[FMT_ULONG]; +char strnum[FMT_ULONG]; stralloc pool = {0}; unsigned int poolbytes = 0; @@ -1,27 +1,27 @@ -/* MD5C.C - RSA Data Security, Inc., MD5 message-digest algorithm - */ - -/* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All - rights reserved. - - License to copy and use this software is granted provided that it - is identified as the "RSA Data Security, Inc. MD5 Message-Digest - Algorithm" in all material mentioning or referencing this software - or this function. - - License is also granted to make and use derivative works provided - that such works are identified as "derived from the RSA Data - Security, Inc. MD5 Message-Digest Algorithm" in all material - mentioning or referencing the derived work. - - RSA Data Security, Inc. makes no representations concerning either - the merchantability of this software or the suitability of this - software for any particular purpose. It is provided "as is" - without express or implied warranty of any kind. - - These notices must be retained in any copies of any part of this - documentation and/or software. - */ +/* MD5C.C - RSA Data Security, Inc., MD5 message-digest algorithm */ + +/* + Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All + rights reserved. + + License to copy and use this software is granted provided that it + is identified as the "RSA Data Security, Inc. MD5 Message-Digest + Algorithm" in all material mentioning or referencing this software + or this function. + + License is also granted to make and use derivative works provided + that such works are identified as "derived from the RSA Data + Security, Inc. MD5 Message-Digest Algorithm" in all material + mentioning or referencing the derived work. + + RSA Data Security, Inc. makes no representations concerning either + the merchantability of this software or the suitability of this + software for any particular purpose. It is provided "as is" + without express or implied warranty of any kind. + + These notices must be retained in any copies of any part of this + documentation and/or software. +*/ #include <stdint.h> @@ -52,9 +52,7 @@ static void Decode PROTO_LIST((UINT4 *, unsigned char *, unsigned int)); static void MD5_memcpy PROTO_LIST((POINTER, POINTER, unsigned int)); static void MD5_memset PROTO_LIST((POINTER, int, unsigned int)); -static unsigned char PADDING[64] = { - 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static unsigned char PADDING[64] = {0x80, 0}; /* F, G, H and I are basic MD5 functions. */ #define F(x, y, z) (((x) & (y)) | ((~x) & (z))) @@ -257,7 +255,7 @@ unsigned char block[64]; MD5_memset((POINTER)x, 0, sizeof(x)); } -/* Encodes input (UINT4) into output (unsigned char). +/* Encodes input (UINT4) into output (unsigned char). Assumes len is a multiple of 4. */ static void Encode(output, input, len) unsigned char *output; @@ -274,7 +272,7 @@ unsigned int len; } } -/* Decodes input (unsigned char) into output (UINT4). +/* Decodes input (unsigned char) into output (UINT4). Assumes len is a multiple of 4. */ static void Decode(output, input, len) UINT4 *output; 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(); diff --git a/src/newinclude.c b/src/newinclude.c index 4e1bab2..4991b43 100644 --- a/src/newinclude.c +++ b/src/newinclude.c @@ -18,12 +18,11 @@ #define WHO "newinclude" -int rename(const char *, const char *); // stdio.h - void nomem() { logmsg(WHO, 111, FATAL, "out of memory"); } + void usage() { logmsg(WHO, 100, USAGE, "newinclude list"); @@ -45,6 +44,7 @@ void readerr() { logmsg(WHO, 111, FATAL, B("unable to read: ", fnlist)); } + void writeerr() { logmsg(WHO, 111, FATAL, B("unable to write to ", fntmp)); @@ -228,8 +228,8 @@ 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) @@ -275,13 +275,12 @@ void parseline() if (!token822_append(&tokaddr, t)) nomem(); continue; } + } if (tokaddr.len) gotaddr(); } -int main(argc, argv) -int argc; -char **argv; +int main(int argc, char **argv) { int fd; diff --git a/src/preline.c b/src/preline.c index e61c588..2a0b8c4 100644 --- a/src/preline.c +++ b/src/preline.c @@ -41,8 +41,8 @@ int main(int argc, char **argv) if (!(rpline = env_get("RPLINE"))) die_usage(); if (!(dtline = env_get("DTLINE"))) die_usage(); - while ((opt = getopt(argc, argv, "frdFRD")) != opteof) switch (opt) - { + while ((opt = getopt(argc, argv, "frdFRD")) != opteof) { + switch (opt) { case 'f': flagufline = 0; break; case 'r': flagrpline = 0; break; case 'd': flagdtline = 0; break; @@ -51,6 +51,7 @@ int main(int argc, char **argv) case 'D': flagdtline = 1; break; default: die_usage(); } + } argc -= optind; argv += optind; if (!*argv) die_usage(); diff --git a/src/printforward.c b/src/printforward.c index 594ccad..ae5d26c 100644 --- a/src/printforward.c +++ b/src/printforward.c @@ -11,6 +11,7 @@ void badformat() { logmsg(WHO, 100, FATAL, "bad database format"); } + void nomem() { logmsg(WHO, 111, FATAL, "out of memory"); @@ -124,8 +125,9 @@ int main() } if (i != j) badformat(); printbuf(";\n"); - } else + } else { badformat(); + } } if (buffer_flush(buffer_1small) == -1) logmsg(WHO, 111, FATAL, "unable to write output"); diff --git a/src/prioq.c b/src/prioq.c index 7cd29e8..1d3beb2 100644 --- a/src/prioq.c +++ b/src/prioq.c @@ -3,9 +3,9 @@ #include "alloc.h" #include "genalloc.h" -GEN_ALLOC_readyplus(prioq, struct prioq_elt, p, len, a, i, n, x, 100, prioq_readyplus) +GEN_ALLOC_readyplus(prioq, struct prioq_elt, p, len, a, i, n, x, 100, prioq_readyplus); - int prioq_insert(prioq *pq, struct prioq_elt *pe) +int prioq_insert(prioq *pq, struct prioq_elt *pe) { int i; int j; diff --git a/src/qbiff.c b/src/qbiff.c index 186e524..800e1f2 100644 --- a/src/qbiff.c +++ b/src/qbiff.c @@ -2,7 +2,19 @@ #include <sys/types.h> #include <unistd.h> +#include "buffer.h" +#include "byte.h" +#include "env.h" +#include "exit.h" +#include "open.h" +#include "str.h" +#include "stralloc.h" + #include "hasutmp.h" +#include "headerbody.h" +#include "hfield.h" + + #ifdef HASUTMP #include <utmp.h> #ifndef UTMP_FILE @@ -15,16 +27,6 @@ #else #include <utmpx.h> #endif -#include "buffer.h" -#include "byte.h" -#include "env.h" -#include "exit.h" -#include "open.h" -#include "str.h" -#include "stralloc.h" - -#include "headerbody.h" -#include "hfield.h" buffer b; #ifdef HASUTMP @@ -67,10 +69,7 @@ void doheader(stralloc *h) } } -void finishheader() -{ - ; -} +void finishheader() {} int main() { @@ -117,10 +116,10 @@ int main() if (fdutmp == -1) _exit(0); buffer_init(&b, read, fdutmp, bufutmp, sizeof(bufutmp)); - while (buffer_get(&b, &ut, sizeof(ut)) == sizeof(ut)) + while (buffer_get(&b, &ut, sizeof(ut)) == sizeof(ut)) { if (!str_diffn(ut.ut_name, user, sizeof(ut.ut_name))) { #else - while ((ut = getutxent()) != 0) + while ((ut = getutxent()) != 0) { if (ut->ut_type == USER_PROCESS && !str_diffn(ut->ut_user, user, sizeof(ut->ut_user))) { #endif #ifdef HASUTMP @@ -152,5 +151,6 @@ int main() buffer_putflush(&b, woof.s, woof.len); close(fdtty); } + } _exit(0); } diff --git a/src/qmail-authuser.c b/src/qmail-authuser.c index 2cdb01e..c26d61b 100644 --- a/src/qmail-authuser.c +++ b/src/qmail-authuser.c @@ -1,7 +1,10 @@ +#include <pwd.h> #include <unistd.h> #include <stdio.h> +#include <crypt.h> + #include "buffer.h" #include "byte.h" #include "case.h" @@ -21,32 +24,29 @@ #include "auto_qmail.h" #include "control.h" #include "global.h" +#include "hasspnam.h" +#include "hasuserpw.h" #include "hmac_md5.h" #include "md5.h" #include "sha1.h" #include "sha256.h" -#define FDAUTH 3 -#define FDGOSSIP 1 -#define SOCKET_CALL "-s" -#define DOVECOT_SERVICE "-x" -#define POP_USER "qmail-pop3d" - -extern char *crypt(); -#include <pwd.h> -static struct passwd *pw; -#include "hasspnam.h" #ifdef HASGETSPNAM #include <shadow.h> static struct spwd *spw; #endif -#include "hasuserpw.h" #ifdef HASUSERPW #include <userpw.h> static struct userpw *upw; #endif +#define FDAUTH 3 +#define FDGOSSIP 1 +#define SOCKET_CALL "-s" +#define DOVECOT_SERVICE "-x" +#define POP_USER "qmail-pop3d" + /** @file qmail-authuser.c @return 0: ok 1: credentials failure @@ -55,6 +55,8 @@ static struct userpw *upw; 111: temporary problem checking the password */ +static struct passwd *pw; + char authbuf[512]; buffer ba = BUFFER_INIT(write, FDAUTH, authbuf, sizeof(authbuf)); @@ -65,16 +67,17 @@ stralloc user = {0}; // user w/o domain appended stralloc homedir = {0}; stralloc shell = {0}; -/** @brief Supported storage methods: - (1) authuser:[=]plainpasswd, - (2) authuser:%hashpasswd, - (3) authuser:?, authuser:!, *:?, *:! (! -> +environment) - (4) x:+ -> checkvpw; x = { user@domain, @domain, @ } vmailmgr - (5) x:& -> vchkpw; x = { user@domain, @domain, @ } vpopmail - (6) x:= -> qmail-client; x = { user@domain, @domain, @ } dovecot - Supported auth methods: - user/login/plain: (1,2,3,4,5,6), - cram-md5/apop: (1,5) +/** + @brief Supported storage methods: + (1) authuser:[=]plainpasswd, + (2) authuser:%hashpasswd, + (3) authuser:?, authuser:!, *:?, *:! (! -> +environment) + (4) x:+ -> checkvpw; x = { user@domain, @domain, @ } vmailmgr + (5) x:& -> vchkpw; x = { user@domain, @domain, @ } vpopmail + (6) x:= -> qmail-client; x = { user@domain, @domain, @ } dovecot + Supported auth methods: + user/login/plain: (1,2,3,4,5,6), + cram-md5/apop: (1,5) */ void exit(int fail) diff --git a/src/qmail-badloadertypes.c b/src/qmail-badloadertypes.c index 779c73a..3ed4e2f 100644 --- a/src/qmail-badloadertypes.c +++ b/src/qmail-badloadertypes.c @@ -1,6 +1,7 @@ #include <sys/stat.h> #include <unistd.h> +#include <stdio.h> #include <stdlib.h> #include "buffer.h" @@ -16,12 +17,11 @@ #define WHO "qmail-badloadertypes" #define LOADER_LEN 5 -int rename(const char *, const char *); // stdio.h - void die_read() { logmsg(WHO, 111, FATAL, "unable to read control/badloadertypes"); } + void die_write() { logmsg(WHO, 111, FATAL, "unable to write to control/badloadertypes.tmp"); diff --git a/src/qmail-badmimetypes.c b/src/qmail-badmimetypes.c index d56854e..314d142 100644 --- a/src/qmail-badmimetypes.c +++ b/src/qmail-badmimetypes.c @@ -1,6 +1,8 @@ #include <sys/stat.h> #include <unistd.h> +#include <stdio.h> + #include "buffer.h" #include "cdbmake.h" #include "exit.h" @@ -14,12 +16,11 @@ #define WHO "qmail-badmimetypes" #define MIMETYPE_LEN 9 -int rename(const char *, const char *); // stdio.h - void die_read() { logmsg(WHO, 111, FATAL, "unable to read control/badmimetypes"); } + void die_write() { logmsg(WHO, 111, FATAL, "unable to write to control/badmimetypes.tmp"); diff --git a/src/qmail-clean.c b/src/qmail-clean.c index 2a9d706..efeda8c 100644 --- a/src/qmail-clean.c +++ b/src/qmail-clean.c @@ -70,9 +70,9 @@ int main() cleanuploop = 0; for (;;) { - if (cleanuploop) + if (cleanuploop) { --cleanuploop; - else { + } else { cleanuppid(); cleanuploop = 30; } @@ -98,28 +98,31 @@ int main() continue; } } - if (line.s[i] == '/') - if (!scan_ulong(line.s + i + 1, &id)) { - respond("x"); - continue; - } - if (byte_equal(line.s, 5, "foop/")) { -#define U(prefix, flag) \ - fmtqfn(fnbuf, prefix, id, flag); \ - if (unlink(fnbuf) == -1) \ - if (errno != ENOENT) { \ - respond("!"); \ - continue; \ + if (line.s[i] == '/' && !scan_ulong(line.s + i + 1, &id)) { + respond("x"); + continue; } - U("intd/", 1) - U("mess/", 1) +#define U(prefix, flag) \ + do { \ + fmtqfn(fnbuf, prefix, id, flag); \ + if (unlink(fnbuf) == -1) \ + if (errno != ENOENT) { \ + respond("!"); \ + continue; \ + } \ + } while (0) + + if (byte_equal(line.s, 5, "foop/")) { + U("intd/", 1); + U("mess/", 1); respond("+"); } else if (byte_equal(line.s, 4, "todo/")) { - U("intd/", 1) - U("todo/", 1) + U("intd/", 1); + U("todo/", 1); respond("+"); - } else + } else { respond("x"); + } } _exit(0); } diff --git a/src/qmail-dkim.cpp b/src/qmail-dkim.cpp index 53e1b27..1a05e6c 100644 --- a/src/qmail-dkim.cpp +++ b/src/qmail-dkim.cpp @@ -34,6 +34,7 @@ #include <time.h> #include "dkim.h" + extern "C" { #include "dns.h" } diff --git a/src/qmail-dksign.c b/src/qmail-dksign.c index 06fee37..0258b29 100644 --- a/src/qmail-dksign.c +++ b/src/qmail-dksign.c @@ -32,28 +32,29 @@ #define DOMAINKEYS "ssl/domainkeys/" -/** @file qmail-dksign.c -- generate signature and attach in DKIM header to outgoing message - - Steps: - ------ - a) DKIM controls: get private key for sending domain - b) Prepare two staging files at queue/dkim (before and after signing) - c) Read input at fd0 and insert CR for every line and store at dkim/x/pre - d) DKIM sign the message with provided private key and store at dkim/y/post - e) Copy signed file from fd to 0 - f) Invoke qmail-remote (respecting the \r\n) - g) Remove staging files (pre/post) - - Hack for hybrid signatures: - --------------------------- - - a) selector is a link to RSA private key - b) selector2 is a link to Ed25519 private key - c) Both are provided in the 'selector' field of dkimdomains separated by colon - d) The coupled selector information is provided to qmail-dkim as: -yselector ,-Yselector2 - e) The RSA privat key is given unaltered - f) The Ed25519 private is supplied as additional argument - */ +/** + @file qmail-dksign.c -- generate signature and attach in DKIM header to outgoing message + + Steps: + ------ + a) DKIM controls: get private key for sending domain + b) Prepare two staging files at queue/dkim (before and after signing) + c) Read input at fd0 and insert CR for every line and store at dkim/x/pre + d) DKIM sign the message with provided private key and store at dkim/y/post + e) Copy signed file from fd to 0 + f) Invoke qmail-remote (respecting the \r\n) + g) Remove staging files (pre/post) + + Hack for hybrid signatures: + --------------------------- + + a) selector is a link to RSA private key + b) selector2 is a link to Ed25519 private key + c) Both are provided in the 'selector' field of dkimdomains separated by colon + d) The coupled selector information is provided to qmail-dkim as: -yselector ,-Yselector2 + e) The RSA privat key is given unaltered + f) The Ed25519 private is supplied as additional argument +*/ char bufin[1000]; // RFC 5322: 998 chars - why? buffer bi = BUFFER_INIT(read, 0, bufin, sizeof(bufin)); @@ -64,23 +65,28 @@ void die(int e) { _exit(e); } + void die_write(char *fn) { unlink(fn); die(53); } + void die_read() { die(54); } + void out(char *s) { if (buffer_puts(&bo, s) == -1) _exit(111); } + void zero() { if (buffer_put(&bo, "\0", 1) == -1) _exit(111); } + void zerodie() { zero(); @@ -106,11 +112,13 @@ void temp_nomem() out("ZOut of memory. (#4.3.0)\n"); zerodie(); } + void temp_chdir() { out("ZUnable to switch to target directory. (#4.3.0)\n"); zerodie(); } + void temp_create() { out("ZUnable to create DKIM stage file: "); @@ -119,26 +127,31 @@ void temp_create() out(". (#4.3.0)\n"); zerodie(); } + void temp_unlink() { out("ZUnable to unlink DKIM stage file. (#4.3.0)\n"); zerodie(); } + void temp_control() { out("ZUnable to read DKIM control files. (#4.3.0)\n"); zerodie(); } + void perm_usage() { out("Zqmail-dksign was invoked improperly. (#5.3.5)\n"); zerodie(); } + void temp_read() { out("DUnable to read message for DKIM signing. (#4.3.0)\n"); zerodie(); } + void temp_nosignkey() { out("DCan't read sign key: "); @@ -175,12 +188,13 @@ int get_controls() /* Parenting domains; senddomain 0-terminated; lowercase */ for (i = 0; i <= senddomain.len; ++i) { - if ((i == 0) || (senddomain.s[i] == '.')) + if ((i == 0) || (senddomain.s[i] == '.')) { if ((dkimparams = constmap(&mapdkimdomains, senddomain.s + i, senddomain.len - i - 1))) { if (!stralloc_copys(&sender, senddomain.s + i)) temp_nomem(); if (!stralloc_0(&sender)) temp_nomem(); return 3; } + } } /* We sign only senddomains we take responsibility for: rcpthosts */ @@ -275,7 +289,7 @@ stralloc length = {0}; // -l qmail-dkim [-h|-v|-s] [tags] <msgfile> [<RSAkeyfile> <outfile> <Ed25519keyfile>] -------------------------------------------------------------------------------- - tags: + tags: ---- -c<canonicalization> - r=relaxed [DEFAULT], s=simple, t=relaxed/simple, u=simple/relaxed -d<sdid> - Signing Domain Identifier,if not provided it will be determined from the envelope originator/from header @@ -564,8 +578,9 @@ int main(int argc, char **args) fdin = open_read(fndkin.s); // DKIM key failed to sign if (fdin == -1) die_read(); } - } else + } else { temp_nosignkey(); + } qmail_remote(qargs, fdin); // closes fdin if (nkey) dkim_unlink(); diff --git a/src/qmail-dkverify.c b/src/qmail-dkverify.c index 3d64e51..6a546e9 100644 --- a/src/qmail-dkverify.c +++ b/src/qmail-dkverify.c @@ -30,18 +30,18 @@ #define WHO "qmail-dkverify" -/** @file qmail-dkverify.c - @brief stub routine for DKIM signature verification and indication in received message - - Steps: - ------ - a) Store message with CRLF - b) Get DKIM signature from message - if given: - c) Call qmail-dkim for verification - d) Include results as appended header - e) Queue the message for processing - - */ +/** + @file qmail-dkverify.c + @brief stub routine for DKIM signature verification and indication in received message + + Steps: + ------ + a) Store message with CRLF + b) Get DKIM signature from message - if given: + c) Call qmail-dkim for verification + d) Include results as appended header + e) Queue the message for processing +*/ char bufin[1024]; // RFC 5322: 998 chars - why? buffer bi = BUFFER_INIT(read, 0, bufin, sizeof(bufin)); // read buffer @@ -52,28 +52,34 @@ void die(int e) { _exit(e); } + void die_pipe(char *fn) { unlink(fn); die(53); } + void die_write(char *fn) { unlink(fn); die(53); } + void die_read() { die(54); } + void out(char *s) { if (buffer_puts(&bo, s) == -1) _exit(111); } + void zero() { if (buffer_put(&bo, "\0", 1) == -1) _exit(111); } + void zerodie() { zero(); @@ -86,31 +92,37 @@ void temp_nomem() out("ZOut of memory. (#4.3.0)\n"); zerodie(); } + void temp_chdir() { out("ZUnable to switch to target directory. (#4.3.0)\n"); zerodie(); } + void temp_create() { out("ZUnable to create DKIM stage file. (#4.3.0)\n"); zerodie(); } + void temp_unlink() { out("ZUnable to unlink DKIM stage file. (#4.3.0)\n"); zerodie(); } + void temp_read() { out("ZUnable to read message. (#4.3.0)\n"); zerodie(); } + void temp_socket() { out("ZUnable to crate socket pair. (#4.3.0)\n"); zerodie(); } + void temp_control() { out("ZUnable to read control files. (#4.3.0)\n"); @@ -272,8 +284,9 @@ int dkim_result(const char *me) if (result.len > 2) { if (case_starts(result.s, "pass")) r = 0; if (case_starts(result.s, "fail")) r = 35; - } else if (!stralloc_copys(&result, "unknown")) + } else if (!stralloc_copys(&result, "unknown")) { temp_nomem(); + } if (!stralloc_copys(&dkheader, "X-Authentication-Results: ")) temp_nomem(); if (!stralloc_cats(&dkheader, senddomain.s)) temp_nomem(); diff --git a/src/qmail-inject.c b/src/qmail-inject.c index dd8bb21..00a1531 100644 --- a/src/qmail-inject.c +++ b/src/qmail-inject.c @@ -71,6 +71,7 @@ void perm() { _exit(100); } + void temp() { _exit(111); @@ -81,28 +82,33 @@ void die_nomem() buffer_putsflush(buffer_2, "qmail-inject: fatal: out of memory\n"); temp(); } + void die_invalid(stralloc *sa) { buffer_putsflush(buffer_2, "qmail-inject: fatal: invalid header field: "); buffer_putflush(buffer_2, sa->s, sa->len); perm(); } + void die_qqt() { buffer_putsflush(buffer_2, "qmail-inject: fatal: unable to run qmail-queue\n"); temp(); } + void die_chdir() { buffer_putsflush(buffer_2, "qmail-inject: fatal: internal bug\n"); temp(); } + void die_read() { if (errno == ENOMEM) die_nomem(); buffer_putsflush(buffer_2, "qmail-inject: fatal: read error\n"); temp(); } + void doordie(stralloc *sa, int r) { if (r == 1) return; @@ -112,10 +118,10 @@ void doordie(stralloc *sa, int r) perm(); } -GEN_ALLOC_typedef(saa, stralloc, sa, len, a) - GEN_ALLOC_readyplus(saa, stralloc, sa, len, a, i, n, x, 10, saa_readyplus) +GEN_ALLOC_typedef(saa, stralloc, sa, len, a); +GEN_ALLOC_readyplus(saa, stralloc, sa, len, a, i, n, x, 10, saa_readyplus); - static stralloc sauninit = {0}; +static stralloc sauninit = {0}; saa savedh = {0}; saa hrlist = {0}; @@ -714,9 +720,9 @@ int main(int argc, char **argv) starttime = now(); qmopts = env_get("QMAILINJECT"); - if (qmopts) - while (*qmopts) switch (*qmopts++) - { + if (qmopts) { + while (*qmopts) { + switch (*qmopts++) { case 'c': flagnamecomment = 1; break; case 's': flagdeletesender = 1; break; case 'f': flagdeletefrom = 1; break; @@ -724,6 +730,8 @@ int main(int argc, char **argv) case 'r': flaghackrecip = 1; break; case 'm': flaghackmess = 1; break; } + } + } mailhost = env_get("QMAILHOST"); if (!mailhost) mailhost = env_get("MAILHOST"); @@ -752,8 +760,8 @@ int main(int argc, char **argv) if (!saa_readyplus(&hrrlist, 1)) die_nomem(); if (!saa_readyplus(&reciplist, 1)) die_nomem(); - while ((opt = getopt(argc, argv, "aAhHnNf:")) != opteof) switch (opt) - { + while ((opt = getopt(argc, argv, "aAhHnNf:")) != opteof) { + switch (opt) { case 'a': recipstrategy = RECIP_ARGS; break; case 'A': recipstrategy = RECIP_DEFAULT; break; case 'h': recipstrategy = RECIP_HEADER; break; @@ -771,6 +779,7 @@ int main(int argc, char **argv) case '?': default: perm(); } + } argc -= optind; argv += optind; diff --git a/src/qmail-local.c b/src/qmail-local.c index 4479e9b..02040f8 100644 --- a/src/qmail-local.c +++ b/src/qmail-local.c @@ -31,6 +31,7 @@ #include "qmail.h" #include "quote.h" + /** @file qmail-local local delivery agent to Mailbox and Maildir @@ -49,26 +50,32 @@ void temp_nomem() { logmsg(WHO, 111, FATAL, "Out of memory. (#4.3.0)"); } + void temp_rewind() { logmsg(WHO, 111, FATAL, "Unable to rewind message. (#4.3.0)"); } + void temp_childcrashed() { logmsg(WHO, 111, FATAL, "Aack, child crashed. (#4.3.0)"); } + void temp_fork() { logmsg(WHO, 111, FATAL, B("Unable to fork: ", error_str(errno), ". (#4.3.0)")); } + void temp_read() { logmsg(WHO, 111, ERROR, B("Unable to read message: ", error_str(errno), ". (#4.3.0)")); } + void temp_slowlock() { logmsg(WHO, 111, ERROR, "File has been locked for 30 seconds straight. (#4.3.0)"); } + void temp_qmail(fn) char *fn; { logmsg(WHO, 111, FATAL, B("Unable to open: ", fn, " ", error_str(errno), ". (#4.3.0)")); @@ -105,10 +112,12 @@ char bufout[1024]; char fntmptph[80 + FMT_ULONG * 2]; char fnnewtph[80 + FMT_ULONG * 2]; + void tryunlinktmp() { unlink(fntmptph); } + void sigalrm() { tryunlinktmp(); @@ -401,11 +410,12 @@ void checkhome() if (stat(".", &st) == -1) logmsg(WHO, 111, ERROR, B("Unable to stat home directory: ", error_str(errno), ". (#4.3.0)")); if (st.st_mode & auto_patrn) logmsg(WHO, 111, ERROR, "Uh-oh: home directory is writable. (#4.7.0)"); - if (st.st_mode & 01000) + if (st.st_mode & 01000) { if (flagdoit) logmsg(WHO, 111, ERROR, "Home directory is sticky: user is editing his .qmail file. (#4.2.1)"); else logmsg(WHO, 0, WARN, "Warning: home directory is sticky."); + } } int qmeox(char *dashowner) @@ -474,7 +484,7 @@ void qmesearch(int *fd, int *cutable) return; } - for (i = safeext.len; i >= 0; --i) + for (i = safeext.len; i >= 0; --i) { if (!i || (safeext.s[i - 1] == '-')) { if (!stralloc_copys(&qme, ".qmail")) temp_nomem(); if (!stralloc_cats(&qme, dash)) temp_nomem(); @@ -486,6 +496,7 @@ void qmesearch(int *fd, int *cutable) return; } } + } *fd = -1; } @@ -539,12 +550,13 @@ int main(int argc, char **argv) if (!env_init()) temp_nomem(); flagdoit = 1; - while ((opt = getopt(argc, argv, "nN")) != opteof) switch (opt) - { + while ((opt = getopt(argc, argv, "nN")) != opteof) { + switch (opt) { case 'n': flagdoit = 0; break; case 'N': flagdoit = 1; break; default: usage(); } + } argc -= optind; argv += optind; @@ -572,10 +584,12 @@ int main(int argc, char **argv) if (str_len(ext) > 1) { i = str_chr(local, *auto_break); if (!stralloc_copys(&envrecip, local + i + 1)) temp_nomem(); - } else + } else { +#else + { #endif - if (!stralloc_copys(&envrecip, local)) - temp_nomem(); + if (!stralloc_copys(&envrecip, local)) temp_nomem(); + } if (!stralloc_cats(&envrecip, "@")) temp_nomem(); if (!stralloc_cats(&envrecip, host)) temp_nomem(); @@ -708,7 +722,7 @@ int main(int argc, char **argv) numforward = 0; i = 0; - for (j = 0; j < cmds.len; ++j) + for (j = 0; j < cmds.len; ++j) { if (cmds.s[j] == '\n') { switch (cmds.s[i]) { case '#': @@ -719,6 +733,7 @@ int main(int argc, char **argv) } i = j + 1; } + } recips = (char **)alloc((numforward + 1) * sizeof(char *)); if (!recips) temp_nomem(); @@ -727,12 +742,13 @@ int main(int argc, char **argv) flag99 = 0; i = 0; - for (j = 0; j < cmds.len; ++j) + for (j = 0; j < cmds.len; ++j) { if (cmds.s[j] == '\n') { cmds.s[j] = 0; k = j; /* Patch contributed by Erik Sjolund <erik.sjolund@gmail.com>. */ while ((k > i) && ((cmds.s[k - 1] == ' ') || (cmds.s[k - 1] == '\t'))) cmds.s[--k] = 0; + switch (cmds.s[i]) { case 0: /* k == i */ if (i) break; @@ -777,12 +793,12 @@ int main(int argc, char **argv) i = j + 1; if (flag99) break; } + } - if (numforward) - if (flagdoit) { - recips[numforward] = 0; - mailforward(recips); - } + if (numforward && flagdoit) { + recips[numforward] = 0; + mailforward(recips); + } count_print(); _exit(0); diff --git a/src/qmail-mfrules.c b/src/qmail-mfrules.c index 7247cf7..c913cda 100644 --- a/src/qmail-mfrules.c +++ b/src/qmail-mfrules.c @@ -19,8 +19,6 @@ #define WHO "qmail-mfrules" -int rename(const char *, const char *); // stdio.h - stralloc address = {0}; stralloc data = {0}; stralloc key = {0}; @@ -39,15 +37,18 @@ void die_nomem() { logmsg(WHO, 112, FATAL, "out of memory"); } + void die_parse() { if (!stralloc_0(&line)) die_nomem(); logmsg(WHO, 100, ERROR, B("unable to parse this line: ", line.s)); } + void die_read() { logmsg(WHO, 111, ERROR, "unable to read control/mailfromrules"); } + void die_write() { logmsg(WHO, 111, ERROR, "unable to write to control/mailfromrules.tmp"); @@ -71,7 +72,7 @@ void doaddressdata() unsigned long bot; unsigned long top; - if (byte_chr(address.s, address.len, '=') == address.len) + if (byte_chr(address.s, address.len, '=') == address.len) { if (byte_chr(address.s, address.len, '@') == address.len) { i = byte_chr(address.s, address.len, '-'); if (i < address.len) { @@ -100,6 +101,7 @@ void doaddressdata() return; } } + } case_lowerb(address.s, address.len); case_lowerb(data.s, data.len); diff --git a/src/qmail-mrtg.c b/src/qmail-mrtg.c index cecd067..bcf4d01 100644 --- a/src/qmail-mrtg.c +++ b/src/qmail-mrtg.c @@ -199,14 +199,14 @@ void mrtg_sendlog(char *in, char flag) if (case_starts(in + i, "success:")) success++; i = str_chr(in, 'T'); if (case_starts(in + i, "TLS_")) tlstrans++; - }; + } break; case '2': if (case_starts(in, "info msg")) { i = str_chr(in, ':') + 8; if ((j = str_chr(in + i, ' '))) in[i + j] = '\0'; bytes += atoi(in + i); - }; + } break; case '3': if (case_starts(in, "status:")) { @@ -216,14 +216,14 @@ void mrtg_sendlog(char *in, char flag) if (atoi(in + i) > local) local = atoi(in + i); if ((j = str_chr(in + k, '/'))) in[k + j] = '\0'; if (atoi(in + k) > remote) remote = atoi(in + k); - }; + } break; case '4': if (case_starts(in, "delivery")) { i = str_chr(in, ':') + 2; if (case_starts(in + i, "failure:")) failure++; if (case_starts(in + i, "deferral:")) deferral++; - }; + } break; case '5': if (case_starts(in, "bounce msg")) bounces++; @@ -234,7 +234,7 @@ void mrtg_sendlog(char *in, char flag) i = str_chr(in, 'q'); if (case_starts(in + i, "qmtp:_ok")) qmtp++; if (case_starts(in + i, "qmtps:_ok")) qmtps++; - }; + } break; default: break; } @@ -326,7 +326,7 @@ void mrtg_pop3log(char *in, char flag) i = str_chr(in, ':') + 2; if (case_starts(in + i, "ok")) pok++; if (case_starts(in + i, "deny")) pdeny++; - }; + } break; default: break; } @@ -353,9 +353,9 @@ int main(int argc, char **argv) WHO, 100, USAGE, - "qmail-mrtg [ -1 | -2 | -3 | -4 | -5 | -6 |\ - -a | -b | -c | -d | -e | -f | -g | -h | -i | -j | -k | -z | -A | -B ] [time] \n\ - qmail-mrtg needs to be called every [time] minutes (i.e. by crontab) - default 305 secs"); + "qmail-mrtg [ -1 | -2 | -3 | -4 | -5 | -6 | -a | -b | -c | -d | -e | -f " + "| -g | -h | -i | -j | -k | -z | -A | -B ] [time] \n" + "qmail-mrtg needs to be called every [time] minutes (i.e. by crontab) - default 305 secs"); flag = *(argv[1] + 1); if (argc == 3) { diff --git a/src/qmail-newmrh.c b/src/qmail-newmrh.c index 20945a4..023f51e 100644 --- a/src/qmail-newmrh.c +++ b/src/qmail-newmrh.c @@ -16,12 +16,11 @@ #define WHO "qmail-newmrh" -int rename(const char *, const char *); // stdio.h - void die_read() { logmsg(WHO, 111, ERROR, "unable to read control/morercpthosts"); } + void die_write() { logmsg(WHO, 111, ERROR, "unable to write to control/morercpthosts.tmp"); diff --git a/src/qmail-newu.c b/src/qmail-newu.c index f2e33cd..ee836bb 100644 --- a/src/qmail-newu.c +++ b/src/qmail-newu.c @@ -17,36 +17,41 @@ #define WHO "qmail-newu" -int rename(const char *, const char *); // stdio.h - void die_chdir() { logmsg(WHO, 110, ERROR, "unable to chdir"); } + void die_nomem() { logmsg(WHO, 111, FATAL, "fatal: out of memory"); } + void die_opena() { logmsg(WHO, 112, ERROR, "unable to open users/assign"); } + void die_reada() { logmsg(WHO, 110, ERROR, "unable to read users/assign"); } + void die_format() { logmsg(WHO, 112, ERROR, "bad format in users/assign"); } + void die_opent() { logmsg(WHO, 112, ERROR, "unable to open users/assign.cdb.tmp"); } + void die_writet() { logmsg(WHO, 112, ERROR, "unable to write users/assign.cdb.tmp"); } + void die_rename() { logmsg(WHO, 112, ERROR, "unable to move users/cdb.tmp to users/assign.cdb"); @@ -112,11 +117,12 @@ int main() if (!stralloc_copyb(&data, line.s + i + 1, line.len - i - 1)) die_nomem(); numcolons = 0; - for (i = 0; i < data.len; ++i) + for (i = 0; i < data.len; ++i) { if (data.s[i] == ':') { data.s[i] = 0; if (++numcolons == 6) break; } + } if (numcolons < 6) die_format(); data.len = i; diff --git a/src/qmail-pop3d.c b/src/qmail-pop3d.c index bd46d7b..795bedc 100644 --- a/src/qmail-pop3d.c +++ b/src/qmail-pop3d.c @@ -2,6 +2,8 @@ #include <sys/types.h> #include <unistd.h> +#include <stdio.h> + #include "alloc.h" #include "buffer.h" #include "exit.h" @@ -21,8 +23,6 @@ #define FDIN 0 #define FDOUT 1 -int rename(const char *, const char *); // stdio.h - void die() { _exit(0); @@ -54,14 +54,17 @@ void out(char *buf, int len) { buffer_put(&bo, buf, len); } + void outs(char *s) { buffer_puts(&bo, s); } + void flush() { buffer_flush(&bo); } + void err(char *s) { outs("-ERR "); @@ -75,11 +78,13 @@ void die_nomem() err("out of memory"); die(); } + void die_nomaildir() { err("this user has no $HOME/Maildir"); die(); } + void die_scan() { err("unable to scan $HOME/Maildir"); @@ -90,26 +95,32 @@ void err_syntax() { err("syntax error"); } + void err_unimpl() { err("unimplemented"); } + void err_deleted() { err("already deleted"); } + void err_nozero() { err("messages are counted from 1"); } + void err_toobig() { err("not that many messages"); } + void err_nosuch() { err("unable to open that message"); } + void err_nounlink() { err("unable to unlink all deleted messages"); @@ -233,7 +244,7 @@ void pop3_quit() { int i; - for (i = 0; i < numm; ++i) + for (i = 0; i < numm; ++i) { if (m[i].flagdeleted) { if (unlink(m[i].fn) == -1) err_nounlink(); } else { @@ -245,6 +256,7 @@ void pop3_quit() rename(m[i].fn, line.s); /* if it fails, bummer */ } } + } okay(); die(); } @@ -318,6 +330,7 @@ void pop3_uidl(char *arg) { dolisting(arg, 1); } + void pop3_list(char *arg) { dolisting(arg, 0); diff --git a/src/qmail-popup.c b/src/qmail-popup.c index 832a56f..e94e9a7 100644 --- a/src/qmail-popup.c +++ b/src/qmail-popup.c @@ -20,10 +20,11 @@ #include "tls_start.h" #define PORT_POP3S "995" -#define FDIN 0 -#define FDOUT 1 -#define FDAUTH 3 -#define FDLOG 5 + +#define FDIN 0 +#define FDOUT 1 +#define FDAUTH 3 +#define FDLOG 5 void die() { @@ -56,10 +57,12 @@ void outs(char *s) { buffer_puts(&bo, s); } + void flush() { buffer_flush(&bo); } + void err(char *s) { outs("-ERR "); @@ -84,11 +87,13 @@ void logs(char *s) { if (buffer_puts(&bl, s) == -1) _exit(1); } + void logp(char *s) { logs(" P:"); logs(s); } + void logh(char *s1, char *s2) { logs(" S:"); @@ -96,17 +101,20 @@ void logh(char *s1, char *s2) logs(":"); logs(s2); } + void logu(char *s) { logs(" ?~ '"); logs(s); logs("'"); } + void logn(char *s) { if (buffer_puts(&bl, s) == -1) _exit(1); if (buffer_flush(&bl) == -1) _exit(1); } + void logpid() { strnum[fmt_ulong(strnum, getpid())] = 0; @@ -114,6 +122,7 @@ void logpid() logs(strnum); logs(" "); } + void log_pop(char *s1, char *s2, char *s3, char *s4, char *s5, char *s6) { logpid(); @@ -128,39 +137,47 @@ void die_usage() err("usage: popup hostname subprogram"); die(); } + void die_nomem() { err("out of memory"); die(); } + void die_pipe() { err("unable to open pipe"); die(); } + void die_write() { err("unable to write pipe"); die(); } + void die_fork() { err("unable to fork"); die(); } + void die_childcrashed() { err("aack, child crashed"); } + void die_badauth() { err("authorization failed"); } + void die_tls() { err("TLS startup failed"); die(); } + void die_notls() { err("TLS required but not negotiated"); @@ -172,10 +189,12 @@ void err_syntax() { err("syntax error"); } + void err_wantuser() { err("USER first"); } + void err_authoriz() { err("authorization first"); @@ -186,6 +205,7 @@ void okay() outs("+OK \r\n"); flush(); } + void pop3_quit() { okay(); @@ -257,8 +277,9 @@ void doanddie(char *user, unsigned int userlen, char *pass) /* userlen: includin if (wait_exitcode(wstat)) { die_badauth(); log_pop("Reject::AUTH::", auth.s, protocol.s, remoteip, remotehost, user); - } else + } else { log_pop("Accept::AUTH::", auth.s, protocol.s, remoteip, remotehost, user); + } die(); } @@ -272,9 +293,9 @@ void pop3_greet() *s++ = '@'; *s++ = 0; - if (!apop) + if (!apop) { outs("+OK\r\n"); - else { + } else { outs("+OK <"); outs(unique); outs(hostname); diff --git a/src/qmail-pw2u.c b/src/qmail-pw2u.c index 9b0a09b..b834301 100644 --- a/src/qmail-pw2u.c +++ b/src/qmail-pw2u.c @@ -281,8 +281,8 @@ int main(int argc, char **argv) int opt; int match; - while ((opt = getopt(argc, argv, "/ohHuUc:C")) != opteof) switch (opt) - { + while ((opt = getopt(argc, argv, "/ohHuUc:C")) != opteof) { + switch (opt) { case '/': dashcolon = "-/:"; break; case 'o': homestrategy = 2; break; case 'h': homestrategy = 1; break; @@ -294,6 +294,7 @@ int main(int argc, char **argv) case '?': default: _exit(100); } + } if (chdir(auto_qmail) == -1) die_chdir(); diff --git a/src/qmail-qmaint.c b/src/qmail-qmaint.c index 70605c8..df789e4 100644 --- a/src/qmail-qmaint.c +++ b/src/qmail-qmaint.c @@ -591,26 +591,32 @@ void fnmake_init() { while (!stralloc_ready(&fn, FMTQFN)) die_nomem(); } + void fnmake_local(unsigned long id) { fn.len = fmtqfn(fn.s, "local/", id, 1); } + void fnmake_remote(unsigned long id) { fn.len = fmtqfn(fn.s, "remote/", id, 1); } + void fnmake_mess(unsigned long id) { fn.len = fmtqfn(fn.s, "mess/", id, 1); } + void fnmake_dkim(unsigned long id) { fn.len = fmtqfn(fn.s, "dkim/", id, 1); } + void fnmake_info(unsigned long id) { fn.len = fmtqfn(fn.s, "info/", id, 1); } + void fnmake_bounce(unsigned long id) { fn.len = fmtqfn(fn.s, "bounce/", id, 0); @@ -715,8 +721,9 @@ int main(int argc, char **argv) if (flag_delete) { if (!delete_msg(id)) logmsg(WHO, 0, INFO, B("file ", mess, " from queue deleted.")); - } else if (fix_names()) + } else if (fix_names()) { die_check(); + } logmsg(WHO, 0, INFO, "done."); diff --git a/src/qmail-qmqpc.c b/src/qmail-qmqpc.c index 2bbfdfe..3817489 100644 --- a/src/qmail-qmqpc.c +++ b/src/qmail-qmqpc.c @@ -28,39 +28,48 @@ void die_success() { _exit(0); } + void die_perm() { _exit(31); } + void nomem() { _exit(51); } + void die_read() { if (errno == ENOMEM) nomem(); _exit(54); } + void die_control() { _exit(55); } + void die_socket() { _exit(56); } + void die_home() { _exit(61); } + void die_temp() { _exit(71); } + void die_conn() { _exit(74); } + void die_format() { _exit(91); diff --git a/src/qmail-qmqpd.c b/src/qmail-qmqpd.c index b949338..db71d61 100644 --- a/src/qmail-qmqpd.c +++ b/src/qmail-qmqpd.c @@ -153,21 +153,22 @@ int main() } getcomma(); - if (getbuf()) + if (getbuf()) { qmail_from(&qq, buf); - else { + } else { qmail_from(&qq, ""); qmail_fail(&qq); flagok = 0; } - while (bytesleft) - if (getbuf()) + while (bytesleft) { + if (getbuf()) { qmail_to(&qq, buf); - else { + } else { qmail_fail(&qq); flagok = 0; } + } bytesleft = 1; getcomma(); diff --git a/src/qmail-qmtpd.c b/src/qmail-qmtpd.c index 8ae81e0..b3a121d 100644 --- a/src/qmail-qmtpd.c +++ b/src/qmail-qmtpd.c @@ -29,6 +29,7 @@ void badproto() { _exit(100); } + void resources() { _exit(111); @@ -233,7 +234,7 @@ int main() /* XXX: check for loops? only if len is big? */ - if (flagdos) + if (flagdos) { while (len > 0) { buffer_get(&bi, &ch, 1); --len; @@ -249,12 +250,11 @@ int main() if (!--bytestooverflow) qmail_fail(&qq); qmail_put(&qq, &ch, 1); } - else { - if (databytes) - if (len > databytes) { - bytestooverflow = 0; - qmail_fail(&qq); - } + } else { + if (databytes && len > databytes) { + bytestooverflow = 0; + qmail_fail(&qq); + } while (len > 0) { /* XXX: could speed this up, obviously */ buffer_get(&bi, &ch, 1); --len; @@ -330,9 +330,9 @@ int main() if (databytes) if (!bytestooverflow) result = "D Sorry, that message size exceeds my databytes limit (#5.3.4)"; - if (*result) + if (*result) { len = str_len(result); - else { + } else { /* success! */ len = 0; len += fmt_str(buf2 + len, "K Ok "); @@ -348,14 +348,15 @@ int main() len += fmt_str(buf + len, result); buf[len++] = ','; - for (i = 0; i < failure.len; ++i) switch (failure.s[i]) - { + for (i = 0; i < failure.len; ++i) { + switch (failure.s[i]) { case 0: buffer_put(&bo, buf, len); break; case 'D': buffer_puts(&bo, "66:D Sorry, that domain isn't in my list of allowed rcpthosts (#5.7.1),"); break; default: buffer_puts(&bo, "46:D Sorry, I can't handle that recipient (#5.1.3),"); break; } + } /* bo will be flushed when we read from the network again */ } diff --git a/src/qmail-qread.c b/src/qmail-qread.c index 039af0c..8fbc96f 100644 --- a/src/qmail-qread.c +++ b/src/qmail-qread.c @@ -40,11 +40,13 @@ void die_nomem() buffer_puts(buffer_1, "fatal: out of memory\n"); die(111); } + void die_chdir() { warn("fatal: unable to chdir", ""); die(110); } + void die_opendir(fn) char *fn; { warn("fatal: unable to opendir ", fn); @@ -123,10 +125,12 @@ void out(char *s, unsigned int n) ++s; } } + void outs(char *s) { out(s, str_len(s)); } + void outok(char *s) { buffer_puts(buffer_1, s); @@ -155,7 +159,7 @@ int main() if (chdir("queue") == -1) die_chdir(); readsubdir_init(&rs, "info", die_opendir); - while ((x = readsubdir_next(&rs, &id))) + while ((x = readsubdir_next(&rs, &id))) { if (x > 0) { fmtqfn(fnmess, "mess/", id, 1); fmtqfn(fninfo, "info/", id, 1); @@ -208,6 +212,7 @@ int main() } } } + } die(0); } diff --git a/src/qmail-queue.c b/src/qmail-queue.c index ee9a3df..26807b2 100644 --- a/src/qmail-queue.c +++ b/src/qmail-queue.c @@ -62,25 +62,30 @@ void die(int e) { _exit(e); } + void die_qhpsi() { cleanup(); die(71); } + void die_write() { cleanup(); die(53); } + void die_read() { cleanup(); die(54); } + void sigalrm() { /* thou shalt not clean up here */ die(52); } + void sigbug() { die(81); @@ -263,8 +268,9 @@ void qhpsiprog(char *arg) if (childrc == qhpsirc) { cleanup(); die(32); - } else if (childrc != 0) + } else if (childrc != 0) { die_qhpsi(); + } } } diff --git a/src/qmail-recipients.c b/src/qmail-recipients.c index 4fb2fb8..81230fe 100644 --- a/src/qmail-recipients.c +++ b/src/qmail-recipients.c @@ -1,6 +1,8 @@ #include <sys/stat.h> #include <unistd.h> +#include <stdio.h> // rename + #include "buffer.h" #include "case.h" #include "cdbmake.h" @@ -14,12 +16,11 @@ #define WHO "qmail-recipients" -int rename(const char *, const char *); // stdio.h - void die_read() { logmsg(WHO, 111, ERROR, "unable to read users/recipients"); } + void die_write() { logmsg(WHO, 111, ERROR, "unable to write to users/recipients.tmp"); diff --git a/src/qmail-remote.c b/src/qmail-remote.c index 2a7498c..ddb4d65 100644 --- a/src/qmail-remote.c +++ b/src/qmail-remote.c @@ -1,6 +1,3 @@ -#ifdef IDN2 - #include <idn2.h> -#endif #include <arpa/inet.h> #include <netinet/in.h> #include <sys/socket.h> @@ -42,6 +39,10 @@ #include "tls_timeoutio.h" #include "ucspissl.h" +#ifdef IDN2 + #include <idn2.h> +#endif + #define WHO "qmail-remote" #define MAX_SIZE 200000000 @@ -60,18 +61,19 @@ unsigned long port = PORT_SMTP; int flagauth = 0; /* 1 = login; 2 = plain; 3 = crammd5 */ int flagsmtps = 0; /* RFC 8314 - 'implicit TLS' */ int flagtlsdomain = 0; /* 0 = no; 1 = yes; 2 = cert */ -int flagtls = 0; /* flagtls: XYZ +int flagtls = 0; /* flagtls: XYZ (mode) Z: -2 = rejected; -1 = not; 0 = no, default; Z > 0 see tls_remote.c (prot) Y: 0 = StartTLS; 1 = SMTPS; 2 = QMTPS (active) X: 1 = running TLS connection (after DNS lookup) (done) Z: 1: CA chain; 2: Cert wildname; 3: Cert exactname; 4: Cert fingerprint; 5: TLSA record */ -int flagverify = 0; /* 1 = verify Cert against CA; 2 = verify against Dir; 3 = triggerd by TLSA; +int flagverify = 0; /* 1 = verify Cert against CA; 2 = verify against Dir; 3 = triggerd by TLSA; -2 = Cert pinning; -1 = no TLSA validation */ int flagutf8 = 0; -GEN_ALLOC_typedef(saa, stralloc, sa, len, a) GEN_ALLOC_readyplus( - saa, stralloc, sa, len, a, i, n, x, 10, saa_readyplus) static stralloc sauninit = {0}; +GEN_ALLOC_typedef(saa, stralloc, sa, len, a); +GEN_ALLOC_readyplus(saa, stralloc, sa, len, a, i, n, x, 10, saa_readyplus); +static stralloc sauninit = {0}; stralloc helohost = {0}; stralloc eaihost = {0}; @@ -113,10 +115,12 @@ void out(char *s) { if (buffer_puts(&bs, s) == -1) _exit(0); } + void zero() { if (buffer_put(&bs, "\0", 1) == -1) _exit(0); } + void zerodie() { zero(); @@ -143,16 +147,19 @@ void temp_noip() out("ZInvalid ipaddr in control/domainips (#4.3.0)\n"); zerodie(); } + void temp_nomem() { out("ZOut of memory. (#4.3.0)\n"); zerodie(); } + void temp_oserr() { out("ZSystem resources temporarily unavailable. (#4.3.0)\n"); zerodie(); } + void temp_osip() { out("ZCan't bind to local ip address: "); @@ -160,6 +167,7 @@ void temp_osip() out(". (#4.3.0)\n"); zerodie(); } + void temp_noconn() { out("ZSorry, I wasn't able to establish an SMTP connection: "); @@ -167,6 +175,7 @@ void temp_noconn() out(". (#4.3.0)\n"); zerodie(); } + void temp_qmtpnoc() { out("ZSorry, I wasn't able to establish an QMTP connection: "); @@ -174,11 +183,13 @@ void temp_qmtpnoc() out(". (#4.3.1)\n"); zerodie(); } + void temp_read() { out("ZUnable to read message. (#4.3.0)\n"); zerodie(); } + void temp_dnscanon() { out("ZCNAME lookup failed temporarily for: "); @@ -186,6 +197,7 @@ void temp_dnscanon() out(". (#4.4.3)\n"); zerodie(); } + void temp_dns() { out("ZSorry, I couldn't find any host named: "); @@ -193,6 +205,7 @@ void temp_dns() out(". (#4.1.2)\n"); zerodie(); } + void temp_nomx() { out("ZSorry, I couldn't find a mail exchanger or IP address for: "); @@ -200,31 +213,37 @@ void temp_nomx() out(". Will try again. (#4.1.2)\n"); zerodie(); } + void temp_chdir() { out("ZUnable to switch to home directory. (#4.3.0)\n"); zerodie(); } + void temp_control() { out("ZUnable to read control files. (#4.3.0)\n"); zerodie(); } + void perm_partialline() { out("DSMTP cannot transfer messages with partial final lines. (#5.6.2)\n"); zerodie(); } + void temp_proto() { out("ZRecipient did not talk proper QMTP (#4.3.0)\n"); zerodie(); } + void perm_usage() { out("Dqmail-remote was invoked improperly. (#5.3.5)\n"); zerodie(); } + void perm_dns() { out("DSorry, I couldn't find any host named: "); @@ -232,6 +251,7 @@ void perm_dns() out(". (#5.1.2)\n"); zerodie(); } + void perm_nomx() { out("DSorry, I couldn't find a mail exchanger or IP address for: "); @@ -239,12 +259,14 @@ void perm_nomx() out(". (#5.4.4)\n"); zerodie(); } + void perm_ambigmx() { - out("DSorry. Although I'm listed as a best-preference MX or A for that host,\n\ -it isn't in my control/locals file, so I don't treat it as local. (#5.4.6)\n"); + out("DSorry. Although I'm listed as a best-preference MX or A for that host,\n" + "it isn't in my control/locals file, so I don't treat it as local. (#5.4.6)\n"); zerodie(); } + void err_authprot() { out("KNo supported AUTH method found, continuing without authentication.\n"); @@ -433,13 +455,14 @@ void tls_init() /* Prepare for Certificate Request */ - if (flagtlsdomain == 2) switch (tls_certkey(ctx, certfile.s, keyfile.s, keypwd.s)) - { + if (flagtlsdomain == 2) { + switch (tls_certkey(ctx, certfile.s, keyfile.s, keypwd.s)) { case 0: break; case -1: temp_tlscert(); case -2: temp_tlskey(); case -3: temp_tlschk(); } + } /* Set SSL Context */ @@ -591,12 +614,12 @@ int flagsize = 0; int smtp_size() { int i; - if (smtptext.len > 10) + if (smtptext.len > 10) { for (i = 0; i < smtptext.len; ++i) { if (case_starts(smtptext.s + i, "SIZE ")) return 1; } + } return 0; - ; } void smtp_greeting() @@ -807,7 +830,7 @@ void smtp_auth() { int i; - if (smtptext.len > 8) + if (smtptext.len > 8) { for (i = 4; i < smtptext.len - 5; ++i) { if (case_starts(smtptext.s + i, "CRAM")) if (mailfrom_cram() >= 0) return; @@ -816,6 +839,7 @@ void smtp_auth() if (case_starts(smtptext.s + i, "PLAIN")) if (mailfrom_plain() >= 0) return; } + } err_authprot(); mailfrom(); } @@ -841,9 +865,9 @@ void smtp() smtp_greeting(); if (flagtls > 0 && flagtls < 10) { /* STARTTLS */ - if (starttls_peer()) + if (starttls_peer()) { smtp_starttls(); - else if (flagtls > 3 && flagtls != 9) { + } else if (flagtls > 3 && flagtls != 9) { if (!stralloc_0(&host)) temp_nomem(); temp_tlshost(); } @@ -1019,9 +1043,9 @@ void qmtp() if (ch != ',') temp_proto(); smtptext.s[smtptext.len - 1] = '\n'; - if (smtptext.s[0] == 'K') + if (smtptext.s[0] == 'K') { out("r"); - else if (smtptext.s[0] == 'D') { + } else if (smtptext.s[0] == 'D') { out("h"); flagallok = 0; } else { /* if (smtptext.s[0] == 'Z') */ @@ -1350,8 +1374,8 @@ int main(int argc, char **argv) } /* cafile starts with '=' => it is a fingerprint - cafile ends with '/' => consider it as cadir - cafile and cadir are now 0-terminated + cafile ends with '/' => consider it as cadir + cafile and cadir are now 0-terminated ciphers are alway 0-terminated if given */ if (cafile.len > 2) { @@ -1365,14 +1389,15 @@ int main(int argc, char **argv) if (cafile.s[0] == '=') flagverify = -2; if (!stralloc_0(&cafile)) temp_nomem(); } - } else + } else { cafile.len = cadir.len = 0; + } - if (ciphers.len > 4) /* otherwise garbage */ - if (!stralloc_0(&ciphers)) - temp_nomem(); - else - ciphers.len = 0; + if (ciphers.len > 4) { /* otherwise garbage */ + if (!stralloc_0(&ciphers)) temp_nomem(); + } else { + ciphers.len = 0; + } if (port == PORT_SMTPS || flagsmtps) flagtls += 10; if (port == PORT_QMTPS) flagtls += 20; diff --git a/src/qmail-rspawn.c b/src/qmail-rspawn.c index 939488d..4ef24e7 100644 --- a/src/qmail-rspawn.c +++ b/src/qmail-rspawn.c @@ -46,7 +46,7 @@ void report(buffer *log, int wstat, char *s, int len) result = -1; j = 0; - for (k = 0; k < len; ++k) + for (k = 0; k < len; ++k) { if (!s[k]) { if (s[j] == 'K') { result = 1; @@ -59,6 +59,7 @@ void report(buffer *log, int wstat, char *s, int len) if (s[j] == 'D') break; j = k + 1; } + } orr = result; @@ -73,18 +74,19 @@ void report(buffer *log, int wstat, char *s, int len) case -1: buffer_put(log, "D", 1); break; } - for (k = 1; k < len;) + for (k = 1; k < len;) { if (!s[k++]) { buffer_puts(log, s + 1); - if (result <= orr) - if (k < len) switch (s[k]) - { - case 'Z': - case 'D': - case 'K': buffer_puts(log, s + k + 1); - } + if (result <= orr && k < len) { + switch (s[k]) { + case 'Z': + case 'D': + case 'K': buffer_puts(log, s + k + 1); + } + } break; } + } } int spawn(int fdmess, int fdout, const char *s, char *r, const int at) diff --git a/src/qmail-send.c b/src/qmail-send.c index 5305d95..31aa60e 100644 --- a/src/qmail-send.c +++ b/src/qmail-send.c @@ -71,11 +71,13 @@ void sigterm() { flagexitasap = 1; } + int flagrunasap = 0; void sigalrm() { flagrunasap = 1; } + int flagreadasap = 0; void sighup() { @@ -118,26 +120,32 @@ void fnmake_info(unsigned long id) { fn.len = fmtqfn(fn.s, "info/", id, 1); } + void fnmake_todo(unsigned long id) { fn.len = fmtqfn(fn.s, "todo/", id, 1); } + void fnmake_mess(unsigned long id) { fn.len = fmtqfn(fn.s, "mess/", id, 1); } + void fnmake_foop(unsigned long id) { fn.len = fmtqfn(fn.s, "foop/", id, 0); } + void fnmake_split(unsigned long id) { fn.len = fmtqfn(fn.s, "", id, 1); } + void fnmake2_bounce(unsigned long id) { fn2.len = fmtqfn(fn2.s, "bounce/", id, 0); } + void fnmake_chanaddr(unsigned long id, int c) { fn.len = fmtqfn(fn.s, chanaddr[c], id, 1); @@ -153,7 +161,7 @@ void senderadd(stralloc *sa, char *sender, char *recip) int k; i = str_len(sender); - if (i >= 4) + if (i >= 4) { if (str_equal(sender + i - 4, "-@[]")) { j = byte_rchr(sender, i - 4, '@'); k = str_rchr(recip, '@'); @@ -168,6 +176,7 @@ void senderadd(stralloc *sa, char *sender, char *recip) return; } } + } while (!stralloc_cats(sa, sender)) nomem(); } @@ -256,21 +265,23 @@ void comm_selprep(int *nfds, fd_set *wfds) { int c; - for (c = 0; c < CHANNELS; ++c) - if (flagspawnalive[c]) + for (c = 0; c < CHANNELS; ++c) { + if (flagspawnalive[c]) { if (comm_buf[c].s && comm_buf[c].len) { FD_SET(chanfdout[c], wfds); if (*nfds <= chanfdout[c]) *nfds = chanfdout[c] + 1; } + } + } } void comm_do(fd_set *wfds) { int c; - for (c = 0; c < CHANNELS; ++c) - if (flagspawnalive[c]) - if (comm_buf[c].s && comm_buf[c].len) + for (c = 0; c < CHANNELS; ++c) { + if (flagspawnalive[c]) { + if (comm_buf[c].s && comm_buf[c].len) { if (FD_ISSET(chanfdout[c], wfds)) { int w; int len; @@ -287,6 +298,9 @@ void comm_do(fd_set *wfds) if (comm_pos[c] == len) comm_buf[c].len = 0; } } + } + } + } } @@ -432,7 +446,7 @@ void pqfinish() struct prioq_elt pe; time_t ut[2]; /* XXX: more portable than utimbuf, but still worrisome */ - for (c = 0; c < CHANNELS; ++c) + for (c = 0; c < CHANNELS; ++c) { while (prioq_min(&pqchan[c], &pe)) { prioq_delmin(&pqchan[c]); fnmake_chanaddr(pe.id, c); @@ -440,6 +454,7 @@ void pqfinish() if (utime(fn.s, ut) == -1) log3s("warning: unable to utime ", fn.s, "; message will be retried too soon\n"); } + } } void pqrun() @@ -555,8 +570,8 @@ char *stripvdomprepend(char *recip) domain = recip + i + 1; domainlen = str_len(domain); - for (i = 0; i <= domainlen; ++i) - if ((i == 0) || (i == domainlen) || (domain[i] == '.')) + for (i = 0; i <= domainlen; ++i) { + if ((i == 0) || (i == domainlen) || (domain[i] == '.')) { if ((prepend = constmap(&mapvdoms, domain + i, domainlen - i))) { if (!*prepend) break; i = str_len(prepend); @@ -564,6 +579,8 @@ char *stripvdomprepend(char *recip) if (recip[i] != '-') break; return recip + i + 1; } + } + } return recip; } @@ -610,8 +627,9 @@ void addbounce(unsigned long id, char *recip, char *report) if (w <= 0) { log1s("alert: unable to append to bounce message; HELP! sleeping...\n"); sleep(10); - } else + } else { pos += w; + } } close(fd); } @@ -637,11 +655,10 @@ int injectbounce(unsigned long id) if (!getinfo(&sender, &birth, id)) return 0; /* XXX: print warning */ /* owner-@host-@[] -> owner-@host */ - if (sender.len >= 5) - if (str_equal(sender.s + sender.len - 5, "-@[]")) { - sender.len -= 4; - sender.s[sender.len - 1] = 0; - } + if (sender.len >= 5 && str_equal(sender.s + sender.len - 5, "-@[]")) { + sender.len -= 4; + sender.s[sender.len - 1] = 0; + } fnmake2_bounce(id); fnmake_mess(id); @@ -652,11 +669,11 @@ int injectbounce(unsigned long id) return 0; } - if (str_equal(sender.s, "#@[]")) + if (str_equal(sender.s, "#@[]")) { log3s("triple bounce: discarding ", fn2.s, "\n"); - else if (!*sender.s && *doublebounceto.s == '@') + } else if (!*sender.s && *doublebounceto.s == '@') { log3s("double bounce: discarding ", fn2.s, "\n"); - else { + } else { if (qmail_open(&qqt) == -1) { log1s("warning: unable to start qmail-queue, will try later\n"); return 0; @@ -701,9 +718,9 @@ I tried to deliver a bounce message to this address, but the bounce bounced!\n\ "); fd = open_read(fn2.s); - if (fd == -1) + if (fd == -1) { qmail_fail(&qqt); - else { + } else { buffer_init(&bi, read, fd, inbuf, sizeof(inbuf)); while ((r = buffer_get(&bi, buf, sizeof(buf))) > 0) qmail_put(&qqt, buf, r); @@ -721,9 +738,9 @@ I tried to deliver a bounce message to this address, but the bounce bounced!\n\ qmail_puts(&qqt, ">\n"); fd = open_read(fn.s); - if (fd == -1) + if (fd == -1) { qmail_fail(&qqt); - else { + } else { if (bouncemaxbytes) { bytestogo = bouncemaxbytes; bytestoget = (bytestogo < sizeof(buf)) ? bytestogo : sizeof(buf); @@ -926,9 +943,9 @@ void del_dochan(int c) if (!ch && (dline[c].len > 1)) { delnum = (unsigned int)(unsigned char)dline[c].s[0]; - if ((delnum < 0) || (delnum >= concurrency[c]) || !d[c][delnum].used) + if ((delnum < 0) || (delnum >= concurrency[c]) || !d[c][delnum].used) { log1s("warning: internal error: delivery report out of range\n"); - else { + } else { strnum3[fmt_ulong(strnum3, d[c][delnum].delid)] = 0; if (dline[c].s[1] == 'Z') if (jo[d[c][delnum].j].flagdying) { @@ -1122,11 +1139,11 @@ void pass_dochan(int c) } switch (line.s[0]) { + case 'D': break; case 'T': ++jo[pass[c].j].numtodo; del_start(pass[c].j, pass[c].mpos, line.s + 1); break; - case 'D': break; default: fnmake_chanaddr(pass[c].id, c); log3s("warning: unknown record type in ", fn.s, "!\n"); diff --git a/src/qmail-showctl.c b/src/qmail-showctl.c index 7aaeb95..6339707 100644 --- a/src/qmail-showctl.c +++ b/src/qmail-showctl.c @@ -74,12 +74,13 @@ void do_str(char *fn, int flagme, char *def, char *pre) if (!stralloc_copys(&line, def)) { buffer_puts(buffer_1, "Oops! Out of memory.\n"); break; - }; - if (flagme && meok) + } + if (flagme && meok) { if (!stralloc_copy(&line, &me)) { buffer_puts(buffer_1, "Oops! Out of memory.\n"); break; - }; + } + } case 1: buffer_puts(buffer_1, pre); safeput(line.s, line.len); @@ -106,7 +107,7 @@ int do_lst(char *fn, char *def, char *pre, char *post) case 1: buffer_puts(buffer_1, "\n"); i = 0; - for (j = 0; j < line.len; ++j) + for (j = 0; j < line.len; ++j) { if (!line.s[j]) { buffer_puts(buffer_1, pre); safeput(line.s + i, j - i); @@ -114,6 +115,7 @@ int do_lst(char *fn, char *def, char *pre, char *post) buffer_puts(buffer_1, "\n"); i = j + 1; } + } return 1; default: buffer_puts(buffer_1, "Oops! Trouble reading this file.\n"); return -1; } diff --git a/src/qmail-smtpam.c b/src/qmail-smtpam.c index 89105c3..77f0718 100644 --- a/src/qmail-smtpam.c +++ b/src/qmail-smtpam.c @@ -38,19 +38,20 @@ #define MAX_SIZE 200000000 #define HUGESMTPTEXT 5000 -#define PORT_SMTP 25 /* silly rabbit, /etc/services is for users */ +#define PORT_SMTP 25 // silly rabbit, /etc/services is for users #define PORT_SMTPS 465 #define VERIFYDEPTH 1 #define FDPAM 3 #define WHO "qmail-smtpam" -/** @file qmail-smtpam.c -- TLS enabled SMTP PAM to check mailbox at remote MX - */ +/** + * @file qmail-smtpam.c -- TLS enabled SMTP PAM to check mailbox at remote MX + */ int flagauth = 0; /* 1 = login; 2 = plain; 3 =crammd5 */ int flagsmtps = 0; /* RFC 8314 - 'implicit TLS' */ -int flagtls = 0; /* -2 = rejected; -1 = not; 0 = no, default; +int flagtls = 0; /* -2 = rejected; -1 = not; 0 = no, default; > 0 see tls_remote.c +10 = SMTPS; +20 = QMTPS; 100 = active TLS connection */ int flagverify = 0; /* 1 = verify Cert against CA ; -1 = Cert pinning */ @@ -58,10 +59,10 @@ int flagutf8mail = 0; unsigned long port = PORT_SMTP; -GEN_ALLOC_typedef(saa, stralloc, sa, len, a) - GEN_ALLOC_readyplus(saa, stralloc, sa, len, a, i, n, x, 10, saa_readyplus) +GEN_ALLOC_typedef(saa, stralloc, sa, len, a); +GEN_ALLOC_readyplus(saa, stralloc, sa, len, a, i, n, x, 10, saa_readyplus); - stralloc helohost = {0}; +stralloc helohost = {0}; stralloc host = {0}; stralloc ports = {0}; stralloc remotehost = {0}; @@ -89,16 +90,19 @@ void out(char *s) { if (buffer_puts(buffer_1small, s) == -1) _exit(111); } + void zero() { if (buffer_put(buffer_1small, "\0", 1) == -1) _exit(111); } + void zerodie() { zero(); buffer_flush(buffer_1small); _exit(111); } + void outsafe(stralloc *sa) { int i; @@ -116,16 +120,19 @@ void temp_noip() out("Zinvalid ipaddr in control/domainips (#4.3.0)\n"); zerodie(); } + void temp_nomem() { out("ZOut of memory. (#4.3.0)\n"); zerodie(); } + void temp_oserr() { out("ZSystem resources temporarily unavailable. (#4.3.0)\n"); zerodie(); } + void temp_osip() { out("ZCan't bind to local ip address: "); @@ -133,11 +140,13 @@ void temp_osip() out(". (#4.3.0)\n"); zerodie(); } + void temp_noconn() { out("ZSorry, I wasn't able to establish an SMTP connection. (#4.4.1)\n"); zerodie(); } + void temp_dnscanon() { out("ZCNAME lookup failed temporarily for: "); @@ -145,6 +154,7 @@ void temp_dnscanon() out(". (#4.4.3)\n"); zerodie(); } + void temp_dns() { out("ZSorry, I couldn't find any host named: "); @@ -152,21 +162,25 @@ void temp_dns() out(". (#4.1.2)\n"); zerodie(); } + void temp_chdir() { out("ZUnable to switch to home directory. (#4.3.0)\n"); zerodie(); } + void temp_control() { out("ZUnable to read control files. (#4.3.0)\n"); zerodie(); } + void perm_usage() { out("Dqmail-smtpam was invoked improperly. (#5.3.5)\n"); zerodie(); } + void perm_dns() { out("DSorry, I couldn't find any host named: "); @@ -174,6 +188,7 @@ void perm_dns() out(". (#5.1.2)\n"); zerodie(); } + void outhost() { char ipaddr[IPFMT]; @@ -262,7 +277,7 @@ unsigned long smtpcode() void outsmtptext() { int i; - if (smtptext.s) + if (smtptext.s) { if (smtptext.len) { out("Remote host said: "); for (i = 0; i < smtptext.len; ++i) @@ -270,6 +285,7 @@ void outsmtptext() if (buffer_put(buffer_1small, smtptext.s, smtptext.len) == -1) _exit(111); smtptext.len = 0; } + } } void quit(char *prepend, char *append) @@ -443,12 +459,13 @@ void smtp() if (flagutf8mail) buffer_puts(&bo, " SMTPUTF8"); - if (flagtls > 0 && flagtls < 10) /* STARTTLS */ + if (flagtls > 0 && flagtls < 10) { /* STARTTLS */ if (starttls_peer()) { smtp_starttls(); } else if (flagtls > 2) { temp_tlshost(); } + } buffer_puts(&bo, "MAIL FROM:<>"); if (flagutf8mail) buffer_puts(&bo, " SMTPUTF8"); diff --git a/src/qmail-smtpd.c b/src/qmail-smtpd.c index 6d2d0d4..035eecf 100644 --- a/src/qmail-smtpd.c +++ b/src/qmail-smtpd.c @@ -93,6 +93,7 @@ void flush() { buffer_flush(&bo); } // this triggers writing to STDIO + void out(char *s) { buffer_puts(&bo, s); @@ -121,8 +122,9 @@ int dnsq(char *arg, char type) at = byte_rchr(arg, len, '@'); if (at < len) { if (!stralloc_copyb(&sa, arg + at + 1, len - at - 1)) die_nomem(); - } else if (!stralloc_copyb(&sa, arg, len)) + } else if (!stralloc_copyb(&sa, arg, len)) { die_nomem(); + } random = now() + (getpid() << 16); @@ -150,10 +152,12 @@ void smtp_greet(char *code) buffer_puts(&bo, code); buffer_put(&bo, greeting.s, greeting.len); } + void smtp_help() { out("214 s/qmail home page: https://www.fehcom.de/sqmail.html\r\n"); } + void smtp_quit() { smtp_greet("221 "); @@ -247,8 +251,18 @@ static struct cdb cdbm; static struct cdb cdbl; static int fdbmt; -int flagmimetype = - 0; /* 1: white; 2: cdb; 3: white+cdb; 4: !relay+white; 6: !relay+white+cdb; -1: found in cdb; -2: found white */ + +/* + -2: found white + -1: found in cdb; + 1: white; + 2: cdb; + 3: white+cdb; + 4: !relay+white; + 6: !relay+white+cdb; +*/ +int flagmimetype = 0; + char *badmimeinit; static int fdblt; @@ -275,13 +289,32 @@ int greylist = 0; stralloc pgbind = {0}; char *auth; -int smtpauth = - 0; /* -1:Cert 0:none 1:login/plain 2:cram 3:login/plain/cram 11:must_login/plain 12:must_2 13:must_3 */ + +/* + -1: Cert + 0: none + 1: login/plain + 2: cram + 3: login/plain/cram + 11: must_login/plain + 12: must_2 + 13: must_3 +*/ +int smtpauth = 0; + int seenauth = 0; /* 1:ESMTPA 2:~CLIENTDN */ stralloc authmethod = {0}; -int starttls = - 0; /* -1:TLS 0:none 1:STARTTLS 2:require_STARTTLS 3:relay_if_CLIENTDN 4:require_+_relay_if_CLIENTDN */ +/* + -1: TLS + 0: none + 1: STARTTLS + 2: require_STARTTLS + 3: relay_if_CLIENTDN + 4: require_+_relay_if_CLIENTDN +*/ +int starttls = 0; + int seentls = 0; /* 1:~STARTTLS 2:~TLS 3:~CLIENTDN */ char *ucspitls = 0; char *tlsversion; @@ -344,8 +377,9 @@ void setup() remoteip = remoteip + 7; flagip6 = 0; } - } else + } else { flagip6 = 0; + } if (!remoteip) { remoteip = "unknown"; flagip6 = -1; @@ -375,7 +409,7 @@ void setup() if (x) { scan_ulong(x, &u); maxrcptcount = u; - }; + } if (!(maxrcptcount + 1)) --maxrcptcount; helocheck = env_get("HELOCHECK"); @@ -390,12 +424,12 @@ void setup() if (x) { scan_ulong(x, &u); tarpitcount = u; - }; + } x = env_get("TARPITDELAY"); if (x) { scan_ulong(x, &u); tarpitdelay = u; - }; + } x = env_get("POSTGREY"); // RFC 6647 if (x) { @@ -532,9 +566,9 @@ int modssl_info() cipherused = env_get("SSL_CIPHER_USEKEYSIZE"); if (!cipherused) cipherused = "unknown"; clientdn = env_get("SSL_CLIENT_S_DN"); - if (!clientdn) + if (!clientdn) { clientdn = "none"; - else { + } else { seentls = 3; seenauth = 2; smtpauth = -1; @@ -794,13 +828,14 @@ int brtcheck() } i = 0; - for (j = 0; j < brt.len; ++j) + for (j = 0; j < brt.len; ++j) { if (!brt.s[j]) { subvalue = brt.s[i] != '!'; if (!subvalue) i++; if ((k != subvalue) && wildmat(addr.s, brt.s + i)) k = subvalue; i = j + 1; } + } return k; } return 0; @@ -842,9 +877,9 @@ int localaddr(char *mf) if (localmf == 3) { if (!case_diffs(remoteinfo, mf)) return 2; return -3; - } else if (localmf == 2) + } else if (localmf == 2) { return mfrules(fdmav, remoteip, remotehost, remoteinfo, mf); - else { + } else { if (str_len(localmfcheck) > 1) { case_lowerb(localmfcheck, str_len(localmfcheck)); at = byte_rchr(mf, mflen, '@'); @@ -988,8 +1023,9 @@ void mailfrom_parms(char *arg) } if (case_starts(mfparms.s, "AUTH=")) mailfrom_auth(mfparms.s + 5, mfparms.len - 5); if (!stralloc_copys(&mfparms, "")) die_nomem(); - } else if (!stralloc_catb(&mfparms, arg, 1)) + } else if (!stralloc_catb(&mfparms, arg, 1)) { die_nomem(); + } } } } diff --git a/src/qmail-tcpto.c b/src/qmail-tcpto.c index b5100ef..7383be1 100644 --- a/src/qmail-tcpto.c +++ b/src/qmail-tcpto.c @@ -39,14 +39,17 @@ void die_chdir() { logmsg(WHO, 110, FATAL, "unable to chdir"); } + void die_open() { logmsg(WHO, 112, FATAL, "unable to open tcpto"); } + void die_lock() { logmsg(WHO, 112, FATAL, "unable to lock tcpto"); } + void die_read() { logmsg(WHO, 112, FATAL, "unable to read tcpto"); diff --git a/src/qmail-todo.c b/src/qmail-todo.c index 34be551..411f514 100644 --- a/src/qmail-todo.c +++ b/src/qmail-todo.c @@ -59,6 +59,7 @@ void sighup(void) { flagreadasap = 1; } + int flagsendalive = 1; void senddied(void) { @@ -85,14 +86,17 @@ void fnmake_info(unsigned long id) { fn.len = fmtqfn(fn.s, "info/", id, 1); } + void fnmake_todo(unsigned long id) { fn.len = fmtqfn(fn.s, "todo/", id, 1); } + void fnmake_mess(unsigned long id) { fn.len = fmtqfn(fn.s, "mess/", id, 1); } + void fnmake_chanaddr(unsigned long id, int c) { fn.len = fmtqfn(fn.s, chanaddr[c], id, 1); @@ -139,8 +143,8 @@ int rewrite(char *recip) return 1; } - for (i = 0; i <= addr.len; ++i) - if (!i || (i == at + 1) || (i == addr.len) || ((i > at) && (addr.s[i] == '.'))) + for (i = 0; i <= addr.len; ++i) { + if (!i || (i == at + 1) || (i == addr.len) || ((i > at) && (addr.s[i] == '.'))) { if ((x = constmap(&mapvdoms, addr.s + i, addr.len - i))) { if (!*x) break; if (!stralloc_cats(&rwline, x)) return 0; @@ -149,6 +153,8 @@ int rewrite(char *recip) if (!stralloc_0(&rwline)) return 0; return 1; } + } + } if (!stralloc_cat(&rwline, &addr)) return 0; if (!stralloc_0(&rwline)) return 0; @@ -263,11 +269,12 @@ void comm_info(unsigned long id, unsigned long size, char *from, unsigned long p i = comm_buf.len; if (!stralloc_cats(&comm_buf, from)) goto FAIL; - for (; i < comm_buf.len; ++i) + for (; i < comm_buf.len; ++i) { if (comm_buf.s[i] == '\n') comm_buf.s[i] = '/'; else if (!issafe(comm_buf.s[i])) comm_buf.s[i] = '_'; + } if (!stralloc_cats(&comm_buf, "> qp ")) goto FAIL; strnum[fmt_ulong(strnum, pid)] = 0; @@ -307,8 +314,8 @@ void comm_selprep(int *nfds, fd_set *wfds, fd_set *rfds) void comm_do(fd_set *wfds, fd_set *rfds) { /* first write then read */ - if (flagsendalive) - if (comm_canwrite()) + if (flagsendalive) { + if (comm_canwrite()) { if (FD_ISSET(fdout, wfds)) { int w; int len; @@ -324,7 +331,9 @@ void comm_do(fd_set *wfds, fd_set *rfds) } } } - if (flagsendalive) + } + } + if (flagsendalive) { if (FD_ISSET(fdin, rfds)) { /* there are only two messages 'H' and 'X' */ char c; @@ -340,6 +349,7 @@ void comm_do(fd_set *wfds, fd_set *rfds) } } } + } } /* this file is not so long ------------------------------------------ TODO */ @@ -423,19 +433,21 @@ void todo_do(fd_set *rfds) for (c = 0; c < CHANNELS; ++c) { fnmake_chanaddr(id, c); - if (unlink(fn.s) == -1) + if (unlink(fn.s) == -1) { if (errno != ENOENT) { sendlog3("warning: qmail-todo: unable to unlink ", fn.s, " for mess\n"); goto FAIL; } + } } fnmake_info(id); - if (unlink(fn.s) == -1) + if (unlink(fn.s) == -1) { if (errno != ENOENT) { sendlog3("warning: qmail-todo: unable to unlink ", fn.s, " for info\n"); goto FAIL; } + } fdnumber = open_excl(fn.s); if (fdnumber == -1) { @@ -518,7 +530,7 @@ void todo_do(fd_set *rfds) close(fdnumber); fdnumber = -1; - for (c = 0; c < CHANNELS; ++c) + for (c = 0; c < CHANNELS; ++c) { if (fdchan[c] != -1) { fnmake_chanaddr(id, c); if (buffer_flush(&bchan[c]) == -1) { @@ -532,6 +544,7 @@ void todo_do(fd_set *rfds) close(fdchan[c]); fdchan[c] = -1; } + } fnmake_todo(id); if (buffer_putflush(&toqc, fn.s, fn.len) == -1) { @@ -613,8 +626,9 @@ void regetcontrols(void) if (r) { while (!stralloc_copy(&vdoms, &newvdoms)) nomem(); while (!constmap_init(&mapvdoms, vdoms.s, vdoms.len, 1)) nomem(); - } else + } else { while (!constmap_init(&mapvdoms, "", 0, 1)) nomem(); + } } void reread(void) @@ -692,12 +706,12 @@ int main() tv.tv_sec = wakeup - recent + SLEEP_FUZZ; tv.tv_usec = 0; - if (select(nfds, &rfds, &wfds, (fd_set *)0, &tv) == -1) + if (select(nfds, &rfds, &wfds, (fd_set *)0, &tv) == -1) { if (errno == EINTR) ; else sendlog1("warning: qmail-todo: trouble in select\n"); - else { + } else { recent = now(); todo_do(&rfds); diff --git a/src/qmail-vmailuser.c b/src/qmail-vmailuser.c index 82cb243..d9de43f 100644 --- a/src/qmail-vmailuser.c +++ b/src/qmail-vmailuser.c @@ -21,12 +21,13 @@ #define RESPECT_CASE "-C" #define BUFFER_SIZE 128 -/** @file qmail-vmailuser.c - @return 0: virtual user exists - 1: virtual user dir not accessible - 2: qmail-vmailuser is misused - 110: can't read controls - 111: temporary problem +/** + @file qmail-vmailuser.c + @return 0: virtual user exists + 1: virtual user dir not accessible + 2: qmail-vmailuser is misused + 110: can't read controls + 111: temporary problem */ char inputbuf[BUFFER_SIZE]; @@ -57,7 +58,7 @@ int main(int argc, char **argv) char ch; char *homedir = "/home"; - if (argv[1]) + if (argv[1]) { if (!case_diffs(argv[1], RESPECT_CASE)) { flagrespect = 1; } else { @@ -65,6 +66,7 @@ int main(int argc, char **argv) dir = opendir(homedir); if (!dir) pam_exit(2); } + } if (argv[2]) if (!case_diffs(argv[2], RESPECT_CASE)) flagrespect = 1; @@ -89,7 +91,7 @@ int main(int argc, char **argv) } close(FDAUTH); - if ((r = byte_rchr(inputbuf, buflen, '@'))) /* @domain */ + if ((r = byte_rchr(inputbuf, buflen, '@'))) { /* @domain */ if (r < buflen && inputbuf[r] == '@') { domain = inputbuf + r + 1; domlen = str_len(domain); @@ -98,6 +100,7 @@ int main(int argc, char **argv) else case_lowerb(domain, domlen); } + } vdomuser = constmap(&mapvdoms, domain, domlen); if (!vdomuser) pam_exit(1); diff --git a/src/qmail.c b/src/qmail.c index f143af1..f344492 100644 --- a/src/qmail.c +++ b/src/qmail.c @@ -114,7 +114,8 @@ char *qmail_close(struct qmail *qq) switch (exitcode) { case 0: - if (!qq->flagerr) return ""; /* fall through */ + if (!qq->flagerr) return ""; + /* fall through */ case 11: return "Denvelope address too long for qq (#5.1.3)"; case 31: return "Dmail server permanently rejected message (#5.3.0)"; case 32: return "Vmail server does not accept message (#5.3.0)"; diff --git a/src/qreceipt.c b/src/qreceipt.c index 6b629ba..ee9fc52 100644 --- a/src/qreceipt.c +++ b/src/qreceipt.c @@ -23,45 +23,54 @@ void die_noreceipt() { _exit(0); } + void die() { _exit(100); } + void die_temp() { _exit(111); } + void die_nomem() { buffer_putsflush(buffer_2, "qreceipt: fatal: out of memory\n"); die_temp(); } + void die_fork() { buffer_putsflush(buffer_2, "qreceipt: fatal: unable to fork\n"); die_temp(); } + void die_qqperm() { buffer_putsflush(buffer_2, "qreceipt: fatal: permanent qmail-queue error\n"); die(); } + void die_qqtemp() { buffer_putsflush(buffer_2, "qreceipt: fatal: temporary qmail-queue error\n"); die_temp(); } + void die_usage() { buffer_putsflush(buffer_2, "qreceipt: usage: qreceipt deliveryaddress\n"); die(); } + void die_read() { if (errno == ENOMEM) die_nomem(); buffer_putsflush(buffer_2, "qreceipt: fatal: read error\n"); die_temp(); } + void doordie(sa, r) stralloc *sa; int r; { @@ -114,10 +123,9 @@ void finishheader() qmail_puts(&qqt, ">\n"); qmail_puts( &qqt, - "Subject: success notice\n\ -\n\ -Hi! This is the qreceipt program. Your message was delivered to the\n\ -following address: "); + "Subject: success notice\n\n" + "Hi! This is the qreceipt program. Your message was delivered to the\n" + "following address: "); qmail_puts(&qqt, target); qmail_puts(&qqt, ". Thanks for asking.\n"); if (messageid.s) { @@ -129,11 +137,12 @@ following address: "); qmail_to(&qqt, returnpath); qqx = qmail_close(&qqt); - if (*qqx) + if (*qqx) { if (*qqx == 'D') die_qqperm(); else die_qqtemp(); + } } stralloc hfbuf = {0}; @@ -154,10 +163,7 @@ void doheaderfield(stralloc *h) } } -void dobody(stralloc *h) -{ - ; -} +void dobody(stralloc *h) {} int main(int argc, char **argv) { diff --git a/src/qsutil.c b/src/qsutil.c index 1d3c9c3..fc4129b 100644 --- a/src/qsutil.c +++ b/src/qsutil.c @@ -76,11 +76,12 @@ void logsafe(char *s) int i; while (!stralloc_copys(&foo, s)) nomem(); - for (i = 0; i < foo.len; ++i) + for (i = 0; i < foo.len; ++i) { if (foo.s[i] == '\n') foo.s[i] = '/'; else if (!issafe(foo.s[i])) foo.s[i] = '_'; + } logsa(&foo); } diff --git a/src/quote.c b/src/quote.c index 0a3efc3..79668ef 100644 --- a/src/quote.c +++ b/src/quote.c @@ -10,11 +10,14 @@ no, 821 and 822 don't have the same encoding. they're not even close. no special encoding here for bytes above 127. */ +// clang-format off static char ok[128] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 7, 0, 7, 7, 7, 7, 7, 0, 0, 7, 7, 0, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 0, 0, 0, 7, 0, 7, - 0, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 0, 0, 0, 7, 7, - 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 0}; + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,7,0,7,7,7,7,7,0,0,7,7,0,7,7,7 ,7,7,7,7,7,7,7,7,7,7,0,0,0,7,0,7, + 0,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7 ,7,7,7,7,7,7,7,7,7,7,7,0,0,0,7,7, + 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7 ,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,0, +}; +// clang-format on static int doit(stralloc *saout, stralloc *sain) { diff --git a/src/rcpthosts.c b/src/rcpthosts.c index f69f4f9..7505229 100644 --- a/src/rcpthosts.c +++ b/src/rcpthosts.c @@ -43,7 +43,7 @@ int rcpthosts(char *buf, int len) if (flagrh != 1) return 1; j = byte_rchr(buf, len, '@'); - if (j >= len) return 1; /* presumably envnoathost is acceptable */ + if (j >= len) return 1; // presumably envnoathost is acceptable ++j; buf += j; @@ -63,7 +63,7 @@ int rcpthosts(char *buf, int len) if (errno == ENOENT) return 0; cdb_init(&cdb, fdmrh); - for (j = 0; j < len; ++j) + for (j = 0; j < len; ++j) { if (!j || (buf[j] == '.')) { r = cdb_find(&cdb, buf + j, len - j); if (r) { @@ -72,6 +72,7 @@ int rcpthosts(char *buf, int len) return r; } } + } cdb_free(&cdb); close(fdmrh); } diff --git a/src/recipients.c b/src/recipients.c index bf70fd7..3d883e2 100644 --- a/src/recipients.c +++ b/src/recipients.c @@ -33,19 +33,20 @@ static int flagrcpts = 0; static int fdrcps; static struct cdb cdb; -/** @file recipients.c - @brief functions recipients_init, recipients, recipients_parse, callapam - @param pointer to address, length of address - @return -3: problem with PAM - -2: out of memory - -1: error reading control file - 0: address not found; unsuccessful - 1: CDB lookup; successful - 2: PAM lookup; successful - 3: USERS lookup; successful - 4: Wildcarded domain; successful - 5: Pass-thru; neutral - 10: none existing control file; pass-thru +/** + @file recipients.c + @brief functions recipients_init, recipients, recipients_parse, callapam + @param pointer to address, length of address + @return -3: problem with PAM + -2: out of memory + -1: error reading control file + 0: address not found; unsuccessful + 1: CDB lookup; successful + 2: PAM lookup; successful + 3: USERS lookup; successful + 4: Wildcarded domain; successful + 5: Pass-thru; neutral + 10: none existing control file; pass-thru */ int recipients_init() @@ -279,7 +280,6 @@ int recipients(char *buf, int len) if (!stralloc_0(&ukey)) return -2; /* \0 terminated */ case_lowerb(ukey.s, ukey.len); - for (i = 0; i < at; i++) { /* VERP addresses */ if (buf[i] == *auto_break || buf[i] == '=' || buf[i] == '+') { /* SRS delimiter */ if (!stralloc_copyb(&verp, buf, i + 1)) return -2; diff --git a/src/sendmail.c b/src/sendmail.c index 801c019..d3936fd 100644 --- a/src/sendmail.c +++ b/src/sendmail.c @@ -43,6 +43,7 @@ void smtpd() } char *qreadarg[] = {"bin/qmail-qread", 0}; + void mailq() { execv(*qreadarg, qreadarg); diff --git a/src/setforward.c b/src/setforward.c index 356ec78..ec282ba 100644 --- a/src/setforward.c +++ b/src/setforward.c @@ -1,5 +1,8 @@ #include <unistd.h> +#include <stdio.h> // rename +#undef EOF // used as a label + #include "buffer.h" #include "case.h" #include "cdbmake.h" @@ -9,32 +12,36 @@ #define WHO "setforward" -int rename(const char *, const char *); // stdio.h - void usage() { logmsg(WHO, 100, USAGE, "setforward data.cdb data.tmp"); } + void nomem() { logmsg(WHO, 111, FATAL, "out of memory"); } + void missingsemicolon() { logmsg(WHO, 100, FATAL, "final instruction must end with semicolon"); } + void extracolon() { logmsg(WHO, 100, FATAL, "double colons are not permitted"); } + void extracomma() { logmsg(WHO, 100, FATAL, "commas are not permitted before colons"); } + void nulbyte() { logmsg(WHO, 100, FATAL, "NUL bytes are not permitted"); } + void longaddress() { logmsg(WHO, 100, FATAL, "addresses over 800 bytes are not permitted"); diff --git a/src/setmaillist.c b/src/setmaillist.c index a32e86b..e06e336 100644 --- a/src/setmaillist.c +++ b/src/setmaillist.c @@ -1,6 +1,8 @@ #include <sys/stat.h> #include <unistd.h> +#include <stdio.h> // rename + #include "buffer.h" #include "byte.h" #include "getln.h" @@ -10,8 +12,6 @@ #define WHO "setmaillist" -int rename(const char *, const char *); // stdio.h - void usage() { logmsg(WHO, 100, USAGE, "setmaillist list.bin list.tmp"); @@ -50,7 +50,6 @@ int main(int argc, char **argv) buffer_init(&bo, write, fd, buf, sizeof(buf)); - do { if (getln(buffer_0small, &line, &match, '\n') == -1) logmsg(WHO, 111, FATAL, "unable to read input: "); @@ -64,7 +63,7 @@ int main(int argc, char **argv) if (byte_chr(line.s, line.len, '\0') != line.len) logmsg(WHO, 111, FATAL, "NUL in input"); - if (line.len) + if (line.len) { if (line.s[0] != '#') { if ((line.s[0] == '.') || (line.s[0] == '/')) { out(line.s, line.len); @@ -76,6 +75,7 @@ int main(int argc, char **argv) out("", 1); } } + } } while (match); @@ -84,86 +84,28 @@ void sha1_transform(uint32_t state[5], const uint8_t buffer[SHA1_BLOCKSIZE]) e = state[4]; /* 4 rounds of 20 operations each. Loop unrolled. */ - R0(a, b, c, d, e, 0); - R0(e, a, b, c, d, 1); - R0(d, e, a, b, c, 2); - R0(c, d, e, a, b, 3); - R0(b, c, d, e, a, 4); - R0(a, b, c, d, e, 5); - R0(e, a, b, c, d, 6); - R0(d, e, a, b, c, 7); - R0(c, d, e, a, b, 8); - R0(b, c, d, e, a, 9); - R0(a, b, c, d, e, 10); - R0(e, a, b, c, d, 11); - R0(d, e, a, b, c, 12); - R0(c, d, e, a, b, 13); - R0(b, c, d, e, a, 14); - R0(a, b, c, d, e, 15); - R1(e, a, b, c, d, 16); - R1(d, e, a, b, c, 17); - R1(c, d, e, a, b, 18); - R1(b, c, d, e, a, 19); - R2(a, b, c, d, e, 20); - R2(e, a, b, c, d, 21); - R2(d, e, a, b, c, 22); - R2(c, d, e, a, b, 23); - R2(b, c, d, e, a, 24); - R2(a, b, c, d, e, 25); - R2(e, a, b, c, d, 26); - R2(d, e, a, b, c, 27); - R2(c, d, e, a, b, 28); - R2(b, c, d, e, a, 29); - R2(a, b, c, d, e, 30); - R2(e, a, b, c, d, 31); - R2(d, e, a, b, c, 32); - R2(c, d, e, a, b, 33); - R2(b, c, d, e, a, 34); - R2(a, b, c, d, e, 35); - R2(e, a, b, c, d, 36); - R2(d, e, a, b, c, 37); - R2(c, d, e, a, b, 38); - R2(b, c, d, e, a, 39); - R3(a, b, c, d, e, 40); - R3(e, a, b, c, d, 41); - R3(d, e, a, b, c, 42); - R3(c, d, e, a, b, 43); - R3(b, c, d, e, a, 44); - R3(a, b, c, d, e, 45); - R3(e, a, b, c, d, 46); - R3(d, e, a, b, c, 47); - R3(c, d, e, a, b, 48); - R3(b, c, d, e, a, 49); - R3(a, b, c, d, e, 50); - R3(e, a, b, c, d, 51); - R3(d, e, a, b, c, 52); - R3(c, d, e, a, b, 53); - R3(b, c, d, e, a, 54); - R3(a, b, c, d, e, 55); - R3(e, a, b, c, d, 56); - R3(d, e, a, b, c, 57); - R3(c, d, e, a, b, 58); - R3(b, c, d, e, a, 59); - R4(a, b, c, d, e, 60); - R4(e, a, b, c, d, 61); - R4(d, e, a, b, c, 62); - R4(c, d, e, a, b, 63); - R4(b, c, d, e, a, 64); - R4(a, b, c, d, e, 65); - R4(e, a, b, c, d, 66); - R4(d, e, a, b, c, 67); - R4(c, d, e, a, b, 68); - R4(b, c, d, e, a, 69); - R4(a, b, c, d, e, 70); - R4(e, a, b, c, d, 71); - R4(d, e, a, b, c, 72); - R4(c, d, e, a, b, 73); - R4(b, c, d, e, a, 74); - R4(a, b, c, d, e, 75); - R4(e, a, b, c, d, 76); - R4(d, e, a, b, c, 77); - R4(c, d, e, a, b, 78); - R4(b, c, d, e, a, 79); + // clang-format off + R0(a,b,c,d,e, 0); R0(e,a,b,c,d, 1); R0(d,e,a,b,c, 2); R0(c,d,e,a,b, 3); + R0(b,c,d,e,a, 4); R0(a,b,c,d,e, 5); R0(e,a,b,c,d, 6); R0(d,e,a,b,c, 7); + R0(c,d,e,a,b, 8); R0(b,c,d,e,a, 9); R0(a,b,c,d,e,10); R0(e,a,b,c,d,11); + R0(d,e,a,b,c,12); R0(c,d,e,a,b,13); R0(b,c,d,e,a,14); R0(a,b,c,d,e,15); + R1(e,a,b,c,d,16); R1(d,e,a,b,c,17); R1(c,d,e,a,b,18); R1(b,c,d,e,a,19); + R2(a,b,c,d,e,20); R2(e,a,b,c,d,21); R2(d,e,a,b,c,22); R2(c,d,e,a,b,23); + R2(b,c,d,e,a,24); R2(a,b,c,d,e,25); R2(e,a,b,c,d,26); R2(d,e,a,b,c,27); + R2(c,d,e,a,b,28); R2(b,c,d,e,a,29); R2(a,b,c,d,e,30); R2(e,a,b,c,d,31); + R2(d,e,a,b,c,32); R2(c,d,e,a,b,33); R2(b,c,d,e,a,34); R2(a,b,c,d,e,35); + R2(e,a,b,c,d,36); R2(d,e,a,b,c,37); R2(c,d,e,a,b,38); R2(b,c,d,e,a,39); + R3(a,b,c,d,e,40); R3(e,a,b,c,d,41); R3(d,e,a,b,c,42); R3(c,d,e,a,b,43); + R3(b,c,d,e,a,44); R3(a,b,c,d,e,45); R3(e,a,b,c,d,46); R3(d,e,a,b,c,47); + R3(c,d,e,a,b,48); R3(b,c,d,e,a,49); R3(a,b,c,d,e,50); R3(e,a,b,c,d,51); + R3(d,e,a,b,c,52); R3(c,d,e,a,b,53); R3(b,c,d,e,a,54); R3(a,b,c,d,e,55); + R3(e,a,b,c,d,56); R3(d,e,a,b,c,57); R3(c,d,e,a,b,58); R3(b,c,d,e,a,59); + R4(a,b,c,d,e,60); R4(e,a,b,c,d,61); R4(d,e,a,b,c,62); R4(c,d,e,a,b,63); + R4(b,c,d,e,a,64); R4(a,b,c,d,e,65); R4(e,a,b,c,d,66); R4(d,e,a,b,c,67); + R4(c,d,e,a,b,68); R4(b,c,d,e,a,69); R4(a,b,c,d,e,70); R4(e,a,b,c,d,71); + R4(d,e,a,b,c,72); R4(c,d,e,a,b,73); R4(b,c,d,e,a,74); R4(a,b,c,d,e,75); + R4(e,a,b,c,d,76); R4(d,e,a,b,c,77); R4(c,d,e,a,b,78); R4(b,c,d,e,a,79); + // clang-format on /* Add the working vars back into context.state[] */ state[0] += a; @@ -209,8 +151,9 @@ void sha1_update(sha1_ctx *context, const uint8_t *data, uint32_t len) sha1_transform(context->state, data + i); } j = 0; - } else + } else { i = 0; + } byte_copy(&context->buffer[j], len - i, &data[i]); } @@ -222,8 +165,8 @@ void sha1_final(uint8_t digest[SHA1_DIGESTSIZE], sha1_ctx *context) uint8_t finalcount[8]; for (i = 0; i < 8; i++) { - finalcount[i] = (uint8_t)((context->count[(i >= 4 ? 0 : 1)] >> ((3 - (i & 3)) * 8)) - & 255); /* Endian independent */ + /* Endian independent */ + finalcount[i] = (uint8_t)((context->count[(i >= 4 ? 0 : 1)] >> ((3 - (i & 3)) * 8)) & 255); } sha1_update(context, (uint8_t *)"\200", 1); diff --git a/src/smtpdlog.c b/src/smtpdlog.c index c7505af..6cb0266 100644 --- a/src/smtpdlog.c +++ b/src/smtpdlog.c @@ -8,6 +8,7 @@ #include "exit.h" #include "fmt.h" #include "str.h" + #define FDLOG 2 char *reply421pgl; @@ -43,11 +44,13 @@ static void logs(char *s) { if (buffer_puts(&bo2, s) == -1) _exit(1); } /* single string */ + static void logp(char *s) { logs(" P:"); logs(s); } /* protocol */ + static void logh(char *s1, char *s2, char *s3) { logs(" S:"); @@ -57,27 +60,32 @@ static void logh(char *s1, char *s2, char *s3) logs(" H:"); logs(s3); } /* host */ + static void logm(char *s) { logs(" F:"); logs(s); } /* mailfrom */ + static void logt(char *s) { logs(" T:"); logs(s); } /* rcptto */ + static void logi(char *s) { logs(" '"); logs(s); logs("'"); } /* information */ + static void logn(char *s) { if (buffer_puts(&bo2, s) == -1) _exit(1); if (buffer_flush(&bo2) == -1) _exit(1); } /* end */ + static void logpid() { strnum[fmt_ulong(strnum, getpid())] = 0; @@ -98,6 +106,7 @@ void smtp_loga(char *s1, char *s2, char *s3, char *s4, char *s5, char *s6, char logi(s8); logn("\n"); } /* Auth info */ + void smtp_logb(char *s1, char *s2, char *s3, char *s4, char *s5, char *s6, char *s7) { logpid(); @@ -109,6 +118,7 @@ void smtp_logb(char *s1, char *s2, char *s3, char *s4, char *s5, char *s6, char logi(s6); logn("\n"); } /* Auth info */ + void smtp_logg(char *s1, char *s2, char *s3, char *s4, char *s5, char *s6, char *s7) { logpid(); @@ -119,6 +129,7 @@ void smtp_logg(char *s1, char *s2, char *s3, char *s4, char *s5, char *s6, char logt(s7); logn("\n"); } /* Generic */ + void smtp_logh(char *s1, char *s2, char *s3, char *s4, char *s5) { logpid(); @@ -127,6 +138,7 @@ void smtp_logh(char *s1, char *s2, char *s3, char *s4, char *s5) logh(s3, s4, s5); logn("\n"); } /* Host */ + void smtp_logi(char *s1, char *s2, char *s3, char *s4, char *s5, char *s6, char *s7, char *s8) { logpid(); @@ -138,6 +150,7 @@ void smtp_logi(char *s1, char *s2, char *s3, char *s4, char *s5, char *s6, char logi(s8); logn("\n"); } /* Generic + Info */ + void smtp_logr(char *s1, char *s2, char *s3, char *s4, char *s5, char *s6, char *s7, char *s8) { logpid(); @@ -154,36 +167,42 @@ void die_read() { _exit(1); } + void die_alarm() { out("451 timeout (#4.4.2)\r\n"); flush(); _exit(1); } + void die_nomem() { out("421 out of memory (#4.3.0)\r\n"); flush(); _exit(1); } + void die_control() { out("421 unable to read controls (#4.3.0)\r\n"); flush(); _exit(1); } + void die_ipme() { out("421 unable to figure out my IP addresses (#4.3.0)\r\n"); flush(); _exit(1); } + void die_starttls() { out("454 TLS not available due to temporary reason (#5.7.3)\r\n"); flush(); _exit(1); } + void die_recipients() { out("421 unable to check recipients (#4.3.0)\r\n"); @@ -195,18 +214,22 @@ void err_unimpl() { out("500 unimplemented (#5.5.1)\r\n"); } + void err_syntax() { out("555 syntax error (#5.5.4)\r\n"); } + void err_noop() { out("250 ok\r\n"); } + void err_vrfy() { out("252 send some mail, i'll try my best\r\n"); } + void err_qqt() { out("451 qqt failure (#4.3.0)\r\n"); @@ -217,16 +240,19 @@ int err_child() out("454 problem with child and I can't auth (#4.3.0)\r\n"); return -1; } + int err_fork() { out("454 child won't start and I can't auth (#4.3.0)\r\n"); return -1; } + int err_pipe() { out("454 unable to open pipe and I can't auth (#4.3.0)\r\n"); return -1; } + int err_write() { out("454 unable to write pipe and I can't auth (#4.3.0)\r\n"); @@ -238,6 +264,7 @@ int err_postgl() out("454 problem with child and I can't greylist (#4.3.0)\r\n"); return -1; } + int err_forkgl() { out("454 problem with child and I can't greylist (#4.3.0)\r\n"); @@ -251,6 +278,7 @@ int err_starttls() out("454 TLS not available due to temporary reason (#5.7.3)\r\n"); _exit(1); } + void err_tlsreq(char *s1, char *s2, char *s3, char *s4, char *s5) { out("535 STARTTLS required (#5.7.1)\r\n"); @@ -274,44 +302,53 @@ void err_authsetup(char *s1, char *s2, char *s3, char *s4, char *s5) out("530 Auth not available (#5.7.1)\r\n"); smtp_logh(s1, s2, s3, s4, s5); } + void err_authd() { out("503 you're already authenticated (#5.5.0)\r\n"); } + void err_authmail() { out("503 no auth during mail transaction (#5.5.0)\r\n"); } + void err_authfail(char *s1, char *s2, char *s3, char *s4, char *s5, char *s6, char *s7) { out("535 authentication failed (#5.7.1)\r\n"); smtp_logb(s1, s2, s3, s4, s5, s6, s7); } + void err_authreq(char *s1, char *s2, char *s3, char *s4, char *s5) { out("535 authentication required (#5.7.1)\r\n"); smtp_logh(s1, s2, s3, s4, s5); } + void err_submission(char *s1, char *s2, char *s3, char *s4, char *s5) { out("530 Authorization required (#5.7.1) \r\n"); smtp_logh(s1, s2, s3, s4, s5); } + int err_authabort() { out("501 auth exchange canceled (#5.0.0)\r\n"); return -1; } + int err_authinput() { out("501 malformed auth input (#5.5.4)\r\n"); return -1; } + void err_authinvalid(char *s1, char *s2, char *s3, char *s4, char *s5) { out("504 auth type unimplemented (#5.5.1)\r\n"); smtp_logh(s1, s2, s3, s4, s5); } + int err_noauth() { out("504 auth type unimplemented (#5.5.1)\r\n"); @@ -332,6 +369,7 @@ void err_mav(char *s1, char *s2, char *s3, char *s4, char *s5, char *s6, char *s out(" (#5.7.1)\r\n"); smtp_logg(s1, s2, s3, s4, s5, s6, s7); } + void err_bmf(char *s1, char *s2, char *s3, char *s4, char *s5, char *s6, char *s7, char *s8) { out("553 sorry, your envelope sender is in my badmailfrom list "); @@ -339,6 +377,7 @@ void err_bmf(char *s1, char *s2, char *s3, char *s4, char *s5, char *s6, char *s out(" (#5.7.1)\r\n"); smtp_logi(s1, s2, s3, s4, s5, s6, s7, s8); } + void err_mfdns(char *s1, char *s2, char *s3, char *s4, char *s5, char *s6, char *s7) { out("553 sorry, your envelope sender must exist "); @@ -385,6 +424,7 @@ void postgrey(char *s1, char *s2, char *s3, char *s4, char *s5, char *s6, char * out(" (#4.3.0)\r\n"); smtp_logg(s1, s2, s3, s4, s5, s6, s7); } + void err_nogateway(char *s1, char *s2, char *s3, char *s4, char *s5, char *s6, char *s7) { out("553 sorry, that domain isn't in my list of allowed rcpthosts "); @@ -392,6 +432,7 @@ void err_nogateway(char *s1, char *s2, char *s3, char *s4, char *s5, char *s6, c out(" (#5.7.1)\r\n"); smtp_logg(s1, s2, s3, s4, s5, s6, s7); } + void err_brt(char *s1, char *s2, char *s3, char *s4, char *s5, char *s6, char *s7) { out("553 sorry, your envelope recipient is in my badrcptto list "); @@ -399,11 +440,13 @@ void err_brt(char *s1, char *s2, char *s3, char *s4, char *s5, char *s6, char *s out(" (#5.7.1)\r\n"); smtp_logg(s1, s2, s3, s4, s5, s6, s7); } + void err_rcpts(char *s1, char *s2, char *s3, char *s4, char *s5, char *s6, char *s7) { out("452 sorry, too many recipients (#4.5.3)\r\n"); /* RFC 5321 */ smtp_logg(s1, s2, s3, s4, s5, s6, s7); } + void err_recipient(char *s1, char *s2, char *s3, char *s4, char *s5, char *s6, char *s7) { if (env_get("RECIPIENTS450")) @@ -424,17 +467,20 @@ void straynewline() flush(); _exit(1); } + void err_notorious() { out("503 DATA command not accepted at this time (#5.5.1)\r\n"); flush(); _exit(1); } + void err_size(char *s1, char *s2, char *s3, char *s4, char *s5, char *s6, char *s7) { out("552 sorry, that message size exceeds my databytes limit (#5.3.4)\r\n"); smtp_logg(s1, s2, s3, s4, s5, s6, s7); } + void err_data(char *s1, char *s2, char *s3, char *s4, char *s5, char *s6, char *s7, char *s8) { out("554 sorry, invalid message content "); @@ -42,19 +42,19 @@ char ip6remote[16] = {16 * 0}; /* Sample SPF TXT records: Standard example: example.net TXT "v=spf1 mx a:pluto.example.net include:aspmx.googlemail.com -all" -Fehcom's example: fehcom.net TXT "v=spf1 ip4:85.25.149.179/32 ip6:2001:4dd0:ff00:3d4::2/64 -all" +Fehcom's example: fehcom.net TXT "v=spf1 ip4:85.25.149.179/32 ip6:2001:4dd0:ff00:3d4::2/64 -all" Include example: mailing.com TXT "v=spf1 a:smtpout.mailing.com include:spf.nl2go.com ~all" -Exists+Expand: exists.com TXT "v=spf1 exists:%{ir}.%{l1r+-}._spf.%{d} -all" +Exists+Expand: exists.com TXT "v=spf1 exists:%{ir}.%{l1r+-}._spf.%{d} -all" */ /* Entry point: -------------------------------------- Go for SPF */ /** - @brief spf_query - prepares the SPF TXT record query - @param input: pointer to remoteip, helo, mf, localhost, and flagIP6 - @return int r = SPF return code - */ + @brief spf_query + prepares the SPF TXT record query + @param input: pointer to remoteip, helo, mf, localhost, and flagIP6 + @return int r = SPF return code +*/ int spf_query( @@ -155,13 +155,13 @@ static struct spf_aliases { }; /** - @brief spf_lookup - calles the actual (recursive) SPF DNS query - @param input: pointer to stralloc domain (fqdn) - @input stralloc spflocalrules (if provided -- for artificial results) - @output stralloc spfdata with RDATA (+ artificial information) - @return int r = SPF return code - */ + @brief spf_lookup + calles the actual (recursive) SPF DNS query + @param input: pointer to stralloc domain (fqdn) + @input stralloc spflocalrules (if provided -- for artificial results) + @output stralloc spfdata with RDATA (+ artificial information) + @return int r = SPF return code +*/ int spf_lookup(stralloc *domain) { @@ -416,14 +416,13 @@ static struct mechanisms { }; /** - @brief spf_mechanism - evaluates the provided mechanisms in the SPF record [RFC7208 Sec 5.] - @param input: pointer to mechanism, SPF specification from record, CIDR prefix length, domain - @input stralloc spflocalrules (if provided) - @output pointer to spfspec: data evaluated - @return int r - */ - + @brief spf_mechanism + evaluates the provided mechanisms in the SPF record [RFC7208 Sec 5.] + @param input: pointer to mechanism, SPF specification from record, CIDR prefix length, domain + @input stralloc spflocalrules (if provided) + @output pointer to spfspec: data evaluated + @return int r +*/ int spf_mechanism(char *mechanism, char *spfspec, char *prefix, char *domain) { struct mechanisms *mech; @@ -458,12 +457,11 @@ int spf_mechanism(char *mechanism, char *spfspec, char *prefix, char *domain) } /** - @brief spf_include - deals with recursive evaluation of SPF record [RFC7208 Sec. 5.2] - @param input: pointer to included SPF specification; CIDR prefix length - @return int r = 1 ok; 0 failure - */ - + @brief spf_include + deals with recursive evaluation of SPF record [RFC7208 Sec. 5.2] + @param input: pointer to included SPF specification; CIDR prefix length + @return int r = 1 ok; 0 failure +*/ int spf_include(char *spfspec, char *prefix) { stralloc sa = {0}; @@ -486,14 +484,13 @@ int spf_include(char *spfspec, char *prefix) } /** - @brief spf_parse - parses the substructure of the SPF record and calls spf_macros - @param input: pointer to SPF specification, pointer to domain - output: stralloc sa -- - @output pointer to spfspec: with found data - @return int r = 1 ok; 0 failure - */ - + @brief spf_parse + parses the substructure of the SPF record and calls spf_macros + @param input: pointer to SPF specification, pointer to domain + output: stralloc sa -- + @output pointer to spfspec: with found data + @return int r = 1 ok; 0 failure +*/ int spf_parse(stralloc *sa, char *spfspec, char *domain) { char *p; @@ -533,13 +530,12 @@ int spf_parse(stralloc *sa, char *spfspec, char *domain) } /** - @brief spf_macros - deals with macros in the SPF specificaton [RFC7208 Sec. 7ff] - @param input: pointer to SPF macro, pointer to domain - output: pointer to stralloc expand(ed information) - @return int r = 1 ok; 0 failure - */ - + @brief spf_macros + deals with macros in the SPF specificaton [RFC7208 Sec. 7ff] + @param input: pointer to SPF macro, pointer to domain + output: pointer to stralloc expand(ed information) + @return int r = 1 ok; 0 failure +*/ int spf_macros(stralloc *expand, char *macro, char *domain) { static const char hextab[] = "0123456789abcdef"; @@ -681,8 +677,9 @@ int spf_macros(stralloc *expand, char *macro, char *domain) } } if (!stralloc_catb(expand, sa.s, pos)) return 0; - } else if (!stralloc_cats(expand, sa.s)) + } else if (!stralloc_cats(expand, sa.s)) { return 0; + } if (urlencode) { stralloc_copyb(&sa, expand->s + start, expand->len - start); diff --git a/src/spfdnsip.c b/src/spfdnsip.c index 9012f69..f2a802e 100644 --- a/src/spfdnsip.c +++ b/src/spfdnsip.c @@ -23,12 +23,11 @@ extern char ip6remote[16]; extern int flagip6; /** - @brief match_ip - compares IPv4/IPv6 addreses up to prefix length - @param input: ip_address1,prefix length, ip_address2 - @return 1 ok; 0 failure - */ - + @brief match_ip + compares IPv4/IPv6 addreses up to prefix length + @param input: ip_address1,prefix length, ip_address2 + @return 1 ok; 0 failure +*/ int match_ip4(unsigned char ip1[4], int prefix, char ip2[4]) { stralloc iptest1 = {0}; @@ -58,12 +57,11 @@ int match_ip6(unsigned char ip1[16], int prefix, char ip2[16]) } /** - @brief get_prefix - return integer value of prefix length - @param input: pointer to prefix - @return (int) length of prefix - */ - + @brief get_prefix + return integer value of prefix length + @param input: pointer to prefix + @return (int) length of prefix +*/ int get_prefix(char *prefix) { unsigned long r; @@ -85,13 +83,12 @@ int get_prefix(char *prefix) /* DNS Record: -------------------------------------- Fetch multiple SPF TXT RRs */ /** - @brief spf_records - get TXT records for domain and extract SPF information - @param input: pointer stralloc domain - output: pointer to stralloc spf records - @return SPF_OK, SPF_NONE; SPF_MULTIRR, SPF_DNSSOFT, SPF_NOMEM - */ - + @brief spf_records + get TXT records for domain and extract SPF information + @param input: pointer stralloc domain + output: pointer to stralloc spf records + @return SPF_OK, SPF_NONE; SPF_MULTIRR, SPF_DNSSOFT, SPF_NOMEM +*/ int spf_records(stralloc *spfrec, stralloc *domain) { static stralloc out = {0}; @@ -138,12 +135,11 @@ int spf_records(stralloc *spfrec, stralloc *domain) /* Mechanisms: -------------------------------------- Lookup functions */ /** - @brief spf_a (a; a:fqdns; a:fqdns/56) - compares A + AAAA records for SPF info and client host - @param input: pointer to spfspecification, pointer to prefix - @return SPF_OK, SPF_NONE; SPF_DNSSOFT, SPF_NOMEM - */ - + @brief spf_a (a; a:fqdns; a:fqdns/56) + compares A + AAAA records for SPF info and client host + @param input: pointer to spfspecification, pointer to prefix + @return SPF_OK, SPF_NONE; SPF_DNSSOFT, SPF_NOMEM +*/ int spf_a(char *spfspec, char *prefix) { stralloc sa = {0}; @@ -183,12 +179,11 @@ int spf_a(char *spfspec, char *prefix) } /** - @brief spf_mx (mx; mx:domain; mx:domain/24) - compares MX records for SPF info and client host - @param input: pointer to spfspecification, pointer to prefix - @return SPF_OK, SPF_NONE; SPF_DNSSOFT, SPF_NOMEM - */ - + @brief spf_mx (mx; mx:domain; mx:domain/24) + compares MX records for SPF info and client host + @param input: pointer to spfspecification, pointer to prefix + @return SPF_OK, SPF_NONE; SPF_DNSSOFT, SPF_NOMEM +*/ int spf_mx(char *spfspec, char *prefix) { stralloc sa = {0}; @@ -224,12 +219,11 @@ int spf_mx(char *spfspec, char *prefix) } /** - @brief spf_ptr (ptr; ptr:fqdn) - compares PTR records from SPF info and client host - @param input: pointer to spfspecification; prefix not used - @return SPF_OK, SPF_NONE; SPF_DNSSOFT, SPF_NOMEM - */ - + @brief spf_ptr (ptr; ptr:fqdn) + compares PTR records from SPF info and client host + @param input: pointer to spfspecification; prefix not used + @return SPF_OK, SPF_NONE; SPF_DNSSOFT, SPF_NOMEM +*/ int spf_ptr(char *spfspec, char *prefix) { stralloc fqdn = {0}; @@ -255,7 +249,7 @@ int spf_ptr(char *spfspec, char *prefix) return SPF_OK; } - /* ok, either it's the first test or it's a very weired setup + /* ok, either it's the first test or it's a very weired setup Assumptions: ip -> inverse DNS name (only one!) inverse DNS name -> (same) ip (only one!) @@ -351,12 +345,11 @@ int spf_ptr(char *spfspec, char *prefix) } /** - @brief spf_ip4 (ip4; ip4:fqdn; ip4:fqdn/24) - compares A records for SPF info and client host - @param input: pointer to spfspecification, pointer to prefix - @return SPF_OK, SPF_NONE; SPF_DNSSOFT, SPF_NOMEM - */ - + @brief spf_ip4 (ip4; ip4:fqdn; ip4:fqdn/24) + compares A records for SPF info and client host + @param input: pointer to spfspecification, pointer to prefix + @return SPF_OK, SPF_NONE; SPF_DNSSOFT, SPF_NOMEM +*/ int spf_ip4(char *spfspec, char *prefix) { char spfip[4]; @@ -374,12 +367,11 @@ int spf_ip4(char *spfspec, char *prefix) } /** - @brief spf_ip6 (ip6; ip6:fqdn; ip6:fqdn/56) - compares AAAA records for SPF info and client host - @param input: pointer to spfspecification, pointer to prefix - @return SPF_OK, SPF_NONE; SPF_DNSSOFT, SPF_NOMEM - */ - + @brief spf_ip6 (ip6; ip6:fqdn; ip6:fqdn/56) + compares AAAA records for SPF info and client host + @param input: pointer to spfspecification, pointer to prefix + @return SPF_OK, SPF_NONE; SPF_DNSSOFT, SPF_NOMEM +*/ int spf_ip6(char *spfspec, char *prefix) { char spfip[16]; @@ -397,12 +389,11 @@ int spf_ip6(char *spfspec, char *prefix) } /** - @brief spf_exists (exists; exists:fqdn) - simply looks for a A records only for SPF info and client host - @param input: pointer to spfspecification, prefix not used - @return SPF_OK, SPF_NONE; SPF_DNSSOFT, SPF_NOMEM - */ - + @brief spf_exists (exists; exists:fqdn) + simply looks for a A records only for SPF info and client host + @param input: pointer to spfspecification, prefix not used + @return SPF_OK, SPF_NONE; SPF_DNSSOFT, SPF_NOMEM +*/ int spf_exists(char *spfspec, char *prefix) { stralloc sa = {0}; diff --git a/src/spfquery.c b/src/spfquery.c index 68a5158..8eb0697 100644 --- a/src/spfquery.c +++ b/src/spfquery.c @@ -20,6 +20,7 @@ void die(int e, char *s) buffer_putsflush(buffer_2, s); _exit(e); } + void die_nomem() { die(111, "fatal: out of memory\n"); diff --git a/src/splogger.c b/src/splogger.c index 2dcfe2a..55fc94a 100644 --- a/src/splogger.c +++ b/src/splogger.c @@ -50,15 +50,17 @@ int main(int argc, char **argv) { char ch; - if (argv[1]) + if (argv[1]) { if (argv[2]) { unsigned long facility; scan_ulong(argv[2], &facility); openlog(argv[1], 0, facility << 3); - } else + } else { openlog(argv[1], 0, LOG_MAIL); - else + } + } else { openlog("splogger", 0, LOG_MAIL); + } for (;;) { if (buffer_get(buffer_0, &ch, 1) < 1) _exit(0); @@ -11,14 +11,15 @@ * information. */ -/* This is a minimal adapted s/qmail version; it requires complete - refactoring: - - a) Use stralloc for addresses - b) Replace stdio, str*, and mem* functions - c) Use tai64 for timestamp function - d) Remove va args - e) Reduce code by 50% +/* + This is a minimal adapted s/qmail version; it requires complete + refactoring: + + a) Use stralloc for addresses + b) Replace stdio, str*, and mem* functions + c) Use tai64 for timestamp function + d) Remove va args + e) Reduce code by 50% */ #include "srs2.h" diff --git a/src/srsforward.c b/src/srsforward.c index c855d36..0477d90 100644 --- a/src/srsforward.c +++ b/src/srsforward.c @@ -23,6 +23,7 @@ void die_nomem() { logmsg(WHO, 111, FATAL, "out of memory"); } + void die_control() { logmsg(WHO, 110, FATAL, "Unable to read control files"); @@ -35,14 +36,14 @@ struct constmap mapsrsdomains; stralloc srshost = {0}; stralloc srserror = {0}; -/** @file srsforward.c - @brief forwarding mails with SRS enhanced addresss - @return 0 on success (forwarded or not) - -3 SRS error with error output - 111 no memory / processing error - 110 control file not readable +/** + @file srsforward.c + @brief forwarding mails with SRS enhanced addresss + @return 0 on success (forwarded or not) + -3 SRS error with error output + 111 no memory / processing error + 110 control file not readable */ - static int srserror_str(int code) { if (!stralloc_copys(&srserror, "SRS: ")) die_nomem(); @@ -128,13 +129,16 @@ int main(int argc, char **argv) if (sendhost[j - 1] == '.') { if (!stralloc_copys(&srshost, sendhost)) die_nomem(); if (!stralloc_cats(&srshost, host)) die_nomem(); - } else if (!stralloc_copys(&srshost, sendhost)) + } else if (!stralloc_copys(&srshost, sendhost)) { die_nomem(); - } else if (!stralloc_copys(&srshost, host)) + } + } else if (!stralloc_copys(&srshost, host)) { die_nomem(); + } if (!stralloc_0(&srshost)) die_nomem(); - } else + } else { die_control(); + } /* Let's go SRS rewrite */ diff --git a/src/srsreverse.c b/src/srsreverse.c index 33d0e5a..6c87fb2 100644 --- a/src/srsreverse.c +++ b/src/srsreverse.c @@ -25,6 +25,7 @@ void die_nomem() { logmsg(WHO, 111, FATAL, "out of memory"); } + void die_control() { logmsg(WHO, 110, FATAL, "Unable to read control files"); @@ -40,14 +41,14 @@ struct constmap mapsrsdomains; stralloc srserror = {0}; stralloc srshost = {0}; -/** @file srsreverse.c - @brief forwarding bounces with SRS enhanced addresss - @return 0 on success (forwarded or not) - -3 SRS error with error output - 111 no memory / processing error - 110 control file not readable +/** + @file srsreverse.c + @brief forwarding bounces with SRS enhanced addresss + @return 0 on success (forwarded or not) + -3 SRS error with error output + 111 no memory / processing error + 110 control file not readable */ - static int srserror_str(int code) { if (!stralloc_copys(&srserror, "SRS: ")) die_nomem(); @@ -105,12 +106,13 @@ int main() } j = str_len(host); - for (i = 0; i <= j; ++i) + for (i = 0; i <= j; ++i) { if ((i == 0) || (host[i] == '.')) { if (!stralloc_copys(&srshost, "")) die_nomem(); if (!stralloc_catb(&srshost, host + i, j - i)) die_nomem(); if ((srsdomaininfo = constmap(&mapvdomains, srshost.s, srshost.len)) != 0) goto SRSDOMAINS; } + } if (!stralloc_copys(&srshost, host)) die_nomem(); SRSDOMAINS: diff --git a/src/tai64nfrac.c b/src/tai64nfrac.c index bb29b44..c433e4f 100644 --- a/src/tai64nfrac.c +++ b/src/tai64nfrac.c @@ -9,11 +9,12 @@ #define TAI64NLEN 24 -/** @file tai64nfrac - @brief Read a TAI64N external format timestamp from stdin and - write fractional seconds since epoch (TAI, not UTC) to stdout. - Return the characters after the timestamp. - */ +/** + @file tai64nfrac + @brief Read a TAI64N external format timestamp from stdin and + write fractional seconds since epoch (TAI, not UTC) to stdout. + Return the characters after the timestamp. +*/ char outbuf[64]; buffer bo = BUFFER_INIT(write, 1, outbuf, sizeof(outbuf)); diff --git a/src/tcpto.c b/src/tcpto.c index 77e565c..243d4ba 100644 --- a/src/tcpto.c +++ b/src/tcpto.c @@ -103,9 +103,9 @@ void tcpto_err(struct ip_mx *ix, int flagerr) for (i = 0; i < n; ++i) { if (af == record[0] && byte_equal(ip->d, af == AF_INET ? 4 : 16, record + 16)) { - if (!flagerr) + if (!flagerr) { record[4] = 0; - else { + } else { lastwhen = (unsigned long)(unsigned char)record[11]; lastwhen = (lastwhen << 8) + (unsigned long)(unsigned char)record[10]; lastwhen = (lastwhen << 8) + (unsigned long)(unsigned char)record[9]; @@ -169,9 +169,9 @@ void tcpto_err(struct ip_mx *ix, int flagerr) if (i >= 0) { record = tcpto_buf + (i << 5); record[0] = af; - if (af == AF_INET6) + if (af == AF_INET6) { byte_copy(record + 16, 16, ip->d); - else { + } else { byte_copy(record + 16, 4, ip->d); byte_copy(record + 20, 12, "............"); } diff --git a/src/tls_errors.c b/src/tls_errors.c index 3d24784..a75760a 100644 --- a/src/tls_errors.c +++ b/src/tls_errors.c @@ -5,8 +5,9 @@ #include "error.h" #include "stralloc.h" -/** @file tls_errors.c - @brief temp_tls* routines are used for error messges +/** + @file tls_errors.c + @brief temp_tls* routines are used for error messges */ /* TLS error messages: A) Setup */ diff --git a/src/tls_remote.c b/src/tls_remote.c index 7986077..fd72033 100644 --- a/src/tls_remote.c +++ b/src/tls_remote.c @@ -13,18 +13,19 @@ #include "tls_errors.h" #include "ucspissl.h" -/** @file tls_remote.c -- TLS client functions - @brief connection functions: tls_conn, tls_exit; - verification functions: tls_certkey, tls_checkpeer, tls_fingerprint, tlsa_check; - tls_destination, tls_domaincert - dummy functions: tls_crlcheck - - tls_checkpeer: r = 0 -> ADH, r = 1 -> wildcard DN, r = 2 -> DN, r = 3 -> CA; r < 0 -> error - tls_fingerprint: r = 0 -> failed, r = 1 -> ok; r < 0 -> error - tlsa_check: r = 0 -> nothing, r = usage + 1, r < 0 -> error +/** + @file tls_remote.c -- TLS client functions + @brief connection functions: tls_conn, tls_exit; + verification functions: tls_certkey, tls_checkpeer, tls_fingerprint, tlsa_check; + tls_destination, tls_domaincert + dummy functions: tls_crlcheck + + tls_checkpeer: r = 0 -> ADH, r = 1 -> wildcard DN, r = 2 -> DN, r = 3 -> CA; r < 0 -> error + tls_fingerprint: r = 0 -> failed, r = 1 -> ok; r < 0 -> error + tlsa_check: r = 0 -> nothing, r = usage + 1, r < 0 -> error */ -/* Caution: OpenSSL's X509_pubkey_digest() does not work as expected. +/* Caution: OpenSSL's X509_pubkey_digest() does not work as expected. I've included now: X509_pkey_digest() and X509_cert_digest() (as makro) */ #define X509_cert_digest X509_digest @@ -126,7 +127,6 @@ int tls_checkpeer(SSL *ssl, X509 *cert, const stralloc host, const int flag, con int tls_checkcrl(SSL *ssl) // not implemented yet { - return 0; } @@ -144,11 +144,12 @@ int dig_ascii(char *digascii, const char *digest, const int len) return (2 * j); // 2*len } -/* X509_pkey_digest() takes the same args as X509_digest(); - however returning the correct hash of pubkey in md. - Subjects keys are restricted to 2048 byte in size. - Return codes: 1: sucess, 0: failed. */ - +/* + X509_pkey_digest() takes the same args as X509_digest(); + however returning the correct hash of pubkey in md. + Subjects keys are restricted to 2048 byte in size. + Return codes: 1: sucess, 0: failed. +*/ int X509_pkey_digest(const X509 *cert, const EVP_MD *type, unsigned char *md, unsigned int *dlen) { unsigned int len = 0; @@ -171,10 +172,11 @@ int X509_pkey_digest(const X509 *cert, const EVP_MD *type, unsigned char *md, un return 1; } -/* Return codes: -4: no X.509 cert (fatal), -3: matching error (deferred), - -2: unsupported type, -1: weird TLSA record - 0: No X.509 cert; seen: usage++; */ - +/* + Return codes: -4: no X.509 cert (fatal), -3: matching error (deferred), + -2: unsupported type, -1: weird TLSA record + 0: No X.509 cert; seen: usage++; +*/ int tlsa_check(const STACK_OF(X509) * certs, const stralloc host, const unsigned long p) { const EVP_MD *methodsha256 = EVP_sha256(); @@ -201,8 +203,7 @@ int tlsa_check(const STACK_OF(X509) * certs, const stralloc host, const unsigned if (!stralloc_cats(&sa, "._tcp.")) temp_nomem(); if (!stralloc_cats(&sa, host.s)) temp_nomem(); - if (dns_cname(&cn, &sa) > 0) // query name could be a cname - { + if (dns_cname(&cn, &sa) > 0) { // query name could be a cname if (dns_tlsa(&out, &cn) <= 0) return 0; } else { if (dns_tlsa(&out, &sa) <= 0) return 0; @@ -211,7 +212,7 @@ int tlsa_check(const STACK_OF(X509) * certs, const stralloc host, const unsigned /* https://www.openssl.org/docs/man3.0/man3/X509_digest.html (1.1.1): "The len parameter, if not NULL, points to a place where the digest size will be stored." - [sigh] + [sigh] */ do { @@ -228,8 +229,9 @@ int tlsa_check(const STACK_OF(X509) * certs, const stralloc host, const unsigned } else if (type == 2) { if (selector == 0) r = X509_cert_digest(cert, methodsha512, digest, &dlen); if (selector == 1) r = X509_pkey_digest(cert, methodsha512, digest, &dlen); - } else + } else { return -2; + } if (!byte_diff(digest, dlen, out.s + i + 3)) return ++usage; } @@ -271,23 +273,22 @@ int tls_fingerprint(X509 *cert, const char *fingerprint, int dlen) int tls_exit(SSL *ssl) { if (SSL_shutdown(ssl) == 0) SSL_shutdown(ssl); - return 0; } -/** @brief tls_destination - @param stralloc hostname (maybe 0-terminated) +/** + @brief tls_destination + @param stralloc hostname (maybe 0-terminated) Certificate Fallthru - @return values: | ADH | Cert *DN FQDN Hash | noTLSA noTLS - ----------+-----+--------------------+------------- - optional TLS | 1 | 3 - - - | - 9 - mandatory TLS | 2 | 4 5 6 7 | 8 - - no TLS -1 - */ + @return values: | ADH | Cert *DN FQDN Hash | noTLSA noTLS + ----------+-----+--------------------+------------- + optional TLS | 1 | 3 - - - | - 9 + mandatory TLS | 2 | 4 5 6 7 | 8 + no TLS -1 +*/ int tls_destination(const stralloc hostname) { int i; diff --git a/src/tls_start.c b/src/tls_start.c index 12c8e75..434591f 100644 --- a/src/tls_start.c +++ b/src/tls_start.c @@ -15,6 +15,7 @@ static void die_nomem() { logmsg(WHO, 111, FATAL, "out of memory"); } + static void die_tlsenv() { logmsg(WHO, 111, FATAL, "no UCSPITLS environment to read"); diff --git a/src/tls_timeoutio.c b/src/tls_timeoutio.c index 3a2936b..e97c858 100644 --- a/src/tls_timeoutio.c +++ b/src/tls_timeoutio.c @@ -57,8 +57,9 @@ int tls_timeoutaccept(int t, int rfd, int wfd, SSL *ssl) if (r <= 0) { ndelay_off(rfd); ndelay_off(wfd); - } else + } else { SSL_set_mode(ssl, SSL_MODE_ENABLE_PARTIAL_WRITE); + } return r; } @@ -74,8 +75,9 @@ int tls_timeoutconn(int t, int rfd, int wfd, SSL *ssl) if (r <= 0) { ndelay_off(rfd); ndelay_off(wfd); - } else + } else { SSL_set_mode(ssl, SSL_MODE_ENABLE_PARTIAL_WRITE); + } return r; } diff --git a/src/token822.c b/src/token822.c index e1048c6..34d8c24 100644 --- a/src/token822.c +++ b/src/token822.c @@ -21,12 +21,12 @@ void token822_reverse(token822_alloc *ta) } } -GEN_ALLOC_ready(token822_alloc, struct token822, t, len, a, i, n, x, 30, token822_ready) - GEN_ALLOC_readyplus(token822_alloc, struct token822, t, len, a, i, n, x, 30, token822_readyplus) - GEN_ALLOC_append( - token822_alloc, struct token822, t, len, a, i, n, x, 30, token822_readyplus, token822_append) +GEN_ALLOC_ready(token822_alloc, struct token822, t, len, a, i, n, x, 30, token822_ready); +GEN_ALLOC_readyplus(token822_alloc, struct token822, t, len, a, i, n, x, 30, token822_readyplus); +GEN_ALLOC_append( + token822_alloc, struct token822, t, len, a, i, n, x, 30, token822_readyplus, token822_append); - static int needspace(int t1, int t2) +static int needspace(int t1, int t2) { if (!t1) return 0; if (t1 == TOKEN822_COLON) return 1; @@ -118,8 +118,8 @@ int token822_unparse(stralloc *sa, token822_alloc *ta, unsigned int linelen) case TOKEN822_LITERAL: case TOKEN822_COMMENT: if (t->type != TOKEN822_ATOM) len += 2; - for (j = 0; j < t->slen; ++j) switch (ch = t->s[j]) - { + for (j = 0; j < t->slen; ++j) { + switch (ch = t->s[j]) { case '"': case '[': case ']': @@ -130,6 +130,7 @@ int token822_unparse(stralloc *sa, token822_alloc *ta, unsigned int linelen) case '\n': ++len; default: ++len; } + } break; } } @@ -180,8 +181,8 @@ int token822_unparse(stralloc *sa, token822_alloc *ta, unsigned int linelen) if (t->type == TOKEN822_LITERAL) *s++ = '['; if (t->type == TOKEN822_COMMENT) *s++ = '('; - for (j = 0; j < t->slen; ++j) switch (ch = t->s[j]) - { + for (j = 0; j < t->slen; ++j) { + switch (ch = t->s[j]) { case '"': case '[': case ']': @@ -192,6 +193,7 @@ int token822_unparse(stralloc *sa, token822_alloc *ta, unsigned int linelen) case '\n': *s++ = '\\'; default: *s++ = ch; } + } if (t->type == TOKEN822_QUOTE) *s++ = '"'; if (t->type == TOKEN822_LITERAL) *s++ = ']'; if (t->type == TOKEN822_COMMENT) *s++ = ')'; @@ -272,8 +274,8 @@ int token822_parse(token822_alloc *ta, stralloc *sa, stralloc *buf) numchars = 0; numtoks = 0; - for (i = 0; i < salen; ++i) switch (sa->s[i]) - { + for (i = 0; i < salen; ++i) { + switch (sa->s[i]) { case '.': case ',': case '@': @@ -339,6 +341,7 @@ int token822_parse(token822_alloc *ta, stralloc *sa, stralloc *buf) --i; ++numtoks; } + } if (!token822_ready(ta, numtoks)) return -1; if (!stralloc_ready(buf, numchars)) return -1; @@ -347,8 +350,8 @@ int token822_parse(token822_alloc *ta, stralloc *sa, stralloc *buf) t = ta->t; - for (i = 0; i < salen; ++i) switch (sa->s[i]) - { + for (i = 0; i < salen; ++i) { + switch (sa->s[i]) { case '.': t->type = TOKEN822_DOT; ++t; @@ -442,6 +445,7 @@ int token822_parse(token822_alloc *ta, stralloc *sa, stralloc *buf) --i; ++t; } + } return 1; } diff --git a/src/trigger.c b/src/trigger.c index 4b7cc49..0578430 100644 --- a/src/trigger.c +++ b/src/trigger.c @@ -1,5 +1,7 @@ #include "trigger.h" +#include <unistd.h> + #include "close.h" #include "ndelay.h" #include "open.h" @@ -28,8 +30,6 @@ int trigger_pulled(fd_set *rfds) return 0; } -void write(); /* compiler warning (temp) */ - void triggerpull() { int fd; diff --git a/src/wildmat.c b/src/wildmat.c index 363c118..bcff8dd 100644 --- a/src/wildmat.c +++ b/src/wildmat.c @@ -1,41 +1,41 @@ -/*** wildmat.c.orig Wed Dec 3 11:46:31 1997 */ -/* $Revision: 1.1 $ -** -** Do shell-style pattern matching for ?, \, [], and * characters. -** Might not be robust in face of malformed patterns; e.g., "foo[a-" -** could cause a segmentation violation. It is 8bit clean. -** -** Written by Rich $alz, mirror!rs, Wed Nov 26 19:03:17 EST 1986. -** Rich $alz is now <rsalz@osf.org>. -** April, 1991: Replaced mutually-recursive calls with in-line code -** for the star character. -** -** Special thanks to Lars Mathiesen <thorinn@diku.dk> for the ABORT code. -** This can greatly speed up failing wildcard patterns. For example: -** pattern: -*-*-*-*-*-*-12-*-*-*-m-*-*-* -** text 1: -adobe-courier-bold-o-normal--12-120-75-75-m-70-iso8859-1 -** text 2: -adobe-courier-bold-o-normal--12-120-75-75-X-70-iso8859-1 -** Text 1 matches with 51 calls, while text 2 fails with 54 calls. Without -** the ABORT code, it takes 22310 calls to fail. Ugh. The following -** explanation is from Lars: -** The precondition that must be fulfilled is that DoMatch will consume -** at least one character in text. This is true if *p is neither '*' nor -** '\0'.) The last return has ABORT instead of FALSE to avoid quadratic -** behaviour in cases like pattern "*a*b*c*d" with text "abcxxxxx". With -** FALSE, each star-loop has to run to the end of the text; with ABORT -** only the last one does. -** -** Once the control of one instance of DoMatch enters the star-loop, that -** instance will return either TRUE or ABORT, and any calling instance -** will therefore return immediately after (without calling recursively -** again). In effect, only one star-loop is ever active. It would be -** possible to modify the code to maintain this context explicitly, -** eliminating all recursive calls at the cost of some complication and -** loss of clarity (and the ABORT stuff seems to be unclear enough by -** itself). I think it would be unwise to try to get this into a -** released version unless you have a good test data base to try it out -** on. -*/ +/*** wildmat.c.orig Wed Dec 3 11:46:31 1997 */ +/* $Revision: 1.1 $ + * + * Do shell-style pattern matching for ?, \, [], and * characters. + * Might not be robust in face of malformed patterns; e.g., "foo[a-" + * could cause a segmentation violation. It is 8bit clean. + * + * Written by Rich $alz, mirror!rs, Wed Nov 26 19:03:17 EST 1986. + * Rich $alz is now <rsalz@osf.org>. + * April, 1991: Replaced mutually-recursive calls with in-line code + * for the star character. + * + * Special thanks to Lars Mathiesen <thorinn@diku.dk> for the ABORT code. + * This can greatly speed up failing wildcard patterns. For example: + * pattern: -*-*-*-*-*-*-12-*-*-*-m-*-*-* + * text 1: -adobe-courier-bold-o-normal--12-120-75-75-m-70-iso8859-1 + * text 2: -adobe-courier-bold-o-normal--12-120-75-75-X-70-iso8859-1 + * Text 1 matches with 51 calls, while text 2 fails with 54 calls. Without + * the ABORT code, it takes 22310 calls to fail. Ugh. The following + * explanation is from Lars: + * The precondition that must be fulfilled is that DoMatch will consume + * at least one character in text. This is true if *p is neither '*' nor + * '\0'.) The last return has ABORT instead of FALSE to avoid quadratic + * behaviour in cases like pattern "*a*b*c*d" with text "abcxxxxx". With + * FALSE, each star-loop has to run to the end of the text; with ABORT + * only the last one does. + * + * Once the control of one instance of DoMatch enters the star-loop, that + * instance will return either TRUE or ABORT, and any calling instance + * will therefore return immediately after (without calling recursively + * again). In effect, only one star-loop is ever active. It would be + * possible to modify the code to maintain this context explicitly, + * eliminating all recursive calls at the cost of some complication and + * loss of clarity (and the ABORT stuff seems to be unclear enough by + * itself). I think it would be unwise to try to get this into a + * released version unless you have a good test data base to try it out + * on. + */ #define TRUE 1 #define FALSE 0 @@ -48,20 +48,20 @@ /* Do tar(1) matching rules, which ignore a trailing slash? */ #undef MATCH_TAR_PATTERN -/* -** Match text and p, return TRUE, FALSE, or ABORT. -*/ -static int DoMatch(register char *text, register char *p) +/** + * Match text and p, return TRUE, FALSE, or ABORT. + */ +static int DoMatch(char *text, char *p) { - register int last; - register int matched; - register int reverse; + int last; + int matched; + int reverse; for (; *p; text++, p++) { if (*text == '\0' && *p != '*') return ABORT; switch (*p) { case '\\': /* Literal match with following character. */ p++; - case '?': /* Match anything. */ continue; + case '?': /* Match anything. */ continue; case '*': /* Consecutive stars act just like one. */ while (*++p == '*') continue; if (*p == '\0') return TRUE; /* Trailing star matches everything. */ @@ -90,9 +90,9 @@ static int DoMatch(register char *text, register char *p) return *text == '\0'; } -/* -** User-level routine. Returns TRUE or FALSE. -*/ +/** + * User-level routine. Returns TRUE or FALSE. + */ int wildmat(char *text, char *p) { #ifdef OPTIMIZE_JUST_STAR |