fp = fopen("./network/filterlist", "r");
if (fp == NULL)
return;
- while (fgets(sbuf, 256, fp) != NULL) {
+ while (fgets(sbuf, sizeof sbuf, fp) != NULL) {
if (sbuf[0] != '#') {
sbuf[strlen(sbuf) - 1] = 0;
fbuf = (struct filterlist *)
}
-void fpgetfield(FILE * fp, char *string)
+void fpgetfield(FILE *fp, char *string, int limit)
{
int a, b;
a = 0;
do {
b = getc(fp);
- if (b < 1) {
+ if ((b < 1) || (a >= limit)) {
string[a] = 0;
return;
}
goto END;
if (b == 'M')
goto END;
- fpgetfield(fp, bbb);
+ fpgetfield(fp, bbb, sizeof bbb);
while ((bbb[0] == ' ') && (strlen(bbb) > 1))
strcpy(bbb, &bbb[1]);
if (b == 'A') {
do {
a = getc(tfp);
if (a != 'M') {
- fpgetfield(tfp, buf);
+ fpgetfield(tfp, buf, sizeof buf);
if (a == 'O') {
strcpy(dest_room, buf);
}
int valid_msg;
/* temp file names */
- strcpy(tname, tmpnam(NULL));
- strcpy(iname, tmpnam(NULL));
+ sprintf(tname, "%s.netproc.%d", tmpnam(NULL), __LINE__);
+ sprintf(iname, "%s.netproc.%d", tmpnam(NULL), __LINE__);
load_filterlist();
getc(mmfp);
while (a = getc(mmfp), ((a != 'M') && (a != 0))) {
- fpgetfield(mmfp, fbuf);
+ fpgetfield(mmfp, fbuf, sizeof fbuf);
if (a == 'P') {
ok = checkpath(fbuf, sysname);
}
{
struct msglist *cmptr;
FILE *mmfp;
- char fbuf[128];
+ char fbuf[1024];
int a;
int msgs_spooled = 0;
long msg_len;
}
/* download the message from the server... */
mmfp = tmpfile();
+ if (mmfp == NULL) {
+ syslog(LOG_NOTICE, "tmpfile() failed: %s\n",
+ strerror(errno) );
+ }
sprintf(buf, "MSG3 %ld", cmptr->m_num);
serv_puts(buf);
serv_gets(buf);
fread(fbuf, 3, 1, mmfp);
fwrite(fbuf, 3, 1, destfp);
while (a = getc(mmfp), ((a != 0) && (a != 'M'))) {
- if (a != 'C')
+ if (a != 'C') {
putc(a, destfp);
- fpgetfield(mmfp, fbuf);
- if (a == 'P')
+ }
+ fpgetfield(mmfp, fbuf, sizeof fbuf);
+ if (a == 'P') {
fprintf(destfp, "%s!", NODENAME);
- if (a != 'C')
+ }
+ if (a != 'C') {
fwrite(fbuf, strlen(fbuf) + 1, 1, destfp);
+ }
if (a == 'S') if (!strcasecmp(fbuf, "CANCEL")) {
delete_locally(cmptr->m_num, cmptr->m_rmname);
}
char tempflnm[64];
char buf[256];
struct msglist *cmlist = NULL;
+ struct msglist *cmlast = NULL;
struct rmlist *crmlist = NULL;
struct rmlist *rmptr, *rmptr2;
- struct msglist *cmptr, *cmptr2;
+ struct msglist *cmptr;
FILE *sysflfp, *tempflfp;
- int outgoing_msgs;
+ int outgoing_msgs = 0;
long thismsg;
- strcpy(tempflnm, tmpnam(NULL));
+ sprintf(tempflnm, "%s.netproc.%d", tmpnam(NULL), __LINE__);
tempflfp = fopen(tempflnm, "w");
if (tempflfp == NULL)
return;
cmptr->m_num = thismsg;
strcpy(cmptr->m_rmname, rmptr->rm_name);
- if (cmlist == NULL)
+ if (cmlist == NULL) {
cmlist = cmptr;
+ }
else {
- cmptr2 = cmlist;
- while (cmptr2->next != NULL)
- cmptr2 = cmptr2->next;
- cmptr2->next = cmptr;
+ cmlast->next = cmptr;
}
+ cmlast = cmptr;
+ ++outgoing_msgs;
}
} else { /* print error from "msgs all" */
syslog(LOG_ERR, "%s", buf);
}
}
- outgoing_msgs = 0;
- cmptr2 = cmlist; /* this loop counts the messages */
- while (cmptr2 != NULL) {
- ++outgoing_msgs;
- cmptr2 = cmptr2->next;
- }
syslog(LOG_NOTICE, "%d messages to be spooled to %s",
outgoing_msgs, sysname);
/*
* Spool out the messages, but only if there are any.
*/
- if (outgoing_msgs != 0)
+ if (outgoing_msgs != 0) {
outgoing_msgs = spool_out(cmlist, tempflfp, sysname);
- syslog(LOG_NOTICE, "%d messages actually spooled",
- outgoing_msgs);
+ }
+
+ syslog(LOG_NOTICE, "%d messages actually spooled", outgoing_msgs);
/*
* Deallocate list of spooled messages.