gboolean ftp_policy_bounce_check(FtpProxy *self, guint side, ZSockAddr *remote, gboolean connect) { PyObject *zsock; gboolean called; ZPolicyObj *res; gboolean ret; z_proxy_enter(self); z_policy_lock(self->super.thread); zsock = z_policy_sockaddr_new(remote); res = z_policy_call(self->super.handler, "bounceCheck", z_policy_var_build("(Oii)", zsock, side, connect), &called, self->super.session_id); if (!called) { z_policy_unlock(self->super.thread); z_proxy_return(self, TRUE); } if ((res == NULL) || !z_policy_var_parse(res, "i", &ret)) ret = FALSE; z_policy_var_unref(res); z_policy_var_unref(zsock); z_policy_unlock(self->super.thread); z_proxy_return(self, ret); }
gboolean ftp_policy_parse_authinfo(FtpProxy *self, const gchar *cmd, GString *param) { gboolean called = FALSE; PyObject *result = NULL; PyObject *args = NULL; gboolean ret; z_proxy_enter(self); z_policy_lock(self->super.thread); args = z_policy_var_build("ss", cmd, param->str); result = z_policy_call(self->super.handler, "parseInbandAuth", args, &called, self->super.session_id); if (!called) { z_policy_unlock(self->super.thread); z_proxy_return(self, FALSE); } if (result == NULL || !z_policy_var_parse(result, "i", &ret)) ret = FALSE; if (result) z_policy_var_unref(result); z_policy_unlock(self->super.thread); z_proxy_return(self, ret); }
gboolean smtp_hash_get_type(ZPolicyObj *tuple, guint *filter_type) { ZPolicyObj *tmp; if (!z_policy_seq_check(tuple)) { if (z_policy_var_parse(tuple, "i", filter_type)) return TRUE; /* not a sequence */ return FALSE; } tmp = z_policy_seq_getitem(tuple, 0); if (!z_policy_var_parse(tmp, "i", filter_type)) { /* policy syntax error */ z_policy_var_unref(tmp); return FALSE; } z_policy_var_unref(tmp); return TRUE; }
gboolean z_policy_tuple_get_verdict(ZPolicyObj *tuple, guint *verdict) { ZPolicyObj *tmp; z_enter(); if (!z_policy_seq_check(tuple)) { if (z_policy_var_parse(tuple, "i", verdict)) z_return(TRUE); /* not a sequence nor an int */ z_return(FALSE); } tmp = z_policy_seq_getitem(tuple, 0); if (!tmp || !z_policy_var_parse(tmp, "i", verdict)) { /* policy syntax error */ z_policy_var_unref(tmp); z_return(FALSE); } z_policy_var_unref(tmp); z_return(TRUE); }
/** * telnet_hash_get_type: * @tuple: * @filter_type: * * * * Returns: * */ gboolean telnet_hash_get_type(ZPolicyObj *tuple, guint *filter_type) { ZPolicyObj *tmp; gboolean res; if (!z_policy_seq_check(tuple)) { res = z_policy_var_parse(tuple, "i", filter_type); } else { tmp = z_policy_seq_getitem(tuple, 0); res = z_policy_var_parse(tmp, "i", filter_type); /* FALSE -> policy syntax error */ z_policy_var_unref(tmp); } return res; }
static void anypy_main(ZProxy * s) { AnyPyProxy *self = Z_CAST(s, AnyPyProxy); ZPolicyObj *res; gboolean called; z_proxy_enter(self); if (!z_proxy_connect_server(&self->super, NULL, 0) || !anypy_stream_init(self)) { z_proxy_leave(self); return; } z_policy_lock(self->super.thread); res = z_policy_call(self->super.handler, "proxyThread", NULL, &called, self->super.session_id); z_policy_var_unref(res); z_policy_unlock(self->super.thread); z_proxy_return(self); }
static gboolean z_proxy_stack_tuple(ZProxy *self, ZPolicyObj *tuple, ZStackedProxy **stacked, ZPolicyDict *stack_info_dict) { guint stack_method; ZPolicyObj *arg = NULL; gboolean success = FALSE; if (!z_policy_tuple_get_verdict(tuple, &stack_method) || z_policy_seq_length(tuple) < 2) goto invalid_tuple; arg = z_policy_seq_getitem(tuple, 1); switch (stack_method) { case Z_STACK_PROXY: if (z_policy_seq_length(tuple) != 2) goto invalid_tuple; success = z_proxy_stack_proxy(self, arg, stacked, stack_info_dict); break; case Z_STACK_PROGRAM: if (!z_policy_str_check(arg)) goto invalid_tuple; success = z_proxy_stack_program(self, z_policy_str_as_string(arg), stacked); break; default: break; } exit: if (arg) z_policy_var_unref(arg); return success; invalid_tuple: z_proxy_log(self, CORE_POLICY, 1, "Invalid stack tuple;"); success = FALSE; goto exit; }
/** * z_proxy_stack_proxy: * @self: proxy instance * @proxy_class: a Python class to be instantiated as the child proxy * * This function is called to start a child proxy. **/ gboolean z_proxy_stack_proxy(ZProxy *self, ZPolicyObj *proxy_class, ZStackedProxy **stacked, ZPolicyDict *stack_info) { int downpair[2], uppair[2]; ZPolicyObj *res, *client_stream, *server_stream, *stack_info_obj; ZStream *tmpstream; ZStream *client_upstream, *server_upstream; z_proxy_enter(self); if (proxy_class == z_policy_none) { z_policy_var_unref(proxy_class); z_proxy_leave(self); return FALSE; } if (!z_proxy_stack_prepare_streams(self, downpair, uppair)) { z_policy_var_unref(proxy_class); z_proxy_leave(self); return FALSE; } /*LOG This message reports that Zorp is about to stack a proxy class with the given fds as communication channels. */ z_proxy_log(self, CORE_DEBUG, 6, "Stacking subproxy; client='%d:%d', server='%d:%d'", downpair[0], downpair[1], uppair[0], uppair[1]); tmpstream = z_stream_fd_new(downpair[1], ""); client_stream = z_policy_stream_new(tmpstream); z_stream_unref(tmpstream); tmpstream = z_stream_fd_new(uppair[1], ""); server_stream = z_policy_stream_new(tmpstream); z_stream_unref(tmpstream); if (stack_info) { stack_info_obj = z_policy_struct_new(stack_info, Z_PST_SHARED); } else { Py_XINCREF(Py_None); stack_info_obj = Py_None; } res = z_policy_call(self->handler, "stackProxy", z_policy_var_build("(OOOO)", client_stream, server_stream, proxy_class, stack_info_obj), NULL, self->session_id); z_policy_var_unref(client_stream); z_policy_var_unref(server_stream); z_policy_var_unref(stack_info_obj); if (!res || res == z_policy_none || !z_policy_proxy_check(res)) { z_proxy_log(self, CORE_ERROR, 3, "Error stacking subproxy;"); close(downpair[0]); close(downpair[1]); close(uppair[0]); close(uppair[1]); z_policy_var_unref(res); z_proxy_leave(self); return FALSE; } client_upstream = z_stream_fd_new(downpair[0], ""); server_upstream = z_stream_fd_new(uppair[0], ""); *stacked = z_stacked_proxy_new(client_upstream, server_upstream, NULL, self, z_policy_proxy_get_proxy(res), 0); z_policy_var_unref(res); z_proxy_leave(self); return TRUE; }
gboolean pop3_policy_stack_hash_do(Pop3Proxy *self, ZStackedProxy **stacked) { guint rc; ZPolicyObj *res = NULL; ZPolicyObj *tmp = g_hash_table_lookup(self->command_stack, self->command->str); ZPolicyObj *command_where = NULL; ZPolicyObj *stack_proxy = NULL; unsigned int command_do; gboolean success = TRUE; z_proxy_enter(self); if (!tmp) tmp = g_hash_table_lookup(self->command_stack, "*"); if (!tmp) z_proxy_return(self, TRUE); z_policy_lock(self->super.thread); if (!pop3_hash_get_type(tmp, &command_do)) { /*LOG This message indicates that the stack policy type is invalid for the given response, so nothing will be stacked. Check the 'response_stack' attribute. */ z_proxy_log(self, POP3_POLICY, 1, "Stack policy type is invalid; req='%s'", self->command->str); z_policy_unlock(self->super.thread); z_proxy_return(self, FALSE); } switch(command_do) { case POP3_STK_NONE: rc = command_do; break; case POP3_STK_DATA: case POP3_STK_MIME: if (!z_policy_var_parse(tmp, "(iO)", &rc, &stack_proxy)) { /*LOG This message indicates that the stack policy for the given response is invalid and Zorp stacks nothing. Check the 'response_stack' attribute. It is likely that the parameter for the POP3_STK_MIME or POP3_STK_DATA is invalid. */ z_proxy_log(self, POP3_POLICY, 1, "Cannot parse stack policy line; req='%s'", self->command->str); success = FALSE; } break; case POP3_STK_POLICY: if (!z_policy_var_parse(tmp, "(iO)", &rc, &command_where)) { /*LOG This message indicates that the stack policy for the given response is invalid and Zorp stacks nothing. Check the 'response_stack' attribute. It is likely that the parameter for the POP3_STK_POLICY is invalid. */ z_proxy_log(self, POP3_POLICY, 1, "Cannot parse stack policy line; req='%s'", self->command->str); success = FALSE; } else { res = z_policy_call_object(command_where, z_policy_var_build("(s)", self->command->str), self->super.session_id); if (res == NULL) { /*LOG This message indicates that the callback for the given request policy is invalid and Zorp stacks nothing. Check the 'request' attribute. It is likely that the parameter for the POP3_STK_POLICY is invalid. */ z_proxy_log(self, POP3_POLICY, 1, "Error in policy call; req='%s'", self->command->str); success = FALSE; } else { if (!z_policy_var_parse(res, "i", &rc) && !z_policy_var_parse(res, "(iO)", &rc, &stack_proxy)) { /*LOG This message indicates that the returned value of the callback for the given response policy is invalid and Zorp stacks nothing. Check the callback function. */ z_proxy_log(self, POP3_POLICY, 1, "Cannot parse return code; req='%s'", self->command->str); success = FALSE; } z_policy_var_unref(res); } } break; } if (success && rc != POP3_STK_NONE && stack_proxy) success = z_proxy_stack_object(&self->super, stack_proxy, stacked, NULL); z_policy_unlock(self->super.thread); z_proxy_return(self, success); }