예제 #1
0
/* main:  register the interface, start listening for clients */
void __cdecl main(int argc, char * argv[])
{
    RPC_STATUS status;
    unsigned char * pszProtocolSequence = "ncacn_ip_tcp";
    unsigned char * pszSecurity         = NULL;
    unsigned char * pszEndpoint         = "8765";
    unsigned char * pszSpn              = NULL;	
    unsigned int    cMinCalls           = 1;
    unsigned int    cMaxCalls           = 20;
    unsigned int    fDontWait           = FALSE;

    int i;

    /* allow the user to override settings with command line switches */
    for (i = 1; i < argc; i++) {
        if ((*argv[i] == '-') || (*argv[i] == '/')) {
            switch (tolower(*(argv[i]+1))) {
            case 'p':  // protocol sequence
                pszProtocolSequence = argv[++i];
                break;
            case 'e':
                pszEndpoint = argv[++i];
                break;
            case 'a':
                pszSpn = argv[++i];
                break;
            case 'm':
                cMaxCalls = (unsigned int) atoi(argv[++i]);
                break;
            case 'n':
                cMinCalls = (unsigned int) atoi(argv[++i]);
                break;
            case 'f':
                fDontWait = (unsigned int) atoi(argv[++i]);
                break;
	  /* case 'i':
		if(!_stricmp(argv[++i],"No_Authenticate"))
			ifFlag = RPC_IF_ALLOW_CALLBACKS_WITH_NO_AUTH;
		break;*/

            case 'h':
            case '?':
            default:
                Usage(argv[0]);
            }
        }
        else
            Usage(argv[0]);
    }

    status = RpcServerUseProtseqEp(pszProtocolSequence,
                                   cMaxCalls,
                                   pszEndpoint,
                                   pszSecurity);  // Security descriptor
    printf_s("RpcServerUseProtseqEp returned 0x%x\n", status);
    if (status) {
        exit(status);
    }

    /* User did not specify spn, construct one. */
    if (pszSpn == NULL) {
        MakeSpn(&pszSpn);
    }

    /* Using Negotiate as security provider */
    status = RpcServerRegisterAuthInfo(pszSpn,
                                       RPC_C_AUTHN_GSS_NEGOTIATE,
                                       NULL,
                                       NULL);
	
    printf_s("RpcServerRegisterAuthInfo returned 0x%x\n", status);
    if (status) {
        exit(status);
    }	

    status = RpcServerRegisterIfEx(umarsh_ServerIfHandle,
		                           NULL,
		                           NULL,
		                           0,
		                           RPC_C_LISTEN_MAX_CALLS_DEFAULT,
		                           NULL );

    printf_s("Calling RpcServerListen\n");
    status = RpcServerListen(cMinCalls,
                             cMaxCalls,
                             fDontWait);
    printf_s("RpcServerListen returned: 0x%x\n", status);
    if (status) {
        exit(status);
    }

    if (fDontWait) {
        printf_s("Calling RpcMgmtWaitServerListen\n");
        status = RpcMgmtWaitServerListen();  //  wait operation
        printf_s("RpcMgmtWaitServerListen returned: 0x%x\n", status);
        if (status) {
            exit(status);
        }
    }

}  // end main()
예제 #2
0
//
//  FUNCTION: ServiceStart
//
//  PURPOSE: Actual code of the service
//           that does the work.
//
//  PARAMETERS:
//    dwArgc   - number of command line arguments
//    lpszArgv - array of command line arguments
//
//  RETURN VALUE:
//    none
//
//  COMMENTS:
//    Starts the service listening for RPC requests.
//
VOID ServiceStart (HWND NotifyWindow)
{
    UINT i;
    RPC_BINDING_VECTOR *pbindingVector = 0;
    RPC_STATUS status;
    BOOL fListening = FALSE;

    ///////////////////////////////////////////////////
    //
    // Service initialization
    //

    //
    // Use protocol sequences (protseqs) specified in ProtocolArray.
    //

    if(NotifyWindow) 
	PostMessage(NotifyWindow,MPM_SERVER_STARTING,0,0);

    for(i = 0; i < sizeof(ProtocolArray)/sizeof(TCHAR *); i++)
        {


        status = RpcServerUseProtseq(ProtocolArray[i],
                                     ProtocolBuffer,
                                     0);

        if (status == RPC_S_OK)
            {
	    if(NotifyWindow) PostMessage(NotifyWindow,MPM_SERVER_PENDING,0,0);
            fListening = TRUE;
            }
        }

    if (!fListening)
        {
        // Unable to listen to any protocol!
        //
	    if(NotifyWindow) 
		PostMessage(NotifyWindow,MPM_SERVER_STOPPED,0,status);
	    dwErr = status;
        return;
        }

    //
    // Register the services interface(s).
    //

    status = RpcServerRegisterIf(R_MPE_v1_0_s_ifspec,0,0);


    if (status != RPC_S_OK) {
        if(NotifyWindow) 
	    PostMessage(NotifyWindow,MPM_SERVER_STOPPED,0,status);

        dwErr = status;
	hMainThread = 0;
        return;
    } 

    if(NotifyWindow) 
	PostMessage(NotifyWindow,MPM_SERVER_PENDING,0,0);


    // Register interface(s) and binding(s) (endpoints) with
    // the endpoint mapper.
    //

    status = RpcServerInqBindings(&pbindingVector);

    if (status != RPC_S_OK) {
	if(NotifyWindow) 
	    PostMessage(NotifyWindow,MPM_SERVER_STOPPED,0,status);
	dwErr = status;
	hMainThread = 0;
        return;
    }

    if(NotifyWindow) 
	PostMessage(NotifyWindow,MPM_SERVER_PENDING,0,0);


    status = RpcEpRegister(R_MPE_v1_0_s_ifspec,pbindingVector,0,0);

    if (status != RPC_S_OK) {
	dwErr = status;
	if(NotifyWindow) 
	    PostMessage(NotifyWindow,MPM_SERVER_STOPPED,0,status);
	hMainThread = 0;
        return;
    }


    if(NotifyWindow) 
	PostMessage(NotifyWindow,MPM_SERVER_PENDING,0,0);


    // Enable NT LM Security Support Provider (NtLmSsp service)
    //
    status = RpcServerRegisterAuthInfo(0,
                                       RPC_C_AUTHN_WINNT,
                                       0,
                                       0
                                       );
    if (status != RPC_S_OK){
	dwErr = status;
	if(NotifyWindow) 
	    PostMessage(NotifyWindow,MPM_SERVER_STOPPED,0,status);
	hMainThread = 0;
        return;
    }

    if(NotifyWindow) 
	PostMessage(NotifyWindow,MPM_SERVER_PENDING,0,0);

    

    // Start accepting client calls.
    //
    status = RpcServerListen(MinimumThreads,
                             RPC_C_LISTEN_MAX_CALLS_DEFAULT,  // rpcdce.h
                             TRUE);                           // don't block.

    if (status != RPC_S_OK) {
	dwErr = status;
	PostMessage(NotifyWindow,MPM_SERVER_STOPPED,0,status);
	hMainThread = 0;
        return;
    }


    //
    // End of initialization
    //
    ////////////////////////////////////////////////////////////

    if(NotifyWindow) 
	PostMessage(NotifyWindow,MPM_SERVER_STARTED,0,status);
    else 
	SetEvent(StartEvent);


    ////////////////////////////////////////////////////////////
    //
    // Cleanup
    //

    // RpcMgmtWaitServerListen() will block until the server has
    // stopped listening.  If this service had something better to
    // do with this thread, it would delay this call until
    // ServiceStop() had been called. (Set an event in ServiceStop()).
    //
    status = RpcMgmtWaitServerListen();

    if (status != RPC_S_OK) {
	dwErr = status;
	PostMessage(NotifyWindow,MPM_SERVER_STOPPED,0,status);
	hMainThread = 0;
        return;
    }


    NotifyWindow = g_hNotifyWindow;
    if(NotifyWindow) 
	PostMessage(NotifyWindow,MPM_SERVER_PENDING,0,0);

    // ASSERT(status == RPC_S_OK)

    status = RpcServerUnregisterIf(R_MPE_v1_0_s_ifspec,0,TRUE);

    if(NotifyWindow) 
	PostMessage(NotifyWindow,MPM_SERVER_PENDING,0,0);

    // Remove entries from the endpoint mapper database.
    //
    RpcEpUnregister(R_MPE_v1_0_s_ifspec,   // from rpcsvc.h
                    pbindingVector,
                    0);

    if(NotifyWindow) 
	PostMessage(NotifyWindow,MPM_SERVER_PENDING,0,0);
    // Delete the binding vector
    //
    status = RpcBindingVectorFree(&pbindingVector);
    if(NotifyWindow) 
	PostMessage(NotifyWindow,MPM_SERVER_STOPPED,0,status);

    //
    ////////////////////////////////////////////////////////////
    
    return;
}
예제 #3
0
    __declspec(dllexport) long RegisterRpc(
        LPWSTR pszProtocolSequence
      , LPWSTR pszEndpoint
      , LPWSTR pszServiceClass
      , LPWSTR pszNetworkAddress
      , LPWSTR psErrorMessageBuffer
      , int errorMessageBufferLength
      )
    {
        LPWSTR pszSpn = NULL;
        long lStatus;

        // The RpcServerUseProtseqEp function tells the RPC run-time library to 
        // use the specified protocol sequence combined with the specified 
        // endpoint for receiving remote procedure calls.
        //
        lStatus = RpcServerUseProtseqEp( ( RPC_WSTR ) pszProtocolSequence,
                                            RPC_C_PROTSEQ_MAX_REQS_DEFAULT,
                                            ( RPC_WSTR ) pszEndpoint,
                                            NULL );

        if ( lStatus )
        {
            swprintf_s(psErrorMessageBuffer, errorMessageBufferLength, L"RpcServerUseProtseqEp returned 0x%x", lStatus );
            return KEYPROVIDER_FAILED;
        }
	
        // User did not specify spn, construct one.
        if ( NULL == pszSpn )
        {
            // Add 2 for the slash character and null terminator.
            INT nSpnLength = wcslen( pszServiceClass ) + wcslen( pszNetworkAddress ) + 2;
            pszSpn = ( LPWSTR ) malloc( nSpnLength * sizeof( wchar_t ) ); 

            if ( !pszSpn )
            {
                return KEYPROVIDER_NOT_ENOUGH_MEMORY;
            }

            wcscpy_s( pszSpn, nSpnLength, pszServiceClass );
            wcscat_s( pszSpn, nSpnLength, L"/" );
            wcscat_s( pszSpn, nSpnLength, pszNetworkAddress );
        }

        // The RpcServerRegisterIfEx function registers an interface with 
        // the RPC run-time library.
        //
        lStatus = RpcServerRegisterIfEx( KeyProviderListener_v1_0_s_ifspec,
                                         NULL,
                                         NULL, 
                                         RPC_IF_ALLOW_CALLBACKS_WITH_NO_AUTH, 
                                         RPC_C_LISTEN_MAX_CALLS_DEFAULT, 
                                         NULL );

        if ( lStatus )
        {
            swprintf_s(psErrorMessageBuffer, errorMessageBufferLength, L"RpcServerRegisterIfEx returned 0x%x", lStatus );
            return KEYPROVIDER_FAILED;
        }

        // The RpcServerRegisterAuthInfo function registers authentication 
        // information with the RPC run-time library.
        //
        // Using Negotiate as security provider.
        lStatus = RpcServerRegisterAuthInfo( ( RPC_WSTR ) pszSpn,
                                             RPC_C_AUTHN_GSS_NEGOTIATE,
                                             NULL,
                                             NULL );
	
        if ( lStatus )
        {
            swprintf_s(psErrorMessageBuffer, errorMessageBufferLength, L"RpcServerRegisterAuthInfo returned 0x%x", lStatus );
            return KEYPROVIDER_FAILED;
        }	

        // The RpcServerListen function signals the RPC run-time library to listen 
        // for remote procedure calls.
        //
        lStatus = RpcServerListen( 1,
                                   RPC_C_LISTEN_MAX_CALLS_DEFAULT,
                                   TRUE );
        if ( lStatus )
        {
            swprintf_s(psErrorMessageBuffer, errorMessageBufferLength, L"RpcServerListen returned: 0x%x", lStatus );
            return KEYPROVIDER_FAILED;
        }

        return 0;
    }
