예제 #1
0
파일: filelist.c 프로젝트: ftnapps/FTNd
char *xtodos(char *orig)
{
    char	buf[13], *copy, *p;

    if (orig == NULL) 
	return NULL;

    if ((remote_flags & SESSION_FNC) == 0) {
	Syslog('o', "No filename conversion for \"%s\"", FTND_SS(orig));
	return xstrcpy(orig);
    }

    copy = xstrcpy(orig);
    if ((p = strrchr(copy,'/'))) 
	p++;
    else 
	p = copy;

    name_mangle(p);
    memset(&buf, 0, sizeof(buf));
    strncpy(buf, p, 12);
    Syslog('o', "name \"%s\" converted to \"%s\"", FTND_SS(orig), buf);
    free(copy);
    return xstrcpy(buf);
}
예제 #2
0
파일: filelist.c 프로젝트: ftnapps/FTNd
/*
 * Add the specified entry to the list of files which should be sent
 * to the remote system.
 * 1. lst		file list to add entry to
 * 2. local		local filename
 * 3. remote		remote filename
 * 4. disposition	disposition
 * 5. floff		offset of entry in flo-file (-1 if this is a flo file)
 * 6. flofp		FILE * of flo file
 * 7. toend		append to end of list
 */
void add_list(file_list **lst, char *local, char *Remote, int disposition, off_t floff, FILE *flofp, int toend)
{
    file_list **tmpl, *tmp;

    Syslog('o', "add_list(\"%s\",\"%s\",%d,%s)", FTND_SS(local),FTND_SS(Remote),disposition,toend?"to end":"to beg");

    if (toend) 
	for (tmpl = lst; *tmpl; tmpl =&((*tmpl)->next));
    else 
	tmpl = &tmp;
    *tmpl = (file_list*)malloc(sizeof(file_list));
    if (toend) {
	(*tmpl)->next = NULL;
    } else {
	(*tmpl)->next = *lst;
	*lst = *tmpl;
    }

    (*tmpl)->remote      = xtodos(Remote);
    (*tmpl)->local       = xstrcpy(local);
    (*tmpl)->disposition = disposition;
    (*tmpl)->floff       = floff;
    (*tmpl)->flofp       = flofp;
    return;
}
예제 #3
0
파일: filelist.c 프로젝트: ftnapps/FTNd
void tidy_filelist(file_list *fl, int dsf)
{
    file_list *tmp;

    if (fl == NULL)
	return;

    for (tmp=fl;fl;fl=tmp) {
	tmp=fl->next;
	if (dsf && (fl->disposition == DSF)) {
	    Syslog('o',"Removing sent file \"%s\"",FTND_SS(fl->local));
	    if (unlink(fl->local) != 0) {
		if (errno == ENOENT)
		    Syslog('o',"Cannot unlink nonexistent file \"%s\"", FTND_SS(fl->local));
		else
		    WriteError("$Cannot unlink file \"%s\"", FTND_SS(fl->local));
	    }
	}
	if (fl->local) 
	    free(fl->local);
	if (fl->remote) 
	    free(fl->remote);
	else if (fl->flofp) 
	    fclose(fl->flofp);
	free(fl);
    }
    return;
}
예제 #4
0
파일: filelist.c 프로젝트: ftnapps/FTNd
/*
 * Create file request list for the Hydra or Binkp protocol.
 */
file_list *create_freqlist(fa_list *al)
{
    file_list	*st = NULL, *tmpf;
    fa_list	*tmpa;
    char	*nm, tmpreq[13];
    struct stat	stbuf;

    Syslog('o', "create_freqlist(%s)", al?ascfnode(al->addr, 0x1f):"<none>");
    made_request = 0;

    for (tmpa = al; tmpa; tmpa = tmpa->next) {
	nm = reqname(tmpa->addr);
	if ((nm != NULL) && (stat(nm, &stbuf) == 0)) {
	    snprintf(tmpreq, 13, "%04X%04X.REQ", tmpa->addr->net, tmpa->addr->node);
	    add_list(&st, nm, tmpreq, DSF, 0L, NULL, 1);
	    made_request = 1;
	}
    }

    if (made_request) {
	for (tmpf = st; tmpf; tmpf = tmpf->next)
	    Syslog('o', "flist: \"%s\" -> \"%s\" dsp:%d flofp:%lu floff:%lu",
			FTND_SS(tmpf->local), FTND_SS(tmpf->remote), tmpf->disposition, tmpf->flofp, tmpf->floff);
    }

    return st;
}
예제 #5
0
파일: backalias.c 프로젝트: ftnapps/FTNd
void readalias(char *fn)
{
	FILE			*fp;
	char			buf[256], *k, *v;
	struct aliaslist	*tmp = NULL;
	faddr			*ta = NULL;

	if ((fp = fopen(fn,"r")) == NULL) {
		WriteError("$cannot open system alias file %s", FTND_SS(fn));
		return;
	}

	while (fgets(buf, sizeof(buf)-1, fp)) {
		k = strtok(buf, " \t:");
		v = strtok(NULL, " \t\n\r\0:");
		if (k && v)
			if ((ta = parsefaddr(v))) {
				if (alist) {
					tmp->next = (struct aliaslist *) xmalloc(sizeof(struct aliaslist));
					tmp = tmp->next;
				} else {
					alist = (struct aliaslist *) xmalloc(sizeof(struct aliaslist));
					tmp = alist;
				}
				tmp->next = NULL;
				tmp->addr = ta;
				ta = NULL;
				tmp->alias = xstrcpy(k);
			}
	}
	fclose(fp);
}
예제 #6
0
파일: filelist.c 프로젝트: ftnapps/FTNd
void check_filebox(char *boxpath, file_list **st)
{
    char	    *temp;
    DIR             *dp;
    struct dirent   *de;
    struct passwd   *pw;
    struct stat     stbuf;

    if ((dp = opendir(boxpath)) == NULL) {
	Syslog('o', "\"%s\" cannot be opened, proceed", FTND_SS(boxpath));
    } else {
	Syslog('o', "checking filebox \"%s\"", boxpath);
        temp = calloc(PATH_MAX, sizeof(char));
	pw = getpwnam((char *)"ftnd");
        while ((de = readdir(dp))) {
            if (strcmp(de->d_name, ".") && strcmp(de->d_name, "..")) {
		snprintf(temp, PATH_MAX -1, "%s/%s", boxpath, de->d_name);
                if (stat(temp, &stbuf) == 0) {
                    Syslog('o' ,"checking file \"%s\"", de->d_name);
                    if (S_ISREG(stbuf.st_mode)) {
                        if (pw->pw_uid == stbuf.st_uid) {
                            /*
                             * We own the file
                             */
                            if ((stbuf.st_mode & S_IRUSR) && (stbuf.st_mode & S_IWUSR)) {
                                add_list(st, temp, de->d_name, KFS, 0L, NULL, 1);
                            } else {
                                Syslog('+', "No R/W permission on %s", temp);
                            }
                        } else if (pw->pw_gid == stbuf.st_gid) {
                            /*
                             * We own the file group
                             */
                            if ((stbuf.st_mode & S_IRGRP) && (stbuf.st_mode & S_IWGRP)) {
                                add_list(st, temp, de->d_name, KFS, 0L, NULL, 1);
                            } else {
                                Syslog('+', "No R/W permission on %s", temp);
                            }
                        } else {
                            /*
                             * No owner of file
                             */
                            if ((stbuf.st_mode & S_IROTH) && (stbuf.st_mode & S_IWOTH)) {
                                add_list(st, temp, de->d_name, KFS, 0L, NULL, 1);
                            } else {
                                Syslog('+', "No R/W permission on %s", temp);
                            }
                        }
                    } else {
                        Syslog('+', "Not a regular file %s", temp);
                    }
                } else {
                    WriteError("Can't stat %s", temp);
                }
            }
	}
	closedir(dp);
	free(temp);
    }
}
예제 #7
0
파일: transfer.c 프로젝트: ftnapps/FTNd
void add_download(down_list **lst, char *local, char *remote, int Area, unsigned int size, int kfs)
{
    down_list	*tmp, *ta;
    int		i;

    Syslog('b', "add_download(\"%s\",\"%s\",%ld,%ld,%d)", FTND_SS(local), FTND_SS(remote), Area, size, kfs);

    tmp = (down_list *)malloc(sizeof(down_list));
    tmp->next = NULL;
    tmp->local = xstrcpy(local);
    tmp->remote = xstrcpy(remote);
    tmp->cps = 0;
    tmp->area = Area;
    tmp->size = size;
    tmp->kfs = kfs;
    tmp->sent = FALSE;
    tmp->failed = FALSE;

    /*
     * Most prottocols don't allow spaces in filenames, so we modify the remote name.
     * However, they should not exist on a bbs.
     */
    for (i = 0; i < strlen(tmp->remote); i++) {
	if (tmp->remote[i] == ' ')
	    tmp->remote[i] = '_';
    }

    if (*lst == NULL) {
	*lst = tmp;
    } else {
	for (ta = *lst; ta; ta = ta->next) {
	    if (ta->next == NULL) {
		ta->next = (down_list *)tmp;
		break;
	    }
	}
    }
    
    return;
}
예제 #8
0
파일: backalias.c 프로젝트: ftnapps/FTNd
char *backalias(faddr *fa)
{
	struct aliaslist	*tmp;

	for (tmp = alist; tmp; tmp = tmp->next)
		if ((!fa->domain || !tmp->addr->domain || !strcasecmp(fa->domain,tmp->addr->domain)) &&
		    (!fa->zone   || (fa->zone == tmp->addr->zone)) && (fa->net == tmp->addr->net) && 
		    (fa->node == tmp->addr->node) && (fa->point == tmp->addr->point) && (fa->name) && 
		    (tmp->addr->name) && (strcasecmp(fa->name,tmp->addr->name) == 0)) {
			Syslog('m', "Address \"%s\" has local alias \"%s\"", ascinode(fa,0x7f), FTND_SS(tmp->alias));
			return tmp->alias;
		}
	return NULL;
}
예제 #9
0
파일: bopenfile.c 프로젝트: ftnapps/FTNd
/*
 * Openfile special for binkp sessions.
 */
