2 * Unix SMB/CIFS implementation.
3 * Garble the netlogon_creds_cli key for testing purposes
4 * Copyright (C) Volker Lendecke 2018
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/>.
21 #include "system/filesys.h"
25 #include "lib/util/talloc_stack.h"
26 #include "popt_common.h"
27 #include "lib/param/loadparm.h"
28 #include "lib/param/param.h"
29 #include "libcli/auth/netlogon_creds_cli.h"
30 #include "lib/dbwrap/dbwrap.h"
31 #include "lib/dbwrap/dbwrap_open.h"
33 int main(int argc
, const char *argv
[])
35 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
36 struct tevent_context
*ev
;
37 struct messaging_context
*msg_ctx
;
38 struct loadparm_context
*lp_ctx
;
39 struct db_context
*global_db
;
40 struct netlogon_creds_cli_context
*ctx
;
41 struct netlogon_creds_CredentialState
*creds
;
47 if (!lp_load_global(get_dyn_CONFIGFILE())) {
48 fprintf(stderr
, "error opening config file %s. Error was %s\n",
49 get_dyn_CONFIGFILE(), strerror(errno
));
54 fprintf(stderr
, "usage: %s cli_computer domain dc\n", argv
[0]);
58 lp_ctx
= loadparm_init_s3(mem_ctx
, loadparm_s3_helpers());
60 fprintf(stderr
, "loadparm_init_s3 failed\n");
64 ev
= samba_tevent_context_init(mem_ctx
);
66 fprintf(stderr
, "samba3_tevent_context_init failed\n");
69 msg_ctx
= messaging_init(mem_ctx
, ev
);
70 if (msg_ctx
== NULL
) {
71 fprintf(stderr
, "messaging_init failed\n");
77 lpcfg_private_db_path(mem_ctx
, lp_ctx
, "netlogon_creds_cli"),
78 0, TDB_CLEAR_IF_FIRST
|TDB_INCOMPATIBLE_HASH
,
79 O_RDWR
|O_CREAT
, 0600, DBWRAP_LOCK_ORDER_2
,
80 DBWRAP_FLAG_OPTIMIZE_READONLY_ACCESS
);
81 if (global_db
== NULL
) {
82 fprintf(stderr
, "db_open failed\n");
86 status
= netlogon_creds_cli_set_global_db(&global_db
);
87 if (!NT_STATUS_IS_OK(status
)) {
89 "netlogon_creds_cli_set_global_db failed: %s\n",
94 status
= netlogon_creds_cli_context_global(
97 talloc_asprintf(mem_ctx
, "%s$", argv
[1]),
104 if (!NT_STATUS_IS_OK(status
)) {
106 "netlogon_creds_cli_context_global failed: %s\n",
111 status
= netlogon_creds_cli_lock(ctx
,
114 if (!NT_STATUS_IS_OK(status
)) {
116 "netlogon_creds_cli_get failed: %s\n",
121 creds
->session_key
[0]++;
123 status
= netlogon_creds_cli_store(ctx
, creds
);
124 if (!NT_STATUS_IS_OK(status
)) {
126 "netlogon_creds_cli_store failed: %s\n",
135 TALLOC_FREE(mem_ctx
);