*
* Revisions :
* $Log: actionlist.h,v $
+ * Revision 1.33 2008/03/29 12:13:45 fabiankeil
+ * Remove send-wafer and send-vanilla-wafer actions.
+ *
* Revision 1.32 2008/03/28 15:13:42 fabiankeil
* Remove inspect-jpegs action.
*
DEFINE_CGI_PARAM_RADIO ("set-image-blocker", ACTION_IMAGE_BLOCKER, ACTION_STRING_IMAGE_BLOCKER, "pattern", 1)
DEFINE_CGI_PARAM_RADIO ("set-image-blocker", ACTION_IMAGE_BLOCKER, ACTION_STRING_IMAGE_BLOCKER, "blank", 0)
DEFINE_CGI_PARAM_CUSTOM ("set-image-blocker", ACTION_IMAGE_BLOCKER, ACTION_STRING_IMAGE_BLOCKER, CGI_PREFIX "send-banner?type=pattern")
+DEFINE_ACTION_STRING ("change-x-forwarded-for", ACTION_CHANGE_X_FORWARDED_FOR, ACTION_STRING_CHANGE_X_FORWARDED_FOR)
+DEFINE_CGI_PARAM_RADIO ("change-x-forwarded-for", ACTION_CHANGE_X_FORWARDED_FOR, ACTION_STRING_CHANGE_X_FORWARDED_FOR, "block", 0)
+DEFINE_CGI_PARAM_RADIO ("change-x-forwarded-for", ACTION_CHANGE_X_FORWARDED_FOR, ACTION_STRING_CHANGE_X_FORWARDED_FOR, "add", 1)
#if DEFINE_ACTION_ALIAS
-const char loaders_rcs[] = "$Id: loaders.c,v 1.66 2008/03/21 11:16:30 fabiankeil Exp $";
+const char loaders_rcs[] = "$Id: loaders.c,v 1.67 2008/03/30 14:52:08 fabiankeil Exp $";
/*********************************************************************
*
* File : $Source: /cvsroot/ijbswa/current/loaders.c,v $
*
* Revisions :
* $Log: loaders.c,v $
+ * Revision 1.67 2008/03/30 14:52:08 fabiankeil
+ * Rename load_actions_file() and load_re_filterfile()
+ * as they load multiple files "now".
+ *
* Revision 1.66 2008/03/21 11:16:30 fabiankeil
* Garbage-collect csp->my_ip_addr_str and csp->my_hostname.
*
freez(csp->ip_addr_str);
freez(csp->iob->buf);
+ freez(csp->x_forwarded_for);
freez(csp->error_message);
if (csp->action->flags & ACTION_FORWARD_OVERRIDE &&
-const char parsers_rcs[] = "$Id: parsers.c,v 1.139 2008/09/04 08:13:58 fabiankeil Exp $";
+const char parsers_rcs[] = "$Id: parsers.c,v 1.140 2008/09/12 17:51:43 fabiankeil Exp $";
/*********************************************************************
*
* File : $Source: /cvsroot/ijbswa/current/parsers.c,v $
*
* Revisions :
* $Log: parsers.c,v $
+ * Revision 1.140 2008/09/12 17:51:43 fabiankeil
+ * - A few style fixes.
+ * - Remove a pointless cast.
+ *
* Revision 1.139 2008/09/04 08:13:58 fabiankeil
* Prepare for critical sections on Windows by adding a
* layer of indirection before the pthread mutex functions.
static jb_err client_host_adder (struct client_state *csp);
static jb_err client_xtra_adder (struct client_state *csp);
+static jb_err client_x_forwarded_for_adder(struct client_state *csp);
static jb_err connection_close_adder (struct client_state *csp);
static jb_err create_forged_referrer(char **header, const char *hostport);
static const add_header_func_ptr add_client_headers[] = {
client_host_adder,
+ client_x_forwarded_for_adder,
client_xtra_adder,
/* Temporarily disabled: client_accept_encoding_adder, */
connection_close_adder,
*********************************************************************/
jb_err client_x_forwarded(struct client_state *csp, char **header)
{
- if ((csp->action->flags & ACTION_HIDE_FORWARDED) != 0)
+ int block_header = (((csp->action->flags & ACTION_HIDE_FORWARDED) != 0)
+ || ((csp->action->flags & ACTION_CHANGE_X_FORWARDED_FOR) &&
+ (0 == strcmpic(csp->action->string[ACTION_STRING_CHANGE_X_FORWARDED_FOR], "block"))));
+
+ if (block_header)
{
freez(*header);
log_error(LOG_LEVEL_HEADER, "crunched x-forwarded-for!");
}
+ else if (0 == strcmpic(csp->action->string[ACTION_STRING_CHANGE_X_FORWARDED_FOR], "add"))
+ {
+ /* Save it so we can re-add it later */
+ freez(csp->x_forwarded_for);
+ csp->x_forwarded_for = *header;
+
+ /*
+ * Always set *header = NULL, since this information
+ * will be sent at the end of the header.
+ */
+ *header = NULL;
+ }
return JB_ERR_OK;
}
}
+/*********************************************************************
+ *
+ * Function : client_x_forwarded_for_adder
+ *
+ * Description : Used in the add_client_headers list. Called from `sed'.
+ *
+ * Parameters :
+ * 1 : csp = Current client state (buffers, headers, etc...)
+ *
+ * Returns : JB_ERR_OK on success, or
+ * JB_ERR_MEMORY on out-of-memory error.
+ *
+ *********************************************************************/
+static jb_err client_x_forwarded_for_adder(struct client_state *csp)
+{
+ char *header = NULL;
+ jb_err err;
+
+ if (!((csp->action->flags & ACTION_CHANGE_X_FORWARDED_FOR) &&
+ (0 == strcmpic(csp->action->string[ACTION_STRING_CHANGE_X_FORWARDED_FOR], "add"))))
+ {
+ return JB_ERR_OK;
+ }
+
+ if (csp->x_forwarded_for)
+ {
+ header = strdup(csp->x_forwarded_for);
+ string_append(&header, ", ");
+ }
+ else
+ {
+ header = strdup("X-Forwarded-For: ");
+ }
+ string_append(&header, csp->ip_addr_str);
+
+ if (header == NULL)
+ {
+ return JB_ERR_MEMORY;
+ }
+
+ log_error(LOG_LEVEL_HEADER, "addh: %s", header);
+ err = enlist(csp->headers, header);
+ freez(header);
+
+ return err;
+}
+
+
/*********************************************************************
*
* Function : connection_close_adder
#ifndef PROJECT_H_INCLUDED
#define PROJECT_H_INCLUDED
/** Version string. */
-#define PROJECT_H_VERSION "$Id: project.h,v 1.116 2008/05/20 16:05:02 fabiankeil Exp $"
+#define PROJECT_H_VERSION "$Id: project.h,v 1.117 2008/08/30 12:03:07 fabiankeil Exp $"
/*********************************************************************
*
* File : $Source: /cvsroot/ijbswa/current/project.h,v $
*
* Revisions :
* $Log: project.h,v $
+ * Revision 1.117 2008/08/30 12:03:07 fabiankeil
+ * Remove FEATURE_COOKIE_JAR.
+ *
* Revision 1.116 2008/05/20 16:05:02 fabiankeil
* Move parsers structure definition from project.h to parsers.h.
*
#define ACTION_OVERWRITE_LAST_MODIFIED 0x02000000UL
/** Action bitmap: Replace or block Accept-Language header */
#define ACTION_HIDE_ACCEPT_LANGUAGE 0x04000000UL
+/** Action bitmap: Remove or add "X-Forwarded-For" header. */
+#define ACTION_CHANGE_X_FORWARDED_FOR 0x08000000UL
/** Action string index: How to deanimate GIFs */
#define ACTION_STRING_FORWARD_OVERRIDE 15
/** Action string index: Reason for the block. */
#define ACTION_STRING_BLOCK 16
+/** Action string index: what to do with the "X-Forwarded-For" header. */
+#define ACTION_STRING_CHANGE_X_FORWARDED_FOR 17
/** Number of string actions. */
-#define ACTION_STRING_COUNT 17
+#define ACTION_STRING_COUNT 18
/* To make the ugly hack in sed easier to understand */
/** MIME-Type key, see CT_* above */
unsigned int content_type;
+ /** The "X-Forwarded-For:" header sent by the client */
+ /*
+ * XXX: this is a hack that causes problems if
+ * there's more than one X-Forwarded-For header.
+ */
+ char *x_forwarded_for;
+
/** Actions files associated with this client */
struct file_list *actions_list[MAX_AF_FILES];
#
# Revisions :
# $Log: edit-actions-for-url,v $
+# Revision 1.54 2008/03/29 12:14:27 fabiankeil
+# Remove send-wafer and send-vanilla-wafer actions.
+#
# Revision 1.53 2008/03/28 15:13:45 fabiankeil
# Remove inspect-jpegs action.
#
<input type="text" name="block_mode" size="40" value="@block-param@">
</td>
</tr>
+ <tr class="bg1" align="left" valign="top">
+ <td class="en1" align="center" valign="middle"><input type="radio"
+ name="change_x_forwarded_for" id="change_x_forwarded_for_y" value="Y" @change-x-forwarded-for-y@
+ onclick="show_change_x_forwarded_for_opts(true)"></td>
+ <td class="dis1" align="center" valign="middle"><input type="radio"
+ name="change_x_forwarded_for" value="N" @change-x-forwarded-for-n@
+ onclick="show_change_x_forwarded_for_opts(false)"></td>
+ <td class="noc1" align="center" valign="middle"><input type="radio"
+ name="change_x_forwarded_for" value="X" @change-x-forwarded-for-x@
+ onclick="show_change_x_forwarded_for_opts(false)"></td>
+ <td class="action"><a href="@user-manual@@actions-help-prefix@CHANGE-X-FORWARDED-FOR">change-x-forwarded-for</a></td>
+ <td>Specifies whether to block or add X-Forwarded-For headers.</td>
+ </tr>
+ <tr class="bg1" align="left" valign="top" id="change_x_forwarded_for_opts">
+ <td class="en1"> </td>
+ <td class="dis1"> </td>
+ <td class="noc1"> </td>
+ <td> </td>
+ <td><input type="radio" name="change_x_forwarded_for_mode" value="block"
+ id="change_x_forwarded_for_mode_block" @change-x-forwarded-for-param-block@><label
+ for="change_x_forwarded_for_mode_block">Block the header.</label><br>
+ <input type="radio" name="change_x_forwarded_for_mode" value="add"
+ id="change_x_forwarded_for_mode_add" @change-x-forwarded-for-param-add@><label
+ for="change_x_forwarded_for_mode_add">Add the header.</label><br>
+ </tr>
<tr class="bg1" align="left" valign="top">
<td class="en1"> </td>
<td class="dis1" align="center" valign="middle"><input type="radio"