int Ganglia_value_send( Ganglia_metric gmetric, Ganglia_udp_send_channels send_channels ) { int len, i; XDR x; char gmetricmsg[GANGLIA_MAX_MESSAGE_LEN]; Ganglia_value_msg msg; const apr_array_header_t *arr; const apr_table_entry_t *elts; const char *spoof = SPOOF; apr_pool_t *gm_pool=(apr_pool_t*)gmetric->pool; if (myhost[0] == '\0') apr_gethostname( (char*)myhost, APRMAXHOSTLEN+1, gm_pool); msg.id = gmetric_string; msg.Ganglia_value_msg_u.gstr.metric_id.host = apr_pstrdup (gm_pool, (char*)myhost); msg.Ganglia_value_msg_u.gstr.metric_id.name = apr_pstrdup (gm_pool, gmetric->msg->name); msg.Ganglia_value_msg_u.gstr.metric_id.spoof = FALSE; msg.Ganglia_value_msg_u.gstr.fmt = apr_pstrdup (gm_pool, "%s"); msg.Ganglia_value_msg_u.gstr.str = apr_pstrdup (gm_pool, gmetric->value); arr = apr_table_elts(gmetric->extra); elts = (const apr_table_entry_t *)arr->elts; /* add all of the metadata to the packet */ for (i = 0; i < arr->nelts; ++i) { if (elts[i].key == NULL) continue; /* Replace the host name with the spoof host if it exists in the metadata */ if ((apr_toupper(elts[i].key[0]) == spoof[0]) && strcasecmp(SPOOF_HOST, elts[i].key) == 0) { msg.Ganglia_value_msg_u.gstr.metric_id.host = apr_pstrdup (gm_pool, elts[i].val); msg.Ganglia_value_msg_u.gstr.metric_id.spoof = TRUE; } if ((apr_toupper(elts[i].key[0]) == spoof[0]) && strcasecmp(SPOOF_HEARTBEAT, elts[i].key) == 0) { msg.Ganglia_value_msg_u.gstr.metric_id.name = apr_pstrdup (gm_pool, "heartbeat"); msg.Ganglia_value_msg_u.gstr.metric_id.spoof = TRUE; } } /* Send the message */ xdrmem_create(&x, gmetricmsg, GANGLIA_MAX_MESSAGE_LEN, XDR_ENCODE); if(!xdr_Ganglia_value_msg(&x, &msg)) { return 1; } len = xdr_getpos(&x); /* Send the encoded data along...*/ return Ganglia_udp_send_message( send_channels, gmetricmsg, len); }
static int strnatcmp0(char const *a, char const *b, int fold_case) { int ai, bi; char ca, cb; int fractional, result; ai = bi = 0; while (1) { ca = a[ai]; cb = b[bi]; /* skip over leading spaces or zeros */ while (apr_isspace(ca)) ca = a[++ai]; while (apr_isspace(cb)) cb = b[++bi]; /* process run of digits */ if (apr_isdigit(ca) && apr_isdigit(cb)) { fractional = (ca == '0' || cb == '0'); if (fractional) { if ((result = compare_left(a+ai, b+bi)) != 0) return result; } else { if ((result = compare_right(a+ai, b+bi)) != 0) return result; } } if (!ca && !cb) { /* The strings compare the same. Perhaps the caller will want to call strcmp to break the tie. */ return 0; } if (fold_case) { ca = apr_toupper(ca); cb = apr_toupper(cb); } if (ca < cb) return -1; else if (ca > cb) return +1; ++ai; ++bi; } }
apr_status_t filepath_drive_get(char **rootpath, char drive, apr_int32_t flags, apr_pool_t *p) { char path[APR_PATH_MAX]; char *pos; ULONG rc; ULONG bufsize = sizeof(path) - 3; path[0] = drive; path[1] = ':'; path[2] = '/'; rc = DosQueryCurrentDir(apr_toupper(drive) - 'A', path+3, &bufsize); if (rc) { return APR_FROM_OS_ERROR(rc); } if (!(flags & APR_FILEPATH_NATIVE)) { for (pos=path; *pos; pos++) { if (*pos == '\\') *pos = '/'; } } *rootpath = apr_pstrdup(p, path); return APR_SUCCESS; }
void modperl_str_toupper(char *str) { while (*str) { *str = apr_toupper(*str); ++str; } }
static void ap_str_toupper(char *str) { while (*str) { *str = apr_toupper(*str); ++str; } }
static apr_status_t CaseFilterInFilter(ap_filter_t *f, apr_bucket_brigade *pbbOut, ap_input_mode_t eMode, apr_read_type_e eBlock, apr_off_t nBytes) { request_rec *r = f->r; conn_rec *c = r->connection; CaseFilterInContext *pCtx; apr_status_t ret; if (!(pCtx = f->ctx)) { f->ctx = pCtx = apr_palloc(r->pool, sizeof *pCtx); pCtx->pbbTmp = apr_brigade_create(r->pool, c->bucket_alloc); } if (APR_BRIGADE_EMPTY(pCtx->pbbTmp)) { ret = ap_get_brigade(f->next, pCtx->pbbTmp, eMode, eBlock, nBytes); if (eMode == AP_MODE_EATCRLF || ret != APR_SUCCESS) return ret; } while (!APR_BRIGADE_EMPTY(pCtx->pbbTmp)) { apr_bucket *pbktIn = APR_BRIGADE_FIRST(pCtx->pbbTmp); apr_bucket *pbktOut; const char *data; apr_size_t len; char *buf; apr_size_t n; /* It is tempting to do this... * APR_BUCKET_REMOVE(pB); * APR_BRIGADE_INSERT_TAIL(pbbOut,pB); * and change the case of the bucket data, but that would be wrong * for a file or socket buffer, for example... */ if (APR_BUCKET_IS_EOS(pbktIn)) { APR_BUCKET_REMOVE(pbktIn); APR_BRIGADE_INSERT_TAIL(pbbOut, pbktIn); break; } ret=apr_bucket_read(pbktIn, &data, &len, eBlock); if (ret != APR_SUCCESS) return ret; buf = ap_malloc(len); for (n=0 ; n < len ; ++n) { buf[n] = apr_toupper(data[n]); } pbktOut = apr_bucket_heap_create(buf, len, 0, c->bucket_alloc); APR_BRIGADE_INSERT_TAIL(pbbOut, pbktOut); apr_bucket_delete(pbktIn); } return APR_SUCCESS; }
static char *http2env(request_rec *r, const char *w) { char *res = (char *)apr_palloc(r->pool, sizeof("HTTP_") + strlen(w)); char *cp = res; char c; *cp++ = 'H'; *cp++ = 'T'; *cp++ = 'T'; *cp++ = 'P'; *cp++ = '_'; while ((c = *w++) != 0) { if (apr_isalnum(c)) { *cp++ = apr_toupper(c); } else if (c == '-') { *cp++ = '_'; } else { if (APLOGrtrace1(r)) ap_log_rerror(APLOG_MARK, APLOG_TRACE1, 0, r, "Not exporting header with invalid name as envvar: %s", ap_escape_logitem(r->pool, w)); return NULL; } } *cp = 0; return res; }
apr_status_t filepath_root_test(char *path, apr_pool_t *p) { char drive = apr_toupper(path[0]); if (drive >= 'A' && drive <= 'Z' && path[1] == ':' && IS_SLASH(path[2])) return APR_SUCCESS; return APR_EBADPATH; }
apr_status_t filepath_root_case(char **rootpath, char *root, apr_pool_t *p) { if (root[0] && apr_islower(root[0]) && root[1] == ':') { *rootpath = apr_pstrdup(p, root); (*rootpath)[0] = apr_toupper((*rootpath)[0]); } else { *rootpath = root; } return APR_SUCCESS; }
APR_DECLARE(apr_status_t) apr_filepath_set(const char *path, apr_pool_t *p) { ULONG rv = 0; if (path[1] == ':') rv = DosSetDefaultDisk(apr_toupper(path[0]) - '@'); if (rv == 0) rv = DosSetCurrentDir(path); return APR_FROM_OS_ERROR(rv); }
static apr_status_t CaseFilterOutFilter(ap_filter_t *f, apr_bucket_brigade *pbbIn) { request_rec *r = f->r; conn_rec *c = r->connection; apr_bucket *pbktIn; apr_bucket_brigade *pbbOut; pbbOut=apr_brigade_create(r->pool, c->bucket_alloc); for (pbktIn = APR_BRIGADE_FIRST(pbbIn); pbktIn != APR_BRIGADE_SENTINEL(pbbIn); pbktIn = APR_BUCKET_NEXT(pbktIn)) { const char *data; apr_size_t len; char *buf; apr_size_t n; apr_bucket *pbktOut; if(APR_BUCKET_IS_EOS(pbktIn)) { apr_bucket *pbktEOS=apr_bucket_eos_create(c->bucket_alloc); APR_BRIGADE_INSERT_TAIL(pbbOut,pbktEOS); continue; } /* read */ apr_bucket_read(pbktIn,&data,&len,APR_BLOCK_READ); /* write */ buf = apr_bucket_alloc(len, c->bucket_alloc); for(n=0 ; n < len ; ++n) buf[n] = apr_toupper(data[n]); pbktOut = apr_bucket_heap_create(buf, len, apr_bucket_free, c->bucket_alloc); APR_BRIGADE_INSERT_TAIL(pbbOut,pbktOut); } /* Q: is there any advantage to passing a brigade for each bucket? * A: obviously, it can cut down server resource consumption, if this * experimental module was fed a file of 4MB, it would be using 8MB for * the 'read' buckets and the 'write' buckets. * * Note it is more efficient to consume (destroy) each bucket as it's * processed above than to do a single cleanup down here. In any case, * don't let our caller pass the same buckets to us, twice; */ apr_brigade_cleanup(pbbIn); return ap_pass_brigade(f->next,pbbOut); }
static apr_status_t urlReplaceFilterOutFilter(ap_filter_t *f, apr_bucket_brigade *pbbIn) { request_rec *r = f->r; conn_rec *c = r->connection; apr_bucket *pbktIn; apr_bucket_brigade *pbbOut; pbbOut=apr_brigade_create(r->pool, c->bucket_alloc); for (pbktIn = APR_BRIGADE_FIRST(pbbIn); pbktIn != APR_BRIGADE_SENTINEL(pbbIn); pbktIn = APR_BUCKET_NEXT(pbktIn)) { const char *data; apr_size_t len; char *buf; apr_size_t n; apr_bucket *pbktOut; if (APR_BUCKET_IS_EOS(pbktIn)) { apr_bucket *pbktEOS=apr_bucket_eos_create(c->bucket_alloc); APR_BRIGADE_INSERT_TAIL(pbbOut,pbktEOS); continue; } /* read */ apr_bucket_read(pbktIn,&data,&len,APR_BLOCK_READ); /* write */ buf = apr_bucket_alloc(len, c->bucket_alloc); for (n=0 ; n < len ; ++n) buf[n] = apr_toupper(data[n]); pbktOut = apr_bucket_heap_create(buf, len, apr_bucket_free, c->bucket_alloc); APR_BRIGADE_INSERT_TAIL(pbbOut,pbktOut); } apr_brigade_cleanup(pbbIn); return ap_pass_brigade(f->next,pbbOut); }
static char *http2env(apr_pool_t *a, const char *w) { char *res = (char *)apr_palloc(a, sizeof("HTTP_") + strlen(w)); char *cp = res; char c; *cp++ = 'H'; *cp++ = 'T'; *cp++ = 'T'; *cp++ = 'P'; *cp++ = '_'; while ((c = *w++) != 0) { if (!apr_isalnum(c)) { *cp++ = '_'; } else { *cp++ = apr_toupper(c); } } *cp = 0; return res; }
static authn_status authn_dbd_realm(request_rec *r, const char *user, const char *realm, char **rethash) { apr_status_t rv; const char *dbd_hash = NULL; apr_dbd_prepared_t *statement; apr_dbd_results_t *res = NULL; apr_dbd_row_t *row = NULL; int ret; authn_dbd_conf *conf = ap_get_module_config(r->per_dir_config, &authn_dbd_module); ap_dbd_t *dbd = authn_dbd_acquire_fn(r); if (dbd == NULL) { ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01658) "Failed to acquire database connection to look up " "user '%s:%s'", user, realm); return AUTH_GENERAL_ERROR; } if (conf->realm == NULL) { ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01659) "No AuthDBDUserRealmQuery has been specified"); return AUTH_GENERAL_ERROR; } statement = apr_hash_get(dbd->prepared, conf->realm, APR_HASH_KEY_STRING); if (statement == NULL) { ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01660) "A prepared statement could not be found for " "AuthDBDUserRealmQuery with the key '%s'", conf->realm); return AUTH_GENERAL_ERROR; } if ((ret = apr_dbd_pvselect(dbd->driver, r->pool, dbd->handle, &res, statement, 0, user, realm, NULL) != 0)) { ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01661) "Query execution error looking up '%s:%s' " "in database [%s]", user, realm, apr_dbd_error(dbd->driver, dbd->handle, ret)); return AUTH_GENERAL_ERROR; } for (rv = apr_dbd_get_row(dbd->driver, r->pool, res, &row, -1); rv != -1; rv = apr_dbd_get_row(dbd->driver, r->pool, res, &row, -1)) { if (rv != 0) { ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01662) "Error retrieving results while looking up '%s:%s' " "in database", user, realm); return AUTH_GENERAL_ERROR; } if (dbd_hash == NULL) { #if APU_MAJOR_VERSION > 1 || (APU_MAJOR_VERSION == 1 && APU_MINOR_VERSION >= 3) /* add the rest of the columns to the environment */ int i = 1; const char *name; for (name = apr_dbd_get_name(dbd->driver, res, i); name != NULL; name = apr_dbd_get_name(dbd->driver, res, i)) { char *str = apr_pstrcat(r->pool, AUTHN_PREFIX, name, NULL); int j = sizeof(AUTHN_PREFIX)-1; /* string length of "AUTHENTICATE_", excluding the trailing NIL */ while (str[j]) { if (!apr_isalnum(str[j])) { str[j] = '_'; } else { str[j] = apr_toupper(str[j]); } j++; } apr_table_set(r->subprocess_env, str, apr_dbd_get_entry(dbd->driver, row, i)); i++; } #endif dbd_hash = apr_dbd_get_entry(dbd->driver, row, 0); } /* we can't break out here or row won't get cleaned up */ } if (!dbd_hash) { return AUTH_USER_NOT_FOUND; } AUTHN_CACHE_STORE(r, user, realm, dbd_hash); *rethash = apr_pstrdup(r->pool, dbd_hash); return AUTH_USER_FOUND; }
static authn_status authn_dbd_password(request_rec *r, const char *user, const char *password) { apr_status_t rv; const char *dbd_password = NULL; apr_dbd_prepared_t *statement; apr_dbd_results_t *res = NULL; apr_dbd_row_t *row = NULL; authn_dbd_conf *conf = ap_get_module_config(r->per_dir_config, &authn_dbd_module); ap_dbd_t *dbd = authn_dbd_acquire_fn(r); char *digest_colon = NULL; if (dbd == NULL) { ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "Failed to acquire database connection to look up " "user '%s'", user); return AUTH_GENERAL_ERROR; } if (conf->user == NULL) { ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "No AuthDBDUserPWQuery has been specified"); return AUTH_GENERAL_ERROR; } statement = apr_hash_get(dbd->prepared, conf->user, APR_HASH_KEY_STRING); if (statement == NULL) { ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "A prepared statement could not be found for " "AuthDBDUserPWQuery with the key '%s'", conf->user); return AUTH_GENERAL_ERROR; } if (apr_dbd_pvselect(dbd->driver, r->pool, dbd->handle, &res, statement, 0, user, NULL) != 0) { ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "Query execution error looking up '%s' " "in database", user); return AUTH_GENERAL_ERROR; } for (rv = apr_dbd_get_row(dbd->driver, r->pool, res, &row, -1); rv != -1; rv = apr_dbd_get_row(dbd->driver, r->pool, res, &row, -1)) { if (rv != 0) { ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, "Error retrieving results while looking up '%s' " "in database", user); return AUTH_GENERAL_ERROR; } if (dbd_password == NULL) { #if APU_MAJOR_VERSION > 1 || (APU_MAJOR_VERSION == 1 && APU_MINOR_VERSION >= 3) /* add the rest of the columns to the environment */ int i = 1; const char *name; for (name = apr_dbd_get_name(dbd->driver, res, i); name != NULL; name = apr_dbd_get_name(dbd->driver, res, i)) { char *str = apr_pstrcat(r->pool, AUTHN_PREFIX, name, NULL); int j = sizeof(AUTHN_PREFIX)-1; /* string length of "AUTHENTICATE_", excluding the trailing NIL */ while (str[j]) { if (!apr_isalnum(str[j])) { str[j] = '_'; } else { str[j] = apr_toupper(str[j]); } j++; } apr_table_set(r->subprocess_env, str, apr_dbd_get_entry(dbd->driver, row, i)); i++; } #endif dbd_password = apr_dbd_get_entry(dbd->driver, row, 0); } /* we can't break out here or row won't get cleaned up */ } if (!dbd_password) { return AUTH_USER_NOT_FOUND; } if ((digest_colon = ap_strchr(dbd_password, ':'))) { const char *realm = NULL, *exp_hash = NULL; const char *act_hash = NULL; realm = apr_pstrndup(r->pool, dbd_password, digest_colon - dbd_password); exp_hash = digest_colon + 1; act_hash = ap_md5(r->pool, (unsigned char*) apr_pstrcat(r->pool, user, ":", realm, ":", password, NULL)); if (strcmp(act_hash, exp_hash)) { return AUTH_DENIED; } else { return AUTH_GRANTED; } } rv = apr_password_validate(password, dbd_password); if (rv != APR_SUCCESS) { return AUTH_DENIED; } return AUTH_GRANTED; }
static int sc_for_req_header(const char *header_name) { char header[16]; apr_size_t len = strlen(header_name); const char *p = header_name; int i = 0; /* ACCEPT-LANGUAGE is the longest header * that is of interest. */ if (len < 4 || len > 15) return UNKNOWN_METHOD; while (*p) header[i++] = apr_toupper(*p++); header[i] = '\0'; p = &header[1]; switch (header[0]) { case 'A': if (memcmp(p, "CCEPT", 5) == 0) { if (!header[6]) return SC_ACCEPT; else if (header[6] == '-') { p += 6; if (strcmp(p, "CHARSET") == 0) return SC_ACCEPT_CHARSET; else if (strcmp(p, "ENCODING") == 0) return SC_ACCEPT_ENCODING; else if (strcmp(p, "LANGUAGE") == 0) return SC_ACCEPT_LANGUAGE; else return UNKNOWN_METHOD; } else return UNKNOWN_METHOD; } else if (strcmp(p, "UTHORIZATION") == 0) return SC_AUTHORIZATION; else return UNKNOWN_METHOD; break; case 'C': if(strcmp(p, "OOKIE2") == 0) return SC_COOKIE2; else if (strcmp(p, "OOKIE") == 0) return SC_COOKIE; else if(strcmp(p, "ONNECTION") == 0) return SC_CONNECTION; else if(strcmp(p, "ONTENT-TYPE") == 0) return SC_CONTENT_TYPE; else if(strcmp(p, "ONTENT-LENGTH") == 0) return SC_CONTENT_LENGTH; else return UNKNOWN_METHOD; break; case 'H': if(strcmp(p, "OST") == 0) return SC_HOST; else return UNKNOWN_METHOD; break; case 'P': if(strcmp(p, "RAGMA") == 0) return SC_PRAGMA; else return UNKNOWN_METHOD; break; case 'R': if(strcmp(p, "EFERER") == 0) return SC_REFERER; else return UNKNOWN_METHOD; break; case 'U': if(strcmp(p, "SER-AGENT") == 0) return SC_USER_AGENT; else return UNKNOWN_METHOD; break; default: return UNKNOWN_METHOD; } /* NOTREACHED */ }
int Ganglia_metadata_send_real( Ganglia_metric gmetric, Ganglia_udp_send_channels send_channels, char *override_string ) { int len, i; XDR x; char gmetricmsg[GANGLIA_MAX_MESSAGE_LEN]; Ganglia_metadata_msg msg; const apr_array_header_t *arr; const apr_table_entry_t *elts; const char *spoof = SPOOF; apr_pool_t *gm_pool=(apr_pool_t*)gmetric->pool; if (myhost[0] == '\0') apr_gethostname( (char*)myhost, APRMAXHOSTLEN+1, gm_pool); msg.id = gmetadata_full; memcpy( &(msg.Ganglia_metadata_msg_u.gfull.metric), gmetric->msg, sizeof(Ganglia_metadata_message)); msg.Ganglia_metadata_msg_u.gfull.metric_id.name = apr_pstrdup (gm_pool, gmetric->msg->name); debug_msg(" msg.Ganglia_metadata_msg_u.gfull.metric_id.name: %s\n", msg.Ganglia_metadata_msg_u.gfull.metric_id.name); if ( override_string != NULL ) { msg.Ganglia_metadata_msg_u.gfull.metric_id.host = apr_pstrdup (gm_pool, (char*)override_string); debug_msg(" msg.Ganglia_metadata_msg_u.gfull.metric_id.host: %s\n", msg.Ganglia_metadata_msg_u.gfull.metric_id.host); msg.Ganglia_metadata_msg_u.gfull.metric_id.spoof = TRUE; } else { msg.Ganglia_metadata_msg_u.gfull.metric_id.host = apr_pstrdup (gm_pool, (char*)myhost); debug_msg(" msg.Ganglia_metadata_msg_u.gfull.metric_id.host: %s\n", msg.Ganglia_metadata_msg_u.gfull.metric_id.host); msg.Ganglia_metadata_msg_u.gfull.metric_id.spoof = FALSE; } arr = apr_table_elts(gmetric->extra); elts = (const apr_table_entry_t *)arr->elts; msg.Ganglia_metadata_msg_u.gfull.metric.metadata.metadata_len = arr->nelts; msg.Ganglia_metadata_msg_u.gfull.metric.metadata.metadata_val = (Ganglia_extra_data*)apr_pcalloc(gm_pool, sizeof(Ganglia_extra_data)*arr->nelts); /* add all of the metadata to the packet */ for (i = 0; i < arr->nelts; ++i) { if (elts[i].key == NULL) continue; /* Replace the host name with the spoof host if it exists in the metadata */ if ((apr_toupper(elts[i].key[0]) == spoof[0]) && strcasecmp(SPOOF_HOST, elts[i].key) == 0) { msg.Ganglia_metadata_msg_u.gfull.metric_id.host = apr_pstrdup (gm_pool, elts[i].val); msg.Ganglia_metadata_msg_u.gfull.metric_id.spoof = TRUE; } if ((apr_toupper(elts[i].key[0]) == spoof[0]) && strcasecmp(SPOOF_HEARTBEAT, elts[i].key) == 0) { msg.Ganglia_metadata_msg_u.gfull.metric_id.name = apr_pstrdup (gm_pool, "heartbeat"); msg.Ganglia_metadata_msg_u.gfull.metric.name = msg.Ganglia_metadata_msg_u.gfull.metric_id.name; msg.Ganglia_metadata_msg_u.gfull.metric_id.spoof = TRUE; } msg.Ganglia_metadata_msg_u.gfull.metric.metadata.metadata_val[i].name = apr_pstrdup(gm_pool, elts[i].key); msg.Ganglia_metadata_msg_u.gfull.metric.metadata.metadata_val[i].data = apr_pstrdup(gm_pool, elts[i].val); } /* Send the message */ xdrmem_create(&x, gmetricmsg, GANGLIA_MAX_MESSAGE_LEN, XDR_ENCODE); if(!xdr_Ganglia_metadata_msg(&x, &msg)) { return 1; } len = xdr_getpos(&x); /* Send the encoded data along...*/ return Ganglia_udp_send_message( send_channels, gmetricmsg, len); }