示例#1
0
SMFSession_T *smf_session_new(void) {
    SMFSession_T *session;
    
    TRACE(TRACE_DEBUG,"initialize session data");
    session = (SMFSession_T *)calloc((size_t)1, sizeof(SMFSession_T));
    if (smf_list_new(&session->local_users,smf_internal_user_data_list_destroy)!=0) {
        free(session);
        return NULL;
    }

    session->helo = NULL;
    session->xforward_addr = NULL;
    session->message_file = NULL;
    session->message_size = 0;
    session->response_msg = NULL;
    session->envelope = smf_envelope_new();
    session->id = smf_internal_generate_sid();
    TRACE(TRACE_INFO,"start new session SID %s",session->id);

    return session;
}
示例#2
0
int main (int argc, char const *argv[]) {
    SMFSmtpStatus_T *status = NULL;
    SMFEnvelope_T *env = smf_envelope_new();
    SMFMessage_T *msg = NULL;
    char *msg_file = NULL;

    printf("Start smf_smtp tests...\n");
    printf("============================================\n");
    printf("This test expects a running SMTP daemon, \n");
    printf("listening on localhost:25 or TEST_NEXTHOP value,\n");
    printf("wich accepts mails for [email protected]\n");
    printf("============================================\n");

    printf("* testing smf_smtp_status_new()...\t\t\t\t");
    status = smf_smtp_status_new();
    if (status == NULL) {
        printf("failed\n");
        return -1;
    }
    printf("passed\n");

    printf("* testing smf_smtp_status_free()...\t\t\t\t");
    status->text = strdup(test_string);
    smf_smtp_status_free(status);
    printf("passed\n");

    asprintf(&msg_file, "%s/m0001.txt",SAMPLES_DIR);

    printf("* testing smf_smtp_deliver() with file...\t\t\t");
    smf_envelope_set_nexthop(env, TEST_NEXTHOP);
    smf_envelope_set_sender(env, test_email);
    smf_envelope_add_rcpt(env, test_email);
    
    status = smf_smtp_deliver(env, SMF_TLS_DISABLED, msg_file, NULL);
    if (status->code == -1) {
        printf("failed\n");
        return -1;
    }
    printf("passed\n");

    smf_smtp_status_free(status);
    printf("* testing smf_smtp_deliver() with envelope...\t\t\t");
    msg = smf_message_new();
    if (smf_message_from_file(&msg, msg_file, 0) != 0){
        printf("failed\n");
        return -1;
    }
    smf_envelope_set_message(env, msg);
    status = smf_smtp_deliver(env, SMF_TLS_DISABLED, NULL, NULL);
    if (status->code == -1) {
        printf("failed\n");
        return -1;
    }
    printf("passed\n");
    smf_smtp_status_free(status);

    printf("* testing smf_smtp_deliver() with envelope and TLS...\t\t");
    status = smf_smtp_deliver(env, SMF_TLS_REQUIRED, NULL, NULL);
    if (status->code == -1) {
        printf("failed\n");
        return -1;
    }
    printf("passed\n");
    smf_smtp_status_free(status);

    printf("* testing smf_smtp_deliver() with smtp auth...\t\t\t");
    smf_envelope_set_auth_user(env, test_auth_user);
    smf_envelope_set_auth_pass(env, test_auth_pass);
    status = smf_smtp_deliver(env, SMF_TLS_DISABLED, NULL, NULL);
    if (status->code == -1) {
        printf("failed\n");
        return -1;
    }
    printf("passed\n");
    smf_smtp_status_free(status);

    free(msg_file);
    smf_envelope_free(env);
    return 0;
}
示例#3
0
int main (int argc, char const *argv[]) {
    char *msg_file = NULL;
    SMFSmtpStatus_T *status = NULL;
    SMFSettings_T *settings = smf_settings_new();
    SMFEnvelope_T *env = smf_envelope_new();
    pid_t pid;

    smf_settings_set_pid_file(settings, "/tmp/smf_test_smtpd.pid");
    smf_settings_set_bind_ip(settings, "127.0.0.1");
    smf_settings_set_foreground(settings, 1);
    smf_settings_set_spare_childs(settings, 0);
    smf_settings_set_max_childs(settings,1);
    smf_settings_set_debug(settings,1);
    smf_settings_set_queue_dir(settings, BINARY_DIR);
    smf_settings_set_engine(settings, "smtpd");

    /* add test modules */
    smf_settings_add_module(settings, BINARY_DIR "/libtestmod1.so");
    smf_settings_add_module(settings, BINARY_DIR "/libtestmod2.so");
    
    printf("Start smf_smtpd tests...\n");

    printf("* preparing smtpd engine...\t\t\t");
    
    printf("passed\n");
    switch(pid = fork()) {
        case -1:
            printf("failed\n");
            break;
        case 0:
            if (load(settings) != 0) {
                return -1;
            }
            break;

        default:
            printf("* sending test message ...\t\t\t");
            asprintf(&msg_file, "%s/m0001.txt",SAMPLES_DIR);

            smf_envelope_set_nexthop(env, "127.0.0.1:33332");
            smf_envelope_set_sender(env, test_email);
            smf_envelope_add_rcpt(env, test_email);
            status = smf_smtp_deliver(env, SMF_TLS_DISABLED, msg_file, NULL);
            
            if (status->code == -1) {
                kill(pid,SIGTERM);
                printf("failed\n");
                return -1;
            }
            
            smf_smtp_status_free(status);
            printf("passed\n");
            kill(pid,SIGTERM);
            waitpid(pid, NULL, 0);

            break;
    }

    if(msg_file != NULL)
        free(msg_file);
        
    
    smf_settings_free(settings);
    smf_envelope_free(env);

    return 0;
}