Click here to Skip to main content
15,882,388 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: MFC - Drawning Bitmaps Transparent Pin
Stuart Dootson8-May-09 5:34
professionalStuart Dootson8-May-09 5:34 
Questionsegmentation error while using mpz_powm in a loop Pin
shrims4u8-May-09 3:40
shrims4u8-May-09 3:40 
QuestionRe: segmentation error while using mpz_powm in a loop Pin
David Crow8-May-09 3:44
David Crow8-May-09 3:44 
AnswerRe: segmentation error while using mpz_powm in a loop Pin
shrims4u8-May-09 3:48
shrims4u8-May-09 3:48 
GeneralRe: segmentation error while using mpz_powm in a loop Pin
David Crow8-May-09 3:52
David Crow8-May-09 3:52 
GeneralRe: segmentation error while using mpz_powm in a loop Pin
shrims4u8-May-09 3:59
shrims4u8-May-09 3:59 
GeneralRe: segmentation error while using mpz_powm in a loop Pin
molesworth8-May-09 5:35
molesworth8-May-09 5:35 
GeneralRe: segmentation error while using mpz_powm in a loop Pin
shrims4u8-May-09 6:00
shrims4u8-May-09 6:00 
ill mail the whole program to uall

Actually it is a milter which decrypts the incoming mail messages...

<br />
/* sample_milter - example mail filter module<br />
**<br />
** Copyright © 2004 by Jef Poskanzer <jef@acme.com>.<br />
** All rights reserved.<br />
**<br />
** Redistribution and use in source and binary forms, with or without<br />
** modification, are permitted provided that the following conditions<br />
** are met:<br />
** 1. Redistributions of source code must retain the above copyright<br />
**    notice, this list of conditions and the following disclaimer.<br />
** 2. Redistributions in binary form must reproduce the above copyright<br />
**    notice, this list of conditions and the following disclaimer in the<br />
**    documentation and/or other materials provided with the distribution.<br />
**<br />
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND<br />
** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE<br />
** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE<br />
** ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE<br />
** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL<br />
** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS<br />
** OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)<br />
** HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT<br />
** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY<br />
** OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF<br />
** SUCH DAMAGE.<br />
**<br />
** For commentary on this license please see http://www.acme.com/license.html<br />
*/<br />
<br />
#include <stdio.h><br />
#include <stdlib.h><br />
#include <unistd.h><br />
#include <string.h><br />
#include <pthread.h><br />
#include <syslog.h><br />
#include <sys/types.h><br />
#include <sys/socket.h><br />
#include <netinet/in.h><br />
#include <arpa/inet.h><br />
#include <sys/stat.h><br />
#include <fcntl.h><br />
<br />
#include <glib.h><br />
#include <gmime/gmime.h><br />
<br />
#include "libmilter/mfapi.h"<br />
<br />
//////////////////////////////////////////////////////////////<br />
#include "gmp.h"<br />
<br />
<br />
/* Forwards. */<br />
<br />
static void usage( void );<br />
static sfsistat sample_connect( SMFICTX* ctx, char* connhost, _SOCK_ADDR* connaddr );<br />
static sfsistat sample_helo( SMFICTX* ctx, char* helohost );<br />
static sfsistat sample_envfrom( SMFICTX* ctx, char** fromargs );<br />
static sfsistat sample_envrcpt( SMFICTX* ctx, char** rcptargs );<br />
static sfsistat sample_header( SMFICTX* ctx, char* name, char* value );<br />
static sfsistat sample_eoh( SMFICTX* ctx );<br />
static sfsistat sample_body( SMFICTX* ctx, unsigned char* bytes, size_t len );<br />
static sfsistat sample_eom( SMFICTX* ctx );<br />
static sfsistat sample_abort( SMFICTX* ctx );<br />
static sfsistat sample_close( SMFICTX* ctx );<br />
static void thread_data_destructor( void* data );<br />
<br />
////////////////////////////////////////////////////////////////////////////////////////////<br />
int smfi_replacebody(<br />
	SMFICTX *ctx,<br />
	unsigned char *bodyp,<br />
	int bodylen<br />
);<br />
<br />
<br />
int smfi_chgheader(<br />
	SMFICTX *ctx,<br />
	char *name,<br />
	int hdridx,<br />
	char *value<br />
);<br />
////////////////////////////////////////////////////////////////////////////////////////////<br />
<br />
<br />
/* Globals. */<br />
<br />
static char* argv0;<br />
static pthread_key_t key;<br />
static int connections;<br />
static char* data_buffer, *contentTypeBuffer;<br />
//data_buffer=(char *) malloc(100);<br />
void *ret;  // This line is compulsory to get correct output<br />
size_t size;<br />
int flag=0;<br />
<br />
	GMimeMessage *message;<br />
	GMimeStream *stream;<br />
	GMimeParser *parser;<br />
	GMimeMultipart *multipart;<br />
	GMimePart *mime_part,*mime_part0;<br />
	GMimeContentType *contentType,*contentType1;<br />
