2 * Samba Unix/Linux SMB client library
3 * Distributed SMB/CIFS Server Management Utility
4 * Nltest netlogon testing tool
6 * Copyright (C) Guenther Deschner 2009
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include <sys/types.h>
41 /****************************************************************
42 ****************************************************************/
44 static void print_netlogon_info_result(uint32_t level,
47 struct NETLOGON_INFO_1 *i1 = NULL;
48 struct NETLOGON_INFO_2 *i2 = NULL;
49 struct NETLOGON_INFO_3 *i3 = NULL;
50 struct NETLOGON_INFO_4 *i4 = NULL;
58 i1 = (struct NETLOGON_INFO_1 *)buffer;
60 printf("Flags: %x\n", i1->netlog1_flags);
61 printf("Connection Status Status = %d 0x%x %s\n",
62 i1->netlog1_pdc_connection_status,
63 i1->netlog1_pdc_connection_status,
64 libnetapi_errstr(i1->netlog1_pdc_connection_status));
68 i2 = (struct NETLOGON_INFO_2 *)buffer;
70 printf("Flags: %x\n", i2->netlog2_flags);
71 printf("Trusted DC Name %s\n", i2->netlog2_trusted_dc_name);
72 printf("Trusted DC Connection Status Status = %d 0x%x %s\n",
73 i2->netlog2_tc_connection_status,
74 i2->netlog2_tc_connection_status,
75 libnetapi_errstr(i2->netlog2_tc_connection_status));
76 printf("Trust Verification Status Status = %d 0x%x %s\n",
77 i2->netlog2_pdc_connection_status,
78 i2->netlog2_pdc_connection_status,
79 libnetapi_errstr(i2->netlog2_pdc_connection_status));
83 i3 = (struct NETLOGON_INFO_3 *)buffer;
85 printf("Flags: %x\n", i3->netlog1_flags);
86 printf("Logon Attempts: %d\n", i3->netlog3_logon_attempts);
90 i4 = (struct NETLOGON_INFO_4 *)buffer;
92 printf("Trusted DC Name %s\n", i4->netlog4_trusted_dc_name);
93 printf("Trusted Domain Name %s\n", i4->netlog4_trusted_domain_name);
101 /****************************************************************
102 ****************************************************************/
104 int main(int argc, const char **argv)
107 NET_API_STATUS status;
108 struct libnetapi_ctx *ctx = NULL;
109 char *opt_server = NULL;
110 char *opt_domain = NULL;
112 uint32_t query_level = 0;
113 uint8_t *buffer = NULL;
116 struct poptOption long_options[] = {
118 {"server", 0, POPT_ARG_STRING, &opt_server, OPT_SERVER, "Servername", "SERVER"},
119 {"dbflag", 0, POPT_ARG_INT, &opt_dbflag, OPT_DBFLAG, "New Debug Flag", "HEXFLAGS"},
120 {"sc_query", 0, POPT_ARG_STRING, &opt_domain, OPT_SC_QUERY, "Query secure channel for domain on server", "DOMAIN"},
121 {"sc_reset", 0, POPT_ARG_STRING, &opt_domain, OPT_SC_RESET, "Reset secure channel for domain on server to dcname", "DOMAIN"},
122 {"sc_verify", 0, POPT_ARG_STRING, &opt_domain, OPT_SC_VERIFY, "Verify secure channel for domain on server", "DOMAIN"},
123 {"sc_change_pwd", 0, POPT_ARG_STRING, &opt_domain, OPT_SC_CHANGE_PWD, "Change a secure channel password for domain on server", "DOMAIN"},
124 POPT_COMMON_LIBNETAPI_EXAMPLES
128 status = libnetapi_init(&ctx);
133 pc = poptGetContext("nltest", argc, argv, long_options, 0);
135 poptSetOtherOptionHelp(pc, "<options>");
136 while((opt = poptGetNextOpt(pc)) != -1) {
140 poptPrintHelp(pc, stderr, 0);
144 poptResetContext(pc);
146 while ((opt = poptGetNextOpt(pc)) != -1) {
151 if ((opt_server[0] == '/' && opt_server[1] == '/') ||
152 (opt_server[0] == '\\' && opt_server[1] == '\\')) {
160 status = I_NetLogonControl2(opt_server,
161 NETLOGON_CONTROL_SET_DBFLAG,
163 (uint8_t *)opt_dbflag,
166 fprintf(stderr, "I_NetlogonControl failed: Status = %d 0x%x %s\n",
168 libnetapi_get_error_string(ctx, status));
172 print_netlogon_info_result(query_level, buffer);
177 status = I_NetLogonControl2(opt_server,
178 NETLOGON_CONTROL_TC_QUERY,
180 (uint8_t *)opt_domain,
183 fprintf(stderr, "I_NetlogonControl failed: Status = %d 0x%x %s\n",
185 libnetapi_get_error_string(ctx, status));
189 print_netlogon_info_result(query_level, buffer);
194 status = I_NetLogonControl2(opt_server,
195 NETLOGON_CONTROL_TC_VERIFY,
197 (uint8_t *)opt_domain,
200 fprintf(stderr, "I_NetlogonControl failed: Status = %d 0x%x %s\n",
202 libnetapi_get_error_string(ctx, status));
206 print_netlogon_info_result(query_level, buffer);
211 status = I_NetLogonControl2(opt_server,
212 NETLOGON_CONTROL_REDISCOVER,
214 (uint8_t *)opt_domain,
217 fprintf(stderr, "I_NetlogonControl failed: Status = %d 0x%x %s\n",
219 libnetapi_get_error_string(ctx, status));
223 print_netlogon_info_result(query_level, buffer);
226 case OPT_SC_CHANGE_PWD:
228 status = I_NetLogonControl2(opt_server,
229 NETLOGON_CONTROL_CHANGE_PASSWORD,
231 (uint8_t *)opt_domain,
234 fprintf(stderr, "I_NetlogonControl failed: Status = %d 0x%x %s\n",
236 libnetapi_get_error_string(ctx, status));
240 print_netlogon_info_result(query_level, buffer);
244 poptPrintHelp(pc, stderr, 0);
249 printf("The command completed successfully\n");