r25598: Add missing become_root/unbecome_root around calls of add_aliases.
[Samba/gebeck_regimport.git] / examples / libmsrpc / test / smbc_test / smbc.c
blob3db3ceadc65f56e4c3ae17dc681538a10685b11a
1 /*simple test for libsmbclient compatibility. initialize a smbc context, open sessions on a couple pipes and quit*/
3 #include "libmsrpc.h"
4 #include "libsmbclient.h"
5 #include "test_util.h"
7 int main(int argc, char **argv) {
8 SMBCCTX *ctx = NULL;
9 CacServerHandle *hnd = NULL;
10 TALLOC_CTX *mem_ctx = NULL;
12 struct LsaOpenPolicy lop;
13 struct RegConnect rc;
14 struct SamOpenDomain sod;
16 ZERO_STRUCT(lop);
17 ZERO_STRUCT(rc);
18 ZERO_STRUCT(sod);
20 mem_ctx = talloc_init("cac_smbc");
21 if(!mem_ctx) {
22 printf("Could not initialize talloc context\n");
23 exit(-1);
26 hnd = cac_NewServerHandle(True);
28 cac_parse_cmd_line(argc, argv, hnd);
30 /*initialize smbc context*/
31 if( (ctx = smbc_new_context()) == NULL) {
32 exit(1);
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;
40 if(smbc_init_context(ctx) == NULL)
41 exit(1);
43 cac_SetSmbcContext(hnd, ctx);
45 /*still have to call cac_Connect()*/
46 if(!cac_Connect(hnd, NULL)) {
47 printf("Could not connect to server\n");
48 exit(1);
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));
55 printf("Opened LSA policy.\n");
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));
62 printf("Connceted to Registry.\n");
64 sod.in.access = MAXIMUM_ALLOWED_ACCESS;
66 if(!cac_SamOpenDomain(hnd, mem_ctx, &sod))
67 printf("Could not open domain SAM. Error: %s\n", nt_errstr(hnd->status));
69 printf("Opened domain.\n");
71 if(lop.out.pol)
72 cac_LsaClosePolicy(hnd, mem_ctx, lop.out.pol);
74 if(rc.out.key)
75 cac_RegClose(hnd, mem_ctx, rc.out.key);
77 if(sod.out.sam)
78 cac_SamClose(hnd, mem_ctx, sod.out.sam);
80 if(sod.out.dom_hnd)
81 cac_SamClose(hnd, mem_ctx, sod.out.dom_hnd);
83 cac_FreeHandle(hnd);
84 talloc_destroy(mem_ctx);
86 return 0;