2 * Unix SMB/CIFS implementation.
4 * Copyright (C) Guenther Deschner 2007
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 "lib/netapi/netapi.h"
23 extern bool AllowDebugChange;
25 static bool libnetapi_initialized = false;
27 NET_API_STATUS libnetapi_init(struct libnetapi_ctx **context)
29 struct libnetapi_ctx *ctx = NULL;
30 TALLOC_CTX *frame = NULL;
32 if (libnetapi_initialized) {
33 return W_ERROR_V(WERR_OK);
36 frame = talloc_stackframe();
38 ctx = talloc_zero(frame, struct libnetapi_ctx);
41 return W_ERROR_V(WERR_NOMEM);
45 setup_logging("libnetapi", true);
48 x_setbuf(x_stderr, NULL);
49 AllowDebugChange = false;
53 if (!lp_load(get_dyn_CONFIGFILE(), true, false, false, false)) {
55 return W_ERROR_V(WERR_GENERAL_FAILURE);
58 AllowDebugChange = true;
64 BlockSignals(True, SIGPIPE);
66 libnetapi_initialized = true;
70 return W_ERROR_V(WERR_OK);
73 NET_API_STATUS libnetapi_free(struct libnetapi_ctx *ctx)
76 return W_ERROR_V(WERR_OK);
79 NET_API_STATUS libnetapi_set_debuglevel(struct libnetapi_ctx *ctx,
80 const char *debuglevel)
82 AllowDebugChange = true;
83 ctx->debuglevel = debuglevel;
84 if (!debug_parse_levels(debuglevel)) {
85 return W_ERROR_V(WERR_GENERAL_FAILURE);
87 return W_ERROR_V(WERR_OK);
90 NET_API_STATUS libnetapi_get_debuglevel(struct libnetapi_ctx *ctx,
91 const char **debuglevel)
93 *debuglevel = ctx->debuglevel;
94 return W_ERROR_V(WERR_OK);
97 NET_API_STATUS libnetapi_set_username(struct libnetapi_ctx *ctx,
100 TALLOC_FREE(ctx->username);
101 ctx->username = talloc_strdup(ctx, username);
102 if (!ctx->username) {
103 return W_ERROR_V(WERR_NOMEM);
105 return W_ERROR_V(WERR_OK);
108 NET_API_STATUS libnetapi_set_password(struct libnetapi_ctx *ctx,
109 const char *password)
111 TALLOC_FREE(ctx->password);
112 ctx->password = talloc_strdup(ctx, password);
113 if (!ctx->password) {
114 return W_ERROR_V(WERR_NOMEM);
116 return W_ERROR_V(WERR_OK);
119 NET_API_STATUS libnetapi_set_workgroup(struct libnetapi_ctx *ctx,
120 const char *workgroup)
122 TALLOC_FREE(ctx->workgroup);
123 ctx->workgroup = talloc_strdup(ctx, workgroup);
124 if (!ctx->workgroup) {
125 return W_ERROR_V(WERR_NOMEM);
127 return W_ERROR_V(WERR_OK);