FILE *bopenfile(char *fname, time_t remtime, off_t remsize, off_t *resofs)
{
    char	    ctt[32], *temp;
    struct stat	    st;
    FILE	    *fp;

    strcpy(ctt,date(remtime));

    Syslog('b', "Binkp: bopenfile(\"%s\",%s,%u)", FTND_SS(fname), ctt, (unsigned int)remsize);

    if ((fname == NULL) || (fname[0] == '\0')) {
	Syslog('+', "Binkp: bopenfile fname=NULL");
	return NULL;
    }
    if (tempinbound == NULL) {
	Syslog('+', "Binkp: bopenfile tempinbound is not set");
	return NULL;
    }

    if ((strlen(fname) == 12) && (strspn(fname,"0123456789abcdefABCDEF") == 8) && (strcasecmp(fname+8,".req") == 0)) {
	Syslog('b', "Binkp: received wazoo freq file");
	isfreq = TRUE;
    } else 
	isfreq = FALSE;

    infpath = xstrcpy(tempinbound);
    infpath = xstrcat(infpath, (char *)"/tmp/");
    infpath = xstrcat(infpath, fname);
    *resofs = 0L;

    /*
     * Set offset if (partial) fie is present
     */
    if (stat(infpath, &st) == 0) {
	Syslog('b', "Binkp: remtine=%ld, st_time=%ld, remsize=%ld, st_size=%ld", remtime, st.st_mtime, remsize, st.st_size);
	Syslog('+', "Binkp: file %s is already here", fname);
	*resofs = st.st_size;
    }

    Syslog('b', "Binkp: try fopen(\"%s\")", infpath);
    if ((infp = fopen(infpath, "a+")) == NULL) {
	WriteError("$Binkp: cannot open local file \"%s\"", infpath);
	free(infpath);
	infpath=NULL;
	return NULL;
    }

    /*
     * Write state file
     */
    temp = calloc(PATH_MAX, sizeof(char));
    snprintf(temp, PATH_MAX, "%s.state", infpath);
    if ((fp = fopen(temp, "w"))) {
	fprintf(fp, "%u\n", (unsigned int)remtime);
	fprintf(fp, "%u\n", (unsigned int)remsize);
	fclose(fp);
    }
    free(temp);

    intime = remtime;

    if (isfreq) {
	if (freqname) 
	    free(freqname);
	freqname = xstrcpy(tempinbound);
	freqname = xstrcat(freqname, (char *)"/");
	freqname = xstrcat(freqname, fname);
    }

    Syslog('b', "Binkp: opened file \"%s\", restart at %u", infpath, (unsigned int)*resofs);
    return infp;
}
예제 #10
0
파일: bopenfile.c 프로젝트: ftnapps/FTNd
/*
 *  close file, even if the file is partial received, we set the date on the
 *  file so that in a next session we know we must append to that file instead of
 *  trying to get the file again.
 */
