Esempio n. 1
0
void    smtp_session_free(SMTP_SESSION *session)
{
#ifdef USE_TLS
    if (session->stream) {
	vstream_fflush(session->stream);
	if (session->tls_context)
	    tls_client_stop(smtp_tls_ctx, session->stream,
			  var_smtp_starttls_tmout, 0, session->tls_context);
    }
    if (session->tls_protocols)
	myfree(session->tls_protocols);
    if (session->tls_grade)
	myfree(session->tls_grade);
    if (session->tls_exclusions)
	vstring_free(session->tls_exclusions);
    if (session->tls_matchargv)
	argv_free(session->tls_matchargv);
#endif
    if (session->stream)
	vstream_fclose(session->stream);
    myfree(session->dest);
    myfree(session->host);
    myfree(session->addr);
    myfree(session->namaddr);
    myfree(session->namaddrport);
    if (session->helo)
	myfree(session->helo);

    vstring_free(session->buffer);
    vstring_free(session->scratch);
    vstring_free(session->scratch2);

    if (session->history)
	smtp_chat_reset(session);
    if (session->mime_state)
	mime_state_free(session->mime_state);

#ifdef USE_SASL_AUTH
    smtp_sasl_cleanup(session);
#endif

    debug_peer_restore();
    myfree((char *) session);
}
Esempio n. 2
0
void    smtp_session_free(SMTP_SESSION *session)
{
#ifdef USE_TLS
    if (session->stream) {
	vstream_fflush(session->stream);
    }
    if (session->tls_context) {
	if (session->features &
	    (SMTP_FEATURE_FROM_CACHE | SMTP_FEATURE_FROM_PROXY))
	    tls_proxy_context_free(session->tls_context);
	else
	    tls_client_stop(smtp_tls_ctx, session->stream,
			  var_smtp_starttls_tmout, 0, session->tls_context);
    }
#endif
    if (session->stream)
	vstream_fclose(session->stream);
    myfree(session->namaddr);
    myfree(session->namaddrport);
    if (session->helo)
	myfree(session->helo);

    vstring_free(session->buffer);
    vstring_free(session->scratch);
    vstring_free(session->scratch2);

    if (session->history)
	smtp_chat_reset(session);
    if (session->mime_state)
	mime_state_free(session->mime_state);

#ifdef USE_SASL_AUTH
    smtp_sasl_cleanup(session);
#endif

    debug_peer_restore();
    myfree((void *) session);
}
Esempio n. 3
0
File: main.c Progetto: 10jschen/acl
static void run_one(TLS_APPL_STATE *client_tls_ctx)
{
	ACL_VSTREAM *client;
	TLS_SESS_STATE *client_sess_ctx;
	TLS_CLIENT_START_PROPS tls_props;
	char  buf[4096];
	int   i, ret;
	time_t last, now;

	int   tls_level = 2;
	char *tls_nexthop = "test.com.cn";
	char *host = "test.com.cn";
	char *namaddrport = "test.com.cn";
	char *serverid = "service:addr:port:helo";
	char *tls_protocols = SSL_TXT_TLSV1;
	char *tls_grade = "low";  /* high, medium, low, export, null */
	char *tls_exclusions = "";
	ACL_ARGV *tls_matchargv = 0;

	client = acl_vstream_connect(serv_addr, ACL_BLOCKING, 20, 30, 8192);
	if (client == NULL) {
		printf("connect %s error(%s)\n", serv_addr, acl_last_serror());
		return;
	}

	acl_tcp_set_nodelay(ACL_VSTREAM_SOCK(client));

#if 0
	client_sess_ctx = TLS_CLIENT_START(&tls_props,
			ctx = client_tls_ctx,
			stream = client,
			log_level = var_client_tls_loglevel,
			timeout = var_client_starttls_tmout,
			tls_level = tls_level,
			nexthop = tls_nexthop,
			host = host,
			namaddr = namaddrport,
			serverid = serverid,
			protocols = tls_protocols,
			cipher_grade = tls_grade,
			cipher_exclusions = tls_exclusions,
			matchargv = tls_matchargv,
			fpt_dgst = var_client_tls_fpt_dgst);
#else
	tls_props.ctx = client_tls_ctx;
	tls_props.stream = client;
	tls_props.log_level = var_client_tls_loglevel;
	tls_props.timeout = var_client_starttls_tmout;
	tls_props.tls_level = tls_level;
	tls_props.nexthop = tls_nexthop;
	tls_props.host = host;
	tls_props.namaddr = namaddrport;
	tls_props.serverid = serverid;
	tls_props.protocols = tls_protocols;
	tls_props.cipher_grade = tls_grade;
	tls_props.cipher_exclusions = tls_exclusions;
	tls_props.matchargv = tls_matchargv;
	tls_props.fpt_dgst = var_client_tls_fpt_dgst;

	client_sess_ctx = tls_client_start(&tls_props);
#endif

	if (client_sess_ctx == NULL) {
		printf("TLS_CLIENT_START error\n");
		acl_vstream_close(client);
		return;
	}

	if (tls_level >= TLS_LEV_VERIFY) {
		if (!TLS_CERT_IS_TRUSTED(client_sess_ctx)) {
			printf("Server certificate not trusted\n");
		}
	}

	if (tls_level > TLS_LEV_ENCRYPT) {
		if (!TLS_CERT_IS_MATCHED(client_sess_ctx)) {
			printf("Server certificate not verified\n");
		}
	}

	time(&last);
	i = 0;
	while (1) {
		ret = acl_vstream_fprintf(client, "hello world\n");
		if (ret == ACL_VSTREAM_EOF)
			goto END;
		ret = acl_vstream_gets(client, buf, sizeof(buf));
		if (ret == ACL_VSTREAM_EOF)
			goto END;
		break;
		i++;
		if (i % 50000 == 0) {
			time(&now);
			printf("client: i=%d, time=%ld\n", i, now - last);
			last = now;
		}
	}

if (0)
{
	if (acl_vstream_writen(client, request, strlen(request)) == ACL_VSTREAM_EOF)
		printf("write request error\n");
	else {
		while (1) {
			if (acl_vstream_gets_nonl(client, buf, sizeof(buf)) == ACL_VSTREAM_EOF)
				break;
			/*
			printf("%s\n", buf);
			*/
		}
		/*
		printf("gets respond over now\n");
		*/
	}
}

END:
	tls_client_stop(client_tls_ctx, client, var_client_starttls_tmout, 0, client_sess_ctx);
	acl_vstream_close(client);
}