Merge branch 'master' of ssh://git.samba.org/data/git/samba into libcli-auth-merge...
[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 "libcli/auth/libcli_auth.h"
27 #include "auth/auth.h"
28 #include "param/param.h"
29 #include "auth/gensec/schannel_state.h"
30
31 /**
32   connect to the schannel ldb
33 */
34 struct ldb_context *schannel_db_connect(TALLOC_CTX *mem_ctx, struct tevent_context *ev_ctx,
35                                         struct loadparm_context *lp_ctx)
36 {
37         char *path;
38         struct ldb_context *ldb;
39         bool existed;
40         const char *init_ldif = 
41                 "dn: @ATTRIBUTES\n" \
42                 "computerName: CASE_INSENSITIVE\n" \
43                 "flatname: CASE_INSENSITIVE\n";
44
45         path = private_path(mem_ctx, lp_ctx, "schannel.ldb");
46         if (!path) {
47                 return NULL;
48         }
49
50         existed = file_exist(path);
51         
52         ldb = ldb_wrap_connect(mem_ctx, ev_ctx, lp_ctx, path, 
53                                system_session(mem_ctx, lp_ctx), 
54                                NULL, LDB_FLG_NOSYNC, NULL);
55         talloc_free(path);
56         if (!ldb) {
57                 return NULL;
58         }
59         
60         if (!existed) {
61                 gendb_add_ldif(ldb, init_ldif);
62         }
63
64         return ldb;
65 }
66