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>
40 /****************************************************************
41 ****************************************************************/
43 static void print_result(uint32_t level,
46 struct NETLOGON_INFO_1 *i1 = NULL;
47 struct NETLOGON_INFO_2 *i2 = NULL;
48 struct NETLOGON_INFO_3 *i3 = NULL;
49 struct NETLOGON_INFO_4 *i4 = NULL;
57 i1 = (struct NETLOGON_INFO_1 *)buffer;
59 printf("Flags: %x\n", i1->netlog1_flags);
60 printf("Connection Status Status = %d 0x%x %s\n",
61 i1->netlog1_pdc_connection_status,
62 i1->netlog1_pdc_connection_status,
63 libnetapi_errstr(i1->netlog1_pdc_connection_status));
67 i2 = (struct NETLOGON_INFO_2 *)buffer;
69 printf("Flags: %x\n", i2->netlog2_flags);
70 printf("Trusted DC Name %s\n", i2->netlog2_trusted_dc_name);
71 printf("Trusted DC Connection Status Status = %d 0x%x %s\n",
72 i2->netlog2_tc_connection_status,
73 i2->netlog2_tc_connection_status,
74 libnetapi_errstr(i2->netlog2_tc_connection_status));
75 printf("Trust Verification Status Status = %d 0x%x %s\n",
76 i2->netlog2_pdc_connection_status,
77 i2->netlog2_pdc_connection_status,
78 libnetapi_errstr(i2->netlog2_pdc_connection_status));
82 i3 = (struct NETLOGON_INFO_3 *)buffer;
84 printf("Flags: %x\n", i3->netlog1_flags);
85 printf("Logon Attempts: %d\n", i3->netlog3_logon_attempts);
89 i4 = (struct NETLOGON_INFO_4 *)buffer;
91 printf("Trusted DC Name %s\n", i4->netlog4_trusted_dc_name);
92 printf("Trusted Domain Name %s\n", i4->netlog4_trusted_domain_name);
100 /****************************************************************
101 ****************************************************************/
103 int main(int argc, const char **argv)
106 NET_API_STATUS status;
107 struct libnetapi_ctx *ctx = NULL;
108 const char *server_name = NULL;
109 char *opt_domain = NULL;
111 uint32_t query_level;
112 uint8_t *buffer = NULL;
115 struct poptOption long_options[] = {
117 {"dbflag", 0, POPT_ARG_INT, &opt_dbflag, OPT_DBFLAG, "New Debug Flag", "HEXFLAGS"},
118 {"sc_query", 0, POPT_ARG_STRING, &opt_domain, OPT_SC_QUERY, "Query secure channel for domain on server", "DOMAIN"},
119 {"sc_reset", 0, POPT_ARG_STRING, &opt_domain, OPT_SC_RESET, "Reset secure channel for domain on server to dcname", "DOMAIN"},
120 {"sc_verify", 0, POPT_ARG_STRING, &opt_domain, OPT_SC_VERIFY, "Verify secure channel for domain on server", "DOMAIN"},
121 {"sc_change_pwd", 0, POPT_ARG_STRING, &opt_domain, OPT_SC_CHANGE_PWD, "Change a secure channel password for domain on server", "DOMAIN"},
122 POPT_COMMON_LIBNETAPI_EXAMPLES
126 status = libnetapi_init(&ctx);
131 pc = poptGetContext("nltest", argc, argv, long_options, 0);
133 poptSetOtherOptionHelp(pc, "server_name");
134 while((opt = poptGetNextOpt(pc)) != -1) {
137 if (!poptPeekArg(pc)) {
138 poptPrintHelp(pc, stderr, 0);
141 server_name = poptGetArg(pc);
144 poptPrintHelp(pc, stderr, 0);
148 if (!server_name || poptGetArg(pc)) {
149 poptPrintHelp(pc, stderr, 0);
153 if ((server_name[0] == '/' && server_name[1] == '/') ||
154 (server_name[0] == '\\' && server_name[1] == '\\')) {
158 poptResetContext(pc);
160 while ((opt = poptGetNextOpt(pc)) != -1) {
165 status = I_NetLogonControl2(server_name,
166 NETLOGON_CONTROL_SET_DBFLAG,
168 (uint8_t *)opt_dbflag,
171 fprintf(stderr, "I_NetlogonControl failed: Status = %d 0x%x %s\n",
173 libnetapi_get_error_string(ctx, status));
179 status = I_NetLogonControl2(server_name,
180 NETLOGON_CONTROL_TC_QUERY,
182 (uint8_t *)opt_domain,
185 fprintf(stderr, "I_NetlogonControl failed: Status = %d 0x%x %s\n",
187 libnetapi_get_error_string(ctx, status));
193 status = I_NetLogonControl2(server_name,
194 NETLOGON_CONTROL_TC_VERIFY,
196 (uint8_t *)opt_domain,
199 fprintf(stderr, "I_NetlogonControl failed: Status = %d 0x%x %s\n",
201 libnetapi_get_error_string(ctx, status));
207 status = I_NetLogonControl2(server_name,
208 NETLOGON_CONTROL_REDISCOVER,
210 (uint8_t *)opt_domain,
213 fprintf(stderr, "I_NetlogonControl failed: Status = %d 0x%x %s\n",
215 libnetapi_get_error_string(ctx, status));
219 case OPT_SC_CHANGE_PWD:
221 status = I_NetLogonControl2(server_name,
222 NETLOGON_CONTROL_CHANGE_PASSWORD,
224 (uint8_t *)opt_domain,
227 fprintf(stderr, "I_NetlogonControl failed: Status = %d 0x%x %s\n",
229 libnetapi_get_error_string(ctx, status));
234 poptPrintHelp(pc, stderr, 0);
239 print_result(query_level, buffer);
241 printf("The command completed successfully\n");