/*
* Unix SMB/CIFS implementation.
* NetApi Join 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
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);
uint32_t flags = DS_DIRECTORY_SERVICE_REQUIRED |
DS_WRITABLE_REQUIRED |
DS_RETURN_DNS_NAME;
- status = DsGetDcName(mem_ctx, NULL, domain_name,
+ status = dsgetdcname(mem_ctx, NULL, domain_name,
NULL, NULL, flags, &info);
if (!NT_STATUS_IS_OK(status)) {
return ntstatus_to_werror(status);
}
- r->in.server_name = talloc_strdup(mem_ctx, info->domain_controller_name);
- W_ERROR_HAVE_NO_MEMORY(r->in.server_name);
+ r->in.dc_name = talloc_strdup(mem_ctx,
+ info->domain_controller_name);
+ W_ERROR_HAVE_NO_MEMORY(r->in.dc_name);
}
if (account_ou) {
}
if (password) {
- r->in.password = talloc_strdup(mem_ctx, password);
- W_ERROR_HAVE_NO_MEMORY(r->in.password);
+ r->in.admin_password = talloc_strdup(mem_ctx, password);
+ W_ERROR_HAVE_NO_MEMORY(r->in.admin_password);
}
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,
{
struct cli_state *cli = NULL;
struct rpc_pipe_client *pipe_cli = NULL;
- struct wkssvc_PasswordBuffer encrypted_password;
+ struct wkssvc_PasswordBuffer *encrypted_password = NULL;
NTSTATUS status;
WERROR werr;
unsigned int old_timeout = 0;
- ZERO_STRUCT(encrypted_password);
-
status = cli_full_connection(&cli, NULL, server_name,
NULL, 0,
"IPC$", "IPC",
goto done;
}
- old_timeout = cli_set_timeout(cli, 60000);
-
pipe_cli = cli_rpc_pipe_open_noauth(cli, PI_WKSSVC,
&status);
if (!pipe_cli) {
werr = ntstatus_to_werror(status);
goto done;
- };
+ }
if (password) {
encode_wkssvc_join_password_buffer(ctx,
status = rpccli_wkssvc_NetrJoinDomain2(pipe_cli, ctx,
server_name, domain_name,
account_ou, Account,
- &encrypted_password,
+ encrypted_password,
join_flags, &werr);
if (!NT_STATUS_IS_OK(status)) {
werr = ntstatus_to_werror(status);
W_ERROR_NOT_OK_RETURN(werr);
if (server_name) {
- r->in.server_name = talloc_strdup(mem_ctx, server_name);
- W_ERROR_HAVE_NO_MEMORY(r->in.server_name);
+ r->in.dc_name = talloc_strdup(mem_ctx, server_name);
+ W_ERROR_HAVE_NO_MEMORY(r->in.dc_name);
} else {
NTSTATUS status;
struct DS_DOMAIN_CONTROLLER_INFO *info = NULL;
uint32_t flags = DS_DIRECTORY_SERVICE_REQUIRED |
DS_WRITABLE_REQUIRED |
- DS_IS_FLAT_NAME |
DS_RETURN_DNS_NAME;
if (lp_realm()) {
domain = lp_realm();
} else {
domain = lp_workgroup();
}
- status = DsGetDcName(mem_ctx, NULL, domain,
+ status = dsgetdcname(mem_ctx, NULL, domain,
NULL, NULL, flags, &info);
if (!NT_STATUS_IS_OK(status)) {
return ntstatus_to_werror(status);
}
- r->in.server_name = talloc_strdup(mem_ctx, info->domain_controller_name);
- W_ERROR_HAVE_NO_MEMORY(r->in.server_name);
+ r->in.dc_name = talloc_strdup(mem_ctx,
+ info->domain_controller_name);
+ W_ERROR_HAVE_NO_MEMORY(r->in.dc_name);
}
if (account) {
}
if (password) {
- r->in.password = talloc_strdup(mem_ctx, password);
- W_ERROR_HAVE_NO_MEMORY(r->in.password);
+ r->in.admin_password = talloc_strdup(mem_ctx, password);
+ W_ERROR_HAVE_NO_MEMORY(r->in.admin_password);
}
r->in.unjoin_flags = unjoin_flags;
{
struct cli_state *cli = NULL;
struct rpc_pipe_client *pipe_cli = NULL;
- struct wkssvc_PasswordBuffer encrypted_password;
+ struct wkssvc_PasswordBuffer *encrypted_password = NULL;
NTSTATUS status;
WERROR werr;
unsigned int old_timeout = 0;
- ZERO_STRUCT(encrypted_password);
-
status = cli_full_connection(&cli, NULL, server_name,
NULL, 0,
"IPC$", "IPC",
goto done;
}
- old_timeout = cli_set_timeout(cli, 60000);
-
pipe_cli = cli_rpc_pipe_open_noauth(cli, PI_WKSSVC,
&status);
if (!pipe_cli) {
werr = ntstatus_to_werror(status);
goto done;
- };
+ }
if (password) {
encode_wkssvc_join_password_buffer(ctx,
status = rpccli_wkssvc_NetrUnjoinDomain2(pipe_cli, ctx,
server_name,
account,
- &encrypted_password,
+ encrypted_password,
unjoin_flags,
&werr);
if (!NT_STATUS_IS_OK(status)) {
if (!pipe_cli) {
werr = ntstatus_to_werror(status);
goto done;
- };
+ }
status = rpccli_wkssvc_NetrGetJoinInformation(pipe_cli, ctx,
server_name,
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;
return WERR_OK;
}
-WERROR libnetapi_NetGetJoinInformation(struct libnetapi_ctx *ctx,
- const char *server_name,
- const char **name_buffer,
- uint16_t *name_type)
+static WERROR libnetapi_NetGetJoinInformation(struct libnetapi_ctx *ctx,
+ const char *server_name,
+ const char **name_buffer,
+ uint16_t *name_type)
{
if (!server_name || is_myname_or_ipaddr(server_name)) {
return NetGetJoinInformationLocal(ctx,