<br />
static struct smfiDesc smfilter =<br />
    {<br />
    "SAMPLE",				/* filter name */<br />
    SMFI_VERSION,			/* version code -- do not change */<br />
    SMFIF_CHGBODY | SMFIF_CHGHDRS,	/* flags */<br />
    sample_connect,			/* connection info filter */<br />
    sample_helo,			/* SMTP HELO command filter */<br />
    sample_envfrom,			/* envelope sender filter */<br />
    sample_envrcpt,			/* envelope recipient filter */<br />
    sample_header,			/* header filter */<br />
    sample_eoh,				/* end of header */<br />
    sample_body,			/* body block filter */<br />
    sample_eom,				/* end of message */<br />
    sample_abort,			/* message aborted */<br />
    sample_close			/* connection cleanup */<br />
    };<br />
<br />
<br />
int<br />
main( int argc, char** argv )<br />
    {<br />
    char* sockarg;<br />
	<br />
////////////////////////////////////////////<br />
<br />
/* init the gmime library */<br />
	g_mime_init (0);<br />
	<br />
	message = g_mime_message_new(FALSE);<br />
	<br />
/////////////////////////////////////////////<br />
<br />
    argv0 = strrchr( argv[0], '/' );<br />
    if ( argv0 != (char*) 0 )<br />
	++argv0;<br />
    else<br />
	argv0 = argv[0];<br />
<br />
    connections = 0;<br />
<br />
    if ( argc != 2 )<br />
	usage();<br />
    sockarg = argv[1];<br />
<br />
    if ( pthread_key_create( &key, &thread_data_destructor ) )<br />
	{<br />
	perror( "pthread_key_create" );<br />
	exit( 1 );<br />
	}<br />
<br />
    openlog( argv0, 0, LOG_MAIL );<br />
<br />
    (void) smfi_setconn( sockarg );<br />
    if ( smfi_register( smfilter ) == MI_FAILURE )<br />
	{<br />
	(void) fprintf( stderr, "%s: register failed\n", argv0 );<br />
	exit( 1 );<br />
	}<br />
    if ( smfi_main() == MI_FAILURE )<br />
	{<br />
	(void) fprintf( stderr, "%s: milter failed\n", argv0 );<br />
	exit( 1 );<br />
	}<br />
<br />
    syslog( LOG_INFO, "exitting - %d connections", connections );<br />
    (void) pthread_key_delete( key );<br />
    closelog();<br />
<br />
<br />
    exit( 0 );<br />
    }<br />
<br />
<br />
static void<br />
usage( void )<br />
    {<br />
    (void) fprintf( stderr, "usage:  %s socket\n", argv0 );<br />
    exit( 1 );<br />
    }<br />
