Hi
I have some easy (I hope) questions:
I wrote a multithreaded ftp bouncer in c++
So far everything works
But if I use certain ftp clients (for example flashfxp v2.1.923) sometimes
some bytes disappear
And if I transfer a textfile, there is a "?" at every lineend
The datafiles are not corrupted every time but often enough
If I use a newer flashfxp version this problem doesn't appear
Any ideas?

Here some lines from the cource code:

-------------------------
// init ssl stuff
        clientsslctx = NULL;
        SSL_load_error_strings();
        SSL_library_init();
        OpenSSL_add_all_algorithms();
        if (RAND_status()) { debugmsg("RAND_status ok"); }
        else { cout << "RAND_status not ok\n"; return 0; }
        clientsslctx =  SSL_CTX_new(SSLv23_server_method());
        if (clientsslctx == NULL)
        {
                cout << "error creating ctx\n";
                return 0;
        }
        SSL_CTX_set_options(clientsslctx, SSL_OP_NO_SSLv2);
        SSL_CTX_set_default_verify_paths(clientsslctx);
        //SSL_CTX_set_options(clientsslctx,SSL_OP_ALL);
        CRYPTO_thread_setup();
        if
(SSL_CTX_use_certificate_file(clientsslctx,"dsa.pem",SSL_FILETYPE_PEM) <= 0)
        {
                cout << "error loading cert file!\n";
                return 0;
        }
        if (SSL_CTX_use_PrivateKey_file(clientsslctx, "dsa.pem",
SSL_FILETYPE_PEM) <=0 )
        {
                cout << "error loading private key!\n";
                return 0;
        }
                
        if ( !SSL_CTX_check_private_key(clientsslctx))
        {
                cout << "key invalid\n";
                return 0;
        }
        //SSL_CTX_set_default_verify_paths(clientsslctx);
        //SSL_CTX_set_session_id_context(clientsslctx, (const unsigned
char*)"1", 1);
        
        SSL_CTX_set_tmp_dh_callback(clientsslctx, tmp_dh_cb);
        char    *tls_cipher_list = "ALL:!EXP";
        SSL_CTX_set_cipher_list(clientsslctx, tls_cipher_list);
-------------------------
This is my init part for the ssl ctx running in my server part

This is my init part for thread handling
//---------------------------------------------------------------------
void CRYPTO_thread_setup(void);
void CRYPTO_thread_cleanup(void);
static void pthreads_locking_callback(int mode,int type,const char *file,int
line);
static unsigned long pthreads_thread_id(void );

static pthread_mutex_t *lock_cs;
static long *lock_count;



void CRYPTO_thread_setup(void)
{
        int i;

        lock_cs = (pthread_mutex_t*)OPENSSL_malloc(CRYPTO_num_locks() *
sizeof(pthread_mutex_t));
        lock_count = (long *)OPENSSL_malloc(CRYPTO_num_locks() *
sizeof(long));
        for (i=0; i<CRYPTO_num_locks(); i++)
        {
                lock_count[i]=0;
                pthread_mutex_init(&(lock_cs[i]),NULL);
        }

        CRYPTO_set_id_callback((unsigned long (*)())pthreads_thread_id);
        CRYPTO_set_locking_callback(pthreads_locking_callback);
}

void thread_cleanup(void)
{
        int i;

        CRYPTO_set_locking_callback(NULL);
        for (i=0; i<CRYPTO_num_locks(); i++)
        {
                pthread_mutex_destroy(&(lock_cs[i]));
        }
        OPENSSL_free(lock_cs);
        OPENSSL_free(lock_count);
}

void pthreads_locking_callback(int mode, int type, const char *file,
     int line)
{
        #if 0
        fprintf(stderr,"thread=%4d mode=%s lock=%s %s:%d\n",
        CRYPTO_thread_id(),
        (mode&CRYPTO_LOCK)?"l":"u",
        (type&CRYPTO_READ)?"r":"w",file,line);
        #endif
        #if 0
        if (CRYPTO_LOCK_SSL_CERT == type)
        fprintf(stderr,"(t,m,f,l) %ld %d %s %d\n",
        CRYPTO_thread_id(),
        mode,file,line);
        #endif
        if (mode & CRYPTO_LOCK)
        {
                pthread_mutex_lock(&(lock_cs[type]));
                lock_count[type]++;
        }
        else
        {
                pthread_mutex_unlock(&(lock_cs[type]));
        }
}

unsigned long pthreads_thread_id(void)
{
        unsigned long ret;

        ret=(unsigned long)pthread_self();
        return(ret);
}
//---------------------------------------------------------------------

And this is the send function I use

int total = 0;
        int bytesleft = nrbytes;
        int rc,len;
        len = nrbytes;
        while(total < len) 
        {               
                
                if (sslcon == NULL)
                {
                        rc = send(sock,data+total,bytesleft,0);
                }
                else
                {
                        rc = SSL_write(sslcon, data+total, bytesleft);
                }
                
                if (rc == -1) { break; }
                total += rc;
                bytesleft -= rc;
        }
        if (bytesleft == 0) { return 1; }
        else { return 0; }

perhaps someone can tell if this is totally nonsense of if I forgort
something important

Thanks in advance
Stephan

______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    [EMAIL PROTECTED]
Automated List Manager                           [EMAIL PROTECTED]

Reply via email to