Пример #1
0
static void preserve_entry(request_rec *r, const char *query)
{
	logsql_state *cls = ap_get_module_config(r->server->module_config,
											&log_sql_module);
	#if defined(WITH_APACHE20)
		apr_file_t *fp;
		apr_status_t result;
	#elif defined(WITH_APACHE13)
		FILE *fp;
		int result;
	#endif
	/* If preserve file is disabled bail out */
	if (global_config.disablepreserve)
       return;
    #if defined(WITH_APACHE20)
		result = apr_file_open(&fp, cls->preserve_file,APR_APPEND | APR_WRITE | APR_CREATE, APR_OS_DEFAULT, r->pool);
    #elif defined(WITH_APACHE13)
		fp = ap_pfopen(r->pool, cls->preserve_file, "a");
		result = (fp)?0:errno;
    #endif
    if (result != APR_SUCCESS) {
		log_error(APLOG_MARK, APLOG_ERR, result, r->server,
			"attempted append of local preserve file '%s' but failed.",cls->preserve_file);
	} else {
		#if defined(WITH_APACHE20)
			apr_file_printf(fp,"%s;\n", query);
			apr_file_close(fp);
		#elif defined(WITH_APACHE13)
			fprintf(fp,"%s;\n", query);
			ap_pfclose(r->pool, fp);
		#endif
		log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
			"mod_log_sql: entry preserved in %s", cls->preserve_file);
	}
}
Пример #2
0
static char *ssl_expr_eval_func_file(request_rec *r, char *filename)
{
    FILE *fp;
    char *buf;
    int len;

    if ((fp = ap_pfopen(r->pool, filename, "r")) == NULL) {
        ssl_expr_error = "Cannot open file";
        return "";
    }
    fseek(fp, 0, SEEK_END);
    len = ftell(fp);
    if (len == 0) {
        buf = (char *)ap_palloc(r->pool, sizeof(char) * 1);
        *buf = NUL;
    }
    else {
        if ((buf = (char *)ap_palloc(r->pool, sizeof(char) * (len+1))) == NULL) {
            ssl_expr_error = "Cannot allocate memory";
            ap_pfclose(r->pool, fp);
            return "";
        }
        fseek(fp, 0, SEEK_SET);
        if (fread(buf, len, 1, fp) == 0) {
            ssl_expr_error = "Cannot read from file";
            fclose(fp);
            return ("");
        }
        buf[len] = NUL;
    }
    ap_pfclose(r->pool, fp);
    return buf;
}
Пример #3
0
apr_status_t jxr_send_file_add_header(jaxer_connection * ac, char *fname, enum BlockType bType)
{
	apr_status_t rv;
	Jaxer_Header jx_hdr;
	request_rec* r = ac->request;
	int rc;
        int n;
        FILE *f;
        char buf[HUGE_STRING_LEN];

	compat_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "mod_jaxer: sending a brigade and add header (type=%s sock=%d)", 
		sBlockType[bType], ac->sock);

	f = ap_pfopen(r->pool, fname, "r");
	if (f == NULL) {
            ap_log_rerror(APLOG_MARK, APLOG_ERR, r, "Could not open file %s",
                      fname);
        }
        while (1) {
            apr_size_t pos;
            while ((n = fread(buf, sizeof(char), HUGE_STRING_LEN, f)) < 1
                   && ferror(f) && errno == EINTR && !r->connection->aborted)
                continue;

            if (n < 1) {
                break;
            }

		jxr_msg_init((unsigned char*) &jx_hdr, &pos, bType);
		pos += n;
		jxr_msg_end((unsigned char*) &jx_hdr, &pos);

		compat_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "mod_jaxer: sending header");

		rc = jxr_socket_sendfull(ac, (unsigned char*)&jx_hdr, (int) sizeof(Jaxer_Header));
		if(rc < 0)
		{
			compat_log_rerror(APLOG_MARK, APLOG_WARNING, rc, r, "mod_jaxer: read data from socket error");
			return HTTP_INTERNAL_SERVER_ERROR;
		}

		compat_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "mod_jaxer: sending body (len=%d)", n);

		rc = jxr_socket_sendfull(ac, buf, (int)n );
		if(rc < 0)
		{
			compat_log_rerror(APLOG_MARK, APLOG_WARNING, rc, r, "mod_jaxer: read data from socket error");
			return HTTP_INTERNAL_SERVER_ERROR;
		}
	}


	compat_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "mod_jaxer: sent a brigade and added header (type=%s sock=%d)", 
		sBlockType[bType], ac->sock);

	return APR_SUCCESS;
}
Пример #4
0
static int asis_handler(request_rec *r)
{
    FILE *f;
    const char *location;

    r->allowed |= (1 << M_GET);
    if (r->method_number != M_GET)
	return DECLINED;
    if (r->finfo.st_mode == 0) {
	ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, r,
		    "File does not exist: %s", r->filename);
	return NOT_FOUND;
    }

    f = ap_pfopen(r->pool, r->filename, "r");

    if (f == NULL) {
	ap_log_rerror(APLOG_MARK, APLOG_ERR, r,
		    "file permissions deny server access: %s", r->filename);
	return FORBIDDEN;
    }

    ap_scan_script_header_err(r, f, NULL);
    location = ap_table_get(r->headers_out, "Location");

    if (location && location[0] == '/' &&
	((r->status == HTTP_OK) || ap_is_HTTP_REDIRECT(r->status))) {

	ap_pfclose(r->pool, f);

	/* Internal redirect -- fake-up a pseudo-request */
	r->status = HTTP_OK;

	/* This redirect needs to be a GET no matter what the original
	 * method was.
	 */
	r->method = ap_pstrdup(r->pool, "GET");
	r->method_number = M_GET;

	ap_internal_redirect_handler(location, r);
	return OK;
    }

    ap_send_http_header(r);
    if (!r->header_only)
	ap_send_fd(f, r);

    ap_pfclose(r->pool, f);
    return OK;
}
Пример #5
0
/*
 * 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;
}
Пример #6
0
static void open_error_log (server_rec *s, pool *p)
{
    char *fname;

    if (*s->error_fname == '|') {
	FILE *dummy;

	if (!ap_spawn_child(p, error_log_child, (void *)(s->error_fname+1),
			    kill_after_timeout, &dummy, NULL, NULL)) {
	    perror ("ap_spawn_child");
	    fprintf (stderr, "Couldn't fork child for ErrorLog process\n");
	    exit (1);
	}

	s->error_log = dummy;
    }

#ifdef HAVE_SYSLOG
    else if (!strncasecmp(s->error_fname, "syslog", 6)) {
	if ((fname = strchr(s->error_fname, ':'))) {
	    const TRANS *fac;

	    fname++;
	    for (fac = facilities; fac->t_name; fac++) {
		if (!strcasecmp(fname, fac->t_name)) {
		    openlog("httpd", LOG_NDELAY|LOG_CONS|LOG_PID, fac->t_val);
		    s->error_log = NULL;
		    return;
		}
	    }
	}
	else
	    openlog("httpd", LOG_NDELAY|LOG_CONS|LOG_PID, LOG_LOCAL7);

	s->error_log = NULL;
    }
#endif
    else {
	fname = ap_server_root_relative (p, s->error_fname);
        if(!(s->error_log = ap_pfopen(p, fname, "a"))) {
            perror("fopen");
            fprintf(stderr,"httpd: could not open error log file %s.\n", fname);
            exit(1);
	}
    }
}