Build fixes for libnetapi.
[nivanova/samba-autobuild/.git] / source3 / lib / netapi / netapi.c
1 /*
2  *  Unix SMB/CIFS implementation.
3  *  NetApi Support
4  *  Copyright (C) Guenther Deschner 2007
5  *
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.
10  *
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.
15  *
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/>.
18  */
19
20 #include "includes.h"
21 #include "lib/netapi/netapi.h"
22
23 extern bool AllowDebugChange;
24
25 static bool libnetapi_initialized = false;
26
27 WERROR libnetapi_init(struct libnetapi_ctx **context)
28 {
29         struct libnetapi_ctx *ctx = NULL;
30         TALLOC_CTX *frame = NULL;
31
32         if (libnetapi_initialized) {
33                 return WERR_OK;
34         }
35
36         frame = talloc_stackframe();
37
38         ctx = talloc_zero(frame, struct libnetapi_ctx);
39         if (!ctx) {
40                 TALLOC_FREE(frame);
41                 return WERR_NOMEM;
42         }
43
44         DEBUGLEVEL = 0;
45         DEBUGLEVEL_CLASS[DBGC_ALL] = 0;
46         dbf = x_stderr;
47         x_setbuf(x_stderr, NULL);
48         AllowDebugChange = false;
49
50         load_case_tables();
51
52         setup_logging("libnetapi", true);
53
54         if (!lp_load(get_dyn_CONFIGFILE(), true, false, false, false)) {
55                 TALLOC_FREE(frame);
56                 return WERR_GENERAL_FAILURE;
57         }
58
59         init_names();
60         load_interfaces();
61         reopen_logs();
62
63         BlockSignals(True, SIGPIPE);
64
65         libnetapi_initialized = true;
66
67         *context = ctx;
68
69         return WERR_OK;
70 }
71
72 WERROR libnetapi_free(struct libnetapi_ctx *ctx)
73 {
74         TALLOC_FREE(ctx);
75         return WERR_OK;
76 }