<br />
<br />
/* The filter routines.  These can return the following values:<br />
**<br />
**   SMFIS_CONTINUE	Continue processing the current connection, message,<br />
**			or recipient.<br />
**   SMFIS_REJECT	For a connection-oriented routine, reject this<br />
**			connection; call xxfi_close.<br />
**			For a recipient-oriented routine, reject the current<br />
**			recipient (but continue processing the current message).<br />
**			For a message-oriented routine (except xxfi_eom or<br />
**			xxfi_abort), reject this message.<br />
**   SMFIS_DISCARD	For a message- or recipient-oriented routine, accept<br />
**			this message, but silently discard it.<br />
**			This should not be returned by a connection-oriented<br />
**			routine.<br />
**   SMFIS_ACCEPT	For a connection-oriented routine, accept this<br />
**			connection without further filter processing;<br />
**			call xxfi_close.<br />
**			For a message- or recipient-oriented routine, accept<br />
**			this message without further filtering.<br />
**   SMFIS_TEMPFAIL	Return a temporary failure, i.e. the corresponding<br />
**			SMTP command will return an appropriate 4xx status<br />
**			code.<br />
**			For a connection-oriented routine, fail for this<br />
**			connection; call xxfi_close.<br />
**			For a recipient-oriented routine, only fail for the<br />
**			current recipient; continue message processing.<br />
**			For a message-oriented routine (except xxfi_envfrom),<br />
**			fail for this message.<br />
**<br />
** The milter API is fully documented here:<br />
**   http://www.milter.org/milter_api/<br />
**<br />
** The sequence of callbacks is as follows:<br />
**<br />
**   The SMTP connection is accepted - sample_connect()<br />
**   The client sends a HELO/EHLO command - sample_helo()<br />
**   For each message:<br />
**     The client sends a MAIL FROM command - sample_envfrom()<br />
**     The client sends one or more RCPT TO commands - sample_envrcpt()<br />
**     The client sends a DATA command.<br />
**     The client sends one or more headers - sample_header()<br />
**     The client sends a blank line - sample_eoh()<br />
**     The client sends the message body - zero or more calls to sample_body()<br />
**     The client sends a dot - sample_eom()<br />
**   The client sends a QUIT command - sample_close().<br />
*/<br />
<br />
<br />
/* Per-thread data structure. */<br />
struct thread_data {<br />
    int junk;<br />
    };<br />
<br />
/* Per-connection data structure. */<br />
struct connection_data {<br />
    int connection_num;<br />
    int messages;<br />
    int recipients;<br />
    int headers;<br />
    int bodyblocks;<br />
    size_t bodybytes;<br />
    int aborts;<br />
    };<br />
<br />
<br />
/* sample_connect - handle the initial TCP connection<br />
**<br />
** Called at the start of a connection.  Any per-connection data should<br />
** be initialized here.<br />
**<br />
** connhost: The hostname of the client, based on a reverse lookup.<br />
** connaddr: The client's IP address, based on getpeername().<br />
*/<br />
static sfsistat<br />
sample_connect( SMFICTX* ctx, char* connhost, _SOCK_ADDR* connaddr )<br />
    {<br />
    struct thread_data* td;<br />
    struct connection_data* cd;<br />
    struct sockaddr_in* sin;<br />
<br />
    td = (struct thread_data*) pthread_getspecific( key );<br />
    if ( td == (struct thread_data*) 0 )<br />
	{<br />
	td = (struct thread_data*) malloc( sizeof(struct thread_data) );<br />
	if ( td == (struct thread_data*) 0 )<br />
	    return SMFIS_TEMPFAIL;<br />
	if ( pthread_setspecific( key, (void*) td ) )<br />
	    {<br />
	    free( (void*) td );<br />
	    return SMFIS_TEMPFAIL;<br />
	    }<br />
	}<br />
<br />
    cd = (struct connection_data*) malloc( sizeof(struct connection_data) );<br />
    if ( cd == (struct connection_data*) 0 )<br />
	return SMFIS_TEMPFAIL;<br />
    (void) smfi_setpriv( ctx, (void*) cd );<br />
    cd->connection_num = ++connections;<br />
<br />
    sin = (struct sockaddr_in*) connaddr;<br />
    syslog( LOG_INFO, "conn# %d - sample_connect( \"%s\" [%s] )", cd->connection_num, connhost, inet_ntoa( sin->sin_addr ) );<br />
<br />
    cd->messages = 0;<br />
    cd->aborts = 0;<br />
<br />
    return SMFIS_CONTINUE;<br />
    }<br />
<br />
<br />
/* sample_helo - handle the MAIL HELO<br />
**<br />
** Called at the start of a connection.<br />
**<br />
** helohost: The string passed to the HELO/EHLO command.<br />
*/<br />
static sfsistat<br />
sample_helo( SMFICTX* ctx, char* helohost )<br />
    {<br />
    struct connection_data* cd = (struct connection_data*) smfi_getpriv( ctx );<br />
<br />
    syslog( LOG_INFO, "conn# %d - sample_helo( \"%s\" )", cd->connection_num, helohost );<br />
<br />
    return SMFIS_CONTINUE;<br />
    }<br />
