./dhis-mx-sendmail-engine-5.0/004075500017500000012000000000000726163263000162355ustar00jcncstaff00001460000000./dhis-mx-sendmail-engine-5.0/CONTRIBUTORS010064400017500000012000000001030726010322500200740ustar00jcncstaff00001460000000Peder Fugl Ian Chilton Nuno Rodriges Jonas Jochum Emile Van Bergen ./dhis-mx-sendmail-engine-5.0/COPYRIGHT010064400017500000012000000025470726010322500175250ustar00jcncstaff00001460000000- Copyright (c) 1998-2001 Joao Cabral (jcnc@dhis.org) All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. DHIS(c) Dynamic Host Information System Release 5.0 ./dhis-mx-sendmail-engine-5.0/INSTALL010064400017500000012000000071210726010567600172700ustar00jcncstaff00001460000000Install instructions for DHIS R5 server module dhis-mx-sendmail-engine ====================================================================== This package contains a dynamic MX service module to be used with dhisd release 5 or above and the dynamic DNS module. While the DHIS server dhisd retrieves dynamic IP addresses from clients, this module allows the server to deliver messages that were previously queued for the newly online host. In order to install dhis-mx-sendmail-engine-5.0: A domain under which dynamic hosts will be updated must be available. The machine must be permanently connected to the internet with a static IP address. The machine which will act as a server should be running a distribution of UNIX or similar system. A DHIS R5 server dhisd must be running on the same machine. This module must be included in the server's service database. 1. Compile Stage ================ If your system is System V based, edit the Makefile and add -lsocket -lnsl to the LIBS section. These are required for TCP/IP operation. Being in the source directory type "make". You may need to edit dhis-mx-sendmail-engine.c and update the sendmail path of sendmail. It should build the dhisd binary. 2. Install stage ================ You will need to have dhisd installed in your system. Move the newly compiled module dhis-mx-sendmail-engine to /etc/dhis/bin Edit /etc/dhis/db/services.db and add a line in the form: mx 5 /etc/dhis/bin/dhis-mx-sendmail-engine In here dns identifies the service type, 5 is the number of processes to serve mail relay (may differ depending on resources and load requirements) and the command is the child process for dhisd to fork into. Edit /etc/dhis/db/dhis.db For each client that is to have dynamic mail relay support add a line such as: Service mx Terminate your current DHIS server if running with SIGTERM Execute your DHIS server with something like /etc/dhis/bin/dhisd The module in installed 3. DNS stage ============ The final stage is to configure DNS, i.e. BIND 8, to allow mail relaying. Assuming BIND is already running from the dynamic DNS module and configured: For each host in dhis.db with the mx service perform a one time nsupdate as follows: execute nsupdate Type in: >update add dyn.example.com. 86400 in mx 0 dyn4.example.com. >update add dyn.example.com. 86400 in mx 10 relay.example.com. And press return twice. This adds a DNS MX record for host dyn.example.com with a lower preference to the dynamic address and a backup relay server. relay.example.com must be a valid static hostname of this server providing mail relaying. 4. Adding mail relay to clients =============================== To add mail relay to clients simply: 1) Edit dhis.db and add "service mx" to the client 2) Add that client MX records to DNS as above 3) Reload dhisd with -HUP 5. Setting up the mail relay agent (MTA) ======================================== This module is based on sendmail residing on /usr/sbin/sendmail To change the location of sendmail edit dhis-mx-sendmail-engine.c and change the appropriate path before compiling. You will need to configure the MTA to relay messages for your domain (example.com). All this engine does is basically receiving requests and issuing sendmail to deliver mail for the appropriate host. In sendmail: Add a DNS A record for relay.example.com with the server's IP address. Edit sendmail.cw and add relay.example.com Edit relay-domains and add example.com Restart sendmail And that's it. The DHIS MX module is installed. ./dhis-mx-sendmail-engine-5.0/Makefile010064400017500000012000000037030726163266100177010ustar00jcncstaff00001460000000# - # Copyright (c) 1998-2001 Joao Cabral (jcnc@dhis.org) # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # DHIS(c) Dynamic Host Information System Release 5.0 CC=gcc CFLAGS=-Wall LFLAGS= LIBS= RM=rm -f INSTALLDIR=/etc/dhis/bin MODE=700 OWNER=root MKDIR=mkdir -p CHOWN=chown CHMOD=chmod CP=cp dhis-mx-sendmail-engine:dhis-mx-sendmail-engine.c $(CC) $(CFLAGS) $(LFLAGS) -o dhis-mx-sendmail-engine dhis-mx-sendmail-engine.c $(LIBS) strip dhis-mx-sendmail-engine install: dhis-mx-sendmail-engine $(MKDIR) $(INSTALLDIR) $(CP) dhis-mx-sendmail-engine $(INSTALLDIR) $(CHOWN) $(OWNER) $(INSTALLDIR)/dhis-mx-sendmail-engine $(CHMOD) $(MODE) $(INSTALLDIR)/dhis-mx-sendmail-engine clean: $(RM) *.core core dhis-mx-sendmail-engine *.o this list of conditions and the following disclaimer in the #./dhis-mx-sendmail-engine-5.0/README010064400017500000012000000025560726141127200171170ustar00jcncstaff00001460000000Install instructions for DHIS R5 server module dhis-mx-sendmail-engine ====================================================================== This package contains a mail relaying service module to be used with dhisd release 5 or above and the dynamic DNS module. While the DHIS server dhisd retrieves dynamic IP addresses from clients, this module allows the server to deliver messages that were previously queued for the newly online host. This module is to be used with sendmail as an MTA. While this module listens to messages from the dhisd server, sendmail is invoqued from it to actually deliver email messages. This module depends on the DNS module as messages will query DNS to obtain the IP address of the host for which mail is to be delivered. This module uses the DHIS server database file itself to build its ID to FQDN matrix. When reading /etc/dhis/db/dhis.db it ignores all keyword lines apart from HostName. This allows a single database file for both DHIS plus MX module. The DHIS server likewise ignores HostName lines. Database files from release 4 may be used with DHIS R5 + this module For more information on modules see the dhisd documentation. Support: ======== Please address any questions regarding this module to server@dhis.org. If you are not part of the mailing list email majordomo@dhis.org with a single line containing "subscribe server". ./dhis-mx-sendmail-engine-5.0/dhis-mx-sendmail-engine.c010064400017500000012000000144560726162351100230140ustar00jcncstaff00001460000000/*- * Copyright (c) 1998-2001 Joao Cabral (jcnc@dhis.org) * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * DHIS(c) Dynamic Host Information System Release 5.0 */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define DHISD_DB "/etc/dhis/db/dhis.db" #define DHISE_LOG "/etc/dhis/log/dhis-mx-sendmail-engine.log" #define SENDMAIL "/usr/sbin/sendmail" #define MAX_HOSTNAME 64 typedef struct db_t { int id; unsigned char fqdn[MAX_HOSTNAME]; struct db_t *next; } db_t; /* Function prototypes */ int db_reload(void); int db_free(void); int db_add(db_t *); unsigned char *db_hostname(int); void strtolower(unsigned char *); void off_nl(unsigned char *); unsigned char *line_entry(int,unsigned char *); int msg_log(unsigned char *); void send_mx(unsigned char *); /* Global variables */ db_t *dbase=NULL; int wait_for_all=1; int wait_timer=0; /* Log function */ int msg_log(unsigned char *msg) { FILE *fp; time_t tt; unsigned char buff[256]; fp=fopen(DHISE_LOG,"a"); while(fp==NULL) { sleep(1); fp=fopen(DHISE_LOG,"a"); } tt=time(NULL); strcpy(buff,ctime(&tt)); off_nl(buff); strcat(buff," : "); strcat(buff,msg); strcat(buff,"\n"); fputs(buff,fp); fclose(fp); return(1); } /* Misc functions */ void strtolower(unsigned char *s) { while(*s!='\0') { *s=tolower(*s); s++; } } void off_nl(unsigned char *s) { while(*s!='\0' && *s!='\n' && *s!='\r') s++; *s='\0'; return; } unsigned char *line_entry(int idx,unsigned char *buff) { static unsigned char b2[1024],*pb2; int i; idx--; b2[0]='\0'; pb2=b2; while((*buff==' ' || *buff=='\t') && *buff!='\0' && *buff!='\n') buff++; if(*buff=='\0' || *buff=='\n') return(b2); for(i=0;iid=atoi(line_entry(1,str)); rec->fqdn[0]='\0'; do { if(fgets(str,1024,fp)==NULL) { fclose(fp);free(rec);return(0);} off_nl(str); strcpy(keyword,line_entry(1,str)); strtolower(keyword); if(!strcmp(keyword,"hostname")) strcpy(rec->fqdn,line_entry(2,str)); } while(strcmp(line_entry(1,str),"}")); if(rec->fqdn[0]=='\0') continue; db_add(rec); } } fclose(fp); return(1); } int db_free() { db_t *p1,*p2; if(dbase==NULL) return(1); p1=dbase; while(p1!=NULL) { p2=p1; p1=p1->next; free(p2); } dbase=NULL; return(1); } unsigned char *db_hostname(int id) { db_t *p1; static unsigned char host[MAX_HOSTNAME]; p1=dbase; while(p1!=NULL) { if(p1->id==id) { strcpy(host,p1->fqdn); return(host); } p1=p1->next; } return(NULL); } int db_add(db_t *rec) { db_t *p; p=dbase; if(dbase==NULL) { dbase=rec; dbase->next=NULL; return(1); } while(p->next!=NULL) p=p->next; p->next=rec; p->next->next=NULL; return(1); } void send_mx(unsigned char *fqdn) { unsigned char str[1024]; if(wait_for_all) { if(time(NULL) < wait_timer) return; wait_for_all=0; } sprintf(str,"-> relay %s",fqdn); msg_log(str); #ifdef BSD sigsetmask(sigmask(SIGCHLD) | SA_NOCLDWAIT); #else signal(SIGCHLD,SIG_IGN); /* Let us not create zombies */ #endif sprintf(str,"-qR%s",fqdn); if(!fork()) { close(0); close(1); close(2); db_free(); sleep(10); /* wait for dns update */ execlp(SENDMAIL,"sendmail",str,NULL); exit(0); } } int main() { unsigned char line[1024]; db_reload(); sprintf(line,"-> DHIS Relay Engine Starting"); msg_log(line); wait_timer=(int)time(NULL)+300; /* Wait for all hosts to become online so we don't fork hundreds of processes */ while(fgets(line,1024,stdin)!=NULL) { off_nl(line); if(!strcmp(line_entry(1,line),"exit")) { db_free(); exit(0); } if(!strcmp(line_entry(1,line),"reload")) { db_reload(); continue; } if(!strcmp(line_entry(1,line),"add")) { int id; id=atoi(line_entry(3,line)); send_mx(db_hostname(id)); continue; } if(!strcmp(line_entry(1,line),"update")) { int id; id=atoi(line_entry(3,line)); send_mx(db_hostname(id)); continue; } if(!strcmp(line_entry(1,line),"delete")) { continue; } } return(0); /* Just to keep -Wall quiet */ }