Пример #1
0
static void TEST__server_1(SOCK sock)
{
    EIO_Status status;
    size_t     n_io, n_io_done;
    char       buf[TEST_BUFSIZE];

    CORE_LOG(eLOG_Note, "TEST__server_1(TS1)");

    /* Receive and send back a short string */
    SOCK_SetDataLogging(sock, eOn);
    n_io = strlen(s_C1) + 1;
    status = SOCK_Read(sock, buf, n_io, &n_io_done, eIO_ReadPlain);
    assert(status == eIO_Success  &&  n_io == n_io_done);
    assert(strcmp(buf, s_C1) == 0  ||  strcmp(buf, s_M1) == 0);

    SOCK_SetDataLogging(sock, eDefault);
    SOCK_SetDataLoggingAPI(eOn);
    n_io = strlen(s_S1) + 1;
    status = SOCK_Write(sock, s_S1, n_io, &n_io_done, eIO_WritePersist);
    assert(status == eIO_Success  &&  n_io == n_io_done);
    SOCK_SetDataLoggingAPI(eOff);

    /* Receive a very big binary blob, and check its content */
    {{
#define DO_LOG_SIZE    300
#define DONT_LOG_SIZE  BIG_BLOB_SIZE - DO_LOG_SIZE
        unsigned char* blob = (unsigned char*) malloc(BIG_BLOB_SIZE);

        status = SOCK_Read(sock,blob,DONT_LOG_SIZE,&n_io_done,eIO_ReadPersist);
        assert(status == eIO_Success  &&  n_io_done == DONT_LOG_SIZE);

        SOCK_SetDataLogging(sock, eOn);
        status = SOCK_Read(sock, blob + DONT_LOG_SIZE, DO_LOG_SIZE,
                           &n_io_done, eIO_ReadPersist);
        assert(status == eIO_Success  &&  n_io_done == DO_LOG_SIZE);
        SOCK_SetDataLogging(sock, eDefault);

        for (n_io = 0;  n_io < BIG_BLOB_SIZE;  n_io++)
            assert(blob[n_io] == (unsigned char) n_io);
        free(blob);
    }}

    /* Receive a very big binary blob, and write data back */
    {{
        unsigned char* blob = (unsigned char*) malloc(BIG_BLOB_SIZE);
        int i;
        for (i = 0;  i < 10;  i++) {
            /*            X_SLEEP(1);*/
            status = SOCK_Read(sock, blob + i * SUB_BLOB_SIZE, SUB_BLOB_SIZE,
                               &n_io_done, eIO_ReadPersist);
            assert(status == eIO_Success  &&  n_io_done == SUB_BLOB_SIZE);
            status = SOCK_Write(sock, blob + i * SUB_BLOB_SIZE, SUB_BLOB_SIZE,
                                &n_io_done, eIO_WritePersist);
            assert(status == eIO_Success  &&  n_io_done == SUB_BLOB_SIZE);
        }
        for (n_io = 0;  n_io < BIG_BLOB_SIZE;  n_io++)
            assert(blob[n_io] == (unsigned char) n_io);
        free(blob);
    }}

    /* Shutdown on write */
#ifdef NCBI_OS_MSWIN
    assert(SOCK_Shutdown(sock, eIO_ReadWrite) == eIO_Success);
#else
    assert(SOCK_Shutdown(sock, eIO_Write)     == eIO_Success);
#endif
    assert(SOCK_Status  (sock, eIO_Write)     == eIO_Closed);
    assert(SOCK_Write   (sock, 0, 0, &n_io_done, eIO_WritePersist)
                                              == eIO_Closed);
    assert(SOCK_Status  (sock, eIO_Write)     == eIO_Closed);
#ifdef NCBI_OS_MSWIN
    assert(SOCK_Status  (sock, eIO_Read)      == eIO_Closed);
#else
    assert(SOCK_Status  (sock, eIO_Read)      == eIO_Success);
#endif
    assert(SOCK_Close   (sock)                == eIO_Success);
}
Пример #2
0
static void TEST__client_1(SOCK sock)
{
    EIO_Status status;
    size_t     n_io, n_io_done;
    char       buf[TEST_BUFSIZE];

    CORE_LOG(eLOG_Note, "TEST__client_1(TC1)");

    /* Send a short string */
    SOCK_SetDataLoggingAPI(eOn);
    {{
        const char* x_C1 = s_C1;
        n_io = strlen(x_C1) + 1;
        status = SOCK_Write(sock, x_C1, n_io, &n_io_done, eIO_WritePersist);
    }}
    assert(status == eIO_Success  &&  n_io == n_io_done);

    /* Read the string back (it must be bounced by the server) */
    SOCK_SetDataLoggingAPI(eOff);
    SOCK_SetDataLogging(sock, eOn);
    n_io = strlen(s_S1) + 1;
    status = SOCK_Read(sock, buf, n_io, &n_io_done, eIO_ReadPeek);
    status = SOCK_Read(sock, buf, n_io, &n_io_done, eIO_ReadPlain);
    if (status == eIO_Closed)
        CORE_LOG(eLOG_Fatal, "TC1:: connection closed");

    assert(status == eIO_Success  &&  n_io == n_io_done);
    assert(strcmp(buf, s_S1) == 0);
    assert(SOCK_PushBack(sock, buf, n_io_done) == eIO_Success);
    memset(buf, '\xFF', n_io_done);
    assert(SOCK_Read(sock, buf, n_io_done, &n_io_done, eIO_ReadPlain)
           == eIO_Success);
    assert(SOCK_Status(sock, eIO_Read) == eIO_Success);
    assert(strcmp(buf, s_S1) == 0);

    SOCK_SetDataLogging(sock, eDefault);

    /* Send a very big binary blob */
    {{
        size_t i;
        unsigned char* blob = (unsigned char*) malloc(BIG_BLOB_SIZE);
        for (i = 0;  i < BIG_BLOB_SIZE;  blob[i] = (unsigned char) i, i++)
            continue;
        for (i = 0;  i < 10;  i++) {
            status = SOCK_Write(sock, blob + i * SUB_BLOB_SIZE, SUB_BLOB_SIZE,
                                &n_io_done, eIO_WritePersist);
            assert(status == eIO_Success  &&  n_io_done==SUB_BLOB_SIZE);
        }
        free(blob);
    }}

    /* Send a very big binary blob with read on write */
    /* (it must be bounced by the server) */
    {{
        size_t i;
        unsigned char* blob = (unsigned char*) malloc(BIG_BLOB_SIZE);

        SOCK_SetReadOnWrite(sock, eOn);

        for (i = 0;  i < BIG_BLOB_SIZE;  blob[i] = (unsigned char) i, i++)
            continue;
        for (i = 0;  i < 10;  i++) {
            status = SOCK_Write(sock, blob + i * SUB_BLOB_SIZE, SUB_BLOB_SIZE,
                                &n_io_done, eIO_WritePersist);
            assert(status == eIO_Success  &&  n_io_done == SUB_BLOB_SIZE);
        }
        /* Receive back a very big binary blob, and check its content */
        memset(blob,0,BIG_BLOB_SIZE);
        for (i = 0;  i < 10;  i++) {
            status = SOCK_Read(sock, blob + i * SUB_BLOB_SIZE, SUB_BLOB_SIZE,
                               &n_io_done, eIO_ReadPersist);
            assert(status == eIO_Success  &&  n_io_done == SUB_BLOB_SIZE);
        }
        for (n_io = 0;  n_io < BIG_BLOB_SIZE;  n_io++)
            assert(blob[n_io] == (unsigned char) n_io);
        free(blob);
    }}

    /* Try to read more data (must hit EOF as the peer is shut down) */
    assert(SOCK_Read(sock, buf, 1, &n_io_done, eIO_ReadPeek)
           == eIO_Closed);
    assert(SOCK_Status(sock, eIO_Read) == eIO_Closed);
    assert(SOCK_Read(sock, buf, 1, &n_io_done, eIO_ReadPlain)
           == eIO_Closed);
    assert(SOCK_Status(sock, eIO_Read) == eIO_Closed);

    /* Shutdown on read */
    assert(SOCK_Shutdown(sock, eIO_Read)  == eIO_Success);
    assert(SOCK_Status  (sock, eIO_Write) == eIO_Success);
    assert(SOCK_Status  (sock, eIO_Read)  == eIO_Closed);
    assert(SOCK_Read    (sock, 0, 0, &n_io_done, eIO_ReadPlain) == eIO_Closed);
    assert(SOCK_Read    (sock, 0, 0, &n_io_done, eIO_ReadPeek)  == eIO_Closed);
    assert(SOCK_Status  (sock, eIO_Read)  == eIO_Closed);
    assert(SOCK_Status  (sock, eIO_Write) == eIO_Success);
    assert(SOCK_Read    (sock, buf, 1,&n_io_done,eIO_ReadPlain) == eIO_Closed);
    assert(SOCK_Read    (sock, buf, 1,&n_io_done,eIO_ReadPeek)  == eIO_Closed);
    assert(SOCK_Status  (sock, eIO_Read)  == eIO_Closed);
    assert(SOCK_Status  (sock, eIO_Write) == eIO_Success);

    /* Shutdown on write */
    assert(SOCK_Shutdown(sock, eIO_Write)          == eIO_Success);
    assert(SOCK_Status  (sock, eIO_Write)          == eIO_Closed);
    assert(SOCK_Write   (sock, 0, 0, &n_io_done, eIO_WritePersist)
                                                   == eIO_Closed);
    assert(SOCK_Status  (sock, eIO_Write)          == eIO_Closed);
    assert(SOCK_Write   (sock, buf, 1, &n_io_done, eIO_WritePersist)
                                                   == eIO_Closed);
    assert(SOCK_Status  (sock, eIO_Write)          == eIO_Closed);

    /* Double shutdown should be okay */
    assert(SOCK_Shutdown(sock, eIO_Read)      == eIO_Success);
    assert(SOCK_Shutdown(sock, eIO_ReadWrite) == eIO_Success);
    assert(SOCK_Shutdown(sock, eIO_Write)     == eIO_Success);
    assert(SOCK_Status  (sock, eIO_Read)      == eIO_Closed);
    assert(SOCK_Status  (sock, eIO_Write)     == eIO_Closed);
    assert(SOCK_Status  (sock, eIO_ReadWrite) == eIO_InvalidArg);
}
Пример #3
0
/****************************************************
 * Main Method
 ****************************************************/