int bclosefile(int success)
{
    int		    rc = 0;
    struct utimbuf  ut;
    char	    *temp;
    
    Syslog('b', "Binkp: closefile(), for file \"%s\"", FTND_SS(infpath));

    if ((infp == NULL) || (infpath == NULL)) {
	Syslog('+', "Binkp: closefile(), nothing to close");
	return 1;
    }

    rc = fclose(infp);
    infp = NULL;

    /*
     * If transfer failed, leave the file in the tmp queue, just close it.
     */
    if (! success) {
	if (rc == 0) {
	    ut.actime = intime;
	    ut.modtime = intime;
	    if ((rc = utime(infpath, &ut)))
		WriteError("$Binkp: utime on %s failed", infpath);
	}
	isfreq = FALSE;
	free(infpath);
	infpath = NULL;
	return rc;
    }

    /*
     * Remove state file.
     */
    temp = calloc(PATH_MAX, sizeof(char));
    snprintf(temp, PATH_MAX, "%s.state", infpath);
    if (unlink(temp))
	WriteError("$Binkp: can't unlink %s", temp);
    else
	Syslog('b', "Binkp: unlinked %s", temp);

    /*
     * Move file from extra tmp to normal tempinbound.
     */
    snprintf(temp, PATH_MAX, "%s/%s", tempinbound, basename(infpath));

    if (rc == 0) {
	snprintf(temp, PATH_MAX, "%s/%s", tempinbound, basename(infpath));
	rc = file_mv(infpath, temp);
	if (rc) {
	    WriteError("$Binkp: file_mv %s to %s rc=%d", infpath, temp, rc);
	} else {
	    Syslog('b', "Binkp: moved to %s", temp);
	}
    }

    if (rc == 0) {
	ut.actime = intime;
	ut.modtime = intime;
	if ((rc = utime(temp, &ut)))
	    WriteError("$Binkp: utime on %s failed", temp);
    }

    if (isfreq) {
	if (rc != 0) {
	    Syslog('+', "Binkp: removing unsuccessfuly received wazoo freq");
	    unlink(freqname);
	    free(freqname);
	    freqname = NULL;
	}
	isfreq = FALSE;
    }

    free(temp); 
    free(infpath);
    infpath = NULL;
    return rc;
}
예제 #11
0
static int sendtfile(char *ln, char *rn)
{
    int		    rc=0;
    struct stat	    st;
    struct flock    fl;
    int		    bufl, sverr;
    int		    offset;

    fl.l_type = F_RDLCK;
    fl.l_whence = 0;
    fl.l_start = 0L;
    fl.l_len = 0L;

    if ((in = fopen(ln,"r")) == NULL) {
	sverr = errno;
	if ((sverr == ENOENT) || (sverr == EINVAL)) {
	    Syslog('+', "TCP: file %s doesn't exist, removing", FTND_SS(ln));
	    return 0;
	} else {
	    WriteError("$TCP: can't open file %s, skipping", FTND_SS(ln));
	    return 1;
	}
    }

    if (fcntl(fileno(in), F_SETLK, &fl) != 0) {
	WriteError("$TCP: can't lock file %s, skipping", FTND_SS(ln));
	fclose(in);
	return 1;
    }

    if (stat(ln, &st) != 0) {
	WriteError("$TCP: can't access \"%s\", skipping", FTND_SS(ln));
	fclose(in);
	return 1;
    }
	
    if (st.st_size > 0) {
	Syslog('+', "TCP: send \"%s\" as \"%s\"", FTND_SS(ln), FTND_SS(rn));
	Syslog('+', "TCP: size %lu bytes, dated %s", (unsigned int)st.st_size, date(st.st_mtime));
	gettimeofday(&starttime, &tz);
    } else {
	Syslog('+', "TCP: file \"%s\" has 0 size, skiped",ln);
	return 0;
    }

    snprintf(txbuf,TCP_BLKSIZE, "S %s %u %u",rn,(unsigned int)st.st_size,(unsigned int)st.st_mtime+(unsigned int)(st.st_mtime%2));
    bufl = strlen(txbuf);
    rc = tcp_sblk(txbuf, bufl, TCP_CMD);
    rc = tcp_rblk(rxbuf, &bufl);

    if (strncmp(rxbuf,"RS",2) == 0) {
	Syslog('+', "TCP: file %s already received, skipping",rn);
	return 0;
    } else if (strncmp(rxbuf,"RN",2) == 0) {
	Syslog('+', "TCP: remote refused file, aborting",rn);
	return 2;
    } else if (strncmp(rxbuf,"ROK",3) == 0) {
	if (bufl > 3 && rxbuf[3]==' ') {
	    offset = strtol(rxbuf+4,(char **)NULL,10);
	    if (fseek(in,offset,SEEK_SET) != 0) {
		WriteError("$TCP: can't seek offset %ld in file %s", offset, ln);
		return 1;
	    }
	} else
	    offset = 0;
    } else
	return rc;

    while ((bufl = fread(&txbuf, 1, TCP_DATSIZE, in)) != 0) {
	if ((rc = tcp_sblk(txbuf, bufl, TCP_DATA)) > 0)
	    break;
    }

    fclose(in);
    if (rc == 0){
	strcpy(txbuf, "EOF");
	rc = tcp_sblk(txbuf, 3, TCP_CMD);
	rc = tcp_rblk(rxbuf, &bufl);
    }

    if (rc == 0 && strncmp(rxbuf,"FOK",3) == 0) {
	gettimeofday(&endtime, &tz);
	Syslog('a', "st_size %d, offset %d",st.st_size,offset);
	Syslog('+', "TCP: OK %s", transfertime(starttime, endtime, st.st_size-offset, TRUE));
	sentbytes += (unsigned int)st.st_size - offset;
	return 0;
    } else if(strncmp(rxbuf,"FERROR",6) == 0){
	WriteError("TCP: remote file error",ln);
	return rc==0?1:rc;
    } else
	return rc==0?1:rc;
}
예제 #12
0
파일: filelist.c 프로젝트: ftnapps/FTNd
static void check_flo(file_list **lst, char *nm)
{
    FILE	*fp;
    off_t	off;
    struct	flock fl;
    char	buf[PATH_MAX], buf2[PATH_MAX], *p, *q;
    int		disposition;
    struct stat stbuf;

    if ((fp = fopen(nm,"r+")) == NULL) {
	/*
	 * If no flo file, return.
	 */
	return;
    }

    Syslog('o', "check_flo(\"%s\")",FTND_SS(nm));

    fl.l_type   = F_RDLCK;
    fl.l_whence = 0;
    fl.l_start  = 0L;
    fl.l_len    = 0L;

    if (fcntl(fileno(fp), F_SETLK, &fl) != 0) {
	if (errno != EAGAIN)
	    WriteError("$Can't read-lock \"%s\"", FTND_SS(nm));
	else 
	    Syslog('o',"flo file busy");
	fclose(fp);
	return;
    }

    if (stat(nm, &stbuf) != 0) {
	WriteError("$Can't access \"%s\"", FTND_SS(nm));
	fclose(fp);
	return;
    }

    while (!feof(fp) && !ferror(fp)) {
	off = ftell(fp);
	if (fgets(buf, sizeof(buf)-1, fp) == NULL) 
	    continue;
	if (buf[0] == '~') 
	    continue; /* skip sent files */
	if (*(p=buf + strlen(buf) -1) == '\n') 
	    *p-- = '\0';
	if (*p == '\r') 
	    *p = '\0';

	switch (buf[0]) {
	    case '#':	p=buf+1; disposition=TFS; break;
	    case '-':
	    case '^':	p=buf+1; disposition=KFS; break;
	    case '@':	p=buf+1; disposition=LEAVE; break;
	    case 0:	continue;
	    default:	p=buf; disposition=LEAVE; break;
	}

	memset(&buf2, 0, sizeof(buf2));
	if (strlen(CFG.dospath)) {
	    if (strncasecmp(p, CFG.dospath, strlen(CFG.dospath)) == 0) {
		strcpy(buf2,uxoutbound);
		for (p+=strlen(CFG.dospath), q=buf2+strlen(buf2); *p; p++, q++)
		    *q = ((*p) == '\\')?'/':tolower(*p);
		*q = '\0';
		p = buf2;
	    }
	}

	if ((q=strrchr(p,'/')))
	    q++;
	else
	    q = p;
	add_list(lst, p, q, disposition, off, fp, 1);
    }

    /*
     * Add flo file to file list
     */
    add_list(lst, nm, NULL, KFS, -1L, fp, 1);

    /* here, we leave .flo file open, it will be closed by */
    /* execute_disposition */

    return;
}
예제 #13
0
파일: bounce.c 프로젝트: ftnapps/FTNd
int Bounce(faddr *f, faddr *t, FILE *fp, char *reason)
{
    int	    rc = 0, count = 0;
    char    *Buf;
    FILE    *np;
    time_t  Now;
    faddr   *from;

    Now = time(NULL);
    if (SearchFidonet(f->zone))
	f->domain = xstrcpy(fidonet.domain);

    Syslog('+', "Bounce msg from %s", ascfnode(f, 0xff));
    Buf = calloc(MAX_LINE_LENGTH +1, sizeof(char));
    rewind(fp);

    np = tmpfile();
    from = bestaka_s(f);
    from->zone  = t->zone;
    from->net   = t->net;
    from->node  = t->node;
    from->point = t->point;
    from->name  = xstrcpy((char *)"Postmaster");

    if (f->point)
	fprintf(np, "\001TOPT %d\r", f->point);
    if (from->point)
	fprintf(np, "\001FMPT %d\r", from->point);
    fprintf(np, "\001INTL %d:%d/%d %d:%d/%d\r", f->zone, f->net, f->node, from->zone, from->net, from->node);

    /*
     * Add MSGID, REPLY and PID
     */
    fprintf(np, "\001MSGID: %s %08x\r", ascfnode(from, 0x1f), sequencer());
    while ((fgets(Buf, MAX_LINE_LENGTH, fp)) != NULL) {
	Striplf(Buf);
	if (strncmp(Buf, "\001MSGID:", 7) == 0) {
	    fprintf(np, "\001REPLY:%s\r", Buf+7);
	}
    }
    fprintf(np, "\001PID: FTND-FIDO %s (%s-%s)\r", VERSION, OsName(), OsCPU());
    fprintf(np, "\001TZUTC: %s\r", gmtoffset(Now));

    fprintf(np, "     Dear %s\r\r", FTND_SS(f->name));
    fprintf(np, "Your message could not be delevered, reason: %s\r\r", reason);
    fprintf(np, "Here are the first lines of the original message from you:\r\r");
    fprintf(np, "======================================================================\r");

    rewind(fp);
    while ((fgets(Buf, MAX_LINE_LENGTH, fp)) != NULL) {
	Striplf(Buf);
	if (Buf[0] == '\001') {
	    fprintf(np, "^a");
	    fwrite(Buf + 1, strlen(Buf) -1, 1, np);
	} else {
	    fwrite(Buf, strlen(Buf), 1, np);
	}
	fputc('\r', np);
	count++;
	if (count == 50)
	    break;
    }
    fprintf(np, "======================================================================\r");
    if (count == 50) {
	fprintf(np, "\rOnly the first 50 lines are displayed\r");
    }

    fprintf(np, "\rWith regards, %s\r\r", CFG.sysop_name);
    fprintf(np, "%s\r", TearLine());
    Now = time(NULL) - (gmt_offset((time_t)0) * 60);
    rc = postnetmail(np, from, f, NULL, (char *)"Bounced message", Now, 0x0000, FALSE, from->zone, f->zone);
    tidy_faddr(from);

    fclose(np);

    free(Buf);
    return rc;
}
예제 #14
0
파일: filelist.c 프로젝트: ftnapps/FTNd
void execute_disposition(file_list *fl)
{
    FILE    *fp=NULL;
    char    *nm, tpl='~';

    Syslog('o', "execute_disposition(%s)", fl->local);
    nm = fl->local;
    if (fl->flofp) {
	/*
	 * Check for special case: flo-file 
	 */
	if (fl->floff == -1) {
	    /*
	     * We check if there are any files left for transmission
	     * in the flo-file to decide whether to remove or leave
	     * it on disk.
	     */
	    char    buf[PATH_MAX];
	    int	    files_remain = 0;

	    if (fseek(fl->flofp, 0L, 0) == 0) {
		while (!feof(fl->flofp) && !ferror(fl->flofp)) {
		    if (fgets(buf, sizeof(buf)-1, fl->flofp) == NULL)
			continue;

		    /*
		     * Count nr of files which haven't been sent yet
		     */
		    if (buf[0] != '~')
			files_remain++;
		}

	    } else {
		WriteError("$Error seeking in .flo to 0");
		files_remain = -1; /* Keep flo-file */
	    }

	    if (files_remain) {
		Syslog('o', "Leaving flo-file \"%s\", %d files remaining", FTND_SS(nm), files_remain);
		fl->disposition = LEAVE;
	    } else {
		fl->disposition = KFS;
	    }
	} else {
	    /*
	     * Mark files as sent in flo-file
	     */
	    if (fseek(fl->flofp, fl->floff, 0) == 0) {
		if (fwrite(&tpl,1,1,fl->flofp) != 1) {
		    WriteError("$Error writing '~' to .flo at %u", (unsigned int)fl->floff);
		} else {
		    Syslog('o', "Marked file \"%s\" as sent", FTND_SS(nm));
		}
		fflush(fl->flofp);
#ifdef HAVE_FDATASYNC
		fdatasync(fileno(fl->flofp));
#else
#ifdef HAVE_FSYNC		
		fsync(fileno(fl->flofp));
#endif
#endif
	    } else 
		WriteError("$error seeking in .flo to %u", (unsigned int)fl->floff);
	}
    }

    switch (fl->disposition) {
	case DSF:
	case LEAVE: break;

	case TFS:   Syslog('o', "Truncating sent file \"%s\"",FTND_SS(nm));
		    if ((fp=fopen(nm,"w"))) 
			fclose(fp);
		    else 
			WriteError("$Cannot truncate file \"%s\"",FTND_SS(nm));
		    break;

	case KFS:   Syslog('o', "Removing sent file \"%s\"",FTND_SS(nm));
		    if (unlink(nm) != 0) {
			if (errno == ENOENT)
			    Syslog('o', "Cannot unlink nonexistent file \"%s\"", FTND_SS(nm));
			else
			    WriteError("$Cannot unlink file \"%s\"", FTND_SS(nm));
		    }
		    break;

	default:    WriteError("execute_disposition: unknown disp %d for \"%s\"", fl->disposition,FTND_SS(nm));
		    break;
    }

    return;
}
예제 #15
0
파일: filelist.c 프로젝트: ftnapps/FTNd
file_list *create_filelist(fa_list *al, char *fl, int create)
{
    file_list	    *st = NULL, *tmpf;
    fa_list	    *tmpa;
    char	    flavor, *tmpfl, *nm, *temp, tmpreq[13], digit[6], *temp2;
    struct stat	    stbuf;
    int		    packets = 0;
    FILE	    *fp;
    unsigned char   buffer[2];
    faddr	    *fa;
    DIR		    *dp = NULL;
    struct dirent   *de;
    struct stat     sb;

    Syslog('o', "Create_filelist(%s,\"%s\",%d)", al?ascfnode(al->addr,0x1f):"<none>", FTND_SS(fl), create);
    made_request = 0;

    for (tmpa = al; tmpa; tmpa = tmpa->next) {
	Syslog('o', "Check address %s", ascfnode(tmpa->addr, 0x1f));

	/*
	 * For the main aka, check the outbox.
	 */
	if ((tmpa->addr) && Loaded && strlen(nodes.OutBox) &&
	    (tmpa->addr->zone == nodes.Aka[0].zone) && (tmpa->addr->net == nodes.Aka[0].net) &&
	    (tmpa->addr->node == nodes.Aka[0].node) && (tmpa->addr->point == nodes.Aka[0].point)) {
	    check_filebox(nodes.OutBox, &st);
	}

	/*
	 * Check spool files, these are more or less useless but they
	 * create a filelist of files to send which are never send.
	 * It gives the transfer protocols something "to do".
	 */
	if (strchr(fl, 'o')) {
	    nm = splname(tmpa->addr);
	    if ((fp = fopen(nm, "w"))) 
		fclose(fp);
	    if ((nm != NULL) && (stat(nm, &stbuf) == 0))
		add_list(&st, nm, NULL, DSF, 0L, NULL, 1);
	}

	/*
	 * Check .pol files
	 */
	nm = polname(tmpa->addr);
	if ((nm != NULL) && (stat(nm,&stbuf) == 0))
	    add_list(&st,nm,NULL,DSF,0L,NULL,1);

	/*
	 * Check other files, all flavors
	 */
	tmpfl = fl;
	while ((flavor = *tmpfl++)) {

	    Syslog('o', "Check flavor %c", flavor);
	    /*
	     * Check normal mail packets
	     */
	    nm = pktname(tmpa->addr,flavor);
	    if ((nm != NULL) && (stat(nm,&stbuf) == 0)) {
		Syslog('o', "found %s", nm);
		packets++;
		add_list(&st, nm, tmpkname(), KFS, 0L, NULL, 1);
	    }

	    /*
	     * Check .flo files for file attaches
	     */
	    nm = floname(tmpa->addr,flavor);
	    check_flo(&st, nm);
	}

	if ((session_flags & SESSION_WAZOO) &&
	    ((session_flags & SESSION_HYDRA) == 0) && (master || ((session_flags & SESSION_IFNA) == 0))) {
	    /*
	     * we don't distinguish flavoured reqs
	     */
	    nm = reqname(tmpa->addr);
	    if ((nm != NULL) && (stat(nm, &stbuf) == 0)) {
		snprintf(tmpreq, 13, "%04X%04X.REQ", tmpa->addr->net, tmpa->addr->node);
		add_list(&st, nm, tmpreq, DSF, 0L, NULL, 1);
		made_request = 1;
	    }
	}
    }

    /*
     * Check T-Mail style fileboxes
     */
    temp = calloc(PATH_MAX, sizeof(char));
    if (strlen(CFG.tmailshort) && (dp = opendir(CFG.tmailshort))) {
       Syslog('o', "Checking T-Mail short box \"%s\"", CFG.tmailshort);
       while ((de = readdir(dp))) {
           if (strcmp(de->d_name, ".") && strcmp(de->d_name, "..")) {
               snprintf(temp, PATH_MAX -1, "%s/%s", CFG.tmailshort, de->d_name);
               if (stat(temp, &sb) == 0) {
                   Syslog('o' ,"checking \"%s\"", de->d_name);
                   if (S_ISDIR(sb.st_mode)) {
                       int i;
                       char b=0;
                       for (i=0; (i<8) && (!b); ++i) {
                           char c = tolower(de->d_name[i]);
                           if ( (c<'0') || (c>'v') || ((c>'9') && (c<'a')) ) 
			       b=1;
                       }
                       if (de->d_name[8]!='.') 
			   b=1;
                       for (i=9; (i<11) && (!b); ++i) {
                           char c = tolower(de->d_name[i]);
                           if ( (c<'0') || (c>'v') || ((c>'9') && (c<'a')) ) 
			       b=1;
                       }
                       if (b) 
			   continue;
                       if (de->d_name[11]==0) 
			   flavor='o';
                       else if ((tolower(de->d_name[11])=='h') && (de->d_name[12]==0)) 
			   flavor='h';
                       else 
			   continue;
                       fa = (faddr*)malloc(sizeof(faddr));
                       fa->name = NULL;
                       fa->domain = NULL;
                       memset(&digit, 0, sizeof(digit));
                       digit[0] = de->d_name[0];
                       digit[1] = de->d_name[1];
                       fa->zone = strtol(digit, NULL, 32);
                       memset(&digit, 0, sizeof(digit));
                       digit[0] = de->d_name[2];
                       digit[1] = de->d_name[3];
                       digit[2] = de->d_name[4];
                       fa->net = strtol(digit, NULL, 32);
                       memset(&digit, 0, sizeof(digit));
                       digit[0] = de->d_name[5];
                       digit[1] = de->d_name[6];
                       digit[2] = de->d_name[7];
                       fa->node = strtol(digit, NULL, 32);
                       memset(&digit, 0, sizeof(digit));
                       digit[0] = de->d_name[9];
                       digit[1] = de->d_name[10];
                       fa->point = strtol(digit, NULL, 32);
                       for (tmpa = al; tmpa; tmpa = tmpa->next) {
                           if ((fa->zone==tmpa->addr->zone) && (fa->net==tmpa->addr->net) && 
			       (fa->node==tmpa->addr->node) && (fa->point==tmpa->addr->point) && strchr(fl, flavor))
				if (SearchFidonet(tmpa->addr->zone))
				    check_filebox(temp, &st);
                       }
                       tidy_faddr(fa);
                   }
               }
           }
       }
       closedir(dp);
    }

    if (strlen(CFG.tmaillong) && (dp = opendir(CFG.tmaillong))) {
       temp2 = calloc(PATH_MAX, sizeof(char));
       Syslog('o', "Checking T-Mail long box \"%s\"", CFG.tmaillong);
       while ((de = readdir(dp))) {
           if (strcmp(de->d_name, ".") && strcmp(de->d_name, "..")) {
               snprintf(temp, PATH_MAX -1, "%s/%s", CFG.tmaillong, de->d_name);
               if (stat(temp, &sb) == 0) {
                   Syslog('o' ,"checking \"%s\"", de->d_name);
                   if (S_ISDIR(sb.st_mode)) {
                       char c, d;
                       int n;
                       snprintf(temp2, PATH_MAX -1, "%s", de->d_name);
                       fa = (faddr*)malloc(sizeof(faddr));
                       fa->name = NULL;
                       fa->domain = NULL;
                       n = sscanf(temp2, "%u.%u.%u.%u.%c%c", &(fa->zone), &(fa->net), &(fa->node), &(fa->point), &c, &d);
                       if ((n==4) || ((n==5) && (tolower(c)=='h'))) {
                           if (n==4) 
			       flavor = 'o';
                           else 
			       flavor = 'h';
                           for (tmpa = al; tmpa; tmpa = tmpa->next) {
                               if ((fa->zone==tmpa->addr->zone) && (fa->net==tmpa->addr->net) && 
				    (fa->node==tmpa->addr->node) && (fa->point==tmpa->addr->point) && 
				    strchr(fl, flavor))
				  if (SearchFidonet(tmpa->addr->zone)) 
					check_filebox(temp, &st);
                           }
                       }
                       tidy_faddr(fa);
                   }   
               }
           }
       }
       closedir(dp);
       free(temp2);
    }
    free(temp);


    /*
     * For FTS-0001 we need to create at least one packet.
     */
    if (((st == NULL) && (create > 1)) || ((st != NULL) && (packets == 0) && (create > 0))) {
	Syslog('o', "Create packet for %s", ascfnode(al->addr,0x1f));
	if ((fp = openpkt(NULL, al->addr, 'o', TRUE))) {
	    memset(&buffer, 0, sizeof(buffer));
	    fwrite(buffer, 1, 2, fp);
	    fclose(fp);
	}
	add_list(&st, pktname(al->addr,'o'), tmpkname(), KFS, 0L, NULL, 0);
    }

    for (tmpf = st; tmpf; tmpf = tmpf->next)
	Syslog('o',"flist: \"%s\" -> \"%s\" dsp:%d flofp:%u floff:%u",
		FTND_SS(tmpf->local), FTND_SS(tmpf->remote), tmpf->disposition,
		(unsigned int)tmpf->flofp, (unsigned int)tmpf->floff);

    return st;
}
예제 #16
0
void AdoptFile(int Area, char *File, char *Description)
{
    FILE		*fp;
    char		*temp, *temp2, *tmpdir, *unarc, *pwd, *lname, *fileid;
    char		Desc[256], TDesc[256];
    int			MustRearc = FALSE, UnPacked = FALSE;
    int			IsVirus = FALSE, File_Id = FALSE;
    int			i, j, k, lines = 0, File_id_cnt = 0;
    struct FILE_record	f_db;

    Syslog('f', "Adopt(%d, %s, %s)", Area, FTND_SS(File), FTND_SS(Description));

    if (!do_quiet)
	ftnd_colour(CYAN, BLACK);

    if (LoadAreaRec(Area) == FALSE)
	die(FTNERR_INIT_ERROR);

    if (area.Available) {
	temp   = calloc(PATH_MAX, sizeof(char));
	temp2  = calloc(PATH_MAX, sizeof(char));
	pwd    = calloc(PATH_MAX, sizeof(char));
	tmpdir = calloc(PATH_MAX, sizeof(char));

	if (CheckFDB(Area, area.Path))
	    die(FTNERR_INIT_ERROR);
	getcwd(pwd, PATH_MAX);

	if (!do_quiet) {
	    printf("Adopt file: %s ", File);
	    printf("Unpacking \b\b\b\b\b\b\b\b\b\b");
	    fflush(stdout);
	}

	snprintf(tmpdir, PATH_MAX, "%s/tmp/arc%d", getenv("FTND_ROOT"), (int)getpid());
	if (create_tmpwork()) {
	    WriteError("Can't create %s", tmpdir);
	    if (!do_quiet)
		printf("\nCan't create dir %s\n", tmpdir);
	    die(FTNERR_INIT_ERROR);
	}

	snprintf(temp, PATH_MAX, "%s/%s", pwd, File);
	if (do_novir == FALSE) {
	    if (!do_quiet) {
		printf("Virscan   \b\b\b\b\b\b\b\b\b\b");
		fflush(stdout);
	    }
	    IsVirus = VirScanFile(temp);
	}
	if (IsVirus) {
	    WriteError("Virus found");
	    if (!do_quiet)
		printf("\nVirus found\n");
	    die(FTNERR_VIRUS_FOUND);
	}

	if ((unarc = unpacker(File))) {
	    if (strlen(area.Archiver) && (strcmp(unarc, area.Archiver) == 0))
		MustRearc = TRUE;
	    UnPacked = UnpackFile(temp);
	    if (!UnPacked)
		die(FTNERR_INIT_ERROR);
	}

        if (!do_quiet) {
	    printf("Checking  \b\b\b\b\b\b\b\b\b\b");
	    fflush(stdout);
        }

        memset(&f_db, 0, sizeof(f_db));
	strcpy(f_db.Uploader, CFG.sysop_name);
	f_db.UploadDate = time(NULL);
	if (do_annon)
	    f_db.Announced = TRUE;
	
	if (UnPacked) {
	    /*
	     * Try to get a FILE_ID.DIZ
	     */
	    fileid = calloc(PATH_MAX, sizeof(char));
            snprintf(temp, PATH_MAX, "%s/tmp/arc%d", getenv("FTND_ROOT"), (int)getpid());
	    snprintf(fileid, PATH_MAX, "FILE_ID.DIZ");
	    if (getfilecase(temp, fileid)) {
		snprintf(temp, PATH_MAX, "%s/tmp/arc%d/%s", getenv("FTND_ROOT"), (int)getpid(), fileid);
		snprintf(temp2, PATH_MAX, "%s/tmp/FILE_ID.DIZ", getenv("FTND_ROOT"));
		if (file_cp(temp, temp2) == 0) {
		    File_Id = TRUE;
		}
	    }
	    free(fileid);

	    if (File_Id) {
		Syslog('f', "FILE_ID.DIZ found");
		if ((fp = fopen(temp2, "r"))) {
		    /*
		     * Read no more then 25 lines
		     */
		    while (((fgets(Desc, 255, fp)) != NULL) && (File_id_cnt < 25)) {
			lines++;
			/*
			 * Check if the FILE_ID.DIZ is in a normal layout.
			 * This should be max. 10 lines of max. 48 characters.
			 * We check at 51 characters and if the lines are longer,
			 * we discard the FILE_ID.DIZ file.
			 */
			if (strlen(Desc) > 51) {
			    File_id_cnt = 0;
			    File_Id = FALSE;
			    Syslog('!', "Discarding illegal formated FILE_ID.DIZ");
			    break;
			}

			if (strlen(Desc)) {
			    if (strlen(Desc) > 48)
				Desc[48] = '\0';
			    j = 0;
			    for (i = 0; i < strlen(Desc); i++) {
				if ((Desc[i] >= ' ') || (Desc[i] < 0)) {
				    f_db.Desc[File_id_cnt][j] = Desc[i];
				    j++;
				}
			    }
			    File_id_cnt++;
			}
		    }
		    fclose(fp);
		    unlink(temp2);

		    /*
		     * Strip empty lines at end of FILE_ID.DIZ
		     */
		    while ((strlen(f_db.Desc[File_id_cnt-1]) == 0) && (File_id_cnt))
			File_id_cnt--;

		    Syslog('f', "Got %d FILE_ID.DIZ lines", File_id_cnt);
		    for (i = 0; i < File_id_cnt; i++)
			Syslog('f', "\"%s\"", f_db.Desc[i]);
		}
	    }
	}

	if (!File_id_cnt) {
	    if (Description == NULL) {
		WriteError("No FILE_ID.DIZ and no description on the commandline");
		if (!do_quiet)
		    printf("\nNo FILE_ID.DIZ and no description on the commandline\n");
		clean_tmpwork();
		die(FTNERR_COMMANDLINE);
	    } else {
		/*
		 * Create description from the commandline.
		 */
		if (strlen(Description) < 48) {
		    /*
		     * Less then 48 chars, copy and ready.
		     */
		    strcpy(f_db.Desc[0], Description);
		    File_id_cnt++;
		} else {
		    /*
		     * More then 48 characters, break into multiple
		     * lines not longer then 48 characters.
		     */
		    memset(&TDesc, 0, sizeof(TDesc));
		    strcpy(TDesc, Description);
		    while (strlen(TDesc) > 48) {
			j = 48;
			while (TDesc[j] != ' ')
			    j--;
			strncat(f_db.Desc[File_id_cnt], TDesc, j);
			File_id_cnt++;
			k = strlen(TDesc);
			j++; /* Correct space */
			for (i = 0; i <= k; i++, j++)
			    TDesc[i] = TDesc[j];
		    }
		    strcpy(f_db.Desc[File_id_cnt], TDesc);
		    File_id_cnt++;
		}
	    }
	}

	/*
	 * Import the file.
	 */
	chdir(pwd);
	clean_tmpwork();

	/*
	 * Work out the kind of filename, is it a long filename
	 * or a 8.3 DOS filename. The file on disk must become
	 * 8.3 for import.
	 */
	if (is_real_8_3(File)) {
	    Syslog('f', "Adopt, file is 8.3");
	    strcpy(f_db.Name, File);
	    strcpy(f_db.LName, File);
	    for (i = 0; i < strlen(File); i++)
		if (isupper(f_db.LName[i]))
		    f_db.LName[i] = tolower(f_db.LName[i]);
	} else {
	    Syslog('f', "Adopt, file is LFN");
	    strcpy(temp2, File);
	    name_mangle(temp2);
	    if (rename(File, temp2)) {
		Syslog('+', "Can't rename %s to %s", File, temp2);
		if (!do_quiet)
		    printf("\nCan't rename %s to %s\n", File, temp2);
		die(FTNERR_GENERAL);
	    }
	    strcpy(f_db.Name, temp2);
	    strcpy(f_db.LName, File);
	}
	f_db.Size = file_size(f_db.Name);
	f_db.Crc32 = file_crc(f_db.Name, TRUE);
	f_db.FileDate = file_time(f_db.Name);
	snprintf(temp2, PATH_MAX, "%s/%s", area.Path, f_db.Name);

	if (!do_quiet) {
	    printf("Adding    \b\b\b\b\b\b\b\b\b\b");
	    fflush(stdout);
	}

	if (strcmp(f_db.Name, f_db.LName)) {
	    lname = calloc(PATH_MAX, sizeof(char));
	    snprintf(lname, PATH_MAX, "%s/%s", area.Path, f_db.LName);
	    if (AddFile(f_db, Area, temp2, f_db.Name, lname) == FALSE) {
		die(FTNERR_GENERAL);
	    }
	    free(lname);
	} else {
	    if (AddFile(f_db, Area, temp2, File, NULL) == FALSE) {
		die(FTNERR_GENERAL);
	    }
	}
	Syslog('+', "File %s added to area %d", File, Area);

	if (MustRearc) {
	    /* Here we should call the rearc function */
	}

	free(pwd);
	free(temp2);
	free(temp);
	free(tmpdir);
    } else {
	WriteError("Area %d is not available", Area);
	if (!do_quiet)
	    printf("\nArea %d is not available\n", Area);
    }

    if (!do_quiet) {
	printf("\r                                                              \r");
	fflush(stdout);
    }
}
예제 #17
0
파일: mkftnhdr.c 프로젝트: ftnapps/FTNd
ftnmsg *mkftnhdr(rfcmsg *msg, int newsmode, faddr *recipient)
{
    char	    *freename = NULL, *rfcfrom = NULL, *p, *q, *l, *r;
    char	    *fbuf = NULL, *ftnfrom=NULL;
    static ftnmsg   *tmsg;
    int		    needreplyaddr = 1;
    faddr	    *tmp, *tmp2;

    tmsg=(ftnmsg *)malloc(sizeof(ftnmsg));
    memset(tmsg, 0, sizeof(ftnmsg));

    if (newsmode) {
	p = xstrcpy(hdr((char *)"Comment-To",msg));
	if (p == NULL) 
	    p = xstrcpy(hdr((char *)"X-Comment-To",msg));
	if (p == NULL) 
	    p = xstrcpy(hdr((char *)"X-FTN-To",msg));
	if (p == NULL) 
	    p = xstrcpy(hdr((char *)"X-Fidonet-Comment-To",msg));
	if (p == NULL) 
	    p = xstrcpy(hdr((char *)"X-Apparently-To",msg));
	if (p == NULL)
	    p = xstrcpy(hdr((char *)"To", msg));  /* 14-Aug-2001 MB */
	if (p) {
	    Syslog('m', "Getting `to' address from \"%s\"", FTND_SS(p));

	    if ((tmsg->to = parsefaddr(p)) == NULL)
		tmsg->to = parsefaddr((char *)"[email protected]");
	    if ((l = strrchr(p,'<')) && (r = strchr(p,'>')) && (l < r)) {
		r = l;
		*r-- = '\0';
		if ((l = strchr(p,'"')) && (r = strrchr(p,'"')) && (l < r)) {
		    l++;
		    *r-- = '\0';
		}
		while (isspace(*r)) 
		    *r-- = '\0';
		if (!l) 
		    l = p;
		while (isspace(*l)) 
		    l++;
	    } else if ((l = strrchr(p,'(')) && (r = strchr(p,')')) && (l < r)) {
		*r-- = '\0';
		while (isspace(*r)) 
		    *r-- = '\0';
		l++;
		while (isspace(*l)) 
		    l++;
	    } else {
		l = p;
		while (isspace(*l)) 
		    l++;
		r = p + strlen(p) -1;
		if (*r == '\n') 
		    *r-- = '\0';
		while (isspace(*r)) 
		    *r-- = '\0';
	    }

	    if (*l) {
		if (strlen(l) > MAXNAME)
		    l[MAXNAME]='\0';
		free(tmsg->to->name);
		tmsg->to->name=xstrcpy(l);
	    }
	    free(p);
	    /*
	     *  It will become echomail, the destination FTN address must
	     *  be our address.  14-Aug-2001 MB.
	     */
	    tmsg->to->zone   = msgs.Aka.zone;
	    tmsg->to->net    = msgs.Aka.net;
	    tmsg->to->node   = msgs.Aka.node;
	    tmsg->to->point  = msgs.Aka.point;
	    tmsg->to->domain = xstrcpy(msgs.Aka.domain);
	} else {
	    /*
	     *  Filling a default To: address.
	     */
	    tmsg->to = (faddr*)malloc(sizeof(faddr));
	    tmsg->to->name   = xstrcpy((char *)"All");
	    tmsg->to->zone   = msgs.Aka.zone;
	    tmsg->to->net    = msgs.Aka.net;
	    tmsg->to->node   = msgs.Aka.node;
	    tmsg->to->point  = msgs.Aka.point;
	    tmsg->to->domain = xstrcpy(msgs.Aka.domain);
	}
    } else {
	if (recipient) {
	    /*
	     *  In ftnmail mode the recipient is valid and must be used 
	     *  as the destination address. The To: field is probably
	     *  an RFC address an cannot be used to route the message.
	     */
	    tmsg->to = (faddr *)malloc(sizeof(faddr));
	    tmsg->to->point = recipient->point;
	    tmsg->to->node  = recipient->node;
	    tmsg->to->net   = recipient->net;
	    tmsg->to->zone  = recipient->zone;
	    tmsg->to->name  = xstrcpy(recipient->name);
	    if (tmsg->to->name && (strlen(tmsg->to->name) > MAXNAME))
		tmsg->to->name[MAXNAME]='\0';
	    tmsg->to->domain = xstrcpy(recipient->domain);
	    Syslog('m', "Recipient TO: %s", ascfnode(tmsg->to,0xff));
	} else {
	    p = xstrcpy(hdr((char *)"To",msg));
	    if (p == NULL)
		p = xstrcpy(hdr((char *)"X-Apparently-To",msg));
	    if (p) {
		if ((tmsg->to = parsefaddr(p)) == NULL)
		    WriteError("Unparsable destination address");
		else
		    Syslog('m', "RFC parsed TO: %s",ascfnode(tmsg->to,0xff));
	    }
	}
    } /* else (newsmode) */

    p = fbuf = xstrcpy(hdr((char *)"Reply-To", msg));
    if (fbuf == NULL) 
	p = fbuf = xstrcpy(hdr((char *)"From", msg));
    if (fbuf == NULL) 
	p = fbuf = xstrcpy(hdr((char *)"X-UUCP-From", msg));
    if (p) {
	q = p;
	while (isspace(*q)) 
	    q++;
	fbuf = parserfcaddr(q).remainder;
	if (parserfcaddr(q).target) {
	    fbuf = xstrcat(fbuf, (char *)"@");
	    fbuf = xstrcat(fbuf, parserfcaddr(q).target);
	}	
	rfcfrom = fbuf;
    }
    if (p)
	free(p);
    p = NULL;
    if (!rfcfrom) 
	rfcfrom = xstrcpy((char *)"postmaster");
    p = fbuf = xstrcpy(hdr((char *)"From", msg));
    if (fbuf == NULL) 
	p = fbuf = xstrcpy(hdr((char *)"X-UUCP-From", msg));
    if (p) {
	q = p;
	while (isspace(*q)) 
	    q++;
        if ((q) && (*q !=  '\0'))
            freename = parserfcaddr(q).comment;
        else 
	    freename = NULL;
    } else 
	freename = xstrcpy((char *)"Unidentified User");
    if (freename) {
	while (isspace(*freename)) 
	    freename++;
    }

    if (rfcfrom) {
	while (isspace(*rfcfrom)) 
	    rfcfrom++;
	p = rfcfrom + strlen(rfcfrom) -1;
	while ((isspace(*p)) || (*p == '\n')) 
	    *(p--)='\0';
    }

    if ((freename) && (*freename != '\0')) {
	while (isspace(*freename)) 
	    freename++;
	p = freename + strlen(freename) -1;
	while ((isspace(*p)) || (*p == '\n')) 
	    *(p--)='\0';
	if ((*freename == '\"') && (*(p=freename+strlen(freename)-1) == '\"')) {
	    freename++;
	    *p='\0';
	}
    }
    // if (*freename == '\0') freename=rfcfrom;
    if ((!freename) || ((freename) && (*freename == '\0')) || (strcmp(freename,".")==0)) 
	freename=rfcfrom;

    if (! newsmode)
	Syslog('+', "from: %s <%s>",freename,rfcfrom);

    needreplyaddr = 1;
    if ((tmsg->from=parsefaddr(rfcfrom)) == NULL) {
	if (freename && rfcfrom)
	    if (!strchr(freename,'@') && !strchr(freename,'%') && 
			    strncasecmp(freename,rfcfrom,MAXNAME) &&
			    strncasecmp(freename,"uucp",4) &&
			    strncasecmp(freename,"usenet",6) &&
			    strncasecmp(freename,"news",4) &&
			    strncasecmp(freename,"super",5) &&
			    strncasecmp(freename,"admin",5) &&
			    strncasecmp(freename,"postmaster",10) &&
			    strncasecmp(freename,"sys",3)) 
		needreplyaddr=registrate(freename,rfcfrom);
    } else {
	tmsg->ftnorigin = 1;
	tmsg->from->name = xstrcpy(freename);
	if (strlen(tmsg->from->name) > MAXNAME)
	    tmsg->from->name[MAXNAME]='\0';
    }
    if (replyaddr) {
	free(replyaddr);
	replyaddr=NULL;
    }
    if (needreplyaddr && (tmsg->from == NULL)) {
	replyaddr=xstrcpy(rfcfrom);
    }

    if (tmsg->from)
	Syslog('m', "From address was%s distinguished as ftn", tmsg->from ? "" : " not");

    if (newsmode) {
	tmp2 = fido2faddr(msgs.Aka);
	bestaka = bestaka_s(tmp2);
	tidy_faddr(tmp2);
    } else
	bestaka = bestaka_s(tmsg->to);

    if ((tmsg->from == NULL) && (bestaka)) {
	if (CFG.dontregate) {
	    p = xstrcpy(hdr((char *)"X-FTN-Sender",msg));
	    if (p == NULL) {
		if ((p = hdr((char *)"X-FTN-From",msg))) {
		    tmp = parsefnode(p);
		    p = xstrcpy(ascinode(tmp, 0xff));
		    tidy_faddr(tmp);
		}
	    }
	    if (p) {
	        q = p;
		while (isspace(*q)) 
		    q++;
		ftnfrom = parserfcaddr(q).remainder;
		if (parserfcaddr(q).target) {
		    ftnfrom = xstrcat(ftnfrom,(char *)"@");
		    ftnfrom = xstrcat(ftnfrom,parserfcaddr(q).target);
		}	
		Syslog('m', "Ftn gateway: \"%s\"", ftnfrom);
		Syslog('+', "Ftn sender: %s",ftnfrom);
		if (ftnfrom) 
		    tmsg->from = parsefaddr(ftnfrom);
		if ((tmsg->from) && (!tmsg->from->name))
		    tmsg->from->name = xstrcpy(rfcfrom);
	    }
	    if (p)
		free(p);
	    p = NULL;
	    if (tmsg->from == NULL) {
		tmsg->from=(faddr *)malloc(sizeof(faddr));
		tmsg->from->name=xstrcpy(freename);
		if (tmsg->from->name && (strlen(tmsg->from->name) > MAXNAME))
		    tmsg->from->name[MAXNAME]='\0';
		tmsg->from->point=bestaka->point;
		tmsg->from->node=bestaka->node;
		tmsg->from->net=bestaka->net;
		tmsg->from->zone=bestaka->zone;
		tmsg->from->domain=xstrcpy(bestaka->domain);
	    }
	} else {
	    tmsg->from=(faddr *)xmalloc(sizeof(faddr));
	    tmsg->from->name=xstrcpy(freename);
	    if (tmsg->from->name && (strlen(tmsg->from->name) > MAXNAME))
		tmsg->from->name[MAXNAME]='\0';
	    tmsg->from->point=bestaka->point;
	    tmsg->from->node=bestaka->node;
	    tmsg->from->net=bestaka->net;
	    tmsg->from->zone=bestaka->zone;
	    tmsg->from->domain=xstrcpy(bestaka->domain);
	}
    }
    if (fbuf) 
	free(fbuf); 
    fbuf = NULL;

    p = hdr((char *)"Subject", msg);
    if (p) {
	while (isspace(*p)) 
	    p++;
	tmsg->subj = xstrcpy(p);
	if (*(p=tmsg->subj+strlen(tmsg->subj)-1) == '\n') 
	    *p='\0';
	if (strlen(tmsg->subj) > MAXSUBJ) 
	    tmsg->subj[MAXSUBJ]='\0';
    } else {
	tmsg->subj = xstrcpy((char *)" ");
    }

    if ((p = hdr((char *)"X-FTN-FLAGS",msg))) 
	tmsg->flags |= flagset(p);
    if (hdr((char *)"Return-Receipt-To",msg)) 
	tmsg->flags |= M_RRQ;
    if (hdr((char *)"Notice-Requested-Upon-Delivery-To",msg)) 
	tmsg->flags |= M_RRQ;
    if (!newsmode) {
	tmsg->flags |= M_PVT;
	tmsg->flags |= M_KILLSENT;
    }

    if ((p = hdr((char *)"X-Origin-Date",msg))) 
	tmsg->date = parsedate(p, NULL) - (gmt_offset((time_t)0) * 60);
    else if ((p = hdr((char *)"Date",msg))) 
	tmsg->date = parsedate(p, NULL) - (gmt_offset((time_t)0) * 60);
    else 
	tmsg->date = time((time_t *)NULL);

    /*
     * SunMail 1.0 creates invalid date formats like: Wed, 19 Jun 2002 18:21:07 GMT-08:00
     *                                                                                ^---- not allowed.
     */
    if (tmsg->date == -1) {
	Syslog('!', "Parsing date \"%s\" failed, using current date", p);
	tmsg->date = time((time_t *)NULL);
    }
	
    if ((p = hdr((char *)"X-FTN-MSGID", msg))) {
	tmsg->ftnorigin &= 1;
	while (isspace(*p)) 
	    p++;
	tmsg->msgid_s = xstrcpy(p);
	if (*(p = tmsg->msgid_s + strlen(tmsg->msgid_s) -1) == '\n') 
	    *p='\0';
    } else if ((p = hdr((char *)".MSGID",msg))) {
	tmsg->ftnorigin &= 1;
	while (isspace(*p)) 
	    p++;
	tmsg->msgid_s = xstrcpy(p);
	if (*(p = tmsg->msgid_s + strlen(tmsg->msgid_s) -1) == '\n') 
	    *p='\0';
    } else if ((p = hdr((char *)"Message-ID",msg))) {
	tmsg->ftnorigin &= ftnmsgid(p,&(tmsg->msgid_a),&(tmsg->msgid_n),tmsg->area);
    } else
	tmsg->msgid_a = NULL;

    if ((p = hdr((char *)"X-FTN-REPLY",msg))) {
	while (isspace(*p)) 
	    p++;
	tmsg->reply_s = xstrcpy(p);
	if (*(p=tmsg->reply_s + strlen(tmsg->reply_s) -1) == '\n') 
	    *p='\0';
    } else {
	if (newsmode) {
	    p = hdr((char *)"References",msg);
	    if (p) {       
		l = xstrcpy(p);
		r = strtok(l," \t\n");
		while ((l=strtok(NULL," \t\n")) != NULL) 
		    r = l;
		p = r;
		free(l);
	    }
	} else
	    p = hdr((char *)"In-Reply-To",msg);
    }
    if (p)
	(void)ftnmsgid(p,&(tmsg->reply_a),&(tmsg->reply_n),NULL);
    else
	tmsg->reply_a=NULL;

    p = hdr((char *)"Organization",msg);
    if (p == NULL)
	p = hdr((char *)"Organisation",msg);
    if (p) {
	while (isspace(*p)) 
	    p++;
	tmsg->origin = xstrcpy(p);
	if (tmsg->origin)
	    if (*(p = tmsg->origin + strlen(tmsg->origin)-1) == '\n') 
		*p='\0';
    } else {
	/*
	 *  No Organization header, insert the default BBS origin.
	 */
	tmsg->origin = xstrcpy(CFG.origin);
    }

    return tmsg;
}
예제 #18
0
/*
 * Process incoming file information header
 */
