Beispiel #1
0
/**
	@memo Start the UPnP Daemon thread.

	@doc
		This function must be called in multithreaded mode to start the
		UPnP daemon, which listens for requests/announcements on the network,
		and sends any events to the attached control point/device runtime.

	@see UPnP_StopDaemon

    @return error code
 */
int  UPnP_StartDaemon (
		UPnPRuntime *rt /** pointer to \Ref{UPnPRuntime} struct */
	)
{
 #ifdef UPNP_MULTITHREAD
	RTP_THREAD threadHandle;

  	UPNP_RUNTIME_ENTER_CRITICAL(rt);

	if (rt->daemonState == UPNP_DAEMON_STOPPED)
	{
		if (rtp_thread_spawn (
				&threadHandle,
				_UPnP_Daemon,
				0, /* thread name */
				0, /* stack size (0 == normal) */
				0, /* priority (0 == normal) */
				rt
			) >= 0)
		{
			rt->daemonState = UPNP_DAEMON_RUNNING;
		  	UPNP_RUNTIME_EXIT_CRITICAL(rt);
			return (0);
		}
	}

  	UPNP_RUNTIME_EXIT_CRITICAL(rt);
 #endif

	return (-1);
}
Beispiel #2
0
/*---------------------------------------------------------------------------*/
int rtp_helper_thread_start (
		RTP_HELPER_THREAD_CTX* ctx		
	)
{
	int result = -1;
	RTP_THREAD threadHandle;

	rtp_sig_mutex_claim(ctx->mutex);
	
	if (rtp_thread_spawn (
			&threadHandle, 
			_rtp_helper_thread, 
			0, 
			RTP_HELPER_THREAD_STACK_SIZE, 
			RTP_HELPER_THREAD_PRIORITY, 
			ctx
		) >= 0)
	{
		ctx->numHelpersRunning++;
		result = 0;
	}
	
	rtp_sig_mutex_release(ctx->mutex);
	
	return (result);
}
Beispiel #3
0
/*---------------------------------------------------------------------------*/
int  rtp_timer_init     (void)
{
    if (rtpTimerInitialized == 0)
    {
        if (rtp_sig_mutex_alloc(&rtpTimerLock, 0) >= 0)
        {
            if (rtp_sig_semaphore_alloc(&rtpTimerSignal, 0) >= 0)
            {
                RTP_THREAD newThread;
                
                DLLIST_INIT(&rtpTimerNewList);
                DLLIST_INIT(&rtpTimerActiveList);
                
                rtpTimerNextToProcess = 0;
                
                if (rtp_thread_spawn (&newThread,
                                      _rtp_timer_thread,
                                      0, 
                                      0, 
                                      2, 
                                      0) >= 0)
                {
                    rtpTimerInitialized = 1;
                    return (0);
                }
                
                rtp_sig_semaphore_free(rtpTimerSignal);
            }
            else
            {
                rtp_printf("rtp_timer_init - rtp_sig_semaphore_alloc failed!\n");
            }
            
            rtp_sig_mutex_free(rtpTimerLock);
        }
        else
        {
            rtp_printf("rtp_timer_init - rtp_sig_mutex_alloc failed!");
        }
        
        return (-1);
    }
    
    rtpTimerInitialized++;
    return (0); 
}
Beispiel #4
0
RTSMB_STATIC void rtsmb_srv_net_thread_split (PNET_THREAD pMaster, PNET_THREAD pThread)
{
    int numSessions = (int)pMaster->numSessions;
    int i, k = 0;
    int end = numSessions / 2;
    RTP_HANDLE newThread;
    /**
     * Set up thread, giving it half our sessions.
     */
    for (i =  numSessions - 1; i >= end; i--)
    {
        pThread->sessionList[k] = pMaster->sessionList[i];

        /**
         * We must also switch buffer pointers to correct place.
         */
        SMBS_SetBuffers (&pThread->sessionList[k]->smbCtx, pThread->inBuffer,
            prtsmb_srv_ctx->small_buffer_size, pThread->outBuffer, prtsmb_srv_ctx->small_buffer_size,
            pThread->tmpBuffer, prtsmb_srv_ctx->small_buffer_size);

        k++;

        pMaster->sessionList[i] = (PNET_SESSIONCTX)0;
        pMaster->numSessions --;
    }
    RTSMB_DEBUG_OUTPUT_STR ("rtsmb_srv_net_thread_split: Giving ", RTSMB_DEBUG_TYPE_ASCII);
    RTSMB_DEBUG_OUTPUT_INT ((int) (numSessions - end));
    RTSMB_DEBUG_OUTPUT_STR (" session", RTSMB_DEBUG_TYPE_ASCII);
    RTSMB_DEBUG_OUTPUT_STR ((numSessions - end == 1 ? "" : "s"), RTSMB_DEBUG_TYPE_ASCII);
    RTSMB_DEBUG_OUTPUT_STR (" to a thread.\n", RTSMB_DEBUG_TYPE_ASCII);

    rtsmb_srv_net_thread_init (pThread, (dword) (numSessions - end));

    if (rtp_thread_spawn(&newThread, (RTP_ENTRY_POINT_FN) rtsmb_srv_net_thread_main, "SMBTHREAD", 0, 0, pThread))
    {
        RTSMB_DEBUG_OUTPUT_STR("rtsmb_srv_net_thread_split: Couldn't start thread!\n", RTSMB_DEBUG_TYPE_ASCII);
    }
}
Beispiel #5
0
// ---------------------------------------------------- 
// ENTRY POINT
// ---------------------------------------------------- 
int smbservermain(void)
{
    char c;
    int go;
    int  have_printer;
    byte security_mode;
    RTP_THREAD new_thread;
#ifndef RTSMB_RTIP
    int spinState = 0;
    char spinner[4] = {'\\', '-', '/', '|'};
#endif

    // ------------------------------------------------ 
#if (INCLUDE_RTIP)
    rtp_memcpy(my_ip_srv_address, my_ip_address, IP_ALEN);
    rtp_memcpy(ip_srv_mask_address, ip_mask_address, IP_ALEN);
#endif

    // ------------------------------------------------ 
    rtp_printf("\n\nRun Alt Port Numbers(Y/y) or Well-Known(N/n)");
    while (!kbhit ())
    {       
    }
    c = getch ();
    if (c == 'Y' || c == 'y')
    {
        rtsmb_init_port_alt ();
    }
    
    if (c == 'N' || c == 'n')
    {
        rtsmb_init_port_well_know ();
    }

    // ------------------------------------------------ 
    if (!rtp_file_mkdir (SHARE_PATH))
    {
        rtp_printf("WARNING: mkdir of SHARE_PATH failed %s\n", SHARE_PATH, 0);
    }

    rtp_printf("\nsmbservermain - enter\n");
    go = 1;
    /* Start ertfs on windows*/
    //pc_ertfs_init ();

    /* initialize server */
    rtsmb_srv_init (my_ip_srv_address, ip_srv_mask_address, 
                    NETWORK_NAME , NETWORK_GROUP);
    rtp_printf ("Initialized rtsmb\n");

#ifdef USE_CONFIG_FILE
    rtsmb_srv_read_config ("smb_config.txt");
#else

    rtp_printf("Note: The demo does not actually print data, it just captures print data to a temporary file.\n");

    {
    char printerName[32];
    char driverName[32];
    char tempPath[32];
    char prnFile[32];

        rtp_strcpy(printerName, "SmbPrinter");
        rtp_strcpy(driverName, "HP LaserJet 1100");
        rtp_strcpy(tempPath, TEMP_PATH);
        rtp_strcpy(prnFile, "SmbPrintData.prn");

        have_printer = in_printer(printerName,driverName, tempPath, prnFile);
        if (have_printer)
        {
            rtsmb_srv_share_add_printer (printerName, driverName, 1, (PSMBFILEAPI)0, tempPath, 0, (PFCHAR)0, prnFile);
        }
    }
    security_mode = in_loginmode();

    //rtsmb_srv_share_add_tree (SHARE_NAME, DESCRIPTION,  NULL, SHARE_PATH, SHARE_FLAGS_8_3, SECURITY_READWRITE, NULL);
    //rtsmb_srv_share_add_tree (SHARE_NAME, DESCRIPTION, (PSMBFILEAPI)0, SHARE_PATH, SHARE_FLAGS_CREATE, SECURITY_READWRITE, (PFCHAR)0);

    rtsmb_srv_share_add_ipc ((PFCHAR)0);

    rtsmb_srv_set_mode (security_mode);  /* AUTH_USER_MODE or AUTH_SHARE_MODE */

    rtsmb_srv_register_group ("rw_access");
    rtsmb_srv_register_group ("rd_access");

    {
    char shareName[32];
    char sharePath[32];
    char shareDesc[32];
    char sharePass[32];
    char secCode[32];

        rtp_strcpy(shareName, SHARE_NAME);
        rtp_strcpy(shareDesc, "Rtsmbshare");
        rtp_strcpy(sharePath, SHARE_PATH);
        rtp_strcpy(sharePass, "");
        rtp_strcpy(secCode,"2");

        if (in_share(security_mode, shareName, sharePath, shareDesc, sharePass, secCode))
        {
        byte security_mode; /* Defult is 2  SECURITY_READWRITE */
        char *psharePass;
            if (sharePass[0])
                psharePass = &sharePass[0];
            else
                psharePass = 0;
            security_mode = (byte)(secCode[0] -'0');
            rtsmb_srv_share_add_tree (shareName, shareDesc, (PSMBFILEAPI)0, sharePath, SHARE_FLAGS_CREATE, security_mode, (PFCHAR)psharePass);
            rtsmb_srv_set_group_permissions ("rw_access", shareName, SECURITY_READWRITE);
            rtsmb_srv_set_group_permissions ("rd_access", shareName, SECURITY_READ);
        }
    }

    //  rtsmb_srv_set_group_permissions ("rw_access", SHARE_NAME, SECURITY_READWRITE);
    rtsmb_srv_set_group_permissions ("rw_access", "IPC$", SECURITY_READWRITE);
    rtsmb_srv_set_group_permissions ("rd_access", "IPC$", SECURITY_READWRITE);

    //rtsmb_srv_register_group ("ro_access");
    //rtsmb_srv_set_group_permissions ("ro_access", SHARE_NAME, SECURITY_READ);
    //rtsmb_srv_set_group_permissions ("ro_access", "IPC$", SECURITY_READWRITE);

    //rtsmb_srv_register_group ("wo_access");
    //rtsmb_srv_set_group_permissions ("wo_access", SHARE_NAME, SECURITY_WRITE);
    //rtsmb_srv_set_group_permissions ("wo_access", "IPC$", SECURITY_READWRITE);

    /* No access */
    //rtsmb_srv_register_group ("nonebs");
    //rtsmb_srv_set_group_permissions ("nonebs", SHARE_NAME, SECURITY_NONE);
    //rtsmb_srv_set_group_permissions ("nonebs", "IPC$", SECURITY_NONE);

    //rtsmb_srv_register_user (SMB_GUESTNAME, (PFCHAR)0);
    //rtsmb_srv_register_user (SMB_GUESTNAME, "ebs");
    //rtsmb_srv_add_user_to_group (SMB_GUESTNAME, "rw_access");

    if (security_mode == AUTH_USER_MODE)
    {
    char userName[32];
    char userPass[32];
    char userPerm[32];

        if (in_guestaccount())
            rtsmb_srv_register_user (SMB_GUESTNAME, (PFCHAR)0);

        rtp_strcpy(userName, "user");
        rtp_strcpy(userPass, "password");
        rtp_printf("Add users, enter a blank user to stop : ");
        while (in_user(userName, userPass, userPerm))
        {
            rtsmb_srv_register_user (userName, userPass);
            if (rtp_strcmp(userPerm, "rw") == 0)
                    {rtsmb_srv_add_user_to_group (userName, "rw_access");break;}
            else if (rtp_strcmp(userPerm, "r") == 0)
                {rtsmb_srv_add_user_to_group (userName, "rd_access");break;}
        }
    }

#endif //USE_CONFIG_FILE

#if (1)
    if (rtp_thread_spawn (
                &new_thread,
                (RTP_ENTRY_POINT_FN) rtsmb_main,
                (const char *) "RTIP_SMB_SRV",
                STACKSIZE_HUGE_INDEX,
                TASKPRIO_NORMAL_INDEX,
                (void *) 0
            ) < 0)
        {
            rtp_term_puts("spawn of SMB task failed");
            return(-1);
        }
        rtp_term_puts("spawn of SMB task WORKED");

        while (1)
        {
#ifndef RTSMB_RTIP
            spinState += 1;
            spinState = spinState%4;
            rtp_printf("\b%c",spinner[spinState]);

#endif
            rtsmb_srv_cycle (1000);
        }

#else
    //Main Loop
    while(go)
    {
        rtsmb_main ();
        if(rtp_term_kbhit())
        {
//          switch (getch())
            switch (rtp_term_getch())
            {
            case 'q':   go = 0;
                        break;
            default:    break;
            }
        }
    }

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

    rtsmb_srv_shutdown ();
    rtp_net_exit ();
#endif
    return(0);
}//main