2 * Unix SMB/CIFS implementation.
4 * Copyright (C) Guenther Deschner 2007-2008
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 struct libnetapi_ctx *stat_ctx = NULL;
26 TALLOC_CTX *frame = NULL;
27 static bool libnetapi_initialized = false;
29 NET_API_STATUS libnetapi_init(struct libnetapi_ctx **context)
31 struct libnetapi_ctx *ctx = NULL;
33 if (stat_ctx && libnetapi_initialized) {
35 return W_ERROR_V(WERR_OK);
38 frame = talloc_stackframe();
40 ctx = talloc_zero(frame, struct libnetapi_ctx);
43 return W_ERROR_V(WERR_NOMEM);
47 setup_logging("libnetapi", true);
50 x_setbuf(x_stderr, NULL);
51 AllowDebugChange = false;
55 if (!lp_load(get_dyn_CONFIGFILE(), true, false, false, false)) {
57 return W_ERROR_V(WERR_GENERAL_FAILURE);
60 AllowDebugChange = true;
66 BlockSignals(True, SIGPIPE);
68 libnetapi_initialized = true;
70 *context = stat_ctx = ctx;
72 return W_ERROR_V(WERR_OK);
75 NET_API_STATUS libnetapi_getctx(struct libnetapi_ctx **ctx)
79 return W_ERROR_V(WERR_OK);
82 return libnetapi_init(ctx);
85 NET_API_STATUS libnetapi_free(struct libnetapi_ctx *ctx)
101 return W_ERROR_V(WERR_OK);
104 NET_API_STATUS libnetapi_set_debuglevel(struct libnetapi_ctx *ctx,
105 const char *debuglevel)
107 AllowDebugChange = true;
108 ctx->debuglevel = debuglevel;
109 if (!debug_parse_levels(debuglevel)) {
110 return W_ERROR_V(WERR_GENERAL_FAILURE);
112 return W_ERROR_V(WERR_OK);
115 NET_API_STATUS libnetapi_get_debuglevel(struct libnetapi_ctx *ctx,
116 const char **debuglevel)
118 *debuglevel = ctx->debuglevel;
119 return W_ERROR_V(WERR_OK);
122 NET_API_STATUS libnetapi_set_username(struct libnetapi_ctx *ctx,
123 const char *username)
125 TALLOC_FREE(ctx->username);
126 ctx->username = talloc_strdup(ctx, username);
127 if (!ctx->username) {
128 return W_ERROR_V(WERR_NOMEM);
130 return W_ERROR_V(WERR_OK);
133 NET_API_STATUS libnetapi_set_password(struct libnetapi_ctx *ctx,
134 const char *password)
136 TALLOC_FREE(ctx->password);
137 ctx->password = talloc_strdup(ctx, password);
138 if (!ctx->password) {
139 return W_ERROR_V(WERR_NOMEM);
141 return W_ERROR_V(WERR_OK);
144 NET_API_STATUS libnetapi_set_workgroup(struct libnetapi_ctx *ctx,
145 const char *workgroup)
147 TALLOC_FREE(ctx->workgroup);
148 ctx->workgroup = talloc_strdup(ctx, workgroup);
149 if (!ctx->workgroup) {
150 return W_ERROR_V(WERR_NOMEM);
152 return W_ERROR_V(WERR_OK);
155 const char *libnetapi_errstr(struct libnetapi_ctx *ctx,
156 NET_API_STATUS status)
158 if (status & 0xc0000000) {
159 return get_friendly_nt_error_msg(NT_STATUS(status));
162 return get_friendly_werror_msg(W_ERROR(status));