[openbnc-cvs] openbnc/src openbnc.c,1.10,1.11 snprintf.c,1.2,1.3
Status: Beta
Brought to you by:
andrereis
From: Kiraly Z. <yo...@us...> - 2004-07-13 21:41:42
|
Update of /cvsroot/openbnc/openbnc/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19629/openbnc/src Modified Files: openbnc.c snprintf.c Log Message: Added support for *BSD Index: snprintf.c =================================================================== RCS file: /cvsroot/openbnc/openbnc/src/snprintf.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- snprintf.c 4 Jun 2004 16:26:39 -0000 1.2 +++ snprintf.c 13 Jul 2004 21:41:32 -0000 1.3 @@ -1,1178 +1,1178 @@ -/* -OpenBNC Advanced IRC Bouncer -Copyright (C) 2004 The OpenBNC Development Team - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of [...2325 lines suppressed...] + return (cc == -1) ? len : cc; +} + + +int ap_vsnprintf(char *buf, size_t len, const char *format, + va_list ap) +{ + int cc; + ap_vformatter_buff vbuff; + + if (len == 0) + return 0; + + /* save one byte for nul terminator */ + vbuff.curpos = buf; + vbuff.endpos = buf + len - 1; + cc = ap_vformatter(snprintf_flush, &vbuff, format, ap); + *vbuff.curpos = '\0'; + return (cc == -1) ? len : cc; +} Index: openbnc.c =================================================================== RCS file: /cvsroot/openbnc/openbnc/src/openbnc.c,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- openbnc.c 7 Jul 2004 10:30:30 -0000 1.10 +++ openbnc.c 13 Jul 2004 21:41:32 -0000 1.11 @@ -1,155 +1,155 @@ -/* -OpenBNC Advanced IRC Bouncer -Copyright (C) 2004 The OpenBNC Development Team - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -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, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -The original version of this program was developed by 'the most psychoid -and the cool lam3rz IRC Group'. - -The original copyright preamble follows: - - ************************************************************************ - * psybnc2.3.1, src/psybnc.c - * Copyright (C) 2002 the most psychoid and - * the cool lam3rz IRC Group, IRCnet - * http://www.psychoid.lam3rz.de - * - * .-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-. - * ,----.,----.,-. ,-.,---.,--. ,-.,----. - * | O || ,-' \ \/ / | o || \| || ,--' - * | _/ _\ \ \ / | o< | |\ || |__ - * |_| |____/ |__| |___||_| \_| \___| - * Version 2.3.1 (c) 1999-2002 - * the most psychoid - * and the cool lam3rz Group IRCnet - * - * `-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=tCl=-' - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 1, or (at your option) - * any later version. - * - * 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, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - -*/ - -#ifndef lint -static char rcsid[] = "@(#)$Id$"; -#endif - -#define P_MAIN - -#include <p_global.h> -#include <p_data.h> +/* +OpenBNC Advanced IRC Bouncer +Copyright (C) 2004 The OpenBNC Development Team + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +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, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +The original version of this program was developed by 'the most psychoid +and the cool lam3rz IRC Group'. + +The original copyright preamble follows: + + ************************************************************************ + * psybnc2.3.1, src/psybnc.c + * Copyright (C) 2002 the most psychoid and + * the cool lam3rz IRC Group, IRCnet + * http://www.psychoid.lam3rz.de + * + * .-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-. + * ,----.,----.,-. ,-.,---.,--. ,-.,----. + * | O || ,-' \ \/ / | o || \| || ,--' + * | _/ _\ \ \ / | o< | |\ || |__ + * |_| |____/ |__| |___||_| \_| \___| + * Version 2.3.1 (c) 1999-2002 + * the most psychoid + * and the cool lam3rz Group IRCnet + * + * `-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=tCl=-' + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 1, or (at your option) + * any later version. + * + * 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, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + +*/ + +#ifndef lint +static char rcsid[] = "@(#)$Id$"; +#endif + +#define P_MAIN + +#include <p_global.h> +#include <p_data.h> #include <sys/types.h> #include <unistd.h> #include <pwd.h> #include <grp.h> - -int slice=0; - -#ifdef HAVE_SSL - -void initSSL() -{ - SSL_load_error_strings(); - OpenSSL_add_ssl_algorithms(); - srvctx=SSL_CTX_new(SSLv23_server_method()); - /* setting up the server context */ - if(srvctx==NULL) - { - log(LOG_ERROR,-1,lngtxt(970)); - exit(0x1); - } - if (SSL_CTX_use_certificate_file(srvctx, SSLCERT, SSL_FILETYPE_PEM) <= 0) - { - log(LOG_ERROR,-1,lngtxt(971), SSLCERT); - exit(0x1); - } - if (SSL_CTX_use_PrivateKey_file(srvctx, SSLKEY, SSL_FILETYPE_PEM) <= 0) - { - log(LOG_ERROR,-1,lngtxt(972), SSLKEY); - exit(0x1); - } - if (!SSL_CTX_check_private_key(srvctx)) - { - log(LOG_ERROR,-1,lngtxt(973)); - exit(0x1); - } - /* create client context */ - clnctx=SSL_CTX_new(SSLv23_client_method()); - if(clnctx==NULL) - { - log(LOG_ERROR,-1,lngtxt(974)); - exit(0x1); - } - if (SSL_CTX_use_certificate_file(clnctx, SSLCERT, SSL_FILETYPE_PEM) <= 0) - { - log(LOG_ERROR,-1,lngtxt(975), SSLCERT); - exit(3); - } - if (SSL_CTX_use_PrivateKey_file(clnctx, SSLKEY, SSL_FILETYPE_PEM) <= 0) - { - log(LOG_ERROR,-1,lngtxt(976), SSLKEY); - exit(4); - } - if (!SSL_CTX_check_private_key(clnctx)) - { - log(LOG_ERROR,-1,lngtxt(977)); - exit(5); - } - log(LOG_INFO,-1,lngtxt(978)); - return; -} - -#endif - -/* alarm-loop */ - -int bncalarm(void) -{ - slice++; - delayinc=1; - if(slice==1) - checkclients(); - else - if(slice==2) - checklinks(); - else - if(slice==3) - { - checkdccs(); -#ifdef TRANSLATE - cleartranslates(); -#endif - checkdcctimeouts(); - slice=0; - } - return; -} - + +int slice=0; + +#ifdef HAVE_SSL + +void initSSL() +{ + SSL_load_error_strings(); + OpenSSL_add_ssl_algorithms(); + srvctx=SSL_CTX_new(SSLv23_server_method()); + /* setting up the server context */ + if(srvctx==NULL) + { + log(LOG_ERROR,-1,lngtxt(970)); + exit(0x1); + } + if (SSL_CTX_use_certificate_file(srvctx, SSLCERT, SSL_FILETYPE_PEM) <= 0) + { + log(LOG_ERROR,-1,lngtxt(971), SSLCERT); + exit(0x1); + } + if (SSL_CTX_use_PrivateKey_file(srvctx, SSLKEY, SSL_FILETYPE_PEM) <= 0) + { + log(LOG_ERROR,-1,lngtxt(972), SSLKEY); + exit(0x1); + } + if (!SSL_CTX_check_private_key(srvctx)) + { + log(LOG_ERROR,-1,lngtxt(973)); + exit(0x1); + } + /* create client context */ + clnctx=SSL_CTX_new(SSLv23_client_method()); + if(clnctx==NULL) + { + log(LOG_ERROR,-1,lngtxt(974)); + exit(0x1); + } + if (SSL_CTX_use_certificate_file(clnctx, SSLCERT, SSL_FILETYPE_PEM) <= 0) + { + log(LOG_ERROR,-1,lngtxt(975), SSLCERT); + exit(3); + } + if (SSL_CTX_use_PrivateKey_file(clnctx, SSLKEY, SSL_FILETYPE_PEM) <= 0) + { + log(LOG_ERROR,-1,lngtxt(976), SSLKEY); + exit(4); + } + if (!SSL_CTX_check_private_key(clnctx)) + { + log(LOG_ERROR,-1,lngtxt(977)); + exit(5); + } + log(LOG_INFO,-1,lngtxt(978)); + return; +} + +#endif + +/* alarm-loop */ + +int bncalarm(void) +{ + slice++; + delayinc=1; + if(slice==1) + checkclients(); + else + if(slice==2) + checklinks(); + else + if(slice==3) + { + checkdccs(); +#ifdef TRANSLATE + cleartranslates(); +#endif + checkdcctimeouts(); + slice=0; + } + return; +} + int user_uid(char user[255]) { @@ -180,63 +180,63 @@ } -/* main bounce-loop */ - -int bncmain(void) { - unsigned long em=0; - delayinc=1; - while(1) - { - em+=socketdriver(); - if(em>=5) - { - em=0; - bncalarm(); - } - checkstonednick(); - } - return 0x0; /* i wonder how often we get here */ -} - -/* printing the banner */ - -int printbanner(void) -{ -/* int i; - for(i=979;i<990;i++) - { - fprintf(stdout,"%s",lngtxt(i)); - if(i==984) - fprintf(stdout,"%s", APPVER); - } - if(getuid()==0) - fprintf(stdout,lngtxt(990)); - fflush(stdout); +/* main bounce-loop */ + +int bncmain(void) { + unsigned long em=0; + delayinc=1; + while(1) + { + em+=socketdriver(); + if(em>=5) + { + em=0; + bncalarm(); + } + checkstonednick(); + } + return 0x0; /* i wonder how often we get here */ +} + +/* printing the banner */ + +int printbanner(void) +{ +/* int i; + for(i=979;i<990;i++) + { + fprintf(stdout,"%s",lngtxt(i)); + if(i==984) + fprintf(stdout,"%s", APPVER); + } + if(getuid()==0) + fprintf(stdout,lngtxt(990)); + fflush(stdout); */ printf("OpenIRC Advanced IRC Bouncer\n"); printf("Copyright (C) 2004 The OpenBNC Development Team\n"); printf("Based on psyBNC, by 'the most psychoid'.\n"); - return 0x0; -} - -/* installation loop */ - -int -main (int argc, char **argv) -{ - int rc; - char *pt; - char buf[200],t_pid[200]; - char *bversion; - FILE *pidfile,*conffile; - int i,t_uid,t_gid=0; -/* if(argc>1) - { - strmncpy(configfile,argv[1],sizeof(configfile)); - } else { - strcpy(configfile,"openbnc.conf"); + return 0x0; +} + +/* installation loop */ + +int +main (int argc, char **argv) +{ + int rc; + char *pt; + char buf[200],t_pid[200]; + char *bversion; + FILE *pidfile,*conffile; + int i,t_uid,t_gid=0; +/* if(argc>1) + { + strmncpy(configfile,argv[1],sizeof(configfile)); + } else { + strcpy(configfile,"openbnc.conf"); } */ @@ -365,70 +365,70 @@ - conffile=fopen(configfile,"r"); - if(conffile==NULL) - { - printf("Configuration File %s not found, aborting\nRun 'make menuconfig' for creating a configuration or create the file manually.\n",conffile); /* rcsid */ - exit (0x0); - } - fclose(conffile); - readconfig(); - rc = getini("SYSTEM","LANGUAGE",INIFILE); /* rcsid */ - if(rc!=0) - { - rc=loadlanguage("english"); /* rcsid */ - } else { - rc=loadlanguage(value); - if(rc<0) - rc=loadlanguage("english"); /* rcsid */ - } - if(rc<0) - { - printf("Could not load language file, aborting.\n"); /* rcsid */ - exit(0x0); - } - printbanner(); - // printf(lngtxt(991),configfile); + conffile=fopen(configfile,"r"); + if(conffile==NULL) + { + printf("Configuration File %s not found, aborting\nRun 'make menuconfig' for creating a configuration or create the file manually.\n",conffile); /* rcsid */ + exit (0x0); + } + fclose(conffile); + readconfig(); + rc = getini("SYSTEM","LANGUAGE",INIFILE); /* rcsid */ + if(rc!=0) + { + rc=loadlanguage("english"); /* rcsid */ + } else { + rc=loadlanguage(value); + if(rc<0) + rc=loadlanguage("english"); /* rcsid */ + } + if(rc<0) + { + printf("Could not load language file, aborting.\n"); /* rcsid */ + exit(0x0); + } + printbanner(); + // printf(lngtxt(991),configfile); if ( configfile[0] != '/' ) { - printf("> Reading config file : %s/%s\n",get_current_dir_name(),configfile); + printf("> Reading config file : %s/%s\n",configfile); } else { printf("> Reading config file : %s\n",configfile); } - // printf(lngtxt(992),langname); - // ap_snprintf(logfile,sizeof(logfile),lngtxt(993)); - printf("> Logging set to : %s/%s",get_current_dir_name(),logfile); - rc = getini(lngtxt(994),lngtxt(995),INIFILE); - if (rc != 0) { - printf(lngtxt(996)); - exit (0x0); - } - listenport = atoi(value); - rc = getini(lngtxt(997),"ME",INIFILE); - if (rc < 0) { - memset(value,0x0,sizeof(value)); - } - pt=strchr(value,' '); /* shortening bouncername to no spaces */ - if(pt) - *pt=0; - ap_snprintf(me,sizeof(me),"%s",value); - rc = getini(lngtxt(998),lngtxt(999),INIFILE); - if (rc < 0) { - printf("%s \n",lngtxt(1001)); - // ap_snprintf(value,sizeof(value),lngtxt(1001)); - } - ap_snprintf(logfile,sizeof(logfile),"%s",value); - oldfile(logfile); - /* creating the socket-root */ - socketnode=(struct socketnodes *) pmalloc(sizeof(struct usernodes)); - socketnode->sock=NULL; - socketnode->next=NULL; - /* creating the demon socket */ - rc = createlisteners(); - if (rc == 0) { - printf(lngtxt(1002)); - exit (0x0); - } - /* creating background */ + // printf(lngtxt(992),langname); + // ap_snprintf(logfile,sizeof(logfile),lngtxt(993)); + printf("> Logging set to : %s/%s",logfile); + rc = getini(lngtxt(994),lngtxt(995),INIFILE); + if (rc != 0) { + printf(lngtxt(996)); + exit (0x0); + } + listenport = atoi(value); + rc = getini(lngtxt(997),"ME",INIFILE); + if (rc < 0) { + memset(value,0x0,sizeof(value)); + } + pt=strchr(value,' '); /* shortening bouncername to no spaces */ + if(pt) + *pt=0; + ap_snprintf(me,sizeof(me),"%s",value); + rc = getini(lngtxt(998),lngtxt(999),INIFILE); + if (rc < 0) { + printf("%s \n",lngtxt(1001)); + // ap_snprintf(value,sizeof(value),lngtxt(1001)); + } + ap_snprintf(logfile,sizeof(logfile),"%s",value); + oldfile(logfile); + /* creating the socket-root */ + socketnode=(struct socketnodes *) pmalloc(sizeof(struct usernodes)); + socketnode->sock=NULL; + socketnode->next=NULL; + /* creating the demon socket */ + rc = createlisteners(); + if (rc == 0) { + printf(lngtxt(1002)); + exit (0x0); + } + /* creating background */ /* UGLY! */ if ( strlen(t_pid) > 0 ) { @@ -438,72 +438,71 @@ pidfile = fopen(lngtxt(1003),"w"); } - if(pidfile==NULL) - { - printf(lngtxt(1004)); - exit(0x0); - } - if(mainlog!=NULL) - { - fclose(mainlog); - mainlog=NULL; - } - fflush(stdout); - pid = fork(); - if (pid < 0) { - - } - if (pid == 0) { - rc= errorhandling(); - makesalt(); -#ifdef HAVE_SSL - initSSL(); - pcontext; -#endif - U_CREATE=0; -#ifdef PARTYCHANNEL - /* partychannel setup */ - strcpy(partytopic,lngtxt(1005)); - partyusers=NULL; -#endif - /* creating the usernode-root */ - usernode=(struct usernodes *) pmalloc(sizeof(struct usernodes)); - usernode->uid=0; - usernode->user=NULL; - usernode->next=NULL; - /* creating the newpeer-root */ - peernode=(struct peernodes *) pmalloc(sizeof(struct peernodes)); - peernode->uid=0; - peernode->peer=NULL; - peernode->next=NULL; - /* creating the datalink-root */ - linknode=(struct linknodes *) pmalloc(sizeof(struct linknodes)); - linknode->uid=0; - linknode->link=NULL; - linknode->next=NULL; - /* loading the users */ - loadusers(); - loadlinks(); - pcontext; - /* loading the hostallows */ - hostallows=loadlist(lngtxt(1006),hostallows); - } - pcontext; - if (pid) { - // bversion=buildversion(); - printf("%s v%s is running (PID=%i, UID=%i, GID=%i)\n",APPNAME,APPVER,pid,getuid(),getgid()); - log(LOG_INFO,-1,lngtxt(1008),bversion,pid); - fprintf( pidfile,"%d\n",pid); - fclose(pidfile); - exit (0x0); - } - pcontext; -#ifndef BLOCKDNS - if(init_dns_core()==0) - { - dns_err(0,1); - } -#endif - bncmain(); -} - + if(pidfile==NULL) + { + printf(lngtxt(1004)); + exit(0x0); + } + if(mainlog!=NULL) + { + fclose(mainlog); + mainlog=NULL; + } + fflush(stdout); + pid = fork(); + if (pid < 0) { + + } + if (pid == 0) { + rc= errorhandling(); + makesalt(); +#ifdef HAVE_SSL + initSSL(); + pcontext; +#endif + U_CREATE=0; +#ifdef PARTYCHANNEL + /* partychannel setup */ + strcpy(partytopic,lngtxt(1005)); + partyusers=NULL; +#endif + /* creating the usernode-root */ + usernode=(struct usernodes *) pmalloc(sizeof(struct usernodes)); + usernode->uid=0; + usernode->user=NULL; + usernode->next=NULL; + /* creating the newpeer-root */ + peernode=(struct peernodes *) pmalloc(sizeof(struct peernodes)); + peernode->uid=0; + peernode->peer=NULL; + peernode->next=NULL; + /* creating the datalink-root */ + linknode=(struct linknodes *) pmalloc(sizeof(struct linknodes)); + linknode->uid=0; + linknode->link=NULL; + linknode->next=NULL; + /* loading the users */ + loadusers(); + loadlinks(); + pcontext; + /* loading the hostallows */ + hostallows=loadlist(lngtxt(1006),hostallows); + } + pcontext; + if (pid) { + // bversion=buildversion(); + printf("%s v%s is running (PID=%i, UID=%i, GID=%i)\n",APPNAME,APPVER,pid,getuid(),getgid()); + log(LOG_INFO,-1,lngtxt(1008),bversion,pid); + fprintf( pidfile,"%d\n",pid); + fclose(pidfile); + exit (0x0); + } + pcontext; +#ifndef BLOCKDNS + if(init_dns_core()==0) + { + dns_err(0,1); + } +#endif + bncmain(); +} |