Пример #1
0
int add_cgi_env(request * req, const char *key, const char *value,
                int http_prefix)
{
    char *p;
    unsigned int prefix_len;

    if (http_prefix) {
        prefix_len = 5;
    } else {
        prefix_len = 0;
    }

    if (req->cgi_env_index < CGI_ENV_MAX) {
        p = env_gen_extra(key, value, prefix_len);
        if (!p) {
            log_error_doc(req);
            fprintf(stderr,
                    "Unable to generate additional CGI environment "
                    "variable -- ran out of memory!\n");
            return 0;
        }
        if (prefix_len)
            memcpy(p, "HTTP_", 5);
        req->cgi_env[req->cgi_env_index++] = p;
        return 1;
    }
    log_error_doc(req);
    fprintf(stderr, "Unable to generate additional CGI Environment "
            "variable \"%s%s=%s\" -- not enough space!\n",
            (prefix_len ? "HTTP_" : ""), key, value);
    return 0;
}
Пример #2
0
void create_common_env()
{
    int index = 0, i;


    /* NOTE NOTE NOTE:
       If you (the reader) someday modify this chunk of code to
       handle more "common" CGI environment variables, then bump the
       value COMMON_CGI_COUNT in defines.h UP

       Also, in the case of document_root and server_admin, two variables
       that may or may not be defined depending on the way the server
       is configured, we check for null values and use an empty
       string to denote a NULL value to the environment, as per the
       specification. The quote for which follows:

       "In all cases, a missing environment variable is
       equivalent to a zero-length (NULL) value, and vice versa."
     */
    common_cgi_env[index++] = env_gen_extra("PATH",
                                            ((cgi_path != NULL) ? cgi_path : DEFAULT_PATH), 0);
    common_cgi_env[index++] = env_gen_extra("SERVER_SOFTWARE", SERVER_VERSION, 0);
    common_cgi_env[index++] = env_gen_extra("SERVER_NAME", server_name, 0);
    common_cgi_env[index++] = env_gen_extra("GATEWAY_INTERFACE", CGI_VERSION, 0);

    common_cgi_env[index++] =
        env_gen_extra("SERVER_PORT", simple_itoa(server_port), 0);

    /* NCSA and APACHE added -- not in CGI spec */
    common_cgi_env[index++] = env_gen_extra("DOCUMENT_ROOT", document_root,0);

    /* NCSA added */
    common_cgi_env[index++] = env_gen_extra("SERVER_ROOT", server_root,0);

    /* APACHE added */
    common_cgi_env[index++] = env_gen_extra("SERVER_ADMIN", server_admin, 0);
    common_cgi_env[index] = NULL;

    /* Sanity checking -- make *sure* the memory got allocated */
    if (index > COMMON_CGI_COUNT) {
        log_error_time();
        fprintf(stderr, "COMMON_CGI_COUNT not high enough.\n");
        exit(1);
    }

    for(i = 0; i < index; ++i) {
        if (common_cgi_env[i] == NULL) {
            log_error_time();
            fprintf(stderr, "Unable to allocate a component of common_cgi_env - out of memory.\n");
            exit(1);
        }
    }
}
Пример #3
0
void add_cgi_env(request * req, char *key, char *value)
{
	char *p;

	if (req->cgi_env_index >= (MAX_CGI_VARS - 17))	/* 16 in complete_env */
		return;

	p = env_gen_extra(key, value, 5);
	memcpy(p, "HTTP_", 5);
	req->cgi_env[req->cgi_env_index++] = p;
	req->cgi_env[req->cgi_env_index] = 0;           /* fix cgi_env */
}
Пример #4
0
void add_to_common_env(char *key, char *value)
{
    common_cgi_env = realloc(common_cgi_env, (common_cgi_env_count + 2) * (sizeof(char *)));
    if (common_cgi_env== NULL) {
        DIE("Unable to allocate memory for common CGI environment variable.");
    }
    common_cgi_env[common_cgi_env_count] = env_gen_extra(key,value, 0);
    if (common_cgi_env[common_cgi_env_count] == NULL) {
        /* errors already reported */
        DIE("memory allocation failure in add_to_common_env");
    }
    common_cgi_env[++common_cgi_env_count] = NULL;
    /* I find it hard to believe that somebody would actually
     * make 90+ *common* CGI variables, but it's always better
     * to be safe.
     */
    if (common_cgi_env_count > CGI_ENV_MAX) {
        DIE("far too many common CGI environment variables added.");
    }
}