1 /*queries trusted domain information*/
6 #define MAX_STRING_LEN 50;
8 void print_info(LSA_TRUSTED_DOMAIN_INFO
*info
) {
9 switch(info
->info_class
) {
10 case CAC_INFO_TRUSTED_DOMAIN_FULL_INFO
:
11 case CAC_INFO_TRUSTED_DOMAIN_INFO_ALL
:
12 printf(" Domain Name: %s\n", unistr2_static(&info
->info_ex
.domain_name
.unistring
));
13 printf(" Netbios Name: %s\n", unistr2_static(&info
->info_ex
.netbios_name
.unistring
));
14 printf(" Domain Sid: %s\n", sid_string_static(&info
->info_ex
.sid
.sid
));
15 printf(" Trust direction: %d\n", info
->info_ex
.trust_direction
);
16 printf(" Trust Type: %d\n", info
->info_ex
.trust_type
);
17 printf(" Trust attr: %d\n", info
->info_ex
.trust_attributes
);
18 printf(" Posix Offset: %d\n", info
->posix_offset
.posix_offset
);
24 CacServerHandle
*hnd
= NULL
;
25 TALLOC_CTX
*mem_ctx
= NULL
;
26 POLICY_HND
*lsa_pol
= NULL
;
30 mem_ctx
= talloc_init("lsatrust");
32 hnd
= cac_NewServerHandle(False
);
34 /*malloc some memory so get_auth_data_fn can work*/
35 hnd
->username
= SMB_MALLOC_ARRAY(char, sizeof(fstring
));
36 hnd
->domain
= SMB_MALLOC_ARRAY(char, sizeof(fstring
));
37 hnd
->netbios_name
= SMB_MALLOC_ARRAY(char, sizeof(fstring
));
38 hnd
->password
= SMB_MALLOC_ARRAY(char, sizeof(fstring
));
40 hnd
->server
= SMB_MALLOC_ARRAY(char, sizeof(fstring
));
44 fscanf(stdin
, "%s", hnd
->server
);
46 printf("Connecting to server....\n");
48 if(!cac_Connect(hnd
, NULL
)) {
49 fprintf(stderr
, "Could not connect to server.\n Error: %s\n errno %s\n", nt_errstr(hnd
->status
), strerror(errno
));
54 printf("Connected to server\n");
56 struct LsaOpenPolicy lop
;
59 lop
.in
.access
= SEC_RIGHT_MAXIMUM_ALLOWED
;
60 lop
.in
.security_qos
= True
;
63 if(!cac_LsaOpenPolicy(hnd
, mem_ctx
, &lop
)) {
64 fprintf(stderr
, "Could not open policy handle.\n Error: %s\n", nt_errstr(hnd
->status
));
69 lsa_pol
= lop
.out
.pol
;
71 printf("Enumerating Trusted Domains\n");
73 struct LsaEnumTrustedDomains etd
;
78 while(cac_LsaEnumTrustedDomains(hnd
, mem_ctx
, &etd
)) {
79 printf(" Enumerated %d domains\n", etd
.out
.num_domains
);
81 for(i
= 0; i
< etd
.out
.num_domains
; i
++) {
82 printf(" Name: %s\n", etd
.out
.domain_names
[i
]);
83 printf(" SID: %s\n", sid_string_static(&etd
.out
.domain_sids
[i
]));
85 printf("\n Attempting to open domain...\n");
87 struct LsaOpenTrustedDomain otd
;
91 otd
.in
.domain_sid
= &etd
.out
.domain_sids
[i
];
92 otd
.in
.access
= SEC_RIGHT_MAXIMUM_ALLOWED
;
94 /*try to query trusted domain info by name*/
95 struct LsaQueryTrustedDomainInfo qtd
;
99 qtd
.in
.domain_name
= etd
.out
.domain_names
[i
];
103 for(j
= 0; j
< 100; j
++ ) {
104 qtd
.in
.info_class
= j
;
106 printf(" Querying trustdom by name\n");
107 if(!cac_LsaQueryTrustedDomainInfo(hnd
, mem_ctx
, &qtd
)) {
108 fprintf(stderr
, " could not query trusted domain info.\n Error %s\n", nt_errstr(hnd
->status
));
112 printf(" info_class %d succeeded\n", j
);
113 printf(" Query result:\n");
114 printf(" size %d\n", sizeof(*qtd
.out
.info
));
117 /*try to query trusted domain info by SID*/
118 printf(" Querying trustdom by sid\n");
119 qtd
.in
.domain_sid
= &etd
.out
.domain_sids
[i
];
120 if(!cac_LsaQueryTrustedDomainInfo(hnd
, mem_ctx
, &qtd
)) {
121 fprintf(stderr
, " could not query trusted domain info.\n Error %s\n", nt_errstr(hnd
->status
));
125 printf(" Query result:\n");
126 /* print_info(qtd.out.info);*/
128 if(CAC_OP_FAILED(hnd
->status
)) {
129 fprintf(stderr
, " Could not enum sids.\n Error: %s\n", nt_errstr(hnd
->status
));
137 if(CAC_OP_FAILED(hnd
->status
)) {
138 fprintf(stderr
, "Error while enumerating trusted domains.\n Error: %s\n", nt_errstr(hnd
->status
));
143 if(!cac_LsaClosePolicy(hnd
, mem_ctx
, lsa_pol
)) {
144 fprintf(stderr
, "Could not close policy handle.\n Error: %s\n", nt_errstr(hnd
->status
));
148 talloc_destroy(mem_ctx
);