int main (int argc, char *argv[])
{
    int go;
    int total, free, per, size;
    char cwd [SMBF_FILENAMESIZE + 1];
/*  int sid;   */
    RTSMB_CLI_SESSION_DSTAT dstat;

    go = 1;
    if (SOCK_Init ())
        return 1;

/*  rtsmb_cli_session_new_with_name (argv[1], TRUE, NULL, &sid);            */
/*  rtsmb_cli_session_full_server_enum (sid, 0xFFFFFFFF, argv[2], NULL, 0); */
/*  return 0;                                                               */

    PRINTF (("Initialized rtsmb\n"));

    rtsmb_cli_ez_set_cwd ("/*blah/c"); */

    rtsmb_cli_ez_open ("yo.txt", RTP_FILE_O_CREAT | RTP_FILE_O_RDONLY, RTP_FILE_S_IREAD);

    rtsmb_cli_ez_get_cwd (cwd, SMBF_FILENAMESIZE);
    printf ("cwd is %s\n", cwd);

    rtsmb_cli_ez_set_cwd ("/*blah/c/trans2"); */

    rtsmb_cli_ez_open ("\\yo.txt", RTP_FILE_O_CREAT | RTP_FILE_O_RDONLY, RTP_FILE_S_IREAD);

    rtsmb_cli_ez_get_cwd (cwd, SMBF_FILENAMESIZE);
    printf ("cwd is %s\n", cwd);

    PRINTF (("Starting client test\n"));
/*  rtsmb_cli_test_regression ("blah", 1);   */

#if defined (RTSMB_LINUX)
    rtsmb_srv_share_add_tree ("c", "testbed dir", NULL, "/rtsmb", SHARE_FLAGS_CASE_SENSITIVE, SECURITY_READWRITE, NULL);
    rtsmb_srv_share_add_ipc (NULL);
#elif 0
    rtsmb_srv_read_config ("c:\\smbconf.txt");
#else

    rtsmb_cli_ez_set_user ("Michael Terry", "hello");

    rtsmb_srv_share_add_tree ("c", "testbed dir", NULL, "c:\\rtsmb", SHARE_FLAGS_8_3 | SHARE_FLAGS_CREATE, SECURITY_READWRITE, NULL);
/*  if (rtsmb_srv_share_add_tree ("c", "testbed dir", NULL, "\\\\" SHARE_SERVER "\\c", SHARE_FLAGS_8_3, SECURITY_READWRITE, NULL) < 0)   */
        /*abort ();                                                                                                                      */
    rtsmb_srv_share_add_ipc (NULL);
  /*  rtsmb_srv_share_add_printer ("printer", "Test Printer", 1, NULL, "c:\\", 0, NULL, "HP LaserJet 1100");   */

    /*rtsmb_srv_set_mode (AUTH_SHARE_MODE);   */

    rtsmb_srv_set_mode (AUTH_USER_MODE);
    rtsmb_srv_register_group ("ebs");
    rtsmb_srv_set_group_permissions ("ebs", "c", SECURITY_READWRITE);
    rtsmb_srv_set_group_permissions ("ebs", "IPC$", SECURITY_READWRITE);
    rtsmb_srv_set_group_permissions ("ebs", "printer", SECURITY_READWRITE);

    rtsmb_srv_register_group ("nonebs");
    rtsmb_srv_set_group_permissions ("nonebs", "c", SECURITY_READ);
    rtsmb_srv_set_group_permissions ("nonebs", "IPC$", SECURITY_READWRITE);
    rtsmb_srv_set_group_permissions ("nonebs", "printer", SECURITY_READWRITE);

    rtsmb_srv_register_user (SMB_GUESTNAME, NULL);
    rtsmb_srv_add_user_to_group (SMB_GUESTNAME, "nonebs");

    rtsmb_srv_register_user ("TONY", "roxor");
    rtsmb_srv_add_user_to_group ("TONY", "ebs");

    rtsmb_srv_register_user ("JOHN", "hello");
    rtsmb_srv_add_user_to_group ("JOHN", "ebs");

    rtsmb_srv_register_user ("MIKE TERRY", "blarg");
    rtsmb_srv_add_user_to_group ("MIKE TERRY", "ebs");

    rtsmb_srv_register_user ("MIKE", "blarg");
    rtsmb_srv_add_user_to_group ("MIKE", "ebs");


#endif
/*  os_spawn_task (TASKCLASS_CURRENT, rtsmb_main, 0,0,0,0);   */

    while (1)
    {
        rtsmb_srv_cycle (-1);
        if (go++ % 2 == 0)
        {
        /*  printf ("0");   */
        }
        else
        {
    /*      printf ("-");   */
        }
    }

    printf ("Press return to shut down SMB Server \n");
    /*Main Loop   */
    while(go)
    {
        int r;
    /*  ks_sleep (ks_ticks_p_sec () * 2);   */
        rtsmb_main ();
#ifndef RTSMB_LINUX
        if(kbhit())
        {
            switch (getch())
            {
            case 'q':   go = 0;
                        break;
            case 'r':   rtsmb_srv_share_remove ("c");
                        break;
            case 'a':   rtsmb_srv_share_add_tree ("c", "windows dir", NULL, "c:\\rtsmb", SHARE_FLAGS_8_3, SECURITY_READWRITE, "blarggity24");
                        break;
            case 'i':   {
                byte newip[4] = {192,168,1,100};
                byte newmask[4] = {255, 255, 0, 0};
                        rtsmb_srv_set_ip (newip, newmask);
                        }
                        break;
            case 'u':   {
                byte newip[4] = {192,168,1,20};
                byte newmask[4] = {255, 255, 255, 0};
                        rtsmb_srv_set_ip (newip, newmask);
                        }
                        break;
#ifdef RTSMB_RTIP
            case 'p':   PRINTF (("Starting Debug Output:\n"));
                        DEBUG_ERROR ("\n\n", PORTS_TCP, 0, 0);
                        break;
#endif

            case '1':   r = rtsmb_cli_ez_open ("/*blah/c/yo.txt", RTP_FILE_O_CREAT | RTP_FILE_O_RDONLY, RTP_FILE_S_IREAD); */
                        PRINTF (("On EZ open, fd is %i\n", r));
                        break;

            case '2':   r = rtsmb_cli_ez_get_free ("/*blah/c/yo.txt", &total, &free, &per, &size); */
                        PRINTF (("total: %i, free: %i, per: %i, size: %i\n", total, free, per, size));
                        break;

            case '3':   r = rtsmb_cli_ez_find_first ("/**", &dstat); */

                        printf ("Start of server search.\n");
                        while (r == 1)
                        {
                            if (dstat.unicode)
                            {
                                PRINTF (("  server name: %S\n", dstat.filename));
                            }
                            else
                            {
                                PRINTF (("  server name: %s\n", dstat.filename));
                            }

                            r = rtsmb_cli_ez_find_next (&dstat);
                        }

                        rtsmb_cli_ez_find_close (&dstat);
                        break;

            default:    break;
            }
       }
#endif
    }

    /*Shutdown   */
    PRINTF (("main: shutting down\n"));

    rtsmb_cli_shutdown ();
    rtsmb_srv_shutdown ();
    SOCK_Shutdown ();

    return(0);
}/*main */