2 * Unix SMB/CIFS implementation.
3 * NetProvisionComputerAccount query
4 * Copyright (C) Guenther Deschner 2021
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/>.
22 #include <sys/types.h>
29 int main(int argc
, const char **argv
)
31 NET_API_STATUS status
;
32 const char *domain
= NULL
;
33 const char *machine_name
= NULL
;
34 const char *machine_account_ou
= NULL
;
35 const char *dcname
= NULL
;
37 const char *provision_text_data
= NULL
;
38 int default_password
= 0;
40 const char *savefile
= NULL
;
43 struct libnetapi_ctx
*ctx
= NULL
;
48 struct poptOption long_options
[] = {
50 { "dcname", 0, POPT_ARG_STRING
, &dcname
, 'D', "Domain Controller Name", "DCNAME" },
51 { "machine_account_ou", 0, POPT_ARG_STRING
, &machine_account_ou
, 'D', "LDAP DN for Machine Account OU", "MACHINE_ACCOUNT_OU" },
52 { "defpwd", 0, POPT_ARG_NONE
, &default_password
, 'D', "Use default password for machine account (not recommended)", "" },
53 { "printblob", 0, POPT_ARG_NONE
, &print_blob
, 'D', "Print base64 encoded ODJ blob (for Windows answer files)", "" },
54 { "savefile", 0, POPT_ARG_STRING
, &savefile
, 'D', "Save ODJ blob to file (for Windows answer files)", "FILENAME" },
55 { "reuse", 0, POPT_ARG_NONE
, &reuse
, 'D', "Reuse machine account", "" },
56 POPT_COMMON_LIBNETAPI_EXAMPLES
60 status
= libnetapi_init(&ctx
);
65 pc
= poptGetContext("provision_computer_account", argc
, argv
, long_options
, 0);
67 poptSetOtherOptionHelp(pc
, "domain machine_name");
68 while((opt
= poptGetNextOpt(pc
)) != -1) {
71 if (!poptPeekArg(pc
)) {
72 poptPrintHelp(pc
, stderr
, 0);
75 domain
= poptGetArg(pc
);
77 if (!poptPeekArg(pc
)) {
78 poptPrintHelp(pc
, stderr
, 0);
81 machine_name
= poptGetArg(pc
);
83 if (default_password
) {
84 options
|= NETSETUP_PROVISION_USE_DEFAULT_PASSWORD
;
87 options
|= NETSETUP_PROVISION_REUSE_ACCOUNT
;
90 /* NetProvisionComputerAccount */
92 status
= NetProvisionComputerAccount(domain
,
99 &provision_text_data
);
101 printf("failed with: %s\n",
102 libnetapi_get_error_string(ctx
, status
));
107 printf("Provision data: %s\n", provision_text_data
);
110 if (savefile
!= NULL
) {
111 status
= netapi_save_file_ucs2(savefile
, provision_text_data
);