<br />
<br />
/* sample_envfrom - handle the MAIL FROM:<> command<br />
**<br />
** Called at the start of each message.  There may be multiple messages<br />
** in a connection.  Any per-message data should be initialized here.<br />
**<br />
** The sender address is also known as the "envelope from" address.<br />
**<br />
** fromargs: Null-terminated SMTP command arguments; fromargs[0] is the<br />
**           sender address.<br />
*/<br />
static sfsistat<br />
sample_envfrom( SMFICTX* ctx, char** fromargs )<br />
    {<br />
    data_buffer=(char*)malloc(100000000);<br />
<br />
    struct connection_data* cd = (struct connection_data*) smfi_getpriv( ctx );<br />
<br />
    syslog( LOG_INFO, "conn# %d - sample_envfrom( \"%s\" )", cd->connection_num, fromargs[0] );<br />
	<br />
/*	if(fromargs[0]!="<shrims@localhost>")<br />
	{<br />
		return SMFIS_REJECT;<br />
	}<br />
*/<br />
    ++cd->messages;<br />
    cd->recipients = 0;<br />
    cd->headers = 0;<br />
    cd->bodyblocks = 0;<br />
    cd->bodybytes = 0;<br />
<br />
    return SMFIS_CONTINUE;<br />
    }<br />
<br />
<br />
/* sample_envrcpt - handle a RCPT TO:<> command<br />
**<br />
** Called separately for each recipient of a message.<br />
**<br />
** rcptargs: Null-terminated SMTP command arguments; rcptargs[0] is the<br />
**           recipient address.<br />
*/<br />
static sfsistat<br />
sample_envrcpt( SMFICTX* ctx, char** rcptargs )<br />
    {<br />
    struct connection_data* cd = (struct connection_data*) smfi_getpriv( ctx );<br />
<br />
    syslog( LOG_INFO, "conn# %d - sample_envrcpt( \"%s\" )", cd->connection_num, rcptargs[0] );<br />
<br />
    ++cd->recipients;<br />
<br />
    return SMFIS_CONTINUE;<br />
    }<br />
<br />
<br />
/* sample_header - handle a header line<br />
**<br />
** Called separately for each header line in a message.<br />
**<br />
** name:  Header field name.<br />
** value: Header vield value, including folded whitespace.  The final CRLF<br />
**        is removed.<br />
*/<br />
static sfsistat<br />
sample_header( SMFICTX* ctx, char* name, char* value )<br />
    {<br />
    struct connection_data* cd = (struct connection_data*) smfi_getpriv( ctx );<br />
<br />
    syslog( LOG_INFO, "conn# %d - sample_header( \"%s\", \"%s\" )", cd->connection_num, name, value );<br />
<br />
    ++cd->headers;<br />
<br />
    return SMFIS_CONTINUE;<br />
    }<br />
<br />
<br />
/* sample_eoh - handle the end of the headers<br />
**<br />
** Called once per message after all headers have been processed.<br />
*/<br />
static sfsistat<br />
sample_eoh( SMFICTX* ctx )<br />
    {<br />
    struct connection_data* cd = (struct connection_data*) smfi_getpriv( ctx );<br />
<br />
    syslog( LOG_INFO, "conn# %d - sample_eoh()", cd->connection_num );<br />
<br />
    return SMFIS_CONTINUE;<br />
    }<br />
<br />
<br />
/* sample_body - handle a block of body bytes<br />
**<br />
** The body of the message is filtered via zero or more calls to this<br />
** routine.  Most messages are handled with a single body call, but<br />
** some do take more than one.<br />
**<br />
** bytes: Pointer to the block of body data.<br />
** len:   Length of the block.<br />
*/<br />
static sfsistat<br />
sample_body( SMFICTX* ctx, unsigned char* bytes, size_t len )<br />
    {<br />
    struct connection_data* cd = (struct connection_data*) smfi_getpriv( ctx );<br />
<br />
<br />
strncat(data_buffer, bytes, len);<br />
//syslog( LOG_INFO, "conn# %d - sample_body( %d ) length= %d sample body(%s)", cd->connection_num, flag,strlen(data_buffer),  bytes );<br />
//flag=flag+1;<br />
<br />
    ++cd->bodyblocks;<br />
    cd->bodybytes += len;<br />
<br />
    return SMFIS_CONTINUE;<br />
    }<br />
