00001
00002
00003 #include "libmsrpc.h"
00004 #include "libsmbclient.h"
00005 #include "test_util.h"
00006
00007 int main(int argc, char **argv) {
00008 SMBCCTX *ctx = NULL;
00009 CacServerHandle *hnd = NULL;
00010 TALLOC_CTX *mem_ctx = NULL;
00011
00012 struct LsaOpenPolicy lop;
00013 struct RegConnect rc;
00014 struct SamOpenDomain sod;
00015
00016 ZERO_STRUCT(lop);
00017 ZERO_STRUCT(rc);
00018 ZERO_STRUCT(sod);
00019
00020 mem_ctx = talloc_init("cac_smbc");
00021 if(!mem_ctx) {
00022 printf("Could not initialize talloc context\n");
00023 exit(-1);
00024 }
00025
00026 hnd = cac_NewServerHandle(True);
00027
00028 cac_parse_cmd_line(argc, argv, hnd);
00029
00030
00031 if( (ctx = smbc_new_context()) == NULL) {
00032 exit(1);
00033 }
00034
00035
00036 ctx->debug = hnd->debug;
00037 ctx->callbacks.auth_fn = cac_GetAuthDataFn;
00038
00039
00040 if(smbc_init_context(ctx) == NULL)
00041 exit(1);
00042
00043 cac_SetSmbcContext(hnd, ctx);
00044
00045
00046 if(!cac_Connect(hnd, NULL)) {
00047 printf("Could not connect to server\n");
00048 exit(1);
00049 }
00050
00051 lop.in.access = MAXIMUM_ALLOWED_ACCESS;
00052 if(!cac_LsaOpenPolicy(hnd, mem_ctx, &lop))
00053 printf("Could not open LSA policy. Error: %s\n", nt_errstr(hnd->status));
00054
00055 printf("Opened LSA policy.\n");
00056
00057 rc.in.access = MAXIMUM_ALLOWED_ACCESS;
00058 rc.in.root = HKEY_LOCAL_MACHINE;
00059 if(!cac_RegConnect(hnd, mem_ctx, &rc))
00060 printf("Could not connect to registry. Error: %s\n", nt_errstr(hnd->status));
00061
00062 printf("Connceted to Registry.\n");
00063
00064 sod.in.access = MAXIMUM_ALLOWED_ACCESS;
00065
00066 if(!cac_SamOpenDomain(hnd, mem_ctx, &sod))
00067 printf("Could not open domain SAM. Error: %s\n", nt_errstr(hnd->status));
00068
00069 printf("Opened domain.\n");
00070
00071 if(lop.out.pol)
00072 cac_LsaClosePolicy(hnd, mem_ctx, lop.out.pol);
00073
00074 if(rc.out.key)
00075 cac_RegClose(hnd, mem_ctx, rc.out.key);
00076
00077 if(sod.out.sam)
00078 cac_SamClose(hnd, mem_ctx, sod.out.sam);
00079
00080 if(sod.out.dom_hnd)
00081 cac_SamClose(hnd, mem_ctx, sod.out.dom_hnd);
00082
00083 cac_FreeHandle(hnd);
00084 talloc_destroy(mem_ctx);
00085
00086 return 0;
00087 }