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 "lib/param/loadparm.h"
27 #include "lib/param/param.h"
28 #include "libcli/auth/netlogon_creds_cli.h"
29 #include "lib/dbwrap/dbwrap.h"
30 #include "lib/dbwrap/dbwrap_open.h"
32 int main(int argc
, const char *argv
[])
34 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
35 struct tevent_context
*ev
;
36 struct messaging_context
*msg_ctx
;
37 struct loadparm_context
*lp_ctx
;
38 struct db_context
*global_db
;
39 struct netlogon_creds_cli_context
*ctx
;
40 struct netlogon_creds_CredentialState
*creds
;
46 if (!lp_load_global(get_dyn_CONFIGFILE())) {
47 fprintf(stderr
, "error opening config file %s. Error was %s\n",
48 get_dyn_CONFIGFILE(), strerror(errno
));
53 fprintf(stderr
, "usage: %s cli_computer domain dc\n", argv
[0]);
57 lp_ctx
= loadparm_init_s3(mem_ctx
, loadparm_s3_helpers());
59 fprintf(stderr
, "loadparm_init_s3 failed\n");
63 ev
= samba_tevent_context_init(mem_ctx
);
65 fprintf(stderr
, "samba3_tevent_context_init failed\n");
68 msg_ctx
= messaging_init(mem_ctx
, ev
);
69 if (msg_ctx
== NULL
) {
70 fprintf(stderr
, "messaging_init failed\n");
76 lpcfg_private_db_path(mem_ctx
, lp_ctx
, "netlogon_creds_cli"),
77 0, TDB_CLEAR_IF_FIRST
|TDB_INCOMPATIBLE_HASH
,
78 O_RDWR
|O_CREAT
, 0600, DBWRAP_LOCK_ORDER_2
,
79 DBWRAP_FLAG_OPTIMIZE_READONLY_ACCESS
);
80 if (global_db
== NULL
) {
81 fprintf(stderr
, "db_open failed\n");
85 status
= netlogon_creds_cli_set_global_db(lp_ctx
, &global_db
);
86 if (!NT_STATUS_IS_OK(status
)) {
88 "netlogon_creds_cli_set_global_db failed: %s\n",
93 status
= netlogon_creds_cli_context_global(
96 talloc_asprintf(mem_ctx
, "%s$", argv
[1]),
103 if (!NT_STATUS_IS_OK(status
)) {
105 "netlogon_creds_cli_context_global failed: %s\n",
110 status
= netlogon_creds_cli_lock(ctx
,
113 if (!NT_STATUS_IS_OK(status
)) {
115 "netlogon_creds_cli_get failed: %s\n",
120 creds
->session_key
[0]++;
122 status
= netlogon_creds_cli_store(ctx
, creds
);
123 if (!NT_STATUS_IS_OK(status
)) {
125 "netlogon_creds_cli_store failed: %s\n",
134 TALLOC_FREE(mem_ctx
);