Example #1
0
int closeit(int success)
{
    struct utimbuf  ut;
    int		    rc;

    Syslog('z', "closeit(%d)", success);
    
    if ((fout == NULL) || (curfile == NULL)) {
	Syslog('+', "closeit(), nothing to close");
	return 1;
    }

    rc = fclose(fout);
    fout = NULL;

    if (rc == 0) {
	ut.actime = Modtime;
	ut.modtime = Modtime;
	if ((rc = utime(curfile, &ut)))
	    WriteError("$utime failed");
    }
    free(curfile);
    curfile = NULL;

    sbytes = rxbytes - sbytes;
    gettimeofday(&endtime, &tz);
    if (success)
        Syslog('+', "%s: OK %s", protname(), transfertime(starttime, endtime, sbytes, FALSE));
    else
	Syslog('+', "%s: dropped after %lu bytes", protname(), sbytes);
    rcvdbytes += sbytes;
    return rc;
}
Example #2
0
/*
 * Receive files with Zmodem, Ymodem or Xmodem.
 * This receiver will figure out what to do, you should
 * be able to send anything.
 */
int zmrcvfiles(int want1k, int wantg)
{
    int	    rc;

    Syslog('+', "%s: start receive", protname());

    get_frame_buffer();

    Rxtimeout = 10;
    if (secbuf == NULL) 
	secbuf = malloc(MAXBLOCK+1);
    tryzhdrtype = ZRINIT;

    if ((rc = tryz()) < 0) {
	Syslog('+', "%s: could not initiate receive, rc=%d", protname(), rc);
    } else {
	if (rc == 0) {
	    if (protocol == ZM_ZMODEM) {
		Syslog('+', "%s: switching to Ymodem", protname());
		protocol = ZM_YMODEM;
	    }
	    rc = ymrcvfiles(want1k, wantg);
	    goto fubar;
	}

	/*
	 * Zmodem receiver
	 */
	switch (rc) {
	    case ZCOMPL:    rc = 0; 
			    break;
	    case ZFILE:	    rc = rzfiles(); 
			    break;
	}
    }
    
fubar:
    if (fout) {
	if (closeit(0)) {
	    WriteError("%s: Error closing file", protname);
	}
    }

    if (secbuf)
	free(secbuf);
    secbuf = NULL;

    io_mode(0, 1);  /* Normal raw mode */
    /*
     * Some programs send some garbage after the transfer, eat these.
     * This also introduces a pause after the transfer, some clients
     * need this.
     */
    purgeline(200);
    
    Syslog('+', "%s: end receive rc=%d", protname(), rc);
    return abs(rc);
}
Example #3
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;
}
Example #4
0
/*
 * Upload files from the user.
 * Returns:
 *  0 - All seems well
 *  1 - No transfer protocol selected.
 *  2 - Transfer failed
 */