int procheader(char *Name)
{
    register char   *openmode, *p;
    static int	    dummy;
    char	    ctt[32];

    Syslog('z', "procheader \"%s\"",printable(Name,0));
    /* set default parameters and overrides */
    openmode = (char *)"w";

    /*
     * Check slashes in the name
     */
    p = strrchr(Name,'/');
    if (p) {
	p++;
	if (!*p) {
	    /* alert - file name ended in with a / */
	    Syslog('!', "%s: file name ends with a /, skipped: %s", protname(), Name);
	    return ZFERR;
	}
	Name = p;
	Syslog('z', "filename converted to \"%s\"", FTND_SS(Name));
    }

    if (strlen(Name) > 80) {
	Syslog('!', "%s: file name received is longer then 80 characters, skipped: %s", protname(), Name);
	return ZFERR;
    }

    Syslog('z', "zmanag=%d", zmanag);
    Syslog('z', "zconv=%d", zconv);

    /*
     *  Process ZMODEM remote file management requests
     */
    if (!Thisbinary && zconv == ZCNL)	/* Remote ASCII override */
	Thisbinary = FALSE;
    if (zconv == ZCBIN)			/* Remote Binary override */
	Thisbinary = TRUE;
    if (zmanag == ZMAPND)
	openmode = (char *)"a";

    Syslog('z', "Thisbinary %s", Thisbinary ?"TRUE":"FALSE");

    Bytesleft = DEFBYTL; 
    Filemode = 0; 
    Modtime = 0L;
    Eofseen = FALSE;

    p = Name + 1 + strlen(Name);
    if (*p) { /* file coming from Unix or DOS system */
	sscanf(p, "%d%o%o%o%d%d%d%d", &Bytesleft, &Modtime, &Filemode, &dummy, &dummy, &dummy, &dummy, &dummy);
	strcpy(ctt, rfcdate(Modtime));
    } else {
	Syslog('z', "File coming from a CP/M system");
    }
    Syslog('+', "%s: \"%s\" %ld bytes, %s mode %o", protname(), Name, Bytesleft, ctt, Filemode);

    if (curfile)
	free(curfile);
    curfile = NULL;

    curfile = xstrcpy(CFG.bbs_usersdir);
    curfile = xstrcat(curfile, (char *)"/");
    curfile = xstrcat(curfile, exitinfo.Name);
    curfile = xstrcat(curfile, (char *)"/upl/");
    curfile = xstrcat(curfile, Name);
    Syslog('z', "try open %s mode \"%s\"", curfile, openmode);
    if ((fout = fopen(curfile, openmode)) == NULL) {
	WriteError("$Can't open %s mode %s", curfile, openmode);
    }

    gettimeofday(&starttime, &tz);
    sbytes = rxbytes = 0;

    Syslog('z', "result %s", fout ? "Ok":"Failed");

/*  if (Bytesleft == rxbytes) { FIXME: if file already received, use this.
	Syslog('+', "Zmodem: Skipping %s", Name);
	fout = NULL;
	return ZSKIP;
    } else */ if (!fout) 
	return ZFERR;
    else 
	return 0;
}
예제 #19
0
파일: mkftnhdr.c 프로젝트: ftnapps/FTNd
int ftnmsgid(char *msgid, char **s, unsigned int *n, char *areaname)
{
    char	    *buf, *l, *r, *p;
    unsigned int    nid = 0L;
    faddr	    *tmp;
    static int	    ftnorigin = 0;

    Syslog('m', "Make ftn msgid from \"%s\"", FTND_SS(msgid));

    if (msgid == NULL) {
	*s = NULL;
	*n = 0L;
	return ftnorigin;
    }

    buf = malloc(strlen(msgid)+65);
    strcpy(buf, msgid);
    if ((l = strchr(buf,'<'))) 
	l++;
    else 
	l = buf;
    while (isspace(*l)) 
	l++;
    if ((r = strchr(l,'>'))) 
	*r = '\0';
    r = l + strlen(l) - 1;
    while (isspace(*r) && (r > l)) 
	(*r--)='\0';
    if ((tmp = parsefaddr(l))) {
	if (tmp->name) {
	    if (strspn(tmp->name,"0123456789") == strlen(tmp->name))
		nid = atoul(tmp->name);
	    else 
		nid = 0xffffffff;
	    if (nid == 0xffffffff) {
		hash_update_s(&nid, tmp->name);
	    } else
		ftnorigin = 1;
	} else {
	    hash_update_s(&nid,l);
	}
	*s = xstrcpy(ascfnode(tmp, 0x1f));
	tidy_faddr(tmp);
    } else {
	if ((r=strchr(l,'@')) == NULL) { /* should never happen */
	    Syslog('!', "ftnmsgid: should never happen: %s", printable(l, 0));
	    *s = xstrcpy(l);
	    hash_update_s(&nid,l);
	/* <*****@*****.**> */
	} else if (strncmp(l,"MSGID_",6) == 0) {
	    *r = '\0';
	    r = strrchr(l+6,'_');
            if (r) 
		*r++ = '\0';
            *s = xstrcpy(l+6);
	    if (r) 
		sscanf(r,"%x",&nid);
	    ftnorigin = 1;
	/* <*****@*****.**> */
	} else if (strncmp(l,"NOMSGID_",8) == 0) {
	    *s = NULL;
	    *n = 0L;
	    ftnorigin = 1;
	    return ftnorigin;
	/* <[email protected]> */
	} else if (strncmp(l,"ftn_",4) == 0) {
	    *r = '\0';
	    if ((r = strchr(l+4,'$')) || (r=strchr(l+4,'#'))) {
		if (*r=='$') 
		    *r='@';
		if ((r=strchr(l+4,'.')))
		    *r=':';
		if ((r=strchr(l+4,'.')))
		    *r='/';
	    }
	    while ((r=strrchr(l+4,'_')) != strchr(l+4,'_')) 
		*r='\0';
	    r=strchr(l+4,'_');
	    *r++='\0';
	    *s=xstrcpy(l+4);
	    sscanf(r,"%x",&nid);
	    ftnorigin=1;
	/* <[email protected]> */
	} else if (strncmp(l,"wgcid$",6) == 0) {
	    *r='\0';
	    if ((r=strstr(l+6,"$g"))) {
		*r='\0';
		*s=xstrcpy(l+6);
		*s=xstrcat(*s,(char *)":");
		l=r+2;
	    }
	    if ((r=strstr(l,"$h"))) {
		*r++='\0';
		*s=xstrcat(*s,l);
		*s=xstrcat(*s,(char *)"/");
		l=r+2;
	    }
	    if ((r=strstr(l,"$i"))) {
		*r='\0';
		*s=xstrcat(*s,l);
		*s=xstrcat(*s,(char *)".");
		l=r+2;
	    }
	    if ((r=strstr(l,"$k"))) {
		*r='\0';
		*s=xstrcat(*s,l);
		*s=xstrcat(*s,(char *)"@");
		l=r+2;
	    }
	    if ((r=strstr(l,"$j"))) {
		*r='\0';
		*s=xstrcat(*s,l);
		sscanf(r+2,"%x",&nid);
	    }
	} else {
	    *r='\0';
	    if ((p=strchr(l,'%'))) {
		*p='\0';
		if (strspn(l,"0123456789") == strlen(l)) {
		    *r='@';
		    r=p;
		} else 
		    *p='%';
	    }
	    r++;
	    if (strspn(l,"0123456789") == strlen(l))
		nid = atoul(l);
	    else 
		nid = 0xffffffff;
	    if (nid == 0xffffffff)
		hash_update_s(&nid,l);
	    *s=xstrcpy(r);
	}
    }
    *n=nid;

    free(buf);
    return ftnorigin;
}
예제 #20
0
파일: ftnfutil.c 프로젝트: ftnapps/FTNd
/*
 * Add file to the BBS. The file is in the current directory.
 * The f_db record already has all needed information.
 */
