r25598: Add missing become_root/unbecome_root around calls of add_aliases.
[ira/wip.git] / examples / libmsrpc / test / smbc_test / smbc.c
1 /*simple test for libsmbclient compatibility. initialize a smbc context, open sessions on a couple pipes and quit*/
2
3 #include "libmsrpc.h"
4 #include "libsmbclient.h"
5 #include "test_util.h"
6
7 int main(int argc, char **argv) {
8    SMBCCTX *ctx = NULL;
9    CacServerHandle *hnd = NULL;
10    TALLOC_CTX *mem_ctx = NULL;
11
12    struct LsaOpenPolicy lop;
13    struct RegConnect    rc;
14    struct SamOpenDomain sod;
15
16    ZERO_STRUCT(lop);
17    ZERO_STRUCT(rc);
18    ZERO_STRUCT(sod);
19
20    mem_ctx = talloc_init("cac_smbc");
21    if(!mem_ctx) {
22       printf("Could not initialize talloc context\n");
23       exit(-1);
24    }
25    
26    hnd = cac_NewServerHandle(True);
27
28    cac_parse_cmd_line(argc, argv, hnd);
29
30    /*initialize smbc context*/
31    if( (ctx = smbc_new_context()) == NULL) {
32       exit(1);
33    }
34
35    /*this probably isn't what someone would want to do, but it initializes the values we need*/
36    ctx->debug = hnd->debug;
37    ctx->callbacks.auth_fn = cac_GetAuthDataFn;
38    
39
40    if(smbc_init_context(ctx) == NULL)
41       exit(1);
42
43    cac_SetSmbcContext(hnd, ctx);
44
45    /*still have to call cac_Connect()*/
46    if(!cac_Connect(hnd, NULL)) {
47       printf("Could not connect to server\n");
48       exit(1);
49    }
50
51    lop.in.access = MAXIMUM_ALLOWED_ACCESS;
52    if(!cac_LsaOpenPolicy(hnd, mem_ctx, &lop))
53       printf("Could not open LSA policy. Error: %s\n", nt_errstr(hnd->status));
54
55    printf("Opened LSA policy.\n");
56
57    rc.in.access = MAXIMUM_ALLOWED_ACCESS;
58    rc.in.root   = HKEY_LOCAL_MACHINE;
59    if(!cac_RegConnect(hnd, mem_ctx, &rc))
60       printf("Could not connect to registry. Error: %s\n", nt_errstr(hnd->status));
61
62    printf("Connceted to Registry.\n");
63
64    sod.in.access = MAXIMUM_ALLOWED_ACCESS;
65
66    if(!cac_SamOpenDomain(hnd, mem_ctx, &sod))
67       printf("Could not open domain SAM. Error: %s\n", nt_errstr(hnd->status));
68
69    printf("Opened domain.\n");
70
71    if(lop.out.pol)
72       cac_LsaClosePolicy(hnd, mem_ctx, lop.out.pol);
73
74    if(rc.out.key)
75       cac_RegClose(hnd, mem_ctx, rc.out.key);
76
77    if(sod.out.sam)
78       cac_SamClose(hnd, mem_ctx, sod.out.sam);
79
80    if(sod.out.dom_hnd)
81       cac_SamClose(hnd, mem_ctx, sod.out.dom_hnd);
82
83    cac_FreeHandle(hnd);
84    talloc_destroy(mem_ctx);
85
86    return 0;
87 }