From 7e96de23175e4d490b06b31b2883e83680fdb4ea Mon Sep 17 00:00:00 2001 From: pfelt Date: Fri, 30 Nov 2007 07:15:17 +0000 Subject: [PATCH] -- the queue now will rewrite the envelope with correct values as to if a recipient is local or remote. this removes the need for smtp to listen on queues 6 and 7 both -- change an old LoggerEvent call for the new Log function call -- fixed a bug in CheckTrustedHost() where it wouldn't ever find an entry --- src/agents/queue/conf.c | 2 +- src/agents/queue/messages.h | 20 +++++------ src/agents/queue/queue.c | 70 +++++++++++++++---------------------- src/agents/queue/queued.c | 43 ++++++++++++----------- src/agents/queue/queued.h | 1 + 5 files changed, 64 insertions(+), 72 deletions(-) diff --git a/src/agents/queue/conf.c b/src/agents/queue/conf.c index 771b058..6f9b559 100644 --- a/src/agents/queue/conf.c +++ b/src/agents/queue/conf.c @@ -175,7 +175,7 @@ ReadConfiguration (BOOL *recover) XplConsolePrintf("bongoqueue: WARNING - Tuning parameters adjusted to %ld par./%ld seq.\r\n", Conf.maxConcurrentWorkers, Conf.maxSequentialWorkers); XplBell(); - LoggerEvent(Agent.agent.loggingHandle, LOGGER_SUBSYSTEM_CONFIGURATION, LOGGER_EVENT_QLIMITS_ADJUSTED, LOG_WARNING, 0, NULL, NULL, Conf.maxConcurrentWorkers, Conf.maxSequentialWorkers, NULL, 0); + Log(LOG_INFO, "Not enough memory; tuning parameters adjusted; concurrent limit: %d, sequential limit: %d", Conf.maxConcurrentWorkers, Conf.maxSequentialWorkers); Conf.defaultConcurrentWorkers = Conf.maxConcurrentWorkers; Conf.defaultSequentialWorkers = Conf.maxSequentialWorkers; } diff --git a/src/agents/queue/messages.h b/src/agents/queue/messages.h index c95994d..4c36b55 100644 --- a/src/agents/queue/messages.h +++ b/src/agents/queue/messages.h @@ -116,16 +116,16 @@ #define NMAP_DOMAIN_LOCATION_COMMAND "DOMAIN LOCATION" #define NMAP_DOMAIN_LOCATION_HELP "DOMAIN LOCATION - Determine if a domain is local or remote.\r\n" -#define MSG1000LOCAL "1000 LOCAL %s\r\n" -#define MSG1001RELAY "1001 RELAY %s\r\n" -#define MSG1002REMOTE "1002 REMOTE %s\r\n" -#define MSG4001NO_USER "4001 Invalid address %s\r\n" -#define MSG4000LOOP "4000 Aliasing loop\r\n" -#define MSG4000UNKNOWN_TYPE "4000 Unknown mapping type\r\n" +#define MSG1000LOCAL "1000 LOCAL %s" +#define MSG1001RELAY "1001 RELAY %s" +#define MSG1002REMOTE "1002 REMOTE %s" +#define MSG4001NO_USER "4001 Invalid address %s" +#define MSG4000LOOP "4000 Aliasing loop" +#define MSG4000UNKNOWN_TYPE "4000 Unknown mapping type" /* --------------------------------------------------- */ -#define MSG1000READY "Bongo NMAP server ready" -#define MSG1000BYE "Bongo NMAP signing off" +#define MSG1000READY "bongoqueue server ready" +#define MSG1000BYE "bongoqueue signing off" #define MSG1000LOGINOK "1000 Login ok\r\n" #define MSG1000FLAGSET "Flags set" #define MSG1000FLAGINFO "Current Flags" @@ -257,8 +257,8 @@ #define MSG4230PATHTOOLONG "4230 Path exceeds allowed length\r\n" #define MSG4240NOPERMISSION "4240 Permission denied\r\n" #define MSG4241AUTHDONE "4241 Already authenticated\r\n" -#define MSG4242AUTHREQUIRED "4242 NMAP <%s>\r\n" -#define MSG4242AUTHREQUIREDF "4242 NMAP <%x%s%x>\r\n" +#define MSG4242AUTHREQUIRED "4242 bongoqueue <%s>\r\n" +#define MSG4242AUTHREQUIREDF "4242 bongoqueue <%x%s%x>\r\n" #define MSG4260NOQENTRY "4260 No queue entry open, try QCREA\r\n" #define MSG4261NODOMAIN "4261 No queue entry with that domain\r\n" #define MSG4262NOTFOUND "4262 Field/Content not found\r\n" diff --git a/src/agents/queue/queue.c b/src/agents/queue/queue.c index d5c876b..498a485 100644 --- a/src/agents/queue/queue.c +++ b/src/agents/queue/queue.c @@ -893,40 +893,7 @@ StartOver: } case QUEUE_RECIP_LOCAL: - case QUEUE_RECIP_MBOX_LOCAL: { - if (ptr) { - *ptr = '\0'; - } - - ptr2 = strchr(cur + 1, ' '); - if (ptr2) { - *ptr2 = '\0'; - } - -/* TODO: here */ - if (MsgAuthFindUser(cur+1) == 0) { - if (ptr2) { - fprintf(newFH, "%c%s %s\r\n", *cur, cur+1, cur+1); - } else { - fprintf(newFH, "%c%s %s %d\r\n", *cur, cur+1, cur+1, DSN_FAILURE); - } - } else { - Log(LOG_INFO, "Entry %ld queue %d, can't find %s", entryID, queue, cur + 1); - - if (ptr2) { - *ptr2 = ' '; - } - - if (ptr) { - *ptr = '\n'; - } - - fwrite(cur, sizeof(unsigned char), next - cur, newFH); - } - - break; - } - + case QUEUE_RECIP_MBOX_LOCAL: case QUEUE_RECIP_REMOTE: { if (ptr) { *ptr = '\0'; @@ -936,15 +903,35 @@ StartOver: if (ptr2) { *ptr2 = '\0'; } -/* TODO: here */ - if (ptr2) { - fprintf(newFH, QUEUES_RECIP_REMOTE"%s %s\n", cur + 1, ptr2 + 1); - } else { - fprintf(newFH, QUEUES_RECIP_REMOTE"%s %s %d\r\n", cur + 1, cur + 1, DSN_FAILURE); + /* alias this user */ + unsigned char buffer[1024]; /* FIXME: is this too big? */ + unsigned char *addrptr; + int cnt; + + aliasing(cur+1, &cnt, buffer); + + /* find the address in teh result buffer so that we can rewrite it properly */ + addrptr = strrchr(buffer, ' '); + addrptr++; + switch(atoi(buffer)) { + case 1000: + /* this is a local user, change the envelope to reflect that */ + fprintf(newFH, QUEUES_RECIP_LOCAL"%s %s\r\n", addrptr, cur+1); + break; + case 1002: + fprintf(newFH, QUEUES_RECIP_REMOTE"%s %s\r\n", addrptr, cur+1); + break; + default: + fprintf(newFH, "%c%s %s %d\r\n", *cur, addrptr, cur+1, DSN_FAILURE); + break; + } + if (ptr) { + *ptr = '\n'; + } + if (ptr2) { + *ptr2 = ' '; } - - break; } case QUEUE_ADDRESS: @@ -1630,6 +1617,7 @@ StartOver: return(TRUE); } + Log(LOG_DEBUG, "Handing off to agent queue %d", queue); /* We got a connection to the guy, tell him what to do */ ConnWriteF(client->conn, "6020 %03d-%s %ld %ld %ld\r\n", queue, entry, (unsigned long)sb.st_size, dSize, lines); ConnWriteFile(client->conn, fh); diff --git a/src/agents/queue/queued.c b/src/agents/queue/queued.c index ade5d13..dacbc4c 100644 --- a/src/agents/queue/queued.c +++ b/src/agents/queue/queued.c @@ -120,20 +120,20 @@ int hostedFindFunc(const void *str1, const void *str2) { * 2: username == domain * 3: username == auth subsystem */ -BOOL aliasing(Connection *conn, char *addr, int *cnt) { +BOOL aliasing(char *addr, int *cnt, unsigned char *buffer) { unsigned char *local = NULL; unsigned char *domain = NULL; int i=-1; BOOL result=FALSE; if (addr[0] == '\0') { - ConnWriteF(conn, MSG4001NO_USER, ""); + sprintf(buffer, MSG4001NO_USER, ""); return TRUE; } /* very rudimentary way to prevent loops */ if (*cnt > 5) { - ConnWriteStr(conn, MSG4000LOOP); + strcpy(buffer, MSG4000LOOP); return TRUE; } @@ -146,12 +146,12 @@ BOOL aliasing(Connection *conn, char *addr, int *cnt) { /* if i get here, then i don't have a domain. assume this is the username. the only possible * choices here are type 0 and type 3 */ if (MsgAuthFindUser(local) == 0) { - ConnWriteF(conn, MSG1000LOCAL, local); + sprintf(buffer, MSG1000LOCAL, local); result = TRUE; goto ExitAliasing; } else { /* the user was not found. it must be an invalid user */ - ConnWriteF(conn, MSG4001NO_USER, local); + sprintf(buffer, MSG4001NO_USER, local); result = TRUE; goto ExitAliasing; } @@ -170,11 +170,11 @@ BOOL aliasing(Connection *conn, char *addr, int *cnt) { if (a.aliases && a.aliases->len && ((i = BongoArrayFindSorted(a.aliases, local, (ArrayCompareFunc)aliasFindFunc)) > -1)) { AliasStruct b; b = BongoArrayIndex(a.aliases, AliasStruct, i); - result = aliasing(conn, b.to, cnt); + result = aliasing(b.to, cnt, buffer); } else if (a.to && a.to[0] != '\0') { /* there are no user aliasess is there a domain alias? */ snprintf(new_addr, 999, "%s@%s", local, a.to); - result = aliasing(conn, new_addr, cnt); + result = aliasing(new_addr, cnt, buffer); } /* we haven't already handled the address. it must be a local address */ @@ -183,30 +183,30 @@ BOOL aliasing(Connection *conn, char *addr, int *cnt) { switch (a.mapping_type) { case 0: if (MsgAuthFindUser(local) == 0) { - ConnWriteF(conn, MSG1000LOCAL, local); + sprintf(buffer, MSG1000LOCAL, local); result = TRUE; } break; case 1: if (MsgAuthFindUser(addr) == 0) { - ConnWriteF(conn, MSG1000LOCAL, addr); + sprintf(buffer, MSG1000LOCAL, addr); result = TRUE; } break; case 2: if (MsgAuthFindUser(domain) == 0) { - ConnWriteF(conn, MSG1000LOCAL, domain); + sprintf(buffer, MSG1000LOCAL, domain); result = TRUE; } break; case 3: /* unhandled for now */ - ConnWriteStr(conn, MSG4000UNKNOWN_TYPE); + strcpy(buffer, MSG4000UNKNOWN_TYPE); result = TRUE; break; default: /* unhandled forever */ - ConnWriteStr(conn, MSG4000UNKNOWN_TYPE); + strcpy(buffer, MSG4000UNKNOWN_TYPE); result = TRUE; break; } @@ -214,12 +214,12 @@ BOOL aliasing(Connection *conn, char *addr, int *cnt) { /* if we still haven't resolved the address, it is an unknown user */ if (result == FALSE) { - ConnWriteF(conn, MSG4001NO_USER, addr); + sprintf(buffer, MSG4001NO_USER, addr); result = TRUE; } } else { /* the user must be remote */ - ConnWriteF(conn, MSG1002REMOTE, addr); + sprintf(buffer, MSG1002REMOTE, addr); result = TRUE; goto ExitAliasing; } @@ -239,11 +239,14 @@ BOOL aliasing(Connection *conn, char *addr, int *cnt) { int CommandAddressResolve(void *param) { BOOL handled=FALSE; int cnt=0; + unsigned char buffer[1024]; /* FIXME: is this too big? */ QueueClient *client = (QueueClient *)param; - handled = aliasing(client->conn, client->buffer + 16, &cnt); + handled = aliasing(client->buffer + 16, &cnt, &buffer); if (!handled) { - ConnWriteF(client->conn, MSG4001NO_USER, client->buffer + 16); + ConnWriteF(client->conn, MSG4001NO_USER"\r\n", client->buffer + 16); + } else { + ConnWriteF(client->conn, "%s\r\n", buffer); } return 0; } @@ -257,10 +260,10 @@ int CommandDomainLocation(void *param) { /* now search for it */ int idx = BongoArrayFindSorted(Conf.hostedDomains, domain, (ArrayCompareFunc)hostedFindFunc); if (idx > -1) { - ConnWriteF(client->conn, MSG1000LOCAL, domain); + ConnWriteF(client->conn, MSG1000LOCAL"\r\n", domain); } else { /* TODO: add the relay domain stuff */ - ConnWriteF(client->conn, MSG1002REMOTE, domain); + ConnWriteF(client->conn, MSG1002REMOTE"\r\n", domain); } return 0; } @@ -425,10 +428,10 @@ CheckTrustedHost(QueueClient *client) if (Conf.trustedHosts) { /* TODO: this can be optimized a little bit */ XplRWReadLockAcquire(&Conf.lock); - i = BongoArrayFindSorted(Conf.trustedHosts, inet_ntoa(client->conn->socketAddress.sin_addr), (ArrayCompareFunc)strcasecmp); + i = BongoArrayFindSorted(Conf.trustedHosts, inet_ntoa(client->conn->socketAddress.sin_addr), (ArrayCompareFunc)hostedFindFunc); XplRWReadLockRelease(&Conf.lock); } - return (i > 0); + return (i > -1); } int diff --git a/src/agents/queue/queued.h b/src/agents/queue/queued.h index 5a33584..257dc83 100644 --- a/src/agents/queue/queued.h +++ b/src/agents/queue/queued.h @@ -99,6 +99,7 @@ extern QueueAgent Agent; void QueueClientFree(void *clientp); int HandleCommand(QueueClient *client); +BOOL aliasing(char *addr, int *cnt, unsigned char *buffer); #define STACKSPACE_Q (1024*80)