예제 #4
0
/* main:  register the interface, start listening for clients */
void __cdecl main(int argc, char * argv[])
{
    RPC_STATUS status;
    UUID MgrTypeUuid, ClientUuid;
    unsigned char * pszProtocolSequence = "ncacn_ip_tcp";
    unsigned char * pszSecurity         = NULL;
    unsigned char * pszClientUuid       = NULL_UUID_STRING;
    unsigned char * pszMgrTypeUuid      = "11111111-1111-1111-1111-111111111111";
    unsigned char * pszEndpoint         = "8765";
    unsigned char * pszSpn              = NULL;	
    unsigned int    cMinCalls           = 1;
    unsigned int    cMaxCalls           = 20;
    unsigned int    fDontWait           = FALSE;
    int i;

    cluuid_SERVER_EPV epv2;    // the mgr_epv for the 2nd implementation

    /* allow the user to override settings with command line switches */
    for (i = 1; i < argc; i++) {
        if ((*argv[i] == '-') || (*argv[i] == '/')) {
            switch (tolower(*(argv[i]+1))) {
            case 'p':  // protocol sequence
                pszProtocolSequence = argv[++i];
                break;
            case 'e':
                pszEndpoint = argv[++i];
                break;
            case 'a':
                pszSpn = argv[++i];
                break;
            case 'm':
                cMaxCalls = (unsigned int) atoi(argv[++i]);
                break;
            case 'n':
                cMinCalls = (unsigned int) atoi(argv[++i]);
                break;
            case 'f':
                fDontWait = (unsigned int) atoi(argv[++i]);
                break;
            case '1':
                pszMgrTypeUuid = argv[++i];
                break;
            case '2':
                pszClientUuid = argv[++i];
                break;

          
            case 'h':
            case '?':
            default:
                Usage(argv[0]);
            }
        }
        else
            Usage(argv[0]);
    }

    status = RpcServerUseProtseqEp(pszProtocolSequence,
                                   cMaxCalls,
                                   pszEndpoint,
                                   pszSecurity);  // Security descriptor
    printf_s("RpcServerUseProtseqEp returned 0x%x\n", status);
    if (status) {
        exit(status);
    }

    status = UuidFromString(pszClientUuid, &ClientUuid);
    printf_s("UuidFromString returned 0x%x = %d\n", status, status);
    if (status) {
        exit(status);
    }

    status = UuidFromString(pszMgrTypeUuid, &MgrTypeUuid);
    printf_s("UuidFromString returned 0x%x = %d\n", status, status);
    if (status) {
        exit(status);
    }
    if (strcmp (pszMgrTypeUuid, NULL_UUID_STRING) == 0) {
        printf_s("Register object using non-null uuid %s\n", pszMgrTypeUuid);
        exit(1);
    }

    if (strcmp (pszClientUuid, NULL_UUID_STRING) == 0) {
        printf_s("Register object using non-null uuid %s\n", pszMgrTypeUuid);
        ClientUuid = MgrTypeUuid;
    }

    RpcObjectSetType(&ClientUuid, &MgrTypeUuid);  // associate type UUID with nil UUID
    printf_s("RpcObjectSetType returned 0x%x\n", status);
    if (status) {
        exit(status);
    }
	
    /* User did not specify spn, construct one. */
    if (pszSpn == NULL) {
        MakeSpn(&pszSpn);
    }

    /* Using Negotiate as security provider. */
    status = RpcServerRegisterAuthInfo(pszSpn,
                                       RPC_C_AUTHN_GSS_NEGOTIATE,
                                       NULL,
                                       NULL);
	
    printf_s("RpcServerRegisterAuthInfo returned 0x%x\n", status);
    if (status) {
        exit(status);
    }	

    status = RpcServerRegisterIfEx(cluuid_ServerIfHandle, NULL, NULL, 0, RPC_C_LISTEN_MAX_CALLS_DEFAULT, NULL );


    /* register the second manager epv and associate it with the
       specified uuid.  the second uuid must be non-null so that
       it will not conflict with the NULL uuid already registered
       for this interface
       */
    epv2.HelloProc = HelloProc2;
    epv2.Shutdown = Shutdown;
  

    status = RpcServerRegisterIfEx(cluuid_ServerIfHandle, &MgrTypeUuid,  &epv2, 0, RPC_C_LISTEN_MAX_CALLS_DEFAULT, NULL ); 

    printf_s("RpcServerRegisterIfEx returned 0x%x\n", status);
    if (status) {
        exit(status);
    }

    printf_s("Calling RpcServerListen\n");
    status = RpcServerListen(cMinCalls,
                             cMaxCalls,
                             fDontWait);
    printf_s("RpcServerListen returned: 0x%x\n", status);
    if (status) {
        exit(status);
    }

    if (fDontWait) {
        printf_s("Calling RpcMgmtWaitServerListen\n");
        status = RpcMgmtWaitServerListen();  //  wait operation
        printf_s("RpcMgmtWaitServerListen returned: 0x%x\n", status);
        if (status) {
            exit(status);
        }
    }

} // end main()
예제 #5
0
void RpcListen()
{
    RPC_STATUS		status;
    char			*task;
    RPC_BINDING_VECTOR	*ptrBindingVector = NULL;
    BOOLEAN			ifaceRegistered = FALSE;
    BOOLEAN			epRegistered = FALSE;

#ifdef	NOOSIDEBUGSERVER	/* Use All Protseqs already done in OSI */

    status = RpcServerUseAllProtseqs(1, NULL);
    if (status != RPC_S_OK) {
        task = "Use All Protocol Sequences";
        goto cleanup;
    }

#endif	/* NOOSIDEBUGSERVER */

    status = RpcServerRegisterIf(afsrpc_v1_0_s_ifspec, NULL, NULL);
    if (status != RPC_S_OK) {
        task = "Register Interface";
        goto cleanup;
    }
    ifaceRegistered = TRUE;

    status = RpcServerInqBindings(&ptrBindingVector);
    if (status != RPC_S_OK) {
        task = "Inquire Bindings";
        goto cleanup;
    }

    status = RpcServerRegisterAuthInfo(NULL, RPC_C_AUTHN_WINNT, NULL, NULL);
    if (status != RPC_S_OK) {
        task = "Register Authentication Info";
        goto cleanup;
    }

    status = RpcEpRegister(afsrpc_v1_0_s_ifspec, ptrBindingVector,
                            NULL, "AFS session key interface");
    if (status != RPC_S_OK) {
        task = "Register Endpoints";
        goto cleanup;
    }
    epRegistered = TRUE;

    afsi_log("RPC server listening");

    status = RpcServerListen(OSI_MAXRPCCALLS, OSI_MAXRPCCALLS, 0);
    if (status != RPC_S_OK) {
        task = "Server Listen";
    }

cleanup:
    if (epRegistered)
        (void) RpcEpUnregister(afsrpc_v1_0_s_ifspec, ptrBindingVector,
                                NULL);

    if (ptrBindingVector)
        (void) RpcBindingVectorFree(&ptrBindingVector);

    if (ifaceRegistered)
        (void) RpcServerUnregisterIf(afsrpc_v1_0_s_ifspec, NULL, FALSE);

    if (status != RPC_S_OK)
        afsi_log("RPC problem, code %d for %s", status, task);
    else
        afsi_log("RPC shutdown");

    if (rpc_ShutdownEvent != NULL)
        thrd_SetEvent(rpc_ShutdownEvent);
    return;
}
void __cdecl main(int argc, char * argv[])
{
   unsigned char *pszProtocolSequence = DEFAULT_PROTOCOL_SEQUENCE;
   unsigned char *pszEndpoint         = DEFAULT_ENDPOINT;
   unsigned char *pszSpn              = NULL; 
   unsigned int   nMinCalls           = DEFAULT_MIN_CALLS;
   unsigned int   nMaxCalls           = DEFAULT_MAX_CALLS;
   BOOL bDontWait                     = DEFAULT_WAIT_FLAG;
   PSECURITY_DESCRIPTOR pszSecurity   = NULL;
   int i;
   RPC_STATUS status;

   // allow the user to override settings with command line switches
   for (i = 1; i < argc; i++)
   {
      if ((*argv[i] == '-') || (*argv[i] == '/'))
      {
         switch (tolower(*(argv[i]+1)))
         {
            case 'p':
               pszProtocolSequence = argv[++i];
               break;
            case 'e':
               pszEndpoint = argv[++i];
               break;
            case 'a':
               pszSpn = argv[++i];
               break;				
            case 'm':
               nMaxCalls = (unsigned int) atoi(argv[++i]);
               break;
            case 'n':
               nMinCalls = (unsigned int) atoi(argv[++i]);
               break;
            case 'f':
               bDontWait = (unsigned int) atoi(argv[++i]);
               break;
	  
            case 'h':
            case '?':
            default:
               Usage(argv[0]);
         }
      }
      else
         Usage(argv[0]);
   }

   if ((pszProtocolSequence == NULL) || (pszEndpoint == NULL) ||
       (nMinCalls < 1) || (nMinCalls > nMaxCalls))
      Usage(argv[0]);

   status = RpcServerUseProtseqEp(pszProtocolSequence,
                                  nMaxCalls,
                                  pszEndpoint,
                                  pszSecurity);
   printf_s("RpcServerUseProtseqEp returned 0x%x\n", status);
   if (status)
      Quit(status);

   
   // User did not specify spn, construct one.
   if (pszSpn == NULL) {
	   MakeSpn(&pszSpn);
   }
   
   // Using Negotiate as security provider.
   status = RpcServerRegisterAuthInfo(pszSpn,
									  RPC_C_AUTHN_GSS_NEGOTIATE,
									  NULL,
									  NULL);
   
   printf_s("RpcServerRegisterAuthInfo returned 0x%x\n", status);
   if (status) {
	   exit(status);
   }   
   
   status = RpcServerRegisterIfEx(AsyncRPC_ServerIfHandle,
                                  NULL,
                                  NULL,
                                  0,
                                  RPC_C_LISTEN_MAX_CALLS_DEFAULT,
                                  NULL);

   printf_s("Calling RpcServerListen\n");
   status = RpcServerListen(nMinCalls,
                            nMaxCalls,
                            bDontWait);
   printf_s("RpcServerListen returned: 0x%x\n", status);
   if (status)
      Quit(status);

   if (bDontWait)
   {
      printf_s("Calling RpcMgmtWaitServerListen\n");
      status = RpcMgmtWaitServerListen();  // wait operation
      printf_s("RpcMgmtWaitServerListen returned: 0x%x\n", status);
      if (status)
         Quit(status);
   }

   free(pszSecurity);
}