<br />
<br />
/* sample_eom - handle the end of the message<br />
**<br />
** Called once per message after all bod y blocks have been processed.<br />
** Any per-message data should be freed both here and in sample_abort().<br />
*/<br />
static sfsistat<br />
sample_eom( SMFICTX* ctx )<br />
    {<br />
    struct connection_data* cd = (struct connection_data*) smfi_getpriv( ctx );<br />
<br />
    syslog( LOG_INFO, "conn# %d - sample_eom(), %d recipients, %d headers, %d bodyblocks with %d bytes", cd->connection_num, cd->recipients, cd->headers, cd->bodyblocks, (int) cd->bodybytes );<br />
<br />
<br />
//syslog( LOG_INFO, "conn# %d - sample_body( %d ) length= %d sample body(%s)", cd->connection_num, flag,strlen(data_buffer),  data_buffer );<br />
<br />
/***Retrieving the body of the message which is the <br />
****actual required message to be decrypted<br />
***/<br />
<br />
	/* create the parts' content stream */<br />
	stream = g_mime_stream_mem_new_with_buffer (data_buffer, strlen(data_buffer) );<br />
<br />
	/* create a new parser object to parse the stream */<br />
	parser = g_mime_parser_new_with_stream (stream);<br />
	<br />
	/* unref the stream (parser owns a ref, so this object does not actually get free'd until we destroy the parser) */<br />
	g_object_unref (stream);<br />
	<br />
	/* parse the message from the stream */<br />
	message = g_mime_parser_construct_message (parser);<br />
	<br />
	/* free the parser (and the stream) */<br />
	g_object_unref (parser);<br />
<br />
<br />
gboolean *is_html;<br />
//const char *content;<br />
//content=(char*)malloc(10000000);<br />
const char *content = g_mime_message_get_body ( message , FALSE , is_html);<br />
//free(data_buffer);<br />
strncpy(data_buffer,content,strlen(content));<br />
//*(data_buffer+strlen(content))='\0';<br />
<br />
	<br />
<br />
<br />
/****************************Decrypting the message**********************************************************************/<br />
<br />
<br />
syslog( LOG_INFO, "conn# %d - body = %s", cd->connection_num, content );<br />
	<br />
int noOfBlocks = strlen(data_buffer)/308;<br />
syslog( LOG_INFO, "conn# %d - body = %d no of blocks = %d", cd->connection_num, strlen(data_buffer), noOfBlocks );<br />
<br />
mpz_t bigbody,encbody,decbody,n,d,e;<br />
	<br />
	<br />
<br />
	mpz_init_set_str (e, "5", 10);<br />
<br />
	mpz_init_set_str (n, "81072118814004638617775947138239917744589505176471539666269773100315781097546894455560658571445286325125766632676152452856383447352821337178984474781813475276075048299705214136395672502245955793627681061360075723595075874516950614187016991430293887968216015097675955399134514678660046996064181098182893072761", 10);<br />
<br />
	mpz_init_set_str (d, "32428847525601855447110378855295967097835802070588615866507909240126312439018757782224263428578114530050306653070460981142553378941128534871593789912725382636961637010791821646038659077539848411532121133465246631106852802485583932352673149866783600963924490576147444236696494852521901563664557493382382127469", 10);<br />
<br />
<br />
<br />
char *STR;<br />
STR=(char*)malloc(1000);<br />
<br />
//mpz_init(bigbody);<br />
//mpz_init(decbody);<br />
<br />
mpz_t array[10];<br />
mpz_array_init (array, 10, 308);<br />
mpz_t array1[10];<br />
mpz_array_init (array1, 10, 100000);<br />
<br />
char substring[400];<br />
int i=0,lower=0,upper=308;<br />
while(i<noOfBlocks)<br />
{	<br />
<br />
		<br />
	<br />
<br />
	syslog( LOG_INFO, "conn# %d - i = %d", cd->connection_num, i );<br />
	strncpy(substring, data_buffer + lower, upper);<br />
	*(substring+308)='\0';<br />
	syslog( LOG_INFO, "conn# %d - substring = %s", cd->connection_num, substring );<br />
	lower=upper;<br />
	upper=upper+308;<br />
	<br />
<br />
	<br />
		<br />
<br />
	//mpz_init_set_str(bigbody,substring,10);<br />
	mpz_init_set_str(array[i],substring,10);<br />
<br />
	//size=len;<br />
<br />
	<br />
	<br />
	//mpz_get_str (STR, 10, bigbody);<br />
	mpz_get_str (STR, 10, array[i]);<br />
	strcat(STR,"\0");<br />
	syslog( LOG_INFO, "conn# %d - Encrypted-Biginteger = %s", cd->connection_num, STR );<br />
<br />
/*	mpz_get_str (STR, 10, d);<br />
	strcat(STR,"\0");<br />
	syslog( LOG_INFO, "conn# %d - d = %s", cd->connection_num, STR );<br />
<br />
	mpz_get_str (STR, 10, n);<br />
	strcat(STR,"\0");<br />
	syslog( LOG_INFO, "conn# %d - n = %s", cd->connection_num, STR );<br />
*/<br />
<br />
	//fflush(stdin);<br />
	//array1[i]=(mpz_t)malloc(400);<br />
	//mpz_init_set_str(array1[i],"0",10);<br />
	//mpz_init(decbody);<br />
	//mpz_powm (decbody, bigbody, d, n);<br />
	mpz_init(array1[i]);<br />
	mpz_powm (array1[i], array[i], d, n);<br />
<br />
	//char *decSTR;<br />
	//decSTR=(char*)malloc(1000);<br />
<br />
	//mpz_get_str (STR, 10, decbody);<br />
	mpz_get_str (STR, 10, array1[i]);<br />
	syslog( LOG_INFO, "conn# %d - Decrypted-Biginteger = %s", cd->connection_num, STR );<br />
<br />
	size_t length;<br />
	void *ret;<br />
	char *decrypted;<br />
	decrypted=(char*)malloc(1000);<br />
	<br />
	ret=mpz_export (decrypted, &length, 1,sizeof(data_buffer[0]), 0, 0, array1[i]);<br />
	//ret=mpz_export (decrypted, &length, 1,sizeof(data_buffer[0]), 0, 0, array1[i]);<br />
<br />
	strncpy(decrypted,ret,length);<br />
	*(decrypted+length)='\0';<br />
<br />
<br />
	syslog( LOG_INFO, "conn# %d - size decrypted = %d Decrypted = %s", cd->connection_num,length, (char *)ret );<br />
	fflush(stdout);<br />
	<br />
	//free(STR);<br />
	//free(decSTR);<br />
	free(decrypted);<br />
	//mpz_clear(bigbody);<br />
	//mpz_clear(decbody);<br />
	fflush(stdin);<br />
	fflush(stdout);<br />
	//mpz_clear(array[i]);<br />
	//mpz_clear(array1[i]);<br />
	i++;<br />
	<br />
}<br />
	<br />
<br />
/*<br />
	mpz_t bigbody,encbody,decbody,n,d,e;<br />
	mpz_init(bigbody);<br />
<br />
	mpz_init_set_str (e, "5", 10);<br />
<br />
	mpz_init_set_str (n, "81072118814004638617775947138239917744589505176471539666269773100315781097546894455560658571445286325125766632676152452856383447352821337178984474781813475276075048299705214136395672502245955793627681061360075723595075874516950614187016991430293887968216015097675955399134514678660046996064181098182893072761", 10);<br />
<br />
	mpz_init_set_str (d, "32428847525601855447110378855295967097835802070588615866507909240126312439018757782224263428578114530050306653070460981142553378941128534871593789912725382636961637010791821646038659077539848411532121133465246631106852802485583932352673149866783600963924490576147444236696494852521901563664557493382382127469", 10);<br />
<br />
char substring[400];<br />
//substring = (char*)malloc(400);<br />
int i=0,lower=0,upper=308;<br />
<br />
//for(i=0;i<2;i++)<br />
//{<br />
	strncpy(substring, data_buffer + lower, upper);<br />
	*(substring+308)='\0';<br />
	syslog( LOG_INFO, "conn# %d - substring = %s", cd->connection_num, substring );<br />
<br />
	lower=upper;<br />
	upper=upper+308;<br />
	i++;<br />
<br />
	<br />
	//mpz_import (bigbody, len-2, 1, sizeof(data_buffer[0]), 0, 0, data_buffer);<br />
<br />
	mpz_set_str(bigbody,substring,10);<br />
<br />
	//size=len;<br />
<br />
<br />
	char *STR;<br />
	STR=(char*)malloc(1000);<br />
	mpz_get_str (STR, 10, bigbody);<br />
	strcat(STR,"\0");<br />
	syslog( LOG_INFO, "conn# %d - Encrypted-Biginteger = %s", cd->connection_num, STR );<br />
<br />
<br />
<br />
mpz_powm (decbody, bigbody, d, n);<br />
<br />
mpz_get_str (STR, 10, decbody);<br />
syslog( LOG_INFO, "conn# %d - Decrypted-Biginteger = %s", cd->connection_num, STR );<br />
<br />
size_t length;<br />
void *ret;<br />
char *decrypted;<br />
decrypted=(char*)malloc(1000);<br />
	<br />
ret=mpz_export (decrypted, &length, 1,sizeof(data_buffer[0]), 0, 0, decbody);<br />
<br />
strncpy(decrypted,ret,length);<br />
*(decrypted+length)='\0';<br />
<br />
<br />
syslog( LOG_INFO, "conn# %d - size decrypted = %d Decrypted = %s", cd->connection_num,length, (char *)ret );<br />
fflush(stdout);<br />
<br />
free(decrypted);<br />
//}<br />
<br />
/************************Retrieving the content-Type of the actual message***********************/<br />
/*<br />
	// free the message //<br />
	g_object_unref (message);<br />
<br />
	// create the parts' content stream //<br />
	stream = g_mime_stream_mem_new_with_buffer (content, strlen(content));<br />
<br />
	// create a new parser object to parse the stream //<br />
	parser = g_mime_parser_new_with_stream (stream);<br />
	<br />
	// unref the stream (parser owns a ref, so this object does not actually get free'd until we destroy the parser) //<br />
	g_object_unref (stream);<br />
	<br />
	// parse the message from the stream //<br />
	message = g_mime_parser_construct_message (parser);<br />
	<br />
	// free the parser (and the stream) //<br />
	g_object_unref (parser);<br />
<br />
<br />
multipart = g_mime_message_get_mime_part ( message );<br />
<br />
contentType =  g_mime_object_get_content_type  ((GMimeObject *)multipart);<br />
<br />
content =  g_mime_content_type_to_string       (contentType);<br />
<br />
contentTypeBuffer = (char *)malloc(10000000);<br />
strcat(contentTypeBuffer, content);<br />
<br />
strcat(contentTypeBuffer, "; \n\tboundary=\"");<br />
<br />
content = g_mime_content_type_get_parameter   (contentType , "boundary");<br />
syslog( LOG_INFO, "conn# %d - boundary = %s", cd->connection_num, content );<br />
strcat(contentTypeBuffer, content );<br />
<br />
fflush(stdout);<br />
strcat(contentTypeBuffer, "\" ");<br />
<br />
//free(data_buffer);<br />
/***************************REPLACING THE CONTENT-TYPE HEADER**********************************/<br />
/*<br />
char *name = "Content-Type";<br />
<br />
if( smfi_chgheader( ctx, name, 1, contentTypeBuffer) == MI_FAILURE)<br />
{<br />
	syslog( LOG_INFO, "MI_FAILURE");<br />
}<br />
<br />
<br />
/***************************REPLACING WITH DECRYPTED BODY*************************************/<br />
/*<br />
fflush(stdout);<br />
if(smfi_replacebody(ctx, data_buffer, strlen(data_buffer) )== MI_FAILURE)<br />
{<br />
	syslog( LOG_INFO, "MI_FAILURE");<br />
}<br />
free(data_buffer);<br />
<br />
/*********************************************************************************************/<br />
<br />
<br />
    return SMFIS_CONTINUE;<br />
    }<br />