int AddFile(struct FILE_record f_db, int Area, char *DestPath, char *FromPath, char *LinkPath)
{
    int	    	    rc;
    struct _fdbarea *fdb_area = NULL;
    char	    *temp, *dest, *lnk;

    Syslog('f', "AddFile Area    : %d", Area);
    Syslog('f', "AddFile DestPath: %s", FTND_SS(DestPath));
    Syslog('f', "AddFile FromPath: %s", FTND_SS(FromPath));
    Syslog('f', "AddFile LinkPath: %s", FTND_SS(LinkPath));

    /*
     * Copy file to the final destination and make a hard link with the
     * 8.3 filename to the long filename.
     */
    mkdirs(DestPath, 0775);

    if ((file_exist(DestPath, F_OK) == 0) || (file_exist(LinkPath, F_OK) == 0)) {
        if (do_force) {
            Syslog('+', "File %s (%s) already exists in area %d, forced overwrite", f_db.Name, f_db.LName, Area);
        } else {
            WriteError("File %s (%s) already exists in area %d", f_db.Name, f_db.LName, Area);
            if (!do_quiet)
                printf("\nFile %s (%s) already exists in area %d\n", f_db.Name, f_db.LName, Area);
            return FALSE;
        }
    }

    if ((rc = file_cp(FromPath, DestPath))) {
        WriteError("Can't copy file to %s, %s", DestPath, strerror(rc));
        if (!do_quiet)
            printf("\nCan't copy file to %s, %s\n", DestPath, strerror(rc));
        return FALSE;
    }

    chmod(DestPath, 0644);
    if (LinkPath) {
        temp = calloc(PATH_MAX, sizeof(char));
        if (getcwd(temp, PATH_MAX-1)) {
            if (chdir(area.Path)) {
                WriteError("$Can't chdir to %s", area.Path);
                free(temp);
                return FALSE;
            }
            unlink(LinkPath);
            dest = xstrcpy(basename(DestPath));
            lnk = xstrcpy(basename(LinkPath));
            if ((rc = symlink(dest, lnk))) {
                WriteError("Can't create symbolic link %s", lnk);
                if (!do_quiet)
                    printf("\nCan't create symbolic link %s, %s\n", lnk, strerror(rc));
                unlink(DestPath);
                return FALSE;
            }
            free(dest);
            free(lnk);
            chdir(temp);
        }
        free(temp);
    }

    if ((fdb_area = ftnddb_OpenFDB(Area, 30))) {
        rc = ftnddb_InsertFDB(fdb_area, f_db, TRUE);
        ftnddb_CloseFDB(fdb_area);
        return rc;
    } else {
        return FALSE;
    }
}
예제 #21
0
파일: sendbark.c 프로젝트: ftnapps/FTNd
int sendbark(void)
{
	char	*fn;
	FILE	*fp;
	char	buf[256], *p;
	int	rc = 0;

	fn = reqname(remote->addr);
	if ((fp = fopen(fn,"r")) == NULL) {
		Syslog('s', "no request file for this node");
		PUTCHAR(ETB);
		return 0;
	}

	while (fgets(buf,sizeof(buf)-1,fp)) {
		nm = buf;
		pw = strchr(buf, '!');
		dt = strchr(buf, '+');

		if (pw) 
			*pw++= '\0';
		if (dt) 
			*dt++= '\0';

		if (nm) {
			while (isspace(*nm)) 
				nm++;
			for (p = nm; (*p != '!') && (*p != '+') && (!isspace(*p)); p++);
			*p = '\0';
		}

		if (pw) {
			while (isspace(*pw)) 
				pw++;
			for (p = pw; (*p != '!') && (*p != '+') && (!isspace(*p)); p++);
			*p = '\0';
		} else
			pw = (char *)"";

		if (dt) {
			while (isspace(*nm)) 
				nm++;
			for (p = nm; (*p != '!') && (*p != '+') && (*p != '-') && (!isspace(*p)); p++);
			*p = '\0';
		} else
			dt = (char *)"0";

		if (*nm == ';') 
			continue;

		Syslog('+', "Sending bark request for \"%s\", password \"%s\", update \"%s\"",FTND_SS(nm),FTND_SS(pw),FTND_SS(dt));
		if ((rc = send_bark())) 
			break;
	}
	if (rc == 0) 
		PUTCHAR(ETB);
	fclose(fp);
	if (rc == 0) 
		unlink(fn);

	return rc;
}