コード例 #1
0
ファイル: Server.cpp プロジェクト: pi0/OSProjects
int main()
{
	
	// Create Handle
	RpcServerUseProtseqEpA(RPC_CSTR("ncacn_ip_tcp"),10, RPC_CSTR("8080"),NULL);

	// Register Server Inrerface
	RpcServerRegisterIf2(
		Server_v1_0_s_ifspec,
		NULL, NULL, RPC_IF_ALLOW_CALLBACKS_WITH_NO_AUTH,10,(unsigned)-1,SecurityCallbackOK
	);

	// Start Listening
	std::cout << "Listening on port 8080 ..." << std::endl;
	RpcServerListen(1,10,FALSE);

}
コード例 #2
0
ファイル: rpc.c プロジェクト: vmware/lightwave
ULONG
VmDirRpcServerUseProtSeqEp(
    PCSTR pszProtSeq,
    PCSTR pszEndpoint
)
{
    DWORD dwError = 0;

    dwError = RpcServerUseProtseqEpA(
                (unsigned char*) pszProtSeq,
                RPC_C_PROTSEQ_MAX_REQS_DEFAULT,
                (unsigned char*) pszEndpoint,
                NULL
    );
    BAIL_ON_VMDIR_ERROR(dwError);

error:

    return dwError;
}
コード例 #3
0
ファイル: rpc_protseq.c プロジェクト: AmesianX/wine
static void test_RpcServerUseProtseq(void)
{
    RPC_STATUS status;
    RPC_BINDING_VECTOR *bindings;
    ULONG i;
    ULONG binding_count_before;
    ULONG binding_count_after1;
    ULONG binding_count_after2;
    ULONG endpoints_registered = 0;
    static unsigned char iptcp[] = "ncacn_ip_tcp";
    static unsigned char np[] = "ncacn_np";
    static unsigned char ncalrpc[] = "ncalrpc";

    status = RpcServerInqBindings(&bindings);
    if (status == RPC_S_NO_BINDINGS)
        binding_count_before = 0;
    else
    {
        binding_count_before = bindings->Count;
        ok(status == RPC_S_OK, "RpcServerInqBindings failed with status %d\n", status);
        RpcBindingVectorFree(&bindings);
    }

    /* show that RpcServerUseProtseqEp(..., NULL, ...) is the same as
     * RpcServerUseProtseq(...) */
    status = RpcServerUseProtseqEpA(ncalrpc, 0, NULL, NULL);
    ok(status == RPC_S_OK || broken(status == RPC_S_INVALID_ENDPOINT_FORMAT),
       "RpcServerUseProtseqEp with NULL endpoint failed with status %d\n",
       status);

    /* register protocol sequences without explicit endpoints */
    status = RpcServerUseProtseqA(np, 0, NULL);
    if (status == RPC_S_PROTSEQ_NOT_SUPPORTED)
        win_skip("ncacn_np not supported\n");
    else
        ok(status == RPC_S_OK, "RpcServerUseProtseq(ncacn_np) failed with status %d\n", status);
    if (status == RPC_S_OK) endpoints_registered++;

    status = RpcServerUseProtseqA(iptcp, 0, NULL);
    ok(status == RPC_S_OK, "RpcServerUseProtseq(ncacn_ip_tcp) failed with status %d\n", status);
    if (status == RPC_S_OK) endpoints_registered++;

    status = RpcServerUseProtseqA(ncalrpc, 0, NULL);
    ok(status == RPC_S_OK, "RpcServerUseProtseqEp(ncalrpc) failed with status %d\n", status);
    if (status == RPC_S_OK) endpoints_registered++;

    status = RpcServerInqBindings(&bindings);
    ok(status == RPC_S_OK, "RpcServerInqBindings failed with status %d\n", status);
    binding_count_after1 = bindings->Count;
    ok(binding_count_after1 == binding_count_before + endpoints_registered,
       "wrong binding count - before: %u, after %u, endpoints registered %u\n",
       binding_count_before, binding_count_after1, endpoints_registered);
    for (i = 0; i < bindings->Count; i++)
    {
        RPC_CSTR str_bind;
        status = RpcBindingToStringBindingA(bindings->BindingH[i], &str_bind);
        ok(status == RPC_S_OK, "RpcBindingToStringBinding failed with status %d\n", status);
        trace("string binding: %s\n", str_bind);
        RpcStringFreeA(&str_bind);
    }
    RpcBindingVectorFree(&bindings);

    /* re-register - endpoints should be reused */
    status = RpcServerUseProtseqA(np, 0, NULL);
    if (status == RPC_S_PROTSEQ_NOT_SUPPORTED)
        win_skip("ncacn_np not supported\n");
    else
        ok(status == RPC_S_OK, "RpcServerUseProtseq(ncacn_np) failed with status %d\n", status);

    status = RpcServerUseProtseqA(iptcp, 0, NULL);
    ok(status == RPC_S_OK, "RpcServerUseProtseq(ncacn_ip_tcp) failed with status %d\n", status);

    status = RpcServerUseProtseqA(ncalrpc, 0, NULL);
    ok(status == RPC_S_OK, "RpcServerUseProtseqEp(ncalrpc) failed with status %d\n", status);

    status = RpcServerInqBindings(&bindings);
    ok(status == RPC_S_OK, "RpcServerInqBindings failed with status %d\n", status);
    binding_count_after2 = bindings->Count;
    ok(binding_count_after2 == binding_count_after1,
       "bindings should have been re-used - after1: %u after2: %u\n",
       binding_count_after1, binding_count_after2);
    RpcBindingVectorFree(&bindings);
}
コード例 #4
0
ファイル: splrpc.c プロジェクト: mingpen/OpenNT
RPC_STATUS
SpoolerStartRpcServer(
    VOID)
