FILE *ApacheRequest_tmpfile(ApacheRequest *req, ApacheUpload *upload) { request_rec *r = req->r; FILE *fp; char prefix[] = "apreq"; char *name = NULL; int fd = 0; int tries = 100; while (--tries > 0) { if ( (name = tempnam(req->temp_dir, prefix)) == NULL ) continue; fd = ap_popenf(r->pool, name, O_CREAT|O_EXCL|O_RDWR|O_BINARY, 0600); if ( fd >= 0 ) break; /* success */ else free(name); } if ( tries == 0 || (fp = ap_pfdopen(r->pool, fd, "w+" "b") ) == NULL ) { ap_log_rerror(REQ_ERROR, "[libapreq] could not create/open temp file"); if ( fd >= 0 ) { remove(name); free(name); } return NULL; } upload->fp = fp; upload->tempname = name; ap_register_cleanup(r->pool, (void *)upload, remove_tmpfile, ap_null_cleanup); return fp; }
/* * Open the SSL logfile */ void ssl_log_open(server_rec *s_main, server_rec *s, pool *p) { char *szLogFile; SSLSrvConfigRec *sc_main = mySrvConfig(s_main); SSLSrvConfigRec *sc = mySrvConfig(s); piped_log *pl; char *cp; /* * Short-circuit for inherited logfiles in order to save * filedescriptors in mass-vhost situation. Be careful, this works * fine because the close happens implicitly by the pool facility. */ if ( s != s_main && sc_main->fileLogFile != NULL && ( (sc->szLogFile == NULL) || ( sc->szLogFile != NULL && sc_main->szLogFile != NULL && strEQ(sc->szLogFile, sc_main->szLogFile)))) { sc->fileLogFile = sc_main->fileLogFile; } else if (sc->szLogFile != NULL) { if (strEQ(sc->szLogFile, "/dev/null")) return; else if (sc->szLogFile[0] == '|') { cp = sc->szLogFile+1; while (*cp == ' ' || *cp == '\t') cp++; szLogFile = ssl_util_server_root_relative(p, "log", cp); if ((pl = ap_open_piped_log(p, szLogFile)) == NULL) { ssl_log(s, SSL_LOG_ERROR|SSL_ADD_ERRNO, "Cannot open reliable pipe to SSL logfile filter %s", szLogFile); ssl_die(); } sc->fileLogFile = ap_pfdopen(p, ap_piped_log_write_fd(pl), "a"); setbuf(sc->fileLogFile, NULL); } else { szLogFile = ssl_util_server_root_relative(p, "log", sc->szLogFile); if ((sc->fileLogFile = ap_pfopen(p, szLogFile, "a")) == NULL) { ssl_log(s, SSL_LOG_ERROR|SSL_ADD_ERRNO, "Cannot open SSL logfile %s", szLogFile); ssl_die(); } setbuf(sc->fileLogFile, NULL); } } return; }