Ejemplo n.º 1
0
DWORD
LwEvtCreateEventlogRpcBinding(
    const char * hostname,
    handle_t *   event_binding
    )
{
    DWORD winerror = 0;
    DWORD dwError = 0;
    const char * protocol;
    const char * endpoint;
    char * pszBindingString = NULL;
    char *hostPrincipal = NULL;
    size_t hostPrincipalSize = 0;
    int ret = 0;
    handle_t eventBinding_local = 0;
    BOOLEAN bLocalHost = FALSE;

    /* Connect using tcp */
    protocol = "ncacn_ip_tcp";
    endpoint = NULL;

    EVT_LOG_VERBOSE("client::eventlogbinding.c: CreateEventlogRpcBinding() hostname=%s, *event_binding=%.16X\n",
                    hostname, *event_binding);

    RPC_STRING_BINDING_COMPOSE((char*) protocol, (char*) hostname, (char*) endpoint, &pszBindingString, &winerror);
    BAIL_ON_DCE_ERROR(dwError, winerror);

    if (pszBindingString == NULL || *pszBindingString == '\0') {
        BAIL_ON_DCE_ERROR(dwError, RPC_S_INVALID_STRING_BINDING);
    }

    EVT_LOG_VERBOSE("client::eventlogbinding.c: CreateEventlogRpcBinding() pszBindingString=%s, running rbfsb\n",
                    pszBindingString);

    RPC_BINDING_FROM_STRING_BINDING(pszBindingString, &eventBinding_local, &winerror);
    BAIL_ON_DCE_ERROR(dwError, winerror);

    EVT_LOG_VERBOSE("client::eventlogbinding.c: CreateEventlogRpcBinding() eventBinding_local=%.16X, finished rbfsb\n",
                    eventBinding_local);


    if (hostname != NULL && !bLocalHost)
    {
        /* Set up authentication if we are connecting to a remote host */
        hostPrincipalSize = strlen(hostname) + 6;
        
        dwError = LwAllocateMemory(hostPrincipalSize, (PVOID*)&hostPrincipal);
        BAIL_ON_EVT_ERROR(dwError);
        
        ret = snprintf(hostPrincipal, hostPrincipalSize, "host/%s", hostname);
        if (ret < 0 || ret >= hostPrincipalSize) {
            BAIL_ON_EVT_ERROR(ERROR_INSUFFICIENT_BUFFER);
        }
        
        EVT_LOG_VERBOSE("client::eventlogbinding.c: CreateEventlogRpcBinding() using host principal [%s]\n",
                        hostPrincipal);
        
        winerror = RpcBindingSetAuthInfo(eventBinding_local,
                                  (unsigned char*)hostPrincipal,
                                  rpc_c_protect_level_pkt_privacy,
                                  rpc_c_authn_gss_negotiate,
                                  NULL,
                                  rpc_c_authz_name);
        BAIL_ON_DCE_ERROR(dwError, winerror);
        
        EVT_LOG_VERBOSE("client::eventlogbinding.c: CreateEventlogRpcBinding() eventBinding_local=%.16X, auth info set"
                        "winerror=0x%08x\n", eventBinding_local, winerror);
        
    }

    *event_binding = eventBinding_local;

    EVT_LOG_VERBOSE("client::eventlogbinding.c: CreateEventlogRpcBinding() finished successfully\n");

cleanup:
    if (hostPrincipal)
    {
        LwFreeMemory(hostPrincipal);
    }

    if (pszBindingString)
    {
        DWORD tempstatus = 0;
        RPC_STRING_FREE(&pszBindingString, &tempstatus);
    }

    return dwError;

error:
    EVT_LOG_VERBOSE("client::eventlogbinding.c: CreateEventlogRpcBinding() label error: winerror=%d\n",
                    winerror);

    goto cleanup;
}
Ejemplo n.º 2
0
//
//  FUNCTION: main
//
//  PURPOSE: Parses arguments and binds to the server.
//
//  PARAMETERS:
//    argc - number of command line arguments
//    argv - array of command line arguments
//
//  RETURN VALUE:
//    Program exit code.
//
//
int main(int argc, char *argv[])
{
    char *serverAddress = NULL;
    char *protocol = "ncalrpc";
    UINT iIterations = 100;
    unsigned char *stringBinding;
    RPC_BINDING_HANDLE Binding;
    RPC_STATUS status;
    ULONG SecurityLevel = RPC_C_AUTHN_LEVEL_PKT_PRIVACY;

    argc--;
    argv++;
    while(argc)
        {
        if (   argv[0][0] != '-'
            && argv[0][0] != '/')
            {
            Usage();
            return(1);
            }

        switch(argv[0][1])
            {
            case 'n':
                if (argc < 2)
                    {
                    Usage();
                    return(1);
                    }
                serverAddress = argv[1];
                argc--;
                argv++;
                break;
            case 't':
                if (argc < 2)
                    {
                    Usage();
                    return(1);
                    }
                protocol = argv[1];
                argc--;
                argv++;
                break;
            case 'i':
                if (argc < 2)
                    {
                    Usage();
                    return(1);
                    }
                iIterations = atoi(argv[1]);
                argc--;
                argv++;
                break;
            case 's':
                if (argc < 2)
                    {
                    Usage();
                    return(1);
                    }
                SecurityLevel = atoi(argv[1]);
                if (SecurityLevel > RPC_C_AUTHN_LEVEL_PKT_PRIVACY)
                    {
                    Usage();
                    return(1);
                    }
                argc--;
                argv++;
                break;
            default:
                Usage();
                return(1);
                break;
            }

        argc--;
        argv++;
        }

    status = RpcStringBindingCompose(0,
                                     protocol,
                                     serverAddress,
                                     0,
                                     0,
                                     &stringBinding);
    if (status != RPC_S_OK)
        {
        printf("RpcStringBindingCompose failed - %d\n", status);
        return(1);
        }

    status = RpcBindingFromStringBinding(stringBinding, &Binding);

    if (status != RPC_S_OK)
        {
        printf("RpcBindingFromStringBinding failed - %d\n", status);
        return(1);
        }

    status =
    RpcBindingSetAuthInfo(Binding,
                          0,
                          SecurityLevel,
                          RPC_C_AUTHN_WINNT,
                          0,
                          0
                         );

    if (status != RPC_S_OK)
        {
        printf("RpcBindingSetAuthInfo failed - %d\n", status);
        return(1);
        }

    status = Ping(Binding);

    if (status != RPC_S_OK)
        {
        printf("Ping failed - %d\n", status);
        }

    printf("Connected.\n");

    //
    // Call and time various RPC calls.
    //

    DoTimings(Binding, iIterations);

    // Cleanup

    status = RpcBindingFree(&Binding);

    // ASSERT(status == RPC_S_OK):

    status = RpcStringFree(&stringBinding);

    // ASSERT(status == RPC_S_OK);

    return(0);
}
Ejemplo n.º 3
0
Archivo: rpc.c Proyecto: Kelimion/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 = RpcNetworkIsProtseqValid(foo);
    ok(status == RPC_S_INVALID_RPC_PROTSEQ, "return wrong\n");

    status = RpcNetworkIsProtseqValid(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 = RpcServerUseProtseqEp(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 = RpcStringBindingCompose(NULL, ncacn_ip_tcp, address,
                                     endpoint, NULL, &binding);
    ok(status == RPC_S_OK, "RpcStringBindingCompose failed (%u)\n", status);

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

    status = RpcBindingSetAuthInfo(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 = RpcBindingInqAuthInfo(IFoo_IfHandle, NULL, NULL, NULL, NULL, NULL);
    ok(status == RPC_S_BINDING_HAS_NO_AUTH, "RpcBindingInqAuthInfo failed (%u)\n",
       status);

    status = RpcBindingSetAuthInfo(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 = RpcBindingInqAuthInfo(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) RpcStringFree(&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 = RpcStringFree(&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);
}