/*++

Routine Description:


Arguments:



Return Value:

    NERR_Success, or any RPC error codes that can be returned from
    RpcServerUnregisterIf.

--*/
{
    unsigned char * InterfaceAddress;
    RPC_STATUS status;
    PSECURITY_DESCRIPTOR SecurityDescriptor = NULL;
    BOOL                Bool;

    HKEY hKey;
    DWORD cbData;
    DWORD dwSerializeRpc = 0;
    DWORD dwType;

    InterfaceAddress = "\\pipe\\spoolss";

    // Croft up a security descriptor that will grant everyone
    // all access to the object (basically, no security)
    //
    // We do this by putting in a NULL Dacl.
    //
    // BUGBUG: rpc should copy the security descriptor,
    // Since it currently doesn't, simply allocate it for now and
    // leave it around forever.
    //


    SecurityDescriptor = LocalAlloc( LMEM_FIXED, sizeof( SECURITY_DESCRIPTOR ));
    if (SecurityDescriptor == 0) {
        DBGMSG(DBG_ERROR, ("Spoolss: out of memory\n"));
        return FALSE;
    }

    InitializeSecurityDescriptor( SecurityDescriptor, SECURITY_DESCRIPTOR_REVISION );

    Bool = SetSecurityDescriptorDacl (
               SecurityDescriptor,
               TRUE,                           // Dacl present
               NULL,                           // NULL Dacl
               FALSE                           // Not defaulted
               );

    //
    // There's no way the above call can fail.  But check anyway.
    //

    if (!Bool) {
        DBGMSG(DBG_ERROR, ("Spoolss: SetSecurityDescriptorDacl failed\n"));
        return FALSE;
    }

    //
    // For now, ignore the second argument.
    //

    status = RpcServerUseProtseqEpA("ncacn_np", 10, InterfaceAddress, SecurityDescriptor);

    if (status) {
        DBGMSG(DBG_ERROR, ("RpcServerUseProtseqEpA = %u\n",status));
        return FALSE;
    }

    //
    // For now, ignore the second argument.
    //

    status = RpcServerUseProtseqEpA("ncalrpc", 10, "spoolss", SecurityDescriptor);

    if (status) {
        DBGMSG(DBG_ERROR, ("RpcServerUseProtseqEpA = %u\n",status));
        return FALSE;
    }

    //
    // Now we need to add the interface.  We can just use the winspool_ServerIfHandle
    // specified by the MIDL compiler in the stubs (winspl_s.c).
    //
    status = RpcServerRegisterIf(winspool_ServerIfHandle, 0, 0);

    if (status) {
        DBGMSG(DBG_ERROR, ("RpcServerRegisterIf = %u\n",status));
        return FALSE;
    }

    if (!RegOpenKeyEx(HKEY_LOCAL_MACHINE,
                      szPrintKey,
                      0,
                      KEY_READ,
                      &hKey)) {

        cbData = sizeof(dwSerializeRpc);

        //
        // Ignore failure case since we can use the default
        //
        RegQueryValueEx(hKey,
                        szSerializeRpc,
                        NULL,
                        &dwType,
                        (LPBYTE)&dwSerializeRpc,
                        &cbData);

        cbData = sizeof(dwCallExitProcessOnShutdown);

        //
        // This value can be used to control if spooler controls ExitProcess
        // on shutdown
        //
        RegQueryValueEx(hKey,
                        szCallExitProcessOnShutdown,
                        NULL,
                        &dwType,
                        (LPBYTE)&dwCallExitProcessOnShutdown,
                        &cbData);

        RegCloseKey(hKey);
    }

    if (dwSerializeRpc) {
            
        // By default, rpc will serialize access to context handles.  Since
        // the spooler needs to be able to have two threads access a context
        // handle at once, and it knows what it is doing, we will tell rpc
        // not to serialize access to context handles.

        I_RpcSsDontSerializeContext();
    }

    status = RpcMgmtSetServerStackSize(16384);

    if (status != RPC_S_OK) {
        DBGMSG(DBG_ERROR, ("Spoolss : RpcMgmtSetServerStackSize = %d\n", status));
    }

    // The first argument specifies the minimum number of threads to
    // create to handle calls; the second argument specifies the maximum
    // concurrent calls to handle.  The third argument indicates that
    // the routine should not wait.

    status = RpcServerListen(1,12345,1); // DaveSn was 0

    if ( status != RPC_S_OK ) {
         DBGMSG(DBG_ERROR, ("Spoolss : RpcServerListen = %d\n", status));
    }

    return (status);
}
コード例 #5
0
ファイル: rpc.c プロジェクト: Barrell/wine
static void test_rpc_ncacn_ip_tcp(void)
{
    RPC_STATUS status;
    unsigned char *binding, *principal;
    handle_t IFoo_IfHandle;
    ULONG level, authnsvc, authzsvc;
    RPC_AUTH_IDENTITY_HANDLE identity;
    static unsigned char foo[] = "foo";
    static unsigned char ncacn_ip_tcp[] = "ncacn_ip_tcp";
    static unsigned char address[] = "127.0.0.1";
    static unsigned char endpoint[] = "4114";
    static unsigned char spn[] = "principal";

    status = RpcNetworkIsProtseqValidA(foo);
    ok(status == RPC_S_INVALID_RPC_PROTSEQ, "return wrong\n");

    status = RpcNetworkIsProtseqValidA(ncacn_ip_tcp);
    ok(status == RPC_S_OK, "return wrong\n");

    status = RpcMgmtStopServerListening(NULL);
todo_wine {
    ok(status == RPC_S_NOT_LISTENING,
       "wrong RpcMgmtStopServerListening error (%u)\n", status);
}

    status = RpcMgmtWaitServerListen();
    ok(status == RPC_S_NOT_LISTENING,
       "wrong RpcMgmtWaitServerListen error status (%u)\n", status);

    status = RpcServerListen(1, 20, FALSE);
    ok(status == RPC_S_NO_PROTSEQS_REGISTERED,
       "wrong RpcServerListen error (%u)\n", status);

    status = RpcServerUseProtseqEpA(ncacn_ip_tcp, 20, endpoint, NULL);
    ok(status == RPC_S_OK, "RpcServerUseProtseqEp failed (%u)\n", status);

    status = RpcServerRegisterIf(IFoo_v0_0_s_ifspec, NULL, NULL);
    ok(status == RPC_S_OK, "RpcServerRegisterIf failed (%u)\n", status);

    status = RpcServerListen(1, 20, TRUE);
todo_wine {
    ok(status == RPC_S_OK, "RpcServerListen failed (%u)\n", status);
}

    status = RpcServerListen(1, 20, TRUE);
todo_wine {
    ok(status == RPC_S_ALREADY_LISTENING,
       "wrong RpcServerListen error (%u)\n", status);
}

    status = RpcStringBindingComposeA(NULL, ncacn_ip_tcp, address,
                                     endpoint, NULL, &binding);
    ok(status == RPC_S_OK, "RpcStringBindingCompose failed (%u)\n", status);

    status = RpcBindingFromStringBindingA(binding, &IFoo_IfHandle);
    ok(status == RPC_S_OK, "RpcBindingFromStringBinding failed (%u)\n",
       status);

    status = RpcBindingSetAuthInfoA(IFoo_IfHandle, NULL, RPC_C_AUTHN_LEVEL_NONE,
                                   RPC_C_AUTHN_WINNT, NULL, RPC_C_AUTHZ_NAME);
    ok(status == RPC_S_OK, "RpcBindingSetAuthInfo failed (%u)\n", status);

    status = RpcBindingInqAuthInfoA(IFoo_IfHandle, NULL, NULL, NULL, NULL, NULL);
    ok(status == RPC_S_BINDING_HAS_NO_AUTH, "RpcBindingInqAuthInfo failed (%u)\n",
       status);

    status = RpcBindingSetAuthInfoA(IFoo_IfHandle, spn, RPC_C_AUTHN_LEVEL_PKT_PRIVACY,
                                   RPC_C_AUTHN_WINNT, NULL, RPC_C_AUTHZ_NAME);
    ok(status == RPC_S_OK, "RpcBindingSetAuthInfo failed (%u)\n", status);

    level = authnsvc = authzsvc = 0;
    principal = (unsigned char *)0xdeadbeef;
    identity = (RPC_AUTH_IDENTITY_HANDLE *)0xdeadbeef;
    status = RpcBindingInqAuthInfoA(IFoo_IfHandle, &principal, &level, &authnsvc,
                                   &identity, &authzsvc);

    ok(status == RPC_S_OK, "RpcBindingInqAuthInfo failed (%u)\n", status);
    ok(identity == NULL, "expected NULL identity, got %p\n", identity);
    ok(principal != (unsigned char *)0xdeadbeef, "expected valid principal, got %p\n", principal);
    ok(level == RPC_C_AUTHN_LEVEL_PKT_PRIVACY, "expected RPC_C_AUTHN_LEVEL_PKT_PRIVACY, got %d\n", level);
    ok(authnsvc == RPC_C_AUTHN_WINNT, "expected RPC_C_AUTHN_WINNT, got %d\n", authnsvc);
    todo_wine ok(authzsvc == RPC_C_AUTHZ_NAME, "expected RPC_C_AUTHZ_NAME, got %d\n", authzsvc);
    if (status == RPC_S_OK) RpcStringFreeA(&principal);

    status = RpcMgmtStopServerListening(NULL);
    ok(status == RPC_S_OK, "RpcMgmtStopServerListening failed (%u)\n",
       status);

    status = RpcMgmtStopServerListening(NULL);
    ok(status == RPC_S_OK, "RpcMgmtStopServerListening failed (%u)\n",
       status);

    status = RpcServerUnregisterIf(NULL, NULL, FALSE);
    ok(status == RPC_S_OK, "RpcServerUnregisterIf failed (%u)\n", status);

    status = RpcMgmtWaitServerListen();
todo_wine {
    ok(status == RPC_S_OK, "RpcMgmtWaitServerListen failed (%u)\n", status);
}

    status = RpcStringFreeA(&binding);
    ok(status == RPC_S_OK, "RpcStringFree failed (%u)\n", status);

    status = RpcBindingFree(&IFoo_IfHandle);
    ok(status == RPC_S_OK, "RpcBindingFree failed (%u)\n", status);
}