aboutsummaryrefslogtreecommitdiff
path: root/src/lib/ccapi/windows/rpcsstest/client.c
blob: a25e8d1ade6068eb2bc228c12ddc01202e01effb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include<windows.h>
#include<stdio.h>
#include<stdlib.h>
#include<tchar.h>
#include"cstest.h"
#include<strsafe.h>

void * __RPC_USER MIDL_user_allocate(size_t s) {
    return malloc(s);
}

void __RPC_USER MIDL_user_free(void * p) {
    free(p);
}

int main(int argc, char ** argv) {
    RPC_STATUS status;
    RPC_BINDING_HANDLE h;
    TCHAR * bindstring = NULL;
    RPC_SECURITY_QOS sqos;
    char inbuf[256];
    char outbuf[256];
    long cb_out;

    status = RpcStringBindingCompose(NULL,
                                     _T("ncalrpc"),
                                     NULL,
                                     NULL,
                                     NULL,
                                     &bindstring);

    if (status != RPC_S_OK) {
        fprintf(stderr, "RpcStringBindingCompose failed: %d\n",
                status);
        return 1;
    }

    status = RpcBindingFromStringBinding(bindstring,
                                         &h);

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

    ZeroMemory(&sqos, sizeof(sqos));

    sqos.Version = 1;
    sqos.Capabilities = RPC_C_QOS_CAPABILITIES_DEFAULT;
    sqos.IdentityTracking = RPC_C_QOS_IDENTITY_STATIC;
    sqos.ImpersonationType = RPC_C_IMP_LEVEL_IMPERSONATE;

    status = RpcBindingSetAuthInfoEx(h,
                                     NULL,
                                     RPC_C_AUTHN_LEVEL_CALL,
                                     RPC_C_AUTHN_WINNT,
                                     NULL,
                                     0,
                                     &sqos);

    if (status != RPC_S_OK) {
        fprintf(stderr, "RpcBindingSetAuthInfoEx failed: %d\n",
                status);
        return 1;
    }

    StringCbCopyA(inbuf, sizeof(inbuf), "Echo Test 1");
    StringCbCopyA(outbuf, sizeof(outbuf), "Blank blank blank");

    printf("Before call: in[%s], out[%s]\n", inbuf, outbuf);
    cb_out = 0;

    status = EchoString(h, inbuf, sizeof(outbuf), &cb_out, outbuf);

    if (status) {
        printf("Call failed: status = %d\n", status);
    } else {
        printf("After call: out[%s], outlen[%d]\n", outbuf, cb_out);
    }

    status = RpcBindingFree(&h);

    status = RpcStringFree(&bindstring);

    return 0;
}