2 Unix SMB/CIFS implementation.
3 Copyright (C) Guenther Deschner 2009
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "../libcli/auth/libcli_auth.h"
21 #include "../libcli/auth/schannel_state.h"
23 /******************************************************************************
24 Open or create the schannel session store tdb.
25 *******************************************************************************/
27 #define SCHANNEL_STORE_VERSION_1 1
28 #define SCHANNEL_STORE_VERSION_2 2 /* should not be used */
29 #define SCHANNEL_STORE_VERSION_CURRENT SCHANNEL_STORE_VERSION_1
31 TDB_CONTEXT *open_schannel_session_store(TALLOC_CTX *mem_ctx)
35 TDB_CONTEXT *tdb_sc = NULL;
36 char *fname = talloc_asprintf(mem_ctx, "%s/schannel_store.tdb", lp_private_dir());
42 tdb_sc = tdb_open_log(fname, 0, TDB_DEFAULT, O_RDWR|O_CREAT, 0600);
45 DEBUG(0,("open_schannel_session_store: Failed to open %s\n", fname));
51 vers = tdb_fetch_bystring(tdb_sc, "SCHANNEL_STORE_VERSION");
52 if (vers.dptr == NULL) {
53 /* First opener, no version. */
54 SIVAL(&ver,0,SCHANNEL_STORE_VERSION_CURRENT);
55 vers.dptr = (uint8 *)&ver;
57 tdb_store_bystring(tdb_sc, "SCHANNEL_STORE_VERSION", vers, TDB_REPLACE);
59 } else if (vers.dsize == 4) {
60 ver = IVAL(vers.dptr,0);
61 if (ver == SCHANNEL_STORE_VERSION_2) {
62 DEBUG(0,("open_schannel_session_store: wrong version number %d in %s\n",
67 if (ver != SCHANNEL_STORE_VERSION_CURRENT) {
68 DEBUG(0,("open_schannel_session_store: wrong version number %d in %s\n",
76 DEBUG(0,("open_schannel_session_store: wrong version number size %d in %s\n",
77 (int)vers.dsize, fname ));
86 /******************************************************************************
87 Wrapper around schannel_fetch_session_key_tdb()
88 Note we must be root here.
89 *******************************************************************************/
91 NTSTATUS schannel_fetch_session_key(TALLOC_CTX *mem_ctx,
92 const char *computer_name,
93 struct netlogon_creds_CredentialState **pcreds)
95 struct tdb_context *tdb;
98 tdb = open_schannel_session_store(mem_ctx);
100 return NT_STATUS_ACCESS_DENIED;
103 status = schannel_fetch_session_key_tdb(tdb, mem_ctx, computer_name, pcreds);
110 /******************************************************************************
111 Wrapper around schannel_store_session_key_tdb()
112 Note we must be root here.
113 *******************************************************************************/
115 NTSTATUS schannel_store_session_key(TALLOC_CTX *mem_ctx,
116 struct netlogon_creds_CredentialState *creds)
118 struct tdb_context *tdb;
121 tdb = open_schannel_session_store(mem_ctx);
123 return NT_STATUS_ACCESS_DENIED;
126 status = schannel_store_session_key_tdb(tdb, mem_ctx, creds);