a5843cd140
- Transparent IRC proxy. Supports DCC CHAT, SEND, RESEND, and TSEND.
279 lines
7.8 KiB
Plaintext
279 lines
7.8 KiB
Plaintext
--- tircproxy.c.orig Wed Dec 30 20:23:13 1998
|
|
+++ tircproxy.c Sun Jun 20 20:15:26 1999
|
|
@@ -107,7 +107,7 @@
|
|
# include <net/if.h>
|
|
# include <netinet/in_systm.h>
|
|
# include <netinet/tcp.h>
|
|
-# include <netinet/ip_compat.h>
|
|
+# include <netinet/ip_fil_compat.h>
|
|
# include <netinet/ip_fil.h>
|
|
# include <netinet/ip_proxy.h>
|
|
# include <netinet/ip_nat.h>
|
|
@@ -164,7 +164,7 @@
|
|
/* Macros & definitions.
|
|
*/
|
|
#define FD_MAX(a,b) ((a) > (b) ? (a) : (b))
|
|
-#define MIN 60
|
|
+#define MINUTE 60
|
|
|
|
#define DEBUG_FEATURES 1
|
|
#define DEBUG_BASIC 2
|
|
@@ -227,8 +227,8 @@
|
|
|
|
/* These make useful global variables..
|
|
*/
|
|
-char user_nick[LENGTH_NICKNAME * 2], user_name[512], alarm_in[64];
|
|
-char user_ident_file[64];
|
|
+char user_nick[LENGTH_NICKNAME * 2], user_name[MAXLOGNAME], alarm_in[64];
|
|
+char user_ident_file[PATH_MAX];
|
|
char server_tag[50];
|
|
ipaddr_t clients_ip = INADDR_NONE;
|
|
char clients_ip_s[64];
|
|
@@ -256,7 +256,7 @@
|
|
char **from_cli_last = NULL;
|
|
char *to_cli_first = NULL;
|
|
char **to_cli_last = NULL;
|
|
-char quizfile[64], quiz[512];
|
|
+char quizfile[PATH_MAX], quiz[512];
|
|
int use_unix_passwd = QUIZ_OFF;
|
|
int use_quiz_mode = QUIZ_OFF;
|
|
#endif
|
|
@@ -353,7 +353,7 @@
|
|
case 'q':
|
|
#ifdef QUIZ_MODE
|
|
use_quiz_mode = QUIZ_ON;
|
|
- sprintf(quizfile, "%.63s", optarg);
|
|
+ snprintf(quizfile, sizeof(quizfile), "%.63s", optarg);
|
|
#else
|
|
usage(argv[0],"Feature QUIZ_MODE not active.");
|
|
#endif
|
|
@@ -482,9 +482,9 @@
|
|
** loops, while allowing proxy-to-proxy operation.
|
|
*/
|
|
{
|
|
- char hostname[128];
|
|
- gethostname(hostname, 127);
|
|
- sprintf(server_tag,"X-tircproxy[%d/%.10s]\n",
|
|
+ char hostname[MAXHOSTNAMELEN];
|
|
+ gethostname(hostname, sizeof(hostname));
|
|
+ snprintf(server_tag, sizeof(server_tag), "X-tircproxy[%d/%.10s]\n",
|
|
getpid(), hostname );
|
|
}
|
|
|
|
@@ -1027,13 +1027,9 @@
|
|
/* Give this thing 10 minutes to get started (paranoia).
|
|
*/
|
|
signal(SIGALRM, alarm_signal);
|
|
- alarm(10*MIN);
|
|
+ alarm(10*MINUTE);
|
|
strcpy(alarm_in, "trans_proxy");
|
|
|
|
- /* Check who the client is, and drop root privs if we have them.
|
|
- */
|
|
- change_uid(from_addr);
|
|
-
|
|
#ifdef TCP_WRAPPERS
|
|
if (use_tcp_wrappers)
|
|
{
|
|
@@ -1132,6 +1128,10 @@
|
|
to_addr.sin_addr.s_addr = server_ip;
|
|
}
|
|
|
|
+ /* Check who the client is, and drop root privs if we have them.
|
|
+ */
|
|
+ change_uid(from_addr);
|
|
+
|
|
signal(SIGHUP, hup_signal);
|
|
|
|
debug_msg(0, LOG_DEBUG,
|
|
@@ -1171,7 +1171,7 @@
|
|
/* Allow 3 minutes for things to get properly started.
|
|
*/
|
|
signal(SIGALRM, alarm_signal);
|
|
- alarm(3*MIN);
|
|
+ alarm(3*MINUTE);
|
|
strcpy(alarm_in, "copy_loop: starting");
|
|
|
|
/* Lookup an ASCII representation of the host's IP address.
|
|
@@ -1268,7 +1268,7 @@
|
|
/* Allow 30 minutes for the loop to complete.
|
|
*/
|
|
signal(SIGALRM, alarm_signal);
|
|
- alarm(30*MIN);
|
|
+ alarm(30*MINUTE);
|
|
strcpy(alarm_in, "copy_loop: waiting");
|
|
#ifdef DEBUG
|
|
debug_msg(DEBUG_TRIVIA, LOG_DEBUG,"copy_loop: waiting");
|
|
@@ -1573,7 +1573,7 @@
|
|
{
|
|
if (!allow_dcc_chat)
|
|
#ifdef DISALLOW_DCC_CHAT
|
|
- sprintf(replace,
|
|
+ snprintf(replace, sizeof(replace),
|
|
DISALLOW_DCC_CHAT,
|
|
type, arg_1);
|
|
#else
|
|
@@ -1587,7 +1587,7 @@
|
|
{
|
|
if (!allow_dcc_send)
|
|
#ifdef DISALLOW_DCC_SEND
|
|
- sprintf(replace,
|
|
+ snprintf(replace, sizeof(replace),
|
|
DISALLOW_DCC_SEND,
|
|
type, arg_1);
|
|
#else
|
|
@@ -1595,7 +1595,7 @@
|
|
#endif
|
|
else if (!dcc_mangle_filename(arg_1))
|
|
#ifdef MANGLE_DCC_SEND
|
|
- sprintf(replace,
|
|
+ snprintf(replace, sizeof(replace),
|
|
MANGLE_DCC_SEND,
|
|
type, arg_1);
|
|
#else
|
|
@@ -1604,7 +1604,7 @@
|
|
}
|
|
else if (!strcasecmp(type, "RESUME"))
|
|
{
|
|
- sprintf(replace,
|
|
+ snprintf(replace, sizeof(replace),
|
|
"%cDCC %s %s %d %d%s%c",
|
|
CTRL_A,
|
|
type, arg_1,
|
|
@@ -1613,7 +1613,7 @@
|
|
}
|
|
else if (!strcasecmp(type, "ACCEPT"))
|
|
{
|
|
- sprintf(replace,
|
|
+ snprintf(replace, sizeof(replace),
|
|
"%cDCC %s %s %d %d%s%c",
|
|
CTRL_A,
|
|
type, arg_1,
|
|
@@ -1624,7 +1624,7 @@
|
|
*/
|
|
else if (!allow_dcc_unknown)
|
|
#ifdef DISALLOW_DCC_SEND
|
|
- sprintf(replace,
|
|
+ snprintf(replace, sizeof(replace),
|
|
DISALLOW_DCC_FUNK,
|
|
type, arg_1);
|
|
#else
|
|
@@ -1636,7 +1636,7 @@
|
|
/* No replacement has been set, so
|
|
** proxy this connection. :-)
|
|
*/
|
|
- sprintf(replace,
|
|
+ snprintf(replace, sizeof(replace),
|
|
"%c%s %s %s %s%s%c",
|
|
CTRL_A, ctcp_type,
|
|
type, arg_1,
|
|
@@ -1730,7 +1730,7 @@
|
|
else if (!strncasecmp(line, "USER", 4))
|
|
{
|
|
int cip = ANON_USERID;
|
|
- sprintf(line, "USER t%x anon anon :%s\n", cip, ANON_IRCNAME);
|
|
+ snprintf(line, sizeof(line), "USER t%x anon anon :%s\n", cip, ANON_IRCNAME);
|
|
}
|
|
}
|
|
else if (!strncasecmp(line, "NOTICE", 6)) /* Fix mIRC junk */
|
|
@@ -1782,9 +1782,9 @@
|
|
*/
|
|
case 1: quiz_delay_line(line, QUIZ_S);
|
|
fuid = getpid() * visible_ip_o;
|
|
- sprintf(user_nick, "}%x", fuid);
|
|
- sprintf(line, "NICK :%s\n", user_nick);
|
|
- sprintf(out, ":%.32s %.256s", r, line);
|
|
+ snprintf(user_nick, sizeof(user_nick), "}%x", fuid);
|
|
+ snprintf(line, sizeof(line), "NICK :%s\n", user_nick);
|
|
+ snprintf(out, sizeof(out), ":%.32s %.256s", r, line);
|
|
quiz_delay_line(out, QUIZ_C);
|
|
quiz_greet();
|
|
|
|
@@ -2007,7 +2007,7 @@
|
|
sprintf(retvalue,"%lu %u",
|
|
(unsigned long int) ntohl(vip), ntohs(to_addr.sin_port));
|
|
#else
|
|
- sprintf(retvalue,"%u %u",
|
|
+ snprintf(retvalue, sizeof(retvalue), "%u %u",
|
|
(unsigned int) ntohl(vip), ntohs(to_addr.sin_port));
|
|
#endif
|
|
return(retvalue);
|
|
@@ -2016,7 +2016,7 @@
|
|
/* Give people five minutes to accept the call..
|
|
*/
|
|
signal(SIGALRM, alarm_signal);
|
|
- alarm(5*MIN);
|
|
+ alarm(5*MINUTE);
|
|
strcpy(alarm_in,"proxy_dcc: accept");
|
|
|
|
/* No silly broadcasts shall mess up our DCC stuff!
|
|
@@ -2075,17 +2075,17 @@
|
|
#ifdef IP_TO_UID_PREFIX
|
|
int fd;
|
|
int tries;
|
|
- char ipfile[512];
|
|
+ char ipfile[PATH_MAX];
|
|
char *cp;
|
|
struct passwd *pw;
|
|
|
|
#ifdef CDIR
|
|
if (use_cdir)
|
|
- sprintf(ipfile, "%s%s-%s", CDIR, CDIR_MAP,
|
|
+ snprintf(ipfile, sizeof(ipfile), "%s%s-%s", CDIR, CDIR_MAP,
|
|
inet_ntoa(addr->sin_addr));
|
|
else
|
|
#endif
|
|
- sprintf(ipfile, "%s%s", IP_TO_UID_PREFIX,
|
|
+ snprintf(ipfile, sizeof(ipfile), "%s%s", IP_TO_UID_PREFIX,
|
|
inet_ntoa(addr->sin_addr));
|
|
|
|
/* Repeat until whe lose the ident race.. :-)
|
|
@@ -2154,7 +2154,7 @@
|
|
*/
|
|
if ((!*user_name) && (!use_anonymity)) return;
|
|
|
|
- sprintf(user_ident_file, "%s%s:%d-%s:%d", CDIR, CDIR_IDENT,
|
|
+ snprintf(user_ident_file, sizeof(user_ident_file), "%s%s:%d-%s:%d", CDIR, CDIR_IDENT,
|
|
ntohs(us->sin_port),
|
|
inet_ntoa(them->sin_addr),
|
|
ntohs(them->sin_port));
|
|
@@ -2172,7 +2172,7 @@
|
|
{
|
|
int cip = ANON_USERID;
|
|
|
|
- sprintf(fakeid, "t%x", cip);
|
|
+ snprintf(fakeid, sizeof(fakeid), "t%x", cip);
|
|
debug_msg(0, LOG_INFO, "Anonymized connection as %s", fakeid);
|
|
|
|
u = fakeid;
|
|
@@ -2451,7 +2451,7 @@
|
|
{
|
|
char out[512];
|
|
|
|
- sprintf(out,":%.32s!irc@proxy PRIVMSG %.32s :%.256s\n",
|
|
+ snprintf(out, sizeof(out), ":%.32s!irc@proxy PRIVMSG %.32s :%.256s\n",
|
|
QUIZ_NICK, user_nick, message);
|
|
|
|
quiz_delay_line(out, QUIZ_C);
|
|
@@ -2461,8 +2461,8 @@
|
|
*/
|
|
static void quiz_greet(void)
|
|
{
|
|
- FILE *fd;
|
|
- int i, r;
|
|
+ FILE *fd;
|
|
+ int i, r, d;
|
|
char question[512], buff[512], *p;
|
|
|
|
if (use_unix_passwd)
|
|
@@ -2475,7 +2475,8 @@
|
|
|
|
srand(time((time_t) NULL));
|
|
|
|
- if ((fd = fopen(quizfile,"r")) == NULL)
|
|
+ d = open(quizfile, O_RDONLY|O_CREAT|O_EXCL, 0400);
|
|
+ if ((fd = fdopen(d,"r")) == NULL)
|
|
{
|
|
debug_msg(0, LOG_DEBUG,
|
|
"Error (%.128s) reading quiz-file: %.128s",
|