163ae1570dab9544b748f63e0868961c52d7d878
[ira/wip.git] / source4 / auth / gensec / schannel_state.c
1 /* 
2    Unix SMB/CIFS implementation.
3
4    module to store/fetch session keys for the schannel server
5
6    Copyright (C) Andrew Tridgell 2004
7    
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.
12    
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.
17    
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/>.
20 */
21
22 #include "includes.h"
23 #include "lib/ldb/include/ldb.h"
24 #include "ldb_wrap.h"
25 #include "../lib/util/util_ldb.h"
26 #include "auth/auth.h"
27 #include "param/param.h"
28
29 /**
30   connect to the schannel ldb
31 */
32 struct ldb_context *schannel_db_connect(TALLOC_CTX *mem_ctx, struct tevent_context *ev_ctx,
33                                         struct loadparm_context *lp_ctx)
34 {
35         char *path;
36         struct ldb_context *ldb;
37         bool existed;
38         const char *init_ldif = 
39                 "dn: @ATTRIBUTES\n" \
40                 "computerName: CASE_INSENSITIVE\n" \
41                 "flatname: CASE_INSENSITIVE\n";
42
43         path = private_path(mem_ctx, lp_ctx, "schannel.ldb");
44         if (!path) {
45                 return NULL;
46         }
47
48         existed = file_exist(path);
49         
50         ldb = ldb_wrap_connect(mem_ctx, ev_ctx, lp_ctx, path, 
51                                system_session(lp_ctx), 
52                                NULL, LDB_FLG_NOSYNC);
53         talloc_free(path);
54         if (!ldb) {
55                 return NULL;
56         }
57         
58         if (!existed) {
59                 gendb_add_ldif(ldb, init_ldif);
60         }
61
62         return ldb;
63 }
64