<br />
<br />
/* sample_abort - handle the message being aborted<br />
**<br />
** May be called at any time during processing of a message, indicating<br />
** that something went wrong.  Any per-message data should be freed both<br />
** here and in sample_eom().<br />
*/<br />
static sfsistat<br />
sample_abort( SMFICTX* ctx )<br />
    {<br />
    struct connection_data* cd = (struct connection_data*) smfi_getpriv( ctx );<br />
<br />
    syslog( LOG_INFO, "conn# %d - sample_abort(), %d recipients, %d headers, %d bodyblocks with %d bytes", cd->connection_num, cd->recipients, cd->headers, cd->bodyblocks, (int) cd->bodybytes );<br />
<br />
    return SMFIS_CONTINUE;<br />
    }<br />
<br />
<br />
/* sample_close - handle the connection being closed<br />
**<br />
** Called once at the end of a connection.  Any per-connection data<br />
** should be freed here.<br />
*/<br />
static sfsistat<br />
sample_close( SMFICTX* ctx )<br />
    {<br />
    struct connection_data* cd = (struct connection_data*) smfi_getpriv( ctx );<br />
<br />
    syslog( LOG_INFO, "conn# %d - sample_close(), %d messages", cd->connection_num, cd->messages );<br />
<br />
    if ( cd != (struct connection_data*) 0 )<br />
	{<br />
	(void) smfi_setpriv( ctx, (void*) 0 );<br />
	free( (void*) cd );<br />
	}<br />
<br />
    return SMFIS_CONTINUE;<br />
    }<br />
