librpc: Shorten dcerpc_binding_handle_call a bit
[Samba/gebeck_regimport.git] / source3 / lib / netapi / examples / netlogon / netlogon_control2.c
blobea8e8c254c4955e376034fe17686ada668883c5a
1 /*
2 * Unix SMB/CIFS implementation.
3 * I_NetLogonControl2 query
4 * Copyright (C) Guenther Deschner 2009
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
20 #include <sys/types.h>
21 #include <inttypes.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
26 #include <netapi.h>
28 #include "common.h"
30 int main(int argc, const char **argv)
32 NET_API_STATUS status;
33 struct libnetapi_ctx *ctx = NULL;
34 const char *hostname = NULL;
35 uint32_t function_code = NETLOGON_CONTROL_QUERY;
36 uint32_t level = 1;
37 uint8_t *buffer = NULL;
38 struct NETLOGON_INFO_1 *i1 = NULL;
39 struct NETLOGON_INFO_2 *i2 = NULL;
40 struct NETLOGON_INFO_3 *i3 = NULL;
41 struct NETLOGON_INFO_4 *i4 = NULL;
42 const char *domain = NULL;
44 poptContext pc;
45 int opt;
47 struct poptOption long_options[] = {
48 POPT_AUTOHELP
49 POPT_COMMON_LIBNETAPI_EXAMPLES
50 POPT_TABLEEND
53 status = libnetapi_init(&ctx);
54 if (status != 0) {
55 return status;
58 pc = poptGetContext("netlogon_control", argc, argv, long_options, 0);
60 poptSetOtherOptionHelp(pc, "hostname");
61 while((opt = poptGetNextOpt(pc)) != -1) {
64 if (!poptPeekArg(pc)) {
65 poptPrintHelp(pc, stderr, 0);
66 goto out;
68 hostname = poptGetArg(pc);
70 if (poptPeekArg(pc)) {
71 function_code = atoi(poptGetArg(pc));
74 if (poptPeekArg(pc)) {
75 level = atoi(poptGetArg(pc));
78 domain = "TEST";
80 /* I_NetLogonControl2 */
82 status = I_NetLogonControl2(hostname,
83 function_code,
84 level,
85 (uint8_t *)domain,
86 &buffer);
87 if (status != 0) {
88 printf("I_NetLogonControl2 failed with: %s\n",
89 libnetapi_get_error_string(ctx, status));
90 goto out;
93 if (!buffer) {
94 goto out;
97 switch (level) {
98 case 1:
99 i1 = (struct NETLOGON_INFO_1 *)buffer;
101 printf("Flags: %x\n", i1->netlog1_flags);
102 printf("Connection Status Status = %d 0x%x %s\n",
103 i1->netlog1_pdc_connection_status,
104 i1->netlog1_pdc_connection_status,
105 libnetapi_errstr(i1->netlog1_pdc_connection_status));
107 break;
108 case 2:
109 i2 = (struct NETLOGON_INFO_2 *)buffer;
111 printf("Flags: %x\n", i2->netlog2_flags);
112 printf("Trusted DC Name %s\n", i2->netlog2_trusted_dc_name);
113 printf("Trusted DC Connection Status Status = %d 0x%x %s\n",
114 i2->netlog2_tc_connection_status,
115 i2->netlog2_tc_connection_status,
116 libnetapi_errstr(i2->netlog2_tc_connection_status));
117 printf("Trust Verification Status Status = %d 0x%x %s\n",
118 i2->netlog2_pdc_connection_status,
119 i2->netlog2_pdc_connection_status,
120 libnetapi_errstr(i2->netlog2_pdc_connection_status));
122 break;
123 case 3:
124 i3 = (struct NETLOGON_INFO_3 *)buffer;
126 printf("Flags: %x\n", i3->netlog1_flags);
127 printf("Logon Attempts: %d\n", i3->netlog3_logon_attempts);
129 break;
130 case 4:
131 i4 = (struct NETLOGON_INFO_4 *)buffer;
133 printf("Trusted DC Name %s\n", i4->netlog4_trusted_dc_name);
134 printf("Trusted Domain Name %s\n", i4->netlog4_trusted_domain_name);
136 break;
137 default:
138 break;
141 out:
142 NetApiBufferFree(buffer);
143 libnetapi_free(ctx);
144 poptFreeContext(pc);
146 return status;