int upload(up_list **upload_list)
{
    char	    *temp;
    struct dirent   *dp;
    DIR		    *dirp;
    struct stat	    statfile;
    struct timeval  starttime, endtime;
    struct timezone tz;
    unsigned int    Size = 0;
    int		    err, Count = 0, rc = 0, want1k = FALSE, wantg = FALSE;
    up_list	    *tmp, *ta;

    /*
     * If user has no default protocol, make sure he has one.
     */
    if (!ForceProtocol()) {
	return 1;
    }

    temp  = calloc(PATH_MAX, sizeof(char));

    /* Please start your upload now */
    snprintf(temp, PATH_MAX, "%s, %s", sProtAdvice, (char *) Language(283));
    pout(CFG.HiliteF, CFG.HiliteB, temp);
    Enter(2);
    Syslog('+', "Upload using %s", sProtName);

    snprintf(temp, PATH_MAX, "%s/%s/upl", CFG.bbs_usersdir, exitinfo.Name);

    if (chdir(temp)) {
	WriteError("$Can't chdir to %s", temp);
	free(temp);
	return 1;
    }
    sleep(2);

    if (uProtInternal) {
	if ((strncasecmp(sProtName, "zmodem", 6) == 0) || 
	    (strncasecmp(sProtName, "ymodem", 6) == 0) || 
	    (strncasecmp(sProtName, "xmodem", 6) == 0)) {

	    if (strncasecmp(sProtName, "zmodem", 6) == 0) {
		zmodem_requested = TRUE;
		protocol = ZM_ZMODEM;
	    } else {
		zmodem_requested = FALSE;
	    }
	    if (strncasecmp(sProtName, "ymodem", 6) == 0)
		protocol = ZM_YMODEM;
	    if (strncasecmp(sProtName, "xmodem", 6) == 0)
		protocol = ZM_XMODEM;

	    if (strstr(sProtName, "-1K") && (protocol != ZM_ZMODEM)) {
		Syslog('x', "%s: want 1K blocks", protname());
		want1k = TRUE;
	    }
	    if ((strstr(sProtName, "-G")) && (protocol == ZM_YMODEM)) {
		Syslog('x', "%s: want Ymodem-G", protname());
		wantg = TRUE;
	    }
	    rc = zmrcvfiles(want1k, wantg);

	    Syslog('b', "Begin dir processing");
	    if ((dirp = opendir(".")) == NULL) {
	        WriteError("$Upload: can't open ./upl");
	        Home();
	        rc = 1;
	    } else {
	        while ((dp = readdir(dirp)) != NULL) {
		    if (*(dp->d_name) != '.') {
			if (rc == 0) {
			    stat(dp->d_name, &statfile);
			    Syslog('b', "Uploaded \"%s\", %ld bytes", dp->d_name, statfile.st_size);
			    snprintf(temp, PATH_MAX, "%s/%s/upl/%s", CFG.bbs_usersdir, exitinfo.Name, dp->d_name);
			    chmod(temp, 0660);

			    /*
			     * Add uploaded file to the list
			     */
			    tmp = (up_list *)malloc(sizeof(up_list));
			    tmp->next = NULL;
			    tmp->filename = xstrcpy(temp);
			    tmp->size = Size;
			    if (*upload_list == NULL) {
				*upload_list = tmp;
			    } else {
				for (ta = *upload_list; ta; ta = ta->next) {
				    if (ta->next == NULL) {
					ta->next = (up_list *)tmp;
					break;
				    }
				}
			    }
			} else {
			    Syslog('+', "Remove failed %s result %d", dp->d_name, unlink(dp->d_name));
			}
		    }
		}
		closedir(dirp);
	    }
	} else {
	    Syslog('!', "Internal protocol %s not supported", sProtName);
	    free(temp);
	    return 1;
	}
    } else {
	/*
	 * External protocol
	 */
	gettimeofday(&starttime, &tz);
    
	Altime(7200);
	alarm_set(7190);
	err = execute_str(sProtUp, (char *)"", NULL, NULL, NULL, NULL);
	if (rawport() != 0) {
	    WriteError("Unable to set raw mode");
	}
	if (err) {
	    WriteError("$Upload error %d, prot: %s", err, sProtUp);
	    rc = 2;
	}
	Altime(0);
	alarm_off();
	alarm_on();

	gettimeofday(&endtime, &tz);

	/*
	 * With external protocols we don't know anything about what we got.
	 * Just check the files in the users upload directory.
	 */
	if ((dirp = opendir(".")) == NULL) {
	    WriteError("$Upload: can't open ./upl");
	    Home();
	    rc = 1;
	} else {
	    while ((dp = readdir(dirp)) != NULL) {
		if (*(dp->d_name) != '.') {
		    stat(dp->d_name, &statfile);
		    Syslog('+', "Uploaded \"%s\", %ld bytes", dp->d_name, statfile.st_size);
		    Count++;
		    Size += statfile.st_size;
		    snprintf(temp, PATH_MAX, "%s/%s/upl/%s", CFG.bbs_usersdir, exitinfo.Name, dp->d_name);
		    chmod(temp, 0660);

		    /*
		     * Add uploaded file to the list
		     */
		    tmp = (up_list *)malloc(sizeof(up_list));
		    tmp->next = NULL;
		    tmp->filename = xstrcpy(temp);
		    tmp->size = Size;

		    if (*upload_list == NULL) {
			*upload_list = tmp;
		    } else {
			for (ta = *upload_list; ta; ta = ta->next) {
			    if (ta->next == NULL) {
				ta->next = (up_list *)tmp;
				break;
			    }
			}
		    }
		}
	    }
	    closedir(dirp);
	    Syslog('+', "Upload %s in %d file(s)", transfertime(starttime, endtime, (unsigned int)Size, FALSE), Count);
	}
    }
    free(temp);
    Syslog('b', "Done, return rc=%d", rc);

    return rc;
}