/* * Open the log file. Takes care of detecting an already-existing * file and asking the user whether they want to append, overwrite * or cancel logging. */ void logfopen(void *handle) { struct LogContext *ctx = (struct LogContext *)handle; struct tm tm; int mode; /* Prevent repeat calls */ if (ctx->state != L_CLOSED) return; if (!ctx->cfg.logtype) return; tm = ltime(); /* substitute special codes in file name */ xlatlognam(&ctx->currlogfilename, ctx->cfg.logfilename,&ctx->cfg, &tm); ctx->lgfp = f_open(&ctx->currlogfilename, "r", FALSE); /* file already present? */ if (ctx->lgfp) { fclose(ctx->lgfp); if (ctx->cfg.logxfovr != LGXF_ASK) { mode = ((ctx->cfg.logxfovr == LGXF_OVR) ? 2 : 1); } else mode = askappend(ctx->frontend, ctx->currlogfilename, logfopen_callback, ctx); } else mode = 2; /* create == overwrite */ if (mode < 0) ctx->state = L_OPENING; else logfopen_callback(ctx, mode); /* open the file */ }
/* open log file append/overwrite mode */ void logfopen(void *handle) { struct LogContext *ctx = (struct LogContext *)handle; char buf[256]; time_t t; struct tm tm; char writemod[4]; /* Prevent repeat calls */ if (ctx->lgfp) return; if (!ctx->cfg.logtype) return; sprintf(writemod, "wb"); /* default to rewrite */ time(&t); tm = *localtime(&t); /* substitute special codes in file name */ xlatlognam(&ctx->currlogfilename, ctx->cfg.logfilename,ctx->cfg.host, &tm); ctx->lgfp = f_open(ctx->currlogfilename, "r"); /* file already present? */ if (ctx->lgfp) { int i; fclose(ctx->lgfp); if (ctx->cfg.logxfovr != LGXF_ASK) { i = ((ctx->cfg.logxfovr == LGXF_OVR) ? 2 : 1); } else i = askappend(ctx->frontend, ctx->currlogfilename); if (i == 1) writemod[0] = 'a'; /* set append mode */ else if (i == 0) { /* cancelled */ ctx->lgfp = NULL; ctx->cfg.logtype = 0; /* disable logging */ return; } } ctx->lgfp = f_open(ctx->currlogfilename, writemod); if (ctx->lgfp) { /* enter into event log */ /* --- write header line into log file */ fputs("=~=~=~=~=~=~=~=~=~=~=~= PuTTY log ", ctx->lgfp); strftime(buf, 24, "%Y.%m.%d %H:%M:%S", &tm); fputs(buf, ctx->lgfp); fputs(" =~=~=~=~=~=~=~=~=~=~=~=\r\n", ctx->lgfp); sprintf(buf, "%s session log (%s mode) to file: ", (writemod[0] == 'a') ? "Appending" : "Writing new", (ctx->cfg.logtype == LGTYP_ASCII ? "ASCII" : ctx->cfg.logtype == LGTYP_DEBUG ? "raw" : ctx->cfg.logtype == LGTYP_PACKETS ? "SSH packets" : "<ukwn>")); /* Make sure we do not exceed the output buffer size */ strncat(buf, filename_to_str(&ctx->currlogfilename), 128); buf[strlen(buf)] = '\0'; logevent(ctx->frontend, buf); } }
/* * Open the log file. Takes care of detecting an already-existing * file and asking the user whether they want to append, overwrite * or cancel logging. */ void logfopen(void *handle) { struct LogContext *ctx = (struct LogContext *)handle; struct tm tm; FILE *fp; int mode; /* Prevent repeat calls */ if (ctx->state != L_CLOSED) return; if (!ctx->logtype) return; tm = ltime(); /* substitute special codes in file name */ if (ctx->currlogfilename) filename_free(ctx->currlogfilename); ctx->currlogfilename = xlatlognam(conf_get_filename(ctx->conf, CONF_logfilename), conf_get_str(ctx->conf, CONF_host), conf_get_int(ctx->conf, CONF_port), &tm); #ifdef PERSOPORT test_dir( /*&*/ctx->currlogfilename ) ; #endif fp = f_open(ctx->currlogfilename, "r", FALSE); /* file already present? */ if (fp) { int logxfovr = conf_get_int(ctx->conf, CONF_logxfovr); fclose(fp); if (logxfovr != LGXF_ASK) { mode = ((logxfovr == LGXF_OVR) ? 2 : 1); } else mode = askappend(ctx->frontend, ctx->currlogfilename, logfopen_callback, ctx); } else mode = 2; /* create == overwrite */ if (mode < 0) ctx->state = L_OPENING; else logfopen_callback(ctx, mode); /* open the file */ }