Ejemplo n.º 1
0
void show_last_call_in(int save) {
    char buf[200];

    sprintf(buf, "\033[1;33;46m★%s\033[37;45m %s \033[m",
	    currutmp->msgs[0].last_userid,
	    currutmp->msgs[0].last_call_in);
    move(b_lines, 0);
    clrtoeol();
    refresh();
    outmsg(buf);
    
    if(save) {
	char genbuf[200];
	time_t now;
	extern FILE *fp_writelog;
	
	if(fp_writelog == NULL) {
	    sethomefile(genbuf, cuser.userid, fn_writelog);
	    fp_writelog = fopen(genbuf, "a");
	}
	if(fp_writelog) {
	    time(&now);
	    fprintf(fp_writelog, 
		    "%s \033[0m[%s]\n",
		    buf, Cdatelite(&now));
	}
    }
}
Ejemplo n.º 2
0
static int
pwcuFinalCUser(userec_t *u)
{
    assert(usernum > 0 && usernum <= MAX_USERS);
    assert(strcmp(u->userid, cuser.userid) == 0);
#ifdef DEBUG
    log_filef("log/pwcu_exitsave.log", LOG_CREAT, "%s FinalCUser invoked at %s\n",
	    cuser.userid, Cdatelite(&now));
#endif
    if (passwd_sync_update(usernum, u) != 0)
	return -1;
    return 0;
}
Ejemplo n.º 3
0
// XXX this is a little different - only invoked at exist,
// so no need to sync back to cuser.
int
pwcuExitSave	()
{
    // determine dirty
    if (pwcu_dirty	||
	cuser.withme	!= currutmp->withme ||
	cuser.pager	!= currutmp->pager  ||
	cuser.invisible != currutmp->invisible)
    {
	// maybe dirty, let's work harder.
	PWCU_START();
	pwcu_dirty = 1;

	// XXX we may work harder to determine if this is a real
	// dirty cache, however maybe it's not that important.

	// configure new utmp values
	u.withme    = currutmp->withme;
	u.pager     = currutmp->pager;
	u.invisible = currutmp->invisible;

	// configure those changed by 'not important variables' API
	u.signature	= cuser.signature;
	u.pager_ui_type = cuser.pager_ui_type;
	// u.money		= moneyof(usernum); // should be already updated by deumoney

#ifdef DEBUG
	log_filef("log/pwcu_exitsave.log", LOG_CREAT, "%s exit %s at %s\n",
		cuser.userid, pwcu_dirty ? "DIRTY" : "CLEAN", Cdatelite(&now));
#endif
	PWCU_END();
	// XXX return 0 here (PWCU_END), following code is not executed.
    }
#ifdef DEBUG
	log_filef("log/pwcu_exitsave.log", LOG_CREAT, "%s exit %s at %s\n",
		cuser.userid, pwcu_dirty ? "DIRTY" : "CLEAN", Cdatelite(&now));
#endif
    return 0;
}
Ejemplo n.º 4
0
static int
pwcuInitCUser(userec_t *u)
{
    assert(usernum > 0 && usernum <= MAX_USERS);
    if (passwd_sync_query(usernum, u) != 0)
	return -1;
#ifdef DEBUG
    log_filef("log/pwcu_exitsave.log", LOG_CREAT, "%s InitCUser  invoked at %s\n",
	    cuser.userid, Cdatelite(&now));
#endif
    assert(strncmp(u->userid, cuser.userid, IDLEN) == 0);
    if    (strncmp(u->userid, cuser.userid, IDLEN) != 0)
	return -1;
    return 0;
}
Ejemplo n.º 5
0
int
append_record_forward(char *fpath, fileheader_t * record, int size, const char *origid)
{
    FILE *fp;
    char buf[PATHLEN];
    char address[64] = "";
    char fwd_title[STRLEN] = "";
    int r;

    // No matter what, append it, and return if that failed.
    r = append_record(fpath, record, size);
    if (r < 0)
        return r;

// #ifdef USE_MAIL_AUTO_FORWARD

    if (strlen(fpath) + strlen(FN_FORWARD) >= PATHLEN) {
        log_filef("log/invalid_append_record_forward", LOG_CREAT,
                  "%s %s %s\n", Cdatelite(&now), cuser.userid, fpath);
        return -1;
    }
    setdirpath(buf, fpath, FN_FORWARD);
    fp = fopen(buf, "r");
    if (!fp)
        return 0;

    // Load and setup address
    address[0] = 0;
    fscanf(fp, "%63s", address);
    fclose(fp);
    chomp(address);
    strip_blank(address, address);

#ifdef UNTRUSTED_FORWARD_TIMEBOMB
    if (dasht(buf) < UNTRUSTED_FORWARD_TIMEBOMB) {
        // We may unlink here, but for systems with timebomb,
        // just leave it alone and let user see it in login screen.
        // unlink(buf);
        return 0;
    }
#endif

    if (get_num_records(fpath, sizeof(fileheader_t)) > MAX_KEEPMAIL_HARDLIMIT) {
        unlink(buf);
        // TODO add a mail so that origid knows what happened.
        LOG_IF(LOG_CONF_INTERNETMAIL,
               log_filef("log/internet_mail.log", LOG_CREAT, 
                         "%s [%s] (%s -> %s) mailbox overflow (%d > %d)\n",
                         Cdatelite(&now), __FUNCTION__,
                         origid, address,
                         get_num_records(fpath, sizeof(fileheader_t)),
                         MAX_KEEPMAIL_HARDLIMIT));
        return 0;
    }


    if (!*address ||
        strchr(address, '@') == NULL ||
        strcasestr(address, str_mail_address)) {
#ifndef UNTRUSTED_FORWARD_TIMEBOMB
        // delete the setting if we don't have timebombs.
        unlink(buf);
        LOG_IF(LOG_CONF_INTERNETMAIL,
               log_filef("log/internet_mail.log", LOG_CREAT, 
                         "%s [%s] Removed bad address: %s (%s)\n",
                         Cdatelite(&now), __FUNCTION__,
                         address, origid));
#endif
        return 0;
    }

    setdirpath(buf, fpath, record->filename);
    // because too many user set wrong forward address,
    // let's put their own address instead. 
    // and again because some really stupid user
    // does not understand they've set auto-forward,
    // let's mark this in the title.
    snprintf(fwd_title, sizeof(fwd_title)-1,
             "[自動轉寄] %s", record->title);
    bsmtp(buf, fwd_title, address, origid);
    LOG_IF(LOG_CONF_INTERNETMAIL,
           log_filef("log/internet_mail.log", LOG_CREAT, 
                     "%s [%s] %s -> (%s) %s: %s\n",
                     Cdatelite(&now), __FUNCTION__,
                     cuser.userid, origid, address, fwd_title));
// #endif // USE_MAIL_AUTO_FORWARD
    return 0;
}
Ejemplo n.º 6
0
// Delete and archive the physical (except header) of file
//
// if backup_direct is provided, backup according to that directory.
// if backup_path points to buffer, return back the backuped file
// Return -1 if cannot delete file, 0 for success,
// 1 if delete success but backup failed.
int
delete_file_content2(const char *direct, const fileheader_t *fh,
                     const char *backup_direct,
                     char *backup_path, size_t sz_backup_path,
                     const char *reason) {
    char fpath[PATHLEN];
    fileheader_t backup = { {0} };
    int backup_failed = DELETE_FILE_CONTENT_SUCCESS;

    if(!fh->filename[0] || !direct)
        return DELETE_FILE_CONTENT_FAILED;

#ifdef FN_SAFEDEL
    if (
#ifdef FN_SAFEDEL_PREFIX_LEN
            strncmp(fh->filename, FN_SAFEDEL, FN_SAFEDEL_PREFIX_LEN) == 0 ||
#endif
            strcmp(fh->filename, FN_SAFEDEL) == 0 ||
#endif
        0)
        return DELETE_FILE_CONTENT_SUCCESS;

    if (backup_path) {
        assert(backup_direct);
        assert(sz_backup_path > 0);
        *backup_path = 0;
    }

    // solve source file name
    setdirpath(fpath, direct, fh->filename);
    if (!dashf(fpath))
        return DELETE_FILE_CONTENT_BACKUP_FAILED;

    // FIXME some announcements were made by sym-links, especial for those
    // in mail. we should ignore them.
    if (backup_direct &&
        !dashl(fpath) &&
        strncmp(fh->owner, RECYCLE_BIN_OWNER, strlen(RECYCLE_BIN_OWNER)) != 0) {

        // FIXME maybe for non-board files we should do this by simply touching
        // file instead of full log.
        if (reason && *reason)
            log_filef(fpath,  LOG_CREAT, "\n※ 刪除原因: %s", reason);
        log_filef(fpath,  LOG_CREAT, "\n※ Deleted by: %s (%s) %s\n",
                  cuser.userid, fromhost, Cdatelite(&now));

        // TODO or only memcpy(&backup, fh, sizeof(backup)); ?
        strlcpy(backup.owner, fh->owner, sizeof(backup.owner));
        strlcpy(backup.date, fh->date, sizeof(backup.date));
        strlcpy(backup.title, fh->title, sizeof(backup.title));
        strlcpy(backup.filename, fh->filename, sizeof(backup.filename));

        if (backup_direct != direct &&
            strcmp(backup_direct, direct) != 0) {
            // need to create a new file entry.
            char *slash = NULL;
            char bakpath[PATHLEN];

            strlcpy(bakpath, backup_direct, sizeof(bakpath));
            slash = strrchr(bakpath, '/');
            if (slash)
                *slash = 0;
            if (stampfile_u(bakpath, &backup) == 0 &&
                Rename(fpath, bakpath) == 0) {
                strlcpy(fpath, bakpath, sizeof(fpath));
            } else {
                backup_direct = NULL;
                backup_failed = 1;
            }
        }

        // now, always backup according to fpath
        if (backup_direct) {
#ifdef USE_TIME_CAPSULE
            if (!timecapsule_archive_new_revision(
                        fpath, &backup, sizeof(backup),
                        backup_path, sz_backup_path))
                backup_failed = DELETE_FILE_CONTENT_BACKUP_FAILED;
#else
            // we can't backup to same folder.
            if (strcmp(direct, backup_direct) == 0) {
                backup_failed = DELETE_FILE_CONTENT_BACKUP_FAILED;
            } else {
                if (append_record(backup_direct, &backup, sizeof(backup)) < 0)
                    backup_failed = DELETE_FILE_CONTENT_BACKUP_FAILED;
                if (backup_path)
                    strlcpy(backup_path, fpath, sz_backup_path);
            }
            // the fpath is used as-is.
            *fpath = 0;
#endif
        }
    }

    // the file should be already in time capsule
    if (*fpath && unlink(fpath) != 0)
        return DELETE_FILE_CONTENT_FAILED;
    return backup_failed;
}