<br />
<br />
static void<br />
thread_data_destructor( void* data )<br />
    {<br />
    struct thread_data* td = (struct thread_data*) data;<br />
<br />
    free( (void*) td );<br />
    }

GeneralRe: segmentation error while using mpz_powm in a loop Pin
shrims4u8-May-09 6:12
shrims4u8-May-09 6:12 
GeneralRe: segmentation error while using mpz_powm in a loop Pin
molesworth8-May-09 8:53
molesworth8-May-09 8:53 
GeneralRe: segmentation error while using mpz_powm in a loop Pin
shrims4u8-May-09 4:02
shrims4u8-May-09 4:02 
GeneralRe: segmentation error while using mpz_powm in a loop Pin
jeron18-May-09 5:05
jeron18-May-09 5:05 
GeneralRe: segmentation error while using mpz_powm in a loop Pin
shrims4u8-May-09 5:57
shrims4u8-May-09 5:57 
GeneralRe: segmentation error while using mpz_powm in a loop Pin
jeron18-May-09 6:02
jeron18-May-09 6:02 
GeneralRe: segmentation error while using mpz_powm in a loop Pin
shrims4u8-May-09 6:10
shrims4u8-May-09 6:10 
Questionhow to code its`?so hard if we use OOP Pin
trongduy8-May-09 3:30
trongduy8-May-09 3:30 
AnswerRe: how to code its`?so hard if we use OOP Pin
Stuart Dootson8-May-09 3:41
professionalStuart Dootson8-May-09 3:41 
AnswerRe: how to code its`?so hard if we use OOP Pin
David Crow8-May-09 3:41
David Crow8-May-09 3:41 
AnswerRe: how to code its`?so hard if we use OOP Pin
Michael Schubert8-May-09 8:05
Michael Schubert8-May-09 8:05 
GeneralRe: how to code its`?so hard if we use OOP Pin
CPallini8-May-09 10:15
mveCPallini8-May-09 10:15 
QuestionProblem with read StdOut from *.com files under Vista Pin
Slepchenkov8-May-09 3:18
Slepchenkov8-May-09 3:18 
AnswerRe: Problem with read StdOut from *.com files under Vista Pin
Madhu Nair8-May-09 7:32
Madhu Nair8-May-09 7:32 
GeneralRe: Problem with read StdOut from *.com files under Vista Pin
Slepchenkov10-May-09 21:09
Slepchenkov10-May-09 21:09 
QuestionRe: Problem with read StdOut from *.com files under Vista Pin
Madhu Nair11-May-09 1:19
Madhu Nair11-May-09 1:19 
GeneralRe: Problem with read StdOut from *.com files under Vista Pin
Slepchenkov11-May-09 1:38
Slepchenkov11-May-09 1:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.