diff options
author | Jelmer Vernooij <jelmer@samba.org> | 2008-01-08 15:43:11 +0100 |
---|---|---|
committer | Jelmer Vernooij <jelmer@samba.org> | 2008-01-08 15:43:11 +0100 |
commit | bfab6ab14bd2ba69fde8bbe32f56f308010c8ea7 (patch) | |
tree | 4edbacab40c67bb5d9d6bebe66a22949349cbf9a /source3/lib/netapi | |
parent | 8dbeca6e9d06d573adebe8d9c5114b24d8782e43 (diff) | |
parent | 62c91987d902d4dfe27023ff2ec2fb73e602105b (diff) | |
download | samba-bfab6ab14bd2ba69fde8bbe32f56f308010c8ea7.tar.gz samba-bfab6ab14bd2ba69fde8bbe32f56f308010c8ea7.tar.bz2 samba-bfab6ab14bd2ba69fde8bbe32f56f308010c8ea7.zip |
Merge branch 'v3-2-test' of ssh://git.samba.org/data/git/samba into v3-2-test
(This used to be commit ea36c3add588061cf338deabb2d8952f2213a8bd)
Diffstat (limited to 'source3/lib/netapi')
-rw-r--r-- | source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c | 19 | ||||
-rw-r--r-- | source3/lib/netapi/examples/netdomjoin/netdomjoin.c | 7 | ||||
-rw-r--r-- | source3/lib/netapi/joindomain.c | 18 | ||||
-rw-r--r-- | source3/lib/netapi/netapi.c | 104 | ||||
-rw-r--r-- | source3/lib/netapi/netapi.h | 25 |
5 files changed, 142 insertions, 31 deletions
diff --git a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c index d12e66bb26..4a3588e9ab 100644 --- a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c +++ b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c @@ -249,6 +249,8 @@ static void callback_do_reboot(GtkWidget *widget, SAFE_FREE(buffer); state->name_type_new = type; #endif + NetApiBufferFree((void *)buffer); + gtk_label_set_text(GTK_LABEL(state->label_current_name_buffer), state->name_buffer_new); if (state->name_type_new == NetSetupDomainName) { @@ -449,14 +451,8 @@ static void callback_do_join(GtkWidget *widget, initial_workgroup_type, state->name_buffer_initial, err_str); - - g_signal_connect_swapped(dialog, "response", - G_CALLBACK(gtk_widget_destroy), - dialog); - - gtk_widget_show(dialog); - - return; + gtk_dialog_run(GTK_DIALOG(dialog)); + gtk_widget_destroy(dialog); } } @@ -1298,8 +1294,12 @@ static int initialize_join_state(struct join_state *state, if (status) { return status; } - state->name_buffer_initial = (char *)buffer; + state->name_buffer_initial = strdup(buffer); + if (!state->name_buffer_initial) { + return -1; + } state->name_type_initial = type; + NetApiBufferFree((void *)buffer); } { @@ -1317,6 +1317,7 @@ static int initialize_join_state(struct join_state *state, if (!state->comment) { return -1; } + NetApiBufferFree(buffer); } #if 0 { diff --git a/source3/lib/netapi/examples/netdomjoin/netdomjoin.c b/source3/lib/netapi/examples/netdomjoin/netdomjoin.c index 634d265597..a0ac0b1e56 100644 --- a/source3/lib/netapi/examples/netdomjoin/netdomjoin.c +++ b/source3/lib/netapi/examples/netdomjoin/netdomjoin.c @@ -104,7 +104,12 @@ int main(int argc, char **argv) password, join_flags); if (status != 0) { - printf("Join failed with: %s\n", libnetapi_errstr(ctx, status)); + const char *errstr = NULL; + errstr = libnetapi_get_error_string(ctx); + if (!errstr) { + errstr = libnetapi_errstr(ctx, status); + } + printf("Join failed with: %s\n", errstr); } else { printf("Successfully joined\n"); } diff --git a/source3/lib/netapi/joindomain.c b/source3/lib/netapi/joindomain.c index c7849c952f..e4fb63eebb 100644 --- a/source3/lib/netapi/joindomain.c +++ b/source3/lib/netapi/joindomain.c @@ -33,13 +33,13 @@ static WERROR NetJoinDomainLocal(struct libnetapi_ctx *mem_ctx, struct libnet_JoinCtx *r = NULL; WERROR werr; - werr = libnet_init_JoinCtx(mem_ctx, &r); - W_ERROR_NOT_OK_RETURN(werr); - if (!domain_name) { return WERR_INVALID_PARAM; } + werr = libnet_init_JoinCtx(mem_ctx, &r); + W_ERROR_NOT_OK_RETURN(werr); + r->in.domain_name = talloc_strdup(mem_ctx, domain_name); W_ERROR_HAVE_NO_MEMORY(r->in.domain_name); @@ -77,7 +77,13 @@ static WERROR NetJoinDomainLocal(struct libnetapi_ctx *mem_ctx, r->in.join_flags = join_flags; r->in.modify_config = true; - return libnet_Join(mem_ctx, r); + werr = libnet_Join(mem_ctx, r); + if (!W_ERROR_IS_OK(werr) && r->out.error_string) { + libnetapi_set_error_string(mem_ctx, r->out.error_string); + } + TALLOC_FREE(r); + + return werr; } static WERROR NetJoinDomainRemote(struct libnetapi_ctx *ctx, @@ -431,9 +437,9 @@ static WERROR NetGetJoinInformationLocal(struct libnetapi_ctx *ctx, uint16_t *name_type) { if ((lp_security() == SEC_ADS) && lp_realm()) { - *name_buffer = SMB_STRDUP(lp_realm()); + *name_buffer = talloc_strdup(ctx, lp_realm()); } else { - *name_buffer = SMB_STRDUP(lp_workgroup()); + *name_buffer = talloc_strdup(ctx, lp_workgroup()); } if (!*name_buffer) { return WERR_NOMEM; diff --git a/source3/lib/netapi/netapi.c b/source3/lib/netapi/netapi.c index 032798d0f9..d4cb3a9fe2 100644 --- a/source3/lib/netapi/netapi.c +++ b/source3/lib/netapi/netapi.c @@ -1,7 +1,7 @@ /* * Unix SMB/CIFS implementation. * NetApi Support - * Copyright (C) Guenther Deschner 2007 + * Copyright (C) Guenther Deschner 2007-2008 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -26,15 +26,22 @@ struct libnetapi_ctx *stat_ctx = NULL; TALLOC_CTX *frame = NULL; static bool libnetapi_initialized = false; +/**************************************************************** +****************************************************************/ + NET_API_STATUS libnetapi_init(struct libnetapi_ctx **context) { struct libnetapi_ctx *ctx = NULL; + char *krb5_cc_env = NULL; if (stat_ctx && libnetapi_initialized) { *context = stat_ctx; - return W_ERROR_V(WERR_OK); + return NET_API_STATUS_SUCCESS; } +#ifdef DEVELOPER + talloc_enable_leak_report(); +#endif frame = talloc_stackframe(); ctx = talloc_zero(frame, struct libnetapi_ctx); @@ -65,57 +72,90 @@ NET_API_STATUS libnetapi_init(struct libnetapi_ctx **context) BlockSignals(True, SIGPIPE); + krb5_cc_env = getenv(KRB5_ENV_CCNAME); + if (!krb5_cc_env || (strlen(krb5_cc_env) == 0)) { + ctx->krb5_cc_env = talloc_strdup(frame, "MEMORY:libnetapi"); + setenv(KRB5_ENV_CCNAME, ctx->krb5_cc_env, 1); + } + libnetapi_initialized = true; *context = stat_ctx = ctx; - return W_ERROR_V(WERR_OK); + return NET_API_STATUS_SUCCESS; } +/**************************************************************** +****************************************************************/ + NET_API_STATUS libnetapi_getctx(struct libnetapi_ctx **ctx) { if (stat_ctx) { *ctx = stat_ctx; - return W_ERROR_V(WERR_OK); + return NET_API_STATUS_SUCCESS; } return libnetapi_init(ctx); } +/**************************************************************** +****************************************************************/ + NET_API_STATUS libnetapi_free(struct libnetapi_ctx *ctx) { + + if (ctx->krb5_cc_env) { + char *env = getenv(KRB5_ENV_CCNAME); + if (env && (strequal(ctx->krb5_cc_env, env))) { + unsetenv(KRB5_ENV_CCNAME); + } + } + gfree_names(); gfree_loadparm(); gfree_case_tables(); gfree_charcnv(); gfree_interfaces(); + gencache_shutdown(); + secrets_shutdown(); + regdb_close(); + TALLOC_FREE(ctx); TALLOC_FREE(frame); gfree_debugsyms(); - return W_ERROR_V(WERR_OK); + return NET_API_STATUS_SUCCESS; } +/**************************************************************** +****************************************************************/ + NET_API_STATUS libnetapi_set_debuglevel(struct libnetapi_ctx *ctx, const char *debuglevel) { AllowDebugChange = true; - ctx->debuglevel = debuglevel; + ctx->debuglevel = talloc_strdup(ctx, debuglevel); if (!debug_parse_levels(debuglevel)) { return W_ERROR_V(WERR_GENERAL_FAILURE); } - return W_ERROR_V(WERR_OK); + return NET_API_STATUS_SUCCESS; } +/**************************************************************** +****************************************************************/ + NET_API_STATUS libnetapi_get_debuglevel(struct libnetapi_ctx *ctx, - const char **debuglevel) + char **debuglevel) { *debuglevel = ctx->debuglevel; - return W_ERROR_V(WERR_OK); + return NET_API_STATUS_SUCCESS; } +/**************************************************************** +****************************************************************/ + NET_API_STATUS libnetapi_set_username(struct libnetapi_ctx *ctx, const char *username) { @@ -124,7 +164,7 @@ NET_API_STATUS libnetapi_set_username(struct libnetapi_ctx *ctx, if (!ctx->username) { return W_ERROR_V(WERR_NOMEM); } - return W_ERROR_V(WERR_OK); + return NET_API_STATUS_SUCCESS; } NET_API_STATUS libnetapi_set_password(struct libnetapi_ctx *ctx, @@ -135,7 +175,7 @@ NET_API_STATUS libnetapi_set_password(struct libnetapi_ctx *ctx, if (!ctx->password) { return W_ERROR_V(WERR_NOMEM); } - return W_ERROR_V(WERR_OK); + return NET_API_STATUS_SUCCESS; } NET_API_STATUS libnetapi_set_workgroup(struct libnetapi_ctx *ctx, @@ -146,9 +186,12 @@ NET_API_STATUS libnetapi_set_workgroup(struct libnetapi_ctx *ctx, if (!ctx->workgroup) { return W_ERROR_V(WERR_NOMEM); } - return W_ERROR_V(WERR_OK); + return NET_API_STATUS_SUCCESS; } +/**************************************************************** +****************************************************************/ + const char *libnetapi_errstr(struct libnetapi_ctx *ctx, NET_API_STATUS status) { @@ -158,3 +201,40 @@ const char *libnetapi_errstr(struct libnetapi_ctx *ctx, return get_friendly_werror_msg(W_ERROR(status)); } + +/**************************************************************** +****************************************************************/ + +NET_API_STATUS libnetapi_set_error_string(struct libnetapi_ctx *ctx, + const char *error_string) +{ + TALLOC_FREE(ctx->error_string); + ctx->error_string = talloc_strdup(ctx, error_string); + if (!ctx->error_string) { + return W_ERROR_V(WERR_NOMEM); + } + return NET_API_STATUS_SUCCESS; + +} + +/**************************************************************** +****************************************************************/ + +const char *libnetapi_get_error_string(struct libnetapi_ctx *ctx) +{ + return ctx->error_string; +} + +/**************************************************************** +****************************************************************/ + +NET_API_STATUS NetApiBufferFree(void *buffer) +{ + if (!buffer) { + return W_ERROR_V(WERR_INSUFFICIENT_BUFFER); + } + + talloc_free(buffer); + + return NET_API_STATUS_SUCCESS; +} diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h index 0dd6d95ceb..4a40b32fc9 100644 --- a/source3/lib/netapi/netapi.h +++ b/source3/lib/netapi/netapi.h @@ -1,7 +1,7 @@ /* * Unix SMB/CIFS implementation. * NetApi Support - * Copyright (C) Guenther Deschner 2007 + * Copyright (C) Guenther Deschner 2007-2008 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -21,23 +21,42 @@ #define __LIB_NETAPI_H__ #define NET_API_STATUS uint32_t +#define NET_API_STATUS_SUCCESS 0 + +/**************************************************************** +****************************************************************/ struct libnetapi_ctx { - const char *debuglevel; + char *debuglevel; + char *error_string; char *username; char *workgroup; char *password; + char *krb5_cc_env; }; +/**************************************************************** +****************************************************************/ + NET_API_STATUS libnetapi_init(struct libnetapi_ctx **ctx); NET_API_STATUS libnetapi_getctx(struct libnetapi_ctx **ctx); NET_API_STATUS libnetapi_free(struct libnetapi_ctx *ctx); NET_API_STATUS libnetapi_set_debuglevel(struct libnetapi_ctx *ctx, const char *debuglevel); -NET_API_STATUS libnetapi_get_debuglevel(struct libnetapi_ctx *ctx, const char **debuglevel); +NET_API_STATUS libnetapi_get_debuglevel(struct libnetapi_ctx *ctx, char **debuglevel); NET_API_STATUS libnetapi_set_username(struct libnetapi_ctx *ctx, const char *username); NET_API_STATUS libnetapi_set_password(struct libnetapi_ctx *ctx, const char *password); NET_API_STATUS libnetapi_set_workgroup(struct libnetapi_ctx *ctx, const char *workgroup); const char *libnetapi_errstr(struct libnetapi_ctx *ctx, NET_API_STATUS status); +NET_API_STATUS libnetapi_set_error_string(struct libnetapi_ctx *ctx, const char *error_string); +const char *libnetapi_get_error_string(struct libnetapi_ctx *ctx); + +/**************************************************************** +****************************************************************/ + +NET_API_STATUS NetApiBufferFree(void *buffer); + +/**************************************************************** +****************************************************************/ /* wkssvc */ NET_API_STATUS NetJoinDomain(const char *server, |