示例#1
0
文件: anypy.c 项目: akatrevorjay/zorp
/**
 * anypy_set_verdict:
 * @self: AnyPyProxy instance
 * @args: Python args argument
 * 
 * sets verdict for the parent proxy
 * args is (verdict,description)
 **/
static ZPolicyObj *
anypy_set_verdict(AnyPyProxy * self, ZPolicyObj *args) 
{
  gint verdict;
  gchar *description;

  z_proxy_enter(self);

  if (!z_policy_var_parse_tuple(args, "is", &verdict, &description))
    {
      z_policy_raise_exception_obj(z_policy_exc_value_error, "Invalid arguments.");
      z_proxy_return(self, NULL);
    }

  if (self->super.parent_proxy)
    {
      ZProxyStackIface *iface;
      iface = z_proxy_find_iface(self->super.parent_proxy, Z_CLASS(ZProxyStackIface));
      if (iface)
        {
          z_proxy_stack_iface_set_verdict(iface, verdict, description);
          z_object_unref(&iface->super);
        }
    }

  z_proxy_return(self, z_policy_none_ref());
}
示例#2
0
文件: anypy.c 项目: akatrevorjay/zorp
/**
 * anypy_set_content_hint:
 * @self: AnyPyProxy instance
 * @args: Python args argument
 *
 * sets verdict for the parent proxy
 * args is (verdict,description)
 **/
static ZPolicyObj *
anypy_set_content_hint(AnyPyProxy * self, ZPolicyObj *args)
{
  gint64 length;

  z_proxy_enter(self);

  if (!z_policy_var_parse_tuple(args, "L", &length))
    {
      z_policy_raise_exception_obj(z_policy_exc_value_error, "Invalid arguments.");
      z_proxy_leave(self);
      return NULL;
    }

  if (self->super.parent_proxy)
    {
      ZProxyStackIface *iface;
      iface = z_proxy_find_iface(self->super.parent_proxy, Z_CLASS(ZProxyStackIface));
      if (iface)
        {
          z_proxy_stack_iface_set_content_hint(iface, length);
          z_object_unref(&iface->super);
        }
    }

  z_proxy_return(self, z_policy_none_ref());
}
示例#3
0
/**
 * finger_proxy_new:
 * @params: ZProxyParams structure
 *
 * Finger proxy constructor. Allocates and initializes a proxy instance,
 * starts proxy thread.
 **/
static ZProxy *
finger_proxy_new(ZProxyParams *params)
{
    FingerProxy  *self;

    z_enter();
    self = Z_CAST(z_proxy_new(Z_CLASS(FingerProxy), params), FingerProxy);
    z_return((ZProxy *) self);
}
示例#4
0
文件: anypy.c 项目: akatrevorjay/zorp
/**
 * anypy_proxy_new:
 * @params: parameters for the AnyPyProxy class constructor
 *
 * This function is called upon startup to create a new AnyPy proxy.
 **/
ZProxy *
anypy_proxy_new(ZProxyParams *params)
{
  AnyPyProxy *self;
  
  z_enter();
  self = Z_CAST(z_proxy_new(Z_CLASS(AnyPyProxy), params), AnyPyProxy);
  z_return(&self->super);
}
示例#5
0
文件: certchain.c 项目: VPetyaa/zorp
ZCertificateChain *
z_certificate_chain_new(void)
{
  ZCertificateChain *self = Z_NEW_COMPAT(Z_CLASS(ZCertificateChain), ZCertificateChain);

  self->chain = sk_X509_new_null();

  return self;
}
示例#6
0
文件: transfer2.c 项目: VPetyaa/zorp
static ZProxyIface *
z_transfer2_ps_iface_new(ZTransfer2 *transfer)
{
  ZTransfer2PSIface *self;

  self = Z_CAST(z_proxy_stack_iface_new(Z_CLASS(ZTransfer2PSIface), transfer->owner), ZTransfer2PSIface);
  self->transfer = transfer;
  return &self->super;
}
示例#7
0
ZProxyIface *
z_proxy_ssl_host_iface_new(ZProxy *owner)
{
  ZProxySslHostIface *self;

  self = Z_CAST(z_proxy_iface_new(Z_CLASS(ZProxySslHostIface), owner), ZProxySslHostIface);
  self->server_cert = owner->ssl_opts.peer_cert[EP_SERVER];

  CRYPTO_add(&self->server_cert->references, 1, CRYPTO_LOCK_X509);
  return &self->super;
}
示例#8
0
/**
 * z_proxy_control_stream_read:
 * @stream: stream to read from
 * @cond: I/O condition which triggered this call
 * @user_data: ZProxy instance as a generic pointer
 *
 * This function is registered as the read callback for control channels
 * of stacked programs.
 **/
