From 3f993bf9d1c69121f87207dca7f1ea675286ad8b Mon Sep 17 00:00:00 2001 From: alexhudson Date: Tue, 24 Jul 2007 12:08:37 +0000 Subject: [PATCH] Second piece of connmgr removal: bye bye agent, bye bye libs. --- src/agents/connmgr/Bongo.rules | 35 - src/agents/connmgr/Makefile.am | 17 - .../connmgr/cmmodules/lists/Bongo.rules | 19 - .../connmgr/cmmodules/lists/Makefile.am | 17 - src/agents/connmgr/cmmodules/lists/cmlists.c | 350 ----- src/agents/connmgr/cmmodules/lists/cmlists.h | 73 - src/agents/connmgr/cmmodules/rbl/Bongo.rules | 23 - src/agents/connmgr/cmmodules/rbl/Makefile.am | 17 - src/agents/connmgr/cmmodules/rbl/cmrbl.c | 495 ------- src/agents/connmgr/cmmodules/rbl/cmrbl.h | 123 -- src/agents/connmgr/cmmodules/rdns/Bongo.rules | 23 - src/agents/connmgr/cmmodules/rdns/Makefile.am | 17 - src/agents/connmgr/cmmodules/rdns/cmrdns.c | 360 ----- src/agents/connmgr/cmmodules/rdns/cmrdns.h | 99 -- src/agents/connmgr/cmmodules/user/Bongo.rules | 19 - src/agents/connmgr/cmmodules/user/Makefile.am | 17 - src/agents/connmgr/cmmodules/user/cmuser.c | 293 ---- src/agents/connmgr/cmmodules/user/cmuser.h | 61 - src/agents/connmgr/connmgr.c | 1290 ----------------- src/agents/connmgr/connmgrp.h | 42 - src/agents/connmgr/modules.c | 212 --- src/libs/connmgr/Bongo.rules | 10 - src/libs/connmgr/Makefile.am | 17 - src/libs/connmgr/connmgr.c | 342 ----- src/libs/connmgr/hashcred.c | 137 -- 25 files changed, 4108 deletions(-) delete mode 100644 src/agents/connmgr/Bongo.rules delete mode 100644 src/agents/connmgr/Makefile.am delete mode 100644 src/agents/connmgr/cmmodules/lists/Bongo.rules delete mode 100644 src/agents/connmgr/cmmodules/lists/Makefile.am delete mode 100644 src/agents/connmgr/cmmodules/lists/cmlists.c delete mode 100644 src/agents/connmgr/cmmodules/lists/cmlists.h delete mode 100644 src/agents/connmgr/cmmodules/rbl/Bongo.rules delete mode 100644 src/agents/connmgr/cmmodules/rbl/Makefile.am delete mode 100644 src/agents/connmgr/cmmodules/rbl/cmrbl.c delete mode 100644 src/agents/connmgr/cmmodules/rbl/cmrbl.h delete mode 100644 src/agents/connmgr/cmmodules/rdns/Bongo.rules delete mode 100644 src/agents/connmgr/cmmodules/rdns/Makefile.am delete mode 100644 src/agents/connmgr/cmmodules/rdns/cmrdns.c delete mode 100644 src/agents/connmgr/cmmodules/rdns/cmrdns.h delete mode 100644 src/agents/connmgr/cmmodules/user/Bongo.rules delete mode 100644 src/agents/connmgr/cmmodules/user/Makefile.am delete mode 100644 src/agents/connmgr/cmmodules/user/cmuser.c delete mode 100644 src/agents/connmgr/cmmodules/user/cmuser.h delete mode 100644 src/agents/connmgr/connmgr.c delete mode 100644 src/agents/connmgr/connmgrp.h delete mode 100644 src/agents/connmgr/modules.c delete mode 100644 src/libs/connmgr/Bongo.rules delete mode 100644 src/libs/connmgr/Makefile.am delete mode 100644 src/libs/connmgr/connmgr.c delete mode 100644 src/libs/connmgr/hashcred.c diff --git a/src/agents/connmgr/Bongo.rules b/src/agents/connmgr/Bongo.rules deleted file mode 100644 index a01fa35..0000000 --- a/src/agents/connmgr/Bongo.rules +++ /dev/null @@ -1,35 +0,0 @@ -# -*- Makefile -*- -cmmoduledir = $(libdir)/connmgr -cmmodule_LTLIBRARIES := - -sbin_PROGRAMS += bongoconnmgr - -bongoconnmgr_SOURCES := \ - src/agents/connmgr/connmgr.c \ - src/agents/connmgr/connmgrp.h \ - src/agents/connmgr/modules.c - -bongoconnmgr_LDADD := \ - libbongomanagement.la \ - libbongomsgapi.la \ - libbongomdb.la \ - libbongologger.la \ - libbongoconnio.la \ - libbongomemmgr.la \ - libbongoutil.la \ - libbongoxpl.la \ - $(top_builddir)/import/log4c/log4c/libbongolog4c.la \ - $(SQLITE_LIBS) \ - $(PTHREAD_LIBS) \ - $(ALL_LIBS) - -src/agents/connmgr/all: bongoconnmgr \ - src/agents/connmgr/cmmodules/rbl/all \ - src/agents/connmgr/cmmodules/rdns/all \ - src/agents/connmgr/cmmodules/user/all \ - src/agents/connmgr/cmmodules/lists/all - -src/agents/connmgr/clean: clean -src/agents/connmgr/install: - @cd $(top_builddir) && $(MAKE) $(MFLAGS) sbin_PROGRAMS=bongoconnmgr \ - install-sbinPROGRAMS install-cmmoduleLTLIBRARIES diff --git a/src/agents/connmgr/Makefile.am b/src/agents/connmgr/Makefile.am deleted file mode 100644 index 8830401..0000000 --- a/src/agents/connmgr/Makefile.am +++ /dev/null @@ -1,17 +0,0 @@ -# -*- Makefile -*- -# -# Do not edit! -# -# (unless this is Makefile.am.subdir) -# -# This file is a copy of the toplevel Makefile.am.subdir. If changes -# need to be made, edit that file, and make update-makefiles, and -# check the new files in. -# -# This is a skeletal automake file. The real automake fules for -# building the targets for this directory can be found in the -# Bongo.rules file. This file is simply here so that 'make all' can -# work in each subdirectory. - -all clean install: - @cd $(top_builddir) && $(MAKE) $(MFLAGS) $(subdir)/$@ diff --git a/src/agents/connmgr/cmmodules/lists/Bongo.rules b/src/agents/connmgr/cmmodules/lists/Bongo.rules deleted file mode 100644 index f6af5ee..0000000 --- a/src/agents/connmgr/cmmodules/lists/Bongo.rules +++ /dev/null @@ -1,19 +0,0 @@ -# -*- Makefile -*- -cmmodule_LTLIBRARIES += libcmlists.la - -libcmlists_la_SOURCES := \ - src/agents/connmgr/cmmodules/lists/cmlists.c \ - src/agents/connmgr/cmmodules/lists/cmlists.h - -libcmlists_la_LDFLAGS := -module -avoid-version -libcmlists_la_LIBADD := \ - libbongomsgapi.la \ - libbongologger.la \ - libbongomemmgr.la \ - libbongomdb.la \ - libbongoxpl.la \ - $(PTHREAD_LIBS) \ - $(ALL_LIBS) - -src/agents/connmgr/cmmodules/lists/all: libcmlists.la -src/agents/connmgr/cmmodules/lists/clean: clean diff --git a/src/agents/connmgr/cmmodules/lists/Makefile.am b/src/agents/connmgr/cmmodules/lists/Makefile.am deleted file mode 100644 index 8830401..0000000 --- a/src/agents/connmgr/cmmodules/lists/Makefile.am +++ /dev/null @@ -1,17 +0,0 @@ -# -*- Makefile -*- -# -# Do not edit! -# -# (unless this is Makefile.am.subdir) -# -# This file is a copy of the toplevel Makefile.am.subdir. If changes -# need to be made, edit that file, and make update-makefiles, and -# check the new files in. -# -# This is a skeletal automake file. The real automake fules for -# building the targets for this directory can be found in the -# Bongo.rules file. This file is simply here so that 'make all' can -# work in each subdirectory. - -all clean install: - @cd $(top_builddir) && $(MAKE) $(MFLAGS) $(subdir)/$@ diff --git a/src/agents/connmgr/cmmodules/lists/cmlists.c b/src/agents/connmgr/cmmodules/lists/cmlists.c deleted file mode 100644 index 037534e..0000000 --- a/src/agents/connmgr/cmmodules/lists/cmlists.c +++ /dev/null @@ -1,350 +0,0 @@ -/**************************************************************************** - * - * Copyright (c) 2001 Novell, Inc. All Rights Reserved. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public License - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, contact Novell, Inc. - * - * To contact Novell about this file by physical or electronic mail, you - * may find current contact information at www.novell.com. - * - ****************************************************************************/ - -#include -#include -#include -#include -#include - -#include "cmlists.h" - -/* Globals */ -BOOL ListUnloadOk = TRUE; -ListGlobal List; - -static BOOL ReadConfiguration(void); - - -EXPORT int ListsVerify(ConnMgrCommand *command, ConnMgrResult *result) -{ - unsigned long i; - - /* Check Allowed List */ - if ((XplStrCaseCmp(command->event, CM_EVENT_RELAY) == 0) || (XplStrCaseCmp(command->event, CM_EVENT_CONNECT) == 0)) { - for (i = 0; i < List.allowed.count; i++) { - if ((List.allowed.start[i] <= (long) command->address) && ((long) command->address <= List.allowed.end[i])) { - /* We like the guy */ - return(CM_MODULE_ACCEPT | CM_MODULE_PERMANENT | CM_MODULE_FORCE); - } - } - } - - /* Check Blocked List */ - if (XplStrCaseCmp(command->event, CM_EVENT_CONNECT) == 0) { - for (i = 0; i < List.blocked.count; i++) { - if ((List.blocked.start[i] <= (long) command->address) && ((long) command->address <= List.blocked.end[i])) { - /* We don't like the guy */ - return(CM_MODULE_DENY | CM_MODULE_PERMANENT | CM_MODULE_FORCE); - } - } - } - - return(0); -} - -EXPORT BOOL -CMLISTSInit(CMModuleRegistrationStruct *registration, unsigned char *datadir) -{ - if (ListUnloadOk == TRUE) { - XplSafeWrite(List.threadCount, 0); - - List.directoryHandle = (MDBHandle) MsgInit(); - if (List.directoryHandle) { - ListUnloadOk = FALSE; - - List.logHandle = LoggerOpen("cmlist"); - if (List.logHandle == NULL) { - XplConsolePrintf("cmlist: Unable to initialize logging. Logging disabled.\r\n"); - } - - /* Fill out registration information */ - registration->priority = 1; /* It is important that the lists are early */ - registration->Shutdown = ListsShutdown; - registration->Verify = ListsVerify; - registration->Notify = NULL; - - XplSafeIncrement(List.threadCount); - - strcpy(List.config.datadir, datadir); - - return(ReadConfiguration()); - } else { - XplConsolePrintf("cmlist: Failed to obtain directory handle\r\n"); - } - } - - return(FALSE); -} - -static void -AddBlockedAddress(const unsigned char *AddressStart, const unsigned char *AddressEnd) -{ - if ((List.blocked.count + 1) > List.blocked.allocated) { - List.blocked.start = MemRealloc(List.blocked.start, (List.blocked.allocated + 5) * sizeof(unsigned long)); - List.blocked.end = MemRealloc(List.blocked.end, (List.blocked.allocated + 5) * sizeof(unsigned long)); - - if (!List.blocked.start || !List.blocked.end) { - LoggerEvent(List.logHandle, LOGGER_SUBSYSTEM_GENERAL, LOGGER_EVENT_OUT_OF_MEMORY, LOG_ERROR, 0, __FILE__, NULL, ((List.blocked.allocated+5) + (List.blocked.allocated+5)) * sizeof(unsigned long), __LINE__, NULL, 0); - return; - } - - List.blocked.allocated += 5; - } - - if ((List.blocked.start[List.blocked.count] = inet_addr(AddressStart)) != -1) { - List.blocked.start[List.blocked.count] = ntohl(List.blocked.start[List.blocked.count]); - - if ((List.blocked.end[List.blocked.count] = inet_addr(AddressEnd)) != -1) { - List.blocked.end[List.blocked.count] = ntohl(List.blocked.end[List.blocked.count]); - List.blocked.count++; - } - } -} - -static void -FreeBlockedAddresses(void) -{ - if (List.blocked.start) { - MemFree(List.blocked.start); - } - - List.blocked.start = NULL; - - if (List.blocked.end) { - MemFree(List.blocked.end); - } - List.blocked.end = NULL; - - List.blocked.allocated = 0; - List.blocked.count = 0; -} - -static void -AddAllowedAddress(const unsigned char *AddressStart, const unsigned char *AddressEnd) -{ - if ((List.allowed.count + 1) > List.allowed.allocated) { - List.allowed.start = MemRealloc(List.allowed.start, (List.allowed.allocated + 5) * sizeof(unsigned long)); - List.allowed.end = MemRealloc(List.allowed.end, (List.allowed.allocated + 5) * sizeof(unsigned long)); - - if (!List.allowed.start || !List.allowed.end) { - LoggerEvent(List.logHandle, LOGGER_SUBSYSTEM_GENERAL, LOGGER_EVENT_OUT_OF_MEMORY, LOG_ERROR, 0, __FILE__, NULL, ((List.allowed.allocated+5) + (List.allowed.allocated+5)) * sizeof(unsigned long), __LINE__, NULL, 0); - return; - } - - List.allowed.allocated += 5; - } - - if ((List.allowed.start[List.allowed.count] = inet_addr(AddressStart)) != -1) { - List.allowed.start[List.allowed.count] = ntohl(List.allowed.start[List.allowed.count]); - - if ((List.allowed.end[List.allowed.count] = inet_addr(AddressEnd)) != -1) { - List.allowed.end[List.allowed.count] = ntohl(List.allowed.end[List.allowed.count]); - List.allowed.count++; - } - } -} - -static void -FreeAllowedAddresses(void) -{ - if (List.allowed.start) { - MemFree(List.allowed.start); - } - - List.allowed.start = NULL; - - if (List.allowed.end) { - MemFree(List.allowed.end); - } - - List.allowed.end = NULL; - - List.allowed.allocated = 0; - List.allowed.count = 0; -} - -EXPORT BOOL -ListsShutdown(void) -{ - XplSafeDecrement(List.threadCount); - - if (ListUnloadOk == FALSE) { - ListUnloadOk = TRUE; - - /* - Make sure the library lists are gone before beginning to - shutdown. - */ - while (XplSafeRead(List.threadCount)) { - XplDelay(33); - } - - LoggerClose(List.logHandle); - FreeBlockedAddresses(); - FreeAllowedAddresses(); - -#if defined(NETWARE) || defined(LIBC) - XplSignalLocalSemaphore(List.shutdownSemaphore); /* The signal will release main() */ - XplWaitOnLocalSemaphore(List.shutdownSemaphore); /* The wait will wait until main() is gone */ - - XplCloseLocalSemaphore(List.shutdownSemaphore); -#endif - } - - return(FALSE); -} - -static BOOL -ReadConfiguration(void) -{ - MDBValueStruct *config; - const unsigned char *Address; - MDBEnumStruct *e; - unsigned char *ptr; - - config = MDBCreateValueStruct(List.directoryHandle, MsgGetServerDN(NULL)); - e = MDBCreateEnumStruct(config); - - if (MDBRead(MSGSRV_AGENT_CONNMGR "\\" MSGSRV_AGENT_CMLISTS, MSGSRV_A_DISABLED, config)) { - if (atol(config->Value[0]) == 1) { - MDBDestroyValueStruct(config); - ListsShutdown(); - return(FALSE); - } - } - - if (MDBRead(MSGSRV_AGENT_CONNMGR "\\" MSGSRV_AGENT_CMLISTS, MSGSRV_A_CONFIG_CHANGED, config)) { - List.config.last = atol(config->Value[0]); - MDBFreeValues(config); - } else { - List.config.last = 0; - } - - while ((Address = MDBReadEx(MSGSRV_AGENT_CONNMGR "\\" MSGSRV_AGENT_CMLISTS, MSGSRV_A_BLOCKED_ADDRESS, e, config)) != NULL) { - ptr = strchr(Address, '-'); - if (ptr) { - *ptr = '\0'; - AddBlockedAddress(Address, ptr + 1); - *ptr = '-'; - } else { - AddBlockedAddress(Address, Address); - } - } - MDBFreeValues(config); - - while ((Address = MDBReadEx(MSGSRV_AGENT_CONNMGR "\\" MSGSRV_AGENT_CMLISTS, MSGSRV_A_ALLOWED_ADDRESS, e, config)) != NULL) { - ptr = strchr(Address, '-'); - if (ptr) { - *ptr = '\0'; - AddAllowedAddress(Address, ptr + 1); - *ptr = '-'; - } else { - AddAllowedAddress(Address, Address); - } - } - MDBFreeValues(config); - - MDBDestroyEnumStruct(e, config); - MDBDestroyValueStruct(config); - - if (List.blocked.count == 0 && List.allowed.count == 0) { -#if VERBOSE - XplConsolePrintf("cmlists: No addresses blocked or allowed\n"); -#endif - - ListsShutdown(); - return(FALSE); - } - - return(TRUE); -} - -/* - Below are "stock" functions that are basically infrastructure. - However, one might want to add initialization code to main - and takedown code to the signal handler -*/ -void -ListShutdownSigHandler(int Signal) -{ - int oldtgid = XplSetThreadGroupID(List.tgid); - - if (ListUnloadOk == FALSE) { - ListUnloadOk = TRUE; - - /* - Make sure the library lists are gone before beginning to - shutdown. - */ - while (XplSafeRead(List.threadCount) > 1) { - XplDelay(33); - } - - /* Do any required cleanup */ - LoggerClose(List.logHandle); - -#if defined(NETWARE) || defined(LIBC) - XplSignalLocalSemaphore(List.shutdownSemaphore); /* The signal will release main() */ - XplWaitOnLocalSemaphore(List.shutdownSemaphore); /* The wait will wait until main() is gone */ - - XplCloseLocalSemaphore(List.shutdownSemaphore); -#endif - } - - XplSetThreadGroupID(oldtgid); - - return; -} - -int -_NonAppCheckUnload(void) -{ - if (ListUnloadOk == FALSE) { - XplConsolePrintf("\rThis module will automatically be unloaded by the thread that loaded it.\n"); - XplConsolePrintf("\rIt does not allow manual unloading.\n"); - - return(1); - } - - return(0); -} - -int main(int argc, char *argv[]) -{ - /* init globals */ - List.tgid = XplGetThreadGroupID(); - - XplRenameThread(GetThreadID(), "Gate Keeper List Module"); - XplOpenLocalSemaphore(List.shutdownSemaphore, 0); - XplSignalHandler(ListShutdownSigHandler); - - /* - This will "park" the module 'til we get unloaded; - it would not be neccessary to do this on NetWare, - but to prevent from automatically exiting on Unix - we need to keep main around... - */ - XplWaitOnLocalSemaphore(List.shutdownSemaphore); - XplSignalLocalSemaphore(List.shutdownSemaphore); - - return(0); -} diff --git a/src/agents/connmgr/cmmodules/lists/cmlists.h b/src/agents/connmgr/cmmodules/lists/cmlists.h deleted file mode 100644 index 90f6a4c..0000000 --- a/src/agents/connmgr/cmmodules/lists/cmlists.h +++ /dev/null @@ -1,73 +0,0 @@ -/**************************************************************************** - * - * Copyright (c) 2001 Novell, Inc. All Rights Reserved. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public License - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, contact Novell, Inc. - * - * To contact Novell about this file by physical or electronic mail, you - * may find current contact information at www.novell.com. - * - ****************************************************************************/ - -#include -#include -#include - -#include - -#define PRODUCT_SHORT_NAME "cmlist.nlm" -#define PRODUCT_NAME "Bongo Connection Manager Block and Allow List Module" - -typedef struct _ListGlobal { - /* Handles */ - void *logHandle; - MDBHandle directoryHandle; - - /* Module State */ - time_t timeStamp; - int tgid; - BOOL unloadOK; - XplSemaphore shutdownSemaphore; - XplAtomic threadCount; - - struct { - long last; - - unsigned char datadir[XPL_MAX_PATH + 1]; - } config; - - struct { - long *start; - long *end; - unsigned long count; - unsigned long allocated; - } blocked; - - struct { - long *start; - long *end; - unsigned long count; - unsigned long allocated; - } allowed; -} ListGlobal; - -extern ListGlobal List; - -/* cmlist.c */ -void ListShutdownSigHandler(int Signal); -int _NonAppCheckUnload(void); - -EXPORT BOOL CMLISTSInit(CMModuleRegistrationStruct *registration, unsigned char *dataDirectory); -EXPORT BOOL ListsShutdown(void); -EXPORT int ListsVerify(ConnMgrCommand *command, ConnMgrResult *result); - diff --git a/src/agents/connmgr/cmmodules/rbl/Bongo.rules b/src/agents/connmgr/cmmodules/rbl/Bongo.rules deleted file mode 100644 index 1e1772f..0000000 --- a/src/agents/connmgr/cmmodules/rbl/Bongo.rules +++ /dev/null @@ -1,23 +0,0 @@ -# -*- Makefile -*- -cmmodule_LTLIBRARIES += libcmrbl.la - -libcmrbl_la_SOURCES := \ - src/agents/connmgr/cmmodules/rbl/cmrbl.c \ - src/agents/connmgr/cmmodules/rbl/cmrbl.h - -libcmrbl_la_CPPFLAGS := $(AM_CPPFLAGS) \ - $(SQLITE_CFLAGS) - -libcmrbl_la_LDFLAGS := -module -avoid-version -libcmrbl_la_LIBADD := \ - libbongomsgapi.la \ - libbongologger.la \ - libbongomemmgr.la \ - libbongomdb.la \ - libbongoxpl.la \ - $(SQLITE_LIBS) \ - $(PTHREAD_LIBS) \ - $(ALL_LIBS) - -src/agents/connmgr/cmmodules/rbl/all: libcmrbl.la -src/agents/connmgr/cmmodules/rbl/clean: clean diff --git a/src/agents/connmgr/cmmodules/rbl/Makefile.am b/src/agents/connmgr/cmmodules/rbl/Makefile.am deleted file mode 100644 index 8830401..0000000 --- a/src/agents/connmgr/cmmodules/rbl/Makefile.am +++ /dev/null @@ -1,17 +0,0 @@ -# -*- Makefile -*- -# -# Do not edit! -# -# (unless this is Makefile.am.subdir) -# -# This file is a copy of the toplevel Makefile.am.subdir. If changes -# need to be made, edit that file, and make update-makefiles, and -# check the new files in. -# -# This is a skeletal automake file. The real automake fules for -# building the targets for this directory can be found in the -# Bongo.rules file. This file is simply here so that 'make all' can -# work in each subdirectory. - -all clean install: - @cd $(top_builddir) && $(MAKE) $(MFLAGS) $(subdir)/$@ diff --git a/src/agents/connmgr/cmmodules/rbl/cmrbl.c b/src/agents/connmgr/cmmodules/rbl/cmrbl.c deleted file mode 100644 index 2e642e9..0000000 --- a/src/agents/connmgr/cmmodules/rbl/cmrbl.c +++ /dev/null @@ -1,495 +0,0 @@ -/**************************************************************************** - * - * Copyright (c) 2001 Novell, Inc. All Rights Reserved. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public License - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, contact Novell, Inc. - * - * To contact Novell about this file by physical or electronic mail, you - * may find current contact information at www.novell.com. - * - ****************************************************************************/ - -#include -#include -#include -#include -#include - -#include - -#include "cmrbl.h" - -/* Globals */ -BOOL RBLUnloadOk = TRUE; -RBLGlobal RBL; - -static BOOL ReadConfiguration(void); - - -EXPORT int RBLVerify(ConnMgrCommand *command, ConnMgrResult *result) -{ - unsigned long i; - - if (XplStrCaseCmp(command->event, CM_EVENT_CONNECT) == 0) { - XplDnsRecord *dns = NULL; - BOOL blocked = FALSE; - int rc = -1; - int commentID = -1; - - /* Check for a cached value */ - XplWaitOnLocalSemaphore(RBL.sqlite.semaphore); - - sqlite3_bind_int(RBL.sqlite.stmt.get, 1, command->address); - - if ((rc = sqlite3_step(RBL.sqlite.stmt.get)) == SQLITE_ROW) { - blocked = sqlite3_column_int(RBL.sqlite.stmt.get, 0); - strncpy(result->comment, sqlite3_column_text(RBL.sqlite.stmt.get, 1), sizeof(result->comment)); - } - - sqlite3_reset(RBL.sqlite.stmt.get); - XplSignalLocalSemaphore(RBL.sqlite.semaphore); - - if (rc != SQLITE_ROW) { - /* Perform the RBL check */ - for (i = 0; i < RBL.rbl.count; i++) { - unsigned char buffer[MAXEMAILNAMESIZE]; - struct in_addr ip; - - ip.s_addr = command->address; - - /* address is in host byte order. RBL checks require least significant first. */ - snprintf(buffer, sizeof(buffer), "%d.%d.%d.%d.%s", - ip.s_net, - ip.s_host, - ip.s_lh, - ip.s_impno, - RBL.rbl.hosts[i]); - - rc = XplDnsResolve(buffer, &dns, XPL_RR_A); - if (dns) { - MemFree(dns); - } - - if (rc == XPL_DNS_SUCCESS) { - blocked = TRUE; - commentID = RBL.rbl.ids[i]; - strncpy(result->comment, RBL.rbl.comments[i], sizeof(result->comment)); - continue; - } - } - - /* Store new value */ - XplWaitOnLocalSemaphore(RBL.sqlite.semaphore); - - /* - Insert the new value into the table. The time for a negative result is a - full day. The time for a positive result is only 15 minutes however, - because a positive result simply means that the servers do not know anything - about the address. - */ - sqlite3_bind_int(RBL.sqlite.stmt.add, 1, command->address); - sqlite3_bind_text(RBL.sqlite.stmt.add, 2, blocked ? RBL.config.blockTimeout : RBL.config.allowTimeout, -1, SQLITE_TRANSIENT); - sqlite3_bind_int(RBL.sqlite.stmt.add, 3, blocked); - sqlite3_bind_int(RBL.sqlite.stmt.add, 4, commentID); - - sqlite3_step(RBL.sqlite.stmt.add); - - sqlite3_reset(RBL.sqlite.stmt.add); - XplSignalLocalSemaphore(RBL.sqlite.semaphore); - } - - if (blocked) { - /* He was blocked by RBL */ - return(CM_MODULE_DENY | CM_MODULE_PERMANENT | CM_MODULE_FORCE); - } else { - /* He was not blocked, don't force it though */ - return(CM_MODULE_ACCEPT); - } - } - - return(0); -} - -static void -TransactionController(void *ignored) -{ - XplWaitOnLocalSemaphore(RBL.sqlite.semaphore); - if (sqlite3_exec(RBL.sqlite.handle, SQL_BEGIN, NULL, NULL, NULL) != SQLITE_OK) { - XplConsolePrintf("cmrbl: Failed to start transaction controller\n"); - } - XplSignalLocalSemaphore(RBL.sqlite.semaphore); - - while (!RBLUnloadOk) { - unsigned long i; - - for (i = 0; i < 15 && !RBLUnloadOk; i++) { - XplDelay(1000); - } - - XplWaitOnLocalSemaphore(RBL.sqlite.semaphore); - if (sqlite3_exec(RBL.sqlite.handle, SQL_SAVE, NULL, NULL, NULL) != SQLITE_OK) { - XplConsolePrintf("cmrbl: Failed to save cache data\n"); - } - XplSignalLocalSemaphore(RBL.sqlite.semaphore); - } - - XplWaitOnLocalSemaphore(RBL.sqlite.semaphore); - if (sqlite3_exec(RBL.sqlite.handle, SQL_END, NULL, NULL, NULL) != SQLITE_OK) { - XplConsolePrintf("cmrbl: Failed to end transaction controller\n"); - } - XplSignalLocalSemaphore(RBL.sqlite.semaphore); -} - -EXPORT BOOL -CMRBLInit(CMModuleRegistrationStruct *registration, unsigned char *datadir) -{ - if (RBLUnloadOk == TRUE) { - XplSafeWrite(RBL.threadCount, 0); - - RBL.directoryHandle = (MDBHandle) MsgInit(); - if (RBL.directoryHandle) { - RBLUnloadOk = FALSE; - - RBL.logHandle = LoggerOpen("cmrbl"); - if (RBL.logHandle == NULL) { - XplConsolePrintf("cmrbl: Unable to initialize logging. Logging disabled.\r\n"); - } - - /* Fill out registration information */ - registration->priority = 1; /* It is important that the rbl are early */ - registration->Shutdown = RBLShutdown; - registration->Verify = RBLVerify; - registration->Notify = NULL; - - XplSafeIncrement(RBL.threadCount); - - strcpy(RBL.config.datadir, datadir); - - XplOpenLocalSemaphore(RBL.sqlite.semaphore, 1); - - if (ReadConfiguration()) { - unsigned char buffer[XPL_MAX_PATH + 1]; - int ccode; - XplThreadID id; - sqlite3_stmt *stmt; - sqlite3_stmt *stmt2; - unsigned long i; - - snprintf(buffer, sizeof(buffer), "%s/cache.db", datadir); - if (sqlite3_open(buffer, &RBL.sqlite.handle) != SQLITE_OK) { - printf("cmrbl: Failed to open database: %s\n", sqlite3_errmsg(RBL.sqlite.handle)); - } - - if (sqlite3_exec(RBL.sqlite.handle, SQL_CREATE, NULL, NULL, NULL) != SQLITE_OK) { -#if 0 - printf("bongogatekeeper: %s\n", sqlite3_errmsg(RBL.sqlite.handle)); -#endif - sqlite3_exec(RBL.sqlite.handle, SQL_ROLLBACK, NULL, NULL, NULL); - } - - if ((sqlite3_prepare(RBL.sqlite.handle, SQL_ADD, -1, &RBL.sqlite.stmt.add, 0) != SQLITE_OK) || - (sqlite3_prepare(RBL.sqlite.handle, SQL_GET, -1, &RBL.sqlite.stmt.get, 0) != SQLITE_OK) || - (sqlite3_prepare(RBL.sqlite.handle, SQL_CLEAN, -1, &RBL.sqlite.stmt.clean,0) != SQLITE_OK)) - { - printf("cmrbl: Failed to prepare sql: %s\n", sqlite3_errmsg(RBL.sqlite.handle)); - } - - /* Cleanup */ - sqlite3_exec(RBL.sqlite.handle, SQL_COMMENTS_CLEAN1, NULL, NULL, NULL); - - sqlite3_prepare(RBL.sqlite.handle, SQL_COMMENTS_CLEAN2, -1, &stmt, 0); - for (i = 0; i < RBL.rbl.count; i++) { - sqlite3_bind_text(stmt, 1, RBL.rbl.hosts[i], -1, SQLITE_TRANSIENT); - sqlite3_step(stmt); - sqlite3_reset(stmt); - } - sqlite3_finalize(stmt); - - sqlite3_exec(RBL.sqlite.handle, SQL_COMMENTS_CLEAN3, NULL, NULL, NULL); - - /* Ok, add any new ones */ - sqlite3_prepare(RBL.sqlite.handle, SQL_COMMENTS_ADD, -1, &stmt, 0); - sqlite3_prepare(RBL.sqlite.handle, SQL_COMMENTS_UPDATE, -1, &stmt2, 0); - for (i = 0; i < RBL.rbl.count; i++) { - sqlite3_bind_text(stmt, 1, RBL.rbl.hosts[i], -1, SQLITE_TRANSIENT); - sqlite3_bind_text(stmt, 2, RBL.rbl.comments[i], -1, SQLITE_TRANSIENT); - - if (sqlite3_step(stmt) != SQLITE_DONE) { - /* It is already there, so just update the comment in case it changed */ - sqlite3_bind_text(stmt2, 1, RBL.rbl.comments[i], -1, SQLITE_TRANSIENT); - sqlite3_bind_text(stmt2, 2, RBL.rbl.hosts[i], -1, SQLITE_TRANSIENT); - - sqlite3_step(stmt2); - sqlite3_reset(stmt2); - } - - sqlite3_reset(stmt); - } - sqlite3_finalize(stmt); - sqlite3_finalize(stmt2); - - /* Get the IDs for them */ - sqlite3_prepare(RBL.sqlite.handle, SQL_COMMENTS_GET_ID, -1, &stmt, 0); - for (i = 0; i < RBL.rbl.count; i++) { - sqlite3_bind_text(stmt, 1, RBL.rbl.hosts[i], -1, SQLITE_TRANSIENT); - if (sqlite3_step(stmt) == SQLITE_ROW) { - RBL.rbl.ids[i] = sqlite3_column_int(RBL.sqlite.stmt.get, 0); - } else { - RBL.rbl.ids[i] = -1; - } - sqlite3_reset(stmt); - } - sqlite3_finalize(stmt); - - /* Begin the transaction controller thread */ - XplBeginThread(&id, TransactionController, (1024 * 32), NULL, ccode); - - return(TRUE); - } - } else { - XplConsolePrintf("cmrbl: Failed to obtain directory handle\r\n"); - } - } - - return(FALSE); -} - -EXPORT BOOL -RBLShutdown(void) -{ - XplSafeDecrement(RBL.threadCount); - - if (RBLUnloadOk == FALSE) { - unsigned long i; - - RBLUnloadOk = TRUE; - - /* - Make sure the library rbl are gone before beginning to - shutdown. - */ - while (XplSafeRead(RBL.threadCount)) { - XplDelay(33); - } - - LoggerClose(RBL.logHandle); - - sqlite3_finalize(RBL.sqlite.stmt.add); - sqlite3_finalize(RBL.sqlite.stmt.get); - sqlite3_finalize(RBL.sqlite.stmt.clean); - - sqlite3_close(RBL.sqlite.handle); - XplCloseLocalSemaphore(RBL.sqlite.semaphore); - - for (i = 0; i < RBL.rbl.count; i++) { - MemFree(RBL.rbl.hosts[i]); - MemFree(RBL.rbl.comments[i]); - } - - if (RBL.rbl.hosts) { - MemFree(RBL.rbl.hosts); - } - - if (RBL.rbl.comments) { - MemFree(RBL.rbl.comments); - } - - if (RBL.rbl.ids) { - MemFree(RBL.rbl.ids); - } - -#if defined(NETWARE) || defined(LIBC) - XplSignalLocalSemaphore(RBL.shutdownSemaphore); /* The signal will release main() */ - XplWaitOnLocalSemaphore(RBL.shutdownSemaphore); /* The wait will wait until main() is gone */ - - XplCloseLocalSemaphore(RBL.shutdownSemaphore); -#endif - } - - return(FALSE); -} - -static BOOL -ReadConfiguration(void) -{ - MDBValueStruct *config; - - config = MDBCreateValueStruct(RBL.directoryHandle, MsgGetServerDN(NULL)); - - if (MDBRead(MSGSRV_AGENT_CONNMGR "\\" MSGSRV_AGENT_CMRBL, MSGSRV_A_DISABLED, config)) { - if (atol(config->Value[0]) == 1) { - MDBDestroyValueStruct(config); - RBLShutdown(); - return(FALSE); - } - } - - if (MDBRead(MSGSRV_AGENT_CONNMGR "\\" MSGSRV_AGENT_CMRBL, MSGSRV_A_CONFIG_CHANGED, config)) { - RBL.config.last = atol(config->Value[0]); - MDBFreeValues(config); - } else { - RBL.config.last = 0; - } - - if (MDBRead(MSGSRV_AGENT_CONNMGR "\\" MSGSRV_AGENT_CMRBL, MSGSRV_A_RBL_HOST, config) > 0) { - unsigned long i; - - for (i = 0; i < RBL.rbl.count; i++) { - MemFree(RBL.rbl.hosts[i]); - MemFree(RBL.rbl.comments[i]); - } - - if (RBL.rbl.hosts) { - MemFree(RBL.rbl.hosts); - } - - if (RBL.rbl.comments) { - MemFree(RBL.rbl.comments); - } - - if (RBL.rbl.ids) { - MemFree(RBL.rbl.ids); - } - - RBL.rbl.count = config->Used; - RBL.rbl.hosts = MemMalloc(config->Used * sizeof(char *)); - RBL.rbl.comments = MemMalloc(config->Used * sizeof(char *)); - RBL.rbl.ids = MemMalloc(config->Used * sizeof(long)); - - if (!RBL.rbl.hosts || !RBL.rbl.comments || !RBL.rbl.ids) { - LoggerEvent(RBL.logHandle, LOGGER_SUBSYSTEM_GENERAL, LOGGER_EVENT_OUT_OF_MEMORY, LOG_ERROR, 0, __FILE__, NULL, config->Used * sizeof(char *) * 2, __LINE__, NULL, 0); - } else { - for (i = 0; i < RBL.rbl.count; i++) { - unsigned char *ptr = strchr(config->Value[i], ';'); - - if (ptr) { - ptr[0] = '\0'; - } - - RBL.rbl.hosts[i] = MemStrdup(config->Value[i]); - if (ptr) { - RBL.rbl.comments[i] = MemStrdup(ptr + 1); - } else { - RBL.rbl.comments[i] = MemMalloc(sizeof(BLOCKED_STRING) + strlen(RBL.rbl.hosts[i])); - sprintf(RBL.rbl.comments[i], BLOCKED_STRING, RBL.rbl.hosts[i]); - } - - LoggerEvent(RBL.logHandle, LOGGER_SUBSYSTEM_CONFIGURATION, LOGGER_EVENT_CONFIGURATION_STRING, LOG_INFO, 0, "MSGSRV_A_RBL_HOST", config->Value[i], 0, 0, NULL, 0); - } - } - - MDBFreeValues(config); - } - - /* - Store the timeout strings. It is faster to do this once, instead of storing the long value - and creating the string each time, since it must be a string that is bound to the SQL statement. - */ - snprintf(RBL.config.blockTimeout, sizeof(RBL.config.blockTimeout), "%d minutes", (24 * 60)); /* Default to 1 day for a block */ - snprintf(RBL.config.allowTimeout, sizeof(RBL.config.blockTimeout), "%d minutes", 15); /* Default to 15 minutes for allow */ - - if (MDBRead(MSGSRV_AGENT_CONNMGR "\\" MSGSRV_AGENT_CMRBL, MSGSRV_A_CONFIGURATION, config) > 0) { - unsigned long i; - - for (i = 0; i < config->Used; i++) { - if (XplStrNCaseCmp(config->Value[i], BLOCK_TIMEOUT_PREFIX, sizeof(BLOCK_TIMEOUT_PREFIX) - 1) == 0) { - snprintf(RBL.config.blockTimeout, sizeof(RBL.config.blockTimeout), "%lu minutes", atol(config->Value[i] + sizeof(BLOCK_TIMEOUT_PREFIX) - 1)); - } else if (XplStrNCaseCmp(config->Value[i], ALLOW_TIMEOUT_PREFIX, sizeof(ALLOW_TIMEOUT_PREFIX) - 1) == 0) { - snprintf(RBL.config.allowTimeout, sizeof(RBL.config.allowTimeout), "%lu minutes", atol(config->Value[i] + sizeof(ALLOW_TIMEOUT_PREFIX) - 1)); - } - } - } - - MDBDestroyValueStruct(config); - - if (RBL.rbl.count == 0) { -#if VERBOSE - XplConsolePrintf("cmrbl: No RBL zones configured. RBL check is disabled.\n"); -#endif - RBLShutdown(); - return(FALSE); - } - - return(TRUE); -} - -/* - Below are "stock" functions that are basically infrastructure. - However, one might want to add initialization code to main - and takedown code to the signal handler -*/ -void -RBLShutdownSigHandler(int Signal) -{ - int oldtgid = XplSetThreadGroupID(RBL.tgid); - - if (RBLUnloadOk == FALSE) { - RBLUnloadOk = TRUE; - - /* - Make sure the library rbl are gone before beginning to - shutdown. - */ - while (XplSafeRead(RBL.threadCount) > 1) { - XplDelay(33); - } - - /* Do any required cleanup */ - LoggerClose(RBL.logHandle); - -#if defined(NETWARE) || defined(LIBC) - XplSignalLocalSemaphore(RBL.shutdownSemaphore); /* The signal will release main() */ - XplWaitOnLocalSemaphore(RBL.shutdownSemaphore); /* The wait will wait until main() is gone */ - - XplCloseLocalSemaphore(RBL.shutdownSemaphore); -#endif - } - - XplSetThreadGroupID(oldtgid); - - return; -} - -int -_NonAppCheckUnload(void) -{ - if (RBLUnloadOk == FALSE) { - XplConsolePrintf("\rThis module will automatically be unloaded by the thread that loaded it.\n"); - XplConsolePrintf("\rIt does not allow manual unloading.\n"); - - return(1); - } - - return(0); -} - -int main(int argc, char *argv[]) -{ - /* init globals */ - RBL.tgid = XplGetThreadGroupID(); - - XplRenameThread(GetThreadID(), "Gate Keeper RBL Module"); - XplOpenLocalSemaphore(RBL.shutdownSemaphore, 0); - XplSignalHandler(RBLShutdownSigHandler); - - /* - This will "park" the module 'til we get unloaded; - it would not be neccessary to do this on NetWare, - but to prevent from automatically exiting on Unix - we need to keep main around... - */ - XplWaitOnLocalSemaphore(RBL.shutdownSemaphore); - XplSignalLocalSemaphore(RBL.shutdownSemaphore); - - return(0); -} diff --git a/src/agents/connmgr/cmmodules/rbl/cmrbl.h b/src/agents/connmgr/cmmodules/rbl/cmrbl.h deleted file mode 100644 index 7df068f..0000000 --- a/src/agents/connmgr/cmmodules/rbl/cmrbl.h +++ /dev/null @@ -1,123 +0,0 @@ -/**************************************************************************** - * - * Copyright (c) 2001 Novell, Inc. All Rights Reserved. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public License - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, contact Novell, Inc. - * - * To contact Novell about this file by physical or electronic mail, you - * may find current contact information at www.novell.com. - * - ****************************************************************************/ - -#include -#include -#include - -#include - -#include - -#define PRODUCT_SHORT_NAME "cmrbl.nlm" -#define PRODUCT_NAME "Bongo Connection Manager RBL Module" - -#define BLOCKED_STRING "Blocked by RBL %s" - -typedef struct _RBLGlobal { - /* Handles */ - void *logHandle; - MDBHandle directoryHandle; - - /* Module State */ - time_t timeStamp; - int tgid; - BOOL unloadOK; - XplSemaphore shutdownSemaphore; - XplAtomic threadCount; - - struct { - long last; - - unsigned char datadir[XPL_MAX_PATH + 1]; - unsigned char blockTimeout[256]; - unsigned char allowTimeout[256]; - } config; - - struct { - unsigned char **hosts; - unsigned char **comments; - unsigned long *ids; - unsigned long count; - unsigned long allocated; - } rbl; - - struct { - sqlite3 *handle; - XplSemaphore semaphore; - - struct { - sqlite3_stmt *add; - sqlite3_stmt *get; - sqlite3_stmt *clean; - } stmt; - } sqlite; -} RBLGlobal; - -extern RBLGlobal RBL; - -/* cmrbl.c */ -void RBLShutdownSigHandler(int Signal); -int _NonAppCheckUnload(void); - -EXPORT BOOL CMRBLInit(CMModuleRegistrationStruct *registration, unsigned char *dataDirectory); -EXPORT BOOL RBLShutdown(void); -EXPORT int RBLVerify(ConnMgrCommand *command, ConnMgrResult *result); - -/* Config Prefixes */ -#define BLOCK_TIMEOUT_PREFIX "RBLBlockTimeout:" -#define ALLOW_TIMEOUT_PREFIX "RBLAllowTimeout:" - -/* SQL */ -#define SQL_CREATE "BEGIN TRANSACTION;" \ - "CREATE TABLE cache (" \ - "ip INTEGER PRIMARY KEY NOT NULL," \ - "timeout DATETIME," \ - "block BOOL," \ - "commentID INTEGER" \ - ");" \ - "CREATE TABLE comments (" \ - "key INTEGER PRIMARY KEY AUTOINCREMENT," \ - "zone TEXT UNIQUE," \ - "comment TEXT," \ - "keep BOOL default 1" \ - ");" \ - "CREATE INDEX timeout_idx ON cache (timeout);" \ - "CREATE INDEX comment_idx ON cache (commentID);"\ - "END TRANSACTION;" - -#define SQL_ROLLBACK "ROLLBACK;" - -#define SQL_ADD "INSERT OR REPLACE INTO cache (ip, timeout, block, commentID) VALUES (?, DATETIME('now', ?), ?, ?);" -#define SQL_GET "SELECT cache.block, comments.comment FROM cache INNER JOIN comments ON cache.commentID=comments.key WHERE ip=? AND julianday('now') < julianday(timeout);" -#define SQL_CLEAN "DELETE FROM cache WHERE julianday('now') >= julianday(timeout);" - -#define SQL_BEGIN "BEGIN TRANSACTION;" -#define SQL_END "END TRANSACTION;" -#define SQL_SAVE SQL_CLEAN SQL_END SQL_BEGIN - -#define SQL_COMMENTS_CLEAN1 "UPDATE comments SET keep=0;" -#define SQL_COMMENTS_CLEAN2 "UPDATE comments SET keep=1 WHERE zone=?;" -#define SQL_COMMENTS_CLEAN3 "DELETE FROM comments WHERE keep=0" -#define SQL_COMMENTS_ADD "INSERT INTO comments (zone, comment) VALUES (?, ?);" -#define SQL_COMMENTS_UPDATE "UPDATE comments SET comment=? WHERE zone=?;" -#define SQL_COMMENTS_GET_ID "SELECT key FROM comments WHERE zone=?;" - diff --git a/src/agents/connmgr/cmmodules/rdns/Bongo.rules b/src/agents/connmgr/cmmodules/rdns/Bongo.rules deleted file mode 100644 index 4bb0452..0000000 --- a/src/agents/connmgr/cmmodules/rdns/Bongo.rules +++ /dev/null @@ -1,23 +0,0 @@ -# -*- Makefile -*- -cmmodule_LTLIBRARIES += libcmrdns.la - -libcmrdns_la_SOURCES := \ - src/agents/connmgr/cmmodules/rdns/cmrdns.c \ - src/agents/connmgr/cmmodules/rdns/cmrdns.h - -libcmrdns_la_CPPFLAGS := $(AM_CPPFLAGS) \ - $(SQLITE_CFLAGS) - -libcmrdns_la_LDFLAGS := -module -avoid-version -libcmrdns_la_LIBADD := \ - libbongomsgapi.la \ - libbongologger.la \ - libbongomemmgr.la \ - libbongomdb.la \ - libbongoxpl.la \ - $(SQLITE_LIBS) \ - $(PTHREAD_LIBS) \ - $(ALL_LIBS) - -src/agents/connmgr/cmmodules/rdns/all: libcmrdns.la -src/agents/connmgr/cmmodules/rdns/clean: clean diff --git a/src/agents/connmgr/cmmodules/rdns/Makefile.am b/src/agents/connmgr/cmmodules/rdns/Makefile.am deleted file mode 100644 index 8830401..0000000 --- a/src/agents/connmgr/cmmodules/rdns/Makefile.am +++ /dev/null @@ -1,17 +0,0 @@ -# -*- Makefile -*- -# -# Do not edit! -# -# (unless this is Makefile.am.subdir) -# -# This file is a copy of the toplevel Makefile.am.subdir. If changes -# need to be made, edit that file, and make update-makefiles, and -# check the new files in. -# -# This is a skeletal automake file. The real automake fules for -# building the targets for this directory can be found in the -# Bongo.rules file. This file is simply here so that 'make all' can -# work in each subdirectory. - -all clean install: - @cd $(top_builddir) && $(MAKE) $(MFLAGS) $(subdir)/$@ diff --git a/src/agents/connmgr/cmmodules/rdns/cmrdns.c b/src/agents/connmgr/cmmodules/rdns/cmrdns.c deleted file mode 100644 index dc756ba..0000000 --- a/src/agents/connmgr/cmmodules/rdns/cmrdns.c +++ /dev/null @@ -1,360 +0,0 @@ -/**************************************************************************** - * - * Copyright (c) 2001 Novell, Inc. All Rights Reserved. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public License - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, contact Novell, Inc. - * - * To contact Novell about this file by physical or electronic mail, you - * may find current contact information at www.novell.com. - * - ****************************************************************************/ - -#include -#include -#include -#include -#include - -#include - -#include "cmrdns.h" - -/* Globals */ -BOOL RDNSUnloadOk = TRUE; -RDNSGlobal RDNS; - -static BOOL ReadConfiguration(void); - - -EXPORT int RDNSVerify(ConnMgrCommand *command, ConnMgrResult *result) -{ - if (XplStrCaseCmp(command->event, CM_EVENT_CONNECT) == 0) { - XplDnsRecord *dns = NULL; - BOOL blocked = FALSE; - int rc = -1; - - /* Check for a cached value */ - XplWaitOnLocalSemaphore(RDNS.sqlite.semaphore); - - sqlite3_bind_int(RDNS.sqlite.stmt.get, 1, command->address); - - if ((rc = sqlite3_step(RDNS.sqlite.stmt.get)) == SQLITE_ROW) { - blocked = sqlite3_column_int(RDNS.sqlite.stmt.get, 0); - } - - sqlite3_reset(RDNS.sqlite.stmt.get); - XplSignalLocalSemaphore(RDNS.sqlite.semaphore); - - if (rc != SQLITE_ROW) { - unsigned char buffer[MAXEMAILNAMESIZE]; - struct in_addr ip; - - /* Perform the RDNS check */ - - ip.s_addr = command->address; - - /* ip is in host byte order. Reverse DNS requires most significant first. (unless providing the .in-addr.arpa extension) */ - snprintf(buffer, sizeof(buffer), "%d.%d.%d.%d", - ip.s_impno, - ip.s_lh, - ip.s_host, - ip.s_net); - - rc = XplDnsResolve(buffer, &dns, XPL_RR_PTR); - - if (dns) { - MemFree(dns); - } - - if (rc != XPL_DNS_SUCCESS) { - /* We don't like the guy */ - blocked = TRUE; - } - - /* Store new value */ - XplWaitOnLocalSemaphore(RDNS.sqlite.semaphore); - - /* - Insert the new value into the table. The time for a negative result is a - full day. The time for a positive result is only 15 minutes however, - because a positive result simply means that the servers do not know anything - about the address. - */ - sqlite3_bind_int(RDNS.sqlite.stmt.add, 1, command->address); - sqlite3_bind_text(RDNS.sqlite.stmt.add, 2, blocked ? RDNS.config.blockTimeout : RDNS.config.allowTimeout, -1, SQLITE_TRANSIENT); - sqlite3_bind_int(RDNS.sqlite.stmt.add, 3, blocked); - - sqlite3_step(RDNS.sqlite.stmt.add); - - sqlite3_reset(RDNS.sqlite.stmt.add); - XplSignalLocalSemaphore(RDNS.sqlite.semaphore); - } - - if (blocked) { - /* He was blocked by RDNS */ - strncpy(result->comment, CM_COMMENT, sizeof(result->comment)); - } - - result->detail.connect.requireAuth = blocked; - return(CM_MODULE_ACCEPT); - } - - return(0); -} - -static void -TransactionController(void *ignored) -{ - XplWaitOnLocalSemaphore(RDNS.sqlite.semaphore); - if (sqlite3_exec(RDNS.sqlite.handle, SQL_BEGIN, NULL, NULL, NULL) != SQLITE_OK) { - XplConsolePrintf("cmrdns: Failed to start transaction controller\n"); - } - XplSignalLocalSemaphore(RDNS.sqlite.semaphore); - - while (!RDNSUnloadOk) { - unsigned long i; - - for (i = 0; i < 15 && !RDNSUnloadOk; i++) { - XplDelay(1000); - } - - XplWaitOnLocalSemaphore(RDNS.sqlite.semaphore); - if (sqlite3_exec(RDNS.sqlite.handle, SQL_SAVE, NULL, NULL, NULL) != SQLITE_OK) { - XplConsolePrintf("cmrdns: Failed to save cache data\n"); - } - XplSignalLocalSemaphore(RDNS.sqlite.semaphore); - } - - XplWaitOnLocalSemaphore(RDNS.sqlite.semaphore); - if (sqlite3_exec(RDNS.sqlite.handle, SQL_END, NULL, NULL, NULL) != SQLITE_OK) { - XplConsolePrintf("cmrdns: Failed to end transaction controller\n"); - } - XplSignalLocalSemaphore(RDNS.sqlite.semaphore); -} - -EXPORT BOOL -CMRDNSInit(CMModuleRegistrationStruct *registration, unsigned char *datadir) -{ - if (RDNSUnloadOk == TRUE) { - XplSafeWrite(RDNS.threadCount, 0); - - RDNS.directoryHandle = (MDBHandle) MsgInit(); - if (RDNS.directoryHandle) { - RDNSUnloadOk = FALSE; - - RDNS.logHandle = LoggerOpen("cmrdns"); - if (RDNS.logHandle == NULL) { - XplConsolePrintf("cmrdns: Unable to initialize logging. Logging disabled.\r\n"); - } - - /* Fill out registration information */ - registration->priority = 1; /* It is important that the rdns are early */ - registration->Shutdown = RDNSShutdown; - registration->Verify = RDNSVerify; - registration->Notify = NULL; - - XplSafeIncrement(RDNS.threadCount); - - strcpy(RDNS.config.datadir, datadir); - - XplOpenLocalSemaphore(RDNS.sqlite.semaphore, 1); - - if (ReadConfiguration()) { - unsigned char buffer[XPL_MAX_PATH + 1]; - int ccode; - XplThreadID id; - - snprintf(buffer, sizeof(buffer), "%s/cache.db", datadir); - if (sqlite3_open(buffer, &RDNS.sqlite.handle) != SQLITE_OK) { - printf("cmrdns: Failed to open database: %s\n", sqlite3_errmsg(RDNS.sqlite.handle)); - } - - if (sqlite3_exec(RDNS.sqlite.handle, SQL_CREATE, NULL, NULL, NULL) != SQLITE_OK) { -#if 0 - printf("bongogatekeeper: %s\n", sqlite3_errmsg(RDNS.sqlite.handle)); -#endif - sqlite3_exec(RDNS.sqlite.handle, SQL_ROLLBACK, NULL, NULL, NULL); - } - - if ((sqlite3_prepare(RDNS.sqlite.handle, SQL_ADD, -1, &RDNS.sqlite.stmt.add, 0) != SQLITE_OK) || - (sqlite3_prepare(RDNS.sqlite.handle, SQL_GET, -1, &RDNS.sqlite.stmt.get, 0) != SQLITE_OK) || - (sqlite3_prepare(RDNS.sqlite.handle, SQL_CLEAN, -1, &RDNS.sqlite.stmt.clean,0) != SQLITE_OK)) - { - printf("cmrdns: Failed to prepare sql: %s\n", sqlite3_errmsg(RDNS.sqlite.handle)); - } - - /* Begin the transaction controller thread */ - XplBeginThread(&id, TransactionController, (1024 * 32), NULL, ccode); - - return(TRUE); - } - } else { - XplConsolePrintf("cmrdns: Failed to obtain directory handle\r\n"); - } - } - - return(FALSE); -} - -EXPORT BOOL -RDNSShutdown(void) -{ - XplSafeDecrement(RDNS.threadCount); - - if (RDNSUnloadOk == FALSE) { - RDNSUnloadOk = TRUE; - - /* - Make sure the library rdns are gone before beginning to - shutdown. - */ - while (XplSafeRead(RDNS.threadCount)) { - XplDelay(33); - } - - LoggerClose(RDNS.logHandle); - - sqlite3_finalize(RDNS.sqlite.stmt.add); - sqlite3_finalize(RDNS.sqlite.stmt.get); - sqlite3_finalize(RDNS.sqlite.stmt.clean); - - sqlite3_close(RDNS.sqlite.handle); - XplCloseLocalSemaphore(RDNS.sqlite.semaphore); - -#if defined(NETWARE) || defined(LIBC) - XplSignalLocalSemaphore(RDNS.shutdownSemaphore); /* The signal will release main() */ - XplWaitOnLocalSemaphore(RDNS.shutdownSemaphore); /* The wait will wait until main() is gone */ - - XplCloseLocalSemaphore(RDNS.shutdownSemaphore); -#endif - } - - return(FALSE); -} - -static BOOL -ReadConfiguration(void) -{ - MDBValueStruct *config; - - config = MDBCreateValueStruct(RDNS.directoryHandle, MsgGetServerDN(NULL)); - - if (MDBRead(MSGSRV_AGENT_CONNMGR "\\" MSGSRV_AGENT_CMRDNS, MSGSRV_A_DISABLED, config)) { - if (atol(config->Value[0]) == 1) { - MDBDestroyValueStruct(config); - RDNSShutdown(); - return(FALSE); - } - } - - if (MDBRead(MSGSRV_AGENT_CONNMGR "\\" MSGSRV_AGENT_CMRDNS, MSGSRV_A_CONFIG_CHANGED, config)) { - RDNS.config.last = atol(config->Value[0]); - MDBFreeValues(config); - } else { - RDNS.config.last = 0; - } - - /* - Store the timeout strings. It is faster to do this once, instead of storing the long value - and creating the string each time, since it must be a string that is bound to the SQL statement. - */ - snprintf(RDNS.config.blockTimeout, sizeof(RDNS.config.blockTimeout), "%d minutes", (3 * 60)); /* Default to 3 hours */ - snprintf(RDNS.config.allowTimeout, sizeof(RDNS.config.blockTimeout), "%d minutes", (3 * 60)); /* Default to 3 hours */ - - if (MDBRead(MSGSRV_AGENT_CONNMGR "\\" MSGSRV_AGENT_CMRDNS, MSGSRV_A_CONFIGURATION, config) > 0) { - unsigned long i; - - for (i = 0; i < config->Used; i++) { - if (XplStrNCaseCmp(config->Value[i], BLOCK_TIMEOUT_PREFIX, sizeof(BLOCK_TIMEOUT_PREFIX) - 1) == 0) { - snprintf(RDNS.config.blockTimeout, sizeof(RDNS.config.blockTimeout), "%lu minutes", atol(config->Value[i] + sizeof(BLOCK_TIMEOUT_PREFIX) - 1)); - } else if (XplStrNCaseCmp(config->Value[i], ALLOW_TIMEOUT_PREFIX, sizeof(ALLOW_TIMEOUT_PREFIX) - 1) == 0) { - snprintf(RDNS.config.allowTimeout, sizeof(RDNS.config.allowTimeout), "%lu minutes", atol(config->Value[i] + sizeof(ALLOW_TIMEOUT_PREFIX) - 1)); - } - } - } - - MDBDestroyValueStruct(config); - - return(TRUE); -} - -/* - Below are "stock" functions that are basically infrastructure. - However, one might want to add initialization code to main - and takedown code to the signal handler -*/ -void -RDNSShutdownSigHandler(int Signal) -{ - int oldtgid = XplSetThreadGroupID(RDNS.tgid); - - if (RDNSUnloadOk == FALSE) { - RDNSUnloadOk = TRUE; - - /* - Make sure the library rdns are gone before beginning to - shutdown. - */ - while (XplSafeRead(RDNS.threadCount) > 1) { - XplDelay(33); - } - - /* Do any required cleanup */ - LoggerClose(RDNS.logHandle); - -#if defined(NETWARE) || defined(LIBC) - XplSignalLocalSemaphore(RDNS.shutdownSemaphore); /* The signal will release main() */ - XplWaitOnLocalSemaphore(RDNS.shutdownSemaphore); /* The wait will wait until main() is gone */ - - XplCloseLocalSemaphore(RDNS.shutdownSemaphore); -#endif - } - - XplSetThreadGroupID(oldtgid); - - return; -} - -int -_NonAppCheckUnload(void) -{ - if (RDNSUnloadOk == FALSE) { - XplConsolePrintf("\rThis module will automatically be unloaded by the thread that loaded it.\n"); - XplConsolePrintf("\rIt does not allow manual unloading.\n"); - - return(1); - } - - return(0); -} - -int main(int argc, char *argv[]) -{ - /* init globals */ - RDNS.tgid = XplGetThreadGroupID(); - - XplRenameThread(GetThreadID(), "Gate Keeper RDNS Module"); - XplOpenLocalSemaphore(RDNS.shutdownSemaphore, 0); - XplSignalHandler(RDNSShutdownSigHandler); - - /* - This will "park" the module 'til we get unloaded; - it would not be neccessary to do this on NetWare, - but to prevent from automatically exiting on Unix - we need to keep main around... - */ - XplWaitOnLocalSemaphore(RDNS.shutdownSemaphore); - XplSignalLocalSemaphore(RDNS.shutdownSemaphore); - - return(0); -} diff --git a/src/agents/connmgr/cmmodules/rdns/cmrdns.h b/src/agents/connmgr/cmmodules/rdns/cmrdns.h deleted file mode 100644 index 88c0e25..0000000 --- a/src/agents/connmgr/cmmodules/rdns/cmrdns.h +++ /dev/null @@ -1,99 +0,0 @@ -/**************************************************************************** - * - * Copyright (c) 2001 Novell, Inc. All Rights Reserved. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public License - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, contact Novell, Inc. - * - * To contact Novell about this file by physical or electronic mail, you - * may find current contact information at www.novell.com. - * - ****************************************************************************/ - -#include -#include -#include - -#include - -#include - -#define PRODUCT_SHORT_NAME "cmrdns.nlm" -#define PRODUCT_NAME "Bongo Connection Manager Reverse DNS Module" - -#define CM_COMMENT "Your computer does not have a hostname, access blocked" - -typedef struct _RDNSGlobal { - /* Handles */ - void *logHandle; - MDBHandle directoryHandle; - - /* Module State */ - time_t timeStamp; - int tgid; - BOOL unloadOK; - XplSemaphore shutdownSemaphore; - XplAtomic threadCount; - - struct { - long last; - - unsigned char datadir[XPL_MAX_PATH + 1]; - unsigned char blockTimeout[256]; - unsigned char allowTimeout[256]; - } config; - - struct { - sqlite3 *handle; - XplSemaphore semaphore; - - struct { - sqlite3_stmt *add; - sqlite3_stmt *get; - sqlite3_stmt *clean; - } stmt; - } sqlite; -} RDNSGlobal; - -extern RDNSGlobal RDNS; - -/* cmrdns.c */ -void RDNSShutdownSigHandler(int Signal); -int _NonAppCheckUnload(void); - -EXPORT BOOL CMRDNSInit(CMModuleRegistrationStruct *registration, unsigned char *dataDirectory); -EXPORT BOOL RDNSShutdown(void); -EXPORT int RDNSVerify(ConnMgrCommand *command, ConnMgrResult *result); - -/* Config Prefixes */ -#define BLOCK_TIMEOUT_PREFIX "RDNSBlockTimeout:" -#define ALLOW_TIMEOUT_PREFIX "RDNSAllowTimeout:" - -/* SQL */ -#define SQL_CREATE "BEGIN TRANSACTION;" \ - "CREATE TABLE cache (" \ - "ip INTEGER PRIMARY KEY NOT NULL," \ - "timeout DATETIME," \ - "block BOOL" \ - ");" \ - "CREATE INDEX timeout_idx ON cache (timeout);" \ - "END TRANSACTION;" - -#define SQL_ROLLBACK "ROLLBACK;" - -#define SQL_ADD "INSERT OR REPLACE INTO cache (ip, timeout, block) VALUES (?, DATETIME('now', ?), ?);" -#define SQL_GET "SELECT block FROM cache WHERE ip=? AND julianday('now') < julianday(timeout);" -#define SQL_CLEAN "DELETE FROM cache WHERE julianday('now') >= julianday(timeout);" - -#define SQL_BEGIN "BEGIN TRANSACTION;" -#define SQL_END "END TRANSACTION;" -#define SQL_SAVE SQL_CLEAN SQL_END SQL_BEGIN diff --git a/src/agents/connmgr/cmmodules/user/Bongo.rules b/src/agents/connmgr/cmmodules/user/Bongo.rules deleted file mode 100644 index 5ad1a23..0000000 --- a/src/agents/connmgr/cmmodules/user/Bongo.rules +++ /dev/null @@ -1,19 +0,0 @@ -# -*- Makefile -*- -cmmodule_LTLIBRARIES += libcmuser.la - -libcmuser_la_SOURCES := \ - src/agents/connmgr/cmmodules/user/cmuser.c \ - src/agents/connmgr/cmmodules/user/cmuser.h - -libcmuser_la_LDFLAGS := -module -avoid-version -libcmuser_la_LIBADD := \ - libbongomsgapi.la \ - libbongologger.la \ - libbongomemmgr.la \ - libbongomdb.la \ - libbongoxpl.la \ - $(PTHREAD_LIBS) \ - $(ALL_LIBS) - -src/agents/connmgr/cmmodules/user/cmuser/all: libcmuser.la -src/agents/connmgr/cmmodules/user/cmuser/clean: clean diff --git a/src/agents/connmgr/cmmodules/user/Makefile.am b/src/agents/connmgr/cmmodules/user/Makefile.am deleted file mode 100644 index 8830401..0000000 --- a/src/agents/connmgr/cmmodules/user/Makefile.am +++ /dev/null @@ -1,17 +0,0 @@ -# -*- Makefile -*- -# -# Do not edit! -# -# (unless this is Makefile.am.subdir) -# -# This file is a copy of the toplevel Makefile.am.subdir. If changes -# need to be made, edit that file, and make update-makefiles, and -# check the new files in. -# -# This is a skeletal automake file. The real automake fules for -# building the targets for this directory can be found in the -# Bongo.rules file. This file is simply here so that 'make all' can -# work in each subdirectory. - -all clean install: - @cd $(top_builddir) && $(MAKE) $(MFLAGS) $(subdir)/$@ diff --git a/src/agents/connmgr/cmmodules/user/cmuser.c b/src/agents/connmgr/cmmodules/user/cmuser.c deleted file mode 100644 index af37576..0000000 --- a/src/agents/connmgr/cmmodules/user/cmuser.c +++ /dev/null @@ -1,293 +0,0 @@ -/**************************************************************************** - * - * Copyright (c) 2001 Novell, Inc. All Rights Reserved. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public License - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, contact Novell, Inc. - * - * To contact Novell about this file by physical or electronic mail, you - * may find current contact information at www.novell.com. - * - ****************************************************************************/ - -#include -#include -#include -#include -#include - -#include "cmuser.h" - -/* Globals */ -BOOL UserUnloadOk = TRUE; -UserGlobal User; - -static BOOL ReadConfiguration(void); -static void Cleanup(void *param); - - -EXPORT BOOL UserNotify(ConnMgrCommand *command) -{ - /* - CM_EVENT_AUTHENTICATED - When receieved, create a file in datadir where the name is the ip address - and the conntent is the username. - */ - - if (XplStrCaseCmp(command->event, CM_EVENT_AUTHENTICATED) == 0) { - unsigned char buffer[XPL_MAX_PATH + 1]; - FILE *addr; - - snprintf(buffer, sizeof(buffer), "%s/%07lx", User.config.datadir, command->address); - addr = fopen(buffer, "w"); - if (addr) { - fwrite(command->detail.authenticated.user, sizeof(unsigned char), strlen(command->detail.authenticated.user), addr); - fclose(addr); - } - } - - return(TRUE); -} - -EXPORT int UserVerify(ConnMgrCommand *command, ConnMgrResult *result) -{ - /* - CM_EVENT_RELAY - When received, look for a file in datadir with the ip address as the - name, and read the user from the content of the file. Check the time - of the file to see if it has expired. - */ - if (XplStrCaseCmp(command->event, CM_EVENT_RELAY) == 0) { - unsigned char buffer[XPL_MAX_PATH + 1]; - struct stat sb; - - snprintf(buffer, sizeof(buffer), "%s/%07lx", User.config.datadir, command->address); - if (stat(buffer, &sb) != -1) { - if (sb.st_mtime > time(NULL) - (User.config.timeout * 60)) { - FILE *addr = fopen(buffer, "r"); - - if (addr) { - int l = fread(result->detail.user, sizeof(unsigned char), MAXEMAILNAMESIZE, addr); - result->detail.user[l] = '\0'; - - fclose(addr); - return(CM_MODULE_ACCEPT); - } - } else { - unlink(buffer); - } - } - return(CM_MODULE_DENY); - } - - return(0); -} - -EXPORT BOOL -CMUSERInit(CMModuleRegistrationStruct *registration, unsigned char *datadir) -{ - if (UserUnloadOk == TRUE) { - XplSafeWrite(User.threadCount, 0); - - User.directoryHandle = (MDBHandle) MsgInit(); - if (User.directoryHandle) { - UserUnloadOk = FALSE; - - User.logHandle = LoggerOpen("cmuser"); - if (User.logHandle == NULL) { - XplConsolePrintf("cmuser: Unable to initialize logging. Logging disabled.\r\n"); - } - - /* Fill out registration information */ - registration->priority = 5; - registration->Shutdown = UserShutdown; - registration->Verify = UserVerify; - registration->Notify = UserNotify; - - XplSafeIncrement(User.threadCount); - - strcpy(User.config.datadir, datadir); - - if (ReadConfiguration()) { - XplThreadID id; - int ccode; - - XplBeginThread(&id, Cleanup, (1024 * 32), NULL, ccode); - return(TRUE); - } - } else { - XplConsolePrintf("cmuser: Failed to obtain directory handle\r\n"); - } - } - - return(FALSE); -} - -EXPORT BOOL -UserShutdown(void) -{ - XplSafeDecrement(User.threadCount); - - if (UserUnloadOk == FALSE) { - UserUnloadOk = TRUE; - - /* - Make sure the library users are gone before beginning to - shutdown. - */ - while (XplSafeRead(User.threadCount)) { - XplDelay(33); - } - - LoggerClose(User.logHandle); - -#if defined(NETWARE) || defined(LIBC) - XplSignalLocalSemaphore(User.shutdownSemaphore); /* The signal will release main() */ - XplWaitOnLocalSemaphore(User.shutdownSemaphore); /* The wait will wait until main() is gone */ - - XplCloseLocalSemaphore(User.shutdownSemaphore); -#endif - } - - return(FALSE); -} - -static BOOL -ReadConfiguration(void) -{ - MDBValueStruct *config; - - config = MDBCreateValueStruct(User.directoryHandle, MsgGetServerDN(NULL)); - - if (MDBRead(MSGSRV_AGENT_CONNMGR "\\" MSGSRV_AGENT_CMUSER, MSGSRV_A_DISABLED, config)) { - if (atol(config->Value[0]) == 1) { - MDBDestroyValueStruct(config); - UserShutdown(); - return(FALSE); - } - } - - if (MDBRead(MSGSRV_AGENT_CONNMGR "\\" MSGSRV_AGENT_CMUSER, MSGSRV_A_CONFIG_CHANGED, config)) { - User.config.last = atol(config->Value[0]); - MDBFreeValues(config); - } else { - User.config.last = 0; - } - - if (MDBRead(MSGSRV_AGENT_CONNMGR "\\" MSGSRV_AGENT_CMUSER, MSGSRV_A_TIMEOUT, config)) { - User.config.timeout = atol(config->Value[0]); - } else { - User.config.timeout = 15; - } - - MDBDestroyValueStruct(config); - - return(TRUE); -} - -static void -Cleanup(void *param) -{ - while (!UserUnloadOk) { - int i; - XplDir *dir; - XplDir *dirent; - struct stat sb; - - if ((dir = XplOpenDir(User.config.datadir)) != NULL) { - while ((dirent = XplReadDir(dir)) != NULL) { - unsigned char buffer[XPL_MAX_PATH +1 ]; - - snprintf(buffer, sizeof(buffer), "%s/%s", User.config.datadir, dirent->d_nameDOS); - if ((stat(buffer, &sb) != -1) && (sb.st_mtime < time(NULL) - (User.config.timeout * 60))) { - unlink(buffer); - } - } - XplCloseDir(dir); - } - - for (i = 0; i < (User.config.timeout * 60) && !UserUnloadOk; i++) { - XplDelay(1000); - } - } -} - -/* - Below are "stock" functions that are basically infrastructure. - However, one might want to add initialization code to main - and takedown code to the signal handler -*/ -void -UserShutdownSigHandler(int Signal) -{ - int oldtgid = XplSetThreadGroupID(User.tgid); - - if (UserUnloadOk == FALSE) { - UserUnloadOk = TRUE; - - /* - Make sure the library users are gone before beginning to - shutdown. - */ - while (XplSafeRead(User.threadCount) > 1) { - XplDelay(33); - } - - /* Do any required cleanup */ - LoggerClose(User.logHandle); - -#if defined(NETWARE) || defined(LIBC) - XplSignalLocalSemaphore(User.shutdownSemaphore); /* The signal will release main() */ - XplWaitOnLocalSemaphore(User.shutdownSemaphore); /* The wait will wait until main() is gone */ - - XplCloseLocalSemaphore(User.shutdownSemaphore); -#endif - } - - XplSetThreadGroupID(oldtgid); - - return; -} - -int -_NonAppCheckUnload(void) -{ - if (UserUnloadOk == FALSE) { - XplConsolePrintf("\rThis module will automatically be unloaded by the thread that loaded it.\n"); - XplConsolePrintf("\rIt does not allow manual unloading.\n"); - - return(1); - } - - return(0); -} - -int main(int argc, char *argv[]) -{ - /* init globals */ - User.tgid = XplGetThreadGroupID(); - - XplRenameThread(GetThreadID(), "Gate Keeper User Module"); - XplOpenLocalSemaphore(User.shutdownSemaphore, 0); - XplSignalHandler(UserShutdownSigHandler); - - /* - This will "park" the module 'til we get unloaded; - it would not be neccessary to do this on NetWare, - but to prevent from automatically exiting on Unix - we need to keep main around... - */ - XplWaitOnLocalSemaphore(User.shutdownSemaphore); - XplSignalLocalSemaphore(User.shutdownSemaphore); - - return(0); -} diff --git a/src/agents/connmgr/cmmodules/user/cmuser.h b/src/agents/connmgr/cmmodules/user/cmuser.h deleted file mode 100644 index 01155ba..0000000 --- a/src/agents/connmgr/cmmodules/user/cmuser.h +++ /dev/null @@ -1,61 +0,0 @@ -/**************************************************************************** - * - * Copyright (c) 2001 Novell, Inc. All Rights Reserved. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public License - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, contact Novell, Inc. - * - * To contact Novell about this file by physical or electronic mail, you - * may find current contact information at www.novell.com. - * - ****************************************************************************/ - -#include -#include -#include - -#include - -#define PRODUCT_SHORT_NAME "cmuser.nlm" -#define PRODUCT_NAME "Bongo Connection Manager User Authentication Module" - -typedef struct _UserGlobal { - /* Handles */ - void *logHandle; - MDBHandle directoryHandle; - - /* Module State */ - time_t timeStamp; - int tgid; - BOOL unloadOK; - XplSemaphore shutdownSemaphore; - XplAtomic threadCount; - - struct { - long last; - - long timeout; - unsigned char datadir[XPL_MAX_PATH + 1]; - } config; -} UserGlobal; - -extern UserGlobal User; - -/* cmuser.c */ -void UserShutdownSigHandler(int Signal); -int _NonAppCheckUnload(void); - -EXPORT BOOL CMUSERInit(CMModuleRegistrationStruct *registration, unsigned char *dataDirectory); -EXPORT BOOL UserShutdown(void); -EXPORT BOOL UserNotify(ConnMgrCommand *command); -EXPORT int UserVerify(ConnMgrCommand *command, ConnMgrResult *result); - diff --git a/src/agents/connmgr/connmgr.c b/src/agents/connmgr/connmgr.c deleted file mode 100644 index 109fbb2..0000000 --- a/src/agents/connmgr/connmgr.c +++ /dev/null @@ -1,1290 +0,0 @@ -/**************************************************************************** - * - * Copyright (c) 2001 Novell, Inc. All Rights Reserved. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public License - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, contact Novell, Inc. - * - * To contact Novell about this file by physical or electronic mail, you - * may find current contact information at www.novell.com. - * - ****************************************************************************/ - -#include - -/* Product defines */ -#define PRODUCT_SHORT_NAME "connmgr.nlm" -#define PRODUCT_NAME "Bongo Connection Manager Agent" -#define PRODUCT_DESCRIPTION "Allows agents to keep and retrieve information about hosts that have talked to the system." -#define PRODUCT_VERSION "$Revision: 1.5 $" - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "connmgrp.h" - -#if !defined(DEBUG) -#define GetConnMgrClientPoolEntry() MemPrivatePoolGetEntry(ConnMgr.client.pool) -#else -#define GetConnMgrClientPoolEntry() MemPrivatePoolGetEntryDebug(ConnMgr.client.pool, __FILE__, __LINE__) -#endif - -static void SignalHandler(int sigtype); - -#define QUEUE_WORK_TO_DO(c, id, r) \ -{ \ - XplWaitOnLocalSemaphore(ConnMgr.client.semaphore); \ - if (XplSafeRead(ConnMgr.client.worker.idle)) { \ - (c)->queue.previous = NULL; \ - if (((c)->queue.next = ConnMgr.client.worker.head) != NULL) { \ - (c)->queue.next->queue.previous = (c); \ - } else { \ - ConnMgr.client.worker.tail = (c); \ - } \ - ConnMgr.client.worker.head = (c); \ - (r) = 0; \ - } else if (XplSafeRead(ConnMgr.client.worker.active) < XplSafeRead(ConnMgr.client.worker.maximum)) { \ - XplSafeIncrement(ConnMgr.client.worker.active); \ - XplSignalBlock(); \ - XplBeginThread(&(id), HandleConnection, CONNMGR_STACK_SPACE, XPL_INT_TO_PTR(XplSafeRead(ConnMgr.client.worker.active)), (r)); \ - XplSignalHandler(SignalHandler); \ - if (!(r)) { \ - (c)->queue.previous = NULL; \ - if (((c)->queue.next = ConnMgr.client.worker.head) != NULL) { \ - (c)->queue.next->queue.previous = (c); \ - } else { \ - ConnMgr.client.worker.tail = (c); \ - } \ - ConnMgr.client.worker.head = (c); \ - } else { \ - XplSafeDecrement(ConnMgr.client.worker.active); \ - (r) = CONNMGR_RECEIVER_OUT_OF_MEMORY; \ - } \ - } else { \ - (r) = CONNMGR_RECEIVER_CONNECTION_LIMIT; \ - } \ - XplSignalLocalSemaphore(ConnMgr.client.semaphore); \ -} - -enum ConnMgrStates { - CONNMGR_STARTING = 0, - CONNMGR_INITIALIZING, - CONNMGR_LOADING, - CONNMGR_RUNNING, - CONNMGR_RELOADING, - CONNMGR_UNLOADING, - CONNMGR_STOPPING, - CONNMGR_DONE, - - CONNMGR_MAX_STATES -}; - -enum ConnMgrReceiverStates { - CONNMGR_RECEIVER_SHUTTING_DOWN = 1, - CONNMGR_RECEIVER_DISABLED, - CONNMGR_RECEIVER_CONNECTION_LIMIT, - CONNMGR_RECEIVER_OUT_OF_MEMORY, - - CONNMGR_RECEIVER_MAX_STATES -}; - -enum ConnMgrClientStates { - CONNMGR_CLIENT_FRESH = 0, - CONNMGR_CLIENT_AUTHORIZED, - CONNMGR_CLIENT_ENDING, - - CONNMGR_CLIENT_MAX_STATES -}; - -typedef struct _ConnMgrClient { - enum ConnMgrClientStates state; - Connection *conn; - - ConnMgrCommand *command; - ConnMgrResult reply; -} ConnMgrClient; - -struct { - enum ConnMgrStates state; - BOOL stopped; - - struct { - XplThreadID main; - XplThreadID group; - } id; - - struct { - XplSemaphore main; - XplSemaphore shutdown; - } sem; - - struct { - Connection *conn; - XplAtomic active; - struct sockaddr_in addr; - unsigned char hash[CM_HASH_SIZE]; - unsigned char host[MAXEMAILNAMESIZE + 1]; - } server; - - struct { - XplSemaphore semaphore; - - struct { - XplSemaphore todo; - - XplAtomic maximum; - XplAtomic active; - XplAtomic idle; - - Connection *head; - Connection *tail; - } worker; - - void *pool; - - time_t sleepTime; - } client; - - struct { - struct { - XplAtomic serviced; - } clients; - - XplAtomic badPasswords; - } stats; - - struct { - XplRWLock lock; - - unsigned long *addresses; - unsigned char **handles; - unsigned char **salts; - unsigned long used; - unsigned long allocated; - } authHandles; - - MDBHandle directoryHandle; - void *loggingHandle; - - ModuleStruct *modules; - unsigned char moduleDir[XPL_MAX_PATH + 1]; -} ConnMgr; - -static BOOL HandleConnection(void *param); - -static BOOL ReadConnMgrVariable(unsigned int Variable, unsigned char *Data, size_t *DataLength); -static BOOL WriteConnMgrVariable(unsigned int Variable, unsigned char *Data, size_t DataLength); - -static BOOL ConnMgrShutdown(unsigned char *Arguments, unsigned char **Response, BOOL *CloseConnection); -static BOOL ConnMgrDMCCommandHelp(unsigned char *Arguments, unsigned char **Response, BOOL *CloseConnection); -static BOOL SendConnMgrStatistics(unsigned char *Arguments, unsigned char **Response, BOOL *CloseConnection); - -ManagementVariables ConnMgrManagementVariables[] = { - /* 0 PRODUCT_VERSION */ { DMCMV_REVISIONS, DMCMV_REVISIONS_HELP, ReadConnMgrVariable, NULL }, - /* 1 ConnMgr.client.worker.maximum */ { DMCMV_MAX_CONNECTION_COUNT, DMCMV_MAX_CONNECTION_COUNT_HELP, ReadConnMgrVariable, WriteConnMgrVariable }, - /* 2 ConnMgr.server.active */ { DMCMV_SERVER_THREAD_COUNT, DMCMV_SERVER_THREAD_COUNT_HELP, ReadConnMgrVariable, NULL }, - /* 3 ConnMgr.client.worker.active */ { DMCMV_CONNECTION_COUNT, DMCMV_CONNECTION_COUNT_HELP, ReadConnMgrVariable, NULL }, - /* 4 ConnMgr.client.worker.idle */ { DMCMV_IDLE_CONNECTION_COUNT, DMCMV_IDLE_CONNECTION_COUNT_HELP, ReadConnMgrVariable, NULL }, - /* 5 ConnMgr.stopped */ { DMCMV_RECEIVER_DISABLED, DMCMV_RECEIVER_DISABLED_HELP, ReadConnMgrVariable, WriteConnMgrVariable }, - /* 6 ConnMgr.stats.clients.serviced */ { DMCMV_TOTAL_CONNECTIONS, DMCMV_TOTAL_CONNECTIONS_HELP, ReadConnMgrVariable, WriteConnMgrVariable }, - /* 7 ConnMgr.stats.badPasswords */ { DMCMV_BAD_PASSWORD_COUNT, DMCMV_BAD_PASSWORD_COUNT_HELP, ReadConnMgrVariable, WriteConnMgrVariable }, - /* 8 */ { DMCMV_VERSION, DMCMV_VERSION_HELP, ReadConnMgrVariable, NULL }, -}; - -ManagementCommands ConnMgrManagementCommands[] = { - /* 0 HELP[ ] */ { DMCMC_HELP, ConnMgrDMCCommandHelp }, - /* 1 SHUTDOWN */ { DMCMC_SHUTDOWN, ConnMgrShutdown }, - /* 2 STATS */ { DMCMC_STATS, SendConnMgrStatistics }, - /* 3 MEMORY */ { DMCMC_DUMP_MEMORY_USAGE, ManagementMemoryStats }, - /* 4 CONNTRACEFLAGS */ { DMCMC_CONN_TRACE_USAGE, ManagementConnTrace }, -}; - - -static BOOL -ConnMgrClientAllocCB(void *buffer, void *clientData) -{ - ConnMgrClient *c = (ConnMgrClient *)buffer; - - memset(c, 0, sizeof(ConnMgrClient)); - - c->state = CONNMGR_CLIENT_FRESH; - return(TRUE); -} - -static void -ConnMgrReturnClientPoolEntry(ConnMgrClient *client) -{ - register ConnMgrClient *c = client; - - memset(c, 0, sizeof(ConnMgrClient)); - - c->state = CONNMGR_CLIENT_FRESH; - - MemPrivatePoolReturnEntry(c); - - return; -} - -static BOOL -HandleConnection(void *param) -{ - long threadNumber = (long)param; - time_t last = time(NULL); - time_t current; - ConnMgrClient *client; - - client = GetConnMgrClientPoolEntry(); - if (!client) { - XplSafeDecrement(ConnMgr.client.worker.active); - - return(FALSE); - } - - do { - XplRenameThread(XplGetThreadID(), "Connection Manager Worker"); - - XplSafeIncrement(ConnMgr.client.worker.idle); - XplWaitOnLocalSemaphore(ConnMgr.client.worker.todo); - XplSafeDecrement(ConnMgr.client.worker.idle); - - current = time(NULL); - - XplWaitOnLocalSemaphore(ConnMgr.client.semaphore); - - client->conn = ConnMgr.client.worker.tail; - if (client->conn) { - ConnMgr.client.worker.tail = client->conn->queue.previous; - if (ConnMgr.client.worker.tail) { - ConnMgr.client.worker.tail->queue.next = NULL; - } else { - ConnMgr.client.worker.head = NULL; - } - } - - XplSignalLocalSemaphore(ConnMgr.client.semaphore); - - if (client->conn) { - /* - Pull the request out of client->conn.receive.buffer. (See large comment in ConnMgrServer) - client->conn.receive.buffer has been abused to deliver the request to the client. - */ - client->command = (ConnMgrCommand *)client->conn->receive.buffer; - LoggerEvent(ConnMgr.loggingHandle, LOGGER_SUBSYSTEM_AUTH, LOGGER_EVENT_CONNECTION, LOG_INFO, 0, NULL, NULL, XplHostToLittle(client->conn->socketAddress.sin_addr.s_addr), 0, NULL, 0); - } - -#if 0 - XplConsolePrintf("[%d.%d.%d.%d] Got command: %lu\r\n", - client->conn->socketAddress.sin_addr.s_net, - client->conn->socketAddress.sin_addr.s_host, - client->conn->socketAddress.sin_addr.s_lh, - client->conn->socketAddress.sin_addr.s_impno, - client->command.request); -#endif - - if (client->command) { - unsigned long i; - BOOL allowed = FALSE; - BOOL found = FALSE; - unsigned char salt[256 + 1]; - - salt[0] = '\0'; - client->command->pass[32] = '\0'; - /* - Check the pass string provided in command. If it is not correct for the given - address, then generate a salt and send it. The client can then repeat the - command with a valid pass. - */ - XplRWReadLockAcquire(&ConnMgr.authHandles.lock); - for (i = 0; i < ConnMgr.authHandles.used; i++) { - - if (ConnMgr.authHandles.addresses[i] == client->conn->socketAddress.sin_addr.s_addr) { - found = TRUE; - if (XplStrCaseCmp(client->command->pass, ConnMgr.authHandles.handles[i]) == 0) { - allowed = TRUE; - } else { - strcpy(salt, ConnMgr.authHandles.salts[i]); - } - } - } - - if (!found) { - xpl_hash_context ctx; - unsigned char handle[XPLHASH_MD5_LENGTH]; - - XplRWReadLockRelease(&ConnMgr.authHandles.lock); - - snprintf(salt, sizeof(salt), "%x%s%x", XplGetThreadID(), ConnMgr.server.host, (unsigned int)time(NULL)); - salt[sizeof(salt) - 1] = 0; - - XplHashNew(&ctx, XPLHASH_MD5); - XplHashWrite(&ctx, salt, strlen(salt)); - XplHashWrite(&ctx, ConnMgr.server.hash, CM_HASH_SIZE); - XplHashFinal(&ctx, XPLHASH_LOWERCASE, handle, XPLHASH_MD5_LENGTH); - - XplRWWriteLockAcquire(&ConnMgr.authHandles.lock); - /* Generate the salt and the pass */ - if (ConnMgr.authHandles.used + 1 > ConnMgr.authHandles.allocated) { - ConnMgr.authHandles.allocated += 5; - - ConnMgr.authHandles.addresses = MemRealloc(ConnMgr.authHandles.addresses, sizeof(unsigned long) * ConnMgr.authHandles.allocated); - ConnMgr.authHandles.handles = MemRealloc(ConnMgr.authHandles.handles, sizeof(unsigned char *) * ConnMgr.authHandles.allocated); - ConnMgr.authHandles.salts = MemRealloc(ConnMgr.authHandles.salts, sizeof(unsigned char *) * ConnMgr.authHandles.allocated); - } - - ConnMgr.authHandles.addresses[ConnMgr.authHandles.used] = client->conn->socketAddress.sin_addr.s_addr; - ConnMgr.authHandles.handles[ConnMgr.authHandles.used] = MemStrdup(handle); - ConnMgr.authHandles.salts[ConnMgr.authHandles.used] = MemStrdup(salt); - ConnMgr.authHandles.used++; - - XplRWWriteLockRelease(&ConnMgr.authHandles.lock); - } - - XplRWReadLockRelease(&ConnMgr.authHandles.lock); - - if (allowed) { - /* - If command->address == 0, then resolve the host in command->host and place the - resulting value in command->addres. To keep the command size down host and user - are in a union. This means you can not provide a host when doing a user related - command. - */ - client->command->address = ntohl(client->command->address); - - switch (client->command->command) { - case CM_COMMAND_VERIFY: { - ModulesVerify(ConnMgr.modules, client->command, &client->reply); - break; - } - - case CM_COMMAND_NOTIFY: { - ModulesNotify(ConnMgr.modules, client->command); - client->reply.result = CM_RESULT_OK; - break; - } - - default: { - LoggerEvent(ConnMgr.loggingHandle, LOGGER_SUBSYSTEM_UNHANDLED, LOGGER_EVENT_UNHANDLED_REQUEST, LOG_INFO, 0, NULL, NULL, XplHostToLittle(client->conn->socketAddress.sin_addr.s_addr), 0, NULL, 0); - client->reply.result = CM_RESULT_UNKNOWN_COMMAND; - break; - } - } - - sendto(ConnMgr.server.conn->socket, (unsigned char *)&client->reply, sizeof(ConnMgrResult), 0, (struct sockaddr *)&client->conn->socketAddress, sizeof(client->conn->socketAddress)); - } else { - /* send a result with the salt */ - client->reply.result = CM_RESULT_MUST_AUTH; - strcpy(client->reply.detail.salt, salt); - sendto(ConnMgr.server.conn->socket, (unsigned char *)&client->reply, sizeof(ConnMgrResult), 0, (struct sockaddr *)&client->conn->socketAddress, sizeof(client->conn->socketAddress)); - } - } - - if (client->conn) { - ConnClose(client->conn, 0); - ConnFree(client->conn); - } - - /* Live or die? */ - if (threadNumber == XplSafeRead(ConnMgr.client.worker.active)) { - if ((current - last) > ConnMgr.client.sleepTime) { - break; - } - } - - last = time(NULL); - - memset(client, 0, sizeof(ConnMgrClient)); - - client->state = CONNMGR_CLIENT_FRESH; - } while (ConnMgr.state == CONNMGR_RUNNING); - - ConnMgrReturnClientPoolEntry(client); - - XplSafeDecrement(ConnMgr.client.worker.active); - - return(TRUE); -} - -static int -ServerSocketInit(void) -{ - ConnMgr.server.conn = ConnAlloc(FALSE); - if (ConnMgr.server.conn) { - ConnMgr.server.conn->socketAddress.sin_family = AF_INET; - ConnMgr.server.conn->socketAddress.sin_port = htons(CM_PORT); - ConnMgr.server.conn->socketAddress.sin_addr.s_addr = MsgGetAgentBindIPAddress(); - - /* Get root privs back for the bind. It's ok if this fails - - * the user might not need to be root to bind to the port */ - XplSetEffectiveUserId(0); - - /* Get our socket, and bind. This is normally done with ConnServerSocket() but that is TCP only */ - ConnMgr.server.conn->socket = IPsocket(PF_INET, SOCK_DGRAM, IPPROTO_UDP); - if (ConnMgr.server.conn->socket != -1) { - int ccode; - - setsockopt(ConnMgr.server.conn->socket, SOL_SOCKET, SO_REUSEADDR, (unsigned char *)&ccode, sizeof(ccode)); - ccode = IPbind(ConnMgr.server.conn->socket, (struct sockaddr *)&ConnMgr.server.conn->socketAddress, sizeof(ConnMgr.server.conn->socketAddress)); - if (ccode == -1) { - IPclose(ConnMgr.server.conn->socket); - ConnMgr.server.conn->socket = -1; - } - } - - if (XplSetEffectiveUser(MsgGetUnprivilegedUser()) < 0) { - XplConsolePrintf("bongoconnmgr: Could not drop to unprivileged user '%s'\n", MsgGetUnprivilegedUser()); - return(-1); - } - - if (ConnMgr.server.conn->socket == -1) { - int ret = ConnMgr.server.conn->socket; - XplConsolePrintf("bongoconnmgr: Could not bind to port %d\n", CM_PORT); - ConnFree(ConnMgr.server.conn); - return(ret); - } - } else { - XplConsolePrintf("bongoconnmgr: Could not allocate connection.\n"); - return(-1); - } - - return(0); -} - -static void -ConnMgrServer(void *ignored) -{ - XplThreadID id; - int ccode; - Connection *conn; - unsigned long i; - - XplSafeIncrement(ConnMgr.server.active); - XplRenameThread(XplGetThreadID(), "Connection Manager Server"); - ConnMgr.state = CONNMGR_RUNNING; - - while (ConnMgr.state < CONNMGR_STOPPING) { - ConnMgrCommand command; - long rc = -1; - - /* Must call connAlloc() with FALSE because we do not need the buffers for UDP */ - conn = ConnAlloc(FALSE); - if (conn) { - int size = 0; - ConnMgrResult result; - - while ((ConnMgr.state < CONNMGR_STOPPING) && ((rc == -1) || (rc == EOF) || (size == 0))) { - size = sizeof(conn->socketAddress); - rc = recvfrom(ConnMgr.server.conn->socket, (unsigned char *)&command, sizeof(ConnMgrCommand), 0, (struct sockaddr *)&conn->socketAddress, &size); - } - - - if ((ConnMgr.state < CONNMGR_STOPPING) && !ConnMgr.stopped) { - conn->ssl.enable = FALSE; - - /* - Abuse conn.receive.buffer. This is a pointer in the Connection structure - that is not being used in this case, because we are calling ConnAlloc() - with FALSE. Since in UDP we don't have accept, we are just calling recvfrom - and the result will contain the entire request. We MUST get this request - to the client thread. The only easy way to do that without changing ConnIO - is to put it into the Connection structure somewhere. - */ - conn->receive.buffer = (unsigned char *) MemMalloc(sizeof(ConnMgrCommand)); - memcpy(conn->receive.buffer, &command, sizeof(ConnMgrCommand)); - - QUEUE_WORK_TO_DO(conn, id, ccode); - if (!ccode) { - XplSignalLocalSemaphore(ConnMgr.client.worker.todo); - - continue; - } - } else if (ConnMgr.stopped) { - ccode = CONNMGR_RECEIVER_DISABLED; - } else { - ccode = CONNMGR_RECEIVER_SHUTTING_DOWN; - } - - memset(&result, 0, sizeof(ConnMgrResult)); - switch(ccode) { - case CONNMGR_RECEIVER_SHUTTING_DOWN: { - result.result = CM_RESULT_SHUTTING_DOWN; - break; - } - - case CONNMGR_RECEIVER_DISABLED: { - result.result = CM_RESULT_RECEIVER_DISABLED; - break; - } - - case CONNMGR_RECEIVER_CONNECTION_LIMIT: { - result.result = CM_RESULT_CONNECTION_LIMIT; - break; - } - - case CONNMGR_RECEIVER_OUT_OF_MEMORY: { - result.result = CM_RESULT_NO_MEMORY; - break; - } - - default: { - break; - } - } - - if (result.result >= CM_RESULT_FIRST_ERROR) { - sendto(ConnMgr.server.conn->socket, (unsigned char *)&result, sizeof(ConnMgrResult), 0, (struct sockaddr *)&conn->socketAddress, sizeof(conn->socketAddress)); - } - - /* fixme - we need connection management flags for ConnClose to force the shutdown */ - ConnClose(conn, 1); - - ConnFree(conn); - conn = NULL; - - continue; - } - - switch (errno) { - case ECONNABORTED: -#ifdef EPROTO - case EPROTO: -#endif - case EINTR: { - if (ConnMgr.state < CONNMGR_STOPPING) { - LoggerEvent(ConnMgr.loggingHandle, LOGGER_SUBSYSTEM_GENERAL, LOGGER_EVENT_ACCEPT_FAILURE, LOG_ERROR, 0, "Server", NULL, errno, 0, NULL, 0); - } - - continue; - } - - default: { - if (ConnMgr.state < CONNMGR_STOPPING) { -#if VERBOSE - XplConsolePrintf("bongoconnmgr: Exiting after an recvfrom() failure; error %d\n", errno); -#endif - - LoggerEvent(ConnMgr.loggingHandle, LOGGER_SUBSYSTEM_GENERAL, LOGGER_EVENT_ACCEPT_FAILURE, LOG_ERROR, 0, "Server", NULL, errno, 0, NULL, 0); - } - - ConnMgr.state = CONNMGR_STOPPING; - - break; - } - } - - break; - } - - /* Shutting down */ -#if VERBOSE - XplConsolePrintf("bongoconnmgr: Shutting down.\r\n"); -#endif - ConnMgr.state = CONNMGR_STOPPING; - - id = XplSetThreadGroupID(ConnMgr.id.group); - - if (ConnMgr.server.conn) { - /* fixme - we need connection management flags for ConnClose to force the shutdown */ - ConnClose(ConnMgr.server.conn, 1); - ConnMgr.server.conn = NULL; - } - - /* fixme - we need connection management flags for ConnClose to force the shutdown */ - ConnCloseAll(1); - - /* Management Client Shutdown */ - if (ManagementState() != MANAGEMENT_STOPPED) { - ManagementShutdown(); - - for (ccode = 0; (ManagementState() != MANAGEMENT_STOPPED) && (ccode < 60); ccode++) { - XplDelay(1000); - } - } - - XplWaitOnLocalSemaphore(ConnMgr.client.semaphore); - - ccode = XplSafeRead(ConnMgr.client.worker.idle); - while (ccode--) { - XplSignalLocalSemaphore(ConnMgr.client.worker.todo); - } - - XplSignalLocalSemaphore(ConnMgr.client.semaphore); - - for (ccode = 0; (XplSafeRead(ConnMgr.server.active) > 1) && (ccode < 60); ccode++) { - XplDelay(1000); - } - - if (XplSafeRead(ConnMgr.server.active) > 1) { - XplConsolePrintf("bongoconnmgr: %d server threads outstanding; attempting forceful unload.\r\n", XplSafeRead(ConnMgr.server.active) - 1); - } - -#if VERBOSE - XplConsolePrintf("\rbongoconnmgr: Shutting down %d client threads\r\n", XplSafeRead(ConnMgr.client.worker.active)); -#endif - - /* Make sure the kids have flown the coop. */ - for (ccode = 0; XplSafeRead(ConnMgr.client.worker.active) && (ccode < 60); ccode++) { - XplDelay(1000); - } - - if (XplSafeRead(ConnMgr.client.worker.active)) { - XplConsolePrintf("\rbongoconnmgr: %d threads outstanding; attempting forceful unload.\r\n", XplSafeRead(ConnMgr.client.worker.active)); - } - - XPLCryptoLockDestroy(); - - CONN_TRACE_SHUTDOWN(); - ConnShutdown(); - - /* Close down the modules */ - if (ConnMgr.modules) { - UnloadModules(ConnMgr.modules); - } - - LoggerClose(ConnMgr.loggingHandle); - ConnMgr.loggingHandle = NULL; - - MsgShutdown(); -/* MDBShutdown(); */ - - MemPrivatePoolFree(ConnMgr.client.pool); - MemoryManagerClose(MSGSRV_AGENT_CONNMGR); - - XplSignalLocalSemaphore(ConnMgr.sem.main); - XplWaitOnLocalSemaphore(ConnMgr.sem.shutdown); - - XplCloseLocalSemaphore(ConnMgr.sem.shutdown); - XplCloseLocalSemaphore(ConnMgr.sem.main); - - XplRWLockDestroy(&ConnMgr.authHandles.lock); - - for (i = 0; i < ConnMgr.authHandles.used; i++) { - MemFree(ConnMgr.authHandles.handles[i]); - } - MemFree(ConnMgr.authHandles.handles); - MemFree(ConnMgr.authHandles.addresses); - -#if VERBOSE - XplConsolePrintf("\rbongoconnmgr: Shutdown complete\r\n"); -#endif - XplSetThreadGroupID(id); - - return; -} - -static BOOL -ReadConfiguration(void) -{ - unsigned long i; - MDBValueStruct *config; - - config = MDBCreateValueStruct(ConnMgr.directoryHandle, NULL); - - if (config && MDBRead(MSGSRV_ROOT, MSGSRV_A_ACL, config)) { - gethostname(ConnMgr.server.host, sizeof(ConnMgr.server.host)); - HashCredential(MsgGetServerDN(NULL), config->Value[0], ConnMgr.server.hash); - - MDBFreeValues(config); - } else { - return(FALSE); - } - - MDBSetValueStructContext(MsgGetServerDN(NULL), config); - if (MDBRead(MSGSRV_AGENT_CONNMGR, MSGSRV_A_CONFIGURATION, config)) { - for (i = 0; i < config->Used; i++) { - if (XplStrNCaseCmp(config->Value[i], "MaxLoad:", 8)==0) { - XplSafeWrite(ConnMgr.client.worker.maximum, atol(config->Value[i] + 8)); - } - } - - MDBFreeValues(config); - } - - MsgGetLibDir(ConnMgr.moduleDir); - strcat(ConnMgr.moduleDir, "/connmgr"); - MsgMakePath(ConnMgr.moduleDir); - - MDBDestroyValueStruct(config); - - return(TRUE); -} - -#if defined(NETWARE) || defined(LIBC) || defined(WIN32) -int -_NonAppCheckUnload(void) -{ - int s; - static BOOL checked = FALSE; - XplThreadID id; - - if (!checked) { - checked = ConnMgr.state = CONNMGR_UNLOADING; - - XplWaitOnLocalSemaphore(ConnMgr.sem.shutdown); - - id = XplSetThreadGroupID(ConnMgr.id.group); - if (ConnMgr.server.conn->socket != -1) { - s = ConnMgr.server.conn->socket; - ConnMgr.server.conn->socket = -1; - - IPclose(s); - } - XplSetThreadGroupID(id); - - XplWaitOnLocalSemaphore(ConnMgr.sem.main); - } - - return(0); -} -#endif - -static void -SignalHandler(int sigtype) -{ - switch(sigtype) { - case SIGHUP: { - if (ConnMgr.state < CONNMGR_UNLOADING) { - ConnMgr.state = CONNMGR_UNLOADING; - } - - break; - } - case SIGINT : - case SIGTERM: { - if (ConnMgr.state == CONNMGR_STOPPING) { - XplUnloadApp(getpid()); - } else if (ConnMgr.state < CONNMGR_STOPPING) { - ConnMgr.state = CONNMGR_STOPPING; - } - - break; - } - - default: { - break; - } - } - - return; -} - -static BOOL -ConnMgrShutdown(unsigned char *arguments, unsigned char **response, BOOL *closeConnection) -{ - XplThreadID id; - - if (response) { - if (!arguments) { - if (ConnMgr.server.conn && (ConnMgr.server.conn->socket != -1)) { - *response = MemStrdup("Shutting down.\r\n"); - if (*response) { - id = XplSetThreadGroupID(ConnMgr.id.group); - - ConnMgr.state = CONNMGR_STOPPING; - - if (ConnMgr.server.conn) { - ConnClose(ConnMgr.server.conn, 1); - ConnMgr.server.conn = NULL; - } - - if (closeConnection) { - *closeConnection = TRUE; - } - - XplSetThreadGroupID(id); - } - } else if (ConnMgr.state >= CONNMGR_STOPPING) { - *response = MemStrdup("Shutdown in progress.\r\n"); - } else { - *response = MemStrdup("Unknown shutdown state.\r\n"); - } - - if (*response) { - return(TRUE); - } - - return(FALSE); - } - - *response = MemStrdup("arguments not allowed.\r\n"); - return(TRUE); - } - - return(FALSE); -} - -static BOOL -ConnMgrDMCCommandHelp(unsigned char *arguments, unsigned char **response, BOOL *closeConnection) -{ - BOOL responded = FALSE; - - if (response) { - if (arguments) { - switch(toupper(arguments[0])) { - case 'M': { - if (XplStrCaseCmp(arguments, DMCMC_DUMP_MEMORY_USAGE) == 0) { - if ((*response = MemStrdup(DMCMC_DUMP_MEMORY_USAGE_HELP)) != NULL) { - responded = TRUE; - } - - break; - } - } - - case 'C': { - if (XplStrNCaseCmp(arguments, DMCMC_CONN_TRACE_USAGE, sizeof(DMCMC_CONN_TRACE_USAGE) - 1) == 0) { - if ((*response = MemStrdup(DMCMC_CONN_TRACE_USAGE_HELP)) != NULL) { - responded = TRUE; - } - - break; - } - } - - case 'S': { - if (XplStrCaseCmp(arguments, DMCMC_SHUTDOWN) == 0) { - if ((*response = MemStrdup(DMCMC_SHUTDOWN_HELP)) != NULL) { - responded = TRUE; - } - - break; - } else if (XplStrCaseCmp(arguments, DMCMC_STATS) == 0) { - if ((*response = MemStrdup(DMCMC_STATS_HELP)) != NULL) { - responded = TRUE; - } - - break; - } - } - - default: { - break; - } - } - } else if ((*response = MemStrdup(DMCMC_HELP_HELP)) != NULL) { - responded = TRUE; - } - - if (responded || ((*response = MemStrdup(DMCMC_UNKOWN_COMMAND)) != NULL)) { - return(TRUE); - } - } - - return(FALSE); -} - -static BOOL -SendConnMgrStatistics(unsigned char *arguments, unsigned char **response, BOOL *closeConnection) -{ - MemStatistics poolStats; - - if (!arguments && response) { - memset(&poolStats, 0, sizeof(MemStatistics)); - - *response = MemMalloc(sizeof(PRODUCT_NAME) /* Long Name */ - + sizeof(PRODUCT_SHORT_NAME) /* Short Name */ - + 10 /* PRODUCT_MAJOR_VERSION */ - + 10 /* PRODUCT_MINOR_VERSION */ - + 10 /* PRODUCT_LETTER_VERSION */ - + 10 /* Connection Pool Allocation Count */ - + 10 /* Connection Pool Memory Usage */ - + 10 /* Connection Pool Pitches */ - + 10 /* Connection Pool Strikes */ - + 10 /* DMCMV_SERVER_THREAD_COUNT */ - + 10 /* DMCMV_CONNECTION_COUNT */ - + 10 /* DMCMV_IDLE_CONNECTION_COUNT */ - + 10 /* DMCMV_MAX_CONNECTION_COUNT */ - + 10 /* DMCMV_TOTAL_CONNECTIONS */ - + 10 /* DMCMV_BAD_PASSWORD_COUNT */ - + 28); /* Formatting */ - - MemPrivatePoolStatistics(ConnMgr.client.pool, &poolStats); - - if (*response) { - sprintf(*response, "%s (%s: v%d.%d.%d)\r\n%lu:%lu:%lu:%lu:%d:%d:%d:%d:%d:%d\r\n", - PRODUCT_NAME, - PRODUCT_SHORT_NAME, - PRODUCT_MAJOR_VERSION, - PRODUCT_MINOR_VERSION, - PRODUCT_LETTER_VERSION, - poolStats.totalAlloc.count, - poolStats.totalAlloc.size, - poolStats.pitches, - poolStats.strikes, - XplSafeRead(ConnMgr.server.active), - XplSafeRead(ConnMgr.client.worker.active), - XplSafeRead(ConnMgr.client.worker.idle), - XplSafeRead(ConnMgr.client.worker.maximum), - XplSafeRead(ConnMgr.stats.clients.serviced), - XplSafeRead(ConnMgr.stats.badPasswords)); - - return(TRUE); - } - - if ((*response = MemStrdup("Out of memory.\r\n")) != NULL) { - return(TRUE); - } - } else if ((arguments) && ((*response = MemStrdup("arguments not allowed.\r\n")) != NULL)) { - return(TRUE); - } - - return(FALSE); -} - -static BOOL -ReadConnMgrVariable(unsigned int variable, unsigned char *data, size_t *dataLength) -{ - size_t count; - unsigned char *ptr; - - switch (variable) { - case 0: { - unsigned char version[30]; - - PVCSRevisionToVersion(PRODUCT_VERSION, version); - count = strlen(version) + 10; - - if (data && (*dataLength > count)) { - ptr = data; - - PVCSRevisionToVersion(PRODUCT_VERSION, version); - ptr += sprintf(ptr, "connmgr.c: %s\r\n", version); - - *dataLength = ptr - data; - } else { - *dataLength = count; - } - - break; - } - - case 1: { - if (data && (*dataLength > 12)) { - sprintf(data, "%010d\r\n", XplSafeRead(ConnMgr.client.worker.maximum)); - } - - *dataLength = 12; - break; - } - - case 2: { - if (data && (*dataLength > 12)) { - sprintf(data, "%010d\r\n", XplSafeRead(ConnMgr.server.active)); - } - - *dataLength = 12; - break; - } - - case 3: { - if (data && (*dataLength > 12)) { - sprintf(data, "%010d\r\n", XplSafeRead(ConnMgr.client.worker.active)); - } - - *dataLength = 12; - break; - } - - case 4: { - if (data && (*dataLength > 12)) { - sprintf(data, "%010d\r\n", XplSafeRead(ConnMgr.client.worker.idle)); - } - - *dataLength = 12; - break; - } - - case 5: { - if (ConnMgr.stopped == FALSE) { - ptr = "FALSE\r\n"; - count = 7; - } else { - ptr = "TRUE\r\n"; - count = 6; - } - - if (data && (*dataLength > count)) { - strcpy(data, ptr); - } - - *dataLength = count; - break; - } - - case 6: { - if (data && (*dataLength > 12)) { - sprintf(data, "%010d\r\n", XplSafeRead(ConnMgr.stats.clients.serviced)); - } - - *dataLength = 12; - break; - } - - case 7: { - if (data && (*dataLength > 12)) { - sprintf(data, "%010d\r\n", XplSafeRead(ConnMgr.stats.badPasswords)); - } - - *dataLength = 12; - break; - } - - case 8: { - DMC_REPORT_PRODUCT_VERSION(data, *dataLength); - break; - } - - default: { - *dataLength = 0; - return(FALSE); - } - } - - return(TRUE); -} - -static BOOL -WriteConnMgrVariable(unsigned int variable, unsigned char *data, size_t dataLength) -{ - unsigned char *ptr; - unsigned char *ptr2; - BOOL result = TRUE; - - if (!data || !dataLength) { - return(FALSE); - } - - switch (variable) { - case 1: { - ptr = strchr(data, '\n'); - if (ptr) { - *ptr = '\0'; - } - - ptr2 = strchr(data, '\r'); - if (ptr2) { - ptr2 = '\0'; - } - - XplSafeWrite(ConnMgr.client.worker.maximum, atol(data)); - - if (ptr) { - *ptr = '\n'; - } - - if (ptr2) { - *ptr2 = 'r'; - } - - break; - } - - case 5: { - if ((toupper(data[0]) == 'T') || (atol(data) != 0)) { - ConnMgr.stopped = TRUE; - } else if ((toupper(data[0] == 'F')) || (atol(data) == 0)) { - ConnMgr.stopped = FALSE; - } else { - result = FALSE; - } - - break; - } - - case 9: { - ptr = strchr(data, '\n'); - if (ptr) { - *ptr = '\0'; - } - - ptr2 = strchr(data, '\r'); - if (ptr2) { - ptr2 = '\0'; - } - - XplSafeWrite(ConnMgr.stats.clients.serviced, atol(data)); - - if (ptr) { - *ptr = '\n'; - } - - if (ptr2) { - *ptr2 = 'r'; - } - - break; - } - - case 10: { - ptr = strchr(data, '\n'); - if (ptr) { - *ptr = '\0'; - } - - ptr2 = strchr(data, '\r'); - if (ptr2) { - ptr2 = '\0'; - } - - XplSafeWrite(ConnMgr.stats.badPasswords, atol(data)); - - if (ptr) { - *ptr = '\n'; - } - - if (ptr2) { - *ptr2 = 'r'; - } - - break; - } - - case 0: - case 2: - case 3: - case 4: - case 6: - case 7: - case 8: - default: { - result = FALSE; - break; - } - } - - return(result); -} - - - -XplServiceCode(SignalHandler) - -int -XplServiceMain(int argc, char *argv[]) -{ - int ccode; - XplThreadID id; - - if (XplSetEffectiveUser(MsgGetUnprivilegedUser()) < 0) { - XplConsolePrintf("bongoconnmgr: Could not drop to unprivileged user '%s', exiting.\n", MsgGetUnprivilegedUser()); - return(-1); - } - XplInit(); - ConnMgr.id.main = XplGetThreadID(); - ConnMgr.id.group = XplGetThreadGroupID(); - - ConnMgr.state = CONNMGR_INITIALIZING; - ConnMgr.stopped = FALSE; - - XplSignalHandler(SignalHandler); - - ConnMgr.client.sleepTime = 60; - ConnMgr.client.pool = NULL; - - ConnMgr.server.conn = NULL; - - ConnMgr.directoryHandle = NULL; - ConnMgr.loggingHandle = NULL; - - XplSafeWrite(ConnMgr.server.active, 0); - - XplSafeWrite(ConnMgr.client.worker.idle, 0); - XplSafeWrite(ConnMgr.client.worker.active, 0); - XplSafeWrite(ConnMgr.client.worker.maximum, 100000); - - XplSafeWrite(ConnMgr.stats.clients.serviced, 0); - XplSafeWrite(ConnMgr.stats.badPasswords, 0); - - if (MemoryManagerOpen(MSGSRV_AGENT_CONNMGR) == TRUE) { - ConnMgr.client.pool = MemPrivatePoolAlloc("Connection Manager Connections", sizeof(ConnMgrClient), 0, 3072, TRUE, FALSE, ConnMgrClientAllocCB, NULL, NULL); - if (ConnMgr.client.pool != NULL) { - XplOpenLocalSemaphore(ConnMgr.sem.main, 0); - XplOpenLocalSemaphore(ConnMgr.sem.shutdown, 1); - XplOpenLocalSemaphore(ConnMgr.client.semaphore, 1); - XplOpenLocalSemaphore(ConnMgr.client.worker.todo, 0); - } else { - MemoryManagerClose(MSGSRV_AGENT_CONNMGR); - - XplConsolePrintf("bongoconnmgr: Unable to create connection pool; shutting down.\r\n"); - return(-1); - } - } else { - XplConsolePrintf("bongoconnmgr: Unable to initialize memory manager; shutting down.\r\n"); - return(-1); - } - - ConnStartup(CONNECTION_TIMEOUT, TRUE); - - MDBInit(); - ConnMgr.directoryHandle = (MDBHandle)MsgInit(); - if (ConnMgr.directoryHandle == NULL) { - XplBell(); - XplConsolePrintf("\rbongoconnmgr: Invalid directory credentials; exiting!\n"); - XplBell(); - - MemoryManagerClose(MSGSRV_AGENT_CONNMGR); - - return(-1); - } - - ConnMgr.loggingHandle = LoggerOpen("bongoconnmgr"); - if (ConnMgr.loggingHandle == NULL) { - XplConsolePrintf("bongoconnmgr: Unable to initialize logging interface. Logging disabled.\r\n"); - } - - if (!ReadConfiguration()) { - XplConsolePrintf("bongoconnmgr: Unable to read configuration. Exiting.\r\n"); - return(-1); - } - CONN_TRACE_INIT((char *)MsgGetWorkDir(NULL), "connmgr"); - // CONN_TRACE_SET_FLAGS(CONN_TRACE_ALL); /* uncomment this line and pass '--enable-conntrace' to autogen to get the agent to trace all connections */ - - - XplRWLockInit(&ConnMgr.authHandles.lock); - - /* Load the modules */ - ConnMgr.modules = LoadModules(ConnMgr.moduleDir, NULL); - if (!ConnMgr.modules) { - XplConsolePrintf("bongoconnmgr: Failed to load any modules. Functionality will be limited.\n"); - } - - if (ServerSocketInit () < 0) { - XplConsolePrintf("bongoconnmgr: Exiting.\n"); - return(-1); - } - - /* Done binding, drop privs permanentely */ - if (XplSetRealUser(MsgGetUnprivilegedUser()) < 0) { - XplConsolePrintf("bongoconnmgr: Could not drop to unprivileged user '%s', exiting.\n", MsgGetUnprivilegedUser()); - return(-1); - } - - /* Management Client Startup */ - if ((ManagementInit(MSGSRV_AGENT_CONNMGR, ConnMgr.directoryHandle)) - && (ManagementSetVariables(ConnMgrManagementVariables, sizeof(ConnMgrManagementVariables) / sizeof(ManagementVariables))) - && (ManagementSetCommands(ConnMgrManagementCommands, sizeof(ConnMgrManagementCommands) / sizeof(ManagementCommands)))) { - XplBeginThread(&id, ManagementServer, DMC_MANAGEMENT_STACKSIZE, NULL, ccode); - } - - ConnMgr.state = CONNMGR_LOADING; - - XplStartMainThread(PRODUCT_SHORT_NAME, &id, ConnMgrServer, 8192, NULL, ccode); - - XplUnloadApp(XplGetThreadID()); - return(0); -} diff --git a/src/agents/connmgr/connmgrp.h b/src/agents/connmgr/connmgrp.h deleted file mode 100644 index f56fd63..0000000 --- a/src/agents/connmgr/connmgrp.h +++ /dev/null @@ -1,42 +0,0 @@ -/**************************************************************************** - * - * Copyright (c) 2001 Novell, Inc. All Rights Reserved. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public License - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, contact Novell, Inc. - * - * To contact Novell about this file by physical or electronic mail, you - * may find current contact information at www.novell.com. - * - ****************************************************************************/ - -#include - -#define CONNMGR_STACK_SPACE (1024 * 32) -#define CONNECTION_TIMEOUT (15 * 60) - -/* modules.c */ -typedef struct _ModuleStruct { - struct _CMModuleRegistrationStruct registration; - - CMInitFunc Init; - XplPluginHandle handle; - struct _ModuleStruct *next; - unsigned char *name; -} ModuleStruct; - - -void ModulesVerify(ModuleStruct *first, ConnMgrCommand *command, ConnMgrResult *result); -void ModulesNotify(ModuleStruct *first, ConnMgrCommand *command); -ModuleStruct * LoadModules(unsigned char *directory, ModuleStruct *first); -void UnloadModules(ModuleStruct *first); - diff --git a/src/agents/connmgr/modules.c b/src/agents/connmgr/modules.c deleted file mode 100644 index db3a069..0000000 --- a/src/agents/connmgr/modules.c +++ /dev/null @@ -1,212 +0,0 @@ -/**************************************************************************** - * - * Copyright (c) 2001 Novell, Inc. All Rights Reserved. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public License - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, contact Novell, Inc. - * - * To contact Novell about this file by physical or electronic mail, you - * may find current contact information at www.novell.com. - * - ****************************************************************************/ - -#include -#include - -#include -#include - -#include "connmgrp.h" - -void -ModulesVerify(ModuleStruct *first, ConnMgrCommand *command, ConnMgrResult *result) -{ - ModuleStruct *module = first; - result->result = command->detail.policy.default_result; - - while (module) { - if (module->registration.Verify) { - int rc = module->registration.Verify(command, result); - - if (rc & CM_MODULE_DENY) { - if (rc & CM_MODULE_PERMANENT) { - result->result = CM_RESULT_DENY_PERMANENT; - } else { - result->result = CM_RESULT_DENY_TEMPORARY; - } - } - - if (rc & CM_MODULE_FORCE) { - if (rc & CM_MODULE_ACCEPT) { - result->result = CM_RESULT_ALLOWED; - } - - return; - } - } - - module = module->next; - } -} - -void -ModulesNotify(ModuleStruct *first, ConnMgrCommand *command) -{ - ModuleStruct *module = first; - - while (module) { - if (module->registration.Notify) { - module->registration.Notify(command); - } - - module = module->next; - } -} - -ModuleStruct * -LoadModules(unsigned char *directory, ModuleStruct *first) -{ - XplDir *dir; - XplDir *dirent; - ModuleStruct *result = first; - - XplMakeDir(XPL_DEFAULT_DBF_DIR "//connmgr"); - - if ((dir = XplOpenDir(directory)) != NULL) { - while ((dirent = XplReadDir(dir)) != NULL) { - unsigned char path[XPL_MAX_PATH +1 ]; - unsigned char name[XPL_MAX_PATH + 1]; - unsigned char *modulename = dirent->d_nameDOS; - ModuleStruct *new = MemMalloc(sizeof(ModuleStruct)); - unsigned char datadir[XPL_MAX_PATH + 1]; - - memset(new, 0, sizeof(ModuleStruct)); - - if (strlen(modulename) > 3) { - snprintf(path, sizeof(path), "%s/lib%s", directory, modulename); - new->handle = XplLoadDLL(path); - - if (!new->handle) { - snprintf(path, sizeof(path), "%s/%s", directory, modulename); - new->handle = XplLoadDLL(path); - } - - if (new->handle) { - unsigned char *ptr; - - /* Initialize the module */ - if (XplStrNCaseCmp(modulename, "lib", 3) == 0) { - BongoStrNCpy(name, modulename + 3, sizeof(name) - strlen("Init")); - } else { - BongoStrNCpy(name, modulename, sizeof(name) - strlen("Init")); - } - - ptr = strrchr(name, '.'); - if (ptr) { - *ptr = '\0'; - } - - /* Setup the work directory for the module */ - ptr = name; - while (*ptr) { - *ptr = tolower(*ptr); - ptr++; - } - - sprintf(datadir, "%s/connmgr/%s", XPL_DEFAULT_DBF_DIR, name); - XplMakeDir(datadir); - - ptr = name; - while (*ptr) { - *ptr = toupper(*ptr); - ptr++; - } - - strcat(name, "Init"); - new->Init = (CMInitFunc)XplGetDLLFunction(modulename, name, new->handle); - name[strlen(name) - 4] = '\0'; -#if 0 - } else { - /* dlerror() is much more useful when dlopen fails than errno is */ - unsigned char *err = dlerror(); - if (err) { - XplConsolePrintf("connmgr: XplLoadDLL failed: %s\n", err); - } - XplConsolePrintf("connmgr: could not load module %s/%s, errno: %d %s\n", directory, modulename, errno, strerror(errno)); -#endif - } - } - - if (new->Init && new->Init(&(new->registration), datadir)) { - new->name = MemStrdup(name); - -#if VERBOSE - XplConsolePrintf("connmgr: loaded module: %s\n", new->name); -#endif - - if (!result) { - result = new; - } else if (result->registration.priority > new->registration.priority) { - new->next = result; - result = new; - } else { - ModuleStruct *n = result; - - /* Find a spot for it */ - while (n && n->next) { - if (n->next->registration.priority > new->registration.priority) { - new->next = n->next; - n->next = new; - n = NULL; - } - - if (n) { - n = n->next; - } - } - - if (n) { - n->next = new; - } - } - } else { - MemFree(new); - } - } - - XplCloseDir(dir); - } - - return(result); -} - -void -UnloadModules(ModuleStruct *first) -{ - ModuleStruct *module = first; - - while (module) { - ModuleStruct *next = module->next; - - if (module->registration.Shutdown) { - module->registration.Shutdown(); - } - - if (module->handle && module->name) { - XplUnloadDLL(module->name, module->handle); - MemFree(module->name); - } - - MemFree(module); - module = next; - } -} diff --git a/src/libs/connmgr/Bongo.rules b/src/libs/connmgr/Bongo.rules deleted file mode 100644 index c08306f..0000000 --- a/src/libs/connmgr/Bongo.rules +++ /dev/null @@ -1,10 +0,0 @@ -# -*- Makefile -*- -lib_LTLIBRARIES += libbongoconnmgr.la - -#libbongonmap_la_LDFLAGS := -static -libbongoconnmgr_la_SOURCES := \ - src/libs/connmgr/connmgr.c \ - src/libs/connmgr/hashcred.c - -src/libs/connmgr/all: libbongoconnmgr.la -src/libs/connmgr/clean: clean diff --git a/src/libs/connmgr/Makefile.am b/src/libs/connmgr/Makefile.am deleted file mode 100644 index 8830401..0000000 --- a/src/libs/connmgr/Makefile.am +++ /dev/null @@ -1,17 +0,0 @@ -# -*- Makefile -*- -# -# Do not edit! -# -# (unless this is Makefile.am.subdir) -# -# This file is a copy of the toplevel Makefile.am.subdir. If changes -# need to be made, edit that file, and make update-makefiles, and -# check the new files in. -# -# This is a skeletal automake file. The real automake fules for -# building the targets for this directory can be found in the -# Bongo.rules file. This file is simply here so that 'make all' can -# work in each subdirectory. - -all clean install: - @cd $(top_builddir) && $(MAKE) $(MFLAGS) $(subdir)/$@ diff --git a/src/libs/connmgr/connmgr.c b/src/libs/connmgr/connmgr.c deleted file mode 100644 index 9ed733e..0000000 --- a/src/libs/connmgr/connmgr.c +++ /dev/null @@ -1,342 +0,0 @@ -/**************************************************************************** - * - * Copyright (c) 2001 Novell, Inc. All Rights Reserved. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public License - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, contact Novell, Inc. - * - * To contact Novell about this file by physical or electronic mail, you - * may find current contact information at www.novell.com. - * - ****************************************************************************/ - -#include -#include -#include - -#include - -#include -#include -#include - -struct { - unsigned char access[CM_HASH_SIZE]; - unsigned char pass[XPLHASH_MD5_LENGTH]; - MDBHandle directoryHandle; - - BOOL debug; - unsigned long address; - - XplRWLock lock; - unsigned char service[16 + 1]; -} CMLibrary = { - { '\0' }, - { '\0' }, - NULL, - - FALSE -}; - -BOOL -CMSendCommand(ConnMgrCommand *command, ConnMgrResult *result) -{ - struct sockaddr_in fromSin; - struct sockaddr_in toSin; - int sock; - int tries = 0; - - do { - result->result = CM_RESULT_UNKNOWN_ERROR; - - XplRWReadLockAcquire(&CMLibrary.lock); - strcpy(command->pass, CMLibrary.pass); - XplRWReadLockRelease(&CMLibrary.lock); - - memset(&fromSin, 0, sizeof(struct sockaddr_in)); - memset(&toSin, 0, sizeof(struct sockaddr_in)); - sock = IPsocket(PF_INET, SOCK_DGRAM, IPPROTO_UDP); - if (sock >= 0) { - toSin.sin_family = AF_INET; - toSin.sin_addr.s_addr = CMLibrary.address; - toSin.sin_port = htons(CM_PORT); - - fromSin.sin_family = AF_INET; - fromSin.sin_addr.s_addr = 0; - fromSin.sin_port = 0; - - if (IPbind(sock, (struct sockaddr *)&fromSin, sizeof(fromSin)) == 0) { - sendto(sock, (unsigned char *)command, sizeof(ConnMgrCommand), 0, (struct sockaddr*)&toSin, sizeof(toSin)); - XplIPRead(XPL_INT_TO_PTR(sock), (unsigned char *)result, sizeof(ConnMgrResult), 19); - } - IPclose(sock); - } - - if (result->result == CM_RESULT_MUST_AUTH) { - xpl_hash_context ctx; - - // Ensure that we don't walk off the edge of the buffer if garbage was sent - result->detail.salt[sizeof(result->detail.salt) - 1] = '\0'; - - XplHashNew(&ctx, XPLHASH_MD5); - XplHashWrite(&ctx, result->detail.salt, strlen(result->detail.salt)); - XplHashWrite(&ctx, CMLibrary.access, CM_HASH_SIZE); - XplHashFinal(&ctx, XPLHASH_LOWERCASE, command->pass, XPLHASH_MD5_LENGTH); - - /* Store the password so we don't have to generate it every time */ - XplRWWriteLockAcquire(&CMLibrary.lock); - strcpy(CMLibrary.pass, command->pass); - XplRWWriteLockRelease(&CMLibrary.lock); - } else { - return(TRUE); - } - } while (tries++ < 3); - - return(FALSE); -} - -int -CMVerifyConnect(unsigned long address, unsigned char *comment, BOOL *requireAuth) -{ - ConnMgrCommand command; - ConnMgrResult result; - - memset(&command, 0, sizeof(command)); - memset(&result, 0, sizeof(result)); - - command.command = CM_COMMAND_VERIFY; - strcpy(command.event, CM_EVENT_CONNECT); - command.address = address; - command.detail.policy.default_result = CM_RESULT_ALLOWED; - - CMSendCommand(&command, &result); - - if (result.comment[0] != '\0') { - strncpy(comment, result.comment, sizeof(result.comment)); - } else { - comment[0] = '\0'; - } - - if (requireAuth) { - *requireAuth = result.detail.connect.requireAuth; - } - - return(result.result); -} - -int -CMVerifyRelay(unsigned long address, unsigned char *user) -{ - ConnMgrCommand command; - ConnMgrResult result; - - memset(&command, 0, sizeof(command)); - memset(&result, 0, sizeof(result)); - - command.command = CM_COMMAND_VERIFY; - strcpy(command.event, CM_EVENT_RELAY); - command.address = address; - command.detail.policy.default_result = CM_RESULT_MUST_AUTH; - - CMSendCommand(&command, &result); - - if (result.result == CM_RESULT_ALLOWED && user) { - strncpy(user, result.detail.user, MAXEMAILNAMESIZE); - } else { - user[0] = '\0'; - } - - return(result.result); -} - -int -CMDisconnected(unsigned long address) -{ - ConnMgrCommand command; - ConnMgrResult result; - - memset(&command, 0, sizeof(command)); - memset(&result, 0, sizeof(result)); - - command.command = CM_COMMAND_NOTIFY; - strcpy(command.event, CM_EVENT_DISCONNECTED); - command.address = address; - - CMSendCommand(&command, &result); - return(result.result); -} - -int -CMAuthenticated(unsigned long address, unsigned char *user) -{ - ConnMgrCommand command; - ConnMgrResult result; - - memset(&command, 0, sizeof(command)); - memset(&result, 0, sizeof(result)); - - command.command = CM_COMMAND_NOTIFY; - strcpy(command.event, CM_EVENT_AUTHENTICATED); - command.address = address; - - if (user) { - strncpy(command.detail.authenticated.user, user, MAXEMAILNAMESIZE); - } else { - command.detail.authenticated.user[0] = '\0'; - } - - CMSendCommand(&command, &result); - return(result.result); -} - -int -CMDelivered(unsigned long address, unsigned long recipients) -{ - ConnMgrCommand command; - ConnMgrResult result; - - memset(&command, 0, sizeof(command)); - memset(&result, 0, sizeof(result)); - - command.command = CM_COMMAND_NOTIFY; - strcpy(command.event, CM_EVENT_DELIVERED); - command.address = address; - command.detail.delivered.recipients = recipients; - - CMSendCommand(&command, &result); - return(result.result); -} - -int -CMReceived(unsigned long address, unsigned long local, unsigned long invalid, unsigned long remote) -{ - ConnMgrCommand command; - ConnMgrResult result; - - memset(&command, 0, sizeof(command)); - memset(&result, 0, sizeof(result)); - - command.command = CM_COMMAND_NOTIFY; - strcpy(command.event, CM_EVENT_RECEIVED); - command.address = address; - - command.detail.received.local = local; - command.detail.received.invalid = invalid; - command.detail.received.remote = remote; - - CMSendCommand(&command, &result); - return(result.result); -} - -int -CMFoundVirus(unsigned long address, unsigned long recipients, unsigned char *name) -{ - ConnMgrCommand command; - ConnMgrResult result; - - memset(&command, 0, sizeof(command)); - memset(&result, 0, sizeof(result)); - - command.command = CM_COMMAND_NOTIFY; - strcpy(command.event, CM_EVENT_VIRUS_FOUND); - command.address = address; - command.detail.virus.recipients = recipients; - - if (name) { - strncpy(command.detail.virus.name, name, 256); - } else { - command.detail.virus.name[0] = '\0'; - } - - CMSendCommand(&command, &result); - return(result.result); -} - -int -CMSpamFound(unsigned long address, unsigned long recipients) -{ - ConnMgrCommand command; - ConnMgrResult result; - - memset(&command, 0, sizeof(command)); - memset(&result, 0, sizeof(result)); - - command.command = CM_COMMAND_NOTIFY; - strcpy(command.event, CM_EVENT_SPAM_FOUND); - command.address = address; - command.detail.spam.recipients = recipients; - - CMSendCommand(&command, &result); - return(result.result); -} - -int -CMDOSDetected(unsigned long address, unsigned char *description) -{ - ConnMgrCommand command; - ConnMgrResult result; - - memset(&command, 0, sizeof(command)); - memset(&result, 0, sizeof(result)); - - command.command = CM_COMMAND_NOTIFY; - strcpy(command.event, CM_EVENT_DOS_DETECTED); - command.address = address; - - if (description) { - strncpy(command.detail.dos.description, description, 256); - } else { - command.detail.dos.description[0] = '\0'; - } - - CMSendCommand(&command, &result); - return(result.result); -} - -BOOL -CMInitialize(MDBHandle directoryHandle, unsigned char *service) -{ - BOOL result = FALSE; - - if (directoryHandle) { - MDBValueStruct *v; - - CMLibrary.directoryHandle = directoryHandle; - - v = MDBCreateValueStruct(CMLibrary.directoryHandle, NULL); - if (v) { - MDBRead(MSGSRV_ROOT, MSGSRV_A_ACL, v); - if (v->Used) { - result = HashCredential(MsgGetServerDN(NULL), v->Value[0], CMLibrary.access); - } - - MDBFreeValues(v); - - if (MsgReadIP((unsigned char *) MsgGetServerDN(NULL), MSGSRV_A_CONNMGR, v)) { - CMLibrary.address = inet_addr(v->Value[0]); - } - - MDBDestroyValueStruct(v); - } - - XplRWLockInit(&CMLibrary.lock); - } - - if (service) { - strncpy(CMLibrary.service, service, 16); - CMLibrary.service[16] = '\0'; - } else { - CMLibrary.service[0] = '\0'; - } - - return(result); -} diff --git a/src/libs/connmgr/hashcred.c b/src/libs/connmgr/hashcred.c deleted file mode 100644 index d9aa49d..0000000 --- a/src/libs/connmgr/hashcred.c +++ /dev/null @@ -1,137 +0,0 @@ -/**************************************************************************** - * - * Copyright (c) 2001 Novell, Inc. All Rights Reserved. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public License - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, contact Novell, Inc. - * - * To contact Novell about this file by physical or electronic mail, you - * may find current contact information at www.novell.com. - * - ****************************************************************************/ - -#if 0 -#include -#include -#include -#include -#include - -#define ORGANIZATION_BUFFER_SIZE 100 - -#define GK_CRED_STORE_SIZE 4096 -#define GK_CRED_DIGEST_SIZE 16 -#define GK_CRED_CHUNK_SIZE (GK_CRED_STORE_SIZE * GK_CRED_DIGEST_SIZE) / GK_HASH_SIZE - -static BOOL -GetOrgName(unsigned char *Organization) -{ - unsigned long len; - unsigned char *ptr; - unsigned char *buffer; - - /* get the treename */ - buffer = MemStrdup(MsgGetServerDN(NULL)); - if (buffer) { - if (buffer[0] == '\\') { - ptr = strchr(buffer + 1, '\\'); - if (ptr) { - len = ptr - (buffer + 1); - if (len > 0) { - if (len < ORGANIZATION_BUFFER_SIZE) { - *ptr = '\0'; - strcpy(Organization, buffer + 1); - *ptr = '\\'; - } else { - memcpy(Organization, buffer + 1, ORGANIZATION_BUFFER_SIZE); - Organization[ORGANIZATION_BUFFER_SIZE] = '\0'; - } - MemFree(buffer); - return(TRUE); - } - } - } - - MemFree(buffer); - } - - return(FALSE); -} - -BOOL -HashCredential(unsigned char *Credential, unsigned char *Hash) -{ - unsigned char organization[ORGANIZATION_BUFFER_SIZE + 1]; - unsigned char *ptr; - unsigned long organizationLen; - unsigned long len; - - if (Hash && Credential) { - len = strlen(Credential); - if (GetOrgName(organization)) { - organizationLen = strlen(organization); - if (len >= GK_CRED_STORE_SIZE) { - unsigned long i; - MD5_CTX mdContext; - unsigned char digest[GK_CRED_DIGEST_SIZE]; - unsigned char *srcPtr; - unsigned char *dstPtr; - unsigned char *dstEnd; - - srcPtr = Credential; - dstPtr = Hash; - dstEnd = Hash + GK_HASH_SIZE; - - MD5_Init(&mdContext); - MD5_Update(&mdContext, srcPtr, GK_CRED_CHUNK_SIZE); - MD5_Update(&mdContext, organization, organizationLen); - MD5_Final(digest, &mdContext); - - srcPtr += GK_CRED_CHUNK_SIZE; - - for (i = 0; i < GK_CRED_DIGEST_SIZE; i++) { - if (dstPtr < dstEnd) { - *dstPtr = digest[i]; - dstPtr++; - } - } - - do { - MD5_Init(&mdContext); - MD5_Update(&mdContext, srcPtr, GK_CRED_CHUNK_SIZE); - MD5_Update(&mdContext, Hash, dstPtr - Hash); - MD5_Final(digest, &mdContext); - - srcPtr += GK_CRED_CHUNK_SIZE; - - for (i = 0; i < GK_CRED_DIGEST_SIZE; i++) { - if (dstPtr < dstEnd) { - *dstPtr = digest[i]; - dstPtr++; - } - } - } while (dstPtr < dstEnd); - - /* Hash now contains a non-terminated 128 byte octet string */ - return(TRUE); - } - - XplConsolePrintf("\rGate Keeper credentials are not properly configured!\r\n"); - return(FALSE); - } - - XplConsolePrintf("\Bongo can not determine what organization it is running on.\r\n"); - return(FALSE); - } - return(FALSE); -} -#endif