static gboolean
z_proxy_control_stream_read(ZStream *stream, GIOCondition cond G_GNUC_UNUSED, gpointer user_data)
{
  ZStackedProxy *stacked = (ZStackedProxy *) user_data;
  ZProxy *proxy = stacked->proxy;
  GIOStatus st;
  gboolean success = FALSE;
  ZCPCommand *request = NULL, *response = NULL;
  ZCPHeader *hdr1, *hdr2;
  guint cp_sid;
  ZProxyIface *iface = NULL;
  const gchar *fail_reason = "Unknown reason";
  gboolean result = TRUE;

  z_enter();
  g_static_mutex_lock(&stacked->destroy_lock);
  if (stacked->destroyed)
    {
      /* NOTE: this stacked proxy has already been destroyed, but a callback
         was still pending, make sure we don't come back again. Note that
         our arguments except stacked might already be freed. */
      result = FALSE;
      goto exit_unlock;
    }

  if (!stacked->control_proto)
    stacked->control_proto = z_cp_context_new(stream);

  st = z_cp_context_read(stacked->control_proto, &cp_sid, &request);
  if (st == G_IO_STATUS_AGAIN)
    goto exit_unlock;
  if (st != G_IO_STATUS_NORMAL)
    {
      /* FIXME: hack, returning FALSE should be enough but it causes
         the poll loop to spin, see bug #7219 */
      z_stream_set_cond(stream, G_IO_IN, FALSE);
      result = FALSE;
      goto exit_unlock;
    }
  
  response = z_cp_command_new("RESULT");
  if (cp_sid != 0)
    {
      fail_reason = "Non-zero session-id";
      goto error;
    }

  z_log(NULL, CORE_DEBUG, 6, "Read request from stack-control channel; request='%s'", request->command->str);
  if (strcmp(request->command->str, "SETVERDICT") == 0
     )
    {
      ZProxyStackIface *siface;
      
      iface = z_proxy_find_iface(proxy, Z_CLASS(ZProxyStackIface));
      if (!iface)
        {
          fail_reason = "Proxy does not support Stack interface";
          goto error;
        }
        
      siface = (ZProxyBasicIface *) iface;
      if (strcmp(request->command->str, "SETVERDICT") == 0)
        {
          ZVerdict verdict;

          hdr1 = z_cp_command_find_header(request, "Verdict");
          hdr2 = z_cp_command_find_header(request, "Description");
          if (!hdr1)
            {
              fail_reason = "No Verdict header in SETVERDICT request";
              goto error;
            }

	  if (strcmp(hdr1->value->str, "Z_ACCEPT") == 0)
	    verdict = Z_ACCEPT;
	  else if (strcmp(hdr1->value->str, "Z_REJECT") == 0)
            verdict = Z_REJECT;
	  else if (strcmp(hdr1->value->str, "Z_DROP") == 0)
            verdict = Z_DROP;
	  else if (strcmp(hdr1->value->str, "Z_ERROR") == 0)
	    verdict = Z_ERROR;
	  else
	    verdict = Z_UNSPEC;
          
          z_proxy_stack_iface_set_verdict(iface, verdict, hdr2 ? hdr2->value->str : NULL);
        }
    }
  else
    {
      fail_reason = "Unknown request received";
      goto error;
    }
  success = TRUE;

 error:
  z_cp_command_add_header(response, g_string_new("Status"), g_string_new(success ? "OK" : "Failure"), FALSE);
  if (!success)
    {
      z_cp_command_add_header(response, g_string_new("Fail-Reason"), g_string_new(fail_reason), FALSE);
      z_log(NULL, CORE_DEBUG, 6, "Error processing control channel request; request='%s', reason='%s'", request ? request->command->str : "None", fail_reason);
    }

  z_log(NULL, CORE_DEBUG, 6, "Responding on stack-control channel; response='%s'", response->command->str);
  if (z_cp_context_write(stacked->control_proto, 0, response) != G_IO_STATUS_NORMAL)
    {
      /* this should not have happened */
      z_log(NULL, CORE_ERROR, 1, "Internal error writing response to stack-control channel;");
      success = FALSE;
    }

  if (iface)
    z_object_unref(&iface->super);
  if (request)
    z_cp_command_free(request);
  if (response)
    z_cp_command_free(response);

 exit_unlock:
  g_static_mutex_unlock(&stacked->destroy_lock);
  z_return(result);
}
示例#9
0
文件: pop3data.c 项目: VPetyaa/zorp
gboolean
pop3_data_transfer(Pop3Proxy *owner)
{
  Pop3Transfer *t;
  GString *preamble;
  gboolean success;
  gchar buf[256];

  z_proxy_enter(owner);
  preamble = g_string_new(owner->response->str);
  if (owner->response_param->len)
    {
      g_string_append_c(preamble, ' ');
      g_string_append(preamble, owner->response_param->str);
    }
  g_string_append(preamble, "\r\n");
  t = Z_CAST(z_dot_transfer_new(Z_CLASS(Pop3Transfer),
                                &owner->super, owner->poll,
                                owner->super.endpoints[EP_SERVER], owner->super.endpoints[EP_CLIENT],
                                owner->buffer_length,
                                owner->timeout,
                                ZT2F_COMPLETE_COPY | ZT2F_PROXY_STREAMS_POLLED,
                                preamble),
             Pop3Transfer);
  z_transfer2_set_content_format(&t->super.super, "email");

  z_stream_line_set_nul_nonfatal(owner->super.endpoints[EP_SERVER], TRUE);
  if (owner->policy_enable_longline)
    z_stream_line_set_split(owner->super.endpoints[EP_SERVER], TRUE);

  success = z_transfer2_simple_run(&t->super.super);
  z_stream_line_set_split(owner->super.endpoints[EP_SERVER], FALSE);
  z_stream_line_set_nul_nonfatal(owner->super.endpoints[EP_SERVER], FALSE);
  if (t->super.dst_write_state == DOT_DW_PREAMBLE)
    {
      /* nothing was written to destination */
      switch (z_transfer2_get_stack_decision(&t->super.super))
        {
        case ZV_REJECT:
	  /*LOG
	    This message indicates that the stacked proxy rejected the content and Zorp
	    rejects the response.
	   */
          z_proxy_log(owner, POP3_ERROR, 2, "Stacked proxy rejected contents; info='%s'", z_transfer2_get_stack_info(&t->super.super));
          g_snprintf(buf, sizeof(buf), "Content rejected (%s)", z_transfer2_get_stack_info(&t->super.super));
          if (owner->reject_by_mail)
            pop3_error_msg(owner, buf);
          else
            pop3_response_reject(owner, buf);
          break;

        case ZV_ERROR:
          g_snprintf(buf, sizeof(buf), "Error occurred while transferring data (%s)", z_transfer2_get_stack_info(&t->super.super));
          pop3_response_reject(owner, buf);
          owner->pop3_state = POP3_STATE_QUIT;
          break;

        default:
          pop3_response_write(owner);
          pop3_write_client(owner, ".\r\n");
          break;
        }
    }
  else
    {
      pop3_write_client(owner, ".\r\n");
    }

  if (owner->from)
    {
      g_string_free(owner->from, TRUE);
      owner->from = NULL;
    }

  if (owner->to)
    {
      g_string_free(owner->to, TRUE);
      owner->to = NULL;
    }

  if (owner->subject)
    {
      g_string_free(owner->subject, TRUE);
      owner->subject = NULL;
    }

  z_object_unref(&t->super.super.super);
  z_proxy_return(owner, success);
}
示例#10
0
  return &self->super;
}

void
z_proxy_ssl_host_iface_free_method(ZObject *s)
{
  ZProxySslHostIface *self = Z_CAST(s, ZProxySslHostIface);

  X509_free(self->server_cert);
  z_object_free_method(s);
}

ZProxyHostIfaceFuncs z_proxy_ssl_host_iface_funcs =
{
  {
    Z_FUNCS_COUNT(ZProxyHostIface),
    z_proxy_ssl_host_iface_free_method,
  },
  .check_name = z_proxy_ssl_host_iface_check_name_method,
};

ZClass ZProxySslHostIface__class =
{
  Z_CLASS_HEADER,
  Z_CLASS(ZProxyHostIface),
  "ZProxySslHostIface",
  sizeof(ZProxySslHostIface),
  &z_proxy_ssl_host_iface_funcs.super,
};