From a51e682a21b42cc518e9f3fdbcfa86a9a881ead0 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 30 Nov 2007 18:49:21 +0100 Subject: Add NetJoinDomain call. Guenther (This used to be commit 08a5a036ba97d1f4830d73e95b8369aa9e6683e8) --- source3/lib/netapi/joindomain.c | 84 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 source3/lib/netapi/joindomain.c (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/joindomain.c b/source3/lib/netapi/joindomain.c new file mode 100644 index 0000000000..fe05297ee1 --- /dev/null +++ b/source3/lib/netapi/joindomain.c @@ -0,0 +1,84 @@ +/* + * Unix SMB/CIFS implementation. + * NetApi Join Support + * Copyright (C) Guenther Deschner 2007 + * + * 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include "includes.h" +#include "utils/net.h" + +WERROR NetJoinDomain(const char *server_name, + const char *domain_name, + const char *account_ou, + const char *Account, + const char *password, + uint32_t join_flags) +{ + TALLOC_CTX *mem_ctx = NULL; + struct cli_state *cli = NULL; + struct rpc_pipe_client *pipe_cli = NULL; + struct wkssvc_PasswordBuffer encrypted_password; + NTSTATUS status; + WERROR werr; + + mem_ctx = talloc_init("NetJoinDomain"); + if (!mem_ctx) { + werr = WERR_NOMEM; + goto done; + } + + if (!server_name || is_myname_or_ipaddr(server_name)) { + werr = WERR_NOT_SUPPORTED; + goto done; + } + + status = net_make_ipc_connection_ex(domain_name, + server_name, + NULL, 0, &cli); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + pipe_cli = cli_rpc_pipe_open_noauth(cli, PI_WKSSVC, + &status); + if (!pipe_cli) { + werr = ntstatus_to_werror(status); + goto done; + }; + + encode_wkssvc_join_password_buffer(mem_ctx, + password, + &cli->user_session_key, + &encrypted_password); + + status = rpccli_wkssvc_NetrJoinDomain2(pipe_cli, mem_ctx, + server_name, domain_name, + account_ou, Account, + &encrypted_password, + join_flags); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + } + + werr = WERR_OK; + + done: + cli_shutdown(cli); + TALLOC_FREE(mem_ctx); + + return werr; +} -- cgit From 5ee27320ce9a662bc8c4f8e99ebbd88c0b3b6a47 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 30 Nov 2007 19:52:27 +0100 Subject: domain_name is a ref pointer. Guenther (This used to be commit b350e482b9b211caf08c22c7528b51e47b4a5cce) --- source3/lib/netapi/joindomain.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/joindomain.c b/source3/lib/netapi/joindomain.c index fe05297ee1..bf2f8fce7e 100644 --- a/source3/lib/netapi/joindomain.c +++ b/source3/lib/netapi/joindomain.c @@ -45,6 +45,11 @@ WERROR NetJoinDomain(const char *server_name, goto done; } + if (!domain_name) { + werr = WERR_INVALID_PARAM; + goto done; + } + status = net_make_ipc_connection_ex(domain_name, server_name, NULL, 0, &cli); -- cgit From 1484b1d17471e33f6687e3fa3635b07a452edf03 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 30 Nov 2007 19:55:40 +0100 Subject: Give NetJoinDomain() enough time to finish. Guenther (This used to be commit 7f021b3cb7845c6eb142668f66599886cd92182f) --- source3/lib/netapi/joindomain.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/joindomain.c b/source3/lib/netapi/joindomain.c index bf2f8fce7e..7c71276de6 100644 --- a/source3/lib/netapi/joindomain.c +++ b/source3/lib/netapi/joindomain.c @@ -33,6 +33,7 @@ WERROR NetJoinDomain(const char *server_name, struct wkssvc_PasswordBuffer encrypted_password; NTSTATUS status; WERROR werr; + unsigned int old_timeout; mem_ctx = talloc_init("NetJoinDomain"); if (!mem_ctx) { @@ -58,6 +59,8 @@ WERROR NetJoinDomain(const char *server_name, goto done; } + old_timeout = cli_set_timeout(cli, 60000); + pipe_cli = cli_rpc_pipe_open_noauth(cli, PI_WKSSVC, &status); if (!pipe_cli) { @@ -70,6 +73,8 @@ WERROR NetJoinDomain(const char *server_name, &cli->user_session_key, &encrypted_password); + old_timeout = cli_set_timeout(cli, 60000); + status = rpccli_wkssvc_NetrJoinDomain2(pipe_cli, mem_ctx, server_name, domain_name, account_ou, Account, @@ -82,6 +87,7 @@ WERROR NetJoinDomain(const char *server_name, werr = WERR_OK; done: + cli_set_timeout(cli, old_timeout); cli_shutdown(cli); TALLOC_FREE(mem_ctx); -- cgit From ac512a5bb2113aed1d41ef5479a75b8e05918876 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 30 Nov 2007 19:56:41 +0100 Subject: Robustness-fixes for NetJoinDomain(). Guenther (This used to be commit 2d5236cc37fe015ce9098a0ebe99cdc0ca3537ae) --- source3/lib/netapi/joindomain.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/joindomain.c b/source3/lib/netapi/joindomain.c index 7c71276de6..29766e5994 100644 --- a/source3/lib/netapi/joindomain.c +++ b/source3/lib/netapi/joindomain.c @@ -35,6 +35,8 @@ WERROR NetJoinDomain(const char *server_name, WERROR werr; unsigned int old_timeout; + ZERO_STRUCT(encrypted_password); + mem_ctx = talloc_init("NetJoinDomain"); if (!mem_ctx) { werr = WERR_NOMEM; @@ -68,10 +70,12 @@ WERROR NetJoinDomain(const char *server_name, goto done; }; - encode_wkssvc_join_password_buffer(mem_ctx, - password, - &cli->user_session_key, - &encrypted_password); + if (password) { + encode_wkssvc_join_password_buffer(mem_ctx, + password, + &cli->user_session_key, + &encrypted_password); + } old_timeout = cli_set_timeout(cli, 60000); @@ -82,13 +86,16 @@ WERROR NetJoinDomain(const char *server_name, join_flags); if (!NT_STATUS_IS_OK(status)) { werr = ntstatus_to_werror(status); + goto done; } werr = WERR_OK; done: - cli_set_timeout(cli, old_timeout); - cli_shutdown(cli); + if (cli) { + cli_set_timeout(cli, old_timeout); + cli_shutdown(cli); + } TALLOC_FREE(mem_ctx); return werr; -- cgit From 9fdb8b82c966cf59a26008f26d070ffb7683b0c4 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 30 Nov 2007 19:57:08 +0100 Subject: Add NetUnjoinDomain(). Guenther (This used to be commit fd9d73ad44b0f0b3656a50a663b60aa26e7f7376) --- source3/lib/netapi/joindomain.c | 74 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/joindomain.c b/source3/lib/netapi/joindomain.c index 29766e5994..66f0137cad 100644 --- a/source3/lib/netapi/joindomain.c +++ b/source3/lib/netapi/joindomain.c @@ -100,3 +100,77 @@ WERROR NetJoinDomain(const char *server_name, return werr; } + +WERROR NetUnjoinDomain(const char *server_name, + const char *account, + const char *password, + uint32_t unjoin_flags) +{ + TALLOC_CTX *mem_ctx = NULL; + struct cli_state *cli = NULL; + struct rpc_pipe_client *pipe_cli = NULL; + struct wkssvc_PasswordBuffer encrypted_password; + NTSTATUS status; + WERROR werr; + unsigned int old_timeout; + + ZERO_STRUCT(encrypted_password); + + mem_ctx = talloc_init("NetUnjoinDomain"); + if (!mem_ctx) { + werr = WERR_NOMEM; + goto done; + } + + if (!server_name || is_myname_or_ipaddr(server_name)) { + werr = WERR_NOT_SUPPORTED; + goto done; + } + + status = net_make_ipc_connection_ex(NULL, + server_name, + NULL, 0, &cli); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + 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(mem_ctx, + password, + &cli->user_session_key, + &encrypted_password); + } + + old_timeout = cli_set_timeout(cli, 60000); + + status = rpccli_wkssvc_NetrUnjoinDomain2(pipe_cli, mem_ctx, + server_name, + account, + &encrypted_password, + unjoin_flags); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + werr = WERR_OK; + + done: + if (cli) { + cli_set_timeout(cli, old_timeout); + cli_shutdown(cli); + } + TALLOC_FREE(mem_ctx); + + return werr; +} -- cgit From 9433010f357428ce48a78f1f99a3806f40eac9d2 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 30 Nov 2007 20:18:46 +0100 Subject: Add header file for NetJoinDomain() and friends. Guenther (This used to be commit 7cea527e8712cde34378ae8b32aad1e4aab0c17b) --- source3/lib/netapi/joindomain.h | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 source3/lib/netapi/joindomain.h (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/joindomain.h b/source3/lib/netapi/joindomain.h new file mode 100644 index 0000000000..2c71702db7 --- /dev/null +++ b/source3/lib/netapi/joindomain.h @@ -0,0 +1,29 @@ +/* + * Unix SMB/CIFS implementation. + * NetApi Support + * Copyright (C) Guenther Deschner 2007 + * + * 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +WERROR NetJoinDomain(const char *server, + const char *domain, + const char *account_ou, + const char *account, + const char *password, + uint32_t join_options); +WERROR NetUnjoinDomain(const char *server_name, + const char *account, + const char *password, + uint32_t unjoin_flags); -- cgit From cfbbeebbc6d8c6197e277c7edaeec14f4ac3ef93 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 30 Nov 2007 20:33:51 +0100 Subject: Avoid to include net prototypes, just reference user creds. Guenther (This used to be commit 09e01a47164702f67403e61bc478d1cb54f0508e) --- source3/lib/netapi/joindomain.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/joindomain.c b/source3/lib/netapi/joindomain.c index 66f0137cad..e0986ce364 100644 --- a/source3/lib/netapi/joindomain.c +++ b/source3/lib/netapi/joindomain.c @@ -18,7 +18,10 @@ */ #include "includes.h" -#include "utils/net.h" + +extern const char *opt_user_name; +extern const char *opt_workgroup; +extern const char *opt_password; WERROR NetJoinDomain(const char *server_name, const char *domain_name, @@ -53,9 +56,12 @@ WERROR NetJoinDomain(const char *server_name, goto done; } - status = net_make_ipc_connection_ex(domain_name, - server_name, - NULL, 0, &cli); + status = cli_full_connection(&cli, NULL, server_name, + NULL, 0, + "IPC$", "IPC", + opt_user_name, opt_workgroup, + opt_password, 0, Undefined, NULL); + if (!NT_STATUS_IS_OK(status)) { werr = ntstatus_to_werror(status); goto done; @@ -127,9 +133,12 @@ WERROR NetUnjoinDomain(const char *server_name, goto done; } - status = net_make_ipc_connection_ex(NULL, - server_name, - NULL, 0, &cli); + status = cli_full_connection(&cli, NULL, server_name, + NULL, 0, + "IPC$", "IPC", + opt_user_name, opt_workgroup, + opt_password, 0, Undefined, NULL); + if (!NT_STATUS_IS_OK(status)) { werr = ntstatus_to_werror(status); goto done; -- cgit From b1a924a0fb7f9f55c655b1b2b31a9dc66ee0478a Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 1 Dec 2007 11:41:44 +0100 Subject: Fix some bogus uninitialized variable warnings (This used to be commit 48a162b709cc14632fd02c4cd40aa8cfafc53324) --- source3/lib/netapi/joindomain.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/joindomain.c b/source3/lib/netapi/joindomain.c index e0986ce364..f6944e4b1f 100644 --- a/source3/lib/netapi/joindomain.c +++ b/source3/lib/netapi/joindomain.c @@ -36,7 +36,7 @@ WERROR NetJoinDomain(const char *server_name, struct wkssvc_PasswordBuffer encrypted_password; NTSTATUS status; WERROR werr; - unsigned int old_timeout; + unsigned int old_timeout = 0; ZERO_STRUCT(encrypted_password); @@ -118,7 +118,7 @@ WERROR NetUnjoinDomain(const char *server_name, struct wkssvc_PasswordBuffer encrypted_password; NTSTATUS status; WERROR werr; - unsigned int old_timeout; + unsigned int old_timeout = 0; ZERO_STRUCT(encrypted_password); -- cgit From 6b37d8e627a2b983a5801ec533e536dd67e5f0e5 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 3 Dec 2007 18:40:09 +0100 Subject: Fix wkssvc callers. Guenther (This used to be commit b734cd8aab163d794b969c4e1e721e81a8b4d44c) --- source3/lib/netapi/joindomain.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/joindomain.c b/source3/lib/netapi/joindomain.c index f6944e4b1f..210763174e 100644 --- a/source3/lib/netapi/joindomain.c +++ b/source3/lib/netapi/joindomain.c @@ -89,14 +89,12 @@ WERROR NetJoinDomain(const char *server_name, server_name, domain_name, account_ou, Account, &encrypted_password, - join_flags); + join_flags, &werr); if (!NT_STATUS_IS_OK(status)) { werr = ntstatus_to_werror(status); goto done; } - werr = WERR_OK; - done: if (cli) { cli_set_timeout(cli, old_timeout); @@ -166,14 +164,13 @@ WERROR NetUnjoinDomain(const char *server_name, server_name, account, &encrypted_password, - unjoin_flags); + unjoin_flags, + &werr); if (!NT_STATUS_IS_OK(status)) { werr = ntstatus_to_werror(status); goto done; } - werr = WERR_OK; - done: if (cli) { cli_set_timeout(cli, old_timeout); -- cgit From 0cdf5cfdfbb6b412e1d365af4f2daf20087b37f5 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Thu, 20 Dec 2007 20:59:27 +0100 Subject: Fix a missing prototype warning (This used to be commit 93e5de23e7109432f554745b18c6d630a39f9c2b) --- source3/lib/netapi/joindomain.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/joindomain.c b/source3/lib/netapi/joindomain.c index 210763174e..10f7e94835 100644 --- a/source3/lib/netapi/joindomain.c +++ b/source3/lib/netapi/joindomain.c @@ -18,6 +18,7 @@ */ #include "includes.h" +#include "lib/netapi/joindomain.h" extern const char *opt_user_name; extern const char *opt_workgroup; -- cgit From 72ffac399077ad7777f1282c94d9b661e7fa53fb Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 6 Dec 2007 19:04:49 +0100 Subject: Add NetGetJoinInformation(). Guenther (This used to be commit d341d251d6e22e9cc1c4596038fd5fe5c7c6c174) --- source3/lib/netapi/joindomain.c | 53 +++++++++++++++++++++++++++++++++++++++++ source3/lib/netapi/joindomain.h | 3 +++ 2 files changed, 56 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/joindomain.c b/source3/lib/netapi/joindomain.c index 10f7e94835..6da4548f05 100644 --- a/source3/lib/netapi/joindomain.c +++ b/source3/lib/netapi/joindomain.c @@ -181,3 +181,56 @@ WERROR NetUnjoinDomain(const char *server_name, return werr; } + +WERROR NetGetJoinInformation(const char *server_name, + const char **name_buffer, + uint16_t *name_type) +{ + TALLOC_CTX *mem_ctx = NULL; + struct cli_state *cli = NULL; + struct rpc_pipe_client *pipe_cli = NULL; + NTSTATUS status; + WERROR werr; + + mem_ctx = talloc_init("NetGetJoinInformation"); + if (!mem_ctx) { + werr = WERR_NOMEM; + goto done; + } + + status = cli_full_connection(&cli, NULL, server_name, + NULL, 0, + "IPC$", "IPC", + opt_user_name, opt_workgroup, + opt_password, 0, Undefined, NULL); + + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + pipe_cli = cli_rpc_pipe_open_noauth(cli, PI_WKSSVC, + &status); + if (!pipe_cli) { + werr = ntstatus_to_werror(status); + goto done; + }; + + status = rpccli_wkssvc_NetrGetJoinInformation(pipe_cli, mem_ctx, + server_name, + name_buffer, + (enum wkssvc_NetJoinStatus *)name_type, + &werr); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + done: + if (cli) { + cli_shutdown(cli); + } + TALLOC_FREE(mem_ctx); + + return werr; +} diff --git a/source3/lib/netapi/joindomain.h b/source3/lib/netapi/joindomain.h index 2c71702db7..d0badd979d 100644 --- a/source3/lib/netapi/joindomain.h +++ b/source3/lib/netapi/joindomain.h @@ -27,3 +27,6 @@ WERROR NetUnjoinDomain(const char *server_name, const char *account, const char *password, uint32_t unjoin_flags); +WERROR NetGetJoinInformation(const char *server_name, + const char **name_buffer, + uint16_t *name_type); -- cgit From 67aa44e7a230cb3cf35c184692bf5249d6d424cf Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 11 Dec 2007 21:23:40 +0100 Subject: Split NetJoinDomain() into NetJoinDomainRemote() and the unsupported NetJoinDomainLocal(). Guenther (This used to be commit d2f21ce6727ec9e4df67989db07b48470d0790a4) --- source3/lib/netapi/joindomain.c | 96 +++++++++++++++++++++++++++++++---------- 1 file changed, 73 insertions(+), 23 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/joindomain.c b/source3/lib/netapi/joindomain.c index 6da4548f05..1b951d7a5c 100644 --- a/source3/lib/netapi/joindomain.c +++ b/source3/lib/netapi/joindomain.c @@ -24,14 +24,25 @@ extern const char *opt_user_name; extern const char *opt_workgroup; extern const char *opt_password; -WERROR NetJoinDomain(const char *server_name, - const char *domain_name, - const char *account_ou, - const char *Account, - const char *password, - uint32_t join_flags) +static WERROR NetJoinDomainLocal(TALLOC_CTX *mem_ctx, + const char *server_name, + const char *domain_name, + const char *account_ou, + const char *Account, + const char *password, + uint32_t join_flags) +{ + return WERR_NOT_SUPPORTED; +} + +static WERROR NetJoinDomainRemote(TALLOC_CTX *mem_ctx, + const char *server_name, + const char *domain_name, + const char *account_ou, + const char *Account, + const char *password, + uint32_t join_flags) { - TALLOC_CTX *mem_ctx = NULL; struct cli_state *cli = NULL; struct rpc_pipe_client *pipe_cli = NULL; struct wkssvc_PasswordBuffer encrypted_password; @@ -41,22 +52,6 @@ WERROR NetJoinDomain(const char *server_name, ZERO_STRUCT(encrypted_password); - mem_ctx = talloc_init("NetJoinDomain"); - if (!mem_ctx) { - werr = WERR_NOMEM; - goto done; - } - - if (!server_name || is_myname_or_ipaddr(server_name)) { - werr = WERR_NOT_SUPPORTED; - goto done; - } - - if (!domain_name) { - werr = WERR_INVALID_PARAM; - goto done; - } - status = cli_full_connection(&cli, NULL, server_name, NULL, 0, "IPC$", "IPC", @@ -101,6 +96,61 @@ WERROR NetJoinDomain(const char *server_name, cli_set_timeout(cli, old_timeout); cli_shutdown(cli); } + + return werr; +} + +WERROR NetJoinDomain(const char *server_name, + const char *domain_name, + const char *account_ou, + const char *Account, + const char *password, + uint32_t join_flags) +{ + TALLOC_CTX *mem_ctx = NULL; + WERROR werr; + + mem_ctx = talloc_init("NetJoinDomain"); + if (!mem_ctx) { + werr = WERR_NOMEM; + goto done; + } + + if (!domain_name) { + werr = WERR_INVALID_PARAM; + goto done; + } + + if (!server_name || is_myname_or_ipaddr(server_name)) { + + const char *dc = NULL; + + /* FIXME: DsGetDcName */ + if (server_name == NULL) { + dc = domain_name; + } else { + dc = domain_name; + } + + werr = NetJoinDomainLocal(mem_ctx, + dc, + domain_name, + account_ou, + Account, + password, + join_flags); + + goto done; + } + + werr = NetJoinDomainRemote(mem_ctx, + server_name, + domain_name, + account_ou, + Account, + password, + join_flags); +done: TALLOC_FREE(mem_ctx); return werr; -- cgit From 4f6e8dfa51dfef72d13efc4acd3ede37d1f69eac Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 11 Dec 2007 21:32:16 +0100 Subject: Fill in NetJoinDomainLocal(). Guenther (This used to be commit 4896f22bb50ea9ae0c4807ed9b2dd4283c254364) --- source3/lib/netapi/joindomain.c | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/joindomain.c b/source3/lib/netapi/joindomain.c index 1b951d7a5c..96983d43e3 100644 --- a/source3/lib/netapi/joindomain.c +++ b/source3/lib/netapi/joindomain.c @@ -32,7 +32,41 @@ static WERROR NetJoinDomainLocal(TALLOC_CTX *mem_ctx, const char *password, uint32_t join_flags) { - return WERR_NOT_SUPPORTED; + struct libnet_JoinCtx *r = NULL; + WERROR werr; + + werr = libnet_init_JoinCtx(mem_ctx, &r); + W_ERROR_NOT_OK_RETURN(werr); + + if (!server_name || !domain_name) { + return WERR_INVALID_PARAM; + } + + r->in.server_name = talloc_strdup(mem_ctx, server_name); + W_ERROR_HAVE_NO_MEMORY(r->in.server_name); + + r->in.domain_name = talloc_strdup(mem_ctx, domain_name); + W_ERROR_HAVE_NO_MEMORY(r->in.domain_name); + + if (account_ou) { + r->in.account_ou = talloc_strdup(mem_ctx, account_ou); + W_ERROR_HAVE_NO_MEMORY(r->in.account_ou); + } + + if (Account) { + r->in.admin_account = talloc_strdup(mem_ctx, Account); + W_ERROR_HAVE_NO_MEMORY(r->in.admin_account); + } + + if (password) { + r->in.password = talloc_strdup(mem_ctx, password); + W_ERROR_HAVE_NO_MEMORY(r->in.password); + } + + r->in.join_flags = join_flags; + r->in.modify_config = true; + + return libnet_Join(mem_ctx, r); } static WERROR NetJoinDomainRemote(TALLOC_CTX *mem_ctx, -- cgit From 749f699f871831e9ad5b2a57e498a32f959d23c6 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 12 Dec 2007 18:14:54 +0100 Subject: Build fixes for libnetapi. Guenther (This used to be commit 07d33557b95106ac57fdef8c767ab86192930a6d) --- source3/lib/netapi/netapi.c | 76 +++++++++++++++++++++++++++++++++++++++++++++ source3/lib/netapi/netapi.h | 26 ++++++++++++++++ 2 files changed, 102 insertions(+) create mode 100644 source3/lib/netapi/netapi.c create mode 100644 source3/lib/netapi/netapi.h (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi.c b/source3/lib/netapi/netapi.c new file mode 100644 index 0000000000..3da492bbe7 --- /dev/null +++ b/source3/lib/netapi/netapi.c @@ -0,0 +1,76 @@ +/* + * Unix SMB/CIFS implementation. + * NetApi Support + * Copyright (C) Guenther Deschner 2007 + * + * 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include "includes.h" +#include "lib/netapi/netapi.h" + +extern bool AllowDebugChange; + +static bool libnetapi_initialized = false; + +WERROR libnetapi_init(struct libnetapi_ctx **context) +{ + struct libnetapi_ctx *ctx = NULL; + TALLOC_CTX *frame = NULL; + + if (libnetapi_initialized) { + return WERR_OK; + } + + frame = talloc_stackframe(); + + ctx = talloc_zero(frame, struct libnetapi_ctx); + if (!ctx) { + TALLOC_FREE(frame); + return WERR_NOMEM; + } + + DEBUGLEVEL = 0; + DEBUGLEVEL_CLASS[DBGC_ALL] = 0; + dbf = x_stderr; + x_setbuf(x_stderr, NULL); + AllowDebugChange = false; + + load_case_tables(); + + setup_logging("libnetapi", true); + + if (!lp_load(get_dyn_CONFIGFILE(), true, false, false, false)) { + TALLOC_FREE(frame); + return WERR_GENERAL_FAILURE; + } + + init_names(); + load_interfaces(); + reopen_logs(); + + BlockSignals(True, SIGPIPE); + + libnetapi_initialized = true; + + *context = ctx; + + return WERR_OK; +} + +WERROR libnetapi_free(struct libnetapi_ctx *ctx) +{ + TALLOC_FREE(ctx); + return WERR_OK; +} diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h new file mode 100644 index 0000000000..ad9fbe4209 --- /dev/null +++ b/source3/lib/netapi/netapi.h @@ -0,0 +1,26 @@ +/* + * Unix SMB/CIFS implementation. + * NetApi Support + * Copyright (C) Guenther Deschner 2007 + * + * 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +struct libnetapi_ctx { + int debuglevel; +}; + +WERROR libnetapi_init(struct libnetapi_ctx **ctx); + +#include "joindomain.h" -- cgit From 7482a18c83d25b2d00e1086aafb33d9a0ff98309 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 12 Dec 2007 19:00:41 +0100 Subject: More minor libnetapi fixes. Guenther (This used to be commit 9f129c069f9feb357cbe1185058cfe3390609c09) --- source3/lib/netapi/netapi.h | 1 + 1 file changed, 1 insertion(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h index ad9fbe4209..ec629d56d9 100644 --- a/source3/lib/netapi/netapi.h +++ b/source3/lib/netapi/netapi.h @@ -22,5 +22,6 @@ struct libnetapi_ctx { }; WERROR libnetapi_init(struct libnetapi_ctx **ctx); +WERROR libnetapi_free(struct libnetapi_ctx *ctx); #include "joindomain.h" -- cgit From 5b5f75d229978d5b9fe14dca768fd8b68d2ab319 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 13 Dec 2007 16:21:27 +0100 Subject: Fill in local branch of NetGetJoinInformation(). Guenther (This used to be commit 46db8754511f915c296771e08e822ba810f804d5) --- source3/lib/netapi/joindomain.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/joindomain.c b/source3/lib/netapi/joindomain.c index 96983d43e3..bc26c22370 100644 --- a/source3/lib/netapi/joindomain.c +++ b/source3/lib/netapi/joindomain.c @@ -282,6 +282,32 @@ WERROR NetGetJoinInformation(const char *server_name, goto done; } + if (!server_name || is_myname_or_ipaddr(server_name)) { + if ((lp_security() == SEC_ADS) && lp_realm()) { + *name_buffer = SMB_STRDUP(lp_realm()); + } else { + *name_buffer = SMB_STRDUP(lp_workgroup()); + } + if (!*name_buffer) { + werr = WERR_NOMEM; + goto done; + } + switch (lp_server_role()) { + case ROLE_DOMAIN_MEMBER: + case ROLE_DOMAIN_PDC: + case ROLE_DOMAIN_BDC: + *name_type = NetSetupDomainName; + break; + case ROLE_STANDALONE: + default: + *name_type = NetSetupWorkgroupName; + break; + } + + werr = WERR_OK; + goto done; + } + status = cli_full_connection(&cli, NULL, server_name, NULL, 0, "IPC$", "IPC", -- cgit From 41410c86cc698f997dd82a143fd92277060384b0 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 14 Dec 2007 12:22:20 +0100 Subject: Some libnet and netapi build fixes. Guenther (This used to be commit 1d47247283f7bc75291007be3fde72b1d3d95b99) --- source3/lib/netapi/joindomain.h | 5 +++++ source3/lib/netapi/netapi.h | 5 +++++ 2 files changed, 10 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/joindomain.h b/source3/lib/netapi/joindomain.h index d0badd979d..73d2ec3d32 100644 --- a/source3/lib/netapi/joindomain.h +++ b/source3/lib/netapi/joindomain.h @@ -17,6 +17,9 @@ * along with this program; if not, see . */ +#ifndef __LIB_NETAPI_JOINDOMAIN_H__ +#define __LIB_NETAPI_JOINDOMAIN_H__ + WERROR NetJoinDomain(const char *server, const char *domain, const char *account_ou, @@ -30,3 +33,5 @@ WERROR NetUnjoinDomain(const char *server_name, WERROR NetGetJoinInformation(const char *server_name, const char **name_buffer, uint16_t *name_type); + +#endif diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h index ec629d56d9..0810ecb7bc 100644 --- a/source3/lib/netapi/netapi.h +++ b/source3/lib/netapi/netapi.h @@ -17,6 +17,9 @@ * along with this program; if not, see . */ +#ifndef __LIB_NETAPI_H__ +#define __LIB_NETAPI_H__ + struct libnetapi_ctx { int debuglevel; }; @@ -25,3 +28,5 @@ WERROR libnetapi_init(struct libnetapi_ctx **ctx); WERROR libnetapi_free(struct libnetapi_ctx *ctx); #include "joindomain.h" + +#endif -- cgit From 9dc0ac4637fdd05a95099c0a6a857c51ca811453 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 18 Dec 2007 02:15:49 +0100 Subject: Getting rid of external credentials in libnetapi. Guenther (This used to be commit c10481dba01a084b0f9c4265f3408a0ec9a8b646) --- source3/lib/netapi/joindomain.c | 16 ++++++++-------- source3/lib/netapi/netapi.h | 3 +++ 2 files changed, 11 insertions(+), 8 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/joindomain.c b/source3/lib/netapi/joindomain.c index bc26c22370..8287cd046f 100644 --- a/source3/lib/netapi/joindomain.c +++ b/source3/lib/netapi/joindomain.c @@ -20,10 +20,6 @@ #include "includes.h" #include "lib/netapi/joindomain.h" -extern const char *opt_user_name; -extern const char *opt_workgroup; -extern const char *opt_password; - static WERROR NetJoinDomainLocal(TALLOC_CTX *mem_ctx, const char *server_name, const char *domain_name, @@ -219,8 +215,10 @@ WERROR NetUnjoinDomain(const char *server_name, status = cli_full_connection(&cli, NULL, server_name, NULL, 0, "IPC$", "IPC", - opt_user_name, opt_workgroup, - opt_password, 0, Undefined, NULL); + ctx->username, + ctx->workgroup, + ctx->password, + 0, Undefined, NULL); if (!NT_STATUS_IS_OK(status)) { werr = ntstatus_to_werror(status); @@ -311,8 +309,10 @@ WERROR NetGetJoinInformation(const char *server_name, status = cli_full_connection(&cli, NULL, server_name, NULL, 0, "IPC$", "IPC", - opt_user_name, opt_workgroup, - opt_password, 0, Undefined, NULL); + ctx->username, + ctx->workgroup, + ctx->password, + 0, Undefined, NULL); if (!NT_STATUS_IS_OK(status)) { werr = ntstatus_to_werror(status); diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h index 0810ecb7bc..0637570c3e 100644 --- a/source3/lib/netapi/netapi.h +++ b/source3/lib/netapi/netapi.h @@ -22,6 +22,9 @@ struct libnetapi_ctx { int debuglevel; + char *username; + char *workgroup; + char *password; }; WERROR libnetapi_init(struct libnetapi_ctx **ctx); -- cgit From 4dd84b351125cdd95c945d8820ffe078f7325988 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 18 Dec 2007 02:21:38 +0100 Subject: Define NET_API_STATUS to be just a uin32_t. Guenther (This used to be commit a42850926a26a4065a6126affc3754d291a2e178) --- source3/lib/netapi/netapi.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h index 0637570c3e..7946cfb446 100644 --- a/source3/lib/netapi/netapi.h +++ b/source3/lib/netapi/netapi.h @@ -20,6 +20,8 @@ #ifndef __LIB_NETAPI_H__ #define __LIB_NETAPI_H__ +#define NET_API_STATUS uint32_t + struct libnetapi_ctx { int debuglevel; char *username; -- cgit From 3d853b8e7e975a3e1c07a125e775e3a597112912 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 18 Dec 2007 02:29:50 +0100 Subject: Move basic libnetapi functions to NET_API_STATUS. Guenther (This used to be commit 086c55005976b3173e915e465108214876aa5bd6) --- source3/lib/netapi/netapi.c | 14 +++++++------- source3/lib/netapi/netapi.h | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi.c b/source3/lib/netapi/netapi.c index 3da492bbe7..898e62d6a5 100644 --- a/source3/lib/netapi/netapi.c +++ b/source3/lib/netapi/netapi.c @@ -24,13 +24,13 @@ extern bool AllowDebugChange; static bool libnetapi_initialized = false; -WERROR libnetapi_init(struct libnetapi_ctx **context) +NET_API_STATUS libnetapi_init(struct libnetapi_ctx **context) { struct libnetapi_ctx *ctx = NULL; TALLOC_CTX *frame = NULL; if (libnetapi_initialized) { - return WERR_OK; + return W_ERROR_V(WERR_OK); } frame = talloc_stackframe(); @@ -38,7 +38,7 @@ WERROR libnetapi_init(struct libnetapi_ctx **context) ctx = talloc_zero(frame, struct libnetapi_ctx); if (!ctx) { TALLOC_FREE(frame); - return WERR_NOMEM; + return W_ERROR_V(WERR_NOMEM); } DEBUGLEVEL = 0; @@ -53,7 +53,7 @@ WERROR libnetapi_init(struct libnetapi_ctx **context) if (!lp_load(get_dyn_CONFIGFILE(), true, false, false, false)) { TALLOC_FREE(frame); - return WERR_GENERAL_FAILURE; + return W_ERROR_V(WERR_GENERAL_FAILURE); } init_names(); @@ -66,11 +66,11 @@ WERROR libnetapi_init(struct libnetapi_ctx **context) *context = ctx; - return WERR_OK; + return W_ERROR_V(WERR_OK); } -WERROR libnetapi_free(struct libnetapi_ctx *ctx) +NET_API_STATUS libnetapi_free(struct libnetapi_ctx *ctx) { TALLOC_FREE(ctx); - return WERR_OK; + return W_ERROR_V(WERR_OK); } diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h index 7946cfb446..3dfbc0cffb 100644 --- a/source3/lib/netapi/netapi.h +++ b/source3/lib/netapi/netapi.h @@ -29,8 +29,8 @@ struct libnetapi_ctx { char *password; }; -WERROR libnetapi_init(struct libnetapi_ctx **ctx); -WERROR libnetapi_free(struct libnetapi_ctx *ctx); +NET_API_STATUS libnetapi_init(struct libnetapi_ctx **ctx); +NET_API_STATUS libnetapi_free(struct libnetapi_ctx *ctx); #include "joindomain.h" -- cgit From c9b44e0fc3750afb6e001baceffad8fa2f33ac4e Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 18 Dec 2007 02:34:07 +0100 Subject: Add basic credential functions for libnetapi. Guenther (This used to be commit 7c38f706b5dc17f15708ac932c84d863a0cc713e) --- source3/lib/netapi/netapi.c | 33 +++++++++++++++++++++++++++++++++ source3/lib/netapi/netapi.h | 3 +++ 2 files changed, 36 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi.c b/source3/lib/netapi/netapi.c index 898e62d6a5..38b44c769d 100644 --- a/source3/lib/netapi/netapi.c +++ b/source3/lib/netapi/netapi.c @@ -74,3 +74,36 @@ NET_API_STATUS libnetapi_free(struct libnetapi_ctx *ctx) TALLOC_FREE(ctx); return W_ERROR_V(WERR_OK); } + +NET_API_STATUS libnetapi_set_username(struct libnetapi_ctx *ctx, + const char *username) +{ + TALLOC_FREE(ctx->username); + ctx->username = talloc_strdup(ctx, username); + if (!ctx->username) { + return W_ERROR_V(WERR_NOMEM); + } + return W_ERROR_V(WERR_OK); +} + +NET_API_STATUS libnetapi_set_password(struct libnetapi_ctx *ctx, + const char *password) +{ + TALLOC_FREE(ctx->password); + ctx->password = talloc_strdup(ctx, password); + if (!ctx->password) { + return W_ERROR_V(WERR_NOMEM); + } + return W_ERROR_V(WERR_OK); +} + +NET_API_STATUS libnetapi_set_workgroup(struct libnetapi_ctx *ctx, + const char *workgroup) +{ + TALLOC_FREE(ctx->workgroup); + ctx->workgroup = talloc_strdup(ctx, workgroup); + if (!ctx->workgroup) { + return W_ERROR_V(WERR_NOMEM); + } + return W_ERROR_V(WERR_OK); +} diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h index 3dfbc0cffb..d75299601f 100644 --- a/source3/lib/netapi/netapi.h +++ b/source3/lib/netapi/netapi.h @@ -31,6 +31,9 @@ struct libnetapi_ctx { NET_API_STATUS libnetapi_init(struct libnetapi_ctx **ctx); NET_API_STATUS libnetapi_free(struct libnetapi_ctx *ctx); +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); #include "joindomain.h" -- cgit From d14ee1dc08c5c765b07bd472e47e34152db2f9d3 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 18 Dec 2007 02:43:22 +0100 Subject: Use full string based debug_parse_levels in libnetapi. Guenther (This used to be commit 78d8f0e41aa3db0060596a7b345c2f04261986e0) --- source3/lib/netapi/netapi.c | 25 ++++++++++++++++++++++--- source3/lib/netapi/netapi.h | 4 +++- 2 files changed, 25 insertions(+), 4 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi.c b/source3/lib/netapi/netapi.c index 38b44c769d..454d766ae9 100644 --- a/source3/lib/netapi/netapi.c +++ b/source3/lib/netapi/netapi.c @@ -42,20 +42,21 @@ NET_API_STATUS libnetapi_init(struct libnetapi_ctx **context) } DEBUGLEVEL = 0; - DEBUGLEVEL_CLASS[DBGC_ALL] = 0; + setup_logging("libnetapi", true); + dbf = x_stderr; x_setbuf(x_stderr, NULL); AllowDebugChange = false; load_case_tables(); - setup_logging("libnetapi", true); - if (!lp_load(get_dyn_CONFIGFILE(), true, false, false, false)) { TALLOC_FREE(frame); return W_ERROR_V(WERR_GENERAL_FAILURE); } + AllowDebugChange = true; + init_names(); load_interfaces(); reopen_logs(); @@ -75,6 +76,24 @@ NET_API_STATUS libnetapi_free(struct libnetapi_ctx *ctx) return W_ERROR_V(WERR_OK); } +NET_API_STATUS libnetapi_set_debuglevel(struct libnetapi_ctx *ctx, + const char *debuglevel) +{ + AllowDebugChange = true; + ctx->debuglevel = debuglevel; + if (!debug_parse_levels(debuglevel)) { + return W_ERROR_V(WERR_GENERAL_FAILURE); + } + return W_ERROR_V(WERR_OK); +} + +NET_API_STATUS libnetapi_get_debuglevel(struct libnetapi_ctx *ctx, + const char **debuglevel) +{ + *debuglevel = ctx->debuglevel; + return W_ERROR_V(WERR_OK); +} + NET_API_STATUS libnetapi_set_username(struct libnetapi_ctx *ctx, const char *username) { diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h index d75299601f..278922224d 100644 --- a/source3/lib/netapi/netapi.h +++ b/source3/lib/netapi/netapi.h @@ -23,7 +23,7 @@ #define NET_API_STATUS uint32_t struct libnetapi_ctx { - int debuglevel; + const char *debuglevel; char *username; char *workgroup; char *password; @@ -31,6 +31,8 @@ struct libnetapi_ctx { NET_API_STATUS libnetapi_init(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_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); -- cgit From fb2c13fe191212f5e782b398fa4dffa42bfba129 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 18 Dec 2007 02:47:01 +0100 Subject: Add static libnetapi_ctx. Guenther (This used to be commit 97449ea341539a709953a57869570cf13be0f44e) --- source3/lib/netapi/netapi.c | 28 +++++++++++++++++++++++++--- source3/lib/netapi/netapi.h | 1 + 2 files changed, 26 insertions(+), 3 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi.c b/source3/lib/netapi/netapi.c index 454d766ae9..853ac55f8a 100644 --- a/source3/lib/netapi/netapi.c +++ b/source3/lib/netapi/netapi.c @@ -22,14 +22,16 @@ extern bool AllowDebugChange; +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; - TALLOC_CTX *frame = NULL; - if (libnetapi_initialized) { + if (stat_ctx && libnetapi_initialized) { + *context = stat_ctx; return W_ERROR_V(WERR_OK); } @@ -65,14 +67,34 @@ NET_API_STATUS libnetapi_init(struct libnetapi_ctx **context) libnetapi_initialized = true; - *context = ctx; + *context = stat_ctx = ctx; return W_ERROR_V(WERR_OK); } +NET_API_STATUS libnetapi_getctx(struct libnetapi_ctx **ctx) +{ + if (stat_ctx) { + *ctx = stat_ctx; + return W_ERROR_V(WERR_OK); + } + + return libnetapi_init(ctx); +} + NET_API_STATUS libnetapi_free(struct libnetapi_ctx *ctx) { + gfree_names(); + gfree_loadparm(); + gfree_case_tables(); + gfree_charcnv(); + gfree_interfaces(); + TALLOC_FREE(ctx); + TALLOC_FREE(frame); + + gfree_debugsyms(); + return W_ERROR_V(WERR_OK); } diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h index 278922224d..0b25c93d5b 100644 --- a/source3/lib/netapi/netapi.h +++ b/source3/lib/netapi/netapi.h @@ -30,6 +30,7 @@ struct libnetapi_ctx { }; 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); -- cgit From 62b3fd209d65caba36595dfbcde83fd74f4047b7 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 18 Dec 2007 02:52:34 +0100 Subject: Missed on instance of external creds. Guenther (This used to be commit 65d50f518766ab0a8115c2599d190e642eb00754) --- source3/lib/netapi/joindomain.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/joindomain.c b/source3/lib/netapi/joindomain.c index 8287cd046f..67e53d4391 100644 --- a/source3/lib/netapi/joindomain.c +++ b/source3/lib/netapi/joindomain.c @@ -85,8 +85,10 @@ static WERROR NetJoinDomainRemote(TALLOC_CTX *mem_ctx, status = cli_full_connection(&cli, NULL, server_name, NULL, 0, "IPC$", "IPC", - opt_user_name, opt_workgroup, - opt_password, 0, Undefined, NULL); + ctx->username, + ctx->workgroup, + ctx->password, + 0, Undefined, NULL); if (!NT_STATUS_IS_OK(status)) { werr = ntstatus_to_werror(status); -- cgit From dab660b9dc42b9e5817e59de4c97009796548b92 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 18 Dec 2007 02:54:18 +0100 Subject: Move NetJoinDomain and friends to NET_API_STATUS and the static libnetapi_ctx. Guenther (This used to be commit e640c3a4a7695613e9e619516befbaf3d44ecb10) --- source3/lib/netapi/joindomain.c | 126 +++++++++++++++++++++++++++++++++------- source3/lib/netapi/joindomain.h | 26 ++++----- 2 files changed, 119 insertions(+), 33 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/joindomain.c b/source3/lib/netapi/joindomain.c index 67e53d4391..a0d3319998 100644 --- a/source3/lib/netapi/joindomain.c +++ b/source3/lib/netapi/joindomain.c @@ -18,9 +18,11 @@ */ #include "includes.h" -#include "lib/netapi/joindomain.h" -static WERROR NetJoinDomainLocal(TALLOC_CTX *mem_ctx, +#include "lib/netapi/netapi.h" +#include "libnet/libnet.h" + +static WERROR NetJoinDomainLocal(struct libnetapi_ctx *mem_ctx, const char *server_name, const char *domain_name, const char *account_ou, @@ -65,7 +67,7 @@ static WERROR NetJoinDomainLocal(TALLOC_CTX *mem_ctx, return libnet_Join(mem_ctx, r); } -static WERROR NetJoinDomainRemote(TALLOC_CTX *mem_ctx, +static WERROR NetJoinDomainRemote(struct libnetapi_ctx *ctx, const char *server_name, const char *domain_name, const char *account_ou, @@ -105,7 +107,7 @@ static WERROR NetJoinDomainRemote(TALLOC_CTX *mem_ctx, }; if (password) { - encode_wkssvc_join_password_buffer(mem_ctx, + encode_wkssvc_join_password_buffer(ctx, password, &cli->user_session_key, &encrypted_password); @@ -113,7 +115,7 @@ static WERROR NetJoinDomainRemote(TALLOC_CTX *mem_ctx, old_timeout = cli_set_timeout(cli, 60000); - status = rpccli_wkssvc_NetrJoinDomain2(pipe_cli, mem_ctx, + status = rpccli_wkssvc_NetrJoinDomain2(pipe_cli, ctx, server_name, domain_name, account_ou, Account, &encrypted_password, @@ -132,12 +134,13 @@ static WERROR NetJoinDomainRemote(TALLOC_CTX *mem_ctx, return werr; } -WERROR NetJoinDomain(const char *server_name, - const char *domain_name, - const char *account_ou, - const char *Account, - const char *password, - uint32_t join_flags) +static WERROR libnetapi_NetJoinDomain(struct libnetapi_ctx *ctx, + const char *server_name, + const char *domain_name, + const char *account_ou, + const char *Account, + const char *password, + uint32_t join_flags) { TALLOC_CTX *mem_ctx = NULL; WERROR werr; @@ -164,7 +167,7 @@ WERROR NetJoinDomain(const char *server_name, dc = domain_name; } - werr = NetJoinDomainLocal(mem_ctx, + werr = NetJoinDomainLocal(ctx, dc, domain_name, account_ou, @@ -175,7 +178,7 @@ WERROR NetJoinDomain(const char *server_name, goto done; } - werr = NetJoinDomainRemote(mem_ctx, + werr = NetJoinDomainRemote(ctx, server_name, domain_name, account_ou, @@ -188,10 +191,41 @@ done: return werr; } -WERROR NetUnjoinDomain(const char *server_name, - const char *account, - const char *password, - uint32_t unjoin_flags) +NET_API_STATUS NetJoinDomain(const char *server_name, + const char *domain_name, + const char *account_ou, + const char *Account, + const char *password, + uint32_t join_flags) +{ + struct libnetapi_ctx *ctx = NULL; + NET_API_STATUS status; + WERROR werr; + + status = libnetapi_getctx(&ctx); + if (status != 0) { + return status; + } + + werr = libnetapi_NetJoinDomain(ctx, + server_name, + domain_name, + account_ou, + Account, + password, + join_flags); + if (!W_ERROR_IS_OK(werr)) { + return W_ERROR_V(werr); + } + + return 0; +} + +static WERROR libnetapi_NetUnjoinDomain(struct libnetapi_ctx *ctx, + const char *server_name, + const char *account, + const char *password, + uint32_t unjoin_flags) { TALLOC_CTX *mem_ctx = NULL; struct cli_state *cli = NULL; @@ -266,9 +300,37 @@ WERROR NetUnjoinDomain(const char *server_name, return werr; } -WERROR NetGetJoinInformation(const char *server_name, - const char **name_buffer, - uint16_t *name_type) +NET_API_STATUS NetUnjoinDomain(const char *server_name, + const char *account, + const char *password, + uint32_t unjoin_flags) +{ + struct libnetapi_ctx *ctx = NULL; + NET_API_STATUS status; + WERROR werr; + + status = libnetapi_getctx(&ctx); + if (status != 0) { + return status; + } + + werr = libnetapi_NetUnjoinDomain(ctx, + server_name, + account, + password, + unjoin_flags); + if (!W_ERROR_IS_OK(werr)) { + return W_ERROR_V(werr); + } + + return 0; +} + + +WERROR libnetapi_NetGetJoinInformation(struct libnetapi_ctx *ctx, + const char *server_name, + const char **name_buffer, + uint16_t *name_type) { TALLOC_CTX *mem_ctx = NULL; struct cli_state *cli = NULL; @@ -346,3 +408,27 @@ WERROR NetGetJoinInformation(const char *server_name, return werr; } + +NET_API_STATUS NetGetJoinInformation(const char *server_name, + const char **name_buffer, + uint16_t *name_type) +{ + struct libnetapi_ctx *ctx = NULL; + NET_API_STATUS status; + WERROR werr; + + status = libnetapi_getctx(&ctx); + if (status != 0) { + return status; + } + + werr = libnetapi_NetGetJoinInformation(ctx, + server_name, + name_buffer, + name_type); + if (!W_ERROR_IS_OK(werr)) { + return W_ERROR_V(werr); + } + + return 0; +} diff --git a/source3/lib/netapi/joindomain.h b/source3/lib/netapi/joindomain.h index 73d2ec3d32..b72bc9aecb 100644 --- a/source3/lib/netapi/joindomain.h +++ b/source3/lib/netapi/joindomain.h @@ -20,18 +20,18 @@ #ifndef __LIB_NETAPI_JOINDOMAIN_H__ #define __LIB_NETAPI_JOINDOMAIN_H__ -WERROR NetJoinDomain(const char *server, - const char *domain, - const char *account_ou, - const char *account, - const char *password, - uint32_t join_options); -WERROR NetUnjoinDomain(const char *server_name, - const char *account, - const char *password, - uint32_t unjoin_flags); -WERROR NetGetJoinInformation(const char *server_name, - const char **name_buffer, - uint16_t *name_type); +NET_API_STATUS NetJoinDomain(const char *server, + const char *domain, + const char *account_ou, + const char *account, + const char *password, + uint32_t join_options); +NET_API_STATUS NetUnjoinDomain(const char *server_name, + const char *account, + const char *password, + uint32_t unjoin_flags); +NET_API_STATUS NetGetJoinInformation(const char *server_name, + const char **name_buffer, + uint16_t *name_type); #endif -- cgit From d1548d035f3c296d5044b9aa47fc350cb62e4e2d Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 19 Dec 2007 02:25:15 +0100 Subject: Use DsGetDcName in local libnetapi join to find a dc. Guenther (This used to be commit fbc60c1648ff8b1fa0ae33c09237e41232f9769c) --- source3/lib/netapi/joindomain.c | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/joindomain.c b/source3/lib/netapi/joindomain.c index a0d3319998..c6bf3d687a 100644 --- a/source3/lib/netapi/joindomain.c +++ b/source3/lib/netapi/joindomain.c @@ -36,16 +36,31 @@ static WERROR NetJoinDomainLocal(struct libnetapi_ctx *mem_ctx, werr = libnet_init_JoinCtx(mem_ctx, &r); W_ERROR_NOT_OK_RETURN(werr); - if (!server_name || !domain_name) { + if (!domain_name) { return WERR_INVALID_PARAM; } - r->in.server_name = talloc_strdup(mem_ctx, server_name); - W_ERROR_HAVE_NO_MEMORY(r->in.server_name); - r->in.domain_name = talloc_strdup(mem_ctx, domain_name); W_ERROR_HAVE_NO_MEMORY(r->in.domain_name); + if (server_name) { + r->in.server_name = talloc_strdup(mem_ctx, server_name); + W_ERROR_HAVE_NO_MEMORY(r->in.server_name); + } else if (join_flags & WKSSVC_JOIN_FLAGS_JOIN_TYPE) { + NTSTATUS status; + struct DS_DOMAIN_CONTROLLER_INFO *info = NULL; + uint32_t flags = DS_DIRECTORY_SERVICE_REQUIRED | + DS_WRITABLE_REQUIRED | + DS_RETURN_DNS_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); + } + if (account_ou) { r->in.account_ou = talloc_strdup(mem_ctx, account_ou); W_ERROR_HAVE_NO_MEMORY(r->in.account_ou); @@ -158,17 +173,8 @@ static WERROR libnetapi_NetJoinDomain(struct libnetapi_ctx *ctx, if (!server_name || is_myname_or_ipaddr(server_name)) { - const char *dc = NULL; - - /* FIXME: DsGetDcName */ - if (server_name == NULL) { - dc = domain_name; - } else { - dc = domain_name; - } - werr = NetJoinDomainLocal(ctx, - dc, + server_name, domain_name, account_ou, Account, -- cgit From 14652eab180fa9555607a413e5d1b429d1e1673c Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 19 Dec 2007 10:52:45 +0100 Subject: Fix NetJoinDomainLocal. Guenther (This used to be commit 24605c9175fb313c9c888783817da755cd8ce594) --- source3/lib/netapi/joindomain.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/joindomain.c b/source3/lib/netapi/joindomain.c index c6bf3d687a..180210f707 100644 --- a/source3/lib/netapi/joindomain.c +++ b/source3/lib/netapi/joindomain.c @@ -43,10 +43,7 @@ static WERROR NetJoinDomainLocal(struct libnetapi_ctx *mem_ctx, r->in.domain_name = talloc_strdup(mem_ctx, domain_name); W_ERROR_HAVE_NO_MEMORY(r->in.domain_name); - if (server_name) { - r->in.server_name = talloc_strdup(mem_ctx, server_name); - W_ERROR_HAVE_NO_MEMORY(r->in.server_name); - } else if (join_flags & WKSSVC_JOIN_FLAGS_JOIN_TYPE) { + if (join_flags & WKSSVC_JOIN_FLAGS_JOIN_TYPE) { NTSTATUS status; struct DS_DOMAIN_CONTROLLER_INFO *info = NULL; uint32_t flags = DS_DIRECTORY_SERVICE_REQUIRED | -- cgit From 8f7723fc28cf9e71b0d5ef2890dbe95ae3fc5e07 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 19 Dec 2007 10:55:52 +0100 Subject: Remove unrequired TALLOC_CTX from libnetapi_NetJoinDomain & friends. Guenther (This used to be commit 96ebdca45b998da7e6137973dea717bf3ac76328) --- source3/lib/netapi/joindomain.c | 39 +++++---------------------------------- 1 file changed, 5 insertions(+), 34 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/joindomain.c b/source3/lib/netapi/joindomain.c index 180210f707..08a39549f9 100644 --- a/source3/lib/netapi/joindomain.c +++ b/source3/lib/netapi/joindomain.c @@ -154,44 +154,28 @@ static WERROR libnetapi_NetJoinDomain(struct libnetapi_ctx *ctx, const char *password, uint32_t join_flags) { - TALLOC_CTX *mem_ctx = NULL; - WERROR werr; - - mem_ctx = talloc_init("NetJoinDomain"); - if (!mem_ctx) { - werr = WERR_NOMEM; - goto done; - } - if (!domain_name) { - werr = WERR_INVALID_PARAM; - goto done; + return WERR_INVALID_PARAM; } if (!server_name || is_myname_or_ipaddr(server_name)) { - werr = NetJoinDomainLocal(ctx, + return NetJoinDomainLocal(ctx, server_name, domain_name, account_ou, Account, password, join_flags); - - goto done; } - werr = NetJoinDomainRemote(ctx, + return NetJoinDomainRemote(ctx, server_name, domain_name, account_ou, Account, password, join_flags); -done: - TALLOC_FREE(mem_ctx); - - return werr; } NET_API_STATUS NetJoinDomain(const char *server_name, @@ -230,7 +214,6 @@ static WERROR libnetapi_NetUnjoinDomain(struct libnetapi_ctx *ctx, const char *password, uint32_t unjoin_flags) { - TALLOC_CTX *mem_ctx = NULL; struct cli_state *cli = NULL; struct rpc_pipe_client *pipe_cli = NULL; struct wkssvc_PasswordBuffer encrypted_password; @@ -240,17 +223,6 @@ static WERROR libnetapi_NetUnjoinDomain(struct libnetapi_ctx *ctx, ZERO_STRUCT(encrypted_password); - mem_ctx = talloc_init("NetUnjoinDomain"); - if (!mem_ctx) { - werr = WERR_NOMEM; - goto done; - } - - if (!server_name || is_myname_or_ipaddr(server_name)) { - werr = WERR_NOT_SUPPORTED; - goto done; - } - status = cli_full_connection(&cli, NULL, server_name, NULL, 0, "IPC$", "IPC", @@ -274,7 +246,7 @@ static WERROR libnetapi_NetUnjoinDomain(struct libnetapi_ctx *ctx, }; if (password) { - encode_wkssvc_join_password_buffer(mem_ctx, + encode_wkssvc_join_password_buffer(ctx, password, &cli->user_session_key, &encrypted_password); @@ -282,7 +254,7 @@ static WERROR libnetapi_NetUnjoinDomain(struct libnetapi_ctx *ctx, old_timeout = cli_set_timeout(cli, 60000); - status = rpccli_wkssvc_NetrUnjoinDomain2(pipe_cli, mem_ctx, + status = rpccli_wkssvc_NetrUnjoinDomain2(pipe_cli, ctx, server_name, account, &encrypted_password, @@ -298,7 +270,6 @@ static WERROR libnetapi_NetUnjoinDomain(struct libnetapi_ctx *ctx, cli_set_timeout(cli, old_timeout); cli_shutdown(cli); } - TALLOC_FREE(mem_ctx); return werr; } -- cgit From 75276ac2e3cb2d92e17231c906128bf98eea5d50 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 19 Dec 2007 11:03:45 +0100 Subject: Add support for remote and local unjoining in libnetapi. Guenther (This used to be commit 74048fe7cfbd05994d533bea4a477d6ca93449d9) --- source3/lib/netapi/joindomain.c | 94 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 89 insertions(+), 5 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/joindomain.c b/source3/lib/netapi/joindomain.c index 08a39549f9..2cc93e2545 100644 --- a/source3/lib/netapi/joindomain.c +++ b/source3/lib/netapi/joindomain.c @@ -208,11 +208,73 @@ NET_API_STATUS NetJoinDomain(const char *server_name, return 0; } -static WERROR libnetapi_NetUnjoinDomain(struct libnetapi_ctx *ctx, - const char *server_name, - const char *account, - const char *password, - uint32_t unjoin_flags) +static WERROR NetUnjoinDomainLocal(struct libnetapi_ctx *mem_ctx, + const char *server_name, + const char *account, + const char *password, + uint32_t unjoin_flags) +{ + struct libnet_UnjoinCtx *r = NULL; + struct dom_sid domain_sid; + WERROR werr; + + if (!secrets_fetch_domain_sid(lp_workgroup(), &domain_sid)) { + return WERR_SETUP_NOT_JOINED; + } + + werr = libnet_init_UnjoinCtx(mem_ctx, &r); + 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); + } else { + + NTSTATUS status; + const char *domain = NULL; + 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, + 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); + } + + if (account) { + r->in.admin_account = talloc_strdup(mem_ctx, account); + W_ERROR_HAVE_NO_MEMORY(r->in.admin_account); + } + + if (password) { + r->in.password = talloc_strdup(mem_ctx, password); + W_ERROR_HAVE_NO_MEMORY(r->in.password); + } + + r->in.unjoin_flags = unjoin_flags; + r->in.modify_config = true; + + r->in.domain_sid = &domain_sid; + + return libnet_Unjoin(mem_ctx, r); + +} + +static WERROR NetUnjoinDomainRemote(struct libnetapi_ctx *ctx, + const char *server_name, + const char *account, + const char *password, + uint32_t unjoin_flags) { struct cli_state *cli = NULL; struct rpc_pipe_client *pipe_cli = NULL; @@ -274,6 +336,28 @@ static WERROR libnetapi_NetUnjoinDomain(struct libnetapi_ctx *ctx, return werr; } +static WERROR libnetapi_NetUnjoinDomain(struct libnetapi_ctx *ctx, + const char *server_name, + const char *account, + const char *password, + uint32_t unjoin_flags) +{ + if (!server_name || is_myname_or_ipaddr(server_name)) { + + return NetUnjoinDomainLocal(ctx, + server_name, + account, + password, + unjoin_flags); + } + + return NetUnjoinDomainRemote(ctx, + server_name, + account, + password, + unjoin_flags); +} + NET_API_STATUS NetUnjoinDomain(const char *server_name, const char *account, const char *password, -- cgit From af08d8be3063ada42637a4ae7437499b03457de2 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 19 Dec 2007 12:09:08 +0100 Subject: Add libnetapi_errstr(). Guenther (This used to be commit 465e61a3599a277366ada6ecda3a1e6ddb1f2490) --- source3/lib/netapi/netapi.c | 50 +++++++++++++++++++++++++++++++++++++++++++++ source3/lib/netapi/netapi.h | 1 + 2 files changed, 51 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi.c b/source3/lib/netapi/netapi.c index 853ac55f8a..70d7e654a7 100644 --- a/source3/lib/netapi/netapi.c +++ b/source3/lib/netapi/netapi.c @@ -148,3 +148,53 @@ NET_API_STATUS libnetapi_set_workgroup(struct libnetapi_ctx *ctx, } return W_ERROR_V(WERR_OK); } + +const char *libnetapi_errstr(struct libnetapi_ctx *ctx, + NET_API_STATUS status) +{ + const char *err_str = NULL; + + switch (status) { + case 0: + err_str = "Success"; + break; + case 0x00000057: /* WERR_INVALID_PARAM */ + err_str = "Invalid parameter"; + break; + case 0x0000052E: /* WERR_LOGON_FAILURE */ + err_str = "Invalid logon credentials"; + break; + case 0x00000995: /* WERR_DOMAIN_CONTROLLER_NOT_FOUND */ + err_str = "A domain controller could not be found"; + break; + case 0x00000a84: /* WERR_SETUP_NOT_JOINED */ + err_str = "Join failed"; + break; + case 0x00000a83: /* WERR_SETUP_ALREADY_JOINED */ + err_str = "Machine is already joined"; + break; + case 0x00000a85: /* WERR_SETUP_DOMAIN_CONTROLLER */ + err_str = "Machine is a Domain Controller"; + break; + case 0x00000032: /* WERR_NOT_SUPPORTED */ + err_str = "Not supported"; + break; + case 0x0000051f: /* WERR_NO_LOGON_SERVERS */ + err_str = "No logon servers found"; + break; + case 0x00000056: /* WERR_BAD_PASSWORD */ + err_str = "A bad password was supplied"; + break; + case 0x00000520: /* WERR_NO_SUCH_LOGON_SESSION */ + err_str = "No such logon session"; + break; + default: + err_str = talloc_asprintf(ctx, "0x%08x", status); + if (!err_str) { + return NULL; + } + break; + } + + return err_str; +} diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h index 0b25c93d5b..232d9c154f 100644 --- a/source3/lib/netapi/netapi.h +++ b/source3/lib/netapi/netapi.h @@ -37,6 +37,7 @@ NET_API_STATUS libnetapi_get_debuglevel(struct libnetapi_ctx *ctx, const char ** 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); #include "joindomain.h" -- cgit From 2bed9564dbe4fc3bc86d6ba231c5f2ecce468b5a Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 19 Dec 2007 13:52:51 +0100 Subject: Split out local and remote paths for NetGetJoinInformation. Guenther (This used to be commit d1e4f9dd5cde79f915e3e0f652621d966aa850e8) --- source3/lib/netapi/joindomain.c | 92 +++++++++++++++++++++++------------------ 1 file changed, 52 insertions(+), 40 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/joindomain.c b/source3/lib/netapi/joindomain.c index 2cc93e2545..0c8d645db9 100644 --- a/source3/lib/netapi/joindomain.c +++ b/source3/lib/netapi/joindomain.c @@ -384,50 +384,16 @@ NET_API_STATUS NetUnjoinDomain(const char *server_name, return 0; } - -WERROR libnetapi_NetGetJoinInformation(struct libnetapi_ctx *ctx, - const char *server_name, - const char **name_buffer, - uint16_t *name_type) +static WERROR NetGetJoinInformationRemote(struct libnetapi_ctx *ctx, + const char *server_name, + const char **name_buffer, + uint16_t *name_type) { - TALLOC_CTX *mem_ctx = NULL; struct cli_state *cli = NULL; struct rpc_pipe_client *pipe_cli = NULL; NTSTATUS status; WERROR werr; - mem_ctx = talloc_init("NetGetJoinInformation"); - if (!mem_ctx) { - werr = WERR_NOMEM; - goto done; - } - - if (!server_name || is_myname_or_ipaddr(server_name)) { - if ((lp_security() == SEC_ADS) && lp_realm()) { - *name_buffer = SMB_STRDUP(lp_realm()); - } else { - *name_buffer = SMB_STRDUP(lp_workgroup()); - } - if (!*name_buffer) { - werr = WERR_NOMEM; - goto done; - } - switch (lp_server_role()) { - case ROLE_DOMAIN_MEMBER: - case ROLE_DOMAIN_PDC: - case ROLE_DOMAIN_BDC: - *name_type = NetSetupDomainName; - break; - case ROLE_STANDALONE: - default: - *name_type = NetSetupWorkgroupName; - break; - } - - werr = WERR_OK; - goto done; - } - status = cli_full_connection(&cli, NULL, server_name, NULL, 0, "IPC$", "IPC", @@ -448,7 +414,7 @@ WERROR libnetapi_NetGetJoinInformation(struct libnetapi_ctx *ctx, goto done; }; - status = rpccli_wkssvc_NetrGetJoinInformation(pipe_cli, mem_ctx, + status = rpccli_wkssvc_NetrGetJoinInformation(pipe_cli, ctx, server_name, name_buffer, (enum wkssvc_NetJoinStatus *)name_type, @@ -462,11 +428,57 @@ WERROR libnetapi_NetGetJoinInformation(struct libnetapi_ctx *ctx, if (cli) { cli_shutdown(cli); } - TALLOC_FREE(mem_ctx); return werr; } +static WERROR NetGetJoinInformationLocal(struct libnetapi_ctx *ctx, + const char *server_name, + const char **name_buffer, + uint16_t *name_type) +{ + if ((lp_security() == SEC_ADS) && lp_realm()) { + *name_buffer = SMB_STRDUP(lp_realm()); + } else { + *name_buffer = SMB_STRDUP(lp_workgroup()); + } + if (!*name_buffer) { + return WERR_NOMEM; + } + + switch (lp_server_role()) { + case ROLE_DOMAIN_MEMBER: + case ROLE_DOMAIN_PDC: + case ROLE_DOMAIN_BDC: + *name_type = NetSetupDomainName; + break; + case ROLE_STANDALONE: + default: + *name_type = NetSetupWorkgroupName; + break; + } + + return WERR_OK; +} + +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, + server_name, + name_buffer, + name_type); + } + + return NetGetJoinInformationRemote(ctx, + server_name, + name_buffer, + name_type); +} + NET_API_STATUS NetGetJoinInformation(const char *server_name, const char **name_buffer, uint16_t *name_type) -- cgit From 721d36df8372dd45430a93c99180bb94ec7d9773 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 19 Dec 2007 15:10:24 +0100 Subject: Add NetServerGetInfo and NetServerSetInfo (for level 1005). Guenther (This used to be commit 1cad549f54563c3a9787624ba7a56b54107ebd57) --- source3/lib/netapi/netapi.h | 1 + source3/lib/netapi/serverinfo.c | 297 ++++++++++++++++++++++++++++++++++++++++ source3/lib/netapi/serverinfo.h | 30 ++++ 3 files changed, 328 insertions(+) create mode 100644 source3/lib/netapi/serverinfo.c create mode 100644 source3/lib/netapi/serverinfo.h (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h index 232d9c154f..a1137b45ee 100644 --- a/source3/lib/netapi/netapi.h +++ b/source3/lib/netapi/netapi.h @@ -40,5 +40,6 @@ NET_API_STATUS libnetapi_set_workgroup(struct libnetapi_ctx *ctx, const char *wo const char *libnetapi_errstr(struct libnetapi_ctx *ctx, NET_API_STATUS status); #include "joindomain.h" +#include "serverinfo.h" #endif diff --git a/source3/lib/netapi/serverinfo.c b/source3/lib/netapi/serverinfo.c new file mode 100644 index 0000000000..d6031b69d2 --- /dev/null +++ b/source3/lib/netapi/serverinfo.c @@ -0,0 +1,297 @@ +/* + * Unix SMB/CIFS implementation. + * NetApi Server Support + * Copyright (C) Guenther Deschner 2007 + * + * 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include "includes.h" + +#include "lib/netapi/netapi.h" +#include "libnet/libnet.h" + +static WERROR NetServerGetInfoLocal_1005(struct libnetapi_ctx *ctx, + uint8_t **buffer) +{ + struct srvsvc_NetSrvInfo1005 info1005; + + info1005.comment = lp_serverstring(); + *buffer = (uint8_t *)talloc_memdup(ctx, &info1005, sizeof(info1005)); + if (!*buffer) { + return WERR_NOMEM; + } + + return WERR_OK; +} + +static WERROR NetServerGetInfoLocal(struct libnetapi_ctx *ctx, + const char *server_name, + uint32_t level, + uint8_t **buffer) +{ + switch (level) { + case 1005: + return NetServerGetInfoLocal_1005(ctx, buffer); + default: + return WERR_UNKNOWN_LEVEL; + } + + return WERR_UNKNOWN_LEVEL; +} + +static WERROR NetServerGetInfoRemote(struct libnetapi_ctx *ctx, + const char *server_name, + uint32_t level, + uint8_t **buffer) +{ + struct cli_state *cli = NULL; + struct rpc_pipe_client *pipe_cli = NULL; + NTSTATUS status; + WERROR werr; + union srvsvc_NetSrvInfo info; + + status = cli_full_connection(&cli, NULL, server_name, + NULL, 0, + "IPC$", "IPC", + ctx->username, + ctx->workgroup, + ctx->password, + 0, Undefined, NULL); + + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + pipe_cli = cli_rpc_pipe_open_noauth(cli, PI_SRVSVC, + &status); + if (!pipe_cli) { + werr = ntstatus_to_werror(status); + goto done; + }; + + status = rpccli_srvsvc_NetSrvGetInfo(pipe_cli, ctx, + server_name, + level, + &info, + &werr); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + *buffer = (uint8_t *)&info; + + done: + if (cli) { + cli_shutdown(cli); + } + + return werr; +} + +WERROR libnetapi_NetServerGetInfo(struct libnetapi_ctx *ctx, + const char *server_name, + uint32_t level, + uint8_t **buffer) +{ + if (!server_name || is_myname_or_ipaddr(server_name)) { + return NetServerGetInfoLocal(ctx, + server_name, + level, + buffer); + } + + return NetServerGetInfoRemote(ctx, + server_name, + level, + buffer); + +} + +NET_API_STATUS NetServerGetInfo(const char *server_name, + uint32_t level, + uint8_t **buffer) +{ + struct libnetapi_ctx *ctx = NULL; + NET_API_STATUS status; + WERROR werr; + + status = libnetapi_getctx(&ctx); + if (status != 0) { + return status; + } + + werr = libnetapi_NetServerGetInfo(ctx, + server_name, + level, + buffer); + if (!W_ERROR_IS_OK(werr)) { + return W_ERROR_V(werr); + } + + return 0; +} + +static WERROR NetServerSetInfoLocal_1005(struct libnetapi_ctx *ctx, + uint8_t *buffer, + uint32_t *parm_error) +{ + struct srvsvc_NetSrvInfo1005 *info1005; + + if (!buffer) { + *parm_error = 1005; /* sure here ? */ + return WERR_INVALID_PARAM; + } + + info1005 = (struct srvsvc_NetSrvInfo1005 *)buffer; + + if (!info1005->comment) { + *parm_error = 1005; + return WERR_INVALID_PARAM; + } + + /* + return libnet_conf_set_parm(GLOBAL_NAME, + "server string", + info1005->comment); + */ + return WERR_NOT_SUPPORTED; +} + +static WERROR NetServerSetInfoLocal(struct libnetapi_ctx *ctx, + const char *server_name, + uint32_t level, + uint8_t *buffer, + uint32_t *parm_error) +{ + switch (level) { + case 1005: + return NetServerSetInfoLocal_1005(ctx, buffer, parm_error); + break; + default: + return WERR_UNKNOWN_LEVEL; + } + + return WERR_UNKNOWN_LEVEL; +} + +static WERROR NetServerSetInfoRemote(struct libnetapi_ctx *ctx, + const char *server_name, + uint32_t level, + uint8_t *buffer, + uint32_t *parm_error) +{ + struct cli_state *cli = NULL; + struct rpc_pipe_client *pipe_cli = NULL; + NTSTATUS status; + WERROR werr; + union srvsvc_NetSrvInfo info; + + status = cli_full_connection(&cli, NULL, server_name, + NULL, 0, + "IPC$", "IPC", + ctx->username, + ctx->workgroup, + ctx->password, + 0, Undefined, NULL); + + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + pipe_cli = cli_rpc_pipe_open_noauth(cli, PI_SRVSVC, + &status); + if (!pipe_cli) { + werr = ntstatus_to_werror(status); + goto done; + }; + + switch (level) { + case 1005: + info.info1005 = (struct srvsvc_NetSrvInfo1005 *)buffer; + break; + default: + werr = WERR_NOT_SUPPORTED; + goto done; + } + + status = rpccli_srvsvc_NetSrvSetInfo(pipe_cli, ctx, + server_name, + level, + info, + parm_error, + &werr); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + done: + if (cli) { + cli_shutdown(cli); + } + + return werr; +} + +WERROR libnetapi_NetServerSetInfo(struct libnetapi_ctx *ctx, + const char *server_name, + uint32_t level, + uint8_t *buffer, + uint32_t *parm_error) +{ + if (!server_name || is_myname_or_ipaddr(server_name)) { + return NetServerSetInfoLocal(ctx, + server_name, + level, + buffer, + parm_error); + } + + return NetServerSetInfoRemote(ctx, + server_name, + level, + buffer, + parm_error); +} + + +NET_API_STATUS NetServerSetInfo(const char *server_name, + uint32_t level, + uint8_t *buffer, + uint32_t *parm_error) +{ + struct libnetapi_ctx *ctx = NULL; + NET_API_STATUS status; + WERROR werr; + + status = libnetapi_getctx(&ctx); + if (status != 0) { + return status; + } + + werr = libnetapi_NetServerSetInfo(ctx, + server_name, + level, + buffer, + parm_error); + if (!W_ERROR_IS_OK(werr)) { + return W_ERROR_V(werr); + } + + return 0; +} diff --git a/source3/lib/netapi/serverinfo.h b/source3/lib/netapi/serverinfo.h new file mode 100644 index 0000000000..66c406657a --- /dev/null +++ b/source3/lib/netapi/serverinfo.h @@ -0,0 +1,30 @@ +/* + * Unix SMB/CIFS implementation. + * NetApi Support + * Copyright (C) Guenther Deschner 2007 + * + * 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#ifndef __LIB_NETAPI_SERVERINFO_H__ +#define __LIB_NETAPI_SERVERINFO_H__ + +NET_API_STATUS NetServerGetInfo(const char *server_name, + uint32_t level, + uint8_t **buffer); +NET_API_STATUS NetServerSetInfo(const char *server_name, + uint32_t level, + uint8_t *buffer, + uint32_t *parm_error); +#endif -- cgit From 991112eda710c97dff607dd615c777023395da65 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 19 Dec 2007 16:07:40 +0100 Subject: Implement NetServerSetInfo level 1005 in local mode with smbconf registry. Guenther (This used to be commit 15c2bc15f20a677c3c94895150e396275de6ac9b) --- source3/lib/netapi/serverinfo.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/serverinfo.c b/source3/lib/netapi/serverinfo.c index d6031b69d2..d1bfa47649 100644 --- a/source3/lib/netapi/serverinfo.c +++ b/source3/lib/netapi/serverinfo.c @@ -163,12 +163,13 @@ static WERROR NetServerSetInfoLocal_1005(struct libnetapi_ctx *ctx, return WERR_INVALID_PARAM; } - /* - return libnet_conf_set_parm(GLOBAL_NAME, - "server string", - info1005->comment); - */ - return WERR_NOT_SUPPORTED; + if (!lp_include_registry_globals()) { + return WERR_NOT_SUPPORTED; + } + + return libnet_smbconf_set_global_param(ctx, + "server string", + info1005->comment); } static WERROR NetServerSetInfoLocal(struct libnetapi_ctx *ctx, @@ -180,7 +181,6 @@ static WERROR NetServerSetInfoLocal(struct libnetapi_ctx *ctx, switch (level) { case 1005: return NetServerSetInfoLocal_1005(ctx, buffer, parm_error); - break; default: return WERR_UNKNOWN_LEVEL; } -- cgit From 5479c50c37ee78037a96df8844fd06b1b0c9ccbb Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 20 Dec 2007 01:19:26 +0100 Subject: Merge all headers into libnetapi.h. Guenther (This used to be commit a2c5beda2ec98dea8951fb3a37774f5f325410ef) --- source3/lib/netapi/joindomain.h | 37 ------------------------------------- source3/lib/netapi/netapi.h | 24 ++++++++++++++++++++++-- source3/lib/netapi/serverinfo.h | 30 ------------------------------ 3 files changed, 22 insertions(+), 69 deletions(-) delete mode 100644 source3/lib/netapi/joindomain.h delete mode 100644 source3/lib/netapi/serverinfo.h (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/joindomain.h b/source3/lib/netapi/joindomain.h deleted file mode 100644 index b72bc9aecb..0000000000 --- a/source3/lib/netapi/joindomain.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Unix SMB/CIFS implementation. - * NetApi Support - * Copyright (C) Guenther Deschner 2007 - * - * 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 - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see . - */ - -#ifndef __LIB_NETAPI_JOINDOMAIN_H__ -#define __LIB_NETAPI_JOINDOMAIN_H__ - -NET_API_STATUS NetJoinDomain(const char *server, - const char *domain, - const char *account_ou, - const char *account, - const char *password, - uint32_t join_options); -NET_API_STATUS NetUnjoinDomain(const char *server_name, - const char *account, - const char *password, - uint32_t unjoin_flags); -NET_API_STATUS NetGetJoinInformation(const char *server_name, - const char **name_buffer, - uint16_t *name_type); - -#endif diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h index a1137b45ee..bbd2282a77 100644 --- a/source3/lib/netapi/netapi.h +++ b/source3/lib/netapi/netapi.h @@ -39,7 +39,27 @@ NET_API_STATUS libnetapi_set_password(struct libnetapi_ctx *ctx, const char *pas 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); -#include "joindomain.h" -#include "serverinfo.h" +/* wkssvc */ +NET_API_STATUS NetJoinDomain(const char *server, + const char *domain, + const char *account_ou, + const char *account, + const char *password, + uint32_t join_options); +NET_API_STATUS NetUnjoinDomain(const char *server_name, + const char *account, + const char *password, + uint32_t unjoin_flags); +NET_API_STATUS NetGetJoinInformation(const char *server_name, + const char **name_buffer, + uint16_t *name_type); +/* srvsvc */ +NET_API_STATUS NetServerGetInfo(const char *server_name, + uint32_t level, + uint8_t **buffer); +NET_API_STATUS NetServerSetInfo(const char *server_name, + uint32_t level, + uint8_t *buffer, + uint32_t *parm_error); #endif diff --git a/source3/lib/netapi/serverinfo.h b/source3/lib/netapi/serverinfo.h deleted file mode 100644 index 66c406657a..0000000000 --- a/source3/lib/netapi/serverinfo.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Unix SMB/CIFS implementation. - * NetApi Support - * Copyright (C) Guenther Deschner 2007 - * - * 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 - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see . - */ - -#ifndef __LIB_NETAPI_SERVERINFO_H__ -#define __LIB_NETAPI_SERVERINFO_H__ - -NET_API_STATUS NetServerGetInfo(const char *server_name, - uint32_t level, - uint8_t **buffer); -NET_API_STATUS NetServerSetInfo(const char *server_name, - uint32_t level, - uint8_t *buffer, - uint32_t *parm_error); -#endif -- cgit From f2fe17245436f8e68be2d5ad96b77721828f040a Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 20 Dec 2007 12:12:06 +0100 Subject: Keep libnetapi_NetX calls static for now. Guenther (This used to be commit c255654c68923aca3e258906e49be82d719d5ccd) --- source3/lib/netapi/joindomain.c | 8 ++++---- source3/lib/netapi/serverinfo.c | 18 +++++++++--------- 2 files changed, 13 insertions(+), 13 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/joindomain.c b/source3/lib/netapi/joindomain.c index 0c8d645db9..0c3e021520 100644 --- a/source3/lib/netapi/joindomain.c +++ b/source3/lib/netapi/joindomain.c @@ -461,10 +461,10 @@ static WERROR NetGetJoinInformationLocal(struct libnetapi_ctx *ctx, 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, diff --git a/source3/lib/netapi/serverinfo.c b/source3/lib/netapi/serverinfo.c index d1bfa47649..276a98c15e 100644 --- a/source3/lib/netapi/serverinfo.c +++ b/source3/lib/netapi/serverinfo.c @@ -102,10 +102,10 @@ static WERROR NetServerGetInfoRemote(struct libnetapi_ctx *ctx, return werr; } -WERROR libnetapi_NetServerGetInfo(struct libnetapi_ctx *ctx, - const char *server_name, - uint32_t level, - uint8_t **buffer) +static WERROR libnetapi_NetServerGetInfo(struct libnetapi_ctx *ctx, + const char *server_name, + uint32_t level, + uint8_t **buffer) { if (!server_name || is_myname_or_ipaddr(server_name)) { return NetServerGetInfoLocal(ctx, @@ -248,11 +248,11 @@ static WERROR NetServerSetInfoRemote(struct libnetapi_ctx *ctx, return werr; } -WERROR libnetapi_NetServerSetInfo(struct libnetapi_ctx *ctx, - const char *server_name, - uint32_t level, - uint8_t *buffer, - uint32_t *parm_error) +static WERROR libnetapi_NetServerSetInfo(struct libnetapi_ctx *ctx, + const char *server_name, + uint32_t level, + uint8_t *buffer, + uint32_t *parm_error) { if (!server_name || is_myname_or_ipaddr(server_name)) { return NetServerSetInfoLocal(ctx, -- cgit From 1a30bdb506f3f288e781cf1f445696c7eceb823e Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 20 Dec 2007 15:03:12 +0100 Subject: Remove doubled cli_set_timeout calls from libnetapi. Guenther (This used to be commit acc5d8e784b706001457ceeeb9bd4961a13d57d2) --- source3/lib/netapi/joindomain.c | 4 ---- 1 file changed, 4 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/joindomain.c b/source3/lib/netapi/joindomain.c index 0c3e021520..e3d5eada02 100644 --- a/source3/lib/netapi/joindomain.c +++ b/source3/lib/netapi/joindomain.c @@ -109,8 +109,6 @@ static WERROR NetJoinDomainRemote(struct libnetapi_ctx *ctx, goto done; } - old_timeout = cli_set_timeout(cli, 60000); - pipe_cli = cli_rpc_pipe_open_noauth(cli, PI_WKSSVC, &status); if (!pipe_cli) { @@ -298,8 +296,6 @@ static WERROR NetUnjoinDomainRemote(struct libnetapi_ctx *ctx, goto done; } - old_timeout = cli_set_timeout(cli, 60000); - pipe_cli = cli_rpc_pipe_open_noauth(cli, PI_WKSSVC, &status); if (!pipe_cli) { -- cgit From 9518d738b17eb987dffb20f68df6b6768113b441 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 20 Dec 2007 15:06:20 +0100 Subject: Add error string for access denied in libnetapi. Guenther (This used to be commit 4df868e3c366958c64ed8445489c8d1e8a28e50b) --- source3/lib/netapi/netapi.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi.c b/source3/lib/netapi/netapi.c index 70d7e654a7..1db745b5c7 100644 --- a/source3/lib/netapi/netapi.c +++ b/source3/lib/netapi/netapi.c @@ -158,6 +158,9 @@ const char *libnetapi_errstr(struct libnetapi_ctx *ctx, case 0: err_str = "Success"; break; + case 0x00000005: /* WERR_ACCESS_DENIED */ + err_str = "Access is denied"; + break; case 0x00000057: /* WERR_INVALID_PARAM */ err_str = "Invalid parameter"; break; -- cgit From d230cd8dd554439c7d5e8fa9d7fd56520d9288d0 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 21 Dec 2007 15:30:29 +0100 Subject: Make libnetapi_errstr use our NTSTATUS and WERROR error string macros. Guenther (This used to be commit e46aa35d432e930835206b9ce7583f46933015d8) --- source3/lib/netapi/netapi.c | 49 +++------------------------------------------ 1 file changed, 3 insertions(+), 46 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi.c b/source3/lib/netapi/netapi.c index 1db745b5c7..032798d0f9 100644 --- a/source3/lib/netapi/netapi.c +++ b/source3/lib/netapi/netapi.c @@ -152,52 +152,9 @@ NET_API_STATUS libnetapi_set_workgroup(struct libnetapi_ctx *ctx, const char *libnetapi_errstr(struct libnetapi_ctx *ctx, NET_API_STATUS status) { - const char *err_str = NULL; - - switch (status) { - case 0: - err_str = "Success"; - break; - case 0x00000005: /* WERR_ACCESS_DENIED */ - err_str = "Access is denied"; - break; - case 0x00000057: /* WERR_INVALID_PARAM */ - err_str = "Invalid parameter"; - break; - case 0x0000052E: /* WERR_LOGON_FAILURE */ - err_str = "Invalid logon credentials"; - break; - case 0x00000995: /* WERR_DOMAIN_CONTROLLER_NOT_FOUND */ - err_str = "A domain controller could not be found"; - break; - case 0x00000a84: /* WERR_SETUP_NOT_JOINED */ - err_str = "Join failed"; - break; - case 0x00000a83: /* WERR_SETUP_ALREADY_JOINED */ - err_str = "Machine is already joined"; - break; - case 0x00000a85: /* WERR_SETUP_DOMAIN_CONTROLLER */ - err_str = "Machine is a Domain Controller"; - break; - case 0x00000032: /* WERR_NOT_SUPPORTED */ - err_str = "Not supported"; - break; - case 0x0000051f: /* WERR_NO_LOGON_SERVERS */ - err_str = "No logon servers found"; - break; - case 0x00000056: /* WERR_BAD_PASSWORD */ - err_str = "A bad password was supplied"; - break; - case 0x00000520: /* WERR_NO_SUCH_LOGON_SESSION */ - err_str = "No such logon session"; - break; - default: - err_str = talloc_asprintf(ctx, "0x%08x", status); - if (!err_str) { - return NULL; - } - break; + if (status & 0xc0000000) { + return get_friendly_nt_error_msg(NT_STATUS(status)); } - return err_str; + return get_friendly_werror_msg(W_ERROR(status)); } -- cgit From eddd190921f2b322a227044a5c8067397f80c0f5 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 21 Dec 2007 15:51:00 +0100 Subject: Add basic remote NetGetDCName and NetGetAnyDCName versions to libnetapi. Guenther (This used to be commit 5bc49546a32abb4524133b9f2916cdd51d4eb462) --- source3/lib/netapi/getdc.c | 243 ++++++++++++++++++++++++++++++++++++++++++++ source3/lib/netapi/netapi.h | 9 ++ 2 files changed, 252 insertions(+) create mode 100644 source3/lib/netapi/getdc.c (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/getdc.c b/source3/lib/netapi/getdc.c new file mode 100644 index 0000000000..85a0ae52ef --- /dev/null +++ b/source3/lib/netapi/getdc.c @@ -0,0 +1,243 @@ +/* + * Unix SMB/CIFS implementation. + * NetApi GetDC Support + * Copyright (C) Guenther Deschner 2007 + * + * 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include "includes.h" + +#include "lib/netapi/netapi.h" +#include "libnet/libnet.h" + +#if 0 +#include "librpc/gen_ndr/cli_netlogon.h" +#endif + +NTSTATUS rpccli_netr_GetDcName(struct rpc_pipe_client *cli, + TALLOC_CTX *mem_ctx, + const char *logon_server, + const char *domainname, + const char **dcname); +NTSTATUS rpccli_netr_GetAnyDCName(struct rpc_pipe_client *cli, + TALLOC_CTX *mem_ctx, + const char *logon_server, + const char *domainname, + const char **dcname, + WERROR *werror); + +static WERROR NetGetDCNameLocal(struct libnetapi_ctx *ctx, + const char *server_name, + const char *domain_name, + uint8_t **buffer) +{ + return WERR_NOT_SUPPORTED; +} + +static WERROR NetGetDCNameRemote(struct libnetapi_ctx *ctx, + const char *server_name, + const char *domain_name, + uint8_t **buffer) +{ + struct cli_state *cli = NULL; + struct rpc_pipe_client *pipe_cli = NULL; + NTSTATUS status; + WERROR werr; + + status = cli_full_connection(&cli, NULL, server_name, + NULL, 0, + "IPC$", "IPC", + ctx->username, + ctx->workgroup, + ctx->password, + 0, Undefined, NULL); + + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + pipe_cli = cli_rpc_pipe_open_noauth(cli, PI_NETLOGON, + &status); + if (!pipe_cli) { + werr = ntstatus_to_werror(status); + goto done; + }; + +#if 0 + werr = rpccli_netr_GetDcName(pipe_cli, ctx, + server_name, + domain_name, + (const char **)&buffer); +#else + werr = rpccli_netlogon_getdcname(pipe_cli, ctx, + server_name, + domain_name, + (char **)buffer); +#endif + done: + if (cli) { + cli_shutdown(cli); + } + + return werr; +} + +static WERROR libnetapi_NetGetDCName(struct libnetapi_ctx *ctx, + const char *server_name, + const char *domain_name, + uint8_t **buffer) +{ + if (!server_name || is_myname_or_ipaddr(server_name)) { + return NetGetDCNameLocal(ctx, + server_name, + domain_name, + buffer); + } + + return NetGetDCNameRemote(ctx, + server_name, + domain_name, + buffer); +} + +NET_API_STATUS NetGetDCName(const char *server_name, + const char *domain_name, + uint8_t **buffer) +{ + struct libnetapi_ctx *ctx = NULL; + NET_API_STATUS status; + WERROR werr; + + status = libnetapi_getctx(&ctx); + if (status != 0) { + return status; + } + + werr = libnetapi_NetGetDCName(ctx, + server_name, + domain_name, + buffer); + if (!W_ERROR_IS_OK(werr)) { + return W_ERROR_V(werr); + } + + return 0; +} + +static WERROR NetGetAnyDCNameLocal(struct libnetapi_ctx *ctx, + const char *server_name, + const char *domain_name, + uint8_t **buffer) +{ + return WERR_NOT_SUPPORTED; +} + +static WERROR NetGetAnyDCNameRemote(struct libnetapi_ctx *ctx, + const char *server_name, + const char *domain_name, + uint8_t **buffer) +{ + struct cli_state *cli = NULL; + struct rpc_pipe_client *pipe_cli = NULL; + NTSTATUS status; + WERROR werr; + + status = cli_full_connection(&cli, NULL, server_name, + NULL, 0, + "IPC$", "IPC", + ctx->username, + ctx->workgroup, + ctx->password, + 0, Undefined, NULL); + + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + pipe_cli = cli_rpc_pipe_open_noauth(cli, PI_NETLOGON, + &status); + if (!pipe_cli) { + werr = ntstatus_to_werror(status); + goto done; + }; + +#if 0 + status = rpccli_netr_GetAnyDCName(pipe_cli, ctx, + server_name, + domain_name, + (const char **)&buffer, + &werr); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } +#else + werr = rpccli_netlogon_getanydcname(pipe_cli, ctx, + server_name, + domain_name, + (char **)buffer); +#endif + done: + if (cli) { + cli_shutdown(cli); + } + + return werr; + +} + +static WERROR libnetapi_NetGetAnyDCName(struct libnetapi_ctx *ctx, + const char *server_name, + const char *domain_name, + uint8_t **buffer) +{ + if (!server_name || is_myname_or_ipaddr(server_name)) { + return NetGetAnyDCNameLocal(ctx, + server_name, + domain_name, + buffer); + } + + return NetGetAnyDCNameRemote(ctx, + server_name, + domain_name, + buffer); +} + +NET_API_STATUS NetGetAnyDCName(const char *server_name, + const char *domain_name, + uint8_t **buffer) +{ + struct libnetapi_ctx *ctx = NULL; + NET_API_STATUS status; + WERROR werr; + + status = libnetapi_getctx(&ctx); + if (status != 0) { + return status; + } + + werr = libnetapi_NetGetAnyDCName(ctx, + server_name, + domain_name, + buffer); + if (!W_ERROR_IS_OK(werr)) { + return W_ERROR_V(werr); + } + + return 0; +} diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h index bbd2282a77..0dd6d95ceb 100644 --- a/source3/lib/netapi/netapi.h +++ b/source3/lib/netapi/netapi.h @@ -62,4 +62,13 @@ NET_API_STATUS NetServerSetInfo(const char *server_name, uint32_t level, uint8_t *buffer, uint32_t *parm_error); + +/* netlogon */ +NET_API_STATUS NetGetDCName(const char *server_name, + const char *domain_name, + uint8_t **buffer); +NET_API_STATUS NetGetAnyDCName(const char *server_name, + const char *domain_name, + uint8_t **buffer); + #endif -- cgit From 27a58bd50cfd749cdcfa90fe7abeaf15dc09bbf3 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 21 Dec 2007 16:02:35 +0100 Subject: Add getdc.c, a libnetapi example (incl. Makefile). Guenther (This used to be commit faedc78fc78527ee3bf05e1177ea43653aea67b2) --- source3/lib/netapi/examples/Makefile.in | 34 ++++++++++++++++++++ source3/lib/netapi/examples/getdc.c | 57 +++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 source3/lib/netapi/examples/Makefile.in create mode 100644 source3/lib/netapi/examples/getdc.c (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/Makefile.in b/source3/lib/netapi/examples/Makefile.in new file mode 100644 index 0000000000..79f9187d84 --- /dev/null +++ b/source3/lib/netapi/examples/Makefile.in @@ -0,0 +1,34 @@ +KRB5LIBS=@KRB5_LIBS@ +LDAP_LIBS=@LDAP_LIBS@ +LIBS=@LIBS@ -lnetapi +DEVELOPER_CFLAGS=@DEVELOPER_CFLAGS@ +FLAGS=@CFLAGS@ +CC=@CC@ +LDFLAGS=@PIE_LDFLAGS@ @LDFLAGS@ +DYNEXP=@DYNEXP@ + +# Compile a source file. +COMPILE_CC = $(CC) -I. $(FLAGS) $(PICFLAG) -c $< -o $@ +COMPILE = $(COMPILE_CC) + +.c.o: + @if (: >> $@ || : > $@) >/dev/null 2>&1; then rm -f $@; else \ + dir=`echo $@ | sed 's,/[^/]*$$,,;s,^$$,.,'` $(MAKEDIR); fi + @echo Compiling $*.c + @$(COMPILE) && exit 0;\ + echo "The following command failed:" 1>&2;\ + echo "$(COMPILE_CC)" 1>&2;\ + $(COMPILE_CC) >/dev/null 2>&1 + +GETDC_OBJ = getdc.o + +PROGS = getdc + +all: $(PROGS) + +getdc: $(GETDC_OBJ) + @echo Linking $@ + @$(CC) $(FLAGS) -o $@ $(GETDC_OBJ) $(LDFLAGS) $(DYNEXP) $(LIBS) $(KRB5LIBS) $(LDAP_LIBS) + +clean: + @rm -f $(PROGS) diff --git a/source3/lib/netapi/examples/getdc.c b/source3/lib/netapi/examples/getdc.c new file mode 100644 index 0000000000..ed6a8bd05d --- /dev/null +++ b/source3/lib/netapi/examples/getdc.c @@ -0,0 +1,57 @@ +/* + * Unix SMB/CIFS implementation. + * GetDCName query + * Copyright (C) Guenther Deschner 2007 + * + * 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include +#include +#include +#include +#include + +#include + +int main(int argc, char **argv) +{ + NET_API_STATUS status; + struct libnetapi_ctx *ctx = NULL; + uint8_t *buffer; + + if (argc < 3) { + printf("usage: getdc \n"); + return -1; + } + + status = libnetapi_init(&ctx); + if (status != 0) { + return status; + } + + libnetapi_set_username(ctx, ""); + libnetapi_set_password(ctx, ""); + + status = NetGetDCName(argv[1], argv[2], &buffer); + if (status != 0) { + printf("GetDcName failed with: %s\n", libnetapi_errstr(ctx, status)); + } else { + printf("%s\n", (char *)buffer); + } + + libnetapi_free(ctx); + + return status; +} -- cgit From f3607f85b673ade41773fcfd2cb6935b512fbf60 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 21 Dec 2007 16:08:13 +0100 Subject: Add netdomjoin cmd line tool (another libnetapi example). Guenther (This used to be commit c502686f09713a7cf3786c254be6515a7aa23555) --- source3/lib/netapi/examples/Makefile.in | 7 +- source3/lib/netapi/examples/netdomjoin.c | 107 +++++++++++++++++++++++++++++++ 2 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 source3/lib/netapi/examples/netdomjoin.c (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/Makefile.in b/source3/lib/netapi/examples/Makefile.in index 79f9187d84..d618599433 100644 --- a/source3/lib/netapi/examples/Makefile.in +++ b/source3/lib/netapi/examples/Makefile.in @@ -21,8 +21,9 @@ COMPILE = $(COMPILE_CC) $(COMPILE_CC) >/dev/null 2>&1 GETDC_OBJ = getdc.o +NETDOMJOIN_OBJ = netdomjoin.o -PROGS = getdc +PROGS = getdc netdomjoin all: $(PROGS) @@ -30,5 +31,9 @@ getdc: $(GETDC_OBJ) @echo Linking $@ @$(CC) $(FLAGS) -o $@ $(GETDC_OBJ) $(LDFLAGS) $(DYNEXP) $(LIBS) $(KRB5LIBS) $(LDAP_LIBS) +netdomjoin: $(NETDOMJOIN_OBJ) + @echo Linking $@ + @$(CC) $(FLAGS) -o $@ $(NETDOMJOIN_OBJ) $(LDFLAGS) $(DYNEXP) $(LIBS) $(KRB5LIBS) $(LDAP_LIBS) + clean: @rm -f $(PROGS) diff --git a/source3/lib/netapi/examples/netdomjoin.c b/source3/lib/netapi/examples/netdomjoin.c new file mode 100644 index 0000000000..a2bb700250 --- /dev/null +++ b/source3/lib/netapi/examples/netdomjoin.c @@ -0,0 +1,107 @@ +/* + * Unix SMB/CIFS implementation. + * Join Support (cmdline + netapi) + * Copyright (C) Guenther Deschner 2007 + * + * 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include +#include +#include +#include +#include + +#include + +char *get_string_param(const char *param) +{ + char *p; + + p = strchr(param, '='); + if (!p) { + return NULL; + } + + return (p+1); +} + +int main(int argc, char **argv) +{ + NET_API_STATUS status; + const char *server_name = NULL; + const char *domain_name = NULL; + const char *account_ou = NULL; + const char *Account = NULL; + const char *password = NULL; + uint32_t join_flags = 3; + struct libnetapi_ctx *ctx = NULL; + int i; + + status = libnetapi_init(&ctx); + if (status != 0) { + return status; + } + + if (argc < 2) { + printf("usage: netdomjoin\n"); + printf("\t[hostname=HOSTNAME] [domain=DOMAIN] \n"); + return 0; + } + + if (argc > 2) { + server_name = argv[1]; + } + + for (i=0; i Date: Fri, 21 Dec 2007 16:36:06 +0100 Subject: Add netdomjoin-gui (my first gui application), another libnetapi user. Guenther (This used to be commit cf57ade5ec4a808eccb19a7723d753742fb71ca9) --- source3/lib/netapi/examples/Makefile.in | 12 +- source3/lib/netapi/examples/logo.png | Bin 0 -> 9329 bytes source3/lib/netapi/examples/netdomjoin-gui.c | 1347 ++++++++++++++++++++++++++ source3/lib/netapi/examples/samba.ico | Bin 0 -> 1406 bytes 4 files changed, 1357 insertions(+), 2 deletions(-) create mode 100644 source3/lib/netapi/examples/logo.png create mode 100644 source3/lib/netapi/examples/netdomjoin-gui.c create mode 100755 source3/lib/netapi/examples/samba.ico (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/Makefile.in b/source3/lib/netapi/examples/Makefile.in index d618599433..119e722aec 100644 --- a/source3/lib/netapi/examples/Makefile.in +++ b/source3/lib/netapi/examples/Makefile.in @@ -1,8 +1,11 @@ +GTK_FLAGS=`pkg-config gtk+-2.0 --cflags` +GTK_LIBS=`pkg-config gtk+-2.0 --libs` + KRB5LIBS=@KRB5_LIBS@ LDAP_LIBS=@LDAP_LIBS@ LIBS=@LIBS@ -lnetapi DEVELOPER_CFLAGS=@DEVELOPER_CFLAGS@ -FLAGS=@CFLAGS@ +FLAGS=@CFLAGS@ $(GTK_FLAGS) CC=@CC@ LDFLAGS=@PIE_LDFLAGS@ @LDFLAGS@ DYNEXP=@DYNEXP@ @@ -22,8 +25,9 @@ COMPILE = $(COMPILE_CC) GETDC_OBJ = getdc.o NETDOMJOIN_OBJ = netdomjoin.o +NETDOMJOIN_GUI_OBJ = netdomjoin-gui.o -PROGS = getdc netdomjoin +PROGS = getdc netdomjoin netdomjoin-gui all: $(PROGS) @@ -35,5 +39,9 @@ netdomjoin: $(NETDOMJOIN_OBJ) @echo Linking $@ @$(CC) $(FLAGS) -o $@ $(NETDOMJOIN_OBJ) $(LDFLAGS) $(DYNEXP) $(LIBS) $(KRB5LIBS) $(LDAP_LIBS) +netdomjoin-gui: $(NETDOMJOIN_GUI_OBJ) + @echo Linking $@ + @$(CC) $(FLAGS) $(GTK_FLAGS) -o $@ $(NETDOMJOIN_GUI_OBJ) $(LDFLAGS) $(DYNEXP) $(LIBS) $(KRB5LIBS) $(LDAP_LIBS) $(GTK_LIBS) + clean: @rm -f $(PROGS) diff --git a/source3/lib/netapi/examples/logo.png b/source3/lib/netapi/examples/logo.png new file mode 100644 index 0000000000..6df4ace659 Binary files /dev/null and b/source3/lib/netapi/examples/logo.png differ diff --git a/source3/lib/netapi/examples/netdomjoin-gui.c b/source3/lib/netapi/examples/netdomjoin-gui.c new file mode 100644 index 0000000000..8ca6897cab --- /dev/null +++ b/source3/lib/netapi/examples/netdomjoin-gui.c @@ -0,0 +1,1347 @@ +/* + * Unix SMB/CIFS implementation. + * Join Support (gtk + netapi) + * Copyright (C) Guenther Deschner 2007 + * + * 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include + +#include +#include + +#include + +#define MAX_CRED_LEN 256 +#define MAX_NETBIOS_NAME_LEN 15 + +#define SAMBA_ICON_PATH "/usr/share/pixmaps/samba/samba.ico" +#define SAMBA_IMAGE_PATH "/usr/share/pixmaps/samba/logo.png" + +#define WKSSVC_JOIN_FLAGS_DOMAIN_JOIN_IF_JOINED ( 0x00000020 ) +#define WKSSVC_JOIN_FLAGS_ACCOUNT_DELETE ( 0x00000004 ) +#define WKSSVC_JOIN_FLAGS_ACCOUNT_CREATE ( 0x00000002 ) +#define WKSSVC_JOIN_FLAGS_JOIN_TYPE ( 0x00000001 ) + +#define NetSetupWorkgroupName ( 2 ) +#define NetSetupDomainName ( 3 ) + +#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0) + +struct srvsvc_NetSrvInfo1005 { + const char *comment;/* [unique,charset(UTF16)] */ +}; + +static gboolean verbose = FALSE; + +typedef struct join_state { + struct libnetapi_ctx *ctx; + GtkWidget *window_main; + GtkWidget *window_parent; + GtkWidget *window_do_change; + GtkWidget *window_creds_prompt; + GtkWidget *entry_account; + GtkWidget *entry_password; + GtkWidget *entry_domain; + GtkWidget *entry_workgroup; + GtkWidget *button_ok; + GtkWidget *button_apply; + GtkWidget *button_ok_creds; + GtkWidget *label_reboot; + GtkWidget *label_current_name_buffer; + GtkWidget *label_current_name_type; + GtkWidget *label_full_computer_name; + uint16_t name_type_initial; + uint16_t name_type_new; + char *name_buffer_initial; + char *name_buffer_new; + char *password; + char *account; + char *comment; + char *comment_new; + char *my_fqdn; + char *my_dnsdomain; + char *my_hostname; + uint16_t server_role; + gboolean settings_changed; + gboolean hostname_changed; +} join_state; + +static void debug(const char *format, ...) +{ + va_list args; + + if (!verbose) { + return; + } + + va_start(args, format); + g_vprintf(format, args); + va_end(args); +} + +static gboolean callback_delete_event(GtkWidget *widget, + GdkEvent *event, + gpointer data) +{ + gtk_main_quit(); + return FALSE; +} + +static void callback_do_close(GtkWidget *widget, + gpointer data) +{ + debug("Closing now...\n"); + gtk_widget_destroy(data); +} + +static void free_join_state(struct join_state *s) +{ + SAFE_FREE(s->name_buffer_initial); + SAFE_FREE(s->name_buffer_new); + SAFE_FREE(s->password); + SAFE_FREE(s->account); + SAFE_FREE(s->comment); + SAFE_FREE(s->comment_new); + SAFE_FREE(s->my_fqdn); + SAFE_FREE(s->my_dnsdomain); + SAFE_FREE(s->my_hostname); + +} + +static void do_cleanup(struct join_state *state) +{ + libnetapi_free(state->ctx); + free_join_state(state); +} + +static void callback_apply_description_change(GtkWidget *widget, + gpointer data) +{ + struct join_state *state = (struct join_state *)data; + NET_API_STATUS status = 0; + uint32_t parm_err = 0; + struct srvsvc_NetSrvInfo1005 info1005; + GtkWidget *dialog; + + info1005.comment = state->comment_new; + + status = NetServerSetInfo(NULL, 1005, (uint8_t *)&info1005, &parm_err); + if (status) { + debug("NetServerSetInfo failed with: %s\n", + libnetapi_errstr(state->ctx, status)); + dialog = gtk_message_dialog_new(GTK_WINDOW(state->window_main), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR, + GTK_BUTTONS_OK, + "Failed to change computer description: %s.", + libnetapi_errstr(state->ctx, status)); + g_signal_connect_swapped(dialog, "response", + G_CALLBACK(gtk_widget_destroy), + dialog); + + gtk_widget_show(dialog); + return; + } + + gtk_widget_set_sensitive(GTK_WIDGET(state->button_apply), FALSE); +} + +static void callback_do_exit(GtkWidget *widget, + gpointer data) +{ + GtkWidget *dialog; + gint result; + struct join_state *state = (struct join_state *)data; + + if (!state->settings_changed) { + callback_delete_event(NULL, NULL, NULL); + return; + } + + dialog = gtk_message_dialog_new(GTK_WINDOW(state->window_main), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_QUESTION, + GTK_BUTTONS_YES_NO, + "You must restart your computer before the new settings will take effect."); + result = gtk_dialog_run(GTK_DIALOG(dialog)); + switch (result) { + case GTK_RESPONSE_YES: + g_print("would reboot here\n"); + break; + case GTK_RESPONSE_NO: + default: + break; + } + gtk_widget_destroy(dialog); + gtk_widget_destroy(state->window_main); + do_cleanup(state); + exit(0); +} + + +static void callback_do_reboot(GtkWidget *widget, + gpointer data, + gpointer data2) +{ + GtkWidget *dialog; + struct join_state *state = (struct join_state *)data2; + + debug("callback_do_reboot\n"); + + state->settings_changed = TRUE; + dialog = gtk_message_dialog_new(GTK_WINDOW(data), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_INFO, + GTK_BUTTONS_OK, + "You must restart this computer for the changes to take effect."); +#if 0 + g_signal_connect_swapped(dialog, "response", + G_CALLBACK(gtk_widget_destroy), + dialog); + + debug("showing dialog\n"); + gtk_widget_show(dialog); +#else + gtk_dialog_run(GTK_DIALOG(dialog)); + gtk_widget_destroy(dialog); +#endif + + gtk_label_set_text(GTK_LABEL(state->label_reboot), "Changes will take effect after you restart this computer"); + + debug("destroying do_change window\n"); + gtk_widget_destroy(GTK_WIDGET(state->window_do_change)); + + { + uint32_t status; + const char *buffer; + uint16_t type; + + status = NetGetJoinInformation(NULL, &buffer, &type); + if (status != 0) { + g_print("failed to query status\n"); + return; + } + + debug("got new status: %s\n", buffer); +#if 0 + SAFE_FREE(state->name_buffer_new); + state->name_buffer_new = strdup(buffer); + SAFE_FREE(buffer); + state->name_type_new = type; +#endif + gtk_label_set_text(GTK_LABEL(state->label_current_name_buffer), state->name_buffer_new); + if (state->name_type_new == 3) { + gtk_label_set_text(GTK_LABEL(state->label_current_name_type), "Domain:"); + } else { + gtk_label_set_text(GTK_LABEL(state->label_current_name_type), "Workgroup:"); + } + } +} + +static void callback_return_username(GtkWidget *widget, + gpointer data) +{ + const gchar *entry_text; + struct join_state *state = (struct join_state *)data; + if (!widget) { + return; + } + entry_text = gtk_entry_get_text(GTK_ENTRY(widget)); + debug("callback_return_username: %s\n", entry_text); + SAFE_FREE(state->account); + state->account = strdup(entry_text); +} + +static void callback_return_username_and_enter(GtkWidget *widget, + gpointer data) +{ + const gchar *entry_text; + struct join_state *state = (struct join_state *)data; + if (!widget) { + return; + } + entry_text = gtk_entry_get_text(GTK_ENTRY(widget)); + debug("callback_return_username: %s\n", entry_text); + SAFE_FREE(state->account); + state->account = strdup(entry_text); + g_signal_emit_by_name(state->button_ok_creds, "clicked"); +} + +static void callback_return_password(GtkWidget *widget, + gpointer data) +{ + const gchar *entry_text; + struct join_state *state = (struct join_state *)data; + if (!widget) { + return; + } + entry_text = gtk_entry_get_text(GTK_ENTRY(widget)); +#ifdef DEBUG_PASSWORD + debug("callback_return_password: %s\n", entry_text); +#else + debug("callback_return_password: (not printed)\n"); +#endif + SAFE_FREE(state->password); + state->password = strdup(entry_text); +} + +static void callback_return_password_and_enter(GtkWidget *widget, + gpointer data) +{ + const gchar *entry_text; + struct join_state *state = (struct join_state *)data; + if (!widget) { + return; + } + entry_text = gtk_entry_get_text(GTK_ENTRY(widget)); +#ifdef DEBUG_PASSWORD + debug("callback_return_password: %s\n", entry_text); +#else + debug("callback_return_password: (not printed)\n"); +#endif + SAFE_FREE(state->password); + state->password = strdup(entry_text); + g_signal_emit_by_name(state->button_ok_creds, "clicked"); +} + +static void callback_do_hostname_change(GtkWidget *widget, + gpointer data) +{ + GtkWidget *dialog; + const char *str = NULL; + + struct join_state *state = (struct join_state *)data; + + switch (state->name_type_initial) { + case NetSetupDomainName: + str = "To be implemented: call NetRenameMachineInDomain\n"; + break; + case NetSetupWorkgroupName: + str = "To be implemented: call SetComputerNameEx\n"; + break; + default: + break; + } + + dialog = gtk_message_dialog_new(GTK_WINDOW(state->window_parent), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR, + GTK_BUTTONS_CLOSE, + str); + + g_signal_connect_swapped(dialog, "response", + G_CALLBACK(gtk_widget_destroy), + dialog); + gtk_widget_show(dialog); +} + +static void callback_do_join(GtkWidget *widget, + gpointer data) +{ + GtkWidget *dialog; + + NET_API_STATUS status; + const char *err_str = NULL; + uint32_t join_flags = 0; + uint32_t unjoin_flags = 0; + gboolean domain_join = FALSE; + gboolean try_unjoin = FALSE; + const char *domain_or_workgroup = NULL; + + struct join_state *state = (struct join_state *)data; + + callback_return_username(state->entry_account, state); + callback_return_password(state->entry_password, state); + + if (state->window_creds_prompt) { + gtk_widget_destroy(GTK_WIDGET(state->window_creds_prompt)); + } + + if (state->name_type_new == NetSetupDomainName) { + domain_join = TRUE; + join_flags = WKSSVC_JOIN_FLAGS_JOIN_TYPE | + WKSSVC_JOIN_FLAGS_ACCOUNT_CREATE | + WKSSVC_JOIN_FLAGS_DOMAIN_JOIN_IF_JOINED; /* for testing */ + domain_or_workgroup = "domain"; + } else { + domain_or_workgroup = "workgroup"; + } + + if ((state->name_type_initial == NetSetupDomainName) && + (state->name_type_new == NetSetupWorkgroupName)) { + try_unjoin = TRUE; + unjoin_flags = WKSSVC_JOIN_FLAGS_JOIN_TYPE | + WKSSVC_JOIN_FLAGS_ACCOUNT_DELETE; + } + + debug("callback_do_join: Joining a %s named %s using join_flags 0x%08x ", + domain_or_workgroup, + state->name_buffer_new, + join_flags); + if (domain_join) { + debug("as %s ", state->account); +#ifdef DEBUG_PASSWORD + debug("with %s ", state->password); +#endif + } + debug("\n"); + if (try_unjoin) { + + debug("callback_do_join: Unjoining\n"); + + status = NetUnjoinDomain(NULL, + state->account, + state->password, + unjoin_flags); + if (status != 0) { + err_str = libnetapi_errstr(state->ctx, status); + g_print("callback_do_join: failed to unjoin (%s)\n", + err_str); + + dialog = gtk_message_dialog_new(GTK_WINDOW(state->window_parent), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR, + GTK_BUTTONS_CLOSE, + "The following error occured attempting to unjoin the %s: \"%s\": %s", + domain_or_workgroup, + state->name_buffer_new, + err_str); + + g_signal_connect_swapped(dialog, "response", + G_CALLBACK(gtk_widget_destroy), + dialog); + + gtk_widget_show(dialog); + + return; + } + + } + status = NetJoinDomain(NULL, + state->name_buffer_new, + NULL, + state->account, + state->password, + join_flags); + if (status != 0) { + err_str = libnetapi_errstr(state->ctx, status); + g_print("callback_do_join: failed to join (%s)\n", err_str); + + dialog = gtk_message_dialog_new(GTK_WINDOW(state->window_parent), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR, + GTK_BUTTONS_CLOSE, + "The following error occured attempting to join the %s: \"%s\": %s", + domain_or_workgroup, + state->name_buffer_new, + err_str); + + g_signal_connect_swapped(dialog, "response", + G_CALLBACK(gtk_widget_destroy), + dialog); + + gtk_widget_show(dialog); + + return; + } + + debug("callback_do_join: Successfully joined %s\n", + domain_or_workgroup); + + dialog = gtk_message_dialog_new(GTK_WINDOW(state->window_parent), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_INFO, + GTK_BUTTONS_OK, + "Welcome to the %s %s.", + state->name_buffer_new, + domain_or_workgroup); + + gtk_dialog_run(GTK_DIALOG(dialog)); + gtk_widget_destroy(dialog); + + callback_do_reboot(NULL, state->window_parent, state); +} + +static void callback_creds_prompt(GtkWidget *widget, + gpointer data) +{ + GtkWidget *window; + GtkWidget *box1; + GtkWidget *bbox; + GtkWidget *button; + GtkWidget *label; + + struct join_state *state = (struct join_state *)data; + + debug("callback_creds_prompt:\n"); + + state->window_parent = state->window_do_change; + + if (state->hostname_changed) { + return callback_do_hostname_change(NULL, state); + } + + if ((state->name_type_initial != NetSetupDomainName) && + (state->name_type_new != NetSetupDomainName)) { + return callback_do_join(NULL, state); + } + + window = gtk_window_new(GTK_WINDOW_TOPLEVEL); + + gtk_window_set_title(GTK_WINDOW(window), "Computer Name Changes"); + gtk_window_set_resizable(GTK_WINDOW(window), FALSE); + gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER); + gtk_widget_set_size_request(GTK_WIDGET(window), 380, 280); + gtk_window_set_icon_from_file(GTK_WINDOW(window), SAMBA_ICON_PATH, NULL); +/* gtk_window_set_icon_name(GTK_WIDGET(window), GTK_STOCK_DIALOG_AUTHENTICATION); */ + state->window_creds_prompt = window; + + g_signal_connect(G_OBJECT(window), "delete_event", + G_CALLBACK(callback_do_close), window); + + gtk_container_set_border_width(GTK_CONTAINER(window), 10); + + box1 = gtk_vbox_new(FALSE, 0); + + gtk_container_add(GTK_CONTAINER(window), box1); + + if ((state->name_type_initial == NetSetupDomainName) && + (state->name_type_new == NetSetupWorkgroupName)) { + label = gtk_label_new("Enter the name and password of an account with permission to leave the domain.\n"); + } else { + label = gtk_label_new("Enter the name and password of an account with permission to join the domain.\n"); + } + gtk_misc_set_alignment(GTK_MISC(label), 0, 0); + gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); + + gtk_box_pack_start(GTK_BOX(box1), label, FALSE, FALSE, 0); + + gtk_widget_show(label); + + /* USER NAME */ + label = gtk_label_new("User name:"); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0); + gtk_box_pack_start(GTK_BOX(box1), label, FALSE, FALSE, 0); + gtk_widget_show(label); + + state->entry_account = gtk_entry_new(); + gtk_entry_set_max_length(GTK_ENTRY(state->entry_account), MAX_CRED_LEN); + g_signal_connect(G_OBJECT(state->entry_account), "activate", + G_CALLBACK(callback_return_username_and_enter), + (gpointer)state); + gtk_editable_select_region(GTK_EDITABLE(state->entry_account), + 0, GTK_ENTRY(state->entry_account)->text_length); + gtk_box_pack_start(GTK_BOX(box1), state->entry_account, TRUE, TRUE, 0); + gtk_widget_show(state->entry_account); + + /* PASSWORD */ + label = gtk_label_new("Password:"); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0); + gtk_box_pack_start(GTK_BOX(box1), label, FALSE, FALSE, 0); + gtk_widget_show(label); + + state->entry_password = gtk_entry_new(); + gtk_entry_set_max_length(GTK_ENTRY(state->entry_password), MAX_CRED_LEN); + gtk_entry_set_visibility(GTK_ENTRY(state->entry_password), FALSE); + g_signal_connect(G_OBJECT(state->entry_password), "activate", + G_CALLBACK(callback_return_password_and_enter), + (gpointer)state); + gtk_editable_set_editable(GTK_EDITABLE(state->entry_password), TRUE); + gtk_editable_select_region(GTK_EDITABLE(state->entry_password), + 0, GTK_ENTRY(state->entry_password)->text_length); + gtk_box_pack_start(GTK_BOX(box1), state->entry_password, TRUE, TRUE, 0); + gtk_widget_show(state->entry_password); + + bbox = gtk_hbutton_box_new(); + gtk_container_set_border_width(GTK_CONTAINER(bbox), 5); + gtk_container_add(GTK_CONTAINER(box1), bbox); + gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); + gtk_box_set_spacing(GTK_BOX(bbox), 10); + + state->button_ok_creds = gtk_button_new_from_stock(GTK_STOCK_OK); + gtk_widget_grab_focus(GTK_WIDGET(state->button_ok_creds)); + gtk_container_add(GTK_CONTAINER(bbox), state->button_ok_creds); + g_signal_connect(G_OBJECT(state->button_ok_creds), "clicked", + G_CALLBACK(callback_do_join), + (gpointer)state); + gtk_widget_show(state->button_ok_creds); + + button = gtk_button_new_from_stock(GTK_STOCK_CANCEL); + gtk_container_add(GTK_CONTAINER(bbox), button); + g_signal_connect(G_OBJECT(button), "clicked", + G_CALLBACK(callback_do_close), (gpointer) window); + gtk_widget_show_all(window); +} + +static void callback_enter_hostname_and_unlock(GtkWidget *widget, + gpointer data) +{ + const gchar *entry_text = NULL; + char *str = NULL; + struct join_state *state = (struct join_state *)data; + + entry_text = gtk_entry_get_text(GTK_ENTRY(widget)); + debug("callback_enter_hostname_and_unlock: %s\n", entry_text); + if (!entry_text || entry_text[0] == 0) { + state->hostname_changed = FALSE; + gtk_widget_set_sensitive(GTK_WIDGET(state->button_ok), FALSE); + return; + } + if (strcasecmp(state->my_hostname, entry_text) == 0) { + state->hostname_changed = FALSE; + gtk_widget_set_sensitive(GTK_WIDGET(state->button_ok), FALSE); + return; + } + state->hostname_changed = TRUE; + if (state->name_type_initial == NetSetupDomainName) { + asprintf(&str, "%s.%s", entry_text, state->my_dnsdomain); + } else { + asprintf(&str, "%s.", entry_text); + } + gtk_label_set_text(GTK_LABEL(state->label_full_computer_name), str); + free(str); + + if (state->hostname_changed && str && str[0] != 0 && str[0] != '.') { + gtk_widget_set_sensitive(GTK_WIDGET(state->button_ok), TRUE); + } +} + +static void callback_enter_computer_description_and_unlock(GtkWidget *widget, + gpointer data) +{ + const gchar *entry_text = NULL; + struct join_state *state = (struct join_state *)data; + int string_unchanged = 0; + + entry_text = gtk_entry_get_text(GTK_ENTRY(widget)); + debug("callback_enter_computer_description_and_unlock: %s\n", + entry_text); +#if 0 + if (!entry_text || entry_text[0] == 0) { + string_unchanged = 1; + gtk_widget_set_sensitive(GTK_WIDGET(state->button_apply), + FALSE); + return; + } +#endif + if (entry_text && strcasecmp(state->comment, entry_text) == 0) { + string_unchanged = 1; + gtk_widget_set_sensitive(GTK_WIDGET(state->button_apply), + FALSE); + return; + } + + gtk_widget_set_sensitive(GTK_WIDGET(state->button_apply), TRUE); + SAFE_FREE(state->comment_new); + state->comment_new = strdup(entry_text); + +} + + +static void callback_enter_workgroup_and_unlock(GtkWidget *widget, + gpointer data) +{ + const gchar *entry_text = NULL; + struct join_state *state = (struct join_state *)data; + + entry_text = gtk_entry_get_text(GTK_ENTRY(widget)); + debug("callback_enter_workgroup_and_unlock: %s\n", entry_text); + if (!entry_text || entry_text[0] == 0) { + gtk_widget_set_sensitive(GTK_WIDGET(state->button_ok), FALSE); + return; + } + if (strcasecmp(state->name_buffer_initial, entry_text) == 0) { + gtk_widget_set_sensitive(GTK_WIDGET(state->button_ok), FALSE); + return; + } + gtk_widget_set_sensitive(GTK_WIDGET(state->button_ok), TRUE); + SAFE_FREE(state->name_buffer_new); + state->name_buffer_new = strdup(entry_text); + state->name_type_new = NetSetupWorkgroupName; +} + +static void callback_enter_domain_and_unlock(GtkWidget *widget, + gpointer data) +{ + const gchar *entry_text = NULL; + struct join_state *state = (struct join_state *)data; + + entry_text = gtk_entry_get_text(GTK_ENTRY(widget)); + debug("callback_enter_domain_and_unlock: %s\n", entry_text); + if (!entry_text || entry_text[0] == 0) { + gtk_widget_set_sensitive(GTK_WIDGET(state->button_ok), FALSE); + return; + } + if (strcasecmp(state->name_buffer_initial, entry_text) == 0) { + gtk_widget_set_sensitive(GTK_WIDGET(state->button_ok), FALSE); + return; + } + gtk_widget_set_sensitive(GTK_WIDGET(state->button_ok), TRUE); + SAFE_FREE(state->name_buffer_new); + state->name_buffer_new = strdup(entry_text); + state->name_type_new = NetSetupDomainName; +} + +static void callback_continue(GtkWidget *widget, + gpointer data) +{ + struct join_state *state = (struct join_state *)data; + + gtk_widget_grab_focus(GTK_WIDGET(state->button_ok)); + g_signal_emit_by_name(state->button_ok, "clicked"); +} + +static void callback_apply_continue(GtkWidget *widget, + gpointer data) +{ + struct join_state *state = (struct join_state *)data; + + gtk_widget_grab_focus(GTK_WIDGET(state->button_apply)); + g_signal_emit_by_name(state->button_apply, "clicked"); +} + +static void callback_do_join_workgroup(GtkWidget *widget, + gpointer data) +{ + struct join_state *state = (struct join_state *)data; + debug("callback_do_join_workgroup choosen\n"); + gtk_widget_set_sensitive(GTK_WIDGET(state->entry_workgroup), TRUE); + gtk_widget_grab_focus(GTK_WIDGET(state->entry_workgroup)); + gtk_widget_set_sensitive(GTK_WIDGET(state->entry_domain), FALSE); + callback_enter_workgroup_and_unlock(state->entry_workgroup, state); /* TEST */ +} + +static void callback_do_join_domain(GtkWidget *widget, + gpointer data) +{ + struct join_state *state = (struct join_state *)data; + debug("callback_do_join_domain choosen\n"); + gtk_widget_set_sensitive(GTK_WIDGET(state->entry_domain), TRUE); + gtk_widget_grab_focus(GTK_WIDGET(state->entry_domain)); + gtk_widget_set_sensitive(GTK_WIDGET(state->entry_workgroup), FALSE); + callback_enter_domain_and_unlock(state->entry_domain, state); /* TEST */ +} + +static void callback_do_change(GtkWidget *widget, + gpointer data) +{ + GtkWidget *window; + GtkWidget *box1; + GtkWidget *bbox; + GtkWidget *button_workgroup; + GtkWidget *button_domain; + GtkWidget *button; + GtkWidget *label; + GtkWidget *frame_horz; + GtkWidget *vbox; + GtkWidget *entry; + GSList *group; + + struct join_state *state = (struct join_state *)data; + + debug("callback_do_change called\n"); + + if (state->server_role == 3) { + GtkWidget *dialog; + dialog = gtk_message_dialog_new(GTK_WINDOW(state->window_main), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR, + GTK_BUTTONS_OK, + "Domain controller cannot be moved from one domain to another, they must first be demoted. Renaming this domain controller may cause it to become temporarily unavailable to users and computers. For information on renaming domain controllers, including alternate renaming methods, see Help and Support. To continue renaming this domain controller, click OK."); + g_signal_connect_swapped(dialog, "response", + G_CALLBACK(gtk_widget_destroy), + dialog); + + gtk_widget_show(dialog); + return; + } + + state->button_ok = gtk_button_new_from_stock(GTK_STOCK_OK); + window = gtk_window_new(GTK_WINDOW_TOPLEVEL); + + gtk_window_set_title(GTK_WINDOW(window), "Computer Name Changes"); + gtk_window_set_resizable(GTK_WINDOW(window), FALSE); + gtk_widget_set_size_request(GTK_WIDGET(window), 480, 500); /* breite * höhe */ + gtk_window_set_icon_from_file(GTK_WINDOW(window), SAMBA_ICON_PATH, NULL); + + g_signal_connect(G_OBJECT(window), "delete_event", + G_CALLBACK(callback_do_close), window); + + gtk_container_set_border_width(GTK_CONTAINER(window), 10); + + box1 = gtk_vbox_new(FALSE, 0); + gtk_container_add(GTK_CONTAINER(window), box1); + + label = gtk_label_new("You can change the name and membership of this computer. Changes may affect access to network ressources."); + gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0); + gtk_box_pack_start(GTK_BOX(box1), label, TRUE, TRUE, 0); + gtk_widget_show(label); + + /* COMPUTER NAME */ + label = gtk_label_new("Computer name:"); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0); + gtk_box_pack_start(GTK_BOX(box1), label, TRUE, TRUE, 0); + gtk_widget_show(label); + + state->label_full_computer_name = gtk_label_new(NULL); + { + entry = gtk_entry_new(); + gtk_entry_set_max_length(GTK_ENTRY(entry), MAX_NETBIOS_NAME_LEN); + g_signal_connect(G_OBJECT(entry), "changed", + G_CALLBACK(callback_enter_hostname_and_unlock), + (gpointer)state); + gtk_entry_set_text(GTK_ENTRY(entry), state->my_hostname); + gtk_editable_select_region(GTK_EDITABLE(entry), + 0, GTK_ENTRY(entry)->text_length); + + gtk_editable_set_editable(GTK_EDITABLE(entry), TRUE); /* ! */ + gtk_box_pack_start(GTK_BOX(box1), entry, TRUE, TRUE, 0); + gtk_widget_show(entry); + } + + /* FULL COMPUTER NAME */ + label = gtk_label_new("Full computer name:"); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0); + gtk_box_pack_start(GTK_BOX(box1), label, TRUE, TRUE, 0); + gtk_widget_show(label); + + { + const gchar *entry_text; + char *str = NULL; + entry_text = gtk_entry_get_text(GTK_ENTRY(entry)); + if (state->name_type_initial == NetSetupDomainName) { + asprintf(&str, "%s.%s", entry_text, state->my_dnsdomain); + } else { + asprintf(&str, "%s.", entry_text); + } + gtk_label_set_text(GTK_LABEL(state->label_full_computer_name), str); + free(str); + gtk_misc_set_alignment(GTK_MISC(state->label_full_computer_name), 0, 0); + gtk_box_pack_start(GTK_BOX(box1), state->label_full_computer_name, TRUE, TRUE, 0); + gtk_widget_show(state->label_full_computer_name); + } + + /* BOX */ + frame_horz = gtk_frame_new ("Member Of"); + gtk_box_pack_start(GTK_BOX(box1), frame_horz, TRUE, TRUE, 10); + + vbox = gtk_vbox_new(FALSE, 0); + gtk_container_set_border_width(GTK_CONTAINER(vbox), 10); + gtk_container_add(GTK_CONTAINER(frame_horz), vbox); + + /* TWO ENTRIES */ + state->entry_workgroup = gtk_entry_new(); + state->entry_domain = gtk_entry_new(); + + /* DOMAIN */ + button_domain = gtk_radio_button_new_with_label(NULL, "Domain"); + if (state->name_type_initial == NetSetupDomainName) { + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button_domain), TRUE); + } + gtk_box_pack_start(GTK_BOX(vbox), button_domain, TRUE, TRUE, 0); + g_signal_connect(G_OBJECT(button_domain), "clicked", + G_CALLBACK(callback_do_join_domain), + (gpointer)state); + + { + gtk_entry_set_max_length(GTK_ENTRY(state->entry_domain), 50); + g_signal_connect(G_OBJECT(state->entry_domain), "changed", + G_CALLBACK(callback_enter_domain_and_unlock), + (gpointer)state); + g_signal_connect(G_OBJECT(state->entry_domain), "activate", + G_CALLBACK(callback_continue), + (gpointer)state); + if (state->name_type_initial == NetSetupDomainName) { + gtk_entry_set_text(GTK_ENTRY(state->entry_domain), state->name_buffer_initial); + gtk_widget_set_sensitive(state->entry_workgroup, FALSE); + gtk_widget_set_sensitive(state->entry_domain, TRUE); + } + gtk_editable_set_editable(GTK_EDITABLE(state->entry_domain), TRUE); + gtk_box_pack_start(GTK_BOX(vbox), state->entry_domain, TRUE, TRUE, 0); + gtk_widget_show(state->entry_domain); + } + gtk_widget_show(button_domain); + + /* WORKGROUP */ + group = gtk_radio_button_get_group(GTK_RADIO_BUTTON(button_domain)); + button_workgroup = gtk_radio_button_new_with_label(group, "Workgroup"); + if (state->name_type_initial == NetSetupWorkgroupName) { + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button_workgroup), TRUE); + } + gtk_box_pack_start(GTK_BOX(vbox), button_workgroup, TRUE, TRUE, 0); + g_signal_connect(G_OBJECT(button_workgroup), "clicked", + G_CALLBACK(callback_do_join_workgroup), + (gpointer)state); + { + gtk_entry_set_max_length(GTK_ENTRY(state->entry_workgroup), MAX_NETBIOS_NAME_LEN); + g_signal_connect(G_OBJECT(state->entry_workgroup), "changed", + G_CALLBACK(callback_enter_workgroup_and_unlock), + (gpointer)state); + g_signal_connect(G_OBJECT(state->entry_workgroup), "activate", + G_CALLBACK(callback_continue), + (gpointer)state); + + if (state->name_type_initial == NetSetupWorkgroupName) { + gtk_entry_set_text(GTK_ENTRY(state->entry_workgroup), state->name_buffer_initial); + gtk_widget_set_sensitive(GTK_WIDGET(state->entry_domain), FALSE); + gtk_widget_set_sensitive(GTK_WIDGET(state->entry_workgroup), TRUE); + } + gtk_box_pack_start(GTK_BOX(vbox), state->entry_workgroup, TRUE, TRUE, 0); + gtk_widget_show(state->entry_workgroup); + } + gtk_widget_show(button_workgroup); + + /* BUTTONS */ + bbox = gtk_hbutton_box_new(); + gtk_container_set_border_width(GTK_CONTAINER(bbox), 5); + gtk_container_add(GTK_CONTAINER(box1), bbox); + gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); + gtk_box_set_spacing(GTK_BOX(bbox), 10); + + state->window_do_change = window; + gtk_widget_set_sensitive(GTK_WIDGET(state->button_ok), FALSE); /* !!! */ + gtk_container_add(GTK_CONTAINER(bbox), state->button_ok); + g_signal_connect(G_OBJECT(state->button_ok), "clicked", + G_CALLBACK(callback_creds_prompt), + (gpointer)state); + + button = gtk_button_new_from_stock(GTK_STOCK_CANCEL); + gtk_container_add(GTK_CONTAINER(bbox), button); + g_signal_connect(G_OBJECT(button), "clicked", + G_CALLBACK(callback_do_close), + (gpointer)window); + + gtk_widget_show_all(window); + +} + +static void callback_do_about(GtkWidget *widget, + gpointer data) +{ + GdkPixbuf *logo; + GError *error = NULL; + + debug("callback_do_about called\n"); + + logo = gdk_pixbuf_new_from_file(SAMBA_IMAGE_PATH, + &error); + if (logo == NULL) { + g_print("failed to load logo from %s: %s\n", + SAMBA_IMAGE_PATH, error->message); + } + + gtk_show_about_dialog(data, + "name", "Samba", + "version", "3.2.0pre2-GIT-904a90-test", + "copyright", "Copyright Andrew Tridgell and the Samba Team 1992-2007", + "website", "http://www.samba.org", + "license", "GPLv3", + "logo", logo, + "comments", "Samba gtk domain join utility", + NULL); +} + +static int draw_main_window(struct join_state *state) +{ + GtkWidget *window; + GtkWidget *button; + GtkWidget *label; + GtkWidget *main_vbox; + GtkWidget *vbox; + GtkWidget *hbox; + GtkWidget *bbox; + GtkWidget *image; + GtkWidget *table; + GtkWidget *entry; + GdkPixbuf *icon; + GError *error = NULL; + + icon = gdk_pixbuf_new_from_file(SAMBA_ICON_PATH, + &error); + if (icon == NULL) { + g_print("failed to load logo from %s : %s\n", + SAMBA_ICON_PATH, error->message); + } + +#if 1 + image = gtk_image_new_from_file(SAMBA_IMAGE_PATH); +#else + image = gtk_image_new_from_file("/usr/share/pixmaps/redhat-system_settings.png"); +#endif + + window = gtk_window_new(GTK_WINDOW_TOPLEVEL); + state->window_main = window; + + gtk_window_set_title(GTK_WINDOW(window), "Samba - Join Domain dialogue"); + gtk_widget_set_size_request(GTK_WIDGET(window), 600, 600); /* breite * höhe */ + gtk_window_set_resizable(GTK_WINDOW(window), FALSE); + gtk_window_set_icon_from_file(GTK_WINDOW(window), SAMBA_ICON_PATH, NULL); + + g_signal_connect(G_OBJECT(window), "delete_event", + G_CALLBACK(callback_delete_event), NULL); + + gtk_container_set_border_width(GTK_CONTAINER(window), 10); + + main_vbox = gtk_vbox_new(FALSE, 10); + gtk_container_add(GTK_CONTAINER(window), main_vbox); + +#if 0 + gtk_box_pack_start(GTK_BOX(main_vbox), image, TRUE, TRUE, 10); + gtk_widget_show(image); +#endif + /* Hbox */ + hbox = gtk_hbox_new(FALSE, 10); + gtk_container_add(GTK_CONTAINER(main_vbox), hbox); + + { +/* gtk_box_pack_start(GTK_BOX(main_vbox), image, TRUE, TRUE, 10); */ + gtk_misc_set_alignment(GTK_MISC(image), 0, 0); + gtk_box_pack_start(GTK_BOX(hbox), image, FALSE, FALSE, 10); + gtk_widget_show(image); + + /* Label */ + label = gtk_label_new("Samba uses the following information to identify your computer on the network."); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0); + gtk_widget_set_size_request(GTK_WIDGET(label), 500, 40); + gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); + gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); + gtk_widget_show(label); + } + + gtk_widget_show(hbox); + + vbox = gtk_vbox_new(FALSE, 0); + gtk_container_set_border_width(GTK_CONTAINER(vbox), 10); + gtk_container_add(GTK_CONTAINER(main_vbox), vbox); + + /* Table */ + table = gtk_table_new(6, 3, TRUE); + gtk_table_set_row_spacings(GTK_TABLE(table), 5); + gtk_table_set_col_spacings(GTK_TABLE(table), 5); + gtk_container_add(GTK_CONTAINER(vbox), table); + + { + /* Label */ + label = gtk_label_new("Computer description:"); +/* gtk_misc_set_alignment(GTK_MISC(label), 0, 0); */ + gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 0, 1); + gtk_widget_show(label); + + state->button_apply = gtk_button_new_from_stock(GTK_STOCK_APPLY); + + /* Entry */ + entry = gtk_entry_new(); + gtk_entry_set_max_length(GTK_ENTRY(entry), 256); + g_signal_connect(G_OBJECT(entry), "changed", + G_CALLBACK(callback_enter_computer_description_and_unlock), + state); + g_signal_connect(G_OBJECT(entry), "activate", + G_CALLBACK(callback_apply_continue), + (gpointer)state); + + gtk_entry_set_text(GTK_ENTRY(entry), (char *)state->comment); + gtk_editable_set_editable(GTK_EDITABLE(entry), TRUE); /* ! */ + gtk_table_attach_defaults(GTK_TABLE(table), entry, 1, 3, 0, 1); + gtk_widget_show(entry); + } + + /* Label */ + label = gtk_label_new("For example: \"Samba \%v\"."); + gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0); + gtk_table_attach_defaults(GTK_TABLE(table), label, 1, 3, 1, 2); + gtk_widget_show(label); + + /* Label */ + label = gtk_label_new("Full computer name:"); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0); + gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 2, 3); + gtk_widget_show(label); + + { + /* Label */ + char *str = NULL; + if (state->name_type_initial == NetSetupDomainName) { + asprintf(&str, "%s.%s", state->my_hostname, + state->my_dnsdomain); + } else { + asprintf(&str, "%s.", state->my_hostname); + } + + label = gtk_label_new(str); + SAFE_FREE(str); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0); + gtk_table_attach_defaults(GTK_TABLE(table), label, 1, 3, 2, 3); + gtk_widget_show(label); + } + + /* Label */ + if (state->name_type_initial == NetSetupDomainName) { + label = gtk_label_new("Domain:"); + } else { + label = gtk_label_new("Workgroup:"); + } + gtk_misc_set_alignment(GTK_MISC(label), 0, 0); + gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 3, 4); + gtk_widget_show(label); + state->label_current_name_type = label; + + /* Label */ + label = gtk_label_new(state->name_buffer_initial); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0); + gtk_table_attach_defaults(GTK_TABLE(table), label, 1, 3, 3, 4); + gtk_widget_show(label); + state->label_current_name_buffer = label; + + { + hbox = gtk_hbox_new(FALSE, 0); + gtk_container_add(GTK_CONTAINER(vbox), hbox); + label = gtk_label_new("To rename this computer or join a domain, click Change."); + gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); + + + } + + /* bbox */ + bbox = gtk_hbutton_box_new(); + gtk_container_set_border_width(GTK_CONTAINER(bbox), 5); + gtk_container_add(GTK_CONTAINER(hbox), bbox); + gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); + gtk_box_set_spacing(GTK_BOX(bbox), 10); + + button = gtk_button_new_with_mnemonic("Ch_ange"); + g_signal_connect(G_OBJECT(button), "clicked", + G_CALLBACK(callback_do_change), + (gpointer)state); + gtk_box_pack_start(GTK_BOX(bbox), button, TRUE, TRUE, 0); + gtk_widget_show(button); + + /* Label (hidden) */ + state->label_reboot = gtk_label_new(NULL); + gtk_label_set_line_wrap(GTK_LABEL(state->label_reboot), TRUE); + gtk_misc_set_alignment(GTK_MISC(state->label_reboot), 0, 0); + gtk_box_pack_start(GTK_BOX(vbox), state->label_reboot, TRUE, TRUE, 0); + gtk_widget_show(state->label_reboot); + +#if 0 + gtk_box_pack_start(GTK_BOX(vbox), + create_bbox(window, TRUE, NULL, 10, 85, 20, GTK_BUTTONBOX_END), + TRUE, TRUE, 5); +#endif + { + + GtkWidget *frame; + GtkWidget *bbox2; + GtkWidget *button2; + + frame = gtk_frame_new(NULL); + bbox2 = gtk_hbutton_box_new(); + + gtk_container_set_border_width(GTK_CONTAINER(bbox2), 5); + gtk_container_add(GTK_CONTAINER(frame), bbox2); + + /* Set the appearance of the Button Box */ + gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox2), GTK_BUTTONBOX_END); + gtk_box_set_spacing(GTK_BOX(bbox2), 10); + /*gtk_button_box_set_child_size(GTK_BUTTON_BOX(bbox2), child_w, child_h);*/ + + button2 = gtk_button_new_from_stock(GTK_STOCK_OK); + gtk_container_add(GTK_CONTAINER(bbox2), button2); + g_signal_connect(G_OBJECT(button2), "clicked", G_CALLBACK(callback_do_exit), state); + + button2 = gtk_button_new_from_stock(GTK_STOCK_CANCEL); + gtk_container_add(GTK_CONTAINER(bbox2), button2); + g_signal_connect(G_OBJECT(button2), "clicked", + G_CALLBACK(callback_delete_event), + window); + + gtk_container_add(GTK_CONTAINER(bbox2), state->button_apply); + g_signal_connect(G_OBJECT(state->button_apply), "clicked", + G_CALLBACK(callback_apply_description_change), + state); + gtk_widget_set_sensitive(GTK_WIDGET(state->button_apply), FALSE); + + button2 = gtk_button_new_from_stock(GTK_STOCK_ABOUT); + gtk_container_add(GTK_CONTAINER(bbox2), button2); + g_signal_connect(G_OBJECT(button2), "clicked", + G_CALLBACK(callback_do_about), + window); + + gtk_box_pack_start(GTK_BOX(vbox), frame, TRUE, TRUE, 5); + } + + gtk_widget_show_all(window); + + return 0; +} + +static int init_join_state(struct join_state **state) +{ + struct join_state *s; + + s = malloc(sizeof(struct join_state)); + if (!s) { + return -1; + } + + memset(s, '\0', sizeof(struct join_state)); + + *state = s; + + return 0; +} + +static int initialize_join_state(struct join_state *state, + const char *debug_level) +{ + struct libnetapi_ctx *ctx = NULL; + NET_API_STATUS status = 0; + + status = libnetapi_init(&ctx); + if (status) { + return status; + } + + if (debug_level) { + libnetapi_set_debuglevel(ctx, debug_level); + } + + { + char my_hostname[HOST_NAME_MAX]; + const char *p = NULL; + if (gethostname(my_hostname, sizeof(my_hostname)) == -1) { + return -1; + } + + state->my_fqdn = strdup(my_hostname); + if (!state->my_fqdn) { + return -1; + } + + p = strchr(my_hostname, '.'); + if (p) { + my_hostname[strlen(my_hostname) - strlen(p)] = '\0'; + state->my_hostname = strdup(my_hostname); + if (!state->my_hostname) { + return -1; + } + p++; + state->my_dnsdomain = strdup(p); + if (!state->my_dnsdomain) { + return -1; + } + } + } + + { + const char *buffer = NULL; + uint16_t type = 0; + status = NetGetJoinInformation(NULL, &buffer, &type); + if (status) { + return status; + } + state->name_buffer_initial = (char *)buffer; + state->name_type_initial = type; + } + + { + struct srvsvc_NetSrvInfo1005 *info1005 = NULL; + uint8_t *buffer = NULL; + + status = NetServerGetInfo(NULL, 1005, &buffer); + if (status) { + return status; + } + + info1005 = (struct srvsvc_NetSrvInfo1005 *)buffer; + + state->comment = strdup(info1005->comment); + if (!state->comment) { + return -1; + } + } +#if 0 + { + struct srvsvc_NetSrvInfo100 *info100 = NULL; + uint8_t *buffer = NULL; + + status = NetServerGetInfo(NULL, 100, &buffer); + if (status) { + return status; + } + + info100 = (struct srvsvc_NetSrvInfo100 *)buffer; + + state->comment = strdup(info100->comment); + if (!state->comment) { + return -1; + } + } +#endif + + state->ctx = ctx; + + return 0; +} + +int main(int argc, char **argv) +{ + GOptionContext *context = NULL; + static const char *debug_level = NULL; + struct join_state *state = NULL; + GError *error = NULL; + int ret = 0; + + static GOptionEntry entries[] = { + { "debug", 'd', 0, G_OPTION_ARG_STRING, &debug_level, "Debug level (for samba)", "N" }, + { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, "Verbose output", 0 }, + { NULL } + }; + + context = g_option_context_new("- Samba domain join utility"); + g_option_context_add_main_entries(context, entries, NULL); +/* g_option_context_add_main_entries(context, entries, GETTEXT_PACKAGE); */ + g_option_context_add_group(context, gtk_get_option_group(TRUE)); + g_option_context_parse(context, &argc, &argv, &error); + + gtk_init(&argc, &argv); + g_set_application_name("Samba"); + + ret = init_join_state(&state); + if (ret) { + return ret; + } + + ret = initialize_join_state(state, debug_level); + if (ret) { + return ret; + } + + draw_main_window(state); + + gtk_main(); + + do_cleanup(state); + + return 0; +} diff --git a/source3/lib/netapi/examples/samba.ico b/source3/lib/netapi/examples/samba.ico new file mode 100755 index 0000000000..b70c9590de Binary files /dev/null and b/source3/lib/netapi/examples/samba.ico differ -- cgit From 77a2e13cb1950cfd591f31b6a12eae66c342e632 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 21 Dec 2007 17:05:55 +0100 Subject: Move libnetapi examples into subdirs. Guenther (This used to be commit 0c3de6f3458419e57daaa71f1dad679897388f5a) --- source3/lib/netapi/examples/Makefile.in | 24 +- source3/lib/netapi/examples/getdc.c | 57 - source3/lib/netapi/examples/getdc/getdc.c | 57 + source3/lib/netapi/examples/logo.png | Bin 9329 -> 0 bytes source3/lib/netapi/examples/netdomjoin-gui.c | 1347 -------------------- .../lib/netapi/examples/netdomjoin-gui/logo.png | Bin 0 -> 9329 bytes .../lib/netapi/examples/netdomjoin-gui/samba.ico | Bin 0 -> 1406 bytes source3/lib/netapi/examples/netdomjoin.c | 107 -- .../netapi/examples/netdomjoin/netdomjoin-gui.c | 1347 ++++++++++++++++++++ .../lib/netapi/examples/netdomjoin/netdomjoin.c | 107 ++ source3/lib/netapi/examples/samba.ico | Bin 1406 -> 0 bytes 11 files changed, 1528 insertions(+), 1518 deletions(-) delete mode 100644 source3/lib/netapi/examples/getdc.c create mode 100644 source3/lib/netapi/examples/getdc/getdc.c delete mode 100644 source3/lib/netapi/examples/logo.png delete mode 100644 source3/lib/netapi/examples/netdomjoin-gui.c create mode 100644 source3/lib/netapi/examples/netdomjoin-gui/logo.png create mode 100755 source3/lib/netapi/examples/netdomjoin-gui/samba.ico delete mode 100644 source3/lib/netapi/examples/netdomjoin.c create mode 100644 source3/lib/netapi/examples/netdomjoin/netdomjoin-gui.c create mode 100644 source3/lib/netapi/examples/netdomjoin/netdomjoin.c delete mode 100755 source3/lib/netapi/examples/samba.ico (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/Makefile.in b/source3/lib/netapi/examples/Makefile.in index 119e722aec..c2f453dedc 100644 --- a/source3/lib/netapi/examples/Makefile.in +++ b/source3/lib/netapi/examples/Makefile.in @@ -14,6 +14,16 @@ DYNEXP=@DYNEXP@ COMPILE_CC = $(CC) -I. $(FLAGS) $(PICFLAG) -c $< -o $@ COMPILE = $(COMPILE_CC) +BINARY_PREREQS = proto_exists bin/.dummy + +MAKEDIR = || exec false; \ + if test -d "$$dir"; then :; else \ + echo mkdir "$$dir"; \ + mkdir -p "$$dir" >/dev/null 2>&1 || \ + test -d "$$dir" || \ + mkdir "$$dir" || \ + exec false; fi || exec false + .c.o: @if (: >> $@ || : > $@) >/dev/null 2>&1; then rm -f $@; else \ dir=`echo $@ | sed 's,/[^/]*$$,,;s,^$$,.,'` $(MAKEDIR); fi @@ -23,23 +33,23 @@ COMPILE = $(COMPILE_CC) echo "$(COMPILE_CC)" 1>&2;\ $(COMPILE_CC) >/dev/null 2>&1 -GETDC_OBJ = getdc.o -NETDOMJOIN_OBJ = netdomjoin.o -NETDOMJOIN_GUI_OBJ = netdomjoin-gui.o +GETDC_OBJ = getdc/getdc.o +NETDOMJOIN_OBJ = netdomjoin/netdomjoin.o +NETDOMJOIN_GUI_OBJ = netdomjoin-gui/netdomjoin-gui.o -PROGS = getdc netdomjoin netdomjoin-gui +PROGS = bin/getdc@EXEEXT@ bin/netdomjoin@EXEEXT@ bin/netdomjoin-gui@EXEEXT@ all: $(PROGS) -getdc: $(GETDC_OBJ) +bin/getdc@EXEEXT@: $(GETDC_OBJ) @echo Linking $@ @$(CC) $(FLAGS) -o $@ $(GETDC_OBJ) $(LDFLAGS) $(DYNEXP) $(LIBS) $(KRB5LIBS) $(LDAP_LIBS) -netdomjoin: $(NETDOMJOIN_OBJ) +bin/netdomjoin@EXEEXT@: $(NETDOMJOIN_OBJ) @echo Linking $@ @$(CC) $(FLAGS) -o $@ $(NETDOMJOIN_OBJ) $(LDFLAGS) $(DYNEXP) $(LIBS) $(KRB5LIBS) $(LDAP_LIBS) -netdomjoin-gui: $(NETDOMJOIN_GUI_OBJ) +bin/netdomjoin-gui@EXEEXT@: $(NETDOMJOIN_GUI_OBJ) @echo Linking $@ @$(CC) $(FLAGS) $(GTK_FLAGS) -o $@ $(NETDOMJOIN_GUI_OBJ) $(LDFLAGS) $(DYNEXP) $(LIBS) $(KRB5LIBS) $(LDAP_LIBS) $(GTK_LIBS) diff --git a/source3/lib/netapi/examples/getdc.c b/source3/lib/netapi/examples/getdc.c deleted file mode 100644 index ed6a8bd05d..0000000000 --- a/source3/lib/netapi/examples/getdc.c +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Unix SMB/CIFS implementation. - * GetDCName query - * Copyright (C) Guenther Deschner 2007 - * - * 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 - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see . - */ - -#include -#include -#include -#include -#include - -#include - -int main(int argc, char **argv) -{ - NET_API_STATUS status; - struct libnetapi_ctx *ctx = NULL; - uint8_t *buffer; - - if (argc < 3) { - printf("usage: getdc \n"); - return -1; - } - - status = libnetapi_init(&ctx); - if (status != 0) { - return status; - } - - libnetapi_set_username(ctx, ""); - libnetapi_set_password(ctx, ""); - - status = NetGetDCName(argv[1], argv[2], &buffer); - if (status != 0) { - printf("GetDcName failed with: %s\n", libnetapi_errstr(ctx, status)); - } else { - printf("%s\n", (char *)buffer); - } - - libnetapi_free(ctx); - - return status; -} diff --git a/source3/lib/netapi/examples/getdc/getdc.c b/source3/lib/netapi/examples/getdc/getdc.c new file mode 100644 index 0000000000..ed6a8bd05d --- /dev/null +++ b/source3/lib/netapi/examples/getdc/getdc.c @@ -0,0 +1,57 @@ +/* + * Unix SMB/CIFS implementation. + * GetDCName query + * Copyright (C) Guenther Deschner 2007 + * + * 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include +#include +#include +#include +#include + +#include + +int main(int argc, char **argv) +{ + NET_API_STATUS status; + struct libnetapi_ctx *ctx = NULL; + uint8_t *buffer; + + if (argc < 3) { + printf("usage: getdc \n"); + return -1; + } + + status = libnetapi_init(&ctx); + if (status != 0) { + return status; + } + + libnetapi_set_username(ctx, ""); + libnetapi_set_password(ctx, ""); + + status = NetGetDCName(argv[1], argv[2], &buffer); + if (status != 0) { + printf("GetDcName failed with: %s\n", libnetapi_errstr(ctx, status)); + } else { + printf("%s\n", (char *)buffer); + } + + libnetapi_free(ctx); + + return status; +} diff --git a/source3/lib/netapi/examples/logo.png b/source3/lib/netapi/examples/logo.png deleted file mode 100644 index 6df4ace659..0000000000 Binary files a/source3/lib/netapi/examples/logo.png and /dev/null differ diff --git a/source3/lib/netapi/examples/netdomjoin-gui.c b/source3/lib/netapi/examples/netdomjoin-gui.c deleted file mode 100644 index 8ca6897cab..0000000000 --- a/source3/lib/netapi/examples/netdomjoin-gui.c +++ /dev/null @@ -1,1347 +0,0 @@ -/* - * Unix SMB/CIFS implementation. - * Join Support (gtk + netapi) - * Copyright (C) Guenther Deschner 2007 - * - * 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 - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see . - */ - -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include - -#include -#include - -#include - -#define MAX_CRED_LEN 256 -#define MAX_NETBIOS_NAME_LEN 15 - -#define SAMBA_ICON_PATH "/usr/share/pixmaps/samba/samba.ico" -#define SAMBA_IMAGE_PATH "/usr/share/pixmaps/samba/logo.png" - -#define WKSSVC_JOIN_FLAGS_DOMAIN_JOIN_IF_JOINED ( 0x00000020 ) -#define WKSSVC_JOIN_FLAGS_ACCOUNT_DELETE ( 0x00000004 ) -#define WKSSVC_JOIN_FLAGS_ACCOUNT_CREATE ( 0x00000002 ) -#define WKSSVC_JOIN_FLAGS_JOIN_TYPE ( 0x00000001 ) - -#define NetSetupWorkgroupName ( 2 ) -#define NetSetupDomainName ( 3 ) - -#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0) - -struct srvsvc_NetSrvInfo1005 { - const char *comment;/* [unique,charset(UTF16)] */ -}; - -static gboolean verbose = FALSE; - -typedef struct join_state { - struct libnetapi_ctx *ctx; - GtkWidget *window_main; - GtkWidget *window_parent; - GtkWidget *window_do_change; - GtkWidget *window_creds_prompt; - GtkWidget *entry_account; - GtkWidget *entry_password; - GtkWidget *entry_domain; - GtkWidget *entry_workgroup; - GtkWidget *button_ok; - GtkWidget *button_apply; - GtkWidget *button_ok_creds; - GtkWidget *label_reboot; - GtkWidget *label_current_name_buffer; - GtkWidget *label_current_name_type; - GtkWidget *label_full_computer_name; - uint16_t name_type_initial; - uint16_t name_type_new; - char *name_buffer_initial; - char *name_buffer_new; - char *password; - char *account; - char *comment; - char *comment_new; - char *my_fqdn; - char *my_dnsdomain; - char *my_hostname; - uint16_t server_role; - gboolean settings_changed; - gboolean hostname_changed; -} join_state; - -static void debug(const char *format, ...) -{ - va_list args; - - if (!verbose) { - return; - } - - va_start(args, format); - g_vprintf(format, args); - va_end(args); -} - -static gboolean callback_delete_event(GtkWidget *widget, - GdkEvent *event, - gpointer data) -{ - gtk_main_quit(); - return FALSE; -} - -static void callback_do_close(GtkWidget *widget, - gpointer data) -{ - debug("Closing now...\n"); - gtk_widget_destroy(data); -} - -static void free_join_state(struct join_state *s) -{ - SAFE_FREE(s->name_buffer_initial); - SAFE_FREE(s->name_buffer_new); - SAFE_FREE(s->password); - SAFE_FREE(s->account); - SAFE_FREE(s->comment); - SAFE_FREE(s->comment_new); - SAFE_FREE(s->my_fqdn); - SAFE_FREE(s->my_dnsdomain); - SAFE_FREE(s->my_hostname); - -} - -static void do_cleanup(struct join_state *state) -{ - libnetapi_free(state->ctx); - free_join_state(state); -} - -static void callback_apply_description_change(GtkWidget *widget, - gpointer data) -{ - struct join_state *state = (struct join_state *)data; - NET_API_STATUS status = 0; - uint32_t parm_err = 0; - struct srvsvc_NetSrvInfo1005 info1005; - GtkWidget *dialog; - - info1005.comment = state->comment_new; - - status = NetServerSetInfo(NULL, 1005, (uint8_t *)&info1005, &parm_err); - if (status) { - debug("NetServerSetInfo failed with: %s\n", - libnetapi_errstr(state->ctx, status)); - dialog = gtk_message_dialog_new(GTK_WINDOW(state->window_main), - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_ERROR, - GTK_BUTTONS_OK, - "Failed to change computer description: %s.", - libnetapi_errstr(state->ctx, status)); - g_signal_connect_swapped(dialog, "response", - G_CALLBACK(gtk_widget_destroy), - dialog); - - gtk_widget_show(dialog); - return; - } - - gtk_widget_set_sensitive(GTK_WIDGET(state->button_apply), FALSE); -} - -static void callback_do_exit(GtkWidget *widget, - gpointer data) -{ - GtkWidget *dialog; - gint result; - struct join_state *state = (struct join_state *)data; - - if (!state->settings_changed) { - callback_delete_event(NULL, NULL, NULL); - return; - } - - dialog = gtk_message_dialog_new(GTK_WINDOW(state->window_main), - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_QUESTION, - GTK_BUTTONS_YES_NO, - "You must restart your computer before the new settings will take effect."); - result = gtk_dialog_run(GTK_DIALOG(dialog)); - switch (result) { - case GTK_RESPONSE_YES: - g_print("would reboot here\n"); - break; - case GTK_RESPONSE_NO: - default: - break; - } - gtk_widget_destroy(dialog); - gtk_widget_destroy(state->window_main); - do_cleanup(state); - exit(0); -} - - -static void callback_do_reboot(GtkWidget *widget, - gpointer data, - gpointer data2) -{ - GtkWidget *dialog; - struct join_state *state = (struct join_state *)data2; - - debug("callback_do_reboot\n"); - - state->settings_changed = TRUE; - dialog = gtk_message_dialog_new(GTK_WINDOW(data), - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_INFO, - GTK_BUTTONS_OK, - "You must restart this computer for the changes to take effect."); -#if 0 - g_signal_connect_swapped(dialog, "response", - G_CALLBACK(gtk_widget_destroy), - dialog); - - debug("showing dialog\n"); - gtk_widget_show(dialog); -#else - gtk_dialog_run(GTK_DIALOG(dialog)); - gtk_widget_destroy(dialog); -#endif - - gtk_label_set_text(GTK_LABEL(state->label_reboot), "Changes will take effect after you restart this computer"); - - debug("destroying do_change window\n"); - gtk_widget_destroy(GTK_WIDGET(state->window_do_change)); - - { - uint32_t status; - const char *buffer; - uint16_t type; - - status = NetGetJoinInformation(NULL, &buffer, &type); - if (status != 0) { - g_print("failed to query status\n"); - return; - } - - debug("got new status: %s\n", buffer); -#if 0 - SAFE_FREE(state->name_buffer_new); - state->name_buffer_new = strdup(buffer); - SAFE_FREE(buffer); - state->name_type_new = type; -#endif - gtk_label_set_text(GTK_LABEL(state->label_current_name_buffer), state->name_buffer_new); - if (state->name_type_new == 3) { - gtk_label_set_text(GTK_LABEL(state->label_current_name_type), "Domain:"); - } else { - gtk_label_set_text(GTK_LABEL(state->label_current_name_type), "Workgroup:"); - } - } -} - -static void callback_return_username(GtkWidget *widget, - gpointer data) -{ - const gchar *entry_text; - struct join_state *state = (struct join_state *)data; - if (!widget) { - return; - } - entry_text = gtk_entry_get_text(GTK_ENTRY(widget)); - debug("callback_return_username: %s\n", entry_text); - SAFE_FREE(state->account); - state->account = strdup(entry_text); -} - -static void callback_return_username_and_enter(GtkWidget *widget, - gpointer data) -{ - const gchar *entry_text; - struct join_state *state = (struct join_state *)data; - if (!widget) { - return; - } - entry_text = gtk_entry_get_text(GTK_ENTRY(widget)); - debug("callback_return_username: %s\n", entry_text); - SAFE_FREE(state->account); - state->account = strdup(entry_text); - g_signal_emit_by_name(state->button_ok_creds, "clicked"); -} - -static void callback_return_password(GtkWidget *widget, - gpointer data) -{ - const gchar *entry_text; - struct join_state *state = (struct join_state *)data; - if (!widget) { - return; - } - entry_text = gtk_entry_get_text(GTK_ENTRY(widget)); -#ifdef DEBUG_PASSWORD - debug("callback_return_password: %s\n", entry_text); -#else - debug("callback_return_password: (not printed)\n"); -#endif - SAFE_FREE(state->password); - state->password = strdup(entry_text); -} - -static void callback_return_password_and_enter(GtkWidget *widget, - gpointer data) -{ - const gchar *entry_text; - struct join_state *state = (struct join_state *)data; - if (!widget) { - return; - } - entry_text = gtk_entry_get_text(GTK_ENTRY(widget)); -#ifdef DEBUG_PASSWORD - debug("callback_return_password: %s\n", entry_text); -#else - debug("callback_return_password: (not printed)\n"); -#endif - SAFE_FREE(state->password); - state->password = strdup(entry_text); - g_signal_emit_by_name(state->button_ok_creds, "clicked"); -} - -static void callback_do_hostname_change(GtkWidget *widget, - gpointer data) -{ - GtkWidget *dialog; - const char *str = NULL; - - struct join_state *state = (struct join_state *)data; - - switch (state->name_type_initial) { - case NetSetupDomainName: - str = "To be implemented: call NetRenameMachineInDomain\n"; - break; - case NetSetupWorkgroupName: - str = "To be implemented: call SetComputerNameEx\n"; - break; - default: - break; - } - - dialog = gtk_message_dialog_new(GTK_WINDOW(state->window_parent), - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_ERROR, - GTK_BUTTONS_CLOSE, - str); - - g_signal_connect_swapped(dialog, "response", - G_CALLBACK(gtk_widget_destroy), - dialog); - gtk_widget_show(dialog); -} - -static void callback_do_join(GtkWidget *widget, - gpointer data) -{ - GtkWidget *dialog; - - NET_API_STATUS status; - const char *err_str = NULL; - uint32_t join_flags = 0; - uint32_t unjoin_flags = 0; - gboolean domain_join = FALSE; - gboolean try_unjoin = FALSE; - const char *domain_or_workgroup = NULL; - - struct join_state *state = (struct join_state *)data; - - callback_return_username(state->entry_account, state); - callback_return_password(state->entry_password, state); - - if (state->window_creds_prompt) { - gtk_widget_destroy(GTK_WIDGET(state->window_creds_prompt)); - } - - if (state->name_type_new == NetSetupDomainName) { - domain_join = TRUE; - join_flags = WKSSVC_JOIN_FLAGS_JOIN_TYPE | - WKSSVC_JOIN_FLAGS_ACCOUNT_CREATE | - WKSSVC_JOIN_FLAGS_DOMAIN_JOIN_IF_JOINED; /* for testing */ - domain_or_workgroup = "domain"; - } else { - domain_or_workgroup = "workgroup"; - } - - if ((state->name_type_initial == NetSetupDomainName) && - (state->name_type_new == NetSetupWorkgroupName)) { - try_unjoin = TRUE; - unjoin_flags = WKSSVC_JOIN_FLAGS_JOIN_TYPE | - WKSSVC_JOIN_FLAGS_ACCOUNT_DELETE; - } - - debug("callback_do_join: Joining a %s named %s using join_flags 0x%08x ", - domain_or_workgroup, - state->name_buffer_new, - join_flags); - if (domain_join) { - debug("as %s ", state->account); -#ifdef DEBUG_PASSWORD - debug("with %s ", state->password); -#endif - } - debug("\n"); - if (try_unjoin) { - - debug("callback_do_join: Unjoining\n"); - - status = NetUnjoinDomain(NULL, - state->account, - state->password, - unjoin_flags); - if (status != 0) { - err_str = libnetapi_errstr(state->ctx, status); - g_print("callback_do_join: failed to unjoin (%s)\n", - err_str); - - dialog = gtk_message_dialog_new(GTK_WINDOW(state->window_parent), - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_ERROR, - GTK_BUTTONS_CLOSE, - "The following error occured attempting to unjoin the %s: \"%s\": %s", - domain_or_workgroup, - state->name_buffer_new, - err_str); - - g_signal_connect_swapped(dialog, "response", - G_CALLBACK(gtk_widget_destroy), - dialog); - - gtk_widget_show(dialog); - - return; - } - - } - status = NetJoinDomain(NULL, - state->name_buffer_new, - NULL, - state->account, - state->password, - join_flags); - if (status != 0) { - err_str = libnetapi_errstr(state->ctx, status); - g_print("callback_do_join: failed to join (%s)\n", err_str); - - dialog = gtk_message_dialog_new(GTK_WINDOW(state->window_parent), - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_ERROR, - GTK_BUTTONS_CLOSE, - "The following error occured attempting to join the %s: \"%s\": %s", - domain_or_workgroup, - state->name_buffer_new, - err_str); - - g_signal_connect_swapped(dialog, "response", - G_CALLBACK(gtk_widget_destroy), - dialog); - - gtk_widget_show(dialog); - - return; - } - - debug("callback_do_join: Successfully joined %s\n", - domain_or_workgroup); - - dialog = gtk_message_dialog_new(GTK_WINDOW(state->window_parent), - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_INFO, - GTK_BUTTONS_OK, - "Welcome to the %s %s.", - state->name_buffer_new, - domain_or_workgroup); - - gtk_dialog_run(GTK_DIALOG(dialog)); - gtk_widget_destroy(dialog); - - callback_do_reboot(NULL, state->window_parent, state); -} - -static void callback_creds_prompt(GtkWidget *widget, - gpointer data) -{ - GtkWidget *window; - GtkWidget *box1; - GtkWidget *bbox; - GtkWidget *button; - GtkWidget *label; - - struct join_state *state = (struct join_state *)data; - - debug("callback_creds_prompt:\n"); - - state->window_parent = state->window_do_change; - - if (state->hostname_changed) { - return callback_do_hostname_change(NULL, state); - } - - if ((state->name_type_initial != NetSetupDomainName) && - (state->name_type_new != NetSetupDomainName)) { - return callback_do_join(NULL, state); - } - - window = gtk_window_new(GTK_WINDOW_TOPLEVEL); - - gtk_window_set_title(GTK_WINDOW(window), "Computer Name Changes"); - gtk_window_set_resizable(GTK_WINDOW(window), FALSE); - gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER); - gtk_widget_set_size_request(GTK_WIDGET(window), 380, 280); - gtk_window_set_icon_from_file(GTK_WINDOW(window), SAMBA_ICON_PATH, NULL); -/* gtk_window_set_icon_name(GTK_WIDGET(window), GTK_STOCK_DIALOG_AUTHENTICATION); */ - state->window_creds_prompt = window; - - g_signal_connect(G_OBJECT(window), "delete_event", - G_CALLBACK(callback_do_close), window); - - gtk_container_set_border_width(GTK_CONTAINER(window), 10); - - box1 = gtk_vbox_new(FALSE, 0); - - gtk_container_add(GTK_CONTAINER(window), box1); - - if ((state->name_type_initial == NetSetupDomainName) && - (state->name_type_new == NetSetupWorkgroupName)) { - label = gtk_label_new("Enter the name and password of an account with permission to leave the domain.\n"); - } else { - label = gtk_label_new("Enter the name and password of an account with permission to join the domain.\n"); - } - gtk_misc_set_alignment(GTK_MISC(label), 0, 0); - gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); - - gtk_box_pack_start(GTK_BOX(box1), label, FALSE, FALSE, 0); - - gtk_widget_show(label); - - /* USER NAME */ - label = gtk_label_new("User name:"); - gtk_misc_set_alignment(GTK_MISC(label), 0, 0); - gtk_box_pack_start(GTK_BOX(box1), label, FALSE, FALSE, 0); - gtk_widget_show(label); - - state->entry_account = gtk_entry_new(); - gtk_entry_set_max_length(GTK_ENTRY(state->entry_account), MAX_CRED_LEN); - g_signal_connect(G_OBJECT(state->entry_account), "activate", - G_CALLBACK(callback_return_username_and_enter), - (gpointer)state); - gtk_editable_select_region(GTK_EDITABLE(state->entry_account), - 0, GTK_ENTRY(state->entry_account)->text_length); - gtk_box_pack_start(GTK_BOX(box1), state->entry_account, TRUE, TRUE, 0); - gtk_widget_show(state->entry_account); - - /* PASSWORD */ - label = gtk_label_new("Password:"); - gtk_misc_set_alignment(GTK_MISC(label), 0, 0); - gtk_box_pack_start(GTK_BOX(box1), label, FALSE, FALSE, 0); - gtk_widget_show(label); - - state->entry_password = gtk_entry_new(); - gtk_entry_set_max_length(GTK_ENTRY(state->entry_password), MAX_CRED_LEN); - gtk_entry_set_visibility(GTK_ENTRY(state->entry_password), FALSE); - g_signal_connect(G_OBJECT(state->entry_password), "activate", - G_CALLBACK(callback_return_password_and_enter), - (gpointer)state); - gtk_editable_set_editable(GTK_EDITABLE(state->entry_password), TRUE); - gtk_editable_select_region(GTK_EDITABLE(state->entry_password), - 0, GTK_ENTRY(state->entry_password)->text_length); - gtk_box_pack_start(GTK_BOX(box1), state->entry_password, TRUE, TRUE, 0); - gtk_widget_show(state->entry_password); - - bbox = gtk_hbutton_box_new(); - gtk_container_set_border_width(GTK_CONTAINER(bbox), 5); - gtk_container_add(GTK_CONTAINER(box1), bbox); - gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); - gtk_box_set_spacing(GTK_BOX(bbox), 10); - - state->button_ok_creds = gtk_button_new_from_stock(GTK_STOCK_OK); - gtk_widget_grab_focus(GTK_WIDGET(state->button_ok_creds)); - gtk_container_add(GTK_CONTAINER(bbox), state->button_ok_creds); - g_signal_connect(G_OBJECT(state->button_ok_creds), "clicked", - G_CALLBACK(callback_do_join), - (gpointer)state); - gtk_widget_show(state->button_ok_creds); - - button = gtk_button_new_from_stock(GTK_STOCK_CANCEL); - gtk_container_add(GTK_CONTAINER(bbox), button); - g_signal_connect(G_OBJECT(button), "clicked", - G_CALLBACK(callback_do_close), (gpointer) window); - gtk_widget_show_all(window); -} - -static void callback_enter_hostname_and_unlock(GtkWidget *widget, - gpointer data) -{ - const gchar *entry_text = NULL; - char *str = NULL; - struct join_state *state = (struct join_state *)data; - - entry_text = gtk_entry_get_text(GTK_ENTRY(widget)); - debug("callback_enter_hostname_and_unlock: %s\n", entry_text); - if (!entry_text || entry_text[0] == 0) { - state->hostname_changed = FALSE; - gtk_widget_set_sensitive(GTK_WIDGET(state->button_ok), FALSE); - return; - } - if (strcasecmp(state->my_hostname, entry_text) == 0) { - state->hostname_changed = FALSE; - gtk_widget_set_sensitive(GTK_WIDGET(state->button_ok), FALSE); - return; - } - state->hostname_changed = TRUE; - if (state->name_type_initial == NetSetupDomainName) { - asprintf(&str, "%s.%s", entry_text, state->my_dnsdomain); - } else { - asprintf(&str, "%s.", entry_text); - } - gtk_label_set_text(GTK_LABEL(state->label_full_computer_name), str); - free(str); - - if (state->hostname_changed && str && str[0] != 0 && str[0] != '.') { - gtk_widget_set_sensitive(GTK_WIDGET(state->button_ok), TRUE); - } -} - -static void callback_enter_computer_description_and_unlock(GtkWidget *widget, - gpointer data) -{ - const gchar *entry_text = NULL; - struct join_state *state = (struct join_state *)data; - int string_unchanged = 0; - - entry_text = gtk_entry_get_text(GTK_ENTRY(widget)); - debug("callback_enter_computer_description_and_unlock: %s\n", - entry_text); -#if 0 - if (!entry_text || entry_text[0] == 0) { - string_unchanged = 1; - gtk_widget_set_sensitive(GTK_WIDGET(state->button_apply), - FALSE); - return; - } -#endif - if (entry_text && strcasecmp(state->comment, entry_text) == 0) { - string_unchanged = 1; - gtk_widget_set_sensitive(GTK_WIDGET(state->button_apply), - FALSE); - return; - } - - gtk_widget_set_sensitive(GTK_WIDGET(state->button_apply), TRUE); - SAFE_FREE(state->comment_new); - state->comment_new = strdup(entry_text); - -} - - -static void callback_enter_workgroup_and_unlock(GtkWidget *widget, - gpointer data) -{ - const gchar *entry_text = NULL; - struct join_state *state = (struct join_state *)data; - - entry_text = gtk_entry_get_text(GTK_ENTRY(widget)); - debug("callback_enter_workgroup_and_unlock: %s\n", entry_text); - if (!entry_text || entry_text[0] == 0) { - gtk_widget_set_sensitive(GTK_WIDGET(state->button_ok), FALSE); - return; - } - if (strcasecmp(state->name_buffer_initial, entry_text) == 0) { - gtk_widget_set_sensitive(GTK_WIDGET(state->button_ok), FALSE); - return; - } - gtk_widget_set_sensitive(GTK_WIDGET(state->button_ok), TRUE); - SAFE_FREE(state->name_buffer_new); - state->name_buffer_new = strdup(entry_text); - state->name_type_new = NetSetupWorkgroupName; -} - -static void callback_enter_domain_and_unlock(GtkWidget *widget, - gpointer data) -{ - const gchar *entry_text = NULL; - struct join_state *state = (struct join_state *)data; - - entry_text = gtk_entry_get_text(GTK_ENTRY(widget)); - debug("callback_enter_domain_and_unlock: %s\n", entry_text); - if (!entry_text || entry_text[0] == 0) { - gtk_widget_set_sensitive(GTK_WIDGET(state->button_ok), FALSE); - return; - } - if (strcasecmp(state->name_buffer_initial, entry_text) == 0) { - gtk_widget_set_sensitive(GTK_WIDGET(state->button_ok), FALSE); - return; - } - gtk_widget_set_sensitive(GTK_WIDGET(state->button_ok), TRUE); - SAFE_FREE(state->name_buffer_new); - state->name_buffer_new = strdup(entry_text); - state->name_type_new = NetSetupDomainName; -} - -static void callback_continue(GtkWidget *widget, - gpointer data) -{ - struct join_state *state = (struct join_state *)data; - - gtk_widget_grab_focus(GTK_WIDGET(state->button_ok)); - g_signal_emit_by_name(state->button_ok, "clicked"); -} - -static void callback_apply_continue(GtkWidget *widget, - gpointer data) -{ - struct join_state *state = (struct join_state *)data; - - gtk_widget_grab_focus(GTK_WIDGET(state->button_apply)); - g_signal_emit_by_name(state->button_apply, "clicked"); -} - -static void callback_do_join_workgroup(GtkWidget *widget, - gpointer data) -{ - struct join_state *state = (struct join_state *)data; - debug("callback_do_join_workgroup choosen\n"); - gtk_widget_set_sensitive(GTK_WIDGET(state->entry_workgroup), TRUE); - gtk_widget_grab_focus(GTK_WIDGET(state->entry_workgroup)); - gtk_widget_set_sensitive(GTK_WIDGET(state->entry_domain), FALSE); - callback_enter_workgroup_and_unlock(state->entry_workgroup, state); /* TEST */ -} - -static void callback_do_join_domain(GtkWidget *widget, - gpointer data) -{ - struct join_state *state = (struct join_state *)data; - debug("callback_do_join_domain choosen\n"); - gtk_widget_set_sensitive(GTK_WIDGET(state->entry_domain), TRUE); - gtk_widget_grab_focus(GTK_WIDGET(state->entry_domain)); - gtk_widget_set_sensitive(GTK_WIDGET(state->entry_workgroup), FALSE); - callback_enter_domain_and_unlock(state->entry_domain, state); /* TEST */ -} - -static void callback_do_change(GtkWidget *widget, - gpointer data) -{ - GtkWidget *window; - GtkWidget *box1; - GtkWidget *bbox; - GtkWidget *button_workgroup; - GtkWidget *button_domain; - GtkWidget *button; - GtkWidget *label; - GtkWidget *frame_horz; - GtkWidget *vbox; - GtkWidget *entry; - GSList *group; - - struct join_state *state = (struct join_state *)data; - - debug("callback_do_change called\n"); - - if (state->server_role == 3) { - GtkWidget *dialog; - dialog = gtk_message_dialog_new(GTK_WINDOW(state->window_main), - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_ERROR, - GTK_BUTTONS_OK, - "Domain controller cannot be moved from one domain to another, they must first be demoted. Renaming this domain controller may cause it to become temporarily unavailable to users and computers. For information on renaming domain controllers, including alternate renaming methods, see Help and Support. To continue renaming this domain controller, click OK."); - g_signal_connect_swapped(dialog, "response", - G_CALLBACK(gtk_widget_destroy), - dialog); - - gtk_widget_show(dialog); - return; - } - - state->button_ok = gtk_button_new_from_stock(GTK_STOCK_OK); - window = gtk_window_new(GTK_WINDOW_TOPLEVEL); - - gtk_window_set_title(GTK_WINDOW(window), "Computer Name Changes"); - gtk_window_set_resizable(GTK_WINDOW(window), FALSE); - gtk_widget_set_size_request(GTK_WIDGET(window), 480, 500); /* breite * höhe */ - gtk_window_set_icon_from_file(GTK_WINDOW(window), SAMBA_ICON_PATH, NULL); - - g_signal_connect(G_OBJECT(window), "delete_event", - G_CALLBACK(callback_do_close), window); - - gtk_container_set_border_width(GTK_CONTAINER(window), 10); - - box1 = gtk_vbox_new(FALSE, 0); - gtk_container_add(GTK_CONTAINER(window), box1); - - label = gtk_label_new("You can change the name and membership of this computer. Changes may affect access to network ressources."); - gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); - gtk_misc_set_alignment(GTK_MISC(label), 0, 0); - gtk_box_pack_start(GTK_BOX(box1), label, TRUE, TRUE, 0); - gtk_widget_show(label); - - /* COMPUTER NAME */ - label = gtk_label_new("Computer name:"); - gtk_misc_set_alignment(GTK_MISC(label), 0, 0); - gtk_box_pack_start(GTK_BOX(box1), label, TRUE, TRUE, 0); - gtk_widget_show(label); - - state->label_full_computer_name = gtk_label_new(NULL); - { - entry = gtk_entry_new(); - gtk_entry_set_max_length(GTK_ENTRY(entry), MAX_NETBIOS_NAME_LEN); - g_signal_connect(G_OBJECT(entry), "changed", - G_CALLBACK(callback_enter_hostname_and_unlock), - (gpointer)state); - gtk_entry_set_text(GTK_ENTRY(entry), state->my_hostname); - gtk_editable_select_region(GTK_EDITABLE(entry), - 0, GTK_ENTRY(entry)->text_length); - - gtk_editable_set_editable(GTK_EDITABLE(entry), TRUE); /* ! */ - gtk_box_pack_start(GTK_BOX(box1), entry, TRUE, TRUE, 0); - gtk_widget_show(entry); - } - - /* FULL COMPUTER NAME */ - label = gtk_label_new("Full computer name:"); - gtk_misc_set_alignment(GTK_MISC(label), 0, 0); - gtk_box_pack_start(GTK_BOX(box1), label, TRUE, TRUE, 0); - gtk_widget_show(label); - - { - const gchar *entry_text; - char *str = NULL; - entry_text = gtk_entry_get_text(GTK_ENTRY(entry)); - if (state->name_type_initial == NetSetupDomainName) { - asprintf(&str, "%s.%s", entry_text, state->my_dnsdomain); - } else { - asprintf(&str, "%s.", entry_text); - } - gtk_label_set_text(GTK_LABEL(state->label_full_computer_name), str); - free(str); - gtk_misc_set_alignment(GTK_MISC(state->label_full_computer_name), 0, 0); - gtk_box_pack_start(GTK_BOX(box1), state->label_full_computer_name, TRUE, TRUE, 0); - gtk_widget_show(state->label_full_computer_name); - } - - /* BOX */ - frame_horz = gtk_frame_new ("Member Of"); - gtk_box_pack_start(GTK_BOX(box1), frame_horz, TRUE, TRUE, 10); - - vbox = gtk_vbox_new(FALSE, 0); - gtk_container_set_border_width(GTK_CONTAINER(vbox), 10); - gtk_container_add(GTK_CONTAINER(frame_horz), vbox); - - /* TWO ENTRIES */ - state->entry_workgroup = gtk_entry_new(); - state->entry_domain = gtk_entry_new(); - - /* DOMAIN */ - button_domain = gtk_radio_button_new_with_label(NULL, "Domain"); - if (state->name_type_initial == NetSetupDomainName) { - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button_domain), TRUE); - } - gtk_box_pack_start(GTK_BOX(vbox), button_domain, TRUE, TRUE, 0); - g_signal_connect(G_OBJECT(button_domain), "clicked", - G_CALLBACK(callback_do_join_domain), - (gpointer)state); - - { - gtk_entry_set_max_length(GTK_ENTRY(state->entry_domain), 50); - g_signal_connect(G_OBJECT(state->entry_domain), "changed", - G_CALLBACK(callback_enter_domain_and_unlock), - (gpointer)state); - g_signal_connect(G_OBJECT(state->entry_domain), "activate", - G_CALLBACK(callback_continue), - (gpointer)state); - if (state->name_type_initial == NetSetupDomainName) { - gtk_entry_set_text(GTK_ENTRY(state->entry_domain), state->name_buffer_initial); - gtk_widget_set_sensitive(state->entry_workgroup, FALSE); - gtk_widget_set_sensitive(state->entry_domain, TRUE); - } - gtk_editable_set_editable(GTK_EDITABLE(state->entry_domain), TRUE); - gtk_box_pack_start(GTK_BOX(vbox), state->entry_domain, TRUE, TRUE, 0); - gtk_widget_show(state->entry_domain); - } - gtk_widget_show(button_domain); - - /* WORKGROUP */ - group = gtk_radio_button_get_group(GTK_RADIO_BUTTON(button_domain)); - button_workgroup = gtk_radio_button_new_with_label(group, "Workgroup"); - if (state->name_type_initial == NetSetupWorkgroupName) { - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button_workgroup), TRUE); - } - gtk_box_pack_start(GTK_BOX(vbox), button_workgroup, TRUE, TRUE, 0); - g_signal_connect(G_OBJECT(button_workgroup), "clicked", - G_CALLBACK(callback_do_join_workgroup), - (gpointer)state); - { - gtk_entry_set_max_length(GTK_ENTRY(state->entry_workgroup), MAX_NETBIOS_NAME_LEN); - g_signal_connect(G_OBJECT(state->entry_workgroup), "changed", - G_CALLBACK(callback_enter_workgroup_and_unlock), - (gpointer)state); - g_signal_connect(G_OBJECT(state->entry_workgroup), "activate", - G_CALLBACK(callback_continue), - (gpointer)state); - - if (state->name_type_initial == NetSetupWorkgroupName) { - gtk_entry_set_text(GTK_ENTRY(state->entry_workgroup), state->name_buffer_initial); - gtk_widget_set_sensitive(GTK_WIDGET(state->entry_domain), FALSE); - gtk_widget_set_sensitive(GTK_WIDGET(state->entry_workgroup), TRUE); - } - gtk_box_pack_start(GTK_BOX(vbox), state->entry_workgroup, TRUE, TRUE, 0); - gtk_widget_show(state->entry_workgroup); - } - gtk_widget_show(button_workgroup); - - /* BUTTONS */ - bbox = gtk_hbutton_box_new(); - gtk_container_set_border_width(GTK_CONTAINER(bbox), 5); - gtk_container_add(GTK_CONTAINER(box1), bbox); - gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); - gtk_box_set_spacing(GTK_BOX(bbox), 10); - - state->window_do_change = window; - gtk_widget_set_sensitive(GTK_WIDGET(state->button_ok), FALSE); /* !!! */ - gtk_container_add(GTK_CONTAINER(bbox), state->button_ok); - g_signal_connect(G_OBJECT(state->button_ok), "clicked", - G_CALLBACK(callback_creds_prompt), - (gpointer)state); - - button = gtk_button_new_from_stock(GTK_STOCK_CANCEL); - gtk_container_add(GTK_CONTAINER(bbox), button); - g_signal_connect(G_OBJECT(button), "clicked", - G_CALLBACK(callback_do_close), - (gpointer)window); - - gtk_widget_show_all(window); - -} - -static void callback_do_about(GtkWidget *widget, - gpointer data) -{ - GdkPixbuf *logo; - GError *error = NULL; - - debug("callback_do_about called\n"); - - logo = gdk_pixbuf_new_from_file(SAMBA_IMAGE_PATH, - &error); - if (logo == NULL) { - g_print("failed to load logo from %s: %s\n", - SAMBA_IMAGE_PATH, error->message); - } - - gtk_show_about_dialog(data, - "name", "Samba", - "version", "3.2.0pre2-GIT-904a90-test", - "copyright", "Copyright Andrew Tridgell and the Samba Team 1992-2007", - "website", "http://www.samba.org", - "license", "GPLv3", - "logo", logo, - "comments", "Samba gtk domain join utility", - NULL); -} - -static int draw_main_window(struct join_state *state) -{ - GtkWidget *window; - GtkWidget *button; - GtkWidget *label; - GtkWidget *main_vbox; - GtkWidget *vbox; - GtkWidget *hbox; - GtkWidget *bbox; - GtkWidget *image; - GtkWidget *table; - GtkWidget *entry; - GdkPixbuf *icon; - GError *error = NULL; - - icon = gdk_pixbuf_new_from_file(SAMBA_ICON_PATH, - &error); - if (icon == NULL) { - g_print("failed to load logo from %s : %s\n", - SAMBA_ICON_PATH, error->message); - } - -#if 1 - image = gtk_image_new_from_file(SAMBA_IMAGE_PATH); -#else - image = gtk_image_new_from_file("/usr/share/pixmaps/redhat-system_settings.png"); -#endif - - window = gtk_window_new(GTK_WINDOW_TOPLEVEL); - state->window_main = window; - - gtk_window_set_title(GTK_WINDOW(window), "Samba - Join Domain dialogue"); - gtk_widget_set_size_request(GTK_WIDGET(window), 600, 600); /* breite * höhe */ - gtk_window_set_resizable(GTK_WINDOW(window), FALSE); - gtk_window_set_icon_from_file(GTK_WINDOW(window), SAMBA_ICON_PATH, NULL); - - g_signal_connect(G_OBJECT(window), "delete_event", - G_CALLBACK(callback_delete_event), NULL); - - gtk_container_set_border_width(GTK_CONTAINER(window), 10); - - main_vbox = gtk_vbox_new(FALSE, 10); - gtk_container_add(GTK_CONTAINER(window), main_vbox); - -#if 0 - gtk_box_pack_start(GTK_BOX(main_vbox), image, TRUE, TRUE, 10); - gtk_widget_show(image); -#endif - /* Hbox */ - hbox = gtk_hbox_new(FALSE, 10); - gtk_container_add(GTK_CONTAINER(main_vbox), hbox); - - { -/* gtk_box_pack_start(GTK_BOX(main_vbox), image, TRUE, TRUE, 10); */ - gtk_misc_set_alignment(GTK_MISC(image), 0, 0); - gtk_box_pack_start(GTK_BOX(hbox), image, FALSE, FALSE, 10); - gtk_widget_show(image); - - /* Label */ - label = gtk_label_new("Samba uses the following information to identify your computer on the network."); - gtk_misc_set_alignment(GTK_MISC(label), 0, 0); - gtk_widget_set_size_request(GTK_WIDGET(label), 500, 40); - gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); - gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); - gtk_widget_show(label); - } - - gtk_widget_show(hbox); - - vbox = gtk_vbox_new(FALSE, 0); - gtk_container_set_border_width(GTK_CONTAINER(vbox), 10); - gtk_container_add(GTK_CONTAINER(main_vbox), vbox); - - /* Table */ - table = gtk_table_new(6, 3, TRUE); - gtk_table_set_row_spacings(GTK_TABLE(table), 5); - gtk_table_set_col_spacings(GTK_TABLE(table), 5); - gtk_container_add(GTK_CONTAINER(vbox), table); - - { - /* Label */ - label = gtk_label_new("Computer description:"); -/* gtk_misc_set_alignment(GTK_MISC(label), 0, 0); */ - gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 0, 1); - gtk_widget_show(label); - - state->button_apply = gtk_button_new_from_stock(GTK_STOCK_APPLY); - - /* Entry */ - entry = gtk_entry_new(); - gtk_entry_set_max_length(GTK_ENTRY(entry), 256); - g_signal_connect(G_OBJECT(entry), "changed", - G_CALLBACK(callback_enter_computer_description_and_unlock), - state); - g_signal_connect(G_OBJECT(entry), "activate", - G_CALLBACK(callback_apply_continue), - (gpointer)state); - - gtk_entry_set_text(GTK_ENTRY(entry), (char *)state->comment); - gtk_editable_set_editable(GTK_EDITABLE(entry), TRUE); /* ! */ - gtk_table_attach_defaults(GTK_TABLE(table), entry, 1, 3, 0, 1); - gtk_widget_show(entry); - } - - /* Label */ - label = gtk_label_new("For example: \"Samba \%v\"."); - gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); - gtk_misc_set_alignment(GTK_MISC(label), 0, 0); - gtk_table_attach_defaults(GTK_TABLE(table), label, 1, 3, 1, 2); - gtk_widget_show(label); - - /* Label */ - label = gtk_label_new("Full computer name:"); - gtk_misc_set_alignment(GTK_MISC(label), 0, 0); - gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 2, 3); - gtk_widget_show(label); - - { - /* Label */ - char *str = NULL; - if (state->name_type_initial == NetSetupDomainName) { - asprintf(&str, "%s.%s", state->my_hostname, - state->my_dnsdomain); - } else { - asprintf(&str, "%s.", state->my_hostname); - } - - label = gtk_label_new(str); - SAFE_FREE(str); - gtk_misc_set_alignment(GTK_MISC(label), 0, 0); - gtk_table_attach_defaults(GTK_TABLE(table), label, 1, 3, 2, 3); - gtk_widget_show(label); - } - - /* Label */ - if (state->name_type_initial == NetSetupDomainName) { - label = gtk_label_new("Domain:"); - } else { - label = gtk_label_new("Workgroup:"); - } - gtk_misc_set_alignment(GTK_MISC(label), 0, 0); - gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 3, 4); - gtk_widget_show(label); - state->label_current_name_type = label; - - /* Label */ - label = gtk_label_new(state->name_buffer_initial); - gtk_misc_set_alignment(GTK_MISC(label), 0, 0); - gtk_table_attach_defaults(GTK_TABLE(table), label, 1, 3, 3, 4); - gtk_widget_show(label); - state->label_current_name_buffer = label; - - { - hbox = gtk_hbox_new(FALSE, 0); - gtk_container_add(GTK_CONTAINER(vbox), hbox); - label = gtk_label_new("To rename this computer or join a domain, click Change."); - gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); - - - } - - /* bbox */ - bbox = gtk_hbutton_box_new(); - gtk_container_set_border_width(GTK_CONTAINER(bbox), 5); - gtk_container_add(GTK_CONTAINER(hbox), bbox); - gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); - gtk_box_set_spacing(GTK_BOX(bbox), 10); - - button = gtk_button_new_with_mnemonic("Ch_ange"); - g_signal_connect(G_OBJECT(button), "clicked", - G_CALLBACK(callback_do_change), - (gpointer)state); - gtk_box_pack_start(GTK_BOX(bbox), button, TRUE, TRUE, 0); - gtk_widget_show(button); - - /* Label (hidden) */ - state->label_reboot = gtk_label_new(NULL); - gtk_label_set_line_wrap(GTK_LABEL(state->label_reboot), TRUE); - gtk_misc_set_alignment(GTK_MISC(state->label_reboot), 0, 0); - gtk_box_pack_start(GTK_BOX(vbox), state->label_reboot, TRUE, TRUE, 0); - gtk_widget_show(state->label_reboot); - -#if 0 - gtk_box_pack_start(GTK_BOX(vbox), - create_bbox(window, TRUE, NULL, 10, 85, 20, GTK_BUTTONBOX_END), - TRUE, TRUE, 5); -#endif - { - - GtkWidget *frame; - GtkWidget *bbox2; - GtkWidget *button2; - - frame = gtk_frame_new(NULL); - bbox2 = gtk_hbutton_box_new(); - - gtk_container_set_border_width(GTK_CONTAINER(bbox2), 5); - gtk_container_add(GTK_CONTAINER(frame), bbox2); - - /* Set the appearance of the Button Box */ - gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox2), GTK_BUTTONBOX_END); - gtk_box_set_spacing(GTK_BOX(bbox2), 10); - /*gtk_button_box_set_child_size(GTK_BUTTON_BOX(bbox2), child_w, child_h);*/ - - button2 = gtk_button_new_from_stock(GTK_STOCK_OK); - gtk_container_add(GTK_CONTAINER(bbox2), button2); - g_signal_connect(G_OBJECT(button2), "clicked", G_CALLBACK(callback_do_exit), state); - - button2 = gtk_button_new_from_stock(GTK_STOCK_CANCEL); - gtk_container_add(GTK_CONTAINER(bbox2), button2); - g_signal_connect(G_OBJECT(button2), "clicked", - G_CALLBACK(callback_delete_event), - window); - - gtk_container_add(GTK_CONTAINER(bbox2), state->button_apply); - g_signal_connect(G_OBJECT(state->button_apply), "clicked", - G_CALLBACK(callback_apply_description_change), - state); - gtk_widget_set_sensitive(GTK_WIDGET(state->button_apply), FALSE); - - button2 = gtk_button_new_from_stock(GTK_STOCK_ABOUT); - gtk_container_add(GTK_CONTAINER(bbox2), button2); - g_signal_connect(G_OBJECT(button2), "clicked", - G_CALLBACK(callback_do_about), - window); - - gtk_box_pack_start(GTK_BOX(vbox), frame, TRUE, TRUE, 5); - } - - gtk_widget_show_all(window); - - return 0; -} - -static int init_join_state(struct join_state **state) -{ - struct join_state *s; - - s = malloc(sizeof(struct join_state)); - if (!s) { - return -1; - } - - memset(s, '\0', sizeof(struct join_state)); - - *state = s; - - return 0; -} - -static int initialize_join_state(struct join_state *state, - const char *debug_level) -{ - struct libnetapi_ctx *ctx = NULL; - NET_API_STATUS status = 0; - - status = libnetapi_init(&ctx); - if (status) { - return status; - } - - if (debug_level) { - libnetapi_set_debuglevel(ctx, debug_level); - } - - { - char my_hostname[HOST_NAME_MAX]; - const char *p = NULL; - if (gethostname(my_hostname, sizeof(my_hostname)) == -1) { - return -1; - } - - state->my_fqdn = strdup(my_hostname); - if (!state->my_fqdn) { - return -1; - } - - p = strchr(my_hostname, '.'); - if (p) { - my_hostname[strlen(my_hostname) - strlen(p)] = '\0'; - state->my_hostname = strdup(my_hostname); - if (!state->my_hostname) { - return -1; - } - p++; - state->my_dnsdomain = strdup(p); - if (!state->my_dnsdomain) { - return -1; - } - } - } - - { - const char *buffer = NULL; - uint16_t type = 0; - status = NetGetJoinInformation(NULL, &buffer, &type); - if (status) { - return status; - } - state->name_buffer_initial = (char *)buffer; - state->name_type_initial = type; - } - - { - struct srvsvc_NetSrvInfo1005 *info1005 = NULL; - uint8_t *buffer = NULL; - - status = NetServerGetInfo(NULL, 1005, &buffer); - if (status) { - return status; - } - - info1005 = (struct srvsvc_NetSrvInfo1005 *)buffer; - - state->comment = strdup(info1005->comment); - if (!state->comment) { - return -1; - } - } -#if 0 - { - struct srvsvc_NetSrvInfo100 *info100 = NULL; - uint8_t *buffer = NULL; - - status = NetServerGetInfo(NULL, 100, &buffer); - if (status) { - return status; - } - - info100 = (struct srvsvc_NetSrvInfo100 *)buffer; - - state->comment = strdup(info100->comment); - if (!state->comment) { - return -1; - } - } -#endif - - state->ctx = ctx; - - return 0; -} - -int main(int argc, char **argv) -{ - GOptionContext *context = NULL; - static const char *debug_level = NULL; - struct join_state *state = NULL; - GError *error = NULL; - int ret = 0; - - static GOptionEntry entries[] = { - { "debug", 'd', 0, G_OPTION_ARG_STRING, &debug_level, "Debug level (for samba)", "N" }, - { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, "Verbose output", 0 }, - { NULL } - }; - - context = g_option_context_new("- Samba domain join utility"); - g_option_context_add_main_entries(context, entries, NULL); -/* g_option_context_add_main_entries(context, entries, GETTEXT_PACKAGE); */ - g_option_context_add_group(context, gtk_get_option_group(TRUE)); - g_option_context_parse(context, &argc, &argv, &error); - - gtk_init(&argc, &argv); - g_set_application_name("Samba"); - - ret = init_join_state(&state); - if (ret) { - return ret; - } - - ret = initialize_join_state(state, debug_level); - if (ret) { - return ret; - } - - draw_main_window(state); - - gtk_main(); - - do_cleanup(state); - - return 0; -} diff --git a/source3/lib/netapi/examples/netdomjoin-gui/logo.png b/source3/lib/netapi/examples/netdomjoin-gui/logo.png new file mode 100644 index 0000000000..6df4ace659 Binary files /dev/null and b/source3/lib/netapi/examples/netdomjoin-gui/logo.png differ diff --git a/source3/lib/netapi/examples/netdomjoin-gui/samba.ico b/source3/lib/netapi/examples/netdomjoin-gui/samba.ico new file mode 100755 index 0000000000..b70c9590de Binary files /dev/null and b/source3/lib/netapi/examples/netdomjoin-gui/samba.ico differ diff --git a/source3/lib/netapi/examples/netdomjoin.c b/source3/lib/netapi/examples/netdomjoin.c deleted file mode 100644 index a2bb700250..0000000000 --- a/source3/lib/netapi/examples/netdomjoin.c +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Unix SMB/CIFS implementation. - * Join Support (cmdline + netapi) - * Copyright (C) Guenther Deschner 2007 - * - * 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 - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see . - */ - -#include -#include -#include -#include -#include - -#include - -char *get_string_param(const char *param) -{ - char *p; - - p = strchr(param, '='); - if (!p) { - return NULL; - } - - return (p+1); -} - -int main(int argc, char **argv) -{ - NET_API_STATUS status; - const char *server_name = NULL; - const char *domain_name = NULL; - const char *account_ou = NULL; - const char *Account = NULL; - const char *password = NULL; - uint32_t join_flags = 3; - struct libnetapi_ctx *ctx = NULL; - int i; - - status = libnetapi_init(&ctx); - if (status != 0) { - return status; - } - - if (argc < 2) { - printf("usage: netdomjoin\n"); - printf("\t[hostname=HOSTNAME] [domain=DOMAIN] \n"); - return 0; - } - - if (argc > 2) { - server_name = argv[1]; - } - - for (i=0; i. + */ + +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include + +#include +#include + +#include + +#define MAX_CRED_LEN 256 +#define MAX_NETBIOS_NAME_LEN 15 + +#define SAMBA_ICON_PATH "/usr/share/pixmaps/samba/samba.ico" +#define SAMBA_IMAGE_PATH "/usr/share/pixmaps/samba/logo.png" + +#define WKSSVC_JOIN_FLAGS_DOMAIN_JOIN_IF_JOINED ( 0x00000020 ) +#define WKSSVC_JOIN_FLAGS_ACCOUNT_DELETE ( 0x00000004 ) +#define WKSSVC_JOIN_FLAGS_ACCOUNT_CREATE ( 0x00000002 ) +#define WKSSVC_JOIN_FLAGS_JOIN_TYPE ( 0x00000001 ) + +#define NetSetupWorkgroupName ( 2 ) +#define NetSetupDomainName ( 3 ) + +#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0) + +struct srvsvc_NetSrvInfo1005 { + const char *comment;/* [unique,charset(UTF16)] */ +}; + +static gboolean verbose = FALSE; + +typedef struct join_state { + struct libnetapi_ctx *ctx; + GtkWidget *window_main; + GtkWidget *window_parent; + GtkWidget *window_do_change; + GtkWidget *window_creds_prompt; + GtkWidget *entry_account; + GtkWidget *entry_password; + GtkWidget *entry_domain; + GtkWidget *entry_workgroup; + GtkWidget *button_ok; + GtkWidget *button_apply; + GtkWidget *button_ok_creds; + GtkWidget *label_reboot; + GtkWidget *label_current_name_buffer; + GtkWidget *label_current_name_type; + GtkWidget *label_full_computer_name; + uint16_t name_type_initial; + uint16_t name_type_new; + char *name_buffer_initial; + char *name_buffer_new; + char *password; + char *account; + char *comment; + char *comment_new; + char *my_fqdn; + char *my_dnsdomain; + char *my_hostname; + uint16_t server_role; + gboolean settings_changed; + gboolean hostname_changed; +} join_state; + +static void debug(const char *format, ...) +{ + va_list args; + + if (!verbose) { + return; + } + + va_start(args, format); + g_vprintf(format, args); + va_end(args); +} + +static gboolean callback_delete_event(GtkWidget *widget, + GdkEvent *event, + gpointer data) +{ + gtk_main_quit(); + return FALSE; +} + +static void callback_do_close(GtkWidget *widget, + gpointer data) +{ + debug("Closing now...\n"); + gtk_widget_destroy(data); +} + +static void free_join_state(struct join_state *s) +{ + SAFE_FREE(s->name_buffer_initial); + SAFE_FREE(s->name_buffer_new); + SAFE_FREE(s->password); + SAFE_FREE(s->account); + SAFE_FREE(s->comment); + SAFE_FREE(s->comment_new); + SAFE_FREE(s->my_fqdn); + SAFE_FREE(s->my_dnsdomain); + SAFE_FREE(s->my_hostname); + +} + +static void do_cleanup(struct join_state *state) +{ + libnetapi_free(state->ctx); + free_join_state(state); +} + +static void callback_apply_description_change(GtkWidget *widget, + gpointer data) +{ + struct join_state *state = (struct join_state *)data; + NET_API_STATUS status = 0; + uint32_t parm_err = 0; + struct srvsvc_NetSrvInfo1005 info1005; + GtkWidget *dialog; + + info1005.comment = state->comment_new; + + status = NetServerSetInfo(NULL, 1005, (uint8_t *)&info1005, &parm_err); + if (status) { + debug("NetServerSetInfo failed with: %s\n", + libnetapi_errstr(state->ctx, status)); + dialog = gtk_message_dialog_new(GTK_WINDOW(state->window_main), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR, + GTK_BUTTONS_OK, + "Failed to change computer description: %s.", + libnetapi_errstr(state->ctx, status)); + g_signal_connect_swapped(dialog, "response", + G_CALLBACK(gtk_widget_destroy), + dialog); + + gtk_widget_show(dialog); + return; + } + + gtk_widget_set_sensitive(GTK_WIDGET(state->button_apply), FALSE); +} + +static void callback_do_exit(GtkWidget *widget, + gpointer data) +{ + GtkWidget *dialog; + gint result; + struct join_state *state = (struct join_state *)data; + + if (!state->settings_changed) { + callback_delete_event(NULL, NULL, NULL); + return; + } + + dialog = gtk_message_dialog_new(GTK_WINDOW(state->window_main), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_QUESTION, + GTK_BUTTONS_YES_NO, + "You must restart your computer before the new settings will take effect."); + result = gtk_dialog_run(GTK_DIALOG(dialog)); + switch (result) { + case GTK_RESPONSE_YES: + g_print("would reboot here\n"); + break; + case GTK_RESPONSE_NO: + default: + break; + } + gtk_widget_destroy(dialog); + gtk_widget_destroy(state->window_main); + do_cleanup(state); + exit(0); +} + + +static void callback_do_reboot(GtkWidget *widget, + gpointer data, + gpointer data2) +{ + GtkWidget *dialog; + struct join_state *state = (struct join_state *)data2; + + debug("callback_do_reboot\n"); + + state->settings_changed = TRUE; + dialog = gtk_message_dialog_new(GTK_WINDOW(data), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_INFO, + GTK_BUTTONS_OK, + "You must restart this computer for the changes to take effect."); +#if 0 + g_signal_connect_swapped(dialog, "response", + G_CALLBACK(gtk_widget_destroy), + dialog); + + debug("showing dialog\n"); + gtk_widget_show(dialog); +#else + gtk_dialog_run(GTK_DIALOG(dialog)); + gtk_widget_destroy(dialog); +#endif + + gtk_label_set_text(GTK_LABEL(state->label_reboot), "Changes will take effect after you restart this computer"); + + debug("destroying do_change window\n"); + gtk_widget_destroy(GTK_WIDGET(state->window_do_change)); + + { + uint32_t status; + const char *buffer; + uint16_t type; + + status = NetGetJoinInformation(NULL, &buffer, &type); + if (status != 0) { + g_print("failed to query status\n"); + return; + } + + debug("got new status: %s\n", buffer); +#if 0 + SAFE_FREE(state->name_buffer_new); + state->name_buffer_new = strdup(buffer); + SAFE_FREE(buffer); + state->name_type_new = type; +#endif + gtk_label_set_text(GTK_LABEL(state->label_current_name_buffer), state->name_buffer_new); + if (state->name_type_new == 3) { + gtk_label_set_text(GTK_LABEL(state->label_current_name_type), "Domain:"); + } else { + gtk_label_set_text(GTK_LABEL(state->label_current_name_type), "Workgroup:"); + } + } +} + +static void callback_return_username(GtkWidget *widget, + gpointer data) +{ + const gchar *entry_text; + struct join_state *state = (struct join_state *)data; + if (!widget) { + return; + } + entry_text = gtk_entry_get_text(GTK_ENTRY(widget)); + debug("callback_return_username: %s\n", entry_text); + SAFE_FREE(state->account); + state->account = strdup(entry_text); +} + +static void callback_return_username_and_enter(GtkWidget *widget, + gpointer data) +{ + const gchar *entry_text; + struct join_state *state = (struct join_state *)data; + if (!widget) { + return; + } + entry_text = gtk_entry_get_text(GTK_ENTRY(widget)); + debug("callback_return_username: %s\n", entry_text); + SAFE_FREE(state->account); + state->account = strdup(entry_text); + g_signal_emit_by_name(state->button_ok_creds, "clicked"); +} + +static void callback_return_password(GtkWidget *widget, + gpointer data) +{ + const gchar *entry_text; + struct join_state *state = (struct join_state *)data; + if (!widget) { + return; + } + entry_text = gtk_entry_get_text(GTK_ENTRY(widget)); +#ifdef DEBUG_PASSWORD + debug("callback_return_password: %s\n", entry_text); +#else + debug("callback_return_password: (not printed)\n"); +#endif + SAFE_FREE(state->password); + state->password = strdup(entry_text); +} + +static void callback_return_password_and_enter(GtkWidget *widget, + gpointer data) +{ + const gchar *entry_text; + struct join_state *state = (struct join_state *)data; + if (!widget) { + return; + } + entry_text = gtk_entry_get_text(GTK_ENTRY(widget)); +#ifdef DEBUG_PASSWORD + debug("callback_return_password: %s\n", entry_text); +#else + debug("callback_return_password: (not printed)\n"); +#endif + SAFE_FREE(state->password); + state->password = strdup(entry_text); + g_signal_emit_by_name(state->button_ok_creds, "clicked"); +} + +static void callback_do_hostname_change(GtkWidget *widget, + gpointer data) +{ + GtkWidget *dialog; + const char *str = NULL; + + struct join_state *state = (struct join_state *)data; + + switch (state->name_type_initial) { + case NetSetupDomainName: + str = "To be implemented: call NetRenameMachineInDomain\n"; + break; + case NetSetupWorkgroupName: + str = "To be implemented: call SetComputerNameEx\n"; + break; + default: + break; + } + + dialog = gtk_message_dialog_new(GTK_WINDOW(state->window_parent), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR, + GTK_BUTTONS_CLOSE, + str); + + g_signal_connect_swapped(dialog, "response", + G_CALLBACK(gtk_widget_destroy), + dialog); + gtk_widget_show(dialog); +} + +static void callback_do_join(GtkWidget *widget, + gpointer data) +{ + GtkWidget *dialog; + + NET_API_STATUS status; + const char *err_str = NULL; + uint32_t join_flags = 0; + uint32_t unjoin_flags = 0; + gboolean domain_join = FALSE; + gboolean try_unjoin = FALSE; + const char *domain_or_workgroup = NULL; + + struct join_state *state = (struct join_state *)data; + + callback_return_username(state->entry_account, state); + callback_return_password(state->entry_password, state); + + if (state->window_creds_prompt) { + gtk_widget_destroy(GTK_WIDGET(state->window_creds_prompt)); + } + + if (state->name_type_new == NetSetupDomainName) { + domain_join = TRUE; + join_flags = WKSSVC_JOIN_FLAGS_JOIN_TYPE | + WKSSVC_JOIN_FLAGS_ACCOUNT_CREATE | + WKSSVC_JOIN_FLAGS_DOMAIN_JOIN_IF_JOINED; /* for testing */ + domain_or_workgroup = "domain"; + } else { + domain_or_workgroup = "workgroup"; + } + + if ((state->name_type_initial == NetSetupDomainName) && + (state->name_type_new == NetSetupWorkgroupName)) { + try_unjoin = TRUE; + unjoin_flags = WKSSVC_JOIN_FLAGS_JOIN_TYPE | + WKSSVC_JOIN_FLAGS_ACCOUNT_DELETE; + } + + debug("callback_do_join: Joining a %s named %s using join_flags 0x%08x ", + domain_or_workgroup, + state->name_buffer_new, + join_flags); + if (domain_join) { + debug("as %s ", state->account); +#ifdef DEBUG_PASSWORD + debug("with %s ", state->password); +#endif + } + debug("\n"); + if (try_unjoin) { + + debug("callback_do_join: Unjoining\n"); + + status = NetUnjoinDomain(NULL, + state->account, + state->password, + unjoin_flags); + if (status != 0) { + err_str = libnetapi_errstr(state->ctx, status); + g_print("callback_do_join: failed to unjoin (%s)\n", + err_str); + + dialog = gtk_message_dialog_new(GTK_WINDOW(state->window_parent), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR, + GTK_BUTTONS_CLOSE, + "The following error occured attempting to unjoin the %s: \"%s\": %s", + domain_or_workgroup, + state->name_buffer_new, + err_str); + + g_signal_connect_swapped(dialog, "response", + G_CALLBACK(gtk_widget_destroy), + dialog); + + gtk_widget_show(dialog); + + return; + } + + } + status = NetJoinDomain(NULL, + state->name_buffer_new, + NULL, + state->account, + state->password, + join_flags); + if (status != 0) { + err_str = libnetapi_errstr(state->ctx, status); + g_print("callback_do_join: failed to join (%s)\n", err_str); + + dialog = gtk_message_dialog_new(GTK_WINDOW(state->window_parent), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR, + GTK_BUTTONS_CLOSE, + "The following error occured attempting to join the %s: \"%s\": %s", + domain_or_workgroup, + state->name_buffer_new, + err_str); + + g_signal_connect_swapped(dialog, "response", + G_CALLBACK(gtk_widget_destroy), + dialog); + + gtk_widget_show(dialog); + + return; + } + + debug("callback_do_join: Successfully joined %s\n", + domain_or_workgroup); + + dialog = gtk_message_dialog_new(GTK_WINDOW(state->window_parent), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_INFO, + GTK_BUTTONS_OK, + "Welcome to the %s %s.", + state->name_buffer_new, + domain_or_workgroup); + + gtk_dialog_run(GTK_DIALOG(dialog)); + gtk_widget_destroy(dialog); + + callback_do_reboot(NULL, state->window_parent, state); +} + +static void callback_creds_prompt(GtkWidget *widget, + gpointer data) +{ + GtkWidget *window; + GtkWidget *box1; + GtkWidget *bbox; + GtkWidget *button; + GtkWidget *label; + + struct join_state *state = (struct join_state *)data; + + debug("callback_creds_prompt:\n"); + + state->window_parent = state->window_do_change; + + if (state->hostname_changed) { + return callback_do_hostname_change(NULL, state); + } + + if ((state->name_type_initial != NetSetupDomainName) && + (state->name_type_new != NetSetupDomainName)) { + return callback_do_join(NULL, state); + } + + window = gtk_window_new(GTK_WINDOW_TOPLEVEL); + + gtk_window_set_title(GTK_WINDOW(window), "Computer Name Changes"); + gtk_window_set_resizable(GTK_WINDOW(window), FALSE); + gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER); + gtk_widget_set_size_request(GTK_WIDGET(window), 380, 280); + gtk_window_set_icon_from_file(GTK_WINDOW(window), SAMBA_ICON_PATH, NULL); +/* gtk_window_set_icon_name(GTK_WIDGET(window), GTK_STOCK_DIALOG_AUTHENTICATION); */ + state->window_creds_prompt = window; + + g_signal_connect(G_OBJECT(window), "delete_event", + G_CALLBACK(callback_do_close), window); + + gtk_container_set_border_width(GTK_CONTAINER(window), 10); + + box1 = gtk_vbox_new(FALSE, 0); + + gtk_container_add(GTK_CONTAINER(window), box1); + + if ((state->name_type_initial == NetSetupDomainName) && + (state->name_type_new == NetSetupWorkgroupName)) { + label = gtk_label_new("Enter the name and password of an account with permission to leave the domain.\n"); + } else { + label = gtk_label_new("Enter the name and password of an account with permission to join the domain.\n"); + } + gtk_misc_set_alignment(GTK_MISC(label), 0, 0); + gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); + + gtk_box_pack_start(GTK_BOX(box1), label, FALSE, FALSE, 0); + + gtk_widget_show(label); + + /* USER NAME */ + label = gtk_label_new("User name:"); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0); + gtk_box_pack_start(GTK_BOX(box1), label, FALSE, FALSE, 0); + gtk_widget_show(label); + + state->entry_account = gtk_entry_new(); + gtk_entry_set_max_length(GTK_ENTRY(state->entry_account), MAX_CRED_LEN); + g_signal_connect(G_OBJECT(state->entry_account), "activate", + G_CALLBACK(callback_return_username_and_enter), + (gpointer)state); + gtk_editable_select_region(GTK_EDITABLE(state->entry_account), + 0, GTK_ENTRY(state->entry_account)->text_length); + gtk_box_pack_start(GTK_BOX(box1), state->entry_account, TRUE, TRUE, 0); + gtk_widget_show(state->entry_account); + + /* PASSWORD */ + label = gtk_label_new("Password:"); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0); + gtk_box_pack_start(GTK_BOX(box1), label, FALSE, FALSE, 0); + gtk_widget_show(label); + + state->entry_password = gtk_entry_new(); + gtk_entry_set_max_length(GTK_ENTRY(state->entry_password), MAX_CRED_LEN); + gtk_entry_set_visibility(GTK_ENTRY(state->entry_password), FALSE); + g_signal_connect(G_OBJECT(state->entry_password), "activate", + G_CALLBACK(callback_return_password_and_enter), + (gpointer)state); + gtk_editable_set_editable(GTK_EDITABLE(state->entry_password), TRUE); + gtk_editable_select_region(GTK_EDITABLE(state->entry_password), + 0, GTK_ENTRY(state->entry_password)->text_length); + gtk_box_pack_start(GTK_BOX(box1), state->entry_password, TRUE, TRUE, 0); + gtk_widget_show(state->entry_password); + + bbox = gtk_hbutton_box_new(); + gtk_container_set_border_width(GTK_CONTAINER(bbox), 5); + gtk_container_add(GTK_CONTAINER(box1), bbox); + gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); + gtk_box_set_spacing(GTK_BOX(bbox), 10); + + state->button_ok_creds = gtk_button_new_from_stock(GTK_STOCK_OK); + gtk_widget_grab_focus(GTK_WIDGET(state->button_ok_creds)); + gtk_container_add(GTK_CONTAINER(bbox), state->button_ok_creds); + g_signal_connect(G_OBJECT(state->button_ok_creds), "clicked", + G_CALLBACK(callback_do_join), + (gpointer)state); + gtk_widget_show(state->button_ok_creds); + + button = gtk_button_new_from_stock(GTK_STOCK_CANCEL); + gtk_container_add(GTK_CONTAINER(bbox), button); + g_signal_connect(G_OBJECT(button), "clicked", + G_CALLBACK(callback_do_close), (gpointer) window); + gtk_widget_show_all(window); +} + +static void callback_enter_hostname_and_unlock(GtkWidget *widget, + gpointer data) +{ + const gchar *entry_text = NULL; + char *str = NULL; + struct join_state *state = (struct join_state *)data; + + entry_text = gtk_entry_get_text(GTK_ENTRY(widget)); + debug("callback_enter_hostname_and_unlock: %s\n", entry_text); + if (!entry_text || entry_text[0] == 0) { + state->hostname_changed = FALSE; + gtk_widget_set_sensitive(GTK_WIDGET(state->button_ok), FALSE); + return; + } + if (strcasecmp(state->my_hostname, entry_text) == 0) { + state->hostname_changed = FALSE; + gtk_widget_set_sensitive(GTK_WIDGET(state->button_ok), FALSE); + return; + } + state->hostname_changed = TRUE; + if (state->name_type_initial == NetSetupDomainName) { + asprintf(&str, "%s.%s", entry_text, state->my_dnsdomain); + } else { + asprintf(&str, "%s.", entry_text); + } + gtk_label_set_text(GTK_LABEL(state->label_full_computer_name), str); + free(str); + + if (state->hostname_changed && str && str[0] != 0 && str[0] != '.') { + gtk_widget_set_sensitive(GTK_WIDGET(state->button_ok), TRUE); + } +} + +static void callback_enter_computer_description_and_unlock(GtkWidget *widget, + gpointer data) +{ + const gchar *entry_text = NULL; + struct join_state *state = (struct join_state *)data; + int string_unchanged = 0; + + entry_text = gtk_entry_get_text(GTK_ENTRY(widget)); + debug("callback_enter_computer_description_and_unlock: %s\n", + entry_text); +#if 0 + if (!entry_text || entry_text[0] == 0) { + string_unchanged = 1; + gtk_widget_set_sensitive(GTK_WIDGET(state->button_apply), + FALSE); + return; + } +#endif + if (entry_text && strcasecmp(state->comment, entry_text) == 0) { + string_unchanged = 1; + gtk_widget_set_sensitive(GTK_WIDGET(state->button_apply), + FALSE); + return; + } + + gtk_widget_set_sensitive(GTK_WIDGET(state->button_apply), TRUE); + SAFE_FREE(state->comment_new); + state->comment_new = strdup(entry_text); + +} + + +static void callback_enter_workgroup_and_unlock(GtkWidget *widget, + gpointer data) +{ + const gchar *entry_text = NULL; + struct join_state *state = (struct join_state *)data; + + entry_text = gtk_entry_get_text(GTK_ENTRY(widget)); + debug("callback_enter_workgroup_and_unlock: %s\n", entry_text); + if (!entry_text || entry_text[0] == 0) { + gtk_widget_set_sensitive(GTK_WIDGET(state->button_ok), FALSE); + return; + } + if (strcasecmp(state->name_buffer_initial, entry_text) == 0) { + gtk_widget_set_sensitive(GTK_WIDGET(state->button_ok), FALSE); + return; + } + gtk_widget_set_sensitive(GTK_WIDGET(state->button_ok), TRUE); + SAFE_FREE(state->name_buffer_new); + state->name_buffer_new = strdup(entry_text); + state->name_type_new = NetSetupWorkgroupName; +} + +static void callback_enter_domain_and_unlock(GtkWidget *widget, + gpointer data) +{ + const gchar *entry_text = NULL; + struct join_state *state = (struct join_state *)data; + + entry_text = gtk_entry_get_text(GTK_ENTRY(widget)); + debug("callback_enter_domain_and_unlock: %s\n", entry_text); + if (!entry_text || entry_text[0] == 0) { + gtk_widget_set_sensitive(GTK_WIDGET(state->button_ok), FALSE); + return; + } + if (strcasecmp(state->name_buffer_initial, entry_text) == 0) { + gtk_widget_set_sensitive(GTK_WIDGET(state->button_ok), FALSE); + return; + } + gtk_widget_set_sensitive(GTK_WIDGET(state->button_ok), TRUE); + SAFE_FREE(state->name_buffer_new); + state->name_buffer_new = strdup(entry_text); + state->name_type_new = NetSetupDomainName; +} + +static void callback_continue(GtkWidget *widget, + gpointer data) +{ + struct join_state *state = (struct join_state *)data; + + gtk_widget_grab_focus(GTK_WIDGET(state->button_ok)); + g_signal_emit_by_name(state->button_ok, "clicked"); +} + +static void callback_apply_continue(GtkWidget *widget, + gpointer data) +{ + struct join_state *state = (struct join_state *)data; + + gtk_widget_grab_focus(GTK_WIDGET(state->button_apply)); + g_signal_emit_by_name(state->button_apply, "clicked"); +} + +static void callback_do_join_workgroup(GtkWidget *widget, + gpointer data) +{ + struct join_state *state = (struct join_state *)data; + debug("callback_do_join_workgroup choosen\n"); + gtk_widget_set_sensitive(GTK_WIDGET(state->entry_workgroup), TRUE); + gtk_widget_grab_focus(GTK_WIDGET(state->entry_workgroup)); + gtk_widget_set_sensitive(GTK_WIDGET(state->entry_domain), FALSE); + callback_enter_workgroup_and_unlock(state->entry_workgroup, state); /* TEST */ +} + +static void callback_do_join_domain(GtkWidget *widget, + gpointer data) +{ + struct join_state *state = (struct join_state *)data; + debug("callback_do_join_domain choosen\n"); + gtk_widget_set_sensitive(GTK_WIDGET(state->entry_domain), TRUE); + gtk_widget_grab_focus(GTK_WIDGET(state->entry_domain)); + gtk_widget_set_sensitive(GTK_WIDGET(state->entry_workgroup), FALSE); + callback_enter_domain_and_unlock(state->entry_domain, state); /* TEST */ +} + +static void callback_do_change(GtkWidget *widget, + gpointer data) +{ + GtkWidget *window; + GtkWidget *box1; + GtkWidget *bbox; + GtkWidget *button_workgroup; + GtkWidget *button_domain; + GtkWidget *button; + GtkWidget *label; + GtkWidget *frame_horz; + GtkWidget *vbox; + GtkWidget *entry; + GSList *group; + + struct join_state *state = (struct join_state *)data; + + debug("callback_do_change called\n"); + + if (state->server_role == 3) { + GtkWidget *dialog; + dialog = gtk_message_dialog_new(GTK_WINDOW(state->window_main), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR, + GTK_BUTTONS_OK, + "Domain controller cannot be moved from one domain to another, they must first be demoted. Renaming this domain controller may cause it to become temporarily unavailable to users and computers. For information on renaming domain controllers, including alternate renaming methods, see Help and Support. To continue renaming this domain controller, click OK."); + g_signal_connect_swapped(dialog, "response", + G_CALLBACK(gtk_widget_destroy), + dialog); + + gtk_widget_show(dialog); + return; + } + + state->button_ok = gtk_button_new_from_stock(GTK_STOCK_OK); + window = gtk_window_new(GTK_WINDOW_TOPLEVEL); + + gtk_window_set_title(GTK_WINDOW(window), "Computer Name Changes"); + gtk_window_set_resizable(GTK_WINDOW(window), FALSE); + gtk_widget_set_size_request(GTK_WIDGET(window), 480, 500); /* breite * höhe */ + gtk_window_set_icon_from_file(GTK_WINDOW(window), SAMBA_ICON_PATH, NULL); + + g_signal_connect(G_OBJECT(window), "delete_event", + G_CALLBACK(callback_do_close), window); + + gtk_container_set_border_width(GTK_CONTAINER(window), 10); + + box1 = gtk_vbox_new(FALSE, 0); + gtk_container_add(GTK_CONTAINER(window), box1); + + label = gtk_label_new("You can change the name and membership of this computer. Changes may affect access to network ressources."); + gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0); + gtk_box_pack_start(GTK_BOX(box1), label, TRUE, TRUE, 0); + gtk_widget_show(label); + + /* COMPUTER NAME */ + label = gtk_label_new("Computer name:"); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0); + gtk_box_pack_start(GTK_BOX(box1), label, TRUE, TRUE, 0); + gtk_widget_show(label); + + state->label_full_computer_name = gtk_label_new(NULL); + { + entry = gtk_entry_new(); + gtk_entry_set_max_length(GTK_ENTRY(entry), MAX_NETBIOS_NAME_LEN); + g_signal_connect(G_OBJECT(entry), "changed", + G_CALLBACK(callback_enter_hostname_and_unlock), + (gpointer)state); + gtk_entry_set_text(GTK_ENTRY(entry), state->my_hostname); + gtk_editable_select_region(GTK_EDITABLE(entry), + 0, GTK_ENTRY(entry)->text_length); + + gtk_editable_set_editable(GTK_EDITABLE(entry), TRUE); /* ! */ + gtk_box_pack_start(GTK_BOX(box1), entry, TRUE, TRUE, 0); + gtk_widget_show(entry); + } + + /* FULL COMPUTER NAME */ + label = gtk_label_new("Full computer name:"); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0); + gtk_box_pack_start(GTK_BOX(box1), label, TRUE, TRUE, 0); + gtk_widget_show(label); + + { + const gchar *entry_text; + char *str = NULL; + entry_text = gtk_entry_get_text(GTK_ENTRY(entry)); + if (state->name_type_initial == NetSetupDomainName) { + asprintf(&str, "%s.%s", entry_text, state->my_dnsdomain); + } else { + asprintf(&str, "%s.", entry_text); + } + gtk_label_set_text(GTK_LABEL(state->label_full_computer_name), str); + free(str); + gtk_misc_set_alignment(GTK_MISC(state->label_full_computer_name), 0, 0); + gtk_box_pack_start(GTK_BOX(box1), state->label_full_computer_name, TRUE, TRUE, 0); + gtk_widget_show(state->label_full_computer_name); + } + + /* BOX */ + frame_horz = gtk_frame_new ("Member Of"); + gtk_box_pack_start(GTK_BOX(box1), frame_horz, TRUE, TRUE, 10); + + vbox = gtk_vbox_new(FALSE, 0); + gtk_container_set_border_width(GTK_CONTAINER(vbox), 10); + gtk_container_add(GTK_CONTAINER(frame_horz), vbox); + + /* TWO ENTRIES */ + state->entry_workgroup = gtk_entry_new(); + state->entry_domain = gtk_entry_new(); + + /* DOMAIN */ + button_domain = gtk_radio_button_new_with_label(NULL, "Domain"); + if (state->name_type_initial == NetSetupDomainName) { + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button_domain), TRUE); + } + gtk_box_pack_start(GTK_BOX(vbox), button_domain, TRUE, TRUE, 0); + g_signal_connect(G_OBJECT(button_domain), "clicked", + G_CALLBACK(callback_do_join_domain), + (gpointer)state); + + { + gtk_entry_set_max_length(GTK_ENTRY(state->entry_domain), 50); + g_signal_connect(G_OBJECT(state->entry_domain), "changed", + G_CALLBACK(callback_enter_domain_and_unlock), + (gpointer)state); + g_signal_connect(G_OBJECT(state->entry_domain), "activate", + G_CALLBACK(callback_continue), + (gpointer)state); + if (state->name_type_initial == NetSetupDomainName) { + gtk_entry_set_text(GTK_ENTRY(state->entry_domain), state->name_buffer_initial); + gtk_widget_set_sensitive(state->entry_workgroup, FALSE); + gtk_widget_set_sensitive(state->entry_domain, TRUE); + } + gtk_editable_set_editable(GTK_EDITABLE(state->entry_domain), TRUE); + gtk_box_pack_start(GTK_BOX(vbox), state->entry_domain, TRUE, TRUE, 0); + gtk_widget_show(state->entry_domain); + } + gtk_widget_show(button_domain); + + /* WORKGROUP */ + group = gtk_radio_button_get_group(GTK_RADIO_BUTTON(button_domain)); + button_workgroup = gtk_radio_button_new_with_label(group, "Workgroup"); + if (state->name_type_initial == NetSetupWorkgroupName) { + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button_workgroup), TRUE); + } + gtk_box_pack_start(GTK_BOX(vbox), button_workgroup, TRUE, TRUE, 0); + g_signal_connect(G_OBJECT(button_workgroup), "clicked", + G_CALLBACK(callback_do_join_workgroup), + (gpointer)state); + { + gtk_entry_set_max_length(GTK_ENTRY(state->entry_workgroup), MAX_NETBIOS_NAME_LEN); + g_signal_connect(G_OBJECT(state->entry_workgroup), "changed", + G_CALLBACK(callback_enter_workgroup_and_unlock), + (gpointer)state); + g_signal_connect(G_OBJECT(state->entry_workgroup), "activate", + G_CALLBACK(callback_continue), + (gpointer)state); + + if (state->name_type_initial == NetSetupWorkgroupName) { + gtk_entry_set_text(GTK_ENTRY(state->entry_workgroup), state->name_buffer_initial); + gtk_widget_set_sensitive(GTK_WIDGET(state->entry_domain), FALSE); + gtk_widget_set_sensitive(GTK_WIDGET(state->entry_workgroup), TRUE); + } + gtk_box_pack_start(GTK_BOX(vbox), state->entry_workgroup, TRUE, TRUE, 0); + gtk_widget_show(state->entry_workgroup); + } + gtk_widget_show(button_workgroup); + + /* BUTTONS */ + bbox = gtk_hbutton_box_new(); + gtk_container_set_border_width(GTK_CONTAINER(bbox), 5); + gtk_container_add(GTK_CONTAINER(box1), bbox); + gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); + gtk_box_set_spacing(GTK_BOX(bbox), 10); + + state->window_do_change = window; + gtk_widget_set_sensitive(GTK_WIDGET(state->button_ok), FALSE); /* !!! */ + gtk_container_add(GTK_CONTAINER(bbox), state->button_ok); + g_signal_connect(G_OBJECT(state->button_ok), "clicked", + G_CALLBACK(callback_creds_prompt), + (gpointer)state); + + button = gtk_button_new_from_stock(GTK_STOCK_CANCEL); + gtk_container_add(GTK_CONTAINER(bbox), button); + g_signal_connect(G_OBJECT(button), "clicked", + G_CALLBACK(callback_do_close), + (gpointer)window); + + gtk_widget_show_all(window); + +} + +static void callback_do_about(GtkWidget *widget, + gpointer data) +{ + GdkPixbuf *logo; + GError *error = NULL; + + debug("callback_do_about called\n"); + + logo = gdk_pixbuf_new_from_file(SAMBA_IMAGE_PATH, + &error); + if (logo == NULL) { + g_print("failed to load logo from %s: %s\n", + SAMBA_IMAGE_PATH, error->message); + } + + gtk_show_about_dialog(data, + "name", "Samba", + "version", "3.2.0pre2-GIT-904a90-test", + "copyright", "Copyright Andrew Tridgell and the Samba Team 1992-2007", + "website", "http://www.samba.org", + "license", "GPLv3", + "logo", logo, + "comments", "Samba gtk domain join utility", + NULL); +} + +static int draw_main_window(struct join_state *state) +{ + GtkWidget *window; + GtkWidget *button; + GtkWidget *label; + GtkWidget *main_vbox; + GtkWidget *vbox; + GtkWidget *hbox; + GtkWidget *bbox; + GtkWidget *image; + GtkWidget *table; + GtkWidget *entry; + GdkPixbuf *icon; + GError *error = NULL; + + icon = gdk_pixbuf_new_from_file(SAMBA_ICON_PATH, + &error); + if (icon == NULL) { + g_print("failed to load logo from %s : %s\n", + SAMBA_ICON_PATH, error->message); + } + +#if 1 + image = gtk_image_new_from_file(SAMBA_IMAGE_PATH); +#else + image = gtk_image_new_from_file("/usr/share/pixmaps/redhat-system_settings.png"); +#endif + + window = gtk_window_new(GTK_WINDOW_TOPLEVEL); + state->window_main = window; + + gtk_window_set_title(GTK_WINDOW(window), "Samba - Join Domain dialogue"); + gtk_widget_set_size_request(GTK_WIDGET(window), 600, 600); /* breite * höhe */ + gtk_window_set_resizable(GTK_WINDOW(window), FALSE); + gtk_window_set_icon_from_file(GTK_WINDOW(window), SAMBA_ICON_PATH, NULL); + + g_signal_connect(G_OBJECT(window), "delete_event", + G_CALLBACK(callback_delete_event), NULL); + + gtk_container_set_border_width(GTK_CONTAINER(window), 10); + + main_vbox = gtk_vbox_new(FALSE, 10); + gtk_container_add(GTK_CONTAINER(window), main_vbox); + +#if 0 + gtk_box_pack_start(GTK_BOX(main_vbox), image, TRUE, TRUE, 10); + gtk_widget_show(image); +#endif + /* Hbox */ + hbox = gtk_hbox_new(FALSE, 10); + gtk_container_add(GTK_CONTAINER(main_vbox), hbox); + + { +/* gtk_box_pack_start(GTK_BOX(main_vbox), image, TRUE, TRUE, 10); */ + gtk_misc_set_alignment(GTK_MISC(image), 0, 0); + gtk_box_pack_start(GTK_BOX(hbox), image, FALSE, FALSE, 10); + gtk_widget_show(image); + + /* Label */ + label = gtk_label_new("Samba uses the following information to identify your computer on the network."); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0); + gtk_widget_set_size_request(GTK_WIDGET(label), 500, 40); + gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); + gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); + gtk_widget_show(label); + } + + gtk_widget_show(hbox); + + vbox = gtk_vbox_new(FALSE, 0); + gtk_container_set_border_width(GTK_CONTAINER(vbox), 10); + gtk_container_add(GTK_CONTAINER(main_vbox), vbox); + + /* Table */ + table = gtk_table_new(6, 3, TRUE); + gtk_table_set_row_spacings(GTK_TABLE(table), 5); + gtk_table_set_col_spacings(GTK_TABLE(table), 5); + gtk_container_add(GTK_CONTAINER(vbox), table); + + { + /* Label */ + label = gtk_label_new("Computer description:"); +/* gtk_misc_set_alignment(GTK_MISC(label), 0, 0); */ + gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 0, 1); + gtk_widget_show(label); + + state->button_apply = gtk_button_new_from_stock(GTK_STOCK_APPLY); + + /* Entry */ + entry = gtk_entry_new(); + gtk_entry_set_max_length(GTK_ENTRY(entry), 256); + g_signal_connect(G_OBJECT(entry), "changed", + G_CALLBACK(callback_enter_computer_description_and_unlock), + state); + g_signal_connect(G_OBJECT(entry), "activate", + G_CALLBACK(callback_apply_continue), + (gpointer)state); + + gtk_entry_set_text(GTK_ENTRY(entry), (char *)state->comment); + gtk_editable_set_editable(GTK_EDITABLE(entry), TRUE); /* ! */ + gtk_table_attach_defaults(GTK_TABLE(table), entry, 1, 3, 0, 1); + gtk_widget_show(entry); + } + + /* Label */ + label = gtk_label_new("For example: \"Samba \%v\"."); + gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0); + gtk_table_attach_defaults(GTK_TABLE(table), label, 1, 3, 1, 2); + gtk_widget_show(label); + + /* Label */ + label = gtk_label_new("Full computer name:"); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0); + gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 2, 3); + gtk_widget_show(label); + + { + /* Label */ + char *str = NULL; + if (state->name_type_initial == NetSetupDomainName) { + asprintf(&str, "%s.%s", state->my_hostname, + state->my_dnsdomain); + } else { + asprintf(&str, "%s.", state->my_hostname); + } + + label = gtk_label_new(str); + SAFE_FREE(str); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0); + gtk_table_attach_defaults(GTK_TABLE(table), label, 1, 3, 2, 3); + gtk_widget_show(label); + } + + /* Label */ + if (state->name_type_initial == NetSetupDomainName) { + label = gtk_label_new("Domain:"); + } else { + label = gtk_label_new("Workgroup:"); + } + gtk_misc_set_alignment(GTK_MISC(label), 0, 0); + gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 3, 4); + gtk_widget_show(label); + state->label_current_name_type = label; + + /* Label */ + label = gtk_label_new(state->name_buffer_initial); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0); + gtk_table_attach_defaults(GTK_TABLE(table), label, 1, 3, 3, 4); + gtk_widget_show(label); + state->label_current_name_buffer = label; + + { + hbox = gtk_hbox_new(FALSE, 0); + gtk_container_add(GTK_CONTAINER(vbox), hbox); + label = gtk_label_new("To rename this computer or join a domain, click Change."); + gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); + + + } + + /* bbox */ + bbox = gtk_hbutton_box_new(); + gtk_container_set_border_width(GTK_CONTAINER(bbox), 5); + gtk_container_add(GTK_CONTAINER(hbox), bbox); + gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); + gtk_box_set_spacing(GTK_BOX(bbox), 10); + + button = gtk_button_new_with_mnemonic("Ch_ange"); + g_signal_connect(G_OBJECT(button), "clicked", + G_CALLBACK(callback_do_change), + (gpointer)state); + gtk_box_pack_start(GTK_BOX(bbox), button, TRUE, TRUE, 0); + gtk_widget_show(button); + + /* Label (hidden) */ + state->label_reboot = gtk_label_new(NULL); + gtk_label_set_line_wrap(GTK_LABEL(state->label_reboot), TRUE); + gtk_misc_set_alignment(GTK_MISC(state->label_reboot), 0, 0); + gtk_box_pack_start(GTK_BOX(vbox), state->label_reboot, TRUE, TRUE, 0); + gtk_widget_show(state->label_reboot); + +#if 0 + gtk_box_pack_start(GTK_BOX(vbox), + create_bbox(window, TRUE, NULL, 10, 85, 20, GTK_BUTTONBOX_END), + TRUE, TRUE, 5); +#endif + { + + GtkWidget *frame; + GtkWidget *bbox2; + GtkWidget *button2; + + frame = gtk_frame_new(NULL); + bbox2 = gtk_hbutton_box_new(); + + gtk_container_set_border_width(GTK_CONTAINER(bbox2), 5); + gtk_container_add(GTK_CONTAINER(frame), bbox2); + + /* Set the appearance of the Button Box */ + gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox2), GTK_BUTTONBOX_END); + gtk_box_set_spacing(GTK_BOX(bbox2), 10); + /*gtk_button_box_set_child_size(GTK_BUTTON_BOX(bbox2), child_w, child_h);*/ + + button2 = gtk_button_new_from_stock(GTK_STOCK_OK); + gtk_container_add(GTK_CONTAINER(bbox2), button2); + g_signal_connect(G_OBJECT(button2), "clicked", G_CALLBACK(callback_do_exit), state); + + button2 = gtk_button_new_from_stock(GTK_STOCK_CANCEL); + gtk_container_add(GTK_CONTAINER(bbox2), button2); + g_signal_connect(G_OBJECT(button2), "clicked", + G_CALLBACK(callback_delete_event), + window); + + gtk_container_add(GTK_CONTAINER(bbox2), state->button_apply); + g_signal_connect(G_OBJECT(state->button_apply), "clicked", + G_CALLBACK(callback_apply_description_change), + state); + gtk_widget_set_sensitive(GTK_WIDGET(state->button_apply), FALSE); + + button2 = gtk_button_new_from_stock(GTK_STOCK_ABOUT); + gtk_container_add(GTK_CONTAINER(bbox2), button2); + g_signal_connect(G_OBJECT(button2), "clicked", + G_CALLBACK(callback_do_about), + window); + + gtk_box_pack_start(GTK_BOX(vbox), frame, TRUE, TRUE, 5); + } + + gtk_widget_show_all(window); + + return 0; +} + +static int init_join_state(struct join_state **state) +{ + struct join_state *s; + + s = malloc(sizeof(struct join_state)); + if (!s) { + return -1; + } + + memset(s, '\0', sizeof(struct join_state)); + + *state = s; + + return 0; +} + +static int initialize_join_state(struct join_state *state, + const char *debug_level) +{ + struct libnetapi_ctx *ctx = NULL; + NET_API_STATUS status = 0; + + status = libnetapi_init(&ctx); + if (status) { + return status; + } + + if (debug_level) { + libnetapi_set_debuglevel(ctx, debug_level); + } + + { + char my_hostname[HOST_NAME_MAX]; + const char *p = NULL; + if (gethostname(my_hostname, sizeof(my_hostname)) == -1) { + return -1; + } + + state->my_fqdn = strdup(my_hostname); + if (!state->my_fqdn) { + return -1; + } + + p = strchr(my_hostname, '.'); + if (p) { + my_hostname[strlen(my_hostname) - strlen(p)] = '\0'; + state->my_hostname = strdup(my_hostname); + if (!state->my_hostname) { + return -1; + } + p++; + state->my_dnsdomain = strdup(p); + if (!state->my_dnsdomain) { + return -1; + } + } + } + + { + const char *buffer = NULL; + uint16_t type = 0; + status = NetGetJoinInformation(NULL, &buffer, &type); + if (status) { + return status; + } + state->name_buffer_initial = (char *)buffer; + state->name_type_initial = type; + } + + { + struct srvsvc_NetSrvInfo1005 *info1005 = NULL; + uint8_t *buffer = NULL; + + status = NetServerGetInfo(NULL, 1005, &buffer); + if (status) { + return status; + } + + info1005 = (struct srvsvc_NetSrvInfo1005 *)buffer; + + state->comment = strdup(info1005->comment); + if (!state->comment) { + return -1; + } + } +#if 0 + { + struct srvsvc_NetSrvInfo100 *info100 = NULL; + uint8_t *buffer = NULL; + + status = NetServerGetInfo(NULL, 100, &buffer); + if (status) { + return status; + } + + info100 = (struct srvsvc_NetSrvInfo100 *)buffer; + + state->comment = strdup(info100->comment); + if (!state->comment) { + return -1; + } + } +#endif + + state->ctx = ctx; + + return 0; +} + +int main(int argc, char **argv) +{ + GOptionContext *context = NULL; + static const char *debug_level = NULL; + struct join_state *state = NULL; + GError *error = NULL; + int ret = 0; + + static GOptionEntry entries[] = { + { "debug", 'd', 0, G_OPTION_ARG_STRING, &debug_level, "Debug level (for samba)", "N" }, + { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, "Verbose output", 0 }, + { NULL } + }; + + context = g_option_context_new("- Samba domain join utility"); + g_option_context_add_main_entries(context, entries, NULL); +/* g_option_context_add_main_entries(context, entries, GETTEXT_PACKAGE); */ + g_option_context_add_group(context, gtk_get_option_group(TRUE)); + g_option_context_parse(context, &argc, &argv, &error); + + gtk_init(&argc, &argv); + g_set_application_name("Samba"); + + ret = init_join_state(&state); + if (ret) { + return ret; + } + + ret = initialize_join_state(state, debug_level); + if (ret) { + return ret; + } + + draw_main_window(state); + + gtk_main(); + + do_cleanup(state); + + return 0; +} diff --git a/source3/lib/netapi/examples/netdomjoin/netdomjoin.c b/source3/lib/netapi/examples/netdomjoin/netdomjoin.c new file mode 100644 index 0000000000..a2bb700250 --- /dev/null +++ b/source3/lib/netapi/examples/netdomjoin/netdomjoin.c @@ -0,0 +1,107 @@ +/* + * Unix SMB/CIFS implementation. + * Join Support (cmdline + netapi) + * Copyright (C) Guenther Deschner 2007 + * + * 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include +#include +#include +#include +#include + +#include + +char *get_string_param(const char *param) +{ + char *p; + + p = strchr(param, '='); + if (!p) { + return NULL; + } + + return (p+1); +} + +int main(int argc, char **argv) +{ + NET_API_STATUS status; + const char *server_name = NULL; + const char *domain_name = NULL; + const char *account_ou = NULL; + const char *Account = NULL; + const char *password = NULL; + uint32_t join_flags = 3; + struct libnetapi_ctx *ctx = NULL; + int i; + + status = libnetapi_init(&ctx); + if (status != 0) { + return status; + } + + if (argc < 2) { + printf("usage: netdomjoin\n"); + printf("\t[hostname=HOSTNAME] [domain=DOMAIN] \n"); + return 0; + } + + if (argc > 2) { + server_name = argv[1]; + } + + for (i=0; i Date: Fri, 21 Dec 2007 17:29:15 +0100 Subject: Move gtk app to the correct location. Thanks obnox! Guenther (This used to be commit 740a2b080db56d504c4edd58bf41d72edb3d32ee) --- .../examples/netdomjoin-gui/netdomjoin-gui.c | 1347 ++++++++++++++++++++ .../netapi/examples/netdomjoin/netdomjoin-gui.c | 1347 -------------------- 2 files changed, 1347 insertions(+), 1347 deletions(-) create mode 100644 source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c delete mode 100644 source3/lib/netapi/examples/netdomjoin/netdomjoin-gui.c (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c new file mode 100644 index 0000000000..8ca6897cab --- /dev/null +++ b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c @@ -0,0 +1,1347 @@ +/* + * Unix SMB/CIFS implementation. + * Join Support (gtk + netapi) + * Copyright (C) Guenther Deschner 2007 + * + * 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include + +#include +#include + +#include + +#define MAX_CRED_LEN 256 +#define MAX_NETBIOS_NAME_LEN 15 + +#define SAMBA_ICON_PATH "/usr/share/pixmaps/samba/samba.ico" +#define SAMBA_IMAGE_PATH "/usr/share/pixmaps/samba/logo.png" + +#define WKSSVC_JOIN_FLAGS_DOMAIN_JOIN_IF_JOINED ( 0x00000020 ) +#define WKSSVC_JOIN_FLAGS_ACCOUNT_DELETE ( 0x00000004 ) +#define WKSSVC_JOIN_FLAGS_ACCOUNT_CREATE ( 0x00000002 ) +#define WKSSVC_JOIN_FLAGS_JOIN_TYPE ( 0x00000001 ) + +#define NetSetupWorkgroupName ( 2 ) +#define NetSetupDomainName ( 3 ) + +#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0) + +struct srvsvc_NetSrvInfo1005 { + const char *comment;/* [unique,charset(UTF16)] */ +}; + +static gboolean verbose = FALSE; + +typedef struct join_state { + struct libnetapi_ctx *ctx; + GtkWidget *window_main; + GtkWidget *window_parent; + GtkWidget *window_do_change; + GtkWidget *window_creds_prompt; + GtkWidget *entry_account; + GtkWidget *entry_password; + GtkWidget *entry_domain; + GtkWidget *entry_workgroup; + GtkWidget *button_ok; + GtkWidget *button_apply; + GtkWidget *button_ok_creds; + GtkWidget *label_reboot; + GtkWidget *label_current_name_buffer; + GtkWidget *label_current_name_type; + GtkWidget *label_full_computer_name; + uint16_t name_type_initial; + uint16_t name_type_new; + char *name_buffer_initial; + char *name_buffer_new; + char *password; + char *account; + char *comment; + char *comment_new; + char *my_fqdn; + char *my_dnsdomain; + char *my_hostname; + uint16_t server_role; + gboolean settings_changed; + gboolean hostname_changed; +} join_state; + +static void debug(const char *format, ...) +{ + va_list args; + + if (!verbose) { + return; + } + + va_start(args, format); + g_vprintf(format, args); + va_end(args); +} + +static gboolean callback_delete_event(GtkWidget *widget, + GdkEvent *event, + gpointer data) +{ + gtk_main_quit(); + return FALSE; +} + +static void callback_do_close(GtkWidget *widget, + gpointer data) +{ + debug("Closing now...\n"); + gtk_widget_destroy(data); +} + +static void free_join_state(struct join_state *s) +{ + SAFE_FREE(s->name_buffer_initial); + SAFE_FREE(s->name_buffer_new); + SAFE_FREE(s->password); + SAFE_FREE(s->account); + SAFE_FREE(s->comment); + SAFE_FREE(s->comment_new); + SAFE_FREE(s->my_fqdn); + SAFE_FREE(s->my_dnsdomain); + SAFE_FREE(s->my_hostname); + +} + +static void do_cleanup(struct join_state *state) +{ + libnetapi_free(state->ctx); + free_join_state(state); +} + +static void callback_apply_description_change(GtkWidget *widget, + gpointer data) +{ + struct join_state *state = (struct join_state *)data; + NET_API_STATUS status = 0; + uint32_t parm_err = 0; + struct srvsvc_NetSrvInfo1005 info1005; + GtkWidget *dialog; + + info1005.comment = state->comment_new; + + status = NetServerSetInfo(NULL, 1005, (uint8_t *)&info1005, &parm_err); + if (status) { + debug("NetServerSetInfo failed with: %s\n", + libnetapi_errstr(state->ctx, status)); + dialog = gtk_message_dialog_new(GTK_WINDOW(state->window_main), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR, + GTK_BUTTONS_OK, + "Failed to change computer description: %s.", + libnetapi_errstr(state->ctx, status)); + g_signal_connect_swapped(dialog, "response", + G_CALLBACK(gtk_widget_destroy), + dialog); + + gtk_widget_show(dialog); + return; + } + + gtk_widget_set_sensitive(GTK_WIDGET(state->button_apply), FALSE); +} + +static void callback_do_exit(GtkWidget *widget, + gpointer data) +{ + GtkWidget *dialog; + gint result; + struct join_state *state = (struct join_state *)data; + + if (!state->settings_changed) { + callback_delete_event(NULL, NULL, NULL); + return; + } + + dialog = gtk_message_dialog_new(GTK_WINDOW(state->window_main), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_QUESTION, + GTK_BUTTONS_YES_NO, + "You must restart your computer before the new settings will take effect."); + result = gtk_dialog_run(GTK_DIALOG(dialog)); + switch (result) { + case GTK_RESPONSE_YES: + g_print("would reboot here\n"); + break; + case GTK_RESPONSE_NO: + default: + break; + } + gtk_widget_destroy(dialog); + gtk_widget_destroy(state->window_main); + do_cleanup(state); + exit(0); +} + + +static void callback_do_reboot(GtkWidget *widget, + gpointer data, + gpointer data2) +{ + GtkWidget *dialog; + struct join_state *state = (struct join_state *)data2; + + debug("callback_do_reboot\n"); + + state->settings_changed = TRUE; + dialog = gtk_message_dialog_new(GTK_WINDOW(data), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_INFO, + GTK_BUTTONS_OK, + "You must restart this computer for the changes to take effect."); +#if 0 + g_signal_connect_swapped(dialog, "response", + G_CALLBACK(gtk_widget_destroy), + dialog); + + debug("showing dialog\n"); + gtk_widget_show(dialog); +#else + gtk_dialog_run(GTK_DIALOG(dialog)); + gtk_widget_destroy(dialog); +#endif + + gtk_label_set_text(GTK_LABEL(state->label_reboot), "Changes will take effect after you restart this computer"); + + debug("destroying do_change window\n"); + gtk_widget_destroy(GTK_WIDGET(state->window_do_change)); + + { + uint32_t status; + const char *buffer; + uint16_t type; + + status = NetGetJoinInformation(NULL, &buffer, &type); + if (status != 0) { + g_print("failed to query status\n"); + return; + } + + debug("got new status: %s\n", buffer); +#if 0 + SAFE_FREE(state->name_buffer_new); + state->name_buffer_new = strdup(buffer); + SAFE_FREE(buffer); + state->name_type_new = type; +#endif + gtk_label_set_text(GTK_LABEL(state->label_current_name_buffer), state->name_buffer_new); + if (state->name_type_new == 3) { + gtk_label_set_text(GTK_LABEL(state->label_current_name_type), "Domain:"); + } else { + gtk_label_set_text(GTK_LABEL(state->label_current_name_type), "Workgroup:"); + } + } +} + +static void callback_return_username(GtkWidget *widget, + gpointer data) +{ + const gchar *entry_text; + struct join_state *state = (struct join_state *)data; + if (!widget) { + return; + } + entry_text = gtk_entry_get_text(GTK_ENTRY(widget)); + debug("callback_return_username: %s\n", entry_text); + SAFE_FREE(state->account); + state->account = strdup(entry_text); +} + +static void callback_return_username_and_enter(GtkWidget *widget, + gpointer data) +{ + const gchar *entry_text; + struct join_state *state = (struct join_state *)data; + if (!widget) { + return; + } + entry_text = gtk_entry_get_text(GTK_ENTRY(widget)); + debug("callback_return_username: %s\n", entry_text); + SAFE_FREE(state->account); + state->account = strdup(entry_text); + g_signal_emit_by_name(state->button_ok_creds, "clicked"); +} + +static void callback_return_password(GtkWidget *widget, + gpointer data) +{ + const gchar *entry_text; + struct join_state *state = (struct join_state *)data; + if (!widget) { + return; + } + entry_text = gtk_entry_get_text(GTK_ENTRY(widget)); +#ifdef DEBUG_PASSWORD + debug("callback_return_password: %s\n", entry_text); +#else + debug("callback_return_password: (not printed)\n"); +#endif + SAFE_FREE(state->password); + state->password = strdup(entry_text); +} + +static void callback_return_password_and_enter(GtkWidget *widget, + gpointer data) +{ + const gchar *entry_text; + struct join_state *state = (struct join_state *)data; + if (!widget) { + return; + } + entry_text = gtk_entry_get_text(GTK_ENTRY(widget)); +#ifdef DEBUG_PASSWORD + debug("callback_return_password: %s\n", entry_text); +#else + debug("callback_return_password: (not printed)\n"); +#endif + SAFE_FREE(state->password); + state->password = strdup(entry_text); + g_signal_emit_by_name(state->button_ok_creds, "clicked"); +} + +static void callback_do_hostname_change(GtkWidget *widget, + gpointer data) +{ + GtkWidget *dialog; + const char *str = NULL; + + struct join_state *state = (struct join_state *)data; + + switch (state->name_type_initial) { + case NetSetupDomainName: + str = "To be implemented: call NetRenameMachineInDomain\n"; + break; + case NetSetupWorkgroupName: + str = "To be implemented: call SetComputerNameEx\n"; + break; + default: + break; + } + + dialog = gtk_message_dialog_new(GTK_WINDOW(state->window_parent), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR, + GTK_BUTTONS_CLOSE, + str); + + g_signal_connect_swapped(dialog, "response", + G_CALLBACK(gtk_widget_destroy), + dialog); + gtk_widget_show(dialog); +} + +static void callback_do_join(GtkWidget *widget, + gpointer data) +{ + GtkWidget *dialog; + + NET_API_STATUS status; + const char *err_str = NULL; + uint32_t join_flags = 0; + uint32_t unjoin_flags = 0; + gboolean domain_join = FALSE; + gboolean try_unjoin = FALSE; + const char *domain_or_workgroup = NULL; + + struct join_state *state = (struct join_state *)data; + + callback_return_username(state->entry_account, state); + callback_return_password(state->entry_password, state); + + if (state->window_creds_prompt) { + gtk_widget_destroy(GTK_WIDGET(state->window_creds_prompt)); + } + + if (state->name_type_new == NetSetupDomainName) { + domain_join = TRUE; + join_flags = WKSSVC_JOIN_FLAGS_JOIN_TYPE | + WKSSVC_JOIN_FLAGS_ACCOUNT_CREATE | + WKSSVC_JOIN_FLAGS_DOMAIN_JOIN_IF_JOINED; /* for testing */ + domain_or_workgroup = "domain"; + } else { + domain_or_workgroup = "workgroup"; + } + + if ((state->name_type_initial == NetSetupDomainName) && + (state->name_type_new == NetSetupWorkgroupName)) { + try_unjoin = TRUE; + unjoin_flags = WKSSVC_JOIN_FLAGS_JOIN_TYPE | + WKSSVC_JOIN_FLAGS_ACCOUNT_DELETE; + } + + debug("callback_do_join: Joining a %s named %s using join_flags 0x%08x ", + domain_or_workgroup, + state->name_buffer_new, + join_flags); + if (domain_join) { + debug("as %s ", state->account); +#ifdef DEBUG_PASSWORD + debug("with %s ", state->password); +#endif + } + debug("\n"); + if (try_unjoin) { + + debug("callback_do_join: Unjoining\n"); + + status = NetUnjoinDomain(NULL, + state->account, + state->password, + unjoin_flags); + if (status != 0) { + err_str = libnetapi_errstr(state->ctx, status); + g_print("callback_do_join: failed to unjoin (%s)\n", + err_str); + + dialog = gtk_message_dialog_new(GTK_WINDOW(state->window_parent), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR, + GTK_BUTTONS_CLOSE, + "The following error occured attempting to unjoin the %s: \"%s\": %s", + domain_or_workgroup, + state->name_buffer_new, + err_str); + + g_signal_connect_swapped(dialog, "response", + G_CALLBACK(gtk_widget_destroy), + dialog); + + gtk_widget_show(dialog); + + return; + } + + } + status = NetJoinDomain(NULL, + state->name_buffer_new, + NULL, + state->account, + state->password, + join_flags); + if (status != 0) { + err_str = libnetapi_errstr(state->ctx, status); + g_print("callback_do_join: failed to join (%s)\n", err_str); + + dialog = gtk_message_dialog_new(GTK_WINDOW(state->window_parent), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR, + GTK_BUTTONS_CLOSE, + "The following error occured attempting to join the %s: \"%s\": %s", + domain_or_workgroup, + state->name_buffer_new, + err_str); + + g_signal_connect_swapped(dialog, "response", + G_CALLBACK(gtk_widget_destroy), + dialog); + + gtk_widget_show(dialog); + + return; + } + + debug("callback_do_join: Successfully joined %s\n", + domain_or_workgroup); + + dialog = gtk_message_dialog_new(GTK_WINDOW(state->window_parent), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_INFO, + GTK_BUTTONS_OK, + "Welcome to the %s %s.", + state->name_buffer_new, + domain_or_workgroup); + + gtk_dialog_run(GTK_DIALOG(dialog)); + gtk_widget_destroy(dialog); + + callback_do_reboot(NULL, state->window_parent, state); +} + +static void callback_creds_prompt(GtkWidget *widget, + gpointer data) +{ + GtkWidget *window; + GtkWidget *box1; + GtkWidget *bbox; + GtkWidget *button; + GtkWidget *label; + + struct join_state *state = (struct join_state *)data; + + debug("callback_creds_prompt:\n"); + + state->window_parent = state->window_do_change; + + if (state->hostname_changed) { + return callback_do_hostname_change(NULL, state); + } + + if ((state->name_type_initial != NetSetupDomainName) && + (state->name_type_new != NetSetupDomainName)) { + return callback_do_join(NULL, state); + } + + window = gtk_window_new(GTK_WINDOW_TOPLEVEL); + + gtk_window_set_title(GTK_WINDOW(window), "Computer Name Changes"); + gtk_window_set_resizable(GTK_WINDOW(window), FALSE); + gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER); + gtk_widget_set_size_request(GTK_WIDGET(window), 380, 280); + gtk_window_set_icon_from_file(GTK_WINDOW(window), SAMBA_ICON_PATH, NULL); +/* gtk_window_set_icon_name(GTK_WIDGET(window), GTK_STOCK_DIALOG_AUTHENTICATION); */ + state->window_creds_prompt = window; + + g_signal_connect(G_OBJECT(window), "delete_event", + G_CALLBACK(callback_do_close), window); + + gtk_container_set_border_width(GTK_CONTAINER(window), 10); + + box1 = gtk_vbox_new(FALSE, 0); + + gtk_container_add(GTK_CONTAINER(window), box1); + + if ((state->name_type_initial == NetSetupDomainName) && + (state->name_type_new == NetSetupWorkgroupName)) { + label = gtk_label_new("Enter the name and password of an account with permission to leave the domain.\n"); + } else { + label = gtk_label_new("Enter the name and password of an account with permission to join the domain.\n"); + } + gtk_misc_set_alignment(GTK_MISC(label), 0, 0); + gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); + + gtk_box_pack_start(GTK_BOX(box1), label, FALSE, FALSE, 0); + + gtk_widget_show(label); + + /* USER NAME */ + label = gtk_label_new("User name:"); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0); + gtk_box_pack_start(GTK_BOX(box1), label, FALSE, FALSE, 0); + gtk_widget_show(label); + + state->entry_account = gtk_entry_new(); + gtk_entry_set_max_length(GTK_ENTRY(state->entry_account), MAX_CRED_LEN); + g_signal_connect(G_OBJECT(state->entry_account), "activate", + G_CALLBACK(callback_return_username_and_enter), + (gpointer)state); + gtk_editable_select_region(GTK_EDITABLE(state->entry_account), + 0, GTK_ENTRY(state->entry_account)->text_length); + gtk_box_pack_start(GTK_BOX(box1), state->entry_account, TRUE, TRUE, 0); + gtk_widget_show(state->entry_account); + + /* PASSWORD */ + label = gtk_label_new("Password:"); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0); + gtk_box_pack_start(GTK_BOX(box1), label, FALSE, FALSE, 0); + gtk_widget_show(label); + + state->entry_password = gtk_entry_new(); + gtk_entry_set_max_length(GTK_ENTRY(state->entry_password), MAX_CRED_LEN); + gtk_entry_set_visibility(GTK_ENTRY(state->entry_password), FALSE); + g_signal_connect(G_OBJECT(state->entry_password), "activate", + G_CALLBACK(callback_return_password_and_enter), + (gpointer)state); + gtk_editable_set_editable(GTK_EDITABLE(state->entry_password), TRUE); + gtk_editable_select_region(GTK_EDITABLE(state->entry_password), + 0, GTK_ENTRY(state->entry_password)->text_length); + gtk_box_pack_start(GTK_BOX(box1), state->entry_password, TRUE, TRUE, 0); + gtk_widget_show(state->entry_password); + + bbox = gtk_hbutton_box_new(); + gtk_container_set_border_width(GTK_CONTAINER(bbox), 5); + gtk_container_add(GTK_CONTAINER(box1), bbox); + gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); + gtk_box_set_spacing(GTK_BOX(bbox), 10); + + state->button_ok_creds = gtk_button_new_from_stock(GTK_STOCK_OK); + gtk_widget_grab_focus(GTK_WIDGET(state->button_ok_creds)); + gtk_container_add(GTK_CONTAINER(bbox), state->button_ok_creds); + g_signal_connect(G_OBJECT(state->button_ok_creds), "clicked", + G_CALLBACK(callback_do_join), + (gpointer)state); + gtk_widget_show(state->button_ok_creds); + + button = gtk_button_new_from_stock(GTK_STOCK_CANCEL); + gtk_container_add(GTK_CONTAINER(bbox), button); + g_signal_connect(G_OBJECT(button), "clicked", + G_CALLBACK(callback_do_close), (gpointer) window); + gtk_widget_show_all(window); +} + +static void callback_enter_hostname_and_unlock(GtkWidget *widget, + gpointer data) +{ + const gchar *entry_text = NULL; + char *str = NULL; + struct join_state *state = (struct join_state *)data; + + entry_text = gtk_entry_get_text(GTK_ENTRY(widget)); + debug("callback_enter_hostname_and_unlock: %s\n", entry_text); + if (!entry_text || entry_text[0] == 0) { + state->hostname_changed = FALSE; + gtk_widget_set_sensitive(GTK_WIDGET(state->button_ok), FALSE); + return; + } + if (strcasecmp(state->my_hostname, entry_text) == 0) { + state->hostname_changed = FALSE; + gtk_widget_set_sensitive(GTK_WIDGET(state->button_ok), FALSE); + return; + } + state->hostname_changed = TRUE; + if (state->name_type_initial == NetSetupDomainName) { + asprintf(&str, "%s.%s", entry_text, state->my_dnsdomain); + } else { + asprintf(&str, "%s.", entry_text); + } + gtk_label_set_text(GTK_LABEL(state->label_full_computer_name), str); + free(str); + + if (state->hostname_changed && str && str[0] != 0 && str[0] != '.') { + gtk_widget_set_sensitive(GTK_WIDGET(state->button_ok), TRUE); + } +} + +static void callback_enter_computer_description_and_unlock(GtkWidget *widget, + gpointer data) +{ + const gchar *entry_text = NULL; + struct join_state *state = (struct join_state *)data; + int string_unchanged = 0; + + entry_text = gtk_entry_get_text(GTK_ENTRY(widget)); + debug("callback_enter_computer_description_and_unlock: %s\n", + entry_text); +#if 0 + if (!entry_text || entry_text[0] == 0) { + string_unchanged = 1; + gtk_widget_set_sensitive(GTK_WIDGET(state->button_apply), + FALSE); + return; + } +#endif + if (entry_text && strcasecmp(state->comment, entry_text) == 0) { + string_unchanged = 1; + gtk_widget_set_sensitive(GTK_WIDGET(state->button_apply), + FALSE); + return; + } + + gtk_widget_set_sensitive(GTK_WIDGET(state->button_apply), TRUE); + SAFE_FREE(state->comment_new); + state->comment_new = strdup(entry_text); + +} + + +static void callback_enter_workgroup_and_unlock(GtkWidget *widget, + gpointer data) +{ + const gchar *entry_text = NULL; + struct join_state *state = (struct join_state *)data; + + entry_text = gtk_entry_get_text(GTK_ENTRY(widget)); + debug("callback_enter_workgroup_and_unlock: %s\n", entry_text); + if (!entry_text || entry_text[0] == 0) { + gtk_widget_set_sensitive(GTK_WIDGET(state->button_ok), FALSE); + return; + } + if (strcasecmp(state->name_buffer_initial, entry_text) == 0) { + gtk_widget_set_sensitive(GTK_WIDGET(state->button_ok), FALSE); + return; + } + gtk_widget_set_sensitive(GTK_WIDGET(state->button_ok), TRUE); + SAFE_FREE(state->name_buffer_new); + state->name_buffer_new = strdup(entry_text); + state->name_type_new = NetSetupWorkgroupName; +} + +static void callback_enter_domain_and_unlock(GtkWidget *widget, + gpointer data) +{ + const gchar *entry_text = NULL; + struct join_state *state = (struct join_state *)data; + + entry_text = gtk_entry_get_text(GTK_ENTRY(widget)); + debug("callback_enter_domain_and_unlock: %s\n", entry_text); + if (!entry_text || entry_text[0] == 0) { + gtk_widget_set_sensitive(GTK_WIDGET(state->button_ok), FALSE); + return; + } + if (strcasecmp(state->name_buffer_initial, entry_text) == 0) { + gtk_widget_set_sensitive(GTK_WIDGET(state->button_ok), FALSE); + return; + } + gtk_widget_set_sensitive(GTK_WIDGET(state->button_ok), TRUE); + SAFE_FREE(state->name_buffer_new); + state->name_buffer_new = strdup(entry_text); + state->name_type_new = NetSetupDomainName; +} + +static void callback_continue(GtkWidget *widget, + gpointer data) +{ + struct join_state *state = (struct join_state *)data; + + gtk_widget_grab_focus(GTK_WIDGET(state->button_ok)); + g_signal_emit_by_name(state->button_ok, "clicked"); +} + +static void callback_apply_continue(GtkWidget *widget, + gpointer data) +{ + struct join_state *state = (struct join_state *)data; + + gtk_widget_grab_focus(GTK_WIDGET(state->button_apply)); + g_signal_emit_by_name(state->button_apply, "clicked"); +} + +static void callback_do_join_workgroup(GtkWidget *widget, + gpointer data) +{ + struct join_state *state = (struct join_state *)data; + debug("callback_do_join_workgroup choosen\n"); + gtk_widget_set_sensitive(GTK_WIDGET(state->entry_workgroup), TRUE); + gtk_widget_grab_focus(GTK_WIDGET(state->entry_workgroup)); + gtk_widget_set_sensitive(GTK_WIDGET(state->entry_domain), FALSE); + callback_enter_workgroup_and_unlock(state->entry_workgroup, state); /* TEST */ +} + +static void callback_do_join_domain(GtkWidget *widget, + gpointer data) +{ + struct join_state *state = (struct join_state *)data; + debug("callback_do_join_domain choosen\n"); + gtk_widget_set_sensitive(GTK_WIDGET(state->entry_domain), TRUE); + gtk_widget_grab_focus(GTK_WIDGET(state->entry_domain)); + gtk_widget_set_sensitive(GTK_WIDGET(state->entry_workgroup), FALSE); + callback_enter_domain_and_unlock(state->entry_domain, state); /* TEST */ +} + +static void callback_do_change(GtkWidget *widget, + gpointer data) +{ + GtkWidget *window; + GtkWidget *box1; + GtkWidget *bbox; + GtkWidget *button_workgroup; + GtkWidget *button_domain; + GtkWidget *button; + GtkWidget *label; + GtkWidget *frame_horz; + GtkWidget *vbox; + GtkWidget *entry; + GSList *group; + + struct join_state *state = (struct join_state *)data; + + debug("callback_do_change called\n"); + + if (state->server_role == 3) { + GtkWidget *dialog; + dialog = gtk_message_dialog_new(GTK_WINDOW(state->window_main), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR, + GTK_BUTTONS_OK, + "Domain controller cannot be moved from one domain to another, they must first be demoted. Renaming this domain controller may cause it to become temporarily unavailable to users and computers. For information on renaming domain controllers, including alternate renaming methods, see Help and Support. To continue renaming this domain controller, click OK."); + g_signal_connect_swapped(dialog, "response", + G_CALLBACK(gtk_widget_destroy), + dialog); + + gtk_widget_show(dialog); + return; + } + + state->button_ok = gtk_button_new_from_stock(GTK_STOCK_OK); + window = gtk_window_new(GTK_WINDOW_TOPLEVEL); + + gtk_window_set_title(GTK_WINDOW(window), "Computer Name Changes"); + gtk_window_set_resizable(GTK_WINDOW(window), FALSE); + gtk_widget_set_size_request(GTK_WIDGET(window), 480, 500); /* breite * höhe */ + gtk_window_set_icon_from_file(GTK_WINDOW(window), SAMBA_ICON_PATH, NULL); + + g_signal_connect(G_OBJECT(window), "delete_event", + G_CALLBACK(callback_do_close), window); + + gtk_container_set_border_width(GTK_CONTAINER(window), 10); + + box1 = gtk_vbox_new(FALSE, 0); + gtk_container_add(GTK_CONTAINER(window), box1); + + label = gtk_label_new("You can change the name and membership of this computer. Changes may affect access to network ressources."); + gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0); + gtk_box_pack_start(GTK_BOX(box1), label, TRUE, TRUE, 0); + gtk_widget_show(label); + + /* COMPUTER NAME */ + label = gtk_label_new("Computer name:"); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0); + gtk_box_pack_start(GTK_BOX(box1), label, TRUE, TRUE, 0); + gtk_widget_show(label); + + state->label_full_computer_name = gtk_label_new(NULL); + { + entry = gtk_entry_new(); + gtk_entry_set_max_length(GTK_ENTRY(entry), MAX_NETBIOS_NAME_LEN); + g_signal_connect(G_OBJECT(entry), "changed", + G_CALLBACK(callback_enter_hostname_and_unlock), + (gpointer)state); + gtk_entry_set_text(GTK_ENTRY(entry), state->my_hostname); + gtk_editable_select_region(GTK_EDITABLE(entry), + 0, GTK_ENTRY(entry)->text_length); + + gtk_editable_set_editable(GTK_EDITABLE(entry), TRUE); /* ! */ + gtk_box_pack_start(GTK_BOX(box1), entry, TRUE, TRUE, 0); + gtk_widget_show(entry); + } + + /* FULL COMPUTER NAME */ + label = gtk_label_new("Full computer name:"); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0); + gtk_box_pack_start(GTK_BOX(box1), label, TRUE, TRUE, 0); + gtk_widget_show(label); + + { + const gchar *entry_text; + char *str = NULL; + entry_text = gtk_entry_get_text(GTK_ENTRY(entry)); + if (state->name_type_initial == NetSetupDomainName) { + asprintf(&str, "%s.%s", entry_text, state->my_dnsdomain); + } else { + asprintf(&str, "%s.", entry_text); + } + gtk_label_set_text(GTK_LABEL(state->label_full_computer_name), str); + free(str); + gtk_misc_set_alignment(GTK_MISC(state->label_full_computer_name), 0, 0); + gtk_box_pack_start(GTK_BOX(box1), state->label_full_computer_name, TRUE, TRUE, 0); + gtk_widget_show(state->label_full_computer_name); + } + + /* BOX */ + frame_horz = gtk_frame_new ("Member Of"); + gtk_box_pack_start(GTK_BOX(box1), frame_horz, TRUE, TRUE, 10); + + vbox = gtk_vbox_new(FALSE, 0); + gtk_container_set_border_width(GTK_CONTAINER(vbox), 10); + gtk_container_add(GTK_CONTAINER(frame_horz), vbox); + + /* TWO ENTRIES */ + state->entry_workgroup = gtk_entry_new(); + state->entry_domain = gtk_entry_new(); + + /* DOMAIN */ + button_domain = gtk_radio_button_new_with_label(NULL, "Domain"); + if (state->name_type_initial == NetSetupDomainName) { + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button_domain), TRUE); + } + gtk_box_pack_start(GTK_BOX(vbox), button_domain, TRUE, TRUE, 0); + g_signal_connect(G_OBJECT(button_domain), "clicked", + G_CALLBACK(callback_do_join_domain), + (gpointer)state); + + { + gtk_entry_set_max_length(GTK_ENTRY(state->entry_domain), 50); + g_signal_connect(G_OBJECT(state->entry_domain), "changed", + G_CALLBACK(callback_enter_domain_and_unlock), + (gpointer)state); + g_signal_connect(G_OBJECT(state->entry_domain), "activate", + G_CALLBACK(callback_continue), + (gpointer)state); + if (state->name_type_initial == NetSetupDomainName) { + gtk_entry_set_text(GTK_ENTRY(state->entry_domain), state->name_buffer_initial); + gtk_widget_set_sensitive(state->entry_workgroup, FALSE); + gtk_widget_set_sensitive(state->entry_domain, TRUE); + } + gtk_editable_set_editable(GTK_EDITABLE(state->entry_domain), TRUE); + gtk_box_pack_start(GTK_BOX(vbox), state->entry_domain, TRUE, TRUE, 0); + gtk_widget_show(state->entry_domain); + } + gtk_widget_show(button_domain); + + /* WORKGROUP */ + group = gtk_radio_button_get_group(GTK_RADIO_BUTTON(button_domain)); + button_workgroup = gtk_radio_button_new_with_label(group, "Workgroup"); + if (state->name_type_initial == NetSetupWorkgroupName) { + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button_workgroup), TRUE); + } + gtk_box_pack_start(GTK_BOX(vbox), button_workgroup, TRUE, TRUE, 0); + g_signal_connect(G_OBJECT(button_workgroup), "clicked", + G_CALLBACK(callback_do_join_workgroup), + (gpointer)state); + { + gtk_entry_set_max_length(GTK_ENTRY(state->entry_workgroup), MAX_NETBIOS_NAME_LEN); + g_signal_connect(G_OBJECT(state->entry_workgroup), "changed", + G_CALLBACK(callback_enter_workgroup_and_unlock), + (gpointer)state); + g_signal_connect(G_OBJECT(state->entry_workgroup), "activate", + G_CALLBACK(callback_continue), + (gpointer)state); + + if (state->name_type_initial == NetSetupWorkgroupName) { + gtk_entry_set_text(GTK_ENTRY(state->entry_workgroup), state->name_buffer_initial); + gtk_widget_set_sensitive(GTK_WIDGET(state->entry_domain), FALSE); + gtk_widget_set_sensitive(GTK_WIDGET(state->entry_workgroup), TRUE); + } + gtk_box_pack_start(GTK_BOX(vbox), state->entry_workgroup, TRUE, TRUE, 0); + gtk_widget_show(state->entry_workgroup); + } + gtk_widget_show(button_workgroup); + + /* BUTTONS */ + bbox = gtk_hbutton_box_new(); + gtk_container_set_border_width(GTK_CONTAINER(bbox), 5); + gtk_container_add(GTK_CONTAINER(box1), bbox); + gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); + gtk_box_set_spacing(GTK_BOX(bbox), 10); + + state->window_do_change = window; + gtk_widget_set_sensitive(GTK_WIDGET(state->button_ok), FALSE); /* !!! */ + gtk_container_add(GTK_CONTAINER(bbox), state->button_ok); + g_signal_connect(G_OBJECT(state->button_ok), "clicked", + G_CALLBACK(callback_creds_prompt), + (gpointer)state); + + button = gtk_button_new_from_stock(GTK_STOCK_CANCEL); + gtk_container_add(GTK_CONTAINER(bbox), button); + g_signal_connect(G_OBJECT(button), "clicked", + G_CALLBACK(callback_do_close), + (gpointer)window); + + gtk_widget_show_all(window); + +} + +static void callback_do_about(GtkWidget *widget, + gpointer data) +{ + GdkPixbuf *logo; + GError *error = NULL; + + debug("callback_do_about called\n"); + + logo = gdk_pixbuf_new_from_file(SAMBA_IMAGE_PATH, + &error); + if (logo == NULL) { + g_print("failed to load logo from %s: %s\n", + SAMBA_IMAGE_PATH, error->message); + } + + gtk_show_about_dialog(data, + "name", "Samba", + "version", "3.2.0pre2-GIT-904a90-test", + "copyright", "Copyright Andrew Tridgell and the Samba Team 1992-2007", + "website", "http://www.samba.org", + "license", "GPLv3", + "logo", logo, + "comments", "Samba gtk domain join utility", + NULL); +} + +static int draw_main_window(struct join_state *state) +{ + GtkWidget *window; + GtkWidget *button; + GtkWidget *label; + GtkWidget *main_vbox; + GtkWidget *vbox; + GtkWidget *hbox; + GtkWidget *bbox; + GtkWidget *image; + GtkWidget *table; + GtkWidget *entry; + GdkPixbuf *icon; + GError *error = NULL; + + icon = gdk_pixbuf_new_from_file(SAMBA_ICON_PATH, + &error); + if (icon == NULL) { + g_print("failed to load logo from %s : %s\n", + SAMBA_ICON_PATH, error->message); + } + +#if 1 + image = gtk_image_new_from_file(SAMBA_IMAGE_PATH); +#else + image = gtk_image_new_from_file("/usr/share/pixmaps/redhat-system_settings.png"); +#endif + + window = gtk_window_new(GTK_WINDOW_TOPLEVEL); + state->window_main = window; + + gtk_window_set_title(GTK_WINDOW(window), "Samba - Join Domain dialogue"); + gtk_widget_set_size_request(GTK_WIDGET(window), 600, 600); /* breite * höhe */ + gtk_window_set_resizable(GTK_WINDOW(window), FALSE); + gtk_window_set_icon_from_file(GTK_WINDOW(window), SAMBA_ICON_PATH, NULL); + + g_signal_connect(G_OBJECT(window), "delete_event", + G_CALLBACK(callback_delete_event), NULL); + + gtk_container_set_border_width(GTK_CONTAINER(window), 10); + + main_vbox = gtk_vbox_new(FALSE, 10); + gtk_container_add(GTK_CONTAINER(window), main_vbox); + +#if 0 + gtk_box_pack_start(GTK_BOX(main_vbox), image, TRUE, TRUE, 10); + gtk_widget_show(image); +#endif + /* Hbox */ + hbox = gtk_hbox_new(FALSE, 10); + gtk_container_add(GTK_CONTAINER(main_vbox), hbox); + + { +/* gtk_box_pack_start(GTK_BOX(main_vbox), image, TRUE, TRUE, 10); */ + gtk_misc_set_alignment(GTK_MISC(image), 0, 0); + gtk_box_pack_start(GTK_BOX(hbox), image, FALSE, FALSE, 10); + gtk_widget_show(image); + + /* Label */ + label = gtk_label_new("Samba uses the following information to identify your computer on the network."); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0); + gtk_widget_set_size_request(GTK_WIDGET(label), 500, 40); + gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); + gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); + gtk_widget_show(label); + } + + gtk_widget_show(hbox); + + vbox = gtk_vbox_new(FALSE, 0); + gtk_container_set_border_width(GTK_CONTAINER(vbox), 10); + gtk_container_add(GTK_CONTAINER(main_vbox), vbox); + + /* Table */ + table = gtk_table_new(6, 3, TRUE); + gtk_table_set_row_spacings(GTK_TABLE(table), 5); + gtk_table_set_col_spacings(GTK_TABLE(table), 5); + gtk_container_add(GTK_CONTAINER(vbox), table); + + { + /* Label */ + label = gtk_label_new("Computer description:"); +/* gtk_misc_set_alignment(GTK_MISC(label), 0, 0); */ + gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 0, 1); + gtk_widget_show(label); + + state->button_apply = gtk_button_new_from_stock(GTK_STOCK_APPLY); + + /* Entry */ + entry = gtk_entry_new(); + gtk_entry_set_max_length(GTK_ENTRY(entry), 256); + g_signal_connect(G_OBJECT(entry), "changed", + G_CALLBACK(callback_enter_computer_description_and_unlock), + state); + g_signal_connect(G_OBJECT(entry), "activate", + G_CALLBACK(callback_apply_continue), + (gpointer)state); + + gtk_entry_set_text(GTK_ENTRY(entry), (char *)state->comment); + gtk_editable_set_editable(GTK_EDITABLE(entry), TRUE); /* ! */ + gtk_table_attach_defaults(GTK_TABLE(table), entry, 1, 3, 0, 1); + gtk_widget_show(entry); + } + + /* Label */ + label = gtk_label_new("For example: \"Samba \%v\"."); + gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0); + gtk_table_attach_defaults(GTK_TABLE(table), label, 1, 3, 1, 2); + gtk_widget_show(label); + + /* Label */ + label = gtk_label_new("Full computer name:"); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0); + gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 2, 3); + gtk_widget_show(label); + + { + /* Label */ + char *str = NULL; + if (state->name_type_initial == NetSetupDomainName) { + asprintf(&str, "%s.%s", state->my_hostname, + state->my_dnsdomain); + } else { + asprintf(&str, "%s.", state->my_hostname); + } + + label = gtk_label_new(str); + SAFE_FREE(str); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0); + gtk_table_attach_defaults(GTK_TABLE(table), label, 1, 3, 2, 3); + gtk_widget_show(label); + } + + /* Label */ + if (state->name_type_initial == NetSetupDomainName) { + label = gtk_label_new("Domain:"); + } else { + label = gtk_label_new("Workgroup:"); + } + gtk_misc_set_alignment(GTK_MISC(label), 0, 0); + gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 3, 4); + gtk_widget_show(label); + state->label_current_name_type = label; + + /* Label */ + label = gtk_label_new(state->name_buffer_initial); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0); + gtk_table_attach_defaults(GTK_TABLE(table), label, 1, 3, 3, 4); + gtk_widget_show(label); + state->label_current_name_buffer = label; + + { + hbox = gtk_hbox_new(FALSE, 0); + gtk_container_add(GTK_CONTAINER(vbox), hbox); + label = gtk_label_new("To rename this computer or join a domain, click Change."); + gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); + + + } + + /* bbox */ + bbox = gtk_hbutton_box_new(); + gtk_container_set_border_width(GTK_CONTAINER(bbox), 5); + gtk_container_add(GTK_CONTAINER(hbox), bbox); + gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); + gtk_box_set_spacing(GTK_BOX(bbox), 10); + + button = gtk_button_new_with_mnemonic("Ch_ange"); + g_signal_connect(G_OBJECT(button), "clicked", + G_CALLBACK(callback_do_change), + (gpointer)state); + gtk_box_pack_start(GTK_BOX(bbox), button, TRUE, TRUE, 0); + gtk_widget_show(button); + + /* Label (hidden) */ + state->label_reboot = gtk_label_new(NULL); + gtk_label_set_line_wrap(GTK_LABEL(state->label_reboot), TRUE); + gtk_misc_set_alignment(GTK_MISC(state->label_reboot), 0, 0); + gtk_box_pack_start(GTK_BOX(vbox), state->label_reboot, TRUE, TRUE, 0); + gtk_widget_show(state->label_reboot); + +#if 0 + gtk_box_pack_start(GTK_BOX(vbox), + create_bbox(window, TRUE, NULL, 10, 85, 20, GTK_BUTTONBOX_END), + TRUE, TRUE, 5); +#endif + { + + GtkWidget *frame; + GtkWidget *bbox2; + GtkWidget *button2; + + frame = gtk_frame_new(NULL); + bbox2 = gtk_hbutton_box_new(); + + gtk_container_set_border_width(GTK_CONTAINER(bbox2), 5); + gtk_container_add(GTK_CONTAINER(frame), bbox2); + + /* Set the appearance of the Button Box */ + gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox2), GTK_BUTTONBOX_END); + gtk_box_set_spacing(GTK_BOX(bbox2), 10); + /*gtk_button_box_set_child_size(GTK_BUTTON_BOX(bbox2), child_w, child_h);*/ + + button2 = gtk_button_new_from_stock(GTK_STOCK_OK); + gtk_container_add(GTK_CONTAINER(bbox2), button2); + g_signal_connect(G_OBJECT(button2), "clicked", G_CALLBACK(callback_do_exit), state); + + button2 = gtk_button_new_from_stock(GTK_STOCK_CANCEL); + gtk_container_add(GTK_CONTAINER(bbox2), button2); + g_signal_connect(G_OBJECT(button2), "clicked", + G_CALLBACK(callback_delete_event), + window); + + gtk_container_add(GTK_CONTAINER(bbox2), state->button_apply); + g_signal_connect(G_OBJECT(state->button_apply), "clicked", + G_CALLBACK(callback_apply_description_change), + state); + gtk_widget_set_sensitive(GTK_WIDGET(state->button_apply), FALSE); + + button2 = gtk_button_new_from_stock(GTK_STOCK_ABOUT); + gtk_container_add(GTK_CONTAINER(bbox2), button2); + g_signal_connect(G_OBJECT(button2), "clicked", + G_CALLBACK(callback_do_about), + window); + + gtk_box_pack_start(GTK_BOX(vbox), frame, TRUE, TRUE, 5); + } + + gtk_widget_show_all(window); + + return 0; +} + +static int init_join_state(struct join_state **state) +{ + struct join_state *s; + + s = malloc(sizeof(struct join_state)); + if (!s) { + return -1; + } + + memset(s, '\0', sizeof(struct join_state)); + + *state = s; + + return 0; +} + +static int initialize_join_state(struct join_state *state, + const char *debug_level) +{ + struct libnetapi_ctx *ctx = NULL; + NET_API_STATUS status = 0; + + status = libnetapi_init(&ctx); + if (status) { + return status; + } + + if (debug_level) { + libnetapi_set_debuglevel(ctx, debug_level); + } + + { + char my_hostname[HOST_NAME_MAX]; + const char *p = NULL; + if (gethostname(my_hostname, sizeof(my_hostname)) == -1) { + return -1; + } + + state->my_fqdn = strdup(my_hostname); + if (!state->my_fqdn) { + return -1; + } + + p = strchr(my_hostname, '.'); + if (p) { + my_hostname[strlen(my_hostname) - strlen(p)] = '\0'; + state->my_hostname = strdup(my_hostname); + if (!state->my_hostname) { + return -1; + } + p++; + state->my_dnsdomain = strdup(p); + if (!state->my_dnsdomain) { + return -1; + } + } + } + + { + const char *buffer = NULL; + uint16_t type = 0; + status = NetGetJoinInformation(NULL, &buffer, &type); + if (status) { + return status; + } + state->name_buffer_initial = (char *)buffer; + state->name_type_initial = type; + } + + { + struct srvsvc_NetSrvInfo1005 *info1005 = NULL; + uint8_t *buffer = NULL; + + status = NetServerGetInfo(NULL, 1005, &buffer); + if (status) { + return status; + } + + info1005 = (struct srvsvc_NetSrvInfo1005 *)buffer; + + state->comment = strdup(info1005->comment); + if (!state->comment) { + return -1; + } + } +#if 0 + { + struct srvsvc_NetSrvInfo100 *info100 = NULL; + uint8_t *buffer = NULL; + + status = NetServerGetInfo(NULL, 100, &buffer); + if (status) { + return status; + } + + info100 = (struct srvsvc_NetSrvInfo100 *)buffer; + + state->comment = strdup(info100->comment); + if (!state->comment) { + return -1; + } + } +#endif + + state->ctx = ctx; + + return 0; +} + +int main(int argc, char **argv) +{ + GOptionContext *context = NULL; + static const char *debug_level = NULL; + struct join_state *state = NULL; + GError *error = NULL; + int ret = 0; + + static GOptionEntry entries[] = { + { "debug", 'd', 0, G_OPTION_ARG_STRING, &debug_level, "Debug level (for samba)", "N" }, + { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, "Verbose output", 0 }, + { NULL } + }; + + context = g_option_context_new("- Samba domain join utility"); + g_option_context_add_main_entries(context, entries, NULL); +/* g_option_context_add_main_entries(context, entries, GETTEXT_PACKAGE); */ + g_option_context_add_group(context, gtk_get_option_group(TRUE)); + g_option_context_parse(context, &argc, &argv, &error); + + gtk_init(&argc, &argv); + g_set_application_name("Samba"); + + ret = init_join_state(&state); + if (ret) { + return ret; + } + + ret = initialize_join_state(state, debug_level); + if (ret) { + return ret; + } + + draw_main_window(state); + + gtk_main(); + + do_cleanup(state); + + return 0; +} diff --git a/source3/lib/netapi/examples/netdomjoin/netdomjoin-gui.c b/source3/lib/netapi/examples/netdomjoin/netdomjoin-gui.c deleted file mode 100644 index 8ca6897cab..0000000000 --- a/source3/lib/netapi/examples/netdomjoin/netdomjoin-gui.c +++ /dev/null @@ -1,1347 +0,0 @@ -/* - * Unix SMB/CIFS implementation. - * Join Support (gtk + netapi) - * Copyright (C) Guenther Deschner 2007 - * - * 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 - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see . - */ - -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include - -#include -#include - -#include - -#define MAX_CRED_LEN 256 -#define MAX_NETBIOS_NAME_LEN 15 - -#define SAMBA_ICON_PATH "/usr/share/pixmaps/samba/samba.ico" -#define SAMBA_IMAGE_PATH "/usr/share/pixmaps/samba/logo.png" - -#define WKSSVC_JOIN_FLAGS_DOMAIN_JOIN_IF_JOINED ( 0x00000020 ) -#define WKSSVC_JOIN_FLAGS_ACCOUNT_DELETE ( 0x00000004 ) -#define WKSSVC_JOIN_FLAGS_ACCOUNT_CREATE ( 0x00000002 ) -#define WKSSVC_JOIN_FLAGS_JOIN_TYPE ( 0x00000001 ) - -#define NetSetupWorkgroupName ( 2 ) -#define NetSetupDomainName ( 3 ) - -#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0) - -struct srvsvc_NetSrvInfo1005 { - const char *comment;/* [unique,charset(UTF16)] */ -}; - -static gboolean verbose = FALSE; - -typedef struct join_state { - struct libnetapi_ctx *ctx; - GtkWidget *window_main; - GtkWidget *window_parent; - GtkWidget *window_do_change; - GtkWidget *window_creds_prompt; - GtkWidget *entry_account; - GtkWidget *entry_password; - GtkWidget *entry_domain; - GtkWidget *entry_workgroup; - GtkWidget *button_ok; - GtkWidget *button_apply; - GtkWidget *button_ok_creds; - GtkWidget *label_reboot; - GtkWidget *label_current_name_buffer; - GtkWidget *label_current_name_type; - GtkWidget *label_full_computer_name; - uint16_t name_type_initial; - uint16_t name_type_new; - char *name_buffer_initial; - char *name_buffer_new; - char *password; - char *account; - char *comment; - char *comment_new; - char *my_fqdn; - char *my_dnsdomain; - char *my_hostname; - uint16_t server_role; - gboolean settings_changed; - gboolean hostname_changed; -} join_state; - -static void debug(const char *format, ...) -{ - va_list args; - - if (!verbose) { - return; - } - - va_start(args, format); - g_vprintf(format, args); - va_end(args); -} - -static gboolean callback_delete_event(GtkWidget *widget, - GdkEvent *event, - gpointer data) -{ - gtk_main_quit(); - return FALSE; -} - -static void callback_do_close(GtkWidget *widget, - gpointer data) -{ - debug("Closing now...\n"); - gtk_widget_destroy(data); -} - -static void free_join_state(struct join_state *s) -{ - SAFE_FREE(s->name_buffer_initial); - SAFE_FREE(s->name_buffer_new); - SAFE_FREE(s->password); - SAFE_FREE(s->account); - SAFE_FREE(s->comment); - SAFE_FREE(s->comment_new); - SAFE_FREE(s->my_fqdn); - SAFE_FREE(s->my_dnsdomain); - SAFE_FREE(s->my_hostname); - -} - -static void do_cleanup(struct join_state *state) -{ - libnetapi_free(state->ctx); - free_join_state(state); -} - -static void callback_apply_description_change(GtkWidget *widget, - gpointer data) -{ - struct join_state *state = (struct join_state *)data; - NET_API_STATUS status = 0; - uint32_t parm_err = 0; - struct srvsvc_NetSrvInfo1005 info1005; - GtkWidget *dialog; - - info1005.comment = state->comment_new; - - status = NetServerSetInfo(NULL, 1005, (uint8_t *)&info1005, &parm_err); - if (status) { - debug("NetServerSetInfo failed with: %s\n", - libnetapi_errstr(state->ctx, status)); - dialog = gtk_message_dialog_new(GTK_WINDOW(state->window_main), - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_ERROR, - GTK_BUTTONS_OK, - "Failed to change computer description: %s.", - libnetapi_errstr(state->ctx, status)); - g_signal_connect_swapped(dialog, "response", - G_CALLBACK(gtk_widget_destroy), - dialog); - - gtk_widget_show(dialog); - return; - } - - gtk_widget_set_sensitive(GTK_WIDGET(state->button_apply), FALSE); -} - -static void callback_do_exit(GtkWidget *widget, - gpointer data) -{ - GtkWidget *dialog; - gint result; - struct join_state *state = (struct join_state *)data; - - if (!state->settings_changed) { - callback_delete_event(NULL, NULL, NULL); - return; - } - - dialog = gtk_message_dialog_new(GTK_WINDOW(state->window_main), - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_QUESTION, - GTK_BUTTONS_YES_NO, - "You must restart your computer before the new settings will take effect."); - result = gtk_dialog_run(GTK_DIALOG(dialog)); - switch (result) { - case GTK_RESPONSE_YES: - g_print("would reboot here\n"); - break; - case GTK_RESPONSE_NO: - default: - break; - } - gtk_widget_destroy(dialog); - gtk_widget_destroy(state->window_main); - do_cleanup(state); - exit(0); -} - - -static void callback_do_reboot(GtkWidget *widget, - gpointer data, - gpointer data2) -{ - GtkWidget *dialog; - struct join_state *state = (struct join_state *)data2; - - debug("callback_do_reboot\n"); - - state->settings_changed = TRUE; - dialog = gtk_message_dialog_new(GTK_WINDOW(data), - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_INFO, - GTK_BUTTONS_OK, - "You must restart this computer for the changes to take effect."); -#if 0 - g_signal_connect_swapped(dialog, "response", - G_CALLBACK(gtk_widget_destroy), - dialog); - - debug("showing dialog\n"); - gtk_widget_show(dialog); -#else - gtk_dialog_run(GTK_DIALOG(dialog)); - gtk_widget_destroy(dialog); -#endif - - gtk_label_set_text(GTK_LABEL(state->label_reboot), "Changes will take effect after you restart this computer"); - - debug("destroying do_change window\n"); - gtk_widget_destroy(GTK_WIDGET(state->window_do_change)); - - { - uint32_t status; - const char *buffer; - uint16_t type; - - status = NetGetJoinInformation(NULL, &buffer, &type); - if (status != 0) { - g_print("failed to query status\n"); - return; - } - - debug("got new status: %s\n", buffer); -#if 0 - SAFE_FREE(state->name_buffer_new); - state->name_buffer_new = strdup(buffer); - SAFE_FREE(buffer); - state->name_type_new = type; -#endif - gtk_label_set_text(GTK_LABEL(state->label_current_name_buffer), state->name_buffer_new); - if (state->name_type_new == 3) { - gtk_label_set_text(GTK_LABEL(state->label_current_name_type), "Domain:"); - } else { - gtk_label_set_text(GTK_LABEL(state->label_current_name_type), "Workgroup:"); - } - } -} - -static void callback_return_username(GtkWidget *widget, - gpointer data) -{ - const gchar *entry_text; - struct join_state *state = (struct join_state *)data; - if (!widget) { - return; - } - entry_text = gtk_entry_get_text(GTK_ENTRY(widget)); - debug("callback_return_username: %s\n", entry_text); - SAFE_FREE(state->account); - state->account = strdup(entry_text); -} - -static void callback_return_username_and_enter(GtkWidget *widget, - gpointer data) -{ - const gchar *entry_text; - struct join_state *state = (struct join_state *)data; - if (!widget) { - return; - } - entry_text = gtk_entry_get_text(GTK_ENTRY(widget)); - debug("callback_return_username: %s\n", entry_text); - SAFE_FREE(state->account); - state->account = strdup(entry_text); - g_signal_emit_by_name(state->button_ok_creds, "clicked"); -} - -static void callback_return_password(GtkWidget *widget, - gpointer data) -{ - const gchar *entry_text; - struct join_state *state = (struct join_state *)data; - if (!widget) { - return; - } - entry_text = gtk_entry_get_text(GTK_ENTRY(widget)); -#ifdef DEBUG_PASSWORD - debug("callback_return_password: %s\n", entry_text); -#else - debug("callback_return_password: (not printed)\n"); -#endif - SAFE_FREE(state->password); - state->password = strdup(entry_text); -} - -static void callback_return_password_and_enter(GtkWidget *widget, - gpointer data) -{ - const gchar *entry_text; - struct join_state *state = (struct join_state *)data; - if (!widget) { - return; - } - entry_text = gtk_entry_get_text(GTK_ENTRY(widget)); -#ifdef DEBUG_PASSWORD - debug("callback_return_password: %s\n", entry_text); -#else - debug("callback_return_password: (not printed)\n"); -#endif - SAFE_FREE(state->password); - state->password = strdup(entry_text); - g_signal_emit_by_name(state->button_ok_creds, "clicked"); -} - -static void callback_do_hostname_change(GtkWidget *widget, - gpointer data) -{ - GtkWidget *dialog; - const char *str = NULL; - - struct join_state *state = (struct join_state *)data; - - switch (state->name_type_initial) { - case NetSetupDomainName: - str = "To be implemented: call NetRenameMachineInDomain\n"; - break; - case NetSetupWorkgroupName: - str = "To be implemented: call SetComputerNameEx\n"; - break; - default: - break; - } - - dialog = gtk_message_dialog_new(GTK_WINDOW(state->window_parent), - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_ERROR, - GTK_BUTTONS_CLOSE, - str); - - g_signal_connect_swapped(dialog, "response", - G_CALLBACK(gtk_widget_destroy), - dialog); - gtk_widget_show(dialog); -} - -static void callback_do_join(GtkWidget *widget, - gpointer data) -{ - GtkWidget *dialog; - - NET_API_STATUS status; - const char *err_str = NULL; - uint32_t join_flags = 0; - uint32_t unjoin_flags = 0; - gboolean domain_join = FALSE; - gboolean try_unjoin = FALSE; - const char *domain_or_workgroup = NULL; - - struct join_state *state = (struct join_state *)data; - - callback_return_username(state->entry_account, state); - callback_return_password(state->entry_password, state); - - if (state->window_creds_prompt) { - gtk_widget_destroy(GTK_WIDGET(state->window_creds_prompt)); - } - - if (state->name_type_new == NetSetupDomainName) { - domain_join = TRUE; - join_flags = WKSSVC_JOIN_FLAGS_JOIN_TYPE | - WKSSVC_JOIN_FLAGS_ACCOUNT_CREATE | - WKSSVC_JOIN_FLAGS_DOMAIN_JOIN_IF_JOINED; /* for testing */ - domain_or_workgroup = "domain"; - } else { - domain_or_workgroup = "workgroup"; - } - - if ((state->name_type_initial == NetSetupDomainName) && - (state->name_type_new == NetSetupWorkgroupName)) { - try_unjoin = TRUE; - unjoin_flags = WKSSVC_JOIN_FLAGS_JOIN_TYPE | - WKSSVC_JOIN_FLAGS_ACCOUNT_DELETE; - } - - debug("callback_do_join: Joining a %s named %s using join_flags 0x%08x ", - domain_or_workgroup, - state->name_buffer_new, - join_flags); - if (domain_join) { - debug("as %s ", state->account); -#ifdef DEBUG_PASSWORD - debug("with %s ", state->password); -#endif - } - debug("\n"); - if (try_unjoin) { - - debug("callback_do_join: Unjoining\n"); - - status = NetUnjoinDomain(NULL, - state->account, - state->password, - unjoin_flags); - if (status != 0) { - err_str = libnetapi_errstr(state->ctx, status); - g_print("callback_do_join: failed to unjoin (%s)\n", - err_str); - - dialog = gtk_message_dialog_new(GTK_WINDOW(state->window_parent), - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_ERROR, - GTK_BUTTONS_CLOSE, - "The following error occured attempting to unjoin the %s: \"%s\": %s", - domain_or_workgroup, - state->name_buffer_new, - err_str); - - g_signal_connect_swapped(dialog, "response", - G_CALLBACK(gtk_widget_destroy), - dialog); - - gtk_widget_show(dialog); - - return; - } - - } - status = NetJoinDomain(NULL, - state->name_buffer_new, - NULL, - state->account, - state->password, - join_flags); - if (status != 0) { - err_str = libnetapi_errstr(state->ctx, status); - g_print("callback_do_join: failed to join (%s)\n", err_str); - - dialog = gtk_message_dialog_new(GTK_WINDOW(state->window_parent), - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_ERROR, - GTK_BUTTONS_CLOSE, - "The following error occured attempting to join the %s: \"%s\": %s", - domain_or_workgroup, - state->name_buffer_new, - err_str); - - g_signal_connect_swapped(dialog, "response", - G_CALLBACK(gtk_widget_destroy), - dialog); - - gtk_widget_show(dialog); - - return; - } - - debug("callback_do_join: Successfully joined %s\n", - domain_or_workgroup); - - dialog = gtk_message_dialog_new(GTK_WINDOW(state->window_parent), - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_INFO, - GTK_BUTTONS_OK, - "Welcome to the %s %s.", - state->name_buffer_new, - domain_or_workgroup); - - gtk_dialog_run(GTK_DIALOG(dialog)); - gtk_widget_destroy(dialog); - - callback_do_reboot(NULL, state->window_parent, state); -} - -static void callback_creds_prompt(GtkWidget *widget, - gpointer data) -{ - GtkWidget *window; - GtkWidget *box1; - GtkWidget *bbox; - GtkWidget *button; - GtkWidget *label; - - struct join_state *state = (struct join_state *)data; - - debug("callback_creds_prompt:\n"); - - state->window_parent = state->window_do_change; - - if (state->hostname_changed) { - return callback_do_hostname_change(NULL, state); - } - - if ((state->name_type_initial != NetSetupDomainName) && - (state->name_type_new != NetSetupDomainName)) { - return callback_do_join(NULL, state); - } - - window = gtk_window_new(GTK_WINDOW_TOPLEVEL); - - gtk_window_set_title(GTK_WINDOW(window), "Computer Name Changes"); - gtk_window_set_resizable(GTK_WINDOW(window), FALSE); - gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER); - gtk_widget_set_size_request(GTK_WIDGET(window), 380, 280); - gtk_window_set_icon_from_file(GTK_WINDOW(window), SAMBA_ICON_PATH, NULL); -/* gtk_window_set_icon_name(GTK_WIDGET(window), GTK_STOCK_DIALOG_AUTHENTICATION); */ - state->window_creds_prompt = window; - - g_signal_connect(G_OBJECT(window), "delete_event", - G_CALLBACK(callback_do_close), window); - - gtk_container_set_border_width(GTK_CONTAINER(window), 10); - - box1 = gtk_vbox_new(FALSE, 0); - - gtk_container_add(GTK_CONTAINER(window), box1); - - if ((state->name_type_initial == NetSetupDomainName) && - (state->name_type_new == NetSetupWorkgroupName)) { - label = gtk_label_new("Enter the name and password of an account with permission to leave the domain.\n"); - } else { - label = gtk_label_new("Enter the name and password of an account with permission to join the domain.\n"); - } - gtk_misc_set_alignment(GTK_MISC(label), 0, 0); - gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); - - gtk_box_pack_start(GTK_BOX(box1), label, FALSE, FALSE, 0); - - gtk_widget_show(label); - - /* USER NAME */ - label = gtk_label_new("User name:"); - gtk_misc_set_alignment(GTK_MISC(label), 0, 0); - gtk_box_pack_start(GTK_BOX(box1), label, FALSE, FALSE, 0); - gtk_widget_show(label); - - state->entry_account = gtk_entry_new(); - gtk_entry_set_max_length(GTK_ENTRY(state->entry_account), MAX_CRED_LEN); - g_signal_connect(G_OBJECT(state->entry_account), "activate", - G_CALLBACK(callback_return_username_and_enter), - (gpointer)state); - gtk_editable_select_region(GTK_EDITABLE(state->entry_account), - 0, GTK_ENTRY(state->entry_account)->text_length); - gtk_box_pack_start(GTK_BOX(box1), state->entry_account, TRUE, TRUE, 0); - gtk_widget_show(state->entry_account); - - /* PASSWORD */ - label = gtk_label_new("Password:"); - gtk_misc_set_alignment(GTK_MISC(label), 0, 0); - gtk_box_pack_start(GTK_BOX(box1), label, FALSE, FALSE, 0); - gtk_widget_show(label); - - state->entry_password = gtk_entry_new(); - gtk_entry_set_max_length(GTK_ENTRY(state->entry_password), MAX_CRED_LEN); - gtk_entry_set_visibility(GTK_ENTRY(state->entry_password), FALSE); - g_signal_connect(G_OBJECT(state->entry_password), "activate", - G_CALLBACK(callback_return_password_and_enter), - (gpointer)state); - gtk_editable_set_editable(GTK_EDITABLE(state->entry_password), TRUE); - gtk_editable_select_region(GTK_EDITABLE(state->entry_password), - 0, GTK_ENTRY(state->entry_password)->text_length); - gtk_box_pack_start(GTK_BOX(box1), state->entry_password, TRUE, TRUE, 0); - gtk_widget_show(state->entry_password); - - bbox = gtk_hbutton_box_new(); - gtk_container_set_border_width(GTK_CONTAINER(bbox), 5); - gtk_container_add(GTK_CONTAINER(box1), bbox); - gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); - gtk_box_set_spacing(GTK_BOX(bbox), 10); - - state->button_ok_creds = gtk_button_new_from_stock(GTK_STOCK_OK); - gtk_widget_grab_focus(GTK_WIDGET(state->button_ok_creds)); - gtk_container_add(GTK_CONTAINER(bbox), state->button_ok_creds); - g_signal_connect(G_OBJECT(state->button_ok_creds), "clicked", - G_CALLBACK(callback_do_join), - (gpointer)state); - gtk_widget_show(state->button_ok_creds); - - button = gtk_button_new_from_stock(GTK_STOCK_CANCEL); - gtk_container_add(GTK_CONTAINER(bbox), button); - g_signal_connect(G_OBJECT(button), "clicked", - G_CALLBACK(callback_do_close), (gpointer) window); - gtk_widget_show_all(window); -} - -static void callback_enter_hostname_and_unlock(GtkWidget *widget, - gpointer data) -{ - const gchar *entry_text = NULL; - char *str = NULL; - struct join_state *state = (struct join_state *)data; - - entry_text = gtk_entry_get_text(GTK_ENTRY(widget)); - debug("callback_enter_hostname_and_unlock: %s\n", entry_text); - if (!entry_text || entry_text[0] == 0) { - state->hostname_changed = FALSE; - gtk_widget_set_sensitive(GTK_WIDGET(state->button_ok), FALSE); - return; - } - if (strcasecmp(state->my_hostname, entry_text) == 0) { - state->hostname_changed = FALSE; - gtk_widget_set_sensitive(GTK_WIDGET(state->button_ok), FALSE); - return; - } - state->hostname_changed = TRUE; - if (state->name_type_initial == NetSetupDomainName) { - asprintf(&str, "%s.%s", entry_text, state->my_dnsdomain); - } else { - asprintf(&str, "%s.", entry_text); - } - gtk_label_set_text(GTK_LABEL(state->label_full_computer_name), str); - free(str); - - if (state->hostname_changed && str && str[0] != 0 && str[0] != '.') { - gtk_widget_set_sensitive(GTK_WIDGET(state->button_ok), TRUE); - } -} - -static void callback_enter_computer_description_and_unlock(GtkWidget *widget, - gpointer data) -{ - const gchar *entry_text = NULL; - struct join_state *state = (struct join_state *)data; - int string_unchanged = 0; - - entry_text = gtk_entry_get_text(GTK_ENTRY(widget)); - debug("callback_enter_computer_description_and_unlock: %s\n", - entry_text); -#if 0 - if (!entry_text || entry_text[0] == 0) { - string_unchanged = 1; - gtk_widget_set_sensitive(GTK_WIDGET(state->button_apply), - FALSE); - return; - } -#endif - if (entry_text && strcasecmp(state->comment, entry_text) == 0) { - string_unchanged = 1; - gtk_widget_set_sensitive(GTK_WIDGET(state->button_apply), - FALSE); - return; - } - - gtk_widget_set_sensitive(GTK_WIDGET(state->button_apply), TRUE); - SAFE_FREE(state->comment_new); - state->comment_new = strdup(entry_text); - -} - - -static void callback_enter_workgroup_and_unlock(GtkWidget *widget, - gpointer data) -{ - const gchar *entry_text = NULL; - struct join_state *state = (struct join_state *)data; - - entry_text = gtk_entry_get_text(GTK_ENTRY(widget)); - debug("callback_enter_workgroup_and_unlock: %s\n", entry_text); - if (!entry_text || entry_text[0] == 0) { - gtk_widget_set_sensitive(GTK_WIDGET(state->button_ok), FALSE); - return; - } - if (strcasecmp(state->name_buffer_initial, entry_text) == 0) { - gtk_widget_set_sensitive(GTK_WIDGET(state->button_ok), FALSE); - return; - } - gtk_widget_set_sensitive(GTK_WIDGET(state->button_ok), TRUE); - SAFE_FREE(state->name_buffer_new); - state->name_buffer_new = strdup(entry_text); - state->name_type_new = NetSetupWorkgroupName; -} - -static void callback_enter_domain_and_unlock(GtkWidget *widget, - gpointer data) -{ - const gchar *entry_text = NULL; - struct join_state *state = (struct join_state *)data; - - entry_text = gtk_entry_get_text(GTK_ENTRY(widget)); - debug("callback_enter_domain_and_unlock: %s\n", entry_text); - if (!entry_text || entry_text[0] == 0) { - gtk_widget_set_sensitive(GTK_WIDGET(state->button_ok), FALSE); - return; - } - if (strcasecmp(state->name_buffer_initial, entry_text) == 0) { - gtk_widget_set_sensitive(GTK_WIDGET(state->button_ok), FALSE); - return; - } - gtk_widget_set_sensitive(GTK_WIDGET(state->button_ok), TRUE); - SAFE_FREE(state->name_buffer_new); - state->name_buffer_new = strdup(entry_text); - state->name_type_new = NetSetupDomainName; -} - -static void callback_continue(GtkWidget *widget, - gpointer data) -{ - struct join_state *state = (struct join_state *)data; - - gtk_widget_grab_focus(GTK_WIDGET(state->button_ok)); - g_signal_emit_by_name(state->button_ok, "clicked"); -} - -static void callback_apply_continue(GtkWidget *widget, - gpointer data) -{ - struct join_state *state = (struct join_state *)data; - - gtk_widget_grab_focus(GTK_WIDGET(state->button_apply)); - g_signal_emit_by_name(state->button_apply, "clicked"); -} - -static void callback_do_join_workgroup(GtkWidget *widget, - gpointer data) -{ - struct join_state *state = (struct join_state *)data; - debug("callback_do_join_workgroup choosen\n"); - gtk_widget_set_sensitive(GTK_WIDGET(state->entry_workgroup), TRUE); - gtk_widget_grab_focus(GTK_WIDGET(state->entry_workgroup)); - gtk_widget_set_sensitive(GTK_WIDGET(state->entry_domain), FALSE); - callback_enter_workgroup_and_unlock(state->entry_workgroup, state); /* TEST */ -} - -static void callback_do_join_domain(GtkWidget *widget, - gpointer data) -{ - struct join_state *state = (struct join_state *)data; - debug("callback_do_join_domain choosen\n"); - gtk_widget_set_sensitive(GTK_WIDGET(state->entry_domain), TRUE); - gtk_widget_grab_focus(GTK_WIDGET(state->entry_domain)); - gtk_widget_set_sensitive(GTK_WIDGET(state->entry_workgroup), FALSE); - callback_enter_domain_and_unlock(state->entry_domain, state); /* TEST */ -} - -static void callback_do_change(GtkWidget *widget, - gpointer data) -{ - GtkWidget *window; - GtkWidget *box1; - GtkWidget *bbox; - GtkWidget *button_workgroup; - GtkWidget *button_domain; - GtkWidget *button; - GtkWidget *label; - GtkWidget *frame_horz; - GtkWidget *vbox; - GtkWidget *entry; - GSList *group; - - struct join_state *state = (struct join_state *)data; - - debug("callback_do_change called\n"); - - if (state->server_role == 3) { - GtkWidget *dialog; - dialog = gtk_message_dialog_new(GTK_WINDOW(state->window_main), - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_ERROR, - GTK_BUTTONS_OK, - "Domain controller cannot be moved from one domain to another, they must first be demoted. Renaming this domain controller may cause it to become temporarily unavailable to users and computers. For information on renaming domain controllers, including alternate renaming methods, see Help and Support. To continue renaming this domain controller, click OK."); - g_signal_connect_swapped(dialog, "response", - G_CALLBACK(gtk_widget_destroy), - dialog); - - gtk_widget_show(dialog); - return; - } - - state->button_ok = gtk_button_new_from_stock(GTK_STOCK_OK); - window = gtk_window_new(GTK_WINDOW_TOPLEVEL); - - gtk_window_set_title(GTK_WINDOW(window), "Computer Name Changes"); - gtk_window_set_resizable(GTK_WINDOW(window), FALSE); - gtk_widget_set_size_request(GTK_WIDGET(window), 480, 500); /* breite * höhe */ - gtk_window_set_icon_from_file(GTK_WINDOW(window), SAMBA_ICON_PATH, NULL); - - g_signal_connect(G_OBJECT(window), "delete_event", - G_CALLBACK(callback_do_close), window); - - gtk_container_set_border_width(GTK_CONTAINER(window), 10); - - box1 = gtk_vbox_new(FALSE, 0); - gtk_container_add(GTK_CONTAINER(window), box1); - - label = gtk_label_new("You can change the name and membership of this computer. Changes may affect access to network ressources."); - gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); - gtk_misc_set_alignment(GTK_MISC(label), 0, 0); - gtk_box_pack_start(GTK_BOX(box1), label, TRUE, TRUE, 0); - gtk_widget_show(label); - - /* COMPUTER NAME */ - label = gtk_label_new("Computer name:"); - gtk_misc_set_alignment(GTK_MISC(label), 0, 0); - gtk_box_pack_start(GTK_BOX(box1), label, TRUE, TRUE, 0); - gtk_widget_show(label); - - state->label_full_computer_name = gtk_label_new(NULL); - { - entry = gtk_entry_new(); - gtk_entry_set_max_length(GTK_ENTRY(entry), MAX_NETBIOS_NAME_LEN); - g_signal_connect(G_OBJECT(entry), "changed", - G_CALLBACK(callback_enter_hostname_and_unlock), - (gpointer)state); - gtk_entry_set_text(GTK_ENTRY(entry), state->my_hostname); - gtk_editable_select_region(GTK_EDITABLE(entry), - 0, GTK_ENTRY(entry)->text_length); - - gtk_editable_set_editable(GTK_EDITABLE(entry), TRUE); /* ! */ - gtk_box_pack_start(GTK_BOX(box1), entry, TRUE, TRUE, 0); - gtk_widget_show(entry); - } - - /* FULL COMPUTER NAME */ - label = gtk_label_new("Full computer name:"); - gtk_misc_set_alignment(GTK_MISC(label), 0, 0); - gtk_box_pack_start(GTK_BOX(box1), label, TRUE, TRUE, 0); - gtk_widget_show(label); - - { - const gchar *entry_text; - char *str = NULL; - entry_text = gtk_entry_get_text(GTK_ENTRY(entry)); - if (state->name_type_initial == NetSetupDomainName) { - asprintf(&str, "%s.%s", entry_text, state->my_dnsdomain); - } else { - asprintf(&str, "%s.", entry_text); - } - gtk_label_set_text(GTK_LABEL(state->label_full_computer_name), str); - free(str); - gtk_misc_set_alignment(GTK_MISC(state->label_full_computer_name), 0, 0); - gtk_box_pack_start(GTK_BOX(box1), state->label_full_computer_name, TRUE, TRUE, 0); - gtk_widget_show(state->label_full_computer_name); - } - - /* BOX */ - frame_horz = gtk_frame_new ("Member Of"); - gtk_box_pack_start(GTK_BOX(box1), frame_horz, TRUE, TRUE, 10); - - vbox = gtk_vbox_new(FALSE, 0); - gtk_container_set_border_width(GTK_CONTAINER(vbox), 10); - gtk_container_add(GTK_CONTAINER(frame_horz), vbox); - - /* TWO ENTRIES */ - state->entry_workgroup = gtk_entry_new(); - state->entry_domain = gtk_entry_new(); - - /* DOMAIN */ - button_domain = gtk_radio_button_new_with_label(NULL, "Domain"); - if (state->name_type_initial == NetSetupDomainName) { - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button_domain), TRUE); - } - gtk_box_pack_start(GTK_BOX(vbox), button_domain, TRUE, TRUE, 0); - g_signal_connect(G_OBJECT(button_domain), "clicked", - G_CALLBACK(callback_do_join_domain), - (gpointer)state); - - { - gtk_entry_set_max_length(GTK_ENTRY(state->entry_domain), 50); - g_signal_connect(G_OBJECT(state->entry_domain), "changed", - G_CALLBACK(callback_enter_domain_and_unlock), - (gpointer)state); - g_signal_connect(G_OBJECT(state->entry_domain), "activate", - G_CALLBACK(callback_continue), - (gpointer)state); - if (state->name_type_initial == NetSetupDomainName) { - gtk_entry_set_text(GTK_ENTRY(state->entry_domain), state->name_buffer_initial); - gtk_widget_set_sensitive(state->entry_workgroup, FALSE); - gtk_widget_set_sensitive(state->entry_domain, TRUE); - } - gtk_editable_set_editable(GTK_EDITABLE(state->entry_domain), TRUE); - gtk_box_pack_start(GTK_BOX(vbox), state->entry_domain, TRUE, TRUE, 0); - gtk_widget_show(state->entry_domain); - } - gtk_widget_show(button_domain); - - /* WORKGROUP */ - group = gtk_radio_button_get_group(GTK_RADIO_BUTTON(button_domain)); - button_workgroup = gtk_radio_button_new_with_label(group, "Workgroup"); - if (state->name_type_initial == NetSetupWorkgroupName) { - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button_workgroup), TRUE); - } - gtk_box_pack_start(GTK_BOX(vbox), button_workgroup, TRUE, TRUE, 0); - g_signal_connect(G_OBJECT(button_workgroup), "clicked", - G_CALLBACK(callback_do_join_workgroup), - (gpointer)state); - { - gtk_entry_set_max_length(GTK_ENTRY(state->entry_workgroup), MAX_NETBIOS_NAME_LEN); - g_signal_connect(G_OBJECT(state->entry_workgroup), "changed", - G_CALLBACK(callback_enter_workgroup_and_unlock), - (gpointer)state); - g_signal_connect(G_OBJECT(state->entry_workgroup), "activate", - G_CALLBACK(callback_continue), - (gpointer)state); - - if (state->name_type_initial == NetSetupWorkgroupName) { - gtk_entry_set_text(GTK_ENTRY(state->entry_workgroup), state->name_buffer_initial); - gtk_widget_set_sensitive(GTK_WIDGET(state->entry_domain), FALSE); - gtk_widget_set_sensitive(GTK_WIDGET(state->entry_workgroup), TRUE); - } - gtk_box_pack_start(GTK_BOX(vbox), state->entry_workgroup, TRUE, TRUE, 0); - gtk_widget_show(state->entry_workgroup); - } - gtk_widget_show(button_workgroup); - - /* BUTTONS */ - bbox = gtk_hbutton_box_new(); - gtk_container_set_border_width(GTK_CONTAINER(bbox), 5); - gtk_container_add(GTK_CONTAINER(box1), bbox); - gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); - gtk_box_set_spacing(GTK_BOX(bbox), 10); - - state->window_do_change = window; - gtk_widget_set_sensitive(GTK_WIDGET(state->button_ok), FALSE); /* !!! */ - gtk_container_add(GTK_CONTAINER(bbox), state->button_ok); - g_signal_connect(G_OBJECT(state->button_ok), "clicked", - G_CALLBACK(callback_creds_prompt), - (gpointer)state); - - button = gtk_button_new_from_stock(GTK_STOCK_CANCEL); - gtk_container_add(GTK_CONTAINER(bbox), button); - g_signal_connect(G_OBJECT(button), "clicked", - G_CALLBACK(callback_do_close), - (gpointer)window); - - gtk_widget_show_all(window); - -} - -static void callback_do_about(GtkWidget *widget, - gpointer data) -{ - GdkPixbuf *logo; - GError *error = NULL; - - debug("callback_do_about called\n"); - - logo = gdk_pixbuf_new_from_file(SAMBA_IMAGE_PATH, - &error); - if (logo == NULL) { - g_print("failed to load logo from %s: %s\n", - SAMBA_IMAGE_PATH, error->message); - } - - gtk_show_about_dialog(data, - "name", "Samba", - "version", "3.2.0pre2-GIT-904a90-test", - "copyright", "Copyright Andrew Tridgell and the Samba Team 1992-2007", - "website", "http://www.samba.org", - "license", "GPLv3", - "logo", logo, - "comments", "Samba gtk domain join utility", - NULL); -} - -static int draw_main_window(struct join_state *state) -{ - GtkWidget *window; - GtkWidget *button; - GtkWidget *label; - GtkWidget *main_vbox; - GtkWidget *vbox; - GtkWidget *hbox; - GtkWidget *bbox; - GtkWidget *image; - GtkWidget *table; - GtkWidget *entry; - GdkPixbuf *icon; - GError *error = NULL; - - icon = gdk_pixbuf_new_from_file(SAMBA_ICON_PATH, - &error); - if (icon == NULL) { - g_print("failed to load logo from %s : %s\n", - SAMBA_ICON_PATH, error->message); - } - -#if 1 - image = gtk_image_new_from_file(SAMBA_IMAGE_PATH); -#else - image = gtk_image_new_from_file("/usr/share/pixmaps/redhat-system_settings.png"); -#endif - - window = gtk_window_new(GTK_WINDOW_TOPLEVEL); - state->window_main = window; - - gtk_window_set_title(GTK_WINDOW(window), "Samba - Join Domain dialogue"); - gtk_widget_set_size_request(GTK_WIDGET(window), 600, 600); /* breite * höhe */ - gtk_window_set_resizable(GTK_WINDOW(window), FALSE); - gtk_window_set_icon_from_file(GTK_WINDOW(window), SAMBA_ICON_PATH, NULL); - - g_signal_connect(G_OBJECT(window), "delete_event", - G_CALLBACK(callback_delete_event), NULL); - - gtk_container_set_border_width(GTK_CONTAINER(window), 10); - - main_vbox = gtk_vbox_new(FALSE, 10); - gtk_container_add(GTK_CONTAINER(window), main_vbox); - -#if 0 - gtk_box_pack_start(GTK_BOX(main_vbox), image, TRUE, TRUE, 10); - gtk_widget_show(image); -#endif - /* Hbox */ - hbox = gtk_hbox_new(FALSE, 10); - gtk_container_add(GTK_CONTAINER(main_vbox), hbox); - - { -/* gtk_box_pack_start(GTK_BOX(main_vbox), image, TRUE, TRUE, 10); */ - gtk_misc_set_alignment(GTK_MISC(image), 0, 0); - gtk_box_pack_start(GTK_BOX(hbox), image, FALSE, FALSE, 10); - gtk_widget_show(image); - - /* Label */ - label = gtk_label_new("Samba uses the following information to identify your computer on the network."); - gtk_misc_set_alignment(GTK_MISC(label), 0, 0); - gtk_widget_set_size_request(GTK_WIDGET(label), 500, 40); - gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); - gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); - gtk_widget_show(label); - } - - gtk_widget_show(hbox); - - vbox = gtk_vbox_new(FALSE, 0); - gtk_container_set_border_width(GTK_CONTAINER(vbox), 10); - gtk_container_add(GTK_CONTAINER(main_vbox), vbox); - - /* Table */ - table = gtk_table_new(6, 3, TRUE); - gtk_table_set_row_spacings(GTK_TABLE(table), 5); - gtk_table_set_col_spacings(GTK_TABLE(table), 5); - gtk_container_add(GTK_CONTAINER(vbox), table); - - { - /* Label */ - label = gtk_label_new("Computer description:"); -/* gtk_misc_set_alignment(GTK_MISC(label), 0, 0); */ - gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 0, 1); - gtk_widget_show(label); - - state->button_apply = gtk_button_new_from_stock(GTK_STOCK_APPLY); - - /* Entry */ - entry = gtk_entry_new(); - gtk_entry_set_max_length(GTK_ENTRY(entry), 256); - g_signal_connect(G_OBJECT(entry), "changed", - G_CALLBACK(callback_enter_computer_description_and_unlock), - state); - g_signal_connect(G_OBJECT(entry), "activate", - G_CALLBACK(callback_apply_continue), - (gpointer)state); - - gtk_entry_set_text(GTK_ENTRY(entry), (char *)state->comment); - gtk_editable_set_editable(GTK_EDITABLE(entry), TRUE); /* ! */ - gtk_table_attach_defaults(GTK_TABLE(table), entry, 1, 3, 0, 1); - gtk_widget_show(entry); - } - - /* Label */ - label = gtk_label_new("For example: \"Samba \%v\"."); - gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); - gtk_misc_set_alignment(GTK_MISC(label), 0, 0); - gtk_table_attach_defaults(GTK_TABLE(table), label, 1, 3, 1, 2); - gtk_widget_show(label); - - /* Label */ - label = gtk_label_new("Full computer name:"); - gtk_misc_set_alignment(GTK_MISC(label), 0, 0); - gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 2, 3); - gtk_widget_show(label); - - { - /* Label */ - char *str = NULL; - if (state->name_type_initial == NetSetupDomainName) { - asprintf(&str, "%s.%s", state->my_hostname, - state->my_dnsdomain); - } else { - asprintf(&str, "%s.", state->my_hostname); - } - - label = gtk_label_new(str); - SAFE_FREE(str); - gtk_misc_set_alignment(GTK_MISC(label), 0, 0); - gtk_table_attach_defaults(GTK_TABLE(table), label, 1, 3, 2, 3); - gtk_widget_show(label); - } - - /* Label */ - if (state->name_type_initial == NetSetupDomainName) { - label = gtk_label_new("Domain:"); - } else { - label = gtk_label_new("Workgroup:"); - } - gtk_misc_set_alignment(GTK_MISC(label), 0, 0); - gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 3, 4); - gtk_widget_show(label); - state->label_current_name_type = label; - - /* Label */ - label = gtk_label_new(state->name_buffer_initial); - gtk_misc_set_alignment(GTK_MISC(label), 0, 0); - gtk_table_attach_defaults(GTK_TABLE(table), label, 1, 3, 3, 4); - gtk_widget_show(label); - state->label_current_name_buffer = label; - - { - hbox = gtk_hbox_new(FALSE, 0); - gtk_container_add(GTK_CONTAINER(vbox), hbox); - label = gtk_label_new("To rename this computer or join a domain, click Change."); - gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); - - - } - - /* bbox */ - bbox = gtk_hbutton_box_new(); - gtk_container_set_border_width(GTK_CONTAINER(bbox), 5); - gtk_container_add(GTK_CONTAINER(hbox), bbox); - gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); - gtk_box_set_spacing(GTK_BOX(bbox), 10); - - button = gtk_button_new_with_mnemonic("Ch_ange"); - g_signal_connect(G_OBJECT(button), "clicked", - G_CALLBACK(callback_do_change), - (gpointer)state); - gtk_box_pack_start(GTK_BOX(bbox), button, TRUE, TRUE, 0); - gtk_widget_show(button); - - /* Label (hidden) */ - state->label_reboot = gtk_label_new(NULL); - gtk_label_set_line_wrap(GTK_LABEL(state->label_reboot), TRUE); - gtk_misc_set_alignment(GTK_MISC(state->label_reboot), 0, 0); - gtk_box_pack_start(GTK_BOX(vbox), state->label_reboot, TRUE, TRUE, 0); - gtk_widget_show(state->label_reboot); - -#if 0 - gtk_box_pack_start(GTK_BOX(vbox), - create_bbox(window, TRUE, NULL, 10, 85, 20, GTK_BUTTONBOX_END), - TRUE, TRUE, 5); -#endif - { - - GtkWidget *frame; - GtkWidget *bbox2; - GtkWidget *button2; - - frame = gtk_frame_new(NULL); - bbox2 = gtk_hbutton_box_new(); - - gtk_container_set_border_width(GTK_CONTAINER(bbox2), 5); - gtk_container_add(GTK_CONTAINER(frame), bbox2); - - /* Set the appearance of the Button Box */ - gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox2), GTK_BUTTONBOX_END); - gtk_box_set_spacing(GTK_BOX(bbox2), 10); - /*gtk_button_box_set_child_size(GTK_BUTTON_BOX(bbox2), child_w, child_h);*/ - - button2 = gtk_button_new_from_stock(GTK_STOCK_OK); - gtk_container_add(GTK_CONTAINER(bbox2), button2); - g_signal_connect(G_OBJECT(button2), "clicked", G_CALLBACK(callback_do_exit), state); - - button2 = gtk_button_new_from_stock(GTK_STOCK_CANCEL); - gtk_container_add(GTK_CONTAINER(bbox2), button2); - g_signal_connect(G_OBJECT(button2), "clicked", - G_CALLBACK(callback_delete_event), - window); - - gtk_container_add(GTK_CONTAINER(bbox2), state->button_apply); - g_signal_connect(G_OBJECT(state->button_apply), "clicked", - G_CALLBACK(callback_apply_description_change), - state); - gtk_widget_set_sensitive(GTK_WIDGET(state->button_apply), FALSE); - - button2 = gtk_button_new_from_stock(GTK_STOCK_ABOUT); - gtk_container_add(GTK_CONTAINER(bbox2), button2); - g_signal_connect(G_OBJECT(button2), "clicked", - G_CALLBACK(callback_do_about), - window); - - gtk_box_pack_start(GTK_BOX(vbox), frame, TRUE, TRUE, 5); - } - - gtk_widget_show_all(window); - - return 0; -} - -static int init_join_state(struct join_state **state) -{ - struct join_state *s; - - s = malloc(sizeof(struct join_state)); - if (!s) { - return -1; - } - - memset(s, '\0', sizeof(struct join_state)); - - *state = s; - - return 0; -} - -static int initialize_join_state(struct join_state *state, - const char *debug_level) -{ - struct libnetapi_ctx *ctx = NULL; - NET_API_STATUS status = 0; - - status = libnetapi_init(&ctx); - if (status) { - return status; - } - - if (debug_level) { - libnetapi_set_debuglevel(ctx, debug_level); - } - - { - char my_hostname[HOST_NAME_MAX]; - const char *p = NULL; - if (gethostname(my_hostname, sizeof(my_hostname)) == -1) { - return -1; - } - - state->my_fqdn = strdup(my_hostname); - if (!state->my_fqdn) { - return -1; - } - - p = strchr(my_hostname, '.'); - if (p) { - my_hostname[strlen(my_hostname) - strlen(p)] = '\0'; - state->my_hostname = strdup(my_hostname); - if (!state->my_hostname) { - return -1; - } - p++; - state->my_dnsdomain = strdup(p); - if (!state->my_dnsdomain) { - return -1; - } - } - } - - { - const char *buffer = NULL; - uint16_t type = 0; - status = NetGetJoinInformation(NULL, &buffer, &type); - if (status) { - return status; - } - state->name_buffer_initial = (char *)buffer; - state->name_type_initial = type; - } - - { - struct srvsvc_NetSrvInfo1005 *info1005 = NULL; - uint8_t *buffer = NULL; - - status = NetServerGetInfo(NULL, 1005, &buffer); - if (status) { - return status; - } - - info1005 = (struct srvsvc_NetSrvInfo1005 *)buffer; - - state->comment = strdup(info1005->comment); - if (!state->comment) { - return -1; - } - } -#if 0 - { - struct srvsvc_NetSrvInfo100 *info100 = NULL; - uint8_t *buffer = NULL; - - status = NetServerGetInfo(NULL, 100, &buffer); - if (status) { - return status; - } - - info100 = (struct srvsvc_NetSrvInfo100 *)buffer; - - state->comment = strdup(info100->comment); - if (!state->comment) { - return -1; - } - } -#endif - - state->ctx = ctx; - - return 0; -} - -int main(int argc, char **argv) -{ - GOptionContext *context = NULL; - static const char *debug_level = NULL; - struct join_state *state = NULL; - GError *error = NULL; - int ret = 0; - - static GOptionEntry entries[] = { - { "debug", 'd', 0, G_OPTION_ARG_STRING, &debug_level, "Debug level (for samba)", "N" }, - { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, "Verbose output", 0 }, - { NULL } - }; - - context = g_option_context_new("- Samba domain join utility"); - g_option_context_add_main_entries(context, entries, NULL); -/* g_option_context_add_main_entries(context, entries, GETTEXT_PACKAGE); */ - g_option_context_add_group(context, gtk_get_option_group(TRUE)); - g_option_context_parse(context, &argc, &argv, &error); - - gtk_init(&argc, &argv); - g_set_application_name("Samba"); - - ret = init_join_state(&state); - if (ret) { - return ret; - } - - ret = initialize_join_state(state, debug_level); - if (ret) { - return ret; - } - - draw_main_window(state); - - gtk_main(); - - do_cleanup(state); - - return 0; -} -- cgit From 86dfb55ffb99abf6fc61a91e58477790395abe38 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Sat, 22 Dec 2007 00:02:45 +0100 Subject: Correct netapi header filename. Thanks Jeremy. Guenther (This used to be commit f192737ec8140aa6570bfb49a165b31890d63b16) --- source3/lib/netapi/examples/getdc/getdc.c | 2 +- source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c | 2 +- source3/lib/netapi/examples/netdomjoin/netdomjoin.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/getdc/getdc.c b/source3/lib/netapi/examples/getdc/getdc.c index ed6a8bd05d..4f5c5332d5 100644 --- a/source3/lib/netapi/examples/getdc/getdc.c +++ b/source3/lib/netapi/examples/getdc/getdc.c @@ -23,7 +23,7 @@ #include #include -#include +#include int main(int argc, char **argv) { diff --git a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c index 8ca6897cab..beb12be8b1 100644 --- a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c +++ b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c @@ -28,7 +28,7 @@ #include #include -#include +#include #define MAX_CRED_LEN 256 #define MAX_NETBIOS_NAME_LEN 15 diff --git a/source3/lib/netapi/examples/netdomjoin/netdomjoin.c b/source3/lib/netapi/examples/netdomjoin/netdomjoin.c index a2bb700250..e8b529927f 100644 --- a/source3/lib/netapi/examples/netdomjoin/netdomjoin.c +++ b/source3/lib/netapi/examples/netdomjoin/netdomjoin.c @@ -23,7 +23,7 @@ #include #include -#include +#include char *get_string_param(const char *param) { -- cgit From 921d8782ccb92d2c9a394bb2d281d3762d75dde6 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 25 Dec 2007 11:34:10 +0100 Subject: Fix the build (This used to be commit 72dc71710813ea9f1d8864c4401fef25a25577bd) --- source3/lib/netapi/serverinfo.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/serverinfo.c b/source3/lib/netapi/serverinfo.c index 276a98c15e..27c7c4b2fc 100644 --- a/source3/lib/netapi/serverinfo.c +++ b/source3/lib/netapi/serverinfo.c @@ -167,8 +167,7 @@ static WERROR NetServerSetInfoLocal_1005(struct libnetapi_ctx *ctx, return WERR_NOT_SUPPORTED; } - return libnet_smbconf_set_global_param(ctx, - "server string", + return libnet_smbconf_set_global_param("server string", info1005->comment); } -- cgit From 6afaafe083ad23e51743ccd5245cf7384b2c4bd9 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 3 Jan 2008 13:36:56 +0100 Subject: Let DsGetDCName figure out whether domain_name is a flat_name when unjoining. Guenther (This used to be commit 75165ba4e7acafaca42f6afd1fb8b56e00bcbed7) --- source3/lib/netapi/joindomain.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/joindomain.c b/source3/lib/netapi/joindomain.c index e3d5eada02..60f48a7b5e 100644 --- a/source3/lib/netapi/joindomain.c +++ b/source3/lib/netapi/joindomain.c @@ -233,7 +233,6 @@ static WERROR NetUnjoinDomainLocal(struct libnetapi_ctx *mem_ctx, 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(); -- cgit From 5655ae7a2468e8fc93b1a8d9ac4b2f35abbf3703 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Thu, 3 Jan 2008 14:15:05 +0100 Subject: Rename libnet_smbconf_set_global_param() to libnet_conf_set_global_parameter(). Now all functions are converted to the consistent naming scheme. Michael (This used to be commit a559533c0c8a80f3f4078bbc2675de395359485f) --- source3/lib/netapi/serverinfo.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/serverinfo.c b/source3/lib/netapi/serverinfo.c index 27c7c4b2fc..0e356e0ee7 100644 --- a/source3/lib/netapi/serverinfo.c +++ b/source3/lib/netapi/serverinfo.c @@ -167,8 +167,8 @@ static WERROR NetServerSetInfoLocal_1005(struct libnetapi_ctx *ctx, return WERR_NOT_SUPPORTED; } - return libnet_smbconf_set_global_param("server string", - info1005->comment); + return libnet_conf_set_global_parameter("server string", + info1005->comment); } static WERROR NetServerSetInfoLocal(struct libnetapi_ctx *ctx, -- cgit From be88a6738823e3a19c4e935dd970ab4c078ceaee Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 3 Jan 2008 16:41:38 +0100 Subject: Minor libnetapi join cosmetic cleanup. Guenther (This used to be commit 4deef80bed374af5032c0f3081d2ee3c70be99df) --- source3/lib/netapi/joindomain.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/joindomain.c b/source3/lib/netapi/joindomain.c index 60f48a7b5e..d200c9b7b0 100644 --- a/source3/lib/netapi/joindomain.c +++ b/source3/lib/netapi/joindomain.c @@ -114,7 +114,7 @@ static WERROR NetJoinDomainRemote(struct libnetapi_ctx *ctx, if (!pipe_cli) { werr = ntstatus_to_werror(status); goto done; - }; + } if (password) { encode_wkssvc_join_password_buffer(ctx, @@ -300,7 +300,7 @@ static WERROR NetUnjoinDomainRemote(struct libnetapi_ctx *ctx, if (!pipe_cli) { werr = ntstatus_to_werror(status); goto done; - }; + } if (password) { encode_wkssvc_join_password_buffer(ctx, @@ -407,7 +407,7 @@ static WERROR NetGetJoinInformationRemote(struct libnetapi_ctx *ctx, if (!pipe_cli) { werr = ntstatus_to_werror(status); goto done; - }; + } status = rpccli_wkssvc_NetrGetJoinInformation(pipe_cli, ctx, server_name, -- cgit From cf6e59de2b475e14660a9b71daad2ab5699d53a7 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 4 Jan 2008 11:54:38 +0100 Subject: Fix some error strings in netdomjoin-gui. Guenther (This used to be commit aaea8f1ed744e9662f92a3840d86ad1aff943d18) --- .../examples/netdomjoin-gui/netdomjoin-gui.c | 43 ++++++++++++++++------ 1 file changed, 31 insertions(+), 12 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c index beb12be8b1..3abf6fd5dc 100644 --- a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c +++ b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c @@ -1,7 +1,7 @@ /* * Unix SMB/CIFS implementation. * Join Support (gtk + netapi) - * 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 @@ -124,7 +124,6 @@ static void free_join_state(struct join_state *s) SAFE_FREE(s->my_fqdn); SAFE_FREE(s->my_dnsdomain); SAFE_FREE(s->my_hostname); - } static void do_cleanup(struct join_state *state) @@ -365,7 +364,8 @@ static void callback_do_join(GtkWidget *widget, uint32_t unjoin_flags = 0; gboolean domain_join = FALSE; gboolean try_unjoin = FALSE; - const char *domain_or_workgroup = NULL; + const char *new_workgroup_type = NULL; + const char *initial_workgroup_type = NULL; struct join_state *state = (struct join_state *)data; @@ -376,14 +376,33 @@ static void callback_do_join(GtkWidget *widget, gtk_widget_destroy(GTK_WIDGET(state->window_creds_prompt)); } + switch (state->name_type_initial) { + case NetSetupWorkgroupName: + initial_workgroup_type = "workgroup"; + break; + case NetSetupDomainName: + initial_workgroup_type = "domain"; + break; + default: + break; + } + + switch (state->name_type_new) { + case NetSetupWorkgroupName: + new_workgroup_type = "workgroup"; + break; + case NetSetupDomainName: + new_workgroup_type = "domain"; + break; + default: + break; + } + if (state->name_type_new == NetSetupDomainName) { domain_join = TRUE; join_flags = WKSSVC_JOIN_FLAGS_JOIN_TYPE | WKSSVC_JOIN_FLAGS_ACCOUNT_CREATE | WKSSVC_JOIN_FLAGS_DOMAIN_JOIN_IF_JOINED; /* for testing */ - domain_or_workgroup = "domain"; - } else { - domain_or_workgroup = "workgroup"; } if ((state->name_type_initial == NetSetupDomainName) && @@ -394,7 +413,7 @@ static void callback_do_join(GtkWidget *widget, } debug("callback_do_join: Joining a %s named %s using join_flags 0x%08x ", - domain_or_workgroup, + new_workgroup_type, state->name_buffer_new, join_flags); if (domain_join) { @@ -422,8 +441,8 @@ static void callback_do_join(GtkWidget *widget, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, "The following error occured attempting to unjoin the %s: \"%s\": %s", - domain_or_workgroup, - state->name_buffer_new, + initial_workgroup_type, + state->name_buffer_initial, err_str); g_signal_connect_swapped(dialog, "response", @@ -451,7 +470,7 @@ static void callback_do_join(GtkWidget *widget, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, "The following error occured attempting to join the %s: \"%s\": %s", - domain_or_workgroup, + new_workgroup_type, state->name_buffer_new, err_str); @@ -465,7 +484,7 @@ static void callback_do_join(GtkWidget *widget, } debug("callback_do_join: Successfully joined %s\n", - domain_or_workgroup); + new_workgroup_type); dialog = gtk_message_dialog_new(GTK_WINDOW(state->window_parent), GTK_DIALOG_DESTROY_WITH_PARENT, @@ -473,7 +492,7 @@ static void callback_do_join(GtkWidget *widget, GTK_BUTTONS_OK, "Welcome to the %s %s.", state->name_buffer_new, - domain_or_workgroup); + new_workgroup_type); gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); -- cgit From 564a54aa168a0866dbd8fb3ef512b1836be11442 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 4 Jan 2008 15:08:28 +0100 Subject: Minor cosmetic cleanup for netdomjoin-gui. Guenther (This used to be commit 02e3887f3962b469c965110b6141a6655f2347af) --- .../netapi/examples/netdomjoin-gui/logo-small.png | Bin 0 -> 4485 bytes .../examples/netdomjoin-gui/netdomjoin-gui.c | 55 ++++++++++++++------- 2 files changed, 37 insertions(+), 18 deletions(-) create mode 100644 source3/lib/netapi/examples/netdomjoin-gui/logo-small.png (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/netdomjoin-gui/logo-small.png b/source3/lib/netapi/examples/netdomjoin-gui/logo-small.png new file mode 100644 index 0000000000..f041198002 Binary files /dev/null and b/source3/lib/netapi/examples/netdomjoin-gui/logo-small.png differ diff --git a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c index 3abf6fd5dc..d12e66bb26 100644 --- a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c +++ b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c @@ -35,6 +35,7 @@ #define SAMBA_ICON_PATH "/usr/share/pixmaps/samba/samba.ico" #define SAMBA_IMAGE_PATH "/usr/share/pixmaps/samba/logo.png" +#define SAMBA_IMAGE_PATH_SMALL "/usr/share/pixmaps/samba/logo-small.png" #define WKSSVC_JOIN_FLAGS_DOMAIN_JOIN_IF_JOINED ( 0x00000020 ) #define WKSSVC_JOIN_FLAGS_ACCOUNT_DELETE ( 0x00000004 ) @@ -224,7 +225,8 @@ static void callback_do_reboot(GtkWidget *widget, gtk_widget_destroy(dialog); #endif - gtk_label_set_text(GTK_LABEL(state->label_reboot), "Changes will take effect after you restart this computer"); + gtk_label_set_text(GTK_LABEL(state->label_reboot), + "Changes will take effect after you restart this computer"); debug("destroying do_change window\n"); gtk_widget_destroy(GTK_WIDGET(state->window_do_change)); @@ -247,11 +249,14 @@ static void callback_do_reboot(GtkWidget *widget, SAFE_FREE(buffer); state->name_type_new = type; #endif - gtk_label_set_text(GTK_LABEL(state->label_current_name_buffer), state->name_buffer_new); - if (state->name_type_new == 3) { - gtk_label_set_text(GTK_LABEL(state->label_current_name_type), "Domain:"); + gtk_label_set_text(GTK_LABEL(state->label_current_name_buffer), + state->name_buffer_new); + if (state->name_type_new == NetSetupDomainName) { + gtk_label_set_text(GTK_LABEL(state->label_current_name_type), + "Domain:"); } else { - gtk_label_set_text(GTK_LABEL(state->label_current_name_type), "Workgroup:"); + gtk_label_set_text(GTK_LABEL(state->label_current_name_type), + "Workgroup:"); } } } @@ -779,6 +784,8 @@ static void callback_do_change(GtkWidget *widget, debug("callback_do_change called\n"); +#if 0 + /* FIXME: add proper warnings for Samba as a DC */ if (state->server_role == 3) { GtkWidget *dialog; dialog = gtk_message_dialog_new(GTK_WINDOW(state->window_main), @@ -793,13 +800,14 @@ static void callback_do_change(GtkWidget *widget, gtk_widget_show(dialog); return; } +#endif state->button_ok = gtk_button_new_from_stock(GTK_STOCK_OK); window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_title(GTK_WINDOW(window), "Computer Name Changes"); gtk_window_set_resizable(GTK_WINDOW(window), FALSE); - gtk_widget_set_size_request(GTK_WIDGET(window), 480, 500); /* breite * höhe */ + gtk_widget_set_size_request(GTK_WIDGET(window), 480, 500); gtk_window_set_icon_from_file(GTK_WINDOW(window), SAMBA_ICON_PATH, NULL); g_signal_connect(G_OBJECT(window), "delete_event", @@ -849,14 +857,17 @@ static void callback_do_change(GtkWidget *widget, char *str = NULL; entry_text = gtk_entry_get_text(GTK_ENTRY(entry)); if (state->name_type_initial == NetSetupDomainName) { - asprintf(&str, "%s.%s", entry_text, state->my_dnsdomain); + asprintf(&str, "%s.%s", entry_text, + state->my_dnsdomain); } else { asprintf(&str, "%s.", entry_text); } - gtk_label_set_text(GTK_LABEL(state->label_full_computer_name), str); + gtk_label_set_text(GTK_LABEL(state->label_full_computer_name), + str); free(str); gtk_misc_set_alignment(GTK_MISC(state->label_full_computer_name), 0, 0); - gtk_box_pack_start(GTK_BOX(box1), state->label_full_computer_name, TRUE, TRUE, 0); + gtk_box_pack_start(GTK_BOX(box1), + state->label_full_computer_name, TRUE, TRUE, 0); gtk_widget_show(state->label_full_computer_name); } @@ -891,7 +902,8 @@ static void callback_do_change(GtkWidget *widget, G_CALLBACK(callback_continue), (gpointer)state); if (state->name_type_initial == NetSetupDomainName) { - gtk_entry_set_text(GTK_ENTRY(state->entry_domain), state->name_buffer_initial); + gtk_entry_set_text(GTK_ENTRY(state->entry_domain), + state->name_buffer_initial); gtk_widget_set_sensitive(state->entry_workgroup, FALSE); gtk_widget_set_sensitive(state->entry_domain, TRUE); } @@ -912,7 +924,8 @@ static void callback_do_change(GtkWidget *widget, G_CALLBACK(callback_do_join_workgroup), (gpointer)state); { - gtk_entry_set_max_length(GTK_ENTRY(state->entry_workgroup), MAX_NETBIOS_NAME_LEN); + gtk_entry_set_max_length(GTK_ENTRY(state->entry_workgroup), + MAX_NETBIOS_NAME_LEN); g_signal_connect(G_OBJECT(state->entry_workgroup), "changed", G_CALLBACK(callback_enter_workgroup_and_unlock), (gpointer)state); @@ -921,7 +934,8 @@ static void callback_do_change(GtkWidget *widget, (gpointer)state); if (state->name_type_initial == NetSetupWorkgroupName) { - gtk_entry_set_text(GTK_ENTRY(state->entry_workgroup), state->name_buffer_initial); + gtk_entry_set_text(GTK_ENTRY(state->entry_workgroup), + state->name_buffer_initial); gtk_widget_set_sensitive(GTK_WIDGET(state->entry_domain), FALSE); gtk_widget_set_sensitive(GTK_WIDGET(state->entry_workgroup), TRUE); } @@ -998,21 +1012,25 @@ static int draw_main_window(struct join_state *state) icon = gdk_pixbuf_new_from_file(SAMBA_ICON_PATH, &error); if (icon == NULL) { - g_print("failed to load logo from %s : %s\n", + g_print("failed to load icon from %s : %s\n", SAMBA_ICON_PATH, error->message); } #if 1 - image = gtk_image_new_from_file(SAMBA_IMAGE_PATH); + image = gtk_image_new_from_file(SAMBA_IMAGE_PATH_SMALL); #else image = gtk_image_new_from_file("/usr/share/pixmaps/redhat-system_settings.png"); #endif + if (image == NULL) { + g_print("failed to load logo from %s : %s\n", + SAMBA_IMAGE_PATH_SMALL, error->message); + } window = gtk_window_new(GTK_WINDOW_TOPLEVEL); state->window_main = window; gtk_window_set_title(GTK_WINDOW(window), "Samba - Join Domain dialogue"); - gtk_widget_set_size_request(GTK_WIDGET(window), 600, 600); /* breite * höhe */ + gtk_widget_set_size_request(GTK_WIDGET(window), 600, 600); gtk_window_set_resizable(GTK_WINDOW(window), FALSE); gtk_window_set_icon_from_file(GTK_WINDOW(window), SAMBA_ICON_PATH, NULL); @@ -1034,14 +1052,15 @@ static int draw_main_window(struct join_state *state) { /* gtk_box_pack_start(GTK_BOX(main_vbox), image, TRUE, TRUE, 10); */ - gtk_misc_set_alignment(GTK_MISC(image), 0, 0); +/* gtk_misc_set_alignment(GTK_MISC(image), 0, 0); */ + gtk_widget_set_size_request(GTK_WIDGET(image), 150, 40); gtk_box_pack_start(GTK_BOX(hbox), image, FALSE, FALSE, 10); gtk_widget_show(image); /* Label */ label = gtk_label_new("Samba uses the following information to identify your computer on the network."); - gtk_misc_set_alignment(GTK_MISC(label), 0, 0); - gtk_widget_set_size_request(GTK_WIDGET(label), 500, 40); +/* gtk_misc_set_alignment(GTK_MISC(label), 0, 0); */ + gtk_widget_set_size_request(GTK_WIDGET(label), 400, 40); gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); gtk_widget_show(label); -- cgit From f78c318eb0b50862b2e6ed6783ee5279af91709c Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 4 Jan 2008 15:18:42 +0100 Subject: Add debug switch to netdomjoin. Guenther (This used to be commit 2b221708c07967bccd68e8c7983791b4628405bb) --- source3/lib/netapi/examples/netdomjoin/netdomjoin.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/netdomjoin/netdomjoin.c b/source3/lib/netapi/examples/netdomjoin/netdomjoin.c index e8b529927f..634d265597 100644 --- a/source3/lib/netapi/examples/netdomjoin/netdomjoin.c +++ b/source3/lib/netapi/examples/netdomjoin/netdomjoin.c @@ -1,7 +1,7 @@ /* * Unix SMB/CIFS implementation. * Join Support (cmdline + netapi) - * 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 @@ -56,7 +56,10 @@ int main(int argc, char **argv) if (argc < 2) { printf("usage: netdomjoin\n"); - printf("\t[hostname=HOSTNAME] [domain=DOMAIN] \n"); + printf("\t[hostname] [domain=DOMAIN] " + " " + " " + "\n"); return 0; } @@ -87,6 +90,11 @@ int main(int argc, char **argv) str = get_string_param(argv[i]); libnetapi_set_password(ctx, str); } + if (strncasecmp(argv[i], "debug", strlen("debug"))== 0) { + const char *str = NULL; + str = get_string_param(argv[i]); + libnetapi_set_debuglevel(ctx, str); + } } status = NetJoinDomain(server_name, -- cgit From 0399df22f0f0999338e48d7b9598a7b2f7b9aab5 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 4 Jan 2008 17:01:52 +0100 Subject: In libnet_join finally separate the admin from the machine pwd entirely. Guenther (This used to be commit d88bb94f0ef00ddbb48498797bd11448e0d74645) --- source3/lib/netapi/joindomain.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/joindomain.c b/source3/lib/netapi/joindomain.c index d200c9b7b0..921f816cbe 100644 --- a/source3/lib/netapi/joindomain.c +++ b/source3/lib/netapi/joindomain.c @@ -1,7 +1,7 @@ /* * 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 @@ -69,8 +69,8 @@ static WERROR NetJoinDomainLocal(struct libnetapi_ctx *mem_ctx, } 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; @@ -254,8 +254,8 @@ static WERROR NetUnjoinDomainLocal(struct libnetapi_ctx *mem_ctx, } 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; -- cgit From 28ef4878d937405340cc1984ef674ad0b670ef0c Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 4 Jan 2008 17:11:14 +0100 Subject: Rename server_name to dc_name in libnet join structures. Guenther (This used to be commit ff5e15b1ba0d5c39ceef9f9995c107e510162564) --- source3/lib/netapi/joindomain.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/joindomain.c b/source3/lib/netapi/joindomain.c index 921f816cbe..0d4452e1df 100644 --- a/source3/lib/netapi/joindomain.c +++ b/source3/lib/netapi/joindomain.c @@ -54,8 +54,9 @@ static WERROR NetJoinDomainLocal(struct libnetapi_ctx *mem_ctx, 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) { @@ -224,8 +225,8 @@ static WERROR NetUnjoinDomainLocal(struct libnetapi_ctx *mem_ctx, 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; @@ -244,8 +245,9 @@ static WERROR NetUnjoinDomainLocal(struct libnetapi_ctx *mem_ctx, 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) { -- cgit From 395c366237dec1a38a53248d2e8df17f877207aa Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 4 Jan 2008 22:56:31 +0100 Subject: Do not pass emtpy wkssvc_PasswordBuffers to rpc functions. Guenther (This used to be commit fe75e5ccdfc2609380367e59215637b0de1ef241) --- source3/lib/netapi/joindomain.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/joindomain.c b/source3/lib/netapi/joindomain.c index 0d4452e1df..c7849c952f 100644 --- a/source3/lib/netapi/joindomain.c +++ b/source3/lib/netapi/joindomain.c @@ -90,13 +90,11 @@ 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", @@ -129,7 +127,7 @@ static WERROR NetJoinDomainRemote(struct libnetapi_ctx *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); @@ -277,13 +275,11 @@ static WERROR NetUnjoinDomainRemote(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", @@ -316,7 +312,7 @@ static WERROR NetUnjoinDomainRemote(struct libnetapi_ctx *ctx, status = rpccli_wkssvc_NetrUnjoinDomain2(pipe_cli, ctx, server_name, account, - &encrypted_password, + encrypted_password, unjoin_flags, &werr); if (!NT_STATUS_IS_OK(status)) { -- cgit From e6c3ac59c5adb433d6269cae7141e575da7fdc8d Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 7 Jan 2008 12:19:56 +0100 Subject: Failure while unjoining a domain is non-critical. Just continue joining to the workgroup in that case. Guenther (This used to be commit bf9ce2a928e3136d3bfe368f75d5b99273c5b04f) --- source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c index d12e66bb26..1e1681ba37 100644 --- a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c +++ b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c @@ -449,14 +449,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); } } -- cgit From be7df54c3912a2db024f19d789d385e99ed98917 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 7 Jan 2008 12:44:25 +0100 Subject: Fix two memleaks in libnetapi. Guenther (This used to be commit d73bde99e8518607bb78b5625ce5fb1991d8e402) --- source3/lib/netapi/netapi.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi.c b/source3/lib/netapi/netapi.c index 032798d0f9..9c418f254c 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 @@ -90,6 +90,9 @@ NET_API_STATUS libnetapi_free(struct libnetapi_ctx *ctx) gfree_charcnv(); gfree_interfaces(); + gencache_shutdown(); + secrets_shutdown(); + TALLOC_FREE(ctx); TALLOC_FREE(frame); -- cgit From fa1e5e95d505d28eb50398511f95ebf13a28b4e5 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 7 Jan 2008 18:36:06 +0100 Subject: Add NET_API_STATUS_SUCCESS define. Guenther (This used to be commit a72ad63163a8c642ea762087a739e6d63c37647a) --- source3/lib/netapi/netapi.c | 18 +++++++++--------- source3/lib/netapi/netapi.h | 6 +++++- 2 files changed, 14 insertions(+), 10 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi.c b/source3/lib/netapi/netapi.c index 9c418f254c..a37ed7c072 100644 --- a/source3/lib/netapi/netapi.c +++ b/source3/lib/netapi/netapi.c @@ -32,7 +32,7 @@ NET_API_STATUS libnetapi_init(struct libnetapi_ctx **context) if (stat_ctx && libnetapi_initialized) { *context = stat_ctx; - return W_ERROR_V(WERR_OK); + return NET_API_STATUS_SUCCESS; } frame = talloc_stackframe(); @@ -69,14 +69,14 @@ NET_API_STATUS libnetapi_init(struct libnetapi_ctx **context) *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); @@ -98,7 +98,7 @@ NET_API_STATUS libnetapi_free(struct libnetapi_ctx *ctx) gfree_debugsyms(); - return W_ERROR_V(WERR_OK); + return NET_API_STATUS_SUCCESS; } NET_API_STATUS libnetapi_set_debuglevel(struct libnetapi_ctx *ctx, @@ -109,14 +109,14 @@ NET_API_STATUS libnetapi_set_debuglevel(struct libnetapi_ctx *ctx, 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) { *debuglevel = ctx->debuglevel; - return W_ERROR_V(WERR_OK); + return NET_API_STATUS_SUCCESS; } NET_API_STATUS libnetapi_set_username(struct libnetapi_ctx *ctx, @@ -127,7 +127,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, @@ -138,7 +138,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, @@ -149,7 +149,7 @@ 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, diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h index 0dd6d95ceb..2c6e126949 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,6 +21,10 @@ #define __LIB_NETAPI_H__ #define NET_API_STATUS uint32_t +#define NET_API_STATUS_SUCCESS 0 + +/**************************************************************** +****************************************************************/ struct libnetapi_ctx { const char *debuglevel; -- cgit From cc1982ab1cb436a9410699bac5bafa7c6077530a Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 7 Jan 2008 18:37:04 +0100 Subject: Close registry in libnetapi_free(). Guenther (This used to be commit e7258a4408e40686ff090d0f8e120ce78acbd097) --- source3/lib/netapi/netapi.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi.c b/source3/lib/netapi/netapi.c index a37ed7c072..33ca67ec85 100644 --- a/source3/lib/netapi/netapi.c +++ b/source3/lib/netapi/netapi.c @@ -92,6 +92,7 @@ NET_API_STATUS libnetapi_free(struct libnetapi_ctx *ctx) gencache_shutdown(); secrets_shutdown(); + regdb_close(); TALLOC_FREE(ctx); TALLOC_FREE(frame); -- cgit From 0b92d8bc79172dc587f53ce4b35a8fa3128ae0ea Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 7 Jan 2008 18:40:25 +0100 Subject: Free libnet_JoinCtx after joining. Guenther (This used to be commit 5abae9ef15fa9884c5c4a0e256274f70f6ecd779) --- source3/lib/netapi/joindomain.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/joindomain.c b/source3/lib/netapi/joindomain.c index c7849c952f..8fe6193f40 100644 --- a/source3/lib/netapi/joindomain.c +++ b/source3/lib/netapi/joindomain.c @@ -77,7 +77,10 @@ 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); + TALLOC_FREE(r); + + return werr; } static WERROR NetJoinDomainRemote(struct libnetapi_ctx *ctx, -- cgit From 528d253cc834235213f29411a058485681260140 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 7 Jan 2008 18:41:49 +0100 Subject: Rearrange order of libnet join context init. Guenther (This used to be commit 89669c66f27fb47c9769d1058e29bff83f862752) --- source3/lib/netapi/joindomain.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/joindomain.c b/source3/lib/netapi/joindomain.c index 8fe6193f40..ceb7ca10d9 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); -- cgit From 1fba8c801934233e754710dd477cafdab97841bd Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 7 Jan 2008 20:01:28 +0100 Subject: Let libnetapi use it's own krb5 cred cache in memory if necessary. Guenther (This used to be commit 863fb30038e384585502f0154a742481594b99d0) --- source3/lib/netapi/netapi.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi.c b/source3/lib/netapi/netapi.c index 33ca67ec85..6d27b99d96 100644 --- a/source3/lib/netapi/netapi.c +++ b/source3/lib/netapi/netapi.c @@ -26,9 +26,13 @@ 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; @@ -65,6 +69,12 @@ 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; @@ -72,6 +82,9 @@ NET_API_STATUS libnetapi_init(struct libnetapi_ctx **context) return NET_API_STATUS_SUCCESS; } +/**************************************************************** +****************************************************************/ + NET_API_STATUS libnetapi_getctx(struct libnetapi_ctx **ctx) { if (stat_ctx) { @@ -82,6 +95,9 @@ NET_API_STATUS libnetapi_getctx(struct libnetapi_ctx **ctx) return libnetapi_init(ctx); } +/**************************************************************** +****************************************************************/ + NET_API_STATUS libnetapi_free(struct libnetapi_ctx *ctx) { gfree_names(); @@ -94,6 +110,11 @@ NET_API_STATUS libnetapi_free(struct libnetapi_ctx *ctx) secrets_shutdown(); regdb_close(); + if (ctx->krb5_cc_env && + (strequal(ctx->krb5_cc_env, getenv(KRB5_ENV_CCNAME)))) { + unsetenv(KRB5_ENV_CCNAME); + } + TALLOC_FREE(ctx); TALLOC_FREE(frame); @@ -102,6 +123,9 @@ NET_API_STATUS libnetapi_free(struct libnetapi_ctx *ctx) return NET_API_STATUS_SUCCESS; } +/**************************************************************** +****************************************************************/ + NET_API_STATUS libnetapi_set_debuglevel(struct libnetapi_ctx *ctx, const char *debuglevel) { @@ -113,6 +137,9 @@ NET_API_STATUS libnetapi_set_debuglevel(struct libnetapi_ctx *ctx, return NET_API_STATUS_SUCCESS; } +/**************************************************************** +****************************************************************/ + NET_API_STATUS libnetapi_get_debuglevel(struct libnetapi_ctx *ctx, const char **debuglevel) { @@ -120,6 +147,9 @@ NET_API_STATUS libnetapi_get_debuglevel(struct libnetapi_ctx *ctx, return NET_API_STATUS_SUCCESS; } +/**************************************************************** +****************************************************************/ + NET_API_STATUS libnetapi_set_username(struct libnetapi_ctx *ctx, const char *username) { @@ -153,6 +183,9 @@ NET_API_STATUS libnetapi_set_workgroup(struct libnetapi_ctx *ctx, return NET_API_STATUS_SUCCESS; } +/**************************************************************** +****************************************************************/ + const char *libnetapi_errstr(struct libnetapi_ctx *ctx, NET_API_STATUS status) { -- cgit From 1b3520db8836437b9d4d48fab4df69126c1d9b5d Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 7 Jan 2008 20:03:32 +0100 Subject: Add krb5 cc env to libnetapi_ctx. Guenther (This used to be commit df2b078fa1658bdbff1280f7fe0b062d9eabd60c) --- source3/lib/netapi/netapi.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h index 2c6e126949..3c9d3b3853 100644 --- a/source3/lib/netapi/netapi.h +++ b/source3/lib/netapi/netapi.h @@ -31,8 +31,12 @@ struct libnetapi_ctx { 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); -- cgit From 751fc874bec2cbc93b4a84067f3e7102f39bd76c Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 7 Jan 2008 20:06:41 +0100 Subject: Add libnetapi_set_error_string and libnetapi_get_error_string. Guenther (This used to be commit f8806bad8134d544229c426f58bee143ba752cf8) --- source3/lib/netapi/netapi.c | 27 +++++++++++++++++++++++++-- source3/lib/netapi/netapi.h | 10 ++++++++-- 2 files changed, 33 insertions(+), 4 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi.c b/source3/lib/netapi/netapi.c index 6d27b99d96..d5527dc4ff 100644 --- a/source3/lib/netapi/netapi.c +++ b/source3/lib/netapi/netapi.c @@ -130,7 +130,7 @@ 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); } @@ -141,7 +141,7 @@ NET_API_STATUS libnetapi_set_debuglevel(struct libnetapi_ctx *ctx, ****************************************************************/ NET_API_STATUS libnetapi_get_debuglevel(struct libnetapi_ctx *ctx, - const char **debuglevel) + char **debuglevel) { *debuglevel = ctx->debuglevel; return NET_API_STATUS_SUCCESS; @@ -195,3 +195,26 @@ 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; +} diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h index 3c9d3b3853..46dd8e1a24 100644 --- a/source3/lib/netapi/netapi.h +++ b/source3/lib/netapi/netapi.h @@ -27,7 +27,8 @@ ****************************************************************/ struct libnetapi_ctx { - const char *debuglevel; + char *debuglevel; + char *error_string; char *username; char *workgroup; char *password; @@ -41,11 +42,16 @@ 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); + +/**************************************************************** +****************************************************************/ /* wkssvc */ NET_API_STATUS NetJoinDomain(const char *server, -- cgit From d6659f8ac84d5b3f19fb16a739657240f835c358 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 7 Jan 2008 20:08:45 +0100 Subject: In the local path of NetJoinDomain, try to get error string from libnetjoin. Guenther (This used to be commit 0f0f0e13022da584b77e850fec2cef6169e1ac28) --- source3/lib/netapi/joindomain.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/joindomain.c b/source3/lib/netapi/joindomain.c index ceb7ca10d9..aa8ec6e0b5 100644 --- a/source3/lib/netapi/joindomain.c +++ b/source3/lib/netapi/joindomain.c @@ -78,6 +78,9 @@ static WERROR NetJoinDomainLocal(struct libnetapi_ctx *mem_ctx, r->in.modify_config = true; 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; -- cgit From 74fc0bf9e5f4fe21b80a4b6df144d780e1bb943a Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 7 Jan 2008 20:10:47 +0100 Subject: In libnetapi example, use libnetapi_get_error_string(). Guenther (This used to be commit b624db92d61809a44881abbdd09dfa3a74ff7a88) --- source3/lib/netapi/examples/netdomjoin/netdomjoin.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'source3/lib/netapi') 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"); } -- cgit From e3ea1e1391a10fb1f4708abab038c0cfc2b86b41 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 7 Jan 2008 22:48:19 +0100 Subject: Enable talloc reporting in libnetapi if DEVELOPER compiled. Guenther (This used to be commit 01e9151546a83e0c772a144efa85437ca0c8a307) --- source3/lib/netapi/netapi.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi.c b/source3/lib/netapi/netapi.c index d5527dc4ff..61b51909c9 100644 --- a/source3/lib/netapi/netapi.c +++ b/source3/lib/netapi/netapi.c @@ -39,6 +39,9 @@ NET_API_STATUS libnetapi_init(struct libnetapi_ctx **context) return NET_API_STATUS_SUCCESS; } +#ifdef DEVELOPER + talloc_enable_leak_report(); +#endif frame = talloc_stackframe(); ctx = talloc_zero(frame, struct libnetapi_ctx); -- cgit From ab216a1b4ea585faa42be4908a24a475173683d2 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 8 Jan 2008 11:49:35 +0100 Subject: Fix crash bug when strequal is used too late in libnetapi_free. Guenther (This used to be commit ba2b8a310e1d6f78116350e24c17ae4db08b9bed) --- source3/lib/netapi/netapi.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi.c b/source3/lib/netapi/netapi.c index 61b51909c9..3516105353 100644 --- a/source3/lib/netapi/netapi.c +++ b/source3/lib/netapi/netapi.c @@ -103,6 +103,14 @@ NET_API_STATUS libnetapi_getctx(struct libnetapi_ctx **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(); @@ -113,11 +121,6 @@ NET_API_STATUS libnetapi_free(struct libnetapi_ctx *ctx) secrets_shutdown(); regdb_close(); - if (ctx->krb5_cc_env && - (strequal(ctx->krb5_cc_env, getenv(KRB5_ENV_CCNAME)))) { - unsetenv(KRB5_ENV_CCNAME); - } - TALLOC_FREE(ctx); TALLOC_FREE(frame); -- cgit From a01dc30db7cb16c794f5daf23ad2df607f891626 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 8 Jan 2008 11:53:38 +0100 Subject: Add NetApiBufferFree() to libnetapi. Guenther (This used to be commit c49196954d38f0c2851abbfe25086cd6fe660a2e) --- source3/lib/netapi/netapi.c | 14 ++++++++++++++ source3/lib/netapi/netapi.h | 5 +++++ 2 files changed, 19 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi.c b/source3/lib/netapi/netapi.c index 3516105353..d4cb3a9fe2 100644 --- a/source3/lib/netapi/netapi.c +++ b/source3/lib/netapi/netapi.c @@ -224,3 +224,17 @@ 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 46dd8e1a24..4a40b32fc9 100644 --- a/source3/lib/netapi/netapi.h +++ b/source3/lib/netapi/netapi.h @@ -53,6 +53,11 @@ const char *libnetapi_get_error_string(struct libnetapi_ctx *ctx); /**************************************************************** ****************************************************************/ +NET_API_STATUS NetApiBufferFree(void *buffer); + +/**************************************************************** +****************************************************************/ + /* wkssvc */ NET_API_STATUS NetJoinDomain(const char *server, const char *domain, -- cgit From 200bba3ad6592952041daa9da9805941c6dd03ba Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 8 Jan 2008 11:54:51 +0100 Subject: Make name_buffer in NetGetJoinInformation() talloced. Guenther (This used to be commit 421905fb608df6736944ac21ac67abee24991521) --- source3/lib/netapi/joindomain.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/joindomain.c b/source3/lib/netapi/joindomain.c index aa8ec6e0b5..e4fb63eebb 100644 --- a/source3/lib/netapi/joindomain.c +++ b/source3/lib/netapi/joindomain.c @@ -437,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; -- cgit From 67f2afe3c4cfd46aa20b7a7c568ac6b5ab16acb8 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 8 Jan 2008 11:55:45 +0100 Subject: Correctly free buffers in netdomjoin-gui. Guenther (This used to be commit 04d78d4d9a8cffe44c927036038aef1d6d6b44b2) --- source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c index 1e1681ba37..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) { @@ -1292,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); } { @@ -1311,6 +1317,7 @@ static int initialize_join_state(struct join_state *state, if (!state->comment) { return -1; } + NetApiBufferFree(buffer); } #if 0 { -- cgit From 4eed7883bb0832157461cac1f0efcd6398746d7d Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 11 Jan 2008 14:47:23 +0100 Subject: Refactor libnetapi error string functions a bit. Guenther (This used to be commit 3b450a8bcc97b6d03c4b7b9373a3a382c0fcea30) --- source3/lib/netapi/netapi.c | 21 +++++++++++++++++---- source3/lib/netapi/netapi.h | 5 +++-- 2 files changed, 20 insertions(+), 6 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi.c b/source3/lib/netapi/netapi.c index d4cb3a9fe2..ce00054e6e 100644 --- a/source3/lib/netapi/netapi.c +++ b/source3/lib/netapi/netapi.c @@ -192,8 +192,7 @@ NET_API_STATUS libnetapi_set_workgroup(struct libnetapi_ctx *ctx, /**************************************************************** ****************************************************************/ -const char *libnetapi_errstr(struct libnetapi_ctx *ctx, - NET_API_STATUS status) +const char *libnetapi_errstr(NET_API_STATUS status) { if (status & 0xc0000000) { return get_friendly_nt_error_msg(NT_STATUS(status)); @@ -220,9 +219,23 @@ NET_API_STATUS libnetapi_set_error_string(struct libnetapi_ctx *ctx, /**************************************************************** ****************************************************************/ -const char *libnetapi_get_error_string(struct libnetapi_ctx *ctx) +const char *libnetapi_get_error_string(struct libnetapi_ctx *ctx, + NET_API_STATUS status) { - return ctx->error_string; + struct libnetapi_ctx *tmp_ctx = ctx; + + if (!tmp_ctx) { + status = libnetapi_getctx(&tmp_ctx); + if (status != 0) { + return NULL; + } + } + + if (tmp_ctx->error_string) { + return tmp_ctx->error_string; + } + + return libnetapi_errstr(status); } /**************************************************************** diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h index 4a40b32fc9..61cece119f 100644 --- a/source3/lib/netapi/netapi.h +++ b/source3/lib/netapi/netapi.h @@ -46,9 +46,10 @@ NET_API_STATUS libnetapi_get_debuglevel(struct libnetapi_ctx *ctx, char **debugl 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); +const char *libnetapi_errstr(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); +const char *libnetapi_get_error_string(struct libnetapi_ctx *ctx, NET_API_STATUS status); + /**************************************************************** ****************************************************************/ -- cgit From 7a87256cd1ac7962da9a5e37945ee5dd26a18c98 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 11 Jan 2008 14:47:52 +0100 Subject: Include some basic headers in netapi.h. Guenther (This used to be commit 23b92a6fa57858c8a23c737a9cd00c076ef5dadd) --- source3/lib/netapi/netapi.h | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h index 61cece119f..274a167d53 100644 --- a/source3/lib/netapi/netapi.h +++ b/source3/lib/netapi/netapi.h @@ -20,6 +20,16 @@ #ifndef __LIB_NETAPI_H__ #define __LIB_NETAPI_H__ +/**************************************************************** + include some basic headers +****************************************************************/ + +#include + +/**************************************************************** + NET_API_STATUS +****************************************************************/ + #define NET_API_STATUS uint32_t #define NET_API_STATUS_SUCCESS 0 -- cgit From efcf285e27e3f52cd6188f678d52977584c78972 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 11 Jan 2008 15:28:24 +0100 Subject: Fix libnetapi error string callers. Guenther (This used to be commit 1ad7a0a361edfa5ac738f011db1d6a9db256ac2c) --- source3/lib/netapi/examples/getdc/getdc.c | 2 +- source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c | 8 ++++---- source3/lib/netapi/examples/netdomjoin/netdomjoin.c | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/getdc/getdc.c b/source3/lib/netapi/examples/getdc/getdc.c index 4f5c5332d5..cdd4d0b3b4 100644 --- a/source3/lib/netapi/examples/getdc/getdc.c +++ b/source3/lib/netapi/examples/getdc/getdc.c @@ -46,7 +46,7 @@ int main(int argc, char **argv) status = NetGetDCName(argv[1], argv[2], &buffer); if (status != 0) { - printf("GetDcName failed with: %s\n", libnetapi_errstr(ctx, status)); + printf("GetDcName failed with: %s\n", libnetapi_errstr(status)); } else { printf("%s\n", (char *)buffer); } diff --git a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c index 4a3588e9ab..9dc2a18138 100644 --- a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c +++ b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c @@ -147,13 +147,13 @@ static void callback_apply_description_change(GtkWidget *widget, status = NetServerSetInfo(NULL, 1005, (uint8_t *)&info1005, &parm_err); if (status) { debug("NetServerSetInfo failed with: %s\n", - libnetapi_errstr(state->ctx, status)); + libnetapi_errstr(status)); dialog = gtk_message_dialog_new(GTK_WINDOW(state->window_main), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "Failed to change computer description: %s.", - libnetapi_errstr(state->ctx, status)); + libnetapi_errstr(status)); g_signal_connect_swapped(dialog, "response", G_CALLBACK(gtk_widget_destroy), dialog); @@ -439,7 +439,7 @@ static void callback_do_join(GtkWidget *widget, state->password, unjoin_flags); if (status != 0) { - err_str = libnetapi_errstr(state->ctx, status); + err_str = libnetapi_errstr(status); g_print("callback_do_join: failed to unjoin (%s)\n", err_str); @@ -463,7 +463,7 @@ static void callback_do_join(GtkWidget *widget, state->password, join_flags); if (status != 0) { - err_str = libnetapi_errstr(state->ctx, status); + err_str = libnetapi_errstr(status); g_print("callback_do_join: failed to join (%s)\n", err_str); dialog = gtk_message_dialog_new(GTK_WINDOW(state->window_parent), diff --git a/source3/lib/netapi/examples/netdomjoin/netdomjoin.c b/source3/lib/netapi/examples/netdomjoin/netdomjoin.c index a0ac0b1e56..29f66a17a2 100644 --- a/source3/lib/netapi/examples/netdomjoin/netdomjoin.c +++ b/source3/lib/netapi/examples/netdomjoin/netdomjoin.c @@ -105,9 +105,9 @@ int main(int argc, char **argv) join_flags); if (status != 0) { const char *errstr = NULL; - errstr = libnetapi_get_error_string(ctx); + errstr = libnetapi_get_error_string(ctx, status); if (!errstr) { - errstr = libnetapi_errstr(ctx, status); + errstr = libnetapi_errstr(status); } printf("Join failed with: %s\n", errstr); } else { -- cgit From c79ce2ffa3f7d00ce6a2cd6008c203e3042b0b02 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 11 Jan 2008 15:32:20 +0100 Subject: As long as DsGetDcName is not part of libnetapi, lowercase the fn name. Guenther (This used to be commit 19a980f52044a170618629e5b0484c1f6b586e5f) --- source3/lib/netapi/joindomain.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/joindomain.c b/source3/lib/netapi/joindomain.c index e4fb63eebb..b268e41a2a 100644 --- a/source3/lib/netapi/joindomain.c +++ b/source3/lib/netapi/joindomain.c @@ -49,7 +49,7 @@ static WERROR NetJoinDomainLocal(struct libnetapi_ctx *mem_ctx, 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); @@ -244,7 +244,7 @@ static WERROR NetUnjoinDomainLocal(struct libnetapi_ctx *mem_ctx, } 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); -- cgit From 1ee6d3e1ee56554d83437a8c79cb169a26732154 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Sun, 13 Jan 2008 01:40:05 +0100 Subject: Introduce a libnet_conf context created by libnet_conf_open(). The libnet_conf_ctx stores the information necessary to interoperate with the configuration. It is created by calling libnet_conf_open() and destroyed by calling libnet_conf_close(). The context is passed to all the libnet_conf functions. It currently stores the token to access the registry. Later, it could store more data, e.g. the server to connect to, credentials, and so on. For support of other backends than registry or support of remote configuration, only the open function will have to be changed. In net_conf, the calls to the actual net_conf functions is wrapped into a function that calls libnet_conf_open()/_close(). Thus an individual variant of net_conf_runfunction2() and functable2 is used to cope with functions being called by the wrapper with the additional libnet_conf_ctx argument. Michael (This used to be commit c2a9346faa26e79af5948197a1b322e545f0ed09) --- source3/lib/netapi/serverinfo.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/serverinfo.c b/source3/lib/netapi/serverinfo.c index 0e356e0ee7..67680ba55a 100644 --- a/source3/lib/netapi/serverinfo.c +++ b/source3/lib/netapi/serverinfo.c @@ -149,6 +149,10 @@ static WERROR NetServerSetInfoLocal_1005(struct libnetapi_ctx *ctx, uint8_t *buffer, uint32_t *parm_error) { + WERROR werr; + struct libnet_conf_ctx *conf_ctx; + TALLOC_CTX *mem_ctx; + struct srvsvc_NetSrvInfo1005 *info1005; if (!buffer) { @@ -167,8 +171,20 @@ static WERROR NetServerSetInfoLocal_1005(struct libnetapi_ctx *ctx, return WERR_NOT_SUPPORTED; } - return libnet_conf_set_global_parameter("server string", + mem_ctx = talloc_stackframe(); + werr = libnet_conf_open(mem_ctx, &conf_ctx); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + werr = libnet_conf_set_global_parameter(conf_ctx, + "server string", info1005->comment); + +done: + libnet_conf_close(conf_ctx); + TALLOC_FREE(mem_ctx); + return werr; } static WERROR NetServerSetInfoLocal(struct libnetapi_ctx *ctx, -- cgit From 7bfceba4bc49f5f5c8d2836dfd76e1ec15459631 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Wed, 16 Jan 2008 17:05:38 +0100 Subject: Use lp_config_backend_is_registry() instead of lp_include_registry_globals(). Michael (This used to be commit c5a7d421c512a6221b0300549d7b5de0368d252e) --- source3/lib/netapi/serverinfo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/serverinfo.c b/source3/lib/netapi/serverinfo.c index 67680ba55a..6cd074615b 100644 --- a/source3/lib/netapi/serverinfo.c +++ b/source3/lib/netapi/serverinfo.c @@ -167,7 +167,7 @@ static WERROR NetServerSetInfoLocal_1005(struct libnetapi_ctx *ctx, return WERR_INVALID_PARAM; } - if (!lp_include_registry_globals()) { + if (!lp_config_backend_is_registry()) { return WERR_NOT_SUPPORTED; } -- cgit From d1abd4d866b59fa67605fc469d6406a981455fbe Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 17 Jan 2008 10:39:15 +0100 Subject: Use new pidl-generated netlogon client calls in NetApi GetDcName(). Guenther (This used to be commit 733e07a06ce3c903ff5837df6a5119f6d6e3eccb) --- source3/lib/netapi/examples/getdc/getdc.c | 4 +-- source3/lib/netapi/getdc.c | 42 +++++-------------------------- 2 files changed, 8 insertions(+), 38 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/getdc/getdc.c b/source3/lib/netapi/examples/getdc/getdc.c index cdd4d0b3b4..272ba1088e 100644 --- a/source3/lib/netapi/examples/getdc/getdc.c +++ b/source3/lib/netapi/examples/getdc/getdc.c @@ -29,7 +29,7 @@ int main(int argc, char **argv) { NET_API_STATUS status; struct libnetapi_ctx *ctx = NULL; - uint8_t *buffer; + uint8_t *buffer = NULL; if (argc < 3) { printf("usage: getdc \n"); @@ -50,7 +50,7 @@ int main(int argc, char **argv) } else { printf("%s\n", (char *)buffer); } - + NetApiBufferFree(buffer); libnetapi_free(ctx); return status; diff --git a/source3/lib/netapi/getdc.c b/source3/lib/netapi/getdc.c index 85a0ae52ef..484af04a55 100644 --- a/source3/lib/netapi/getdc.c +++ b/source3/lib/netapi/getdc.c @@ -22,22 +22,6 @@ #include "lib/netapi/netapi.h" #include "libnet/libnet.h" -#if 0 -#include "librpc/gen_ndr/cli_netlogon.h" -#endif - -NTSTATUS rpccli_netr_GetDcName(struct rpc_pipe_client *cli, - TALLOC_CTX *mem_ctx, - const char *logon_server, - const char *domainname, - const char **dcname); -NTSTATUS rpccli_netr_GetAnyDCName(struct rpc_pipe_client *cli, - TALLOC_CTX *mem_ctx, - const char *logon_server, - const char *domainname, - const char **dcname, - WERROR *werror); - static WERROR NetGetDCNameLocal(struct libnetapi_ctx *ctx, const char *server_name, const char *domain_name, @@ -76,17 +60,11 @@ static WERROR NetGetDCNameRemote(struct libnetapi_ctx *ctx, goto done; }; -#if 0 - werr = rpccli_netr_GetDcName(pipe_cli, ctx, - server_name, - domain_name, - (const char **)&buffer); -#else - werr = rpccli_netlogon_getdcname(pipe_cli, ctx, - server_name, - domain_name, - (char **)buffer); -#endif + status = rpccli_netr_GetDcName(pipe_cli, ctx, + server_name, + domain_name, + (const char **)buffer); + werr = ntstatus_to_werror(status); done: if (cli) { cli_shutdown(cli); @@ -175,22 +153,14 @@ static WERROR NetGetAnyDCNameRemote(struct libnetapi_ctx *ctx, goto done; }; -#if 0 status = rpccli_netr_GetAnyDCName(pipe_cli, ctx, server_name, domain_name, - (const char **)&buffer, + (const char **)buffer, &werr); if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); goto done; } -#else - werr = rpccli_netlogon_getanydcname(pipe_cli, ctx, - server_name, - domain_name, - (char **)buffer); -#endif done: if (cli) { cli_shutdown(cli); -- cgit From c2ff6c94f2f9ddc2c4b03f7907f7d6e0de951c24 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 18 Jan 2008 01:56:01 +0100 Subject: Improve libnetapi_set_error_string(). Guenther (This used to be commit 96f645553ae5c75aabfe588e1a67f3d4bfacb5cb) --- source3/lib/netapi/netapi.c | 11 ++++++++--- source3/lib/netapi/netapi.h | 35 +++++++++++++++++++++++++++++++---- 2 files changed, 39 insertions(+), 7 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi.c b/source3/lib/netapi/netapi.c index ce00054e6e..5c3f7ec465 100644 --- a/source3/lib/netapi/netapi.c +++ b/source3/lib/netapi/netapi.c @@ -205,15 +205,20 @@ const char *libnetapi_errstr(NET_API_STATUS status) ****************************************************************/ NET_API_STATUS libnetapi_set_error_string(struct libnetapi_ctx *ctx, - const char *error_string) + const char *format, ...) { + va_list args; + TALLOC_FREE(ctx->error_string); - ctx->error_string = talloc_strdup(ctx, error_string); + + va_start(args, format); + ctx->error_string = talloc_vasprintf(ctx, format, args); + va_end(args); + if (!ctx->error_string) { return W_ERROR_V(WERR_NOMEM); } return NET_API_STATUS_SUCCESS; - } /**************************************************************** diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h index 274a167d53..67bb8a8fca 100644 --- a/source3/lib/netapi/netapi.h +++ b/source3/lib/netapi/netapi.h @@ -57,46 +57,73 @@ NET_API_STATUS libnetapi_set_username(struct libnetapi_ctx *ctx, const char *use 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(NET_API_STATUS status); -NET_API_STATUS libnetapi_set_error_string(struct libnetapi_ctx *ctx, const char *error_string); +NET_API_STATUS libnetapi_set_error_string(struct libnetapi_ctx *ctx, const char *format, ...); const char *libnetapi_get_error_string(struct libnetapi_ctx *ctx, NET_API_STATUS status); /**************************************************************** + NetApiBufferFree ****************************************************************/ NET_API_STATUS NetApiBufferFree(void *buffer); /**************************************************************** + NetJoinDomain ****************************************************************/ -/* wkssvc */ NET_API_STATUS NetJoinDomain(const char *server, const char *domain, const char *account_ou, const char *account, const char *password, uint32_t join_options); + +/**************************************************************** + NetUnjoinDomain +****************************************************************/ + NET_API_STATUS NetUnjoinDomain(const char *server_name, const char *account, const char *password, uint32_t unjoin_flags); + +/**************************************************************** + NetGetJoinInformation +****************************************************************/ + NET_API_STATUS NetGetJoinInformation(const char *server_name, const char **name_buffer, uint16_t *name_type); -/* srvsvc */ +/**************************************************************** + NetServerGetInfo +****************************************************************/ + NET_API_STATUS NetServerGetInfo(const char *server_name, uint32_t level, uint8_t **buffer); + +/**************************************************************** + NetServerSetInfo +****************************************************************/ + NET_API_STATUS NetServerSetInfo(const char *server_name, uint32_t level, uint8_t *buffer, uint32_t *parm_error); -/* netlogon */ +/**************************************************************** + NetGetDCName +****************************************************************/ + NET_API_STATUS NetGetDCName(const char *server_name, const char *domain_name, uint8_t **buffer); + +/**************************************************************** + NetGetAnyDCName +****************************************************************/ + NET_API_STATUS NetGetAnyDCName(const char *server_name, const char *domain_name, uint8_t **buffer); -- cgit From bb97b272a975e4af7738c58e7af4b8e3047d4b77 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 18 Jan 2008 02:30:09 +0100 Subject: Fix local hostname detection in netdomjoin-gui. Guenther (This used to be commit 30458116b389889cad845eb96b54c3edc833e722) --- .../examples/netdomjoin-gui/netdomjoin-gui.c | 37 ++++++++++++++++------ 1 file changed, 27 insertions(+), 10 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c index 9dc2a18138..6e958b4c73 100644 --- a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c +++ b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -1263,28 +1264,44 @@ static int initialize_join_state(struct join_state *state, { char my_hostname[HOST_NAME_MAX]; const char *p = NULL; + struct hostent *hp = NULL; + if (gethostname(my_hostname, sizeof(my_hostname)) == -1) { return -1; } - state->my_fqdn = strdup(my_hostname); + p = strchr(my_hostname, '.'); + if (p) { + my_hostname[strlen(my_hostname)-strlen(p)] = '\0'; + } + state->my_hostname = strdup(my_hostname); + if (!state->my_hostname) { + return -1; + } + debug("state->my_hostname: %s\n", state->my_hostname); + + hp = gethostbyname(my_hostname); + if (!hp || !hp->h_name || !*hp->h_name) { + return -1; + } + + state->my_fqdn = strdup(hp->h_name); if (!state->my_fqdn) { return -1; } + debug("state->my_fqdn: %s\n", state->my_fqdn); - p = strchr(my_hostname, '.'); + p = strchr(state->my_fqdn, '.'); if (p) { - my_hostname[strlen(my_hostname) - strlen(p)] = '\0'; - state->my_hostname = strdup(my_hostname); - if (!state->my_hostname) { - return -1; - } p++; state->my_dnsdomain = strdup(p); - if (!state->my_dnsdomain) { - return -1; - } + } else { + state->my_dnsdomain = strdup(""); + } + if (!state->my_dnsdomain) { + return -1; } + debug("state->my_dnsdomain: %s\n", state->my_dnsdomain); } { -- cgit From cfb7e254662dd957da7e193010f87544b96c2f17 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 18 Jan 2008 02:30:53 +0100 Subject: Add some more debugging into netdomjoin-gui. Guenther (This used to be commit d4c5b323229c6f43c824e3559084c98e370730a5) --- source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c index 6e958b4c73..73b14d4d87 100644 --- a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c +++ b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c @@ -440,7 +440,7 @@ static void callback_do_join(GtkWidget *widget, state->password, unjoin_flags); if (status != 0) { - err_str = libnetapi_errstr(status); + err_str = libnetapi_get_error_string(state->ctx, status); g_print("callback_do_join: failed to unjoin (%s)\n", err_str); @@ -464,7 +464,7 @@ static void callback_do_join(GtkWidget *widget, state->password, join_flags); if (status != 0) { - err_str = libnetapi_errstr(status); + err_str = libnetapi_get_error_string(state->ctx, status); g_print("callback_do_join: failed to join (%s)\n", err_str); dialog = gtk_message_dialog_new(GTK_WINDOW(state->window_parent), @@ -1308,9 +1308,12 @@ static int initialize_join_state(struct join_state *state, const char *buffer = NULL; uint16_t type = 0; status = NetGetJoinInformation(NULL, &buffer, &type); - if (status) { + if (status != 0) { + printf("NetGetJoinInformation failed with: %s\n", + libnetapi_get_error_string(state->ctx, status)); return status; } + debug("NetGetJoinInformation gave: %s and %d\n", buffer, type); state->name_buffer_initial = strdup(buffer); if (!state->name_buffer_initial) { return -1; @@ -1324,7 +1327,9 @@ static int initialize_join_state(struct join_state *state, uint8_t *buffer = NULL; status = NetServerGetInfo(NULL, 1005, &buffer); - if (status) { + if (status != 0) { + printf("NetServerGetInfo failed with: %s\n", + libnetapi_get_error_string(state->ctx, status)); return status; } -- cgit From b1424846c60848d685853fcf632ab766543e05ee Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 18 Jan 2008 02:38:35 +0100 Subject: Cosmetics and error string reporting for libnetapi. Guenther (This used to be commit 4ca33928512bd71268bafd41d2b608e814a7295f) --- source3/lib/netapi/getdc.c | 30 ++++++++++++++++++++-- source3/lib/netapi/joindomain.c | 57 ++++++++++++++++++++++++++++++++++++----- source3/lib/netapi/serverinfo.c | 43 +++++++++++++++++++++++++------ 3 files changed, 114 insertions(+), 16 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/getdc.c b/source3/lib/netapi/getdc.c index 484af04a55..1084ddc3c8 100644 --- a/source3/lib/netapi/getdc.c +++ b/source3/lib/netapi/getdc.c @@ -22,6 +22,9 @@ #include "lib/netapi/netapi.h" #include "libnet/libnet.h" +/******************************************************************** +********************************************************************/ + static WERROR NetGetDCNameLocal(struct libnetapi_ctx *ctx, const char *server_name, const char *domain_name, @@ -30,6 +33,9 @@ static WERROR NetGetDCNameLocal(struct libnetapi_ctx *ctx, return WERR_NOT_SUPPORTED; } +/******************************************************************** +********************************************************************/ + static WERROR NetGetDCNameRemote(struct libnetapi_ctx *ctx, const char *server_name, const char *domain_name, @@ -73,6 +79,9 @@ static WERROR NetGetDCNameRemote(struct libnetapi_ctx *ctx, return werr; } +/******************************************************************** +********************************************************************/ + static WERROR libnetapi_NetGetDCName(struct libnetapi_ctx *ctx, const char *server_name, const char *domain_name, @@ -91,6 +100,10 @@ static WERROR libnetapi_NetGetDCName(struct libnetapi_ctx *ctx, buffer); } +/**************************************************************** + NetGetDCName +****************************************************************/ + NET_API_STATUS NetGetDCName(const char *server_name, const char *domain_name, uint8_t **buffer) @@ -112,9 +125,12 @@ NET_API_STATUS NetGetDCName(const char *server_name, return W_ERROR_V(werr); } - return 0; + return NET_API_STATUS_SUCCESS; } +/******************************************************************** +********************************************************************/ + static WERROR NetGetAnyDCNameLocal(struct libnetapi_ctx *ctx, const char *server_name, const char *domain_name, @@ -123,6 +139,9 @@ static WERROR NetGetAnyDCNameLocal(struct libnetapi_ctx *ctx, return WERR_NOT_SUPPORTED; } +/******************************************************************** +********************************************************************/ + static WERROR NetGetAnyDCNameRemote(struct libnetapi_ctx *ctx, const char *server_name, const char *domain_name, @@ -170,6 +189,9 @@ static WERROR NetGetAnyDCNameRemote(struct libnetapi_ctx *ctx, } +/******************************************************************** +********************************************************************/ + static WERROR libnetapi_NetGetAnyDCName(struct libnetapi_ctx *ctx, const char *server_name, const char *domain_name, @@ -188,6 +210,10 @@ static WERROR libnetapi_NetGetAnyDCName(struct libnetapi_ctx *ctx, buffer); } +/**************************************************************** + NetGetAnyDCName +****************************************************************/ + NET_API_STATUS NetGetAnyDCName(const char *server_name, const char *domain_name, uint8_t **buffer) @@ -209,5 +235,5 @@ NET_API_STATUS NetGetAnyDCName(const char *server_name, return W_ERROR_V(werr); } - return 0; + return NET_API_STATUS_SUCCESS; } diff --git a/source3/lib/netapi/joindomain.c b/source3/lib/netapi/joindomain.c index b268e41a2a..43662b3ffa 100644 --- a/source3/lib/netapi/joindomain.c +++ b/source3/lib/netapi/joindomain.c @@ -22,6 +22,9 @@ #include "lib/netapi/netapi.h" #include "libnet/libnet.h" +/**************************************************************** +****************************************************************/ + static WERROR NetJoinDomainLocal(struct libnetapi_ctx *mem_ctx, const char *server_name, const char *domain_name, @@ -52,6 +55,8 @@ static WERROR NetJoinDomainLocal(struct libnetapi_ctx *mem_ctx, status = dsgetdcname(mem_ctx, NULL, domain_name, NULL, NULL, flags, &info); if (!NT_STATUS_IS_OK(status)) { + libnetapi_set_error_string(mem_ctx, + "%s", get_friendly_nt_error_msg(status)); return ntstatus_to_werror(status); } r->in.dc_name = talloc_strdup(mem_ctx, @@ -79,13 +84,16 @@ static WERROR NetJoinDomainLocal(struct libnetapi_ctx *mem_ctx, 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); + libnetapi_set_error_string(mem_ctx, "%s", r->out.error_string); } TALLOC_FREE(r); return werr; } +/**************************************************************** +****************************************************************/ + static WERROR NetJoinDomainRemote(struct libnetapi_ctx *ctx, const char *server_name, const char *domain_name, @@ -149,6 +157,9 @@ static WERROR NetJoinDomainRemote(struct libnetapi_ctx *ctx, return werr; } +/**************************************************************** +****************************************************************/ + static WERROR libnetapi_NetJoinDomain(struct libnetapi_ctx *ctx, const char *server_name, const char *domain_name, @@ -181,6 +192,10 @@ static WERROR libnetapi_NetJoinDomain(struct libnetapi_ctx *ctx, join_flags); } +/**************************************************************** + NetJoinDomain +****************************************************************/ + NET_API_STATUS NetJoinDomain(const char *server_name, const char *domain_name, const char *account_ou, @@ -208,9 +223,12 @@ NET_API_STATUS NetJoinDomain(const char *server_name, return W_ERROR_V(werr); } - return 0; + return NET_API_STATUS_SUCCESS; } +/**************************************************************** +****************************************************************/ + static WERROR NetUnjoinDomainLocal(struct libnetapi_ctx *mem_ctx, const char *server_name, const char *account, @@ -232,7 +250,6 @@ static WERROR NetUnjoinDomainLocal(struct libnetapi_ctx *mem_ctx, r->in.dc_name = talloc_strdup(mem_ctx, server_name); W_ERROR_HAVE_NO_MEMORY(r->in.dc_name); } else { - NTSTATUS status; const char *domain = NULL; struct DS_DOMAIN_CONTROLLER_INFO *info = NULL; @@ -247,6 +264,8 @@ static WERROR NetUnjoinDomainLocal(struct libnetapi_ctx *mem_ctx, status = dsgetdcname(mem_ctx, NULL, domain, NULL, NULL, flags, &info); if (!NT_STATUS_IS_OK(status)) { + libnetapi_set_error_string(mem_ctx, + "%s", get_friendly_nt_error_msg(status)); return ntstatus_to_werror(status); } r->in.dc_name = talloc_strdup(mem_ctx, @@ -266,13 +285,22 @@ static WERROR NetUnjoinDomainLocal(struct libnetapi_ctx *mem_ctx, r->in.unjoin_flags = unjoin_flags; r->in.modify_config = true; + r->in.debug = true; r->in.domain_sid = &domain_sid; - return libnet_Unjoin(mem_ctx, r); + werr = libnet_Unjoin(mem_ctx, r); + if (!W_ERROR_IS_OK(werr) && r->out.error_string) { + libnetapi_set_error_string(mem_ctx, "%s", r->out.error_string); + } + TALLOC_FREE(r); + return werr; } +/**************************************************************** +****************************************************************/ + static WERROR NetUnjoinDomainRemote(struct libnetapi_ctx *ctx, const char *server_name, const char *account, @@ -335,6 +363,9 @@ static WERROR NetUnjoinDomainRemote(struct libnetapi_ctx *ctx, return werr; } +/**************************************************************** +****************************************************************/ + static WERROR libnetapi_NetUnjoinDomain(struct libnetapi_ctx *ctx, const char *server_name, const char *account, @@ -357,6 +388,10 @@ static WERROR libnetapi_NetUnjoinDomain(struct libnetapi_ctx *ctx, unjoin_flags); } +/**************************************************************** + NetUnjoinDomain +****************************************************************/ + NET_API_STATUS NetUnjoinDomain(const char *server_name, const char *account, const char *password, @@ -380,9 +415,12 @@ NET_API_STATUS NetUnjoinDomain(const char *server_name, return W_ERROR_V(werr); } - return 0; + return NET_API_STATUS_SUCCESS; } +/**************************************************************** +****************************************************************/ + static WERROR NetGetJoinInformationRemote(struct libnetapi_ctx *ctx, const char *server_name, const char **name_buffer, @@ -431,6 +469,9 @@ static WERROR NetGetJoinInformationRemote(struct libnetapi_ctx *ctx, return werr; } +/**************************************************************** +****************************************************************/ + static WERROR NetGetJoinInformationLocal(struct libnetapi_ctx *ctx, const char *server_name, const char **name_buffer, @@ -478,6 +519,10 @@ static WERROR libnetapi_NetGetJoinInformation(struct libnetapi_ctx *ctx, name_type); } +/**************************************************************** + NetGetJoinInformation +****************************************************************/ + NET_API_STATUS NetGetJoinInformation(const char *server_name, const char **name_buffer, uint16_t *name_type) @@ -499,5 +544,5 @@ NET_API_STATUS NetGetJoinInformation(const char *server_name, return W_ERROR_V(werr); } - return 0; + return NET_API_STATUS_SUCCESS; } diff --git a/source3/lib/netapi/serverinfo.c b/source3/lib/netapi/serverinfo.c index 6cd074615b..7fa166e411 100644 --- a/source3/lib/netapi/serverinfo.c +++ b/source3/lib/netapi/serverinfo.c @@ -22,6 +22,9 @@ #include "lib/netapi/netapi.h" #include "libnet/libnet.h" +/**************************************************************** +****************************************************************/ + static WERROR NetServerGetInfoLocal_1005(struct libnetapi_ctx *ctx, uint8_t **buffer) { @@ -36,6 +39,9 @@ static WERROR NetServerGetInfoLocal_1005(struct libnetapi_ctx *ctx, return WERR_OK; } +/**************************************************************** +****************************************************************/ + static WERROR NetServerGetInfoLocal(struct libnetapi_ctx *ctx, const char *server_name, uint32_t level, @@ -51,6 +57,9 @@ static WERROR NetServerGetInfoLocal(struct libnetapi_ctx *ctx, return WERR_UNKNOWN_LEVEL; } +/**************************************************************** +****************************************************************/ + static WERROR NetServerGetInfoRemote(struct libnetapi_ctx *ctx, const char *server_name, uint32_t level, @@ -102,6 +111,9 @@ static WERROR NetServerGetInfoRemote(struct libnetapi_ctx *ctx, return werr; } +/**************************************************************** +****************************************************************/ + static WERROR libnetapi_NetServerGetInfo(struct libnetapi_ctx *ctx, const char *server_name, uint32_t level, @@ -121,6 +133,10 @@ static WERROR libnetapi_NetServerGetInfo(struct libnetapi_ctx *ctx, } +/**************************************************************** + NetServerGetInfo +****************************************************************/ + NET_API_STATUS NetServerGetInfo(const char *server_name, uint32_t level, uint8_t **buffer) @@ -142,17 +158,18 @@ NET_API_STATUS NetServerGetInfo(const char *server_name, return W_ERROR_V(werr); } - return 0; + return NET_API_STATUS_SUCCESS; } +/**************************************************************** +****************************************************************/ + static WERROR NetServerSetInfoLocal_1005(struct libnetapi_ctx *ctx, uint8_t *buffer, uint32_t *parm_error) { WERROR werr; struct libnet_conf_ctx *conf_ctx; - TALLOC_CTX *mem_ctx; - struct srvsvc_NetSrvInfo1005 *info1005; if (!buffer) { @@ -171,8 +188,7 @@ static WERROR NetServerSetInfoLocal_1005(struct libnetapi_ctx *ctx, return WERR_NOT_SUPPORTED; } - mem_ctx = talloc_stackframe(); - werr = libnet_conf_open(mem_ctx, &conf_ctx); + werr = libnet_conf_open(ctx, &conf_ctx); if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -181,12 +197,14 @@ static WERROR NetServerSetInfoLocal_1005(struct libnetapi_ctx *ctx, "server string", info1005->comment); -done: + done: libnet_conf_close(conf_ctx); - TALLOC_FREE(mem_ctx); return werr; } +/**************************************************************** +****************************************************************/ + static WERROR NetServerSetInfoLocal(struct libnetapi_ctx *ctx, const char *server_name, uint32_t level, @@ -203,6 +221,9 @@ static WERROR NetServerSetInfoLocal(struct libnetapi_ctx *ctx, return WERR_UNKNOWN_LEVEL; } +/**************************************************************** +****************************************************************/ + static WERROR NetServerSetInfoRemote(struct libnetapi_ctx *ctx, const char *server_name, uint32_t level, @@ -263,6 +284,9 @@ static WERROR NetServerSetInfoRemote(struct libnetapi_ctx *ctx, return werr; } +/**************************************************************** +****************************************************************/ + static WERROR libnetapi_NetServerSetInfo(struct libnetapi_ctx *ctx, const char *server_name, uint32_t level, @@ -284,6 +308,9 @@ static WERROR libnetapi_NetServerSetInfo(struct libnetapi_ctx *ctx, parm_error); } +/**************************************************************** + NetServerSetInfo +****************************************************************/ NET_API_STATUS NetServerSetInfo(const char *server_name, uint32_t level, @@ -308,5 +335,5 @@ NET_API_STATUS NetServerSetInfo(const char *server_name, return W_ERROR_V(werr); } - return 0; + return NET_API_STATUS_SUCCESS; } -- cgit From b18fd380bd142933b7c1a341629aac61c8799d22 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 18 Jan 2008 02:50:33 +0100 Subject: Add NetGetJoinableOUs() to libnetapi (incl. example). Guenther (This used to be commit 8858e403e1940c362d307b4d4125f977abb0b96a) --- source3/lib/netapi/examples/Makefile.in | 16 +- .../examples/getjoinableous/getjoinableous.c | 104 +++++++++++ source3/lib/netapi/joindomain.c | 192 +++++++++++++++++++++ 3 files changed, 309 insertions(+), 3 deletions(-) create mode 100644 source3/lib/netapi/examples/getjoinableous/getjoinableous.c (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/Makefile.in b/source3/lib/netapi/examples/Makefile.in index c2f453dedc..86e1b1bc2f 100644 --- a/source3/lib/netapi/examples/Makefile.in +++ b/source3/lib/netapi/examples/Makefile.in @@ -5,7 +5,7 @@ KRB5LIBS=@KRB5_LIBS@ LDAP_LIBS=@LDAP_LIBS@ LIBS=@LIBS@ -lnetapi DEVELOPER_CFLAGS=@DEVELOPER_CFLAGS@ -FLAGS=@CFLAGS@ $(GTK_FLAGS) +FLAGS=-I../ -L../../../bin @CFLAGS@ $(GTK_FLAGS) CC=@CC@ LDFLAGS=@PIE_LDFLAGS@ @LDFLAGS@ DYNEXP=@DYNEXP@ @@ -36,8 +36,12 @@ MAKEDIR = || exec false; \ GETDC_OBJ = getdc/getdc.o NETDOMJOIN_OBJ = netdomjoin/netdomjoin.o NETDOMJOIN_GUI_OBJ = netdomjoin-gui/netdomjoin-gui.o +GETJOINABLEOUS_OBJ = getjoinableous/getjoinableous.o -PROGS = bin/getdc@EXEEXT@ bin/netdomjoin@EXEEXT@ bin/netdomjoin-gui@EXEEXT@ +PROGS = bin/getdc@EXEEXT@ \ + bin/netdomjoin@EXEEXT@ \ + bin/netdomjoin-gui@EXEEXT@ \ + bin/getjoinableous@EXEEXT@ all: $(PROGS) @@ -45,6 +49,10 @@ bin/getdc@EXEEXT@: $(GETDC_OBJ) @echo Linking $@ @$(CC) $(FLAGS) -o $@ $(GETDC_OBJ) $(LDFLAGS) $(DYNEXP) $(LIBS) $(KRB5LIBS) $(LDAP_LIBS) +bin/getjoinableous@EXEEXT@: $(GETJOINABLEOUS_OBJ) + @echo Linking $@ + @$(CC) $(FLAGS) -o $@ $(GETJOINABLEOUS_OBJ) $(LDFLAGS) $(DYNEXP) $(LIBS) $(KRB5LIBS) $(LDAP_LIBS) + bin/netdomjoin@EXEEXT@: $(NETDOMJOIN_OBJ) @echo Linking $@ @$(CC) $(FLAGS) -o $@ $(NETDOMJOIN_OBJ) $(LDFLAGS) $(DYNEXP) $(LIBS) $(KRB5LIBS) $(LDAP_LIBS) @@ -54,4 +62,6 @@ bin/netdomjoin-gui@EXEEXT@: $(NETDOMJOIN_GUI_OBJ) @$(CC) $(FLAGS) $(GTK_FLAGS) -o $@ $(NETDOMJOIN_GUI_OBJ) $(LDFLAGS) $(DYNEXP) $(LIBS) $(KRB5LIBS) $(LDAP_LIBS) $(GTK_LIBS) clean: - @rm -f $(PROGS) + -rm -f $(PROGS) + -rm -f core */*~ *~ \ + */*.o */*/*.o */*/*/*.o \ diff --git a/source3/lib/netapi/examples/getjoinableous/getjoinableous.c b/source3/lib/netapi/examples/getjoinableous/getjoinableous.c new file mode 100644 index 0000000000..5a3366c9dc --- /dev/null +++ b/source3/lib/netapi/examples/getjoinableous/getjoinableous.c @@ -0,0 +1,104 @@ +/* + * Unix SMB/CIFS implementation. + * Join Support (cmdline + netapi) + * Copyright (C) Guenther Deschner 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include +#include + +#include + +char *get_string_param(const char *param) +{ + char *p; + + p = strchr(param, '='); + if (!p) { + return NULL; + } + + return (p+1); +} + +int main(int argc, char **argv) +{ + NET_API_STATUS status; + const char *server_name = NULL; + const char *domain_name = NULL; + const char *account = NULL; + const char *password = NULL; + const char **ous = NULL; + uint32_t num_ous = 0; + struct libnetapi_ctx *ctx = NULL; + int i; + + status = libnetapi_init(&ctx); + if (status != 0) { + return status; + } + + if (argc < 2) { + printf("usage: getjoinableous\n"); + printf("\t [domain=DOMAIN] \n"); + return 0; + } + + if (argc > 2) { + server_name = argv[1]; + } + + for (i=0; idomain_controller_name); + if (!ads) { + return WERR_GENERAL_FAILURE; + } + + SAFE_FREE(ads->auth.user_name); + if (account) { + ads->auth.user_name = SMB_STRDUP(account); + } else if (ctx->username) { + ads->auth.user_name = SMB_STRDUP(ctx->username); + } + + SAFE_FREE(ads->auth.password); + if (password) { + ads->auth.password = SMB_STRDUP(password); + } else if (ctx->password) { + ads->auth.password = SMB_STRDUP(ctx->password); + } + + ads_status = ads_connect(ads); + if (!ADS_ERR_OK(ads_status)) { + ads_destroy(&ads); + return WERR_DEFAULT_JOIN_REQUIRED; + } + + ads_status = ads_get_joinable_ous(ads, ctx, + (char ***)ous, + (size_t *)ou_count); + if (!ADS_ERR_OK(ads_status)) { + ads_destroy(&ads); + return WERR_DEFAULT_JOIN_REQUIRED; + } + + ads_destroy(&ads); + return WERR_OK; +} + +/**************************************************************** +****************************************************************/ + +static WERROR NetGetJoinableOUsRemote(struct libnetapi_ctx *ctx, + const char *server_name, + const char *domain, + const char *account, + const char *password, + uint32_t *ou_count, + const char ***ous) +{ + struct cli_state *cli = NULL; + struct rpc_pipe_client *pipe_cli = NULL; + struct wkssvc_PasswordBuffer *encrypted_password = NULL; + NTSTATUS status; + WERROR werr; + + status = cli_full_connection(&cli, NULL, server_name, + NULL, 0, + "IPC$", "IPC", + ctx->username, + ctx->workgroup, + ctx->password, + 0, Undefined, NULL); + + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + 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, + password, + &cli->user_session_key, + &encrypted_password); + } + + status = rpccli_wkssvc_NetrGetJoinableOus2(pipe_cli, ctx, + server_name, + domain, + account, + encrypted_password, + ou_count, + ous, + &werr); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + done: + if (cli) { + cli_shutdown(cli); + } + + return werr; +} + +/**************************************************************** +****************************************************************/ + +static WERROR libnetapi_NetGetJoinableOUs(struct libnetapi_ctx *ctx, + const char *server_name, + const char *domain, + const char *account, + const char *password, + uint32_t *ou_count, + const char ***ous) +{ + if (!server_name || is_myname_or_ipaddr(server_name)) { + return NetGetJoinableOUsLocal(ctx, + server_name, + domain, + account, + password, + ou_count, + ous); + } + + return NetGetJoinableOUsRemote(ctx, + server_name, + domain, + account, + password, + ou_count, + ous); +} + +/**************************************************************** + NetGetJoinableOUs +****************************************************************/ + +NET_API_STATUS NetGetJoinableOUs(const char *server_name, + const char *domain, + const char *account, + const char *password, + uint32_t *ou_count, + const char ***ous) +{ + struct libnetapi_ctx *ctx = NULL; + NET_API_STATUS status; + WERROR werr; + + status = libnetapi_getctx(&ctx); + if (status != 0) { + return status; + } + + werr = libnetapi_NetGetJoinableOUs(ctx, + server_name, + domain, + account, + password, + ou_count, + ous); + if (!W_ERROR_IS_OK(werr)) { + return W_ERROR_V(werr); + } + + return NET_API_STATUS_SUCCESS; +} -- cgit From 9dd8940e5f4d89da67b66fb1932a95cc6fda63a5 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 18 Jan 2008 03:14:08 +0100 Subject: Add header for NetGetJoinableOUs to libnetapi. Guenther (This used to be commit f297ea259d58f7a12924b7111ab79818188cff46) --- source3/lib/netapi/netapi.h | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h index 67bb8a8fca..c2f1b488db 100644 --- a/source3/lib/netapi/netapi.h +++ b/source3/lib/netapi/netapi.h @@ -95,6 +95,17 @@ NET_API_STATUS NetGetJoinInformation(const char *server_name, const char **name_buffer, uint16_t *name_type); +/**************************************************************** + NetGetJoinableOUs +****************************************************************/ + +NET_API_STATUS NetGetJoinableOUs(const char *server_name, + const char *domain, + const char *account, + const char *password, + uint32_t *ou_count, + const char ***ous); + /**************************************************************** NetServerGetInfo ****************************************************************/ -- cgit From db40120c73f4d4cbb132f94cd3c5859fbdad0f5a Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 18 Jan 2008 08:48:44 +0100 Subject: Fix the build w/o ADS. Guenther (This used to be commit 645f2376d40fabdc787902ac7506ad7234616619) --- source3/lib/netapi/joindomain.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/joindomain.c b/source3/lib/netapi/joindomain.c index cbfc6c01e3..133aff3dd8 100644 --- a/source3/lib/netapi/joindomain.c +++ b/source3/lib/netapi/joindomain.c @@ -558,6 +558,7 @@ static WERROR NetGetJoinableOUsLocal(struct libnetapi_ctx *ctx, uint32_t *ou_count, const char ***ous) { +#ifdef WITH_ADS NTSTATUS status; ADS_STATUS ads_status; ADS_STRUCT *ads = NULL; @@ -608,6 +609,9 @@ static WERROR NetGetJoinableOUsLocal(struct libnetapi_ctx *ctx, ads_destroy(&ads); return WERR_OK; +#else + return WERR_NOT_SUPPORTED; +#endif } /**************************************************************** -- cgit From a30361ede36af7ef9d8f6d723798a07b360c813b Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 25 Jan 2008 15:45:38 +0100 Subject: No need to close registry on libnetapi_free() anymore. Guenther (This used to be commit 6bf75652ef07f5a534cef5034b7aad4fdcbcd265) --- source3/lib/netapi/netapi.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi.c b/source3/lib/netapi/netapi.c index 5c3f7ec465..47b3ba93cf 100644 --- a/source3/lib/netapi/netapi.c +++ b/source3/lib/netapi/netapi.c @@ -119,7 +119,6 @@ NET_API_STATUS libnetapi_free(struct libnetapi_ctx *ctx) gencache_shutdown(); secrets_shutdown(); - regdb_close(); TALLOC_FREE(ctx); TALLOC_FREE(frame); -- cgit From c04b738a136485a8f1df21fbccd1c418ee6fd444 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 25 Jan 2008 15:46:11 +0100 Subject: Add LIBNETAPI_LOCAL_SERVER() macro. Guenther (This used to be commit 4bdcf07bcc3aaf7c3f7245cfdda06433bcf4ae60) --- source3/lib/netapi/netapi.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h index c2f1b488db..002fc37762 100644 --- a/source3/lib/netapi/netapi.h +++ b/source3/lib/netapi/netapi.h @@ -36,6 +36,11 @@ /**************************************************************** ****************************************************************/ +#define LIBNETAPI_LOCAL_SERVER(x) (!x || is_myname_or_ipaddr(x)) + +/**************************************************************** +****************************************************************/ + struct libnetapi_ctx { char *debuglevel; char *error_string; -- cgit From 5ab43ae0d8e66a1fd4c877089df52282367be7dd Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Sat, 26 Jan 2008 01:39:33 +0100 Subject: Eliminate remote tree of dsgetdcname (which will happen in libnetapi then). Guenther (This used to be commit fd490d236b1fb73a75c457b75128c9b98719418f) --- source3/lib/netapi/joindomain.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/joindomain.c b/source3/lib/netapi/joindomain.c index 133aff3dd8..55f334b5e1 100644 --- a/source3/lib/netapi/joindomain.c +++ b/source3/lib/netapi/joindomain.c @@ -52,7 +52,7 @@ static WERROR NetJoinDomainLocal(struct libnetapi_ctx *mem_ctx, 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, domain_name, NULL, NULL, flags, &info); if (!NT_STATUS_IS_OK(status)) { libnetapi_set_error_string(mem_ctx, @@ -261,7 +261,7 @@ static WERROR NetUnjoinDomainLocal(struct libnetapi_ctx *mem_ctx, } else { domain = lp_workgroup(); } - status = dsgetdcname(mem_ctx, NULL, domain, + status = dsgetdcname(mem_ctx, domain, NULL, NULL, flags, &info); if (!NT_STATUS_IS_OK(status)) { libnetapi_set_error_string(mem_ctx, @@ -566,7 +566,7 @@ static WERROR NetGetJoinableOUsLocal(struct libnetapi_ctx *ctx, uint32_t flags = DS_DIRECTORY_SERVICE_REQUIRED | DS_RETURN_DNS_NAME; - status = dsgetdcname(ctx, NULL, domain, + status = dsgetdcname(ctx, domain, NULL, NULL, flags, &info); if (!NT_STATUS_IS_OK(status)) { libnetapi_set_error_string(ctx, "%s", -- cgit From 2e0a1fcf3f461f134c910e83ab82115c00827231 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 31 Jan 2008 14:10:22 +0100 Subject: Re-run make idl. Guenther (This used to be commit b658270518140c457536b0c7db06a646d7077529) --- source3/lib/netapi/getdc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/getdc.c b/source3/lib/netapi/getdc.c index 1084ddc3c8..2626eb0af4 100644 --- a/source3/lib/netapi/getdc.c +++ b/source3/lib/netapi/getdc.c @@ -69,8 +69,8 @@ static WERROR NetGetDCNameRemote(struct libnetapi_ctx *ctx, status = rpccli_netr_GetDcName(pipe_cli, ctx, server_name, domain_name, - (const char **)buffer); - werr = ntstatus_to_werror(status); + (const char **)buffer, + &werr); done: if (cli) { cli_shutdown(cli); -- cgit From 0d8985f2da43d35d8f940af112ad74a199778dd8 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 28 Feb 2008 12:30:18 +0100 Subject: Let dsgetdcname() return a struct netr_DsRGetDCNameInfo. Guenther (This used to be commit b1a4b21f8c35dc23e5c986ebe44d3806055eb39b) --- source3/lib/netapi/joindomain.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/joindomain.c b/source3/lib/netapi/joindomain.c index 55f334b5e1..405f96a87e 100644 --- a/source3/lib/netapi/joindomain.c +++ b/source3/lib/netapi/joindomain.c @@ -48,7 +48,7 @@ static WERROR NetJoinDomainLocal(struct libnetapi_ctx *mem_ctx, if (join_flags & WKSSVC_JOIN_FLAGS_JOIN_TYPE) { NTSTATUS status; - struct DS_DOMAIN_CONTROLLER_INFO *info = NULL; + struct netr_DsRGetDCNameInfo *info = NULL; uint32_t flags = DS_DIRECTORY_SERVICE_REQUIRED | DS_WRITABLE_REQUIRED | DS_RETURN_DNS_NAME; @@ -60,7 +60,7 @@ static WERROR NetJoinDomainLocal(struct libnetapi_ctx *mem_ctx, return ntstatus_to_werror(status); } r->in.dc_name = talloc_strdup(mem_ctx, - info->domain_controller_name); + info->dc_unc); W_ERROR_HAVE_NO_MEMORY(r->in.dc_name); } @@ -252,7 +252,7 @@ static WERROR NetUnjoinDomainLocal(struct libnetapi_ctx *mem_ctx, } else { NTSTATUS status; const char *domain = NULL; - struct DS_DOMAIN_CONTROLLER_INFO *info = NULL; + struct netr_DsRGetDCNameInfo *info = NULL; uint32_t flags = DS_DIRECTORY_SERVICE_REQUIRED | DS_WRITABLE_REQUIRED | DS_RETURN_DNS_NAME; @@ -269,7 +269,7 @@ static WERROR NetUnjoinDomainLocal(struct libnetapi_ctx *mem_ctx, return ntstatus_to_werror(status); } r->in.dc_name = talloc_strdup(mem_ctx, - info->domain_controller_name); + info->dc_unc); W_ERROR_HAVE_NO_MEMORY(r->in.dc_name); } @@ -562,7 +562,7 @@ static WERROR NetGetJoinableOUsLocal(struct libnetapi_ctx *ctx, NTSTATUS status; ADS_STATUS ads_status; ADS_STRUCT *ads = NULL; - struct DS_DOMAIN_CONTROLLER_INFO *info = NULL; + struct netr_DsRGetDCNameInfo *info = NULL; uint32_t flags = DS_DIRECTORY_SERVICE_REQUIRED | DS_RETURN_DNS_NAME; @@ -574,7 +574,7 @@ static WERROR NetGetJoinableOUsLocal(struct libnetapi_ctx *ctx, return ntstatus_to_werror(status); } - ads = ads_init(domain, domain, info->domain_controller_name); + ads = ads_init(domain, domain, info->dc_unc); if (!ads) { return WERR_GENERAL_FAILURE; } -- cgit From 77a25318105d90ae34a05c8a1e71df84343bb28e Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 28 Feb 2008 17:09:47 +0100 Subject: Only set DEBUGLEVEL to 0 in libnetapi when not set already. Guenther (This used to be commit 3ace1601ac5b5d87d6bfd8aa0afe0c75858b6990) --- source3/lib/netapi/netapi.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi.c b/source3/lib/netapi/netapi.c index 47b3ba93cf..fb091f6e0b 100644 --- a/source3/lib/netapi/netapi.c +++ b/source3/lib/netapi/netapi.c @@ -50,7 +50,9 @@ NET_API_STATUS libnetapi_init(struct libnetapi_ctx **context) return W_ERROR_V(WERR_NOMEM); } - DEBUGLEVEL = 0; + if (!DEBUGLEVEL) { + DEBUGLEVEL = 0; + } setup_logging("libnetapi", true); dbf = x_stderr; -- cgit From 808348a8ca1499f74343808b043983cb6fd5d06d Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 29 Feb 2008 02:49:27 +0100 Subject: Trying to fix libnetapi examples Makefile.in. Guenther (This used to be commit 405ef74d7e9ef614ea39b7cfd1d57307d9490545) --- source3/lib/netapi/examples/Makefile.in | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/Makefile.in b/source3/lib/netapi/examples/Makefile.in index 86e1b1bc2f..6de3e65546 100644 --- a/source3/lib/netapi/examples/Makefile.in +++ b/source3/lib/netapi/examples/Makefile.in @@ -3,7 +3,7 @@ GTK_LIBS=`pkg-config gtk+-2.0 --libs` KRB5LIBS=@KRB5_LIBS@ LDAP_LIBS=@LDAP_LIBS@ -LIBS=@LIBS@ -lnetapi +LIBS=@LIBS@ -lnetapi -ltdb -ltalloc DEVELOPER_CFLAGS=@DEVELOPER_CFLAGS@ FLAGS=-I../ -L../../../bin @CFLAGS@ $(GTK_FLAGS) CC=@CC@ @@ -14,7 +14,12 @@ DYNEXP=@DYNEXP@ COMPILE_CC = $(CC) -I. $(FLAGS) $(PICFLAG) -c $< -o $@ COMPILE = $(COMPILE_CC) -BINARY_PREREQS = proto_exists bin/.dummy +PROGS = bin/getdc@EXEEXT@ \ + bin/netdomjoin@EXEEXT@ \ + bin/netdomjoin-gui@EXEEXT@ \ + bin/getjoinableous@EXEEXT@ + +all: $(PROGS) MAKEDIR = || exec false; \ if test -d "$$dir"; then :; else \ @@ -24,6 +29,13 @@ MAKEDIR = || exec false; \ mkdir "$$dir" || \ exec false; fi || exec false +BINARY_PREREQS = bin/.dummy + +bin/.dummy: + @if (: >> $@ || : > $@) >/dev/null 2>&1; then :; else \ + dir=bin $(MAKEDIR); fi + @: >> $@ || : > $@ # what a fancy emoticon! + .c.o: @if (: >> $@ || : > $@) >/dev/null 2>&1; then rm -f $@; else \ dir=`echo $@ | sed 's,/[^/]*$$,,;s,^$$,.,'` $(MAKEDIR); fi @@ -38,30 +50,23 @@ NETDOMJOIN_OBJ = netdomjoin/netdomjoin.o NETDOMJOIN_GUI_OBJ = netdomjoin-gui/netdomjoin-gui.o GETJOINABLEOUS_OBJ = getjoinableous/getjoinableous.o -PROGS = bin/getdc@EXEEXT@ \ - bin/netdomjoin@EXEEXT@ \ - bin/netdomjoin-gui@EXEEXT@ \ - bin/getjoinableous@EXEEXT@ - -all: $(PROGS) - -bin/getdc@EXEEXT@: $(GETDC_OBJ) +bin/getdc@EXEEXT@: $(BINARY_PREREQS) $(GETDC_OBJ) @echo Linking $@ @$(CC) $(FLAGS) -o $@ $(GETDC_OBJ) $(LDFLAGS) $(DYNEXP) $(LIBS) $(KRB5LIBS) $(LDAP_LIBS) -bin/getjoinableous@EXEEXT@: $(GETJOINABLEOUS_OBJ) +bin/getjoinableous@EXEEXT@: $(BINARY_PREREQS) $(GETJOINABLEOUS_OBJ) @echo Linking $@ @$(CC) $(FLAGS) -o $@ $(GETJOINABLEOUS_OBJ) $(LDFLAGS) $(DYNEXP) $(LIBS) $(KRB5LIBS) $(LDAP_LIBS) -bin/netdomjoin@EXEEXT@: $(NETDOMJOIN_OBJ) +bin/netdomjoin@EXEEXT@: $(BINARY_PREREQS) $(NETDOMJOIN_OBJ) @echo Linking $@ @$(CC) $(FLAGS) -o $@ $(NETDOMJOIN_OBJ) $(LDFLAGS) $(DYNEXP) $(LIBS) $(KRB5LIBS) $(LDAP_LIBS) -bin/netdomjoin-gui@EXEEXT@: $(NETDOMJOIN_GUI_OBJ) +bin/netdomjoin-gui@EXEEXT@: $(BINARY_PREREQS) $(NETDOMJOIN_GUI_OBJ) @echo Linking $@ @$(CC) $(FLAGS) $(GTK_FLAGS) -o $@ $(NETDOMJOIN_GUI_OBJ) $(LDFLAGS) $(DYNEXP) $(LIBS) $(KRB5LIBS) $(LDAP_LIBS) $(GTK_LIBS) clean: -rm -f $(PROGS) -rm -f core */*~ *~ \ - */*.o */*/*.o */*/*/*.o \ + */*.o */*/*.o */*/*/*.o -- cgit From d1ef6699c0f9648dd76ac5230694e03a574cd48d Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 5 Mar 2008 09:53:33 +0100 Subject: Fix rpccli_srvsvc_NetSrvSetInfo call in libnetapi. Guenther (This used to be commit 5911529205ca69c438e0782c07ee4fe5aa95de62) --- source3/lib/netapi/serverinfo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/serverinfo.c b/source3/lib/netapi/serverinfo.c index 7fa166e411..54512950bf 100644 --- a/source3/lib/netapi/serverinfo.c +++ b/source3/lib/netapi/serverinfo.c @@ -268,7 +268,7 @@ static WERROR NetServerSetInfoRemote(struct libnetapi_ctx *ctx, status = rpccli_srvsvc_NetSrvSetInfo(pipe_cli, ctx, server_name, level, - info, + &info, parm_error, &werr); if (!NT_STATUS_IS_OK(status)) { -- cgit From 2223292338111e0c97419cc643aa45e05d3c7aa8 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 5 Mar 2008 13:20:32 +0100 Subject: Add PICFLAG to libnetapi Makefile. Guenther (This used to be commit 29fca3c0353f2be4577613d7e38fbc51d2a370fa) --- source3/lib/netapi/examples/Makefile.in | 1 + 1 file changed, 1 insertion(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/Makefile.in b/source3/lib/netapi/examples/Makefile.in index 6de3e65546..000eef118b 100644 --- a/source3/lib/netapi/examples/Makefile.in +++ b/source3/lib/netapi/examples/Makefile.in @@ -7,6 +7,7 @@ LIBS=@LIBS@ -lnetapi -ltdb -ltalloc DEVELOPER_CFLAGS=@DEVELOPER_CFLAGS@ FLAGS=-I../ -L../../../bin @CFLAGS@ $(GTK_FLAGS) CC=@CC@ +PICFLAG=@PICFLAG@ LDFLAGS=@PIE_LDFLAGS@ @LDFLAGS@ DYNEXP=@DYNEXP@ -- cgit From 65b0235ee394f90e7a4938cfa5bc5d2d951e9d82 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 5 Mar 2008 15:21:43 +0100 Subject: Give a better error message why NetServerSetInfo() may fail in the gui. Guenther (This used to be commit 1bbbebb7767b8a25532e8be3dbd274c211e34bbd) --- source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c | 2 +- source3/lib/netapi/serverinfo.c | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c index 73b14d4d87..a3719c7442 100644 --- a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c +++ b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c @@ -154,7 +154,7 @@ static void callback_apply_description_change(GtkWidget *widget, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "Failed to change computer description: %s.", - libnetapi_errstr(status)); + libnetapi_get_error_string(state->ctx, status)); g_signal_connect_swapped(dialog, "response", G_CALLBACK(gtk_widget_destroy), dialog); diff --git a/source3/lib/netapi/serverinfo.c b/source3/lib/netapi/serverinfo.c index 54512950bf..d30e7d97f7 100644 --- a/source3/lib/netapi/serverinfo.c +++ b/source3/lib/netapi/serverinfo.c @@ -185,6 +185,9 @@ static WERROR NetServerSetInfoLocal_1005(struct libnetapi_ctx *ctx, } if (!lp_config_backend_is_registry()) { + libnetapi_set_error_string(ctx, + "Configuration manipulation requested but not " + "supported by backend"); return WERR_NOT_SUPPORTED; } -- cgit From fee1ab104947ced6929d75c907a111790903fb17 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 6 Mar 2008 00:45:20 +0100 Subject: In libnetapi, point out that lp_load has failed. Guenther (This used to be commit be673bfc61559f661040c6fb1ba7d2e4552967f2) --- source3/lib/netapi/netapi.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi.c b/source3/lib/netapi/netapi.c index fb091f6e0b..82a8a8d3cd 100644 --- a/source3/lib/netapi/netapi.c +++ b/source3/lib/netapi/netapi.c @@ -63,6 +63,7 @@ NET_API_STATUS libnetapi_init(struct libnetapi_ctx **context) if (!lp_load(get_dyn_CONFIGFILE(), true, false, false, false)) { TALLOC_FREE(frame); + fprintf(stderr, "lp_load failed\n"); return W_ERROR_V(WERR_GENERAL_FAILURE); } -- cgit From 5259a7a808324e7896943d22723b65bb57cfdf60 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 7 Mar 2008 18:18:35 +0100 Subject: Enable libnetjoin debugging for now but avoid printing passwords. The gen_ndr needs proper fixing still. Guenther (This used to be commit 966d7244d7765d285a7026b97e6093fd1f8d83ce) --- source3/lib/netapi/joindomain.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/joindomain.c b/source3/lib/netapi/joindomain.c index 405f96a87e..9c0e8aaaf8 100644 --- a/source3/lib/netapi/joindomain.c +++ b/source3/lib/netapi/joindomain.c @@ -81,6 +81,7 @@ static WERROR NetJoinDomainLocal(struct libnetapi_ctx *mem_ctx, r->in.join_flags = join_flags; r->in.modify_config = true; + r->in.debug = true; werr = libnet_Join(mem_ctx, r); if (!W_ERROR_IS_OK(werr) && r->out.error_string) { -- cgit From 6274929b1e1ddf89f4c5e93414121eaf06b6ab14 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Mon, 17 Mar 2008 18:01:33 +0100 Subject: libsmbconf: rename all occurrences of libnet_conf_ to smbconf_ . Michael (This used to be commit 097af0309d7c3e9342058ba5266667293b23c80d) --- source3/lib/netapi/serverinfo.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/serverinfo.c b/source3/lib/netapi/serverinfo.c index d30e7d97f7..a29a840da0 100644 --- a/source3/lib/netapi/serverinfo.c +++ b/source3/lib/netapi/serverinfo.c @@ -169,7 +169,7 @@ static WERROR NetServerSetInfoLocal_1005(struct libnetapi_ctx *ctx, uint32_t *parm_error) { WERROR werr; - struct libnet_conf_ctx *conf_ctx; + struct smbconf_ctx *conf_ctx; struct srvsvc_NetSrvInfo1005 *info1005; if (!buffer) { @@ -191,17 +191,16 @@ static WERROR NetServerSetInfoLocal_1005(struct libnetapi_ctx *ctx, return WERR_NOT_SUPPORTED; } - werr = libnet_conf_open(ctx, &conf_ctx); + werr = smbconf_open(ctx, &conf_ctx); if (!W_ERROR_IS_OK(werr)) { goto done; } - werr = libnet_conf_set_global_parameter(conf_ctx, - "server string", - info1005->comment); + werr = smbconf_set_global_parameter(conf_ctx, "server string", + info1005->comment); done: - libnet_conf_close(conf_ctx); + smbconf_close(conf_ctx); return werr; } -- cgit From adf5bf554cd6bfdc5c6e7b1ed54f7f9329b15c50 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Thu, 20 Mar 2008 23:41:39 +0100 Subject: libsmbconf: rename smbconf_open() to smbconf_init(). That's more appropriate. Michael (This used to be commit d7bd9bb8aa2003ec0a9860df26857f67255febe2) --- source3/lib/netapi/serverinfo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/serverinfo.c b/source3/lib/netapi/serverinfo.c index a29a840da0..c5b0c2f709 100644 --- a/source3/lib/netapi/serverinfo.c +++ b/source3/lib/netapi/serverinfo.c @@ -191,7 +191,7 @@ static WERROR NetServerSetInfoLocal_1005(struct libnetapi_ctx *ctx, return WERR_NOT_SUPPORTED; } - werr = smbconf_open(ctx, &conf_ctx); + werr = smbconf_init(ctx, &conf_ctx); if (!W_ERROR_IS_OK(werr)) { goto done; } -- cgit From 23b1d721b8262f69cb7e28348c8e5cdf3483d4ea Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Fri, 21 Mar 2008 01:04:57 +0100 Subject: libsmbconf: rename smbconf_close() to smbconf_shutdown(). Michael (This used to be commit 797b26ad3fad27e085827efb61f6b4d8b37e93f0) --- source3/lib/netapi/serverinfo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/serverinfo.c b/source3/lib/netapi/serverinfo.c index c5b0c2f709..ffc5f6fd3e 100644 --- a/source3/lib/netapi/serverinfo.c +++ b/source3/lib/netapi/serverinfo.c @@ -200,7 +200,7 @@ static WERROR NetServerSetInfoLocal_1005(struct libnetapi_ctx *ctx, info1005->comment); done: - smbconf_close(conf_ctx); + smbconf_shutdown(conf_ctx); return werr; } -- cgit From fececde1815bf0469bb56e07cf23f54011c9b4ae Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Fri, 21 Mar 2008 02:20:16 +0100 Subject: libsmbconf: add backend specific init function. Hide generic init function taking smbconf_ops argument from public api. Michael (This used to be commit b3f6920ccb9a27fde26e889a7f1f3afaf56b784f) --- source3/lib/netapi/serverinfo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/serverinfo.c b/source3/lib/netapi/serverinfo.c index ffc5f6fd3e..913338fd49 100644 --- a/source3/lib/netapi/serverinfo.c +++ b/source3/lib/netapi/serverinfo.c @@ -191,7 +191,7 @@ static WERROR NetServerSetInfoLocal_1005(struct libnetapi_ctx *ctx, return WERR_NOT_SUPPORTED; } - werr = smbconf_init(ctx, &conf_ctx); + werr = smbconf_init_reg(ctx, &conf_ctx); if (!W_ERROR_IS_OK(werr)) { goto done; } -- cgit From 6f7cfeddd61f728e2452a7b89f5ee2ff36ca394f Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Fri, 21 Mar 2008 17:55:31 +0100 Subject: libsmbconf: add a "path" variable to the conf context. This is passed to the module init routines. In case of the registry, this is the path of the basekey in registry, that is to be used, defaulting to KEY_SMBCONF (HKLM\software\samba\smbconf), when NULL is given. This is the only case currently used. In order to support other keys, registry initialization for smbconf has to be changed to support different keys. Michael (This used to be commit 96434d9dc7a66773e313cc128af57493dee245a1) --- source3/lib/netapi/serverinfo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/serverinfo.c b/source3/lib/netapi/serverinfo.c index 913338fd49..a9749a12f9 100644 --- a/source3/lib/netapi/serverinfo.c +++ b/source3/lib/netapi/serverinfo.c @@ -191,7 +191,7 @@ static WERROR NetServerSetInfoLocal_1005(struct libnetapi_ctx *ctx, return WERR_NOT_SUPPORTED; } - werr = smbconf_init_reg(ctx, &conf_ctx); + werr = smbconf_init_reg(ctx, &conf_ctx, NULL); if (!W_ERROR_IS_OK(werr)) { goto done; } -- cgit From 6c1c07bde3ce01bb6585216db6d4f13abd2a8ff2 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 2 Apr 2008 11:14:15 +0200 Subject: Make sure to hand down the domain name in libnetapi NetUnjoinDomain. Guenther (This used to be commit 0058ab30de943f134792e3d66051206086987110) --- source3/lib/netapi/joindomain.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/joindomain.c b/source3/lib/netapi/joindomain.c index 9c0e8aaaf8..ed8327ed68 100644 --- a/source3/lib/netapi/joindomain.c +++ b/source3/lib/netapi/joindomain.c @@ -238,6 +238,7 @@ static WERROR NetUnjoinDomainLocal(struct libnetapi_ctx *mem_ctx, { struct libnet_UnjoinCtx *r = NULL; struct dom_sid domain_sid; + const char *domain = NULL; WERROR werr; if (!secrets_fetch_domain_sid(lp_workgroup(), &domain_sid)) { @@ -247,26 +248,28 @@ static WERROR NetUnjoinDomainLocal(struct libnetapi_ctx *mem_ctx, werr = libnet_init_UnjoinCtx(mem_ctx, &r); W_ERROR_NOT_OK_RETURN(werr); + if (lp_realm()) { + domain = lp_realm(); + } else { + domain = lp_workgroup(); + } + if (server_name) { r->in.dc_name = talloc_strdup(mem_ctx, server_name); W_ERROR_HAVE_NO_MEMORY(r->in.dc_name); } else { NTSTATUS status; - const char *domain = NULL; struct netr_DsRGetDCNameInfo *info = NULL; uint32_t flags = DS_DIRECTORY_SERVICE_REQUIRED | DS_WRITABLE_REQUIRED | DS_RETURN_DNS_NAME; - if (lp_realm()) { - domain = lp_realm(); - } else { - domain = lp_workgroup(); - } status = dsgetdcname(mem_ctx, domain, NULL, NULL, flags, &info); if (!NT_STATUS_IS_OK(status)) { libnetapi_set_error_string(mem_ctx, - "%s", get_friendly_nt_error_msg(status)); + "failed to find DC for domain %s: %s", + domain, + get_friendly_nt_error_msg(status)); return ntstatus_to_werror(status); } r->in.dc_name = talloc_strdup(mem_ctx, @@ -284,6 +287,7 @@ static WERROR NetUnjoinDomainLocal(struct libnetapi_ctx *mem_ctx, W_ERROR_HAVE_NO_MEMORY(r->in.admin_password); } + r->in.domain_name = domain; r->in.unjoin_flags = unjoin_flags; r->in.modify_config = true; r->in.debug = true; -- cgit From 68bfa9682b0b9bf859e382d90688e48a8d6b8479 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 2 Apr 2008 11:18:10 +0200 Subject: Some fixes for netdomjoin-gui and support for browsing/joining OUs. Guenther (This used to be commit 4714bae0dbbb2ad010c2929f83de6bca84cfac46) --- .../examples/netdomjoin-gui/netdomjoin-gui.c | 547 +++++++++++++++------ 1 file changed, 390 insertions(+), 157 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c index a3719c7442..a4daf4fea7 100644 --- a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c +++ b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c @@ -63,14 +63,17 @@ typedef struct join_state { GtkWidget *entry_account; GtkWidget *entry_password; GtkWidget *entry_domain; + GtkWidget *entry_ou_list; GtkWidget *entry_workgroup; GtkWidget *button_ok; GtkWidget *button_apply; GtkWidget *button_ok_creds; + GtkWidget *button_get_ous; GtkWidget *label_reboot; GtkWidget *label_current_name_buffer; GtkWidget *label_current_name_type; GtkWidget *label_full_computer_name; + GtkWidget *label_winbind; uint16_t name_type_initial; uint16_t name_type_new; char *name_buffer_initial; @@ -111,10 +114,40 @@ static gboolean callback_delete_event(GtkWidget *widget, static void callback_do_close(GtkWidget *widget, gpointer data) { - debug("Closing now...\n"); + debug("callback_do_close called\n"); + gtk_widget_destroy(data); } +static void callback_do_freeauth(GtkWidget *widget, + gpointer data) +{ + struct join_state *state = (struct join_state *)data; + + debug("callback_do_freeauth called\n"); + + SAFE_FREE(state->account); + SAFE_FREE(state->password); + + if (state->window_creds_prompt) { + gtk_widget_destroy(state->window_creds_prompt); + } +} + +static void callback_do_freeauth_and_close(GtkWidget *widget, + gpointer data) +{ + struct join_state *state = (struct join_state *)data; + + debug("callback_do_freeauth_and_close called\n"); + + SAFE_FREE(state->account); + SAFE_FREE(state->password); + + gtk_widget_destroy(state->window_creds_prompt); + gtk_widget_destroy(state->window_do_change); +} + static void free_join_state(struct join_state *s) { SAFE_FREE(s->name_buffer_initial); @@ -155,6 +188,8 @@ static void callback_apply_description_change(GtkWidget *widget, GTK_BUTTONS_OK, "Failed to change computer description: %s.", libnetapi_get_error_string(state->ctx, status)); + gtk_window_set_modal(GTK_WINDOW(dialog), TRUE); + g_signal_connect_swapped(dialog, "response", G_CALLBACK(gtk_widget_destroy), dialog); @@ -183,6 +218,7 @@ static void callback_do_exit(GtkWidget *widget, GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO, "You must restart your computer before the new settings will take effect."); + gtk_window_set_modal(GTK_WINDOW(dialog), TRUE); result = gtk_dialog_run(GTK_DIALOG(dialog)); switch (result) { case GTK_RESPONSE_YES: @@ -214,6 +250,7 @@ static void callback_do_reboot(GtkWidget *widget, GTK_MESSAGE_INFO, GTK_BUTTONS_OK, "You must restart this computer for the changes to take effect."); + gtk_window_set_modal(GTK_WINDOW(dialog), TRUE); #if 0 g_signal_connect_swapped(dialog, "response", G_CALLBACK(gtk_widget_destroy), @@ -269,10 +306,14 @@ static void callback_return_username(GtkWidget *widget, { const gchar *entry_text; struct join_state *state = (struct join_state *)data; + debug("callback_return_username called\n"); if (!widget) { return; } entry_text = gtk_entry_get_text(GTK_ENTRY(widget)); + if (!entry_text) { + return; + } debug("callback_return_username: %s\n", entry_text); SAFE_FREE(state->account); state->account = strdup(entry_text); @@ -287,7 +328,10 @@ static void callback_return_username_and_enter(GtkWidget *widget, return; } entry_text = gtk_entry_get_text(GTK_ENTRY(widget)); - debug("callback_return_username: %s\n", entry_text); + if (!entry_text) { + return; + } + debug("callback_return_username_and_enter: %s\n", entry_text); SAFE_FREE(state->account); state->account = strdup(entry_text); g_signal_emit_by_name(state->button_ok_creds, "clicked"); @@ -298,10 +342,14 @@ static void callback_return_password(GtkWidget *widget, { const gchar *entry_text; struct join_state *state = (struct join_state *)data; + debug("callback_return_password called\n"); if (!widget) { return; } entry_text = gtk_entry_get_text(GTK_ENTRY(widget)); + if (!entry_text) { + return; + } #ifdef DEBUG_PASSWORD debug("callback_return_password: %s\n", entry_text); #else @@ -320,16 +368,59 @@ static void callback_return_password_and_enter(GtkWidget *widget, return; } entry_text = gtk_entry_get_text(GTK_ENTRY(widget)); + if (!entry_text) { + return; + } #ifdef DEBUG_PASSWORD - debug("callback_return_password: %s\n", entry_text); + debug("callback_return_password_and_enter: %s\n", entry_text); #else - debug("callback_return_password: (not printed)\n"); + debug("callback_return_password_and_enter: (not printed)\n"); #endif SAFE_FREE(state->password); state->password = strdup(entry_text); g_signal_emit_by_name(state->button_ok_creds, "clicked"); } +static void callback_do_storeauth(GtkWidget *widget, + gpointer data) +{ + struct join_state *state = (struct join_state *)data; + + debug("callback_do_storeauth called\n"); + + SAFE_FREE(state->account); + SAFE_FREE(state->password); + + callback_return_username(state->entry_account, state); + callback_return_password(state->entry_password, state); + + gtk_widget_destroy(state->window_creds_prompt); +} + +static void callback_continue(GtkWidget *widget, + gpointer data) +{ + struct join_state *state = (struct join_state *)data; + + gtk_widget_grab_focus(GTK_WIDGET(state->button_ok)); + g_signal_emit_by_name(state->button_ok, "clicked"); +} + +static void callback_do_storeauth_and_continue(GtkWidget *widget, + gpointer data) +{ + callback_do_storeauth(widget, data); + callback_continue(NULL, data); +} + +static void callback_do_storeauth_and_scan(GtkWidget *widget, + gpointer data) +{ + struct join_state *state = (struct join_state *)data; + callback_do_storeauth(widget, data); + g_signal_emit_by_name(state->button_get_ous, "clicked"); +} + static void callback_do_hostname_change(GtkWidget *widget, gpointer data) { @@ -355,12 +446,112 @@ static void callback_do_hostname_change(GtkWidget *widget, GTK_BUTTONS_CLOSE, str); + gtk_window_set_modal(GTK_WINDOW(dialog), TRUE); g_signal_connect_swapped(dialog, "response", G_CALLBACK(gtk_widget_destroy), dialog); gtk_widget_show(dialog); } +static void callback_creds_prompt(GtkWidget *widget, + gpointer data, + const char *label_string, + gpointer cont_fn) +{ + GtkWidget *window; + GtkWidget *box1; + GtkWidget *bbox; + GtkWidget *button; + GtkWidget *label; + + struct join_state *state = (struct join_state *)data; + + debug("callback_creds_prompt\n"); + + window = gtk_window_new(GTK_WINDOW_TOPLEVEL); + gtk_window_set_modal(GTK_WINDOW(window), TRUE); + + gtk_window_set_title(GTK_WINDOW(window), "Computer Name Changes"); + gtk_window_set_resizable(GTK_WINDOW(window), FALSE); + gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER); + gtk_widget_set_size_request(GTK_WIDGET(window), 380, 280); + gtk_window_set_icon_from_file(GTK_WINDOW(window), SAMBA_ICON_PATH, NULL); + + g_signal_connect(G_OBJECT(window), "delete_event", + G_CALLBACK(callback_do_close), window); + + state->window_creds_prompt = window; + gtk_container_set_border_width(GTK_CONTAINER(window), 10); + + box1 = gtk_vbox_new(FALSE, 0); + + gtk_container_add(GTK_CONTAINER(window), box1); + + label = gtk_label_new(label_string); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0); + gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); + + gtk_box_pack_start(GTK_BOX(box1), label, FALSE, FALSE, 0); + + gtk_widget_show(label); + + /* USER NAME */ + label = gtk_label_new("User name:"); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0); + gtk_box_pack_start(GTK_BOX(box1), label, FALSE, FALSE, 0); + gtk_widget_show(label); + + state->entry_account = gtk_entry_new(); + gtk_entry_set_max_length(GTK_ENTRY(state->entry_account), MAX_CRED_LEN); + g_signal_connect(G_OBJECT(state->entry_account), "activate", + G_CALLBACK(callback_return_username_and_enter), + (gpointer)state); + gtk_editable_select_region(GTK_EDITABLE(state->entry_account), + 0, GTK_ENTRY(state->entry_account)->text_length); + gtk_box_pack_start(GTK_BOX(box1), state->entry_account, TRUE, TRUE, 0); + gtk_widget_show(state->entry_account); + + /* PASSWORD */ + label = gtk_label_new("Password:"); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0); + gtk_box_pack_start(GTK_BOX(box1), label, FALSE, FALSE, 0); + gtk_widget_show(label); + + state->entry_password = gtk_entry_new(); + gtk_entry_set_max_length(GTK_ENTRY(state->entry_password), MAX_CRED_LEN); + gtk_entry_set_visibility(GTK_ENTRY(state->entry_password), FALSE); + g_signal_connect(G_OBJECT(state->entry_password), "activate", + G_CALLBACK(callback_return_password_and_enter), + (gpointer)state); + gtk_editable_set_editable(GTK_EDITABLE(state->entry_password), TRUE); + gtk_editable_select_region(GTK_EDITABLE(state->entry_password), + 0, GTK_ENTRY(state->entry_password)->text_length); + gtk_box_pack_start(GTK_BOX(box1), state->entry_password, TRUE, TRUE, 0); + gtk_widget_show(state->entry_password); + + /* BUTTONS */ + bbox = gtk_hbutton_box_new(); + gtk_container_set_border_width(GTK_CONTAINER(bbox), 5); + gtk_container_add(GTK_CONTAINER(box1), bbox); + gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); + gtk_box_set_spacing(GTK_BOX(bbox), 10); + + state->button_ok_creds = gtk_button_new_from_stock(GTK_STOCK_OK); + gtk_widget_grab_focus(GTK_WIDGET(state->button_ok_creds)); + gtk_container_add(GTK_CONTAINER(bbox), state->button_ok_creds); + g_signal_connect(G_OBJECT(state->button_ok_creds), "clicked", + G_CALLBACK(cont_fn), + (gpointer)state); + gtk_widget_show(state->button_ok_creds); + + button = gtk_button_new_from_stock(GTK_STOCK_CANCEL); + gtk_container_add(GTK_CONTAINER(bbox), button); + g_signal_connect(G_OBJECT(button), "clicked", + G_CALLBACK(callback_do_freeauth), + (gpointer)state); + gtk_widget_show_all(window); +} + static void callback_do_join(GtkWidget *widget, gpointer data) { @@ -372,16 +563,17 @@ static void callback_do_join(GtkWidget *widget, uint32_t unjoin_flags = 0; gboolean domain_join = FALSE; gboolean try_unjoin = FALSE; + gboolean join_creds_required = TRUE; + gboolean unjoin_creds_required = TRUE; const char *new_workgroup_type = NULL; const char *initial_workgroup_type = NULL; + const char *account_ou = NULL; struct join_state *state = (struct join_state *)data; - callback_return_username(state->entry_account, state); - callback_return_password(state->entry_password, state); - - if (state->window_creds_prompt) { - gtk_widget_destroy(GTK_WIDGET(state->window_creds_prompt)); + if (state->hostname_changed) { + callback_do_hostname_change(NULL, state); + return; } switch (state->name_type_initial) { @@ -406,8 +598,20 @@ static void callback_do_join(GtkWidget *widget, break; } + account_ou = gtk_combo_box_get_active_text(GTK_COMBO_BOX(state->entry_ou_list)); + if (account_ou && strlen(account_ou) == 0) { + account_ou = NULL; + } + + if ((state->name_type_initial != NetSetupDomainName) && + (state->name_type_new != NetSetupDomainName)) { + join_creds_required = FALSE; + unjoin_creds_required = FALSE; + } + if (state->name_type_new == NetSetupDomainName) { domain_join = TRUE; + join_creds_required = TRUE; join_flags = WKSSVC_JOIN_FLAGS_JOIN_TYPE | WKSSVC_JOIN_FLAGS_ACCOUNT_CREATE | WKSSVC_JOIN_FLAGS_DOMAIN_JOIN_IF_JOINED; /* for testing */ @@ -416,30 +620,36 @@ static void callback_do_join(GtkWidget *widget, if ((state->name_type_initial == NetSetupDomainName) && (state->name_type_new == NetSetupWorkgroupName)) { try_unjoin = TRUE; + unjoin_creds_required = TRUE; + join_creds_required = FALSE; unjoin_flags = WKSSVC_JOIN_FLAGS_JOIN_TYPE | WKSSVC_JOIN_FLAGS_ACCOUNT_DELETE; } - debug("callback_do_join: Joining a %s named %s using join_flags 0x%08x ", - new_workgroup_type, - state->name_buffer_new, - join_flags); - if (domain_join) { - debug("as %s ", state->account); -#ifdef DEBUG_PASSWORD - debug("with %s ", state->password); -#endif - } - debug("\n"); if (try_unjoin) { debug("callback_do_join: Unjoining\n"); + if (unjoin_creds_required) { + if (!state->account || !state->password) { + debug("callback_do_join: no creds yet\n"); + callback_creds_prompt(NULL, state, + "Enter the name and password of an account with permission to leave the domain.", + callback_do_storeauth_and_continue); + } + + if (!state->account || !state->password) { + debug("callback_do_join: still no creds???\n"); + return; + } + } + status = NetUnjoinDomain(NULL, state->account, state->password, unjoin_flags); if (status != 0) { + callback_do_freeauth(NULL, state); err_str = libnetapi_get_error_string(state->ctx, status); g_print("callback_do_join: failed to unjoin (%s)\n", err_str); @@ -452,18 +662,47 @@ static void callback_do_join(GtkWidget *widget, initial_workgroup_type, state->name_buffer_initial, err_str); + gtk_window_set_modal(GTK_WINDOW(dialog), TRUE); gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); } } + + if (join_creds_required) { + if (!state->account || !state->password) { + debug("callback_do_join: no creds yet\n"); + callback_creds_prompt(NULL, state, + "Enter the name and password of an account with permission to leave the domain.", + callback_do_storeauth_and_continue); + } + + if (!state->account || !state->password) { + debug("callback_do_join: still no creds???\n"); + return; + } + } + + debug("callback_do_join: Joining a %s named %s using join_flags 0x%08x ", + new_workgroup_type, + state->name_buffer_new, + join_flags); + if (domain_join) { + debug("as %s ", state->account); +#ifdef DEBUG_PASSWORD + debug("with %s ", state->password); +#endif + } + debug("\n"); + status = NetJoinDomain(NULL, state->name_buffer_new, - NULL, + account_ou, state->account, state->password, join_flags); if (status != 0) { + callback_do_freeauth(NULL, state); err_str = libnetapi_get_error_string(state->ctx, status); g_print("callback_do_join: failed to join (%s)\n", err_str); @@ -476,6 +715,7 @@ static void callback_do_join(GtkWidget *widget, state->name_buffer_new, err_str); + gtk_window_set_modal(GTK_WINDOW(dialog), TRUE); g_signal_connect_swapped(dialog, "response", G_CALLBACK(gtk_widget_destroy), dialog); @@ -488,6 +728,7 @@ static void callback_do_join(GtkWidget *widget, debug("callback_do_join: Successfully joined %s\n", new_workgroup_type); + callback_do_freeauth(NULL, state); dialog = gtk_message_dialog_new(GTK_WINDOW(state->window_parent), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_INFO, @@ -496,123 +737,13 @@ static void callback_do_join(GtkWidget *widget, state->name_buffer_new, new_workgroup_type); + gtk_window_set_modal(GTK_WINDOW(dialog), TRUE); gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); callback_do_reboot(NULL, state->window_parent, state); } -static void callback_creds_prompt(GtkWidget *widget, - gpointer data) -{ - GtkWidget *window; - GtkWidget *box1; - GtkWidget *bbox; - GtkWidget *button; - GtkWidget *label; - - struct join_state *state = (struct join_state *)data; - - debug("callback_creds_prompt:\n"); - - state->window_parent = state->window_do_change; - - if (state->hostname_changed) { - return callback_do_hostname_change(NULL, state); - } - - if ((state->name_type_initial != NetSetupDomainName) && - (state->name_type_new != NetSetupDomainName)) { - return callback_do_join(NULL, state); - } - - window = gtk_window_new(GTK_WINDOW_TOPLEVEL); - - gtk_window_set_title(GTK_WINDOW(window), "Computer Name Changes"); - gtk_window_set_resizable(GTK_WINDOW(window), FALSE); - gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER); - gtk_widget_set_size_request(GTK_WIDGET(window), 380, 280); - gtk_window_set_icon_from_file(GTK_WINDOW(window), SAMBA_ICON_PATH, NULL); -/* gtk_window_set_icon_name(GTK_WIDGET(window), GTK_STOCK_DIALOG_AUTHENTICATION); */ - state->window_creds_prompt = window; - - g_signal_connect(G_OBJECT(window), "delete_event", - G_CALLBACK(callback_do_close), window); - - gtk_container_set_border_width(GTK_CONTAINER(window), 10); - - box1 = gtk_vbox_new(FALSE, 0); - - gtk_container_add(GTK_CONTAINER(window), box1); - - if ((state->name_type_initial == NetSetupDomainName) && - (state->name_type_new == NetSetupWorkgroupName)) { - label = gtk_label_new("Enter the name and password of an account with permission to leave the domain.\n"); - } else { - label = gtk_label_new("Enter the name and password of an account with permission to join the domain.\n"); - } - gtk_misc_set_alignment(GTK_MISC(label), 0, 0); - gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); - - gtk_box_pack_start(GTK_BOX(box1), label, FALSE, FALSE, 0); - - gtk_widget_show(label); - - /* USER NAME */ - label = gtk_label_new("User name:"); - gtk_misc_set_alignment(GTK_MISC(label), 0, 0); - gtk_box_pack_start(GTK_BOX(box1), label, FALSE, FALSE, 0); - gtk_widget_show(label); - - state->entry_account = gtk_entry_new(); - gtk_entry_set_max_length(GTK_ENTRY(state->entry_account), MAX_CRED_LEN); - g_signal_connect(G_OBJECT(state->entry_account), "activate", - G_CALLBACK(callback_return_username_and_enter), - (gpointer)state); - gtk_editable_select_region(GTK_EDITABLE(state->entry_account), - 0, GTK_ENTRY(state->entry_account)->text_length); - gtk_box_pack_start(GTK_BOX(box1), state->entry_account, TRUE, TRUE, 0); - gtk_widget_show(state->entry_account); - - /* PASSWORD */ - label = gtk_label_new("Password:"); - gtk_misc_set_alignment(GTK_MISC(label), 0, 0); - gtk_box_pack_start(GTK_BOX(box1), label, FALSE, FALSE, 0); - gtk_widget_show(label); - - state->entry_password = gtk_entry_new(); - gtk_entry_set_max_length(GTK_ENTRY(state->entry_password), MAX_CRED_LEN); - gtk_entry_set_visibility(GTK_ENTRY(state->entry_password), FALSE); - g_signal_connect(G_OBJECT(state->entry_password), "activate", - G_CALLBACK(callback_return_password_and_enter), - (gpointer)state); - gtk_editable_set_editable(GTK_EDITABLE(state->entry_password), TRUE); - gtk_editable_select_region(GTK_EDITABLE(state->entry_password), - 0, GTK_ENTRY(state->entry_password)->text_length); - gtk_box_pack_start(GTK_BOX(box1), state->entry_password, TRUE, TRUE, 0); - gtk_widget_show(state->entry_password); - - bbox = gtk_hbutton_box_new(); - gtk_container_set_border_width(GTK_CONTAINER(bbox), 5); - gtk_container_add(GTK_CONTAINER(box1), bbox); - gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); - gtk_box_set_spacing(GTK_BOX(bbox), 10); - - state->button_ok_creds = gtk_button_new_from_stock(GTK_STOCK_OK); - gtk_widget_grab_focus(GTK_WIDGET(state->button_ok_creds)); - gtk_container_add(GTK_CONTAINER(bbox), state->button_ok_creds); - g_signal_connect(G_OBJECT(state->button_ok_creds), "clicked", - G_CALLBACK(callback_do_join), - (gpointer)state); - gtk_widget_show(state->button_ok_creds); - - button = gtk_button_new_from_stock(GTK_STOCK_CANCEL); - gtk_container_add(GTK_CONTAINER(bbox), button); - g_signal_connect(G_OBJECT(button), "clicked", - G_CALLBACK(callback_do_close), (gpointer) window); - gtk_widget_show_all(window); -} - static void callback_enter_hostname_and_unlock(GtkWidget *widget, gpointer data) { @@ -717,20 +848,13 @@ static void callback_enter_domain_and_unlock(GtkWidget *widget, return; } gtk_widget_set_sensitive(GTK_WIDGET(state->button_ok), TRUE); + gtk_widget_set_sensitive(GTK_WIDGET(state->entry_ou_list), TRUE); + gtk_widget_set_sensitive(GTK_WIDGET(state->button_get_ous), TRUE); SAFE_FREE(state->name_buffer_new); state->name_buffer_new = strdup(entry_text); state->name_type_new = NetSetupDomainName; } -static void callback_continue(GtkWidget *widget, - gpointer data) -{ - struct join_state *state = (struct join_state *)data; - - gtk_widget_grab_focus(GTK_WIDGET(state->button_ok)); - g_signal_emit_by_name(state->button_ok, "clicked"); -} - static void callback_apply_continue(GtkWidget *widget, gpointer data) { @@ -748,6 +872,8 @@ static void callback_do_join_workgroup(GtkWidget *widget, gtk_widget_set_sensitive(GTK_WIDGET(state->entry_workgroup), TRUE); gtk_widget_grab_focus(GTK_WIDGET(state->entry_workgroup)); gtk_widget_set_sensitive(GTK_WIDGET(state->entry_domain), FALSE); + gtk_widget_set_sensitive(GTK_WIDGET(state->entry_ou_list), FALSE); + gtk_widget_set_sensitive(GTK_WIDGET(state->button_get_ous), FALSE); callback_enter_workgroup_and_unlock(state->entry_workgroup, state); /* TEST */ } @@ -762,6 +888,62 @@ static void callback_do_join_domain(GtkWidget *widget, callback_enter_domain_and_unlock(state->entry_domain, state); /* TEST */ } +static void callback_do_getous(GtkWidget *widget, + gpointer data) +{ + NET_API_STATUS status; + uint32_t num_ous = 0; + const char **ous = NULL; + int i; + const char *domain = NULL; + + struct join_state *state = (struct join_state *)data; + + debug("callback_do_getous called\n"); + + domain = state->name_buffer_new ? state->name_buffer_new : state->name_buffer_initial; + + if (!state->account || !state->password) { + debug("callback_do_getous: no creds yet\n"); + callback_creds_prompt(NULL, state, + "Enter the name and password of an account with permission to join the domain.", + callback_do_storeauth_and_scan); + } + + if (!state->account || !state->password) { + debug("callback_do_getous: still no creds ???\n"); + return; + } + + status = NetGetJoinableOUs(NULL, domain, + state->account, + state->password, + &num_ous, &ous); + if (status != NET_API_STATUS_SUCCESS) { + GtkWidget *dialog; + callback_do_freeauth(NULL, state); + debug("failed to call NetGetJoinableOUs: %s\n", + libnetapi_get_error_string(state->ctx, status)); + dialog = gtk_message_dialog_new(NULL, + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_INFO, + GTK_BUTTONS_OK, + "Failed to query joinable OUs: %s", + libnetapi_get_error_string(state->ctx, status)); + gtk_window_set_modal(GTK_WINDOW(dialog), TRUE); + gtk_dialog_run(GTK_DIALOG(dialog)); + gtk_widget_destroy(dialog); + return; + } + + for (i=0; ientry_ou_list), + ous[i]); + } + NetApiBufferFree(ous); + gtk_combo_box_set_active(GTK_COMBO_BOX(state->entry_ou_list), num_ous-1); +} + static void callback_do_change(GtkWidget *widget, gpointer data) { @@ -785,11 +967,13 @@ static void callback_do_change(GtkWidget *widget, /* FIXME: add proper warnings for Samba as a DC */ if (state->server_role == 3) { GtkWidget *dialog; + callback_do_freeauth(NULL, state); dialog = gtk_message_dialog_new(GTK_WINDOW(state->window_main), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "Domain controller cannot be moved from one domain to another, they must first be demoted. Renaming this domain controller may cause it to become temporarily unavailable to users and computers. For information on renaming domain controllers, including alternate renaming methods, see Help and Support. To continue renaming this domain controller, click OK."); + gtk_window_set_modal(GTK_WINDOW(dialog), TRUE); g_signal_connect_swapped(dialog, "response", G_CALLBACK(gtk_widget_destroy), dialog); @@ -800,11 +984,13 @@ static void callback_do_change(GtkWidget *widget, #endif state->button_ok = gtk_button_new_from_stock(GTK_STOCK_OK); + state->button_get_ous = gtk_button_new_with_label("Scan for joinable OUs"); window = gtk_window_new(GTK_WINDOW_TOPLEVEL); + gtk_window_set_modal(GTK_WINDOW(window), TRUE); gtk_window_set_title(GTK_WINDOW(window), "Computer Name Changes"); gtk_window_set_resizable(GTK_WINDOW(window), FALSE); - gtk_widget_set_size_request(GTK_WIDGET(window), 480, 500); + gtk_widget_set_size_request(GTK_WIDGET(window), 480, 650); gtk_window_set_icon_from_file(GTK_WINDOW(window), SAMBA_ICON_PATH, NULL); g_signal_connect(G_OBJECT(window), "delete_event", @@ -941,6 +1127,37 @@ static void callback_do_change(GtkWidget *widget, } gtk_widget_show(button_workgroup); + /* Advanced Options */ + frame_horz = gtk_frame_new("Advanced Options"); + gtk_box_pack_start(GTK_BOX(box1), frame_horz, TRUE, TRUE, 10); + + vbox = gtk_vbox_new(FALSE, 0); + gtk_container_set_border_width(GTK_CONTAINER(vbox), 10); + gtk_container_add(GTK_CONTAINER(frame_horz), vbox); + + /* OUs */ + gtk_container_add(GTK_CONTAINER(vbox), state->button_get_ous); + gtk_widget_set_sensitive(GTK_WIDGET(state->button_get_ous), FALSE); + g_signal_connect(G_OBJECT(state->button_get_ous), "clicked", + G_CALLBACK(callback_do_getous), + (gpointer)state); + + state->entry_ou_list = gtk_combo_box_entry_new_text(); + gtk_widget_set_sensitive(state->entry_ou_list, FALSE); + if (state->name_type_initial == NetSetupWorkgroupName) { + gtk_widget_set_sensitive(state->entry_ou_list, FALSE); + gtk_widget_set_sensitive(state->button_get_ous, FALSE); + } + gtk_box_pack_start(GTK_BOX(vbox), state->entry_ou_list, TRUE, TRUE, 0); + gtk_widget_show(state->entry_ou_list); + + { + state->label_winbind = gtk_check_button_new_with_label("Modify winbind configuration"); + gtk_box_pack_start(GTK_BOX(vbox), state->label_winbind, TRUE, TRUE, 0); + gtk_widget_set_sensitive(state->label_winbind, FALSE); + } + + /* BUTTONS */ bbox = gtk_hbutton_box_new(); gtk_container_set_border_width(GTK_CONTAINER(bbox), 5); @@ -949,20 +1166,19 @@ static void callback_do_change(GtkWidget *widget, gtk_box_set_spacing(GTK_BOX(bbox), 10); state->window_do_change = window; - gtk_widget_set_sensitive(GTK_WIDGET(state->button_ok), FALSE); /* !!! */ + gtk_widget_set_sensitive(GTK_WIDGET(state->button_ok), FALSE); gtk_container_add(GTK_CONTAINER(bbox), state->button_ok); g_signal_connect(G_OBJECT(state->button_ok), "clicked", - G_CALLBACK(callback_creds_prompt), + G_CALLBACK(callback_do_join), (gpointer)state); button = gtk_button_new_from_stock(GTK_STOCK_CANCEL); gtk_container_add(GTK_CONTAINER(bbox), button); g_signal_connect(G_OBJECT(button), "clicked", - G_CALLBACK(callback_do_close), - (gpointer)window); + G_CALLBACK(callback_do_freeauth_and_close), + (gpointer)state); gtk_widget_show_all(window); - } static void callback_do_about(GtkWidget *widget, @@ -970,6 +1186,7 @@ static void callback_do_about(GtkWidget *widget, { GdkPixbuf *logo; GError *error = NULL; + GtkWidget *about; debug("callback_do_about called\n"); @@ -980,15 +1197,25 @@ static void callback_do_about(GtkWidget *widget, SAMBA_IMAGE_PATH, error->message); } - gtk_show_about_dialog(data, - "name", "Samba", - "version", "3.2.0pre2-GIT-904a90-test", - "copyright", "Copyright Andrew Tridgell and the Samba Team 1992-2007", - "website", "http://www.samba.org", - "license", "GPLv3", - "logo", logo, - "comments", "Samba gtk domain join utility", - NULL); + about = gtk_about_dialog_new(); + gtk_about_dialog_set_name(GTK_ABOUT_DIALOG(about), "Samba"); + gtk_about_dialog_set_version(GTK_ABOUT_DIALOG(about), "3.2.0pre3"); + gtk_about_dialog_set_copyright(GTK_ABOUT_DIALOG(about), + "Copyright Andrew Tridgell and the Samba Team 1992-2008\n" + "Copyright Günther Deschner 2007-2008"); + gtk_about_dialog_set_license(GTK_ABOUT_DIALOG(about), "GPLv3"); + gtk_about_dialog_set_website(GTK_ABOUT_DIALOG(about), "http://www.samba.org"); + gtk_about_dialog_set_website_label(GTK_ABOUT_DIALOG(about), "http://www.samba.org"); + if (logo) { + gtk_about_dialog_set_logo(GTK_ABOUT_DIALOG(about), logo); + } + gtk_about_dialog_set_comments(GTK_ABOUT_DIALOG(about), "Samba gtk domain join utility"); + gtk_window_set_modal(GTK_WINDOW(about), TRUE); + g_signal_connect_swapped(about, "response", + G_CALLBACK(gtk_widget_destroy), + about); + + gtk_widget_show(about); } static int draw_main_window(struct join_state *state) @@ -1221,7 +1448,13 @@ static int draw_main_window(struct join_state *state) g_signal_connect(G_OBJECT(button2), "clicked", G_CALLBACK(callback_do_about), window); - +#if 0 + button2 = gtk_button_new_from_stock(GTK_STOCK_HELP); + gtk_container_add(GTK_CONTAINER(bbox2), button2); + g_signal_connect(G_OBJECT(button2), "clicked", + G_CALLBACK(callback_do_about), + window); +#endif gtk_box_pack_start(GTK_BOX(vbox), frame, TRUE, TRUE, 5); } -- cgit From ba35a8c8dd530fa8aa6a2fd17cd43dfaa434b2f3 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 8 Apr 2008 02:42:50 +0200 Subject: Restructure inner workings of libnetapi a bit. Guenther (This used to be commit a4e3bc2bade8bf74696e1c6ced74da563ff2df7b) --- .../examples/getjoinableous/getjoinableous.c | 1 + source3/lib/netapi/getdc.c | 142 +----- source3/lib/netapi/joindomain.c | 478 +++++---------------- source3/lib/netapi/libnetapi.c | 393 +++++++++++++++++ source3/lib/netapi/libnetapi.h | 67 +++ source3/lib/netapi/netapi.h | 80 ++-- source3/lib/netapi/serverinfo.c | 181 ++------ 7 files changed, 662 insertions(+), 680 deletions(-) create mode 100644 source3/lib/netapi/libnetapi.c create mode 100644 source3/lib/netapi/libnetapi.h (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/getjoinableous/getjoinableous.c b/source3/lib/netapi/examples/getjoinableous/getjoinableous.c index 5a3366c9dc..be95198bcf 100644 --- a/source3/lib/netapi/examples/getjoinableous/getjoinableous.c +++ b/source3/lib/netapi/examples/getjoinableous/getjoinableous.c @@ -19,6 +19,7 @@ #include #include +#include #include diff --git a/source3/lib/netapi/getdc.c b/source3/lib/netapi/getdc.c index 2626eb0af4..f6a666d70d 100644 --- a/source3/lib/netapi/getdc.c +++ b/source3/lib/netapi/getdc.c @@ -19,16 +19,16 @@ #include "includes.h" +#include "librpc/gen_ndr/libnetapi.h" #include "lib/netapi/netapi.h" +#include "lib/netapi/libnetapi.h" #include "libnet/libnet.h" /******************************************************************** ********************************************************************/ -static WERROR NetGetDCNameLocal(struct libnetapi_ctx *ctx, - const char *server_name, - const char *domain_name, - uint8_t **buffer) +WERROR NetGetDCName_l(struct libnetapi_ctx *ctx, + struct NetGetDCName *r) { return WERR_NOT_SUPPORTED; } @@ -36,17 +36,15 @@ static WERROR NetGetDCNameLocal(struct libnetapi_ctx *ctx, /******************************************************************** ********************************************************************/ -static WERROR NetGetDCNameRemote(struct libnetapi_ctx *ctx, - const char *server_name, - const char *domain_name, - uint8_t **buffer) +WERROR NetGetDCName_r(struct libnetapi_ctx *ctx, + struct NetGetDCName *r) { struct cli_state *cli = NULL; struct rpc_pipe_client *pipe_cli = NULL; NTSTATUS status; WERROR werr; - status = cli_full_connection(&cli, NULL, server_name, + status = cli_full_connection(&cli, NULL, r->in.server_name, NULL, 0, "IPC$", "IPC", ctx->username, @@ -64,12 +62,12 @@ static WERROR NetGetDCNameRemote(struct libnetapi_ctx *ctx, if (!pipe_cli) { werr = ntstatus_to_werror(status); goto done; - }; + } status = rpccli_netr_GetDcName(pipe_cli, ctx, - server_name, - domain_name, - (const char **)buffer, + r->in.server_name, + r->in.domain_name, + (const char **)r->out.buffer, &werr); done: if (cli) { @@ -82,59 +80,8 @@ static WERROR NetGetDCNameRemote(struct libnetapi_ctx *ctx, /******************************************************************** ********************************************************************/ -static WERROR libnetapi_NetGetDCName(struct libnetapi_ctx *ctx, - const char *server_name, - const char *domain_name, - uint8_t **buffer) -{ - if (!server_name || is_myname_or_ipaddr(server_name)) { - return NetGetDCNameLocal(ctx, - server_name, - domain_name, - buffer); - } - - return NetGetDCNameRemote(ctx, - server_name, - domain_name, - buffer); -} - -/**************************************************************** - NetGetDCName -****************************************************************/ - -NET_API_STATUS NetGetDCName(const char *server_name, - const char *domain_name, - uint8_t **buffer) -{ - struct libnetapi_ctx *ctx = NULL; - NET_API_STATUS status; - WERROR werr; - - status = libnetapi_getctx(&ctx); - if (status != 0) { - return status; - } - - werr = libnetapi_NetGetDCName(ctx, - server_name, - domain_name, - buffer); - if (!W_ERROR_IS_OK(werr)) { - return W_ERROR_V(werr); - } - - return NET_API_STATUS_SUCCESS; -} - -/******************************************************************** -********************************************************************/ - -static WERROR NetGetAnyDCNameLocal(struct libnetapi_ctx *ctx, - const char *server_name, - const char *domain_name, - uint8_t **buffer) +WERROR NetGetAnyDCName_l(struct libnetapi_ctx *ctx, + struct NetGetAnyDCName *r) { return WERR_NOT_SUPPORTED; } @@ -142,17 +89,15 @@ static WERROR NetGetAnyDCNameLocal(struct libnetapi_ctx *ctx, /******************************************************************** ********************************************************************/ -static WERROR NetGetAnyDCNameRemote(struct libnetapi_ctx *ctx, - const char *server_name, - const char *domain_name, - uint8_t **buffer) +WERROR NetGetAnyDCName_r(struct libnetapi_ctx *ctx, + struct NetGetAnyDCName *r) { struct cli_state *cli = NULL; struct rpc_pipe_client *pipe_cli = NULL; NTSTATUS status; WERROR werr; - status = cli_full_connection(&cli, NULL, server_name, + status = cli_full_connection(&cli, NULL, r->in.server_name, NULL, 0, "IPC$", "IPC", ctx->username, @@ -173,9 +118,9 @@ static WERROR NetGetAnyDCNameRemote(struct libnetapi_ctx *ctx, }; status = rpccli_netr_GetAnyDCName(pipe_cli, ctx, - server_name, - domain_name, - (const char **)buffer, + r->in.server_name, + r->in.domain_name, + (const char **)r->out.buffer, &werr); if (!NT_STATUS_IS_OK(status)) { goto done; @@ -188,52 +133,3 @@ static WERROR NetGetAnyDCNameRemote(struct libnetapi_ctx *ctx, return werr; } - -/******************************************************************** -********************************************************************/ - -static WERROR libnetapi_NetGetAnyDCName(struct libnetapi_ctx *ctx, - const char *server_name, - const char *domain_name, - uint8_t **buffer) -{ - if (!server_name || is_myname_or_ipaddr(server_name)) { - return NetGetAnyDCNameLocal(ctx, - server_name, - domain_name, - buffer); - } - - return NetGetAnyDCNameRemote(ctx, - server_name, - domain_name, - buffer); -} - -/**************************************************************** - NetGetAnyDCName -****************************************************************/ - -NET_API_STATUS NetGetAnyDCName(const char *server_name, - const char *domain_name, - uint8_t **buffer) -{ - struct libnetapi_ctx *ctx = NULL; - NET_API_STATUS status; - WERROR werr; - - status = libnetapi_getctx(&ctx); - if (status != 0) { - return status; - } - - werr = libnetapi_NetGetAnyDCName(ctx, - server_name, - domain_name, - buffer); - if (!W_ERROR_IS_OK(werr)) { - return W_ERROR_V(werr); - } - - return NET_API_STATUS_SUCCESS; -} diff --git a/source3/lib/netapi/joindomain.c b/source3/lib/netapi/joindomain.c index ed8327ed68..468360f146 100644 --- a/source3/lib/netapi/joindomain.c +++ b/source3/lib/netapi/joindomain.c @@ -19,75 +19,72 @@ #include "includes.h" +#include "librpc/gen_ndr/libnetapi.h" #include "lib/netapi/netapi.h" +#include "lib/netapi/libnetapi.h" #include "libnet/libnet.h" /**************************************************************** ****************************************************************/ -static WERROR NetJoinDomainLocal(struct libnetapi_ctx *mem_ctx, - const char *server_name, - const char *domain_name, - const char *account_ou, - const char *Account, - const char *password, - uint32_t join_flags) +WERROR NetJoinDomain_l(struct libnetapi_ctx *mem_ctx, + struct NetJoinDomain *r) { - struct libnet_JoinCtx *r = NULL; + struct libnet_JoinCtx *j = NULL; WERROR werr; - if (!domain_name) { + if (!r->in.domain) { return WERR_INVALID_PARAM; } - werr = libnet_init_JoinCtx(mem_ctx, &r); + werr = libnet_init_JoinCtx(mem_ctx, &j); 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); + j->in.domain_name = talloc_strdup(mem_ctx, r->in.domain); + W_ERROR_HAVE_NO_MEMORY(j->in.domain_name); - if (join_flags & WKSSVC_JOIN_FLAGS_JOIN_TYPE) { + if (r->in.join_flags & WKSSVC_JOIN_FLAGS_JOIN_TYPE) { NTSTATUS status; struct netr_DsRGetDCNameInfo *info = NULL; uint32_t flags = DS_DIRECTORY_SERVICE_REQUIRED | DS_WRITABLE_REQUIRED | DS_RETURN_DNS_NAME; - status = dsgetdcname(mem_ctx, domain_name, + status = dsgetdcname(mem_ctx, r->in.domain, NULL, NULL, flags, &info); if (!NT_STATUS_IS_OK(status)) { libnetapi_set_error_string(mem_ctx, "%s", get_friendly_nt_error_msg(status)); return ntstatus_to_werror(status); } - r->in.dc_name = talloc_strdup(mem_ctx, + j->in.dc_name = talloc_strdup(mem_ctx, info->dc_unc); - W_ERROR_HAVE_NO_MEMORY(r->in.dc_name); + W_ERROR_HAVE_NO_MEMORY(j->in.dc_name); } - if (account_ou) { - r->in.account_ou = talloc_strdup(mem_ctx, account_ou); - W_ERROR_HAVE_NO_MEMORY(r->in.account_ou); + if (r->in.account_ou) { + j->in.account_ou = talloc_strdup(mem_ctx, r->in.account_ou); + W_ERROR_HAVE_NO_MEMORY(j->in.account_ou); } - if (Account) { - r->in.admin_account = talloc_strdup(mem_ctx, Account); - W_ERROR_HAVE_NO_MEMORY(r->in.admin_account); + if (r->in.account) { + j->in.admin_account = talloc_strdup(mem_ctx, r->in.account); + W_ERROR_HAVE_NO_MEMORY(j->in.admin_account); } - if (password) { - r->in.admin_password = talloc_strdup(mem_ctx, password); - W_ERROR_HAVE_NO_MEMORY(r->in.admin_password); + if (r->in.password) { + j->in.admin_password = talloc_strdup(mem_ctx, r->in.password); + W_ERROR_HAVE_NO_MEMORY(j->in.admin_password); } - r->in.join_flags = join_flags; - r->in.modify_config = true; - r->in.debug = true; + j->in.join_flags = r->in.join_flags; + j->in.modify_config = true; + j->in.debug = true; - werr = libnet_Join(mem_ctx, r); - if (!W_ERROR_IS_OK(werr) && r->out.error_string) { - libnetapi_set_error_string(mem_ctx, "%s", r->out.error_string); + werr = libnet_Join(mem_ctx, j); + if (!W_ERROR_IS_OK(werr) && j->out.error_string) { + libnetapi_set_error_string(mem_ctx, "%s", j->out.error_string); } - TALLOC_FREE(r); + TALLOC_FREE(j); return werr; } @@ -95,13 +92,8 @@ static WERROR NetJoinDomainLocal(struct libnetapi_ctx *mem_ctx, /**************************************************************** ****************************************************************/ -static WERROR NetJoinDomainRemote(struct libnetapi_ctx *ctx, - const char *server_name, - const char *domain_name, - const char *account_ou, - const char *Account, - const char *password, - uint32_t join_flags) +WERROR NetJoinDomain_r(struct libnetapi_ctx *ctx, + struct NetJoinDomain *r) { struct cli_state *cli = NULL; struct rpc_pipe_client *pipe_cli = NULL; @@ -110,7 +102,7 @@ static WERROR NetJoinDomainRemote(struct libnetapi_ctx *ctx, WERROR werr; unsigned int old_timeout = 0; - status = cli_full_connection(&cli, NULL, server_name, + status = cli_full_connection(&cli, NULL, r->in.server, NULL, 0, "IPC$", "IPC", ctx->username, @@ -130,20 +122,23 @@ static WERROR NetJoinDomainRemote(struct libnetapi_ctx *ctx, goto done; } - if (password) { + if (r->in.password) { encode_wkssvc_join_password_buffer(ctx, - password, + r->in.password, &cli->user_session_key, &encrypted_password); } - old_timeout = cli_set_timeout(cli, 60000); + old_timeout = cli_set_timeout(cli, 600000); status = rpccli_wkssvc_NetrJoinDomain2(pipe_cli, ctx, - server_name, domain_name, - account_ou, Account, + r->in.server, + r->in.domain, + r->in.account_ou, + r->in.account, encrypted_password, - join_flags, &werr); + r->in.join_flags, + &werr); if (!NT_STATUS_IS_OK(status)) { werr = ntstatus_to_werror(status); goto done; @@ -151,92 +146,21 @@ static WERROR NetJoinDomainRemote(struct libnetapi_ctx *ctx, done: if (cli) { - cli_set_timeout(cli, old_timeout); + if (old_timeout) { + cli_set_timeout(cli, old_timeout); + } cli_shutdown(cli); } return werr; } - -/**************************************************************** -****************************************************************/ - -static WERROR libnetapi_NetJoinDomain(struct libnetapi_ctx *ctx, - const char *server_name, - const char *domain_name, - const char *account_ou, - const char *Account, - const char *password, - uint32_t join_flags) -{ - if (!domain_name) { - return WERR_INVALID_PARAM; - } - - if (!server_name || is_myname_or_ipaddr(server_name)) { - - return NetJoinDomainLocal(ctx, - server_name, - domain_name, - account_ou, - Account, - password, - join_flags); - } - - return NetJoinDomainRemote(ctx, - server_name, - domain_name, - account_ou, - Account, - password, - join_flags); -} - /**************************************************************** - NetJoinDomain ****************************************************************/ -NET_API_STATUS NetJoinDomain(const char *server_name, - const char *domain_name, - const char *account_ou, - const char *Account, - const char *password, - uint32_t join_flags) +WERROR NetUnjoinDomain_l(struct libnetapi_ctx *mem_ctx, + struct NetUnjoinDomain *r) { - struct libnetapi_ctx *ctx = NULL; - NET_API_STATUS status; - WERROR werr; - - status = libnetapi_getctx(&ctx); - if (status != 0) { - return status; - } - - werr = libnetapi_NetJoinDomain(ctx, - server_name, - domain_name, - account_ou, - Account, - password, - join_flags); - if (!W_ERROR_IS_OK(werr)) { - return W_ERROR_V(werr); - } - - return NET_API_STATUS_SUCCESS; -} - -/**************************************************************** -****************************************************************/ - -static WERROR NetUnjoinDomainLocal(struct libnetapi_ctx *mem_ctx, - const char *server_name, - const char *account, - const char *password, - uint32_t unjoin_flags) -{ - struct libnet_UnjoinCtx *r = NULL; + struct libnet_UnjoinCtx *u = NULL; struct dom_sid domain_sid; const char *domain = NULL; WERROR werr; @@ -245,7 +169,7 @@ static WERROR NetUnjoinDomainLocal(struct libnetapi_ctx *mem_ctx, return WERR_SETUP_NOT_JOINED; } - werr = libnet_init_UnjoinCtx(mem_ctx, &r); + werr = libnet_init_UnjoinCtx(mem_ctx, &u); W_ERROR_NOT_OK_RETURN(werr); if (lp_realm()) { @@ -254,9 +178,9 @@ static WERROR NetUnjoinDomainLocal(struct libnetapi_ctx *mem_ctx, domain = lp_workgroup(); } - if (server_name) { - r->in.dc_name = talloc_strdup(mem_ctx, server_name); - W_ERROR_HAVE_NO_MEMORY(r->in.dc_name); + if (r->in.server_name) { + u->in.dc_name = talloc_strdup(mem_ctx, r->in.server_name); + W_ERROR_HAVE_NO_MEMORY(u->in.dc_name); } else { NTSTATUS status; struct netr_DsRGetDCNameInfo *info = NULL; @@ -272,33 +196,35 @@ static WERROR NetUnjoinDomainLocal(struct libnetapi_ctx *mem_ctx, get_friendly_nt_error_msg(status)); return ntstatus_to_werror(status); } - r->in.dc_name = talloc_strdup(mem_ctx, + u->in.dc_name = talloc_strdup(mem_ctx, info->dc_unc); - W_ERROR_HAVE_NO_MEMORY(r->in.dc_name); + W_ERROR_HAVE_NO_MEMORY(u->in.dc_name); + + u->in.domain_name = domain; } - if (account) { - r->in.admin_account = talloc_strdup(mem_ctx, account); - W_ERROR_HAVE_NO_MEMORY(r->in.admin_account); + if (r->in.account) { + u->in.admin_account = talloc_strdup(mem_ctx, r->in.account); + W_ERROR_HAVE_NO_MEMORY(u->in.admin_account); } - if (password) { - r->in.admin_password = talloc_strdup(mem_ctx, password); - W_ERROR_HAVE_NO_MEMORY(r->in.admin_password); + if (r->in.password) { + u->in.admin_password = talloc_strdup(mem_ctx, r->in.password); + W_ERROR_HAVE_NO_MEMORY(u->in.admin_password); } - r->in.domain_name = domain; - r->in.unjoin_flags = unjoin_flags; - r->in.modify_config = true; - r->in.debug = true; + u->in.domain_name = domain; + u->in.unjoin_flags = r->in.unjoin_flags; + u->in.modify_config = true; + u->in.debug = true; - r->in.domain_sid = &domain_sid; + u->in.domain_sid = &domain_sid; - werr = libnet_Unjoin(mem_ctx, r); - if (!W_ERROR_IS_OK(werr) && r->out.error_string) { - libnetapi_set_error_string(mem_ctx, "%s", r->out.error_string); + werr = libnet_Unjoin(mem_ctx, u); + if (!W_ERROR_IS_OK(werr) && u->out.error_string) { + libnetapi_set_error_string(mem_ctx, "%s", u->out.error_string); } - TALLOC_FREE(r); + TALLOC_FREE(u); return werr; } @@ -306,11 +232,8 @@ static WERROR NetUnjoinDomainLocal(struct libnetapi_ctx *mem_ctx, /**************************************************************** ****************************************************************/ -static WERROR NetUnjoinDomainRemote(struct libnetapi_ctx *ctx, - const char *server_name, - const char *account, - const char *password, - uint32_t unjoin_flags) +WERROR NetUnjoinDomain_r(struct libnetapi_ctx *ctx, + struct NetUnjoinDomain *r) { struct cli_state *cli = NULL; struct rpc_pipe_client *pipe_cli = NULL; @@ -319,7 +242,7 @@ static WERROR NetUnjoinDomainRemote(struct libnetapi_ctx *ctx, WERROR werr; unsigned int old_timeout = 0; - status = cli_full_connection(&cli, NULL, server_name, + status = cli_full_connection(&cli, NULL, r->in.server_name, NULL, 0, "IPC$", "IPC", ctx->username, @@ -339,9 +262,9 @@ static WERROR NetUnjoinDomainRemote(struct libnetapi_ctx *ctx, goto done; } - if (password) { + if (r->in.password) { encode_wkssvc_join_password_buffer(ctx, - password, + r->in.password, &cli->user_session_key, &encrypted_password); } @@ -349,10 +272,10 @@ static WERROR NetUnjoinDomainRemote(struct libnetapi_ctx *ctx, old_timeout = cli_set_timeout(cli, 60000); status = rpccli_wkssvc_NetrUnjoinDomain2(pipe_cli, ctx, - server_name, - account, + r->in.server_name, + r->in.account, encrypted_password, - unjoin_flags, + r->in.unjoin_flags, &werr); if (!NT_STATUS_IS_OK(status)) { werr = ntstatus_to_werror(status); @@ -371,72 +294,15 @@ static WERROR NetUnjoinDomainRemote(struct libnetapi_ctx *ctx, /**************************************************************** ****************************************************************/ -static WERROR libnetapi_NetUnjoinDomain(struct libnetapi_ctx *ctx, - const char *server_name, - const char *account, - const char *password, - uint32_t unjoin_flags) -{ - if (!server_name || is_myname_or_ipaddr(server_name)) { - - return NetUnjoinDomainLocal(ctx, - server_name, - account, - password, - unjoin_flags); - } - - return NetUnjoinDomainRemote(ctx, - server_name, - account, - password, - unjoin_flags); -} - -/**************************************************************** - NetUnjoinDomain -****************************************************************/ - -NET_API_STATUS NetUnjoinDomain(const char *server_name, - const char *account, - const char *password, - uint32_t unjoin_flags) -{ - struct libnetapi_ctx *ctx = NULL; - NET_API_STATUS status; - WERROR werr; - - status = libnetapi_getctx(&ctx); - if (status != 0) { - return status; - } - - werr = libnetapi_NetUnjoinDomain(ctx, - server_name, - account, - password, - unjoin_flags); - if (!W_ERROR_IS_OK(werr)) { - return W_ERROR_V(werr); - } - - return NET_API_STATUS_SUCCESS; -} - -/**************************************************************** -****************************************************************/ - -static WERROR NetGetJoinInformationRemote(struct libnetapi_ctx *ctx, - const char *server_name, - const char **name_buffer, - uint16_t *name_type) +WERROR NetGetJoinInformation_r(struct libnetapi_ctx *ctx, + struct NetGetJoinInformation *r) { struct cli_state *cli = NULL; struct rpc_pipe_client *pipe_cli = NULL; NTSTATUS status; WERROR werr; - status = cli_full_connection(&cli, NULL, server_name, + status = cli_full_connection(&cli, NULL, r->in.server_name, NULL, 0, "IPC$", "IPC", ctx->username, @@ -457,9 +323,9 @@ static WERROR NetGetJoinInformationRemote(struct libnetapi_ctx *ctx, } status = rpccli_wkssvc_NetrGetJoinInformation(pipe_cli, ctx, - server_name, - name_buffer, - (enum wkssvc_NetJoinStatus *)name_type, + r->in.server_name, + r->out.name_buffer, + (enum wkssvc_NetJoinStatus *)r->out.name_type, &werr); if (!NT_STATUS_IS_OK(status)) { werr = ntstatus_to_werror(status); @@ -477,17 +343,15 @@ static WERROR NetGetJoinInformationRemote(struct libnetapi_ctx *ctx, /**************************************************************** ****************************************************************/ -static WERROR NetGetJoinInformationLocal(struct libnetapi_ctx *ctx, - const char *server_name, - const char **name_buffer, - uint16_t *name_type) +WERROR NetGetJoinInformation_l(struct libnetapi_ctx *ctx, + struct NetGetJoinInformation *r) { if ((lp_security() == SEC_ADS) && lp_realm()) { - *name_buffer = talloc_strdup(ctx, lp_realm()); + *r->out.name_buffer = talloc_strdup(ctx, lp_realm()); } else { - *name_buffer = talloc_strdup(ctx, lp_workgroup()); + *r->out.name_buffer = talloc_strdup(ctx, lp_workgroup()); } - if (!*name_buffer) { + if (!*r->out.name_buffer) { return WERR_NOMEM; } @@ -495,73 +359,22 @@ static WERROR NetGetJoinInformationLocal(struct libnetapi_ctx *ctx, case ROLE_DOMAIN_MEMBER: case ROLE_DOMAIN_PDC: case ROLE_DOMAIN_BDC: - *name_type = NetSetupDomainName; + *r->out.name_type = NetSetupDomainName; break; case ROLE_STANDALONE: default: - *name_type = NetSetupWorkgroupName; + *r->out.name_type = NetSetupWorkgroupName; break; } return WERR_OK; } -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, - server_name, - name_buffer, - name_type); - } - - return NetGetJoinInformationRemote(ctx, - server_name, - name_buffer, - name_type); -} - -/**************************************************************** - NetGetJoinInformation -****************************************************************/ - -NET_API_STATUS NetGetJoinInformation(const char *server_name, - const char **name_buffer, - uint16_t *name_type) -{ - struct libnetapi_ctx *ctx = NULL; - NET_API_STATUS status; - WERROR werr; - - status = libnetapi_getctx(&ctx); - if (status != 0) { - return status; - } - - werr = libnetapi_NetGetJoinInformation(ctx, - server_name, - name_buffer, - name_type); - if (!W_ERROR_IS_OK(werr)) { - return W_ERROR_V(werr); - } - - return NET_API_STATUS_SUCCESS; -} - /**************************************************************** ****************************************************************/ -static WERROR NetGetJoinableOUsLocal(struct libnetapi_ctx *ctx, - const char *server_name, - const char *domain, - const char *account, - const char *password, - uint32_t *ou_count, - const char ***ous) +WERROR NetGetJoinableOUs_l(struct libnetapi_ctx *ctx, + struct NetGetJoinableOUs *r) { #ifdef WITH_ADS NTSTATUS status; @@ -571,7 +384,7 @@ static WERROR NetGetJoinableOUsLocal(struct libnetapi_ctx *ctx, uint32_t flags = DS_DIRECTORY_SERVICE_REQUIRED | DS_RETURN_DNS_NAME; - status = dsgetdcname(ctx, domain, + status = dsgetdcname(ctx, r->in.domain, NULL, NULL, flags, &info); if (!NT_STATUS_IS_OK(status)) { libnetapi_set_error_string(ctx, "%s", @@ -579,21 +392,21 @@ static WERROR NetGetJoinableOUsLocal(struct libnetapi_ctx *ctx, return ntstatus_to_werror(status); } - ads = ads_init(domain, domain, info->dc_unc); + ads = ads_init(r->in.domain, r->in.domain, info->dc_unc); if (!ads) { return WERR_GENERAL_FAILURE; } SAFE_FREE(ads->auth.user_name); - if (account) { - ads->auth.user_name = SMB_STRDUP(account); + if (r->in.account) { + ads->auth.user_name = SMB_STRDUP(r->in.account); } else if (ctx->username) { ads->auth.user_name = SMB_STRDUP(ctx->username); } SAFE_FREE(ads->auth.password); - if (password) { - ads->auth.password = SMB_STRDUP(password); + if (r->in.password) { + ads->auth.password = SMB_STRDUP(r->in.password); } else if (ctx->password) { ads->auth.password = SMB_STRDUP(ctx->password); } @@ -605,8 +418,8 @@ static WERROR NetGetJoinableOUsLocal(struct libnetapi_ctx *ctx, } ads_status = ads_get_joinable_ous(ads, ctx, - (char ***)ous, - (size_t *)ou_count); + (char ***)r->out.ous, + (size_t *)r->out.ou_count); if (!ADS_ERR_OK(ads_status)) { ads_destroy(&ads); return WERR_DEFAULT_JOIN_REQUIRED; @@ -622,13 +435,8 @@ static WERROR NetGetJoinableOUsLocal(struct libnetapi_ctx *ctx, /**************************************************************** ****************************************************************/ -static WERROR NetGetJoinableOUsRemote(struct libnetapi_ctx *ctx, - const char *server_name, - const char *domain, - const char *account, - const char *password, - uint32_t *ou_count, - const char ***ous) +WERROR NetGetJoinableOUs_r(struct libnetapi_ctx *ctx, + struct NetGetJoinableOUs *r) { struct cli_state *cli = NULL; struct rpc_pipe_client *pipe_cli = NULL; @@ -636,7 +444,7 @@ static WERROR NetGetJoinableOUsRemote(struct libnetapi_ctx *ctx, NTSTATUS status; WERROR werr; - status = cli_full_connection(&cli, NULL, server_name, + status = cli_full_connection(&cli, NULL, r->in.server_name, NULL, 0, "IPC$", "IPC", ctx->username, @@ -656,20 +464,20 @@ static WERROR NetGetJoinableOUsRemote(struct libnetapi_ctx *ctx, goto done; } - if (password) { + if (r->in.password) { encode_wkssvc_join_password_buffer(ctx, - password, + r->in.password, &cli->user_session_key, &encrypted_password); } status = rpccli_wkssvc_NetrGetJoinableOus2(pipe_cli, ctx, - server_name, - domain, - account, + r->in.server_name, + r->in.domain, + r->in.account, encrypted_password, - ou_count, - ous, + r->out.ou_count, + r->out.ous, &werr); if (!NT_STATUS_IS_OK(status)) { werr = ntstatus_to_werror(status); @@ -683,67 +491,3 @@ static WERROR NetGetJoinableOUsRemote(struct libnetapi_ctx *ctx, return werr; } - -/**************************************************************** -****************************************************************/ - -static WERROR libnetapi_NetGetJoinableOUs(struct libnetapi_ctx *ctx, - const char *server_name, - const char *domain, - const char *account, - const char *password, - uint32_t *ou_count, - const char ***ous) -{ - if (!server_name || is_myname_or_ipaddr(server_name)) { - return NetGetJoinableOUsLocal(ctx, - server_name, - domain, - account, - password, - ou_count, - ous); - } - - return NetGetJoinableOUsRemote(ctx, - server_name, - domain, - account, - password, - ou_count, - ous); -} - -/**************************************************************** - NetGetJoinableOUs -****************************************************************/ - -NET_API_STATUS NetGetJoinableOUs(const char *server_name, - const char *domain, - const char *account, - const char *password, - uint32_t *ou_count, - const char ***ous) -{ - struct libnetapi_ctx *ctx = NULL; - NET_API_STATUS status; - WERROR werr; - - status = libnetapi_getctx(&ctx); - if (status != 0) { - return status; - } - - werr = libnetapi_NetGetJoinableOUs(ctx, - server_name, - domain, - account, - password, - ou_count, - ous); - if (!W_ERROR_IS_OK(werr)) { - return W_ERROR_V(werr); - } - - return NET_API_STATUS_SUCCESS; -} diff --git a/source3/lib/netapi/libnetapi.c b/source3/lib/netapi/libnetapi.c new file mode 100644 index 0000000000..9d42b7e97c --- /dev/null +++ b/source3/lib/netapi/libnetapi.c @@ -0,0 +1,393 @@ +/* + * Unix SMB/CIFS implementation. + * NetApi Support + * 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include "includes.h" +#include "librpc/gen_ndr/libnetapi.h" +#include "lib/netapi/netapi.h" +#include "libnetapi.h" +#include "librpc/gen_ndr/ndr_libnetapi.h" + +/**************************************************************** + NetJoinDomain +****************************************************************/ + +NET_API_STATUS NetJoinDomain(const char * server /* [in] [unique] */, + const char * domain /* [in] [ref] */, + const char * account_ou /* [in] [unique] */, + const char * account /* [in] [unique] */, + const char * password /* [in] [unique] */, + uint32_t join_flags /* [in] */) +{ + struct NetJoinDomain r; + struct libnetapi_ctx *ctx = NULL; + NET_API_STATUS status; + WERROR werr; + + status = libnetapi_getctx(&ctx); + if (status != 0) { + return status; + } + + /* In parameters */ + r.in.server = server; + r.in.domain = domain; + r.in.account_ou = account_ou; + r.in.account = account; + r.in.password = password; + r.in.join_flags = join_flags; + + /* Out parameters */ + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_IN_DEBUG(NetJoinDomain, &r); + } + + if (LIBNETAPI_LOCAL_SERVER(server)) { + werr = NetJoinDomain_l(ctx, &r); + } else { + werr = NetJoinDomain_r(ctx, &r); + } + + r.out.result = W_ERROR_V(werr); + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_OUT_DEBUG(NetJoinDomain, &r); + } + + return r.out.result; +} + +/**************************************************************** + NetUnjoinDomain +****************************************************************/ + +NET_API_STATUS NetUnjoinDomain(const char * server_name /* [in] [unique] */, + const char * account /* [in] [unique] */, + const char * password /* [in] [unique] */, + uint32_t unjoin_flags /* [in] */) +{ + struct NetUnjoinDomain r; + struct libnetapi_ctx *ctx = NULL; + NET_API_STATUS status; + WERROR werr; + + status = libnetapi_getctx(&ctx); + if (status != 0) { + return status; + } + + /* In parameters */ + r.in.server_name = server_name; + r.in.account = account; + r.in.password = password; + r.in.unjoin_flags = unjoin_flags; + + /* Out parameters */ + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_IN_DEBUG(NetUnjoinDomain, &r); + } + + if (LIBNETAPI_LOCAL_SERVER(server_name)) { + werr = NetUnjoinDomain_l(ctx, &r); + } else { + werr = NetUnjoinDomain_r(ctx, &r); + } + + r.out.result = W_ERROR_V(werr); + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_OUT_DEBUG(NetUnjoinDomain, &r); + } + + return r.out.result; +} + +/**************************************************************** + NetGetJoinInformation +****************************************************************/ + +NET_API_STATUS NetGetJoinInformation(const char * server_name /* [in] [unique] */, + const char * *name_buffer /* [out] [ref] */, + uint16_t *name_type /* [out] [ref] */) +{ + struct NetGetJoinInformation r; + struct libnetapi_ctx *ctx = NULL; + NET_API_STATUS status; + WERROR werr; + + status = libnetapi_getctx(&ctx); + if (status != 0) { + return status; + } + + /* In parameters */ + r.in.server_name = server_name; + + /* Out parameters */ + r.out.name_buffer = name_buffer; + r.out.name_type = name_type; + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_IN_DEBUG(NetGetJoinInformation, &r); + } + + if (LIBNETAPI_LOCAL_SERVER(server_name)) { + werr = NetGetJoinInformation_l(ctx, &r); + } else { + werr = NetGetJoinInformation_r(ctx, &r); + } + + r.out.result = W_ERROR_V(werr); + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_OUT_DEBUG(NetGetJoinInformation, &r); + } + + return r.out.result; +} + +/**************************************************************** + NetGetJoinableOUs +****************************************************************/ + +NET_API_STATUS NetGetJoinableOUs(const char * server_name /* [in] [unique] */, + const char * domain /* [in] [ref] */, + const char * account /* [in] [unique] */, + const char * password /* [in] [unique] */, + uint32_t *ou_count /* [out] [ref] */, + const char * **ous /* [out] [ref] */) +{ + struct NetGetJoinableOUs r; + struct libnetapi_ctx *ctx = NULL; + NET_API_STATUS status; + WERROR werr; + + status = libnetapi_getctx(&ctx); + if (status != 0) { + return status; + } + + /* In parameters */ + r.in.server_name = server_name; + r.in.domain = domain; + r.in.account = account; + r.in.password = password; + + /* Out parameters */ + r.out.ou_count = ou_count; + r.out.ous = ous; + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_IN_DEBUG(NetGetJoinableOUs, &r); + } + + if (LIBNETAPI_LOCAL_SERVER(server_name)) { + werr = NetGetJoinableOUs_l(ctx, &r); + } else { + werr = NetGetJoinableOUs_r(ctx, &r); + } + + r.out.result = W_ERROR_V(werr); + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_OUT_DEBUG(NetGetJoinableOUs, &r); + } + + return r.out.result; +} + +/**************************************************************** + NetServerGetInfo +****************************************************************/ + +NET_API_STATUS NetServerGetInfo(const char * server_name /* [in] [unique] */, + uint32_t level /* [in] */, + uint8_t **buffer /* [out] [ref] */) +{ + struct NetServerGetInfo r; + struct libnetapi_ctx *ctx = NULL; + NET_API_STATUS status; + WERROR werr; + + status = libnetapi_getctx(&ctx); + if (status != 0) { + return status; + } + + /* In parameters */ + r.in.server_name = server_name; + r.in.level = level; + + /* Out parameters */ + r.out.buffer = buffer; + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_IN_DEBUG(NetServerGetInfo, &r); + } + + if (LIBNETAPI_LOCAL_SERVER(server_name)) { + werr = NetServerGetInfo_l(ctx, &r); + } else { + werr = NetServerGetInfo_r(ctx, &r); + } + + r.out.result = W_ERROR_V(werr); + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_OUT_DEBUG(NetServerGetInfo, &r); + } + + return r.out.result; +} + +/**************************************************************** + NetServerSetInfo +****************************************************************/ + +NET_API_STATUS NetServerSetInfo(const char * server_name /* [in] [unique] */, + uint32_t level /* [in] */, + uint8_t *buffer /* [in] [ref] */, + uint32_t *parm_error /* [out] [ref] */) +{ + struct NetServerSetInfo r; + struct libnetapi_ctx *ctx = NULL; + NET_API_STATUS status; + WERROR werr; + + status = libnetapi_getctx(&ctx); + if (status != 0) { + return status; + } + + /* In parameters */ + r.in.server_name = server_name; + r.in.level = level; + r.in.buffer = buffer; + + /* Out parameters */ + r.out.parm_error = parm_error; + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_IN_DEBUG(NetServerSetInfo, &r); + } + + if (LIBNETAPI_LOCAL_SERVER(server_name)) { + werr = NetServerSetInfo_l(ctx, &r); + } else { + werr = NetServerSetInfo_r(ctx, &r); + } + + r.out.result = W_ERROR_V(werr); + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_OUT_DEBUG(NetServerSetInfo, &r); + } + + return r.out.result; +} + +/**************************************************************** + NetGetDCName +****************************************************************/ + +NET_API_STATUS NetGetDCName(const char * server_name /* [in] [unique] */, + const char * domain_name /* [in] [unique] */, + uint8_t **buffer /* [out] [ref] */) +{ + struct NetGetDCName r; + struct libnetapi_ctx *ctx = NULL; + NET_API_STATUS status; + WERROR werr; + + status = libnetapi_getctx(&ctx); + if (status != 0) { + return status; + } + + /* In parameters */ + r.in.server_name = server_name; + r.in.domain_name = domain_name; + + /* Out parameters */ + r.out.buffer = buffer; + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_IN_DEBUG(NetGetDCName, &r); + } + + if (LIBNETAPI_LOCAL_SERVER(server_name)) { + werr = NetGetDCName_l(ctx, &r); + } else { + werr = NetGetDCName_r(ctx, &r); + } + + r.out.result = W_ERROR_V(werr); + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_OUT_DEBUG(NetGetDCName, &r); + } + + return r.out.result; +} + +/**************************************************************** + NetGetAnyDCName +****************************************************************/ + +NET_API_STATUS NetGetAnyDCName(const char * server_name /* [in] [unique] */, + const char * domain_name /* [in] [unique] */, + uint8_t **buffer /* [out] [ref] */) +{ + struct NetGetAnyDCName r; + struct libnetapi_ctx *ctx = NULL; + NET_API_STATUS status; + WERROR werr; + + status = libnetapi_getctx(&ctx); + if (status != 0) { + return status; + } + + /* In parameters */ + r.in.server_name = server_name; + r.in.domain_name = domain_name; + + /* Out parameters */ + r.out.buffer = buffer; + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_IN_DEBUG(NetGetAnyDCName, &r); + } + + if (LIBNETAPI_LOCAL_SERVER(server_name)) { + werr = NetGetAnyDCName_l(ctx, &r); + } else { + werr = NetGetAnyDCName_r(ctx, &r); + } + + r.out.result = W_ERROR_V(werr); + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_OUT_DEBUG(NetGetAnyDCName, &r); + } + + return r.out.result; +} + diff --git a/source3/lib/netapi/libnetapi.h b/source3/lib/netapi/libnetapi.h new file mode 100644 index 0000000000..a215c84cb3 --- /dev/null +++ b/source3/lib/netapi/libnetapi.h @@ -0,0 +1,67 @@ +#ifndef __LIBNETAPI_LIBNETAPI__ +#define __LIBNETAPI_LIBNETAPI__ +NET_API_STATUS NetJoinDomain(const char * server /* [in] [unique] */, + const char * domain /* [in] [ref] */, + const char * account_ou /* [in] [unique] */, + const char * account /* [in] [unique] */, + const char * password /* [in] [unique] */, + uint32_t join_flags /* [in] */); +WERROR NetJoinDomain_r(struct libnetapi_ctx *ctx, + struct NetJoinDomain *r); +WERROR NetJoinDomain_l(struct libnetapi_ctx *ctx, + struct NetJoinDomain *r); +NET_API_STATUS NetUnjoinDomain(const char * server_name /* [in] [unique] */, + const char * account /* [in] [unique] */, + const char * password /* [in] [unique] */, + uint32_t unjoin_flags /* [in] */); +WERROR NetUnjoinDomain_r(struct libnetapi_ctx *ctx, + struct NetUnjoinDomain *r); +WERROR NetUnjoinDomain_l(struct libnetapi_ctx *ctx, + struct NetUnjoinDomain *r); +NET_API_STATUS NetGetJoinInformation(const char * server_name /* [in] [unique] */, + const char * *name_buffer /* [out] [ref] */, + uint16_t *name_type /* [out] [ref] */); +WERROR NetGetJoinInformation_r(struct libnetapi_ctx *ctx, + struct NetGetJoinInformation *r); +WERROR NetGetJoinInformation_l(struct libnetapi_ctx *ctx, + struct NetGetJoinInformation *r); +NET_API_STATUS NetGetJoinableOUs(const char * server_name /* [in] [unique] */, + const char * domain /* [in] [ref] */, + const char * account /* [in] [unique] */, + const char * password /* [in] [unique] */, + uint32_t *ou_count /* [out] [ref] */, + const char * **ous /* [out] [ref] */); +WERROR NetGetJoinableOUs_r(struct libnetapi_ctx *ctx, + struct NetGetJoinableOUs *r); +WERROR NetGetJoinableOUs_l(struct libnetapi_ctx *ctx, + struct NetGetJoinableOUs *r); +NET_API_STATUS NetServerGetInfo(const char * server_name /* [in] [unique] */, + uint32_t level /* [in] */, + uint8_t **buffer /* [out] [ref] */); +WERROR NetServerGetInfo_r(struct libnetapi_ctx *ctx, + struct NetServerGetInfo *r); +WERROR NetServerGetInfo_l(struct libnetapi_ctx *ctx, + struct NetServerGetInfo *r); +NET_API_STATUS NetServerSetInfo(const char * server_name /* [in] [unique] */, + uint32_t level /* [in] */, + uint8_t *buffer /* [in] [ref] */, + uint32_t *parm_error /* [out] [ref] */); +WERROR NetServerSetInfo_r(struct libnetapi_ctx *ctx, + struct NetServerSetInfo *r); +WERROR NetServerSetInfo_l(struct libnetapi_ctx *ctx, + struct NetServerSetInfo *r); +NET_API_STATUS NetGetDCName(const char * server_name /* [in] [unique] */, + const char * domain_name /* [in] [unique] */, + uint8_t **buffer /* [out] [ref] */); +WERROR NetGetDCName_r(struct libnetapi_ctx *ctx, + struct NetGetDCName *r); +WERROR NetGetDCName_l(struct libnetapi_ctx *ctx, + struct NetGetDCName *r); +NET_API_STATUS NetGetAnyDCName(const char * server_name /* [in] [unique] */, + const char * domain_name /* [in] [unique] */, + uint8_t **buffer /* [out] [ref] */); +WERROR NetGetAnyDCName_r(struct libnetapi_ctx *ctx, + struct NetGetAnyDCName *r); +WERROR NetGetAnyDCName_l(struct libnetapi_ctx *ctx, + struct NetGetAnyDCName *r); +#endif /* __LIBNETAPI_LIBNETAPI__ */ diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h index 002fc37762..87126fbacf 100644 --- a/source3/lib/netapi/netapi.h +++ b/source3/lib/netapi/netapi.h @@ -20,23 +20,13 @@ #ifndef __LIB_NETAPI_H__ #define __LIB_NETAPI_H__ -/**************************************************************** - include some basic headers -****************************************************************/ - -#include - /**************************************************************** NET_API_STATUS ****************************************************************/ -#define NET_API_STATUS uint32_t -#define NET_API_STATUS_SUCCESS 0 - -/**************************************************************** -****************************************************************/ - -#define LIBNETAPI_LOCAL_SERVER(x) (!x || is_myname_or_ipaddr(x)) +typedef enum { + NET_API_STATUS_SUCCESS = 0 +} NET_API_STATUS; /**************************************************************** ****************************************************************/ @@ -76,72 +66,72 @@ NET_API_STATUS NetApiBufferFree(void *buffer); NetJoinDomain ****************************************************************/ -NET_API_STATUS NetJoinDomain(const char *server, - const char *domain, - const char *account_ou, - const char *account, - const char *password, - uint32_t join_options); +NET_API_STATUS NetJoinDomain(const char * server /* [in] */, + const char * domain /* [in] [ref] */, + const char * account_ou /* [in] */, + const char * account /* [in] */, + const char * password /* [in] */, + uint32_t join_flags /* [in] */); /**************************************************************** NetUnjoinDomain ****************************************************************/ -NET_API_STATUS NetUnjoinDomain(const char *server_name, - const char *account, - const char *password, - uint32_t unjoin_flags); +NET_API_STATUS NetUnjoinDomain(const char * server_name /* [in] */, + const char * account /* [in] */, + const char * password /* [in] */, + uint32_t unjoin_flags /* [in] */); /**************************************************************** NetGetJoinInformation ****************************************************************/ -NET_API_STATUS NetGetJoinInformation(const char *server_name, - const char **name_buffer, - uint16_t *name_type); +NET_API_STATUS NetGetJoinInformation(const char * server_name /* [in] */, + const char * *name_buffer /* [out] [ref] */, + uint16_t *name_type /* [out] [ref] */); /**************************************************************** NetGetJoinableOUs ****************************************************************/ -NET_API_STATUS NetGetJoinableOUs(const char *server_name, - const char *domain, - const char *account, - const char *password, - uint32_t *ou_count, - const char ***ous); +NET_API_STATUS NetGetJoinableOUs(const char * server_name /* [in] */, + const char * domain /* [in] [ref] */, + const char * account /* [in] */, + const char * password /* [in] */, + uint32_t *ou_count /* [out] [ref] */, + const char * **ous /* [out] [ref] */); /**************************************************************** NetServerGetInfo ****************************************************************/ -NET_API_STATUS NetServerGetInfo(const char *server_name, - uint32_t level, - uint8_t **buffer); +NET_API_STATUS NetServerGetInfo(const char * server_name /* [in] */, + uint32_t level /* [in] */, + uint8_t **buffer /* [out] [ref] */); /**************************************************************** NetServerSetInfo ****************************************************************/ -NET_API_STATUS NetServerSetInfo(const char *server_name, - uint32_t level, - uint8_t *buffer, - uint32_t *parm_error); +NET_API_STATUS NetServerSetInfo(const char * server_name /* [in] */, + uint32_t level /* [in] */, + uint8_t *buffer /* [in] [ref] */, + uint32_t *parm_error /* [out] [ref] */); /**************************************************************** NetGetDCName ****************************************************************/ -NET_API_STATUS NetGetDCName(const char *server_name, - const char *domain_name, - uint8_t **buffer); +NET_API_STATUS NetGetDCName(const char * server_name /* [in] */, + const char * domain_name /* [in] */, + uint8_t **buffer /* [out] [ref] */); /**************************************************************** NetGetAnyDCName ****************************************************************/ -NET_API_STATUS NetGetAnyDCName(const char *server_name, - const char *domain_name, - uint8_t **buffer); +NET_API_STATUS NetGetAnyDCName(const char * server_name /* [in] */, + const char * domain_name /* [in] */, + uint8_t **buffer /* [out] [ref] */); #endif diff --git a/source3/lib/netapi/serverinfo.c b/source3/lib/netapi/serverinfo.c index a9749a12f9..e2a458cdc1 100644 --- a/source3/lib/netapi/serverinfo.c +++ b/source3/lib/netapi/serverinfo.c @@ -19,14 +19,16 @@ #include "includes.h" +#include "librpc/gen_ndr/libnetapi.h" #include "lib/netapi/netapi.h" +#include "lib/netapi/libnetapi.h" #include "libnet/libnet.h" /**************************************************************** ****************************************************************/ -static WERROR NetServerGetInfoLocal_1005(struct libnetapi_ctx *ctx, - uint8_t **buffer) +static WERROR NetServerGetInfo_l_1005(struct libnetapi_ctx *ctx, + uint8_t **buffer) { struct srvsvc_NetSrvInfo1005 info1005; @@ -42,14 +44,12 @@ static WERROR NetServerGetInfoLocal_1005(struct libnetapi_ctx *ctx, /**************************************************************** ****************************************************************/ -static WERROR NetServerGetInfoLocal(struct libnetapi_ctx *ctx, - const char *server_name, - uint32_t level, - uint8_t **buffer) +WERROR NetServerGetInfo_l(struct libnetapi_ctx *ctx, + struct NetServerGetInfo *r) { - switch (level) { + switch (r->in.level) { case 1005: - return NetServerGetInfoLocal_1005(ctx, buffer); + return NetServerGetInfo_l_1005(ctx, r->out.buffer); default: return WERR_UNKNOWN_LEVEL; } @@ -60,10 +60,8 @@ static WERROR NetServerGetInfoLocal(struct libnetapi_ctx *ctx, /**************************************************************** ****************************************************************/ -static WERROR NetServerGetInfoRemote(struct libnetapi_ctx *ctx, - const char *server_name, - uint32_t level, - uint8_t **buffer) +WERROR NetServerGetInfo_r(struct libnetapi_ctx *ctx, + struct NetServerGetInfo *r) { struct cli_state *cli = NULL; struct rpc_pipe_client *pipe_cli = NULL; @@ -71,7 +69,7 @@ static WERROR NetServerGetInfoRemote(struct libnetapi_ctx *ctx, WERROR werr; union srvsvc_NetSrvInfo info; - status = cli_full_connection(&cli, NULL, server_name, + status = cli_full_connection(&cli, NULL, r->in.server_name, NULL, 0, "IPC$", "IPC", ctx->username, @@ -92,8 +90,8 @@ static WERROR NetServerGetInfoRemote(struct libnetapi_ctx *ctx, }; status = rpccli_srvsvc_NetSrvGetInfo(pipe_cli, ctx, - server_name, - level, + r->in.server_name, + r->in.level, &info, &werr); if (!NT_STATUS_IS_OK(status)) { @@ -101,7 +99,11 @@ static WERROR NetServerGetInfoRemote(struct libnetapi_ctx *ctx, goto done; } - *buffer = (uint8_t *)&info; + *r->out.buffer = talloc_memdup(ctx, &info, sizeof(info)); + if (!*r->out.buffer) { + werr = WERR_NOMEM; + goto done; + } done: if (cli) { @@ -114,73 +116,22 @@ static WERROR NetServerGetInfoRemote(struct libnetapi_ctx *ctx, /**************************************************************** ****************************************************************/ -static WERROR libnetapi_NetServerGetInfo(struct libnetapi_ctx *ctx, - const char *server_name, - uint32_t level, - uint8_t **buffer) -{ - if (!server_name || is_myname_or_ipaddr(server_name)) { - return NetServerGetInfoLocal(ctx, - server_name, - level, - buffer); - } - - return NetServerGetInfoRemote(ctx, - server_name, - level, - buffer); - -} - -/**************************************************************** - NetServerGetInfo -****************************************************************/ - -NET_API_STATUS NetServerGetInfo(const char *server_name, - uint32_t level, - uint8_t **buffer) -{ - struct libnetapi_ctx *ctx = NULL; - NET_API_STATUS status; - WERROR werr; - - status = libnetapi_getctx(&ctx); - if (status != 0) { - return status; - } - - werr = libnetapi_NetServerGetInfo(ctx, - server_name, - level, - buffer); - if (!W_ERROR_IS_OK(werr)) { - return W_ERROR_V(werr); - } - - return NET_API_STATUS_SUCCESS; -} - -/**************************************************************** -****************************************************************/ - -static WERROR NetServerSetInfoLocal_1005(struct libnetapi_ctx *ctx, - uint8_t *buffer, - uint32_t *parm_error) +static WERROR NetServerSetInfo_l_1005(struct libnetapi_ctx *ctx, + struct NetServerSetInfo *r) { WERROR werr; struct smbconf_ctx *conf_ctx; struct srvsvc_NetSrvInfo1005 *info1005; - if (!buffer) { - *parm_error = 1005; /* sure here ? */ + if (!r->in.buffer) { + *r->out.parm_error = 1005; /* sure here ? */ return WERR_INVALID_PARAM; } - info1005 = (struct srvsvc_NetSrvInfo1005 *)buffer; + info1005 = (struct srvsvc_NetSrvInfo1005 *)r->in.buffer; if (!info1005->comment) { - *parm_error = 1005; + *r->out.parm_error = 1005; return WERR_INVALID_PARAM; } @@ -207,15 +158,12 @@ static WERROR NetServerSetInfoLocal_1005(struct libnetapi_ctx *ctx, /**************************************************************** ****************************************************************/ -static WERROR NetServerSetInfoLocal(struct libnetapi_ctx *ctx, - const char *server_name, - uint32_t level, - uint8_t *buffer, - uint32_t *parm_error) +WERROR NetServerSetInfo_l(struct libnetapi_ctx *ctx, + struct NetServerSetInfo *r) { - switch (level) { + switch (r->in.level) { case 1005: - return NetServerSetInfoLocal_1005(ctx, buffer, parm_error); + return NetServerSetInfo_l_1005(ctx, r); default: return WERR_UNKNOWN_LEVEL; } @@ -226,11 +174,8 @@ static WERROR NetServerSetInfoLocal(struct libnetapi_ctx *ctx, /**************************************************************** ****************************************************************/ -static WERROR NetServerSetInfoRemote(struct libnetapi_ctx *ctx, - const char *server_name, - uint32_t level, - uint8_t *buffer, - uint32_t *parm_error) +WERROR NetServerSetInfo_r(struct libnetapi_ctx *ctx, + struct NetServerSetInfo *r) { struct cli_state *cli = NULL; struct rpc_pipe_client *pipe_cli = NULL; @@ -238,7 +183,7 @@ static WERROR NetServerSetInfoRemote(struct libnetapi_ctx *ctx, WERROR werr; union srvsvc_NetSrvInfo info; - status = cli_full_connection(&cli, NULL, server_name, + status = cli_full_connection(&cli, NULL, r->in.server_name, NULL, 0, "IPC$", "IPC", ctx->username, @@ -258,9 +203,9 @@ static WERROR NetServerSetInfoRemote(struct libnetapi_ctx *ctx, goto done; }; - switch (level) { + switch (r->in.level) { case 1005: - info.info1005 = (struct srvsvc_NetSrvInfo1005 *)buffer; + info.info1005 = (struct srvsvc_NetSrvInfo1005 *)r->in.buffer; break; default: werr = WERR_NOT_SUPPORTED; @@ -268,10 +213,10 @@ static WERROR NetServerSetInfoRemote(struct libnetapi_ctx *ctx, } status = rpccli_srvsvc_NetSrvSetInfo(pipe_cli, ctx, - server_name, - level, + r->in.server_name, + r->in.level, &info, - parm_error, + r->out.parm_error, &werr); if (!NT_STATUS_IS_OK(status)) { werr = ntstatus_to_werror(status); @@ -285,57 +230,3 @@ static WERROR NetServerSetInfoRemote(struct libnetapi_ctx *ctx, return werr; } - -/**************************************************************** -****************************************************************/ - -static WERROR libnetapi_NetServerSetInfo(struct libnetapi_ctx *ctx, - const char *server_name, - uint32_t level, - uint8_t *buffer, - uint32_t *parm_error) -{ - if (!server_name || is_myname_or_ipaddr(server_name)) { - return NetServerSetInfoLocal(ctx, - server_name, - level, - buffer, - parm_error); - } - - return NetServerSetInfoRemote(ctx, - server_name, - level, - buffer, - parm_error); -} - -/**************************************************************** - NetServerSetInfo -****************************************************************/ - -NET_API_STATUS NetServerSetInfo(const char *server_name, - uint32_t level, - uint8_t *buffer, - uint32_t *parm_error) -{ - struct libnetapi_ctx *ctx = NULL; - NET_API_STATUS status; - WERROR werr; - - status = libnetapi_getctx(&ctx); - if (status != 0) { - return status; - } - - werr = libnetapi_NetServerSetInfo(ctx, - server_name, - level, - buffer, - parm_error); - if (!W_ERROR_IS_OK(werr)) { - return W_ERROR_V(werr); - } - - return NET_API_STATUS_SUCCESS; -} -- cgit From 0f86cc18ff2e88a0f1fe244574ff5e3fcfce2f92 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 8 Apr 2008 14:29:21 +0200 Subject: Prefill in username in libnetapi ctx. Guenther (This used to be commit 394bdb89ef350db0ab6aca093054e1048a8ffe1f) --- source3/lib/netapi/netapi.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi.c b/source3/lib/netapi/netapi.c index 82a8a8d3cd..fbec2757f0 100644 --- a/source3/lib/netapi/netapi.c +++ b/source3/lib/netapi/netapi.c @@ -81,6 +81,13 @@ NET_API_STATUS libnetapi_init(struct libnetapi_ctx **context) setenv(KRB5_ENV_CCNAME, ctx->krb5_cc_env, 1); } + ctx->username = talloc_strdup(frame, getenv("USER")); + if (!ctx->username) { + TALLOC_FREE(frame); + fprintf(stderr, "out of memory\n"); + return W_ERROR_V(WERR_NOMEM); + } + libnetapi_initialized = true; *context = stat_ctx = ctx; @@ -162,7 +169,8 @@ NET_API_STATUS libnetapi_set_username(struct libnetapi_ctx *ctx, const char *username) { TALLOC_FREE(ctx->username); - ctx->username = talloc_strdup(ctx, username); + ctx->username = talloc_strdup(ctx, username ? username : ""); + if (!ctx->username) { return W_ERROR_V(WERR_NOMEM); } -- cgit From cccaef9e0896e9a3fcf9b860283543fd35d3f248 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 8 Apr 2008 14:34:30 +0200 Subject: Use popt in libetapi example code. Guenther (This used to be commit 6f239df3f5a57c9549f1637e53fd42d2ed604c3f) --- source3/lib/netapi/examples/Makefile.in | 15 ++-- source3/lib/netapi/examples/common.c | 58 +++++++++++++ source3/lib/netapi/examples/common.h | 11 +++ source3/lib/netapi/examples/getdc/getdc.c | 45 ++++++++-- .../examples/getjoinableous/getjoinableous.c | 76 ++++++++--------- .../lib/netapi/examples/netdomjoin/netdomjoin.c | 96 +++++++++------------- 6 files changed, 187 insertions(+), 114 deletions(-) create mode 100644 source3/lib/netapi/examples/common.c create mode 100644 source3/lib/netapi/examples/common.h (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/Makefile.in b/source3/lib/netapi/examples/Makefile.in index 000eef118b..9020d60224 100644 --- a/source3/lib/netapi/examples/Makefile.in +++ b/source3/lib/netapi/examples/Makefile.in @@ -10,6 +10,8 @@ CC=@CC@ PICFLAG=@PICFLAG@ LDFLAGS=@PIE_LDFLAGS@ @LDFLAGS@ DYNEXP=@DYNEXP@ +NETAPI_LIBS=$(LIBS) $(KRB5LIBS) $(LDAP_LIBS) +CMDLINE_LIBS=$(NETAPI_LIBS) @POPTLIBS@ # Compile a source file. COMPILE_CC = $(CC) -I. $(FLAGS) $(PICFLAG) -c $< -o $@ @@ -46,22 +48,23 @@ bin/.dummy: echo "$(COMPILE_CC)" 1>&2;\ $(COMPILE_CC) >/dev/null 2>&1 -GETDC_OBJ = getdc/getdc.o -NETDOMJOIN_OBJ = netdomjoin/netdomjoin.o +CMDLINE_OBJ = common.o +GETDC_OBJ = getdc/getdc.o $(CMDLINE_OBJ) +NETDOMJOIN_OBJ = netdomjoin/netdomjoin.o $(CMDLINE_OBJ) NETDOMJOIN_GUI_OBJ = netdomjoin-gui/netdomjoin-gui.o -GETJOINABLEOUS_OBJ = getjoinableous/getjoinableous.o +GETJOINABLEOUS_OBJ = getjoinableous/getjoinableous.o $(CMDLINE_OBJ) bin/getdc@EXEEXT@: $(BINARY_PREREQS) $(GETDC_OBJ) @echo Linking $@ - @$(CC) $(FLAGS) -o $@ $(GETDC_OBJ) $(LDFLAGS) $(DYNEXP) $(LIBS) $(KRB5LIBS) $(LDAP_LIBS) + @$(CC) $(FLAGS) -o $@ $(GETDC_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) bin/getjoinableous@EXEEXT@: $(BINARY_PREREQS) $(GETJOINABLEOUS_OBJ) @echo Linking $@ - @$(CC) $(FLAGS) -o $@ $(GETJOINABLEOUS_OBJ) $(LDFLAGS) $(DYNEXP) $(LIBS) $(KRB5LIBS) $(LDAP_LIBS) + @$(CC) $(FLAGS) -o $@ $(GETJOINABLEOUS_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) bin/netdomjoin@EXEEXT@: $(BINARY_PREREQS) $(NETDOMJOIN_OBJ) @echo Linking $@ - @$(CC) $(FLAGS) -o $@ $(NETDOMJOIN_OBJ) $(LDFLAGS) $(DYNEXP) $(LIBS) $(KRB5LIBS) $(LDAP_LIBS) + @$(CC) $(FLAGS) -o $@ $(NETDOMJOIN_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) bin/netdomjoin-gui@EXEEXT@: $(BINARY_PREREQS) $(NETDOMJOIN_GUI_OBJ) @echo Linking $@ diff --git a/source3/lib/netapi/examples/common.c b/source3/lib/netapi/examples/common.c new file mode 100644 index 0000000000..db9ab0a2c9 --- /dev/null +++ b/source3/lib/netapi/examples/common.c @@ -0,0 +1,58 @@ +#include +#include +#include +#include + +void popt_common_callback(poptContext con, + enum poptCallbackReason reason, + const struct poptOption *opt, + const char *arg, const void *data) +{ + struct libnetapi_ctx *ctx = NULL; + + libnetapi_getctx(&ctx); + + if (reason == POPT_CALLBACK_REASON_PRE) { + } + + if (reason == POPT_CALLBACK_REASON_POST) { + } + + if (!opt) { + return; + } + switch (opt->val) { + case 'U': { + char *puser = strdup(arg); + char *p = NULL; + + if ((p = strchr(puser,'%'))) { + size_t len; + *p = 0; + libnetapi_set_username(ctx, puser); + libnetapi_set_password(ctx, p+1); + len = strlen(p+1); + memset(strchr(arg,'%')+1,'X',len); + } else { + libnetapi_set_username(ctx, puser); + } + free(puser); + break; + } + case 'd': + libnetapi_set_debuglevel(ctx, arg); + break; + case 'p': + libnetapi_set_password(ctx, arg); + break; + } +} + +struct poptOption popt_common_netapi_examples[] = { + { NULL, 0, POPT_ARG_CALLBACK|POPT_CBFLAG_PRE|POPT_CBFLAG_POST, (void *)popt_common_callback }, + { "user", 'U', POPT_ARG_STRING, NULL, 'U', "Username used for connection", "USERNAME" }, + { "password", 'p', POPT_ARG_STRING, NULL, 'p', "Password used for connection", "PASSWORD" }, + { "debuglevel", 'd', POPT_ARG_STRING, NULL, 'd', "Debuglevel", "DEBUGLEVEL" }, + POPT_TABLEEND +}; + diff --git a/source3/lib/netapi/examples/common.h b/source3/lib/netapi/examples/common.h new file mode 100644 index 0000000000..85df51d868 --- /dev/null +++ b/source3/lib/netapi/examples/common.h @@ -0,0 +1,11 @@ +#include + +void popt_common_callback(poptContext con, + enum poptCallbackReason reason, + const struct poptOption *opt, + const char *arg, const void *data); + +extern struct poptOption popt_common_netapi_examples[]; + +#define POPT_COMMON_LIBNETAPI_EXAMPLES { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_netapi_examples, 0, "Common samba netapi example options:", NULL }, + diff --git a/source3/lib/netapi/examples/getdc/getdc.c b/source3/lib/netapi/examples/getdc/getdc.c index 272ba1088e..98bb6a13b2 100644 --- a/source3/lib/netapi/examples/getdc/getdc.c +++ b/source3/lib/netapi/examples/getdc/getdc.c @@ -25,33 +25,62 @@ #include -int main(int argc, char **argv) +#include "common.h" + +int main(int argc, const char **argv) { NET_API_STATUS status; struct libnetapi_ctx *ctx = NULL; + + const char *hostname = NULL; + const char *domain = NULL; uint8_t *buffer = NULL; - if (argc < 3) { - printf("usage: getdc \n"); - return -1; - } + poptContext pc; + int opt; + + struct poptOption long_options[] = { + POPT_AUTOHELP + POPT_COMMON_LIBNETAPI_EXAMPLES + POPT_TABLEEND + }; status = libnetapi_init(&ctx); if (status != 0) { return status; } - libnetapi_set_username(ctx, ""); - libnetapi_set_password(ctx, ""); + pc = poptGetContext("getdc", argc, argv, long_options, 0); + + poptSetOtherOptionHelp(pc, "hostname domainname"); + while((opt = poptGetNextOpt(pc)) != -1) { + } + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + hostname = poptGetArg(pc); + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + domain = poptGetArg(pc); + + /* NetGetDCName */ - status = NetGetDCName(argv[1], argv[2], &buffer); + status = NetGetDCName(hostname, domain, &buffer); if (status != 0) { printf("GetDcName failed with: %s\n", libnetapi_errstr(status)); } else { printf("%s\n", (char *)buffer); } + + out: NetApiBufferFree(buffer); libnetapi_free(ctx); + poptFreeContext(pc); return status; } diff --git a/source3/lib/netapi/examples/getjoinableous/getjoinableous.c b/source3/lib/netapi/examples/getjoinableous/getjoinableous.c index be95198bcf..732f73dd57 100644 --- a/source3/lib/netapi/examples/getjoinableous/getjoinableous.c +++ b/source3/lib/netapi/examples/getjoinableous/getjoinableous.c @@ -19,72 +19,61 @@ #include #include +#include #include #include -char *get_string_param(const char *param) -{ - char *p; - - p = strchr(param, '='); - if (!p) { - return NULL; - } - - return (p+1); -} +#include "common.h" -int main(int argc, char **argv) +int main(int argc, const char **argv) { NET_API_STATUS status; - const char *server_name = NULL; + const char *host_name = NULL; const char *domain_name = NULL; - const char *account = NULL; - const char *password = NULL; const char **ous = NULL; uint32_t num_ous = 0; struct libnetapi_ctx *ctx = NULL; int i; + poptContext pc; + int opt; + + struct poptOption long_options[] = { + POPT_AUTOHELP + { "domain", 0, POPT_ARG_STRING, NULL, 'D', "Domain name", "DOMAIN" }, + POPT_COMMON_LIBNETAPI_EXAMPLES + POPT_TABLEEND + }; + status = libnetapi_init(&ctx); if (status != 0) { return status; } - if (argc < 2) { - printf("usage: getjoinableous\n"); - printf("\t [domain=DOMAIN] \n"); - return 0; - } + pc = poptGetContext("getjoinableous", argc, argv, long_options, 0); - if (argc > 2) { - server_name = argv[1]; + poptSetOtherOptionHelp(pc, "hostname domainname"); + while((opt = poptGetNextOpt(pc)) != -1) { + switch (opt) { + case 'D': + domain_name = poptGetOptArg(pc); + break; + } } - for (i=0; iusername, + ctx->password, &num_ous, &ous); if (status != 0) { @@ -97,9 +86,10 @@ int main(int argc, char **argv) } } + out: NetApiBufferFree(ous); - libnetapi_free(ctx); + poptFreeContext(pc); return status; } diff --git a/source3/lib/netapi/examples/netdomjoin/netdomjoin.c b/source3/lib/netapi/examples/netdomjoin/netdomjoin.c index 29f66a17a2..bd7c36382a 100644 --- a/source3/lib/netapi/examples/netdomjoin/netdomjoin.c +++ b/source3/lib/netapi/examples/netdomjoin/netdomjoin.c @@ -25,96 +25,78 @@ #include -char *get_string_param(const char *param) -{ - char *p; +#include "common.h" - p = strchr(param, '='); - if (!p) { - return NULL; - } +enum { + OPT_OU = 1000 +}; - return (p+1); -} - -int main(int argc, char **argv) +int main(int argc, const char **argv) { NET_API_STATUS status; - const char *server_name = NULL; + const char *host_name = NULL; const char *domain_name = NULL; const char *account_ou = NULL; - const char *Account = NULL; + const char *account = NULL; const char *password = NULL; - uint32_t join_flags = 3; + uint32_t join_flags = 0x00000023; struct libnetapi_ctx *ctx = NULL; - int i; + + poptContext pc; + int opt; + + struct poptOption long_options[] = { + POPT_AUTOHELP + { "ou", 0, POPT_ARG_STRING, &account_ou, 'U', "Account ou", "ACCOUNT_OU" }, + { "domain", 0, POPT_ARG_STRING, &domain_name, 'U', "Domain name (required)", "DOMAIN" }, + { "userd", 0, POPT_ARG_STRING, &account, 'U', "Domain admin account", "USERNAME" }, + { "passwordd", 0, POPT_ARG_STRING, &password, 'U', "Domain admin password", "PASSWORD" }, + POPT_COMMON_LIBNETAPI_EXAMPLES + POPT_TABLEEND + }; + status = libnetapi_init(&ctx); if (status != 0) { return status; } - if (argc < 2) { - printf("usage: netdomjoin\n"); - printf("\t[hostname] [domain=DOMAIN] " - " " - " " - "\n"); - return 0; + pc = poptGetContext("netdomjoin", argc, argv, long_options, 0); + + poptSetOtherOptionHelp(pc, "hostname"); + while((opt = poptGetNextOpt(pc)) != -1) { } - if (argc > 2) { - server_name = argv[1]; + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; } + host_name = poptGetArg(pc); - for (i=0; i Date: Tue, 8 Apr 2008 17:17:17 +0200 Subject: Fix includes in libnetapi examples common.c Guenther (This used to be commit 922ff9d01668c2c2ad10decfd09c0e7b3f0d7592) --- source3/lib/netapi/examples/common.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/common.c b/source3/lib/netapi/examples/common.c index db9ab0a2c9..2c3e4d711d 100644 --- a/source3/lib/netapi/examples/common.c +++ b/source3/lib/netapi/examples/common.c @@ -1,7 +1,10 @@ #include #include -#include +#include +#include + #include +#include void popt_common_callback(poptContext con, enum poptCallbackReason reason, -- cgit From 05202a5d4ef3326db3d43feff2bef5271850296b Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 8 Apr 2008 18:43:51 +0200 Subject: Add DsGetDcName call to libnetapi library. Guenther (This used to be commit 27780e984152e38c8f80e1c67ddf13b73a2b220d) --- source3/lib/netapi/getdc.c | 76 ++++++++++++++++++++++++++++++++++++++++++ source3/lib/netapi/libnetapi.c | 50 +++++++++++++++++++++++++++ source3/lib/netapi/libnetapi.h | 10 ++++++ source3/lib/netapi/netapi.h | 42 +++++++++++++++++++++++ 4 files changed, 178 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/getdc.c b/source3/lib/netapi/getdc.c index f6a666d70d..9ad935efd8 100644 --- a/source3/lib/netapi/getdc.c +++ b/source3/lib/netapi/getdc.c @@ -133,3 +133,79 @@ WERROR NetGetAnyDCName_r(struct libnetapi_ctx *ctx, return werr; } + +/******************************************************************** +********************************************************************/ + +WERROR DsGetDcName_l(struct libnetapi_ctx *ctx, + struct DsGetDcName *r) +{ + NTSTATUS status; + + status = dsgetdcname(ctx, + r->in.domain_name, + r->in.domain_guid, + r->in.site_name, + r->in.flags, + (struct netr_DsRGetDCNameInfo **)r->out.dc_info); + if (!NT_STATUS_IS_OK(status)) { + libnetapi_set_error_string(ctx, + "failed to find DC: %s", + get_friendly_nt_error_msg(status)); + } + + return ntstatus_to_werror(status); +} + +/******************************************************************** +********************************************************************/ + +WERROR DsGetDcName_r(struct libnetapi_ctx *ctx, + struct DsGetDcName *r) +{ + WERROR werr; + NTSTATUS status = NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND; + struct cli_state *cli = NULL; + struct rpc_pipe_client *pipe_cli = NULL; + + status = cli_full_connection(&cli, NULL, r->in.server_name, + NULL, 0, + "IPC$", "IPC", + ctx->username, + ctx->workgroup, + ctx->password, + 0, Undefined, NULL); + + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + pipe_cli = cli_rpc_pipe_open_noauth(cli, PI_NETLOGON, + &status); + if (!pipe_cli) { + werr = ntstatus_to_werror(status); + goto done; + } + + status = rpccli_netr_DsRGetDCName(pipe_cli, + ctx, + r->in.server_name, + r->in.domain_name, + r->in.domain_guid, + NULL, + r->in.flags, + (struct netr_DsRGetDCNameInfo **)r->out.dc_info, + &werr); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + done: + if (cli) { + cli_shutdown(cli); + } + + return werr; +} diff --git a/source3/lib/netapi/libnetapi.c b/source3/lib/netapi/libnetapi.c index 9d42b7e97c..ed97df2143 100644 --- a/source3/lib/netapi/libnetapi.c +++ b/source3/lib/netapi/libnetapi.c @@ -391,3 +391,53 @@ NET_API_STATUS NetGetAnyDCName(const char * server_name /* [in] [unique] */, return r.out.result; } +/**************************************************************** + DsGetDcName +****************************************************************/ + +NET_API_STATUS DsGetDcName(const char * server_name /* [in] [unique] */, + const char * domain_name /* [in] [ref] */, + struct GUID *domain_guid /* [in] [unique] */, + const char * site_name /* [in] [unique] */, + uint32_t flags /* [in] */, + struct DOMAIN_CONTROLLER_INFO **dc_info /* [out] [ref] */) +{ + struct DsGetDcName r; + struct libnetapi_ctx *ctx = NULL; + NET_API_STATUS status; + WERROR werr; + + status = libnetapi_getctx(&ctx); + if (status != 0) { + return status; + } + + /* In parameters */ + r.in.server_name = server_name; + r.in.domain_name = domain_name; + r.in.domain_guid = domain_guid; + r.in.site_name = site_name; + r.in.flags = flags; + + /* Out parameters */ + r.out.dc_info = dc_info; + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_IN_DEBUG(DsGetDcName, &r); + } + + if (LIBNETAPI_LOCAL_SERVER(server_name)) { + werr = DsGetDcName_l(ctx, &r); + } else { + werr = DsGetDcName_r(ctx, &r); + } + + r.out.result = W_ERROR_V(werr); + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_OUT_DEBUG(DsGetDcName, &r); + } + + return r.out.result; +} + diff --git a/source3/lib/netapi/libnetapi.h b/source3/lib/netapi/libnetapi.h index a215c84cb3..99c5295c56 100644 --- a/source3/lib/netapi/libnetapi.h +++ b/source3/lib/netapi/libnetapi.h @@ -64,4 +64,14 @@ WERROR NetGetAnyDCName_r(struct libnetapi_ctx *ctx, struct NetGetAnyDCName *r); WERROR NetGetAnyDCName_l(struct libnetapi_ctx *ctx, struct NetGetAnyDCName *r); +NET_API_STATUS DsGetDcName(const char * server_name /* [in] [unique] */, + const char * domain_name /* [in] [ref] */, + struct GUID *domain_guid /* [in] [unique] */, + const char * site_name /* [in] [unique] */, + uint32_t flags /* [in] */, + struct DOMAIN_CONTROLLER_INFO **dc_info /* [out] [ref] */); +WERROR DsGetDcName_r(struct libnetapi_ctx *ctx, + struct DsGetDcName *r); +WERROR DsGetDcName_l(struct libnetapi_ctx *ctx, + struct DsGetDcName *r); #endif /* __LIBNETAPI_LIBNETAPI__ */ diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h index 87126fbacf..68f23720ff 100644 --- a/source3/lib/netapi/netapi.h +++ b/source3/lib/netapi/netapi.h @@ -31,6 +31,37 @@ typedef enum { /**************************************************************** ****************************************************************/ +#ifndef _HEADER_misc + +struct GUID { + uint32_t time_low; + uint16_t time_mid; + uint16_t time_hi_and_version; + uint8_t clock_seq[2]; + uint8_t node[6]; +}; + +#endif /* _HEADER_misc */ + +#ifndef _HEADER_libnetapi + +struct DOMAIN_CONTROLLER_INFO { + const char * domain_controller_name; + const char * domain_controller_address; + uint32_t domain_controller_address_type; + struct GUID domain_guid; + const char * domain_name; + const char * dns_foreset_name; + uint32_t flags; + const char * dc_site_name; + const char * client_site_name; +}; + +#endif /* _HEADER_libnetapi */ + +/**************************************************************** +****************************************************************/ + struct libnetapi_ctx { char *debuglevel; char *error_string; @@ -134,4 +165,15 @@ NET_API_STATUS NetGetAnyDCName(const char * server_name /* [in] */, const char * domain_name /* [in] */, uint8_t **buffer /* [out] [ref] */); + +/**************************************************************** + DsGetDcName +****************************************************************/ + +NET_API_STATUS DsGetDcName(const char * server_name /* [in] [unique] */, + const char * domain_name /* [in] [ref] */, + struct GUID *domain_guid /* [in] [unique] */, + const char * site_name /* [in] [unique] */, + uint32_t flags /* [in] */, + struct DOMAIN_CONTROLLER_INFO **dc_info /* [out] [ref] */); #endif -- cgit From 298824357a5b94e92b6fb76fb02f2ebecf9e1a35 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 8 Apr 2008 18:45:26 +0200 Subject: Add DsGetDcName libnetapi example. Guenther (This used to be commit 0216e55fa87a14fc45c320268f0511eb6638460b) --- source3/lib/netapi/examples/Makefile.in | 6 ++ source3/lib/netapi/examples/dsgetdc/dsgetdc.c | 89 +++++++++++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 source3/lib/netapi/examples/dsgetdc/dsgetdc.c (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/Makefile.in b/source3/lib/netapi/examples/Makefile.in index 9020d60224..b60437de37 100644 --- a/source3/lib/netapi/examples/Makefile.in +++ b/source3/lib/netapi/examples/Makefile.in @@ -18,6 +18,7 @@ COMPILE_CC = $(CC) -I. $(FLAGS) $(PICFLAG) -c $< -o $@ COMPILE = $(COMPILE_CC) PROGS = bin/getdc@EXEEXT@ \ + bin/dsgetdc@EXEEXT@ \ bin/netdomjoin@EXEEXT@ \ bin/netdomjoin-gui@EXEEXT@ \ bin/getjoinableous@EXEEXT@ @@ -50,6 +51,7 @@ bin/.dummy: CMDLINE_OBJ = common.o GETDC_OBJ = getdc/getdc.o $(CMDLINE_OBJ) +DSGETDC_OBJ = dsgetdc/dsgetdc.o $(CMDLINE_OBJ) NETDOMJOIN_OBJ = netdomjoin/netdomjoin.o $(CMDLINE_OBJ) NETDOMJOIN_GUI_OBJ = netdomjoin-gui/netdomjoin-gui.o GETJOINABLEOUS_OBJ = getjoinableous/getjoinableous.o $(CMDLINE_OBJ) @@ -58,6 +60,10 @@ bin/getdc@EXEEXT@: $(BINARY_PREREQS) $(GETDC_OBJ) @echo Linking $@ @$(CC) $(FLAGS) -o $@ $(GETDC_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) +bin/dsgetdc@EXEEXT@: $(BINARY_PREREQS) $(DSGETDC_OBJ) + @echo Linking $@ + @$(CC) $(FLAGS) -o $@ $(DSGETDC_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) + bin/getjoinableous@EXEEXT@: $(BINARY_PREREQS) $(GETJOINABLEOUS_OBJ) @echo Linking $@ @$(CC) $(FLAGS) -o $@ $(GETJOINABLEOUS_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) diff --git a/source3/lib/netapi/examples/dsgetdc/dsgetdc.c b/source3/lib/netapi/examples/dsgetdc/dsgetdc.c new file mode 100644 index 0000000000..7c0ec4d57d --- /dev/null +++ b/source3/lib/netapi/examples/dsgetdc/dsgetdc.c @@ -0,0 +1,89 @@ +/* + * Unix SMB/CIFS implementation. + * DsGetDcName query + * Copyright (C) Guenther Deschner 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include +#include +#include +#include +#include + +#include + +#include "common.h" + +int main(int argc, const char **argv) +{ + NET_API_STATUS status; + struct libnetapi_ctx *ctx = NULL; + + const char *hostname = NULL; + const char *domain = NULL; + struct DOMAIN_CONTROLLER_INFO *info = NULL; + + poptContext pc; + int opt; + + struct poptOption long_options[] = { + POPT_AUTOHELP + POPT_COMMON_LIBNETAPI_EXAMPLES + POPT_TABLEEND + }; + + status = libnetapi_init(&ctx); + if (status != 0) { + return status; + } + + pc = poptGetContext("dsgetdc", argc, argv, long_options, 0); + + poptSetOtherOptionHelp(pc, "hostname domainname"); + while((opt = poptGetNextOpt(pc)) != -1) { + } + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + hostname = poptGetArg(pc); + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + domain = poptGetArg(pc); + + /* DsGetDcName */ + + status = DsGetDcName(hostname, domain, NULL, NULL, 0, &info); + if (status != 0) { + printf("DsGetDcName failed with: %s\n", + libnetapi_errstr(status)); + return status; + } + + printf("domain %s has name: %s\n", + info->domain_name, info->domain_controller_name); + + out: + NetApiBufferFree(info); + libnetapi_free(ctx); + poptFreeContext(pc); + + return status; +} -- cgit From af19343df8f3ac733538bed37b983b9488a01ef8 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 8 Apr 2008 19:42:26 +0200 Subject: Try to use kerberos in libnetapi. Guenther (This used to be commit 9cfce2229508c2145c3527074ac76520544e5d25) --- source3/lib/netapi/getdc.c | 15 ++++++++++++--- source3/lib/netapi/joindomain.c | 16 ++++++++++++---- source3/lib/netapi/serverinfo.c | 8 ++++++-- 3 files changed, 30 insertions(+), 9 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/getdc.c b/source3/lib/netapi/getdc.c index 9ad935efd8..a865474019 100644 --- a/source3/lib/netapi/getdc.c +++ b/source3/lib/netapi/getdc.c @@ -50,7 +50,10 @@ WERROR NetGetDCName_r(struct libnetapi_ctx *ctx, ctx->username, ctx->workgroup, ctx->password, - 0, Undefined, NULL); + CLI_FULL_CONNECTION_USE_KERBEROS | + CLI_FULL_CONNECTION_FALLBACK_AFTER_KERBEROS | + CLI_FULL_CONNECTION_ANONYMOUS_FALLBACK, + Undefined, NULL); if (!NT_STATUS_IS_OK(status)) { werr = ntstatus_to_werror(status); @@ -103,7 +106,10 @@ WERROR NetGetAnyDCName_r(struct libnetapi_ctx *ctx, ctx->username, ctx->workgroup, ctx->password, - 0, Undefined, NULL); + CLI_FULL_CONNECTION_USE_KERBEROS | + CLI_FULL_CONNECTION_FALLBACK_AFTER_KERBEROS | + CLI_FULL_CONNECTION_ANONYMOUS_FALLBACK, + Undefined, NULL); if (!NT_STATUS_IS_OK(status)) { werr = ntstatus_to_werror(status); @@ -174,7 +180,10 @@ WERROR DsGetDcName_r(struct libnetapi_ctx *ctx, ctx->username, ctx->workgroup, ctx->password, - 0, Undefined, NULL); + CLI_FULL_CONNECTION_USE_KERBEROS | + CLI_FULL_CONNECTION_FALLBACK_AFTER_KERBEROS | + CLI_FULL_CONNECTION_ANONYMOUS_FALLBACK, + Undefined, NULL); if (!NT_STATUS_IS_OK(status)) { werr = ntstatus_to_werror(status); diff --git a/source3/lib/netapi/joindomain.c b/source3/lib/netapi/joindomain.c index 468360f146..48a6a91888 100644 --- a/source3/lib/netapi/joindomain.c +++ b/source3/lib/netapi/joindomain.c @@ -108,7 +108,9 @@ WERROR NetJoinDomain_r(struct libnetapi_ctx *ctx, ctx->username, ctx->workgroup, ctx->password, - 0, Undefined, NULL); + CLI_FULL_CONNECTION_USE_KERBEROS | + CLI_FULL_CONNECTION_FALLBACK_AFTER_KERBEROS, + Undefined, NULL); if (!NT_STATUS_IS_OK(status)) { werr = ntstatus_to_werror(status); @@ -248,7 +250,9 @@ WERROR NetUnjoinDomain_r(struct libnetapi_ctx *ctx, ctx->username, ctx->workgroup, ctx->password, - 0, Undefined, NULL); + CLI_FULL_CONNECTION_USE_KERBEROS | + CLI_FULL_CONNECTION_FALLBACK_AFTER_KERBEROS, + Undefined, NULL); if (!NT_STATUS_IS_OK(status)) { werr = ntstatus_to_werror(status); @@ -308,7 +312,9 @@ WERROR NetGetJoinInformation_r(struct libnetapi_ctx *ctx, ctx->username, ctx->workgroup, ctx->password, - 0, Undefined, NULL); + CLI_FULL_CONNECTION_USE_KERBEROS | + CLI_FULL_CONNECTION_FALLBACK_AFTER_KERBEROS, + Undefined, NULL); if (!NT_STATUS_IS_OK(status)) { werr = ntstatus_to_werror(status); @@ -450,7 +456,9 @@ WERROR NetGetJoinableOUs_r(struct libnetapi_ctx *ctx, ctx->username, ctx->workgroup, ctx->password, - 0, Undefined, NULL); + CLI_FULL_CONNECTION_USE_KERBEROS | + CLI_FULL_CONNECTION_FALLBACK_AFTER_KERBEROS, + Undefined, NULL); if (!NT_STATUS_IS_OK(status)) { werr = ntstatus_to_werror(status); diff --git a/source3/lib/netapi/serverinfo.c b/source3/lib/netapi/serverinfo.c index e2a458cdc1..7cc84f5367 100644 --- a/source3/lib/netapi/serverinfo.c +++ b/source3/lib/netapi/serverinfo.c @@ -75,7 +75,9 @@ WERROR NetServerGetInfo_r(struct libnetapi_ctx *ctx, ctx->username, ctx->workgroup, ctx->password, - 0, Undefined, NULL); + CLI_FULL_CONNECTION_USE_KERBEROS | + CLI_FULL_CONNECTION_FALLBACK_AFTER_KERBEROS, + Undefined, NULL); if (!NT_STATUS_IS_OK(status)) { werr = ntstatus_to_werror(status); @@ -189,7 +191,9 @@ WERROR NetServerSetInfo_r(struct libnetapi_ctx *ctx, ctx->username, ctx->workgroup, ctx->password, - 0, Undefined, NULL); + CLI_FULL_CONNECTION_USE_KERBEROS | + CLI_FULL_CONNECTION_FALLBACK_AFTER_KERBEROS, + Undefined, NULL); if (!NT_STATUS_IS_OK(status)) { werr = ntstatus_to_werror(status); -- cgit From 6b2ae8e9ffabfa61f48397bf27966fd87a39aff9 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 9 Apr 2008 12:38:22 +0200 Subject: Add NetUserAdd to libnetapi. Guenther (This used to be commit cb98996ed2ac93a0e15838048405772d2043021a) --- source3/lib/netapi/libnetapi.c | 46 ++++++ source3/lib/netapi/libnetapi.h | 8 + source3/lib/netapi/netapi.h | 24 +++ source3/lib/netapi/user.c | 358 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 436 insertions(+) create mode 100644 source3/lib/netapi/user.c (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/libnetapi.c b/source3/lib/netapi/libnetapi.c index ed97df2143..9d92dac39f 100644 --- a/source3/lib/netapi/libnetapi.c +++ b/source3/lib/netapi/libnetapi.c @@ -441,3 +441,49 @@ NET_API_STATUS DsGetDcName(const char * server_name /* [in] [unique] */, return r.out.result; } +/**************************************************************** + NetUserAdd +****************************************************************/ + +NET_API_STATUS NetUserAdd(const char * server_name /* [in] [unique] */, + uint32_t level /* [in] */, + uint8_t *buffer /* [in] [ref] */, + uint32_t *parm_error /* [out] [ref] */) +{ + struct NetUserAdd r; + struct libnetapi_ctx *ctx = NULL; + NET_API_STATUS status; + WERROR werr; + + status = libnetapi_getctx(&ctx); + if (status != 0) { + return status; + } + + /* In parameters */ + r.in.server_name = server_name; + r.in.level = level; + r.in.buffer = buffer; + + /* Out parameters */ + r.out.parm_error = parm_error; + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_IN_DEBUG(NetUserAdd, &r); + } + + if (LIBNETAPI_LOCAL_SERVER(server_name)) { + werr = NetUserAdd_l(ctx, &r); + } else { + werr = NetUserAdd_r(ctx, &r); + } + + r.out.result = W_ERROR_V(werr); + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_OUT_DEBUG(NetUserAdd, &r); + } + + return r.out.result; +} + diff --git a/source3/lib/netapi/libnetapi.h b/source3/lib/netapi/libnetapi.h index 99c5295c56..8e4e73bcd8 100644 --- a/source3/lib/netapi/libnetapi.h +++ b/source3/lib/netapi/libnetapi.h @@ -74,4 +74,12 @@ WERROR DsGetDcName_r(struct libnetapi_ctx *ctx, struct DsGetDcName *r); WERROR DsGetDcName_l(struct libnetapi_ctx *ctx, struct DsGetDcName *r); +NET_API_STATUS NetUserAdd(const char * server_name /* [in] [unique] */, + uint32_t level /* [in] */, + uint8_t *buffer /* [in] [ref] */, + uint32_t *parm_error /* [out] [ref] */); +WERROR NetUserAdd_r(struct libnetapi_ctx *ctx, + struct NetUserAdd *r); +WERROR NetUserAdd_l(struct libnetapi_ctx *ctx, + struct NetUserAdd *r); #endif /* __LIBNETAPI_LIBNETAPI__ */ diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h index 68f23720ff..f328f57946 100644 --- a/source3/lib/netapi/netapi.h +++ b/source3/lib/netapi/netapi.h @@ -57,6 +57,21 @@ struct DOMAIN_CONTROLLER_INFO { const char * client_site_name; }; +struct USER_INFO_0 { + const char * usri0_name; +}; + +struct USER_INFO_1 { + const char * usri1_name; + const char * usri1_password; + uint32_t usri1_password_age; + uint32_t usri1_priv; + const char * usri1_home_dir; + const char * usri1_comment; + uint32_t usri1_flags; + const char * usri1_script_path; +}; + #endif /* _HEADER_libnetapi */ /**************************************************************** @@ -176,4 +191,13 @@ NET_API_STATUS DsGetDcName(const char * server_name /* [in] [unique] */, const char * site_name /* [in] [unique] */, uint32_t flags /* [in] */, struct DOMAIN_CONTROLLER_INFO **dc_info /* [out] [ref] */); + +/**************************************************************** + NetUserAdd +****************************************************************/ + +NET_API_STATUS NetUserAdd(const char * server_name /* [in] */, + uint32_t level /* [in] */, + uint8_t *buffer /* [in] [ref] */, + uint32_t *parm_error /* [out] [ref] */); #endif diff --git a/source3/lib/netapi/user.c b/source3/lib/netapi/user.c new file mode 100644 index 0000000000..71f08c2b21 --- /dev/null +++ b/source3/lib/netapi/user.c @@ -0,0 +1,358 @@ +/* + * Unix SMB/CIFS implementation. + * NetApi User Support + * Copyright (C) Guenther Deschner 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include "includes.h" + +#include "librpc/gen_ndr/libnetapi.h" +#include "lib/netapi/netapi.h" +#include "lib/netapi/libnetapi.h" + +/**************************************************************** +****************************************************************/ + +WERROR NetUserAdd_l(struct libnetapi_ctx *ctx, + struct NetUserAdd *r) +{ + return WERR_NOT_SUPPORTED; +} + +/**************************************************************** +****************************************************************/ + +static void convert_USER_INFO_1_to_samr_user_info25(struct USER_INFO_1 *info1, + DATA_BLOB *user_session_key, + struct samr_UserInfo25 *info25) +{ + uint32_t fields_present = SAMR_FIELD_ACCT_FLAGS; + struct samr_LogonHours zero_logon_hours; + struct lsa_BinaryString zero_parameters; + uint32_t acct_flags = 0; + NTTIME password_age; + + ZERO_STRUCTP(info25); + ZERO_STRUCT(zero_logon_hours); + ZERO_STRUCT(zero_parameters); + + if (info1->usri1_name) { + fields_present |= SAMR_FIELD_FULL_NAME; + } + if (info1->usri1_password) { + fields_present |= SAMR_FIELD_PASSWORD; + } + if (info1->usri1_flags) { + fields_present |= SAMR_FIELD_ACCT_FLAGS; + } + if (info1->usri1_name) { + fields_present |= SAMR_FIELD_FULL_NAME; + } + if (info1->usri1_home_dir) { + fields_present |= SAMR_FIELD_HOME_DIRECTORY; + } + if (info1->usri1_script_path) { + fields_present |= SAMR_FIELD_LOGON_SCRIPT; + } + if (info1->usri1_comment) { + fields_present |= SAMR_FIELD_DESCRIPTION; + } + if (info1->usri1_password_age) { + fields_present |= SAMR_FIELD_FORCE_PWD_CHANGE; + } + + acct_flags |= info1->usri1_flags | ACB_NORMAL; + + unix_to_nt_time_abs(&password_age, info1->usri1_password_age); + + /* TODO: info1->usri1_priv */ + init_samr_user_info21(&info25->info, + 0, + 0, + 0, + 0, + 0, + password_age, + NULL, + info1->usri1_name, + info1->usri1_home_dir, + NULL, + info1->usri1_script_path, + NULL, + info1->usri1_comment, + NULL, + NULL, + &zero_parameters, + 0, + 0, + acct_flags, + fields_present, + zero_logon_hours, + 0, + 0, + 0, + 0, + 0, + 0, + 0); + + if (info1->usri1_password) { + uchar pwbuf[532]; + struct MD5Context ctx; + uint8_t confounder[16]; + DATA_BLOB confounded_session_key = data_blob(NULL, 16); + + encode_pw_buffer(pwbuf, info1->usri1_password, STR_UNICODE); + + generate_random_buffer((uint8_t *)confounder, 16); + + MD5Init(&ctx); + MD5Update(&ctx, confounder, 16); + MD5Update(&ctx, user_session_key->data, + user_session_key->length); + MD5Final(confounded_session_key.data, &ctx); + + SamOEMhashBlob(pwbuf, 516, &confounded_session_key); + memcpy(&pwbuf[516], confounder, 16); + + memcpy(info25->password.data, pwbuf, sizeof(pwbuf)); + data_blob_free(&confounded_session_key); + } +} + +/**************************************************************** +****************************************************************/ + +WERROR NetUserAdd_r(struct libnetapi_ctx *ctx, + struct NetUserAdd *r) +{ + struct cli_state *cli = NULL; + struct rpc_pipe_client *pipe_cli = NULL; + NTSTATUS status; + WERROR werr; + uint32_t resume_handle = 0; + uint32_t num_entries = 0; + POLICY_HND connect_handle, domain_handle, user_handle; + struct samr_SamArray *sam = NULL; + const char *domain_name = NULL; + struct lsa_String lsa_domain_name, lsa_account_name; + struct dom_sid2 *domain_sid = NULL; + struct samr_UserInfo25 info25; + union samr_UserInfo *user_info = NULL; + struct samr_PwInfo pw_info; + uint32_t access_granted = 0; + uint32_t rid = 0; + bool domain_found = true; + int i; + struct USER_INFO_1 *info1; + + ZERO_STRUCT(connect_handle); + ZERO_STRUCT(domain_handle); + ZERO_STRUCT(user_handle); + + if (!r->in.buffer) { + return WERR_INVALID_PARAM; + } + + switch (r->in.level) { + case 1: + info1 = (struct USER_INFO_1 *)r->in.buffer; + break; + case 2: + case 3: + case 4: + default: + werr = WERR_NOT_SUPPORTED; + goto done; + } + + status = cli_full_connection(&cli, NULL, r->in.server_name, + NULL, 0, + "IPC$", "IPC", + ctx->username, + ctx->workgroup, + ctx->password, + CLI_FULL_CONNECTION_USE_KERBEROS | + CLI_FULL_CONNECTION_FALLBACK_AFTER_KERBEROS, + Undefined, NULL); + + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + pipe_cli = cli_rpc_pipe_open_noauth(cli, PI_SAMR, &status); + if (!pipe_cli) { + werr = ntstatus_to_werror(status); + goto done; + } + + status = rpccli_try_samr_connects(pipe_cli, ctx, + SAMR_ACCESS_ENUM_DOMAINS | + SAMR_ACCESS_OPEN_DOMAIN, + &connect_handle); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + status = rpccli_samr_EnumDomains(pipe_cli, ctx, + &connect_handle, + &resume_handle, + &sam, + 0xffffffff, + &num_entries); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + for (i=0; ientries[i].name.string; + + if (strequal(domain_name, builtin_domain_name())) { + continue; + } + + domain_found = true; + break; + } + + if (!domain_found) { + werr = WERR_NO_SUCH_DOMAIN; + goto done; + } + + init_lsa_String(&lsa_domain_name, domain_name); + + status = rpccli_samr_LookupDomain(pipe_cli, ctx, + &connect_handle, + &lsa_domain_name, + &domain_sid); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + status = rpccli_samr_OpenDomain(pipe_cli, ctx, + &connect_handle, + SAMR_DOMAIN_ACCESS_LOOKUP_INFO_1 | + SAMR_DOMAIN_ACCESS_CREATE_USER | + SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, + domain_sid, + &domain_handle); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + init_lsa_String(&lsa_account_name, info1->usri1_name); + + status = rpccli_samr_CreateUser2(pipe_cli, ctx, + &domain_handle, + &lsa_account_name, + ACB_NORMAL, + SEC_STD_WRITE_DAC | + SEC_STD_DELETE | + SAMR_USER_ACCESS_SET_PASSWORD | + SAMR_USER_ACCESS_SET_ATTRIBUTES | + SAMR_USER_ACCESS_GET_ATTRIBUTES, + &user_handle, + &access_granted, + &rid); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + status = rpccli_samr_QueryUserInfo(pipe_cli, ctx, + &user_handle, + 16, + &user_info); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + if (!(user_info->info16.acct_flags & ACB_NORMAL)) { + werr = WERR_INVALID_PARAM; + goto done; + } + + status = rpccli_samr_GetUserPwInfo(pipe_cli, ctx, + &user_handle, + &pw_info); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + ZERO_STRUCTP(user_info); + + convert_USER_INFO_1_to_samr_user_info25(info1, + &cli->user_session_key, + &info25); + + if (info1->usri1_password) { + user_info->info25 = info25; + status = rpccli_samr_SetUserInfo2(pipe_cli, ctx, + &user_handle, + 25, + user_info); + } else { + user_info->info21 = info25.info; + status = rpccli_samr_SetUserInfo(pipe_cli, ctx, + &user_handle, + 21, + user_info); + + } + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto failed; + } + + werr = WERR_OK; + goto done; + + failed: + status = rpccli_samr_DeleteUser(pipe_cli, ctx, + &user_handle); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + done: + if (!cli) { + return werr; + } + + if (is_valid_policy_hnd(&user_handle)) { + rpccli_samr_Close(pipe_cli, ctx, &user_handle); + } + if (is_valid_policy_hnd(&domain_handle)) { + rpccli_samr_Close(pipe_cli, ctx, &domain_handle); + } + if (is_valid_policy_hnd(&connect_handle)) { + rpccli_samr_Close(pipe_cli, ctx, &connect_handle); + } + + cli_shutdown(cli); + + return werr; +} -- cgit From 41c8597ae309aa1e2573b7474f4d8bed46491261 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 9 Apr 2008 13:28:30 +0200 Subject: Add NetUserAdd example. Guenther (This used to be commit 0d795606655a67d79c8c3bb2f3676ca7ee28f347) --- source3/lib/netapi/examples/Makefile.in | 8 ++- source3/lib/netapi/examples/user/user_add.c | 103 ++++++++++++++++++++++++++++ 2 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 source3/lib/netapi/examples/user/user_add.c (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/Makefile.in b/source3/lib/netapi/examples/Makefile.in index b60437de37..0e074b6972 100644 --- a/source3/lib/netapi/examples/Makefile.in +++ b/source3/lib/netapi/examples/Makefile.in @@ -21,7 +21,8 @@ PROGS = bin/getdc@EXEEXT@ \ bin/dsgetdc@EXEEXT@ \ bin/netdomjoin@EXEEXT@ \ bin/netdomjoin-gui@EXEEXT@ \ - bin/getjoinableous@EXEEXT@ + bin/getjoinableous@EXEEXT@ \ + bin/user_add@EXEEXT@ all: $(PROGS) @@ -55,6 +56,7 @@ DSGETDC_OBJ = dsgetdc/dsgetdc.o $(CMDLINE_OBJ) NETDOMJOIN_OBJ = netdomjoin/netdomjoin.o $(CMDLINE_OBJ) NETDOMJOIN_GUI_OBJ = netdomjoin-gui/netdomjoin-gui.o GETJOINABLEOUS_OBJ = getjoinableous/getjoinableous.o $(CMDLINE_OBJ) +USERADD_OBJ = user/user_add.o $(CMDLINE_OBJ) bin/getdc@EXEEXT@: $(BINARY_PREREQS) $(GETDC_OBJ) @echo Linking $@ @@ -76,6 +78,10 @@ bin/netdomjoin-gui@EXEEXT@: $(BINARY_PREREQS) $(NETDOMJOIN_GUI_OBJ) @echo Linking $@ @$(CC) $(FLAGS) $(GTK_FLAGS) -o $@ $(NETDOMJOIN_GUI_OBJ) $(LDFLAGS) $(DYNEXP) $(LIBS) $(KRB5LIBS) $(LDAP_LIBS) $(GTK_LIBS) +bin/user_add@EXEEXT@: $(BINARY_PREREQS) $(USERADD_OBJ) + @echo Linking $@ + @$(CC) $(FLAGS) -o $@ $(USERADD_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) + clean: -rm -f $(PROGS) -rm -f core */*~ *~ \ diff --git a/source3/lib/netapi/examples/user/user_add.c b/source3/lib/netapi/examples/user/user_add.c new file mode 100644 index 0000000000..5452f77bb7 --- /dev/null +++ b/source3/lib/netapi/examples/user/user_add.c @@ -0,0 +1,103 @@ +/* + * Unix SMB/CIFS implementation. + * NetUserAdd query + * Copyright (C) Guenther Deschner 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include +#include +#include +#include +#include + +#include + +#include "common.h" + +int main(int argc, const char **argv) +{ + NET_API_STATUS status; + struct libnetapi_ctx *ctx = NULL; + const char *hostname = NULL; + const char *username = NULL; + const char *password = NULL; + struct USER_INFO_1 info1; + uint32_t parm_error = 0; + + poptContext pc; + int opt; + + struct poptOption long_options[] = { + POPT_AUTOHELP + POPT_COMMON_LIBNETAPI_EXAMPLES + POPT_TABLEEND + }; + + status = libnetapi_init(&ctx); + if (status != 0) { + return status; + } + + pc = poptGetContext("user_add", argc, argv, long_options, 0); + + poptSetOtherOptionHelp(pc, "hostname username password"); + while((opt = poptGetNextOpt(pc)) != -1) { + } + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + hostname = poptGetArg(pc); + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + username = poptGetArg(pc); + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + password = poptGetArg(pc); + + /* NetUserAdd */ + + info1.usri1_name = username; + info1.usri1_password = password; + info1.usri1_password_age = 0; + info1.usri1_priv = 0; + info1.usri1_home_dir = NULL; + info1.usri1_comment = "User created using Samba NetApi Example code"; + info1.usri1_flags = 0; + info1.usri1_script_path = NULL; + + status = NetUserAdd(hostname, + 1, + (uint8_t *)&info1, + &parm_error); + if (status != 0) { + printf("NetUserAdd failed with: %s\n", + libnetapi_get_error_string(ctx, status)); + } + + out: + libnetapi_free(ctx); + poptFreeContext(pc); + + return status; +} -- cgit From fb538ad641842b69e83709cc7588cbef80d6544b Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 9 Apr 2008 13:35:49 +0200 Subject: Add NetUserDel to libnetapi. Guenther (This used to be commit 92ba18fcd0816fb85846c6e788ea4a04c71e02a8) --- source3/lib/netapi/libnetapi.c | 42 +++++++++ source3/lib/netapi/libnetapi.h | 6 ++ source3/lib/netapi/netapi.h | 8 ++ source3/lib/netapi/user.c | 190 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 246 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/libnetapi.c b/source3/lib/netapi/libnetapi.c index 9d92dac39f..7fd1e76ebd 100644 --- a/source3/lib/netapi/libnetapi.c +++ b/source3/lib/netapi/libnetapi.c @@ -487,3 +487,45 @@ NET_API_STATUS NetUserAdd(const char * server_name /* [in] [unique] */, return r.out.result; } +/**************************************************************** + NetUserDel +****************************************************************/ + +NET_API_STATUS NetUserDel(const char * server_name /* [in] [unique] */, + const char * user_name /* [in] [ref] */) +{ + struct NetUserDel r; + struct libnetapi_ctx *ctx = NULL; + NET_API_STATUS status; + WERROR werr; + + status = libnetapi_getctx(&ctx); + if (status != 0) { + return status; + } + + /* In parameters */ + r.in.server_name = server_name; + r.in.user_name = user_name; + + /* Out parameters */ + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_IN_DEBUG(NetUserDel, &r); + } + + if (LIBNETAPI_LOCAL_SERVER(server_name)) { + werr = NetUserDel_l(ctx, &r); + } else { + werr = NetUserDel_r(ctx, &r); + } + + r.out.result = W_ERROR_V(werr); + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_OUT_DEBUG(NetUserDel, &r); + } + + return r.out.result; +} + diff --git a/source3/lib/netapi/libnetapi.h b/source3/lib/netapi/libnetapi.h index 8e4e73bcd8..9ab5481164 100644 --- a/source3/lib/netapi/libnetapi.h +++ b/source3/lib/netapi/libnetapi.h @@ -82,4 +82,10 @@ WERROR NetUserAdd_r(struct libnetapi_ctx *ctx, struct NetUserAdd *r); WERROR NetUserAdd_l(struct libnetapi_ctx *ctx, struct NetUserAdd *r); +NET_API_STATUS NetUserDel(const char * server_name /* [in] [unique] */, + const char * user_name /* [in] [ref] */); +WERROR NetUserDel_r(struct libnetapi_ctx *ctx, + struct NetUserDel *r); +WERROR NetUserDel_l(struct libnetapi_ctx *ctx, + struct NetUserDel *r); #endif /* __LIBNETAPI_LIBNETAPI__ */ diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h index f328f57946..67919eeb01 100644 --- a/source3/lib/netapi/netapi.h +++ b/source3/lib/netapi/netapi.h @@ -200,4 +200,12 @@ NET_API_STATUS NetUserAdd(const char * server_name /* [in] */, uint32_t level /* [in] */, uint8_t *buffer /* [in] [ref] */, uint32_t *parm_error /* [out] [ref] */); + +/**************************************************************** + NetUserDel +****************************************************************/ + +NET_API_STATUS NetUserDel(const char * server_name /* [in] */, + const char * user_name /* [in] */); + #endif diff --git a/source3/lib/netapi/user.c b/source3/lib/netapi/user.c index 71f08c2b21..f5bdc27fd8 100644 --- a/source3/lib/netapi/user.c +++ b/source3/lib/netapi/user.c @@ -356,3 +356,193 @@ WERROR NetUserAdd_r(struct libnetapi_ctx *ctx, return werr; } + +/**************************************************************** +****************************************************************/ + +WERROR NetUserDel_r(struct libnetapi_ctx *ctx, + struct NetUserDel *r) +{ + struct cli_state *cli = NULL; + struct rpc_pipe_client *pipe_cli = NULL; + NTSTATUS status; + WERROR werr; + uint32_t resume_handle = 0; + uint32_t num_entries = 0; + POLICY_HND connect_handle, builtin_handle, domain_handle, user_handle; + struct samr_SamArray *sam = NULL; + const char *domain_name = NULL; + struct lsa_String lsa_domain_name, lsa_account_name; + struct samr_Ids user_rids, name_types; + struct dom_sid2 *domain_sid = NULL; + struct dom_sid2 user_sid; + bool domain_found = true; + int i; + + ZERO_STRUCT(connect_handle); + ZERO_STRUCT(builtin_handle); + ZERO_STRUCT(domain_handle); + ZERO_STRUCT(user_handle); + + status = cli_full_connection(&cli, NULL, r->in.server_name, + NULL, 0, + "IPC$", "IPC", + ctx->username, + ctx->workgroup, + ctx->password, + CLI_FULL_CONNECTION_USE_KERBEROS | + CLI_FULL_CONNECTION_FALLBACK_AFTER_KERBEROS, + Undefined, NULL); + + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + pipe_cli = cli_rpc_pipe_open_noauth(cli, PI_SAMR, &status); + if (!pipe_cli) { + werr = ntstatus_to_werror(status); + goto done; + } + + status = rpccli_try_samr_connects(pipe_cli, ctx, + SAMR_ACCESS_ENUM_DOMAINS | + SAMR_ACCESS_OPEN_DOMAIN, + &connect_handle); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + status = rpccli_samr_EnumDomains(pipe_cli, ctx, + &connect_handle, + &resume_handle, + &sam, + 0xffffffff, + &num_entries); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + for (i=0; ientries[i].name.string; + + if (strequal(domain_name, builtin_domain_name())) { + continue; + } + + domain_found = true; + break; + } + + if (!domain_found) { + werr = WERR_NO_SUCH_DOMAIN; + goto done; + } + + init_lsa_String(&lsa_domain_name, domain_name); + + status = rpccli_samr_LookupDomain(pipe_cli, ctx, + &connect_handle, + &lsa_domain_name, + &domain_sid); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + status = rpccli_samr_OpenDomain(pipe_cli, ctx, + &connect_handle, + SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, + domain_sid, + &domain_handle); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + status = rpccli_samr_OpenDomain(pipe_cli, ctx, + &connect_handle, + SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, + CONST_DISCARD(DOM_SID *, &global_sid_Builtin), + &builtin_handle); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + init_lsa_String(&lsa_account_name, r->in.user_name); + + status = rpccli_samr_LookupNames(pipe_cli, ctx, + &domain_handle, + 1, + &lsa_account_name, + &user_rids, + &name_types); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + status = rpccli_samr_OpenUser(pipe_cli, ctx, + &domain_handle, + STD_RIGHT_DELETE_ACCESS, + user_rids.ids[0], + &user_handle); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + sid_compose(&user_sid, domain_sid, user_rids.ids[0]); + + status = rpccli_samr_RemoveMemberFromForeignDomain(pipe_cli, ctx, + &builtin_handle, + &user_sid); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + status = rpccli_samr_DeleteUser(pipe_cli, ctx, + &user_handle); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + werr = WERR_OK; + + done: + if (!cli) { + return werr; + } + + if (is_valid_policy_hnd(&user_handle)) { + rpccli_samr_Close(pipe_cli, ctx, &user_handle); + } + if (is_valid_policy_hnd(&builtin_handle)) { + rpccli_samr_Close(pipe_cli, ctx, &builtin_handle); + } + if (is_valid_policy_hnd(&domain_handle)) { + rpccli_samr_Close(pipe_cli, ctx, &domain_handle); + } + if (is_valid_policy_hnd(&connect_handle)) { + rpccli_samr_Close(pipe_cli, ctx, &connect_handle); + } + + cli_shutdown(cli); + + return werr; +} + +/**************************************************************** +****************************************************************/ + +WERROR NetUserDel_l(struct libnetapi_ctx *ctx, + struct NetUserDel *r) +{ + return WERR_NOT_SUPPORTED; +} -- cgit From b3422d1d1c0471b694769ac9d804643f6a3f73d9 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 9 Apr 2008 13:38:39 +0200 Subject: Add Add NetUserDel example. Guenther (This used to be commit 3123e68bda70ad1cff9bd8f9375fd7935bf755dd) --- source3/lib/netapi/examples/Makefile.in | 8 ++- source3/lib/netapi/examples/user/user_del.c | 82 +++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 source3/lib/netapi/examples/user/user_del.c (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/Makefile.in b/source3/lib/netapi/examples/Makefile.in index 0e074b6972..c00c505a3a 100644 --- a/source3/lib/netapi/examples/Makefile.in +++ b/source3/lib/netapi/examples/Makefile.in @@ -22,7 +22,8 @@ PROGS = bin/getdc@EXEEXT@ \ bin/netdomjoin@EXEEXT@ \ bin/netdomjoin-gui@EXEEXT@ \ bin/getjoinableous@EXEEXT@ \ - bin/user_add@EXEEXT@ + bin/user_add@EXEEXT@ \ + bin/user_del@EXEEXT@ all: $(PROGS) @@ -57,6 +58,7 @@ NETDOMJOIN_OBJ = netdomjoin/netdomjoin.o $(CMDLINE_OBJ) NETDOMJOIN_GUI_OBJ = netdomjoin-gui/netdomjoin-gui.o GETJOINABLEOUS_OBJ = getjoinableous/getjoinableous.o $(CMDLINE_OBJ) USERADD_OBJ = user/user_add.o $(CMDLINE_OBJ) +USERDEL_OBJ = user/user_del.o $(CMDLINE_OBJ) bin/getdc@EXEEXT@: $(BINARY_PREREQS) $(GETDC_OBJ) @echo Linking $@ @@ -82,6 +84,10 @@ bin/user_add@EXEEXT@: $(BINARY_PREREQS) $(USERADD_OBJ) @echo Linking $@ @$(CC) $(FLAGS) -o $@ $(USERADD_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) +bin/user_del@EXEEXT@: $(BINARY_PREREQS) $(USERDEL_OBJ) + @echo Linking $@ + @$(CC) $(FLAGS) -o $@ $(USERDEL_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) + clean: -rm -f $(PROGS) -rm -f core */*~ *~ \ diff --git a/source3/lib/netapi/examples/user/user_del.c b/source3/lib/netapi/examples/user/user_del.c new file mode 100644 index 0000000000..9cf28a91ba --- /dev/null +++ b/source3/lib/netapi/examples/user/user_del.c @@ -0,0 +1,82 @@ +/* + * Unix SMB/CIFS implementation. + * NetUserDel query + * Copyright (C) Guenther Deschner 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include +#include +#include +#include +#include + +#include + +#include "common.h" + +int main(int argc, const char **argv) +{ + NET_API_STATUS status; + struct libnetapi_ctx *ctx = NULL; + const char *hostname = NULL; + const char *username = NULL; + + poptContext pc; + int opt; + + struct poptOption long_options[] = { + POPT_AUTOHELP + POPT_COMMON_LIBNETAPI_EXAMPLES + POPT_TABLEEND + }; + + status = libnetapi_init(&ctx); + if (status != 0) { + return status; + } + + pc = poptGetContext("user_del", argc, argv, long_options, 0); + + poptSetOtherOptionHelp(pc, "hostname username"); + while((opt = poptGetNextOpt(pc)) != -1) { + } + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + hostname = poptGetArg(pc); + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + username = poptGetArg(pc); + + /* NetUserDel */ + + status = NetUserDel(hostname, username); + if (status != 0) { + printf("NetUserDel failed with: %s\n", + libnetapi_get_error_string(ctx, status)); + } + + out: + libnetapi_free(ctx); + poptFreeContext(pc); + + return status; +} -- cgit From 4801d0c6f3cd08cbbfc0d68d36632044356e9d12 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 9 Apr 2008 13:47:51 +0200 Subject: Add NetUserEnum to libnetapi. Guenther (This used to be commit 6c933d0b3838808aeee7f4b29ee89aab8d203538) --- source3/lib/netapi/libnetapi.c | 55 ++++++++++++ source3/lib/netapi/libnetapi.h | 12 +++ source3/lib/netapi/netapi.h | 16 +++- source3/lib/netapi/user.c | 197 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 279 insertions(+), 1 deletion(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/libnetapi.c b/source3/lib/netapi/libnetapi.c index 7fd1e76ebd..eeff7c5229 100644 --- a/source3/lib/netapi/libnetapi.c +++ b/source3/lib/netapi/libnetapi.c @@ -529,3 +529,58 @@ NET_API_STATUS NetUserDel(const char * server_name /* [in] [unique] */, return r.out.result; } +/**************************************************************** + NetUserEnum +****************************************************************/ + +NET_API_STATUS NetUserEnum(const char * server_name /* [in] [unique] */, + uint32_t level /* [in] */, + uint32_t filter /* [in] */, + uint8_t **buffer /* [out] [ref] */, + uint32_t prefmaxlen /* [in] */, + uint32_t *entries_read /* [out] [ref] */, + uint32_t *total_entries /* [out] [ref] */, + uint32_t *resume_handle /* [in,out] [ref] */) +{ + struct NetUserEnum r; + struct libnetapi_ctx *ctx = NULL; + NET_API_STATUS status; + WERROR werr; + + status = libnetapi_getctx(&ctx); + if (status != 0) { + return status; + } + + /* In parameters */ + r.in.server_name = server_name; + r.in.level = level; + r.in.filter = filter; + r.in.prefmaxlen = prefmaxlen; + r.in.resume_handle = resume_handle; + + /* Out parameters */ + r.out.buffer = buffer; + r.out.entries_read = entries_read; + r.out.total_entries = total_entries; + r.out.resume_handle = resume_handle; + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_IN_DEBUG(NetUserEnum, &r); + } + + if (LIBNETAPI_LOCAL_SERVER(server_name)) { + werr = NetUserEnum_l(ctx, &r); + } else { + werr = NetUserEnum_r(ctx, &r); + } + + r.out.result = W_ERROR_V(werr); + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_OUT_DEBUG(NetUserEnum, &r); + } + + return r.out.result; +} + diff --git a/source3/lib/netapi/libnetapi.h b/source3/lib/netapi/libnetapi.h index 9ab5481164..5cd4165299 100644 --- a/source3/lib/netapi/libnetapi.h +++ b/source3/lib/netapi/libnetapi.h @@ -88,4 +88,16 @@ WERROR NetUserDel_r(struct libnetapi_ctx *ctx, struct NetUserDel *r); WERROR NetUserDel_l(struct libnetapi_ctx *ctx, struct NetUserDel *r); +NET_API_STATUS NetUserEnum(const char * server_name /* [in] [unique] */, + uint32_t level /* [in] */, + uint32_t filter /* [in] */, + uint8_t **buffer /* [out] [ref] */, + uint32_t prefmaxlen /* [in] */, + uint32_t *entries_read /* [out] [ref] */, + uint32_t *total_entries /* [out] [ref] */, + uint32_t *resume_handle /* [in,out] [ref] */); +WERROR NetUserEnum_r(struct libnetapi_ctx *ctx, + struct NetUserEnum *r); +WERROR NetUserEnum_l(struct libnetapi_ctx *ctx, + struct NetUserEnum *r); #endif /* __LIBNETAPI_LIBNETAPI__ */ diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h index 67919eeb01..483973566f 100644 --- a/source3/lib/netapi/netapi.h +++ b/source3/lib/netapi/netapi.h @@ -23,11 +23,12 @@ /**************************************************************** NET_API_STATUS ****************************************************************/ - typedef enum { NET_API_STATUS_SUCCESS = 0 } NET_API_STATUS; +#define ERROR_MORE_DATA ( 234L ) + /**************************************************************** ****************************************************************/ @@ -208,4 +209,17 @@ NET_API_STATUS NetUserAdd(const char * server_name /* [in] */, NET_API_STATUS NetUserDel(const char * server_name /* [in] */, const char * user_name /* [in] */); +/**************************************************************** + NetUserEnum +****************************************************************/ + +NET_API_STATUS NetUserEnum(const char * server_name /* [in] */, + uint32_t level /* [in] */, + uint32_t filter /* [in] */, + uint8_t **buffer /* [out] [ref] */, + uint32_t prefmaxlen /* [in] */, + uint32_t *entries_read /* [out] [ref] */, + uint32_t *total_entries /* [out] [ref] */, + uint32_t *resume_handle /* [in,out] [ref] */); + #endif diff --git a/source3/lib/netapi/user.c b/source3/lib/netapi/user.c index f5bdc27fd8..8dcc159c9e 100644 --- a/source3/lib/netapi/user.c +++ b/source3/lib/netapi/user.c @@ -546,3 +546,200 @@ WERROR NetUserDel_l(struct libnetapi_ctx *ctx, { return WERR_NOT_SUPPORTED; } + +/**************************************************************** +****************************************************************/ + +static WERROR convert_samr_samarray_to_USER_INFO_buffer(TALLOC_CTX *mem_ctx, + struct samr_SamArray *sam_array, + uint32_t level, + uint8_t **buffer) +{ + struct USER_INFO_0 *info0 = NULL; + int i; + + switch (level) { + case 0: + info0 = TALLOC_ZERO_ARRAY(mem_ctx, struct USER_INFO_0, + sam_array->count); + W_ERROR_HAVE_NO_MEMORY(info0); + + for (i=0; icount; i++) { + info0[i].usri0_name = talloc_strdup(mem_ctx, + sam_array->entries[i].name.string); + W_ERROR_HAVE_NO_MEMORY(info0[i].usri0_name); + } + + *buffer = (uint8_t *)talloc_memdup(mem_ctx, info0, + sizeof(struct USER_INFO_0) * sam_array->count); + W_ERROR_HAVE_NO_MEMORY(*buffer); + break; + default: + return WERR_NOT_SUPPORTED; + } + + return WERR_OK; +} + +/**************************************************************** +****************************************************************/ + +WERROR NetUserEnum_r(struct libnetapi_ctx *ctx, + struct NetUserEnum *r) +{ + struct cli_state *cli = NULL; + struct rpc_pipe_client *pipe_cli = NULL; + struct policy_handle connect_handle; + struct dom_sid2 *domain_sid = NULL; + struct policy_handle domain_handle; + struct samr_SamArray *sam = NULL; + uint32_t num_entries = 0; + int i; + const char *domain_name = NULL; + bool domain_found = true; + uint32_t dom_resume_handle = 0; + struct lsa_String lsa_domain_name; + + NTSTATUS status; + WERROR werr; + + ZERO_STRUCT(connect_handle); + ZERO_STRUCT(domain_handle); + + switch (r->in.level) { + case 0: + break; + case 1: + case 2: + case 3: + case 10: + case 11: + case 20: + case 23: + default: + return WERR_NOT_SUPPORTED; + } + + status = cli_full_connection(&cli, NULL, r->in.server_name, + NULL, 0, + "IPC$", "IPC", + ctx->username, + ctx->workgroup, + ctx->password, + CLI_FULL_CONNECTION_USE_KERBEROS | + CLI_FULL_CONNECTION_FALLBACK_AFTER_KERBEROS, + Undefined, NULL); + + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + pipe_cli = cli_rpc_pipe_open_noauth(cli, PI_SAMR, &status); + if (!pipe_cli) { + werr = ntstatus_to_werror(status); + goto done; + } + + status = rpccli_try_samr_connects(pipe_cli, ctx, + SAMR_ACCESS_OPEN_DOMAIN | + SAMR_ACCESS_ENUM_DOMAINS, + &connect_handle); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + status = rpccli_samr_EnumDomains(pipe_cli, ctx, + &connect_handle, + &dom_resume_handle, + &sam, + 0xffffffff, + &num_entries); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + for (i=0; ientries[i].name.string; + + if (strequal(domain_name, builtin_domain_name())) { + continue; + } + + domain_found = true; + break; + } + + if (!domain_found) { + werr = WERR_NO_SUCH_DOMAIN; + goto done; + } + + init_lsa_String(&lsa_domain_name, domain_name); + + status = rpccli_samr_LookupDomain(pipe_cli, ctx, + &connect_handle, + &lsa_domain_name, + &domain_sid); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + status = rpccli_samr_OpenDomain(pipe_cli, + ctx, + &connect_handle, + SAMR_DOMAIN_ACCESS_LOOKUP_INFO_2 | + SAMR_DOMAIN_ACCESS_ENUM_ACCOUNTS | + SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, + domain_sid, + &domain_handle); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + status = rpccli_samr_EnumDomainUsers(pipe_cli, + ctx, + &domain_handle, + r->in.resume_handle, + r->in.filter, + &sam, + r->in.prefmaxlen, + r->out.entries_read); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + werr = convert_samr_samarray_to_USER_INFO_buffer(ctx, sam, + r->in.level, + r->out.buffer); + + done: + if (is_valid_policy_hnd(&domain_handle)) { + rpccli_samr_Close(pipe_cli, ctx, &domain_handle); + } + if (is_valid_policy_hnd(&connect_handle)) { + rpccli_samr_Close(pipe_cli, ctx, &connect_handle); + } + + if (cli) { + cli_shutdown(cli); + } + + return werr; +} + +/**************************************************************** +****************************************************************/ + +WERROR NetUserEnum_l(struct libnetapi_ctx *ctx, + struct NetUserEnum *r) +{ + return WERR_NOT_SUPPORTED; +} + -- cgit From c12bf374fe4b7e1eb1a4f121f21495b4c5cb6725 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 9 Apr 2008 13:50:30 +0200 Subject: Add NetUserEnum example. Guenther (This used to be commit 7d9f64fd8401f8abb938757b4f092e25fd6b154f) --- source3/lib/netapi/examples/Makefile.in | 8 ++- source3/lib/netapi/examples/user/user_enum.c | 100 +++++++++++++++++++++++++++ 2 files changed, 107 insertions(+), 1 deletion(-) create mode 100644 source3/lib/netapi/examples/user/user_enum.c (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/Makefile.in b/source3/lib/netapi/examples/Makefile.in index c00c505a3a..84a8ecf075 100644 --- a/source3/lib/netapi/examples/Makefile.in +++ b/source3/lib/netapi/examples/Makefile.in @@ -23,7 +23,8 @@ PROGS = bin/getdc@EXEEXT@ \ bin/netdomjoin-gui@EXEEXT@ \ bin/getjoinableous@EXEEXT@ \ bin/user_add@EXEEXT@ \ - bin/user_del@EXEEXT@ + bin/user_del@EXEEXT@ \ + bin/user_enum@EXEEXT@ all: $(PROGS) @@ -59,6 +60,7 @@ NETDOMJOIN_GUI_OBJ = netdomjoin-gui/netdomjoin-gui.o GETJOINABLEOUS_OBJ = getjoinableous/getjoinableous.o $(CMDLINE_OBJ) USERADD_OBJ = user/user_add.o $(CMDLINE_OBJ) USERDEL_OBJ = user/user_del.o $(CMDLINE_OBJ) +USERENUM_OBJ = user/user_enum.o $(CMDLINE_OBJ) bin/getdc@EXEEXT@: $(BINARY_PREREQS) $(GETDC_OBJ) @echo Linking $@ @@ -88,6 +90,10 @@ bin/user_del@EXEEXT@: $(BINARY_PREREQS) $(USERDEL_OBJ) @echo Linking $@ @$(CC) $(FLAGS) -o $@ $(USERDEL_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) +bin/user_enum@EXEEXT@: $(BINARY_PREREQS) $(USERENUM_OBJ) + @echo Linking $@ + @$(CC) $(FLAGS) -o $@ $(USERENUM_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) + clean: -rm -f $(PROGS) -rm -f core */*~ *~ \ diff --git a/source3/lib/netapi/examples/user/user_enum.c b/source3/lib/netapi/examples/user/user_enum.c new file mode 100644 index 0000000000..e1f6bda10b --- /dev/null +++ b/source3/lib/netapi/examples/user/user_enum.c @@ -0,0 +1,100 @@ +/* + * Unix SMB/CIFS implementation. + * NetUserEnum query + * Copyright (C) Guenther Deschner 2007 + * + * 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include +#include +#include +#include +#include + +#include + +#include "common.h" + +int main(int argc, const char **argv) +{ + NET_API_STATUS status; + struct libnetapi_ctx *ctx = NULL; + const char *hostname = NULL; + uint8_t *buffer = NULL; + uint32_t entries_read = 0; + uint32_t total_entries = 0; + uint32_t resume_handle = 0; + int i; + + struct USER_INFO_0 *info0; + + poptContext pc; + int opt; + + struct poptOption long_options[] = { + POPT_AUTOHELP + POPT_COMMON_LIBNETAPI_EXAMPLES + POPT_TABLEEND + }; + + status = libnetapi_init(&ctx); + if (status != 0) { + return status; + } + + pc = poptGetContext("user_enum", argc, argv, long_options, 0); + + poptSetOtherOptionHelp(pc, "hostname"); + while((opt = poptGetNextOpt(pc)) != -1) { + } + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + hostname = poptGetArg(pc); + + /* NetUserEnum */ + + do { + status = NetUserEnum(hostname, + 0, + 0, + &buffer, + (uint32_t)-1, + &entries_read, + &total_entries, + &resume_handle); + if (status == 0 || status == ERROR_MORE_DATA) { + info0 = (struct USER_INFO_0 *)buffer; + for (i=0; iusri0_name); + info0++; + } + NetApiBufferFree(buffer); + } + } while (status == ERROR_MORE_DATA); + + if (status != 0) { + printf("NetUserEnum failed with: %s\n", + libnetapi_get_error_string(ctx, status)); + } + + out: + libnetapi_free(ctx); + poptFreeContext(pc); + + return status; +} -- cgit From 8ea6da93541ccdecbd3a2c55d77cb9afff0a4288 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 10 Apr 2008 21:23:59 +0200 Subject: Fix typo. Guenther (This used to be commit 30337bce2c748e5338f9cc923e096883322f50d3) --- source3/lib/netapi/netapi.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h index 483973566f..ea850c51c4 100644 --- a/source3/lib/netapi/netapi.h +++ b/source3/lib/netapi/netapi.h @@ -52,7 +52,7 @@ struct DOMAIN_CONTROLLER_INFO { uint32_t domain_controller_address_type; struct GUID domain_guid; const char * domain_name; - const char * dns_foreset_name; + const char * dns_forest_name; uint32_t flags; const char * dc_site_name; const char * client_site_name; -- cgit From 1a8a8b776961c9220fa686cb60b7ab82a7c76a3d Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 10 Apr 2008 21:31:12 +0200 Subject: Use SERVER_INFO_1005 in libnetapi. Guenther (This used to be commit 5f8793dd1d8a3694afb7f2d882cfb9990eb40b75) --- .../lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c | 14 +++++--------- source3/lib/netapi/netapi.h | 4 ++++ source3/lib/netapi/serverinfo.c | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c index a4daf4fea7..fa1bafd5ae 100644 --- a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c +++ b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c @@ -48,10 +48,6 @@ #define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0) -struct srvsvc_NetSrvInfo1005 { - const char *comment;/* [unique,charset(UTF16)] */ -}; - static gboolean verbose = FALSE; typedef struct join_state { @@ -173,10 +169,10 @@ static void callback_apply_description_change(GtkWidget *widget, struct join_state *state = (struct join_state *)data; NET_API_STATUS status = 0; uint32_t parm_err = 0; - struct srvsvc_NetSrvInfo1005 info1005; + struct SERVER_INFO_1005 info1005; GtkWidget *dialog; - info1005.comment = state->comment_new; + info1005.sv1005_comment = state->comment_new; status = NetServerSetInfo(NULL, 1005, (uint8_t *)&info1005, &parm_err); if (status) { @@ -1556,7 +1552,7 @@ static int initialize_join_state(struct join_state *state, } { - struct srvsvc_NetSrvInfo1005 *info1005 = NULL; + struct SERVER_INFO_1005 *info1005 = NULL; uint8_t *buffer = NULL; status = NetServerGetInfo(NULL, 1005, &buffer); @@ -1566,9 +1562,9 @@ static int initialize_join_state(struct join_state *state, return status; } - info1005 = (struct srvsvc_NetSrvInfo1005 *)buffer; + info1005 = (struct SERVER_INFO_1005 *)buffer; - state->comment = strdup(info1005->comment); + state->comment = strdup(info1005->sv1005_comment); if (!state->comment) { return -1; } diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h index ea850c51c4..a9b50c4e89 100644 --- a/source3/lib/netapi/netapi.h +++ b/source3/lib/netapi/netapi.h @@ -58,6 +58,10 @@ struct DOMAIN_CONTROLLER_INFO { const char * client_site_name; }; +struct SERVER_INFO_1005 { + const char * sv1005_comment; +}; + struct USER_INFO_0 { const char * usri0_name; }; diff --git a/source3/lib/netapi/serverinfo.c b/source3/lib/netapi/serverinfo.c index 7cc84f5367..643b04c4da 100644 --- a/source3/lib/netapi/serverinfo.c +++ b/source3/lib/netapi/serverinfo.c @@ -30,9 +30,9 @@ static WERROR NetServerGetInfo_l_1005(struct libnetapi_ctx *ctx, uint8_t **buffer) { - struct srvsvc_NetSrvInfo1005 info1005; + struct SERVER_INFO_1005 info1005; - info1005.comment = lp_serverstring(); + info1005.sv1005_comment = lp_serverstring(); *buffer = (uint8_t *)talloc_memdup(ctx, &info1005, sizeof(info1005)); if (!*buffer) { return WERR_NOMEM; -- cgit From 4968ce25554b0891bf78601c4b41c8b18c89bde1 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 10 Apr 2008 21:41:03 +0200 Subject: Add very basic cli_cm_* based connection handler to libnetapi. Guenther (This used to be commit e9e46cfcbe25366121f680a6d81fe08c128bf00a) --- source3/lib/netapi/cm.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 source3/lib/netapi/cm.c (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/cm.c b/source3/lib/netapi/cm.c new file mode 100644 index 0000000000..31446efde3 --- /dev/null +++ b/source3/lib/netapi/cm.c @@ -0,0 +1,75 @@ +/* + * Unix SMB/CIFS implementation. + * NetApi Support + * Copyright (C) Guenther Deschner 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include "includes.h" + +#include "lib/netapi/netapi.h" + +/******************************************************************** +********************************************************************/ + +WERROR libnetapi_open_ipc_connection(struct libnetapi_ctx *ctx, + const char *server_name, + struct cli_state **cli) +{ + struct cli_state *cli_ipc = NULL; + + if (!ctx || !cli || !server_name) { + return WERR_INVALID_PARAM; + } + + cli_cm_set_signing_state(Undefined); + cli_cm_set_use_kerberos(); + + if (ctx->password) { + cli_cm_set_password(ctx->password); + } + if (ctx->username) { + cli_cm_set_username(ctx->username); + } + + if (ctx->username && ctx->username[0] && + ctx->password && ctx->password[0]) { + cli_cm_set_fallback_after_kerberos(); + } + + cli_ipc = cli_cm_open(ctx, NULL, + server_name, "IPC$", + false, false); + if (!cli_ipc) { + libnetapi_set_error_string(ctx, + "Failed to connect to IPC$ share on %s", + server_name); + return WERR_CAN_NOT_COMPLETE; + } + + *cli = cli_ipc; + + return WERR_OK; +} + +/******************************************************************** +********************************************************************/ + +WERROR libnetapi_shutdown_cm(struct libnetapi_ctx *ctx) +{ + cli_cm_shutdown(); + + return WERR_OK; +} -- cgit From 8ab9696bfb5e127a35ab31e7e7746388a8f8a365 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 10 Apr 2008 21:52:03 +0200 Subject: Split out private headers in libnetapi. Guenther (This used to be commit dd6251d51472a96bfc5ba3d62ea788c8924d4c6b) --- source3/lib/netapi/getdc.c | 1 + source3/lib/netapi/joindomain.c | 1 + source3/lib/netapi/libnetapi.c | 1 + source3/lib/netapi/netapi.h | 51 +++++++++++++++++++++++++++++++------ source3/lib/netapi/netapi_private.h | 32 +++++++++++++++++++++++ source3/lib/netapi/serverinfo.c | 1 + source3/lib/netapi/user.c | 1 + 7 files changed, 80 insertions(+), 8 deletions(-) create mode 100644 source3/lib/netapi/netapi_private.h (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/getdc.c b/source3/lib/netapi/getdc.c index a865474019..944cfb24f3 100644 --- a/source3/lib/netapi/getdc.c +++ b/source3/lib/netapi/getdc.c @@ -21,6 +21,7 @@ #include "librpc/gen_ndr/libnetapi.h" #include "lib/netapi/netapi.h" +#include "lib/netapi/netapi_private.h" #include "lib/netapi/libnetapi.h" #include "libnet/libnet.h" diff --git a/source3/lib/netapi/joindomain.c b/source3/lib/netapi/joindomain.c index 48a6a91888..96c2f3d1fc 100644 --- a/source3/lib/netapi/joindomain.c +++ b/source3/lib/netapi/joindomain.c @@ -21,6 +21,7 @@ #include "librpc/gen_ndr/libnetapi.h" #include "lib/netapi/netapi.h" +#include "lib/netapi/netapi_private.h" #include "lib/netapi/libnetapi.h" #include "libnet/libnet.h" diff --git a/source3/lib/netapi/libnetapi.c b/source3/lib/netapi/libnetapi.c index eeff7c5229..fd1802f99f 100644 --- a/source3/lib/netapi/libnetapi.c +++ b/source3/lib/netapi/libnetapi.c @@ -20,6 +20,7 @@ #include "includes.h" #include "librpc/gen_ndr/libnetapi.h" #include "lib/netapi/netapi.h" +#include "lib/netapi/netapi_private.h" #include "libnetapi.h" #include "librpc/gen_ndr/ndr_libnetapi.h" diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h index a9b50c4e89..7b03e41c19 100644 --- a/source3/lib/netapi/netapi.h +++ b/source3/lib/netapi/netapi.h @@ -95,16 +95,51 @@ struct libnetapi_ctx { ****************************************************************/ 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, 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); + +/**************************************************************** +****************************************************************/ + +NET_API_STATUS libnetapi_getctx(struct libnetapi_ctx **ctx); + +/**************************************************************** +****************************************************************/ + +NET_API_STATUS libnetapi_set_debuglevel(struct libnetapi_ctx *ctx, + const 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(NET_API_STATUS status); -NET_API_STATUS libnetapi_set_error_string(struct libnetapi_ctx *ctx, const char *format, ...); -const char *libnetapi_get_error_string(struct libnetapi_ctx *ctx, NET_API_STATUS status); + +/**************************************************************** +****************************************************************/ + +const char *libnetapi_get_error_string(struct libnetapi_ctx *ctx, + NET_API_STATUS status); /**************************************************************** diff --git a/source3/lib/netapi/netapi_private.h b/source3/lib/netapi/netapi_private.h new file mode 100644 index 0000000000..2591a7bc09 --- /dev/null +++ b/source3/lib/netapi/netapi_private.h @@ -0,0 +1,32 @@ +/* + * Unix SMB/CIFS implementation. + * NetApi Support + * Copyright (C) Guenther Deschner 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#ifndef __LIB_NETAPI_PRIVATE_H__ +#define __LIB_NETAPI_PRIVATE_H__ + +NET_API_STATUS libnetapi_get_password(struct libnetapi_ctx *ctx, char **password); +NET_API_STATUS libnetapi_get_username(struct libnetapi_ctx *ctx, char **username); +NET_API_STATUS libnetapi_set_error_string(struct libnetapi_ctx *ctx, const char *format, ...); +NET_API_STATUS libnetapi_get_debuglevel(struct libnetapi_ctx *ctx, char **debuglevel); + +WERROR libnetapi_open_ipc_connection(struct libnetapi_ctx *ctx, + const char *server_name, + struct cli_state **cli); +WERROR libnetapi_shutdown_cm(struct libnetapi_ctx *ctx); +#endif diff --git a/source3/lib/netapi/serverinfo.c b/source3/lib/netapi/serverinfo.c index 643b04c4da..fb5d9402cf 100644 --- a/source3/lib/netapi/serverinfo.c +++ b/source3/lib/netapi/serverinfo.c @@ -21,6 +21,7 @@ #include "librpc/gen_ndr/libnetapi.h" #include "lib/netapi/netapi.h" +#include "lib/netapi/netapi_private.h" #include "lib/netapi/libnetapi.h" #include "libnet/libnet.h" diff --git a/source3/lib/netapi/user.c b/source3/lib/netapi/user.c index 8dcc159c9e..54157a8f82 100644 --- a/source3/lib/netapi/user.c +++ b/source3/lib/netapi/user.c @@ -21,6 +21,7 @@ #include "librpc/gen_ndr/libnetapi.h" #include "lib/netapi/netapi.h" +#include "lib/netapi/netapi_private.h" #include "lib/netapi/libnetapi.h" /**************************************************************** -- cgit From deb6362f1f1ac12d6e2a245370ca36accc9506b1 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 10 Apr 2008 21:56:12 +0200 Subject: Fix one missing netapi_private header. Guenther (This used to be commit d34c3e8ad2b21051162e2a9d65f773c486c43d8b) --- source3/lib/netapi/cm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/cm.c b/source3/lib/netapi/cm.c index 31446efde3..a3b842f96e 100644 --- a/source3/lib/netapi/cm.c +++ b/source3/lib/netapi/cm.c @@ -20,6 +20,7 @@ #include "includes.h" #include "lib/netapi/netapi.h" +#include "lib/netapi/netapi_private.h" /******************************************************************** ********************************************************************/ @@ -54,8 +55,7 @@ WERROR libnetapi_open_ipc_connection(struct libnetapi_ctx *ctx, false, false); if (!cli_ipc) { libnetapi_set_error_string(ctx, - "Failed to connect to IPC$ share on %s", - server_name); + "Failed to connect to IPC$ share on %s", server_name); return WERR_CAN_NOT_COMPLETE; } -- cgit From aeb7f7db4014695eb6510cc7a713db4c6228bd1f Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 10 Apr 2008 22:04:04 +0200 Subject: Use libnetapi_open_ipc_connection in libnetapi. Guenther (This used to be commit d9f19fc61586d606393368799dee9757c169d602) --- source3/lib/netapi/getdc.c | 55 ++++------------------------------ source3/lib/netapi/joindomain.c | 66 +++++++---------------------------------- source3/lib/netapi/netapi.c | 2 ++ source3/lib/netapi/serverinfo.c | 36 +++------------------- source3/lib/netapi/user.c | 54 +++++++-------------------------- 5 files changed, 33 insertions(+), 180 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/getdc.c b/source3/lib/netapi/getdc.c index 944cfb24f3..8f882941b3 100644 --- a/source3/lib/netapi/getdc.c +++ b/source3/lib/netapi/getdc.c @@ -45,19 +45,8 @@ WERROR NetGetDCName_r(struct libnetapi_ctx *ctx, NTSTATUS status; WERROR werr; - status = cli_full_connection(&cli, NULL, r->in.server_name, - NULL, 0, - "IPC$", "IPC", - ctx->username, - ctx->workgroup, - ctx->password, - CLI_FULL_CONNECTION_USE_KERBEROS | - CLI_FULL_CONNECTION_FALLBACK_AFTER_KERBEROS | - CLI_FULL_CONNECTION_ANONYMOUS_FALLBACK, - Undefined, NULL); - - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); + werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli); + if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -74,9 +63,6 @@ WERROR NetGetDCName_r(struct libnetapi_ctx *ctx, (const char **)r->out.buffer, &werr); done: - if (cli) { - cli_shutdown(cli); - } return werr; } @@ -101,19 +87,8 @@ WERROR NetGetAnyDCName_r(struct libnetapi_ctx *ctx, NTSTATUS status; WERROR werr; - status = cli_full_connection(&cli, NULL, r->in.server_name, - NULL, 0, - "IPC$", "IPC", - ctx->username, - ctx->workgroup, - ctx->password, - CLI_FULL_CONNECTION_USE_KERBEROS | - CLI_FULL_CONNECTION_FALLBACK_AFTER_KERBEROS | - CLI_FULL_CONNECTION_ANONYMOUS_FALLBACK, - Undefined, NULL); - - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); + werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli); + if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -133,9 +108,6 @@ WERROR NetGetAnyDCName_r(struct libnetapi_ctx *ctx, goto done; } done: - if (cli) { - cli_shutdown(cli); - } return werr; @@ -175,19 +147,8 @@ WERROR DsGetDcName_r(struct libnetapi_ctx *ctx, struct cli_state *cli = NULL; struct rpc_pipe_client *pipe_cli = NULL; - status = cli_full_connection(&cli, NULL, r->in.server_name, - NULL, 0, - "IPC$", "IPC", - ctx->username, - ctx->workgroup, - ctx->password, - CLI_FULL_CONNECTION_USE_KERBEROS | - CLI_FULL_CONNECTION_FALLBACK_AFTER_KERBEROS | - CLI_FULL_CONNECTION_ANONYMOUS_FALLBACK, - Undefined, NULL); - - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); + werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli); + if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -213,9 +174,5 @@ WERROR DsGetDcName_r(struct libnetapi_ctx *ctx, } done: - if (cli) { - cli_shutdown(cli); - } - return werr; } diff --git a/source3/lib/netapi/joindomain.c b/source3/lib/netapi/joindomain.c index 96c2f3d1fc..056d8d27e2 100644 --- a/source3/lib/netapi/joindomain.c +++ b/source3/lib/netapi/joindomain.c @@ -103,18 +103,8 @@ WERROR NetJoinDomain_r(struct libnetapi_ctx *ctx, WERROR werr; unsigned int old_timeout = 0; - status = cli_full_connection(&cli, NULL, r->in.server, - NULL, 0, - "IPC$", "IPC", - ctx->username, - ctx->workgroup, - ctx->password, - CLI_FULL_CONNECTION_USE_KERBEROS | - CLI_FULL_CONNECTION_FALLBACK_AFTER_KERBEROS, - Undefined, NULL); - - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); + werr = libnetapi_open_ipc_connection(ctx, r->in.server, &cli); + if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -152,7 +142,6 @@ WERROR NetJoinDomain_r(struct libnetapi_ctx *ctx, if (old_timeout) { cli_set_timeout(cli, old_timeout); } - cli_shutdown(cli); } return werr; @@ -245,18 +234,8 @@ WERROR NetUnjoinDomain_r(struct libnetapi_ctx *ctx, WERROR werr; unsigned int old_timeout = 0; - status = cli_full_connection(&cli, NULL, r->in.server_name, - NULL, 0, - "IPC$", "IPC", - ctx->username, - ctx->workgroup, - ctx->password, - CLI_FULL_CONNECTION_USE_KERBEROS | - CLI_FULL_CONNECTION_FALLBACK_AFTER_KERBEROS, - Undefined, NULL); - - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); + werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli); + if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -289,8 +268,9 @@ WERROR NetUnjoinDomain_r(struct libnetapi_ctx *ctx, done: if (cli) { - cli_set_timeout(cli, old_timeout); - cli_shutdown(cli); + if (old_timeout) { + cli_set_timeout(cli, old_timeout); + } } return werr; @@ -307,18 +287,8 @@ WERROR NetGetJoinInformation_r(struct libnetapi_ctx *ctx, NTSTATUS status; WERROR werr; - status = cli_full_connection(&cli, NULL, r->in.server_name, - NULL, 0, - "IPC$", "IPC", - ctx->username, - ctx->workgroup, - ctx->password, - CLI_FULL_CONNECTION_USE_KERBEROS | - CLI_FULL_CONNECTION_FALLBACK_AFTER_KERBEROS, - Undefined, NULL); - - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); + werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli); + if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -340,10 +310,6 @@ WERROR NetGetJoinInformation_r(struct libnetapi_ctx *ctx, } done: - if (cli) { - cli_shutdown(cli); - } - return werr; } @@ -451,18 +417,8 @@ WERROR NetGetJoinableOUs_r(struct libnetapi_ctx *ctx, NTSTATUS status; WERROR werr; - status = cli_full_connection(&cli, NULL, r->in.server_name, - NULL, 0, - "IPC$", "IPC", - ctx->username, - ctx->workgroup, - ctx->password, - CLI_FULL_CONNECTION_USE_KERBEROS | - CLI_FULL_CONNECTION_FALLBACK_AFTER_KERBEROS, - Undefined, NULL); - - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); + werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli); + if (!W_ERROR_IS_OK(werr)) { goto done; } diff --git a/source3/lib/netapi/netapi.c b/source3/lib/netapi/netapi.c index fbec2757f0..2478a8dda1 100644 --- a/source3/lib/netapi/netapi.c +++ b/source3/lib/netapi/netapi.c @@ -19,6 +19,7 @@ #include "includes.h" #include "lib/netapi/netapi.h" +#include "lib/netapi/netapi_private.h" extern bool AllowDebugChange; @@ -113,6 +114,7 @@ NET_API_STATUS libnetapi_getctx(struct libnetapi_ctx **ctx) NET_API_STATUS libnetapi_free(struct libnetapi_ctx *ctx) { + libnetapi_shutdown_cm(ctx); if (ctx->krb5_cc_env) { char *env = getenv(KRB5_ENV_CCNAME); diff --git a/source3/lib/netapi/serverinfo.c b/source3/lib/netapi/serverinfo.c index fb5d9402cf..238b9ca308 100644 --- a/source3/lib/netapi/serverinfo.c +++ b/source3/lib/netapi/serverinfo.c @@ -70,18 +70,8 @@ WERROR NetServerGetInfo_r(struct libnetapi_ctx *ctx, WERROR werr; union srvsvc_NetSrvInfo info; - status = cli_full_connection(&cli, NULL, r->in.server_name, - NULL, 0, - "IPC$", "IPC", - ctx->username, - ctx->workgroup, - ctx->password, - CLI_FULL_CONNECTION_USE_KERBEROS | - CLI_FULL_CONNECTION_FALLBACK_AFTER_KERBEROS, - Undefined, NULL); - - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); + werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli); + if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -109,10 +99,6 @@ WERROR NetServerGetInfo_r(struct libnetapi_ctx *ctx, } done: - if (cli) { - cli_shutdown(cli); - } - return werr; } @@ -186,18 +172,8 @@ WERROR NetServerSetInfo_r(struct libnetapi_ctx *ctx, WERROR werr; union srvsvc_NetSrvInfo info; - status = cli_full_connection(&cli, NULL, r->in.server_name, - NULL, 0, - "IPC$", "IPC", - ctx->username, - ctx->workgroup, - ctx->password, - CLI_FULL_CONNECTION_USE_KERBEROS | - CLI_FULL_CONNECTION_FALLBACK_AFTER_KERBEROS, - Undefined, NULL); - - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); + werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli); + if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -229,9 +205,5 @@ WERROR NetServerSetInfo_r(struct libnetapi_ctx *ctx, } done: - if (cli) { - cli_shutdown(cli); - } - return werr; } diff --git a/source3/lib/netapi/user.c b/source3/lib/netapi/user.c index 54157a8f82..d9505bc067 100644 --- a/source3/lib/netapi/user.c +++ b/source3/lib/netapi/user.c @@ -180,18 +180,8 @@ WERROR NetUserAdd_r(struct libnetapi_ctx *ctx, goto done; } - status = cli_full_connection(&cli, NULL, r->in.server_name, - NULL, 0, - "IPC$", "IPC", - ctx->username, - ctx->workgroup, - ctx->password, - CLI_FULL_CONNECTION_USE_KERBEROS | - CLI_FULL_CONNECTION_FALLBACK_AFTER_KERBEROS, - Undefined, NULL); - - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); + werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli); + if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -353,8 +343,6 @@ WERROR NetUserAdd_r(struct libnetapi_ctx *ctx, rpccli_samr_Close(pipe_cli, ctx, &connect_handle); } - cli_shutdown(cli); - return werr; } @@ -385,18 +373,8 @@ WERROR NetUserDel_r(struct libnetapi_ctx *ctx, ZERO_STRUCT(domain_handle); ZERO_STRUCT(user_handle); - status = cli_full_connection(&cli, NULL, r->in.server_name, - NULL, 0, - "IPC$", "IPC", - ctx->username, - ctx->workgroup, - ctx->password, - CLI_FULL_CONNECTION_USE_KERBEROS | - CLI_FULL_CONNECTION_FALLBACK_AFTER_KERBEROS, - Undefined, NULL); - - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); + werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli); + if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -534,8 +512,6 @@ WERROR NetUserDel_r(struct libnetapi_ctx *ctx, rpccli_samr_Close(pipe_cli, ctx, &connect_handle); } - cli_shutdown(cli); - return werr; } @@ -621,18 +597,8 @@ WERROR NetUserEnum_r(struct libnetapi_ctx *ctx, return WERR_NOT_SUPPORTED; } - status = cli_full_connection(&cli, NULL, r->in.server_name, - NULL, 0, - "IPC$", "IPC", - ctx->username, - ctx->workgroup, - ctx->password, - CLI_FULL_CONNECTION_USE_KERBEROS | - CLI_FULL_CONNECTION_FALLBACK_AFTER_KERBEROS, - Undefined, NULL); - - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); + werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli); + if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -721,6 +687,10 @@ WERROR NetUserEnum_r(struct libnetapi_ctx *ctx, r->out.buffer); done: + if (!cli) { + return werr; + } + if (is_valid_policy_hnd(&domain_handle)) { rpccli_samr_Close(pipe_cli, ctx, &domain_handle); } @@ -728,10 +698,6 @@ WERROR NetUserEnum_r(struct libnetapi_ctx *ctx, rpccli_samr_Close(pipe_cli, ctx, &connect_handle); } - if (cli) { - cli_shutdown(cli); - } - return werr; } -- cgit From 3d5aecd2b940215c2566b2e429c2cc3803ff0ad4 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 10 Apr 2008 22:42:07 +0200 Subject: Add libnetapi_open_pipe, inspired by the cli_cm_ interface. Guenther (This used to be commit 87d8fc338f6e6b48691bff3eeebfc00c5d408ff7) --- source3/lib/netapi/cm.c | 110 ++++++++++++++++++++++++++++++++++++ source3/lib/netapi/netapi_private.h | 4 ++ 2 files changed, 114 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/cm.c b/source3/lib/netapi/cm.c index a3b842f96e..96087247d2 100644 --- a/source3/lib/netapi/cm.c +++ b/source3/lib/netapi/cm.c @@ -73,3 +73,113 @@ WERROR libnetapi_shutdown_cm(struct libnetapi_ctx *ctx) return WERR_OK; } + +/******************************************************************** +********************************************************************/ + +struct client_pipe_connection { + struct client_pipe_connection *prev, *next; + struct rpc_pipe_client *pipe; +}; + +static struct client_pipe_connection *pipe_connections; + +/******************************************************************** +********************************************************************/ + +static struct rpc_pipe_client *pipe_cm_find(struct cli_state *cli, + int pipe_idx, + NTSTATUS *status) +{ + struct client_pipe_connection *p; + + for (p = pipe_connections; p; p = p->next) { + + if (!p->pipe->cli) { + *status = NT_STATUS_PIPE_EMPTY; + return NULL; + } + + if (strequal(cli->desthost, p->pipe->cli->desthost) && + pipe_idx == p->pipe->pipe_idx) { + *status = NT_STATUS_OK; + return p->pipe; + } + } + + *status = NT_STATUS_PIPE_NOT_AVAILABLE; + + return NULL; +} + +/******************************************************************** +********************************************************************/ + +static struct rpc_pipe_client *pipe_cm_connect(TALLOC_CTX *mem_ctx, + struct cli_state *cli, + int pipe_idx, + NTSTATUS *status) +{ + struct client_pipe_connection *p; + + p = TALLOC_ZERO_ARRAY(mem_ctx, struct client_pipe_connection, 1); + if (!p) { + *status = NT_STATUS_NO_MEMORY; + return NULL; + } + + p->pipe = cli_rpc_pipe_open_noauth(cli, pipe_idx, status); + if (!p->pipe) { + TALLOC_FREE(p); + return NULL; + } + + DLIST_ADD(pipe_connections, p); + + return p->pipe; +} + +/******************************************************************** +********************************************************************/ + +static struct rpc_pipe_client *pipe_cm_open(TALLOC_CTX *ctx, + struct cli_state *cli, + int pipe_idx, + NTSTATUS *status) +{ + struct rpc_pipe_client *p; + + p = pipe_cm_find(cli, pipe_idx, status); + if (!p) { + p = pipe_cm_connect(ctx, cli, pipe_idx, status); + } + + return p; +} + +/******************************************************************** +********************************************************************/ + +WERROR libnetapi_open_pipe(struct libnetapi_ctx *ctx, + struct cli_state *cli, + int pipe_idx, + struct rpc_pipe_client **pipe_cli) +{ + NTSTATUS status; + + if (!cli || !pipe_cli) { + return WERR_INVALID_PARAM; + } + + *pipe_cli = pipe_cm_open(ctx, cli, pipe_idx, &status); + if (!*pipe_cli) { + libnetapi_set_error_string(ctx, "failed to open PIPE %s: %s", + cli_get_pipe_name(pipe_idx), + get_friendly_nt_error_msg(status)); + return WERR_DEST_NOT_FOUND; + } + + return WERR_OK; +} + + diff --git a/source3/lib/netapi/netapi_private.h b/source3/lib/netapi/netapi_private.h index 2591a7bc09..a575f42f4e 100644 --- a/source3/lib/netapi/netapi_private.h +++ b/source3/lib/netapi/netapi_private.h @@ -29,4 +29,8 @@ WERROR libnetapi_open_ipc_connection(struct libnetapi_ctx *ctx, const char *server_name, struct cli_state **cli); WERROR libnetapi_shutdown_cm(struct libnetapi_ctx *ctx); +WERROR libnetapi_open_pipe(struct libnetapi_ctx *ctx, + struct cli_state *cli, + int pipe_idx, + struct rpc_pipe_client **pipe_cli); #endif -- cgit From ef6ed54765b1d8ccaabfb3268f8427cc791b738b Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 10 Apr 2008 22:44:00 +0200 Subject: Use libnetapi_open_pipe in netapi functions. Guenther (This used to be commit 5804d8b112e1da022988c635284eb4799974d4c7) --- source3/lib/netapi/getdc.c | 20 +++++++------------- source3/lib/netapi/joindomain.c | 24 ++++++++---------------- source3/lib/netapi/serverinfo.c | 16 ++++++---------- source3/lib/netapi/user.c | 15 ++++++--------- 4 files changed, 27 insertions(+), 48 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/getdc.c b/source3/lib/netapi/getdc.c index 8f882941b3..38aaf0ef85 100644 --- a/source3/lib/netapi/getdc.c +++ b/source3/lib/netapi/getdc.c @@ -50,10 +50,8 @@ WERROR NetGetDCName_r(struct libnetapi_ctx *ctx, goto done; } - pipe_cli = cli_rpc_pipe_open_noauth(cli, PI_NETLOGON, - &status); - if (!pipe_cli) { - werr = ntstatus_to_werror(status); + werr = libnetapi_open_pipe(ctx, cli, PI_NETLOGON, &pipe_cli); + if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -92,12 +90,10 @@ WERROR NetGetAnyDCName_r(struct libnetapi_ctx *ctx, goto done; } - pipe_cli = cli_rpc_pipe_open_noauth(cli, PI_NETLOGON, - &status); - if (!pipe_cli) { - werr = ntstatus_to_werror(status); + werr = libnetapi_open_pipe(ctx, cli, PI_NETLOGON, &pipe_cli); + if (!W_ERROR_IS_OK(werr)) { goto done; - }; + } status = rpccli_netr_GetAnyDCName(pipe_cli, ctx, r->in.server_name, @@ -152,10 +148,8 @@ WERROR DsGetDcName_r(struct libnetapi_ctx *ctx, goto done; } - pipe_cli = cli_rpc_pipe_open_noauth(cli, PI_NETLOGON, - &status); - if (!pipe_cli) { - werr = ntstatus_to_werror(status); + werr = libnetapi_open_pipe(ctx, cli, PI_NETLOGON, &pipe_cli); + if (!W_ERROR_IS_OK(werr)) { goto done; } diff --git a/source3/lib/netapi/joindomain.c b/source3/lib/netapi/joindomain.c index 056d8d27e2..8e0a62e820 100644 --- a/source3/lib/netapi/joindomain.c +++ b/source3/lib/netapi/joindomain.c @@ -108,10 +108,8 @@ WERROR NetJoinDomain_r(struct libnetapi_ctx *ctx, goto done; } - pipe_cli = cli_rpc_pipe_open_noauth(cli, PI_WKSSVC, - &status); - if (!pipe_cli) { - werr = ntstatus_to_werror(status); + werr = libnetapi_open_pipe(ctx, cli, PI_WKSSVC, &pipe_cli); + if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -239,10 +237,8 @@ WERROR NetUnjoinDomain_r(struct libnetapi_ctx *ctx, goto done; } - pipe_cli = cli_rpc_pipe_open_noauth(cli, PI_WKSSVC, - &status); - if (!pipe_cli) { - werr = ntstatus_to_werror(status); + werr = libnetapi_open_pipe(ctx, cli, PI_WKSSVC, &pipe_cli); + if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -292,10 +288,8 @@ WERROR NetGetJoinInformation_r(struct libnetapi_ctx *ctx, goto done; } - pipe_cli = cli_rpc_pipe_open_noauth(cli, PI_WKSSVC, - &status); - if (!pipe_cli) { - werr = ntstatus_to_werror(status); + werr = libnetapi_open_pipe(ctx, cli, PI_WKSSVC, &pipe_cli); + if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -422,10 +416,8 @@ WERROR NetGetJoinableOUs_r(struct libnetapi_ctx *ctx, goto done; } - pipe_cli = cli_rpc_pipe_open_noauth(cli, PI_WKSSVC, - &status); - if (!pipe_cli) { - werr = ntstatus_to_werror(status); + werr = libnetapi_open_pipe(ctx, cli, PI_WKSSVC, &pipe_cli); + if (!W_ERROR_IS_OK(werr)) { goto done; } diff --git a/source3/lib/netapi/serverinfo.c b/source3/lib/netapi/serverinfo.c index 238b9ca308..58efeb375d 100644 --- a/source3/lib/netapi/serverinfo.c +++ b/source3/lib/netapi/serverinfo.c @@ -75,12 +75,10 @@ WERROR NetServerGetInfo_r(struct libnetapi_ctx *ctx, goto done; } - pipe_cli = cli_rpc_pipe_open_noauth(cli, PI_SRVSVC, - &status); - if (!pipe_cli) { - werr = ntstatus_to_werror(status); + werr = libnetapi_open_pipe(ctx, cli, PI_SRVSVC, &pipe_cli); + if (!W_ERROR_IS_OK(werr)) { goto done; - }; + } status = rpccli_srvsvc_NetSrvGetInfo(pipe_cli, ctx, r->in.server_name, @@ -177,12 +175,10 @@ WERROR NetServerSetInfo_r(struct libnetapi_ctx *ctx, goto done; } - pipe_cli = cli_rpc_pipe_open_noauth(cli, PI_SRVSVC, - &status); - if (!pipe_cli) { - werr = ntstatus_to_werror(status); + werr = libnetapi_open_pipe(ctx, cli, PI_SRVSVC, &pipe_cli); + if (!W_ERROR_IS_OK(werr)) { goto done; - }; + } switch (r->in.level) { case 1005: diff --git a/source3/lib/netapi/user.c b/source3/lib/netapi/user.c index d9505bc067..31e5faa594 100644 --- a/source3/lib/netapi/user.c +++ b/source3/lib/netapi/user.c @@ -185,9 +185,8 @@ WERROR NetUserAdd_r(struct libnetapi_ctx *ctx, goto done; } - pipe_cli = cli_rpc_pipe_open_noauth(cli, PI_SAMR, &status); - if (!pipe_cli) { - werr = ntstatus_to_werror(status); + werr = libnetapi_open_pipe(ctx, cli, PI_SAMR, &pipe_cli); + if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -378,9 +377,8 @@ WERROR NetUserDel_r(struct libnetapi_ctx *ctx, goto done; } - pipe_cli = cli_rpc_pipe_open_noauth(cli, PI_SAMR, &status); - if (!pipe_cli) { - werr = ntstatus_to_werror(status); + werr = libnetapi_open_pipe(ctx, cli, PI_SAMR, &pipe_cli); + if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -602,9 +600,8 @@ WERROR NetUserEnum_r(struct libnetapi_ctx *ctx, goto done; } - pipe_cli = cli_rpc_pipe_open_noauth(cli, PI_SAMR, &status); - if (!pipe_cli) { - werr = ntstatus_to_werror(status); + werr = libnetapi_open_pipe(ctx, cli, PI_SAMR, &pipe_cli); + if (!W_ERROR_IS_OK(werr)) { goto done; } -- cgit From ecd46b8ad4e77bbfd6f24cecdccd4029655336b8 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Sat, 12 Apr 2008 02:05:25 +0200 Subject: libnetapi: fix interactive logging by preventing setup_logging from closing stderr. Michael (This used to be commit 563b837b76e3a6086051fc56e0522b841939d37f) --- source3/lib/netapi/netapi.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi.c b/source3/lib/netapi/netapi.c index 2478a8dda1..cb218f0ced 100644 --- a/source3/lib/netapi/netapi.c +++ b/source3/lib/netapi/netapi.c @@ -54,6 +54,9 @@ NET_API_STATUS libnetapi_init(struct libnetapi_ctx **context) if (!DEBUGLEVEL) { DEBUGLEVEL = 0; } + + /* prevent setup_logging() from closing x_stderr... */ + dbf = 0; setup_logging("libnetapi", true); dbf = x_stderr; -- cgit From 25953779884483b9bb49feaa7da0f634ed20681b Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Sun, 13 Apr 2008 00:24:42 +0200 Subject: libnetapi: fix a C++ warning by making implicit cast explicit Michael (This used to be commit b62dd61cc56ec33601289fd4e23058c7f9ad3f0d) --- source3/lib/netapi/serverinfo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/serverinfo.c b/source3/lib/netapi/serverinfo.c index 58efeb375d..dd7a8808b4 100644 --- a/source3/lib/netapi/serverinfo.c +++ b/source3/lib/netapi/serverinfo.c @@ -90,7 +90,7 @@ WERROR NetServerGetInfo_r(struct libnetapi_ctx *ctx, goto done; } - *r->out.buffer = talloc_memdup(ctx, &info, sizeof(info)); + *r->out.buffer = (uint8_t *)talloc_memdup(ctx, &info, sizeof(info)); if (!*r->out.buffer) { werr = WERR_NOMEM; goto done; -- cgit From a75421b0190763e5e482db215d8b1e6052bdcc19 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Sat, 12 Apr 2008 23:12:53 +0200 Subject: Fix ou handling in netdomjoin-gui. The ou list was concatenated again and again... Guenther (This used to be commit 84608e165e24c68c12d40086f81684ef37f69159) --- source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c index fa1bafd5ae..a7b2079f95 100644 --- a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c +++ b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c @@ -84,6 +84,7 @@ typedef struct join_state { uint16_t server_role; gboolean settings_changed; gboolean hostname_changed; + uint32_t stored_num_ous; } join_state; static void debug(const char *format, ...) @@ -932,11 +933,15 @@ static void callback_do_getous(GtkWidget *widget, return; } + for (i=0; istored_num_ous; i++) { + gtk_combo_box_remove_text(GTK_COMBO_BOX(state->entry_ou_list), 0); + } for (i=0; ientry_ou_list), ous[i]); } NetApiBufferFree(ous); + state->stored_num_ous = num_ous; gtk_combo_box_set_active(GTK_COMBO_BOX(state->entry_ou_list), num_ous-1); } -- cgit From e39f02217a8ec0eeee4a4179ab5b39d35e0575c6 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Sun, 13 Apr 2008 17:33:27 +0200 Subject: libnetapi: don't to try to free NULL struct. Guenther (This used to be commit eb33d30d80ab2fe770e248f5b2a70a83a43dd156) --- source3/lib/netapi/netapi.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi.c b/source3/lib/netapi/netapi.c index cb218f0ced..f15e5bf067 100644 --- a/source3/lib/netapi/netapi.c +++ b/source3/lib/netapi/netapi.c @@ -117,6 +117,10 @@ NET_API_STATUS libnetapi_getctx(struct libnetapi_ctx **ctx) NET_API_STATUS libnetapi_free(struct libnetapi_ctx *ctx) { + if (!ctx) { + return NET_API_STATUS_SUCCESS; + } + libnetapi_shutdown_cm(ctx); if (ctx->krb5_cc_env) { -- cgit From 5647deccb1372b4ea478b34814e304ae8962f282 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Sun, 13 Apr 2008 19:04:18 +0200 Subject: libnetapi: add NetQueryDisplayInformation skeleton. Guenther (This used to be commit 6ec4a62b6d584f6745c3285474372f235614b598) --- source3/lib/netapi/libnetapi.c | 52 ++++++++++++++++++++++++++++++++++++++++++ source3/lib/netapi/libnetapi.h | 11 +++++++++ source3/lib/netapi/user.c | 19 +++++++++++++++ 3 files changed, 82 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/libnetapi.c b/source3/lib/netapi/libnetapi.c index fd1802f99f..e71adc6893 100644 --- a/source3/lib/netapi/libnetapi.c +++ b/source3/lib/netapi/libnetapi.c @@ -585,3 +585,55 @@ NET_API_STATUS NetUserEnum(const char * server_name /* [in] [unique] */, return r.out.result; } +/**************************************************************** + NetQueryDisplayInformation +****************************************************************/ + +NET_API_STATUS NetQueryDisplayInformation(const char * server_name /* [in] [unique] */, + uint32_t level /* [in] */, + uint32_t idx /* [in] */, + uint32_t entries_requested /* [in] */, + uint32_t prefmaxlen /* [in] */, + uint32_t *entries_read /* [out] [ref] */, + void **buffer /* [out] [noprint,ref] */) +{ + struct NetQueryDisplayInformation r; + struct libnetapi_ctx *ctx = NULL; + NET_API_STATUS status; + WERROR werr; + + status = libnetapi_getctx(&ctx); + if (status != 0) { + return status; + } + + /* In parameters */ + r.in.server_name = server_name; + r.in.level = level; + r.in.idx = idx; + r.in.entries_requested = entries_requested; + r.in.prefmaxlen = prefmaxlen; + + /* Out parameters */ + r.out.entries_read = entries_read; + r.out.buffer = buffer; + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_IN_DEBUG(NetQueryDisplayInformation, &r); + } + + if (LIBNETAPI_LOCAL_SERVER(server_name)) { + werr = NetQueryDisplayInformation_l(ctx, &r); + } else { + werr = NetQueryDisplayInformation_r(ctx, &r); + } + + r.out.result = W_ERROR_V(werr); + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_OUT_DEBUG(NetQueryDisplayInformation, &r); + } + + return r.out.result; +} + diff --git a/source3/lib/netapi/libnetapi.h b/source3/lib/netapi/libnetapi.h index 5cd4165299..7aff355652 100644 --- a/source3/lib/netapi/libnetapi.h +++ b/source3/lib/netapi/libnetapi.h @@ -100,4 +100,15 @@ WERROR NetUserEnum_r(struct libnetapi_ctx *ctx, struct NetUserEnum *r); WERROR NetUserEnum_l(struct libnetapi_ctx *ctx, struct NetUserEnum *r); +NET_API_STATUS NetQueryDisplayInformation(const char * server_name /* [in] [unique] */, + uint32_t level /* [in] */, + uint32_t idx /* [in] */, + uint32_t entries_requested /* [in] */, + uint32_t prefmaxlen /* [in] */, + uint32_t *entries_read /* [out] [ref] */, + void **buffer /* [out] [noprint,ref] */); +WERROR NetQueryDisplayInformation_r(struct libnetapi_ctx *ctx, + struct NetQueryDisplayInformation *r); +WERROR NetQueryDisplayInformation_l(struct libnetapi_ctx *ctx, + struct NetQueryDisplayInformation *r); #endif /* __LIBNETAPI_LIBNETAPI__ */ diff --git a/source3/lib/netapi/user.c b/source3/lib/netapi/user.c index 31e5faa594..f0ce26bdf8 100644 --- a/source3/lib/netapi/user.c +++ b/source3/lib/netapi/user.c @@ -707,3 +707,22 @@ WERROR NetUserEnum_l(struct libnetapi_ctx *ctx, return WERR_NOT_SUPPORTED; } +/**************************************************************** +****************************************************************/ + + +WERROR NetQueryDisplayInformation_r(struct libnetapi_ctx *ctx, + struct NetQueryDisplayInformation *r) +{ + return WERR_NOT_SUPPORTED; +} + +/**************************************************************** +****************************************************************/ + + +WERROR NetQueryDisplayInformation_l(struct libnetapi_ctx *ctx, + struct NetQueryDisplayInformation *r) +{ + return WERR_NOT_SUPPORTED; +} -- cgit From dcb9264edf2ca9f08fafaeb0633d90e5ba0da2f3 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Sun, 13 Apr 2008 19:11:01 +0200 Subject: libnetapi: don't reset the error code in NetUserAdd_r if the operation failed. Guenther (This used to be commit 9edb067f62b1e36f1da461b3eb09cb123d2089dd) --- source3/lib/netapi/user.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/user.c b/source3/lib/netapi/user.c index f0ce26bdf8..7b7cb9db05 100644 --- a/source3/lib/netapi/user.c +++ b/source3/lib/netapi/user.c @@ -320,12 +320,8 @@ WERROR NetUserAdd_r(struct libnetapi_ctx *ctx, goto done; failed: - status = rpccli_samr_DeleteUser(pipe_cli, ctx, - &user_handle); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } + rpccli_samr_DeleteUser(pipe_cli, ctx, + &user_handle); done: if (!cli) { -- cgit From b3367c9e353e947c6b0641418cbb66ae64db2ed3 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Sun, 13 Apr 2008 19:12:31 +0200 Subject: libnetapi: fill in NetQueryDisplayInformation_r. Guenther (This used to be commit 7fb9991b4c54fd0b9629e47afc1e5bbc2cfc1088) --- source3/lib/netapi/user.c | 296 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 295 insertions(+), 1 deletion(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/user.c b/source3/lib/netapi/user.c index 7b7cb9db05..55d9795f2d 100644 --- a/source3/lib/netapi/user.c +++ b/source3/lib/netapi/user.c @@ -706,11 +706,305 @@ WERROR NetUserEnum_l(struct libnetapi_ctx *ctx, /**************************************************************** ****************************************************************/ +static WERROR convert_samr_dispinfo_to_NET_DISPLAY_USER(TALLOC_CTX *mem_ctx, + struct samr_DispInfoGeneral *info, + uint32_t *entries_read, + void **buffer) +{ + struct NET_DISPLAY_USER *user = NULL; + int i; + + user = TALLOC_ZERO_ARRAY(mem_ctx, + struct NET_DISPLAY_USER, + info->count); + W_ERROR_HAVE_NO_MEMORY(user); + + for (i = 0; i < info->count; i++) { + user[i].usri1_name = talloc_strdup(mem_ctx, + info->entries[i].account_name.string); + user[i].usri1_comment = talloc_strdup(mem_ctx, + info->entries[i].description.string); + user[i].usri1_flags = + info->entries[i].acct_flags; + user[i].usri1_full_name = talloc_strdup(mem_ctx, + info->entries[i].full_name.string); + user[i].usri1_user_id = + info->entries[i].rid; + user[i].usri1_next_index = + info->entries[i].idx; + + if (!user[i].usri1_name) { + return WERR_NOMEM; + } + } + + *buffer = talloc_memdup(mem_ctx, user, + sizeof(struct NET_DISPLAY_USER) * info->count); + W_ERROR_HAVE_NO_MEMORY(*buffer); + + *entries_read = info->count; + + return WERR_OK; +} + +/**************************************************************** +****************************************************************/ + +static WERROR convert_samr_dispinfo_to_NET_DISPLAY_MACHINE(TALLOC_CTX *mem_ctx, + struct samr_DispInfoFull *info, + uint32_t *entries_read, + void **buffer) +{ + struct NET_DISPLAY_MACHINE *machine = NULL; + int i; + + machine = TALLOC_ZERO_ARRAY(mem_ctx, + struct NET_DISPLAY_MACHINE, + info->count); + W_ERROR_HAVE_NO_MEMORY(machine); + + for (i = 0; i < info->count; i++) { + machine[i].usri2_name = talloc_strdup(mem_ctx, + info->entries[i].account_name.string); + machine[i].usri2_comment = talloc_strdup(mem_ctx, + info->entries[i].description.string); + machine[i].usri2_flags = + info->entries[i].acct_flags; + machine[i].usri2_user_id = + info->entries[i].rid; + machine[i].usri2_next_index = + info->entries[i].idx; + + if (!machine[i].usri2_name) { + return WERR_NOMEM; + } + } + + *buffer = talloc_memdup(mem_ctx, machine, + sizeof(struct NET_DISPLAY_MACHINE) * info->count); + W_ERROR_HAVE_NO_MEMORY(*buffer); + + *entries_read = info->count; + + return WERR_OK; +} + +/**************************************************************** +****************************************************************/ + +static WERROR convert_samr_dispinfo_to_NET_DISPLAY_GROUP(TALLOC_CTX *mem_ctx, + struct samr_DispInfoFullGroups *info, + uint32_t *entries_read, + void **buffer) +{ + struct NET_DISPLAY_GROUP *group = NULL; + int i; + + group = TALLOC_ZERO_ARRAY(mem_ctx, + struct NET_DISPLAY_GROUP, + info->count); + W_ERROR_HAVE_NO_MEMORY(group); + + for (i = 0; i < info->count; i++) { + group[i].grpi3_name = talloc_strdup(mem_ctx, + info->entries[i].account_name.string); + group[i].grpi3_comment = talloc_strdup(mem_ctx, + info->entries[i].description.string); + group[i].grpi3_group_id = + info->entries[i].rid; + group[i].grpi3_attributes = + info->entries[i].acct_flags; + group[i].grpi3_next_index = + info->entries[i].idx; + + if (!group[i].grpi3_name) { + return WERR_NOMEM; + } + } + + *buffer = talloc_memdup(mem_ctx, group, + sizeof(struct NET_DISPLAY_GROUP) * info->count); + W_ERROR_HAVE_NO_MEMORY(*buffer); + + *entries_read = info->count; + + return WERR_OK; + +} + +/**************************************************************** +****************************************************************/ + +WERROR convert_samr_dispinfo_to_NET_DISPLAY(TALLOC_CTX *mem_ctx, + union samr_DispInfo *info, + uint32_t level, + uint32_t *entries_read, + void **buffer) +{ + switch (level) { + case 1: + return convert_samr_dispinfo_to_NET_DISPLAY_USER(mem_ctx, + &info->info1, + entries_read, + buffer); + case 2: + return convert_samr_dispinfo_to_NET_DISPLAY_MACHINE(mem_ctx, + &info->info2, + entries_read, + buffer); + case 3: + return convert_samr_dispinfo_to_NET_DISPLAY_GROUP(mem_ctx, + &info->info3, + entries_read, + buffer); + default: + return WERR_UNKNOWN_LEVEL; + } + + return WERR_OK; +} + +/**************************************************************** +****************************************************************/ WERROR NetQueryDisplayInformation_r(struct libnetapi_ctx *ctx, struct NetQueryDisplayInformation *r) { - return WERR_NOT_SUPPORTED; + struct cli_state *cli = NULL; + struct rpc_pipe_client *pipe_cli = NULL; + struct policy_handle connect_handle; + struct dom_sid2 *domain_sid = NULL; + struct policy_handle domain_handle; + union samr_DispInfo info; + struct samr_SamArray *sam = NULL; + uint32_t num_entries = 0; + int i; + const char *domain_name = NULL; + bool domain_found = true; + uint32_t dom_resume_handle = 0; + struct lsa_String lsa_domain_name; + + uint32_t total_size = 0; + uint32_t returned_size = 0; + + NTSTATUS status; + WERROR werr; + + ZERO_STRUCT(connect_handle); + ZERO_STRUCT(domain_handle); + + switch (r->in.level) { + case 1: + case 2: + case 3: + break; + default: + return WERR_UNKNOWN_LEVEL; + } + + werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + werr = libnetapi_open_pipe(ctx, cli, PI_SAMR, &pipe_cli); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + status = rpccli_try_samr_connects(pipe_cli, ctx, + SAMR_ACCESS_OPEN_DOMAIN | + SAMR_ACCESS_ENUM_DOMAINS, + &connect_handle); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + status = rpccli_samr_EnumDomains(pipe_cli, ctx, + &connect_handle, + &dom_resume_handle, + &sam, + 0xffffffff, + &num_entries); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + for (i=0; ientries[i].name.string; + + if (strequal(domain_name, builtin_domain_name())) { + continue; + } + + domain_found = true; + break; + } + + if (!domain_found) { + werr = WERR_NO_SUCH_DOMAIN; + goto done; + } + + init_lsa_String(&lsa_domain_name, domain_name); + + status = rpccli_samr_LookupDomain(pipe_cli, ctx, + &connect_handle, + &lsa_domain_name, + &domain_sid); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + status = rpccli_samr_OpenDomain(pipe_cli, + ctx, + &connect_handle, + SAMR_DOMAIN_ACCESS_ENUM_ACCOUNTS | + SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, + domain_sid, + &domain_handle); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + status = rpccli_samr_QueryDisplayInfo2(pipe_cli, + ctx, + &domain_handle, + r->in.level, + r->in.idx, + r->in.entries_requested, + r->in.prefmaxlen, + &total_size, + &returned_size, + &info); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + werr = convert_samr_dispinfo_to_NET_DISPLAY(ctx, &info, + r->in.level, + r->out.entries_read, + r->out.buffer); + done: + if (!cli) { + return werr; + } + + if (is_valid_policy_hnd(&domain_handle)) { + rpccli_samr_Close(pipe_cli, ctx, &domain_handle); + } + if (is_valid_policy_hnd(&connect_handle)) { + rpccli_samr_Close(pipe_cli, ctx, &connect_handle); + } + + return werr; + } /**************************************************************** -- cgit From d0acdc90385302cdac16a4eac0b503e2d3707108 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Sun, 13 Apr 2008 19:15:15 +0200 Subject: libnetapi: add NetQueryDisplayInformation example. Guenther (This used to be commit 5f9332cf1f60bb5a23a16776b95af3a83c5deb40) --- source3/lib/netapi/examples/Makefile.in | 8 +- source3/lib/netapi/examples/user/user_dispinfo.c | 98 ++++++++++++++++++++++++ 2 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 source3/lib/netapi/examples/user/user_dispinfo.c (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/Makefile.in b/source3/lib/netapi/examples/Makefile.in index 84a8ecf075..1e2e28c471 100644 --- a/source3/lib/netapi/examples/Makefile.in +++ b/source3/lib/netapi/examples/Makefile.in @@ -24,7 +24,8 @@ PROGS = bin/getdc@EXEEXT@ \ bin/getjoinableous@EXEEXT@ \ bin/user_add@EXEEXT@ \ bin/user_del@EXEEXT@ \ - bin/user_enum@EXEEXT@ + bin/user_enum@EXEEXT@ \ + bin/user_dispinfo@EXEEXT@ all: $(PROGS) @@ -61,6 +62,7 @@ GETJOINABLEOUS_OBJ = getjoinableous/getjoinableous.o $(CMDLINE_OBJ) USERADD_OBJ = user/user_add.o $(CMDLINE_OBJ) USERDEL_OBJ = user/user_del.o $(CMDLINE_OBJ) USERENUM_OBJ = user/user_enum.o $(CMDLINE_OBJ) +USERDISPINFO_OBJ = user/user_dispinfo.o $(CMDLINE_OBJ) bin/getdc@EXEEXT@: $(BINARY_PREREQS) $(GETDC_OBJ) @echo Linking $@ @@ -94,6 +96,10 @@ bin/user_enum@EXEEXT@: $(BINARY_PREREQS) $(USERENUM_OBJ) @echo Linking $@ @$(CC) $(FLAGS) -o $@ $(USERENUM_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) +bin/user_dispinfo@EXEEXT@: $(BINARY_PREREQS) $(USERDISPINFO_OBJ) + @echo Linking $@ + @$(CC) $(FLAGS) -o $@ $(USERDISPINFO_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) + clean: -rm -f $(PROGS) -rm -f core */*~ *~ \ diff --git a/source3/lib/netapi/examples/user/user_dispinfo.c b/source3/lib/netapi/examples/user/user_dispinfo.c new file mode 100644 index 0000000000..9f862505aa --- /dev/null +++ b/source3/lib/netapi/examples/user/user_dispinfo.c @@ -0,0 +1,98 @@ +/* + * Unix SMB/CIFS implementation. + * NetQueryDisplayInformation query + * Copyright (C) Guenther Deschner 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include +#include +#include +#include +#include + +#include + +#include "common.h" + +int main(int argc, const char **argv) +{ + NET_API_STATUS status; + struct libnetapi_ctx *ctx = NULL; + const char *hostname = NULL; + void *buffer = NULL; + uint32_t entries_read = 0; + uint32_t idx = 0; + int i; + + struct NET_DISPLAY_USER *user; + + poptContext pc; + int opt; + + struct poptOption long_options[] = { + POPT_AUTOHELP + POPT_COMMON_LIBNETAPI_EXAMPLES + POPT_TABLEEND + }; + + status = libnetapi_init(&ctx); + if (status != 0) { + return status; + } + + pc = poptGetContext("user_dispinfo", argc, argv, long_options, 0); + + poptSetOtherOptionHelp(pc, "hostname"); + while((opt = poptGetNextOpt(pc)) != -1) { + } + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + hostname = poptGetArg(pc); + + /* NetQueryDisplayInformation */ + + do { + status = NetQueryDisplayInformation(hostname, + 1, + idx, + 1000, + (uint32_t)-1, + &entries_read, + &buffer); + if (status == 0 || status == ERROR_MORE_DATA) { + user = (struct NET_DISPLAY_USER *)buffer; + for (i=0; iusri1_name); + user++; + } + NetApiBufferFree(buffer); + } + } while (status == ERROR_MORE_DATA); + + if (status != 0) { + printf("NetQueryDisplayInformation failed with: %s\n", + libnetapi_get_error_string(ctx, status)); + } + + out: + libnetapi_free(ctx); + poptFreeContext(pc); + + return status; +} -- cgit From 631808843400c97f47f29a32ee990205dce7aa20 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Sun, 13 Apr 2008 19:23:42 +0200 Subject: libnetapi: Add NetQueryDisplayInformation header. Guenther (This used to be commit 3c107934acc907e3eedd116b42d1d07ee0574183) --- source3/lib/netapi/netapi.h | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h index 7b03e41c19..97fed2e1d3 100644 --- a/source3/lib/netapi/netapi.h +++ b/source3/lib/netapi/netapi.h @@ -261,4 +261,12 @@ NET_API_STATUS NetUserEnum(const char * server_name /* [in] */, uint32_t *total_entries /* [out] [ref] */, uint32_t *resume_handle /* [in,out] [ref] */); +NET_API_STATUS NetQueryDisplayInformation(const char * server_name /* [in] [unique] */, + uint32_t level /* [in] */, + uint32_t idx /* [in] */, + uint32_t entries_requested /* [in] */, + uint32_t prefmaxlen /* [in] */, + uint32_t *entries_read /* [out] [ref] */, + void **buffer /* [out] [noprint,ref] */); + #endif -- cgit From aea1a244eed1c474d8e95048563c2d304a4f3696 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Sun, 13 Apr 2008 19:22:24 +0200 Subject: libnetapi: add libnetapi_set_use_kerberos Don't unconditionally set the kerberos flag for authentication. Guenther (This used to be commit 15bef5ae413adf278cccc0e547c4b8ccd180eca2) --- source3/lib/netapi/cm.c | 8 ++++++-- source3/lib/netapi/examples/common.c | 4 ++++ source3/lib/netapi/netapi.c | 9 +++++++++ source3/lib/netapi/netapi.h | 6 ++++++ 4 files changed, 25 insertions(+), 2 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/cm.c b/source3/lib/netapi/cm.c index 96087247d2..071ebfd4bc 100644 --- a/source3/lib/netapi/cm.c +++ b/source3/lib/netapi/cm.c @@ -36,7 +36,10 @@ WERROR libnetapi_open_ipc_connection(struct libnetapi_ctx *ctx, } cli_cm_set_signing_state(Undefined); - cli_cm_set_use_kerberos(); + + if (ctx->use_kerberos) { + cli_cm_set_use_kerberos(); + } if (ctx->password) { cli_cm_set_password(ctx->password); @@ -46,7 +49,8 @@ WERROR libnetapi_open_ipc_connection(struct libnetapi_ctx *ctx, } if (ctx->username && ctx->username[0] && - ctx->password && ctx->password[0]) { + ctx->password && ctx->password[0] && + ctx->use_kerberos) { cli_cm_set_fallback_after_kerberos(); } diff --git a/source3/lib/netapi/examples/common.c b/source3/lib/netapi/examples/common.c index 2c3e4d711d..74e28616bf 100644 --- a/source3/lib/netapi/examples/common.c +++ b/source3/lib/netapi/examples/common.c @@ -48,6 +48,9 @@ void popt_common_callback(poptContext con, case 'p': libnetapi_set_password(ctx, arg); break; + case 'k': + libnetapi_set_use_kerberos(ctx); + break; } } @@ -56,6 +59,7 @@ struct poptOption popt_common_netapi_examples[] = { { "user", 'U', POPT_ARG_STRING, NULL, 'U', "Username used for connection", "USERNAME" }, { "password", 'p', POPT_ARG_STRING, NULL, 'p', "Password used for connection", "PASSWORD" }, { "debuglevel", 'd', POPT_ARG_STRING, NULL, 'd', "Debuglevel", "DEBUGLEVEL" }, + { "kerberos", 'k', POPT_ARG_NONE, NULL, 'k', "Use Kerberos", NULL }, POPT_TABLEEND }; diff --git a/source3/lib/netapi/netapi.c b/source3/lib/netapi/netapi.c index f15e5bf067..9e309634b4 100644 --- a/source3/lib/netapi/netapi.c +++ b/source3/lib/netapi/netapi.c @@ -211,6 +211,15 @@ NET_API_STATUS libnetapi_set_workgroup(struct libnetapi_ctx *ctx, /**************************************************************** ****************************************************************/ +NET_API_STATUS libnetapi_set_use_kerberos(struct libnetapi_ctx *ctx) +{ + ctx->use_kerberos = true; + return NET_API_STATUS_SUCCESS; +} + +/**************************************************************** +****************************************************************/ + const char *libnetapi_errstr(NET_API_STATUS status) { if (status & 0xc0000000) { diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h index 97fed2e1d3..0d21067a20 100644 --- a/source3/lib/netapi/netapi.h +++ b/source3/lib/netapi/netapi.h @@ -89,6 +89,7 @@ struct libnetapi_ctx { char *workgroup; char *password; char *krb5_cc_env; + int use_kerberos; }; /**************************************************************** @@ -133,6 +134,11 @@ NET_API_STATUS libnetapi_set_workgroup(struct libnetapi_ctx *ctx, /**************************************************************** ****************************************************************/ +NET_API_STATUS libnetapi_set_use_kerberos(struct libnetapi_ctx *ctx); + +/**************************************************************** +****************************************************************/ + const char *libnetapi_errstr(NET_API_STATUS status); /**************************************************************** -- cgit From 7d7283fb0e11bc452f1da283e210378bd0d0e354 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 15 Apr 2008 22:30:06 +0200 Subject: libnetapi: Add missing headers. Guenther (This used to be commit 3fda711f2526914bf18ec004d553453e692b1e85) --- source3/lib/netapi/netapi.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h index 0d21067a20..e93381533b 100644 --- a/source3/lib/netapi/netapi.h +++ b/source3/lib/netapi/netapi.h @@ -77,6 +77,31 @@ struct USER_INFO_1 { const char * usri1_script_path; }; +struct NET_DISPLAY_USER { + const char * usri1_name; + const char * usri1_comment; + uint32_t usri1_flags; + const char * usri1_full_name; + uint32_t usri1_user_id; + uint32_t usri1_next_index; +}; + +struct NET_DISPLAY_MACHINE { + const char * usri2_name; + const char * usri2_comment; + uint32_t usri2_flags; + uint32_t usri2_user_id; + uint32_t usri2_next_index; +}; + +struct NET_DISPLAY_GROUP { + const char * grpi3_name; + const char * grpi3_comment; + uint32_t grpi3_group_id; + uint32_t grpi3_attributes; + uint32_t grpi3_next_index; +}; + #endif /* _HEADER_libnetapi */ /**************************************************************** -- cgit From 46e6bc1153dbcf406f873a3e082582a44cd4467e Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 16 Apr 2008 00:14:52 +0200 Subject: libnetapi: do not overwrite status in libnetapi_get_error_string(). Guenther (This used to be commit 143e2b573043dd04a6404fc91d781e8a727bd092) --- source3/lib/netapi/netapi.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi.c b/source3/lib/netapi/netapi.c index 9e309634b4..941e323183 100644 --- a/source3/lib/netapi/netapi.c +++ b/source3/lib/netapi/netapi.c @@ -253,8 +253,9 @@ NET_API_STATUS libnetapi_set_error_string(struct libnetapi_ctx *ctx, ****************************************************************/ const char *libnetapi_get_error_string(struct libnetapi_ctx *ctx, - NET_API_STATUS status) + NET_API_STATUS status_in) { + NET_API_STATUS status; struct libnetapi_ctx *tmp_ctx = ctx; if (!tmp_ctx) { @@ -268,7 +269,7 @@ const char *libnetapi_get_error_string(struct libnetapi_ctx *ctx, return tmp_ctx->error_string; } - return libnetapi_errstr(status); + return libnetapi_errstr(status_in); } /**************************************************************** -- cgit From 3455702721c0888a475afe3e0fe2e8469aa8cdd3 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 16 Apr 2008 02:38:13 +0200 Subject: libnetapi: Let NetUserAdd_l/NetUserDel_l talk to the local RPC server. Guenther (This used to be commit 9bbb6cea0b21d98ae13f7a41226b437515bd5a2f) --- source3/lib/netapi/user.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/user.c b/source3/lib/netapi/user.c index 55d9795f2d..05a051067a 100644 --- a/source3/lib/netapi/user.c +++ b/source3/lib/netapi/user.c @@ -27,15 +27,6 @@ /**************************************************************** ****************************************************************/ -WERROR NetUserAdd_l(struct libnetapi_ctx *ctx, - struct NetUserAdd *r) -{ - return WERR_NOT_SUPPORTED; -} - -/**************************************************************** -****************************************************************/ - static void convert_USER_INFO_1_to_samr_user_info25(struct USER_INFO_1 *info1, DATA_BLOB *user_session_key, struct samr_UserInfo25 *info25) @@ -344,6 +335,20 @@ WERROR NetUserAdd_r(struct libnetapi_ctx *ctx, /**************************************************************** ****************************************************************/ +WERROR NetUserAdd_l(struct libnetapi_ctx *ctx, + struct NetUserAdd *r) +{ + /* for now just talk to local RPC server */ + if (!r->in.server_name) { + r->in.server_name = "localhost"; + } + + return NetUserAdd_r(ctx, r); +} + +/**************************************************************** +****************************************************************/ + WERROR NetUserDel_r(struct libnetapi_ctx *ctx, struct NetUserDel *r) { @@ -515,7 +520,12 @@ WERROR NetUserDel_r(struct libnetapi_ctx *ctx, WERROR NetUserDel_l(struct libnetapi_ctx *ctx, struct NetUserDel *r) { - return WERR_NOT_SUPPORTED; + /* for now just talk to local RPC server */ + if (!r->in.server_name) { + r->in.server_name = "localhost"; + } + + return NetUserDel_r(ctx, r); } /**************************************************************** -- cgit From b10510893955966f36cd8aa0229bfcac6db14055 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 16 Apr 2008 10:03:06 +0200 Subject: libnetapi: Add initial inline doxygen comments. Guenther (This used to be commit 01bc4b6ac03b98c2371b4dfc0948f5ef8d06bcbc) --- source3/lib/netapi/netapi.h | 231 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 195 insertions(+), 36 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h index e93381533b..e9fcc3777a 100644 --- a/source3/lib/netapi/netapi.h +++ b/source3/lib/netapi/netapi.h @@ -179,9 +179,23 @@ const char *libnetapi_get_error_string(struct libnetapi_ctx *ctx, NET_API_STATUS NetApiBufferFree(void *buffer); -/**************************************************************** - NetJoinDomain -****************************************************************/ +/************************************************************//** + * + * NetJoinDomain + * + * @brief Join a computer to a domain or workgroup + * + * @param[in] server The server name to connect to + * @param[in] domain The domain or workgroup to join + * @param[in] account_ou The organizational Unit to create the computer account + * in (AD only) + * @param[in] account The domain account used for joining a domain + * @param[in] password The domain account's password used for joining a domain + * @param[in] join_flags Bitmask field to define specific join features + * @return NET_API_STATUS + * + * example netdomjoin/netdomjoin.c + ***************************************************************/ NET_API_STATUS NetJoinDomain(const char * server /* [in] */, const char * domain /* [in] [ref] */, @@ -190,26 +204,62 @@ NET_API_STATUS NetJoinDomain(const char * server /* [in] */, const char * password /* [in] */, uint32_t join_flags /* [in] */); -/**************************************************************** - NetUnjoinDomain -****************************************************************/ +/************************************************************//** + * + * NetUnjoinDomain + * + * @brief Unjoin a computer from a domain or workgroup + * + * @param[in] server_name The server name to connect to + * @param[in] account The domain account used for unjoining a domain + * @param[in] password The domain account's password used for unjoining a domain + * @param[in] unjoin_flags Bitmask field to define specific unjoin features + * @return NET_API_STATUS + * + ***************************************************************/ NET_API_STATUS NetUnjoinDomain(const char * server_name /* [in] */, const char * account /* [in] */, const char * password /* [in] */, uint32_t unjoin_flags /* [in] */); -/**************************************************************** - NetGetJoinInformation -****************************************************************/ +/************************************************************//** + * + * NetGetJoinInformation + * + * @brief Unjoin a computer from a domain or workgroup + * + * @param[in] server_name The server name to connect to + * @param[out] name_buffer Returns the name of the workgroup or domain + * @param[out] name_type Returns the type of that name + * @return NET_API_STATUS + * + * example netdomjoin-gui/netdomjoin-gui.c + * + ***************************************************************/ NET_API_STATUS NetGetJoinInformation(const char * server_name /* [in] */, const char * *name_buffer /* [out] [ref] */, uint16_t *name_type /* [out] [ref] */); -/**************************************************************** - NetGetJoinableOUs -****************************************************************/ +/************************************************************//** + * + * NetGetJoinableOUs + * + * @brief Query for the list of joinable organizational Units that can be used + * for joining AD + * + * @param[in] server_name The server name to connect to + * @param[in] domain The AD domain to query + * @param[in] account The domain account used for the query + * @param[in] password The domain account's password used for the query + * @param[out] ou_count The number of ous returned + * @param[out] ous Returned string array containing the ous + * @return NET_API_STATUS + * + * example netdomjoin-gui/netdomjoin-gui.c + * + ***************************************************************/ NET_API_STATUS NetGetJoinableOUs(const char * server_name /* [in] */, const char * domain /* [in] [ref] */, @@ -218,43 +268,95 @@ NET_API_STATUS NetGetJoinableOUs(const char * server_name /* [in] */, uint32_t *ou_count /* [out] [ref] */, const char * **ous /* [out] [ref] */); -/**************************************************************** - NetServerGetInfo -****************************************************************/ +/************************************************************//** + * + * NetServerGetInfo + * + * @brief Get Information on a server + * + * @param[in] server_name The server name to connect to + * @param[in] level The level to define which information is requested + * @param[out] buffer The returned buffer carrying the SERVER_INFO structure + * @return NET_API_STATUS + * + ***************************************************************/ NET_API_STATUS NetServerGetInfo(const char * server_name /* [in] */, uint32_t level /* [in] */, uint8_t **buffer /* [out] [ref] */); -/**************************************************************** - NetServerSetInfo -****************************************************************/ +/************************************************************//** + * + * NetServerSetInfo + * + * @brief Get Information on a server + * + * @param[in] server_name The server name to connect to + * @param[in] level The level to define which information is set + * @param[in] buffer The buffer carrying the SERVER_INFO structure + * @param[out] parm_error On failure returns the invalid SERVER_INFO member + * @return NET_API_STATUS + * + ***************************************************************/ NET_API_STATUS NetServerSetInfo(const char * server_name /* [in] */, uint32_t level /* [in] */, uint8_t *buffer /* [in] [ref] */, uint32_t *parm_error /* [out] [ref] */); -/**************************************************************** - NetGetDCName -****************************************************************/ +/************************************************************//** + * + * NetGetDCName + * + * @brief Query for the PDC for a given domain + * + * @param[in] server_name The server name to connect to + * @param[in] domain_name The name of the domain to lookup + * @param[out] buffer The name of the domain to lookup + * @return NET_API_STATUS + * + * example getdc/getdc.c + ***************************************************************/ NET_API_STATUS NetGetDCName(const char * server_name /* [in] */, const char * domain_name /* [in] */, uint8_t **buffer /* [out] [ref] */); -/**************************************************************** - NetGetAnyDCName -****************************************************************/ +/************************************************************//** + * + * NetGetAnyDCName + * + * @brief Query for any DC for a given domain + * + * @param[in] server_name The server name to connect to + * @param[in] domain_name The name of the domain to lookup + * @param[out] buffer The name of the domain to lookup + * @return NET_API_STATUS + * + * example getdc/getdc.c + ***************************************************************/ NET_API_STATUS NetGetAnyDCName(const char * server_name /* [in] */, const char * domain_name /* [in] */, uint8_t **buffer /* [out] [ref] */); -/**************************************************************** - DsGetDcName -****************************************************************/ +/************************************************************//** + * + * DsGetDcName + * + * @brief Lookup a DC for a given domain and return information structure + * + * @param[in] server_name The server name to connect to + * @param[in] domain_name The name of the domain to lookup (cannot be NULL) + * @param[in] domain_guid The GUID of the domain to lookup (optional) + * @param[in] site_name The name of the site the DC should reside in + * @param[in] flags A bitmask to request specific features supported by the DC + * @param[out] dc_info Pointer to a DOMAIN_CONTROLLER_INFO structure + * @return NET_API_STATUS + * + * example dsgetdc/dsgetdc.c + ***************************************************************/ NET_API_STATUS DsGetDcName(const char * server_name /* [in] [unique] */, const char * domain_name /* [in] [ref] */, @@ -263,25 +365,64 @@ NET_API_STATUS DsGetDcName(const char * server_name /* [in] [unique] */, uint32_t flags /* [in] */, struct DOMAIN_CONTROLLER_INFO **dc_info /* [out] [ref] */); -/**************************************************************** - NetUserAdd -****************************************************************/ +/************************************************************//** + * + * NetUserAdd + * + * @brief Create a user on a given server + * + * @param[in] server_name The server name to connect to + * @param[in] level The level of the USER_INFO structure passed in (Currently + * only level 1 is supported) + * @param[in] buffer The buffer carrying the USER_INFO structure + * @param[out] parm_error In case of error returns the failing member of the + * structure + * @return NET_API_STATUS + * + * example user/user_add.c + ***************************************************************/ NET_API_STATUS NetUserAdd(const char * server_name /* [in] */, uint32_t level /* [in] */, uint8_t *buffer /* [in] [ref] */, uint32_t *parm_error /* [out] [ref] */); -/**************************************************************** - NetUserDel -****************************************************************/ +/************************************************************//** + * + * NetUserDel + * + * @brief Delete a user on a given server + * + * @param[in] server_name The server name to connect to + * @param[in] user_name The user account to delete + * @return NET_API_STATUS + * + * example user/user_del.c + ***************************************************************/ NET_API_STATUS NetUserDel(const char * server_name /* [in] */, const char * user_name /* [in] */); -/**************************************************************** - NetUserEnum -****************************************************************/ +/************************************************************//** + * + * NetUserEnum + * + * @brief Enumerate accounts on a server + * + * @param[in] server_name The server name to connect to + * @param[in] level The enumeration level used for the query (Currently only + * level 0 is supported) + * @param[in] filter The account flags filter used for the query + * @param[out] buffer The returned enumeration buffer + * @param[in] prefmaxlen The requested maximal buffer size + * @param[out] entries_read The number of returned entries + * @param[out] total_entries The number of total entries + * @param[in,out] resume_handle A handle passed in and returned for resuming + * operations + * @return NET_API_STATUS + * + * example user/user_enum.c + ***************************************************************/ NET_API_STATUS NetUserEnum(const char * server_name /* [in] */, uint32_t level /* [in] */, @@ -292,6 +433,24 @@ NET_API_STATUS NetUserEnum(const char * server_name /* [in] */, uint32_t *total_entries /* [out] [ref] */, uint32_t *resume_handle /* [in,out] [ref] */); +/************************************************************//** + * + * NetQueryDisplayInformation + * + * @brief Enumerate accounts on a server + * + * @param[in] server_name The server name to connect to + * @param[in] level The enumeration level used for the query + * @param[in] idx The index to start the the display enumeration at + * @param[in] entries_requested The number of entries requested + * @param[in] prefmaxlen The requested maximal buffer size + * @param[out] entries_read The number of returned entries + * @param[out] buffer The returned display information buffer + * @return NET_API_STATUS + * + * example user/user_dispinfo.c + ***************************************************************/ + NET_API_STATUS NetQueryDisplayInformation(const char * server_name /* [in] [unique] */, uint32_t level /* [in] */, uint32_t idx /* [in] */, -- cgit From 73754b98f4b58bd20eac5ffe8ed891313a8644b1 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 17 Apr 2008 14:07:53 +0200 Subject: netdomjoin-gui: Fix label alignment showing up with lower screen-resolution. Guenther (This used to be commit e06a54aa7da857e006649469e7eb8d76711221c1) --- source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c index a7b2079f95..7c84d4d8c6 100644 --- a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c +++ b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c @@ -1306,7 +1306,7 @@ static int draw_main_window(struct join_state *state) { /* Label */ label = gtk_label_new("Computer description:"); -/* gtk_misc_set_alignment(GTK_MISC(label), 0, 0); */ + gtk_misc_set_alignment(GTK_MISC(label), 0, 0); gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 0, 1); gtk_widget_show(label); -- cgit From 08cc63f8147051967140602a2dd2ace2a7d9fe1e Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 17 Apr 2008 14:09:29 +0200 Subject: libnetapi: Disable talloc_enable_leak_report. Guenther (This used to be commit 4ba98dd0cc13984a8dc54e4d4935487fc8938039) --- source3/lib/netapi/netapi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi.c b/source3/lib/netapi/netapi.c index 941e323183..944c2c9304 100644 --- a/source3/lib/netapi/netapi.c +++ b/source3/lib/netapi/netapi.c @@ -40,7 +40,7 @@ NET_API_STATUS libnetapi_init(struct libnetapi_ctx **context) return NET_API_STATUS_SUCCESS; } -#ifdef DEVELOPER +#if 0 talloc_enable_leak_report(); #endif frame = talloc_stackframe(); -- cgit From 2a2188591b5ed922d09dc723adcf10f8b8f5e5a0 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 19 Apr 2008 21:56:43 +0200 Subject: Add "desthost" to rpc_pipe_client This reduces the dependency on cli_state (This used to be commit 783afab9c891dd7bcb78895b2a639b6f3a0edf5b) --- source3/lib/netapi/cm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/cm.c b/source3/lib/netapi/cm.c index 071ebfd4bc..5464237247 100644 --- a/source3/lib/netapi/cm.c +++ b/source3/lib/netapi/cm.c @@ -104,7 +104,7 @@ static struct rpc_pipe_client *pipe_cm_find(struct cli_state *cli, return NULL; } - if (strequal(cli->desthost, p->pipe->cli->desthost) && + if (strequal(cli->desthost, p->pipe->desthost) && pipe_idx == p->pipe->pipe_idx) { *status = NT_STATUS_OK; return p->pipe; -- cgit From f56eedb95c64593ceff0ef91b99729c5071aa7ac Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 20 Apr 2008 11:45:41 +0200 Subject: Remove the pipe_idx variable from rpc_pipe_client (This used to be commit 4840febcd481563c3d9b2fabc1fe1b2ae5a76cf6) --- source3/lib/netapi/cm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/cm.c b/source3/lib/netapi/cm.c index 5464237247..2e16b98ffb 100644 --- a/source3/lib/netapi/cm.c +++ b/source3/lib/netapi/cm.c @@ -105,7 +105,7 @@ static struct rpc_pipe_client *pipe_cm_find(struct cli_state *cli, } if (strequal(cli->desthost, p->pipe->desthost) && - pipe_idx == p->pipe->pipe_idx) { + rpccli_is_pipe_idx(p->pipe, pipe_idx)) { *status = NT_STATUS_OK; return p->pipe; } -- cgit From b9cc05506273e5ce3398a5912b9c9e5989717480 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 20 Apr 2008 14:05:25 +0200 Subject: Introduce rpc_pipe_np_smb_conn() This abstracts away all references to rpc_pipe_client->cli, the only reference is now in cli_pipe.c. (This used to be commit c56e1c08cef107ff33a34346ceeca3475a102b19) --- source3/lib/netapi/cm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/cm.c b/source3/lib/netapi/cm.c index 2e16b98ffb..ae1091c504 100644 --- a/source3/lib/netapi/cm.c +++ b/source3/lib/netapi/cm.c @@ -99,7 +99,7 @@ static struct rpc_pipe_client *pipe_cm_find(struct cli_state *cli, for (p = pipe_connections; p; p = p->next) { - if (!p->pipe->cli) { + if (!rpc_pipe_np_smb_conn(p->pipe)) { *status = NT_STATUS_PIPE_EMPTY; return NULL; } -- cgit From cee268b5cb32076cc09cbfa429a0e2553ba5be4d Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 20 Apr 2008 14:07:38 +0200 Subject: Make convert_samr_dispinfo_to_NET_DISPLAY() static (This used to be commit a30a26d471a572167ee13bf10be1a275a6592851) --- source3/lib/netapi/user.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/user.c b/source3/lib/netapi/user.c index 05a051067a..f2dc785a36 100644 --- a/source3/lib/netapi/user.c +++ b/source3/lib/netapi/user.c @@ -845,11 +845,11 @@ static WERROR convert_samr_dispinfo_to_NET_DISPLAY_GROUP(TALLOC_CTX *mem_ctx, /**************************************************************** ****************************************************************/ -WERROR convert_samr_dispinfo_to_NET_DISPLAY(TALLOC_CTX *mem_ctx, - union samr_DispInfo *info, - uint32_t level, - uint32_t *entries_read, - void **buffer) +static WERROR convert_samr_dispinfo_to_NET_DISPLAY(TALLOC_CTX *mem_ctx, + union samr_DispInfo *info, + uint32_t level, + uint32_t *entries_read, + void **buffer) { switch (level) { case 1: -- cgit From 25c454cbba83b34b53752c11dcc80ae1a3d2e4ed Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Sun, 20 Apr 2008 22:58:52 +0200 Subject: netdomjoin-gui: Omit warning when unjoining a domain fails. Guenther (This used to be commit ba1d2e87614a98b4f811c75a0d9cfa8491f5cb4d) --- source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c index 7c84d4d8c6..5ce4ca2c87 100644 --- a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c +++ b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c @@ -650,6 +650,9 @@ static void callback_do_join(GtkWidget *widget, err_str = libnetapi_get_error_string(state->ctx, status); g_print("callback_do_join: failed to unjoin (%s)\n", err_str); +#if 0 + + /* in fact we shouldn't annoy the user with an error message here */ dialog = gtk_message_dialog_new(GTK_WINDOW(state->window_parent), GTK_DIALOG_DESTROY_WITH_PARENT, @@ -662,6 +665,7 @@ static void callback_do_join(GtkWidget *widget, gtk_window_set_modal(GTK_WINDOW(dialog), TRUE); gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); +#endif } } -- cgit From 50e64115fc45a1887838efad5b33e5fe226fb564 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Sun, 20 Apr 2008 23:03:33 +0200 Subject: libnetapi: Add Doxyfile. Guenther (This used to be commit a34801d67789340b515c5e575c3fd3175dddbecf) --- source3/lib/netapi/Doxyfile | 1362 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 1362 insertions(+) create mode 100644 source3/lib/netapi/Doxyfile (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/Doxyfile b/source3/lib/netapi/Doxyfile new file mode 100644 index 0000000000..44bf78b06c --- /dev/null +++ b/source3/lib/netapi/Doxyfile @@ -0,0 +1,1362 @@ +# Doxyfile 1.5.5 + +# This file describes the settings to be used by the documentation system +# doxygen (www.doxygen.org) for a project +# +# All text after a hash (#) is considered a comment and will be ignored +# The format is: +# TAG = value [value, ...] +# For lists items can also be appended using: +# TAG += value [value, ...] +# Values that contain spaces should be placed between quotes (" ") + +#--------------------------------------------------------------------------- +# Project related configuration options +#--------------------------------------------------------------------------- + +# This tag specifies the encoding used for all characters in the config file +# that follow. The default is UTF-8 which is also the encoding used for all +# text before the first occurrence of this tag. Doxygen uses libiconv (or the +# iconv built into libc) for the transcoding. See +# http://www.gnu.org/software/libiconv for the list of possible encodings. + +DOXYFILE_ENCODING = UTF-8 + +# The PROJECT_NAME tag is a single word (or a sequence of words surrounded +# by quotes) that should identify the project. + +PROJECT_NAME = Samba + +# The PROJECT_NUMBER tag can be used to enter a project or revision number. +# This could be handy for archiving the generated documentation or +# if some version control system is used. + +PROJECT_NUMBER = 3.2.0pre3 + +# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) +# base path where the generated documentation will be put. +# If a relative path is entered, it will be relative to the location +# where doxygen was started. If left blank the current directory will be used. + +OUTPUT_DIRECTORY = dox + +# If the CREATE_SUBDIRS tag is set to YES, then doxygen will create +# 4096 sub-directories (in 2 levels) under the output directory of each output +# format and will distribute the generated files over these directories. +# Enabling this option can be useful when feeding doxygen a huge amount of +# source files, where putting all generated files in the same directory would +# otherwise cause performance problems for the file system. + +CREATE_SUBDIRS = NO + +# The OUTPUT_LANGUAGE tag is used to specify the language in which all +# documentation generated by doxygen is written. Doxygen will use this +# information to generate all constant output in the proper language. +# The default language is English, other supported languages are: +# Afrikaans, Arabic, Brazilian, Catalan, Chinese, Chinese-Traditional, +# Croatian, Czech, Danish, Dutch, Farsi, Finnish, French, German, Greek, +# Hungarian, Italian, Japanese, Japanese-en (Japanese with English messages), +# Korean, Korean-en, Lithuanian, Norwegian, Macedonian, Persian, Polish, +# Portuguese, Romanian, Russian, Serbian, Slovak, Slovene, Spanish, Swedish, +# and Ukrainian. + +OUTPUT_LANGUAGE = English + +# If the BRIEF_MEMBER_DESC tag is set to YES (the default) Doxygen will +# include brief member descriptions after the members that are listed in +# the file and class documentation (similar to JavaDoc). +# Set to NO to disable this. + +BRIEF_MEMBER_DESC = YES + +# If the REPEAT_BRIEF tag is set to YES (the default) Doxygen will prepend +# the brief description of a member or function before the detailed description. +# Note: if both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the +# brief descriptions will be completely suppressed. + +REPEAT_BRIEF = YES + +# This tag implements a quasi-intelligent brief description abbreviator +# that is used to form the text in various listings. Each string +# in this list, if found as the leading text of the brief description, will be +# stripped from the text and the result after processing the whole list, is +# used as the annotated text. Otherwise, the brief description is used as-is. +# If left blank, the following values are used ("$name" is automatically +# replaced with the name of the entity): "The $name class" "The $name widget" +# "The $name file" "is" "provides" "specifies" "contains" +# "represents" "a" "an" "the" + +ABBREVIATE_BRIEF = + +# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then +# Doxygen will generate a detailed section even if there is only a brief +# description. + +ALWAYS_DETAILED_SEC = NO + +# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all +# inherited members of a class in the documentation of that class as if those +# members were ordinary class members. Constructors, destructors and assignment +# operators of the base classes will not be shown. + +INLINE_INHERITED_MEMB = NO + +# If the FULL_PATH_NAMES tag is set to YES then Doxygen will prepend the full +# path before files name in the file list and in the header files. If set +# to NO the shortest path that makes the file name unique will be used. + +FULL_PATH_NAMES = YES + +# If the FULL_PATH_NAMES tag is set to YES then the STRIP_FROM_PATH tag +# can be used to strip a user-defined part of the path. Stripping is +# only done if one of the specified strings matches the left-hand part of +# the path. The tag can be used to show relative paths in the file list. +# If left blank the directory from which doxygen is run is used as the +# path to strip. + +STRIP_FROM_PATH = $(PWD)/ + +# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of +# the path mentioned in the documentation of a class, which tells +# the reader which header file to include in order to use a class. +# If left blank only the name of the header file containing the class +# definition is used. Otherwise one should specify the include paths that +# are normally passed to the compiler using the -I flag. + +STRIP_FROM_INC_PATH = + +# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter +# (but less readable) file names. This can be useful is your file systems +# doesn't support long names like on DOS, Mac, or CD-ROM. + +SHORT_NAMES = NO + +# If the JAVADOC_AUTOBRIEF tag is set to YES then Doxygen +# will interpret the first line (until the first dot) of a JavaDoc-style +# comment as the brief description. If set to NO, the JavaDoc +# comments will behave just like regular Qt-style comments +# (thus requiring an explicit @brief command for a brief description.) + +JAVADOC_AUTOBRIEF = YES + +# If the QT_AUTOBRIEF tag is set to YES then Doxygen will +# interpret the first line (until the first dot) of a Qt-style +# comment as the brief description. If set to NO, the comments +# will behave just like regular Qt-style comments (thus requiring +# an explicit \brief command for a brief description.) + +QT_AUTOBRIEF = NO + +# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make Doxygen +# treat a multi-line C++ special comment block (i.e. a block of //! or /// +# comments) as a brief description. This used to be the default behaviour. +# The new default is to treat a multi-line C++ comment block as a detailed +# description. Set this tag to YES if you prefer the old behaviour instead. + +MULTILINE_CPP_IS_BRIEF = NO + +# If the DETAILS_AT_TOP tag is set to YES then Doxygen +# will output the detailed description near the top, like JavaDoc. +# If set to NO, the detailed description appears after the member +# documentation. + +DETAILS_AT_TOP = NO + +# If the INHERIT_DOCS tag is set to YES (the default) then an undocumented +# member inherits the documentation from any documented member that it +# re-implements. + +INHERIT_DOCS = YES + +# If the SEPARATE_MEMBER_PAGES tag is set to YES, then doxygen will produce +# a new page for each member. If set to NO, the documentation of a member will +# be part of the file/class/namespace that contains it. + +SEPARATE_MEMBER_PAGES = NO + +# The TAB_SIZE tag can be used to set the number of spaces in a tab. +# Doxygen uses this value to replace tabs by spaces in code fragments. + +TAB_SIZE = 8 + +# This tag can be used to specify a number of aliases that acts +# as commands in the documentation. An alias has the form "name=value". +# For example adding "sideeffect=\par Side Effects:\n" will allow you to +# put the command \sideeffect (or @sideeffect) in the documentation, which +# will result in a user-defined paragraph with heading "Side Effects:". +# You can put \n's in the value part of an alias to insert newlines. + +ALIASES = + +# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C +# sources only. Doxygen will then generate output that is more tailored for C. +# For instance, some of the names that are used will be different. The list +# of all members will be omitted, etc. + +OPTIMIZE_OUTPUT_FOR_C = YES + +# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java +# sources only. Doxygen will then generate output that is more tailored for +# Java. For instance, namespaces will be presented as packages, qualified +# scopes will look different, etc. + +OPTIMIZE_OUTPUT_JAVA = NO + +# Set the OPTIMIZE_FOR_FORTRAN tag to YES if your project consists of Fortran +# sources only. Doxygen will then generate output that is more tailored for +# Fortran. + +OPTIMIZE_FOR_FORTRAN = NO + +# Set the OPTIMIZE_OUTPUT_VHDL tag to YES if your project consists of VHDL +# sources. Doxygen will then generate output that is tailored for +# VHDL. + +OPTIMIZE_OUTPUT_VHDL = NO + +# If you use STL classes (i.e. std::string, std::vector, etc.) but do not want +# to include (a tag file for) the STL sources as input, then you should +# set this tag to YES in order to let doxygen match functions declarations and +# definitions whose arguments contain STL classes (e.g. func(std::string); v.s. +# func(std::string) {}). This also make the inheritance and collaboration +# diagrams that involve STL classes more complete and accurate. + +BUILTIN_STL_SUPPORT = NO + +# If you use Microsoft's C++/CLI language, you should set this option to YES to +# enable parsing support. + +CPP_CLI_SUPPORT = NO + +# Set the SIP_SUPPORT tag to YES if your project consists of sip sources only. +# Doxygen will parse them like normal C++ but will assume all classes use public +# instead of private inheritance when no explicit protection keyword is present. + +SIP_SUPPORT = NO + +# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC +# tag is set to YES, then doxygen will reuse the documentation of the first +# member in the group (if any) for the other members of the group. By default +# all members of a group must be documented explicitly. + +DISTRIBUTE_GROUP_DOC = NO + +# Set the SUBGROUPING tag to YES (the default) to allow class member groups of +# the same type (for instance a group of public functions) to be put as a +# subgroup of that type (e.g. under the Public Functions section). Set it to +# NO to prevent subgrouping. Alternatively, this can be done per class using +# the \nosubgrouping command. + +SUBGROUPING = YES + +# When TYPEDEF_HIDES_STRUCT is enabled, a typedef of a struct, union, or enum +# is documented as struct, union, or enum with the name of the typedef. So +# typedef struct TypeS {} TypeT, will appear in the documentation as a struct +# with name TypeT. When disabled the typedef will appear as a member of a file, +# namespace, or class. And the struct will be named TypeS. This can typically +# be useful for C code in case the coding convention dictates that all compound +# types are typedef'ed and only the typedef is referenced, never the tag name. + +TYPEDEF_HIDES_STRUCT = NO + +#--------------------------------------------------------------------------- +# Build related configuration options +#--------------------------------------------------------------------------- + +# If the EXTRACT_ALL tag is set to YES doxygen will assume all entities in +# documentation are documented, even if no documentation was available. +# Private class members and static file members will be hidden unless +# the EXTRACT_PRIVATE and EXTRACT_STATIC tags are set to YES + +EXTRACT_ALL = YES + +# If the EXTRACT_PRIVATE tag is set to YES all private members of a class +# will be included in the documentation. + +EXTRACT_PRIVATE = YES + +# If the EXTRACT_STATIC tag is set to YES all static members of a file +# will be included in the documentation. + +EXTRACT_STATIC = YES + +# If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs) +# defined locally in source files will be included in the documentation. +# If set to NO only classes defined in header files are included. + +EXTRACT_LOCAL_CLASSES = YES + +# This flag is only useful for Objective-C code. When set to YES local +# methods, which are defined in the implementation section but not in +# the interface are included in the documentation. +# If set to NO (the default) only methods in the interface are included. + +EXTRACT_LOCAL_METHODS = NO + +# If this flag is set to YES, the members of anonymous namespaces will be +# extracted and appear in the documentation as a namespace called +# 'anonymous_namespace{file}', where file will be replaced with the base +# name of the file that contains the anonymous namespace. By default +# anonymous namespace are hidden. + +EXTRACT_ANON_NSPACES = NO + +# If the HIDE_UNDOC_MEMBERS tag is set to YES, Doxygen will hide all +# undocumented members of documented classes, files or namespaces. +# If set to NO (the default) these members will be included in the +# various overviews, but no documentation section is generated. +# This option has no effect if EXTRACT_ALL is enabled. + +HIDE_UNDOC_MEMBERS = NO + +# If the HIDE_UNDOC_CLASSES tag is set to YES, Doxygen will hide all +# undocumented classes that are normally visible in the class hierarchy. +# If set to NO (the default) these classes will be included in the various +# overviews. This option has no effect if EXTRACT_ALL is enabled. + +HIDE_UNDOC_CLASSES = NO + +# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, Doxygen will hide all +# friend (class|struct|union) declarations. +# If set to NO (the default) these declarations will be included in the +# documentation. + +HIDE_FRIEND_COMPOUNDS = NO + +# If the HIDE_IN_BODY_DOCS tag is set to YES, Doxygen will hide any +# documentation blocks found inside the body of a function. +# If set to NO (the default) these blocks will be appended to the +# function's detailed documentation block. + +HIDE_IN_BODY_DOCS = NO + +# The INTERNAL_DOCS tag determines if documentation +# that is typed after a \internal command is included. If the tag is set +# to NO (the default) then the documentation will be excluded. +# Set it to YES to include the internal documentation. + +INTERNAL_DOCS = YES + +# If the CASE_SENSE_NAMES tag is set to NO then Doxygen will only generate +# file names in lower-case letters. If set to YES upper-case letters are also +# allowed. This is useful if you have classes or files whose names only differ +# in case and if your file system supports case sensitive file names. Windows +# and Mac users are advised to set this option to NO. + +CASE_SENSE_NAMES = YES + +# If the HIDE_SCOPE_NAMES tag is set to NO (the default) then Doxygen +# will show members with their full class and namespace scopes in the +# documentation. If set to YES the scope will be hidden. + +HIDE_SCOPE_NAMES = YES + +# If the SHOW_INCLUDE_FILES tag is set to YES (the default) then Doxygen +# will put a list of the files that are included by a file in the documentation +# of that file. + +SHOW_INCLUDE_FILES = YES + +# If the INLINE_INFO tag is set to YES (the default) then a tag [inline] +# is inserted in the documentation for inline members. + +INLINE_INFO = YES + +# If the SORT_MEMBER_DOCS tag is set to YES (the default) then doxygen +# will sort the (detailed) documentation of file and class members +# alphabetically by member name. If set to NO the members will appear in +# declaration order. + +SORT_MEMBER_DOCS = NO + +# If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the +# brief documentation of file, namespace and class members alphabetically +# by member name. If set to NO (the default) the members will appear in +# declaration order. + +SORT_BRIEF_DOCS = NO + +# If the SORT_GROUP_NAMES tag is set to YES then doxygen will sort the +# hierarchy of group names into alphabetical order. If set to NO (the default) +# the group names will appear in their defined order. + +SORT_GROUP_NAMES = NO + +# If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be +# sorted by fully-qualified names, including namespaces. If set to +# NO (the default), the class list will be sorted only by class name, +# not including the namespace part. +# Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES. +# Note: This option applies only to the class list, not to the +# alphabetical list. + +SORT_BY_SCOPE_NAME = NO + +# The GENERATE_TODOLIST tag can be used to enable (YES) or +# disable (NO) the todo list. This list is created by putting \todo +# commands in the documentation. + +GENERATE_TODOLIST = YES + +# The GENERATE_TESTLIST tag can be used to enable (YES) or +# disable (NO) the test list. This list is created by putting \test +# commands in the documentation. + +GENERATE_TESTLIST = YES + +# The GENERATE_BUGLIST tag can be used to enable (YES) or +# disable (NO) the bug list. This list is created by putting \bug +# commands in the documentation. + +GENERATE_BUGLIST = YES + +# The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or +# disable (NO) the deprecated list. This list is created by putting +# \deprecated commands in the documentation. + +GENERATE_DEPRECATEDLIST= YES + +# The ENABLED_SECTIONS tag can be used to enable conditional +# documentation sections, marked by \if sectionname ... \endif. + +ENABLED_SECTIONS = + +# The MAX_INITIALIZER_LINES tag determines the maximum number of lines +# the initial value of a variable or define consists of for it to appear in +# the documentation. If the initializer consists of more lines than specified +# here it will be hidden. Use a value of 0 to hide initializers completely. +# The appearance of the initializer of individual variables and defines in the +# documentation can be controlled using \showinitializer or \hideinitializer +# command in the documentation regardless of this setting. + +MAX_INITIALIZER_LINES = 30 + +# Set the SHOW_USED_FILES tag to NO to disable the list of files generated +# at the bottom of the documentation of classes and structs. If set to YES the +# list will mention the files that were used to generate the documentation. + +SHOW_USED_FILES = YES + +# If the sources in your project are distributed over multiple directories +# then setting the SHOW_DIRECTORIES tag to YES will show the directory hierarchy +# in the documentation. The default is NO. + +SHOW_DIRECTORIES = NO + +# The FILE_VERSION_FILTER tag can be used to specify a program or script that +# doxygen should invoke to get the current version for each file (typically from +# the version control system). Doxygen will invoke the program by executing (via +# popen()) the command , where is the value of +# the FILE_VERSION_FILTER tag, and is the name of an input file +# provided by doxygen. Whatever the program writes to standard output +# is used as the file version. See the manual for examples. + +FILE_VERSION_FILTER = + +#--------------------------------------------------------------------------- +# configuration options related to warning and progress messages +#--------------------------------------------------------------------------- + +# The QUIET tag can be used to turn on/off the messages that are generated +# by doxygen. Possible values are YES and NO. If left blank NO is used. + +QUIET = YES + +# The WARNINGS tag can be used to turn on/off the warning messages that are +# generated by doxygen. Possible values are YES and NO. If left blank +# NO is used. + +WARNINGS = NO + +# If WARN_IF_UNDOCUMENTED is set to YES, then doxygen will generate warnings +# for undocumented members. If EXTRACT_ALL is set to YES then this flag will +# automatically be disabled. + +WARN_IF_UNDOCUMENTED = NO + +# If WARN_IF_DOC_ERROR is set to YES, doxygen will generate warnings for +# potential errors in the documentation, such as not documenting some +# parameters in a documented function, or documenting parameters that +# don't exist or using markup commands wrongly. + +WARN_IF_DOC_ERROR = YES + +# This WARN_NO_PARAMDOC option can be abled to get warnings for +# functions that are documented, but have no documentation for their parameters +# or return value. If set to NO (the default) doxygen will only warn about +# wrong or incomplete parameter documentation, but not about the absence of +# documentation. + +WARN_NO_PARAMDOC = NO + +# The WARN_FORMAT tag determines the format of the warning messages that +# doxygen can produce. The string should contain the $file, $line, and $text +# tags, which will be replaced by the file and line number from which the +# warning originated and the warning text. Optionally the format may contain +# $version, which will be replaced by the version of the file (if it could +# be obtained via FILE_VERSION_FILTER) + +WARN_FORMAT = "$file:$line: $text" + +# The WARN_LOGFILE tag can be used to specify a file to which warning +# and error messages should be written. If left blank the output is written +# to stderr. + +WARN_LOGFILE = + +#--------------------------------------------------------------------------- +# configuration options related to the input files +#--------------------------------------------------------------------------- + +# The INPUT tag can be used to specify the files and/or directories that contain +# documented source files. You may enter file names like "myfile.cpp" or +# directories like "/usr/src/myproject". Separate the files or directories +# with spaces. + +INPUT = netapi.h + +# This tag can be used to specify the character encoding of the source files +# that doxygen parses. Internally doxygen uses the UTF-8 encoding, which is +# also the default input encoding. Doxygen uses libiconv (or the iconv built +# into libc) for the transcoding. See http://www.gnu.org/software/libiconv for +# the list of possible encodings. + +INPUT_ENCODING = UTF-8 + +# If the value of the INPUT tag contains directories, you can use the +# FILE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp +# and *.h) to filter out the source-files in the directories. If left +# blank the following patterns are tested: +# *.c *.cc *.cxx *.cpp *.c++ *.java *.ii *.ixx *.ipp *.i++ *.inl *.h *.hh *.hxx +# *.hpp *.h++ *.idl *.odl *.cs *.php *.php3 *.inc *.m *.mm *.py *.f90 + +FILE_PATTERNS = *.c \ + *.h \ + *.idl + +# The RECURSIVE tag can be used to turn specify whether or not subdirectories +# should be searched for input files as well. Possible values are YES and NO. +# If left blank NO is used. + +RECURSIVE = YES + +# The EXCLUDE tag can be used to specify files and/or directories that should +# excluded from the INPUT source files. This way you can easily exclude a +# subdirectory from a directory tree whose root is specified with the INPUT tag. + +EXCLUDE = include/includes.h \ + include/proto.h \ + libnetapi.c \ + libnetapi.h \ + netapi.c + +# The EXCLUDE_SYMLINKS tag can be used select whether or not files or +# directories that are symbolic links (a Unix filesystem feature) are excluded +# from the input. + +EXCLUDE_SYMLINKS = NO + +# If the value of the INPUT tag contains directories, you can use the +# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude +# certain files from those directories. Note that the wildcards are matched +# against the file with absolute path, so to exclude all test directories +# for example use the pattern */test/* + +EXCLUDE_PATTERNS = + +# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names +# (namespaces, classes, functions, etc.) that should be excluded from the +# output. The symbol name can be a fully qualified name, a word, or if the +# wildcard * is used, a substring. Examples: ANamespace, AClass, +# AClass::ANamespace, ANamespace::*Test + +EXCLUDE_SYMBOLS = + +# The EXAMPLE_PATH tag can be used to specify one or more files or +# directories that contain example code fragments that are included (see +# the \include command). + +EXAMPLE_PATH = examples + +# If the value of the EXAMPLE_PATH tag contains directories, you can use the +# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp +# and *.h) to filter out the source-files in the directories. If left +# blank all files are included. + +EXAMPLE_PATTERNS = + +# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be +# searched for input files to be used with the \include or \dontinclude +# commands irrespective of the value of the RECURSIVE tag. +# Possible values are YES and NO. If left blank NO is used. + +EXAMPLE_RECURSIVE = NO + +# The IMAGE_PATH tag can be used to specify one or more files or +# directories that contain image that are included in the documentation (see +# the \image command). + +IMAGE_PATH = + +# The INPUT_FILTER tag can be used to specify a program that doxygen should +# invoke to filter for each input file. Doxygen will invoke the filter program +# by executing (via popen()) the command , where +# is the value of the INPUT_FILTER tag, and is the name of an +# input file. Doxygen will then use the output that the filter program writes +# to standard output. If FILTER_PATTERNS is specified, this tag will be +# ignored. + +INPUT_FILTER = + +# The FILTER_PATTERNS tag can be used to specify filters on a per file pattern +# basis. Doxygen will compare the file name with each pattern and apply the +# filter if there is a match. The filters are a list of the form: +# pattern=filter (like *.cpp=my_cpp_filter). See INPUT_FILTER for further +# info on how filters are used. If FILTER_PATTERNS is empty, INPUT_FILTER +# is applied to all files. + +FILTER_PATTERNS = + +# If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using +# INPUT_FILTER) will be used to filter the input files when producing source +# files to browse (i.e. when SOURCE_BROWSER is set to YES). + +FILTER_SOURCE_FILES = NO + +#--------------------------------------------------------------------------- +# configuration options related to source browsing +#--------------------------------------------------------------------------- + +# If the SOURCE_BROWSER tag is set to YES then a list of source files will +# be generated. Documented entities will be cross-referenced with these sources. +# Note: To get rid of all source code in the generated output, make sure also +# VERBATIM_HEADERS is set to NO. + +SOURCE_BROWSER = YES + +# Setting the INLINE_SOURCES tag to YES will include the body +# of functions and classes directly in the documentation. + +INLINE_SOURCES = YES + +# Setting the STRIP_CODE_COMMENTS tag to YES (the default) will instruct +# doxygen to hide any special comment blocks from generated source code +# fragments. Normal C and C++ comments will always remain visible. + +STRIP_CODE_COMMENTS = NO + +# If the REFERENCED_BY_RELATION tag is set to YES (the default) +# then for each documented function all documented +# functions referencing it will be listed. + +REFERENCED_BY_RELATION = YES + +# If the REFERENCES_RELATION tag is set to YES (the default) +# then for each documented function all documented entities +# called/used by that function will be listed. + +REFERENCES_RELATION = NO + +# If the REFERENCES_LINK_SOURCE tag is set to YES (the default) +# and SOURCE_BROWSER tag is set to YES, then the hyperlinks from +# functions in REFERENCES_RELATION and REFERENCED_BY_RELATION lists will +# link to the source code. Otherwise they will link to the documentstion. + +REFERENCES_LINK_SOURCE = YES + +# If the USE_HTAGS tag is set to YES then the references to source code +# will point to the HTML generated by the htags(1) tool instead of doxygen +# built-in source browser. The htags tool is part of GNU's global source +# tagging system (see http://www.gnu.org/software/global/global.html). You +# will need version 4.8.6 or higher. + +USE_HTAGS = NO + +# If the VERBATIM_HEADERS tag is set to YES (the default) then Doxygen +# will generate a verbatim copy of the header file for each class for +# which an include is specified. Set to NO to disable this. + +VERBATIM_HEADERS = YES + +#--------------------------------------------------------------------------- +# configuration options related to the alphabetical class index +#--------------------------------------------------------------------------- + +# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index +# of all compounds will be generated. Enable this if the project +# contains a lot of classes, structs, unions or interfaces. + +ALPHABETICAL_INDEX = YES + +# If the alphabetical index is enabled (see ALPHABETICAL_INDEX) then +# the COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns +# in which this list will be split (can be a number in the range [1..20]) + +COLS_IN_ALPHA_INDEX = 1 + +# In case all classes in a project start with a common prefix, all +# classes will be put under the same header in the alphabetical index. +# The IGNORE_PREFIX tag can be used to specify one or more prefixes that +# should be ignored while generating the index headers. + +IGNORE_PREFIX = + +#--------------------------------------------------------------------------- +# configuration options related to the HTML output +#--------------------------------------------------------------------------- + +# If the GENERATE_HTML tag is set to YES (the default) Doxygen will +# generate HTML output. + +GENERATE_HTML = YES + +# The HTML_OUTPUT tag is used to specify where the HTML docs will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `html' will be used as the default path. + +HTML_OUTPUT = . + +# The HTML_FILE_EXTENSION tag can be used to specify the file extension for +# each generated HTML page (for example: .htm,.php,.asp). If it is left blank +# doxygen will generate files with .html extension. + +HTML_FILE_EXTENSION = .html + +# The HTML_HEADER tag can be used to specify a personal HTML header for +# each generated HTML page. If it is left blank doxygen will generate a +# standard header. + +HTML_HEADER = + +# The HTML_FOOTER tag can be used to specify a personal HTML footer for +# each generated HTML page. If it is left blank doxygen will generate a +# standard footer. + +HTML_FOOTER = + +# The HTML_STYLESHEET tag can be used to specify a user-defined cascading +# style sheet that is used by each HTML page. It can be used to +# fine-tune the look of the HTML output. If the tag is left blank doxygen +# will generate a default style sheet. Note that doxygen will try to copy +# the style sheet file to the HTML output directory, so don't put your own +# stylesheet in the HTML output directory as well, or it will be erased! + +HTML_STYLESHEET = + +# If the HTML_ALIGN_MEMBERS tag is set to YES, the members of classes, +# files or namespaces will be aligned in HTML using tables. If set to +# NO a bullet list will be used. + +HTML_ALIGN_MEMBERS = YES + +# If the GENERATE_HTMLHELP tag is set to YES, additional index files +# will be generated that can be used as input for tools like the +# Microsoft HTML help workshop to generate a compiled HTML help file (.chm) +# of the generated HTML documentation. + +GENERATE_HTMLHELP = NO + +# If the GENERATE_DOCSET tag is set to YES, additional index files +# will be generated that can be used as input for Apple's Xcode 3 +# integrated development environment, introduced with OSX 10.5 (Leopard). +# To create a documentation set, doxygen will generate a Makefile in the +# HTML output directory. Running make will produce the docset in that +# directory and running "make install" will install the docset in +# ~/Library/Developer/Shared/Documentation/DocSets so that Xcode will find +# it at startup. + +GENERATE_DOCSET = NO + +# When GENERATE_DOCSET tag is set to YES, this tag determines the name of the +# feed. A documentation feed provides an umbrella under which multiple +# documentation sets from a single provider (such as a company or product suite) +# can be grouped. + +DOCSET_FEEDNAME = "Doxygen generated docs" + +# When GENERATE_DOCSET tag is set to YES, this tag specifies a string that +# should uniquely identify the documentation set bundle. This should be a +# reverse domain-name style string, e.g. com.mycompany.MyDocSet. Doxygen +# will append .docset to the name. + +DOCSET_BUNDLE_ID = org.doxygen.Project + +# If the HTML_DYNAMIC_SECTIONS tag is set to YES then the generated HTML +# documentation will contain sections that can be hidden and shown after the +# page has loaded. For this to work a browser that supports +# JavaScript and DHTML is required (for instance Mozilla 1.0+, Firefox +# Netscape 6.0+, Internet explorer 5.0+, Konqueror, or Safari). + +HTML_DYNAMIC_SECTIONS = NO + +# If the GENERATE_HTMLHELP tag is set to YES, the CHM_FILE tag can +# be used to specify the file name of the resulting .chm file. You +# can add a path in front of the file if the result should not be +# written to the html output directory. + +CHM_FILE = + +# If the GENERATE_HTMLHELP tag is set to YES, the HHC_LOCATION tag can +# be used to specify the location (absolute path including file name) of +# the HTML help compiler (hhc.exe). If non-empty doxygen will try to run +# the HTML help compiler on the generated index.hhp. + +HHC_LOCATION = + +# If the GENERATE_HTMLHELP tag is set to YES, the GENERATE_CHI flag +# controls if a separate .chi index file is generated (YES) or that +# it should be included in the master .chm file (NO). + +GENERATE_CHI = NO + +# If the GENERATE_HTMLHELP tag is set to YES, the BINARY_TOC flag +# controls whether a binary table of contents is generated (YES) or a +# normal table of contents (NO) in the .chm file. + +BINARY_TOC = NO + +# The TOC_EXPAND flag can be set to YES to add extra items for group members +# to the contents of the HTML help documentation and to the tree view. + +TOC_EXPAND = NO + +# The DISABLE_INDEX tag can be used to turn on/off the condensed index at +# top of each HTML page. The value NO (the default) enables the index and +# the value YES disables it. + +DISABLE_INDEX = NO + +# This tag can be used to set the number of enum values (range [1..20]) +# that doxygen will group on one line in the generated HTML documentation. + +ENUM_VALUES_PER_LINE = 3 + +# If the GENERATE_TREEVIEW tag is set to YES, a side panel will be +# generated containing a tree-like index structure (just like the one that +# is generated for HTML Help). For this to work a browser that supports +# JavaScript, DHTML, CSS and frames is required (for instance Mozilla 1.0+, +# Netscape 6.0+, Internet explorer 5.0+, or Konqueror). Windows users are +# probably better off using the HTML help feature. + +GENERATE_TREEVIEW = NO + +# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be +# used to set the initial width (in pixels) of the frame in which the tree +# is shown. + +TREEVIEW_WIDTH = 250 + +#--------------------------------------------------------------------------- +# configuration options related to the LaTeX output +#--------------------------------------------------------------------------- + +# If the GENERATE_LATEX tag is set to YES (the default) Doxygen will +# generate Latex output. + +GENERATE_LATEX = NO + +# The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `latex' will be used as the default path. + +LATEX_OUTPUT = latex + +# The LATEX_CMD_NAME tag can be used to specify the LaTeX command name to be +# invoked. If left blank `latex' will be used as the default command name. + +LATEX_CMD_NAME = latex + +# The MAKEINDEX_CMD_NAME tag can be used to specify the command name to +# generate index for LaTeX. If left blank `makeindex' will be used as the +# default command name. + +MAKEINDEX_CMD_NAME = makeindex + +# If the COMPACT_LATEX tag is set to YES Doxygen generates more compact +# LaTeX documents. This may be useful for small projects and may help to +# save some trees in general. + +COMPACT_LATEX = NO + +# The PAPER_TYPE tag can be used to set the paper type that is used +# by the printer. Possible values are: a4, a4wide, letter, legal and +# executive. If left blank a4wide will be used. + +PAPER_TYPE = a4wide + +# The EXTRA_PACKAGES tag can be to specify one or more names of LaTeX +# packages that should be included in the LaTeX output. + +EXTRA_PACKAGES = + +# The LATEX_HEADER tag can be used to specify a personal LaTeX header for +# the generated latex document. The header should contain everything until +# the first chapter. If it is left blank doxygen will generate a +# standard header. Notice: only use this tag if you know what you are doing! + +LATEX_HEADER = + +# If the PDF_HYPERLINKS tag is set to YES, the LaTeX that is generated +# is prepared for conversion to pdf (using ps2pdf). The pdf file will +# contain links (just like the HTML output) instead of page references +# This makes the output suitable for online browsing using a pdf viewer. + +PDF_HYPERLINKS = YES + +# If the USE_PDFLATEX tag is set to YES, pdflatex will be used instead of +# plain latex in the generated Makefile. Set this option to YES to get a +# higher quality PDF documentation. + +USE_PDFLATEX = YES + +# If the LATEX_BATCHMODE tag is set to YES, doxygen will add the \\batchmode. +# command to the generated LaTeX files. This will instruct LaTeX to keep +# running if errors occur, instead of asking the user for help. +# This option is also used when generating formulas in HTML. + +LATEX_BATCHMODE = YES + +# If LATEX_HIDE_INDICES is set to YES then doxygen will not +# include the index chapters (such as File Index, Compound Index, etc.) +# in the output. + +LATEX_HIDE_INDICES = NO + +#--------------------------------------------------------------------------- +# configuration options related to the RTF output +#--------------------------------------------------------------------------- + +# If the GENERATE_RTF tag is set to YES Doxygen will generate RTF output +# The RTF output is optimized for Word 97 and may not look very pretty with +# other RTF readers or editors. + +GENERATE_RTF = NO + +# The RTF_OUTPUT tag is used to specify where the RTF docs will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `rtf' will be used as the default path. + +RTF_OUTPUT = rtf + +# If the COMPACT_RTF tag is set to YES Doxygen generates more compact +# RTF documents. This may be useful for small projects and may help to +# save some trees in general. + +COMPACT_RTF = NO + +# If the RTF_HYPERLINKS tag is set to YES, the RTF that is generated +# will contain hyperlink fields. The RTF file will +# contain links (just like the HTML output) instead of page references. +# This makes the output suitable for online browsing using WORD or other +# programs which support those fields. +# Note: wordpad (write) and others do not support links. + +RTF_HYPERLINKS = NO + +# Load stylesheet definitions from file. Syntax is similar to doxygen's +# config file, i.e. a series of assignments. You only have to provide +# replacements, missing definitions are set to their default value. + +RTF_STYLESHEET_FILE = + +# Set optional variables used in the generation of an rtf document. +# Syntax is similar to doxygen's config file. + +RTF_EXTENSIONS_FILE = + +#--------------------------------------------------------------------------- +# configuration options related to the man page output +#--------------------------------------------------------------------------- + +# If the GENERATE_MAN tag is set to YES (the default) Doxygen will +# generate man pages + +GENERATE_MAN = YES + +# The MAN_OUTPUT tag is used to specify where the man pages will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `man' will be used as the default path. + +MAN_OUTPUT = man + +# The MAN_EXTENSION tag determines the extension that is added to +# the generated man pages (default is the subroutine's section .3) + +MAN_EXTENSION = .3 + +# If the MAN_LINKS tag is set to YES and Doxygen generates man output, +# then it will generate one additional man file for each entity +# documented in the real man page(s). These additional files +# only source the real man page, but without them the man command +# would be unable to find the correct page. The default is NO. + +MAN_LINKS = NO + +#--------------------------------------------------------------------------- +# configuration options related to the XML output +#--------------------------------------------------------------------------- + +# If the GENERATE_XML tag is set to YES Doxygen will +# generate an XML file that captures the structure of +# the code including all documentation. + +GENERATE_XML = NO + +# The XML_OUTPUT tag is used to specify where the XML pages will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `xml' will be used as the default path. + +XML_OUTPUT = xml + +# The XML_SCHEMA tag can be used to specify an XML schema, +# which can be used by a validating XML parser to check the +# syntax of the XML files. + +XML_SCHEMA = + +# The XML_DTD tag can be used to specify an XML DTD, +# which can be used by a validating XML parser to check the +# syntax of the XML files. + +XML_DTD = + +# If the XML_PROGRAMLISTING tag is set to YES Doxygen will +# dump the program listings (including syntax highlighting +# and cross-referencing information) to the XML output. Note that +# enabling this will significantly increase the size of the XML output. + +XML_PROGRAMLISTING = YES + +#--------------------------------------------------------------------------- +# configuration options for the AutoGen Definitions output +#--------------------------------------------------------------------------- + +# If the GENERATE_AUTOGEN_DEF tag is set to YES Doxygen will +# generate an AutoGen Definitions (see autogen.sf.net) file +# that captures the structure of the code including all +# documentation. Note that this feature is still experimental +# and incomplete at the moment. + +GENERATE_AUTOGEN_DEF = NO + +#--------------------------------------------------------------------------- +# configuration options related to the Perl module output +#--------------------------------------------------------------------------- + +# If the GENERATE_PERLMOD tag is set to YES Doxygen will +# generate a Perl module file that captures the structure of +# the code including all documentation. Note that this +# feature is still experimental and incomplete at the +# moment. + +GENERATE_PERLMOD = NO + +# If the PERLMOD_LATEX tag is set to YES Doxygen will generate +# the necessary Makefile rules, Perl scripts and LaTeX code to be able +# to generate PDF and DVI output from the Perl module output. + +PERLMOD_LATEX = NO + +# If the PERLMOD_PRETTY tag is set to YES the Perl module output will be +# nicely formatted so it can be parsed by a human reader. This is useful +# if you want to understand what is going on. On the other hand, if this +# tag is set to NO the size of the Perl module output will be much smaller +# and Perl will parse it just the same. + +PERLMOD_PRETTY = YES + +# The names of the make variables in the generated doxyrules.make file +# are prefixed with the string contained in PERLMOD_MAKEVAR_PREFIX. +# This is useful so different doxyrules.make files included by the same +# Makefile don't overwrite each other's variables. + +PERLMOD_MAKEVAR_PREFIX = + +#--------------------------------------------------------------------------- +# Configuration options related to the preprocessor +#--------------------------------------------------------------------------- + +# If the ENABLE_PREPROCESSING tag is set to YES (the default) Doxygen will +# evaluate all C-preprocessor directives found in the sources and include +# files. + +ENABLE_PREPROCESSING = NO + +# If the MACRO_EXPANSION tag is set to YES Doxygen will expand all macro +# names in the source code. If set to NO (the default) only conditional +# compilation will be performed. Macro expansion can be done in a controlled +# way by setting EXPAND_ONLY_PREDEF to YES. + +MACRO_EXPANSION = NO + +# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES +# then the macro expansion is limited to the macros specified with the +# PREDEFINED and EXPAND_AS_DEFINED tags. + +EXPAND_ONLY_PREDEF = NO + +# If the SEARCH_INCLUDES tag is set to YES (the default) the includes files +# in the INCLUDE_PATH (see below) will be search if a #include is found. + +SEARCH_INCLUDES = YES + +# The INCLUDE_PATH tag can be used to specify one or more directories that +# contain include files that are not input files but should be processed by +# the preprocessor. + +INCLUDE_PATH = + +# You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard +# patterns (like *.h and *.hpp) to filter out the header-files in the +# directories. If left blank, the patterns specified with FILE_PATTERNS will +# be used. + +INCLUDE_FILE_PATTERNS = + +# The PREDEFINED tag can be used to specify one or more macro names that +# are defined before the preprocessor is started (similar to the -D option of +# gcc). The argument of the tag is a list of macros of the form: name +# or name=definition (no spaces). If the definition and the = are +# omitted =1 is assumed. To prevent a macro definition from being +# undefined via #undef or recursively expanded use the := operator +# instead of the = operator. + +PREDEFINED = + +# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then +# this tag can be used to specify a list of macro names that should be expanded. +# The macro definition that is found in the sources will be used. +# Use the PREDEFINED tag if you want to use a different macro definition. + +EXPAND_AS_DEFINED = + +# If the SKIP_FUNCTION_MACROS tag is set to YES (the default) then +# doxygen's preprocessor will remove all function-like macros that are alone +# on a line, have an all uppercase name, and do not end with a semicolon. Such +# function macros are typically used for boiler-plate code, and will confuse +# the parser if not removed. + +SKIP_FUNCTION_MACROS = YES + +#--------------------------------------------------------------------------- +# Configuration::additions related to external references +#--------------------------------------------------------------------------- + +# The TAGFILES option can be used to specify one or more tagfiles. +# Optionally an initial location of the external documentation +# can be added for each tagfile. The format of a tag file without +# this location is as follows: +# TAGFILES = file1 file2 ... +# Adding location for the tag files is done as follows: +# TAGFILES = file1=loc1 "file2 = loc2" ... +# where "loc1" and "loc2" can be relative or absolute paths or +# URLs. If a location is present for each tag, the installdox tool +# does not have to be run to correct the links. +# Note that each tag file must have a unique name +# (where the name does NOT include the path) +# If a tag file is not located in the directory in which doxygen +# is run, you must also specify the path to the tagfile here. + +TAGFILES = + +# When a file name is specified after GENERATE_TAGFILE, doxygen will create +# a tag file that is based on the input files it reads. + +GENERATE_TAGFILE = + +# If the ALLEXTERNALS tag is set to YES all external classes will be listed +# in the class index. If set to NO only the inherited external classes +# will be listed. + +ALLEXTERNALS = NO + +# If the EXTERNAL_GROUPS tag is set to YES all external groups will be listed +# in the modules index. If set to NO, only the current project's groups will +# be listed. + +EXTERNAL_GROUPS = YES + +# The PERL_PATH should be the absolute path and name of the perl script +# interpreter (i.e. the result of `which perl'). + +PERL_PATH = /usr/bin/perl + +#--------------------------------------------------------------------------- +# Configuration options related to the dot tool +#--------------------------------------------------------------------------- + +# If the CLASS_DIAGRAMS tag is set to YES (the default) Doxygen will +# generate a inheritance diagram (in HTML, RTF and LaTeX) for classes with base +# or super classes. Setting the tag to NO turns the diagrams off. Note that +# this option is superseded by the HAVE_DOT option below. This is only a +# fallback. It is recommended to install and use dot, since it yields more +# powerful graphs. + +CLASS_DIAGRAMS = YES + +# You can define message sequence charts within doxygen comments using the \msc +# command. Doxygen will then run the mscgen tool (see +# http://www.mcternan.me.uk/mscgen/) to produce the chart and insert it in the +# documentation. The MSCGEN_PATH tag allows you to specify the directory where +# the mscgen tool resides. If left empty the tool is assumed to be found in the +# default search path. + +MSCGEN_PATH = + +# If set to YES, the inheritance and collaboration graphs will hide +# inheritance and usage relations if the target is undocumented +# or is not a class. + +HIDE_UNDOC_RELATIONS = YES + +# If you set the HAVE_DOT tag to YES then doxygen will assume the dot tool is +# available from the path. This tool is part of Graphviz, a graph visualization +# toolkit from AT&T and Lucent Bell Labs. The other options in this section +# have no effect if this option is set to NO (the default) + +HAVE_DOT = NO + +# If the CLASS_GRAPH and HAVE_DOT tags are set to YES then doxygen +# will generate a graph for each documented class showing the direct and +# indirect inheritance relations. Setting this tag to YES will force the +# the CLASS_DIAGRAMS tag to NO. + +CLASS_GRAPH = YES + +# If the COLLABORATION_GRAPH and HAVE_DOT tags are set to YES then doxygen +# will generate a graph for each documented class showing the direct and +# indirect implementation dependencies (inheritance, containment, and +# class references variables) of the class with other documented classes. + +COLLABORATION_GRAPH = YES + +# If the GROUP_GRAPHS and HAVE_DOT tags are set to YES then doxygen +# will generate a graph for groups, showing the direct groups dependencies + +GROUP_GRAPHS = YES + +# If the UML_LOOK tag is set to YES doxygen will generate inheritance and +# collaboration diagrams in a style similar to the OMG's Unified Modeling +# Language. + +UML_LOOK = NO + +# If set to YES, the inheritance and collaboration graphs will show the +# relations between templates and their instances. + +TEMPLATE_RELATIONS = YES + +# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDE_GRAPH, and HAVE_DOT +# tags are set to YES then doxygen will generate a graph for each documented +# file showing the direct and indirect include dependencies of the file with +# other documented files. + +INCLUDE_GRAPH = YES + +# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDED_BY_GRAPH, and +# HAVE_DOT tags are set to YES then doxygen will generate a graph for each +# documented header file showing the documented files that directly or +# indirectly include this file. + +INCLUDED_BY_GRAPH = YES + +# If the CALL_GRAPH and HAVE_DOT options are set to YES then +# doxygen will generate a call dependency graph for every global function +# or class method. Note that enabling this option will significantly increase +# the time of a run. So in most cases it will be better to enable call graphs +# for selected functions only using the \callgraph command. + +CALL_GRAPH = NO + +# If the CALLER_GRAPH and HAVE_DOT tags are set to YES then +# doxygen will generate a caller dependency graph for every global function +# or class method. Note that enabling this option will significantly increase +# the time of a run. So in most cases it will be better to enable caller +# graphs for selected functions only using the \callergraph command. + +CALLER_GRAPH = NO + +# If the GRAPHICAL_HIERARCHY and HAVE_DOT tags are set to YES then doxygen +# will graphical hierarchy of all classes instead of a textual one. + +GRAPHICAL_HIERARCHY = YES + +# If the DIRECTORY_GRAPH, SHOW_DIRECTORIES and HAVE_DOT tags are set to YES +# then doxygen will show the dependencies a directory has on other directories +# in a graphical way. The dependency relations are determined by the #include +# relations between the files in the directories. + +DIRECTORY_GRAPH = YES + +# The DOT_IMAGE_FORMAT tag can be used to set the image format of the images +# generated by dot. Possible values are png, jpg, or gif +# If left blank png will be used. + +DOT_IMAGE_FORMAT = png + +# The tag DOT_PATH can be used to specify the path where the dot tool can be +# found. If left blank, it is assumed the dot tool can be found in the path. + +DOT_PATH = + +# The DOTFILE_DIRS tag can be used to specify one or more directories that +# contain dot files that are included in the documentation (see the +# \dotfile command). + +DOTFILE_DIRS = + +# The MAX_DOT_GRAPH_MAX_NODES tag can be used to set the maximum number of +# nodes that will be shown in the graph. If the number of nodes in a graph +# becomes larger than this value, doxygen will truncate the graph, which is +# visualized by representing a node as a red box. Note that doxygen if the +# number of direct children of the root node in a graph is already larger than +# DOT_GRAPH_MAX_NODES then the graph will not be shown at all. Also note +# that the size of a graph can be further restricted by MAX_DOT_GRAPH_DEPTH. + +DOT_GRAPH_MAX_NODES = 50 + +# The MAX_DOT_GRAPH_DEPTH tag can be used to set the maximum depth of the +# graphs generated by dot. A depth value of 3 means that only nodes reachable +# from the root by following a path via at most 3 edges will be shown. Nodes +# that lay further from the root node will be omitted. Note that setting this +# option to 1 or 2 may greatly reduce the computation time needed for large +# code bases. Also note that the size of a graph can be further restricted by +# DOT_GRAPH_MAX_NODES. Using a depth of 0 means no depth restriction. + +MAX_DOT_GRAPH_DEPTH = 0 + +# Set the DOT_TRANSPARENT tag to YES to generate images with a transparent +# background. This is enabled by default, which results in a transparent +# background. Warning: Depending on the platform used, enabling this option +# may lead to badly anti-aliased labels on the edges of a graph (i.e. they +# become hard to read). + +DOT_TRANSPARENT = YES + +# Set the DOT_MULTI_TARGETS tag to YES allow dot to generate multiple output +# files in one run (i.e. multiple -o and -T options on the command line). This +# makes dot run faster, but since only newer versions of dot (>1.8.10) +# support this, this feature is disabled by default. + +DOT_MULTI_TARGETS = NO + +# If the GENERATE_LEGEND tag is set to YES (the default) Doxygen will +# generate a legend page explaining the meaning of the various boxes and +# arrows in the dot generated graphs. + +GENERATE_LEGEND = YES + +# If the DOT_CLEANUP tag is set to YES (the default) Doxygen will +# remove the intermediate dot files that are used to generate +# the various graphs. + +DOT_CLEANUP = YES + +#--------------------------------------------------------------------------- +# Configuration::additions related to the search engine +#--------------------------------------------------------------------------- + +# The SEARCHENGINE tag specifies whether or not a search engine should be +# used. If set to NO the values of all tags below this one will be ignored. + +SEARCHENGINE = NO -- cgit From 1223574c7b4833092887653139cf8308d3260b36 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 29 Apr 2008 20:11:02 +0200 Subject: netapi: fix returned name buffer in NetGetJoinInformation_r(). Guenther (This used to be commit 0e8e05d556a7f84e500cca3fa858f9b4a9522a5f) --- source3/lib/netapi/joindomain.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/joindomain.c b/source3/lib/netapi/joindomain.c index 8e0a62e820..74ed8f2302 100644 --- a/source3/lib/netapi/joindomain.c +++ b/source3/lib/netapi/joindomain.c @@ -282,6 +282,7 @@ WERROR NetGetJoinInformation_r(struct libnetapi_ctx *ctx, struct rpc_pipe_client *pipe_cli = NULL; NTSTATUS status; WERROR werr; + const char *buffer = NULL; werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli); if (!W_ERROR_IS_OK(werr)) { @@ -295,7 +296,7 @@ WERROR NetGetJoinInformation_r(struct libnetapi_ctx *ctx, status = rpccli_wkssvc_NetrGetJoinInformation(pipe_cli, ctx, r->in.server_name, - r->out.name_buffer, + &buffer, (enum wkssvc_NetJoinStatus *)r->out.name_type, &werr); if (!NT_STATUS_IS_OK(status)) { @@ -303,6 +304,9 @@ WERROR NetGetJoinInformation_r(struct libnetapi_ctx *ctx, goto done; } + *r->out.name_buffer = talloc_strdup(ctx, buffer); + W_ERROR_HAVE_NO_MEMORY(*r->out.name_buffer); + done: return werr; } -- cgit From f847929c2c25159fef7c1c419ce1819f2afe558f Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 6 May 2008 17:09:44 +0200 Subject: netapi: add -f switch for DsGetDCName() example and be more verbose on output. Guenther (This used to be commit 3feaa9829cc5bdeb7a5401c3c24b3811816396ce) --- source3/lib/netapi/examples/dsgetdc/dsgetdc.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/dsgetdc/dsgetdc.c b/source3/lib/netapi/examples/dsgetdc/dsgetdc.c index 7c0ec4d57d..6265e66a25 100644 --- a/source3/lib/netapi/examples/dsgetdc/dsgetdc.c +++ b/source3/lib/netapi/examples/dsgetdc/dsgetdc.c @@ -34,6 +34,7 @@ int main(int argc, const char **argv) const char *hostname = NULL; const char *domain = NULL; + uint32_t flags = 0; struct DOMAIN_CONTROLLER_INFO *info = NULL; poptContext pc; @@ -42,6 +43,7 @@ int main(int argc, const char **argv) struct poptOption long_options[] = { POPT_AUTOHELP POPT_COMMON_LIBNETAPI_EXAMPLES + { "flags", 0, POPT_ARG_INT, NULL, 'f', "Query flags", "FLAGS" }, POPT_TABLEEND }; @@ -54,6 +56,10 @@ int main(int argc, const char **argv) poptSetOtherOptionHelp(pc, "hostname domainname"); while((opt = poptGetNextOpt(pc)) != -1) { + switch (opt) { + case 'f': + sscanf(poptGetOptArg(pc), "%x", &flags); + } } if (!poptPeekArg(pc)) { @@ -70,15 +76,21 @@ int main(int argc, const char **argv) /* DsGetDcName */ - status = DsGetDcName(hostname, domain, NULL, NULL, 0, &info); + status = DsGetDcName(hostname, domain, NULL, NULL, flags, &info); if (status != 0) { printf("DsGetDcName failed with: %s\n", libnetapi_errstr(status)); return status; } - printf("domain %s has name: %s\n", - info->domain_name, info->domain_controller_name); + printf("DC Name:\t\t%s\n", info->domain_controller_name); + printf("DC Address:\t\t%s\n", info->domain_controller_address); + printf("DC Address Type:\t%d\n", info->domain_controller_address_type); + printf("Domain Name:\t\t%s\n", info->domain_name); + printf("DNS Forest Name:\t%s\n", info->dns_forest_name); + printf("DC flags:\t\t0x%08x\n", info->flags); + printf("DC Sitename:\t\t%s\n", info->dc_site_name); + printf("Client Sitename:\t%s\n", info->client_site_name); out: NetApiBufferFree(info); -- cgit From d3dfdc2f598fae92f1d3d1e95754917ff5869fa7 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 8 May 2008 01:07:10 +0200 Subject: netdomjoin-gui: before prompting for creds, ask dsgetdcname for a dc. Guenther (This used to be commit 47146effc1c2bca516d4fbccf221b5b0e02737bf) --- .../examples/netdomjoin-gui/netdomjoin-gui.c | 35 ++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c index 5ce4ca2c87..a11b0eb0a4 100644 --- a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c +++ b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c @@ -670,6 +670,41 @@ static void callback_do_join(GtkWidget *widget, } + /* before prompting for creds, make sure we can find a dc */ + + if (domain_join) { + + struct DOMAIN_CONTROLLER_INFO *dc_info = NULL; + + status = DsGetDcName(NULL, + state->name_buffer_new, + NULL, + NULL, + 0, + &dc_info); + if (status != 0) { + err_str = libnetapi_get_error_string(state->ctx, status); + g_print("callback_do_join: failed find dc (%s)\n", err_str); + + dialog = gtk_message_dialog_new(GTK_WINDOW(state->window_parent), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR, + GTK_BUTTONS_CLOSE, + "Failed to find a domain controller for domain: \"%s\": %s", + state->name_buffer_new, + err_str); + + gtk_window_set_modal(GTK_WINDOW(dialog), TRUE); + g_signal_connect_swapped(dialog, "response", + G_CALLBACK(gtk_widget_destroy), + dialog); + + gtk_widget_show(dialog); + + return; + } + } + if (join_creds_required) { if (!state->account || !state->password) { debug("callback_do_join: no creds yet\n"); -- cgit From f11acf358225ecf10a8af2a12e304019adc6ee4f Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 8 May 2008 14:23:20 +0200 Subject: Use strip_hostname after dsgetdcname/getdcname calls. Guenther (This used to be commit 82cbb3269b2e764c9c2a2fbcbe9c29feae07fb62) --- source3/lib/netapi/joindomain.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/joindomain.c b/source3/lib/netapi/joindomain.c index 74ed8f2302..b7c9fa5acc 100644 --- a/source3/lib/netapi/joindomain.c +++ b/source3/lib/netapi/joindomain.c @@ -47,6 +47,7 @@ WERROR NetJoinDomain_l(struct libnetapi_ctx *mem_ctx, if (r->in.join_flags & WKSSVC_JOIN_FLAGS_JOIN_TYPE) { NTSTATUS status; struct netr_DsRGetDCNameInfo *info = NULL; + const char *dc = NULL; uint32_t flags = DS_DIRECTORY_SERVICE_REQUIRED | DS_WRITABLE_REQUIRED | DS_RETURN_DNS_NAME; @@ -57,8 +58,9 @@ WERROR NetJoinDomain_l(struct libnetapi_ctx *mem_ctx, "%s", get_friendly_nt_error_msg(status)); return ntstatus_to_werror(status); } - j->in.dc_name = talloc_strdup(mem_ctx, - info->dc_unc); + + dc = strip_hostname(info->dc_unc); + j->in.dc_name = talloc_strdup(mem_ctx, dc); W_ERROR_HAVE_NO_MEMORY(j->in.dc_name); } @@ -174,6 +176,7 @@ WERROR NetUnjoinDomain_l(struct libnetapi_ctx *mem_ctx, } else { NTSTATUS status; struct netr_DsRGetDCNameInfo *info = NULL; + const char *dc = NULL; uint32_t flags = DS_DIRECTORY_SERVICE_REQUIRED | DS_WRITABLE_REQUIRED | DS_RETURN_DNS_NAME; @@ -186,8 +189,9 @@ WERROR NetUnjoinDomain_l(struct libnetapi_ctx *mem_ctx, get_friendly_nt_error_msg(status)); return ntstatus_to_werror(status); } - u->in.dc_name = talloc_strdup(mem_ctx, - info->dc_unc); + + dc = strip_hostname(info->dc_unc); + u->in.dc_name = talloc_strdup(mem_ctx, dc); W_ERROR_HAVE_NO_MEMORY(u->in.dc_name); u->in.domain_name = domain; @@ -352,6 +356,7 @@ WERROR NetGetJoinableOUs_l(struct libnetapi_ctx *ctx, ADS_STATUS ads_status; ADS_STRUCT *ads = NULL; struct netr_DsRGetDCNameInfo *info = NULL; + const char *dc = NULL; uint32_t flags = DS_DIRECTORY_SERVICE_REQUIRED | DS_RETURN_DNS_NAME; @@ -363,7 +368,9 @@ WERROR NetGetJoinableOUs_l(struct libnetapi_ctx *ctx, return ntstatus_to_werror(status); } - ads = ads_init(r->in.domain, r->in.domain, info->dc_unc); + dc = strip_hostname(info->dc_unc); + + ads = ads_init(r->in.domain, r->in.domain, dc); if (!ads) { return WERR_GENERAL_FAILURE; } -- cgit From 67c644aa591c051cfe1e3f3536186ecf0b4449f2 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 8 May 2008 18:32:22 +0200 Subject: dsgetdcname: use existing messaging_context if possible. Guenther (This used to be commit 7889516a384c155a9045aad4409c041fddd0d98d) --- source3/lib/netapi/getdc.c | 1 + source3/lib/netapi/joindomain.c | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/getdc.c b/source3/lib/netapi/getdc.c index 38aaf0ef85..c1d021b1d4 100644 --- a/source3/lib/netapi/getdc.c +++ b/source3/lib/netapi/getdc.c @@ -118,6 +118,7 @@ WERROR DsGetDcName_l(struct libnetapi_ctx *ctx, NTSTATUS status; status = dsgetdcname(ctx, + NULL, r->in.domain_name, r->in.domain_guid, r->in.site_name, diff --git a/source3/lib/netapi/joindomain.c b/source3/lib/netapi/joindomain.c index b7c9fa5acc..66f7cfb13f 100644 --- a/source3/lib/netapi/joindomain.c +++ b/source3/lib/netapi/joindomain.c @@ -51,7 +51,7 @@ WERROR NetJoinDomain_l(struct libnetapi_ctx *mem_ctx, uint32_t flags = DS_DIRECTORY_SERVICE_REQUIRED | DS_WRITABLE_REQUIRED | DS_RETURN_DNS_NAME; - status = dsgetdcname(mem_ctx, r->in.domain, + status = dsgetdcname(mem_ctx, NULL, r->in.domain, NULL, NULL, flags, &info); if (!NT_STATUS_IS_OK(status)) { libnetapi_set_error_string(mem_ctx, @@ -180,7 +180,7 @@ WERROR NetUnjoinDomain_l(struct libnetapi_ctx *mem_ctx, uint32_t flags = DS_DIRECTORY_SERVICE_REQUIRED | DS_WRITABLE_REQUIRED | DS_RETURN_DNS_NAME; - status = dsgetdcname(mem_ctx, domain, + status = dsgetdcname(mem_ctx, NULL, domain, NULL, NULL, flags, &info); if (!NT_STATUS_IS_OK(status)) { libnetapi_set_error_string(mem_ctx, @@ -360,7 +360,7 @@ WERROR NetGetJoinableOUs_l(struct libnetapi_ctx *ctx, uint32_t flags = DS_DIRECTORY_SERVICE_REQUIRED | DS_RETURN_DNS_NAME; - status = dsgetdcname(ctx, r->in.domain, + status = dsgetdcname(ctx, NULL, r->in.domain, NULL, NULL, flags, &info); if (!NT_STATUS_IS_OK(status)) { libnetapi_set_error_string(ctx, "%s", -- cgit From 0b25870b547efdd954ac343c1a753d853a75ba67 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 16 May 2008 12:11:43 +0200 Subject: netdomjoin-gui: before prompting for creds (for receiving joinable ous), find a dc. Guenther (This used to be commit ae60695a349bccd1128e6c439664b0607627ef23) --- .../examples/netdomjoin-gui/netdomjoin-gui.c | 32 +++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c index a11b0eb0a4..df8193707c 100644 --- a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c +++ b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c @@ -932,6 +932,9 @@ static void callback_do_getous(GtkWidget *widget, const char **ous = NULL; int i; const char *domain = NULL; + struct DOMAIN_CONTROLLER_INFO *dc_info = NULL; + const char *err_str = NULL; + GtkWidget *dialog; struct join_state *state = (struct join_state *)data; @@ -939,6 +942,34 @@ static void callback_do_getous(GtkWidget *widget, domain = state->name_buffer_new ? state->name_buffer_new : state->name_buffer_initial; + status = DsGetDcName(NULL, + domain, + NULL, + NULL, + 0, + &dc_info); + if (status != 0) { + err_str = libnetapi_get_error_string(state->ctx, status); + g_print("callback_do_getous: failed find dc (%s)\n", err_str); + + dialog = gtk_message_dialog_new(GTK_WINDOW(state->window_parent), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR, + GTK_BUTTONS_CLOSE, + "Failed to find a domain controller for domain: \"%s\": %s", + domain, + err_str); + + gtk_window_set_modal(GTK_WINDOW(dialog), TRUE); + g_signal_connect_swapped(dialog, "response", + G_CALLBACK(gtk_widget_destroy), + dialog); + + gtk_widget_show(dialog); + + return; + } + if (!state->account || !state->password) { debug("callback_do_getous: no creds yet\n"); callback_creds_prompt(NULL, state, @@ -956,7 +987,6 @@ static void callback_do_getous(GtkWidget *widget, state->password, &num_ous, &ous); if (status != NET_API_STATUS_SUCCESS) { - GtkWidget *dialog; callback_do_freeauth(NULL, state); debug("failed to call NetGetJoinableOUs: %s\n", libnetapi_get_error_string(state->ctx, status)); -- cgit From ee671b19826ebf57d03ec7f3ee8f653d22d9ce3e Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 27 May 2008 12:11:28 +0200 Subject: libnetapi: add dummy implementation for NetGroupAdd() and NetGroupDel(). Guenther (This used to be commit d690f9e9f8b8a0aeda311913589ae48805f7e3b8) --- source3/lib/netapi/group.c | 54 +++++++++++++++++++++++++ source3/lib/netapi/libnetapi.c | 90 +++++++++++++++++++++++++++++++++++++++++- source3/lib/netapi/libnetapi.h | 14 +++++++ 3 files changed, 157 insertions(+), 1 deletion(-) create mode 100644 source3/lib/netapi/group.c (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/group.c b/source3/lib/netapi/group.c new file mode 100644 index 0000000000..3515d28c69 --- /dev/null +++ b/source3/lib/netapi/group.c @@ -0,0 +1,54 @@ +/* + * Unix SMB/CIFS implementation. + * NetApi Group Support + * Copyright (C) Guenther Deschner 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include "includes.h" + +#include "librpc/gen_ndr/libnetapi.h" +#include "lib/netapi/netapi.h" +#include "lib/netapi/netapi_private.h" +#include "lib/netapi/libnetapi.h" + +/**************************************************************** +****************************************************************/ + + +WERROR NetGroupAdd_r(struct libnetapi_ctx *ctx, + struct NetGroupAdd *r) +{ + return WERR_NOT_SUPPORTED; +} + +WERROR NetGroupAdd_l(struct libnetapi_ctx *ctx, + struct NetGroupAdd *r) +{ + return WERR_NOT_SUPPORTED; +} + +WERROR NetGroupDel_r(struct libnetapi_ctx *ctx, + struct NetGroupDel *r) +{ + return WERR_NOT_SUPPORTED; +} + +WERROR NetGroupDel_l(struct libnetapi_ctx *ctx, + struct NetGroupDel *r) +{ + return WERR_NOT_SUPPORTED; +} + diff --git a/source3/lib/netapi/libnetapi.c b/source3/lib/netapi/libnetapi.c index e71adc6893..75087e8b29 100644 --- a/source3/lib/netapi/libnetapi.c +++ b/source3/lib/netapi/libnetapi.c @@ -21,7 +21,7 @@ #include "librpc/gen_ndr/libnetapi.h" #include "lib/netapi/netapi.h" #include "lib/netapi/netapi_private.h" -#include "libnetapi.h" +#include "lib/netapi/libnetapi.h" #include "librpc/gen_ndr/ndr_libnetapi.h" /**************************************************************** @@ -637,3 +637,91 @@ NET_API_STATUS NetQueryDisplayInformation(const char * server_name /* [in] [uniq return r.out.result; } +/**************************************************************** + NetGroupAdd +****************************************************************/ + +NET_API_STATUS NetGroupAdd(const char * server_name /* [in] */, + uint32_t level /* [in] */, + uint8_t *buf /* [in] [ref] */, + uint32_t *parm_err /* [out] [ref] */) +{ + struct NetGroupAdd r; + struct libnetapi_ctx *ctx = NULL; + NET_API_STATUS status; + WERROR werr; + + status = libnetapi_getctx(&ctx); + if (status != 0) { + return status; + } + + /* In parameters */ + r.in.server_name = server_name; + r.in.level = level; + r.in.buf = buf; + + /* Out parameters */ + r.out.parm_err = parm_err; + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_IN_DEBUG(NetGroupAdd, &r); + } + + if (LIBNETAPI_LOCAL_SERVER(server_name)) { + werr = NetGroupAdd_l(ctx, &r); + } else { + werr = NetGroupAdd_r(ctx, &r); + } + + r.out.result = W_ERROR_V(werr); + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_OUT_DEBUG(NetGroupAdd, &r); + } + + return r.out.result; +} + +/**************************************************************** + NetGroupDel +****************************************************************/ + +NET_API_STATUS NetGroupDel(const char * server_name /* [in] */, + const char * group_name /* [in] */) +{ + struct NetGroupDel r; + struct libnetapi_ctx *ctx = NULL; + NET_API_STATUS status; + WERROR werr; + + status = libnetapi_getctx(&ctx); + if (status != 0) { + return status; + } + + /* In parameters */ + r.in.server_name = server_name; + r.in.group_name = group_name; + + /* Out parameters */ + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_IN_DEBUG(NetGroupDel, &r); + } + + if (LIBNETAPI_LOCAL_SERVER(server_name)) { + werr = NetGroupDel_l(ctx, &r); + } else { + werr = NetGroupDel_r(ctx, &r); + } + + r.out.result = W_ERROR_V(werr); + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_OUT_DEBUG(NetGroupDel, &r); + } + + return r.out.result; +} + diff --git a/source3/lib/netapi/libnetapi.h b/source3/lib/netapi/libnetapi.h index 7aff355652..93029ab4f3 100644 --- a/source3/lib/netapi/libnetapi.h +++ b/source3/lib/netapi/libnetapi.h @@ -111,4 +111,18 @@ WERROR NetQueryDisplayInformation_r(struct libnetapi_ctx *ctx, struct NetQueryDisplayInformation *r); WERROR NetQueryDisplayInformation_l(struct libnetapi_ctx *ctx, struct NetQueryDisplayInformation *r); +NET_API_STATUS NetGroupAdd(const char * server_name /* [in] */, + uint32_t level /* [in] */, + uint8_t *buf /* [in] [ref] */, + uint32_t *parm_err /* [out] [ref] */); +WERROR NetGroupAdd_r(struct libnetapi_ctx *ctx, + struct NetGroupAdd *r); +WERROR NetGroupAdd_l(struct libnetapi_ctx *ctx, + struct NetGroupAdd *r); +NET_API_STATUS NetGroupDel(const char * server_name /* [in] */, + const char * group_name /* [in] */); +WERROR NetGroupDel_r(struct libnetapi_ctx *ctx, + struct NetGroupDel *r); +WERROR NetGroupDel_l(struct libnetapi_ctx *ctx, + struct NetGroupDel *r); #endif /* __LIBNETAPI_LIBNETAPI__ */ -- cgit From d8c1f1d24f4c3a065fbb53330f0ed76c31250a3b Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 28 May 2008 01:18:05 +0200 Subject: netapi: Add NetGroupDel/NetGroupAdd header. Guenther (This used to be commit 84104cb900774fd2987636e59e562477c3ed2977) --- source3/lib/netapi/netapi.h | 71 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h index e9fcc3777a..abfd53e0c9 100644 --- a/source3/lib/netapi/netapi.h +++ b/source3/lib/netapi/netapi.h @@ -46,6 +46,17 @@ struct GUID { #ifndef _HEADER_libnetapi +#ifndef MAXSUBAUTHS +#define MAXSUBAUTHS 15 /* max sub authorities in a SID */ +#endif + +struct domsid { + uint8_t sid_rev_num; + uint8_t num_auths; + uint8_t id_auth[6]; + uint32_t sub_auths[MAXSUBAUTHS]; +}; + struct DOMAIN_CONTROLLER_INFO { const char * domain_controller_name; const char * domain_controller_address; @@ -102,6 +113,29 @@ struct NET_DISPLAY_GROUP { uint32_t grpi3_next_index; }; +struct GROUP_INFO_0 { + const char * grpi0_name; +}; + +struct GROUP_INFO_1 { + const char * grpi1_name; + const char * grpi1_comment; +}; + +struct GROUP_INFO_2 { + const char * grpi2_name; + const char * grpi2_comment; + uint32_t grpi2_group_id; + uint32_t grpi2_attributes; +}; + +struct GROUP_INFO_3 { + const char * grpi3_name; + const char * grpi3_comment; + struct domsid grpi3_group_sid; + uint32_t grpi3_attributes; +}; + #endif /* _HEADER_libnetapi */ /**************************************************************** @@ -459,4 +493,41 @@ NET_API_STATUS NetQueryDisplayInformation(const char * server_name /* [in] [uniq uint32_t *entries_read /* [out] [ref] */, void **buffer /* [out] [noprint,ref] */); +/************************************************************//** + * + * NetGroupAdd + * + * @brief Create Domain Group + * + * @param[in] server_name The server name to connect to + * @param[in] level The level used for the new group creation + * @param[in] buf The buffer containing the group structure + * @param[out] parm_err The returned parameter error number if any + * @return NET_API_STATUS + * + * example group/group_add.c + ***************************************************************/ + +NET_API_STATUS NetGroupAdd(const char * server_name /* [in] */, + uint32_t level /* [in] */, + uint8_t *buf /* [in] [ref] */, + uint32_t *parm_err /* [out] [ref] */); + +/************************************************************//** + * + * NetGroupDel + * + * @brief Delete Domain Group + * + * @param[in] server_name The server name to connect to + * @param[in] group_name The name of the group that is going to be deleted + * @return NET_API_STATUS + * + * example group/group_del.c + ***************************************************************/ + + +NET_API_STATUS NetGroupDel(const char * server_name /* [in] */, + const char * group_name /* [in] */); + #endif -- cgit From c36b5dc227285e622370b0bc11d34bac1d2884b1 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 28 May 2008 14:48:30 +0200 Subject: netapi: implement NetGroupAdd_r(). Guenther (This used to be commit b00bff961ea786b0cbd8ec7faf554efae72169ea) --- source3/lib/netapi/group.c | 239 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 237 insertions(+), 2 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/group.c b/source3/lib/netapi/group.c index 3515d28c69..4e4530a005 100644 --- a/source3/lib/netapi/group.c +++ b/source3/lib/netapi/group.c @@ -27,13 +27,248 @@ /**************************************************************** ****************************************************************/ - WERROR NetGroupAdd_r(struct libnetapi_ctx *ctx, struct NetGroupAdd *r) { - return WERR_NOT_SUPPORTED; + struct cli_state *cli = NULL; + struct rpc_pipe_client *pipe_cli = NULL; + NTSTATUS status; + WERROR werr; + uint32_t resume_handle = 0; + uint32_t num_entries = 0; + POLICY_HND connect_handle, domain_handle, group_handle; + struct samr_SamArray *sam = NULL; + const char *domain_name = NULL; + struct lsa_String lsa_domain_name, lsa_group_name; + struct dom_sid2 *domain_sid = NULL; + uint32_t rid = 0; + bool domain_found = true; + int i; + struct GROUP_INFO_0 *info0; + struct GROUP_INFO_1 *info1; + struct GROUP_INFO_2 *info2; + struct GROUP_INFO_3 *info3; + union samr_GroupInfo info; + + ZERO_STRUCT(connect_handle); + ZERO_STRUCT(domain_handle); + ZERO_STRUCT(group_handle); + + if (!r->in.buf) { + return WERR_INVALID_PARAM; + } + + switch (r->in.level) { + case 0: + info0 = (struct GROUP_INFO_0 *)r->in.buf; + break; + case 1: + info1 = (struct GROUP_INFO_1 *)r->in.buf; + break; + case 2: + info2 = (struct GROUP_INFO_2 *)r->in.buf; + break; + case 3: + info3 = (struct GROUP_INFO_3 *)r->in.buf; + break; + default: + werr = WERR_UNKNOWN_LEVEL; + goto done; + } + + werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + werr = libnetapi_open_pipe(ctx, cli, PI_SAMR, &pipe_cli); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + status = rpccli_try_samr_connects(pipe_cli, ctx, + SAMR_ACCESS_ENUM_DOMAINS | + SAMR_ACCESS_OPEN_DOMAIN, + &connect_handle); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + status = rpccli_samr_EnumDomains(pipe_cli, ctx, + &connect_handle, + &resume_handle, + &sam, + 0xffffffff, + &num_entries); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + for (i=0; ientries[i].name.string; + + if (strequal(domain_name, builtin_domain_name())) { + continue; + } + + domain_found = true; + break; + } + + if (!domain_found) { + werr = WERR_NO_SUCH_DOMAIN; + goto done; + } + + init_lsa_String(&lsa_domain_name, domain_name); + + status = rpccli_samr_LookupDomain(pipe_cli, ctx, + &connect_handle, + &lsa_domain_name, + &domain_sid); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + status = rpccli_samr_OpenDomain(pipe_cli, ctx, + &connect_handle, + SAMR_DOMAIN_ACCESS_CREATE_GROUP | + SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, + domain_sid, + &domain_handle); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + switch (r->in.level) { + case 0: + init_lsa_String(&lsa_group_name, info0->grpi0_name); + break; + case 1: + init_lsa_String(&lsa_group_name, info1->grpi1_name); + break; + case 2: + init_lsa_String(&lsa_group_name, info2->grpi2_name); + break; + case 3: + init_lsa_String(&lsa_group_name, info3->grpi3_name); + break; + } + + status = rpccli_samr_CreateDomainGroup(pipe_cli, ctx, + &domain_handle, + &lsa_group_name, + SEC_STD_DELETE | + SAMR_GROUP_ACCESS_SET_INFO, + &group_handle, + &rid); + + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + switch (r->in.level) { + case 1: + if (info1->grpi1_comment) { + init_lsa_String(&info.description, + info1->grpi1_comment); + + status = rpccli_samr_SetGroupInfo(pipe_cli, ctx, + &group_handle, + GROUPINFODESCRIPTION, + &info); + } + break; + case 2: + if (info2->grpi2_comment) { + init_lsa_String(&info.description, + info2->grpi2_comment); + + status = rpccli_samr_SetGroupInfo(pipe_cli, ctx, + &group_handle, + GROUPINFODESCRIPTION, + &info); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto failed; + } + } + + if (info2->grpi2_attributes != 0) { + info.attributes.attributes = info2->grpi2_attributes; + status = rpccli_samr_SetGroupInfo(pipe_cli, ctx, + &group_handle, + GROUPINFOATTRIBUTES, + &info); + + } + break; + case 3: + if (info3->grpi3_comment) { + init_lsa_String(&info.description, + info3->grpi3_comment); + + status = rpccli_samr_SetGroupInfo(pipe_cli, ctx, + &group_handle, + GROUPINFODESCRIPTION, + &info); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto failed; + } + } + + if (info3->grpi3_attributes != 0) { + info.attributes.attributes = info3->grpi3_attributes; + status = rpccli_samr_SetGroupInfo(pipe_cli, ctx, + &group_handle, + GROUPINFOATTRIBUTES, + &info); + } + break; + default: + break; + } + + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto failed; + } + + werr = WERR_OK; + goto done; + + failed: + rpccli_samr_DeleteDomainGroup(pipe_cli, ctx, + &group_handle); + + done: + if (!cli) { + return werr; + } + + if (is_valid_policy_hnd(&group_handle)) { + rpccli_samr_Close(pipe_cli, ctx, &group_handle); + } + if (is_valid_policy_hnd(&domain_handle)) { + rpccli_samr_Close(pipe_cli, ctx, &domain_handle); + } + if (is_valid_policy_hnd(&connect_handle)) { + rpccli_samr_Close(pipe_cli, ctx, &connect_handle); + } + + return werr; } +/**************************************************************** +****************************************************************/ + WERROR NetGroupAdd_l(struct libnetapi_ctx *ctx, struct NetGroupAdd *r) { -- cgit From 2ae4df46e83f47ccc9a6aff330ad4e8cd01df3c8 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 28 May 2008 14:56:45 +0200 Subject: netapi: add NetGroupAdd() example code. Guenther (This used to be commit 53272e29ad9c2a6c81ab35a405c57b1799f3f832) --- source3/lib/netapi/examples/Makefile.in | 8 ++- source3/lib/netapi/examples/group/group_add.c | 90 +++++++++++++++++++++++++++ 2 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 source3/lib/netapi/examples/group/group_add.c (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/Makefile.in b/source3/lib/netapi/examples/Makefile.in index 1e2e28c471..89f869555d 100644 --- a/source3/lib/netapi/examples/Makefile.in +++ b/source3/lib/netapi/examples/Makefile.in @@ -25,7 +25,8 @@ PROGS = bin/getdc@EXEEXT@ \ bin/user_add@EXEEXT@ \ bin/user_del@EXEEXT@ \ bin/user_enum@EXEEXT@ \ - bin/user_dispinfo@EXEEXT@ + bin/user_dispinfo@EXEEXT@ \ + bin/group_add@EXEEXT@ all: $(PROGS) @@ -63,6 +64,7 @@ USERADD_OBJ = user/user_add.o $(CMDLINE_OBJ) USERDEL_OBJ = user/user_del.o $(CMDLINE_OBJ) USERENUM_OBJ = user/user_enum.o $(CMDLINE_OBJ) USERDISPINFO_OBJ = user/user_dispinfo.o $(CMDLINE_OBJ) +GROUPADD_OBJ = group/group_add.o $(CMDLINE_OBJ) bin/getdc@EXEEXT@: $(BINARY_PREREQS) $(GETDC_OBJ) @echo Linking $@ @@ -100,6 +102,10 @@ bin/user_dispinfo@EXEEXT@: $(BINARY_PREREQS) $(USERDISPINFO_OBJ) @echo Linking $@ @$(CC) $(FLAGS) -o $@ $(USERDISPINFO_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) +bin/group_add@EXEEXT@: $(BINARY_PREREQS) $(GROUPADD_OBJ) + @echo Linking $@ + @$(CC) $(FLAGS) -o $@ $(GROUPADD_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) + clean: -rm -f $(PROGS) -rm -f core */*~ *~ \ diff --git a/source3/lib/netapi/examples/group/group_add.c b/source3/lib/netapi/examples/group/group_add.c new file mode 100644 index 0000000000..4da97c5fc5 --- /dev/null +++ b/source3/lib/netapi/examples/group/group_add.c @@ -0,0 +1,90 @@ +/* + * Unix SMB/CIFS implementation. + * NetGroupAdd query + * Copyright (C) Guenther Deschner 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include +#include +#include +#include +#include + +#include + +#include "common.h" + +int main(int argc, const char **argv) +{ + NET_API_STATUS status; + struct libnetapi_ctx *ctx = NULL; + const char *hostname = NULL; + const char *groupname = NULL; + struct GROUP_INFO_1 g1; + uint32_t parm_error = 0; + + poptContext pc; + int opt; + + struct poptOption long_options[] = { + POPT_AUTOHELP + POPT_COMMON_LIBNETAPI_EXAMPLES + POPT_TABLEEND + }; + + status = libnetapi_init(&ctx); + if (status != 0) { + return status; + } + + pc = poptGetContext("group_add", argc, argv, long_options, 0); + + poptSetOtherOptionHelp(pc, "hostname groupname"); + while((opt = poptGetNextOpt(pc)) != -1) { + } + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + hostname = poptGetArg(pc); + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + groupname = poptGetArg(pc); + + /* NetGroupAdd */ + + g1.grpi1_name = groupname; + g1.grpi1_comment = "Domain Group created using NetApi example code"; + + status = NetGroupAdd(hostname, + 1, + (uint8_t *)&g1, + &parm_error); + if (status != 0) { + printf("NetGroupAdd failed with: %s\n", + libnetapi_get_error_string(ctx, status)); + } + + out: + libnetapi_free(ctx); + poptFreeContext(pc); + + return status; +} -- cgit From e310fac54f77b473cd3109f227f0e6efd1e21c05 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 29 May 2008 01:43:06 +0200 Subject: netapi: implement NetGroupDel_r(). Guenther (This used to be commit bcf3df6ca96845755eee6c762f57548de8aba610) --- source3/lib/netapi/group.c | 211 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 209 insertions(+), 2 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/group.c b/source3/lib/netapi/group.c index 4e4530a005..fe75880d1a 100644 --- a/source3/lib/netapi/group.c +++ b/source3/lib/netapi/group.c @@ -275,15 +275,222 @@ WERROR NetGroupAdd_l(struct libnetapi_ctx *ctx, return WERR_NOT_SUPPORTED; } +/**************************************************************** +****************************************************************/ + WERROR NetGroupDel_r(struct libnetapi_ctx *ctx, struct NetGroupDel *r) { - return WERR_NOT_SUPPORTED; + struct cli_state *cli = NULL; + struct rpc_pipe_client *pipe_cli = NULL; + NTSTATUS status; + WERROR werr; + uint32_t resume_handle = 0; + uint32_t num_entries = 0; + POLICY_HND connect_handle, domain_handle, group_handle; + struct samr_SamArray *sam = NULL; + const char *domain_name = NULL; + struct lsa_String lsa_domain_name, lsa_group_name; + struct dom_sid2 *domain_sid = NULL; + bool domain_found = true; + int i; + + struct samr_Ids rids; + struct samr_Ids types; + union samr_GroupInfo *info = NULL; + struct samr_RidTypeArray *rid_array = NULL; + + ZERO_STRUCT(connect_handle); + ZERO_STRUCT(domain_handle); + ZERO_STRUCT(group_handle); + + if (!r->in.group_name) { + return WERR_INVALID_PARAM; + } + + werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + werr = libnetapi_open_pipe(ctx, cli, PI_SAMR, &pipe_cli); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + status = rpccli_try_samr_connects(pipe_cli, ctx, + SAMR_ACCESS_ENUM_DOMAINS | + SAMR_ACCESS_OPEN_DOMAIN, + &connect_handle); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + status = rpccli_samr_EnumDomains(pipe_cli, ctx, + &connect_handle, + &resume_handle, + &sam, + 0xffffffff, + &num_entries); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + for (i=0; ientries[i].name.string; + + if (strequal(domain_name, builtin_domain_name())) { + continue; + } + + domain_found = true; + break; + } + + if (!domain_found) { + werr = WERR_NO_SUCH_DOMAIN; + goto done; + } + + init_lsa_String(&lsa_domain_name, domain_name); + + status = rpccli_samr_LookupDomain(pipe_cli, ctx, + &connect_handle, + &lsa_domain_name, + &domain_sid); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + status = rpccli_samr_OpenDomain(pipe_cli, ctx, + &connect_handle, + SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, + domain_sid, + &domain_handle); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + init_lsa_String(&lsa_group_name, r->in.group_name); + + status = rpccli_samr_LookupNames(pipe_cli, ctx, + &domain_handle, + 1, + &lsa_group_name, + &rids, + &types); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + if (types.ids[0] != SID_NAME_DOM_GRP) { + werr = WERR_INVALID_DATATYPE; + goto done; + } + + status = rpccli_samr_OpenGroup(pipe_cli, ctx, + &domain_handle, + SEC_STD_DELETE | + SAMR_GROUP_ACCESS_GET_MEMBERS | + SAMR_GROUP_ACCESS_REMOVE_MEMBER | + SAMR_GROUP_ACCESS_ADD_MEMBER | + SAMR_GROUP_ACCESS_LOOKUP_INFO, + rids.ids[0], + &group_handle); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + status = rpccli_samr_QueryGroupInfo(pipe_cli, ctx, + &group_handle, + GROUPINFOATTRIBUTES, + &info); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + if (!(info->attributes.attributes & SE_GROUP_ENABLED)) { + werr = WERR_ACCESS_DENIED; + goto done; + } + + status = rpccli_samr_QueryGroupMember(pipe_cli, ctx, + &group_handle, + &rid_array); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + { + struct lsa_Strings names; + struct samr_Ids member_types; + + status = rpccli_samr_LookupRids(pipe_cli, ctx, + &domain_handle, + rid_array->count, + rid_array->rids, + &names, + &member_types); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + } + + for (i=0; i < rid_array->count; i++) { + + status = rpccli_samr_DeleteGroupMember(pipe_cli, ctx, + &group_handle, + rid_array->rids[i]); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + } + + status = rpccli_samr_DeleteDomainGroup(pipe_cli, ctx, + &group_handle); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + ZERO_STRUCT(group_handle); + + werr = WERR_OK; + + done: + if (!cli) { + return werr; + } + + if (is_valid_policy_hnd(&group_handle)) { + rpccli_samr_Close(pipe_cli, ctx, &group_handle); + } + if (is_valid_policy_hnd(&domain_handle)) { + rpccli_samr_Close(pipe_cli, ctx, &domain_handle); + } + if (is_valid_policy_hnd(&connect_handle)) { + rpccli_samr_Close(pipe_cli, ctx, &connect_handle); + } + + return werr; } +/**************************************************************** +****************************************************************/ + WERROR NetGroupDel_l(struct libnetapi_ctx *ctx, struct NetGroupDel *r) { return WERR_NOT_SUPPORTED; } - -- cgit From 4e85043e267720a442e43dd6b6ceba378f7aadf4 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 29 May 2008 01:43:52 +0200 Subject: netapi: add NetGroupDel() example code. Guenther (This used to be commit 08f345741110c6e25fa6a4349885c3066acf5205) --- source3/lib/netapi/examples/Makefile.in | 8 ++- source3/lib/netapi/examples/group/group_del.c | 82 +++++++++++++++++++++++++++ 2 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 source3/lib/netapi/examples/group/group_del.c (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/Makefile.in b/source3/lib/netapi/examples/Makefile.in index 89f869555d..01f4a9d1ae 100644 --- a/source3/lib/netapi/examples/Makefile.in +++ b/source3/lib/netapi/examples/Makefile.in @@ -26,7 +26,8 @@ PROGS = bin/getdc@EXEEXT@ \ bin/user_del@EXEEXT@ \ bin/user_enum@EXEEXT@ \ bin/user_dispinfo@EXEEXT@ \ - bin/group_add@EXEEXT@ + bin/group_add@EXEEXT@ \ + bin/group_del@EXEEXT@ all: $(PROGS) @@ -65,6 +66,7 @@ USERDEL_OBJ = user/user_del.o $(CMDLINE_OBJ) USERENUM_OBJ = user/user_enum.o $(CMDLINE_OBJ) USERDISPINFO_OBJ = user/user_dispinfo.o $(CMDLINE_OBJ) GROUPADD_OBJ = group/group_add.o $(CMDLINE_OBJ) +GROUPDEL_OBJ = group/group_del.o $(CMDLINE_OBJ) bin/getdc@EXEEXT@: $(BINARY_PREREQS) $(GETDC_OBJ) @echo Linking $@ @@ -106,6 +108,10 @@ bin/group_add@EXEEXT@: $(BINARY_PREREQS) $(GROUPADD_OBJ) @echo Linking $@ @$(CC) $(FLAGS) -o $@ $(GROUPADD_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) +bin/group_del@EXEEXT@: $(BINARY_PREREQS) $(GROUPDEL_OBJ) + @echo Linking $@ + @$(CC) $(FLAGS) -o $@ $(GROUPDEL_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) + clean: -rm -f $(PROGS) -rm -f core */*~ *~ \ diff --git a/source3/lib/netapi/examples/group/group_del.c b/source3/lib/netapi/examples/group/group_del.c new file mode 100644 index 0000000000..789e429ea2 --- /dev/null +++ b/source3/lib/netapi/examples/group/group_del.c @@ -0,0 +1,82 @@ +/* + * Unix SMB/CIFS implementation. + * NetGroupDel query + * Copyright (C) Guenther Deschner 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include +#include +#include +#include +#include + +#include + +#include "common.h" + +int main(int argc, const char **argv) +{ + NET_API_STATUS status; + struct libnetapi_ctx *ctx = NULL; + const char *hostname = NULL; + const char *groupname = NULL; + + poptContext pc; + int opt; + + struct poptOption long_options[] = { + POPT_AUTOHELP + POPT_COMMON_LIBNETAPI_EXAMPLES + POPT_TABLEEND + }; + + status = libnetapi_init(&ctx); + if (status != 0) { + return status; + } + + pc = poptGetContext("group_del", argc, argv, long_options, 0); + + poptSetOtherOptionHelp(pc, "hostname groupname"); + while((opt = poptGetNextOpt(pc)) != -1) { + } + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + hostname = poptGetArg(pc); + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + groupname = poptGetArg(pc); + + /* NetGroupDel */ + + status = NetGroupDel(hostname, groupname); + if (status != 0) { + printf("NetGroupDel failed with: %s\n", + libnetapi_get_error_string(ctx, status)); + } + + out: + libnetapi_free(ctx); + poptFreeContext(pc); + + return status; +} -- cgit From 903c418b5aac90bc2c2375895e8191ecf51bc0d7 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 29 May 2008 01:44:21 +0200 Subject: netapi: let NetGroupAdd_l and NetGroupDel_l call the remote functions. Guenther (This used to be commit d62eae5705e001ed7e39832b52ae139c19549ab8) --- source3/lib/netapi/group.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/group.c b/source3/lib/netapi/group.c index fe75880d1a..b47e099ce6 100644 --- a/source3/lib/netapi/group.c +++ b/source3/lib/netapi/group.c @@ -272,7 +272,7 @@ WERROR NetGroupAdd_r(struct libnetapi_ctx *ctx, WERROR NetGroupAdd_l(struct libnetapi_ctx *ctx, struct NetGroupAdd *r) { - return WERR_NOT_SUPPORTED; + return NetGroupAdd_r(ctx, r); } /**************************************************************** @@ -492,5 +492,5 @@ WERROR NetGroupDel_r(struct libnetapi_ctx *ctx, WERROR NetGroupDel_l(struct libnetapi_ctx *ctx, struct NetGroupDel *r) { - return WERR_NOT_SUPPORTED; + return NetGroupDel_r(ctx, r); } -- cgit From b01a0a16a6dc167bf25fb2f90cb7d7a4471194c2 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 2 Jun 2008 12:54:17 +0200 Subject: netapi: Add dummy implementation of NetGroupSetInfo(). Guenther (This used to be commit 7e47bdc0829d7ac856028a99389310f721a265ce) --- source3/lib/netapi/group.c | 18 ++++++++++++++++ source3/lib/netapi/libnetapi.c | 48 ++++++++++++++++++++++++++++++++++++++++++ source3/lib/netapi/libnetapi.h | 9 ++++++++ source3/lib/netapi/netapi.h | 30 +++++++++++++++++++++++++- 4 files changed, 104 insertions(+), 1 deletion(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/group.c b/source3/lib/netapi/group.c index b47e099ce6..7eb6d7c840 100644 --- a/source3/lib/netapi/group.c +++ b/source3/lib/netapi/group.c @@ -494,3 +494,21 @@ WERROR NetGroupDel_l(struct libnetapi_ctx *ctx, { return NetGroupDel_r(ctx, r); } + +/**************************************************************** +****************************************************************/ + +WERROR NetGroupSetInfo_r(struct libnetapi_ctx *ctx, + struct NetGroupSetInfo *r) +{ + return WERR_NOT_SUPPORTED; +} + +/**************************************************************** +****************************************************************/ + +WERROR NetGroupSetInfo_l(struct libnetapi_ctx *ctx, + struct NetGroupSetInfo *r) +{ + return WERR_NOT_SUPPORTED; +} diff --git a/source3/lib/netapi/libnetapi.c b/source3/lib/netapi/libnetapi.c index 75087e8b29..0e1d1b30a5 100644 --- a/source3/lib/netapi/libnetapi.c +++ b/source3/lib/netapi/libnetapi.c @@ -725,3 +725,51 @@ NET_API_STATUS NetGroupDel(const char * server_name /* [in] */, return r.out.result; } +/**************************************************************** + NetGroupSetInfo +****************************************************************/ + +NET_API_STATUS NetGroupSetInfo(const char * server_name /* [in] */, + const char * group_name /* [in] */, + uint32_t level /* [in] */, + uint8_t *buf /* [in] [ref] */, + uint32_t *parm_err /* [out] [ref] */) +{ + struct NetGroupSetInfo r; + struct libnetapi_ctx *ctx = NULL; + NET_API_STATUS status; + WERROR werr; + + status = libnetapi_getctx(&ctx); + if (status != 0) { + return status; + } + + /* In parameters */ + r.in.server_name = server_name; + r.in.group_name = group_name; + r.in.level = level; + r.in.buf = buf; + + /* Out parameters */ + r.out.parm_err = parm_err; + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_IN_DEBUG(NetGroupSetInfo, &r); + } + + if (LIBNETAPI_LOCAL_SERVER(server_name)) { + werr = NetGroupSetInfo_l(ctx, &r); + } else { + werr = NetGroupSetInfo_r(ctx, &r); + } + + r.out.result = W_ERROR_V(werr); + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_OUT_DEBUG(NetGroupSetInfo, &r); + } + + return r.out.result; +} + diff --git a/source3/lib/netapi/libnetapi.h b/source3/lib/netapi/libnetapi.h index 93029ab4f3..9a7bbd1953 100644 --- a/source3/lib/netapi/libnetapi.h +++ b/source3/lib/netapi/libnetapi.h @@ -125,4 +125,13 @@ WERROR NetGroupDel_r(struct libnetapi_ctx *ctx, struct NetGroupDel *r); WERROR NetGroupDel_l(struct libnetapi_ctx *ctx, struct NetGroupDel *r); +NET_API_STATUS NetGroupSetInfo(const char * server_name /* [in] */, + const char * group_name /* [in] */, + uint32_t level /* [in] */, + uint8_t *buf /* [in] [ref] */, + uint32_t *parm_err /* [out] [ref] */); +WERROR NetGroupSetInfo_r(struct libnetapi_ctx *ctx, + struct NetGroupSetInfo *r); +WERROR NetGroupSetInfo_l(struct libnetapi_ctx *ctx, + struct NetGroupSetInfo *r); #endif /* __LIBNETAPI_LIBNETAPI__ */ diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h index abfd53e0c9..bd4dc09079 100644 --- a/source3/lib/netapi/netapi.h +++ b/source3/lib/netapi/netapi.h @@ -136,6 +136,14 @@ struct GROUP_INFO_3 { uint32_t grpi3_attributes; }; +struct GROUP_INFO_1002 { + const char * grpi1002_comment; +}; + +struct GROUP_INFO_1005 { + uint32_t grpi1005_attributes; +}; + #endif /* _HEADER_libnetapi */ /**************************************************************** @@ -526,8 +534,28 @@ NET_API_STATUS NetGroupAdd(const char * server_name /* [in] */, * example group/group_del.c ***************************************************************/ - NET_API_STATUS NetGroupDel(const char * server_name /* [in] */, const char * group_name /* [in] */); +/************************************************************//** + * + * NetGroupSetInfo + * + * @brief Set Domain Group Information + * + * @param[in] server_name The server name to connect to + * @param[in] group_name The name of the group that is going to be modified + * @param[in] level The level defining the structure type in buf + * @param[in] buf The buffer containing a GROUP_INFO_X structure + * @param[out] parm_err The returned parameter error number if any + * @return NET_API_STATUS + * + * example group/group_setinfo.c + ***************************************************************/ + +NET_API_STATUS NetGroupSetInfo(const char * server_name /* [in] */, + const char * group_name /* [in] */, + uint32_t level /* [in] */, + uint8_t *buf /* [in] [ref] */, + uint32_t *parm_err /* [out] [ref] */); #endif -- cgit From a6f057c0ab0a4a135491e797ab6361a999ce9684 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 2 Jun 2008 12:58:02 +0200 Subject: netapi: implement NetGroupSetInfo_r(). Guenther (This used to be commit 4d11c32874f4cbc64c7bcb2092970fa5c07b1d0e) --- source3/lib/netapi/group.c | 227 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 225 insertions(+), 2 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/group.c b/source3/lib/netapi/group.c index 7eb6d7c840..e1cd4e6692 100644 --- a/source3/lib/netapi/group.c +++ b/source3/lib/netapi/group.c @@ -501,7 +501,230 @@ WERROR NetGroupDel_l(struct libnetapi_ctx *ctx, WERROR NetGroupSetInfo_r(struct libnetapi_ctx *ctx, struct NetGroupSetInfo *r) { - return WERR_NOT_SUPPORTED; + struct cli_state *cli = NULL; + struct rpc_pipe_client *pipe_cli = NULL; + NTSTATUS status; + WERROR werr; + uint32_t resume_handle = 0; + uint32_t num_entries = 0; + POLICY_HND connect_handle, domain_handle, group_handle; + struct samr_SamArray *sam = NULL; + const char *domain_name = NULL; + struct lsa_String lsa_domain_name, lsa_group_name; + struct dom_sid2 *domain_sid = NULL; + bool domain_found = true; + int i; + + struct samr_Ids rids; + struct samr_Ids types; + union samr_GroupInfo info; + struct GROUP_INFO_0 *g0; + struct GROUP_INFO_1 *g1; + struct GROUP_INFO_2 *g2; + struct GROUP_INFO_3 *g3; + struct GROUP_INFO_1002 *g1002; + struct GROUP_INFO_1005 *g1005; + + ZERO_STRUCT(connect_handle); + ZERO_STRUCT(domain_handle); + ZERO_STRUCT(group_handle); + + if (!r->in.group_name) { + return WERR_INVALID_PARAM; + } + + werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + werr = libnetapi_open_pipe(ctx, cli, PI_SAMR, &pipe_cli); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + status = rpccli_try_samr_connects(pipe_cli, ctx, + SAMR_ACCESS_ENUM_DOMAINS | + SAMR_ACCESS_OPEN_DOMAIN, + &connect_handle); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + status = rpccli_samr_EnumDomains(pipe_cli, ctx, + &connect_handle, + &resume_handle, + &sam, + 0xffffffff, + &num_entries); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + for (i=0; ientries[i].name.string; + + if (strequal(domain_name, builtin_domain_name())) { + continue; + } + + domain_found = true; + break; + } + + if (!domain_found) { + werr = WERR_NO_SUCH_DOMAIN; + goto done; + } + + init_lsa_String(&lsa_domain_name, domain_name); + + status = rpccli_samr_LookupDomain(pipe_cli, ctx, + &connect_handle, + &lsa_domain_name, + &domain_sid); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + status = rpccli_samr_OpenDomain(pipe_cli, ctx, + &connect_handle, + SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, + domain_sid, + &domain_handle); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + init_lsa_String(&lsa_group_name, r->in.group_name); + + status = rpccli_samr_LookupNames(pipe_cli, ctx, + &domain_handle, + 1, + &lsa_group_name, + &rids, + &types); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + if (types.ids[0] != SID_NAME_DOM_GRP) { + werr = WERR_INVALID_DATATYPE; + goto done; + } + + status = rpccli_samr_OpenGroup(pipe_cli, ctx, + &domain_handle, + SAMR_GROUP_ACCESS_SET_INFO | + SAMR_GROUP_ACCESS_LOOKUP_INFO, + rids.ids[0], + &group_handle); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + switch (r->in.level) { + case 0: + g0 = (struct GROUP_INFO_0 *)r->in.buf; + init_lsa_String(&info.name, g0->grpi0_name); + status = rpccli_samr_SetGroupInfo(pipe_cli, ctx, + &group_handle, + GROUPINFONAME, + &info); + break; + case 1: + g1 = (struct GROUP_INFO_1 *)r->in.buf; + init_lsa_String(&info.description, g1->grpi1_comment); + status = rpccli_samr_SetGroupInfo(pipe_cli, ctx, + &group_handle, + GROUPINFODESCRIPTION, + &info); + break; + case 2: + g2 = (struct GROUP_INFO_2 *)r->in.buf; + init_lsa_String(&info.description, g2->grpi2_comment); + status = rpccli_samr_SetGroupInfo(pipe_cli, ctx, + &group_handle, + GROUPINFODESCRIPTION, + &info); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + info.attributes.attributes = g2->grpi2_attributes; + status = rpccli_samr_SetGroupInfo(pipe_cli, ctx, + &group_handle, + GROUPINFOATTRIBUTES, + &info); + break; + case 3: + g3 = (struct GROUP_INFO_3 *)r->in.buf; + init_lsa_String(&info.description, g3->grpi3_comment); + status = rpccli_samr_SetGroupInfo(pipe_cli, ctx, + &group_handle, + GROUPINFODESCRIPTION, + &info); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + info.attributes.attributes = g3->grpi3_attributes; + status = rpccli_samr_SetGroupInfo(pipe_cli, ctx, + &group_handle, + GROUPINFOATTRIBUTES, + &info); + break; + case 1002: + g1002 = (struct GROUP_INFO_1002 *)r->in.buf; + init_lsa_String(&info.description, g1002->grpi1002_comment); + status = rpccli_samr_SetGroupInfo(pipe_cli, ctx, + &group_handle, + GROUPINFODESCRIPTION, + &info); + break; + case 1005: + g1005 = (struct GROUP_INFO_1005 *)r->in.buf; + info.attributes.attributes = g1005->grpi1005_attributes; + status = rpccli_samr_SetGroupInfo(pipe_cli, ctx, + &group_handle, + GROUPINFOATTRIBUTES, + &info); + break; + default: + status = NT_STATUS_INVALID_LEVEL; + break; + } + + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + werr = WERR_OK; + + done: + if (!cli) { + return werr; + } + + if (is_valid_policy_hnd(&group_handle)) { + rpccli_samr_Close(pipe_cli, ctx, &group_handle); + } + if (is_valid_policy_hnd(&domain_handle)) { + rpccli_samr_Close(pipe_cli, ctx, &domain_handle); + } + if (is_valid_policy_hnd(&connect_handle)) { + rpccli_samr_Close(pipe_cli, ctx, &connect_handle); + } + + return werr; } /**************************************************************** @@ -510,5 +733,5 @@ WERROR NetGroupSetInfo_r(struct libnetapi_ctx *ctx, WERROR NetGroupSetInfo_l(struct libnetapi_ctx *ctx, struct NetGroupSetInfo *r) { - return WERR_NOT_SUPPORTED; + return NetGroupSetInfo_r(ctx, r); } -- cgit From fe0f0ff2cedbdc18c22aa8d5232fd7606dd884d3 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 2 Jun 2008 12:59:30 +0200 Subject: netapi: Add NetGroupSetInfo() example code. Guenther (This used to be commit a81b302953eca90d5fb2998fb655406324f67865) --- source3/lib/netapi/examples/Makefile.in | 8 +- source3/lib/netapi/examples/group/group_setinfo.c | 142 ++++++++++++++++++++++ 2 files changed, 149 insertions(+), 1 deletion(-) create mode 100644 source3/lib/netapi/examples/group/group_setinfo.c (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/Makefile.in b/source3/lib/netapi/examples/Makefile.in index 01f4a9d1ae..63b65f2090 100644 --- a/source3/lib/netapi/examples/Makefile.in +++ b/source3/lib/netapi/examples/Makefile.in @@ -27,7 +27,8 @@ PROGS = bin/getdc@EXEEXT@ \ bin/user_enum@EXEEXT@ \ bin/user_dispinfo@EXEEXT@ \ bin/group_add@EXEEXT@ \ - bin/group_del@EXEEXT@ + bin/group_del@EXEEXT@ \ + bin/group_setinfo@EXEEXT@ all: $(PROGS) @@ -67,6 +68,7 @@ USERENUM_OBJ = user/user_enum.o $(CMDLINE_OBJ) USERDISPINFO_OBJ = user/user_dispinfo.o $(CMDLINE_OBJ) GROUPADD_OBJ = group/group_add.o $(CMDLINE_OBJ) GROUPDEL_OBJ = group/group_del.o $(CMDLINE_OBJ) +GROUPSETINFO_OBJ = group/group_setinfo.o $(CMDLINE_OBJ) bin/getdc@EXEEXT@: $(BINARY_PREREQS) $(GETDC_OBJ) @echo Linking $@ @@ -112,6 +114,10 @@ bin/group_del@EXEEXT@: $(BINARY_PREREQS) $(GROUPDEL_OBJ) @echo Linking $@ @$(CC) $(FLAGS) -o $@ $(GROUPDEL_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) +bin/group_setinfo@EXEEXT@: $(BINARY_PREREQS) $(GROUPSETINFO_OBJ) + @echo Linking $@ + @$(CC) $(FLAGS) -o $@ $(GROUPSETINFO_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) + clean: -rm -f $(PROGS) -rm -f core */*~ *~ \ diff --git a/source3/lib/netapi/examples/group/group_setinfo.c b/source3/lib/netapi/examples/group/group_setinfo.c new file mode 100644 index 0000000000..cd30d8b9b8 --- /dev/null +++ b/source3/lib/netapi/examples/group/group_setinfo.c @@ -0,0 +1,142 @@ +/* + * Unix SMB/CIFS implementation. + * NetGroupSetInfo query + * Copyright (C) Guenther Deschner 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include +#include +#include +#include +#include + +#include + +#include "common.h" + +int main(int argc, const char **argv) +{ + NET_API_STATUS status; + struct libnetapi_ctx *ctx = NULL; + const char *hostname = NULL; + const char *groupname = NULL; + const char *option = NULL; + uint8_t *buffer = NULL; + uint32_t level = 0; + uint32_t parm_err = 0; + struct GROUP_INFO_0 g0; + struct GROUP_INFO_1 g1; + struct GROUP_INFO_2 g2; + struct GROUP_INFO_3 g3; + struct GROUP_INFO_1002 g1002; + struct GROUP_INFO_1005 g1005; + + poptContext pc; + int opt; + + struct poptOption long_options[] = { + POPT_AUTOHELP + POPT_COMMON_LIBNETAPI_EXAMPLES + POPT_TABLEEND + }; + + status = libnetapi_init(&ctx); + if (status != 0) { + return status; + } + + pc = poptGetContext("group_setinfo", argc, argv, long_options, 0); + + poptSetOtherOptionHelp(pc, "hostname groupname level option"); + while((opt = poptGetNextOpt(pc)) != -1) { + } + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + hostname = poptGetArg(pc); + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + groupname = poptGetArg(pc); + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + level = atoi(poptGetArg(pc)); + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + option = poptGetArg(pc); + + /* NetGroupSetInfo */ + + switch (level) { + case 0: + g0.grpi0_name = option; + buffer = (uint8_t *)&g0; + break; + case 1: + g1.grpi1_name = option; /* this one will be ignored */ + g1.grpi1_comment = option; + buffer = (uint8_t *)&g1; + break; + case 2: + g2.grpi2_name = option; /* this one will be ignored */ + g2.grpi2_comment = option; + g2.grpi2_group_id = 4711; /* this one will be ignored */ + g2.grpi2_attributes = 7; + buffer = (uint8_t *)&g2; + break; + case 3: + g3.grpi3_name = option; /* this one will be ignored */ + g3.grpi3_comment = option; + g2.grpi2_attributes = 7; + buffer = (uint8_t *)&g3; + break; + case 1002: + g1002.grpi1002_comment = option; + buffer = (uint8_t *)&g1002; + break; + case 1005: + g1005.grpi1005_attributes = atoi(option); + buffer = (uint8_t *)&g1005; + break; + } + + status = NetGroupSetInfo(hostname, + groupname, + level, + buffer, + &parm_err); + if (status != 0) { + printf("NetGroupSetInfo failed with: %s\n", + libnetapi_get_error_string(ctx, status)); + goto out; + } + + out: + libnetapi_free(ctx); + poptFreeContext(pc); + + return status; +} -- cgit From 5b111cc4d59db5573e8d488f49ac87a72cc44ae7 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 2 Jun 2008 13:04:15 +0200 Subject: netapi: add dummy implementation of NetGroupGetInfo(). Guenther (This used to be commit 88d03b1645d78334eb6f1fee52838a08539a6aba) --- source3/lib/netapi/group.c | 18 +++++++++++++++++ source3/lib/netapi/libnetapi.c | 46 ++++++++++++++++++++++++++++++++++++++++++ source3/lib/netapi/libnetapi.h | 8 ++++++++ source3/lib/netapi/netapi.h | 21 +++++++++++++++++++ 4 files changed, 93 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/group.c b/source3/lib/netapi/group.c index e1cd4e6692..8f1b96f74f 100644 --- a/source3/lib/netapi/group.c +++ b/source3/lib/netapi/group.c @@ -735,3 +735,21 @@ WERROR NetGroupSetInfo_l(struct libnetapi_ctx *ctx, { return NetGroupSetInfo_r(ctx, r); } + +/**************************************************************** +****************************************************************/ + +WERROR NetGroupGetInfo_r(struct libnetapi_ctx *ctx, + struct NetGroupGetInfo *r) +{ + return WERR_NOT_SUPPORTED; +} + +/**************************************************************** +****************************************************************/ + +WERROR NetGroupGetInfo_l(struct libnetapi_ctx *ctx, + struct NetGroupGetInfo *r) +{ + return WERR_NOT_SUPPORTED; +} diff --git a/source3/lib/netapi/libnetapi.c b/source3/lib/netapi/libnetapi.c index 0e1d1b30a5..a7e38bd420 100644 --- a/source3/lib/netapi/libnetapi.c +++ b/source3/lib/netapi/libnetapi.c @@ -773,3 +773,49 @@ NET_API_STATUS NetGroupSetInfo(const char * server_name /* [in] */, return r.out.result; } +/**************************************************************** + NetGroupGetInfo +****************************************************************/ + +NET_API_STATUS NetGroupGetInfo(const char * server_name /* [in] */, + const char * group_name /* [in] */, + uint32_t level /* [in] */, + uint8_t **buf /* [out] [ref] */) +{ + struct NetGroupGetInfo r; + struct libnetapi_ctx *ctx = NULL; + NET_API_STATUS status; + WERROR werr; + + status = libnetapi_getctx(&ctx); + if (status != 0) { + return status; + } + + /* In parameters */ + r.in.server_name = server_name; + r.in.group_name = group_name; + r.in.level = level; + + /* Out parameters */ + r.out.buf = buf; + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_IN_DEBUG(NetGroupGetInfo, &r); + } + + if (LIBNETAPI_LOCAL_SERVER(server_name)) { + werr = NetGroupGetInfo_l(ctx, &r); + } else { + werr = NetGroupGetInfo_r(ctx, &r); + } + + r.out.result = W_ERROR_V(werr); + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_OUT_DEBUG(NetGroupGetInfo, &r); + } + + return r.out.result; +} + diff --git a/source3/lib/netapi/libnetapi.h b/source3/lib/netapi/libnetapi.h index 9a7bbd1953..cd9a1b704a 100644 --- a/source3/lib/netapi/libnetapi.h +++ b/source3/lib/netapi/libnetapi.h @@ -134,4 +134,12 @@ WERROR NetGroupSetInfo_r(struct libnetapi_ctx *ctx, struct NetGroupSetInfo *r); WERROR NetGroupSetInfo_l(struct libnetapi_ctx *ctx, struct NetGroupSetInfo *r); +NET_API_STATUS NetGroupGetInfo(const char * server_name /* [in] */, + const char * group_name /* [in] */, + uint32_t level /* [in] */, + uint8_t **buf /* [out] [ref] */); +WERROR NetGroupGetInfo_r(struct libnetapi_ctx *ctx, + struct NetGroupGetInfo *r); +WERROR NetGroupGetInfo_l(struct libnetapi_ctx *ctx, + struct NetGroupGetInfo *r); #endif /* __LIBNETAPI_LIBNETAPI__ */ diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h index bd4dc09079..0f9d70ee35 100644 --- a/source3/lib/netapi/netapi.h +++ b/source3/lib/netapi/netapi.h @@ -558,4 +558,25 @@ NET_API_STATUS NetGroupSetInfo(const char * server_name /* [in] */, uint32_t level /* [in] */, uint8_t *buf /* [in] [ref] */, uint32_t *parm_err /* [out] [ref] */); + +/************************************************************//** + * + * NetGroupGetInfo + * + * @brief Get Domain Group Information + * + * @param[in] server_name The server name to connect to + * @param[in] group_name The name of the group that is going to be modified + * @param[in] level The level defining the requested GROUP_INFO_X structure + * @param[out] buf The buffer containing a GROUP_INFO_X structure + * @return NET_API_STATUS + * + * example group/group_del.c + ***************************************************************/ + +NET_API_STATUS NetGroupGetInfo(const char * server_name /* [in] */, + const char * group_name /* [in] */, + uint32_t level /* [in] */, + uint8_t **buf /* [out] [ref] */); + #endif -- cgit From 457649fb026ca7710b0ca83bca01131bb94ff094 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 2 Jun 2008 13:04:58 +0200 Subject: netapi: Implement NetGroupGetInfo_r(). Guenther (This used to be commit a8baa45aecc22763a9f86e722ca1c6b7bc88b150) --- source3/lib/netapi/group.c | 215 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 213 insertions(+), 2 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/group.c b/source3/lib/netapi/group.c index 8f1b96f74f..1c6015bf74 100644 --- a/source3/lib/netapi/group.c +++ b/source3/lib/netapi/group.c @@ -739,10 +739,221 @@ WERROR NetGroupSetInfo_l(struct libnetapi_ctx *ctx, /**************************************************************** ****************************************************************/ +static WERROR map_group_info_to_buffer(TALLOC_CTX *mem_ctx, + uint32_t level, + struct samr_GroupInfoAll *info, + struct dom_sid2 *domain_sid, + uint32_t rid, + uint8_t **buffer) +{ + struct GROUP_INFO_0 info0; + struct GROUP_INFO_1 info1; + struct GROUP_INFO_2 info2; + struct GROUP_INFO_3 info3; + + switch (level) { + case 0: + info0.grpi0_name = info->name.string; + + *buffer = (uint8_t *)talloc_memdup(mem_ctx, &info0, sizeof(info0)); + + break; + case 1: + info1.grpi1_name = info->name.string; + info1.grpi1_comment = info->description.string; + + *buffer = (uint8_t *)talloc_memdup(mem_ctx, &info1, sizeof(info1)); + + break; + case 2: + info2.grpi2_name = info->name.string; + info2.grpi2_comment = info->description.string; + info2.grpi2_group_id = rid; + info2.grpi2_attributes = info->attributes; + + *buffer = (uint8_t *)talloc_memdup(mem_ctx, &info2, sizeof(info2)); + + break; + case 3: + info3.grpi3_name = info->name.string; + info3.grpi3_comment = info->description.string; + info3.grpi3_attributes = info->attributes; + + if (!sid_compose((struct dom_sid *)&info3.grpi3_group_sid, domain_sid, rid)) { + return WERR_NOMEM; + } + + *buffer = (uint8_t *)talloc_memdup(mem_ctx, &info3, sizeof(info3)); + + break; + default: + return WERR_UNKNOWN_LEVEL; + } + + W_ERROR_HAVE_NO_MEMORY(*buffer); + + return WERR_OK; +} + +/**************************************************************** +****************************************************************/ + WERROR NetGroupGetInfo_r(struct libnetapi_ctx *ctx, struct NetGroupGetInfo *r) { - return WERR_NOT_SUPPORTED; + struct cli_state *cli = NULL; + struct rpc_pipe_client *pipe_cli = NULL; + NTSTATUS status; + WERROR werr; + uint32_t resume_handle = 0; + uint32_t num_entries = 0; + POLICY_HND connect_handle, domain_handle, group_handle; + struct samr_SamArray *sam = NULL; + const char *domain_name = NULL; + struct lsa_String lsa_domain_name, lsa_group_name; + struct dom_sid2 *domain_sid = NULL; + bool domain_found = true; + int i; + + struct samr_Ids rids; + struct samr_Ids types; + union samr_GroupInfo *info = NULL; + + ZERO_STRUCT(connect_handle); + ZERO_STRUCT(domain_handle); + ZERO_STRUCT(group_handle); + + if (!r->in.group_name) { + return WERR_INVALID_PARAM; + } + + werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + werr = libnetapi_open_pipe(ctx, cli, PI_SAMR, &pipe_cli); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + status = rpccli_try_samr_connects(pipe_cli, ctx, + SAMR_ACCESS_ENUM_DOMAINS | + SAMR_ACCESS_OPEN_DOMAIN, + &connect_handle); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + status = rpccli_samr_EnumDomains(pipe_cli, ctx, + &connect_handle, + &resume_handle, + &sam, + 0xffffffff, + &num_entries); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + for (i=0; ientries[i].name.string; + + if (strequal(domain_name, builtin_domain_name())) { + continue; + } + + domain_found = true; + break; + } + + if (!domain_found) { + werr = WERR_NO_SUCH_DOMAIN; + goto done; + } + + init_lsa_String(&lsa_domain_name, domain_name); + + status = rpccli_samr_LookupDomain(pipe_cli, ctx, + &connect_handle, + &lsa_domain_name, + &domain_sid); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + status = rpccli_samr_OpenDomain(pipe_cli, ctx, + &connect_handle, + SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, + domain_sid, + &domain_handle); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + init_lsa_String(&lsa_group_name, r->in.group_name); + + status = rpccli_samr_LookupNames(pipe_cli, ctx, + &domain_handle, + 1, + &lsa_group_name, + &rids, + &types); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + if (types.ids[0] != SID_NAME_DOM_GRP) { + werr = WERR_INVALID_DATATYPE; + goto done; + } + + status = rpccli_samr_OpenGroup(pipe_cli, ctx, + &domain_handle, + SAMR_GROUP_ACCESS_LOOKUP_INFO, + rids.ids[0], + &group_handle); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + status = rpccli_samr_QueryGroupInfo(pipe_cli, ctx, + &group_handle, + GROUPINFOALL2, + &info); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + werr = map_group_info_to_buffer(ctx, r->in.level, + &info->all2, domain_sid, rids.ids[0], + r->out.buf); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + done: + if (!cli) { + return werr; + } + + if (is_valid_policy_hnd(&group_handle)) { + rpccli_samr_Close(pipe_cli, ctx, &group_handle); + } + if (is_valid_policy_hnd(&domain_handle)) { + rpccli_samr_Close(pipe_cli, ctx, &domain_handle); + } + if (is_valid_policy_hnd(&connect_handle)) { + rpccli_samr_Close(pipe_cli, ctx, &connect_handle); + } + + return werr; } /**************************************************************** @@ -751,5 +962,5 @@ WERROR NetGroupGetInfo_r(struct libnetapi_ctx *ctx, WERROR NetGroupGetInfo_l(struct libnetapi_ctx *ctx, struct NetGroupGetInfo *r) { - return WERR_NOT_SUPPORTED; + return NetGroupGetInfo_r(ctx, r); } -- cgit From 0469db82a9036ba0821314591d192e17faecb666 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 2 Jun 2008 13:07:02 +0200 Subject: netapi: add NetGroupGetInfo() example code. Guenther (This used to be commit 99c8f7e90c6ac512dbb0c3eefb55c74b4d097d62) --- source3/lib/netapi/examples/Makefile.in | 8 +- source3/lib/netapi/examples/group/group_getinfo.c | 122 ++++++++++++++++++++++ 2 files changed, 129 insertions(+), 1 deletion(-) create mode 100644 source3/lib/netapi/examples/group/group_getinfo.c (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/Makefile.in b/source3/lib/netapi/examples/Makefile.in index 63b65f2090..121c706d9c 100644 --- a/source3/lib/netapi/examples/Makefile.in +++ b/source3/lib/netapi/examples/Makefile.in @@ -28,7 +28,8 @@ PROGS = bin/getdc@EXEEXT@ \ bin/user_dispinfo@EXEEXT@ \ bin/group_add@EXEEXT@ \ bin/group_del@EXEEXT@ \ - bin/group_setinfo@EXEEXT@ + bin/group_setinfo@EXEEXT@ \ + bin/group_getinfo@EXEEXT@ all: $(PROGS) @@ -69,6 +70,7 @@ USERDISPINFO_OBJ = user/user_dispinfo.o $(CMDLINE_OBJ) GROUPADD_OBJ = group/group_add.o $(CMDLINE_OBJ) GROUPDEL_OBJ = group/group_del.o $(CMDLINE_OBJ) GROUPSETINFO_OBJ = group/group_setinfo.o $(CMDLINE_OBJ) +GROUPGETINFO_OBJ = group/group_getinfo.o $(CMDLINE_OBJ) bin/getdc@EXEEXT@: $(BINARY_PREREQS) $(GETDC_OBJ) @echo Linking $@ @@ -118,6 +120,10 @@ bin/group_setinfo@EXEEXT@: $(BINARY_PREREQS) $(GROUPSETINFO_OBJ) @echo Linking $@ @$(CC) $(FLAGS) -o $@ $(GROUPSETINFO_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) +bin/group_getinfo@EXEEXT@: $(BINARY_PREREQS) $(GROUPGETINFO_OBJ) + @echo Linking $@ + @$(CC) $(FLAGS) -o $@ $(GROUPGETINFO_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) + clean: -rm -f $(PROGS) -rm -f core */*~ *~ \ diff --git a/source3/lib/netapi/examples/group/group_getinfo.c b/source3/lib/netapi/examples/group/group_getinfo.c new file mode 100644 index 0000000000..9a76996336 --- /dev/null +++ b/source3/lib/netapi/examples/group/group_getinfo.c @@ -0,0 +1,122 @@ +/* + * Unix SMB/CIFS implementation. + * NetGroupGetInfo query + * Copyright (C) Guenther Deschner 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include +#include +#include +#include +#include + +#include + +#include "common.h" + +int main(int argc, const char **argv) +{ + NET_API_STATUS status; + struct libnetapi_ctx *ctx = NULL; + const char *hostname = NULL; + const char *groupname = NULL; + uint8_t *buffer = NULL; + uint32_t level = 0; + struct GROUP_INFO_0 *g0; + struct GROUP_INFO_1 *g1; + struct GROUP_INFO_2 *g2; + struct GROUP_INFO_3 *g3; + + poptContext pc; + int opt; + + struct poptOption long_options[] = { + POPT_AUTOHELP + POPT_COMMON_LIBNETAPI_EXAMPLES + POPT_TABLEEND + }; + + status = libnetapi_init(&ctx); + if (status != 0) { + return status; + } + + pc = poptGetContext("group_getinfo", argc, argv, long_options, 0); + + poptSetOtherOptionHelp(pc, "hostname groupname level"); + while((opt = poptGetNextOpt(pc)) != -1) { + } + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + hostname = poptGetArg(pc); + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + groupname = poptGetArg(pc); + + if (poptPeekArg(pc)) { + level = atoi(poptGetArg(pc)); + } + + /* NetGroupGetInfo */ + + status = NetGroupGetInfo(hostname, + groupname, + level, + &buffer); + if (status != 0) { + printf("NetGroupGetInfo failed with: %s\n", + libnetapi_get_error_string(ctx, status)); + goto out; + } + + switch (level) { + case 0: + g0 = (struct GROUP_INFO_0 *)buffer; + printf("name: %s\n", g0->grpi0_name); + break; + case 1: + g1 = (struct GROUP_INFO_1 *)buffer; + printf("name: %s\n", g1->grpi1_name); + printf("comment: %s\n", g1->grpi1_comment); + break; + case 2: + g2 = (struct GROUP_INFO_2 *)buffer; + printf("name: %s\n", g2->grpi2_name); + printf("comment: %s\n", g2->grpi2_comment); + printf("group_id: %d\n", g2->grpi2_group_id); + printf("attributes: %d\n", g2->grpi2_attributes); + break; + case 3: + g3 = (struct GROUP_INFO_3 *)buffer; + printf("name: %s\n", g3->grpi3_name); + printf("comment: %s\n", g3->grpi3_comment); +/* printf("group_sid: %p\n", g3->grpi3_group_sid);*/ + printf("attributes: %d\n", g3->grpi3_attributes); + break; + } + + out: + libnetapi_free(ctx); + poptFreeContext(pc); + + return status; +} -- cgit From c30b8c4eafc945f8641e39157e4bb70f17815eee Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 2 Jun 2008 13:43:21 +0200 Subject: netapi: add dummy implementation for NetGroupAddUser() and NetGroupDelUser(). Guenther (This used to be commit 6eba84edc60829f0cdf3508520625e66fe88afde) --- source3/lib/netapi/group.c | 36 +++++++++++++++++ source3/lib/netapi/libnetapi.c | 88 ++++++++++++++++++++++++++++++++++++++++++ source3/lib/netapi/libnetapi.h | 14 +++++++ 3 files changed, 138 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/group.c b/source3/lib/netapi/group.c index 1c6015bf74..415110b3d3 100644 --- a/source3/lib/netapi/group.c +++ b/source3/lib/netapi/group.c @@ -964,3 +964,39 @@ WERROR NetGroupGetInfo_l(struct libnetapi_ctx *ctx, { return NetGroupGetInfo_r(ctx, r); } + +/**************************************************************** +****************************************************************/ + +WERROR NetGroupAddUser_r(struct libnetapi_ctx *ctx, + struct NetGroupAddUser *r) +{ + return WERR_NOT_SUPPORTED; +} + +/**************************************************************** +****************************************************************/ + +WERROR NetGroupAddUser_l(struct libnetapi_ctx *ctx, + struct NetGroupAddUser *r) +{ + return WERR_NOT_SUPPORTED; +} + +/**************************************************************** +****************************************************************/ + +WERROR NetGroupDelUser_r(struct libnetapi_ctx *ctx, + struct NetGroupDelUser *r) +{ + return WERR_NOT_SUPPORTED; +} + +/**************************************************************** +****************************************************************/ + +WERROR NetGroupDelUser_l(struct libnetapi_ctx *ctx, + struct NetGroupDelUser *r) +{ + return WERR_NOT_SUPPORTED; +} diff --git a/source3/lib/netapi/libnetapi.c b/source3/lib/netapi/libnetapi.c index a7e38bd420..3bbb1686ab 100644 --- a/source3/lib/netapi/libnetapi.c +++ b/source3/lib/netapi/libnetapi.c @@ -819,3 +819,91 @@ NET_API_STATUS NetGroupGetInfo(const char * server_name /* [in] */, return r.out.result; } +/**************************************************************** + NetGroupAddUser +****************************************************************/ + +NET_API_STATUS NetGroupAddUser(const char * server_name /* [in] */, + const char * group_name /* [in] */, + const char * user_name /* [in] */) +{ + struct NetGroupAddUser r; + struct libnetapi_ctx *ctx = NULL; + NET_API_STATUS status; + WERROR werr; + + status = libnetapi_getctx(&ctx); + if (status != 0) { + return status; + } + + /* In parameters */ + r.in.server_name = server_name; + r.in.group_name = group_name; + r.in.user_name = user_name; + + /* Out parameters */ + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_IN_DEBUG(NetGroupAddUser, &r); + } + + if (LIBNETAPI_LOCAL_SERVER(server_name)) { + werr = NetGroupAddUser_l(ctx, &r); + } else { + werr = NetGroupAddUser_r(ctx, &r); + } + + r.out.result = W_ERROR_V(werr); + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_OUT_DEBUG(NetGroupAddUser, &r); + } + + return r.out.result; +} + +/**************************************************************** + NetGroupDelUser +****************************************************************/ + +NET_API_STATUS NetGroupDelUser(const char * server_name /* [in] */, + const char * group_name /* [in] */, + const char * user_name /* [in] */) +{ + struct NetGroupDelUser r; + struct libnetapi_ctx *ctx = NULL; + NET_API_STATUS status; + WERROR werr; + + status = libnetapi_getctx(&ctx); + if (status != 0) { + return status; + } + + /* In parameters */ + r.in.server_name = server_name; + r.in.group_name = group_name; + r.in.user_name = user_name; + + /* Out parameters */ + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_IN_DEBUG(NetGroupDelUser, &r); + } + + if (LIBNETAPI_LOCAL_SERVER(server_name)) { + werr = NetGroupDelUser_l(ctx, &r); + } else { + werr = NetGroupDelUser_r(ctx, &r); + } + + r.out.result = W_ERROR_V(werr); + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_OUT_DEBUG(NetGroupDelUser, &r); + } + + return r.out.result; +} + diff --git a/source3/lib/netapi/libnetapi.h b/source3/lib/netapi/libnetapi.h index cd9a1b704a..4faca46b22 100644 --- a/source3/lib/netapi/libnetapi.h +++ b/source3/lib/netapi/libnetapi.h @@ -142,4 +142,18 @@ WERROR NetGroupGetInfo_r(struct libnetapi_ctx *ctx, struct NetGroupGetInfo *r); WERROR NetGroupGetInfo_l(struct libnetapi_ctx *ctx, struct NetGroupGetInfo *r); +NET_API_STATUS NetGroupAddUser(const char * server_name /* [in] */, + const char * group_name /* [in] */, + const char * user_name /* [in] */); +WERROR NetGroupAddUser_r(struct libnetapi_ctx *ctx, + struct NetGroupAddUser *r); +WERROR NetGroupAddUser_l(struct libnetapi_ctx *ctx, + struct NetGroupAddUser *r); +NET_API_STATUS NetGroupDelUser(const char * server_name /* [in] */, + const char * group_name /* [in] */, + const char * user_name /* [in] */); +WERROR NetGroupDelUser_r(struct libnetapi_ctx *ctx, + struct NetGroupDelUser *r); +WERROR NetGroupDelUser_l(struct libnetapi_ctx *ctx, + struct NetGroupDelUser *r); #endif /* __LIBNETAPI_LIBNETAPI__ */ -- cgit From 749e5a80c24f5f6d0c4b91c5e5ae30606acad3a5 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 2 Jun 2008 14:46:56 +0200 Subject: netapi: implement NetGroupAddUser(). Guenther (This used to be commit c727a49519b2da6c5eb9ccc5025ab844fe8330ad) --- source3/lib/netapi/group.c | 169 +++++++++++++++++++++++++++++++++++++++++++- source3/lib/netapi/netapi.h | 18 +++++ 2 files changed, 185 insertions(+), 2 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/group.c b/source3/lib/netapi/group.c index 415110b3d3..24335016b2 100644 --- a/source3/lib/netapi/group.c +++ b/source3/lib/netapi/group.c @@ -971,7 +971,172 @@ WERROR NetGroupGetInfo_l(struct libnetapi_ctx *ctx, WERROR NetGroupAddUser_r(struct libnetapi_ctx *ctx, struct NetGroupAddUser *r) { - return WERR_NOT_SUPPORTED; + struct cli_state *cli = NULL; + struct rpc_pipe_client *pipe_cli = NULL; + NTSTATUS status; + WERROR werr; + uint32_t resume_handle = 0; + uint32_t num_entries = 0; + POLICY_HND connect_handle, domain_handle, group_handle; + struct samr_SamArray *sam = NULL; + const char *domain_name = NULL; + struct lsa_String lsa_domain_name, lsa_group_name, lsa_user_name; + struct dom_sid2 *domain_sid = NULL; + bool domain_found = true; + int i; + + struct samr_Ids rids; + struct samr_Ids types; + + ZERO_STRUCT(connect_handle); + ZERO_STRUCT(domain_handle); + ZERO_STRUCT(group_handle); + + if (!r->in.group_name) { + return WERR_INVALID_PARAM; + } + + werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + werr = libnetapi_open_pipe(ctx, cli, PI_SAMR, &pipe_cli); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + status = rpccli_try_samr_connects(pipe_cli, ctx, + SAMR_ACCESS_ENUM_DOMAINS | + SAMR_ACCESS_OPEN_DOMAIN, + &connect_handle); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + status = rpccli_samr_EnumDomains(pipe_cli, ctx, + &connect_handle, + &resume_handle, + &sam, + 0xffffffff, + &num_entries); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + for (i=0; ientries[i].name.string; + + if (strequal(domain_name, builtin_domain_name())) { + continue; + } + + domain_found = true; + break; + } + + if (!domain_found) { + werr = WERR_NO_SUCH_DOMAIN; + goto done; + } + + init_lsa_String(&lsa_domain_name, domain_name); + + status = rpccli_samr_LookupDomain(pipe_cli, ctx, + &connect_handle, + &lsa_domain_name, + &domain_sid); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + status = rpccli_samr_OpenDomain(pipe_cli, ctx, + &connect_handle, + SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, + domain_sid, + &domain_handle); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + init_lsa_String(&lsa_group_name, r->in.group_name); + + status = rpccli_samr_LookupNames(pipe_cli, ctx, + &domain_handle, + 1, + &lsa_group_name, + &rids, + &types); + if (!NT_STATUS_IS_OK(status)) { + werr = WERR_GROUP_NOT_FOUND; + goto done; + } + + if (types.ids[0] != SID_NAME_DOM_GRP) { + werr = WERR_GROUP_NOT_FOUND; + goto done; + } + + status = rpccli_samr_OpenGroup(pipe_cli, ctx, + &domain_handle, + SAMR_GROUP_ACCESS_ADD_MEMBER, + rids.ids[0], + &group_handle); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + init_lsa_String(&lsa_user_name, r->in.user_name); + + status = rpccli_samr_LookupNames(pipe_cli, ctx, + &domain_handle, + 1, + &lsa_user_name, + &rids, + &types); + if (!NT_STATUS_IS_OK(status)) { + werr = WERR_USER_NOT_FOUND; + goto done; + } + + if (types.ids[0] != SID_NAME_USER) { + werr = WERR_USER_NOT_FOUND; + goto done; + } + + status = rpccli_samr_AddGroupMember(pipe_cli, ctx, + &group_handle, + rids.ids[0], + 7); /* why ? */ + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + werr = WERR_OK; + + done: + if (!cli) { + return werr; + } + + if (is_valid_policy_hnd(&group_handle)) { + rpccli_samr_Close(pipe_cli, ctx, &group_handle); + } + if (is_valid_policy_hnd(&domain_handle)) { + rpccli_samr_Close(pipe_cli, ctx, &domain_handle); + } + if (is_valid_policy_hnd(&connect_handle)) { + rpccli_samr_Close(pipe_cli, ctx, &connect_handle); + } + + return werr; } /**************************************************************** @@ -980,7 +1145,7 @@ WERROR NetGroupAddUser_r(struct libnetapi_ctx *ctx, WERROR NetGroupAddUser_l(struct libnetapi_ctx *ctx, struct NetGroupAddUser *r) { - return WERR_NOT_SUPPORTED; + return NetGroupAddUser_r(ctx, r); } /**************************************************************** diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h index 0f9d70ee35..c4beda2a9c 100644 --- a/source3/lib/netapi/netapi.h +++ b/source3/lib/netapi/netapi.h @@ -579,4 +579,22 @@ NET_API_STATUS NetGroupGetInfo(const char * server_name /* [in] */, uint32_t level /* [in] */, uint8_t **buf /* [out] [ref] */); +/************************************************************//** + * + * NetGroupAddUser + * + * @brief Add existing User to existing Domain Group + * + * @param[in] server_name The server name to connect to + * @param[in] group_name The name of the group that is going to be modified + * @param[in] user_name The name of the user that is going to be added to the + * group + * @return NET_API_STATUS + * + * example group/group_adduser.c + ***************************************************************/ + +NET_API_STATUS NetGroupAddUser(const char * server_name /* [in] */, + const char * group_name /* [in] */, + const char * user_name /* [in] */); #endif -- cgit From 1e0c8207b0b17a230e8a97d5bc87c085f98c171d Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 2 Jun 2008 14:48:45 +0200 Subject: netapi: add NetGroupAddUser() example. Guenther (This used to be commit 7ebe949643a53f636a942171147f0be5e32b4a37) --- source3/lib/netapi/examples/Makefile.in | 8 +- source3/lib/netapi/examples/group/group_adduser.c | 91 +++++++++++++++++++++++ 2 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 source3/lib/netapi/examples/group/group_adduser.c (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/Makefile.in b/source3/lib/netapi/examples/Makefile.in index 121c706d9c..986269d024 100644 --- a/source3/lib/netapi/examples/Makefile.in +++ b/source3/lib/netapi/examples/Makefile.in @@ -29,7 +29,8 @@ PROGS = bin/getdc@EXEEXT@ \ bin/group_add@EXEEXT@ \ bin/group_del@EXEEXT@ \ bin/group_setinfo@EXEEXT@ \ - bin/group_getinfo@EXEEXT@ + bin/group_getinfo@EXEEXT@ \ + bin/group_adduser@EXEEXT@ all: $(PROGS) @@ -71,6 +72,7 @@ GROUPADD_OBJ = group/group_add.o $(CMDLINE_OBJ) GROUPDEL_OBJ = group/group_del.o $(CMDLINE_OBJ) GROUPSETINFO_OBJ = group/group_setinfo.o $(CMDLINE_OBJ) GROUPGETINFO_OBJ = group/group_getinfo.o $(CMDLINE_OBJ) +GROUPADDUSER_OBJ = group/group_adduser.o $(CMDLINE_OBJ) bin/getdc@EXEEXT@: $(BINARY_PREREQS) $(GETDC_OBJ) @echo Linking $@ @@ -124,6 +126,10 @@ bin/group_getinfo@EXEEXT@: $(BINARY_PREREQS) $(GROUPGETINFO_OBJ) @echo Linking $@ @$(CC) $(FLAGS) -o $@ $(GROUPGETINFO_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) +bin/group_adduser@EXEEXT@: $(BINARY_PREREQS) $(GROUPADDUSER_OBJ) + @echo Linking $@ + @$(CC) $(FLAGS) -o $@ $(GROUPADDUSER_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) + clean: -rm -f $(PROGS) -rm -f core */*~ *~ \ diff --git a/source3/lib/netapi/examples/group/group_adduser.c b/source3/lib/netapi/examples/group/group_adduser.c new file mode 100644 index 0000000000..253b3c5ab4 --- /dev/null +++ b/source3/lib/netapi/examples/group/group_adduser.c @@ -0,0 +1,91 @@ +/* + * Unix SMB/CIFS implementation. + * NetGroupAddUser query + * Copyright (C) Guenther Deschner 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include +#include +#include +#include +#include + +#include + +#include "common.h" + +int main(int argc, const char **argv) +{ + NET_API_STATUS status; + struct libnetapi_ctx *ctx = NULL; + const char *hostname = NULL; + const char *groupname = NULL; + const char *username = NULL; + + poptContext pc; + int opt; + + struct poptOption long_options[] = { + POPT_AUTOHELP + POPT_COMMON_LIBNETAPI_EXAMPLES + POPT_TABLEEND + }; + + status = libnetapi_init(&ctx); + if (status != 0) { + return status; + } + + pc = poptGetContext("group_adduser", argc, argv, long_options, 0); + + poptSetOtherOptionHelp(pc, "hostname groupname username"); + while((opt = poptGetNextOpt(pc)) != -1) { + } + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + hostname = poptGetArg(pc); + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + groupname = poptGetArg(pc); + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + username = poptGetArg(pc); + + /* NetGroupAddUser */ + + status = NetGroupAddUser(hostname, + groupname, + username); + if (status != 0) { + printf("NetGroupAddUser failed with: %s\n", + libnetapi_get_error_string(ctx, status)); + } + + out: + libnetapi_free(ctx); + poptFreeContext(pc); + + return status; +} -- cgit From 4dcfa15b0bde75d15f8831ef572fb9ce9aad18a8 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 2 Jun 2008 14:58:01 +0200 Subject: netapi: Implement NetGroupDelUser(). Guenther (This used to be commit 10f69b3ce58be06d95e4dfd5782d9481f4af76bf) --- source3/lib/netapi/group.c | 168 +++++++++++++++++++++++++++++++++++++++++++- source3/lib/netapi/netapi.h | 20 ++++++ 2 files changed, 186 insertions(+), 2 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/group.c b/source3/lib/netapi/group.c index 24335016b2..d46d2e6135 100644 --- a/source3/lib/netapi/group.c +++ b/source3/lib/netapi/group.c @@ -1154,7 +1154,171 @@ WERROR NetGroupAddUser_l(struct libnetapi_ctx *ctx, WERROR NetGroupDelUser_r(struct libnetapi_ctx *ctx, struct NetGroupDelUser *r) { - return WERR_NOT_SUPPORTED; + struct cli_state *cli = NULL; + struct rpc_pipe_client *pipe_cli = NULL; + NTSTATUS status; + WERROR werr; + uint32_t resume_handle = 0; + uint32_t num_entries = 0; + POLICY_HND connect_handle, domain_handle, group_handle; + struct samr_SamArray *sam = NULL; + const char *domain_name = NULL; + struct lsa_String lsa_domain_name, lsa_group_name, lsa_user_name; + struct dom_sid2 *domain_sid = NULL; + bool domain_found = true; + int i; + + struct samr_Ids rids; + struct samr_Ids types; + + ZERO_STRUCT(connect_handle); + ZERO_STRUCT(domain_handle); + ZERO_STRUCT(group_handle); + + if (!r->in.group_name) { + return WERR_INVALID_PARAM; + } + + werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + werr = libnetapi_open_pipe(ctx, cli, PI_SAMR, &pipe_cli); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + status = rpccli_try_samr_connects(pipe_cli, ctx, + SAMR_ACCESS_ENUM_DOMAINS | + SAMR_ACCESS_OPEN_DOMAIN, + &connect_handle); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + status = rpccli_samr_EnumDomains(pipe_cli, ctx, + &connect_handle, + &resume_handle, + &sam, + 0xffffffff, + &num_entries); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + for (i=0; ientries[i].name.string; + + if (strequal(domain_name, builtin_domain_name())) { + continue; + } + + domain_found = true; + break; + } + + if (!domain_found) { + werr = WERR_NO_SUCH_DOMAIN; + goto done; + } + + init_lsa_String(&lsa_domain_name, domain_name); + + status = rpccli_samr_LookupDomain(pipe_cli, ctx, + &connect_handle, + &lsa_domain_name, + &domain_sid); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + status = rpccli_samr_OpenDomain(pipe_cli, ctx, + &connect_handle, + SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, + domain_sid, + &domain_handle); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + init_lsa_String(&lsa_group_name, r->in.group_name); + + status = rpccli_samr_LookupNames(pipe_cli, ctx, + &domain_handle, + 1, + &lsa_group_name, + &rids, + &types); + if (!NT_STATUS_IS_OK(status)) { + werr = WERR_GROUP_NOT_FOUND; + goto done; + } + + if (types.ids[0] != SID_NAME_DOM_GRP) { + werr = WERR_GROUP_NOT_FOUND; + goto done; + } + + status = rpccli_samr_OpenGroup(pipe_cli, ctx, + &domain_handle, + SAMR_GROUP_ACCESS_REMOVE_MEMBER, + rids.ids[0], + &group_handle); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + init_lsa_String(&lsa_user_name, r->in.user_name); + + status = rpccli_samr_LookupNames(pipe_cli, ctx, + &domain_handle, + 1, + &lsa_user_name, + &rids, + &types); + if (!NT_STATUS_IS_OK(status)) { + werr = WERR_USER_NOT_FOUND; + goto done; + } + + if (types.ids[0] != SID_NAME_USER) { + werr = WERR_USER_NOT_FOUND; + goto done; + } + + status = rpccli_samr_DeleteGroupMember(pipe_cli, ctx, + &group_handle, + rids.ids[0]); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + werr = WERR_OK; + + done: + if (!cli) { + return werr; + } + + if (is_valid_policy_hnd(&group_handle)) { + rpccli_samr_Close(pipe_cli, ctx, &group_handle); + } + if (is_valid_policy_hnd(&domain_handle)) { + rpccli_samr_Close(pipe_cli, ctx, &domain_handle); + } + if (is_valid_policy_hnd(&connect_handle)) { + rpccli_samr_Close(pipe_cli, ctx, &connect_handle); + } + + return werr; } /**************************************************************** @@ -1163,5 +1327,5 @@ WERROR NetGroupDelUser_r(struct libnetapi_ctx *ctx, WERROR NetGroupDelUser_l(struct libnetapi_ctx *ctx, struct NetGroupDelUser *r) { - return WERR_NOT_SUPPORTED; + return NetGroupDelUser_r(ctx, r); } diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h index c4beda2a9c..d787cedf4c 100644 --- a/source3/lib/netapi/netapi.h +++ b/source3/lib/netapi/netapi.h @@ -597,4 +597,24 @@ NET_API_STATUS NetGroupGetInfo(const char * server_name /* [in] */, NET_API_STATUS NetGroupAddUser(const char * server_name /* [in] */, const char * group_name /* [in] */, const char * user_name /* [in] */); + +/************************************************************//** + * + * NetGroupDelUser + * + * @brief Remove User from Domain Group + * + * @param[in] server_name The server name to connect to + * @param[in] group_name The name of the group that is going to be modified + * @param[in] user_name The name of the user that is going to be removed from + * the group + * @return NET_API_STATUS + * + * example group/group_deluser.c + ***************************************************************/ + +NET_API_STATUS NetGroupDelUser(const char * server_name /* [in] */, + const char * group_name /* [in] */, + const char * user_name /* [in] */); + #endif -- cgit From 43a0060f091d17237a9df785656b6e8958b3bda3 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 2 Jun 2008 14:58:43 +0200 Subject: netapi: Add NetGroupDelUser() example. Guenther (This used to be commit 1a8df720306662c2109654c8666cd33dcb769ec4) --- source3/lib/netapi/examples/Makefile.in | 8 +- source3/lib/netapi/examples/group/group_deluser.c | 91 +++++++++++++++++++++++ 2 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 source3/lib/netapi/examples/group/group_deluser.c (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/Makefile.in b/source3/lib/netapi/examples/Makefile.in index 986269d024..156bd218ba 100644 --- a/source3/lib/netapi/examples/Makefile.in +++ b/source3/lib/netapi/examples/Makefile.in @@ -30,7 +30,8 @@ PROGS = bin/getdc@EXEEXT@ \ bin/group_del@EXEEXT@ \ bin/group_setinfo@EXEEXT@ \ bin/group_getinfo@EXEEXT@ \ - bin/group_adduser@EXEEXT@ + bin/group_adduser@EXEEXT@ \ + bin/group_deluser@EXEEXT@ all: $(PROGS) @@ -73,6 +74,7 @@ GROUPDEL_OBJ = group/group_del.o $(CMDLINE_OBJ) GROUPSETINFO_OBJ = group/group_setinfo.o $(CMDLINE_OBJ) GROUPGETINFO_OBJ = group/group_getinfo.o $(CMDLINE_OBJ) GROUPADDUSER_OBJ = group/group_adduser.o $(CMDLINE_OBJ) +GROUPDELUSER_OBJ = group/group_deluser.o $(CMDLINE_OBJ) bin/getdc@EXEEXT@: $(BINARY_PREREQS) $(GETDC_OBJ) @echo Linking $@ @@ -130,6 +132,10 @@ bin/group_adduser@EXEEXT@: $(BINARY_PREREQS) $(GROUPADDUSER_OBJ) @echo Linking $@ @$(CC) $(FLAGS) -o $@ $(GROUPADDUSER_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) +bin/group_deluser@EXEEXT@: $(BINARY_PREREQS) $(GROUPDELUSER_OBJ) + @echo Linking $@ + @$(CC) $(FLAGS) -o $@ $(GROUPDELUSER_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) + clean: -rm -f $(PROGS) -rm -f core */*~ *~ \ diff --git a/source3/lib/netapi/examples/group/group_deluser.c b/source3/lib/netapi/examples/group/group_deluser.c new file mode 100644 index 0000000000..751ab5c630 --- /dev/null +++ b/source3/lib/netapi/examples/group/group_deluser.c @@ -0,0 +1,91 @@ +/* + * Unix SMB/CIFS implementation. + * NetGroupDelUser query + * Copyright (C) Guenther Deschner 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include +#include +#include +#include +#include + +#include + +#include "common.h" + +int main(int argc, const char **argv) +{ + NET_API_STATUS status; + struct libnetapi_ctx *ctx = NULL; + const char *hostname = NULL; + const char *groupname = NULL; + const char *username = NULL; + + poptContext pc; + int opt; + + struct poptOption long_options[] = { + POPT_AUTOHELP + POPT_COMMON_LIBNETAPI_EXAMPLES + POPT_TABLEEND + }; + + status = libnetapi_init(&ctx); + if (status != 0) { + return status; + } + + pc = poptGetContext("group_deluser", argc, argv, long_options, 0); + + poptSetOtherOptionHelp(pc, "hostname groupname username"); + while((opt = poptGetNextOpt(pc)) != -1) { + } + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + hostname = poptGetArg(pc); + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + groupname = poptGetArg(pc); + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + username = poptGetArg(pc); + + /* NetGroupDelUser */ + + status = NetGroupDelUser(hostname, + groupname, + username); + if (status != 0) { + printf("NetGroupDelUser failed with: %s\n", + libnetapi_get_error_string(ctx, status)); + } + + out: + libnetapi_free(ctx); + poptFreeContext(pc); + + return status; +} -- cgit From 31c185011fc70038f1f7fad3049f782bdba49688 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 2 Jun 2008 17:29:55 +0200 Subject: netapi: add libnetapi_samr_open_domain(). Guenther (This used to be commit a99906f661faa104da4b40707597ceb4542548f8) --- source3/lib/netapi/netapi_private.h | 7 +++ source3/lib/netapi/samr.c | 104 ++++++++++++++++++++++++++++++++++++ 2 files changed, 111 insertions(+) create mode 100644 source3/lib/netapi/samr.c (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi_private.h b/source3/lib/netapi/netapi_private.h index a575f42f4e..c788222ad3 100644 --- a/source3/lib/netapi/netapi_private.h +++ b/source3/lib/netapi/netapi_private.h @@ -33,4 +33,11 @@ WERROR libnetapi_open_pipe(struct libnetapi_ctx *ctx, struct cli_state *cli, int pipe_idx, struct rpc_pipe_client **pipe_cli); +NTSTATUS libnetapi_samr_open_domain(TALLOC_CTX *mem_ctx, + struct rpc_pipe_client *pipe_cli, + uint32_t connect_mask, + uint32_t domain_mask, + struct policy_handle *connect_handle, + struct policy_handle *domain_handle, + struct dom_sid2 **domain_sid); #endif diff --git a/source3/lib/netapi/samr.c b/source3/lib/netapi/samr.c new file mode 100644 index 0000000000..8e1c409ed9 --- /dev/null +++ b/source3/lib/netapi/samr.c @@ -0,0 +1,104 @@ +/* + * Unix SMB/CIFS implementation. + * NetApi Samr Support + * Copyright (C) Guenther Deschner 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include "includes.h" + +#include "librpc/gen_ndr/libnetapi.h" +#include "lib/netapi/netapi.h" +#include "lib/netapi/netapi_private.h" +#include "lib/netapi/libnetapi.h" + +/**************************************************************** +****************************************************************/ + +NTSTATUS libnetapi_samr_open_domain(TALLOC_CTX *mem_ctx, + struct rpc_pipe_client *pipe_cli, + uint32_t connect_mask, + uint32_t domain_mask, + struct policy_handle *connect_handle, + struct policy_handle *domain_handle, + struct dom_sid2 **domain_sid) +{ + NTSTATUS status; + uint32_t resume_handle = 0; + uint32_t num_entries = 0; + struct samr_SamArray *sam = NULL; + const char *domain_name = NULL; + struct lsa_String lsa_domain_name; + bool domain_found = true; + int i; + + if (!is_valid_policy_hnd(connect_handle)) { + status = rpccli_try_samr_connects(pipe_cli, mem_ctx, + connect_mask, + connect_handle); + if (!NT_STATUS_IS_OK(status)) { + goto done; + } + } + + status = rpccli_samr_EnumDomains(pipe_cli, mem_ctx, + connect_handle, + &resume_handle, + &sam, + 0xffffffff, + &num_entries); + if (!NT_STATUS_IS_OK(status)) { + goto done; + } + + for (i=0; ientries[i].name.string; + + if (strequal(domain_name, builtin_domain_name())) { + continue; + } + + domain_found = true; + break; + } + + if (!domain_found) { + status = NT_STATUS_NO_SUCH_DOMAIN; + goto done; + } + + init_lsa_String(&lsa_domain_name, domain_name); + + status = rpccli_samr_LookupDomain(pipe_cli, mem_ctx, + connect_handle, + &lsa_domain_name, + domain_sid); + if (!NT_STATUS_IS_OK(status)) { + goto done; + } + + status = rpccli_samr_OpenDomain(pipe_cli, mem_ctx, + connect_handle, + domain_mask, + *domain_sid, + domain_handle); + if (!NT_STATUS_IS_OK(status)) { + goto done; + } + + done: + return status; +} -- cgit From 2997e2868cbff93e6ff3b1f59a8997871c946ca1 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 2 Jun 2008 17:31:00 +0200 Subject: netapi: use libnetapi_samr_open_domain(). Guenther (This used to be commit b07445e86f43d6e9e45b7c502ab7998bca4db14f) --- source3/lib/netapi/group.c | 412 ++++++--------------------------------------- source3/lib/netapi/user.c | 282 ++++--------------------------- 2 files changed, 87 insertions(+), 607 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/group.c b/source3/lib/netapi/group.c index d46d2e6135..7f905f0185 100644 --- a/source3/lib/netapi/group.c +++ b/source3/lib/netapi/group.c @@ -34,16 +34,11 @@ WERROR NetGroupAdd_r(struct libnetapi_ctx *ctx, struct rpc_pipe_client *pipe_cli = NULL; NTSTATUS status; WERROR werr; - uint32_t resume_handle = 0; - uint32_t num_entries = 0; POLICY_HND connect_handle, domain_handle, group_handle; - struct samr_SamArray *sam = NULL; - const char *domain_name = NULL; - struct lsa_String lsa_domain_name, lsa_group_name; + struct lsa_String lsa_group_name; struct dom_sid2 *domain_sid = NULL; uint32_t rid = 0; - bool domain_found = true; - int i; + struct GROUP_INFO_0 *info0; struct GROUP_INFO_1 *info1; struct GROUP_INFO_2 *info2; @@ -86,60 +81,14 @@ WERROR NetGroupAdd_r(struct libnetapi_ctx *ctx, goto done; } - status = rpccli_try_samr_connects(pipe_cli, ctx, - SAMR_ACCESS_ENUM_DOMAINS | - SAMR_ACCESS_OPEN_DOMAIN, - &connect_handle); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - status = rpccli_samr_EnumDomains(pipe_cli, ctx, - &connect_handle, - &resume_handle, - &sam, - 0xffffffff, - &num_entries); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - for (i=0; ientries[i].name.string; - - if (strequal(domain_name, builtin_domain_name())) { - continue; - } - - domain_found = true; - break; - } - - if (!domain_found) { - werr = WERR_NO_SUCH_DOMAIN; - goto done; - } - - init_lsa_String(&lsa_domain_name, domain_name); - - status = rpccli_samr_LookupDomain(pipe_cli, ctx, - &connect_handle, - &lsa_domain_name, - &domain_sid); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - status = rpccli_samr_OpenDomain(pipe_cli, ctx, - &connect_handle, - SAMR_DOMAIN_ACCESS_CREATE_GROUP | - SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, - domain_sid, - &domain_handle); + status = libnetapi_samr_open_domain(ctx, pipe_cli, + SAMR_ACCESS_ENUM_DOMAINS | + SAMR_ACCESS_OPEN_DOMAIN, + SAMR_DOMAIN_ACCESS_CREATE_GROUP | + SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, + &connect_handle, + &domain_handle, + &domain_sid); if (!NT_STATUS_IS_OK(status)) { werr = ntstatus_to_werror(status); goto done; @@ -285,15 +234,10 @@ WERROR NetGroupDel_r(struct libnetapi_ctx *ctx, struct rpc_pipe_client *pipe_cli = NULL; NTSTATUS status; WERROR werr; - uint32_t resume_handle = 0; - uint32_t num_entries = 0; POLICY_HND connect_handle, domain_handle, group_handle; - struct samr_SamArray *sam = NULL; - const char *domain_name = NULL; - struct lsa_String lsa_domain_name, lsa_group_name; + struct lsa_String lsa_group_name; struct dom_sid2 *domain_sid = NULL; - bool domain_found = true; - int i; + int i = 0; struct samr_Ids rids; struct samr_Ids types; @@ -318,59 +262,13 @@ WERROR NetGroupDel_r(struct libnetapi_ctx *ctx, goto done; } - status = rpccli_try_samr_connects(pipe_cli, ctx, - SAMR_ACCESS_ENUM_DOMAINS | - SAMR_ACCESS_OPEN_DOMAIN, - &connect_handle); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - status = rpccli_samr_EnumDomains(pipe_cli, ctx, - &connect_handle, - &resume_handle, - &sam, - 0xffffffff, - &num_entries); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - for (i=0; ientries[i].name.string; - - if (strequal(domain_name, builtin_domain_name())) { - continue; - } - - domain_found = true; - break; - } - - if (!domain_found) { - werr = WERR_NO_SUCH_DOMAIN; - goto done; - } - - init_lsa_String(&lsa_domain_name, domain_name); - - status = rpccli_samr_LookupDomain(pipe_cli, ctx, - &connect_handle, - &lsa_domain_name, - &domain_sid); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - status = rpccli_samr_OpenDomain(pipe_cli, ctx, - &connect_handle, - SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, - domain_sid, - &domain_handle); + status = libnetapi_samr_open_domain(ctx, pipe_cli, + SAMR_ACCESS_ENUM_DOMAINS | + SAMR_ACCESS_OPEN_DOMAIN, + SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, + &connect_handle, + &domain_handle, + &domain_sid); if (!NT_STATUS_IS_OK(status)) { werr = ntstatus_to_werror(status); goto done; @@ -505,15 +403,9 @@ WERROR NetGroupSetInfo_r(struct libnetapi_ctx *ctx, struct rpc_pipe_client *pipe_cli = NULL; NTSTATUS status; WERROR werr; - uint32_t resume_handle = 0; - uint32_t num_entries = 0; POLICY_HND connect_handle, domain_handle, group_handle; - struct samr_SamArray *sam = NULL; - const char *domain_name = NULL; - struct lsa_String lsa_domain_name, lsa_group_name; + struct lsa_String lsa_group_name; struct dom_sid2 *domain_sid = NULL; - bool domain_found = true; - int i; struct samr_Ids rids; struct samr_Ids types; @@ -543,59 +435,13 @@ WERROR NetGroupSetInfo_r(struct libnetapi_ctx *ctx, goto done; } - status = rpccli_try_samr_connects(pipe_cli, ctx, - SAMR_ACCESS_ENUM_DOMAINS | - SAMR_ACCESS_OPEN_DOMAIN, - &connect_handle); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - status = rpccli_samr_EnumDomains(pipe_cli, ctx, - &connect_handle, - &resume_handle, - &sam, - 0xffffffff, - &num_entries); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - for (i=0; ientries[i].name.string; - - if (strequal(domain_name, builtin_domain_name())) { - continue; - } - - domain_found = true; - break; - } - - if (!domain_found) { - werr = WERR_NO_SUCH_DOMAIN; - goto done; - } - - init_lsa_String(&lsa_domain_name, domain_name); - - status = rpccli_samr_LookupDomain(pipe_cli, ctx, - &connect_handle, - &lsa_domain_name, - &domain_sid); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - status = rpccli_samr_OpenDomain(pipe_cli, ctx, - &connect_handle, - SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, - domain_sid, - &domain_handle); + status = libnetapi_samr_open_domain(ctx, pipe_cli, + SAMR_ACCESS_ENUM_DOMAINS | + SAMR_ACCESS_OPEN_DOMAIN, + SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, + &connect_handle, + &domain_handle, + &domain_sid); if (!NT_STATUS_IS_OK(status)) { werr = ntstatus_to_werror(status); goto done; @@ -805,15 +651,9 @@ WERROR NetGroupGetInfo_r(struct libnetapi_ctx *ctx, struct rpc_pipe_client *pipe_cli = NULL; NTSTATUS status; WERROR werr; - uint32_t resume_handle = 0; - uint32_t num_entries = 0; POLICY_HND connect_handle, domain_handle, group_handle; - struct samr_SamArray *sam = NULL; - const char *domain_name = NULL; - struct lsa_String lsa_domain_name, lsa_group_name; + struct lsa_String lsa_group_name; struct dom_sid2 *domain_sid = NULL; - bool domain_found = true; - int i; struct samr_Ids rids; struct samr_Ids types; @@ -837,59 +677,13 @@ WERROR NetGroupGetInfo_r(struct libnetapi_ctx *ctx, goto done; } - status = rpccli_try_samr_connects(pipe_cli, ctx, - SAMR_ACCESS_ENUM_DOMAINS | - SAMR_ACCESS_OPEN_DOMAIN, - &connect_handle); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - status = rpccli_samr_EnumDomains(pipe_cli, ctx, - &connect_handle, - &resume_handle, - &sam, - 0xffffffff, - &num_entries); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - for (i=0; ientries[i].name.string; - - if (strequal(domain_name, builtin_domain_name())) { - continue; - } - - domain_found = true; - break; - } - - if (!domain_found) { - werr = WERR_NO_SUCH_DOMAIN; - goto done; - } - - init_lsa_String(&lsa_domain_name, domain_name); - - status = rpccli_samr_LookupDomain(pipe_cli, ctx, - &connect_handle, - &lsa_domain_name, - &domain_sid); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - status = rpccli_samr_OpenDomain(pipe_cli, ctx, - &connect_handle, - SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, - domain_sid, - &domain_handle); + status = libnetapi_samr_open_domain(ctx, pipe_cli, + SAMR_ACCESS_ENUM_DOMAINS | + SAMR_ACCESS_OPEN_DOMAIN, + SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, + &connect_handle, + &domain_handle, + &domain_sid); if (!NT_STATUS_IS_OK(status)) { werr = ntstatus_to_werror(status); goto done; @@ -975,15 +769,9 @@ WERROR NetGroupAddUser_r(struct libnetapi_ctx *ctx, struct rpc_pipe_client *pipe_cli = NULL; NTSTATUS status; WERROR werr; - uint32_t resume_handle = 0; - uint32_t num_entries = 0; POLICY_HND connect_handle, domain_handle, group_handle; - struct samr_SamArray *sam = NULL; - const char *domain_name = NULL; - struct lsa_String lsa_domain_name, lsa_group_name, lsa_user_name; + struct lsa_String lsa_group_name, lsa_user_name; struct dom_sid2 *domain_sid = NULL; - bool domain_found = true; - int i; struct samr_Ids rids; struct samr_Ids types; @@ -1006,59 +794,13 @@ WERROR NetGroupAddUser_r(struct libnetapi_ctx *ctx, goto done; } - status = rpccli_try_samr_connects(pipe_cli, ctx, - SAMR_ACCESS_ENUM_DOMAINS | - SAMR_ACCESS_OPEN_DOMAIN, - &connect_handle); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - status = rpccli_samr_EnumDomains(pipe_cli, ctx, - &connect_handle, - &resume_handle, - &sam, - 0xffffffff, - &num_entries); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - for (i=0; ientries[i].name.string; - - if (strequal(domain_name, builtin_domain_name())) { - continue; - } - - domain_found = true; - break; - } - - if (!domain_found) { - werr = WERR_NO_SUCH_DOMAIN; - goto done; - } - - init_lsa_String(&lsa_domain_name, domain_name); - - status = rpccli_samr_LookupDomain(pipe_cli, ctx, - &connect_handle, - &lsa_domain_name, - &domain_sid); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - status = rpccli_samr_OpenDomain(pipe_cli, ctx, - &connect_handle, - SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, - domain_sid, - &domain_handle); + status = libnetapi_samr_open_domain(ctx, pipe_cli, + SAMR_ACCESS_ENUM_DOMAINS | + SAMR_ACCESS_OPEN_DOMAIN, + SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, + &connect_handle, + &domain_handle, + &domain_sid); if (!NT_STATUS_IS_OK(status)) { werr = ntstatus_to_werror(status); goto done; @@ -1158,15 +900,9 @@ WERROR NetGroupDelUser_r(struct libnetapi_ctx *ctx, struct rpc_pipe_client *pipe_cli = NULL; NTSTATUS status; WERROR werr; - uint32_t resume_handle = 0; - uint32_t num_entries = 0; POLICY_HND connect_handle, domain_handle, group_handle; - struct samr_SamArray *sam = NULL; - const char *domain_name = NULL; - struct lsa_String lsa_domain_name, lsa_group_name, lsa_user_name; + struct lsa_String lsa_group_name, lsa_user_name; struct dom_sid2 *domain_sid = NULL; - bool domain_found = true; - int i; struct samr_Ids rids; struct samr_Ids types; @@ -1189,59 +925,13 @@ WERROR NetGroupDelUser_r(struct libnetapi_ctx *ctx, goto done; } - status = rpccli_try_samr_connects(pipe_cli, ctx, - SAMR_ACCESS_ENUM_DOMAINS | - SAMR_ACCESS_OPEN_DOMAIN, - &connect_handle); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - status = rpccli_samr_EnumDomains(pipe_cli, ctx, - &connect_handle, - &resume_handle, - &sam, - 0xffffffff, - &num_entries); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - for (i=0; ientries[i].name.string; - - if (strequal(domain_name, builtin_domain_name())) { - continue; - } - - domain_found = true; - break; - } - - if (!domain_found) { - werr = WERR_NO_SUCH_DOMAIN; - goto done; - } - - init_lsa_String(&lsa_domain_name, domain_name); - - status = rpccli_samr_LookupDomain(pipe_cli, ctx, - &connect_handle, - &lsa_domain_name, - &domain_sid); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - status = rpccli_samr_OpenDomain(pipe_cli, ctx, - &connect_handle, - SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, - domain_sid, - &domain_handle); + status = libnetapi_samr_open_domain(ctx, pipe_cli, + SAMR_ACCESS_ENUM_DOMAINS | + SAMR_ACCESS_OPEN_DOMAIN, + SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, + &connect_handle, + &domain_handle, + &domain_sid); if (!NT_STATUS_IS_OK(status)) { werr = ntstatus_to_werror(status); goto done; diff --git a/source3/lib/netapi/user.c b/source3/lib/netapi/user.c index f2dc785a36..de4f9164ce 100644 --- a/source3/lib/netapi/user.c +++ b/source3/lib/netapi/user.c @@ -135,20 +135,14 @@ WERROR NetUserAdd_r(struct libnetapi_ctx *ctx, struct rpc_pipe_client *pipe_cli = NULL; NTSTATUS status; WERROR werr; - uint32_t resume_handle = 0; - uint32_t num_entries = 0; POLICY_HND connect_handle, domain_handle, user_handle; - struct samr_SamArray *sam = NULL; - const char *domain_name = NULL; - struct lsa_String lsa_domain_name, lsa_account_name; + struct lsa_String lsa_account_name; struct dom_sid2 *domain_sid = NULL; struct samr_UserInfo25 info25; union samr_UserInfo *user_info = NULL; struct samr_PwInfo pw_info; uint32_t access_granted = 0; uint32_t rid = 0; - bool domain_found = true; - int i; struct USER_INFO_1 *info1; ZERO_STRUCT(connect_handle); @@ -181,61 +175,15 @@ WERROR NetUserAdd_r(struct libnetapi_ctx *ctx, goto done; } - status = rpccli_try_samr_connects(pipe_cli, ctx, - SAMR_ACCESS_ENUM_DOMAINS | - SAMR_ACCESS_OPEN_DOMAIN, - &connect_handle); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - status = rpccli_samr_EnumDomains(pipe_cli, ctx, - &connect_handle, - &resume_handle, - &sam, - 0xffffffff, - &num_entries); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - for (i=0; ientries[i].name.string; - - if (strequal(domain_name, builtin_domain_name())) { - continue; - } - - domain_found = true; - break; - } - - if (!domain_found) { - werr = WERR_NO_SUCH_DOMAIN; - goto done; - } - - init_lsa_String(&lsa_domain_name, domain_name); - - status = rpccli_samr_LookupDomain(pipe_cli, ctx, - &connect_handle, - &lsa_domain_name, - &domain_sid); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - status = rpccli_samr_OpenDomain(pipe_cli, ctx, - &connect_handle, - SAMR_DOMAIN_ACCESS_LOOKUP_INFO_1 | - SAMR_DOMAIN_ACCESS_CREATE_USER | - SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, - domain_sid, - &domain_handle); + status = libnetapi_samr_open_domain(ctx, pipe_cli, + SAMR_ACCESS_ENUM_DOMAINS | + SAMR_ACCESS_OPEN_DOMAIN, + SAMR_DOMAIN_ACCESS_LOOKUP_INFO_1 | + SAMR_DOMAIN_ACCESS_CREATE_USER | + SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, + &connect_handle, + &domain_handle, + &domain_sid); if (!NT_STATUS_IS_OK(status)) { werr = ntstatus_to_werror(status); goto done; @@ -356,17 +304,11 @@ WERROR NetUserDel_r(struct libnetapi_ctx *ctx, struct rpc_pipe_client *pipe_cli = NULL; NTSTATUS status; WERROR werr; - uint32_t resume_handle = 0; - uint32_t num_entries = 0; POLICY_HND connect_handle, builtin_handle, domain_handle, user_handle; - struct samr_SamArray *sam = NULL; - const char *domain_name = NULL; - struct lsa_String lsa_domain_name, lsa_account_name; + struct lsa_String lsa_account_name; struct samr_Ids user_rids, name_types; struct dom_sid2 *domain_sid = NULL; struct dom_sid2 user_sid; - bool domain_found = true; - int i; ZERO_STRUCT(connect_handle); ZERO_STRUCT(builtin_handle); @@ -383,59 +325,13 @@ WERROR NetUserDel_r(struct libnetapi_ctx *ctx, goto done; } - status = rpccli_try_samr_connects(pipe_cli, ctx, - SAMR_ACCESS_ENUM_DOMAINS | - SAMR_ACCESS_OPEN_DOMAIN, - &connect_handle); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - status = rpccli_samr_EnumDomains(pipe_cli, ctx, - &connect_handle, - &resume_handle, - &sam, - 0xffffffff, - &num_entries); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - for (i=0; ientries[i].name.string; - - if (strequal(domain_name, builtin_domain_name())) { - continue; - } - - domain_found = true; - break; - } - - if (!domain_found) { - werr = WERR_NO_SUCH_DOMAIN; - goto done; - } - - init_lsa_String(&lsa_domain_name, domain_name); - - status = rpccli_samr_LookupDomain(pipe_cli, ctx, - &connect_handle, - &lsa_domain_name, - &domain_sid); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - status = rpccli_samr_OpenDomain(pipe_cli, ctx, - &connect_handle, - SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, - domain_sid, - &domain_handle); + status = libnetapi_samr_open_domain(ctx, pipe_cli, + SAMR_ACCESS_ENUM_DOMAINS | + SAMR_ACCESS_OPEN_DOMAIN, + SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, + &connect_handle, + &domain_handle, + &domain_sid); if (!NT_STATUS_IS_OK(status)) { werr = ntstatus_to_werror(status); goto done; @@ -574,12 +470,6 @@ WERROR NetUserEnum_r(struct libnetapi_ctx *ctx, struct dom_sid2 *domain_sid = NULL; struct policy_handle domain_handle; struct samr_SamArray *sam = NULL; - uint32_t num_entries = 0; - int i; - const char *domain_name = NULL; - bool domain_found = true; - uint32_t dom_resume_handle = 0; - struct lsa_String lsa_domain_name; NTSTATUS status; WERROR werr; @@ -611,62 +501,15 @@ WERROR NetUserEnum_r(struct libnetapi_ctx *ctx, goto done; } - status = rpccli_try_samr_connects(pipe_cli, ctx, - SAMR_ACCESS_OPEN_DOMAIN | - SAMR_ACCESS_ENUM_DOMAINS, - &connect_handle); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - status = rpccli_samr_EnumDomains(pipe_cli, ctx, - &connect_handle, - &dom_resume_handle, - &sam, - 0xffffffff, - &num_entries); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - for (i=0; ientries[i].name.string; - - if (strequal(domain_name, builtin_domain_name())) { - continue; - } - - domain_found = true; - break; - } - - if (!domain_found) { - werr = WERR_NO_SUCH_DOMAIN; - goto done; - } - - init_lsa_String(&lsa_domain_name, domain_name); - - status = rpccli_samr_LookupDomain(pipe_cli, ctx, - &connect_handle, - &lsa_domain_name, - &domain_sid); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - status = rpccli_samr_OpenDomain(pipe_cli, - ctx, - &connect_handle, - SAMR_DOMAIN_ACCESS_LOOKUP_INFO_2 | - SAMR_DOMAIN_ACCESS_ENUM_ACCOUNTS | - SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, - domain_sid, - &domain_handle); + status = libnetapi_samr_open_domain(ctx, pipe_cli, + SAMR_ACCESS_ENUM_DOMAINS | + SAMR_ACCESS_OPEN_DOMAIN, + SAMR_DOMAIN_ACCESS_LOOKUP_INFO_2 | + SAMR_DOMAIN_ACCESS_ENUM_ACCOUNTS | + SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, + &connect_handle, + &domain_handle, + &domain_sid); if (!NT_STATUS_IS_OK(status)) { werr = ntstatus_to_werror(status); goto done; @@ -886,13 +729,6 @@ WERROR NetQueryDisplayInformation_r(struct libnetapi_ctx *ctx, struct dom_sid2 *domain_sid = NULL; struct policy_handle domain_handle; union samr_DispInfo info; - struct samr_SamArray *sam = NULL; - uint32_t num_entries = 0; - int i; - const char *domain_name = NULL; - bool domain_found = true; - uint32_t dom_resume_handle = 0; - struct lsa_String lsa_domain_name; uint32_t total_size = 0; uint32_t returned_size = 0; @@ -922,61 +758,15 @@ WERROR NetQueryDisplayInformation_r(struct libnetapi_ctx *ctx, goto done; } - status = rpccli_try_samr_connects(pipe_cli, ctx, - SAMR_ACCESS_OPEN_DOMAIN | - SAMR_ACCESS_ENUM_DOMAINS, - &connect_handle); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - status = rpccli_samr_EnumDomains(pipe_cli, ctx, - &connect_handle, - &dom_resume_handle, - &sam, - 0xffffffff, - &num_entries); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - for (i=0; ientries[i].name.string; - - if (strequal(domain_name, builtin_domain_name())) { - continue; - } - - domain_found = true; - break; - } - - if (!domain_found) { - werr = WERR_NO_SUCH_DOMAIN; - goto done; - } - - init_lsa_String(&lsa_domain_name, domain_name); - - status = rpccli_samr_LookupDomain(pipe_cli, ctx, - &connect_handle, - &lsa_domain_name, - &domain_sid); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - status = rpccli_samr_OpenDomain(pipe_cli, - ctx, - &connect_handle, - SAMR_DOMAIN_ACCESS_ENUM_ACCOUNTS | - SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, - domain_sid, - &domain_handle); + status = libnetapi_samr_open_domain(ctx, pipe_cli, + SAMR_ACCESS_ENUM_DOMAINS | + SAMR_ACCESS_OPEN_DOMAIN, + SAMR_DOMAIN_ACCESS_LOOKUP_INFO_2 | + SAMR_DOMAIN_ACCESS_ENUM_ACCOUNTS | + SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, + &connect_handle, + &domain_handle, + &domain_sid); if (!NT_STATUS_IS_OK(status)) { werr = ntstatus_to_werror(status); goto done; -- cgit From 4f419aae8041511329761daa475129421b665ce5 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 2 Jun 2008 17:34:53 +0200 Subject: netapi: add NetLocalGroupAdd() skeleton. Guenther (This used to be commit 528544d4ce8fa27940a2f5e3c989cf37ef888f94) --- source3/lib/netapi/libnetapi.c | 46 +++++++++++++++++++++++++++++++++++++++++ source3/lib/netapi/libnetapi.h | 8 +++++++ source3/lib/netapi/localgroup.c | 43 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 97 insertions(+) create mode 100644 source3/lib/netapi/localgroup.c (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/libnetapi.c b/source3/lib/netapi/libnetapi.c index 3bbb1686ab..6537329fe0 100644 --- a/source3/lib/netapi/libnetapi.c +++ b/source3/lib/netapi/libnetapi.c @@ -907,3 +907,49 @@ NET_API_STATUS NetGroupDelUser(const char * server_name /* [in] */, return r.out.result; } +/**************************************************************** + NetLocalGroupAdd +****************************************************************/ + +NET_API_STATUS NetLocalGroupAdd(const char * server_name /* [in] */, + uint32_t level /* [in] */, + uint8_t *buf /* [in] [ref] */, + uint32_t *parm_err /* [out] [ref] */) +{ + struct NetLocalGroupAdd r; + struct libnetapi_ctx *ctx = NULL; + NET_API_STATUS status; + WERROR werr; + + status = libnetapi_getctx(&ctx); + if (status != 0) { + return status; + } + + /* In parameters */ + r.in.server_name = server_name; + r.in.level = level; + r.in.buf = buf; + + /* Out parameters */ + r.out.parm_err = parm_err; + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_IN_DEBUG(NetLocalGroupAdd, &r); + } + + if (LIBNETAPI_LOCAL_SERVER(server_name)) { + werr = NetLocalGroupAdd_l(ctx, &r); + } else { + werr = NetLocalGroupAdd_r(ctx, &r); + } + + r.out.result = W_ERROR_V(werr); + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_OUT_DEBUG(NetLocalGroupAdd, &r); + } + + return r.out.result; +} + diff --git a/source3/lib/netapi/libnetapi.h b/source3/lib/netapi/libnetapi.h index 4faca46b22..38826996fa 100644 --- a/source3/lib/netapi/libnetapi.h +++ b/source3/lib/netapi/libnetapi.h @@ -156,4 +156,12 @@ WERROR NetGroupDelUser_r(struct libnetapi_ctx *ctx, struct NetGroupDelUser *r); WERROR NetGroupDelUser_l(struct libnetapi_ctx *ctx, struct NetGroupDelUser *r); +NET_API_STATUS NetLocalGroupAdd(const char * server_name /* [in] */, + uint32_t level /* [in] */, + uint8_t *buf /* [in] [ref] */, + uint32_t *parm_err /* [out] [ref] */); +WERROR NetLocalGroupAdd_r(struct libnetapi_ctx *ctx, + struct NetLocalGroupAdd *r); +WERROR NetLocalGroupAdd_l(struct libnetapi_ctx *ctx, + struct NetLocalGroupAdd *r); #endif /* __LIBNETAPI_LIBNETAPI__ */ diff --git a/source3/lib/netapi/localgroup.c b/source3/lib/netapi/localgroup.c new file mode 100644 index 0000000000..4a1b76003c --- /dev/null +++ b/source3/lib/netapi/localgroup.c @@ -0,0 +1,43 @@ +/* + * Unix SMB/CIFS implementation. + * NetApi LocalGroup Support + * Copyright (C) Guenther Deschner 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include "includes.h" + +#include "librpc/gen_ndr/libnetapi.h" +#include "lib/netapi/netapi.h" +#include "lib/netapi/netapi_private.h" +#include "lib/netapi/libnetapi.h" + +/**************************************************************** +****************************************************************/ + +WERROR NetLocalGroupAdd_r(struct libnetapi_ctx *ctx, + struct NetLocalGroupAdd *r) +{ + return WERR_NOT_SUPPORTED; +} + +/**************************************************************** +****************************************************************/ + +WERROR NetLocalGroupAdd_l(struct libnetapi_ctx *ctx, + struct NetLocalGroupAdd *r) +{ + return WERR_NOT_SUPPORTED; +} -- cgit From 97cf9db58307a6869967d056e7e5113d5985d583 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 2 Jun 2008 19:02:52 +0200 Subject: netapi: Implement NetLocalGroupAdd(). Guenther (This used to be commit f68f75a6e4b4ba8b38cac7578c65dc7361315b28) --- source3/lib/netapi/localgroup.c | 155 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 153 insertions(+), 2 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/localgroup.c b/source3/lib/netapi/localgroup.c index 4a1b76003c..ab550ede9c 100644 --- a/source3/lib/netapi/localgroup.c +++ b/source3/lib/netapi/localgroup.c @@ -30,7 +30,158 @@ WERROR NetLocalGroupAdd_r(struct libnetapi_ctx *ctx, struct NetLocalGroupAdd *r) { - return WERR_NOT_SUPPORTED; + struct cli_state *cli = NULL; + struct rpc_pipe_client *pipe_cli = NULL; + NTSTATUS status; + WERROR werr; + struct lsa_String lsa_account_name; + struct policy_handle connect_handle, domain_handle, builtin_handle, alias_handle; + struct samr_Ids user_rids, name_types; + struct dom_sid2 *domain_sid = NULL; + uint32_t rid; + + struct LOCALGROUP_INFO_0 *info0; + struct LOCALGROUP_INFO_1 *info1; + + const char *alias_name = NULL; + + if (!r->in.buf) { + return WERR_INVALID_PARAM; + } + + switch (r->in.level) { + case 0: + info0 = (struct LOCALGROUP_INFO_0 *)r->in.buf; + alias_name = info0->lgrpi0_name; + break; + case 1: + info1 = (struct LOCALGROUP_INFO_1 *)r->in.buf; + alias_name = info1->lgrpi1_name; + break; + default: + werr = WERR_UNKNOWN_LEVEL; + goto done; + } + + ZERO_STRUCT(connect_handle); + ZERO_STRUCT(builtin_handle); + ZERO_STRUCT(domain_handle); + ZERO_STRUCT(alias_handle); + + werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + werr = libnetapi_open_pipe(ctx, cli, PI_SAMR, &pipe_cli); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + status = rpccli_try_samr_connects(pipe_cli, ctx, + SAMR_ACCESS_OPEN_DOMAIN | + SAMR_ACCESS_ENUM_DOMAINS, + &connect_handle); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + status = rpccli_samr_OpenDomain(pipe_cli, ctx, + &connect_handle, + SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, + CONST_DISCARD(DOM_SID *, &global_sid_Builtin), + &builtin_handle); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + init_lsa_String(&lsa_account_name, alias_name); + + status = rpccli_samr_LookupNames(pipe_cli, ctx, + &builtin_handle, + 1, + &lsa_account_name, + &user_rids, + &name_types); + if (NT_STATUS_IS_OK(status)) { + status = rpccli_samr_OpenAlias(pipe_cli, ctx, + &builtin_handle, + SAMR_ALIAS_ACCESS_LOOKUP_INFO, + user_rids.ids[0], + &alias_handle); + if (NT_STATUS_IS_OK(status)) { + werr = WERR_ALIAS_EXISTS; + goto done; + } + + } + + rpccli_samr_Close(pipe_cli, ctx, &builtin_handle); + + status = libnetapi_samr_open_domain(ctx, pipe_cli, + SAMR_ACCESS_ENUM_DOMAINS | + SAMR_ACCESS_OPEN_DOMAIN, + SAMR_DOMAIN_ACCESS_CREATE_ALIAS | + SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, + &connect_handle, + &domain_handle, + &domain_sid); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + status = rpccli_samr_CreateDomAlias(pipe_cli, ctx, + &domain_handle, + &lsa_account_name, + SEC_STD_DELETE | + SAMR_ALIAS_ACCESS_SET_INFO, + &alias_handle, + &rid); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + if (r->in.level == 1) { + + union samr_AliasInfo alias_info; + + init_lsa_String(&alias_info.description, info1->lgrpi1_comment); + + status = rpccli_samr_SetAliasInfo(pipe_cli, ctx, + &alias_handle, + ALIASINFODESCRIPTION, + &alias_info); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + } + + werr = WERR_OK; + + done: + if (!cli) { + return werr; + } + + if (is_valid_policy_hnd(&alias_handle)) { + rpccli_samr_Close(pipe_cli, ctx, &alias_handle); + } + if (is_valid_policy_hnd(&domain_handle)) { + rpccli_samr_Close(pipe_cli, ctx, &domain_handle); + } + if (is_valid_policy_hnd(&builtin_handle)) { + rpccli_samr_Close(pipe_cli, ctx, &builtin_handle); + } + if (is_valid_policy_hnd(&connect_handle)) { + rpccli_samr_Close(pipe_cli, ctx, &connect_handle); + } + + return werr; } /**************************************************************** @@ -39,5 +190,5 @@ WERROR NetLocalGroupAdd_r(struct libnetapi_ctx *ctx, WERROR NetLocalGroupAdd_l(struct libnetapi_ctx *ctx, struct NetLocalGroupAdd *r) { - return WERR_NOT_SUPPORTED; + return NetLocalGroupAdd_r(ctx, r); } -- cgit From dac9e2228c93d296f2fd3110837ec8e7edbd3ea8 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 2 Jun 2008 19:12:54 +0200 Subject: netapi: add NetLocalGroupAdd to public api. Guenther (This used to be commit 05ded246426415b61597d003ffac519847c08620) --- source3/lib/netapi/netapi.h | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h index d787cedf4c..d08f1b7f74 100644 --- a/source3/lib/netapi/netapi.h +++ b/source3/lib/netapi/netapi.h @@ -144,6 +144,19 @@ struct GROUP_INFO_1005 { uint32_t grpi1005_attributes; }; +struct LOCALGROUP_INFO_0 { + const char * lgrpi0_name; +}; + +struct LOCALGROUP_INFO_1 { + const char * lgrpi1_name; + const char * lgrpi1_comment; +}; + +struct LOCALGROUP_INFO_1002 { + const char * lgrpi1002_comment; +}; + #endif /* _HEADER_libnetapi */ /**************************************************************** @@ -617,4 +630,24 @@ NET_API_STATUS NetGroupDelUser(const char * server_name /* [in] */, const char * group_name /* [in] */, const char * user_name /* [in] */); +/************************************************************//** + * + * NetLocalGroupAdd + * + * @brief Create Local Group + * + * @param[in] server_name The server name to connect to + * @param[in] level The level used for the new group creation + * @param[in] buf The buffer containing the group structure + * @param[out] parm_err The returned parameter error number if any + * @return NET_API_STATUS + * + * example localgroup/localgroup_add.c + ***************************************************************/ + +NET_API_STATUS NetLocalGroupAdd(const char * server_name /* [in] */, + uint32_t level /* [in] */, + uint8_t *buf /* [in] [ref] */, + uint32_t *parm_err /* [out] [ref] */); + #endif -- cgit From 5e0c89af5a2e8ef39cb4ca921bfea031a8c77da1 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 2 Jun 2008 19:13:26 +0200 Subject: netapi: add NetLocalGroupAdd() example. Guenther (This used to be commit ce60450d831ee2f4ab18c3ce09decee548ec4543) --- source3/lib/netapi/examples/Makefile.in | 8 +- .../netapi/examples/localgroup/localgroup_add.c | 106 +++++++++++++++++++++ 2 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 source3/lib/netapi/examples/localgroup/localgroup_add.c (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/Makefile.in b/source3/lib/netapi/examples/Makefile.in index 156bd218ba..e5ab4c13fe 100644 --- a/source3/lib/netapi/examples/Makefile.in +++ b/source3/lib/netapi/examples/Makefile.in @@ -31,7 +31,8 @@ PROGS = bin/getdc@EXEEXT@ \ bin/group_setinfo@EXEEXT@ \ bin/group_getinfo@EXEEXT@ \ bin/group_adduser@EXEEXT@ \ - bin/group_deluser@EXEEXT@ + bin/group_deluser@EXEEXT@ \ + bin/localgroup_add@EXEEXT@ all: $(PROGS) @@ -75,6 +76,7 @@ GROUPSETINFO_OBJ = group/group_setinfo.o $(CMDLINE_OBJ) GROUPGETINFO_OBJ = group/group_getinfo.o $(CMDLINE_OBJ) GROUPADDUSER_OBJ = group/group_adduser.o $(CMDLINE_OBJ) GROUPDELUSER_OBJ = group/group_deluser.o $(CMDLINE_OBJ) +LOCALGROUPADD_OBJ = localgroup/localgroup_add.o $(CMDLINE_OBJ) bin/getdc@EXEEXT@: $(BINARY_PREREQS) $(GETDC_OBJ) @echo Linking $@ @@ -136,6 +138,10 @@ bin/group_deluser@EXEEXT@: $(BINARY_PREREQS) $(GROUPDELUSER_OBJ) @echo Linking $@ @$(CC) $(FLAGS) -o $@ $(GROUPDELUSER_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) +bin/localgroup_add@EXEEXT@: $(BINARY_PREREQS) $(LOCALGROUPADD_OBJ) + @echo Linking $@ + @$(CC) $(FLAGS) -o $@ $(LOCALGROUPADD_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) + clean: -rm -f $(PROGS) -rm -f core */*~ *~ \ diff --git a/source3/lib/netapi/examples/localgroup/localgroup_add.c b/source3/lib/netapi/examples/localgroup/localgroup_add.c new file mode 100644 index 0000000000..7f23c99db1 --- /dev/null +++ b/source3/lib/netapi/examples/localgroup/localgroup_add.c @@ -0,0 +1,106 @@ +/* + * Unix SMB/CIFS implementation. + * NetLocalGroupAdd query + * Copyright (C) Guenther Deschner 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include +#include +#include +#include +#include + +#include + +#include "common.h" + +int main(int argc, const char **argv) +{ + NET_API_STATUS status; + struct libnetapi_ctx *ctx = NULL; + const char *hostname = NULL; + const char *groupname = NULL; + const char *comment = NULL; + struct LOCALGROUP_INFO_0 g0; + struct LOCALGROUP_INFO_1 g1; + uint32_t parm_error = 0; + uint8_t *buf = NULL; + uint32_t level = 0; + + poptContext pc; + int opt; + + struct poptOption long_options[] = { + POPT_AUTOHELP + POPT_COMMON_LIBNETAPI_EXAMPLES + POPT_TABLEEND + }; + + status = libnetapi_init(&ctx); + if (status != 0) { + return status; + } + + pc = poptGetContext("localgroup_add", argc, argv, long_options, 0); + + poptSetOtherOptionHelp(pc, "hostname groupname comment"); + while((opt = poptGetNextOpt(pc)) != -1) { + } + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + hostname = poptGetArg(pc); + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + groupname = poptGetArg(pc); + + if (poptPeekArg(pc)) { + comment = poptGetArg(pc); + } + + /* NetLocalGroupAdd */ + + if (comment) { + level = 1; + g1.lgrpi1_name = groupname; + g1.lgrpi1_comment = comment; + buf = (uint8_t *)&g1; + } else { + level = 0; + g0.lgrpi0_name = groupname; + buf = (uint8_t *)&g0; + } + + status = NetLocalGroupAdd(hostname, + level, + buf, + &parm_error); + if (status != 0) { + printf("NetLocalGroupAdd failed with: %s\n", + libnetapi_get_error_string(ctx, status)); + } + + out: + libnetapi_free(ctx); + poptFreeContext(pc); + + return status; +} -- cgit From 7773d79afd4718cacd33d490870c5bc042642d1f Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 2 Jun 2008 19:20:25 +0200 Subject: netapi: add NetLocalGroupDel() skeleton. Guenther (This used to be commit 4234c87c6c30434bc5bcfcc003fdaa0114e9d74a) --- source3/lib/netapi/libnetapi.c | 42 +++++++++++++++++++++++++++++++++++++++++ source3/lib/netapi/libnetapi.h | 6 ++++++ source3/lib/netapi/localgroup.c | 20 ++++++++++++++++++++ 3 files changed, 68 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/libnetapi.c b/source3/lib/netapi/libnetapi.c index 6537329fe0..522d2aa970 100644 --- a/source3/lib/netapi/libnetapi.c +++ b/source3/lib/netapi/libnetapi.c @@ -953,3 +953,45 @@ NET_API_STATUS NetLocalGroupAdd(const char * server_name /* [in] */, return r.out.result; } +/**************************************************************** + NetLocalGroupDel +****************************************************************/ + +NET_API_STATUS NetLocalGroupDel(const char * server_name /* [in] */, + const char * group_name /* [in] */) +{ + struct NetLocalGroupDel r; + struct libnetapi_ctx *ctx = NULL; + NET_API_STATUS status; + WERROR werr; + + status = libnetapi_getctx(&ctx); + if (status != 0) { + return status; + } + + /* In parameters */ + r.in.server_name = server_name; + r.in.group_name = group_name; + + /* Out parameters */ + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_IN_DEBUG(NetLocalGroupDel, &r); + } + + if (LIBNETAPI_LOCAL_SERVER(server_name)) { + werr = NetLocalGroupDel_l(ctx, &r); + } else { + werr = NetLocalGroupDel_r(ctx, &r); + } + + r.out.result = W_ERROR_V(werr); + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_OUT_DEBUG(NetLocalGroupDel, &r); + } + + return r.out.result; +} + diff --git a/source3/lib/netapi/libnetapi.h b/source3/lib/netapi/libnetapi.h index 38826996fa..2386488b72 100644 --- a/source3/lib/netapi/libnetapi.h +++ b/source3/lib/netapi/libnetapi.h @@ -164,4 +164,10 @@ WERROR NetLocalGroupAdd_r(struct libnetapi_ctx *ctx, struct NetLocalGroupAdd *r); WERROR NetLocalGroupAdd_l(struct libnetapi_ctx *ctx, struct NetLocalGroupAdd *r); +NET_API_STATUS NetLocalGroupDel(const char * server_name /* [in] */, + const char * group_name /* [in] */); +WERROR NetLocalGroupDel_r(struct libnetapi_ctx *ctx, + struct NetLocalGroupDel *r); +WERROR NetLocalGroupDel_l(struct libnetapi_ctx *ctx, + struct NetLocalGroupDel *r); #endif /* __LIBNETAPI_LIBNETAPI__ */ diff --git a/source3/lib/netapi/localgroup.c b/source3/lib/netapi/localgroup.c index ab550ede9c..b2e5d9094b 100644 --- a/source3/lib/netapi/localgroup.c +++ b/source3/lib/netapi/localgroup.c @@ -192,3 +192,23 @@ WERROR NetLocalGroupAdd_l(struct libnetapi_ctx *ctx, { return NetLocalGroupAdd_r(ctx, r); } + +/**************************************************************** +****************************************************************/ + + +WERROR NetLocalGroupDel_r(struct libnetapi_ctx *ctx, + struct NetLocalGroupDel *r) +{ + return WERR_NOT_SUPPORTED; +} + +/**************************************************************** +****************************************************************/ + + +WERROR NetLocalGroupDel_l(struct libnetapi_ctx *ctx, + struct NetLocalGroupDel *r) +{ + return WERR_NOT_SUPPORTED; +} -- cgit From 4d6e66a42efc58e7ba119599f3436053f16a9bec Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 2 Jun 2008 19:44:32 +0200 Subject: netapi: Implement NetLocalGroupDel(). Guenther (This used to be commit d2426f53fabaf75d130fb99216b71299f4371253) --- source3/lib/netapi/localgroup.c | 139 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 137 insertions(+), 2 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/localgroup.c b/source3/lib/netapi/localgroup.c index b2e5d9094b..fd76e09e8e 100644 --- a/source3/lib/netapi/localgroup.c +++ b/source3/lib/netapi/localgroup.c @@ -200,7 +200,142 @@ WERROR NetLocalGroupAdd_l(struct libnetapi_ctx *ctx, WERROR NetLocalGroupDel_r(struct libnetapi_ctx *ctx, struct NetLocalGroupDel *r) { - return WERR_NOT_SUPPORTED; + struct cli_state *cli = NULL; + struct rpc_pipe_client *pipe_cli = NULL; + NTSTATUS status; + WERROR werr; + struct lsa_String lsa_account_name; + struct policy_handle connect_handle, domain_handle, builtin_handle, alias_handle; + struct samr_Ids user_rids, name_types; + struct dom_sid2 *domain_sid = NULL; + + if (!r->in.group_name) { + return WERR_INVALID_PARAM; + } + + ZERO_STRUCT(connect_handle); + ZERO_STRUCT(builtin_handle); + ZERO_STRUCT(domain_handle); + ZERO_STRUCT(alias_handle); + + werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + werr = libnetapi_open_pipe(ctx, cli, PI_SAMR, &pipe_cli); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + status = rpccli_try_samr_connects(pipe_cli, ctx, + SAMR_ACCESS_OPEN_DOMAIN | + SAMR_ACCESS_ENUM_DOMAINS, + &connect_handle); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + status = rpccli_samr_OpenDomain(pipe_cli, ctx, + &connect_handle, + SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, + CONST_DISCARD(DOM_SID *, &global_sid_Builtin), + &builtin_handle); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + init_lsa_String(&lsa_account_name, r->in.group_name); + + status = rpccli_samr_LookupNames(pipe_cli, ctx, + &builtin_handle, + 1, + &lsa_account_name, + &user_rids, + &name_types); + if (NT_STATUS_IS_OK(status)) { + status = rpccli_samr_OpenAlias(pipe_cli, ctx, + &builtin_handle, + SEC_STD_DELETE, + user_rids.ids[0], + &alias_handle); + if (NT_STATUS_IS_OK(status)) { + rpccli_samr_Close(pipe_cli, ctx, &builtin_handle); + goto delete_alias; + } + } + + rpccli_samr_Close(pipe_cli, ctx, &builtin_handle); + + status = libnetapi_samr_open_domain(ctx, pipe_cli, + SAMR_ACCESS_ENUM_DOMAINS | + SAMR_ACCESS_OPEN_DOMAIN, + SAMR_DOMAIN_ACCESS_CREATE_ALIAS | + SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, + &connect_handle, + &domain_handle, + &domain_sid); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + status = rpccli_samr_LookupNames(pipe_cli, ctx, + &domain_handle, + 1, + &lsa_account_name, + &user_rids, + &name_types); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + status = rpccli_samr_OpenAlias(pipe_cli, ctx, + &domain_handle, + SEC_STD_DELETE, + user_rids.ids[0], + &alias_handle); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + rpccli_samr_Close(pipe_cli, ctx, &domain_handle); + + delete_alias: + status = rpccli_samr_DeleteDomAlias(pipe_cli, ctx, + &alias_handle); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + ZERO_STRUCT(alias_handle); + + werr = WERR_OK; + + done: + if (!cli) { + return werr; + } + + if (is_valid_policy_hnd(&alias_handle)) { + rpccli_samr_Close(pipe_cli, ctx, &alias_handle); + } + if (is_valid_policy_hnd(&domain_handle)) { + rpccli_samr_Close(pipe_cli, ctx, &domain_handle); + } + if (is_valid_policy_hnd(&builtin_handle)) { + rpccli_samr_Close(pipe_cli, ctx, &builtin_handle); + } + if (is_valid_policy_hnd(&connect_handle)) { + rpccli_samr_Close(pipe_cli, ctx, &connect_handle); + } + + return werr; } /**************************************************************** @@ -210,5 +345,5 @@ WERROR NetLocalGroupDel_r(struct libnetapi_ctx *ctx, WERROR NetLocalGroupDel_l(struct libnetapi_ctx *ctx, struct NetLocalGroupDel *r) { - return WERR_NOT_SUPPORTED; + return NetLocalGroupDel_r(ctx, r); } -- cgit From 5800a52950ef3bd3509b3b332b9c890323f22a89 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 2 Jun 2008 19:45:23 +0200 Subject: netapi: add NetLocalGroupDel() to public headers. Guenther (This used to be commit efd4a899f5d139b5e3e22660f5fb1c12f59525fc) --- source3/lib/netapi/netapi.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h index d08f1b7f74..28bb7fa68a 100644 --- a/source3/lib/netapi/netapi.h +++ b/source3/lib/netapi/netapi.h @@ -650,4 +650,21 @@ NET_API_STATUS NetLocalGroupAdd(const char * server_name /* [in] */, uint8_t *buf /* [in] [ref] */, uint32_t *parm_err /* [out] [ref] */); +/************************************************************//** + * + * NetLocalGroupDel + * + * @brief Delete Local Group + * + * @param[in] server_name The server name to connect to + * @param[in] group_name The name of the group that is going to be deleted + * @return NET_API_STATUS + * + * example localgroup/localgroup_del.c + ***************************************************************/ + + +NET_API_STATUS NetLocalGroupDel(const char * server_name /* [in] */, + const char * group_name /* [in] */); + #endif -- cgit From 808c70340e49fcfd90b4d141ca87f0b0935803e5 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 2 Jun 2008 19:46:04 +0200 Subject: netapi: add NetLocalGroupDel() example code. Guenther (This used to be commit 6ebd618cc768df142b035362cc648d8bc2c1bc89) --- source3/lib/netapi/examples/Makefile.in | 8 ++- .../netapi/examples/localgroup/localgroup_del.c | 83 ++++++++++++++++++++++ 2 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 source3/lib/netapi/examples/localgroup/localgroup_del.c (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/Makefile.in b/source3/lib/netapi/examples/Makefile.in index e5ab4c13fe..bdc8fcef88 100644 --- a/source3/lib/netapi/examples/Makefile.in +++ b/source3/lib/netapi/examples/Makefile.in @@ -32,7 +32,8 @@ PROGS = bin/getdc@EXEEXT@ \ bin/group_getinfo@EXEEXT@ \ bin/group_adduser@EXEEXT@ \ bin/group_deluser@EXEEXT@ \ - bin/localgroup_add@EXEEXT@ + bin/localgroup_add@EXEEXT@ \ + bin/localgroup_del@EXEEXT@ all: $(PROGS) @@ -77,6 +78,7 @@ GROUPGETINFO_OBJ = group/group_getinfo.o $(CMDLINE_OBJ) GROUPADDUSER_OBJ = group/group_adduser.o $(CMDLINE_OBJ) GROUPDELUSER_OBJ = group/group_deluser.o $(CMDLINE_OBJ) LOCALGROUPADD_OBJ = localgroup/localgroup_add.o $(CMDLINE_OBJ) +LOCALGROUPDEL_OBJ = localgroup/localgroup_del.o $(CMDLINE_OBJ) bin/getdc@EXEEXT@: $(BINARY_PREREQS) $(GETDC_OBJ) @echo Linking $@ @@ -142,6 +144,10 @@ bin/localgroup_add@EXEEXT@: $(BINARY_PREREQS) $(LOCALGROUPADD_OBJ) @echo Linking $@ @$(CC) $(FLAGS) -o $@ $(LOCALGROUPADD_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) +bin/localgroup_del@EXEEXT@: $(BINARY_PREREQS) $(LOCALGROUPDEL_OBJ) + @echo Linking $@ + @$(CC) $(FLAGS) -o $@ $(LOCALGROUPDEL_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) + clean: -rm -f $(PROGS) -rm -f core */*~ *~ \ diff --git a/source3/lib/netapi/examples/localgroup/localgroup_del.c b/source3/lib/netapi/examples/localgroup/localgroup_del.c new file mode 100644 index 0000000000..a2515dfdcd --- /dev/null +++ b/source3/lib/netapi/examples/localgroup/localgroup_del.c @@ -0,0 +1,83 @@ +/* + * Unix SMB/CIFS implementation. + * NetLocalGroupDel query + * Copyright (C) Guenther Deschner 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include +#include +#include +#include +#include + +#include + +#include "common.h" + +int main(int argc, const char **argv) +{ + NET_API_STATUS status; + struct libnetapi_ctx *ctx = NULL; + const char *hostname = NULL; + const char *groupname = NULL; + + poptContext pc; + int opt; + + struct poptOption long_options[] = { + POPT_AUTOHELP + POPT_COMMON_LIBNETAPI_EXAMPLES + POPT_TABLEEND + }; + + status = libnetapi_init(&ctx); + if (status != 0) { + return status; + } + + pc = poptGetContext("localgroup_del", argc, argv, long_options, 0); + + poptSetOtherOptionHelp(pc, "hostname groupname"); + while((opt = poptGetNextOpt(pc)) != -1) { + } + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + hostname = poptGetArg(pc); + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + groupname = poptGetArg(pc); + + /* NetLocalGroupDel */ + + status = NetLocalGroupDel(hostname, + groupname); + if (status != 0) { + printf("NetLocalGroupDel failed with: %s\n", + libnetapi_get_error_string(ctx, status)); + } + + out: + libnetapi_free(ctx); + poptFreeContext(pc); + + return status; +} -- cgit From 45baadb31aee114529b93f959b8a6ecb60b4fab8 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 2 Jun 2008 20:20:27 +0200 Subject: netapi: add NetLocalGroupGetInfo() skeleton. Guenther (This used to be commit f70e37a7fe1915f557e194237a8bb26bcf9635d7) --- source3/lib/netapi/libnetapi.c | 46 +++++++++++++++++++++++++++++++++++++++++ source3/lib/netapi/libnetapi.h | 8 +++++++ source3/lib/netapi/localgroup.c | 20 +++++++++++++++++- 3 files changed, 73 insertions(+), 1 deletion(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/libnetapi.c b/source3/lib/netapi/libnetapi.c index 522d2aa970..dbe26882d2 100644 --- a/source3/lib/netapi/libnetapi.c +++ b/source3/lib/netapi/libnetapi.c @@ -995,3 +995,49 @@ NET_API_STATUS NetLocalGroupDel(const char * server_name /* [in] */, return r.out.result; } +/**************************************************************** + NetLocalGroupGetInfo +****************************************************************/ + +NET_API_STATUS NetLocalGroupGetInfo(const char * server_name /* [in] */, + const char * group_name /* [in] */, + uint32_t level /* [in] */, + uint8_t **buf /* [out] [ref] */) +{ + struct NetLocalGroupGetInfo r; + struct libnetapi_ctx *ctx = NULL; + NET_API_STATUS status; + WERROR werr; + + status = libnetapi_getctx(&ctx); + if (status != 0) { + return status; + } + + /* In parameters */ + r.in.server_name = server_name; + r.in.group_name = group_name; + r.in.level = level; + + /* Out parameters */ + r.out.buf = buf; + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_IN_DEBUG(NetLocalGroupGetInfo, &r); + } + + if (LIBNETAPI_LOCAL_SERVER(server_name)) { + werr = NetLocalGroupGetInfo_l(ctx, &r); + } else { + werr = NetLocalGroupGetInfo_r(ctx, &r); + } + + r.out.result = W_ERROR_V(werr); + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_OUT_DEBUG(NetLocalGroupGetInfo, &r); + } + + return r.out.result; +} + diff --git a/source3/lib/netapi/libnetapi.h b/source3/lib/netapi/libnetapi.h index 2386488b72..3ee8cf3634 100644 --- a/source3/lib/netapi/libnetapi.h +++ b/source3/lib/netapi/libnetapi.h @@ -170,4 +170,12 @@ WERROR NetLocalGroupDel_r(struct libnetapi_ctx *ctx, struct NetLocalGroupDel *r); WERROR NetLocalGroupDel_l(struct libnetapi_ctx *ctx, struct NetLocalGroupDel *r); +NET_API_STATUS NetLocalGroupGetInfo(const char * server_name /* [in] */, + const char * group_name /* [in] */, + uint32_t level /* [in] */, + uint8_t **buf /* [out] [ref] */); +WERROR NetLocalGroupGetInfo_r(struct libnetapi_ctx *ctx, + struct NetLocalGroupGetInfo *r); +WERROR NetLocalGroupGetInfo_l(struct libnetapi_ctx *ctx, + struct NetLocalGroupGetInfo *r); #endif /* __LIBNETAPI_LIBNETAPI__ */ diff --git a/source3/lib/netapi/localgroup.c b/source3/lib/netapi/localgroup.c index fd76e09e8e..09b86c8bd9 100644 --- a/source3/lib/netapi/localgroup.c +++ b/source3/lib/netapi/localgroup.c @@ -341,9 +341,27 @@ WERROR NetLocalGroupDel_r(struct libnetapi_ctx *ctx, /**************************************************************** ****************************************************************/ - WERROR NetLocalGroupDel_l(struct libnetapi_ctx *ctx, struct NetLocalGroupDel *r) { return NetLocalGroupDel_r(ctx, r); } + +/**************************************************************** +****************************************************************/ + + +WERROR NetLocalGroupGetInfo_r(struct libnetapi_ctx *ctx, + struct NetLocalGroupGetInfo *r) +{ + return WERR_NOT_SUPPORTED; +} + +/**************************************************************** +****************************************************************/ + +WERROR NetLocalGroupGetInfo_l(struct libnetapi_ctx *ctx, + struct NetLocalGroupGetInfo *r) +{ + return WERR_NOT_SUPPORTED; +} -- cgit From d8fc64de7604c38de12ea267cb071520db2a7730 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 2 Jun 2008 20:27:49 +0200 Subject: netapi: add NetLocalGroupGetInfo() to public headers. Guenther (This used to be commit 4d40d8b51a5323c36ff78ccfc4d7405ac97dde6b) --- source3/lib/netapi/netapi.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h index 28bb7fa68a..5b7a31f320 100644 --- a/source3/lib/netapi/netapi.h +++ b/source3/lib/netapi/netapi.h @@ -667,4 +667,23 @@ NET_API_STATUS NetLocalGroupAdd(const char * server_name /* [in] */, NET_API_STATUS NetLocalGroupDel(const char * server_name /* [in] */, const char * group_name /* [in] */); +/************************************************************//** + * + * NetLocalGroupGetInfo + * + * @brief Get Local Group Information + * + * @param[in] server_name The server name to connect to + * @param[in] group_name The name of the group that is going to be queried + * @param[in] level The level defining the requested LOCALGROUP_INFO_X structure + * @param[out] buf The buffer containing a LOCALGROUP_INFO_X structure + * @return NET_API_STATUS + * + * example localgroup/localgroup_getinfo.c + ***************************************************************/ + +NET_API_STATUS NetLocalGroupGetInfo(const char * server_name /* [in] */, + const char * group_name /* [in] */, + uint32_t level /* [in] */, + uint8_t **buf /* [out] [ref] */); #endif -- cgit From bfef3bb3c6f8f5f1e552a19b9e6395a7f4adfe68 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 2 Jun 2008 20:28:31 +0200 Subject: netapi: add NetLocalGroupGetInfo() example code. Guenther (This used to be commit 591003b109d936b62cc80827971c201b3ea79e39) --- source3/lib/netapi/examples/Makefile.in | 8 +- .../examples/localgroup/localgroup_getinfo.c | 112 +++++++++++++++++++++ 2 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 source3/lib/netapi/examples/localgroup/localgroup_getinfo.c (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/Makefile.in b/source3/lib/netapi/examples/Makefile.in index bdc8fcef88..f8d735795a 100644 --- a/source3/lib/netapi/examples/Makefile.in +++ b/source3/lib/netapi/examples/Makefile.in @@ -33,7 +33,8 @@ PROGS = bin/getdc@EXEEXT@ \ bin/group_adduser@EXEEXT@ \ bin/group_deluser@EXEEXT@ \ bin/localgroup_add@EXEEXT@ \ - bin/localgroup_del@EXEEXT@ + bin/localgroup_del@EXEEXT@ \ + bin/localgroup_getinfo@EXEEXT@ all: $(PROGS) @@ -79,6 +80,7 @@ GROUPADDUSER_OBJ = group/group_adduser.o $(CMDLINE_OBJ) GROUPDELUSER_OBJ = group/group_deluser.o $(CMDLINE_OBJ) LOCALGROUPADD_OBJ = localgroup/localgroup_add.o $(CMDLINE_OBJ) LOCALGROUPDEL_OBJ = localgroup/localgroup_del.o $(CMDLINE_OBJ) +LOCALGROUPGETINFO_OBJ = localgroup/localgroup_getinfo.o $(CMDLINE_OBJ) bin/getdc@EXEEXT@: $(BINARY_PREREQS) $(GETDC_OBJ) @echo Linking $@ @@ -148,6 +150,10 @@ bin/localgroup_del@EXEEXT@: $(BINARY_PREREQS) $(LOCALGROUPDEL_OBJ) @echo Linking $@ @$(CC) $(FLAGS) -o $@ $(LOCALGROUPDEL_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) +bin/localgroup_getinfo@EXEEXT@: $(BINARY_PREREQS) $(LOCALGROUPGETINFO_OBJ) + @echo Linking $@ + @$(CC) $(FLAGS) -o $@ $(LOCALGROUPGETINFO_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) + clean: -rm -f $(PROGS) -rm -f core */*~ *~ \ diff --git a/source3/lib/netapi/examples/localgroup/localgroup_getinfo.c b/source3/lib/netapi/examples/localgroup/localgroup_getinfo.c new file mode 100644 index 0000000000..cd8fa8c3b3 --- /dev/null +++ b/source3/lib/netapi/examples/localgroup/localgroup_getinfo.c @@ -0,0 +1,112 @@ +/* + * Unix SMB/CIFS implementation. + * NetLocalGroupGetInfo query + * Copyright (C) Guenther Deschner 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include +#include +#include +#include +#include + +#include + +#include "common.h" + +int main(int argc, const char **argv) +{ + NET_API_STATUS status; + struct libnetapi_ctx *ctx = NULL; + const char *hostname = NULL; + const char *groupname = NULL; + uint8_t *buffer = NULL; + uint32_t level = 0; + struct LOCALGROUP_INFO_0 *g0; + struct LOCALGROUP_INFO_1 *g1; + struct LOCALGROUP_INFO_1002 *g1002; + + poptContext pc; + int opt; + + struct poptOption long_options[] = { + POPT_AUTOHELP + POPT_COMMON_LIBNETAPI_EXAMPLES + POPT_TABLEEND + }; + + status = libnetapi_init(&ctx); + if (status != 0) { + return status; + } + + pc = poptGetContext("localgroup_getinfo", argc, argv, long_options, 0); + + poptSetOtherOptionHelp(pc, "hostname groupname level"); + while((opt = poptGetNextOpt(pc)) != -1) { + } + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + hostname = poptGetArg(pc); + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + groupname = poptGetArg(pc); + + if (poptPeekArg(pc)) { + level = atoi(poptGetArg(pc)); + } + + /* NetLocalGroupGetInfo */ + + status = NetLocalGroupGetInfo(hostname, + groupname, + level, + &buffer); + if (status != 0) { + printf("NetLocalGroupGetInfo failed with: %s\n", + libnetapi_get_error_string(ctx, status)); + goto out; + } + + switch (level) { + case 0: + g0 = (struct LOCALGROUP_INFO_0 *)buffer; + printf("name: %s\n", g0->lgrpi0_name); + break; + case 1: + g1 = (struct LOCALGROUP_INFO_1 *)buffer; + printf("name: %s\n", g1->lgrpi1_name); + printf("comment: %s\n", g1->lgrpi1_comment); + break; + case 1002: + g1002 = (struct LOCALGROUP_INFO_1002 *)buffer; + printf("comment: %s\n", g1002->lgrpi1002_comment); + break; + } + NetApiBufferFree(buffer); + + out: + libnetapi_free(ctx); + poptFreeContext(pc); + + return status; +} -- cgit From a3f1e2ee0abea2054c06d3fd0e52db28b10ec30c Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 2 Jun 2008 22:20:14 +0200 Subject: netapi: implement NetLocalGroupGetInfo(). Guenther (This used to be commit d735ee79fa5b9b7ec409ea387e4ff10357e417e7) --- source3/lib/netapi/localgroup.c | 190 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 188 insertions(+), 2 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/localgroup.c b/source3/lib/netapi/localgroup.c index 09b86c8bd9..d05ebd3457 100644 --- a/source3/lib/netapi/localgroup.c +++ b/source3/lib/netapi/localgroup.c @@ -350,11 +350,197 @@ WERROR NetLocalGroupDel_l(struct libnetapi_ctx *ctx, /**************************************************************** ****************************************************************/ +static WERROR map_alias_info_to_buffer(TALLOC_CTX *mem_ctx, + struct samr_AliasInfoAll *info, + uint32_t level, + uint8_t **buffer) +{ + struct LOCALGROUP_INFO_0 g0; + struct LOCALGROUP_INFO_1 g1; + struct LOCALGROUP_INFO_1002 g1002; + + switch (level) { + case 0: + g0.lgrpi0_name = info->name.string; + + *buffer = (uint8_t *)talloc_memdup(mem_ctx, &g0, sizeof(g0)); + + break; + case 1: + g1.lgrpi1_name = info->name.string; + g1.lgrpi1_comment = info->description.string; + + *buffer = (uint8_t *)talloc_memdup(mem_ctx, &g1, sizeof(g1)); + + break; + case 1002: + g1002.lgrpi1002_comment = info->description.string; + + *buffer = (uint8_t *)talloc_memdup(mem_ctx, &g1002, sizeof(g1002)); + + break; + default: + return WERR_UNKNOWN_LEVEL; + } + + W_ERROR_HAVE_NO_MEMORY(*buffer); + + return WERR_OK; +} + +/**************************************************************** +****************************************************************/ WERROR NetLocalGroupGetInfo_r(struct libnetapi_ctx *ctx, struct NetLocalGroupGetInfo *r) { - return WERR_NOT_SUPPORTED; + struct cli_state *cli = NULL; + struct rpc_pipe_client *pipe_cli = NULL; + NTSTATUS status; + WERROR werr; + struct lsa_String lsa_account_name; + struct policy_handle connect_handle, domain_handle, builtin_handle, alias_handle; + struct samr_Ids user_rids, name_types; + struct dom_sid2 *domain_sid = NULL; + union samr_AliasInfo *alias_info = NULL; + + if (!r->in.group_name) { + return WERR_INVALID_PARAM; + } + + switch (r->in.level) { + case 0: + case 1: + case 1002: + break; + default: + return WERR_UNKNOWN_LEVEL; + } + + ZERO_STRUCT(connect_handle); + ZERO_STRUCT(builtin_handle); + ZERO_STRUCT(domain_handle); + ZERO_STRUCT(alias_handle); + + werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + werr = libnetapi_open_pipe(ctx, cli, PI_SAMR, &pipe_cli); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + status = rpccli_try_samr_connects(pipe_cli, ctx, + SAMR_ACCESS_OPEN_DOMAIN | + SAMR_ACCESS_ENUM_DOMAINS, + &connect_handle); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + status = rpccli_samr_OpenDomain(pipe_cli, ctx, + &connect_handle, + SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, + CONST_DISCARD(DOM_SID *, &global_sid_Builtin), + &builtin_handle); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + init_lsa_String(&lsa_account_name, r->in.group_name); + + status = rpccli_samr_LookupNames(pipe_cli, ctx, + &builtin_handle, + 1, + &lsa_account_name, + &user_rids, + &name_types); + if (NT_STATUS_IS_OK(status)) { + status = rpccli_samr_OpenAlias(pipe_cli, ctx, + &builtin_handle, + SAMR_ALIAS_ACCESS_LOOKUP_INFO, + user_rids.ids[0], + &alias_handle); + if (NT_STATUS_IS_OK(status)) { + rpccli_samr_Close(pipe_cli, ctx, &builtin_handle); + goto query_alias; + } + } + + rpccli_samr_Close(pipe_cli, ctx, &builtin_handle); + + status = libnetapi_samr_open_domain(ctx, pipe_cli, + SAMR_ACCESS_ENUM_DOMAINS | + SAMR_ACCESS_OPEN_DOMAIN, + SAMR_DOMAIN_ACCESS_CREATE_ALIAS | + SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, + &connect_handle, + &domain_handle, + &domain_sid); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + status = rpccli_samr_LookupNames(pipe_cli, ctx, + &domain_handle, + 1, + &lsa_account_name, + &user_rids, + &name_types); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + status = rpccli_samr_OpenAlias(pipe_cli, ctx, + &domain_handle, + SAMR_ALIAS_ACCESS_LOOKUP_INFO, + user_rids.ids[0], + &alias_handle); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + rpccli_samr_Close(pipe_cli, ctx, &domain_handle); + + query_alias: + status = rpccli_samr_QueryAliasInfo(pipe_cli, ctx, + &alias_handle, + ALIASINFOALL, + &alias_info); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + werr = map_alias_info_to_buffer(ctx, &alias_info->all, + r->in.level, r->out.buf); + + done: + if (!cli) { + return werr; + } + + if (is_valid_policy_hnd(&alias_handle)) { + rpccli_samr_Close(pipe_cli, ctx, &alias_handle); + } + if (is_valid_policy_hnd(&domain_handle)) { + rpccli_samr_Close(pipe_cli, ctx, &domain_handle); + } + if (is_valid_policy_hnd(&builtin_handle)) { + rpccli_samr_Close(pipe_cli, ctx, &builtin_handle); + } + if (is_valid_policy_hnd(&connect_handle)) { + rpccli_samr_Close(pipe_cli, ctx, &connect_handle); + } + + return werr; } /**************************************************************** @@ -363,5 +549,5 @@ WERROR NetLocalGroupGetInfo_r(struct libnetapi_ctx *ctx, WERROR NetLocalGroupGetInfo_l(struct libnetapi_ctx *ctx, struct NetLocalGroupGetInfo *r) { - return WERR_NOT_SUPPORTED; + return NetLocalGroupGetInfo_r(ctx, r); } -- cgit From bf225fc8e0d9160527fcf1cce5896c300a594f1e Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 2 Jun 2008 22:29:32 +0200 Subject: netapi: add NetLocalGroupSetInfo() skeleton. Guenther (This used to be commit 325f419636a69c40ee25c068787866384ef52279) --- source3/lib/netapi/libnetapi.c | 48 +++++++++++++++++++++++++++++++++++++++++ source3/lib/netapi/libnetapi.h | 9 ++++++++ source3/lib/netapi/localgroup.c | 20 +++++++++++++++++ 3 files changed, 77 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/libnetapi.c b/source3/lib/netapi/libnetapi.c index dbe26882d2..097086f12f 100644 --- a/source3/lib/netapi/libnetapi.c +++ b/source3/lib/netapi/libnetapi.c @@ -1041,3 +1041,51 @@ NET_API_STATUS NetLocalGroupGetInfo(const char * server_name /* [in] */, return r.out.result; } +/**************************************************************** + NetLocalGroupSetInfo +****************************************************************/ + +NET_API_STATUS NetLocalGroupSetInfo(const char * server_name /* [in] */, + const char * group_name /* [in] */, + uint32_t level /* [in] */, + uint8_t *buf /* [in] [ref] */, + uint32_t *parm_err /* [out] [ref] */) +{ + struct NetLocalGroupSetInfo r; + struct libnetapi_ctx *ctx = NULL; + NET_API_STATUS status; + WERROR werr; + + status = libnetapi_getctx(&ctx); + if (status != 0) { + return status; + } + + /* In parameters */ + r.in.server_name = server_name; + r.in.group_name = group_name; + r.in.level = level; + r.in.buf = buf; + + /* Out parameters */ + r.out.parm_err = parm_err; + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_IN_DEBUG(NetLocalGroupSetInfo, &r); + } + + if (LIBNETAPI_LOCAL_SERVER(server_name)) { + werr = NetLocalGroupSetInfo_l(ctx, &r); + } else { + werr = NetLocalGroupSetInfo_r(ctx, &r); + } + + r.out.result = W_ERROR_V(werr); + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_OUT_DEBUG(NetLocalGroupSetInfo, &r); + } + + return r.out.result; +} + diff --git a/source3/lib/netapi/libnetapi.h b/source3/lib/netapi/libnetapi.h index 3ee8cf3634..911be7420b 100644 --- a/source3/lib/netapi/libnetapi.h +++ b/source3/lib/netapi/libnetapi.h @@ -178,4 +178,13 @@ WERROR NetLocalGroupGetInfo_r(struct libnetapi_ctx *ctx, struct NetLocalGroupGetInfo *r); WERROR NetLocalGroupGetInfo_l(struct libnetapi_ctx *ctx, struct NetLocalGroupGetInfo *r); +NET_API_STATUS NetLocalGroupSetInfo(const char * server_name /* [in] */, + const char * group_name /* [in] */, + uint32_t level /* [in] */, + uint8_t *buf /* [in] [ref] */, + uint32_t *parm_err /* [out] [ref] */); +WERROR NetLocalGroupSetInfo_r(struct libnetapi_ctx *ctx, + struct NetLocalGroupSetInfo *r); +WERROR NetLocalGroupSetInfo_l(struct libnetapi_ctx *ctx, + struct NetLocalGroupSetInfo *r); #endif /* __LIBNETAPI_LIBNETAPI__ */ diff --git a/source3/lib/netapi/localgroup.c b/source3/lib/netapi/localgroup.c index d05ebd3457..7f7aa9a2b1 100644 --- a/source3/lib/netapi/localgroup.c +++ b/source3/lib/netapi/localgroup.c @@ -551,3 +551,23 @@ WERROR NetLocalGroupGetInfo_l(struct libnetapi_ctx *ctx, { return NetLocalGroupGetInfo_r(ctx, r); } + +/**************************************************************** +****************************************************************/ + +WERROR NetLocalGroupSetInfo_r(struct libnetapi_ctx *ctx, + struct NetLocalGroupSetInfo *r) +{ + return WERR_NOT_SUPPORTED; +} + +/**************************************************************** +****************************************************************/ + +WERROR NetLocalGroupSetInfo_l(struct libnetapi_ctx *ctx, + struct NetLocalGroupSetInfo *r) +{ + return WERR_NOT_SUPPORTED; +} + + -- cgit From 0ae3f8b926e242e521949c0aa853cc0feba76fce Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 2 Jun 2008 22:37:03 +0200 Subject: netapi: add NetLocalGroupSetInfo() example code. Guenther (This used to be commit abd3f701340a31d9c3779cfe37c639f9105dfdb3) --- source3/lib/netapi/examples/Makefile.in | 8 +- .../examples/localgroup/localgroup_setinfo.c | 128 +++++++++++++++++++++ 2 files changed, 135 insertions(+), 1 deletion(-) create mode 100644 source3/lib/netapi/examples/localgroup/localgroup_setinfo.c (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/Makefile.in b/source3/lib/netapi/examples/Makefile.in index f8d735795a..13a682ff6d 100644 --- a/source3/lib/netapi/examples/Makefile.in +++ b/source3/lib/netapi/examples/Makefile.in @@ -34,7 +34,8 @@ PROGS = bin/getdc@EXEEXT@ \ bin/group_deluser@EXEEXT@ \ bin/localgroup_add@EXEEXT@ \ bin/localgroup_del@EXEEXT@ \ - bin/localgroup_getinfo@EXEEXT@ + bin/localgroup_getinfo@EXEEXT@ \ + bin/localgroup_setinfo@EXEEXT@ all: $(PROGS) @@ -81,6 +82,7 @@ GROUPDELUSER_OBJ = group/group_deluser.o $(CMDLINE_OBJ) LOCALGROUPADD_OBJ = localgroup/localgroup_add.o $(CMDLINE_OBJ) LOCALGROUPDEL_OBJ = localgroup/localgroup_del.o $(CMDLINE_OBJ) LOCALGROUPGETINFO_OBJ = localgroup/localgroup_getinfo.o $(CMDLINE_OBJ) +LOCALGROUPSETINFO_OBJ = localgroup/localgroup_setinfo.o $(CMDLINE_OBJ) bin/getdc@EXEEXT@: $(BINARY_PREREQS) $(GETDC_OBJ) @echo Linking $@ @@ -154,6 +156,10 @@ bin/localgroup_getinfo@EXEEXT@: $(BINARY_PREREQS) $(LOCALGROUPGETINFO_OBJ) @echo Linking $@ @$(CC) $(FLAGS) -o $@ $(LOCALGROUPGETINFO_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) +bin/localgroup_setinfo@EXEEXT@: $(BINARY_PREREQS) $(LOCALGROUPSETINFO_OBJ) + @echo Linking $@ + @$(CC) $(FLAGS) -o $@ $(LOCALGROUPSETINFO_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) + clean: -rm -f $(PROGS) -rm -f core */*~ *~ \ diff --git a/source3/lib/netapi/examples/localgroup/localgroup_setinfo.c b/source3/lib/netapi/examples/localgroup/localgroup_setinfo.c new file mode 100644 index 0000000000..efcec76786 --- /dev/null +++ b/source3/lib/netapi/examples/localgroup/localgroup_setinfo.c @@ -0,0 +1,128 @@ +/* + * Unix SMB/CIFS implementation. + * NetLocalGroupSetInfo query + * Copyright (C) Guenther Deschner 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include +#include +#include +#include +#include + +#include + +#include "common.h" + +int main(int argc, const char **argv) +{ + NET_API_STATUS status; + struct libnetapi_ctx *ctx = NULL; + const char *hostname = NULL; + const char *groupname = NULL; + uint8_t *buffer = NULL; + uint32_t level = 0; + struct LOCALGROUP_INFO_0 g0; + struct LOCALGROUP_INFO_1 g1; + struct LOCALGROUP_INFO_1002 g1002; + const char *newname = NULL; + const char *newcomment = NULL; + uint32_t parm_err = 0; + + poptContext pc; + int opt; + + struct poptOption long_options[] = { + POPT_AUTOHELP + POPT_COMMON_LIBNETAPI_EXAMPLES + { "newname", 0, POPT_ARG_STRING, NULL, 'n', "New Local Group Name", "NEWNAME" }, + { "newcomment", 0, POPT_ARG_STRING, NULL, 'c', "New Local Group Comment", "NETCOMMENT" }, + POPT_TABLEEND + }; + + status = libnetapi_init(&ctx); + if (status != 0) { + return status; + } + + pc = poptGetContext("localgroup_setinfo", argc, argv, long_options, 0); + + poptSetOtherOptionHelp(pc, "hostname groupname level"); + while((opt = poptGetNextOpt(pc)) != -1) { + switch (opt) { + case 'n': + newname = poptGetOptArg(pc); + break; + case 'c': + newcomment = poptGetOptArg(pc); + break; + } + + } + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + hostname = poptGetArg(pc); + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + groupname = poptGetArg(pc); + + if (poptPeekArg(pc)) { + level = atoi(poptGetArg(pc)); + } + + if (newname && !newcomment) { + g0.lgrpi0_name = newname; + buffer = (uint8_t *)&g0; + level = 0; + } else if (newcomment && !newname) { + g1002.lgrpi1002_comment = newcomment; + buffer = (uint8_t *)&g1002; + level = 1002; + } else if (newname && newcomment) { + g1.lgrpi1_name = newname; + g1.lgrpi1_comment = newcomment; + buffer = (uint8_t *)&g1; + level = 1; + } else { + printf("not enough input\n"); + goto out; + } + + /* NetLocalGroupSetInfo */ + + status = NetLocalGroupSetInfo(hostname, + groupname, + level, + buffer, + &parm_err); + if (status != 0) { + printf("NetLocalGroupSetInfo failed with: %s\n", + libnetapi_get_error_string(ctx, status)); + goto out; + } + + out: + libnetapi_free(ctx); + poptFreeContext(pc); + + return status; +} -- cgit From 1ecf67a18cd33f5f9f80fb3b8b97fcb43836a13a Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 2 Jun 2008 23:36:25 +0200 Subject: netapi: Implement NetLocalGroupSetInfo(). Guenther (This used to be commit f991b4d58ed660e648f29c3f25195072f91643ba) --- source3/lib/netapi/localgroup.c | 199 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 195 insertions(+), 4 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/localgroup.c b/source3/lib/netapi/localgroup.c index 7f7aa9a2b1..24b1c0cbbf 100644 --- a/source3/lib/netapi/localgroup.c +++ b/source3/lib/netapi/localgroup.c @@ -555,10 +555,203 @@ WERROR NetLocalGroupGetInfo_l(struct libnetapi_ctx *ctx, /**************************************************************** ****************************************************************/ +static WERROR map_buffer_to_alias_info(TALLOC_CTX *mem_ctx, + uint32_t level, + uint8_t *buffer, + enum samr_AliasInfoEnum *alias_level, + union samr_AliasInfo **alias_info) +{ + struct LOCALGROUP_INFO_0 *info0; + struct LOCALGROUP_INFO_1 *info1; + struct LOCALGROUP_INFO_1002 *info1002; + union samr_AliasInfo *info = NULL; + + info = TALLOC_ZERO_P(mem_ctx, union samr_AliasInfo); + W_ERROR_HAVE_NO_MEMORY(info); + + switch (level) { + case 0: + info0 = (struct LOCALGROUP_INFO_0 *)buffer; + init_lsa_String(&info->name, info0->lgrpi0_name); + *alias_level = ALIASINFONAME; + break; + case 1: + info1 = (struct LOCALGROUP_INFO_1 *)buffer; + /* group name will be ignored */ + init_lsa_String(&info->description, info1->lgrpi1_comment); + *alias_level = ALIASINFODESCRIPTION; + break; + case 1002: + info1002 = (struct LOCALGROUP_INFO_1002 *)buffer; + init_lsa_String(&info->description, info1002->lgrpi1002_comment); + *alias_level = ALIASINFODESCRIPTION; + break; + } + + *alias_info = info; + + return WERR_OK; +} + +/**************************************************************** +****************************************************************/ + WERROR NetLocalGroupSetInfo_r(struct libnetapi_ctx *ctx, struct NetLocalGroupSetInfo *r) { - return WERR_NOT_SUPPORTED; + struct cli_state *cli = NULL; + struct rpc_pipe_client *pipe_cli = NULL; + NTSTATUS status; + WERROR werr; + struct lsa_String lsa_account_name; + struct policy_handle connect_handle, domain_handle, builtin_handle, alias_handle; + struct samr_Ids user_rids, name_types; + struct dom_sid2 *domain_sid = NULL; + enum samr_AliasInfoEnum alias_level; + union samr_AliasInfo *alias_info = NULL; + + if (!r->in.group_name) { + return WERR_INVALID_PARAM; + } + + switch (r->in.level) { + case 0: + case 1: + case 1002: + break; + default: + return WERR_UNKNOWN_LEVEL; + } + + ZERO_STRUCT(connect_handle); + ZERO_STRUCT(builtin_handle); + ZERO_STRUCT(domain_handle); + ZERO_STRUCT(alias_handle); + + werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + werr = libnetapi_open_pipe(ctx, cli, PI_SAMR, &pipe_cli); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + status = rpccli_try_samr_connects(pipe_cli, ctx, + SAMR_ACCESS_OPEN_DOMAIN | + SAMR_ACCESS_ENUM_DOMAINS, + &connect_handle); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + status = rpccli_samr_OpenDomain(pipe_cli, ctx, + &connect_handle, + SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, + CONST_DISCARD(DOM_SID *, &global_sid_Builtin), + &builtin_handle); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + init_lsa_String(&lsa_account_name, r->in.group_name); + + status = rpccli_samr_LookupNames(pipe_cli, ctx, + &builtin_handle, + 1, + &lsa_account_name, + &user_rids, + &name_types); + if (NT_STATUS_IS_OK(status)) { + status = rpccli_samr_OpenAlias(pipe_cli, ctx, + &builtin_handle, + SAMR_ALIAS_ACCESS_SET_INFO, + user_rids.ids[0], + &alias_handle); + if (NT_STATUS_IS_OK(status)) { + rpccli_samr_Close(pipe_cli, ctx, &builtin_handle); + goto set_alias; + } + } + + rpccli_samr_Close(pipe_cli, ctx, &builtin_handle); + + status = libnetapi_samr_open_domain(ctx, pipe_cli, + SAMR_ACCESS_ENUM_DOMAINS | + SAMR_ACCESS_OPEN_DOMAIN, + SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, + &connect_handle, + &domain_handle, + &domain_sid); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + status = rpccli_samr_LookupNames(pipe_cli, ctx, + &domain_handle, + 1, + &lsa_account_name, + &user_rids, + &name_types); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + status = rpccli_samr_OpenAlias(pipe_cli, ctx, + &domain_handle, + SAMR_ALIAS_ACCESS_SET_INFO, + user_rids.ids[0], + &alias_handle); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + rpccli_samr_Close(pipe_cli, ctx, &domain_handle); + + set_alias: + + werr = map_buffer_to_alias_info(ctx, r->in.level, r->in.buf, + &alias_level, &alias_info); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + status = rpccli_samr_SetAliasInfo(pipe_cli, ctx, + &alias_handle, + alias_level, + alias_info); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + werr = WERR_OK; + + done: + if (!cli) { + return werr; + } + + if (is_valid_policy_hnd(&alias_handle)) { + rpccli_samr_Close(pipe_cli, ctx, &alias_handle); + } + if (is_valid_policy_hnd(&domain_handle)) { + rpccli_samr_Close(pipe_cli, ctx, &domain_handle); + } + if (is_valid_policy_hnd(&builtin_handle)) { + rpccli_samr_Close(pipe_cli, ctx, &builtin_handle); + } + if (is_valid_policy_hnd(&connect_handle)) { + rpccli_samr_Close(pipe_cli, ctx, &connect_handle); + } + + return werr; } /**************************************************************** @@ -567,7 +760,5 @@ WERROR NetLocalGroupSetInfo_r(struct libnetapi_ctx *ctx, WERROR NetLocalGroupSetInfo_l(struct libnetapi_ctx *ctx, struct NetLocalGroupSetInfo *r) { - return WERR_NOT_SUPPORTED; + return NetLocalGroupSetInfo_r(ctx, r); } - - -- cgit From e46506866ae6c55aba6f65cff3f1889fea5227f4 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 2 Jun 2008 23:37:42 +0200 Subject: netapi: add public header for NetLocalGroupSetInfo(). Guenther (This used to be commit cb20271012e7713a28c302e199b676bdb821e5e4) --- source3/lib/netapi/netapi.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h index 5b7a31f320..d80e78ebbf 100644 --- a/source3/lib/netapi/netapi.h +++ b/source3/lib/netapi/netapi.h @@ -686,4 +686,28 @@ NET_API_STATUS NetLocalGroupGetInfo(const char * server_name /* [in] */, const char * group_name /* [in] */, uint32_t level /* [in] */, uint8_t **buf /* [out] [ref] */); + +/************************************************************//** + * + * NetLocalGroupSetInfo + * + * @brief Set Local Group Information + * + * @param[in] server_name The server name to connect to + * @param[in] group_name The name of the group that is going to be modified + * @param[in] level The level defining the requested LOCALGROUP_INFO_X structure + * @param[in] buf The buffer containing a LOCALGROUP_INFO_X structure + * @param[out] parm_err The returned parameter error number if any + * @return NET_API_STATUS + * + * example localgroup/localgroup_setinfo.c + ***************************************************************/ + + +NET_API_STATUS NetLocalGroupSetInfo(const char * server_name /* [in] */, + const char * group_name /* [in] */, + uint32_t level /* [in] */, + uint8_t *buf /* [in] [ref] */, + uint32_t *parm_err /* [out] [ref] */); + #endif -- cgit From b652e5b4753afd8916d347d5c8ef6f54ca140097 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 2 Jun 2008 23:55:45 +0200 Subject: netapi: let libnetapi_samr_open_domain return WERROR. Guenther (This used to be commit 3d037a07e015a3af75dde054cef4c0bb7795fbb5) --- source3/lib/netapi/group.c | 104 +++++++++++++++++------------------- source3/lib/netapi/localgroup.c | 75 ++++++++++++-------------- source3/lib/netapi/netapi_private.h | 14 ++--- source3/lib/netapi/samr.c | 25 +++++---- source3/lib/netapi/user.c | 80 +++++++++++++-------------- 5 files changed, 145 insertions(+), 153 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/group.c b/source3/lib/netapi/group.c index 7f905f0185..f56c92175b 100644 --- a/source3/lib/netapi/group.c +++ b/source3/lib/netapi/group.c @@ -81,16 +81,15 @@ WERROR NetGroupAdd_r(struct libnetapi_ctx *ctx, goto done; } - status = libnetapi_samr_open_domain(ctx, pipe_cli, - SAMR_ACCESS_ENUM_DOMAINS | - SAMR_ACCESS_OPEN_DOMAIN, - SAMR_DOMAIN_ACCESS_CREATE_GROUP | - SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, - &connect_handle, - &domain_handle, - &domain_sid); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); + werr = libnetapi_samr_open_domain(ctx, pipe_cli, + SAMR_ACCESS_ENUM_DOMAINS | + SAMR_ACCESS_OPEN_DOMAIN, + SAMR_DOMAIN_ACCESS_CREATE_GROUP | + SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, + &connect_handle, + &domain_handle, + &domain_sid); + if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -262,15 +261,14 @@ WERROR NetGroupDel_r(struct libnetapi_ctx *ctx, goto done; } - status = libnetapi_samr_open_domain(ctx, pipe_cli, - SAMR_ACCESS_ENUM_DOMAINS | - SAMR_ACCESS_OPEN_DOMAIN, - SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, - &connect_handle, - &domain_handle, - &domain_sid); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); + werr = libnetapi_samr_open_domain(ctx, pipe_cli, + SAMR_ACCESS_ENUM_DOMAINS | + SAMR_ACCESS_OPEN_DOMAIN, + SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, + &connect_handle, + &domain_handle, + &domain_sid); + if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -435,15 +433,14 @@ WERROR NetGroupSetInfo_r(struct libnetapi_ctx *ctx, goto done; } - status = libnetapi_samr_open_domain(ctx, pipe_cli, - SAMR_ACCESS_ENUM_DOMAINS | - SAMR_ACCESS_OPEN_DOMAIN, - SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, - &connect_handle, - &domain_handle, - &domain_sid); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); + werr = libnetapi_samr_open_domain(ctx, pipe_cli, + SAMR_ACCESS_ENUM_DOMAINS | + SAMR_ACCESS_OPEN_DOMAIN, + SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, + &connect_handle, + &domain_handle, + &domain_sid); + if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -677,15 +674,14 @@ WERROR NetGroupGetInfo_r(struct libnetapi_ctx *ctx, goto done; } - status = libnetapi_samr_open_domain(ctx, pipe_cli, - SAMR_ACCESS_ENUM_DOMAINS | - SAMR_ACCESS_OPEN_DOMAIN, - SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, - &connect_handle, - &domain_handle, - &domain_sid); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); + werr = libnetapi_samr_open_domain(ctx, pipe_cli, + SAMR_ACCESS_ENUM_DOMAINS | + SAMR_ACCESS_OPEN_DOMAIN, + SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, + &connect_handle, + &domain_handle, + &domain_sid); + if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -794,15 +790,14 @@ WERROR NetGroupAddUser_r(struct libnetapi_ctx *ctx, goto done; } - status = libnetapi_samr_open_domain(ctx, pipe_cli, - SAMR_ACCESS_ENUM_DOMAINS | - SAMR_ACCESS_OPEN_DOMAIN, - SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, - &connect_handle, - &domain_handle, - &domain_sid); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); + werr = libnetapi_samr_open_domain(ctx, pipe_cli, + SAMR_ACCESS_ENUM_DOMAINS | + SAMR_ACCESS_OPEN_DOMAIN, + SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, + &connect_handle, + &domain_handle, + &domain_sid); + if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -925,15 +920,14 @@ WERROR NetGroupDelUser_r(struct libnetapi_ctx *ctx, goto done; } - status = libnetapi_samr_open_domain(ctx, pipe_cli, - SAMR_ACCESS_ENUM_DOMAINS | - SAMR_ACCESS_OPEN_DOMAIN, - SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, - &connect_handle, - &domain_handle, - &domain_sid); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); + werr = libnetapi_samr_open_domain(ctx, pipe_cli, + SAMR_ACCESS_ENUM_DOMAINS | + SAMR_ACCESS_OPEN_DOMAIN, + SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, + &connect_handle, + &domain_handle, + &domain_sid); + if (!W_ERROR_IS_OK(werr)) { goto done; } diff --git a/source3/lib/netapi/localgroup.c b/source3/lib/netapi/localgroup.c index 24b1c0cbbf..77d7498371 100644 --- a/source3/lib/netapi/localgroup.c +++ b/source3/lib/netapi/localgroup.c @@ -115,21 +115,19 @@ WERROR NetLocalGroupAdd_r(struct libnetapi_ctx *ctx, werr = WERR_ALIAS_EXISTS; goto done; } - } rpccli_samr_Close(pipe_cli, ctx, &builtin_handle); - status = libnetapi_samr_open_domain(ctx, pipe_cli, - SAMR_ACCESS_ENUM_DOMAINS | - SAMR_ACCESS_OPEN_DOMAIN, - SAMR_DOMAIN_ACCESS_CREATE_ALIAS | - SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, - &connect_handle, - &domain_handle, - &domain_sid); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); + werr = libnetapi_samr_open_domain(ctx, pipe_cli, + SAMR_ACCESS_ENUM_DOMAINS | + SAMR_ACCESS_OPEN_DOMAIN, + SAMR_DOMAIN_ACCESS_CREATE_ALIAS | + SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, + &connect_handle, + &domain_handle, + &domain_sid); + if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -269,16 +267,15 @@ WERROR NetLocalGroupDel_r(struct libnetapi_ctx *ctx, rpccli_samr_Close(pipe_cli, ctx, &builtin_handle); - status = libnetapi_samr_open_domain(ctx, pipe_cli, - SAMR_ACCESS_ENUM_DOMAINS | - SAMR_ACCESS_OPEN_DOMAIN, - SAMR_DOMAIN_ACCESS_CREATE_ALIAS | - SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, - &connect_handle, - &domain_handle, - &domain_sid); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); + werr = libnetapi_samr_open_domain(ctx, pipe_cli, + SAMR_ACCESS_ENUM_DOMAINS | + SAMR_ACCESS_OPEN_DOMAIN, + SAMR_DOMAIN_ACCESS_CREATE_ALIAS | + SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, + &connect_handle, + &domain_handle, + &domain_sid); + if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -473,16 +470,15 @@ WERROR NetLocalGroupGetInfo_r(struct libnetapi_ctx *ctx, rpccli_samr_Close(pipe_cli, ctx, &builtin_handle); - status = libnetapi_samr_open_domain(ctx, pipe_cli, - SAMR_ACCESS_ENUM_DOMAINS | - SAMR_ACCESS_OPEN_DOMAIN, - SAMR_DOMAIN_ACCESS_CREATE_ALIAS | - SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, - &connect_handle, - &domain_handle, - &domain_sid); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); + werr = libnetapi_samr_open_domain(ctx, pipe_cli, + SAMR_ACCESS_ENUM_DOMAINS | + SAMR_ACCESS_OPEN_DOMAIN, + SAMR_DOMAIN_ACCESS_CREATE_ALIAS | + SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, + &connect_handle, + &domain_handle, + &domain_sid); + if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -679,15 +675,14 @@ WERROR NetLocalGroupSetInfo_r(struct libnetapi_ctx *ctx, rpccli_samr_Close(pipe_cli, ctx, &builtin_handle); - status = libnetapi_samr_open_domain(ctx, pipe_cli, - SAMR_ACCESS_ENUM_DOMAINS | - SAMR_ACCESS_OPEN_DOMAIN, - SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, - &connect_handle, - &domain_handle, - &domain_sid); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); + werr = libnetapi_samr_open_domain(ctx, pipe_cli, + SAMR_ACCESS_ENUM_DOMAINS | + SAMR_ACCESS_OPEN_DOMAIN, + SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, + &connect_handle, + &domain_handle, + &domain_sid); + if (!W_ERROR_IS_OK(werr)) { goto done; } diff --git a/source3/lib/netapi/netapi_private.h b/source3/lib/netapi/netapi_private.h index c788222ad3..69e68ab733 100644 --- a/source3/lib/netapi/netapi_private.h +++ b/source3/lib/netapi/netapi_private.h @@ -33,11 +33,11 @@ WERROR libnetapi_open_pipe(struct libnetapi_ctx *ctx, struct cli_state *cli, int pipe_idx, struct rpc_pipe_client **pipe_cli); -NTSTATUS libnetapi_samr_open_domain(TALLOC_CTX *mem_ctx, - struct rpc_pipe_client *pipe_cli, - uint32_t connect_mask, - uint32_t domain_mask, - struct policy_handle *connect_handle, - struct policy_handle *domain_handle, - struct dom_sid2 **domain_sid); +WERROR libnetapi_samr_open_domain(TALLOC_CTX *mem_ctx, + struct rpc_pipe_client *pipe_cli, + uint32_t connect_mask, + uint32_t domain_mask, + struct policy_handle *connect_handle, + struct policy_handle *domain_handle, + struct dom_sid2 **domain_sid); #endif diff --git a/source3/lib/netapi/samr.c b/source3/lib/netapi/samr.c index 8e1c409ed9..a41de91de3 100644 --- a/source3/lib/netapi/samr.c +++ b/source3/lib/netapi/samr.c @@ -27,15 +27,16 @@ /**************************************************************** ****************************************************************/ -NTSTATUS libnetapi_samr_open_domain(TALLOC_CTX *mem_ctx, - struct rpc_pipe_client *pipe_cli, - uint32_t connect_mask, - uint32_t domain_mask, - struct policy_handle *connect_handle, - struct policy_handle *domain_handle, - struct dom_sid2 **domain_sid) +WERROR libnetapi_samr_open_domain(TALLOC_CTX *mem_ctx, + struct rpc_pipe_client *pipe_cli, + uint32_t connect_mask, + uint32_t domain_mask, + struct policy_handle *connect_handle, + struct policy_handle *domain_handle, + struct dom_sid2 **domain_sid) { NTSTATUS status; + WERROR werr; uint32_t resume_handle = 0; uint32_t num_entries = 0; struct samr_SamArray *sam = NULL; @@ -49,6 +50,7 @@ NTSTATUS libnetapi_samr_open_domain(TALLOC_CTX *mem_ctx, connect_mask, connect_handle); if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); goto done; } } @@ -60,6 +62,7 @@ NTSTATUS libnetapi_samr_open_domain(TALLOC_CTX *mem_ctx, 0xffffffff, &num_entries); if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); goto done; } @@ -76,7 +79,7 @@ NTSTATUS libnetapi_samr_open_domain(TALLOC_CTX *mem_ctx, } if (!domain_found) { - status = NT_STATUS_NO_SUCH_DOMAIN; + werr = WERR_NO_SUCH_DOMAIN; goto done; } @@ -87,6 +90,7 @@ NTSTATUS libnetapi_samr_open_domain(TALLOC_CTX *mem_ctx, &lsa_domain_name, domain_sid); if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); goto done; } @@ -96,9 +100,12 @@ NTSTATUS libnetapi_samr_open_domain(TALLOC_CTX *mem_ctx, *domain_sid, domain_handle); if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); goto done; } + werr = WERR_OK; + done: - return status; + return werr; } diff --git a/source3/lib/netapi/user.c b/source3/lib/netapi/user.c index de4f9164ce..f053732ac9 100644 --- a/source3/lib/netapi/user.c +++ b/source3/lib/netapi/user.c @@ -175,17 +175,16 @@ WERROR NetUserAdd_r(struct libnetapi_ctx *ctx, goto done; } - status = libnetapi_samr_open_domain(ctx, pipe_cli, - SAMR_ACCESS_ENUM_DOMAINS | - SAMR_ACCESS_OPEN_DOMAIN, - SAMR_DOMAIN_ACCESS_LOOKUP_INFO_1 | - SAMR_DOMAIN_ACCESS_CREATE_USER | - SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, - &connect_handle, - &domain_handle, - &domain_sid); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); + werr = libnetapi_samr_open_domain(ctx, pipe_cli, + SAMR_ACCESS_ENUM_DOMAINS | + SAMR_ACCESS_OPEN_DOMAIN, + SAMR_DOMAIN_ACCESS_LOOKUP_INFO_1 | + SAMR_DOMAIN_ACCESS_CREATE_USER | + SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, + &connect_handle, + &domain_handle, + &domain_sid); + if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -325,15 +324,14 @@ WERROR NetUserDel_r(struct libnetapi_ctx *ctx, goto done; } - status = libnetapi_samr_open_domain(ctx, pipe_cli, - SAMR_ACCESS_ENUM_DOMAINS | - SAMR_ACCESS_OPEN_DOMAIN, - SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, - &connect_handle, - &domain_handle, - &domain_sid); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); + werr = libnetapi_samr_open_domain(ctx, pipe_cli, + SAMR_ACCESS_ENUM_DOMAINS | + SAMR_ACCESS_OPEN_DOMAIN, + SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, + &connect_handle, + &domain_handle, + &domain_sid); + if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -501,17 +499,16 @@ WERROR NetUserEnum_r(struct libnetapi_ctx *ctx, goto done; } - status = libnetapi_samr_open_domain(ctx, pipe_cli, - SAMR_ACCESS_ENUM_DOMAINS | - SAMR_ACCESS_OPEN_DOMAIN, - SAMR_DOMAIN_ACCESS_LOOKUP_INFO_2 | - SAMR_DOMAIN_ACCESS_ENUM_ACCOUNTS | - SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, - &connect_handle, - &domain_handle, - &domain_sid); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); + werr = libnetapi_samr_open_domain(ctx, pipe_cli, + SAMR_ACCESS_ENUM_DOMAINS | + SAMR_ACCESS_OPEN_DOMAIN, + SAMR_DOMAIN_ACCESS_LOOKUP_INFO_2 | + SAMR_DOMAIN_ACCESS_ENUM_ACCOUNTS | + SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, + &connect_handle, + &domain_handle, + &domain_sid); + if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -758,17 +755,16 @@ WERROR NetQueryDisplayInformation_r(struct libnetapi_ctx *ctx, goto done; } - status = libnetapi_samr_open_domain(ctx, pipe_cli, - SAMR_ACCESS_ENUM_DOMAINS | - SAMR_ACCESS_OPEN_DOMAIN, - SAMR_DOMAIN_ACCESS_LOOKUP_INFO_2 | - SAMR_DOMAIN_ACCESS_ENUM_ACCOUNTS | - SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, - &connect_handle, - &domain_handle, - &domain_sid); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); + werr = libnetapi_samr_open_domain(ctx, pipe_cli, + SAMR_ACCESS_ENUM_DOMAINS | + SAMR_ACCESS_OPEN_DOMAIN, + SAMR_DOMAIN_ACCESS_LOOKUP_INFO_2 | + SAMR_DOMAIN_ACCESS_ENUM_ACCOUNTS | + SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, + &connect_handle, + &domain_handle, + &domain_sid); + if (!W_ERROR_IS_OK(werr)) { goto done; } -- cgit From 56bdfad87f69963d65ceb8f7c780a1bd887c1fea Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 3 Jun 2008 00:13:39 +0200 Subject: netapi: add libnetapi_samr_open_builtin_domain(). Guenther (This used to be commit f15a7f9ab1da88369185beda267f3e67a3b36191) --- source3/lib/netapi/netapi_private.h | 7 +++++++ source3/lib/netapi/samr.c | 39 +++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi_private.h b/source3/lib/netapi/netapi_private.h index 69e68ab733..3ce078c2b6 100644 --- a/source3/lib/netapi/netapi_private.h +++ b/source3/lib/netapi/netapi_private.h @@ -40,4 +40,11 @@ WERROR libnetapi_samr_open_domain(TALLOC_CTX *mem_ctx, struct policy_handle *connect_handle, struct policy_handle *domain_handle, struct dom_sid2 **domain_sid); +WERROR libnetapi_samr_open_builtin_domain(TALLOC_CTX *mem_ctx, + struct rpc_pipe_client *pipe_cli, + uint32_t connect_mask, + uint32_t builtin_mask, + struct policy_handle *connect_handle, + struct policy_handle *builtin_handle); + #endif diff --git a/source3/lib/netapi/samr.c b/source3/lib/netapi/samr.c index a41de91de3..8289890237 100644 --- a/source3/lib/netapi/samr.c +++ b/source3/lib/netapi/samr.c @@ -109,3 +109,42 @@ WERROR libnetapi_samr_open_domain(TALLOC_CTX *mem_ctx, done: return werr; } + +/**************************************************************** +****************************************************************/ + +WERROR libnetapi_samr_open_builtin_domain(TALLOC_CTX *mem_ctx, + struct rpc_pipe_client *pipe_cli, + uint32_t connect_mask, + uint32_t builtin_mask, + struct policy_handle *connect_handle, + struct policy_handle *builtin_handle) +{ + NTSTATUS status; + WERROR werr; + + if (!is_valid_policy_hnd(connect_handle)) { + status = rpccli_try_samr_connects(pipe_cli, mem_ctx, + connect_mask, + connect_handle); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + } + + status = rpccli_samr_OpenDomain(pipe_cli, mem_ctx, + connect_handle, + builtin_mask, + CONST_DISCARD(DOM_SID *, &global_sid_Builtin), + builtin_handle); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + werr = WERR_OK; + + done: + return werr; +} -- cgit From bd9d129e6a3857a0faa3ed4ab5a4a71f1272f94a Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 3 Jun 2008 00:13:59 +0200 Subject: netapi: use libnetapi_samr_open_builtin_domain(). Guenther (This used to be commit d1bf8c5ae6f4e3ade2000dd884c8384fb4b9f12c) --- source3/lib/netapi/localgroup.c | 92 +++++++++++++---------------------------- 1 file changed, 28 insertions(+), 64 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/localgroup.c b/source3/lib/netapi/localgroup.c index 77d7498371..a505abdf5b 100644 --- a/source3/lib/netapi/localgroup.c +++ b/source3/lib/netapi/localgroup.c @@ -78,22 +78,13 @@ WERROR NetLocalGroupAdd_r(struct libnetapi_ctx *ctx, goto done; } - status = rpccli_try_samr_connects(pipe_cli, ctx, - SAMR_ACCESS_OPEN_DOMAIN | - SAMR_ACCESS_ENUM_DOMAINS, - &connect_handle); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - status = rpccli_samr_OpenDomain(pipe_cli, ctx, - &connect_handle, - SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, - CONST_DISCARD(DOM_SID *, &global_sid_Builtin), - &builtin_handle); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); + werr = libnetapi_samr_open_builtin_domain(ctx, pipe_cli, + SAMR_ACCESS_OPEN_DOMAIN | + SAMR_ACCESS_ENUM_DOMAINS, + SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, + &connect_handle, + &builtin_handle); + if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -226,22 +217,13 @@ WERROR NetLocalGroupDel_r(struct libnetapi_ctx *ctx, goto done; } - status = rpccli_try_samr_connects(pipe_cli, ctx, - SAMR_ACCESS_OPEN_DOMAIN | - SAMR_ACCESS_ENUM_DOMAINS, - &connect_handle); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - status = rpccli_samr_OpenDomain(pipe_cli, ctx, - &connect_handle, - SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, - CONST_DISCARD(DOM_SID *, &global_sid_Builtin), - &builtin_handle); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); + werr = libnetapi_samr_open_builtin_domain(ctx, pipe_cli, + SAMR_ACCESS_OPEN_DOMAIN | + SAMR_ACCESS_ENUM_DOMAINS, + SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, + &connect_handle, + &builtin_handle); + if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -429,22 +411,13 @@ WERROR NetLocalGroupGetInfo_r(struct libnetapi_ctx *ctx, goto done; } - status = rpccli_try_samr_connects(pipe_cli, ctx, - SAMR_ACCESS_OPEN_DOMAIN | - SAMR_ACCESS_ENUM_DOMAINS, - &connect_handle); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - status = rpccli_samr_OpenDomain(pipe_cli, ctx, - &connect_handle, - SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, - CONST_DISCARD(DOM_SID *, &global_sid_Builtin), - &builtin_handle); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); + werr = libnetapi_samr_open_builtin_domain(ctx, pipe_cli, + SAMR_ACCESS_OPEN_DOMAIN | + SAMR_ACCESS_ENUM_DOMAINS, + SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, + &connect_handle, + &builtin_handle); + if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -634,22 +607,13 @@ WERROR NetLocalGroupSetInfo_r(struct libnetapi_ctx *ctx, goto done; } - status = rpccli_try_samr_connects(pipe_cli, ctx, - SAMR_ACCESS_OPEN_DOMAIN | - SAMR_ACCESS_ENUM_DOMAINS, - &connect_handle); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - status = rpccli_samr_OpenDomain(pipe_cli, ctx, - &connect_handle, - SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, - CONST_DISCARD(DOM_SID *, &global_sid_Builtin), - &builtin_handle); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); + werr = libnetapi_samr_open_builtin_domain(ctx, pipe_cli, + SAMR_ACCESS_OPEN_DOMAIN | + SAMR_ACCESS_ENUM_DOMAINS, + SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, + &connect_handle, + &builtin_handle); + if (!W_ERROR_IS_OK(werr)) { goto done; } -- cgit From 4fd700ca0776862313917103dcb8bbb14dcdd589 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 3 Jun 2008 00:41:36 +0200 Subject: netapi: add libnetapi_samr_lookup_and_open_alias(). Guenther (This used to be commit 890d63f31c0ff3931b8efb627c3a375850a59a9a) --- source3/lib/netapi/localgroup.c | 46 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/localgroup.c b/source3/lib/netapi/localgroup.c index a505abdf5b..07adf7c6a6 100644 --- a/source3/lib/netapi/localgroup.c +++ b/source3/lib/netapi/localgroup.c @@ -24,6 +24,52 @@ #include "lib/netapi/netapi_private.h" #include "lib/netapi/libnetapi.h" +static WERROR libnetapi_samr_lookup_and_open_alias(TALLOC_CTX *mem_ctx, + struct rpc_pipe_client *pipe_cli, + struct policy_handle *domain_handle, + struct lsa_String *lsa_account_name, + uint32_t access_rights, + struct policy_handle *alias_handle) +{ + NTSTATUS status; + WERROR werr; + struct samr_Ids user_rids, name_types; + + status = rpccli_samr_LookupNames(pipe_cli, mem_ctx, + domain_handle, + 1, + lsa_account_name, + &user_rids, + &name_types); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + switch (name_types.ids[0]) { + case SID_NAME_ALIAS: + case SID_NAME_WKN_GRP: + break; + default: + return WERR_INVALID_DATATYPE; + } + + status = rpccli_samr_OpenAlias(pipe_cli, mem_ctx, + domain_handle, + access_rights, + user_rids.ids[0], + alias_handle); + if (NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + werr = WERR_OK; + + done: + return werr; +} + /**************************************************************** ****************************************************************/ -- cgit From dbb8e163af87c09d5ec7091a925b369ee1147e5e Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 3 Jun 2008 00:42:00 +0200 Subject: netapi: use libnetapi_samr_lookup_and_open_alias(). Guenther (This used to be commit d8fad6bf442ac6f218c1c4572da9f1e9932c9cee) --- source3/lib/netapi/localgroup.c | 186 +++++++++++++--------------------------- 1 file changed, 59 insertions(+), 127 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/localgroup.c b/source3/lib/netapi/localgroup.c index 07adf7c6a6..de15dcf699 100644 --- a/source3/lib/netapi/localgroup.c +++ b/source3/lib/netapi/localgroup.c @@ -82,7 +82,6 @@ WERROR NetLocalGroupAdd_r(struct libnetapi_ctx *ctx, WERROR werr; struct lsa_String lsa_account_name; struct policy_handle connect_handle, domain_handle, builtin_handle, alias_handle; - struct samr_Ids user_rids, name_types; struct dom_sid2 *domain_sid = NULL; uint32_t rid; @@ -136,26 +135,19 @@ WERROR NetLocalGroupAdd_r(struct libnetapi_ctx *ctx, init_lsa_String(&lsa_account_name, alias_name); - status = rpccli_samr_LookupNames(pipe_cli, ctx, - &builtin_handle, - 1, - &lsa_account_name, - &user_rids, - &name_types); - if (NT_STATUS_IS_OK(status)) { - status = rpccli_samr_OpenAlias(pipe_cli, ctx, - &builtin_handle, - SAMR_ALIAS_ACCESS_LOOKUP_INFO, - user_rids.ids[0], - &alias_handle); - if (NT_STATUS_IS_OK(status)) { - werr = WERR_ALIAS_EXISTS; - goto done; - } - } + werr = libnetapi_samr_lookup_and_open_alias(ctx, pipe_cli, + &builtin_handle, + &lsa_account_name, + SAMR_ALIAS_ACCESS_LOOKUP_INFO, + &alias_handle); rpccli_samr_Close(pipe_cli, ctx, &builtin_handle); + if (W_ERROR_IS_OK(werr)) { + werr = WERR_ALIAS_EXISTS; + goto done; + } + werr = libnetapi_samr_open_domain(ctx, pipe_cli, SAMR_ACCESS_ENUM_DOMAINS | SAMR_ACCESS_OPEN_DOMAIN, @@ -241,7 +233,6 @@ WERROR NetLocalGroupDel_r(struct libnetapi_ctx *ctx, WERROR werr; struct lsa_String lsa_account_name; struct policy_handle connect_handle, domain_handle, builtin_handle, alias_handle; - struct samr_Ids user_rids, name_types; struct dom_sid2 *domain_sid = NULL; if (!r->in.group_name) { @@ -275,26 +266,18 @@ WERROR NetLocalGroupDel_r(struct libnetapi_ctx *ctx, init_lsa_String(&lsa_account_name, r->in.group_name); - status = rpccli_samr_LookupNames(pipe_cli, ctx, - &builtin_handle, - 1, - &lsa_account_name, - &user_rids, - &name_types); - if (NT_STATUS_IS_OK(status)) { - status = rpccli_samr_OpenAlias(pipe_cli, ctx, - &builtin_handle, - SEC_STD_DELETE, - user_rids.ids[0], - &alias_handle); - if (NT_STATUS_IS_OK(status)) { - rpccli_samr_Close(pipe_cli, ctx, &builtin_handle); - goto delete_alias; - } - } + werr = libnetapi_samr_lookup_and_open_alias(ctx, pipe_cli, + &builtin_handle, + &lsa_account_name, + SEC_STD_DELETE, + &alias_handle); rpccli_samr_Close(pipe_cli, ctx, &builtin_handle); + if (W_ERROR_IS_OK(werr)) { + goto delete_alias; + } + werr = libnetapi_samr_open_domain(ctx, pipe_cli, SAMR_ACCESS_ENUM_DOMAINS | SAMR_ACCESS_OPEN_DOMAIN, @@ -307,28 +290,18 @@ WERROR NetLocalGroupDel_r(struct libnetapi_ctx *ctx, goto done; } - status = rpccli_samr_LookupNames(pipe_cli, ctx, - &domain_handle, - 1, - &lsa_account_name, - &user_rids, - &name_types); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } + werr = libnetapi_samr_lookup_and_open_alias(ctx, pipe_cli, + &domain_handle, + &lsa_account_name, + SEC_STD_DELETE, + &alias_handle); - status = rpccli_samr_OpenAlias(pipe_cli, ctx, - &domain_handle, - SEC_STD_DELETE, - user_rids.ids[0], - &alias_handle); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); + rpccli_samr_Close(pipe_cli, ctx, &domain_handle); + + if (!W_ERROR_IS_OK(werr)) { goto done; } - rpccli_samr_Close(pipe_cli, ctx, &domain_handle); delete_alias: status = rpccli_samr_DeleteDomAlias(pipe_cli, ctx, @@ -425,7 +398,6 @@ WERROR NetLocalGroupGetInfo_r(struct libnetapi_ctx *ctx, WERROR werr; struct lsa_String lsa_account_name; struct policy_handle connect_handle, domain_handle, builtin_handle, alias_handle; - struct samr_Ids user_rids, name_types; struct dom_sid2 *domain_sid = NULL; union samr_AliasInfo *alias_info = NULL; @@ -469,26 +441,18 @@ WERROR NetLocalGroupGetInfo_r(struct libnetapi_ctx *ctx, init_lsa_String(&lsa_account_name, r->in.group_name); - status = rpccli_samr_LookupNames(pipe_cli, ctx, - &builtin_handle, - 1, - &lsa_account_name, - &user_rids, - &name_types); - if (NT_STATUS_IS_OK(status)) { - status = rpccli_samr_OpenAlias(pipe_cli, ctx, - &builtin_handle, - SAMR_ALIAS_ACCESS_LOOKUP_INFO, - user_rids.ids[0], - &alias_handle); - if (NT_STATUS_IS_OK(status)) { - rpccli_samr_Close(pipe_cli, ctx, &builtin_handle); - goto query_alias; - } - } + werr = libnetapi_samr_lookup_and_open_alias(ctx, pipe_cli, + &builtin_handle, + &lsa_account_name, + SAMR_ALIAS_ACCESS_LOOKUP_INFO, + &alias_handle); rpccli_samr_Close(pipe_cli, ctx, &builtin_handle); + if (W_ERROR_IS_OK(werr)) { + goto query_alias; + } + werr = libnetapi_samr_open_domain(ctx, pipe_cli, SAMR_ACCESS_ENUM_DOMAINS | SAMR_ACCESS_OPEN_DOMAIN, @@ -501,29 +465,18 @@ WERROR NetLocalGroupGetInfo_r(struct libnetapi_ctx *ctx, goto done; } - status = rpccli_samr_LookupNames(pipe_cli, ctx, - &domain_handle, - 1, - &lsa_account_name, - &user_rids, - &name_types); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } + werr = libnetapi_samr_lookup_and_open_alias(ctx, pipe_cli, + &domain_handle, + &lsa_account_name, + SAMR_ALIAS_ACCESS_LOOKUP_INFO, + &alias_handle); - status = rpccli_samr_OpenAlias(pipe_cli, ctx, - &domain_handle, - SAMR_ALIAS_ACCESS_LOOKUP_INFO, - user_rids.ids[0], - &alias_handle); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); + rpccli_samr_Close(pipe_cli, ctx, &domain_handle); + + if (!W_ERROR_IS_OK(werr)) { goto done; } - rpccli_samr_Close(pipe_cli, ctx, &domain_handle); - query_alias: status = rpccli_samr_QueryAliasInfo(pipe_cli, ctx, &alias_handle, @@ -620,7 +573,6 @@ WERROR NetLocalGroupSetInfo_r(struct libnetapi_ctx *ctx, WERROR werr; struct lsa_String lsa_account_name; struct policy_handle connect_handle, domain_handle, builtin_handle, alias_handle; - struct samr_Ids user_rids, name_types; struct dom_sid2 *domain_sid = NULL; enum samr_AliasInfoEnum alias_level; union samr_AliasInfo *alias_info = NULL; @@ -665,26 +617,18 @@ WERROR NetLocalGroupSetInfo_r(struct libnetapi_ctx *ctx, init_lsa_String(&lsa_account_name, r->in.group_name); - status = rpccli_samr_LookupNames(pipe_cli, ctx, - &builtin_handle, - 1, - &lsa_account_name, - &user_rids, - &name_types); - if (NT_STATUS_IS_OK(status)) { - status = rpccli_samr_OpenAlias(pipe_cli, ctx, - &builtin_handle, - SAMR_ALIAS_ACCESS_SET_INFO, - user_rids.ids[0], - &alias_handle); - if (NT_STATUS_IS_OK(status)) { - rpccli_samr_Close(pipe_cli, ctx, &builtin_handle); - goto set_alias; - } - } + werr = libnetapi_samr_lookup_and_open_alias(ctx, pipe_cli, + &builtin_handle, + &lsa_account_name, + SAMR_ALIAS_ACCESS_SET_INFO, + &alias_handle); rpccli_samr_Close(pipe_cli, ctx, &builtin_handle); + if (W_ERROR_IS_OK(werr)) { + goto set_alias; + } + werr = libnetapi_samr_open_domain(ctx, pipe_cli, SAMR_ACCESS_ENUM_DOMAINS | SAMR_ACCESS_OPEN_DOMAIN, @@ -696,24 +640,12 @@ WERROR NetLocalGroupSetInfo_r(struct libnetapi_ctx *ctx, goto done; } - status = rpccli_samr_LookupNames(pipe_cli, ctx, - &domain_handle, - 1, - &lsa_account_name, - &user_rids, - &name_types); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - status = rpccli_samr_OpenAlias(pipe_cli, ctx, - &domain_handle, - SAMR_ALIAS_ACCESS_SET_INFO, - user_rids.ids[0], - &alias_handle); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); + werr = libnetapi_samr_lookup_and_open_alias(ctx, pipe_cli, + &domain_handle, + &lsa_account_name, + SAMR_ALIAS_ACCESS_SET_INFO, + &alias_handle); + if (!W_ERROR_IS_OK(werr)) { goto done; } -- cgit From 34413e47070e789c1b547647a409fac9929938d4 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 3 Jun 2008 01:37:55 +0200 Subject: netapi: fix some build warnings. Guenther (This used to be commit 45cd78030f18a792d0761160bb96116d19801109) --- source3/lib/netapi/group.c | 8 ++++---- source3/lib/netapi/localgroup.c | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/group.c b/source3/lib/netapi/group.c index f56c92175b..00e995dc83 100644 --- a/source3/lib/netapi/group.c +++ b/source3/lib/netapi/group.c @@ -39,10 +39,10 @@ WERROR NetGroupAdd_r(struct libnetapi_ctx *ctx, struct dom_sid2 *domain_sid = NULL; uint32_t rid = 0; - struct GROUP_INFO_0 *info0; - struct GROUP_INFO_1 *info1; - struct GROUP_INFO_2 *info2; - struct GROUP_INFO_3 *info3; + struct GROUP_INFO_0 *info0 = NULL; + struct GROUP_INFO_1 *info1 = NULL; + struct GROUP_INFO_2 *info2 = NULL; + struct GROUP_INFO_3 *info3 = NULL; union samr_GroupInfo info; ZERO_STRUCT(connect_handle); diff --git a/source3/lib/netapi/localgroup.c b/source3/lib/netapi/localgroup.c index de15dcf699..d3a9aa1270 100644 --- a/source3/lib/netapi/localgroup.c +++ b/source3/lib/netapi/localgroup.c @@ -85,8 +85,8 @@ WERROR NetLocalGroupAdd_r(struct libnetapi_ctx *ctx, struct dom_sid2 *domain_sid = NULL; uint32_t rid; - struct LOCALGROUP_INFO_0 *info0; - struct LOCALGROUP_INFO_1 *info1; + struct LOCALGROUP_INFO_0 *info0 = NULL; + struct LOCALGROUP_INFO_1 *info1 = NULL; const char *alias_name = NULL; @@ -574,7 +574,7 @@ WERROR NetLocalGroupSetInfo_r(struct libnetapi_ctx *ctx, struct lsa_String lsa_account_name; struct policy_handle connect_handle, domain_handle, builtin_handle, alias_handle; struct dom_sid2 *domain_sid = NULL; - enum samr_AliasInfoEnum alias_level; + enum samr_AliasInfoEnum alias_level = 0; union samr_AliasInfo *alias_info = NULL; if (!r->in.group_name) { -- cgit From 12281d02ae0f6b5abf17edcaa973ec27a0340320 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 3 Jun 2008 20:42:58 +0200 Subject: netapi: remove unrequired headers. Guenther (This used to be commit f8fec49ce10cbd663cb30ac94a543b4a76a8dc57) --- source3/lib/netapi/samr.c | 5 ----- 1 file changed, 5 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/samr.c b/source3/lib/netapi/samr.c index 8289890237..2346f7f956 100644 --- a/source3/lib/netapi/samr.c +++ b/source3/lib/netapi/samr.c @@ -19,11 +19,6 @@ #include "includes.h" -#include "librpc/gen_ndr/libnetapi.h" -#include "lib/netapi/netapi.h" -#include "lib/netapi/netapi_private.h" -#include "lib/netapi/libnetapi.h" - /**************************************************************** ****************************************************************/ -- cgit From 7d35e4e294a00288ba83d3f9c4f1ce9a23260311 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 3 Jun 2008 15:19:46 +0200 Subject: netdomjoin-gui: some minor fixes + hunting down typecast bugs. Guenther (This used to be commit 0fa6c8c6a3efd026154e8af54ba73b3d3de1affa) --- .../examples/netdomjoin-gui/netdomjoin-gui.c | 36 +++++++++++++++------- 1 file changed, 25 insertions(+), 11 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c index df8193707c..dd4e4ad394 100644 --- a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c +++ b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c @@ -113,7 +113,9 @@ static void callback_do_close(GtkWidget *widget, { debug("callback_do_close called\n"); - gtk_widget_destroy(data); + if (data) { + gtk_widget_destroy(GTK_WIDGET(data)); + } } static void callback_do_freeauth(GtkWidget *widget, @@ -127,7 +129,8 @@ static void callback_do_freeauth(GtkWidget *widget, SAFE_FREE(state->password); if (state->window_creds_prompt) { - gtk_widget_destroy(state->window_creds_prompt); + gtk_widget_destroy(GTK_WIDGET(state->window_creds_prompt)); + state->window_creds_prompt = NULL; } } @@ -141,8 +144,13 @@ static void callback_do_freeauth_and_close(GtkWidget *widget, SAFE_FREE(state->account); SAFE_FREE(state->password); - gtk_widget_destroy(state->window_creds_prompt); - gtk_widget_destroy(state->window_do_change); + if (state->window_creds_prompt) { + gtk_widget_destroy(GTK_WIDGET(state->window_creds_prompt)); + state->window_creds_prompt = NULL; + } + if (state->window_do_change) { + gtk_widget_destroy(GTK_WIDGET(state->window_do_change)); + } } static void free_join_state(struct join_state *s) @@ -225,8 +233,12 @@ static void callback_do_exit(GtkWidget *widget, default: break; } - gtk_widget_destroy(dialog); - gtk_widget_destroy(state->window_main); + if (dialog) { + gtk_widget_destroy(GTK_WIDGET(dialog)); + } + if (state->window_main) { + gtk_widget_destroy(GTK_WIDGET(state->window_main)); + } do_cleanup(state); exit(0); } @@ -257,7 +269,7 @@ static void callback_do_reboot(GtkWidget *widget, gtk_widget_show(dialog); #else gtk_dialog_run(GTK_DIALOG(dialog)); - gtk_widget_destroy(dialog); + gtk_widget_destroy(GTK_WIDGET(dialog)); #endif gtk_label_set_text(GTK_LABEL(state->label_reboot), @@ -388,10 +400,12 @@ static void callback_do_storeauth(GtkWidget *widget, SAFE_FREE(state->account); SAFE_FREE(state->password); - callback_return_username(state->entry_account, state); - callback_return_password(state->entry_password, state); + callback_return_username(state->entry_account, (gpointer)state); + callback_return_password(state->entry_password, (gpointer)state); - gtk_widget_destroy(state->window_creds_prompt); + if (state->window_creds_prompt) { + gtk_widget_destroy(GTK_WIDGET(state->window_creds_prompt)); + } } static void callback_continue(GtkWidget *widget, @@ -1537,7 +1551,7 @@ static int init_join_state(struct join_state **state) { struct join_state *s; - s = malloc(sizeof(struct join_state)); + s = (struct join_state *)malloc(sizeof(struct join_state)); if (!s) { return -1; } -- cgit From 19e5ee0e094c563521e6515294f448f7136a928f Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 5 Jun 2008 01:11:23 +0200 Subject: netdomjoin-gui: disable annoying "reboot now" dialog. Guenther (This used to be commit 8f0c5f1bedaae7a86ca671cdb2ba798079ec1d84) --- source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c index dd4e4ad394..bfd4fea87e 100644 --- a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c +++ b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c @@ -209,8 +209,10 @@ static void callback_apply_description_change(GtkWidget *widget, static void callback_do_exit(GtkWidget *widget, gpointer data) { +#if 0 GtkWidget *dialog; gint result; +#endif struct join_state *state = (struct join_state *)data; if (!state->settings_changed) { @@ -218,6 +220,7 @@ static void callback_do_exit(GtkWidget *widget, return; } +#if 0 dialog = gtk_message_dialog_new(GTK_WINDOW(state->window_main), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_QUESTION, @@ -236,6 +239,7 @@ static void callback_do_exit(GtkWidget *widget, if (dialog) { gtk_widget_destroy(GTK_WIDGET(dialog)); } +#endif if (state->window_main) { gtk_widget_destroy(GTK_WIDGET(state->window_main)); } -- cgit From de89de4b58249aa6b73eae7399fe78e6b86e81f1 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 5 Jun 2008 19:02:09 +0200 Subject: netdomjoin-gui: fix more gtk runtime warnings. Guenther (This used to be commit 521ea68719524eeef827875e018bb8cba2a92e87) --- source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c index bfd4fea87e..1da8169f63 100644 --- a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c +++ b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c @@ -115,6 +115,7 @@ static void callback_do_close(GtkWidget *widget, if (data) { gtk_widget_destroy(GTK_WIDGET(data)); + data = NULL; } } @@ -150,6 +151,7 @@ static void callback_do_freeauth_and_close(GtkWidget *widget, } if (state->window_do_change) { gtk_widget_destroy(GTK_WIDGET(state->window_do_change)); + state->window_do_change = NULL; } } @@ -242,6 +244,7 @@ static void callback_do_exit(GtkWidget *widget, #endif if (state->window_main) { gtk_widget_destroy(GTK_WIDGET(state->window_main)); + state->window_main = NULL; } do_cleanup(state); exit(0); @@ -409,6 +412,7 @@ static void callback_do_storeauth(GtkWidget *widget, if (state->window_creds_prompt) { gtk_widget_destroy(GTK_WIDGET(state->window_creds_prompt)); + state->window_creds_prompt = NULL; } } -- cgit From 66a5cbaf8be9de66d40660cfb57df553b651d75d Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 5 Jun 2008 19:04:31 +0200 Subject: netdomjoin-gui: enable NetGetJoinInformation() call after successfull joining. Now that libnetjoin reloads configuration after joining, we can rely on the NetGetJoinInformation() output and use it for displaying the new domain name and type. Guenther (This used to be commit cc1b8de2632e87002cac86838f2a77ab9771ce2c) --- source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c index 1da8169f63..418b9c8b8e 100644 --- a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c +++ b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c @@ -297,12 +297,12 @@ static void callback_do_reboot(GtkWidget *widget, } debug("got new status: %s\n", buffer); -#if 0 + SAFE_FREE(state->name_buffer_new); state->name_buffer_new = strdup(buffer); - SAFE_FREE(buffer); state->name_type_new = type; -#endif + state->name_buffer_initial = strdup(buffer); + state->name_type_initial = type; NetApiBufferFree((void *)buffer); gtk_label_set_text(GTK_LABEL(state->label_current_name_buffer), -- cgit From 4500f1d5844ed743ce6d209cd45815ef2b547fab Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 17 Jun 2008 10:31:44 +0200 Subject: netapi: Fix Bug #5545 (libnetapi_init without $USER) Based on patch from Erik van Pienbroek. Guenther (This used to be commit 71f4cf773022525ba617f09c495dbff97f8eb2d5) --- source3/lib/netapi/netapi.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi.c b/source3/lib/netapi/netapi.c index 944c2c9304..cf1be00849 100644 --- a/source3/lib/netapi/netapi.c +++ b/source3/lib/netapi/netapi.c @@ -85,10 +85,14 @@ NET_API_STATUS libnetapi_init(struct libnetapi_ctx **context) setenv(KRB5_ENV_CCNAME, ctx->krb5_cc_env, 1); } - ctx->username = talloc_strdup(frame, getenv("USER")); + if (getenv("USER")) { + ctx->username = talloc_strdup(frame, getenv("USER")); + } else { + ctx->username = talloc_strdup(frame, ""); + } if (!ctx->username) { TALLOC_FREE(frame); - fprintf(stderr, "out of memory\n"); + fprintf(stderr, "libnetapi_init: out of memory\n"); return W_ERROR_V(WERR_NOMEM); } -- cgit From ebbeddfdcd7b3782f5b6e58abb7af7d9484090ae Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 6 Jun 2008 13:50:39 +0200 Subject: netapi: add NetRemoteTOD() skeleton. Guenther (This used to be commit 78bc98cb55e36ef175f9c0f6fcd943781a514005) --- source3/lib/netapi/libnetapi.c | 42 +++++++++++++++++++++++++++++++++++++++++ source3/lib/netapi/libnetapi.h | 6 ++++++ source3/lib/netapi/serverinfo.c | 19 +++++++++++++++++++ 3 files changed, 67 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/libnetapi.c b/source3/lib/netapi/libnetapi.c index 097086f12f..173c4d3c66 100644 --- a/source3/lib/netapi/libnetapi.c +++ b/source3/lib/netapi/libnetapi.c @@ -1089,3 +1089,45 @@ NET_API_STATUS NetLocalGroupSetInfo(const char * server_name /* [in] */, return r.out.result; } +/**************************************************************** + NetRemoteTOD +****************************************************************/ + +NET_API_STATUS NetRemoteTOD(const char * server_name /* [in] */, + uint8_t **buf /* [out] [ref] */) +{ + struct NetRemoteTOD r; + struct libnetapi_ctx *ctx = NULL; + NET_API_STATUS status; + WERROR werr; + + status = libnetapi_getctx(&ctx); + if (status != 0) { + return status; + } + + /* In parameters */ + r.in.server_name = server_name; + + /* Out parameters */ + r.out.buf = buf; + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_IN_DEBUG(NetRemoteTOD, &r); + } + + if (LIBNETAPI_LOCAL_SERVER(server_name)) { + werr = NetRemoteTOD_l(ctx, &r); + } else { + werr = NetRemoteTOD_r(ctx, &r); + } + + r.out.result = W_ERROR_V(werr); + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_OUT_DEBUG(NetRemoteTOD, &r); + } + + return r.out.result; +} + diff --git a/source3/lib/netapi/libnetapi.h b/source3/lib/netapi/libnetapi.h index 911be7420b..12be1cc074 100644 --- a/source3/lib/netapi/libnetapi.h +++ b/source3/lib/netapi/libnetapi.h @@ -187,4 +187,10 @@ WERROR NetLocalGroupSetInfo_r(struct libnetapi_ctx *ctx, struct NetLocalGroupSetInfo *r); WERROR NetLocalGroupSetInfo_l(struct libnetapi_ctx *ctx, struct NetLocalGroupSetInfo *r); +NET_API_STATUS NetRemoteTOD(const char * server_name /* [in] */, + uint8_t **buf /* [out] [ref] */); +WERROR NetRemoteTOD_r(struct libnetapi_ctx *ctx, + struct NetRemoteTOD *r); +WERROR NetRemoteTOD_l(struct libnetapi_ctx *ctx, + struct NetRemoteTOD *r); #endif /* __LIBNETAPI_LIBNETAPI__ */ diff --git a/source3/lib/netapi/serverinfo.c b/source3/lib/netapi/serverinfo.c index dd7a8808b4..f75779a653 100644 --- a/source3/lib/netapi/serverinfo.c +++ b/source3/lib/netapi/serverinfo.c @@ -203,3 +203,22 @@ WERROR NetServerSetInfo_r(struct libnetapi_ctx *ctx, done: return werr; } + +/**************************************************************** +****************************************************************/ + +WERROR NetRemoteTOD_r(struct libnetapi_ctx *ctx, + struct NetRemoteTOD *r) +{ + return WERR_NOT_SUPPORTED; +} + +/**************************************************************** +****************************************************************/ + +WERROR NetRemoteTOD_l(struct libnetapi_ctx *ctx, + struct NetRemoteTOD *r) +{ + return WERR_NOT_SUPPORTED; +} + -- cgit From feca006232764fdd389a221aa23f322a492347e2 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 6 Jun 2008 16:44:35 +0200 Subject: netapi: make NetRemoteTOD() headers public. Guenther (This used to be commit 1262ab1843a8a8cb794f6bbfb113bd2d99ffba22) --- source3/lib/netapi/netapi.h | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h index d80e78ebbf..d24e15901b 100644 --- a/source3/lib/netapi/netapi.h +++ b/source3/lib/netapi/netapi.h @@ -157,6 +157,21 @@ struct LOCALGROUP_INFO_1002 { const char * lgrpi1002_comment; }; +struct TIME_OF_DAY_INFO { + uint32_t tod_elapsedt; + uint32_t tod_msecs; + uint32_t tod_hours; + uint32_t tod_mins; + uint32_t tod_secs; + uint32_t tod_hunds; + int32_t tod_timezone; + uint32_t tod_tinterval; + uint32_t tod_day; + uint32_t tod_month; + uint32_t tod_year; + uint32_t tod_weekday; +}; + #endif /* _HEADER_libnetapi */ /**************************************************************** @@ -710,4 +725,20 @@ NET_API_STATUS NetLocalGroupSetInfo(const char * server_name /* [in] */, uint8_t *buf /* [in] [ref] */, uint32_t *parm_err /* [out] [ref] */); +/************************************************************//** + * + * NetRemoteTOD + * + * @brief Query remote Time of Day + * + * @param[in] server_name The server name to connect to + * @param[out] buf The buffer containing a TIME_OF_DAY_INFO structure + * @return NET_API_STATUS + * + * example server/remote_tod.c + ***************************************************************/ + +NET_API_STATUS NetRemoteTOD(const char * server_name /* [in] */, + uint8_t **buf /* [out] [ref] */); + #endif -- cgit From a2290e5e0073fdfbfe4d5a4df12ee0a1b25f5f4e Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 6 Jun 2008 16:41:19 +0200 Subject: netapi: implement NetRemoteTOD(). Guenther (This used to be commit 76877680a8a6400bc2d3b5e3b788b7d5fc683850) --- source3/lib/netapi/serverinfo.c | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/serverinfo.c b/source3/lib/netapi/serverinfo.c index f75779a653..7920bc29d0 100644 --- a/source3/lib/netapi/serverinfo.c +++ b/source3/lib/netapi/serverinfo.c @@ -210,7 +210,37 @@ WERROR NetServerSetInfo_r(struct libnetapi_ctx *ctx, WERROR NetRemoteTOD_r(struct libnetapi_ctx *ctx, struct NetRemoteTOD *r) { - return WERR_NOT_SUPPORTED; + struct cli_state *cli = NULL; + struct rpc_pipe_client *pipe_cli = NULL; + NTSTATUS status; + WERROR werr; + struct srvsvc_NetRemoteTODInfo *info = NULL; + + werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + werr = libnetapi_open_pipe(ctx, cli, PI_SRVSVC, &pipe_cli); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + status = rpccli_srvsvc_NetRemoteTOD(pipe_cli, ctx, + r->in.server_name, + &info, + &werr); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + *r->out.buf = (uint8_t *)talloc_memdup(ctx, info, + sizeof(struct srvsvc_NetRemoteTODInfo)); + W_ERROR_HAVE_NO_MEMORY(*r->out.buf); + + done: + return werr; } /**************************************************************** @@ -219,6 +249,6 @@ WERROR NetRemoteTOD_r(struct libnetapi_ctx *ctx, WERROR NetRemoteTOD_l(struct libnetapi_ctx *ctx, struct NetRemoteTOD *r) { - return WERR_NOT_SUPPORTED; + return NetRemoteTOD_r(ctx, r); } -- cgit From ffba83d22d757a26fff07a6fa47cd792f26d066e Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 17 Jun 2008 13:18:02 +0200 Subject: netapi: add NetRemoteTOD example code. Guenther (This used to be commit 2b82779a401dd1d14f5842872ac37b2454efc92b) --- source3/lib/netapi/examples/Makefile.in | 8 ++- source3/lib/netapi/examples/server/remote_tod.c | 83 +++++++++++++++++++++++++ 2 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 source3/lib/netapi/examples/server/remote_tod.c (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/Makefile.in b/source3/lib/netapi/examples/Makefile.in index 13a682ff6d..4b5ce2573b 100644 --- a/source3/lib/netapi/examples/Makefile.in +++ b/source3/lib/netapi/examples/Makefile.in @@ -35,7 +35,8 @@ PROGS = bin/getdc@EXEEXT@ \ bin/localgroup_add@EXEEXT@ \ bin/localgroup_del@EXEEXT@ \ bin/localgroup_getinfo@EXEEXT@ \ - bin/localgroup_setinfo@EXEEXT@ + bin/localgroup_setinfo@EXEEXT@ \ + bin/remote_tod@EXEEXT@ all: $(PROGS) @@ -83,6 +84,7 @@ LOCALGROUPADD_OBJ = localgroup/localgroup_add.o $(CMDLINE_OBJ) LOCALGROUPDEL_OBJ = localgroup/localgroup_del.o $(CMDLINE_OBJ) LOCALGROUPGETINFO_OBJ = localgroup/localgroup_getinfo.o $(CMDLINE_OBJ) LOCALGROUPSETINFO_OBJ = localgroup/localgroup_setinfo.o $(CMDLINE_OBJ) +REMOTETOD_OBJ = server/remote_tod.o $(CMDLINE_OBJ) bin/getdc@EXEEXT@: $(BINARY_PREREQS) $(GETDC_OBJ) @echo Linking $@ @@ -160,6 +162,10 @@ bin/localgroup_setinfo@EXEEXT@: $(BINARY_PREREQS) $(LOCALGROUPSETINFO_OBJ) @echo Linking $@ @$(CC) $(FLAGS) -o $@ $(LOCALGROUPSETINFO_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) +bin/remote_tod@EXEEXT@: $(BINARY_PREREQS) $(REMOTETOD_OBJ) + @echo Linking $@ + @$(CC) $(FLAGS) -o $@ $(REMOTETOD_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) + clean: -rm -f $(PROGS) -rm -f core */*~ *~ \ diff --git a/source3/lib/netapi/examples/server/remote_tod.c b/source3/lib/netapi/examples/server/remote_tod.c new file mode 100644 index 0000000000..7636f6ac95 --- /dev/null +++ b/source3/lib/netapi/examples/server/remote_tod.c @@ -0,0 +1,83 @@ +/* + * Unix SMB/CIFS implementation. + * NetRemoteTOD query + * Copyright (C) Guenther Deschner 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include +#include +#include +#include +#include + +#include + +#include "common.h" + +int main(int argc, const char **argv) +{ + NET_API_STATUS status; + struct libnetapi_ctx *ctx = NULL; + const char *hostname = NULL; + struct TIME_OF_DAY_INFO *tod = NULL; + + poptContext pc; + int opt; + + struct poptOption long_options[] = { + POPT_AUTOHELP + POPT_COMMON_LIBNETAPI_EXAMPLES + POPT_TABLEEND + }; + + status = libnetapi_init(&ctx); + if (status != 0) { + return status; + } + + pc = poptGetContext("tod", argc, argv, long_options, 0); + + poptSetOtherOptionHelp(pc, "hostname"); + while((opt = poptGetNextOpt(pc)) != -1) { + } + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + hostname = poptGetArg(pc); + + + /* NetRemoteTOD */ + + status = NetRemoteTOD(hostname, + (uint8_t **)&tod); + if (status != 0) { + printf("NetRemoteTOD failed with: %s\n", + libnetapi_get_error_string(ctx, status)); + } else { + printf("%d-%d-%d %d:%d:%d\n", + tod->tod_day, tod->tod_month, tod->tod_year, + tod->tod_hours, tod->tod_mins, tod->tod_secs); + NetApiBufferFree(tod); + } + + out: + libnetapi_free(ctx); + poptFreeContext(pc); + + return status; +} -- cgit From d0b7bccf6d7ce8b5f053a73a722d388d2483d8e8 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 9 Jun 2008 11:01:59 +0200 Subject: netapi: implement NetUserEnum filters. Guenther (This used to be commit 0bd69df7704789888eba2a07aba505dce037c4eb) --- source3/lib/netapi/user.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/user.c b/source3/lib/netapi/user.c index f053732ac9..53a307a6aa 100644 --- a/source3/lib/netapi/user.c +++ b/source3/lib/netapi/user.c @@ -468,6 +468,7 @@ WERROR NetUserEnum_r(struct libnetapi_ctx *ctx, struct dom_sid2 *domain_sid = NULL; struct policy_handle domain_handle; struct samr_SamArray *sam = NULL; + uint32_t filter = ACB_NORMAL; NTSTATUS status; WERROR werr; @@ -512,11 +513,31 @@ WERROR NetUserEnum_r(struct libnetapi_ctx *ctx, goto done; } + switch (r->in.filter) { + case FILTER_NORMAL_ACCOUNT: + filter = ACB_NORMAL; + break; + case FILTER_TEMP_DUPLICATE_ACCOUNT: + filter = ACB_TEMPDUP; + break; + case FILTER_INTERDOMAIN_TRUST_ACCOUNT: + filter = ACB_DOMTRUST; + break; + case FILTER_WORKSTATION_TRUST_ACCOUNT: + filter = ACB_WSTRUST; + break; + case FILTER_SERVER_TRUST_ACCOUNT: + filter = ACB_SVRTRUST; + break; + default: + break; + } + status = rpccli_samr_EnumDomainUsers(pipe_cli, ctx, &domain_handle, r->in.resume_handle, - r->in.filter, + filter, &sam, r->in.prefmaxlen, r->out.entries_read); -- cgit From b330ea29c7af8e0cdd7d9773016e8fdc2d09df22 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 17 Jun 2008 13:13:10 +0200 Subject: netapi: add NetUserEnum filter constants to public headers. Guenther (This used to be commit 32a66131eb56e1c66b89e348141047c6b98cf35e) --- source3/lib/netapi/netapi.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h index d24e15901b..9496d77e83 100644 --- a/source3/lib/netapi/netapi.h +++ b/source3/lib/netapi/netapi.h @@ -69,6 +69,12 @@ struct DOMAIN_CONTROLLER_INFO { const char * client_site_name; }; +#define FILTER_TEMP_DUPLICATE_ACCOUNT ( 0x0001 ) +#define FILTER_NORMAL_ACCOUNT ( 0x0002 ) +#define FILTER_INTERDOMAIN_TRUST_ACCOUNT ( 0x0008 ) +#define FILTER_WORKSTATION_TRUST_ACCOUNT ( 0x0010 ) +#define FILTER_SERVER_TRUST_ACCOUNT ( 0x0020 ) + struct SERVER_INFO_1005 { const char * sv1005_comment; }; -- cgit From 44e153e3c1880d63a3e4ea03a61bd43a05dea74a Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 9 Jun 2008 11:02:27 +0200 Subject: netapi: use NetUserEnum filter in example code. Guenther (This used to be commit ad105177686da823ef9cce1c1bedaf0f84a49b8c) --- source3/lib/netapi/examples/user/user_enum.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/user/user_enum.c b/source3/lib/netapi/examples/user/user_enum.c index e1f6bda10b..569d5a62d6 100644 --- a/source3/lib/netapi/examples/user/user_enum.c +++ b/source3/lib/netapi/examples/user/user_enum.c @@ -71,7 +71,7 @@ int main(int argc, const char **argv) do { status = NetUserEnum(hostname, 0, - 0, + FILTER_NORMAL_ACCOUNT, &buffer, (uint32_t)-1, &entries_read, -- cgit From 18c9e752182bc7d0c5e87d1773ca084495b7ff21 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 24 Jun 2008 13:06:38 +0200 Subject: libads: use ads_connect_user_creds in some places. Guenther (This used to be commit ebf31203e7cf22e32b986c536279688b17a65d22) --- source3/lib/netapi/joindomain.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/joindomain.c b/source3/lib/netapi/joindomain.c index 66f7cfb13f..a33e0eeee5 100644 --- a/source3/lib/netapi/joindomain.c +++ b/source3/lib/netapi/joindomain.c @@ -389,7 +389,7 @@ WERROR NetGetJoinableOUs_l(struct libnetapi_ctx *ctx, ads->auth.password = SMB_STRDUP(ctx->password); } - ads_status = ads_connect(ads); + ads_status = ads_connect_user_creds(ads); if (!ADS_ERR_OK(ads_status)) { ads_destroy(&ads); return WERR_DEFAULT_JOIN_REQUIRED; -- cgit From 6fa8ac6ab4e99f16c5e47e78343266d77cc646c0 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 25 Jun 2008 00:32:02 +0200 Subject: netapi: add NetUserChangePassword skeleton. Guenther (This used to be commit f4ce6887103d0f50bf9a91251e2aceb77674604f) --- source3/lib/netapi/libnetapi.c | 46 ++++++++++++++++++++++++++++++++++++++++++ source3/lib/netapi/libnetapi.h | 8 ++++++++ source3/lib/netapi/user.c | 18 +++++++++++++++++ 3 files changed, 72 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/libnetapi.c b/source3/lib/netapi/libnetapi.c index 173c4d3c66..659c4c7e5f 100644 --- a/source3/lib/netapi/libnetapi.c +++ b/source3/lib/netapi/libnetapi.c @@ -585,6 +585,52 @@ NET_API_STATUS NetUserEnum(const char * server_name /* [in] [unique] */, return r.out.result; } +/**************************************************************** + NetUserChangePassword +****************************************************************/ + +NET_API_STATUS NetUserChangePassword(const char * domain_name /* [in] */, + const char * user_name /* [in] */, + const char * old_password /* [in] */, + const char * new_password /* [in] */) +{ + struct NetUserChangePassword r; + struct libnetapi_ctx *ctx = NULL; + NET_API_STATUS status; + WERROR werr; + + status = libnetapi_getctx(&ctx); + if (status != 0) { + return status; + } + + /* In parameters */ + r.in.domain_name = domain_name; + r.in.user_name = user_name; + r.in.old_password = old_password; + r.in.new_password = new_password; + + /* Out parameters */ + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_IN_DEBUG(NetUserChangePassword, &r); + } + + if (LIBNETAPI_LOCAL_SERVER(domain_name)) { + werr = NetUserChangePassword_l(ctx, &r); + } else { + werr = NetUserChangePassword_r(ctx, &r); + } + + r.out.result = W_ERROR_V(werr); + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_OUT_DEBUG(NetUserChangePassword, &r); + } + + return r.out.result; +} + /**************************************************************** NetQueryDisplayInformation ****************************************************************/ diff --git a/source3/lib/netapi/libnetapi.h b/source3/lib/netapi/libnetapi.h index 12be1cc074..1364a4c08f 100644 --- a/source3/lib/netapi/libnetapi.h +++ b/source3/lib/netapi/libnetapi.h @@ -100,6 +100,14 @@ WERROR NetUserEnum_r(struct libnetapi_ctx *ctx, struct NetUserEnum *r); WERROR NetUserEnum_l(struct libnetapi_ctx *ctx, struct NetUserEnum *r); +NET_API_STATUS NetUserChangePassword(const char * domain_name /* [in] */, + const char * user_name /* [in] */, + const char * old_password /* [in] */, + const char * new_password /* [in] */); +WERROR NetUserChangePassword_r(struct libnetapi_ctx *ctx, + struct NetUserChangePassword *r); +WERROR NetUserChangePassword_l(struct libnetapi_ctx *ctx, + struct NetUserChangePassword *r); NET_API_STATUS NetQueryDisplayInformation(const char * server_name /* [in] [unique] */, uint32_t level /* [in] */, uint32_t idx /* [in] */, diff --git a/source3/lib/netapi/user.c b/source3/lib/netapi/user.c index 53a307a6aa..0d8065dd7f 100644 --- a/source3/lib/netapi/user.c +++ b/source3/lib/netapi/user.c @@ -833,3 +833,21 @@ WERROR NetQueryDisplayInformation_l(struct libnetapi_ctx *ctx, { return WERR_NOT_SUPPORTED; } + +/**************************************************************** +****************************************************************/ + +WERROR NetUserChangePassword_r(struct libnetapi_ctx *ctx, + struct NetUserChangePassword *r) +{ + return WERR_NOT_SUPPORTED; +} + +/**************************************************************** +****************************************************************/ + +WERROR NetUserChangePassword_l(struct libnetapi_ctx *ctx, + struct NetUserChangePassword *r) +{ + return WERR_NOT_SUPPORTED; +} -- cgit From 8a01bd8f7364bdad6d758236a415359e84bffde4 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 25 Jun 2008 00:47:41 +0200 Subject: netapi: add NetUserChangePassword() to public headers. Guenther (This used to be commit 5d06891238d7dddedeb6fe2aca677c765b90c74a) --- source3/lib/netapi/netapi.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h index 9496d77e83..113a72ca13 100644 --- a/source3/lib/netapi/netapi.h +++ b/source3/lib/netapi/netapi.h @@ -509,6 +509,26 @@ NET_API_STATUS NetUserEnum(const char * server_name /* [in] */, uint32_t *total_entries /* [out] [ref] */, uint32_t *resume_handle /* [in,out] [ref] */); +/************************************************************//** + * + * NetUserChangePassword + * + * @brief Change the password for a user on a given server or in a given domain + * + * @param[in] domain_name The server or domain name to connect to + * @param[in] user_name The user account to change the password for + * @param[in] old_password The user account's old password + * @param[in] old_password The user account's new password + * @return NET_API_STATUS + * + * example user/user_chgpwd.c + ***************************************************************/ + +NET_API_STATUS NetUserChangePassword(const char * domain_name /* [in] */, + const char * user_name /* [in] */, + const char * old_password /* [in] */, + const char * new_password /* [in] */); + /************************************************************//** * * NetQueryDisplayInformation -- cgit From ee35b50cad4a9901721a317a4241db9c077e0682 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 25 Jun 2008 00:47:17 +0200 Subject: netapi: add NetUserChangePassword() example code. Guenther (This used to be commit ac5aaf29004584d0f1821689eb985d837cda1aa1) --- source3/lib/netapi/examples/Makefile.in | 6 ++ source3/lib/netapi/examples/user/user_chgpwd.c | 99 ++++++++++++++++++++++++++ 2 files changed, 105 insertions(+) create mode 100644 source3/lib/netapi/examples/user/user_chgpwd.c (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/Makefile.in b/source3/lib/netapi/examples/Makefile.in index 4b5ce2573b..8e6a59a2e9 100644 --- a/source3/lib/netapi/examples/Makefile.in +++ b/source3/lib/netapi/examples/Makefile.in @@ -26,6 +26,7 @@ PROGS = bin/getdc@EXEEXT@ \ bin/user_del@EXEEXT@ \ bin/user_enum@EXEEXT@ \ bin/user_dispinfo@EXEEXT@ \ + bin/user_chgpwd@EXEEXT@ \ bin/group_add@EXEEXT@ \ bin/group_del@EXEEXT@ \ bin/group_setinfo@EXEEXT@ \ @@ -74,6 +75,7 @@ USERADD_OBJ = user/user_add.o $(CMDLINE_OBJ) USERDEL_OBJ = user/user_del.o $(CMDLINE_OBJ) USERENUM_OBJ = user/user_enum.o $(CMDLINE_OBJ) USERDISPINFO_OBJ = user/user_dispinfo.o $(CMDLINE_OBJ) +USERCHGPWD_OBJ = user/user_chgpwd.o $(CMDLINE_OBJ) GROUPADD_OBJ = group/group_add.o $(CMDLINE_OBJ) GROUPDEL_OBJ = group/group_del.o $(CMDLINE_OBJ) GROUPSETINFO_OBJ = group/group_setinfo.o $(CMDLINE_OBJ) @@ -122,6 +124,10 @@ bin/user_dispinfo@EXEEXT@: $(BINARY_PREREQS) $(USERDISPINFO_OBJ) @echo Linking $@ @$(CC) $(FLAGS) -o $@ $(USERDISPINFO_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) +bin/user_chgpwd@EXEEXT@: $(BINARY_PREREQS) $(USERCHGPWD_OBJ) + @echo Linking $@ + @$(CC) $(FLAGS) -o $@ $(USERCHGPWD_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) + bin/group_add@EXEEXT@: $(BINARY_PREREQS) $(GROUPADD_OBJ) @echo Linking $@ @$(CC) $(FLAGS) -o $@ $(GROUPADD_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) diff --git a/source3/lib/netapi/examples/user/user_chgpwd.c b/source3/lib/netapi/examples/user/user_chgpwd.c new file mode 100644 index 0000000000..8b37ec2a99 --- /dev/null +++ b/source3/lib/netapi/examples/user/user_chgpwd.c @@ -0,0 +1,99 @@ +/* + * Unix SMB/CIFS implementation. + * NetUserChangePassword query + * Copyright (C) Guenther Deschner 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include +#include +#include +#include +#include + +#include + +#include "common.h" + +int main(int argc, const char **argv) +{ + NET_API_STATUS status; + struct libnetapi_ctx *ctx = NULL; + const char *hostname = NULL; + const char *username = NULL; + const char *old_password = NULL; + const char *new_password = NULL; + + poptContext pc; + int opt; + + struct poptOption long_options[] = { + POPT_AUTOHELP + POPT_COMMON_LIBNETAPI_EXAMPLES + POPT_TABLEEND + }; + + status = libnetapi_init(&ctx); + if (status != 0) { + return status; + } + + pc = poptGetContext("user_chgpwd", argc, argv, long_options, 0); + + poptSetOtherOptionHelp(pc, "hostname username old_password new_password"); + while((opt = poptGetNextOpt(pc)) != -1) { + } + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + hostname = poptGetArg(pc); + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + username = poptGetArg(pc); + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + old_password = poptGetArg(pc); + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + new_password = poptGetArg(pc); + + /* NetUserChangePassword */ + + status = NetUserChangePassword(hostname, + username, + old_password, + new_password); + if (status != 0) { + printf("NetUserChangePassword failed with: %s\n", + libnetapi_get_error_string(ctx, status)); + } + + out: + libnetapi_free(ctx); + poptFreeContext(pc); + + return status; +} -- cgit From b74c0fa10f3bddd2a0fcc5bb098133df66744f93 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 2 Jul 2008 13:09:23 +0200 Subject: netapi: fix doxygen warning. Guenther (This used to be commit cfd59383d680e41a885e546842b0eb8585123acb) --- source3/lib/netapi/netapi.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h index 113a72ca13..8ec1fbfb03 100644 --- a/source3/lib/netapi/netapi.h +++ b/source3/lib/netapi/netapi.h @@ -518,7 +518,7 @@ NET_API_STATUS NetUserEnum(const char * server_name /* [in] */, * @param[in] domain_name The server or domain name to connect to * @param[in] user_name The user account to change the password for * @param[in] old_password The user account's old password - * @param[in] old_password The user account's new password + * @param[in] new_password The user account's new password * @return NET_API_STATUS * * example user/user_chgpwd.c -- cgit From b3152fb26849fa90347b315adbbebf57366c9927 Mon Sep 17 00:00:00 2001 From: Kai Blin Date: Wed, 9 Jul 2008 10:39:24 +0200 Subject: netapi: Correctly increase idx when displaying user information (This used to be commit 5fad9de2507b88820149def31faa28e5e45f7b5f) --- source3/lib/netapi/examples/user/user_dispinfo.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/user/user_dispinfo.c b/source3/lib/netapi/examples/user/user_dispinfo.c index 9f862505aa..c7d3112d71 100644 --- a/source3/lib/netapi/examples/user/user_dispinfo.c +++ b/source3/lib/netapi/examples/user/user_dispinfo.c @@ -78,11 +78,13 @@ int main(int argc, const char **argv) if (status == 0 || status == ERROR_MORE_DATA) { user = (struct NET_DISPLAY_USER *)buffer; for (i=0; iusri1_name); + printf("user %d: %s\n", i + idx,i + user->usri1_name); user++; } NetApiBufferFree(buffer); } + idx += entries_read; } while (status == ERROR_MORE_DATA); if (status != 0) { -- cgit From 730678c73177474ef8614f979661d9f6119a61f4 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Tue, 15 Jul 2008 22:46:12 +0200 Subject: netapi: fix vim(?)-typo Michael (This used to be commit 7a7bddd75413dba3c0c43fab68a115cf0445f12b) --- source3/lib/netapi/examples/user/user_dispinfo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/user/user_dispinfo.c b/source3/lib/netapi/examples/user/user_dispinfo.c index c7d3112d71..23024fe9fe 100644 --- a/source3/lib/netapi/examples/user/user_dispinfo.c +++ b/source3/lib/netapi/examples/user/user_dispinfo.c @@ -78,7 +78,7 @@ int main(int argc, const char **argv) if (status == 0 || status == ERROR_MORE_DATA) { user = (struct NET_DISPLAY_USER *)buffer; for (i=0; iusri1_name); user++; } -- cgit From bda5542de19445b00398440518e2896ad165d5fd Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 16 Jul 2008 16:20:42 +0200 Subject: netapi: fix documentation for NetGroupSetInfo. Guenther (This used to be commit 7b4f84793b39f2940381bccae27f65275cc39572) --- source3/lib/netapi/netapi.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h index 8ec1fbfb03..323b0c8754 100644 --- a/source3/lib/netapi/netapi.h +++ b/source3/lib/netapi/netapi.h @@ -620,12 +620,12 @@ NET_API_STATUS NetGroupSetInfo(const char * server_name /* [in] */, * @brief Get Domain Group Information * * @param[in] server_name The server name to connect to - * @param[in] group_name The name of the group that is going to be modified + * @param[in] group_name The name of the group that is going to be queried * @param[in] level The level defining the requested GROUP_INFO_X structure * @param[out] buf The buffer containing a GROUP_INFO_X structure * @return NET_API_STATUS * - * example group/group_del.c + * example group/group_getinfo.c ***************************************************************/ NET_API_STATUS NetGroupGetInfo(const char * server_name /* [in] */, -- cgit From a6aeb73e4afcdcfbddbc8f9f2983e252d75975c8 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 16 Jul 2008 15:22:04 +0200 Subject: netapi: add ConvertSidToStringSid() for convenience of the callers. Guenther (This used to be commit b7633998ed76c7bb2faa803841fafe9126a39847) --- source3/lib/netapi/netapi.h | 15 ++++++++++++++ source3/lib/netapi/sid.c | 50 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 source3/lib/netapi/sid.c (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h index 323b0c8754..e7f3527d1a 100644 --- a/source3/lib/netapi/netapi.h +++ b/source3/lib/netapi/netapi.h @@ -255,6 +255,21 @@ const char *libnetapi_get_error_string(struct libnetapi_ctx *ctx, NET_API_STATUS NetApiBufferFree(void *buffer); +/************************************************************//** + * + * ConvertSidToStringSid + * + * @brief Convert a domain sid into a string + * + * @param[in] sid A pointer to a sid structure + * @param[in] sid_string A pointer that holds a pointer to a sid string. Caller + * needs to free with free(3) + * @return bool + ***************************************************************/ + +int ConvertSidToStringSid(const struct domsid *sid, + char **sid_string); + /************************************************************//** * * NetJoinDomain diff --git a/source3/lib/netapi/sid.c b/source3/lib/netapi/sid.c new file mode 100644 index 0000000000..869bd0f763 --- /dev/null +++ b/source3/lib/netapi/sid.c @@ -0,0 +1,50 @@ +/* + * Unix SMB/CIFS implementation. + * NetApi Support + * Copyright (C) Guenther Deschner 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include "includes.h" + +#include "librpc/gen_ndr/libnetapi.h" + +/**************************************************************** +****************************************************************/ + +bool ConvertSidToStringSid(const struct domsid *sid, + char **sid_string) +{ + char *ret; + + if (!sid || !sid_string) { + return false; + } + + ret = sid_string_talloc(NULL, (const struct dom_sid *)sid); + if (!ret) { + return false; + } + + *sid_string = SMB_STRDUP(ret); + + TALLOC_FREE(ret); + + if (!*sid_string) { + return false; + } + + return true; +} -- cgit From c343190344f60cb92c9ad8c5ba71becd5f6329e9 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 1 Jul 2008 20:11:02 +0200 Subject: netapi: add skeleton for NetGroupEnum(). Guenther (This used to be commit 21a0d9d254d5c21c4bc9fe305e9df2126476f3f4) --- source3/lib/netapi/group.c | 18 ++++++++++++++ source3/lib/netapi/libnetapi.c | 53 ++++++++++++++++++++++++++++++++++++++++++ source3/lib/netapi/libnetapi.h | 11 +++++++++ 3 files changed, 82 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/group.c b/source3/lib/netapi/group.c index 00e995dc83..5807ad83c1 100644 --- a/source3/lib/netapi/group.c +++ b/source3/lib/netapi/group.c @@ -1013,3 +1013,21 @@ WERROR NetGroupDelUser_l(struct libnetapi_ctx *ctx, { return NetGroupDelUser_r(ctx, r); } + +/**************************************************************** +****************************************************************/ + +WERROR NetGroupEnum_r(struct libnetapi_ctx *ctx, + struct NetGroupEnum *r) +{ + return WERR_NOT_SUPPORTED; +} + +/**************************************************************** +****************************************************************/ + +WERROR NetGroupEnum_l(struct libnetapi_ctx *ctx, + struct NetGroupEnum *r) +{ + return WERR_NOT_SUPPORTED; +} diff --git a/source3/lib/netapi/libnetapi.c b/source3/lib/netapi/libnetapi.c index 659c4c7e5f..0953de6058 100644 --- a/source3/lib/netapi/libnetapi.c +++ b/source3/lib/netapi/libnetapi.c @@ -771,6 +771,59 @@ NET_API_STATUS NetGroupDel(const char * server_name /* [in] */, return r.out.result; } +/**************************************************************** + NetGroupEnum +****************************************************************/ + +NET_API_STATUS NetGroupEnum(const char * server_name /* [in] */, + uint32_t level /* [in] */, + uint8_t **buffer /* [out] [ref] */, + uint32_t prefmaxlen /* [in] */, + uint32_t *entries_read /* [out] [ref] */, + uint32_t *total_entries /* [out] [ref] */, + uint32_t *resume_handle /* [in,out] [ref] */) +{ + struct NetGroupEnum r; + struct libnetapi_ctx *ctx = NULL; + NET_API_STATUS status; + WERROR werr; + + status = libnetapi_getctx(&ctx); + if (status != 0) { + return status; + } + + /* In parameters */ + r.in.server_name = server_name; + r.in.level = level; + r.in.prefmaxlen = prefmaxlen; + r.in.resume_handle = resume_handle; + + /* Out parameters */ + r.out.buffer = buffer; + r.out.entries_read = entries_read; + r.out.total_entries = total_entries; + r.out.resume_handle = resume_handle; + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_IN_DEBUG(NetGroupEnum, &r); + } + + if (LIBNETAPI_LOCAL_SERVER(server_name)) { + werr = NetGroupEnum_l(ctx, &r); + } else { + werr = NetGroupEnum_r(ctx, &r); + } + + r.out.result = W_ERROR_V(werr); + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_OUT_DEBUG(NetGroupEnum, &r); + } + + return r.out.result; +} + /**************************************************************** NetGroupSetInfo ****************************************************************/ diff --git a/source3/lib/netapi/libnetapi.h b/source3/lib/netapi/libnetapi.h index 1364a4c08f..a6c8e84b6b 100644 --- a/source3/lib/netapi/libnetapi.h +++ b/source3/lib/netapi/libnetapi.h @@ -133,6 +133,17 @@ WERROR NetGroupDel_r(struct libnetapi_ctx *ctx, struct NetGroupDel *r); WERROR NetGroupDel_l(struct libnetapi_ctx *ctx, struct NetGroupDel *r); +NET_API_STATUS NetGroupEnum(const char * server_name /* [in] */, + uint32_t level /* [in] */, + uint8_t **buffer /* [out] [ref] */, + uint32_t prefmaxlen /* [in] */, + uint32_t *entries_read /* [out] [ref] */, + uint32_t *total_entries /* [out] [ref] */, + uint32_t *resume_handle /* [in,out] [ref] */); +WERROR NetGroupEnum_r(struct libnetapi_ctx *ctx, + struct NetGroupEnum *r); +WERROR NetGroupEnum_l(struct libnetapi_ctx *ctx, + struct NetGroupEnum *r); NET_API_STATUS NetGroupSetInfo(const char * server_name /* [in] */, const char * group_name /* [in] */, uint32_t level /* [in] */, -- cgit From a035851b65700e93316344ab47c48460f6ef8397 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 1 Jul 2008 20:11:38 +0200 Subject: netapi: add NetGroupEnum to public headers. Guenther (This used to be commit 4564581f9aaf4afd6c47c6d5a9a299bc5012244d) --- source3/lib/netapi/netapi.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h index e7f3527d1a..086a9a9fca 100644 --- a/source3/lib/netapi/netapi.h +++ b/source3/lib/netapi/netapi.h @@ -606,6 +606,34 @@ NET_API_STATUS NetGroupAdd(const char * server_name /* [in] */, NET_API_STATUS NetGroupDel(const char * server_name /* [in] */, const char * group_name /* [in] */); +/************************************************************//** + * + * NetGroupEnum + * + * @brief Enumerate groups on a server + * + * @param[in] server_name The server name to connect to + * @param[in] level The enumeration level used for the query (Currently only + * level 0 is supported) + * @param[out] buffer The returned enumeration buffer + * @param[in] prefmaxlen The requested maximal buffer size + * @param[out] entries_read The number of returned entries + * @param[out] total_entries The number of total entries + * @param[in,out] resume_handle A handle passed in and returned for resuming + * operations + * @return NET_API_STATUS + * + * example group/group_enum.c + ***************************************************************/ + +NET_API_STATUS NetGroupEnum(const char * server_name /* [in] */, + uint32_t level /* [in] */, + uint8_t **buffer /* [out] [ref] */, + uint32_t prefmaxlen /* [in] */, + uint32_t *entries_read /* [out] [ref] */, + uint32_t *total_entries /* [out] [ref] */, + uint32_t *resume_handle /* [in,out] [ref] */); + /************************************************************//** * * NetGroupSetInfo -- cgit From 89f4e869b657b6c92f84741bc1cdebbabe4dd72d Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 16 Jul 2008 16:14:47 +0200 Subject: netapi: fix map_group_info_to_buffer for GROUP_INFO_3 change. Guenther (This used to be commit f2875677194f440ffebf18e6f5171be948114353) --- source3/lib/netapi/group.c | 10 ++++++---- source3/lib/netapi/netapi.h | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/group.c b/source3/lib/netapi/group.c index 5807ad83c1..ebaf3660ec 100644 --- a/source3/lib/netapi/group.c +++ b/source3/lib/netapi/group.c @@ -593,6 +593,7 @@ static WERROR map_group_info_to_buffer(TALLOC_CTX *mem_ctx, struct GROUP_INFO_1 info1; struct GROUP_INFO_2 info2; struct GROUP_INFO_3 info3; + struct dom_sid sid; switch (level) { case 0: @@ -618,13 +619,14 @@ static WERROR map_group_info_to_buffer(TALLOC_CTX *mem_ctx, break; case 3: + if (!sid_compose(&sid, domain_sid, rid)) { + return WERR_NOMEM; + } + info3.grpi3_name = info->name.string; info3.grpi3_comment = info->description.string; info3.grpi3_attributes = info->attributes; - - if (!sid_compose((struct dom_sid *)&info3.grpi3_group_sid, domain_sid, rid)) { - return WERR_NOMEM; - } + info3.grpi3_group_sid = (struct domsid *)sid_dup_talloc(mem_ctx, &sid); *buffer = (uint8_t *)talloc_memdup(mem_ctx, &info3, sizeof(info3)); diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h index 086a9a9fca..f6345afe67 100644 --- a/source3/lib/netapi/netapi.h +++ b/source3/lib/netapi/netapi.h @@ -138,7 +138,7 @@ struct GROUP_INFO_2 { struct GROUP_INFO_3 { const char * grpi3_name; const char * grpi3_comment; - struct domsid grpi3_group_sid; + struct domsid * grpi3_group_sid; uint32_t grpi3_attributes; }; -- cgit From bf0eaf64cec97308d8cd4d4e4c958b01bc4f39e2 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 17 Jul 2008 01:06:29 +0200 Subject: netapi: fill in NetGroupEnum_r(). Guenther (This used to be commit 64700e09ce9417c0b0128cc016abd34ab92f3695) --- source3/lib/netapi/group.c | 261 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 259 insertions(+), 2 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/group.c b/source3/lib/netapi/group.c index ebaf3660ec..d28e7578be 100644 --- a/source3/lib/netapi/group.c +++ b/source3/lib/netapi/group.c @@ -1019,10 +1019,267 @@ WERROR NetGroupDelUser_l(struct libnetapi_ctx *ctx, /**************************************************************** ****************************************************************/ +static WERROR convert_samr_disp_groups_to_GROUP_INFO_0_buffer(TALLOC_CTX *mem_ctx, + struct samr_DispInfoFullGroups *groups, + uint8_t **buffer) +{ + struct GROUP_INFO_0 *g0; + int i; + + g0 = TALLOC_ZERO_ARRAY(mem_ctx, struct GROUP_INFO_0, groups->count); + W_ERROR_HAVE_NO_MEMORY(g0); + + for (i=0; icount; i++) { + g0[i].grpi0_name = talloc_strdup(mem_ctx, + groups->entries[i].account_name.string); + W_ERROR_HAVE_NO_MEMORY(g0[i].grpi0_name); + } + + *buffer = (uint8_t *)talloc_memdup(mem_ctx, g0, + sizeof(struct GROUP_INFO_0) * groups->count); + W_ERROR_HAVE_NO_MEMORY(*buffer); + + return WERR_OK; +} + +/**************************************************************** +****************************************************************/ + +static WERROR convert_samr_disp_groups_to_GROUP_INFO_1_buffer(TALLOC_CTX *mem_ctx, + struct samr_DispInfoFullGroups *groups, + uint8_t **buffer) +{ + struct GROUP_INFO_1 *g1; + int i; + + g1 = TALLOC_ZERO_ARRAY(mem_ctx, struct GROUP_INFO_1, groups->count); + W_ERROR_HAVE_NO_MEMORY(g1); + + for (i=0; icount; i++) { + g1[i].grpi1_name = talloc_strdup(mem_ctx, + groups->entries[i].account_name.string); + g1[i].grpi1_comment = talloc_strdup(mem_ctx, + groups->entries[i].description.string); + W_ERROR_HAVE_NO_MEMORY(g1[i].grpi1_name); + } + + *buffer = (uint8_t *)talloc_memdup(mem_ctx, g1, + sizeof(struct GROUP_INFO_1) * groups->count); + W_ERROR_HAVE_NO_MEMORY(*buffer); + + return WERR_OK; +} + +/**************************************************************** +****************************************************************/ + +static WERROR convert_samr_disp_groups_to_GROUP_INFO_2_buffer(TALLOC_CTX *mem_ctx, + struct samr_DispInfoFullGroups *groups, + uint8_t **buffer) +{ + struct GROUP_INFO_2 *g2; + int i; + + g2 = TALLOC_ZERO_ARRAY(mem_ctx, struct GROUP_INFO_2, groups->count); + W_ERROR_HAVE_NO_MEMORY(g2); + + for (i=0; icount; i++) { + g2[i].grpi2_name = talloc_strdup(mem_ctx, + groups->entries[i].account_name.string); + g2[i].grpi2_comment = talloc_strdup(mem_ctx, + groups->entries[i].description.string); + g2[i].grpi2_group_id = groups->entries[i].rid; + g2[i].grpi2_attributes = groups->entries[i].acct_flags; + W_ERROR_HAVE_NO_MEMORY(g2[i].grpi2_name); + } + + *buffer = (uint8_t *)talloc_memdup(mem_ctx, g2, + sizeof(struct GROUP_INFO_2) * groups->count); + W_ERROR_HAVE_NO_MEMORY(*buffer); + + return WERR_OK; +} + +/**************************************************************** +****************************************************************/ + +static WERROR convert_samr_disp_groups_to_GROUP_INFO_3_buffer(TALLOC_CTX *mem_ctx, + struct samr_DispInfoFullGroups *groups, + const struct dom_sid *domain_sid, + uint8_t **buffer) +{ + struct GROUP_INFO_3 *g3; + int i; + + g3 = TALLOC_ZERO_ARRAY(mem_ctx, struct GROUP_INFO_3, groups->count); + W_ERROR_HAVE_NO_MEMORY(g3); + + for (i=0; icount; i++) { + + struct dom_sid sid; + + if (!sid_compose(&sid, domain_sid, groups->entries[i].rid)) { + return WERR_NOMEM; + } + + g3[i].grpi3_name = talloc_strdup(mem_ctx, + groups->entries[i].account_name.string); + g3[i].grpi3_comment = talloc_strdup(mem_ctx, + groups->entries[i].description.string); + g3[i].grpi3_group_sid = (struct domsid *)sid_dup_talloc(mem_ctx, &sid); + g3[i].grpi3_attributes = groups->entries[i].acct_flags; + W_ERROR_HAVE_NO_MEMORY(g3[i].grpi3_name); + } + + *buffer = (uint8_t *)talloc_memdup(mem_ctx, g3, + sizeof(struct GROUP_INFO_3) * groups->count); + W_ERROR_HAVE_NO_MEMORY(*buffer); + + return WERR_OK; +} + +/**************************************************************** +****************************************************************/ + +static WERROR convert_samr_disp_groups_to_GROUP_INFO_buffer(TALLOC_CTX *mem_ctx, + uint32_t level, + struct samr_DispInfoFullGroups *groups, + const struct dom_sid *domain_sid, + uint32_t *entries_read, + uint8_t **buffer) +{ + if (entries_read) { + *entries_read = groups->count; + } + + switch (level) { + case 0: + return convert_samr_disp_groups_to_GROUP_INFO_0_buffer(mem_ctx, groups, buffer); + case 1: + return convert_samr_disp_groups_to_GROUP_INFO_1_buffer(mem_ctx, groups, buffer); + case 2: + return convert_samr_disp_groups_to_GROUP_INFO_2_buffer(mem_ctx, groups, buffer); + case 3: + return convert_samr_disp_groups_to_GROUP_INFO_3_buffer(mem_ctx, groups, domain_sid, buffer); + default: + return WERR_UNKNOWN_LEVEL; + } +} + +/**************************************************************** +****************************************************************/ + WERROR NetGroupEnum_r(struct libnetapi_ctx *ctx, struct NetGroupEnum *r) { - return WERR_NOT_SUPPORTED; + struct cli_state *cli = NULL; + struct rpc_pipe_client *pipe_cli = NULL; + struct policy_handle connect_handle; + struct dom_sid2 *domain_sid = NULL; + struct policy_handle domain_handle; + union samr_DispInfo info; + union samr_DomainInfo *domain_info = NULL; + + uint32_t total_size = 0; + uint32_t returned_size = 0; + + NTSTATUS status; + WERROR werr, tmp_werr; + + ZERO_STRUCT(connect_handle); + ZERO_STRUCT(domain_handle); + + switch (r->in.level) { + case 0: + case 1: + case 2: + case 3: + break; + default: + return WERR_UNKNOWN_LEVEL; + } + + werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + werr = libnetapi_open_pipe(ctx, cli, PI_SAMR, &pipe_cli); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + werr = libnetapi_samr_open_domain(ctx, pipe_cli, + SAMR_ACCESS_ENUM_DOMAINS | + SAMR_ACCESS_OPEN_DOMAIN, + SAMR_DOMAIN_ACCESS_LOOKUP_INFO_2 | + SAMR_DOMAIN_ACCESS_ENUM_ACCOUNTS | + SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, + &connect_handle, + &domain_handle, + &domain_sid); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + status = rpccli_samr_QueryDomainInfo(pipe_cli, ctx, + &domain_handle, + 2, + &domain_info); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + if (r->out.total_entries) { + *r->out.total_entries = domain_info->info2.num_groups; + } + + status = rpccli_samr_QueryDisplayInfo2(pipe_cli, + ctx, + &domain_handle, + 3, + r->in.resume_handle ? + *r->in.resume_handle : 0, + (uint32_t)-1, + r->in.prefmaxlen, + &total_size, + &returned_size, + &info); + werr = ntstatus_to_werror(status); + if (NT_STATUS_IS_ERR(status)) { + goto done; + } + + if (r->out.resume_handle) { + *r->out.resume_handle = + info.info3.entries[info.info3.count-1].idx; + } + + tmp_werr = convert_samr_disp_groups_to_GROUP_INFO_buffer(ctx, + r->in.level, + &info.info3, + domain_sid, + r->out.entries_read, + r->out.buffer); + if (!W_ERROR_IS_OK(tmp_werr)) { + werr = tmp_werr; + goto done; + } + + done: + if (!cli) { + return werr; + } +#if 0 + if (is_valid_policy_hnd(&domain_handle)) { + rpccli_samr_Close(pipe_cli, ctx, &domain_handle); + } + if (is_valid_policy_hnd(&connect_handle)) { + rpccli_samr_Close(pipe_cli, ctx, &connect_handle); + } +#endif + return werr; } /**************************************************************** @@ -1031,5 +1288,5 @@ WERROR NetGroupEnum_r(struct libnetapi_ctx *ctx, WERROR NetGroupEnum_l(struct libnetapi_ctx *ctx, struct NetGroupEnum *r) { - return WERR_NOT_SUPPORTED; + return NetGroupEnum_r(ctx, r); } -- cgit From f266bb4cec61a1092f098a91ee58356af35dbf77 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 1 Jul 2008 20:12:43 +0200 Subject: netapi: add NetGroupEnum example code. Guenther (This used to be commit 133ea72a996a1eefda1b6351277f415823db55fc) --- source3/lib/netapi/examples/Makefile.in | 6 + source3/lib/netapi/examples/group/group_enum.c | 153 +++++++++++++++++++++++++ 2 files changed, 159 insertions(+) create mode 100644 source3/lib/netapi/examples/group/group_enum.c (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/Makefile.in b/source3/lib/netapi/examples/Makefile.in index 8e6a59a2e9..47626348bf 100644 --- a/source3/lib/netapi/examples/Makefile.in +++ b/source3/lib/netapi/examples/Makefile.in @@ -29,6 +29,7 @@ PROGS = bin/getdc@EXEEXT@ \ bin/user_chgpwd@EXEEXT@ \ bin/group_add@EXEEXT@ \ bin/group_del@EXEEXT@ \ + bin/group_enum@EXEEXT@ \ bin/group_setinfo@EXEEXT@ \ bin/group_getinfo@EXEEXT@ \ bin/group_adduser@EXEEXT@ \ @@ -78,6 +79,7 @@ USERDISPINFO_OBJ = user/user_dispinfo.o $(CMDLINE_OBJ) USERCHGPWD_OBJ = user/user_chgpwd.o $(CMDLINE_OBJ) GROUPADD_OBJ = group/group_add.o $(CMDLINE_OBJ) GROUPDEL_OBJ = group/group_del.o $(CMDLINE_OBJ) +GROUPENUM_OBJ = group/group_enum.o $(CMDLINE_OBJ) GROUPSETINFO_OBJ = group/group_setinfo.o $(CMDLINE_OBJ) GROUPGETINFO_OBJ = group/group_getinfo.o $(CMDLINE_OBJ) GROUPADDUSER_OBJ = group/group_adduser.o $(CMDLINE_OBJ) @@ -136,6 +138,10 @@ bin/group_del@EXEEXT@: $(BINARY_PREREQS) $(GROUPDEL_OBJ) @echo Linking $@ @$(CC) $(FLAGS) -o $@ $(GROUPDEL_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) +bin/group_enum@EXEEXT@: $(BINARY_PREREQS) $(GROUPENUM_OBJ) + @echo Linking $@ + @$(CC) $(FLAGS) -o $@ $(GROUPENUM_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) + bin/group_setinfo@EXEEXT@: $(BINARY_PREREQS) $(GROUPSETINFO_OBJ) @echo Linking $@ @$(CC) $(FLAGS) -o $@ $(GROUPSETINFO_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) diff --git a/source3/lib/netapi/examples/group/group_enum.c b/source3/lib/netapi/examples/group/group_enum.c new file mode 100644 index 0000000000..a9b6ad96cb --- /dev/null +++ b/source3/lib/netapi/examples/group/group_enum.c @@ -0,0 +1,153 @@ +/* + * Unix SMB/CIFS implementation. + * NetGroupEnum query + * Copyright (C) Guenther Deschner 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include +#include +#include +#include +#include + +#include + +#include "common.h" + +int main(int argc, const char **argv) +{ + NET_API_STATUS status; + struct libnetapi_ctx *ctx = NULL; + const char *hostname = NULL; + uint32_t level = 0; + uint8_t *buffer = NULL; + uint32_t entries_read = 0; + uint32_t total_entries = 0; + uint32_t resume_handle = 0; + int i; + char *sid_str = NULL; + + struct GROUP_INFO_0 *info0 = NULL; + struct GROUP_INFO_1 *info1 = NULL; + struct GROUP_INFO_2 *info2 = NULL; + struct GROUP_INFO_3 *info3 = NULL; + + poptContext pc; + int opt; + + struct poptOption long_options[] = { + POPT_AUTOHELP + POPT_COMMON_LIBNETAPI_EXAMPLES + POPT_TABLEEND + }; + + status = libnetapi_init(&ctx); + if (status != 0) { + return status; + } + + pc = poptGetContext("group_enum", argc, argv, long_options, 0); + + poptSetOtherOptionHelp(pc, "hostname level"); + while((opt = poptGetNextOpt(pc)) != -1) { + } + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + hostname = poptGetArg(pc); + + if (poptPeekArg(pc)) { + level = atoi(poptGetArg(pc)); + } + + /* NetUserEnum */ + + do { + status = NetGroupEnum(hostname, + level, + &buffer, + (uint32_t)-1, + &entries_read, + &total_entries, + &resume_handle); + if (status == 0 || status == ERROR_MORE_DATA) { + printf("total entries: %d\n", total_entries); + switch (level) { + case 0: + info0 = (struct GROUP_INFO_0 *)buffer; + break; + case 1: + info1 = (struct GROUP_INFO_1 *)buffer; + break; + case 2: + info2 = (struct GROUP_INFO_2 *)buffer; + break; + case 3: + info3 = (struct GROUP_INFO_3 *)buffer; + break; + default: + break; + } + for (i=0; igrpi0_name); + info0++; + break; + case 1: + printf("#%d group: %s\n", i, info1->grpi1_name); + printf("#%d comment: %s\n", i, info1->grpi1_comment); + info1++; + break; + case 2: + printf("#%d group: %s\n", i, info2->grpi2_name); + printf("#%d comment: %s\n", i, info2->grpi2_comment); + printf("#%d rid: %d\n", i, info2->grpi2_group_id); + printf("#%d attributes: 0x%08x\n", i, info2->grpi2_attributes); + info2++; + break; + case 3: + printf("#%d group: %s\n", i, info3->grpi3_name); + printf("#%d comment: %s\n", i, info3->grpi3_comment); + if (ConvertSidToStringSid(info3->grpi3_group_sid, + &sid_str)) { + printf("#%d group_sid: %s\n", i, sid_str); + free(sid_str); + } + printf("#%d attributes: 0x%08x\n", i, info3->grpi3_attributes); + info3++; + break; + + + } + } + NetApiBufferFree(buffer); + } + } while (status == ERROR_MORE_DATA); + + if (status != 0) { + printf("NetGroupEnum failed with: %s\n", + libnetapi_get_error_string(ctx, status)); + } + + out: + libnetapi_free(ctx); + poptFreeContext(pc); + + return status; +} -- cgit From 848558026f8c10366db07053714557a9840e8bc9 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 16 Jul 2008 16:42:21 +0200 Subject: netapi: use ConvertSidToStringSid in NetGetGroupInfo query. Guenther (This used to be commit d9d0cf6411a29d456735e980f9ac8ad75f3edfbd) --- source3/lib/netapi/examples/group/group_getinfo.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/group/group_getinfo.c b/source3/lib/netapi/examples/group/group_getinfo.c index 9a76996336..2e5b793905 100644 --- a/source3/lib/netapi/examples/group/group_getinfo.c +++ b/source3/lib/netapi/examples/group/group_getinfo.c @@ -39,6 +39,7 @@ int main(int argc, const char **argv) struct GROUP_INFO_1 *g1; struct GROUP_INFO_2 *g2; struct GROUP_INFO_3 *g3; + char *sid_str = NULL; poptContext pc; int opt; @@ -109,7 +110,11 @@ int main(int argc, const char **argv) g3 = (struct GROUP_INFO_3 *)buffer; printf("name: %s\n", g3->grpi3_name); printf("comment: %s\n", g3->grpi3_comment); -/* printf("group_sid: %p\n", g3->grpi3_group_sid);*/ + if (ConvertSidToStringSid(g3->grpi3_group_sid, + &sid_str)) { + printf("group_sid: %s\n", sid_str); + free(sid_str); + } printf("attributes: %d\n", g3->grpi3_attributes); break; } -- cgit From 4ee046a7914dc7ac2d7625fad9f8bf44fa8f72f9 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 18 Jul 2008 16:42:07 +0200 Subject: netapi: fix build warning for ConvertSidToStringSid(). Guenther (This used to be commit 5136daec0a35e7f099477409009672ddd960b684) --- source3/lib/netapi/sid.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/sid.c b/source3/lib/netapi/sid.c index 869bd0f763..4db98bf3d2 100644 --- a/source3/lib/netapi/sid.c +++ b/source3/lib/netapi/sid.c @@ -19,13 +19,13 @@ #include "includes.h" -#include "librpc/gen_ndr/libnetapi.h" +#include "lib/netapi/netapi.h" /**************************************************************** ****************************************************************/ -bool ConvertSidToStringSid(const struct domsid *sid, - char **sid_string) +int ConvertSidToStringSid(const struct domsid *sid, + char **sid_string) { char *ret; -- cgit From a5e1a7a9f706a7173168b1e6466212c4b2c3e3e7 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 18 Jul 2008 01:39:27 +0200 Subject: netapi: typo in NetGroupEnum example code. Guenther (This used to be commit b0c44d7e6cf321f84bd7b9cdb25635304bbfea81) --- source3/lib/netapi/examples/group/group_enum.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/group/group_enum.c b/source3/lib/netapi/examples/group/group_enum.c index a9b6ad96cb..fe2aee1dab 100644 --- a/source3/lib/netapi/examples/group/group_enum.c +++ b/source3/lib/netapi/examples/group/group_enum.c @@ -75,7 +75,7 @@ int main(int argc, const char **argv) level = atoi(poptGetArg(pc)); } - /* NetUserEnum */ + /* NetGroupEnum */ do { status = NetGroupEnum(hostname, -- cgit From d711db5811ccd8a56df5600770689b3c8fbc00e1 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 18 Jul 2008 01:10:31 +0200 Subject: netapi: fix NetUserAdd() against NT4. Guenther (This used to be commit 42c44d18eeb4d37e7c2e1209c421b3ec3a07ae28) --- source3/lib/netapi/user.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/user.c b/source3/lib/netapi/user.c index 0d8065dd7f..382704769d 100644 --- a/source3/lib/netapi/user.c +++ b/source3/lib/netapi/user.c @@ -241,6 +241,21 @@ WERROR NetUserAdd_r(struct libnetapi_ctx *ctx, &user_handle, 25, user_info); + + if (NT_STATUS_EQUAL(status, NT_STATUS(DCERPC_FAULT_INVALID_TAG))) { + + user_info->info23.info = info25.info; + + encode_pw_buffer(user_info->info23.password.data, + info1->usri1_password, STR_UNICODE); + SamOEMhashBlob(user_info->info23.password.data, 516, + &cli->user_session_key); + + status = rpccli_samr_SetUserInfo2(pipe_cli, ctx, + &user_handle, + 23, + user_info); + } } else { user_info->info21 = info25.info; status = rpccli_samr_SetUserInfo(pipe_cli, ctx, -- cgit From 0f966cfd8a123dcc6fcbd95c209b004b2b260ba6 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 18 Jul 2008 01:11:08 +0200 Subject: netapi: fix NetGroupDel() against NT4. Guenther (This used to be commit 55035d7240bd163abb155239029a03f399c8f41f) --- source3/lib/netapi/group.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/group.c b/source3/lib/netapi/group.c index d28e7578be..6d9ed18b68 100644 --- a/source3/lib/netapi/group.c +++ b/source3/lib/netapi/group.c @@ -313,11 +313,13 @@ WERROR NetGroupDel_r(struct libnetapi_ctx *ctx, goto done; } +#if 0 + /* breaks against NT4 */ if (!(info->attributes.attributes & SE_GROUP_ENABLED)) { werr = WERR_ACCESS_DENIED; goto done; } - +#endif status = rpccli_samr_QueryGroupMember(pipe_cli, ctx, &group_handle, &rid_array); -- cgit From f09df9b1869b7d95d7399b13b79ecf1f14b02f07 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 18 Jul 2008 01:11:32 +0200 Subject: netapi: fix NetGroupGetInfo() against NT4. Guenther (This used to be commit c0fea9c4d0d3d297972c052c17b9be6d0530e098) --- source3/lib/netapi/group.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/group.c b/source3/lib/netapi/group.c index 6d9ed18b68..f856ec0a13 100644 --- a/source3/lib/netapi/group.c +++ b/source3/lib/netapi/group.c @@ -659,6 +659,7 @@ WERROR NetGroupGetInfo_r(struct libnetapi_ctx *ctx, struct samr_Ids rids; struct samr_Ids types; union samr_GroupInfo *info = NULL; + bool group_info_all = false; ZERO_STRUCT(connect_handle); ZERO_STRUCT(domain_handle); @@ -721,13 +722,22 @@ WERROR NetGroupGetInfo_r(struct libnetapi_ctx *ctx, &group_handle, GROUPINFOALL2, &info); + if (NT_STATUS_EQUAL(status, NT_STATUS_INVALID_INFO_CLASS)) { + status = rpccli_samr_QueryGroupInfo(pipe_cli, ctx, + &group_handle, + GROUPINFOALL, + &info); + group_info_all = true; + } + if (!NT_STATUS_IS_OK(status)) { werr = ntstatus_to_werror(status); goto done; } werr = map_group_info_to_buffer(ctx, r->in.level, - &info->all2, domain_sid, rids.ids[0], + group_info_all ? &info->all : &info->all2, + domain_sid, rids.ids[0], r->out.buf); if (!W_ERROR_IS_OK(werr)) { goto done; -- cgit From 3f0da66d5cae7efb600080c054ab52ed5b5a650f Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 1 Jul 2008 20:14:36 +0200 Subject: netapi: add libnetapi_private_ctx and init function. Guenther (This used to be commit 45fff2d37ae21c76d100f66d9154f6add446f380) --- source3/lib/netapi/netapi.c | 28 ++++++++++++++++++++++++++++ source3/lib/netapi/netapi.h | 2 ++ source3/lib/netapi/netapi_private.h | 18 ++++++++++++++++++ 3 files changed, 48 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi.c b/source3/lib/netapi/netapi.c index cf1be00849..2cc636ffb7 100644 --- a/source3/lib/netapi/netapi.c +++ b/source3/lib/netapi/netapi.c @@ -30,8 +30,30 @@ static bool libnetapi_initialized = false; /**************************************************************** ****************************************************************/ +static NET_API_STATUS libnetapi_init_private_context(struct libnetapi_ctx *ctx) +{ + struct libnetapi_private_ctx *priv; + + if (!ctx) { + return W_ERROR_V(WERR_INVALID_PARAM); + } + + priv = TALLOC_ZERO_P(ctx, struct libnetapi_private_ctx); + if (!priv) { + return W_ERROR_V(WERR_NOMEM); + } + + ctx->private_data = priv; + + return NET_API_STATUS_SUCCESS; +} + +/**************************************************************** +****************************************************************/ + NET_API_STATUS libnetapi_init(struct libnetapi_ctx **context) { + NET_API_STATUS status; struct libnetapi_ctx *ctx = NULL; char *krb5_cc_env = NULL; @@ -96,6 +118,12 @@ NET_API_STATUS libnetapi_init(struct libnetapi_ctx **context) return W_ERROR_V(WERR_NOMEM); } + status = libnetapi_init_private_context(ctx); + if (status != 0) { + TALLOC_FREE(frame); + return status; + } + libnetapi_initialized = true; *context = stat_ctx = ctx; diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h index f6345afe67..3612fa8240 100644 --- a/source3/lib/netapi/netapi.h +++ b/source3/lib/netapi/netapi.h @@ -191,6 +191,8 @@ struct libnetapi_ctx { char *password; char *krb5_cc_env; int use_kerberos; + + void *private_data; }; /**************************************************************** diff --git a/source3/lib/netapi/netapi_private.h b/source3/lib/netapi/netapi_private.h index 3ce078c2b6..c913fe789d 100644 --- a/source3/lib/netapi/netapi_private.h +++ b/source3/lib/netapi/netapi_private.h @@ -20,6 +20,24 @@ #ifndef __LIB_NETAPI_PRIVATE_H__ #define __LIB_NETAPI_PRIVATE_H__ +struct libnetapi_private_ctx { + struct { + const char *domain_name; + struct dom_sid *domain_sid; + struct rpc_pipe_client *cli; + + uint32_t connect_mask; + struct policy_handle connect_handle; + + uint32_t domain_mask; + struct policy_handle domain_handle; + + uint32_t builtin_mask; + struct policy_handle builtin_handle; + } samr; + +}; + NET_API_STATUS libnetapi_get_password(struct libnetapi_ctx *ctx, char **password); NET_API_STATUS libnetapi_get_username(struct libnetapi_ctx *ctx, char **username); NET_API_STATUS libnetapi_set_error_string(struct libnetapi_ctx *ctx, const char *format, ...); -- cgit From 3b667f90aaefe3c5d064b18542ae3c5b3d4771cd Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 17 Jul 2008 19:47:59 +0200 Subject: netapi: add libnetapi_samr_close_domain/connect_handle. Guenther (This used to be commit b042787ec61bb5cb98f882ac7be8df1691a78921) --- source3/lib/netapi/netapi_private.h | 4 ++++ source3/lib/netapi/samr.c | 48 +++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi_private.h b/source3/lib/netapi/netapi_private.h index c913fe789d..cb08ed0394 100644 --- a/source3/lib/netapi/netapi_private.h +++ b/source3/lib/netapi/netapi_private.h @@ -64,5 +64,9 @@ WERROR libnetapi_samr_open_builtin_domain(TALLOC_CTX *mem_ctx, uint32_t builtin_mask, struct policy_handle *connect_handle, struct policy_handle *builtin_handle); +void libnetapi_samr_close_domain_handle(struct libnetapi_ctx *ctx, + struct policy_handle *handle); +void libnetapi_samr_close_connect_handle(struct libnetapi_ctx *ctx, + struct policy_handle *handle); #endif diff --git a/source3/lib/netapi/samr.c b/source3/lib/netapi/samr.c index 2346f7f956..5df50fe85b 100644 --- a/source3/lib/netapi/samr.c +++ b/source3/lib/netapi/samr.c @@ -143,3 +143,51 @@ WERROR libnetapi_samr_open_builtin_domain(TALLOC_CTX *mem_ctx, done: return werr; } + +/**************************************************************** +****************************************************************/ + +void libnetapi_samr_close_domain_handle(struct libnetapi_ctx *ctx, + struct policy_handle *handle) +{ + struct libnetapi_private_ctx *priv; + + if (!is_valid_policy_hnd(handle)) { + return; + } + + priv = talloc_get_type_abort(ctx->private_data, + struct libnetapi_private_ctx); + + if (!policy_hnd_equal(handle, &priv->samr.domain_handle)) { + return; + } + + rpccli_samr_Close(priv->samr.cli, ctx, handle); + + ZERO_STRUCT(priv->samr.domain_handle); +} + +/**************************************************************** +****************************************************************/ + +void libnetapi_samr_close_connect_handle(struct libnetapi_ctx *ctx, + struct policy_handle *handle) +{ + struct libnetapi_private_ctx *priv; + + if (!is_valid_policy_hnd(handle)) { + return; + } + + priv = talloc_get_type_abort(ctx->private_data, + struct libnetapi_private_ctx); + + if (!policy_hnd_equal(handle, &priv->samr.connect_handle)) { + return; + } + + rpccli_samr_Close(priv->samr.cli, ctx, handle); + + ZERO_STRUCT(priv->samr.connect_handle); +} -- cgit From 4704864338b62a57afb86986ed2d4a0ce0a97020 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 17 Jul 2008 19:56:25 +0200 Subject: netapi: add libnetapi_samr_close_builtin_handle(). Guenther (This used to be commit 05cad0d8b4205c052c607b1d36c121bb4c226ab1) --- source3/lib/netapi/netapi_private.h | 2 ++ source3/lib/netapi/samr.c | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi_private.h b/source3/lib/netapi/netapi_private.h index cb08ed0394..db4eb6f0a3 100644 --- a/source3/lib/netapi/netapi_private.h +++ b/source3/lib/netapi/netapi_private.h @@ -66,6 +66,8 @@ WERROR libnetapi_samr_open_builtin_domain(TALLOC_CTX *mem_ctx, struct policy_handle *builtin_handle); void libnetapi_samr_close_domain_handle(struct libnetapi_ctx *ctx, struct policy_handle *handle); +void libnetapi_samr_close_builtin_handle(struct libnetapi_ctx *ctx, + struct policy_handle *handle); void libnetapi_samr_close_connect_handle(struct libnetapi_ctx *ctx, struct policy_handle *handle); diff --git a/source3/lib/netapi/samr.c b/source3/lib/netapi/samr.c index 5df50fe85b..bd90067a6d 100644 --- a/source3/lib/netapi/samr.c +++ b/source3/lib/netapi/samr.c @@ -171,6 +171,30 @@ void libnetapi_samr_close_domain_handle(struct libnetapi_ctx *ctx, /**************************************************************** ****************************************************************/ +void libnetapi_samr_close_builtin_handle(struct libnetapi_ctx *ctx, + struct policy_handle *handle) +{ + struct libnetapi_private_ctx *priv; + + if (!is_valid_policy_hnd(handle)) { + return; + } + + priv = talloc_get_type_abort(ctx->private_data, + struct libnetapi_private_ctx); + + if (!policy_hnd_equal(handle, &priv->samr.builtin_handle)) { + return; + } + + rpccli_samr_Close(priv->samr.cli, ctx, handle); + + ZERO_STRUCT(priv->samr.builtin_handle); +} + +/**************************************************************** +****************************************************************/ + void libnetapi_samr_close_connect_handle(struct libnetapi_ctx *ctx, struct policy_handle *handle) { -- cgit From 6fa58fdc07743e5db71d9f27b67d14d8103aa2e9 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 17 Jul 2008 19:43:34 +0200 Subject: netapi: use private samr structure in libnetapi_samr_open_domain(). Guenther (This used to be commit 3c63ebfc00cda0334802bff1883ebbc3138a70f1) --- source3/lib/netapi/netapi_private.h | 2 +- source3/lib/netapi/samr.c | 48 ++++++++++++++++++++++++++++++++++++- 2 files changed, 48 insertions(+), 2 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi_private.h b/source3/lib/netapi/netapi_private.h index db4eb6f0a3..246672a349 100644 --- a/source3/lib/netapi/netapi_private.h +++ b/source3/lib/netapi/netapi_private.h @@ -51,7 +51,7 @@ WERROR libnetapi_open_pipe(struct libnetapi_ctx *ctx, struct cli_state *cli, int pipe_idx, struct rpc_pipe_client **pipe_cli); -WERROR libnetapi_samr_open_domain(TALLOC_CTX *mem_ctx, +WERROR libnetapi_samr_open_domain(struct libnetapi_ctx *mem_ctx, struct rpc_pipe_client *pipe_cli, uint32_t connect_mask, uint32_t domain_mask, diff --git a/source3/lib/netapi/samr.c b/source3/lib/netapi/samr.c index bd90067a6d..e83b8eba9c 100644 --- a/source3/lib/netapi/samr.c +++ b/source3/lib/netapi/samr.c @@ -18,11 +18,13 @@ */ #include "includes.h" +#include "lib/netapi/netapi.h" +#include "lib/netapi/netapi_private.h" /**************************************************************** ****************************************************************/ -WERROR libnetapi_samr_open_domain(TALLOC_CTX *mem_ctx, +WERROR libnetapi_samr_open_domain(struct libnetapi_ctx *mem_ctx, struct rpc_pipe_client *pipe_cli, uint32_t connect_mask, uint32_t domain_mask, @@ -32,6 +34,7 @@ WERROR libnetapi_samr_open_domain(TALLOC_CTX *mem_ctx, { NTSTATUS status; WERROR werr; + struct libnetapi_private_ctx *priv; uint32_t resume_handle = 0; uint32_t num_entries = 0; struct samr_SamArray *sam = NULL; @@ -40,6 +43,38 @@ WERROR libnetapi_samr_open_domain(TALLOC_CTX *mem_ctx, bool domain_found = true; int i; + priv = talloc_get_type_abort(mem_ctx->private_data, + struct libnetapi_private_ctx); + + if (is_valid_policy_hnd(&priv->samr.connect_handle)) { + if ((priv->samr.connect_mask & connect_mask) == connect_mask) { + *connect_handle = priv->samr.connect_handle; + } else { + libnetapi_samr_close_connect_handle(mem_ctx, + &priv->samr.connect_handle); + } + } + + if (is_valid_policy_hnd(&priv->samr.domain_handle)) { + if ((priv->samr.domain_mask & domain_mask) == domain_mask) { + *domain_handle = priv->samr.domain_handle; + } else { + libnetapi_samr_close_domain_handle(mem_ctx, + &priv->samr.domain_handle); + } + } + + if (priv->samr.domain_sid) { + *domain_sid = priv->samr.domain_sid; + } + + if (is_valid_policy_hnd(&priv->samr.connect_handle) && + ((priv->samr.connect_mask & connect_mask) == connect_mask) && + is_valid_policy_hnd(&priv->samr.domain_handle) && + (priv->samr.domain_mask & domain_mask) == domain_mask) { + return WERR_OK; + } + if (!is_valid_policy_hnd(connect_handle)) { status = rpccli_try_samr_connects(pipe_cli, mem_ctx, connect_mask, @@ -99,6 +134,17 @@ WERROR libnetapi_samr_open_domain(TALLOC_CTX *mem_ctx, goto done; } + priv->samr.cli = pipe_cli; + + priv->samr.domain_name = domain_name; + priv->samr.domain_sid = *domain_sid; + + priv->samr.connect_mask = connect_mask; + priv->samr.connect_handle = *connect_handle; + + priv->samr.domain_mask = domain_mask; + priv->samr.domain_handle = *domain_handle; + werr = WERR_OK; done: -- cgit From bbdf38d1d73e0424c3b4a6ee27c11b6751af2582 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 17 Jul 2008 20:16:10 +0200 Subject: netapi: use private samr structure in libnetapi_samr_open_builtin(). Guenther (This used to be commit 538ac493b71b4c880bb6fb0fc5fc2f15e1a19f95) --- source3/lib/netapi/netapi_private.h | 2 +- source3/lib/netapi/samr.c | 39 ++++++++++++++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 2 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi_private.h b/source3/lib/netapi/netapi_private.h index 246672a349..37c837d897 100644 --- a/source3/lib/netapi/netapi_private.h +++ b/source3/lib/netapi/netapi_private.h @@ -58,7 +58,7 @@ WERROR libnetapi_samr_open_domain(struct libnetapi_ctx *mem_ctx, struct policy_handle *connect_handle, struct policy_handle *domain_handle, struct dom_sid2 **domain_sid); -WERROR libnetapi_samr_open_builtin_domain(TALLOC_CTX *mem_ctx, +WERROR libnetapi_samr_open_builtin_domain(struct libnetapi_ctx *mem_ctx, struct rpc_pipe_client *pipe_cli, uint32_t connect_mask, uint32_t builtin_mask, diff --git a/source3/lib/netapi/samr.c b/source3/lib/netapi/samr.c index e83b8eba9c..19cf6cb338 100644 --- a/source3/lib/netapi/samr.c +++ b/source3/lib/netapi/samr.c @@ -154,7 +154,7 @@ WERROR libnetapi_samr_open_domain(struct libnetapi_ctx *mem_ctx, /**************************************************************** ****************************************************************/ -WERROR libnetapi_samr_open_builtin_domain(TALLOC_CTX *mem_ctx, +WERROR libnetapi_samr_open_builtin_domain(struct libnetapi_ctx *mem_ctx, struct rpc_pipe_client *pipe_cli, uint32_t connect_mask, uint32_t builtin_mask, @@ -163,6 +163,35 @@ WERROR libnetapi_samr_open_builtin_domain(TALLOC_CTX *mem_ctx, { NTSTATUS status; WERROR werr; + struct libnetapi_private_ctx *priv; + + priv = talloc_get_type_abort(mem_ctx->private_data, + struct libnetapi_private_ctx); + + if (is_valid_policy_hnd(&priv->samr.connect_handle)) { + if ((priv->samr.connect_mask & connect_mask) == connect_mask) { + *connect_handle = priv->samr.connect_handle; + } else { + libnetapi_samr_close_connect_handle(mem_ctx, + &priv->samr.connect_handle); + } + } + + if (is_valid_policy_hnd(&priv->samr.builtin_handle)) { + if ((priv->samr.builtin_mask & builtin_mask) == builtin_mask) { + *builtin_handle = priv->samr.builtin_handle; + } else { + libnetapi_samr_close_builtin_handle(mem_ctx, + &priv->samr.builtin_handle); + } + } + + if (is_valid_policy_hnd(&priv->samr.connect_handle) && + ((priv->samr.connect_mask & connect_mask) == connect_mask) && + is_valid_policy_hnd(&priv->samr.builtin_handle) && + (priv->samr.builtin_mask & builtin_mask) == builtin_mask) { + return WERR_OK; + } if (!is_valid_policy_hnd(connect_handle)) { status = rpccli_try_samr_connects(pipe_cli, mem_ctx, @@ -184,6 +213,14 @@ WERROR libnetapi_samr_open_builtin_domain(TALLOC_CTX *mem_ctx, goto done; } + priv->samr.cli = pipe_cli; + + priv->samr.connect_mask = connect_mask; + priv->samr.connect_handle = *connect_handle; + + priv->samr.builtin_mask = builtin_mask; + priv->samr.builtin_handle = *builtin_handle; + werr = WERR_OK; done: -- cgit From 352d40c0664919530f394c83fbbb7eb53adb1f31 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 17 Jul 2008 19:06:02 +0200 Subject: netapi: add libnetapi_samr_free(). Guenther (This used to be commit 3228088a0954ac25584d06a681f4e0615dee425c) --- source3/lib/netapi/netapi.c | 2 ++ source3/lib/netapi/netapi_private.h | 1 + source3/lib/netapi/samr.c | 19 +++++++++++++++++++ 3 files changed, 22 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi.c b/source3/lib/netapi/netapi.c index 2cc636ffb7..7d78aa8120 100644 --- a/source3/lib/netapi/netapi.c +++ b/source3/lib/netapi/netapi.c @@ -153,6 +153,8 @@ NET_API_STATUS libnetapi_free(struct libnetapi_ctx *ctx) return NET_API_STATUS_SUCCESS; } + libnetapi_samr_free(ctx); + libnetapi_shutdown_cm(ctx); if (ctx->krb5_cc_env) { diff --git a/source3/lib/netapi/netapi_private.h b/source3/lib/netapi/netapi_private.h index 37c837d897..915d60617f 100644 --- a/source3/lib/netapi/netapi_private.h +++ b/source3/lib/netapi/netapi_private.h @@ -70,5 +70,6 @@ void libnetapi_samr_close_builtin_handle(struct libnetapi_ctx *ctx, struct policy_handle *handle); void libnetapi_samr_close_connect_handle(struct libnetapi_ctx *ctx, struct policy_handle *handle); +void libnetapi_samr_free(struct libnetapi_ctx *ctx); #endif diff --git a/source3/lib/netapi/samr.c b/source3/lib/netapi/samr.c index 19cf6cb338..dbcef38dc7 100644 --- a/source3/lib/netapi/samr.c +++ b/source3/lib/netapi/samr.c @@ -298,3 +298,22 @@ void libnetapi_samr_close_connect_handle(struct libnetapi_ctx *ctx, ZERO_STRUCT(priv->samr.connect_handle); } + +/**************************************************************** +****************************************************************/ + +void libnetapi_samr_free(struct libnetapi_ctx *ctx) +{ + struct libnetapi_private_ctx *priv; + + if (!ctx->private_data) { + return; + } + + priv = talloc_get_type_abort(ctx->private_data, + struct libnetapi_private_ctx); + + libnetapi_samr_close_domain_handle(ctx, &priv->samr.domain_handle); + libnetapi_samr_close_builtin_handle(ctx, &priv->samr.builtin_handle); + libnetapi_samr_close_connect_handle(ctx, &priv->samr.connect_handle); +} -- cgit From 29e1bbcf001516eeba528c46f12de729093e6e54 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 17 Jul 2008 13:37:50 +0200 Subject: netapi: add new USER_INFO_X structures to public headers. Guenther (This used to be commit 4439edb0465630091e53fdcc2d647acc7abf1045) --- source3/lib/netapi/netapi.h | 140 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 140 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h index 3612fa8240..2260c28bf1 100644 --- a/source3/lib/netapi/netapi.h +++ b/source3/lib/netapi/netapi.h @@ -94,6 +94,146 @@ struct USER_INFO_1 { const char * usri1_script_path; }; +struct USER_INFO_2 { + const char * usri2_name; + const char * usri2_password; + uint32_t usri2_password_age; + uint32_t usri2_priv; + const char * usri2_home_dir; + const char * usri2_comment; + uint32_t usri2_flags; + const char * usri2_script_path; + uint32_t usri2_auth_flags; + const char * usri2_full_name; + const char * usri2_usr_comment; + const char * usri2_parms; + const char * usri2_workstations; + uint32_t usri2_last_logon; + uint32_t usri2_last_logoff; + uint32_t usri2_acct_expires; + uint32_t usri2_max_storage; + uint32_t usri2_units_per_week; + uint8_t *usri2_logon_hours;/* [unique] */ + uint32_t usri2_bad_pw_count; + uint32_t usri2_num_logons; + const char * usri2_logon_server; + uint32_t usri2_country_code; + uint32_t usri2_code_page; +}; + +struct USER_INFO_3 { + const char * usri3_name; + uint32_t usri3_password_age; + uint32_t usri3_priv; + const char * usri3_home_dir; + const char * usri3_comment; + uint32_t usri3_flags; + const char * usri3_script_path; + uint32_t usri3_auth_flags; + const char * usri3_full_name; + const char * usri3_usr_comment; + const char * usri3_parms; + const char * usri3_workstations; + uint32_t usri3_last_logon; + uint32_t usri3_last_logoff; + uint32_t usri3_acct_expires; + uint32_t usri3_max_storage; + uint32_t usri3_units_per_week; + uint8_t *usri3_logon_hours;/* [unique] */ + uint32_t usri3_bad_pw_count; + uint32_t usri3_num_logons; + const char * usri3_logon_server; + uint32_t usri3_country_code; + uint32_t usri3_code_page; + uint32_t usri3_user_id; + uint32_t usri3_primary_group_id; + const char * usri3_profile; + const char * usri3_home_dir_drive; + uint32_t usri3_password_expired; +}; + +struct USER_INFO_4 { + const char * usri4_name; + const char * usri4_password; + uint32_t usri4_password_age; + uint32_t usri4_priv; + const char * usri4_home_dir; + const char * usri4_comment; + uint32_t usri4_flags; + const char * usri4_script_path; + uint32_t usri4_auth_flags; + const char * usri4_full_name; + const char * usri4_usr_comment; + const char * usri4_parms; + const char * usri4_workstations; + uint32_t usri4_last_logon; + uint32_t usri4_last_logoff; + uint32_t usri4_acct_expires; + uint32_t usri4_max_storage; + uint32_t usri4_units_per_week; + uint8_t *usri4_logon_hours;/* [unique] */ + uint32_t usri4_bad_pw_count; + uint32_t usri4_num_logons; + const char * usri4_logon_server; + uint32_t usri4_country_code; + uint32_t usri4_code_page; + struct dom_sid *usri4_user_sid;/* [unique] */ + uint32_t usri4_primary_group_id; + const char * usri4_profile; + const char * usri4_home_dir_drive; + uint32_t usri4_password_expired; +}; + +struct USER_INFO_10 { + const char * usri10_name; + const char * usri10_comment; + const char * usri10_usr_comment; + const char * usri10_full_name; +}; + +struct USER_INFO_11 { + const char * usri11_name; + const char * usri11_comment; + const char * usri11_usr_comment; + const char * usri11_full_name; + uint32_t usri11_priv; + uint32_t usri11_auth_flags; + uint32_t usri11_password_age; + const char * usri11_home_dir; + const char * usri11_parms; + uint32_t usri11_last_logon; + uint32_t usri11_last_logoff; + uint32_t usri11_bad_pw_count; + uint32_t usri11_num_logons; + const char * usri11_logon_server; + uint32_t usri11_country_code; + const char * usri11_workstations; + uint32_t usri11_max_storage; + uint32_t usri11_units_per_week; + uint8_t *usri11_logon_hours;/* [unique] */ + uint32_t usri11_code_page; +}; + +struct USER_INFO_20 { + const char * usri20_name; + const char * usri20_full_name; + const char * usri20_comment; + uint32_t usri20_flags; + uint32_t usri20_user_id; +}; + +struct USER_INFO_23 { + const char * usri23_name; + const char * usri23_full_name; + const char * usri23_comment; + uint32_t usri23_flags; + struct domsid *usri23_user_sid;/* [unique] */ +}; + +struct USER_INFO_1007 { + const char * usri1007_comment; +}; + struct NET_DISPLAY_USER { const char * usri1_name; const char * usri1_comment; -- cgit From 11269b8923a64f67daea16b29a99962c9b93c6f4 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 17 Jul 2008 13:37:06 +0200 Subject: netapi: add support to define info level in NetUserEnum example. Guenther (This used to be commit 7cbc90c3e881fd54c97df553168e089ad7f2294c) --- source3/lib/netapi/examples/user/user_enum.c | 69 +++++++++++++++++++++++++--- 1 file changed, 63 insertions(+), 6 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/user/user_enum.c b/source3/lib/netapi/examples/user/user_enum.c index 569d5a62d6..cf77bf2d54 100644 --- a/source3/lib/netapi/examples/user/user_enum.c +++ b/source3/lib/netapi/examples/user/user_enum.c @@ -32,13 +32,18 @@ int main(int argc, const char **argv) NET_API_STATUS status; struct libnetapi_ctx *ctx = NULL; const char *hostname = NULL; + uint32_t level = 0; uint8_t *buffer = NULL; uint32_t entries_read = 0; uint32_t total_entries = 0; uint32_t resume_handle = 0; + char *sid_str = NULL; int i; - struct USER_INFO_0 *info0; + struct USER_INFO_0 *info0 = NULL; + struct USER_INFO_10 *info10 = NULL; + struct USER_INFO_20 *info20 = NULL; + struct USER_INFO_23 *info23 = NULL; poptContext pc; int opt; @@ -56,7 +61,7 @@ int main(int argc, const char **argv) pc = poptGetContext("user_enum", argc, argv, long_options, 0); - poptSetOtherOptionHelp(pc, "hostname"); + poptSetOtherOptionHelp(pc, "hostname level"); while((opt = poptGetNextOpt(pc)) != -1) { } @@ -66,11 +71,15 @@ int main(int argc, const char **argv) } hostname = poptGetArg(pc); + if (poptPeekArg(pc)) { + level = atoi(poptGetArg(pc)); + } + /* NetUserEnum */ do { status = NetUserEnum(hostname, - 0, + level, FILTER_NORMAL_ACCOUNT, &buffer, (uint32_t)-1, @@ -78,10 +87,58 @@ int main(int argc, const char **argv) &total_entries, &resume_handle); if (status == 0 || status == ERROR_MORE_DATA) { - info0 = (struct USER_INFO_0 *)buffer; + + switch (level) { + case 0: + info0 = (struct USER_INFO_0 *)buffer; + break; + case 10: + info10 = (struct USER_INFO_10 *)buffer; + break; + case 20: + info20 = (struct USER_INFO_20 *)buffer; + break; + case 23: + info23 = (struct USER_INFO_23 *)buffer; + break; + default: + break; + } + for (i=0; iusri0_name); - info0++; + switch (level) { + case 0: + printf("#%d user: %s\n", i, info0->usri0_name); + info0++; + break; + case 10: + printf("#%d user: %s\n", i, info10->usri10_name); + printf("#%d comment: %s\n", i, info10->usri10_comment); + printf("#%d usr_comment: %s\n", i, info10->usri10_usr_comment); + printf("#%d full_name: %s\n", i, info10->usri10_full_name); + info10++; + break; + case 20: + printf("#%d user: %s\n", i, info20->usri20_name); + printf("#%d comment: %s\n", i, info20->usri20_comment); + printf("#%d flags: 0x%08x\n", i, info20->usri20_flags); + printf("#%d rid: %d\n", i, info20->usri20_user_id); + info20++; + break; + case 23: + printf("#%d user: %s\n", i, info23->usri23_name); + printf("#%d comment: %s\n", i, info23->usri23_comment); + printf("#%d flags: 0x%08x\n", i, info23->usri23_flags); + if (ConvertSidToStringSid(info23->usri23_user_sid, + &sid_str)) { + printf("#%d sid: %s\n", i, sid_str); + free(sid_str); + } + info23++; + break; + default: + break; + } } NetApiBufferFree(buffer); } -- cgit From b6caa0de4cffb5ce2ea4aa6144901832ddbb9667 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 1 Jul 2008 20:19:10 +0200 Subject: netapi: support more infolevels in NetUserEnum. Guenther (This used to be commit 22bd3d401e47ffedf1169c0c74a329e9fdcac561) --- source3/lib/netapi/user.c | 274 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 245 insertions(+), 29 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/user.c b/source3/lib/netapi/user.c index 382704769d..8b1287e300 100644 --- a/source3/lib/netapi/user.c +++ b/source3/lib/netapi/user.c @@ -440,35 +440,229 @@ WERROR NetUserDel_l(struct libnetapi_ctx *ctx, /**************************************************************** ****************************************************************/ -static WERROR convert_samr_samarray_to_USER_INFO_buffer(TALLOC_CTX *mem_ctx, - struct samr_SamArray *sam_array, - uint32_t level, - uint8_t **buffer) +static NTSTATUS libnetapi_samr_lookup_user(TALLOC_CTX *mem_ctx, + struct rpc_pipe_client *pipe_cli, + struct policy_handle *domain_handle, + struct policy_handle *builtin_handle, + const char *user_name, + uint32_t rid, + uint32_t level, + struct samr_UserInfo21 **info21, + struct sec_desc_buf **sec_desc) { + NTSTATUS status; + + struct policy_handle user_handle; + union samr_UserInfo *user_info = NULL; + struct samr_RidWithAttributeArray *rid_array = NULL; + uint32_t access_mask = SEC_STD_READ_CONTROL | + SAMR_USER_ACCESS_GET_ATTRIBUTES | + SAMR_USER_ACCESS_GET_NAME_ETC; + + ZERO_STRUCT(user_handle); + + switch (level) { + case 0: + case 1: + case 2: + case 3: + case 10: + case 11: + case 20: + case 23: + break; + default: + return NT_STATUS_INVALID_LEVEL; + } + + if (level == 0) { + return NT_STATUS_OK; + } + + status = rpccli_samr_OpenUser(pipe_cli, mem_ctx, + domain_handle, + access_mask, + rid, + &user_handle); + if (!NT_STATUS_IS_OK(status)) { + goto done; + } + + status = rpccli_samr_QueryUserInfo(pipe_cli, mem_ctx, + &user_handle, + 21, + &user_info); + if (!NT_STATUS_IS_OK(status)) { + goto done; + } + + status = rpccli_samr_QuerySecurity(pipe_cli, mem_ctx, + &user_handle, + SECINFO_DACL, + sec_desc); + if (!NT_STATUS_IS_OK(status)) { + goto done; + } + + if (level == 1) { + status = rpccli_samr_GetGroupsForUser(pipe_cli, mem_ctx, + &user_handle, + &rid_array); + if (!NT_STATUS_IS_OK(status)) { + goto done; + } + +#if 0 + status = rpccli_samr_GetAliasMembership(pipe_cli, ctx, + &builtin_handle, + &sids, + &rids); + if (!NT_STATUS_IS_OK(status)) { + goto done; + } +#endif + } + + *info21 = &user_info->info21; + + done: + if (is_valid_policy_hnd(&user_handle)) { + rpccli_samr_Close(pipe_cli, mem_ctx, &user_handle); + } + + return status; +} + +/**************************************************************** +****************************************************************/ + +static NTSTATUS libnetapi_samr_lookup_user_map_USER_INFO(TALLOC_CTX *mem_ctx, + struct rpc_pipe_client *pipe_cli, + struct dom_sid *domain_sid, + struct policy_handle *domain_handle, + struct policy_handle *builtin_handle, + const char *user_name, + uint32_t rid, + uint32_t level, + uint8_t **buffer, + uint32_t *num_entries) +{ + NTSTATUS status; + + struct samr_UserInfo21 *info21 = NULL; + struct sec_desc_buf *sec_desc = NULL; + struct dom_sid sid; + struct USER_INFO_0 *info0 = NULL; - int i; + struct USER_INFO_10 *info10 = NULL; + struct USER_INFO_20 *info20 = NULL; + struct USER_INFO_23 *info23 = NULL; switch (level) { case 0: - info0 = TALLOC_ZERO_ARRAY(mem_ctx, struct USER_INFO_0, - sam_array->count); - W_ERROR_HAVE_NO_MEMORY(info0); - - for (i=0; icount; i++) { - info0[i].usri0_name = talloc_strdup(mem_ctx, - sam_array->entries[i].name.string); - W_ERROR_HAVE_NO_MEMORY(info0[i].usri0_name); + case 1: + case 2: + case 3: + case 10: + case 11: + case 20: + case 23: + break; + default: + return NT_STATUS_INVALID_LEVEL; + } + + if (level == 0) { + info0 = TALLOC_P(mem_ctx, struct USER_INFO_0); + NT_STATUS_HAVE_NO_MEMORY(info0); + + info0->usri0_name = talloc_strdup(mem_ctx, user_name); + NT_STATUS_HAVE_NO_MEMORY(info0->usri0_name); + + ADD_TO_ARRAY(mem_ctx, struct USER_INFO_0, *info0, + (struct USER_INFO_0 **)buffer, num_entries); + + return NT_STATUS_OK; + } + + status = libnetapi_samr_lookup_user(mem_ctx, pipe_cli, + domain_handle, + builtin_handle, + user_name, + rid, + level, + &info21, + &sec_desc); + + if (!NT_STATUS_IS_OK(status)) { + goto done; + } + + switch (level) { + case 10: + info10 = TALLOC_P(mem_ctx, struct USER_INFO_10); + NT_STATUS_HAVE_NO_MEMORY(info10); + + info10->usri10_name = talloc_strdup(mem_ctx, user_name); + NT_STATUS_HAVE_NO_MEMORY(info10->usri10_name); + + info10->usri10_comment = talloc_strdup(mem_ctx, + info21->description.string); + + info10->usri10_full_name = talloc_strdup(mem_ctx, + info21->full_name.string); + + info10->usri10_usr_comment = talloc_strdup(mem_ctx, + info21->comment.string); + + ADD_TO_ARRAY(mem_ctx, struct USER_INFO_10, *info10, + (struct USER_INFO_10 **)buffer, num_entries); + + break; + + case 20: + info20 = TALLOC_P(mem_ctx, struct USER_INFO_20); + NT_STATUS_HAVE_NO_MEMORY(info20); + + info20->usri20_name = talloc_strdup(mem_ctx, user_name); + NT_STATUS_HAVE_NO_MEMORY(info20->usri20_name); + + info20->usri20_comment = talloc_strdup(mem_ctx, + info21->description.string); + + info20->usri20_flags = info21->acct_flags; + info20->usri20_user_id = rid; + + ADD_TO_ARRAY(mem_ctx, struct USER_INFO_20, *info20, + (struct USER_INFO_20 **)buffer, num_entries); + + break; + case 23: + info23 = TALLOC_P(mem_ctx, struct USER_INFO_23); + NT_STATUS_HAVE_NO_MEMORY(info23); + + info23->usri23_name = talloc_strdup(mem_ctx, user_name); + NT_STATUS_HAVE_NO_MEMORY(info23->usri23_name); + + info23->usri23_comment = talloc_strdup(mem_ctx, + info21->description.string); + + info23->usri23_flags = info21->acct_flags; + + if (!sid_compose(&sid, domain_sid, rid)) { + return NT_STATUS_NO_MEMORY; } - *buffer = (uint8_t *)talloc_memdup(mem_ctx, info0, - sizeof(struct USER_INFO_0) * sam_array->count); - W_ERROR_HAVE_NO_MEMORY(*buffer); + info23->usri23_user_sid = + (struct domsid *)sid_dup_talloc(mem_ctx, &sid); + + ADD_TO_ARRAY(mem_ctx, struct USER_INFO_23, *info23, + (struct USER_INFO_23 **)buffer, num_entries); break; - default: - return WERR_NOT_SUPPORTED; } - return WERR_OK; + done: + return status; } /**************************************************************** @@ -484,23 +678,32 @@ WERROR NetUserEnum_r(struct libnetapi_ctx *ctx, struct policy_handle domain_handle; struct samr_SamArray *sam = NULL; uint32_t filter = ACB_NORMAL; + int i; + uint32_t entries_read = 0; - NTSTATUS status; + NTSTATUS status = NT_STATUS_OK; WERROR werr; ZERO_STRUCT(connect_handle); ZERO_STRUCT(domain_handle); + if (!r->out.buffer) { + return WERR_INVALID_PARAM; + } + + *r->out.buffer = NULL; + *r->out.entries_read = 0; + switch (r->in.level) { case 0: + case 10: + case 20: + case 23: break; case 1: case 2: case 3: - case 10: case 11: - case 20: - case 23: default: return WERR_NOT_SUPPORTED; } @@ -555,15 +758,28 @@ WERROR NetUserEnum_r(struct libnetapi_ctx *ctx, filter, &sam, r->in.prefmaxlen, - r->out.entries_read); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); + &entries_read); + werr = ntstatus_to_werror(status); + if (NT_STATUS_IS_ERR(status)) { goto done; } - werr = convert_samr_samarray_to_USER_INFO_buffer(ctx, sam, - r->in.level, - r->out.buffer); + for (i=0; i < sam->count; i++) { + + status = libnetapi_samr_lookup_user_map_USER_INFO(ctx, pipe_cli, + domain_sid, + &domain_handle, + NULL, /*&builtin_handle, */ + sam->entries[i].name.string, + sam->entries[i].idx, + r->in.level, + r->out.buffer, + r->out.entries_read); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + } done: if (!cli) { -- cgit From 668ce210ce8f280771625208e105f90e6375aee6 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 16 Jul 2008 10:47:38 +0200 Subject: netapi: add skeleton for NetUserGetInfo(). Guenther (This used to be commit 84962bf50d2c3265c0134481f24f6fa34f1dfc99) --- source3/lib/netapi/libnetapi.c | 46 ++++++++++++++++++++++++++++++++++++++++++ source3/lib/netapi/libnetapi.h | 8 ++++++++ source3/lib/netapi/user.c | 19 +++++++++++++++++ 3 files changed, 73 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/libnetapi.c b/source3/lib/netapi/libnetapi.c index 0953de6058..8013c74fd6 100644 --- a/source3/lib/netapi/libnetapi.c +++ b/source3/lib/netapi/libnetapi.c @@ -631,6 +631,52 @@ NET_API_STATUS NetUserChangePassword(const char * domain_name /* [in] */, return r.out.result; } +/**************************************************************** + NetUserGetInfo +****************************************************************/ + +NET_API_STATUS NetUserGetInfo(const char * server_name /* [in] */, + const char * user_name /* [in] */, + uint32_t level /* [in] */, + uint8_t **buffer /* [out] [ref] */) +{ + struct NetUserGetInfo r; + struct libnetapi_ctx *ctx = NULL; + NET_API_STATUS status; + WERROR werr; + + status = libnetapi_getctx(&ctx); + if (status != 0) { + return status; + } + + /* In parameters */ + r.in.server_name = server_name; + r.in.user_name = user_name; + r.in.level = level; + + /* Out parameters */ + r.out.buffer = buffer; + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_IN_DEBUG(NetUserGetInfo, &r); + } + + if (LIBNETAPI_LOCAL_SERVER(server_name)) { + werr = NetUserGetInfo_l(ctx, &r); + } else { + werr = NetUserGetInfo_r(ctx, &r); + } + + r.out.result = W_ERROR_V(werr); + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_OUT_DEBUG(NetUserGetInfo, &r); + } + + return r.out.result; +} + /**************************************************************** NetQueryDisplayInformation ****************************************************************/ diff --git a/source3/lib/netapi/libnetapi.h b/source3/lib/netapi/libnetapi.h index a6c8e84b6b..349c3c1d3c 100644 --- a/source3/lib/netapi/libnetapi.h +++ b/source3/lib/netapi/libnetapi.h @@ -108,6 +108,14 @@ WERROR NetUserChangePassword_r(struct libnetapi_ctx *ctx, struct NetUserChangePassword *r); WERROR NetUserChangePassword_l(struct libnetapi_ctx *ctx, struct NetUserChangePassword *r); +NET_API_STATUS NetUserGetInfo(const char * server_name /* [in] */, + const char * user_name /* [in] */, + uint32_t level /* [in] */, + uint8_t **buffer /* [out] [ref] */); +WERROR NetUserGetInfo_r(struct libnetapi_ctx *ctx, + struct NetUserGetInfo *r); +WERROR NetUserGetInfo_l(struct libnetapi_ctx *ctx, + struct NetUserGetInfo *r); NET_API_STATUS NetQueryDisplayInformation(const char * server_name /* [in] [unique] */, uint32_t level /* [in] */, uint32_t idx /* [in] */, diff --git a/source3/lib/netapi/user.c b/source3/lib/netapi/user.c index 8b1287e300..b5e64fb67d 100644 --- a/source3/lib/netapi/user.c +++ b/source3/lib/netapi/user.c @@ -1082,3 +1082,22 @@ WERROR NetUserChangePassword_l(struct libnetapi_ctx *ctx, { return WERR_NOT_SUPPORTED; } + +/**************************************************************** +****************************************************************/ + +WERROR NetUserGetInfo_r(struct libnetapi_ctx *ctx, + struct NetUserGetInfo *r) +{ + return WERR_NOT_SUPPORTED; +} + +/**************************************************************** +****************************************************************/ + +WERROR NetUserGetInfo_l(struct libnetapi_ctx *ctx, + struct NetUserGetInfo *r) +{ + return WERR_NOT_SUPPORTED; +} + -- cgit From 04463e29f3b10d8230e21bf2743e44fdbbed60c3 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 16 Jul 2008 10:50:26 +0200 Subject: netapi: add NetUserGetInfo to public headers. Guenther (This used to be commit 7260fb4dbae556b116e385bdcc240416e8a8cbd2) --- source3/lib/netapi/netapi.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h index 2260c28bf1..95ecbe35cd 100644 --- a/source3/lib/netapi/netapi.h +++ b/source3/lib/netapi/netapi.h @@ -686,6 +686,26 @@ NET_API_STATUS NetUserChangePassword(const char * domain_name /* [in] */, const char * old_password /* [in] */, const char * new_password /* [in] */); +/************************************************************//** + * + * NetUserGetInfo + * + * @brief Get User Information + * + * @param[in] server_name The server name to connect to + * @param[in] user_name The name of the user that is going to be queried + * @param[in] level The level defining the requested USER_INFO_X structure + * @param[out] buffer The buffer containing a USER_INFO_X structure + * @return NET_API_STATUS + * + * example user/user_getinfo.c + ***************************************************************/ + +NET_API_STATUS NetUserGetInfo(const char * server_name /* [in] */, + const char * user_name /* [in] */, + uint32_t level /* [in] */, + uint8_t **buffer /* [out] [ref] */); + /************************************************************//** * * NetQueryDisplayInformation -- cgit From 83ed7b3c079c8da148385a43a5996738ce84c7e9 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 16 Jul 2008 10:59:53 +0200 Subject: netapi: add NetUserGetInfo example code. Guenther (This used to be commit 62cdd66a7e91b986f76f94935f04375591671893) --- source3/lib/netapi/examples/Makefile.in | 6 + source3/lib/netapi/examples/user/user_getinfo.c | 144 ++++++++++++++++++++++++ 2 files changed, 150 insertions(+) create mode 100644 source3/lib/netapi/examples/user/user_getinfo.c (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/Makefile.in b/source3/lib/netapi/examples/Makefile.in index 47626348bf..f15b099949 100644 --- a/source3/lib/netapi/examples/Makefile.in +++ b/source3/lib/netapi/examples/Makefile.in @@ -27,6 +27,7 @@ PROGS = bin/getdc@EXEEXT@ \ bin/user_enum@EXEEXT@ \ bin/user_dispinfo@EXEEXT@ \ bin/user_chgpwd@EXEEXT@ \ + bin/user_getinfo@EXEEXT@ \ bin/group_add@EXEEXT@ \ bin/group_del@EXEEXT@ \ bin/group_enum@EXEEXT@ \ @@ -77,6 +78,7 @@ USERDEL_OBJ = user/user_del.o $(CMDLINE_OBJ) USERENUM_OBJ = user/user_enum.o $(CMDLINE_OBJ) USERDISPINFO_OBJ = user/user_dispinfo.o $(CMDLINE_OBJ) USERCHGPWD_OBJ = user/user_chgpwd.o $(CMDLINE_OBJ) +USERGETINFO_OBJ = user/user_getinfo.o $(CMDLINE_OBJ) GROUPADD_OBJ = group/group_add.o $(CMDLINE_OBJ) GROUPDEL_OBJ = group/group_del.o $(CMDLINE_OBJ) GROUPENUM_OBJ = group/group_enum.o $(CMDLINE_OBJ) @@ -130,6 +132,10 @@ bin/user_chgpwd@EXEEXT@: $(BINARY_PREREQS) $(USERCHGPWD_OBJ) @echo Linking $@ @$(CC) $(FLAGS) -o $@ $(USERCHGPWD_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) +bin/user_getinfo@EXEEXT@: $(BINARY_PREREQS) $(USERGETINFO_OBJ) + @echo Linking $@ + @$(CC) $(FLAGS) -o $@ $(USERGETINFO_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) + bin/group_add@EXEEXT@: $(BINARY_PREREQS) $(GROUPADD_OBJ) @echo Linking $@ @$(CC) $(FLAGS) -o $@ $(GROUPADD_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) diff --git a/source3/lib/netapi/examples/user/user_getinfo.c b/source3/lib/netapi/examples/user/user_getinfo.c new file mode 100644 index 0000000000..19234d0532 --- /dev/null +++ b/source3/lib/netapi/examples/user/user_getinfo.c @@ -0,0 +1,144 @@ +/* + * Unix SMB/CIFS implementation. + * NetUserGetInfo query + * Copyright (C) Guenther Deschner 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include +#include +#include +#include +#include + +#include + +#include "common.h" + +int main(int argc, const char **argv) +{ + NET_API_STATUS status; + struct libnetapi_ctx *ctx = NULL; + const char *hostname = NULL; + const char *username = NULL; + uint8_t *buffer = NULL; + uint32_t level = 0; + char *sid_str = NULL; + + struct USER_INFO_0 *u0; + struct USER_INFO_1 *u1; + struct USER_INFO_10 *u10; + struct USER_INFO_20 *u20; + struct USER_INFO_23 *u23; + + poptContext pc; + int opt; + + struct poptOption long_options[] = { + POPT_AUTOHELP + POPT_COMMON_LIBNETAPI_EXAMPLES + POPT_TABLEEND + }; + + status = libnetapi_init(&ctx); + if (status != 0) { + return status; + } + + pc = poptGetContext("user_getinfo", argc, argv, long_options, 0); + + poptSetOtherOptionHelp(pc, "hostname username level"); + while((opt = poptGetNextOpt(pc)) != -1) { + } + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + hostname = poptGetArg(pc); + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + username = poptGetArg(pc); + + if (poptPeekArg(pc)) { + level = atoi(poptGetArg(pc)); + } + + /* NetUserGetInfo */ + + status = NetUserGetInfo(hostname, + username, + level, + &buffer); + if (status != 0) { + printf("NetUserGetInfo failed with: %s\n", + libnetapi_get_error_string(ctx, status)); + goto out; + } + + switch (level) { + case 0: + u0 = (struct USER_INFO_0 *)buffer; + printf("name: %s\n", u0->usri0_name); + break; + case 1: + u1 = (struct USER_INFO_1 *)buffer; + printf("name: %s\n", u1->usri1_name); + printf("password: %s\n", u1->usri1_password); + printf("password_age: %d\n", u1->usri1_password_age); + printf("priv: %d\n", u1->usri1_priv); + printf("homedir: %s\n", u1->usri1_home_dir); + printf("comment: %s\n", u1->usri1_comment); + printf("flags: 0x%08x\n", u1->usri1_flags); + printf("script: %s\n", u1->usri1_script_path); + break; + case 10: + u10 = (struct USER_INFO_10 *)buffer; + printf("name: %s\n", u10->usri10_name); + printf("comment: %s\n", u10->usri10_comment); + printf("usr_comment: %s\n", u10->usri10_usr_comment); + printf("full_name: %s\n", u10->usri10_full_name); + break; + case 20: + u20 = (struct USER_INFO_20 *)buffer; + printf("name: %s\n", u20->usri20_name); + printf("comment: %s\n", u20->usri20_comment); + printf("flags: 0x%08x\n", u20->usri20_flags); + printf("rid: %d\n", u20->usri20_user_id); + break; + case 23: + u23 = (struct USER_INFO_23 *)buffer; + printf("name: %s\n", u23->usri23_name); + printf("comment: %s\n", u23->usri23_comment); + printf("flags: 0x%08x\n", u23->usri23_flags); + if (ConvertSidToStringSid(u23->usri23_user_sid, + &sid_str)) { + printf("user_sid: %s\n", sid_str); + free(sid_str); + } + break; + default: + break; + } + + out: + libnetapi_free(ctx); + poptFreeContext(pc); + + return status; +} -- cgit From 99b8d914303961b3d735898e6737468a4f4047d6 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 17 Jul 2008 22:45:09 +0200 Subject: netapi: fill in NetUserGetInfo_r(). Guenther (This used to be commit d282e5eca298c4c45cbe91a93350273d1417a050) --- source3/lib/netapi/user.c | 105 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 104 insertions(+), 1 deletion(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/user.c b/source3/lib/netapi/user.c index b5e64fb67d..b318aa66dc 100644 --- a/source3/lib/netapi/user.c +++ b/source3/lib/netapi/user.c @@ -1089,7 +1089,110 @@ WERROR NetUserChangePassword_l(struct libnetapi_ctx *ctx, WERROR NetUserGetInfo_r(struct libnetapi_ctx *ctx, struct NetUserGetInfo *r) { - return WERR_NOT_SUPPORTED; + struct cli_state *cli = NULL; + struct rpc_pipe_client *pipe_cli = NULL; + NTSTATUS status; + WERROR werr; + + struct policy_handle connect_handle, domain_handle, builtin_handle, user_handle; + struct lsa_String lsa_account_name; + struct dom_sid2 *domain_sid = NULL; + struct samr_Ids user_rids, name_types; + uint32_t num_entries = 0; + + ZERO_STRUCT(connect_handle); + ZERO_STRUCT(domain_handle); + ZERO_STRUCT(builtin_handle); + ZERO_STRUCT(user_handle); + + if (!r->out.buffer) { + return WERR_INVALID_PARAM; + } + + switch (r->in.level) { + case 0: + /* case 1: */ + case 10: + case 20: + case 23: + break; + default: + werr = WERR_NOT_SUPPORTED; + goto done; + } + + werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + werr = libnetapi_open_pipe(ctx, cli, PI_SAMR, &pipe_cli); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + werr = libnetapi_samr_open_domain(ctx, pipe_cli, + SAMR_ACCESS_ENUM_DOMAINS | + SAMR_ACCESS_OPEN_DOMAIN, + SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, + &connect_handle, + &domain_handle, + &domain_sid); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + werr = libnetapi_samr_open_builtin_domain(ctx, pipe_cli, + SAMR_ACCESS_ENUM_DOMAINS | + SAMR_ACCESS_OPEN_DOMAIN, + SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT | + SAMR_DOMAIN_ACCESS_LOOKUP_ALIAS, + &connect_handle, + &builtin_handle); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + init_lsa_String(&lsa_account_name, r->in.user_name); + + status = rpccli_samr_LookupNames(pipe_cli, ctx, + &domain_handle, + 1, + &lsa_account_name, + &user_rids, + &name_types); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + status = libnetapi_samr_lookup_user_map_USER_INFO(ctx, pipe_cli, + domain_sid, + &domain_handle, + &builtin_handle, + r->in.user_name, + user_rids.ids[0], + r->in.level, + r->out.buffer, + &num_entries); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + done: + if (!cli) { + return werr; + } + + if (is_valid_policy_hnd(&user_handle)) { + rpccli_samr_Close(pipe_cli, ctx, &user_handle); + } + + libnetapi_samr_close_domain_handle(ctx, &domain_handle); + libnetapi_samr_close_connect_handle(ctx, &connect_handle); + + return werr; } /**************************************************************** -- cgit From c7b151e78c704ff878d11894c2e22aa2454dcff0 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 17 Jul 2008 01:00:33 +0200 Subject: netapi: add skeleton for NetUserSetInfo. Guenther (This used to be commit 8cc555602f53f6afaded2eff58ed57f87b915c64) --- source3/lib/netapi/libnetapi.c | 48 ++++++++++++++++++++++++++++++++++++++++++ source3/lib/netapi/libnetapi.h | 9 ++++++++ source3/lib/netapi/user.c | 18 ++++++++++++++++ 3 files changed, 75 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/libnetapi.c b/source3/lib/netapi/libnetapi.c index 8013c74fd6..567fab6113 100644 --- a/source3/lib/netapi/libnetapi.c +++ b/source3/lib/netapi/libnetapi.c @@ -677,6 +677,54 @@ NET_API_STATUS NetUserGetInfo(const char * server_name /* [in] */, return r.out.result; } +/**************************************************************** + NetUserSetInfo +****************************************************************/ + +NET_API_STATUS NetUserSetInfo(const char * server_name /* [in] */, + const char * user_name /* [in] */, + uint32_t level /* [in] */, + uint8_t *buffer /* [in] [ref] */, + uint32_t *parm_err /* [out] [ref] */) +{ + struct NetUserSetInfo r; + struct libnetapi_ctx *ctx = NULL; + NET_API_STATUS status; + WERROR werr; + + status = libnetapi_getctx(&ctx); + if (status != 0) { + return status; + } + + /* In parameters */ + r.in.server_name = server_name; + r.in.user_name = user_name; + r.in.level = level; + r.in.buffer = buffer; + + /* Out parameters */ + r.out.parm_err = parm_err; + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_IN_DEBUG(NetUserSetInfo, &r); + } + + if (LIBNETAPI_LOCAL_SERVER(server_name)) { + werr = NetUserSetInfo_l(ctx, &r); + } else { + werr = NetUserSetInfo_r(ctx, &r); + } + + r.out.result = W_ERROR_V(werr); + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_OUT_DEBUG(NetUserSetInfo, &r); + } + + return r.out.result; +} + /**************************************************************** NetQueryDisplayInformation ****************************************************************/ diff --git a/source3/lib/netapi/libnetapi.h b/source3/lib/netapi/libnetapi.h index 349c3c1d3c..f104b72f30 100644 --- a/source3/lib/netapi/libnetapi.h +++ b/source3/lib/netapi/libnetapi.h @@ -116,6 +116,15 @@ WERROR NetUserGetInfo_r(struct libnetapi_ctx *ctx, struct NetUserGetInfo *r); WERROR NetUserGetInfo_l(struct libnetapi_ctx *ctx, struct NetUserGetInfo *r); +NET_API_STATUS NetUserSetInfo(const char * server_name /* [in] */, + const char * user_name /* [in] */, + uint32_t level /* [in] */, + uint8_t *buffer /* [in] [ref] */, + uint32_t *parm_err /* [out] [ref] */); +WERROR NetUserSetInfo_r(struct libnetapi_ctx *ctx, + struct NetUserSetInfo *r); +WERROR NetUserSetInfo_l(struct libnetapi_ctx *ctx, + struct NetUserSetInfo *r); NET_API_STATUS NetQueryDisplayInformation(const char * server_name /* [in] [unique] */, uint32_t level /* [in] */, uint32_t idx /* [in] */, diff --git a/source3/lib/netapi/user.c b/source3/lib/netapi/user.c index b318aa66dc..2c18cd0282 100644 --- a/source3/lib/netapi/user.c +++ b/source3/lib/netapi/user.c @@ -1204,3 +1204,21 @@ WERROR NetUserGetInfo_l(struct libnetapi_ctx *ctx, return WERR_NOT_SUPPORTED; } +/**************************************************************** +****************************************************************/ + +WERROR NetUserSetInfo_r(struct libnetapi_ctx *ctx, + struct NetUserSetInfo *r) +{ + return WERR_NOT_SUPPORTED; +} + +/**************************************************************** +****************************************************************/ + +WERROR NetUserSetInfo_l(struct libnetapi_ctx *ctx, + struct NetUserSetInfo *r) +{ + return WERR_NOT_SUPPORTED; +} + -- cgit From ce6db92d952de87ac22cf637aab4a5159531a70d Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 18 Jul 2008 01:40:14 +0200 Subject: netapi: add NetUserSetInfo to public header. Guenther (This used to be commit 0acf8352a3ca7deb2e3465be441f20d455eb802b) --- source3/lib/netapi/netapi.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h index 95ecbe35cd..9c3468d055 100644 --- a/source3/lib/netapi/netapi.h +++ b/source3/lib/netapi/netapi.h @@ -706,6 +706,28 @@ NET_API_STATUS NetUserGetInfo(const char * server_name /* [in] */, uint32_t level /* [in] */, uint8_t **buffer /* [out] [ref] */); +/************************************************************//** + * + * NetUserSetInfo + * + * @brief Set User Information + * + * @param[in] server_name The server name to connect to + * @param[in] user_name The name of the user that is going to be modified + * @param[in] level The level defining the requested USER_INFO_X structure + * @param[in] buf The buffer containing a USER_INFO_X structure + * @param[out] parm_err The returned parameter error number if any + * @return NET_API_STATUS + * + * example user/user_setinfo.c + ***************************************************************/ + +NET_API_STATUS NetUserSetInfo(const char * server_name /* [in] */, + const char * user_name /* [in] */, + uint32_t level /* [in] */, + uint8_t *buffer /* [in] [ref] */, + uint32_t *parm_err /* [out] [ref] */); + /************************************************************//** * * NetQueryDisplayInformation -- cgit From 10534fe878a1de3a41838ace8b796fee179913f4 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 18 Jul 2008 02:23:29 +0200 Subject: netapi: add NetUserSetInfo example code. Guenther (This used to be commit 5000d4c743b09665405776569782f46eeb6c2e36) --- source3/lib/netapi/examples/Makefile.in | 6 ++ source3/lib/netapi/examples/user/user_setinfo.c | 97 +++++++++++++++++++++++++ 2 files changed, 103 insertions(+) create mode 100644 source3/lib/netapi/examples/user/user_setinfo.c (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/Makefile.in b/source3/lib/netapi/examples/Makefile.in index f15b099949..b853f2f635 100644 --- a/source3/lib/netapi/examples/Makefile.in +++ b/source3/lib/netapi/examples/Makefile.in @@ -28,6 +28,7 @@ PROGS = bin/getdc@EXEEXT@ \ bin/user_dispinfo@EXEEXT@ \ bin/user_chgpwd@EXEEXT@ \ bin/user_getinfo@EXEEXT@ \ + bin/user_setinfo@EXEEXT@ \ bin/group_add@EXEEXT@ \ bin/group_del@EXEEXT@ \ bin/group_enum@EXEEXT@ \ @@ -79,6 +80,7 @@ USERENUM_OBJ = user/user_enum.o $(CMDLINE_OBJ) USERDISPINFO_OBJ = user/user_dispinfo.o $(CMDLINE_OBJ) USERCHGPWD_OBJ = user/user_chgpwd.o $(CMDLINE_OBJ) USERGETINFO_OBJ = user/user_getinfo.o $(CMDLINE_OBJ) +USERSETINFO_OBJ = user/user_setinfo.o $(CMDLINE_OBJ) GROUPADD_OBJ = group/group_add.o $(CMDLINE_OBJ) GROUPDEL_OBJ = group/group_del.o $(CMDLINE_OBJ) GROUPENUM_OBJ = group/group_enum.o $(CMDLINE_OBJ) @@ -136,6 +138,10 @@ bin/user_getinfo@EXEEXT@: $(BINARY_PREREQS) $(USERGETINFO_OBJ) @echo Linking $@ @$(CC) $(FLAGS) -o $@ $(USERGETINFO_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) +bin/user_setinfo@EXEEXT@: $(BINARY_PREREQS) $(USERSETINFO_OBJ) + @echo Linking $@ + @$(CC) $(FLAGS) -o $@ $(USERSETINFO_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) + bin/group_add@EXEEXT@: $(BINARY_PREREQS) $(GROUPADD_OBJ) @echo Linking $@ @$(CC) $(FLAGS) -o $@ $(GROUPADD_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) diff --git a/source3/lib/netapi/examples/user/user_setinfo.c b/source3/lib/netapi/examples/user/user_setinfo.c new file mode 100644 index 0000000000..ec464232e9 --- /dev/null +++ b/source3/lib/netapi/examples/user/user_setinfo.c @@ -0,0 +1,97 @@ +/* + * Unix SMB/CIFS implementation. + * NetUserSetInfo query + * Copyright (C) Guenther Deschner 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include +#include +#include +#include +#include + +#include + +#include "common.h" + +int main(int argc, const char **argv) +{ + NET_API_STATUS status; + struct libnetapi_ctx *ctx = NULL; + const char *hostname = NULL; + const char *username = NULL; + uint32_t level = 1007; + uint32_t parm_err = 0; + + struct USER_INFO_1007 u1007; + + poptContext pc; + int opt; + + struct poptOption long_options[] = { + POPT_AUTOHELP + POPT_COMMON_LIBNETAPI_EXAMPLES + POPT_TABLEEND + }; + + status = libnetapi_init(&ctx); + if (status != 0) { + return status; + } + + pc = poptGetContext("user_setinfo", argc, argv, long_options, 0); + + poptSetOtherOptionHelp(pc, "hostname username level"); + while((opt = poptGetNextOpt(pc)) != -1) { + } + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + hostname = poptGetArg(pc); + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + username = poptGetArg(pc); + + if (poptPeekArg(pc)) { + level = atoi(poptGetArg(pc)); + } + + /* NetUserSetInfo */ + + u1007.usri1007_comment = "NetApi test comment"; + + status = NetUserSetInfo(hostname, + username, + level, + (uint8_t *)&u1007, + &parm_err); + if (status != 0) { + printf("NetUserSetInfo failed with: %s\n", + libnetapi_get_error_string(ctx, status)); + goto out; + } + + out: + libnetapi_free(ctx); + poptFreeContext(pc); + + return status; +} -- cgit From 3e5dabc9687f8af8d1938b6a7c8472edff7ecbbb Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 18 Jul 2008 15:01:21 +0200 Subject: netapi: add libnetapi_samr_open_alias_queryinfo. Guenther (This used to be commit 401d6ce210817d9ab6915ed838e1495ae220559a) --- source3/lib/netapi/localgroup.c | 44 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/localgroup.c b/source3/lib/netapi/localgroup.c index d3a9aa1270..9237c2bdf4 100644 --- a/source3/lib/netapi/localgroup.c +++ b/source3/lib/netapi/localgroup.c @@ -73,6 +73,50 @@ static WERROR libnetapi_samr_lookup_and_open_alias(TALLOC_CTX *mem_ctx, /**************************************************************** ****************************************************************/ +static NTSTATUS libnetapi_samr_open_alias_queryinfo(TALLOC_CTX *mem_ctx, + struct rpc_pipe_client *pipe_cli, + struct policy_handle *handle, + uint32_t rid, + uint32_t access_rights, + enum samr_AliasInfoEnum level, + union samr_AliasInfo **alias_info) +{ + NTSTATUS status; + struct policy_handle alias_handle; + union samr_AliasInfo *_alias_info = NULL; + + ZERO_STRUCT(alias_handle); + + status = rpccli_samr_OpenAlias(pipe_cli, mem_ctx, + handle, + access_rights, + rid, + &alias_handle); + if (!NT_STATUS_IS_OK(status)) { + goto done; + } + + status = rpccli_samr_QueryAliasInfo(pipe_cli, mem_ctx, + &alias_handle, + level, + &_alias_info); + if (!NT_STATUS_IS_OK(status)) { + goto done; + } + + *alias_info = _alias_info; + + done: + if (is_valid_policy_hnd(&alias_handle)) { + rpccli_samr_Close(pipe_cli, mem_ctx, &alias_handle); + } + + return status; +} + +/**************************************************************** +****************************************************************/ + WERROR NetLocalGroupAdd_r(struct libnetapi_ctx *ctx, struct NetLocalGroupAdd *r) { -- cgit From 63c93682ace180d50f93b95386ccf60d48a30285 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 18 Jul 2008 15:10:43 +0200 Subject: netapi: make map_alias_info_to_buffer suitable for arrays in the buffer. Guenther (This used to be commit dc0f737bd5e86369b2bbfbef420a095205c2d3cb) --- source3/lib/netapi/localgroup.c | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/localgroup.c b/source3/lib/netapi/localgroup.c index 9237c2bdf4..d91045bab3 100644 --- a/source3/lib/netapi/localgroup.c +++ b/source3/lib/netapi/localgroup.c @@ -393,8 +393,10 @@ WERROR NetLocalGroupDel_l(struct libnetapi_ctx *ctx, ****************************************************************/ static WERROR map_alias_info_to_buffer(TALLOC_CTX *mem_ctx, + const char *alias_name, struct samr_AliasInfoAll *info, uint32_t level, + uint32_t *entries_read, uint8_t **buffer) { struct LOCALGROUP_INFO_0 g0; @@ -403,30 +405,33 @@ static WERROR map_alias_info_to_buffer(TALLOC_CTX *mem_ctx, switch (level) { case 0: - g0.lgrpi0_name = info->name.string; + g0.lgrpi0_name = talloc_strdup(mem_ctx, alias_name); + W_ERROR_HAVE_NO_MEMORY(g0.lgrpi0_name); - *buffer = (uint8_t *)talloc_memdup(mem_ctx, &g0, sizeof(g0)); + ADD_TO_ARRAY(mem_ctx, struct LOCALGROUP_INFO_0, g0, + (struct LOCALGROUP_INFO_0 **)buffer, entries_read); break; case 1: - g1.lgrpi1_name = info->name.string; - g1.lgrpi1_comment = info->description.string; + g1.lgrpi1_name = talloc_strdup(mem_ctx, alias_name); + g1.lgrpi1_comment = talloc_strdup(mem_ctx, info->description.string); + W_ERROR_HAVE_NO_MEMORY(g1.lgrpi1_name); - *buffer = (uint8_t *)talloc_memdup(mem_ctx, &g1, sizeof(g1)); + ADD_TO_ARRAY(mem_ctx, struct LOCALGROUP_INFO_1, g1, + (struct LOCALGROUP_INFO_1 **)buffer, entries_read); break; case 1002: - g1002.lgrpi1002_comment = info->description.string; + g1002.lgrpi1002_comment = talloc_strdup(mem_ctx, info->description.string); - *buffer = (uint8_t *)talloc_memdup(mem_ctx, &g1002, sizeof(g1002)); + ADD_TO_ARRAY(mem_ctx, struct LOCALGROUP_INFO_1002, g1002, + (struct LOCALGROUP_INFO_1002 **)buffer, entries_read); break; default: return WERR_UNKNOWN_LEVEL; } - W_ERROR_HAVE_NO_MEMORY(*buffer); - return WERR_OK; } @@ -444,6 +449,7 @@ WERROR NetLocalGroupGetInfo_r(struct libnetapi_ctx *ctx, struct policy_handle connect_handle, domain_handle, builtin_handle, alias_handle; struct dom_sid2 *domain_sid = NULL; union samr_AliasInfo *alias_info = NULL; + uint32_t entries_read = 0; if (!r->in.group_name) { return WERR_INVALID_PARAM; @@ -531,8 +537,11 @@ WERROR NetLocalGroupGetInfo_r(struct libnetapi_ctx *ctx, goto done; } - werr = map_alias_info_to_buffer(ctx, &alias_info->all, - r->in.level, r->out.buf); + werr = map_alias_info_to_buffer(ctx, + r->in.group_name, + &alias_info->all, + r->in.level, &entries_read, + r->out.buf); done: if (!cli) { -- cgit From d86068977c3aaa8ac127156fbee1f62e535b59d7 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 18 Jul 2008 01:23:26 +0200 Subject: netapi: add skeleton for NetLocalGroupEnum(). Guenther (This used to be commit 71bd0109d6c393d4361729b514e63fab113bf78a) --- source3/lib/netapi/libnetapi.c | 53 +++++++++++++++++++++++++++++++++++++++++ source3/lib/netapi/libnetapi.h | 11 +++++++++ source3/lib/netapi/localgroup.c | 18 ++++++++++++++ 3 files changed, 82 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/libnetapi.c b/source3/lib/netapi/libnetapi.c index 567fab6113..1ebe338f6c 100644 --- a/source3/lib/netapi/libnetapi.c +++ b/source3/lib/netapi/libnetapi.c @@ -1282,6 +1282,59 @@ NET_API_STATUS NetLocalGroupSetInfo(const char * server_name /* [in] */, return r.out.result; } +/**************************************************************** + NetLocalGroupEnum +****************************************************************/ + +NET_API_STATUS NetLocalGroupEnum(const char * server_name /* [in] */, + uint32_t level /* [in] */, + uint8_t **buffer /* [out] [ref] */, + uint32_t prefmaxlen /* [in] */, + uint32_t *entries_read /* [out] [ref] */, + uint32_t *total_entries /* [out] [ref] */, + uint32_t *resume_handle /* [in,out] [ref] */) +{ + struct NetLocalGroupEnum r; + struct libnetapi_ctx *ctx = NULL; + NET_API_STATUS status; + WERROR werr; + + status = libnetapi_getctx(&ctx); + if (status != 0) { + return status; + } + + /* In parameters */ + r.in.server_name = server_name; + r.in.level = level; + r.in.prefmaxlen = prefmaxlen; + r.in.resume_handle = resume_handle; + + /* Out parameters */ + r.out.buffer = buffer; + r.out.entries_read = entries_read; + r.out.total_entries = total_entries; + r.out.resume_handle = resume_handle; + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_IN_DEBUG(NetLocalGroupEnum, &r); + } + + if (LIBNETAPI_LOCAL_SERVER(server_name)) { + werr = NetLocalGroupEnum_l(ctx, &r); + } else { + werr = NetLocalGroupEnum_r(ctx, &r); + } + + r.out.result = W_ERROR_V(werr); + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_OUT_DEBUG(NetLocalGroupEnum, &r); + } + + return r.out.result; +} + /**************************************************************** NetRemoteTOD ****************************************************************/ diff --git a/source3/lib/netapi/libnetapi.h b/source3/lib/netapi/libnetapi.h index f104b72f30..774a0ac269 100644 --- a/source3/lib/netapi/libnetapi.h +++ b/source3/lib/netapi/libnetapi.h @@ -223,6 +223,17 @@ WERROR NetLocalGroupSetInfo_r(struct libnetapi_ctx *ctx, struct NetLocalGroupSetInfo *r); WERROR NetLocalGroupSetInfo_l(struct libnetapi_ctx *ctx, struct NetLocalGroupSetInfo *r); +NET_API_STATUS NetLocalGroupEnum(const char * server_name /* [in] */, + uint32_t level /* [in] */, + uint8_t **buffer /* [out] [ref] */, + uint32_t prefmaxlen /* [in] */, + uint32_t *entries_read /* [out] [ref] */, + uint32_t *total_entries /* [out] [ref] */, + uint32_t *resume_handle /* [in,out] [ref] */); +WERROR NetLocalGroupEnum_r(struct libnetapi_ctx *ctx, + struct NetLocalGroupEnum *r); +WERROR NetLocalGroupEnum_l(struct libnetapi_ctx *ctx, + struct NetLocalGroupEnum *r); NET_API_STATUS NetRemoteTOD(const char * server_name /* [in] */, uint8_t **buf /* [out] [ref] */); WERROR NetRemoteTOD_r(struct libnetapi_ctx *ctx, diff --git a/source3/lib/netapi/localgroup.c b/source3/lib/netapi/localgroup.c index d91045bab3..1069fde738 100644 --- a/source3/lib/netapi/localgroup.c +++ b/source3/lib/netapi/localgroup.c @@ -752,3 +752,21 @@ WERROR NetLocalGroupSetInfo_l(struct libnetapi_ctx *ctx, { return NetLocalGroupSetInfo_r(ctx, r); } + +/**************************************************************** +****************************************************************/ + +WERROR NetLocalGroupEnum_r(struct libnetapi_ctx *ctx, + struct NetLocalGroupEnum *r) +{ + return WERR_NOT_SUPPORTED; +} + +/**************************************************************** +****************************************************************/ + +WERROR NetLocalGroupEnum_l(struct libnetapi_ctx *ctx, + struct NetLocalGroupEnum *r) +{ + return WERR_NOT_SUPPORTED; +} -- cgit From ca2296f19f65e77dd65aac2c849f8f1db5d210df Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 18 Jul 2008 01:40:34 +0200 Subject: netapi: add NetLocalGroupEnum to public header. Guenther (This used to be commit 151c8fa7901983a3e7a82f1af599c839249b6cd7) --- source3/lib/netapi/netapi.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h index 9c3468d055..300bae59ea 100644 --- a/source3/lib/netapi/netapi.h +++ b/source3/lib/netapi/netapi.h @@ -978,6 +978,34 @@ NET_API_STATUS NetLocalGroupSetInfo(const char * server_name /* [in] */, uint8_t *buf /* [in] [ref] */, uint32_t *parm_err /* [out] [ref] */); +/************************************************************//** + * + * NetLocalGroupEnum + * + * @brief Enumerate local groups on a server + * + * @param[in] server_name The server name to connect to + * @param[in] level The enumeration level used for the query (Currently only + * level 0 is supported) + * @param[out] buffer The returned enumeration buffer + * @param[in] prefmaxlen The requested maximal buffer size + * @param[out] entries_read The number of returned entries + * @param[out] total_entries The number of total entries + * @param[in,out] resume_handle A handle passed in and returned for resuming + * operations + * @return NET_API_STATUS + * + * example localgroup/localgroup_enum.c + ***************************************************************/ + +NET_API_STATUS NetLocalGroupEnum(const char * server_name /* [in] */, + uint32_t level /* [in] */, + uint8_t **buffer /* [out] [ref] */, + uint32_t prefmaxlen /* [in] */, + uint32_t *entries_read /* [out] [ref] */, + uint32_t *total_entries /* [out] [ref] */, + uint32_t *resume_handle /* [in,out] [ref] */); + /************************************************************//** * * NetRemoteTOD -- cgit From 0c9014da442f04cde27b8e1d93f25c81b30043e3 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 18 Jul 2008 01:41:30 +0200 Subject: netapi: add NetLocalGroupEnum example code. Guenther (This used to be commit a5a8d03699220e1f237debb84a75cacbbb8899fa) --- source3/lib/netapi/examples/Makefile.in | 6 + .../netapi/examples/localgroup/localgroup_enum.c | 126 +++++++++++++++++++++ 2 files changed, 132 insertions(+) create mode 100644 source3/lib/netapi/examples/localgroup/localgroup_enum.c (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/Makefile.in b/source3/lib/netapi/examples/Makefile.in index b853f2f635..ca387ee79c 100644 --- a/source3/lib/netapi/examples/Makefile.in +++ b/source3/lib/netapi/examples/Makefile.in @@ -40,6 +40,7 @@ PROGS = bin/getdc@EXEEXT@ \ bin/localgroup_del@EXEEXT@ \ bin/localgroup_getinfo@EXEEXT@ \ bin/localgroup_setinfo@EXEEXT@ \ + bin/localgroup_enum@EXEEXT@ \ bin/remote_tod@EXEEXT@ all: $(PROGS) @@ -92,6 +93,7 @@ LOCALGROUPADD_OBJ = localgroup/localgroup_add.o $(CMDLINE_OBJ) LOCALGROUPDEL_OBJ = localgroup/localgroup_del.o $(CMDLINE_OBJ) LOCALGROUPGETINFO_OBJ = localgroup/localgroup_getinfo.o $(CMDLINE_OBJ) LOCALGROUPSETINFO_OBJ = localgroup/localgroup_setinfo.o $(CMDLINE_OBJ) +LOCALGROUPENUM_OBJ = localgroup/localgroup_enum.o $(CMDLINE_OBJ) REMOTETOD_OBJ = server/remote_tod.o $(CMDLINE_OBJ) bin/getdc@EXEEXT@: $(BINARY_PREREQS) $(GETDC_OBJ) @@ -186,6 +188,10 @@ bin/localgroup_setinfo@EXEEXT@: $(BINARY_PREREQS) $(LOCALGROUPSETINFO_OBJ) @echo Linking $@ @$(CC) $(FLAGS) -o $@ $(LOCALGROUPSETINFO_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) +bin/localgroup_enum@EXEEXT@: $(BINARY_PREREQS) $(LOCALGROUPENUM_OBJ) + @echo Linking $@ + @$(CC) $(FLAGS) -o $@ $(LOCALGROUPENUM_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) + bin/remote_tod@EXEEXT@: $(BINARY_PREREQS) $(REMOTETOD_OBJ) @echo Linking $@ @$(CC) $(FLAGS) -o $@ $(REMOTETOD_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) diff --git a/source3/lib/netapi/examples/localgroup/localgroup_enum.c b/source3/lib/netapi/examples/localgroup/localgroup_enum.c new file mode 100644 index 0000000000..6fe0cf4173 --- /dev/null +++ b/source3/lib/netapi/examples/localgroup/localgroup_enum.c @@ -0,0 +1,126 @@ +/* + * Unix SMB/CIFS implementation. + * NetLocalGroupEnum query + * Copyright (C) Guenther Deschner 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include +#include +#include +#include +#include + +#include + +#include "common.h" + +int main(int argc, const char **argv) +{ + NET_API_STATUS status; + struct libnetapi_ctx *ctx = NULL; + const char *hostname = NULL; + uint32_t level = 0; + uint8_t *buffer = NULL; + uint32_t entries_read = 0; + uint32_t total_entries = 0; + uint32_t resume_handle = 0; + int i; + + struct LOCALGROUP_INFO_0 *info0 = NULL; + struct LOCALGROUP_INFO_1 *info1 = NULL; + + poptContext pc; + int opt; + + struct poptOption long_options[] = { + POPT_AUTOHELP + POPT_COMMON_LIBNETAPI_EXAMPLES + POPT_TABLEEND + }; + + status = libnetapi_init(&ctx); + if (status != 0) { + return status; + } + + pc = poptGetContext("localgroup_enum", argc, argv, long_options, 0); + + poptSetOtherOptionHelp(pc, "hostname level"); + while((opt = poptGetNextOpt(pc)) != -1) { + } + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + hostname = poptGetArg(pc); + + if (poptPeekArg(pc)) { + level = atoi(poptGetArg(pc)); + } + + /* NetLocalGroupEnum */ + + do { + status = NetLocalGroupEnum(hostname, + level, + &buffer, + (uint32_t)-1, + &entries_read, + &total_entries, + &resume_handle); + if (status == 0 || status == ERROR_MORE_DATA) { + printf("total entries: %d\n", total_entries); + switch (level) { + case 0: + info0 = (struct LOCALGROUP_INFO_0 *)buffer; + break; + case 1: + info1 = (struct LOCALGROUP_INFO_1 *)buffer; + break; + default: + break; + } + for (i=0; ilgrpi0_name); + info0++; + break; + case 1: + printf("#%d group: %s\n", i, info1->lgrpi1_name); + printf("#%d comment: %s\n", i, info1->lgrpi1_comment); + info1++; + break; + default: + break; + } + } + NetApiBufferFree(buffer); + } + } while (status == ERROR_MORE_DATA); + + if (status != 0) { + printf("NetLocalGroupEnum failed with: %s\n", + libnetapi_get_error_string(ctx, status)); + } + + out: + libnetapi_free(ctx); + poptFreeContext(pc); + + return status; +} -- cgit From 3d140562fa67a468828c46c703cc3c3de23fa113 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 18 Jul 2008 15:11:08 +0200 Subject: netapi: implement NetLocalGroupEnum_r. Guenther (This used to be commit 2cd91e7d4d4847e1daef2585b09da4e6da6c9d11) --- source3/lib/netapi/localgroup.c | 166 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 165 insertions(+), 1 deletion(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/localgroup.c b/source3/lib/netapi/localgroup.c index 1069fde738..a7dc5e4752 100644 --- a/source3/lib/netapi/localgroup.c +++ b/source3/lib/netapi/localgroup.c @@ -759,7 +759,171 @@ WERROR NetLocalGroupSetInfo_l(struct libnetapi_ctx *ctx, WERROR NetLocalGroupEnum_r(struct libnetapi_ctx *ctx, struct NetLocalGroupEnum *r) { - return WERR_NOT_SUPPORTED; + struct cli_state *cli = NULL; + struct rpc_pipe_client *pipe_cli = NULL; + NTSTATUS status; + WERROR werr; + struct policy_handle connect_handle, domain_handle, builtin_handle, alias_handle; + struct dom_sid2 *domain_sid = NULL; + uint32_t entries_read = 0; + union samr_DomainInfo *domain_info = NULL; + union samr_DomainInfo *builtin_info = NULL; + struct samr_SamArray *domain_sam_array = NULL; + struct samr_SamArray *builtin_sam_array = NULL; + int i; + + if (!r->out.buffer) { + return WERR_INVALID_PARAM; + } + + switch (r->in.level) { + case 0: + case 1: + break; + default: + return WERR_UNKNOWN_LEVEL; + } + + ZERO_STRUCT(connect_handle); + ZERO_STRUCT(builtin_handle); + ZERO_STRUCT(domain_handle); + ZERO_STRUCT(alias_handle); + + werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + werr = libnetapi_open_pipe(ctx, cli, PI_SAMR, &pipe_cli); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + werr = libnetapi_samr_open_builtin_domain(ctx, pipe_cli, + SAMR_ACCESS_OPEN_DOMAIN | + SAMR_ACCESS_ENUM_DOMAINS, + SAMR_DOMAIN_ACCESS_LOOKUP_INFO_2 | + SAMR_DOMAIN_ACCESS_ENUM_ACCOUNTS | + SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, + &connect_handle, + &builtin_handle); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + werr = libnetapi_samr_open_domain(ctx, pipe_cli, + SAMR_ACCESS_OPEN_DOMAIN | + SAMR_ACCESS_ENUM_DOMAINS, + SAMR_DOMAIN_ACCESS_LOOKUP_INFO_2 | + SAMR_DOMAIN_ACCESS_ENUM_ACCOUNTS | + SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, + &connect_handle, + &domain_handle, + &domain_sid); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + status = rpccli_samr_QueryDomainInfo(pipe_cli, ctx, + &builtin_handle, + 2, + &builtin_info); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + status = rpccli_samr_QueryDomainInfo(pipe_cli, ctx, + &domain_handle, + 2, + &domain_info); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + status = rpccli_samr_EnumDomainAliases(pipe_cli, ctx, + &builtin_handle, + r->in.resume_handle, + &builtin_sam_array, + r->in.prefmaxlen, + &entries_read); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + for (i=0; icount; i++) { + union samr_AliasInfo *alias_info = NULL; + + if (r->in.level == 1) { + + status = libnetapi_samr_open_alias_queryinfo(ctx, pipe_cli, + &builtin_handle, + builtin_sam_array->entries[i].idx, + SAMR_ALIAS_ACCESS_LOOKUP_INFO, + ALIASINFOALL, + &alias_info); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + } + + werr = map_alias_info_to_buffer(ctx, + builtin_sam_array->entries[i].name.string, + alias_info ? &alias_info->all : NULL, + r->in.level, + r->out.entries_read, + r->out.buffer); + } + + status = rpccli_samr_EnumDomainAliases(pipe_cli, ctx, + &domain_handle, + r->in.resume_handle, + &domain_sam_array, + r->in.prefmaxlen, + &entries_read); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + for (i=0; icount; i++) { + + union samr_AliasInfo *alias_info = NULL; + + if (r->in.level == 1) { + status = libnetapi_samr_open_alias_queryinfo(ctx, pipe_cli, + &domain_handle, + domain_sam_array->entries[i].idx, + SAMR_ALIAS_ACCESS_LOOKUP_INFO, + ALIASINFOALL, + &alias_info); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + } + + werr = map_alias_info_to_buffer(ctx, + domain_sam_array->entries[i].name.string, + alias_info ? &alias_info->all : NULL, + r->in.level, + r->out.entries_read, + r->out.buffer); + } + + done: + if (!cli) { + return werr; + } + + libnetapi_samr_close_domain_handle(ctx, &domain_handle); + libnetapi_samr_close_builtin_handle(ctx, &builtin_handle); + libnetapi_samr_close_connect_handle(ctx, &connect_handle); + + return werr; } /**************************************************************** -- cgit From 6565087b7313b4ebaa1cc6df8ff888f3fd49ecf6 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 18 Jul 2008 16:24:02 +0200 Subject: netapi: let libnetapi_samr_lookup_and_open_alias compose lsa string. Guenther (This used to be commit f93090037798ffb4d9b875a4320f970ae10a64b6) --- source3/lib/netapi/localgroup.c | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/localgroup.c b/source3/lib/netapi/localgroup.c index a7dc5e4752..2c1e9dfc4c 100644 --- a/source3/lib/netapi/localgroup.c +++ b/source3/lib/netapi/localgroup.c @@ -27,18 +27,22 @@ static WERROR libnetapi_samr_lookup_and_open_alias(TALLOC_CTX *mem_ctx, struct rpc_pipe_client *pipe_cli, struct policy_handle *domain_handle, - struct lsa_String *lsa_account_name, + const char *group_name, uint32_t access_rights, struct policy_handle *alias_handle) { NTSTATUS status; WERROR werr; + + struct lsa_String lsa_account_name; struct samr_Ids user_rids, name_types; + init_lsa_String(&lsa_account_name, group_name); + status = rpccli_samr_LookupNames(pipe_cli, mem_ctx, domain_handle, 1, - lsa_account_name, + &lsa_account_name, &user_rids, &name_types); if (!NT_STATUS_IS_OK(status)) { @@ -177,11 +181,9 @@ WERROR NetLocalGroupAdd_r(struct libnetapi_ctx *ctx, goto done; } - init_lsa_String(&lsa_account_name, alias_name); - werr = libnetapi_samr_lookup_and_open_alias(ctx, pipe_cli, &builtin_handle, - &lsa_account_name, + alias_name, SAMR_ALIAS_ACCESS_LOOKUP_INFO, &alias_handle); @@ -275,7 +277,6 @@ WERROR NetLocalGroupDel_r(struct libnetapi_ctx *ctx, struct rpc_pipe_client *pipe_cli = NULL; NTSTATUS status; WERROR werr; - struct lsa_String lsa_account_name; struct policy_handle connect_handle, domain_handle, builtin_handle, alias_handle; struct dom_sid2 *domain_sid = NULL; @@ -308,11 +309,9 @@ WERROR NetLocalGroupDel_r(struct libnetapi_ctx *ctx, goto done; } - init_lsa_String(&lsa_account_name, r->in.group_name); - werr = libnetapi_samr_lookup_and_open_alias(ctx, pipe_cli, &builtin_handle, - &lsa_account_name, + r->in.group_name, SEC_STD_DELETE, &alias_handle); @@ -336,7 +335,7 @@ WERROR NetLocalGroupDel_r(struct libnetapi_ctx *ctx, werr = libnetapi_samr_lookup_and_open_alias(ctx, pipe_cli, &domain_handle, - &lsa_account_name, + r->in.group_name, SEC_STD_DELETE, &alias_handle); @@ -445,7 +444,6 @@ WERROR NetLocalGroupGetInfo_r(struct libnetapi_ctx *ctx, struct rpc_pipe_client *pipe_cli = NULL; NTSTATUS status; WERROR werr; - struct lsa_String lsa_account_name; struct policy_handle connect_handle, domain_handle, builtin_handle, alias_handle; struct dom_sid2 *domain_sid = NULL; union samr_AliasInfo *alias_info = NULL; @@ -489,11 +487,9 @@ WERROR NetLocalGroupGetInfo_r(struct libnetapi_ctx *ctx, goto done; } - init_lsa_String(&lsa_account_name, r->in.group_name); - werr = libnetapi_samr_lookup_and_open_alias(ctx, pipe_cli, &builtin_handle, - &lsa_account_name, + r->in.group_name, SAMR_ALIAS_ACCESS_LOOKUP_INFO, &alias_handle); @@ -517,7 +513,7 @@ WERROR NetLocalGroupGetInfo_r(struct libnetapi_ctx *ctx, werr = libnetapi_samr_lookup_and_open_alias(ctx, pipe_cli, &domain_handle, - &lsa_account_name, + r->in.group_name, SAMR_ALIAS_ACCESS_LOOKUP_INFO, &alias_handle); @@ -672,7 +668,7 @@ WERROR NetLocalGroupSetInfo_r(struct libnetapi_ctx *ctx, werr = libnetapi_samr_lookup_and_open_alias(ctx, pipe_cli, &builtin_handle, - &lsa_account_name, + r->in.group_name, SAMR_ALIAS_ACCESS_SET_INFO, &alias_handle); @@ -695,7 +691,7 @@ WERROR NetLocalGroupSetInfo_r(struct libnetapi_ctx *ctx, werr = libnetapi_samr_lookup_and_open_alias(ctx, pipe_cli, &domain_handle, - &lsa_account_name, + r->in.group_name, SAMR_ALIAS_ACCESS_SET_INFO, &alias_handle); if (!W_ERROR_IS_OK(werr)) { -- cgit From c703304f557021c78ba0ad24e9b2e7b42147b8fd Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 17 Jul 2008 22:44:24 +0200 Subject: netapi: add caching of samr policy handles. Guenther (This used to be commit bf8453da9af1be788955204cc581c5143a854072) --- source3/lib/netapi/group.c | 73 ++++++++++++++++------------------ source3/lib/netapi/localgroup.c | 88 +++++++++++++++++++++-------------------- source3/lib/netapi/netapi.h | 1 + source3/lib/netapi/user.c | 56 ++++++++++++++------------ 4 files changed, 112 insertions(+), 106 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/group.c b/source3/lib/netapi/group.c index f856ec0a13..15580b3c22 100644 --- a/source3/lib/netapi/group.c +++ b/source3/lib/netapi/group.c @@ -204,11 +204,10 @@ WERROR NetGroupAdd_r(struct libnetapi_ctx *ctx, if (is_valid_policy_hnd(&group_handle)) { rpccli_samr_Close(pipe_cli, ctx, &group_handle); } - if (is_valid_policy_hnd(&domain_handle)) { - rpccli_samr_Close(pipe_cli, ctx, &domain_handle); - } - if (is_valid_policy_hnd(&connect_handle)) { - rpccli_samr_Close(pipe_cli, ctx, &connect_handle); + + if (ctx->disable_policy_handle_cache) { + libnetapi_samr_close_domain_handle(ctx, &domain_handle); + libnetapi_samr_close_connect_handle(ctx, &connect_handle); } return werr; @@ -374,11 +373,10 @@ WERROR NetGroupDel_r(struct libnetapi_ctx *ctx, if (is_valid_policy_hnd(&group_handle)) { rpccli_samr_Close(pipe_cli, ctx, &group_handle); } - if (is_valid_policy_hnd(&domain_handle)) { - rpccli_samr_Close(pipe_cli, ctx, &domain_handle); - } - if (is_valid_policy_hnd(&connect_handle)) { - rpccli_samr_Close(pipe_cli, ctx, &connect_handle); + + if (ctx->disable_policy_handle_cache) { + libnetapi_samr_close_domain_handle(ctx, &domain_handle); + libnetapi_samr_close_connect_handle(ctx, &connect_handle); } return werr; @@ -562,11 +560,10 @@ WERROR NetGroupSetInfo_r(struct libnetapi_ctx *ctx, if (is_valid_policy_hnd(&group_handle)) { rpccli_samr_Close(pipe_cli, ctx, &group_handle); } - if (is_valid_policy_hnd(&domain_handle)) { - rpccli_samr_Close(pipe_cli, ctx, &domain_handle); - } - if (is_valid_policy_hnd(&connect_handle)) { - rpccli_samr_Close(pipe_cli, ctx, &connect_handle); + + if (ctx->disable_policy_handle_cache) { + libnetapi_samr_close_domain_handle(ctx, &domain_handle); + libnetapi_samr_close_connect_handle(ctx, &connect_handle); } return werr; @@ -750,11 +747,10 @@ WERROR NetGroupGetInfo_r(struct libnetapi_ctx *ctx, if (is_valid_policy_hnd(&group_handle)) { rpccli_samr_Close(pipe_cli, ctx, &group_handle); } - if (is_valid_policy_hnd(&domain_handle)) { - rpccli_samr_Close(pipe_cli, ctx, &domain_handle); - } - if (is_valid_policy_hnd(&connect_handle)) { - rpccli_samr_Close(pipe_cli, ctx, &connect_handle); + + if (ctx->disable_policy_handle_cache) { + libnetapi_samr_close_domain_handle(ctx, &domain_handle); + libnetapi_samr_close_connect_handle(ctx, &connect_handle); } return werr; @@ -880,11 +876,10 @@ WERROR NetGroupAddUser_r(struct libnetapi_ctx *ctx, if (is_valid_policy_hnd(&group_handle)) { rpccli_samr_Close(pipe_cli, ctx, &group_handle); } - if (is_valid_policy_hnd(&domain_handle)) { - rpccli_samr_Close(pipe_cli, ctx, &domain_handle); - } - if (is_valid_policy_hnd(&connect_handle)) { - rpccli_samr_Close(pipe_cli, ctx, &connect_handle); + + if (ctx->disable_policy_handle_cache) { + libnetapi_samr_close_domain_handle(ctx, &domain_handle); + libnetapi_samr_close_connect_handle(ctx, &connect_handle); } return werr; @@ -1009,11 +1004,10 @@ WERROR NetGroupDelUser_r(struct libnetapi_ctx *ctx, if (is_valid_policy_hnd(&group_handle)) { rpccli_samr_Close(pipe_cli, ctx, &group_handle); } - if (is_valid_policy_hnd(&domain_handle)) { - rpccli_samr_Close(pipe_cli, ctx, &domain_handle); - } - if (is_valid_policy_hnd(&connect_handle)) { - rpccli_samr_Close(pipe_cli, ctx, &connect_handle); + + if (ctx->disable_policy_handle_cache) { + libnetapi_samr_close_domain_handle(ctx, &domain_handle); + libnetapi_samr_close_connect_handle(ctx, &connect_handle); } return werr; @@ -1195,7 +1189,7 @@ WERROR NetGroupEnum_r(struct libnetapi_ctx *ctx, uint32_t total_size = 0; uint32_t returned_size = 0; - NTSTATUS status; + NTSTATUS status = NT_STATUS_OK; WERROR werr, tmp_werr; ZERO_STRUCT(connect_handle); @@ -1283,14 +1277,17 @@ WERROR NetGroupEnum_r(struct libnetapi_ctx *ctx, if (!cli) { return werr; } -#if 0 - if (is_valid_policy_hnd(&domain_handle)) { - rpccli_samr_Close(pipe_cli, ctx, &domain_handle); - } - if (is_valid_policy_hnd(&connect_handle)) { - rpccli_samr_Close(pipe_cli, ctx, &connect_handle); + + /* if last query */ + if (NT_STATUS_IS_OK(status) || + NT_STATUS_IS_ERR(status)) { + + if (ctx->disable_policy_handle_cache) { + libnetapi_samr_close_domain_handle(ctx, &domain_handle); + libnetapi_samr_close_connect_handle(ctx, &connect_handle); + } } -#endif + return werr; } diff --git a/source3/lib/netapi/localgroup.c b/source3/lib/netapi/localgroup.c index 2c1e9dfc4c..faf57cc5fa 100644 --- a/source3/lib/netapi/localgroup.c +++ b/source3/lib/netapi/localgroup.c @@ -187,7 +187,9 @@ WERROR NetLocalGroupAdd_r(struct libnetapi_ctx *ctx, SAMR_ALIAS_ACCESS_LOOKUP_INFO, &alias_handle); - rpccli_samr_Close(pipe_cli, ctx, &builtin_handle); + if (ctx->disable_policy_handle_cache) { + libnetapi_samr_close_builtin_handle(ctx, &builtin_handle); + } if (W_ERROR_IS_OK(werr)) { werr = WERR_ALIAS_EXISTS; @@ -244,14 +246,11 @@ WERROR NetLocalGroupAdd_r(struct libnetapi_ctx *ctx, if (is_valid_policy_hnd(&alias_handle)) { rpccli_samr_Close(pipe_cli, ctx, &alias_handle); } - if (is_valid_policy_hnd(&domain_handle)) { - rpccli_samr_Close(pipe_cli, ctx, &domain_handle); - } - if (is_valid_policy_hnd(&builtin_handle)) { - rpccli_samr_Close(pipe_cli, ctx, &builtin_handle); - } - if (is_valid_policy_hnd(&connect_handle)) { - rpccli_samr_Close(pipe_cli, ctx, &connect_handle); + + if (ctx->disable_policy_handle_cache) { + libnetapi_samr_close_domain_handle(ctx, &domain_handle); + libnetapi_samr_close_builtin_handle(ctx, &builtin_handle); + libnetapi_samr_close_connect_handle(ctx, &connect_handle); } return werr; @@ -315,7 +314,9 @@ WERROR NetLocalGroupDel_r(struct libnetapi_ctx *ctx, SEC_STD_DELETE, &alias_handle); - rpccli_samr_Close(pipe_cli, ctx, &builtin_handle); + if (ctx->disable_policy_handle_cache) { + libnetapi_samr_close_builtin_handle(ctx, &builtin_handle); + } if (W_ERROR_IS_OK(werr)) { goto delete_alias; @@ -339,7 +340,9 @@ WERROR NetLocalGroupDel_r(struct libnetapi_ctx *ctx, SEC_STD_DELETE, &alias_handle); - rpccli_samr_Close(pipe_cli, ctx, &domain_handle); + if (ctx->disable_policy_handle_cache) { + libnetapi_samr_close_domain_handle(ctx, &domain_handle); + } if (!W_ERROR_IS_OK(werr)) { goto done; @@ -366,14 +369,11 @@ WERROR NetLocalGroupDel_r(struct libnetapi_ctx *ctx, if (is_valid_policy_hnd(&alias_handle)) { rpccli_samr_Close(pipe_cli, ctx, &alias_handle); } - if (is_valid_policy_hnd(&domain_handle)) { - rpccli_samr_Close(pipe_cli, ctx, &domain_handle); - } - if (is_valid_policy_hnd(&builtin_handle)) { - rpccli_samr_Close(pipe_cli, ctx, &builtin_handle); - } - if (is_valid_policy_hnd(&connect_handle)) { - rpccli_samr_Close(pipe_cli, ctx, &connect_handle); + + if (ctx->disable_policy_handle_cache) { + libnetapi_samr_close_domain_handle(ctx, &domain_handle); + libnetapi_samr_close_builtin_handle(ctx, &builtin_handle); + libnetapi_samr_close_connect_handle(ctx, &connect_handle); } return werr; @@ -493,7 +493,9 @@ WERROR NetLocalGroupGetInfo_r(struct libnetapi_ctx *ctx, SAMR_ALIAS_ACCESS_LOOKUP_INFO, &alias_handle); - rpccli_samr_Close(pipe_cli, ctx, &builtin_handle); + if (ctx->disable_policy_handle_cache) { + libnetapi_samr_close_builtin_handle(ctx, &builtin_handle); + } if (W_ERROR_IS_OK(werr)) { goto query_alias; @@ -517,7 +519,9 @@ WERROR NetLocalGroupGetInfo_r(struct libnetapi_ctx *ctx, SAMR_ALIAS_ACCESS_LOOKUP_INFO, &alias_handle); - rpccli_samr_Close(pipe_cli, ctx, &domain_handle); + if (ctx->disable_policy_handle_cache) { + libnetapi_samr_close_domain_handle(ctx, &domain_handle); + } if (!W_ERROR_IS_OK(werr)) { goto done; @@ -547,14 +551,11 @@ WERROR NetLocalGroupGetInfo_r(struct libnetapi_ctx *ctx, if (is_valid_policy_hnd(&alias_handle)) { rpccli_samr_Close(pipe_cli, ctx, &alias_handle); } - if (is_valid_policy_hnd(&domain_handle)) { - rpccli_samr_Close(pipe_cli, ctx, &domain_handle); - } - if (is_valid_policy_hnd(&builtin_handle)) { - rpccli_samr_Close(pipe_cli, ctx, &builtin_handle); - } - if (is_valid_policy_hnd(&connect_handle)) { - rpccli_samr_Close(pipe_cli, ctx, &connect_handle); + + if (ctx->disable_policy_handle_cache) { + libnetapi_samr_close_domain_handle(ctx, &domain_handle); + libnetapi_samr_close_builtin_handle(ctx, &builtin_handle); + libnetapi_samr_close_connect_handle(ctx, &connect_handle); } return werr; @@ -672,7 +673,9 @@ WERROR NetLocalGroupSetInfo_r(struct libnetapi_ctx *ctx, SAMR_ALIAS_ACCESS_SET_INFO, &alias_handle); - rpccli_samr_Close(pipe_cli, ctx, &builtin_handle); + if (ctx->disable_policy_handle_cache) { + libnetapi_samr_close_builtin_handle(ctx, &builtin_handle); + } if (W_ERROR_IS_OK(werr)) { goto set_alias; @@ -698,7 +701,9 @@ WERROR NetLocalGroupSetInfo_r(struct libnetapi_ctx *ctx, goto done; } - rpccli_samr_Close(pipe_cli, ctx, &domain_handle); + if (ctx->disable_policy_handle_cache) { + libnetapi_samr_close_domain_handle(ctx, &domain_handle); + } set_alias: @@ -727,14 +732,11 @@ WERROR NetLocalGroupSetInfo_r(struct libnetapi_ctx *ctx, if (is_valid_policy_hnd(&alias_handle)) { rpccli_samr_Close(pipe_cli, ctx, &alias_handle); } - if (is_valid_policy_hnd(&domain_handle)) { - rpccli_samr_Close(pipe_cli, ctx, &domain_handle); - } - if (is_valid_policy_hnd(&builtin_handle)) { - rpccli_samr_Close(pipe_cli, ctx, &builtin_handle); - } - if (is_valid_policy_hnd(&connect_handle)) { - rpccli_samr_Close(pipe_cli, ctx, &connect_handle); + + if (ctx->disable_policy_handle_cache) { + libnetapi_samr_close_domain_handle(ctx, &domain_handle); + libnetapi_samr_close_builtin_handle(ctx, &builtin_handle); + libnetapi_samr_close_connect_handle(ctx, &connect_handle); } return werr; @@ -915,9 +917,11 @@ WERROR NetLocalGroupEnum_r(struct libnetapi_ctx *ctx, return werr; } - libnetapi_samr_close_domain_handle(ctx, &domain_handle); - libnetapi_samr_close_builtin_handle(ctx, &builtin_handle); - libnetapi_samr_close_connect_handle(ctx, &connect_handle); + if (ctx->disable_policy_handle_cache) { + libnetapi_samr_close_domain_handle(ctx, &domain_handle); + libnetapi_samr_close_builtin_handle(ctx, &builtin_handle); + libnetapi_samr_close_connect_handle(ctx, &connect_handle); + } return werr; } diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h index 300bae59ea..7d32ffcbae 100644 --- a/source3/lib/netapi/netapi.h +++ b/source3/lib/netapi/netapi.h @@ -331,6 +331,7 @@ struct libnetapi_ctx { char *password; char *krb5_cc_env; int use_kerberos; + int disable_policy_handle_cache; void *private_data; }; diff --git a/source3/lib/netapi/user.c b/source3/lib/netapi/user.c index 2c18cd0282..8d69536848 100644 --- a/source3/lib/netapi/user.c +++ b/source3/lib/netapi/user.c @@ -284,11 +284,10 @@ WERROR NetUserAdd_r(struct libnetapi_ctx *ctx, if (is_valid_policy_hnd(&user_handle)) { rpccli_samr_Close(pipe_cli, ctx, &user_handle); } - if (is_valid_policy_hnd(&domain_handle)) { - rpccli_samr_Close(pipe_cli, ctx, &domain_handle); - } - if (is_valid_policy_hnd(&connect_handle)) { - rpccli_samr_Close(pipe_cli, ctx, &connect_handle); + + if (ctx->disable_policy_handle_cache) { + libnetapi_samr_close_domain_handle(ctx, &domain_handle); + libnetapi_samr_close_connect_handle(ctx, &connect_handle); } return werr; @@ -410,14 +409,11 @@ WERROR NetUserDel_r(struct libnetapi_ctx *ctx, if (is_valid_policy_hnd(&user_handle)) { rpccli_samr_Close(pipe_cli, ctx, &user_handle); } - if (is_valid_policy_hnd(&builtin_handle)) { - rpccli_samr_Close(pipe_cli, ctx, &builtin_handle); - } - if (is_valid_policy_hnd(&domain_handle)) { - rpccli_samr_Close(pipe_cli, ctx, &domain_handle); - } - if (is_valid_policy_hnd(&connect_handle)) { - rpccli_samr_Close(pipe_cli, ctx, &connect_handle); + + if (ctx->disable_policy_handle_cache) { + libnetapi_samr_close_builtin_handle(ctx, &builtin_handle); + libnetapi_samr_close_domain_handle(ctx, &domain_handle); + libnetapi_samr_close_connect_handle(ctx, &connect_handle); } return werr; @@ -786,11 +782,14 @@ WERROR NetUserEnum_r(struct libnetapi_ctx *ctx, return werr; } - if (is_valid_policy_hnd(&domain_handle)) { - rpccli_samr_Close(pipe_cli, ctx, &domain_handle); - } - if (is_valid_policy_hnd(&connect_handle)) { - rpccli_samr_Close(pipe_cli, ctx, &connect_handle); + /* if last query */ + if (NT_STATUS_IS_OK(status) || + NT_STATUS_IS_ERR(status)) { + + if (ctx->disable_policy_handle_cache) { + libnetapi_samr_close_domain_handle(ctx, &domain_handle); + libnetapi_samr_close_connect_handle(ctx, &connect_handle); + } } return werr; @@ -982,7 +981,7 @@ WERROR NetQueryDisplayInformation_r(struct libnetapi_ctx *ctx, uint32_t total_size = 0; uint32_t returned_size = 0; - NTSTATUS status; + NTSTATUS status = NT_STATUS_OK; WERROR werr; ZERO_STRUCT(connect_handle); @@ -1044,11 +1043,14 @@ WERROR NetQueryDisplayInformation_r(struct libnetapi_ctx *ctx, return werr; } - if (is_valid_policy_hnd(&domain_handle)) { - rpccli_samr_Close(pipe_cli, ctx, &domain_handle); - } - if (is_valid_policy_hnd(&connect_handle)) { - rpccli_samr_Close(pipe_cli, ctx, &connect_handle); + /* if last query */ + if (NT_STATUS_IS_OK(status) || + NT_STATUS_IS_ERR(status)) { + + if (ctx->disable_policy_handle_cache) { + libnetapi_samr_close_domain_handle(ctx, &domain_handle); + libnetapi_samr_close_connect_handle(ctx, &connect_handle); + } } return werr; @@ -1189,8 +1191,10 @@ WERROR NetUserGetInfo_r(struct libnetapi_ctx *ctx, rpccli_samr_Close(pipe_cli, ctx, &user_handle); } - libnetapi_samr_close_domain_handle(ctx, &domain_handle); - libnetapi_samr_close_connect_handle(ctx, &connect_handle); + if (ctx->disable_policy_handle_cache) { + libnetapi_samr_close_domain_handle(ctx, &domain_handle); + libnetapi_samr_close_connect_handle(ctx, &connect_handle); + } return werr; } -- cgit From 1335da2a7cc639310e5d389e8e8dbe67c4e7ca25 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 20 Jul 2008 11:04:31 +0200 Subject: Refactoring: Change calling conventions for cli_rpc_pipe_open_noauth Pass in ndr_syntax_id instead of pipe_idx, return NTSTATUS (This used to be commit 9abc9dc4dc13bd3e42f98eff64eacf24b51f5779) --- source3/lib/netapi/cm.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/cm.c b/source3/lib/netapi/cm.c index ae1091c504..fe5490c73b 100644 --- a/source3/lib/netapi/cm.c +++ b/source3/lib/netapi/cm.c @@ -132,8 +132,9 @@ static struct rpc_pipe_client *pipe_cm_connect(TALLOC_CTX *mem_ctx, return NULL; } - p->pipe = cli_rpc_pipe_open_noauth(cli, pipe_idx, status); - if (!p->pipe) { + *status = cli_rpc_pipe_open_noauth(cli, cli_get_iface(pipe_idx), + &p->pipe); + if (!NT_STATUS_IS_OK(*status)) { TALLOC_FREE(p); return NULL; } -- cgit From 798b56edaec88206b0d61d2852af41777d53aef2 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 20 Jul 2008 17:59:30 +0200 Subject: Refactoring: libnetapi_open_pipe takes an interface instead of pipe_idx (This used to be commit 726e56c72fdb685ab5eddefd2fd8b043dc38d6ad) --- source3/lib/netapi/cm.c | 76 ++++++++++++++++++------------------- source3/lib/netapi/getdc.c | 9 +++-- source3/lib/netapi/group.c | 21 ++++++---- source3/lib/netapi/joindomain.c | 12 ++++-- source3/lib/netapi/localgroup.c | 15 +++++--- source3/lib/netapi/netapi_private.h | 4 +- source3/lib/netapi/serverinfo.c | 9 +++-- source3/lib/netapi/user.c | 15 +++++--- 8 files changed, 93 insertions(+), 68 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/cm.c b/source3/lib/netapi/cm.c index fe5490c73b..8eaabb3cda 100644 --- a/source3/lib/netapi/cm.c +++ b/source3/lib/netapi/cm.c @@ -91,75 +91,70 @@ static struct client_pipe_connection *pipe_connections; /******************************************************************** ********************************************************************/ -static struct rpc_pipe_client *pipe_cm_find(struct cli_state *cli, - int pipe_idx, - NTSTATUS *status) +static NTSTATUS pipe_cm_find(struct cli_state *cli, + const struct ndr_syntax_id *interface, + struct rpc_pipe_client **presult) { struct client_pipe_connection *p; for (p = pipe_connections; p; p = p->next) { if (!rpc_pipe_np_smb_conn(p->pipe)) { - *status = NT_STATUS_PIPE_EMPTY; - return NULL; + return NT_STATUS_PIPE_EMPTY; } - if (strequal(cli->desthost, p->pipe->desthost) && - rpccli_is_pipe_idx(p->pipe, pipe_idx)) { - *status = NT_STATUS_OK; - return p->pipe; + if (strequal(cli->desthost, p->pipe->desthost) + && ndr_syntax_id_equal(&p->pipe->abstract_syntax, + interface)) { + *presult = p->pipe; + return NT_STATUS_OK; } } - *status = NT_STATUS_PIPE_NOT_AVAILABLE; - - return NULL; + return NT_STATUS_PIPE_NOT_AVAILABLE; } /******************************************************************** ********************************************************************/ -static struct rpc_pipe_client *pipe_cm_connect(TALLOC_CTX *mem_ctx, - struct cli_state *cli, - int pipe_idx, - NTSTATUS *status) +static NTSTATUS pipe_cm_connect(TALLOC_CTX *mem_ctx, + struct cli_state *cli, + const struct ndr_syntax_id *interface, + struct rpc_pipe_client **presult) { struct client_pipe_connection *p; + NTSTATUS status; p = TALLOC_ZERO_ARRAY(mem_ctx, struct client_pipe_connection, 1); if (!p) { - *status = NT_STATUS_NO_MEMORY; - return NULL; + return NT_STATUS_NO_MEMORY; } - *status = cli_rpc_pipe_open_noauth(cli, cli_get_iface(pipe_idx), - &p->pipe); - if (!NT_STATUS_IS_OK(*status)) { + status = cli_rpc_pipe_open_noauth(cli, interface, &p->pipe); + if (!NT_STATUS_IS_OK(status)) { TALLOC_FREE(p); - return NULL; + return status; } DLIST_ADD(pipe_connections, p); - return p->pipe; + *presult = p->pipe; + return NT_STATUS_OK; } /******************************************************************** ********************************************************************/ -static struct rpc_pipe_client *pipe_cm_open(TALLOC_CTX *ctx, - struct cli_state *cli, - int pipe_idx, - NTSTATUS *status) +static NTSTATUS pipe_cm_open(TALLOC_CTX *ctx, + struct cli_state *cli, + const struct ndr_syntax_id *interface, + struct rpc_pipe_client **presult) { - struct rpc_pipe_client *p; - - p = pipe_cm_find(cli, pipe_idx, status); - if (!p) { - p = pipe_cm_connect(ctx, cli, pipe_idx, status); + if (NT_STATUS_IS_OK(pipe_cm_find(cli, interface, presult))) { + return NT_STATUS_OK; } - return p; + return pipe_cm_connect(ctx, cli, interface, presult); } /******************************************************************** @@ -167,23 +162,26 @@ static struct rpc_pipe_client *pipe_cm_open(TALLOC_CTX *ctx, WERROR libnetapi_open_pipe(struct libnetapi_ctx *ctx, struct cli_state *cli, - int pipe_idx, - struct rpc_pipe_client **pipe_cli) + const struct ndr_syntax_id *interface, + struct rpc_pipe_client **presult) { + struct rpc_pipe_client *result; NTSTATUS status; - if (!cli || !pipe_cli) { + if (!cli || !presult) { return WERR_INVALID_PARAM; } - *pipe_cli = pipe_cm_open(ctx, cli, pipe_idx, &status); - if (!*pipe_cli) { + status = pipe_cm_open(ctx, cli, interface, &result); + if (!NT_STATUS_IS_OK(status)) { libnetapi_set_error_string(ctx, "failed to open PIPE %s: %s", - cli_get_pipe_name(pipe_idx), + cli_get_pipe_name_from_iface(debug_ctx(), cli, + interface), get_friendly_nt_error_msg(status)); return WERR_DEST_NOT_FOUND; } + *presult = result; return WERR_OK; } diff --git a/source3/lib/netapi/getdc.c b/source3/lib/netapi/getdc.c index c1d021b1d4..4636042431 100644 --- a/source3/lib/netapi/getdc.c +++ b/source3/lib/netapi/getdc.c @@ -50,7 +50,8 @@ WERROR NetGetDCName_r(struct libnetapi_ctx *ctx, goto done; } - werr = libnetapi_open_pipe(ctx, cli, PI_NETLOGON, &pipe_cli); + werr = libnetapi_open_pipe(ctx, cli, &ndr_table_netlogon.syntax_id, + &pipe_cli); if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -90,7 +91,8 @@ WERROR NetGetAnyDCName_r(struct libnetapi_ctx *ctx, goto done; } - werr = libnetapi_open_pipe(ctx, cli, PI_NETLOGON, &pipe_cli); + werr = libnetapi_open_pipe(ctx, cli, &ndr_table_netlogon.syntax_id, + &pipe_cli); if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -149,7 +151,8 @@ WERROR DsGetDcName_r(struct libnetapi_ctx *ctx, goto done; } - werr = libnetapi_open_pipe(ctx, cli, PI_NETLOGON, &pipe_cli); + werr = libnetapi_open_pipe(ctx, cli, &ndr_table_netlogon.syntax_id, + &pipe_cli); if (!W_ERROR_IS_OK(werr)) { goto done; } diff --git a/source3/lib/netapi/group.c b/source3/lib/netapi/group.c index 15580b3c22..04ffb7c807 100644 --- a/source3/lib/netapi/group.c +++ b/source3/lib/netapi/group.c @@ -76,7 +76,8 @@ WERROR NetGroupAdd_r(struct libnetapi_ctx *ctx, goto done; } - werr = libnetapi_open_pipe(ctx, cli, PI_SAMR, &pipe_cli); + werr = libnetapi_open_pipe(ctx, cli, &ndr_table_samr.syntax_id, + &pipe_cli); if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -255,7 +256,8 @@ WERROR NetGroupDel_r(struct libnetapi_ctx *ctx, goto done; } - werr = libnetapi_open_pipe(ctx, cli, PI_SAMR, &pipe_cli); + werr = libnetapi_open_pipe(ctx, cli, &ndr_table_samr.syntax_id, + &pipe_cli); if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -428,7 +430,8 @@ WERROR NetGroupSetInfo_r(struct libnetapi_ctx *ctx, goto done; } - werr = libnetapi_open_pipe(ctx, cli, PI_SAMR, &pipe_cli); + werr = libnetapi_open_pipe(ctx, cli, &ndr_table_samr.syntax_id, + &pipe_cli); if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -671,7 +674,8 @@ WERROR NetGroupGetInfo_r(struct libnetapi_ctx *ctx, goto done; } - werr = libnetapi_open_pipe(ctx, cli, PI_SAMR, &pipe_cli); + werr = libnetapi_open_pipe(ctx, cli, &ndr_table_samr.syntax_id, + &pipe_cli); if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -795,7 +799,8 @@ WERROR NetGroupAddUser_r(struct libnetapi_ctx *ctx, goto done; } - werr = libnetapi_open_pipe(ctx, cli, PI_SAMR, &pipe_cli); + werr = libnetapi_open_pipe(ctx, cli, &ndr_table_samr.syntax_id, + &pipe_cli); if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -924,7 +929,8 @@ WERROR NetGroupDelUser_r(struct libnetapi_ctx *ctx, goto done; } - werr = libnetapi_open_pipe(ctx, cli, PI_SAMR, &pipe_cli); + werr = libnetapi_open_pipe(ctx, cli, &ndr_table_samr.syntax_id, + &pipe_cli); if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -1210,7 +1216,8 @@ WERROR NetGroupEnum_r(struct libnetapi_ctx *ctx, goto done; } - werr = libnetapi_open_pipe(ctx, cli, PI_SAMR, &pipe_cli); + werr = libnetapi_open_pipe(ctx, cli, &ndr_table_samr.syntax_id, + &pipe_cli); if (!W_ERROR_IS_OK(werr)) { goto done; } diff --git a/source3/lib/netapi/joindomain.c b/source3/lib/netapi/joindomain.c index a33e0eeee5..8d5202f07e 100644 --- a/source3/lib/netapi/joindomain.c +++ b/source3/lib/netapi/joindomain.c @@ -110,7 +110,8 @@ WERROR NetJoinDomain_r(struct libnetapi_ctx *ctx, goto done; } - werr = libnetapi_open_pipe(ctx, cli, PI_WKSSVC, &pipe_cli); + werr = libnetapi_open_pipe(ctx, cli, &ndr_table_wkssvc.syntax_id, + &pipe_cli); if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -241,7 +242,8 @@ WERROR NetUnjoinDomain_r(struct libnetapi_ctx *ctx, goto done; } - werr = libnetapi_open_pipe(ctx, cli, PI_WKSSVC, &pipe_cli); + werr = libnetapi_open_pipe(ctx, cli, &ndr_table_wkssvc.syntax_id, + &pipe_cli); if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -293,7 +295,8 @@ WERROR NetGetJoinInformation_r(struct libnetapi_ctx *ctx, goto done; } - werr = libnetapi_open_pipe(ctx, cli, PI_WKSSVC, &pipe_cli); + werr = libnetapi_open_pipe(ctx, cli, &ndr_table_wkssvc.syntax_id, + &pipe_cli); if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -427,7 +430,8 @@ WERROR NetGetJoinableOUs_r(struct libnetapi_ctx *ctx, goto done; } - werr = libnetapi_open_pipe(ctx, cli, PI_WKSSVC, &pipe_cli); + werr = libnetapi_open_pipe(ctx, cli, &ndr_table_wkssvc.syntax_id, + &pipe_cli); if (!W_ERROR_IS_OK(werr)) { goto done; } diff --git a/source3/lib/netapi/localgroup.c b/source3/lib/netapi/localgroup.c index faf57cc5fa..fe36d86b05 100644 --- a/source3/lib/netapi/localgroup.c +++ b/source3/lib/netapi/localgroup.c @@ -166,7 +166,8 @@ WERROR NetLocalGroupAdd_r(struct libnetapi_ctx *ctx, goto done; } - werr = libnetapi_open_pipe(ctx, cli, PI_SAMR, &pipe_cli); + werr = libnetapi_open_pipe(ctx, cli, &ndr_table_samr.syntax_id, + &pipe_cli); if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -293,7 +294,8 @@ WERROR NetLocalGroupDel_r(struct libnetapi_ctx *ctx, goto done; } - werr = libnetapi_open_pipe(ctx, cli, PI_SAMR, &pipe_cli); + werr = libnetapi_open_pipe(ctx, cli, &ndr_table_samr.syntax_id, + &pipe_cli); if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -472,7 +474,8 @@ WERROR NetLocalGroupGetInfo_r(struct libnetapi_ctx *ctx, goto done; } - werr = libnetapi_open_pipe(ctx, cli, PI_SAMR, &pipe_cli); + werr = libnetapi_open_pipe(ctx, cli, &ndr_table_samr.syntax_id, + &pipe_cli); if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -650,7 +653,8 @@ WERROR NetLocalGroupSetInfo_r(struct libnetapi_ctx *ctx, goto done; } - werr = libnetapi_open_pipe(ctx, cli, PI_SAMR, &pipe_cli); + werr = libnetapi_open_pipe(ctx, cli, &ndr_table_samr.syntax_id, + &pipe_cli); if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -792,7 +796,8 @@ WERROR NetLocalGroupEnum_r(struct libnetapi_ctx *ctx, goto done; } - werr = libnetapi_open_pipe(ctx, cli, PI_SAMR, &pipe_cli); + werr = libnetapi_open_pipe(ctx, cli, &ndr_table_samr.syntax_id, + &pipe_cli); if (!W_ERROR_IS_OK(werr)) { goto done; } diff --git a/source3/lib/netapi/netapi_private.h b/source3/lib/netapi/netapi_private.h index 915d60617f..ef6e7cf2b7 100644 --- a/source3/lib/netapi/netapi_private.h +++ b/source3/lib/netapi/netapi_private.h @@ -49,8 +49,8 @@ WERROR libnetapi_open_ipc_connection(struct libnetapi_ctx *ctx, WERROR libnetapi_shutdown_cm(struct libnetapi_ctx *ctx); WERROR libnetapi_open_pipe(struct libnetapi_ctx *ctx, struct cli_state *cli, - int pipe_idx, - struct rpc_pipe_client **pipe_cli); + const struct ndr_syntax_id *interface, + struct rpc_pipe_client **presult); WERROR libnetapi_samr_open_domain(struct libnetapi_ctx *mem_ctx, struct rpc_pipe_client *pipe_cli, uint32_t connect_mask, diff --git a/source3/lib/netapi/serverinfo.c b/source3/lib/netapi/serverinfo.c index 7920bc29d0..a591d3753a 100644 --- a/source3/lib/netapi/serverinfo.c +++ b/source3/lib/netapi/serverinfo.c @@ -75,7 +75,8 @@ WERROR NetServerGetInfo_r(struct libnetapi_ctx *ctx, goto done; } - werr = libnetapi_open_pipe(ctx, cli, PI_SRVSVC, &pipe_cli); + werr = libnetapi_open_pipe(ctx, cli, &ndr_table_srvsvc.syntax_id, + &pipe_cli); if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -175,7 +176,8 @@ WERROR NetServerSetInfo_r(struct libnetapi_ctx *ctx, goto done; } - werr = libnetapi_open_pipe(ctx, cli, PI_SRVSVC, &pipe_cli); + werr = libnetapi_open_pipe(ctx, cli, &ndr_table_srvsvc.syntax_id, + &pipe_cli); if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -221,7 +223,8 @@ WERROR NetRemoteTOD_r(struct libnetapi_ctx *ctx, goto done; } - werr = libnetapi_open_pipe(ctx, cli, PI_SRVSVC, &pipe_cli); + werr = libnetapi_open_pipe(ctx, cli, &ndr_table_srvsvc.syntax_id, + &pipe_cli); if (!W_ERROR_IS_OK(werr)) { goto done; } diff --git a/source3/lib/netapi/user.c b/source3/lib/netapi/user.c index 8d69536848..f896dde3aa 100644 --- a/source3/lib/netapi/user.c +++ b/source3/lib/netapi/user.c @@ -170,7 +170,8 @@ WERROR NetUserAdd_r(struct libnetapi_ctx *ctx, goto done; } - werr = libnetapi_open_pipe(ctx, cli, PI_SAMR, &pipe_cli); + werr = libnetapi_open_pipe(ctx, cli, &ndr_table_samr.syntax_id, + &pipe_cli); if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -333,7 +334,8 @@ WERROR NetUserDel_r(struct libnetapi_ctx *ctx, goto done; } - werr = libnetapi_open_pipe(ctx, cli, PI_SAMR, &pipe_cli); + werr = libnetapi_open_pipe(ctx, cli, &ndr_table_samr.syntax_id, + &pipe_cli); if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -709,7 +711,8 @@ WERROR NetUserEnum_r(struct libnetapi_ctx *ctx, goto done; } - werr = libnetapi_open_pipe(ctx, cli, PI_SAMR, &pipe_cli); + werr = libnetapi_open_pipe(ctx, cli, &ndr_table_samr.syntax_id, + &pipe_cli); if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -1001,7 +1004,8 @@ WERROR NetQueryDisplayInformation_r(struct libnetapi_ctx *ctx, goto done; } - werr = libnetapi_open_pipe(ctx, cli, PI_SAMR, &pipe_cli); + werr = libnetapi_open_pipe(ctx, cli, &ndr_table_samr.syntax_id, + &pipe_cli); if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -1128,7 +1132,8 @@ WERROR NetUserGetInfo_r(struct libnetapi_ctx *ctx, goto done; } - werr = libnetapi_open_pipe(ctx, cli, PI_SAMR, &pipe_cli); + werr = libnetapi_open_pipe(ctx, cli, &ndr_table_samr.syntax_id, + &pipe_cli); if (!W_ERROR_IS_OK(werr)) { goto done; } -- cgit From 39c344a27fbe1a66281aa36e49e4049286cea0f0 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 18 Jul 2008 20:10:37 +0200 Subject: netapi: fix NetLocalGroupAdd. Guenther (This used to be commit d4594a7a03381fb251c9f8caf4c70e1ed97674b6) --- source3/lib/netapi/localgroup.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/localgroup.c b/source3/lib/netapi/localgroup.c index fe36d86b05..57067621b7 100644 --- a/source3/lib/netapi/localgroup.c +++ b/source3/lib/netapi/localgroup.c @@ -209,6 +209,8 @@ WERROR NetLocalGroupAdd_r(struct libnetapi_ctx *ctx, goto done; } + init_lsa_String(&lsa_account_name, alias_name); + status = rpccli_samr_CreateDomAlias(pipe_cli, ctx, &domain_handle, &lsa_account_name, @@ -786,6 +788,13 @@ WERROR NetLocalGroupEnum_r(struct libnetapi_ctx *ctx, return WERR_UNKNOWN_LEVEL; } + if (r->out.total_entries) { + *r->out.total_entries = 0; + } + if (r->out.entries_read) { + *r->out.entries_read = 0; + } + ZERO_STRUCT(connect_handle); ZERO_STRUCT(builtin_handle); ZERO_STRUCT(domain_handle); @@ -836,6 +845,10 @@ WERROR NetLocalGroupEnum_r(struct libnetapi_ctx *ctx, goto done; } + if (r->out.total_entries) { + *r->out.total_entries += builtin_info->info2.num_aliases; + } + status = rpccli_samr_QueryDomainInfo(pipe_cli, ctx, &domain_handle, 2, @@ -845,6 +858,10 @@ WERROR NetLocalGroupEnum_r(struct libnetapi_ctx *ctx, goto done; } + if (r->out.total_entries) { + *r->out.total_entries += domain_info->info2.num_aliases; + } + status = rpccli_samr_EnumDomainAliases(pipe_cli, ctx, &builtin_handle, r->in.resume_handle, -- cgit From 8417316b58cac32fa301cecf949e398a8c1b4143 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 18 Jul 2008 19:12:42 +0200 Subject: netapi: add netapi testsuite. Guenther (This used to be commit 8b3149b4a663f59b504c1458cd7ecafe0c0e0322) --- source3/lib/netapi/tests/Makefile.in | 57 ++++++ source3/lib/netapi/tests/common.c | 86 ++++++++++ source3/lib/netapi/tests/common.h | 55 ++++++ source3/lib/netapi/tests/netapitest.c | 92 ++++++++++ source3/lib/netapi/tests/netdisplay.c | 150 ++++++++++++++++ source3/lib/netapi/tests/netgroup.c | 286 +++++++++++++++++++++++++++++++ source3/lib/netapi/tests/netlocalgroup.c | 226 ++++++++++++++++++++++++ source3/lib/netapi/tests/netuser.c | 259 ++++++++++++++++++++++++++++ 8 files changed, 1211 insertions(+) create mode 100644 source3/lib/netapi/tests/Makefile.in create mode 100644 source3/lib/netapi/tests/common.c create mode 100644 source3/lib/netapi/tests/common.h create mode 100644 source3/lib/netapi/tests/netapitest.c create mode 100644 source3/lib/netapi/tests/netdisplay.c create mode 100644 source3/lib/netapi/tests/netgroup.c create mode 100644 source3/lib/netapi/tests/netlocalgroup.c create mode 100644 source3/lib/netapi/tests/netuser.c (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/tests/Makefile.in b/source3/lib/netapi/tests/Makefile.in new file mode 100644 index 0000000000..f13281ee8c --- /dev/null +++ b/source3/lib/netapi/tests/Makefile.in @@ -0,0 +1,57 @@ +KRB5LIBS=@KRB5_LIBS@ +LDAP_LIBS=@LDAP_LIBS@ +LIBS=@LIBS@ -lnetapi -ltdb -ltalloc +DEVELOPER_CFLAGS=@DEVELOPER_CFLAGS@ +FLAGS=-I../ -L../../../bin @CFLAGS@ $(GTK_FLAGS) +CC=@CC@ +PICFLAG=@PICFLAG@ +LDFLAGS=@PIE_LDFLAGS@ @LDFLAGS@ +DYNEXP=@DYNEXP@ +NETAPI_LIBS=$(LIBS) $(KRB5LIBS) $(LDAP_LIBS) +CMDLINE_LIBS=$(NETAPI_LIBS) @POPTLIBS@ + +# Compile a source file. +COMPILE_CC = $(CC) -I. $(FLAGS) $(PICFLAG) -c $< -o $@ +COMPILE = $(COMPILE_CC) + +PROGS = bin/netapitest@EXEEXT@ + +all: $(PROGS) + +MAKEDIR = || exec false; \ + if test -d "$$dir"; then :; else \ + echo mkdir "$$dir"; \ + mkdir -p "$$dir" >/dev/null 2>&1 || \ + test -d "$$dir" || \ + mkdir "$$dir" || \ + exec false; fi || exec false + +BINARY_PREREQS = bin/.dummy + +bin/.dummy: + @if (: >> $@ || : > $@) >/dev/null 2>&1; then :; else \ + dir=bin $(MAKEDIR); fi + @: >> $@ || : > $@ # what a fancy emoticon! + +.c.o: + @if (: >> $@ || : > $@) >/dev/null 2>&1; then rm -f $@; else \ + dir=`echo $@ | sed 's,/[^/]*$$,,;s,^$$,.,'` $(MAKEDIR); fi + @echo Compiling $*.c + @$(COMPILE) && exit 0;\ + echo "The following command failed:" 1>&2;\ + echo "$(COMPILE_CC)" 1>&2;\ + $(COMPILE_CC) >/dev/null 2>&1 + +CMDLINE_OBJ = common.o +NETAPIBUFFER_OBJ = netapibuffer.o +NETAPITEST_OBJ = netapitest.o netlocalgroup.o netuser.o netgroup.o netdisplay.o $(CMDLINE_OBJ) + +bin/netapitest@EXEEXT@: $(BINARY_PREREQS) $(NETAPITEST_OBJ) + @echo Linking $@ + @$(CC) $(FLAGS) -o $@ $(NETAPITEST_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) + +clean: + -rm -f $(PROGS) + -rm -f core */*~ *~ \ + */*.o */*/*.o */*/*/*.o + diff --git a/source3/lib/netapi/tests/common.c b/source3/lib/netapi/tests/common.c new file mode 100644 index 0000000000..22175afb48 --- /dev/null +++ b/source3/lib/netapi/tests/common.c @@ -0,0 +1,86 @@ +/* + * Unix SMB/CIFS implementation. + * NetApi testsuite + * Copyright (C) Guenther Deschner 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include +#include +#include +#include + +#include +#include + +#include "common.h" + +void popt_common_callback(poptContext con, + enum poptCallbackReason reason, + const struct poptOption *opt, + const char *arg, const void *data) +{ + struct libnetapi_ctx *ctx = NULL; + + libnetapi_getctx(&ctx); + + if (reason == POPT_CALLBACK_REASON_PRE) { + } + + if (reason == POPT_CALLBACK_REASON_POST) { + } + + if (!opt) { + return; + } + switch (opt->val) { + case 'U': { + char *puser = strdup(arg); + char *p = NULL; + + if ((p = strchr(puser,'%'))) { + size_t len; + *p = 0; + libnetapi_set_username(ctx, puser); + libnetapi_set_password(ctx, p+1); + len = strlen(p+1); + memset(strchr(arg,'%')+1,'X',len); + } else { + libnetapi_set_username(ctx, puser); + } + free(puser); + break; + } + case 'd': + libnetapi_set_debuglevel(ctx, arg); + break; + case 'p': + libnetapi_set_password(ctx, arg); + break; + case 'k': + libnetapi_set_use_kerberos(ctx); + break; + } +} + +struct poptOption popt_common_netapi_examples[] = { + { NULL, 0, POPT_ARG_CALLBACK|POPT_CBFLAG_PRE|POPT_CBFLAG_POST, (void *)popt_common_callback }, + { "user", 'U', POPT_ARG_STRING, NULL, 'U', "Username used for connection", "USERNAME" }, + { "password", 'p', POPT_ARG_STRING, NULL, 'p', "Password used for connection", "PASSWORD" }, + { "debuglevel", 'd', POPT_ARG_STRING, NULL, 'd', "Debuglevel", "DEBUGLEVEL" }, + { "kerberos", 'k', POPT_ARG_NONE, NULL, 'k', "Use Kerberos", NULL }, + POPT_TABLEEND +}; + diff --git a/source3/lib/netapi/tests/common.h b/source3/lib/netapi/tests/common.h new file mode 100644 index 0000000000..ed073c0038 --- /dev/null +++ b/source3/lib/netapi/tests/common.h @@ -0,0 +1,55 @@ +/* + * Unix SMB/CIFS implementation. + * NetApi testsuite + * Copyright (C) Guenther Deschner 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include + +void popt_common_callback(poptContext con, + enum poptCallbackReason reason, + const struct poptOption *opt, + const char *arg, const void *data); + +extern struct poptOption popt_common_netapi_examples[]; + +#define POPT_COMMON_LIBNETAPI_EXAMPLES { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_netapi_examples, 0, "Common samba netapi example options:", NULL }, + +NET_API_STATUS test_netuseradd(const char *hostname, + const char *username); + +NET_API_STATUS netapitest_localgroup(struct libnetapi_ctx *ctx, + const char *hostname); +NET_API_STATUS netapitest_user(struct libnetapi_ctx *ctx, + const char *hostname); +NET_API_STATUS netapitest_group(struct libnetapi_ctx *ctx, + const char *hostname); +NET_API_STATUS netapitest_display(struct libnetapi_ctx *ctx, + const char *hostname); + +#ifndef ARRAY_SIZE +#define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0])) +#endif + +#define NETAPI_STATUS(x,y,fn) \ + printf("FAILURE: line %d: %s failed with status: %s (%d)\n", \ + __LINE__, fn, libnetapi_get_error_string(x,y), y); + +#define NETAPI_STATUS_MSG(x,y,fn,z) \ + printf("FAILURE: line %d: %s failed with status: %s (%d), %s\n", \ + __LINE__, fn, libnetapi_get_error_string(x,y), y, z); + +#define ZERO_STRUCT(x) memset((char *)&(x), 0, sizeof(x)) diff --git a/source3/lib/netapi/tests/netapitest.c b/source3/lib/netapi/tests/netapitest.c new file mode 100644 index 0000000000..de81f5efe8 --- /dev/null +++ b/source3/lib/netapi/tests/netapitest.c @@ -0,0 +1,92 @@ +/* + * Unix SMB/CIFS implementation. + * NetApi testsuite + * Copyright (C) Guenther Deschner 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include +#include +#include +#include +#include + +#include + +#include "common.h" + +int main(int argc, const char **argv) +{ + NET_API_STATUS status = 0; + struct libnetapi_ctx *ctx = NULL; + const char *hostname = NULL; + + poptContext pc; + int opt; + + struct poptOption long_options[] = { + POPT_AUTOHELP + POPT_COMMON_LIBNETAPI_EXAMPLES + POPT_TABLEEND + }; + + status = libnetapi_init(&ctx); + if (status != 0) { + return status; + } + + pc = poptGetContext("netapitest", argc, argv, long_options, 0); + + poptSetOtherOptionHelp(pc, "hostname"); + while((opt = poptGetNextOpt(pc)) != -1) { + } + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + hostname = poptGetArg(pc); + + status = netapitest_localgroup(ctx, hostname); + if (status) { + goto out; + } + + status = netapitest_user(ctx, hostname); + if (status) { + goto out; + } + + status = netapitest_group(ctx, hostname); + if (status) { + goto out; + } + + status = netapitest_display(ctx, hostname); + if (status) { + goto out; + } + + out: + if (status != 0) { + printf("testsuite failed with: %s\n", + libnetapi_get_error_string(ctx, status)); + } + + libnetapi_free(ctx); + poptFreeContext(pc); + + return status; +} diff --git a/source3/lib/netapi/tests/netdisplay.c b/source3/lib/netapi/tests/netdisplay.c new file mode 100644 index 0000000000..090792cec2 --- /dev/null +++ b/source3/lib/netapi/tests/netdisplay.c @@ -0,0 +1,150 @@ +/* + * Unix SMB/CIFS implementation. + * NetGroup testsuite + * Copyright (C) Guenther Deschner 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include +#include +#include +#include +#include + +#include + +#include "common.h" + +static NET_API_STATUS test_netquerydisplayinformation(const char *hostname, + uint32_t level, + const char *name) +{ + NET_API_STATUS status; + uint32_t entries_read = 0; + int found_name = 0; + const char *current_name; + uint8_t *buffer = NULL; + uint32_t idx = 0; + int i; + + struct NET_DISPLAY_USER *user; + struct NET_DISPLAY_GROUP *group; + struct NET_DISPLAY_MACHINE *machine; + + printf("testing NetQueryDisplayInformation level %d\n", level); + + do { + status = NetQueryDisplayInformation(hostname, + level, + idx, + 1000, + (uint32_t)-1, + &entries_read, + (void **)&buffer); + if (status == 0 || status == ERROR_MORE_DATA) { + switch (level) { + case 1: + user = (struct NET_DISPLAY_USER *)buffer; + break; + case 2: + machine = (struct NET_DISPLAY_MACHINE *)buffer; + break; + case 3: + group = (struct NET_DISPLAY_GROUP *)buffer; + break; + default: + return -1; + } + + for (i=0; iusri1_name; + break; + case 2: + current_name = machine->usri2_name; + break; + case 3: + current_name = group->grpi3_name; + break; + default: + break; + } + + if (name && strcasecmp(current_name, name) == 0) { + found_name = 1; + } + + switch (level) { + case 1: + user++; + break; + case 2: + machine++; + break; + case 3: + group++; + break; + } + } + NetApiBufferFree(buffer); + } + idx += entries_read; + } while (status == ERROR_MORE_DATA); + + if (status) { + return status; + } + + if (name && !found_name) { + printf("failed to get name\n"); + return -1; + } + + return 0; +} + +NET_API_STATUS netapitest_display(struct libnetapi_ctx *ctx, + const char *hostname) +{ + NET_API_STATUS status = 0; + uint32_t levels[] = { 1, 2, 3}; + int i; + + printf("NetDisplay tests\n"); + + /* test enum */ + + for (i=0; i. + */ + +#include +#include +#include +#include +#include + +#include + +#include "common.h" + +static NET_API_STATUS test_netgroupenum(const char *hostname, + uint32_t level, + const char *groupname) +{ + NET_API_STATUS status; + uint32_t entries_read = 0; + uint32_t total_entries = 0; + uint32_t resume_handle = 0; + int found_group = 0; + const char *current_name; + uint8_t *buffer = NULL; + int i; + + struct GROUP_INFO_0 *info0; + struct GROUP_INFO_1 *info1; + struct GROUP_INFO_2 *info2; + struct GROUP_INFO_3 *info3; + + printf("testing NetGroupEnum level %d\n", level); + + do { + status = NetGroupEnum(hostname, + level, + &buffer, + 120, //(uint32_t)-1, + &entries_read, + &total_entries, + &resume_handle); + if (status == 0 || status == ERROR_MORE_DATA) { + switch (level) { + case 0: + info0 = (struct GROUP_INFO_0 *)buffer; + break; + case 1: + info1 = (struct GROUP_INFO_1 *)buffer; + break; + case 2: + info2 = (struct GROUP_INFO_2 *)buffer; + break; + case 3: + info3 = (struct GROUP_INFO_3 *)buffer; + break; + default: + return -1; + } + + for (i=0; igrpi0_name; + break; + case 1: + current_name = info1->grpi1_name; + break; + case 2: + current_name = info2->grpi2_name; + break; + case 3: + current_name = info3->grpi3_name; + break; + default: + break; + } + + if (strcasecmp(current_name, groupname) == 0) { + found_group = 1; + } + + switch (level) { + case 0: + info0++; + break; + case 1: + info1++; + break; + case 2: + info2++; + break; + case 3: + info3++; + break; + } + } + NetApiBufferFree(buffer); + } + } while (status == ERROR_MORE_DATA); + + if (status) { + return status; + } + + if (!found_group) { + printf("failed to get group\n"); + return -1; + } + + return 0; +} + +NET_API_STATUS netapitest_group(struct libnetapi_ctx *ctx, + const char *hostname) +{ + NET_API_STATUS status = 0; + const char *username, *groupname, *groupname2; + uint8_t *buffer = NULL; + struct GROUP_INFO_0 g0; + uint32_t parm_err = 0; + uint32_t levels[] = { 0, 1, 2, 3}; + uint32_t enum_levels[] = { 0, 1, 2, 3}; + int i; + + printf("NetGroup tests\n"); + + username = "torture_test_user"; + groupname = "torture_test_group"; + groupname2 = "torture_test_group2"; + + /* cleanup */ + NetGroupDel(hostname, groupname); + NetGroupDel(hostname, groupname2); + NetUserDel(hostname, username); + + /* add a group */ + + g0.grpi0_name = groupname; + + printf("testing NetGroupAdd\n"); + + status = NetGroupAdd(hostname, 0, (uint8_t *)&g0, &parm_err); + if (status) { + NETAPI_STATUS(ctx, status, "NetGroupAdd"); + goto out; + } + + /* 2nd add must fail */ + + status = NetGroupAdd(hostname, 0, (uint8_t *)&g0, &parm_err); + if (status == 0) { + NETAPI_STATUS(ctx, status, "NetGroupAdd"); + goto out; + } + + /* test enum */ + + for (i=0; i. + */ + +#include +#include +#include +#include +#include + +#include + +#include "common.h" + +static NET_API_STATUS test_netlocalgroupenum(const char *hostname, + uint32_t level, + const char *groupname) +{ + NET_API_STATUS status; + uint32_t entries_read = 0; + uint32_t total_entries = 0; + uint32_t resume_handle = 0; + int found_group = 0; + const char *current_name; + uint8_t *buffer = NULL; + int i; + + struct LOCALGROUP_INFO_0 *info0; + struct LOCALGROUP_INFO_1 *info1; + + printf("testing NetLocalGroupEnum level %d\n", level); + + do { + status = NetLocalGroupEnum(hostname, + level, + &buffer, + (uint32_t)-1, + &entries_read, + &total_entries, + &resume_handle); + if (status == 0 || status == ERROR_MORE_DATA) { + switch (level) { + case 0: + info0 = (struct LOCALGROUP_INFO_0 *)buffer; + break; + case 1: + info1 = (struct LOCALGROUP_INFO_1 *)buffer; + break; + default: + return -1; + } + + for (i=0; ilgrpi0_name; + break; + case 1: + current_name = info1->lgrpi1_name; + break; + default: + break; + } + + if (strcasecmp(current_name, groupname) == 0) { + found_group = 1; + } + + switch (level) { + case 0: + info0++; + break; + case 1: + info1++; + break; + } + } + NetApiBufferFree(buffer); + } + } while (status == ERROR_MORE_DATA); + + if (status) { + return status; + } + + if (!found_group) { + printf("failed to get group\n"); + return -1; + } + + return 0; +} + +NET_API_STATUS netapitest_localgroup(struct libnetapi_ctx *ctx, + const char *hostname) +{ + NET_API_STATUS status = 0; + const char *groupname, *groupname2; + uint8_t *buffer = NULL; + struct LOCALGROUP_INFO_0 g0; + uint32_t parm_err = 0; + uint32_t levels[] = { 0, 1, 1002 }; + uint32_t enum_levels[] = { 0, 1 }; + int i; + + printf("NetLocalgroup tests\n"); + + groupname = "torture_test_localgroup"; + groupname2 = "torture_test_localgroup2"; + + /* cleanup */ + NetLocalGroupDel(hostname, groupname); + NetLocalGroupDel(hostname, groupname2); + + /* add a localgroup */ + + printf("testing NetLocalGroupAdd\n"); + + g0.lgrpi0_name = groupname; + + status = NetLocalGroupAdd(hostname, 0, (uint8_t *)&g0, &parm_err); + if (status) { + NETAPI_STATUS(ctx, status, "NetLocalGroupAdd"); + goto out; + }; + + /* test enum */ + + for (i=0; i. + */ + +#include +#include +#include +#include +#include + +#include + +#include "common.h" + +static NET_API_STATUS test_netuserenum(const char *hostname, + uint32_t level, + const char *username) +{ + NET_API_STATUS status; + uint32_t entries_read = 0; + uint32_t total_entries = 0; + uint32_t resume_handle = 0; + const char *current_name; + int found_user = 0; + uint8_t *buffer = NULL; + int i; + + struct USER_INFO_0 *info0; + struct USER_INFO_10 *info10; + struct USER_INFO_20 *info20; + struct USER_INFO_23 *info23; + + printf("testing NetUserEnum level %d\n", level); + + do { + status = NetUserEnum(hostname, + level, + FILTER_NORMAL_ACCOUNT, + &buffer, + 120, //(uint32_t)-1, + &entries_read, + &total_entries, + &resume_handle); + if (status == 0 || status == ERROR_MORE_DATA) { + switch (level) { + case 0: + info0 = (struct USER_INFO_0 *)buffer; + break; + case 10: + info10 = (struct USER_INFO_10 *)buffer; + break; + case 20: + info20 = (struct USER_INFO_20 *)buffer; + break; + case 23: + info23 = (struct USER_INFO_23 *)buffer; + break; + default: + return -1; + } + + for (i=0; iusri0_name; + break; + case 10: + current_name = info10->usri10_name; + break; + case 20: + current_name = info20->usri20_name; + break; + case 23: + current_name = info23->usri23_name; + break; + default: + return -1; + } + + if (strcasecmp(current_name, username) == 0) { + found_user = 1; + } + + switch (level) { + case 0: + info0++; + break; + case 10: + info10++; + break; + case 20: + info20++; + break; + case 23: + info23++; + break; + default: + break; + } + } + NetApiBufferFree(buffer); + } + } while (status == ERROR_MORE_DATA); + + if (status) { + return status; + } + + if (!found_user) { + printf("failed to get user\n"); + return -1; + } + + return 0; +} + +NET_API_STATUS test_netuseradd(const char *hostname, + const char *username) +{ + struct USER_INFO_1 u1; + uint32_t parm_err = 0; + + ZERO_STRUCT(u1); + + printf("testing NetUserAdd\n"); + + u1.usri1_name = username; + u1.usri1_password = "W297!832jD8J"; + u1.usri1_password_age = 0; + u1.usri1_priv = 0; + u1.usri1_home_dir = NULL; + u1.usri1_comment = "User created using Samba NetApi Example code"; + u1.usri1_flags = 0; + u1.usri1_script_path = NULL; + + return NetUserAdd(hostname, 1, (uint8_t *)&u1, &parm_err); +} + +NET_API_STATUS netapitest_user(struct libnetapi_ctx *ctx, + const char *hostname) +{ + NET_API_STATUS status = 0; + const char *username, *username2; + uint8_t *buffer = NULL; + uint32_t levels[] = { 0, 10, 20, 23 }; + uint32_t enum_levels[] = { 0, 10, 20, 23 }; + int i; + + struct USER_INFO_1007 u1007; + uint32_t parm_err = 0; + + printf("NetUser tests\n"); + + username = "torture_test_user"; + username2 = "torture_test_user2"; + + /* cleanup */ + NetUserDel(hostname, username); + NetUserDel(hostname, username2); + + /* add a user */ + + status = test_netuseradd(hostname, username); + if (status) { + NETAPI_STATUS(ctx, status, "NetUserAdd"); + goto out; + } + + /* enum the new user */ + + for (i=0; i Date: Fri, 18 Jul 2008 20:12:13 +0200 Subject: netapi: add convert_USER_INFO_X_to_samr_user_info21 fn and use it NetUserAdd. Guenther (This used to be commit c3e4c7cb5f2728a8219789aeb2344bff368713d5) --- source3/lib/netapi/user.c | 175 +++++++++++++++++++++++++++++++++------------- 1 file changed, 126 insertions(+), 49 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/user.c b/source3/lib/netapi/user.c index f896dde3aa..faf1a6d65c 100644 --- a/source3/lib/netapi/user.c +++ b/source3/lib/netapi/user.c @@ -27,9 +27,8 @@ /**************************************************************** ****************************************************************/ -static void convert_USER_INFO_1_to_samr_user_info25(struct USER_INFO_1 *info1, - DATA_BLOB *user_session_key, - struct samr_UserInfo25 *info25) +static void convert_USER_INFO_X_to_samr_user_info21(struct USER_INFO_X *infoX, + struct samr_UserInfo21 *info21) { uint32_t fields_present = SAMR_FIELD_ACCT_FLAGS; struct samr_LogonHours zero_logon_hours; @@ -37,41 +36,41 @@ static void convert_USER_INFO_1_to_samr_user_info25(struct USER_INFO_1 *info1, uint32_t acct_flags = 0; NTTIME password_age; - ZERO_STRUCTP(info25); + ZERO_STRUCTP(info21); ZERO_STRUCT(zero_logon_hours); ZERO_STRUCT(zero_parameters); - if (info1->usri1_name) { + if (infoX->usriX_name) { fields_present |= SAMR_FIELD_FULL_NAME; } - if (info1->usri1_password) { + if (infoX->usriX_password) { fields_present |= SAMR_FIELD_PASSWORD; } - if (info1->usri1_flags) { + if (infoX->usriX_flags) { fields_present |= SAMR_FIELD_ACCT_FLAGS; } - if (info1->usri1_name) { + if (infoX->usriX_name) { fields_present |= SAMR_FIELD_FULL_NAME; } - if (info1->usri1_home_dir) { + if (infoX->usriX_home_dir) { fields_present |= SAMR_FIELD_HOME_DIRECTORY; } - if (info1->usri1_script_path) { + if (infoX->usriX_script_path) { fields_present |= SAMR_FIELD_LOGON_SCRIPT; } - if (info1->usri1_comment) { + if (infoX->usriX_comment) { fields_present |= SAMR_FIELD_DESCRIPTION; } - if (info1->usri1_password_age) { + if (infoX->usriX_password_age) { fields_present |= SAMR_FIELD_FORCE_PWD_CHANGE; } - acct_flags |= info1->usri1_flags | ACB_NORMAL; + acct_flags |= infoX->usriX_flags | ACB_NORMAL; - unix_to_nt_time_abs(&password_age, info1->usri1_password_age); + unix_to_nt_time_abs(&password_age, infoX->usriX_password_age); - /* TODO: info1->usri1_priv */ - init_samr_user_info21(&info25->info, + /* TODO: infoX->usriX_priv */ + init_samr_user_info21(info21, 0, 0, 0, @@ -79,12 +78,12 @@ static void convert_USER_INFO_1_to_samr_user_info25(struct USER_INFO_1 *info1, 0, password_age, NULL, - info1->usri1_name, - info1->usri1_home_dir, + infoX->usriX_name, + infoX->usriX_home_dir, NULL, - info1->usri1_script_path, + infoX->usriX_script_path, NULL, - info1->usri1_comment, + infoX->usriX_comment, NULL, NULL, &zero_parameters, @@ -100,29 +99,80 @@ static void convert_USER_INFO_1_to_samr_user_info25(struct USER_INFO_1 *info1, 0, 0, 0); +} - if (info1->usri1_password) { - uchar pwbuf[532]; - struct MD5Context ctx; - uint8_t confounder[16]; - DATA_BLOB confounded_session_key = data_blob(NULL, 16); - - encode_pw_buffer(pwbuf, info1->usri1_password, STR_UNICODE); +/**************************************************************** +****************************************************************/ - generate_random_buffer((uint8_t *)confounder, 16); +static NTSTATUS construct_USER_INFO_X(uint32_t level, + uint8_t *buffer, + struct USER_INFO_X *uX) +{ + struct USER_INFO_0 *u0 = NULL; + struct USER_INFO_1 *u1 = NULL; + struct USER_INFO_2 *u2 = NULL; + struct USER_INFO_1007 *u1007 = NULL; - MD5Init(&ctx); - MD5Update(&ctx, confounder, 16); - MD5Update(&ctx, user_session_key->data, - user_session_key->length); - MD5Final(confounded_session_key.data, &ctx); + if (!buffer || !uX) { + return NT_STATUS_INVALID_PARAMETER; + } - SamOEMhashBlob(pwbuf, 516, &confounded_session_key); - memcpy(&pwbuf[516], confounder, 16); + ZERO_STRUCTP(uX); - memcpy(info25->password.data, pwbuf, sizeof(pwbuf)); - data_blob_free(&confounded_session_key); + switch (level) { + case 0: + u0 = (struct USER_INFO_0 *)buffer; + uX->usriX_name = u0->usri0_name; + break; + case 1: + u1 = (struct USER_INFO_1 *)buffer; + uX->usriX_name = u1->usri1_name; + uX->usriX_password = u1->usri1_password; + uX->usriX_password_age = u1->usri1_password_age; + uX->usriX_priv = u1->usri1_priv; + uX->usriX_home_dir = u1->usri1_home_dir; + uX->usriX_comment = u1->usri1_comment; + uX->usriX_flags = u1->usri1_flags; + uX->usriX_script_path = u1->usri1_script_path; + break; + case 2: + u2 = (struct USER_INFO_2 *)buffer; + uX->usriX_name = u2->usri2_name; + uX->usriX_password = u2->usri2_password; + uX->usriX_password_age = u2->usri2_password_age; + uX->usriX_priv = u2->usri2_priv; + uX->usriX_home_dir = u2->usri2_home_dir; + uX->usriX_comment = u2->usri2_comment; + uX->usriX_flags = u2->usri2_flags; + uX->usriX_script_path = u2->usri2_script_path; + uX->usriX_auth_flags = u2->usri2_auth_flags; + uX->usriX_full_name = u2->usri2_full_name; + uX->usriX_usr_comment = u2->usri2_usr_comment; + uX->usriX_parms = u2->usri2_parms; + uX->usriX_workstations = u2->usri2_workstations; + uX->usriX_last_logon = u2->usri2_last_logon; + uX->usriX_last_logoff = u2->usri2_last_logoff; + uX->usriX_acct_expires = u2->usri2_acct_expires; + uX->usriX_max_storage = u2->usri2_max_storage; + uX->usriX_units_per_week= u2->usri2_units_per_week; + uX->usriX_logon_hours = u2->usri2_logon_hours; + uX->usriX_bad_pw_count = u2->usri2_bad_pw_count; + uX->usriX_num_logons = u2->usri2_num_logons; + uX->usriX_logon_server = u2->usri2_logon_server; + uX->usriX_country_code = u2->usri2_country_code; + uX->usriX_code_page = u2->usri2_code_page; + break; + case 1007: + u1007 = (struct USER_INFO_1007 *)buffer; + uX->usriX_comment = u1007->usri1007_comment; + break; + case 3: + case 4: + default: + return NT_STATUS_INVALID_INFO_CLASS; } + + return NT_STATUS_OK; } /**************************************************************** @@ -138,12 +188,12 @@ WERROR NetUserAdd_r(struct libnetapi_ctx *ctx, POLICY_HND connect_handle, domain_handle, user_handle; struct lsa_String lsa_account_name; struct dom_sid2 *domain_sid = NULL; - struct samr_UserInfo25 info25; + struct samr_UserInfo21 info21; union samr_UserInfo *user_info = NULL; struct samr_PwInfo pw_info; uint32_t access_granted = 0; uint32_t rid = 0; - struct USER_INFO_1 *info1; + struct USER_INFO_X uX; ZERO_STRUCT(connect_handle); ZERO_STRUCT(domain_handle); @@ -155,7 +205,6 @@ WERROR NetUserAdd_r(struct libnetapi_ctx *ctx, switch (r->in.level) { case 1: - info1 = (struct USER_INFO_1 *)r->in.buffer; break; case 2: case 3: @@ -176,6 +225,12 @@ WERROR NetUserAdd_r(struct libnetapi_ctx *ctx, goto done; } + status = construct_USER_INFO_X(r->in.level, r->in.buffer, &uX); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + werr = libnetapi_samr_open_domain(ctx, pipe_cli, SAMR_ACCESS_ENUM_DOMAINS | SAMR_ACCESS_OPEN_DOMAIN, @@ -189,7 +244,7 @@ WERROR NetUserAdd_r(struct libnetapi_ctx *ctx, goto done; } - init_lsa_String(&lsa_account_name, info1->usri1_name); + init_lsa_String(&lsa_account_name, uX.usriX_name); status = rpccli_samr_CreateUser2(pipe_cli, ctx, &domain_handle, @@ -230,14 +285,36 @@ WERROR NetUserAdd_r(struct libnetapi_ctx *ctx, goto done; } + convert_USER_INFO_X_to_samr_user_info21(&uX, + &info21); + ZERO_STRUCTP(user_info); - convert_USER_INFO_1_to_samr_user_info25(info1, - &cli->user_session_key, - &info25); + if (uX.usriX_password) { + + uchar pwbuf[532]; + struct MD5Context md5_ctx; + uint8_t confounder[16]; + DATA_BLOB confounded_session_key = data_blob(NULL, 16); + + encode_pw_buffer(pwbuf, uX.usriX_password, STR_UNICODE); + + generate_random_buffer((uint8_t *)confounder, 16); + + MD5Init(&md5_ctx); + MD5Update(&md5_ctx, confounder, 16); + MD5Update(&md5_ctx, cli->user_session_key.data, + cli->user_session_key.length); + MD5Final(confounded_session_key.data, &md5_ctx); + + SamOEMhashBlob(pwbuf, 516, &confounded_session_key); + memcpy(&pwbuf[516], confounder, 16); + + memcpy(user_info->info25.password.data, pwbuf, sizeof(pwbuf)); + data_blob_free(&confounded_session_key); + + user_info->info25.info = info21; - if (info1->usri1_password) { - user_info->info25 = info25; status = rpccli_samr_SetUserInfo2(pipe_cli, ctx, &user_handle, 25, @@ -245,10 +322,10 @@ WERROR NetUserAdd_r(struct libnetapi_ctx *ctx, if (NT_STATUS_EQUAL(status, NT_STATUS(DCERPC_FAULT_INVALID_TAG))) { - user_info->info23.info = info25.info; + user_info->info23.info = info21; encode_pw_buffer(user_info->info23.password.data, - info1->usri1_password, STR_UNICODE); + uX.usriX_password, STR_UNICODE); SamOEMhashBlob(user_info->info23.password.data, 516, &cli->user_session_key); @@ -258,7 +335,7 @@ WERROR NetUserAdd_r(struct libnetapi_ctx *ctx, user_info); } } else { - user_info->info21 = info25.info; + user_info->info21 = info21; status = rpccli_samr_SetUserInfo(pipe_cli, ctx, &user_handle, 21, -- cgit From b15d2dea75f9d1104285bd1fad01f6872efb6ac3 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 18 Jul 2008 20:12:45 +0200 Subject: netapi: implement NetUserSetInfo_r() for at least level 1007. Guenther (This used to be commit ff9bcd57738aa04c5e18e0e21dd0e788127317c4) --- source3/lib/netapi/user.c | 124 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 123 insertions(+), 1 deletion(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/user.c b/source3/lib/netapi/user.c index faf1a6d65c..fe30b14d77 100644 --- a/source3/lib/netapi/user.c +++ b/source3/lib/netapi/user.c @@ -1296,7 +1296,129 @@ WERROR NetUserGetInfo_l(struct libnetapi_ctx *ctx, WERROR NetUserSetInfo_r(struct libnetapi_ctx *ctx, struct NetUserSetInfo *r) { - return WERR_NOT_SUPPORTED; + struct cli_state *cli = NULL; + struct rpc_pipe_client *pipe_cli = NULL; + NTSTATUS status; + WERROR werr; + + struct policy_handle connect_handle, domain_handle, builtin_handle, user_handle; + struct lsa_String lsa_account_name; + struct dom_sid2 *domain_sid = NULL; + struct samr_Ids user_rids, name_types; + union samr_UserInfo user_info; + + struct USER_INFO_X uX; + + ZERO_STRUCT(connect_handle); + ZERO_STRUCT(domain_handle); + ZERO_STRUCT(builtin_handle); + ZERO_STRUCT(user_handle); + + if (!r->in.buffer) { + return WERR_INVALID_PARAM; + } + + switch (r->in.level) { + case 0: + case 1007: + break; + default: + werr = WERR_NOT_SUPPORTED; + goto done; + } + + werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + werr = libnetapi_open_pipe(ctx, cli, &ndr_table_samr.syntax_id, + &pipe_cli); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + werr = libnetapi_samr_open_domain(ctx, pipe_cli, + SAMR_ACCESS_ENUM_DOMAINS | + SAMR_ACCESS_OPEN_DOMAIN, + SAMR_DOMAIN_ACCESS_LOOKUP_INFO_1 | + SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, + &connect_handle, + &domain_handle, + &domain_sid); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + werr = libnetapi_samr_open_builtin_domain(ctx, pipe_cli, + SAMR_ACCESS_ENUM_DOMAINS | + SAMR_ACCESS_OPEN_DOMAIN, + SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT | + SAMR_DOMAIN_ACCESS_LOOKUP_ALIAS, + &connect_handle, + &builtin_handle); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + init_lsa_String(&lsa_account_name, r->in.user_name); + + status = rpccli_samr_LookupNames(pipe_cli, ctx, + &domain_handle, + 1, + &lsa_account_name, + &user_rids, + &name_types); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + status = rpccli_samr_OpenUser(pipe_cli, ctx, + &domain_handle, + SAMR_USER_ACCESS_SET_ATTRIBUTES, + user_rids.ids[0], + &user_handle); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + status = construct_USER_INFO_X(r->in.level, r->in.buffer, &uX); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + convert_USER_INFO_X_to_samr_user_info21(&uX, &user_info.info21); + + status = rpccli_samr_SetUserInfo(pipe_cli, ctx, + &user_handle, + 21, + &user_info); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + werr = WERR_OK; + + done: + if (!cli) { + return werr; + } + + if (is_valid_policy_hnd(&user_handle)) { + rpccli_samr_Close(pipe_cli, ctx, &user_handle); + } + + if (ctx->disable_policy_handle_cache) { + libnetapi_samr_close_domain_handle(ctx, &domain_handle); + libnetapi_samr_close_builtin_handle(ctx, &builtin_handle); + libnetapi_samr_close_connect_handle(ctx, &connect_handle); + } + + return werr; } /**************************************************************** -- cgit From 3076cc4257d2673d4ecc2734682d45d1736fd462 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 18 Jul 2008 20:43:14 +0200 Subject: netapi: use init_samr_CryptPasswordEx and init_samr_CryptPassword. Guenther (This used to be commit 97106199f1a2add886a14523aa7b402667d2cd89) --- source3/lib/netapi/user.c | 34 +++++++++------------------------- 1 file changed, 9 insertions(+), 25 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/user.c b/source3/lib/netapi/user.c index fe30b14d77..e36274bfad 100644 --- a/source3/lib/netapi/user.c +++ b/source3/lib/netapi/user.c @@ -292,29 +292,12 @@ WERROR NetUserAdd_r(struct libnetapi_ctx *ctx, if (uX.usriX_password) { - uchar pwbuf[532]; - struct MD5Context md5_ctx; - uint8_t confounder[16]; - DATA_BLOB confounded_session_key = data_blob(NULL, 16); - - encode_pw_buffer(pwbuf, uX.usriX_password, STR_UNICODE); - - generate_random_buffer((uint8_t *)confounder, 16); - - MD5Init(&md5_ctx); - MD5Update(&md5_ctx, confounder, 16); - MD5Update(&md5_ctx, cli->user_session_key.data, - cli->user_session_key.length); - MD5Final(confounded_session_key.data, &md5_ctx); - - SamOEMhashBlob(pwbuf, 516, &confounded_session_key); - memcpy(&pwbuf[516], confounder, 16); - - memcpy(user_info->info25.password.data, pwbuf, sizeof(pwbuf)); - data_blob_free(&confounded_session_key); - user_info->info25.info = info21; + init_samr_CryptPasswordEx(uX.usriX_password, + &cli->user_session_key, + &user_info->info25.password); + status = rpccli_samr_SetUserInfo2(pipe_cli, ctx, &user_handle, 25, @@ -324,10 +307,9 @@ WERROR NetUserAdd_r(struct libnetapi_ctx *ctx, user_info->info23.info = info21; - encode_pw_buffer(user_info->info23.password.data, - uX.usriX_password, STR_UNICODE); - SamOEMhashBlob(user_info->info23.password.data, 516, - &cli->user_session_key); + init_samr_CryptPassword(uX.usriX_password, + &cli->user_session_key, + &user_info->info23.password); status = rpccli_samr_SetUserInfo2(pipe_cli, ctx, &user_handle, @@ -335,7 +317,9 @@ WERROR NetUserAdd_r(struct libnetapi_ctx *ctx, user_info); } } else { + user_info->info21 = info21; + status = rpccli_samr_SetUserInfo(pipe_cli, ctx, &user_handle, 21, -- cgit From 44465215ff86452bf4136727c99854a835032505 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 18 Jul 2008 23:33:08 +0200 Subject: netapi: use "buffer" in libnetapi. Guenther (This used to be commit 80957bc1bc1462a2478b3eea64f5cb7a84d08677) --- source3/lib/netapi/group.c | 24 ++++++++++++------------ source3/lib/netapi/libnetapi.c | 28 ++++++++++++++-------------- source3/lib/netapi/libnetapi.h | 14 +++++++------- source3/lib/netapi/localgroup.c | 10 +++++----- source3/lib/netapi/serverinfo.c | 6 +++--- 5 files changed, 41 insertions(+), 41 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/group.c b/source3/lib/netapi/group.c index 04ffb7c807..c1c55c8a31 100644 --- a/source3/lib/netapi/group.c +++ b/source3/lib/netapi/group.c @@ -49,22 +49,22 @@ WERROR NetGroupAdd_r(struct libnetapi_ctx *ctx, ZERO_STRUCT(domain_handle); ZERO_STRUCT(group_handle); - if (!r->in.buf) { + if (!r->in.buffer) { return WERR_INVALID_PARAM; } switch (r->in.level) { case 0: - info0 = (struct GROUP_INFO_0 *)r->in.buf; + info0 = (struct GROUP_INFO_0 *)r->in.buffer; break; case 1: - info1 = (struct GROUP_INFO_1 *)r->in.buf; + info1 = (struct GROUP_INFO_1 *)r->in.buffer; break; case 2: - info2 = (struct GROUP_INFO_2 *)r->in.buf; + info2 = (struct GROUP_INFO_2 *)r->in.buffer; break; case 3: - info3 = (struct GROUP_INFO_3 *)r->in.buf; + info3 = (struct GROUP_INFO_3 *)r->in.buffer; break; default: werr = WERR_UNKNOWN_LEVEL; @@ -478,7 +478,7 @@ WERROR NetGroupSetInfo_r(struct libnetapi_ctx *ctx, switch (r->in.level) { case 0: - g0 = (struct GROUP_INFO_0 *)r->in.buf; + g0 = (struct GROUP_INFO_0 *)r->in.buffer; init_lsa_String(&info.name, g0->grpi0_name); status = rpccli_samr_SetGroupInfo(pipe_cli, ctx, &group_handle, @@ -486,7 +486,7 @@ WERROR NetGroupSetInfo_r(struct libnetapi_ctx *ctx, &info); break; case 1: - g1 = (struct GROUP_INFO_1 *)r->in.buf; + g1 = (struct GROUP_INFO_1 *)r->in.buffer; init_lsa_String(&info.description, g1->grpi1_comment); status = rpccli_samr_SetGroupInfo(pipe_cli, ctx, &group_handle, @@ -494,7 +494,7 @@ WERROR NetGroupSetInfo_r(struct libnetapi_ctx *ctx, &info); break; case 2: - g2 = (struct GROUP_INFO_2 *)r->in.buf; + g2 = (struct GROUP_INFO_2 *)r->in.buffer; init_lsa_String(&info.description, g2->grpi2_comment); status = rpccli_samr_SetGroupInfo(pipe_cli, ctx, &group_handle, @@ -511,7 +511,7 @@ WERROR NetGroupSetInfo_r(struct libnetapi_ctx *ctx, &info); break; case 3: - g3 = (struct GROUP_INFO_3 *)r->in.buf; + g3 = (struct GROUP_INFO_3 *)r->in.buffer; init_lsa_String(&info.description, g3->grpi3_comment); status = rpccli_samr_SetGroupInfo(pipe_cli, ctx, &group_handle, @@ -528,7 +528,7 @@ WERROR NetGroupSetInfo_r(struct libnetapi_ctx *ctx, &info); break; case 1002: - g1002 = (struct GROUP_INFO_1002 *)r->in.buf; + g1002 = (struct GROUP_INFO_1002 *)r->in.buffer; init_lsa_String(&info.description, g1002->grpi1002_comment); status = rpccli_samr_SetGroupInfo(pipe_cli, ctx, &group_handle, @@ -536,7 +536,7 @@ WERROR NetGroupSetInfo_r(struct libnetapi_ctx *ctx, &info); break; case 1005: - g1005 = (struct GROUP_INFO_1005 *)r->in.buf; + g1005 = (struct GROUP_INFO_1005 *)r->in.buffer; info.attributes.attributes = g1005->grpi1005_attributes; status = rpccli_samr_SetGroupInfo(pipe_cli, ctx, &group_handle, @@ -739,7 +739,7 @@ WERROR NetGroupGetInfo_r(struct libnetapi_ctx *ctx, werr = map_group_info_to_buffer(ctx, r->in.level, group_info_all ? &info->all : &info->all2, domain_sid, rids.ids[0], - r->out.buf); + r->out.buffer); if (!W_ERROR_IS_OK(werr)) { goto done; } diff --git a/source3/lib/netapi/libnetapi.c b/source3/lib/netapi/libnetapi.c index 1ebe338f6c..7e9e094df4 100644 --- a/source3/lib/netapi/libnetapi.c +++ b/source3/lib/netapi/libnetapi.c @@ -783,7 +783,7 @@ NET_API_STATUS NetQueryDisplayInformation(const char * server_name /* [in] [uniq NET_API_STATUS NetGroupAdd(const char * server_name /* [in] */, uint32_t level /* [in] */, - uint8_t *buf /* [in] [ref] */, + uint8_t *buffer /* [in] [ref] */, uint32_t *parm_err /* [out] [ref] */) { struct NetGroupAdd r; @@ -799,7 +799,7 @@ NET_API_STATUS NetGroupAdd(const char * server_name /* [in] */, /* In parameters */ r.in.server_name = server_name; r.in.level = level; - r.in.buf = buf; + r.in.buffer = buffer; /* Out parameters */ r.out.parm_err = parm_err; @@ -925,7 +925,7 @@ NET_API_STATUS NetGroupEnum(const char * server_name /* [in] */, NET_API_STATUS NetGroupSetInfo(const char * server_name /* [in] */, const char * group_name /* [in] */, uint32_t level /* [in] */, - uint8_t *buf /* [in] [ref] */, + uint8_t *buffer /* [in] [ref] */, uint32_t *parm_err /* [out] [ref] */) { struct NetGroupSetInfo r; @@ -942,7 +942,7 @@ NET_API_STATUS NetGroupSetInfo(const char * server_name /* [in] */, r.in.server_name = server_name; r.in.group_name = group_name; r.in.level = level; - r.in.buf = buf; + r.in.buffer = buffer; /* Out parameters */ r.out.parm_err = parm_err; @@ -973,7 +973,7 @@ NET_API_STATUS NetGroupSetInfo(const char * server_name /* [in] */, NET_API_STATUS NetGroupGetInfo(const char * server_name /* [in] */, const char * group_name /* [in] */, uint32_t level /* [in] */, - uint8_t **buf /* [out] [ref] */) + uint8_t **buffer /* [out] [ref] */) { struct NetGroupGetInfo r; struct libnetapi_ctx *ctx = NULL; @@ -991,7 +991,7 @@ NET_API_STATUS NetGroupGetInfo(const char * server_name /* [in] */, r.in.level = level; /* Out parameters */ - r.out.buf = buf; + r.out.buffer = buffer; if (DEBUGLEVEL >= 10) { NDR_PRINT_IN_DEBUG(NetGroupGetInfo, &r); @@ -1106,7 +1106,7 @@ NET_API_STATUS NetGroupDelUser(const char * server_name /* [in] */, NET_API_STATUS NetLocalGroupAdd(const char * server_name /* [in] */, uint32_t level /* [in] */, - uint8_t *buf /* [in] [ref] */, + uint8_t *buffer /* [in] [ref] */, uint32_t *parm_err /* [out] [ref] */) { struct NetLocalGroupAdd r; @@ -1122,7 +1122,7 @@ NET_API_STATUS NetLocalGroupAdd(const char * server_name /* [in] */, /* In parameters */ r.in.server_name = server_name; r.in.level = level; - r.in.buf = buf; + r.in.buffer = buffer; /* Out parameters */ r.out.parm_err = parm_err; @@ -1195,7 +1195,7 @@ NET_API_STATUS NetLocalGroupDel(const char * server_name /* [in] */, NET_API_STATUS NetLocalGroupGetInfo(const char * server_name /* [in] */, const char * group_name /* [in] */, uint32_t level /* [in] */, - uint8_t **buf /* [out] [ref] */) + uint8_t **buffer /* [out] [ref] */) { struct NetLocalGroupGetInfo r; struct libnetapi_ctx *ctx = NULL; @@ -1213,7 +1213,7 @@ NET_API_STATUS NetLocalGroupGetInfo(const char * server_name /* [in] */, r.in.level = level; /* Out parameters */ - r.out.buf = buf; + r.out.buffer = buffer; if (DEBUGLEVEL >= 10) { NDR_PRINT_IN_DEBUG(NetLocalGroupGetInfo, &r); @@ -1241,7 +1241,7 @@ NET_API_STATUS NetLocalGroupGetInfo(const char * server_name /* [in] */, NET_API_STATUS NetLocalGroupSetInfo(const char * server_name /* [in] */, const char * group_name /* [in] */, uint32_t level /* [in] */, - uint8_t *buf /* [in] [ref] */, + uint8_t *buffer /* [in] [ref] */, uint32_t *parm_err /* [out] [ref] */) { struct NetLocalGroupSetInfo r; @@ -1258,7 +1258,7 @@ NET_API_STATUS NetLocalGroupSetInfo(const char * server_name /* [in] */, r.in.server_name = server_name; r.in.group_name = group_name; r.in.level = level; - r.in.buf = buf; + r.in.buffer = buffer; /* Out parameters */ r.out.parm_err = parm_err; @@ -1340,7 +1340,7 @@ NET_API_STATUS NetLocalGroupEnum(const char * server_name /* [in] */, ****************************************************************/ NET_API_STATUS NetRemoteTOD(const char * server_name /* [in] */, - uint8_t **buf /* [out] [ref] */) + uint8_t **buffer /* [out] [ref] */) { struct NetRemoteTOD r; struct libnetapi_ctx *ctx = NULL; @@ -1356,7 +1356,7 @@ NET_API_STATUS NetRemoteTOD(const char * server_name /* [in] */, r.in.server_name = server_name; /* Out parameters */ - r.out.buf = buf; + r.out.buffer = buffer; if (DEBUGLEVEL >= 10) { NDR_PRINT_IN_DEBUG(NetRemoteTOD, &r); diff --git a/source3/lib/netapi/libnetapi.h b/source3/lib/netapi/libnetapi.h index 774a0ac269..001040096d 100644 --- a/source3/lib/netapi/libnetapi.h +++ b/source3/lib/netapi/libnetapi.h @@ -138,7 +138,7 @@ WERROR NetQueryDisplayInformation_l(struct libnetapi_ctx *ctx, struct NetQueryDisplayInformation *r); NET_API_STATUS NetGroupAdd(const char * server_name /* [in] */, uint32_t level /* [in] */, - uint8_t *buf /* [in] [ref] */, + uint8_t *buffer /* [in] [ref] */, uint32_t *parm_err /* [out] [ref] */); WERROR NetGroupAdd_r(struct libnetapi_ctx *ctx, struct NetGroupAdd *r); @@ -164,7 +164,7 @@ WERROR NetGroupEnum_l(struct libnetapi_ctx *ctx, NET_API_STATUS NetGroupSetInfo(const char * server_name /* [in] */, const char * group_name /* [in] */, uint32_t level /* [in] */, - uint8_t *buf /* [in] [ref] */, + uint8_t *buffer /* [in] [ref] */, uint32_t *parm_err /* [out] [ref] */); WERROR NetGroupSetInfo_r(struct libnetapi_ctx *ctx, struct NetGroupSetInfo *r); @@ -173,7 +173,7 @@ WERROR NetGroupSetInfo_l(struct libnetapi_ctx *ctx, NET_API_STATUS NetGroupGetInfo(const char * server_name /* [in] */, const char * group_name /* [in] */, uint32_t level /* [in] */, - uint8_t **buf /* [out] [ref] */); + uint8_t **buffer /* [out] [ref] */); WERROR NetGroupGetInfo_r(struct libnetapi_ctx *ctx, struct NetGroupGetInfo *r); WERROR NetGroupGetInfo_l(struct libnetapi_ctx *ctx, @@ -194,7 +194,7 @@ WERROR NetGroupDelUser_l(struct libnetapi_ctx *ctx, struct NetGroupDelUser *r); NET_API_STATUS NetLocalGroupAdd(const char * server_name /* [in] */, uint32_t level /* [in] */, - uint8_t *buf /* [in] [ref] */, + uint8_t *buffer /* [in] [ref] */, uint32_t *parm_err /* [out] [ref] */); WERROR NetLocalGroupAdd_r(struct libnetapi_ctx *ctx, struct NetLocalGroupAdd *r); @@ -209,7 +209,7 @@ WERROR NetLocalGroupDel_l(struct libnetapi_ctx *ctx, NET_API_STATUS NetLocalGroupGetInfo(const char * server_name /* [in] */, const char * group_name /* [in] */, uint32_t level /* [in] */, - uint8_t **buf /* [out] [ref] */); + uint8_t **buffer /* [out] [ref] */); WERROR NetLocalGroupGetInfo_r(struct libnetapi_ctx *ctx, struct NetLocalGroupGetInfo *r); WERROR NetLocalGroupGetInfo_l(struct libnetapi_ctx *ctx, @@ -217,7 +217,7 @@ WERROR NetLocalGroupGetInfo_l(struct libnetapi_ctx *ctx, NET_API_STATUS NetLocalGroupSetInfo(const char * server_name /* [in] */, const char * group_name /* [in] */, uint32_t level /* [in] */, - uint8_t *buf /* [in] [ref] */, + uint8_t *buffer /* [in] [ref] */, uint32_t *parm_err /* [out] [ref] */); WERROR NetLocalGroupSetInfo_r(struct libnetapi_ctx *ctx, struct NetLocalGroupSetInfo *r); @@ -235,7 +235,7 @@ WERROR NetLocalGroupEnum_r(struct libnetapi_ctx *ctx, WERROR NetLocalGroupEnum_l(struct libnetapi_ctx *ctx, struct NetLocalGroupEnum *r); NET_API_STATUS NetRemoteTOD(const char * server_name /* [in] */, - uint8_t **buf /* [out] [ref] */); + uint8_t **buffer /* [out] [ref] */); WERROR NetRemoteTOD_r(struct libnetapi_ctx *ctx, struct NetRemoteTOD *r); WERROR NetRemoteTOD_l(struct libnetapi_ctx *ctx, diff --git a/source3/lib/netapi/localgroup.c b/source3/lib/netapi/localgroup.c index 57067621b7..a0a122d74b 100644 --- a/source3/lib/netapi/localgroup.c +++ b/source3/lib/netapi/localgroup.c @@ -138,17 +138,17 @@ WERROR NetLocalGroupAdd_r(struct libnetapi_ctx *ctx, const char *alias_name = NULL; - if (!r->in.buf) { + if (!r->in.buffer) { return WERR_INVALID_PARAM; } switch (r->in.level) { case 0: - info0 = (struct LOCALGROUP_INFO_0 *)r->in.buf; + info0 = (struct LOCALGROUP_INFO_0 *)r->in.buffer; alias_name = info0->lgrpi0_name; break; case 1: - info1 = (struct LOCALGROUP_INFO_1 *)r->in.buf; + info1 = (struct LOCALGROUP_INFO_1 *)r->in.buffer; alias_name = info1->lgrpi1_name; break; default: @@ -546,7 +546,7 @@ WERROR NetLocalGroupGetInfo_r(struct libnetapi_ctx *ctx, r->in.group_name, &alias_info->all, r->in.level, &entries_read, - r->out.buf); + r->out.buffer); done: if (!cli) { @@ -713,7 +713,7 @@ WERROR NetLocalGroupSetInfo_r(struct libnetapi_ctx *ctx, set_alias: - werr = map_buffer_to_alias_info(ctx, r->in.level, r->in.buf, + werr = map_buffer_to_alias_info(ctx, r->in.level, r->in.buffer, &alias_level, &alias_info); if (!W_ERROR_IS_OK(werr)) { goto done; diff --git a/source3/lib/netapi/serverinfo.c b/source3/lib/netapi/serverinfo.c index a591d3753a..622b8d425d 100644 --- a/source3/lib/netapi/serverinfo.c +++ b/source3/lib/netapi/serverinfo.c @@ -238,9 +238,9 @@ WERROR NetRemoteTOD_r(struct libnetapi_ctx *ctx, goto done; } - *r->out.buf = (uint8_t *)talloc_memdup(ctx, info, - sizeof(struct srvsvc_NetRemoteTODInfo)); - W_ERROR_HAVE_NO_MEMORY(*r->out.buf); + *r->out.buffer = (uint8_t *)talloc_memdup(ctx, info, + sizeof(struct srvsvc_NetRemoteTODInfo)); + W_ERROR_HAVE_NO_MEMORY(*r->out.buffer); done: return werr; -- cgit From 603688f4ab1296f65240eeacb2fc5a81db897955 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 18 Jul 2008 23:35:33 +0200 Subject: netapi: fix libnetapi_samr_lookup_user_map_USER_INFO. Guenther (This used to be commit 52218506d6ad51c4f340206d035f79272ba15e3b) --- source3/lib/netapi/user.c | 68 +++++++++++++++++++++-------------------------- 1 file changed, 31 insertions(+), 37 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/user.c b/source3/lib/netapi/user.c index e36274bfad..4bcab4c372 100644 --- a/source3/lib/netapi/user.c +++ b/source3/lib/netapi/user.c @@ -612,10 +612,10 @@ static NTSTATUS libnetapi_samr_lookup_user_map_USER_INFO(TALLOC_CTX *mem_ctx, struct sec_desc_buf *sec_desc = NULL; struct dom_sid sid; - struct USER_INFO_0 *info0 = NULL; - struct USER_INFO_10 *info10 = NULL; - struct USER_INFO_20 *info20 = NULL; - struct USER_INFO_23 *info23 = NULL; + struct USER_INFO_0 info0; + struct USER_INFO_10 info10; + struct USER_INFO_20 info20; + struct USER_INFO_23 info23; switch (level) { case 0: @@ -632,13 +632,10 @@ static NTSTATUS libnetapi_samr_lookup_user_map_USER_INFO(TALLOC_CTX *mem_ctx, } if (level == 0) { - info0 = TALLOC_P(mem_ctx, struct USER_INFO_0); - NT_STATUS_HAVE_NO_MEMORY(info0); + info0.usri0_name = talloc_strdup(mem_ctx, user_name); + NT_STATUS_HAVE_NO_MEMORY(info0.usri0_name); - info0->usri0_name = talloc_strdup(mem_ctx, user_name); - NT_STATUS_HAVE_NO_MEMORY(info0->usri0_name); - - ADD_TO_ARRAY(mem_ctx, struct USER_INFO_0, *info0, + ADD_TO_ARRAY(mem_ctx, struct USER_INFO_0, info0, (struct USER_INFO_0 **)buffer, num_entries); return NT_STATUS_OK; @@ -659,63 +656,60 @@ static NTSTATUS libnetapi_samr_lookup_user_map_USER_INFO(TALLOC_CTX *mem_ctx, switch (level) { case 10: - info10 = TALLOC_P(mem_ctx, struct USER_INFO_10); - NT_STATUS_HAVE_NO_MEMORY(info10); - - info10->usri10_name = talloc_strdup(mem_ctx, user_name); - NT_STATUS_HAVE_NO_MEMORY(info10->usri10_name); + info10.usri10_name = talloc_strdup(mem_ctx, user_name); + NT_STATUS_HAVE_NO_MEMORY(info10.usri10_name); - info10->usri10_comment = talloc_strdup(mem_ctx, + info10.usri10_comment = talloc_strdup(mem_ctx, info21->description.string); - info10->usri10_full_name = talloc_strdup(mem_ctx, + info10.usri10_full_name = talloc_strdup(mem_ctx, info21->full_name.string); - info10->usri10_usr_comment = talloc_strdup(mem_ctx, + info10.usri10_usr_comment = talloc_strdup(mem_ctx, info21->comment.string); - ADD_TO_ARRAY(mem_ctx, struct USER_INFO_10, *info10, + ADD_TO_ARRAY(mem_ctx, struct USER_INFO_10, info10, (struct USER_INFO_10 **)buffer, num_entries); break; case 20: - info20 = TALLOC_P(mem_ctx, struct USER_INFO_20); - NT_STATUS_HAVE_NO_MEMORY(info20); + info20.usri20_name = talloc_strdup(mem_ctx, user_name); + NT_STATUS_HAVE_NO_MEMORY(info20.usri20_name); - info20->usri20_name = talloc_strdup(mem_ctx, user_name); - NT_STATUS_HAVE_NO_MEMORY(info20->usri20_name); - - info20->usri20_comment = talloc_strdup(mem_ctx, + info20.usri20_comment = talloc_strdup(mem_ctx, info21->description.string); - info20->usri20_flags = info21->acct_flags; - info20->usri20_user_id = rid; + info20.usri20_full_name = talloc_strdup(mem_ctx, + info21->full_name.string); + + info20.usri20_flags = info21->acct_flags; + info20.usri20_user_id = rid; - ADD_TO_ARRAY(mem_ctx, struct USER_INFO_20, *info20, + ADD_TO_ARRAY(mem_ctx, struct USER_INFO_20, info20, (struct USER_INFO_20 **)buffer, num_entries); break; case 23: - info23 = TALLOC_P(mem_ctx, struct USER_INFO_23); - NT_STATUS_HAVE_NO_MEMORY(info23); - - info23->usri23_name = talloc_strdup(mem_ctx, user_name); - NT_STATUS_HAVE_NO_MEMORY(info23->usri23_name); + info23.usri23_name = talloc_strdup(mem_ctx, user_name); + NT_STATUS_HAVE_NO_MEMORY(info23.usri23_name); - info23->usri23_comment = talloc_strdup(mem_ctx, + info23.usri23_comment = talloc_strdup(mem_ctx, info21->description.string); - info23->usri23_flags = info21->acct_flags; + info23.usri23_full_name = talloc_strdup(mem_ctx, + info21->full_name.string); + + info23.usri23_flags = info21->acct_flags; if (!sid_compose(&sid, domain_sid, rid)) { return NT_STATUS_NO_MEMORY; } - info23->usri23_user_sid = + info23.usri23_user_sid = (struct domsid *)sid_dup_talloc(mem_ctx, &sid); - ADD_TO_ARRAY(mem_ctx, struct USER_INFO_23, *info23, + ADD_TO_ARRAY(mem_ctx, struct USER_INFO_23, info23, (struct USER_INFO_23 **)buffer, num_entries); break; } -- cgit From cf2ac8f8db3b62afb2c9a6ff56de5d9691af5a0f Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 18 Jul 2008 23:40:33 +0200 Subject: netapi: add NetGroupGetUsers skeleton. GUenther (This used to be commit 0b4e2687ae8fb48faacceb4078d61f9fd2acea9d) --- source3/lib/netapi/group.c | 18 ++++++++++++++ source3/lib/netapi/libnetapi.c | 55 ++++++++++++++++++++++++++++++++++++++++++ source3/lib/netapi/libnetapi.h | 12 +++++++++ 3 files changed, 85 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/group.c b/source3/lib/netapi/group.c index c1c55c8a31..30ff6af2f0 100644 --- a/source3/lib/netapi/group.c +++ b/source3/lib/netapi/group.c @@ -1306,3 +1306,21 @@ WERROR NetGroupEnum_l(struct libnetapi_ctx *ctx, { return NetGroupEnum_r(ctx, r); } + +/**************************************************************** +****************************************************************/ + +WERROR NetGroupGetUsers_r(struct libnetapi_ctx *ctx, + struct NetGroupGetUsers *r) +{ + return WERR_NOT_SUPPORTED; +} + +/**************************************************************** +****************************************************************/ + +WERROR NetGroupGetUsers_l(struct libnetapi_ctx *ctx, + struct NetGroupGetUsers *r) +{ + return WERR_NOT_SUPPORTED; +} diff --git a/source3/lib/netapi/libnetapi.c b/source3/lib/netapi/libnetapi.c index 7e9e094df4..fe57238303 100644 --- a/source3/lib/netapi/libnetapi.c +++ b/source3/lib/netapi/libnetapi.c @@ -1100,6 +1100,61 @@ NET_API_STATUS NetGroupDelUser(const char * server_name /* [in] */, return r.out.result; } +/**************************************************************** + NetGroupGetUsers +****************************************************************/ + +NET_API_STATUS NetGroupGetUsers(const char * server_name /* [in] */, + const char * group_name /* [in] */, + uint32_t level /* [in] */, + uint8_t **buffer /* [out] [ref] */, + uint32_t prefmaxlen /* [in] */, + uint32_t *entries_read /* [out] [ref] */, + uint32_t *total_entries /* [out] [ref] */, + uint32_t *resume_handle /* [in,out] [ref] */) +{ + struct NetGroupGetUsers r; + struct libnetapi_ctx *ctx = NULL; + NET_API_STATUS status; + WERROR werr; + + status = libnetapi_getctx(&ctx); + if (status != 0) { + return status; + } + + /* In parameters */ + r.in.server_name = server_name; + r.in.group_name = group_name; + r.in.level = level; + r.in.prefmaxlen = prefmaxlen; + r.in.resume_handle = resume_handle; + + /* Out parameters */ + r.out.buffer = buffer; + r.out.entries_read = entries_read; + r.out.total_entries = total_entries; + r.out.resume_handle = resume_handle; + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_IN_DEBUG(NetGroupGetUsers, &r); + } + + if (LIBNETAPI_LOCAL_SERVER(server_name)) { + werr = NetGroupGetUsers_l(ctx, &r); + } else { + werr = NetGroupGetUsers_r(ctx, &r); + } + + r.out.result = W_ERROR_V(werr); + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_OUT_DEBUG(NetGroupGetUsers, &r); + } + + return r.out.result; +} + /**************************************************************** NetLocalGroupAdd ****************************************************************/ diff --git a/source3/lib/netapi/libnetapi.h b/source3/lib/netapi/libnetapi.h index 001040096d..5c9e2e2cef 100644 --- a/source3/lib/netapi/libnetapi.h +++ b/source3/lib/netapi/libnetapi.h @@ -192,6 +192,18 @@ WERROR NetGroupDelUser_r(struct libnetapi_ctx *ctx, struct NetGroupDelUser *r); WERROR NetGroupDelUser_l(struct libnetapi_ctx *ctx, struct NetGroupDelUser *r); +NET_API_STATUS NetGroupGetUsers(const char * server_name /* [in] */, + const char * group_name /* [in] */, + uint32_t level /* [in] */, + uint8_t **buffer /* [out] [ref] */, + uint32_t prefmaxlen /* [in] */, + uint32_t *entries_read /* [out] [ref] */, + uint32_t *total_entries /* [out] [ref] */, + uint32_t *resume_handle /* [in,out] [ref] */); +WERROR NetGroupGetUsers_r(struct libnetapi_ctx *ctx, + struct NetGroupGetUsers *r); +WERROR NetGroupGetUsers_l(struct libnetapi_ctx *ctx, + struct NetGroupGetUsers *r); NET_API_STATUS NetLocalGroupAdd(const char * server_name /* [in] */, uint32_t level /* [in] */, uint8_t *buffer /* [in] [ref] */, -- cgit From 493fb24e37f5685c5999eb684f5a8ca0bcf8e09e Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 18 Jul 2008 23:43:33 +0200 Subject: netapi: add NetGroupGetUsers to public header. Guenther (This used to be commit d31f822b79ed5344ec3c6795d66ceefd024b7d30) --- source3/lib/netapi/netapi.h | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h index 7d32ffcbae..a1041c009d 100644 --- a/source3/lib/netapi/netapi.h +++ b/source3/lib/netapi/netapi.h @@ -290,6 +290,15 @@ struct GROUP_INFO_1005 { uint32_t grpi1005_attributes; }; +struct GROUP_USERS_INFO_0 { + const char * grui0_name; +}; + +struct GROUP_USERS_INFO_1 { + const char * grui1_name; + uint32_t grui1_attributes; +}; + struct LOCALGROUP_INFO_0 { const char * lgrpi0_name; }; @@ -899,6 +908,35 @@ NET_API_STATUS NetGroupDelUser(const char * server_name /* [in] */, const char * group_name /* [in] */, const char * user_name /* [in] */); +/************************************************************//** + * + * NetGroupGetUsers + * + * @brief Get Users for a group on a server + * + * @param[in] server_name The server name to connect to + * @param[in] group_name The group name to enumerate users for + * @param[in] level The enumeration level used for the query + * @param[out] buffer The returned enumeration buffer + * @param[in] prefmaxlen The requested maximal buffer size + * @param[out] entries_read The number of returned entries + * @param[out] total_entries The number of total entries + * @param[in,out] resume_handle A handle passed in and returned for resuming + * operations + * @return NET_API_STATUS + * + * example group/group_getusers.c + ***************************************************************/ + +NET_API_STATUS NetGroupGetUsers(const char * server_name /* [in] */, + const char * group_name /* [in] */, + uint32_t level /* [in] */, + uint8_t **buffer /* [out] [ref] */, + uint32_t prefmaxlen /* [in] */, + uint32_t *entries_read /* [out] [ref] */, + uint32_t *total_entries /* [out] [ref] */, + uint32_t *resume_handle /* [in,out] [ref] */); + /************************************************************//** * * NetLocalGroupAdd -- cgit From 7a7902692aabf7541cefd33cc2f825aa81ef4406 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Sat, 19 Jul 2008 00:10:58 +0200 Subject: netapi: add NetGroupGetUsers example code. Guenther (This used to be commit 0298f7fe9e273a94d14b5b6ce3dbd5e6deee9ecb) --- source3/lib/netapi/examples/Makefile.in | 6 + source3/lib/netapi/examples/group/group_getusers.c | 132 +++++++++++++++++++++ 2 files changed, 138 insertions(+) create mode 100644 source3/lib/netapi/examples/group/group_getusers.c (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/Makefile.in b/source3/lib/netapi/examples/Makefile.in index ca387ee79c..e7b61a1776 100644 --- a/source3/lib/netapi/examples/Makefile.in +++ b/source3/lib/netapi/examples/Makefile.in @@ -36,6 +36,7 @@ PROGS = bin/getdc@EXEEXT@ \ bin/group_getinfo@EXEEXT@ \ bin/group_adduser@EXEEXT@ \ bin/group_deluser@EXEEXT@ \ + bin/group_getusers@EXEEXT@ \ bin/localgroup_add@EXEEXT@ \ bin/localgroup_del@EXEEXT@ \ bin/localgroup_getinfo@EXEEXT@ \ @@ -89,6 +90,7 @@ GROUPSETINFO_OBJ = group/group_setinfo.o $(CMDLINE_OBJ) GROUPGETINFO_OBJ = group/group_getinfo.o $(CMDLINE_OBJ) GROUPADDUSER_OBJ = group/group_adduser.o $(CMDLINE_OBJ) GROUPDELUSER_OBJ = group/group_deluser.o $(CMDLINE_OBJ) +GROUPGETUSERS_OBJ = group/group_getusers.o $(CMDLINE_OBJ) LOCALGROUPADD_OBJ = localgroup/localgroup_add.o $(CMDLINE_OBJ) LOCALGROUPDEL_OBJ = localgroup/localgroup_del.o $(CMDLINE_OBJ) LOCALGROUPGETINFO_OBJ = localgroup/localgroup_getinfo.o $(CMDLINE_OBJ) @@ -172,6 +174,10 @@ bin/group_deluser@EXEEXT@: $(BINARY_PREREQS) $(GROUPDELUSER_OBJ) @echo Linking $@ @$(CC) $(FLAGS) -o $@ $(GROUPDELUSER_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) +bin/group_getusers@EXEEXT@: $(BINARY_PREREQS) $(GROUPGETUSERS_OBJ) + @echo Linking $@ + @$(CC) $(FLAGS) -o $@ $(GROUPGETUSERS_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) + bin/localgroup_add@EXEEXT@: $(BINARY_PREREQS) $(LOCALGROUPADD_OBJ) @echo Linking $@ @$(CC) $(FLAGS) -o $@ $(LOCALGROUPADD_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) diff --git a/source3/lib/netapi/examples/group/group_getusers.c b/source3/lib/netapi/examples/group/group_getusers.c new file mode 100644 index 0000000000..55d0717aa5 --- /dev/null +++ b/source3/lib/netapi/examples/group/group_getusers.c @@ -0,0 +1,132 @@ +/* + * Unix SMB/CIFS implementation. + * NetGroupGetUsers query + * Copyright (C) Guenther Deschner 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include +#include +#include +#include +#include + +#include + +#include "common.h" + +int main(int argc, const char **argv) +{ + NET_API_STATUS status; + struct libnetapi_ctx *ctx = NULL; + const char *hostname = NULL; + const char *groupname = NULL; + uint32_t level = 0; + uint8_t *buffer = NULL; + uint32_t entries_read = 0; + uint32_t total_entries = 0; + uint32_t resume_handle = 0; + int i; + + struct GROUP_USERS_INFO_0 *info0 = NULL; + struct GROUP_USERS_INFO_1 *info1 = NULL; + + poptContext pc; + int opt; + + struct poptOption long_options[] = { + POPT_AUTOHELP + POPT_COMMON_LIBNETAPI_EXAMPLES + POPT_TABLEEND + }; + + status = libnetapi_init(&ctx); + if (status != 0) { + return status; + } + + pc = poptGetContext("group_getusers", argc, argv, long_options, 0); + + poptSetOtherOptionHelp(pc, "hostname groupname level"); + while((opt = poptGetNextOpt(pc)) != -1) { + } + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + hostname = poptGetArg(pc); + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + groupname = poptGetArg(pc); + + if (poptPeekArg(pc)) { + level = atoi(poptGetArg(pc)); + } + + /* NetGroupGetUsers */ + + do { + status = NetGroupGetUsers(hostname, + groupname, + level, + &buffer, + (uint32_t)-1, + &entries_read, + &total_entries, + &resume_handle); + if (status == 0 || status == ERROR_MORE_DATA) { + printf("total entries: %d\n", total_entries); + switch (level) { + case 0: + info0 = (struct GROUP_USERS_INFO_0 *)buffer; + break; + case 1: + info1 = (struct GROUP_USERS_INFO_1 *)buffer; + break; + default: + break; + } + for (i=0; igrui0_name); + info0++; + break; + case 1: + printf("#%d group: %s\n", i, info1->grui1_name); + printf("#%d attributes: %d\n", i, info1->grui1_attributes); + info1++; + break; + } + } + NetApiBufferFree(buffer); + } + } while (status == ERROR_MORE_DATA); + + if (status != 0) { + printf("NetGroupGetUsers failed with: %s\n", + libnetapi_get_error_string(ctx, status)); + } + + out: + libnetapi_free(ctx); + poptFreeContext(pc); + + return status; +} -- cgit From d701d23b604dd21288e894b7d286de206eca2857 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 30 Jul 2008 16:06:30 -0700 Subject: Fix uninitialized variables. Jeremy. (This used to be commit 1db7e00a5400863fd5dbb81c1a4c6ea6092d0495) --- source3/lib/netapi/cm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/cm.c b/source3/lib/netapi/cm.c index 8eaabb3cda..8ea31e54f9 100644 --- a/source3/lib/netapi/cm.c +++ b/source3/lib/netapi/cm.c @@ -165,7 +165,7 @@ WERROR libnetapi_open_pipe(struct libnetapi_ctx *ctx, const struct ndr_syntax_id *interface, struct rpc_pipe_client **presult) { - struct rpc_pipe_client *result; + struct rpc_pipe_client *result = NULL; NTSTATUS status; if (!cli || !presult) { -- cgit From 4b74ae0f15303cbd6def0aef033424a14416947b Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 31 Jul 2008 15:11:20 +0200 Subject: netapi: in NetLocalGroupAdd_r() only set description if necessary. Guenther (This used to be commit 7e9fa2c5396d3663e83ffbf90475473fdb509871) --- source3/lib/netapi/localgroup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/localgroup.c b/source3/lib/netapi/localgroup.c index a0a122d74b..c15a17efb1 100644 --- a/source3/lib/netapi/localgroup.c +++ b/source3/lib/netapi/localgroup.c @@ -223,7 +223,7 @@ WERROR NetLocalGroupAdd_r(struct libnetapi_ctx *ctx, goto done; } - if (r->in.level == 1) { + if (r->in.level == 1 && info1->lgrpi1_comment) { union samr_AliasInfo alias_info; -- cgit From c7c35108105eea60e3cf81f2d53d241889349c91 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 1 Aug 2008 15:15:05 +0200 Subject: netapi: add ConvertStringSidToSid(). Guenther (This used to be commit 36f1e45e4ec295115f1ba39ec7ad3690a96dac3e) --- source3/lib/netapi/netapi.h | 15 +++++++++++++++ source3/lib/netapi/sid.c | 26 ++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h index a1041c009d..2c6b667123 100644 --- a/source3/lib/netapi/netapi.h +++ b/source3/lib/netapi/netapi.h @@ -422,6 +422,21 @@ NET_API_STATUS NetApiBufferFree(void *buffer); int ConvertSidToStringSid(const struct domsid *sid, char **sid_string); +/************************************************************//** + * + * ConvertStringSidToSid + * + * @brief Convert a string into a domain sid + * + * @param[in] sid_string A pointer to a sid string. + * @param[in] sid A pointer that holds a pointer to a sid structure. + * Caller needs to free with free(3) + * @return bool + ***************************************************************/ + +int ConvertStringSidToSid(const char *sid_string, + struct domsid **sid); + /************************************************************//** * * NetJoinDomain diff --git a/source3/lib/netapi/sid.c b/source3/lib/netapi/sid.c index 4db98bf3d2..a9bca2689f 100644 --- a/source3/lib/netapi/sid.c +++ b/source3/lib/netapi/sid.c @@ -48,3 +48,29 @@ int ConvertSidToStringSid(const struct domsid *sid, return true; } + +/**************************************************************** +****************************************************************/ + +int ConvertStringSidToSid(const char *sid_string, + struct domsid **sid) +{ + struct dom_sid _sid; + + if (!sid_string || !sid) { + return false; + } + + if (!string_to_sid(&_sid, sid_string)) { + return false; + } + + *sid = (struct domsid *)SMB_MALLOC(sizeof(struct domsid)); + if (!*sid) { + return false; + } + + sid_copy((struct dom_sid*)*sid, &_sid); + + return true; +} -- cgit From e480162e5b44cd9705b05a0bf9d64894309a7ae4 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 1 Aug 2008 16:44:05 +0200 Subject: netapi: add NetApiBufferAllocate. Guenther (This used to be commit 99cc8f023b4ad9210b677e11371f404048752031) --- source3/lib/netapi/netapi.c | 27 +++++++++++++++++++++++++++ source3/lib/netapi/netapi.h | 6 ++++++ 2 files changed, 33 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi.c b/source3/lib/netapi/netapi.c index 7d78aa8120..889388173f 100644 --- a/source3/lib/netapi/netapi.c +++ b/source3/lib/netapi/netapi.c @@ -309,6 +309,33 @@ const char *libnetapi_get_error_string(struct libnetapi_ctx *ctx, /**************************************************************** ****************************************************************/ +NET_API_STATUS NetApiBufferAllocate(uint32_t byte_count, + void **buffer) +{ + void *buf = NULL; + + if (!buffer) { + return W_ERROR_V(WERR_INSUFFICIENT_BUFFER); + } + + if (byte_count == 0) { + goto done; + } + + buf = talloc_size(NULL, byte_count); + if (!buf) { + return W_ERROR_V(WERR_NOMEM); + } + + done: + *buffer = buf; + + return NET_API_STATUS_SUCCESS; +} + +/**************************************************************** +****************************************************************/ + NET_API_STATUS NetApiBufferFree(void *buffer) { if (!buffer) { diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h index 2c6b667123..9cc8e9eca4 100644 --- a/source3/lib/netapi/netapi.h +++ b/source3/lib/netapi/netapi.h @@ -400,6 +400,12 @@ const char *libnetapi_errstr(NET_API_STATUS status); const char *libnetapi_get_error_string(struct libnetapi_ctx *ctx, NET_API_STATUS status); +/**************************************************************** + NetApiBufferAllocate +****************************************************************/ + +NET_API_STATUS NetApiBufferAllocate(uint32_t byte_count, + void **buffer); /**************************************************************** NetApiBufferFree -- cgit From 974250cd03410cfcd72b8539565061dde33e79c9 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 31 Jul 2008 16:43:27 +0200 Subject: netapi: add skeleton for NetUserModalsGet and NetUserModalsSet. Guenther (This used to be commit 5648145bec3bd24ecedea24a8834ac6768bfc640) --- source3/lib/netapi/libnetapi.c | 90 ++++++++++++++++++++++++++++++++++++++++++ source3/lib/netapi/libnetapi.h | 15 +++++++ source3/lib/netapi/user.c | 35 ++++++++++++++++ 3 files changed, 140 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/libnetapi.c b/source3/lib/netapi/libnetapi.c index fe57238303..adc875d213 100644 --- a/source3/lib/netapi/libnetapi.c +++ b/source3/lib/netapi/libnetapi.c @@ -725,6 +725,96 @@ NET_API_STATUS NetUserSetInfo(const char * server_name /* [in] */, return r.out.result; } +/**************************************************************** + NetUserModalsGet +****************************************************************/ + +NET_API_STATUS NetUserModalsGet(const char * server_name /* [in] */, + uint32_t level /* [in] */, + uint8_t **buffer /* [out] [ref] */) +{ + struct NetUserModalsGet r; + struct libnetapi_ctx *ctx = NULL; + NET_API_STATUS status; + WERROR werr; + + status = libnetapi_getctx(&ctx); + if (status != 0) { + return status; + } + + /* In parameters */ + r.in.server_name = server_name; + r.in.level = level; + + /* Out parameters */ + r.out.buffer = buffer; + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_IN_DEBUG(NetUserModalsGet, &r); + } + + if (LIBNETAPI_LOCAL_SERVER(server_name)) { + werr = NetUserModalsGet_l(ctx, &r); + } else { + werr = NetUserModalsGet_r(ctx, &r); + } + + r.out.result = W_ERROR_V(werr); + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_OUT_DEBUG(NetUserModalsGet, &r); + } + + return r.out.result; +} + +/**************************************************************** + NetUserModalsSet +****************************************************************/ + +NET_API_STATUS NetUserModalsSet(const char * server_name /* [in] */, + uint32_t level /* [in] */, + uint8_t *buffer /* [in] [ref] */, + uint32_t *parm_err /* [out] [ref] */) +{ + struct NetUserModalsSet r; + struct libnetapi_ctx *ctx = NULL; + NET_API_STATUS status; + WERROR werr; + + status = libnetapi_getctx(&ctx); + if (status != 0) { + return status; + } + + /* In parameters */ + r.in.server_name = server_name; + r.in.level = level; + r.in.buffer = buffer; + + /* Out parameters */ + r.out.parm_err = parm_err; + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_IN_DEBUG(NetUserModalsSet, &r); + } + + if (LIBNETAPI_LOCAL_SERVER(server_name)) { + werr = NetUserModalsSet_l(ctx, &r); + } else { + werr = NetUserModalsSet_r(ctx, &r); + } + + r.out.result = W_ERROR_V(werr); + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_OUT_DEBUG(NetUserModalsSet, &r); + } + + return r.out.result; +} + /**************************************************************** NetQueryDisplayInformation ****************************************************************/ diff --git a/source3/lib/netapi/libnetapi.h b/source3/lib/netapi/libnetapi.h index 5c9e2e2cef..8e7a662d60 100644 --- a/source3/lib/netapi/libnetapi.h +++ b/source3/lib/netapi/libnetapi.h @@ -125,6 +125,21 @@ WERROR NetUserSetInfo_r(struct libnetapi_ctx *ctx, struct NetUserSetInfo *r); WERROR NetUserSetInfo_l(struct libnetapi_ctx *ctx, struct NetUserSetInfo *r); +NET_API_STATUS NetUserModalsGet(const char * server_name /* [in] */, + uint32_t level /* [in] */, + uint8_t **buffer /* [out] [ref] */); +WERROR NetUserModalsGet_r(struct libnetapi_ctx *ctx, + struct NetUserModalsGet *r); +WERROR NetUserModalsGet_l(struct libnetapi_ctx *ctx, + struct NetUserModalsGet *r); +NET_API_STATUS NetUserModalsSet(const char * server_name /* [in] */, + uint32_t level /* [in] */, + uint8_t *buffer /* [in] [ref] */, + uint32_t *parm_err /* [out] [ref] */); +WERROR NetUserModalsSet_r(struct libnetapi_ctx *ctx, + struct NetUserModalsSet *r); +WERROR NetUserModalsSet_l(struct libnetapi_ctx *ctx, + struct NetUserModalsSet *r); NET_API_STATUS NetQueryDisplayInformation(const char * server_name /* [in] [unique] */, uint32_t level /* [in] */, uint32_t idx /* [in] */, diff --git a/source3/lib/netapi/user.c b/source3/lib/netapi/user.c index 4bcab4c372..f52941235b 100644 --- a/source3/lib/netapi/user.c +++ b/source3/lib/netapi/user.c @@ -1408,3 +1408,38 @@ WERROR NetUserSetInfo_l(struct libnetapi_ctx *ctx, return WERR_NOT_SUPPORTED; } +/**************************************************************** +****************************************************************/ + +WERROR NetUserModalsGet_r(struct libnetapi_ctx *ctx, + struct NetUserModalsGet *r) +{ + return WERR_NOT_SUPPORTED; +} + +/**************************************************************** +****************************************************************/ + +WERROR NetUserModalsGet_l(struct libnetapi_ctx *ctx, + struct NetUserModalsGet *r) +{ + return WERR_NOT_SUPPORTED; +} + +/**************************************************************** +****************************************************************/ + +WERROR NetUserModalsSet_r(struct libnetapi_ctx *ctx, + struct NetUserModalsSet *r) +{ + return WERR_NOT_SUPPORTED; +} + +/**************************************************************** +****************************************************************/ + +WERROR NetUserModalsSet_l(struct libnetapi_ctx *ctx, + struct NetUserModalsSet *r) +{ + return WERR_NOT_SUPPORTED; +} -- cgit From ee43b80149933980b5280cf66f51f16d3a10d97b Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 31 Jul 2008 16:47:15 +0200 Subject: netapi: add NetUserModalsGet and NetUserModalsSet to public headers. Guenther (This used to be commit b4c912bfbc62768ff4d7ecb39c02dc4a2a9825d2) --- source3/lib/netapi/netapi.h | 62 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h index 9cc8e9eca4..9b6288d9e9 100644 --- a/source3/lib/netapi/netapi.h +++ b/source3/lib/netapi/netapi.h @@ -75,6 +75,8 @@ struct DOMAIN_CONTROLLER_INFO { #define FILTER_WORKSTATION_TRUST_ACCOUNT ( 0x0010 ) #define FILTER_SERVER_TRUST_ACCOUNT ( 0x0020 ) +#define TIMEQ_FOREVER ( (uint32_t)-1L ) + struct SERVER_INFO_1005 { const char * sv1005_comment; }; @@ -234,6 +236,58 @@ struct USER_INFO_1007 { const char * usri1007_comment; }; +struct USER_MODALS_INFO_0 { + uint32_t usrmod0_min_passwd_len; + uint32_t usrmod0_max_passwd_age; + uint32_t usrmod0_min_passwd_age; + uint32_t usrmod0_force_logoff; + uint32_t usrmod0_password_hist_len; +}; + +struct USER_MODALS_INFO_1 { + uint32_t usrmod1_role; + const char * usrmod1_primary; +}; + +struct USER_MODALS_INFO_2 { + const char * usrmod2_domain_name; + struct domsid *usrmod2_domain_id;/* [unique] */ +}; + +struct USER_MODALS_INFO_3 { + uint32_t usrmod3_lockout_duration; + uint32_t usrmod3_lockout_observation_window; + uint32_t usrmod3_lockout_threshold; +}; + +struct USER_MODALS_INFO_1001 { + uint32_t usrmod1001_min_passwd_len; +}; + +struct USER_MODALS_INFO_1002 { + uint32_t usrmod1002_max_passwd_age; +}; + +struct USER_MODALS_INFO_1003 { + uint32_t usrmod1003_min_passwd_age; +}; + +struct USER_MODALS_INFO_1004 { + uint32_t usrmod1004_force_logoff; +}; + +struct USER_MODALS_INFO_1005 { + uint32_t usrmod1005_password_hist_len; +}; + +struct USER_MODALS_INFO_1006 { + uint32_t usrmod1006_role; +}; + +struct USER_MODALS_INFO_1007 { + const char * usrmod1007_primary; +}; + struct NET_DISPLAY_USER { const char * usri1_name; const char * usri1_comment; @@ -759,6 +813,14 @@ NET_API_STATUS NetUserSetInfo(const char * server_name /* [in] */, uint8_t *buffer /* [in] [ref] */, uint32_t *parm_err /* [out] [ref] */); +NET_API_STATUS NetUserModalsGet(const char * server_name /* [in] */, + uint32_t level /* [in] */, + uint8_t **buffer /* [out] [ref] */); +NET_API_STATUS NetUserModalsSet(const char * server_name /* [in] */, + uint32_t level /* [in] */, + uint8_t *buffer /* [in] [ref] */, + uint32_t *parm_err /* [out] [ref] */); + /************************************************************//** * * NetQueryDisplayInformation -- cgit From eec91430f5509f517350046692931dd9b74bc745 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 31 Jul 2008 17:39:07 +0200 Subject: netapi: add example code for NetUserModalsGet and NetUserModalsSet. Guenther (This used to be commit 316575b412e19008ecb6729f97e93b6103d8ba56) --- source3/lib/netapi/examples/Makefile.in | 12 ++ source3/lib/netapi/examples/user/user_modalsget.c | 131 ++++++++++++++++++++ source3/lib/netapi/examples/user/user_modalsset.c | 141 ++++++++++++++++++++++ 3 files changed, 284 insertions(+) create mode 100644 source3/lib/netapi/examples/user/user_modalsget.c create mode 100644 source3/lib/netapi/examples/user/user_modalsset.c (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/Makefile.in b/source3/lib/netapi/examples/Makefile.in index e7b61a1776..5e577ed330 100644 --- a/source3/lib/netapi/examples/Makefile.in +++ b/source3/lib/netapi/examples/Makefile.in @@ -29,6 +29,8 @@ PROGS = bin/getdc@EXEEXT@ \ bin/user_chgpwd@EXEEXT@ \ bin/user_getinfo@EXEEXT@ \ bin/user_setinfo@EXEEXT@ \ + bin/user_modalsget@EXEEXT@ \ + bin/user_modalsset@EXEEXT@ \ bin/group_add@EXEEXT@ \ bin/group_del@EXEEXT@ \ bin/group_enum@EXEEXT@ \ @@ -83,6 +85,8 @@ USERDISPINFO_OBJ = user/user_dispinfo.o $(CMDLINE_OBJ) USERCHGPWD_OBJ = user/user_chgpwd.o $(CMDLINE_OBJ) USERGETINFO_OBJ = user/user_getinfo.o $(CMDLINE_OBJ) USERSETINFO_OBJ = user/user_setinfo.o $(CMDLINE_OBJ) +USERMODALSGET_OBJ = user/user_modalsget.o $(CMDLINE_OBJ) +USERMODALSSET_OBJ = user/user_modalsset.o $(CMDLINE_OBJ) GROUPADD_OBJ = group/group_add.o $(CMDLINE_OBJ) GROUPDEL_OBJ = group/group_del.o $(CMDLINE_OBJ) GROUPENUM_OBJ = group/group_enum.o $(CMDLINE_OBJ) @@ -146,6 +150,14 @@ bin/user_setinfo@EXEEXT@: $(BINARY_PREREQS) $(USERSETINFO_OBJ) @echo Linking $@ @$(CC) $(FLAGS) -o $@ $(USERSETINFO_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) +bin/user_modalsget@EXEEXT@: $(BINARY_PREREQS) $(USERMODALSGET_OBJ) + @echo Linking $@ + @$(CC) $(FLAGS) -o $@ $(USERMODALSGET_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) + +bin/user_modalsset@EXEEXT@: $(BINARY_PREREQS) $(USERMODALSSET_OBJ) + @echo Linking $@ + @$(CC) $(FLAGS) -o $@ $(USERMODALSSET_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) + bin/group_add@EXEEXT@: $(BINARY_PREREQS) $(GROUPADD_OBJ) @echo Linking $@ @$(CC) $(FLAGS) -o $@ $(GROUPADD_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) diff --git a/source3/lib/netapi/examples/user/user_modalsget.c b/source3/lib/netapi/examples/user/user_modalsget.c new file mode 100644 index 0000000000..4dcb41bef7 --- /dev/null +++ b/source3/lib/netapi/examples/user/user_modalsget.c @@ -0,0 +1,131 @@ +/* + * Unix SMB/CIFS implementation. + * NetUserModalsGet query + * Copyright (C) Guenther Deschner 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include +#include +#include +#include +#include + +#include + +#include "common.h" + +int main(int argc, const char **argv) +{ + NET_API_STATUS status; + struct libnetapi_ctx *ctx = NULL; + const char *hostname = NULL; + uint8_t *buffer = NULL; + uint32_t level = 0; + char *sid_str = NULL; + + struct USER_MODALS_INFO_0 *u0; + struct USER_MODALS_INFO_1 *u1; + struct USER_MODALS_INFO_2 *u2; + struct USER_MODALS_INFO_3 *u3; + + poptContext pc; + int opt; + + struct poptOption long_options[] = { + POPT_AUTOHELP + POPT_COMMON_LIBNETAPI_EXAMPLES + POPT_TABLEEND + }; + + status = libnetapi_init(&ctx); + if (status != 0) { + return status; + } + + pc = poptGetContext("user_modalsget", argc, argv, long_options, 0); + + poptSetOtherOptionHelp(pc, "hostname level"); + while((opt = poptGetNextOpt(pc)) != -1) { + } + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + hostname = poptGetArg(pc); + + if (poptPeekArg(pc)) { + level = atoi(poptGetArg(pc)); + } + + /* NetUserModalsGet */ + + status = NetUserModalsGet(hostname, + level, + &buffer); + if (status != 0) { + printf("NetUserModalsGet failed with: %s\n", + libnetapi_get_error_string(ctx, status)); + goto out; + } + + switch (level) { + case 0: + u0 = (struct USER_MODALS_INFO_0 *)buffer; + printf("min passwd len: %d character\n", + u0->usrmod0_min_passwd_len); + printf("max passwd age: %d (days)\n", + u0->usrmod0_max_passwd_age/86400); + printf("min passwd age: %d (days)\n", + u0->usrmod0_min_passwd_age/86400); + printf("force logoff: %d (seconds)\n", + u0->usrmod0_force_logoff); + printf("password history length: %d entries\n", + u0->usrmod0_password_hist_len); + break; + case 1: + u1 = (struct USER_MODALS_INFO_1 *)buffer; + printf("role: %d\n", u1->usrmod1_role); + printf("primary: %s\n", u1->usrmod1_primary); + break; + case 2: + u2 = (struct USER_MODALS_INFO_2 *)buffer; + printf("domain name: %s\n", u2->usrmod2_domain_name); + if (ConvertSidToStringSid(u2->usrmod2_domain_id, + &sid_str)) { + printf("domain sid: %s\n", sid_str); + free(sid_str); + } + break; + case 3: + u3 = (struct USER_MODALS_INFO_3 *)buffer; + printf("lockout duration: %d (seconds)\n", + u3->usrmod3_lockout_duration); + printf("lockout observation window: %d (seconds)\n", + u3->usrmod3_lockout_observation_window); + printf("lockout threshold: %d entries\n", + u3->usrmod3_lockout_threshold); + break; + default: + break; + } + + out: + libnetapi_free(ctx); + poptFreeContext(pc); + + return status; +} diff --git a/source3/lib/netapi/examples/user/user_modalsset.c b/source3/lib/netapi/examples/user/user_modalsset.c new file mode 100644 index 0000000000..57e1ef70ea --- /dev/null +++ b/source3/lib/netapi/examples/user/user_modalsset.c @@ -0,0 +1,141 @@ +/* + * Unix SMB/CIFS implementation. + * NetUserModalsSet query + * Copyright (C) Guenther Deschner 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include +#include +#include +#include +#include + +#include + +#include "common.h" + +int main(int argc, const char **argv) +{ + NET_API_STATUS status; + struct libnetapi_ctx *ctx = NULL; + const char *hostname = NULL; + uint8_t *buffer = NULL; + uint32_t level = 0; + uint32_t value = 0; + uint32_t parm_err = 0; + + struct USER_MODALS_INFO_0 u0; + struct USER_MODALS_INFO_1 u1; + struct USER_MODALS_INFO_2 u2; + struct USER_MODALS_INFO_3 u3; + struct USER_MODALS_INFO_1001 u1001; + struct USER_MODALS_INFO_1002 u1002; + struct USER_MODALS_INFO_1003 u1003; + struct USER_MODALS_INFO_1004 u1004; + struct USER_MODALS_INFO_1005 u1005; + struct USER_MODALS_INFO_1006 u1006; + struct USER_MODALS_INFO_1007 u1007; + + poptContext pc; + int opt; + + struct poptOption long_options[] = { + POPT_AUTOHELP + POPT_COMMON_LIBNETAPI_EXAMPLES + POPT_TABLEEND + }; + + status = libnetapi_init(&ctx); + if (status != 0) { + return status; + } + + pc = poptGetContext("user_modalsset", argc, argv, long_options, 0); + + poptSetOtherOptionHelp(pc, "hostname level value"); + while((opt = poptGetNextOpt(pc)) != -1) { + } + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + hostname = poptGetArg(pc); + + if (poptPeekArg(pc)) { + level = atoi(poptGetArg(pc)); + } + + if (poptPeekArg(pc)) { + value = atoi(poptGetArg(pc)); + } + + switch (level) { + case 0: + u0.usrmod0_min_passwd_len = 0; + u0.usrmod0_max_passwd_age = (86400 * 30); /* once a month */ + u0.usrmod0_min_passwd_age = 0; + u0.usrmod0_force_logoff = TIMEQ_FOREVER; + u0.usrmod0_password_hist_len = 0; + buffer = (uint8_t *)&u0; + break; + case 1: + case 2: + case 3: + case 1001: + u1001.usrmod1001_min_passwd_len = 0; + buffer = (uint8_t *)&u1001; + break; + case 1002: + u1002.usrmod1002_max_passwd_age = 0; + buffer = (uint8_t *)&u1002; + break; + case 1003: + u1003.usrmod1003_min_passwd_age = (86400 * 30); /* once a month */ + buffer = (uint8_t *)&u1003; + break; + case 1004: + u1004.usrmod1004_force_logoff = TIMEQ_FOREVER; + buffer = (uint8_t *)&u1004; + break; + case 1005: + u1005.usrmod1005_password_hist_len = 0; + buffer = (uint8_t *)&u1005; + break; + case 1006: + case 1007: + default: + break; + } + + /* NetUserModalsSet */ + + status = NetUserModalsSet(hostname, + level, + buffer, + &parm_err); + if (status != 0) { + printf("NetUserModalsSet failed with: %s\n", + libnetapi_get_error_string(ctx, status)); + goto out; + } + + out: + libnetapi_free(ctx); + poptFreeContext(pc); + + return status; +} -- cgit From 005fb1fb11897d9338d7aae472278d5a6eb8cd8e Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 31 Jul 2008 19:26:29 +0200 Subject: netapi: implement NetUserModalsGet_r. Guenther (This used to be commit 7f7e6ca9091101aa7a3dc275c1d0258d97743f4b) --- source3/lib/netapi/user.c | 374 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 372 insertions(+), 2 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/user.c b/source3/lib/netapi/user.c index f52941235b..6a6cb6c42b 100644 --- a/source3/lib/netapi/user.c +++ b/source3/lib/netapi/user.c @@ -1411,10 +1411,380 @@ WERROR NetUserSetInfo_l(struct libnetapi_ctx *ctx, /**************************************************************** ****************************************************************/ +static NTSTATUS query_USER_MODALS_INFO_rpc(TALLOC_CTX *mem_ctx, + struct rpc_pipe_client *pipe_cli, + struct policy_handle *domain_handle, + struct samr_DomInfo1 *info1, + struct samr_DomInfo3 *info3, + struct samr_DomInfo5 *info5, + struct samr_DomInfo6 *info6, + struct samr_DomInfo7 *info7, + struct samr_DomInfo12 *info12) +{ + NTSTATUS status; + union samr_DomainInfo *dom_info = NULL; + + if (info1) { + status = rpccli_samr_QueryDomainInfo(pipe_cli, mem_ctx, + domain_handle, + 1, + &dom_info); + NT_STATUS_NOT_OK_RETURN(status); + + *info1 = dom_info->info1; + } + + if (info3) { + status = rpccli_samr_QueryDomainInfo(pipe_cli, mem_ctx, + domain_handle, + 3, + &dom_info); + NT_STATUS_NOT_OK_RETURN(status); + + *info3 = dom_info->info3; + } + + if (info5) { + status = rpccli_samr_QueryDomainInfo(pipe_cli, mem_ctx, + domain_handle, + 5, + &dom_info); + NT_STATUS_NOT_OK_RETURN(status); + + *info5 = dom_info->info5; + } + + if (info6) { + status = rpccli_samr_QueryDomainInfo(pipe_cli, mem_ctx, + domain_handle, + 6, + &dom_info); + NT_STATUS_NOT_OK_RETURN(status); + + *info6 = dom_info->info6; + } + + if (info7) { + status = rpccli_samr_QueryDomainInfo(pipe_cli, mem_ctx, + domain_handle, + 7, + &dom_info); + NT_STATUS_NOT_OK_RETURN(status); + + *info7 = dom_info->info7; + } + + if (info12) { + status = rpccli_samr_QueryDomainInfo2(pipe_cli, mem_ctx, + domain_handle, + 12, + &dom_info); + NT_STATUS_NOT_OK_RETURN(status); + + *info12 = dom_info->info12; + } + + return NT_STATUS_OK; +} + +/**************************************************************** +****************************************************************/ + +static NTSTATUS query_USER_MODALS_INFO_0(TALLOC_CTX *mem_ctx, + struct rpc_pipe_client *pipe_cli, + struct policy_handle *domain_handle, + struct USER_MODALS_INFO_0 *info0) +{ + NTSTATUS status; + struct samr_DomInfo1 dom_info1; + struct samr_DomInfo3 dom_info3; + + ZERO_STRUCTP(info0); + + status = query_USER_MODALS_INFO_rpc(mem_ctx, + pipe_cli, + domain_handle, + &dom_info1, + &dom_info3, + NULL, + NULL, + NULL, + NULL); + NT_STATUS_NOT_OK_RETURN(status); + + info0->usrmod0_min_passwd_len = + dom_info1.min_password_length; + info0->usrmod0_max_passwd_age = + nt_time_to_unix_abs((NTTIME *)&dom_info1.max_password_age); + info0->usrmod0_min_passwd_age = + nt_time_to_unix_abs((NTTIME *)&dom_info1.min_password_age); + info0->usrmod0_password_hist_len = + dom_info1.password_history_length; + + info0->usrmod0_force_logoff = + nt_time_to_unix_abs(&dom_info3.force_logoff_time); + + return NT_STATUS_OK; +} + +/**************************************************************** +****************************************************************/ + +static NTSTATUS query_USER_MODALS_INFO_1(TALLOC_CTX *mem_ctx, + struct rpc_pipe_client *pipe_cli, + struct policy_handle *domain_handle, + struct USER_MODALS_INFO_1 *info1) +{ + NTSTATUS status; + struct samr_DomInfo6 dom_info6; + struct samr_DomInfo7 dom_info7; + + status = query_USER_MODALS_INFO_rpc(mem_ctx, + pipe_cli, + domain_handle, + NULL, + NULL, + NULL, + &dom_info6, + &dom_info7, + NULL); + NT_STATUS_NOT_OK_RETURN(status); + + info1->usrmod1_primary = + talloc_strdup(mem_ctx, dom_info6.primary.string); + + info1->usrmod1_role = dom_info7.role; + + return NT_STATUS_OK; +} + +/**************************************************************** +****************************************************************/ + +static NTSTATUS query_USER_MODALS_INFO_2(TALLOC_CTX *mem_ctx, + struct rpc_pipe_client *pipe_cli, + struct policy_handle *domain_handle, + struct dom_sid *domain_sid, + struct USER_MODALS_INFO_2 *info2) +{ + NTSTATUS status; + struct samr_DomInfo5 dom_info5; + + status = query_USER_MODALS_INFO_rpc(mem_ctx, + pipe_cli, + domain_handle, + NULL, + NULL, + &dom_info5, + NULL, + NULL, + NULL); + NT_STATUS_NOT_OK_RETURN(status); + + info2->usrmod2_domain_name = + talloc_strdup(mem_ctx, dom_info5.domain_name.string); + info2->usrmod2_domain_id = + (struct domsid *)sid_dup_talloc(mem_ctx, domain_sid); + + NT_STATUS_HAVE_NO_MEMORY(info2->usrmod2_domain_name); + NT_STATUS_HAVE_NO_MEMORY(info2->usrmod2_domain_id); + + return NT_STATUS_OK; +} + +/**************************************************************** +****************************************************************/ + +static NTSTATUS query_USER_MODALS_INFO_3(TALLOC_CTX *mem_ctx, + struct rpc_pipe_client *pipe_cli, + struct policy_handle *domain_handle, + struct USER_MODALS_INFO_3 *info3) +{ + NTSTATUS status; + struct samr_DomInfo12 dom_info12; + + status = query_USER_MODALS_INFO_rpc(mem_ctx, + pipe_cli, + domain_handle, + NULL, + NULL, + NULL, + NULL, + NULL, + &dom_info12); + NT_STATUS_NOT_OK_RETURN(status); + + info3->usrmod3_lockout_duration = + nt_time_to_unix_abs(&dom_info12.lockout_duration); + info3->usrmod3_lockout_observation_window = + nt_time_to_unix_abs(&dom_info12.lockout_window); + info3->usrmod3_lockout_threshold = + dom_info12.lockout_threshold; + + return NT_STATUS_OK; +} + +/**************************************************************** +****************************************************************/ + +static NTSTATUS query_USER_MODALS_INFO_to_buffer(TALLOC_CTX *mem_ctx, + struct rpc_pipe_client *pipe_cli, + uint32_t level, + struct policy_handle *domain_handle, + struct dom_sid *domain_sid, + uint8_t **buffer) +{ + NTSTATUS status; + + struct USER_MODALS_INFO_0 info0; + struct USER_MODALS_INFO_1 info1; + struct USER_MODALS_INFO_2 info2; + struct USER_MODALS_INFO_3 info3; + + if (!buffer) { + return ERROR_INSUFFICIENT_BUFFER; + } + + switch (level) { + case 0: + status = query_USER_MODALS_INFO_0(mem_ctx, + pipe_cli, + domain_handle, + &info0); + NT_STATUS_NOT_OK_RETURN(status); + + *buffer = (uint8_t *)talloc_memdup(mem_ctx, &info0, + sizeof(info0)); + break; + + case 1: + status = query_USER_MODALS_INFO_1(mem_ctx, + pipe_cli, + domain_handle, + &info1); + NT_STATUS_NOT_OK_RETURN(status); + + *buffer = (uint8_t *)talloc_memdup(mem_ctx, &info1, + sizeof(info1)); + break; + case 2: + status = query_USER_MODALS_INFO_2(mem_ctx, + pipe_cli, + domain_handle, + domain_sid, + &info2); + NT_STATUS_NOT_OK_RETURN(status); + + *buffer = (uint8_t *)talloc_memdup(mem_ctx, &info2, + sizeof(info2)); + break; + case 3: + status = query_USER_MODALS_INFO_3(mem_ctx, + pipe_cli, + domain_handle, + &info3); + NT_STATUS_NOT_OK_RETURN(status); + + *buffer = (uint8_t *)talloc_memdup(mem_ctx, &info3, + sizeof(info3)); + break; + default: + break; + } + + NT_STATUS_HAVE_NO_MEMORY(*buffer); + + return NT_STATUS_OK; +} + +/**************************************************************** +****************************************************************/ + WERROR NetUserModalsGet_r(struct libnetapi_ctx *ctx, struct NetUserModalsGet *r) { - return WERR_NOT_SUPPORTED; + struct cli_state *cli = NULL; + struct rpc_pipe_client *pipe_cli = NULL; + NTSTATUS status; + WERROR werr; + + struct policy_handle connect_handle, domain_handle; + struct dom_sid2 *domain_sid = NULL; + uint32_t access_mask = SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT; + + ZERO_STRUCT(connect_handle); + ZERO_STRUCT(domain_handle); + + if (!r->out.buffer) { + return WERR_INVALID_PARAM; + } + + switch (r->in.level) { + case 0: + access_mask |= SAMR_DOMAIN_ACCESS_LOOKUP_INFO_1 | + SAMR_DOMAIN_ACCESS_LOOKUP_INFO_2; + break; + case 1: + case 2: + access_mask |= SAMR_DOMAIN_ACCESS_LOOKUP_INFO_2; + break; + case 3: + access_mask |= SAMR_DOMAIN_ACCESS_LOOKUP_INFO_1; + break; + default: + werr = WERR_UNKNOWN_LEVEL; + goto done; + } + + werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + werr = libnetapi_open_pipe(ctx, cli, &ndr_table_samr.syntax_id, + &pipe_cli); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + werr = libnetapi_samr_open_domain(ctx, pipe_cli, + SAMR_ACCESS_ENUM_DOMAINS | + SAMR_ACCESS_OPEN_DOMAIN, + access_mask, + &connect_handle, + &domain_handle, + &domain_sid); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + /* 0: 1 + 3 */ + /* 1: 6 + 7 */ + /* 2: 5 */ + /* 3: 12 (DomainInfo2) */ + + status = query_USER_MODALS_INFO_to_buffer(ctx, + pipe_cli, + r->in.level, + &domain_handle, + domain_sid, + r->out.buffer); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + done: + if (!cli) { + return werr; + } + + if (ctx->disable_policy_handle_cache) { + libnetapi_samr_close_domain_handle(ctx, &domain_handle); + libnetapi_samr_close_connect_handle(ctx, &connect_handle); + } + + return werr; } /**************************************************************** @@ -1423,7 +1793,7 @@ WERROR NetUserModalsGet_r(struct libnetapi_ctx *ctx, WERROR NetUserModalsGet_l(struct libnetapi_ctx *ctx, struct NetUserModalsGet *r) { - return WERR_NOT_SUPPORTED; + return NetUserModalsGet_r(ctx, r); } /**************************************************************** -- cgit From cd1a1e3490ab7ba441f3f5caaad86dce88c2f57d Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 31 Jul 2008 21:08:31 +0200 Subject: netapi: implement NetUserModalsSet_r. Guenther (This used to be commit bb345187b7c62e9ad214037120545addd87a666d) --- source3/lib/netapi/user.c | 468 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 466 insertions(+), 2 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/user.c b/source3/lib/netapi/user.c index 6a6cb6c42b..ff807997ae 100644 --- a/source3/lib/netapi/user.c +++ b/source3/lib/netapi/user.c @@ -1799,10 +1799,474 @@ WERROR NetUserModalsGet_l(struct libnetapi_ctx *ctx, /**************************************************************** ****************************************************************/ +static NTSTATUS set_USER_MODALS_INFO_rpc(TALLOC_CTX *mem_ctx, + struct rpc_pipe_client *pipe_cli, + struct policy_handle *domain_handle, + struct samr_DomInfo1 *info1, + struct samr_DomInfo3 *info3, + struct samr_DomInfo12 *info12) +{ + NTSTATUS status; + union samr_DomainInfo dom_info; + + if (info1) { + + ZERO_STRUCT(dom_info); + + dom_info.info1 = *info1; + + status = rpccli_samr_SetDomainInfo(pipe_cli, mem_ctx, + domain_handle, + 1, + &dom_info); + NT_STATUS_NOT_OK_RETURN(status); + } + + if (info3) { + + ZERO_STRUCT(dom_info); + + dom_info.info3 = *info3; + + status = rpccli_samr_SetDomainInfo(pipe_cli, mem_ctx, + domain_handle, + 3, + &dom_info); + + NT_STATUS_NOT_OK_RETURN(status); + } + + if (info12) { + + ZERO_STRUCT(dom_info); + + dom_info.info12 = *info12; + + status = rpccli_samr_SetDomainInfo(pipe_cli, mem_ctx, + domain_handle, + 12, + &dom_info); + + NT_STATUS_NOT_OK_RETURN(status); + } + + return NT_STATUS_OK; +} + +/**************************************************************** +****************************************************************/ + +static NTSTATUS set_USER_MODALS_INFO_0_buffer(TALLOC_CTX *mem_ctx, + struct rpc_pipe_client *pipe_cli, + struct policy_handle *domain_handle, + struct USER_MODALS_INFO_0 *info0) +{ + NTSTATUS status; + struct samr_DomInfo1 dom_info_1; + struct samr_DomInfo3 dom_info_3; + + status = query_USER_MODALS_INFO_rpc(mem_ctx, + pipe_cli, + domain_handle, + &dom_info_1, + &dom_info_3, + NULL, + NULL, + NULL, + NULL); + NT_STATUS_NOT_OK_RETURN(status); + + dom_info_1.min_password_length = + info0->usrmod0_min_passwd_len; + dom_info_1.password_history_length = + info0->usrmod0_password_hist_len; + + unix_to_nt_time_abs((NTTIME *)&dom_info_1.max_password_age, + info0->usrmod0_max_passwd_age); + unix_to_nt_time_abs((NTTIME *)&dom_info_1.min_password_age, + info0->usrmod0_min_passwd_age); + + unix_to_nt_time_abs(&dom_info_3.force_logoff_time, + info0->usrmod0_force_logoff); + + return set_USER_MODALS_INFO_rpc(mem_ctx, + pipe_cli, + domain_handle, + &dom_info_1, + &dom_info_3, + NULL); +} + +/**************************************************************** +****************************************************************/ + +static NTSTATUS set_USER_MODALS_INFO_3_buffer(TALLOC_CTX *mem_ctx, + struct rpc_pipe_client *pipe_cli, + struct policy_handle *domain_handle, + struct USER_MODALS_INFO_3 *info3) +{ + NTSTATUS status; + struct samr_DomInfo12 dom_info_12; + + status = query_USER_MODALS_INFO_rpc(mem_ctx, + pipe_cli, + domain_handle, + NULL, + NULL, + NULL, + NULL, + NULL, + &dom_info_12); + NT_STATUS_NOT_OK_RETURN(status); + + unix_to_nt_time_abs((NTTIME *)&dom_info_12.lockout_duration, + info3->usrmod3_lockout_duration); + unix_to_nt_time_abs((NTTIME *)&dom_info_12.lockout_window, + info3->usrmod3_lockout_observation_window); + dom_info_12.lockout_threshold = info3->usrmod3_lockout_threshold; + + return set_USER_MODALS_INFO_rpc(mem_ctx, + pipe_cli, + domain_handle, + NULL, + NULL, + &dom_info_12); +} + +/**************************************************************** +****************************************************************/ + +static NTSTATUS set_USER_MODALS_INFO_1001_buffer(TALLOC_CTX *mem_ctx, + struct rpc_pipe_client *pipe_cli, + struct policy_handle *domain_handle, + struct USER_MODALS_INFO_1001 *info1001) +{ + NTSTATUS status; + struct samr_DomInfo1 dom_info_1; + + status = query_USER_MODALS_INFO_rpc(mem_ctx, + pipe_cli, + domain_handle, + &dom_info_1, + NULL, + NULL, + NULL, + NULL, + NULL); + NT_STATUS_NOT_OK_RETURN(status); + + dom_info_1.min_password_length = + info1001->usrmod1001_min_passwd_len; + + return set_USER_MODALS_INFO_rpc(mem_ctx, + pipe_cli, + domain_handle, + &dom_info_1, + NULL, + NULL); +} + +/**************************************************************** +****************************************************************/ + +static NTSTATUS set_USER_MODALS_INFO_1002_buffer(TALLOC_CTX *mem_ctx, + struct rpc_pipe_client *pipe_cli, + struct policy_handle *domain_handle, + struct USER_MODALS_INFO_1002 *info1002) +{ + NTSTATUS status; + struct samr_DomInfo1 dom_info_1; + + status = query_USER_MODALS_INFO_rpc(mem_ctx, + pipe_cli, + domain_handle, + &dom_info_1, + NULL, + NULL, + NULL, + NULL, + NULL); + NT_STATUS_NOT_OK_RETURN(status); + + unix_to_nt_time_abs((NTTIME *)&dom_info_1.max_password_age, + info1002->usrmod1002_max_passwd_age); + + return set_USER_MODALS_INFO_rpc(mem_ctx, + pipe_cli, + domain_handle, + &dom_info_1, + NULL, + NULL); +} + +/**************************************************************** +****************************************************************/ + +static NTSTATUS set_USER_MODALS_INFO_1003_buffer(TALLOC_CTX *mem_ctx, + struct rpc_pipe_client *pipe_cli, + struct policy_handle *domain_handle, + struct USER_MODALS_INFO_1003 *info1003) +{ + NTSTATUS status; + struct samr_DomInfo1 dom_info_1; + + status = query_USER_MODALS_INFO_rpc(mem_ctx, + pipe_cli, + domain_handle, + &dom_info_1, + NULL, + NULL, + NULL, + NULL, + NULL); + NT_STATUS_NOT_OK_RETURN(status); + + unix_to_nt_time_abs((NTTIME *)&dom_info_1.min_password_age, + info1003->usrmod1003_min_passwd_age); + + return set_USER_MODALS_INFO_rpc(mem_ctx, + pipe_cli, + domain_handle, + &dom_info_1, + NULL, + NULL); +} + +/**************************************************************** +****************************************************************/ + +static NTSTATUS set_USER_MODALS_INFO_1004_buffer(TALLOC_CTX *mem_ctx, + struct rpc_pipe_client *pipe_cli, + struct policy_handle *domain_handle, + struct USER_MODALS_INFO_1004 *info1004) +{ + NTSTATUS status; + struct samr_DomInfo3 dom_info_3; + + status = query_USER_MODALS_INFO_rpc(mem_ctx, + pipe_cli, + domain_handle, + NULL, + &dom_info_3, + NULL, + NULL, + NULL, + NULL); + NT_STATUS_NOT_OK_RETURN(status); + + unix_to_nt_time_abs(&dom_info_3.force_logoff_time, + info1004->usrmod1004_force_logoff); + + return set_USER_MODALS_INFO_rpc(mem_ctx, + pipe_cli, + domain_handle, + NULL, + &dom_info_3, + NULL); +} + +/**************************************************************** +****************************************************************/ + +static NTSTATUS set_USER_MODALS_INFO_1005_buffer(TALLOC_CTX *mem_ctx, + struct rpc_pipe_client *pipe_cli, + struct policy_handle *domain_handle, + struct USER_MODALS_INFO_1005 *info1005) +{ + NTSTATUS status; + struct samr_DomInfo1 dom_info_1; + + status = query_USER_MODALS_INFO_rpc(mem_ctx, + pipe_cli, + domain_handle, + &dom_info_1, + NULL, + NULL, + NULL, + NULL, + NULL); + NT_STATUS_NOT_OK_RETURN(status); + + dom_info_1.password_history_length = + info1005->usrmod1005_password_hist_len; + + return set_USER_MODALS_INFO_rpc(mem_ctx, + pipe_cli, + domain_handle, + &dom_info_1, + NULL, + NULL); +} + +/**************************************************************** +****************************************************************/ + +static NTSTATUS set_USER_MODALS_INFO_buffer(TALLOC_CTX *mem_ctx, + struct rpc_pipe_client *pipe_cli, + uint32_t level, + struct policy_handle *domain_handle, + struct dom_sid *domain_sid, + uint8_t *buffer) +{ + struct USER_MODALS_INFO_0 *info0; + struct USER_MODALS_INFO_3 *info3; + struct USER_MODALS_INFO_1001 *info1001; + struct USER_MODALS_INFO_1002 *info1002; + struct USER_MODALS_INFO_1003 *info1003; + struct USER_MODALS_INFO_1004 *info1004; + struct USER_MODALS_INFO_1005 *info1005; + + if (!buffer) { + return ERROR_INSUFFICIENT_BUFFER; + } + + switch (level) { + case 0: + info0 = (struct USER_MODALS_INFO_0 *)buffer; + return set_USER_MODALS_INFO_0_buffer(mem_ctx, + pipe_cli, + domain_handle, + info0); + case 3: + info3 = (struct USER_MODALS_INFO_3 *)buffer; + return set_USER_MODALS_INFO_3_buffer(mem_ctx, + pipe_cli, + domain_handle, + info3); + case 1001: + info1001 = (struct USER_MODALS_INFO_1001 *)buffer; + return set_USER_MODALS_INFO_1001_buffer(mem_ctx, + pipe_cli, + domain_handle, + info1001); + case 1002: + info1002 = (struct USER_MODALS_INFO_1002 *)buffer; + return set_USER_MODALS_INFO_1002_buffer(mem_ctx, + pipe_cli, + domain_handle, + info1002); + case 1003: + info1003 = (struct USER_MODALS_INFO_1003 *)buffer; + return set_USER_MODALS_INFO_1003_buffer(mem_ctx, + pipe_cli, + domain_handle, + info1003); + case 1004: + info1004 = (struct USER_MODALS_INFO_1004 *)buffer; + return set_USER_MODALS_INFO_1004_buffer(mem_ctx, + pipe_cli, + domain_handle, + info1004); + case 1005: + info1005 = (struct USER_MODALS_INFO_1005 *)buffer; + return set_USER_MODALS_INFO_1005_buffer(mem_ctx, + pipe_cli, + domain_handle, + info1005); + + default: + break; + } + + return NT_STATUS_OK; +} + +/**************************************************************** +****************************************************************/ + WERROR NetUserModalsSet_r(struct libnetapi_ctx *ctx, struct NetUserModalsSet *r) { - return WERR_NOT_SUPPORTED; + struct cli_state *cli = NULL; + struct rpc_pipe_client *pipe_cli = NULL; + NTSTATUS status; + WERROR werr; + + struct policy_handle connect_handle, domain_handle; + struct dom_sid2 *domain_sid = NULL; + uint32_t access_mask = SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT; + + ZERO_STRUCT(connect_handle); + ZERO_STRUCT(domain_handle); + + if (!r->in.buffer) { + return WERR_INVALID_PARAM; + } + + switch (r->in.level) { + case 0: + access_mask |= SAMR_DOMAIN_ACCESS_LOOKUP_INFO_1 | + SAMR_DOMAIN_ACCESS_LOOKUP_INFO_2 | + SAMR_DOMAIN_ACCESS_SET_INFO_1 | + SAMR_DOMAIN_ACCESS_SET_INFO_2; + break; + case 3: + case 1001: + case 1002: + case 1003: + case 1005: + access_mask |= SAMR_DOMAIN_ACCESS_LOOKUP_INFO_1 | + SAMR_DOMAIN_ACCESS_SET_INFO_1; + break; + case 1004: + access_mask |= SAMR_DOMAIN_ACCESS_LOOKUP_INFO_2 | + SAMR_DOMAIN_ACCESS_SET_INFO_2; + break; + case 1: + case 2: + case 1006: + case 1007: + werr = WERR_NOT_SUPPORTED; + break; + default: + werr = WERR_UNKNOWN_LEVEL; + goto done; + } + + werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + werr = libnetapi_open_pipe(ctx, cli, &ndr_table_samr.syntax_id, + &pipe_cli); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + werr = libnetapi_samr_open_domain(ctx, pipe_cli, + SAMR_ACCESS_ENUM_DOMAINS | + SAMR_ACCESS_OPEN_DOMAIN, + access_mask, + &connect_handle, + &domain_handle, + &domain_sid); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + status = set_USER_MODALS_INFO_buffer(ctx, + pipe_cli, + r->in.level, + &domain_handle, + domain_sid, + r->in.buffer); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + done: + if (!cli) { + return werr; + } + + if (ctx->disable_policy_handle_cache) { + libnetapi_samr_close_domain_handle(ctx, &domain_handle); + libnetapi_samr_close_connect_handle(ctx, &connect_handle); + } + + return werr; } /**************************************************************** @@ -1811,5 +2275,5 @@ WERROR NetUserModalsSet_r(struct libnetapi_ctx *ctx, WERROR NetUserModalsSet_l(struct libnetapi_ctx *ctx, struct NetUserModalsSet *r) { - return WERR_NOT_SUPPORTED; + return NetUserModalsSet_r(ctx, r); } -- cgit From fabd6551b3e601c3c3cf921632a4a9f4c79ee847 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 31 Jul 2008 21:09:00 +0200 Subject: netapi: add NetUserModalsGet and NetUserModalsSet tests. Guenther (This used to be commit a9c444a342968b539918c082b78af8640f8c87cd) --- source3/lib/netapi/tests/netuser.c | 55 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/tests/netuser.c b/source3/lib/netapi/tests/netuser.c index ca2dc1a2f4..c50e384951 100644 --- a/source3/lib/netapi/tests/netuser.c +++ b/source3/lib/netapi/tests/netuser.c @@ -152,6 +152,56 @@ NET_API_STATUS test_netuseradd(const char *hostname, return NetUserAdd(hostname, 1, (uint8_t *)&u1, &parm_err); } +static NET_API_STATUS test_netusermodals(struct libnetapi_ctx *ctx, + const char *hostname) +{ + NET_API_STATUS status; + struct USER_MODALS_INFO_0 *u0 = NULL; + struct USER_MODALS_INFO_0 *_u0 = NULL; + uint8_t *buffer = NULL; + uint32_t parm_err = 0; + uint32_t levels[] = { 0, 1, 2, 3 }; + int i = 0; + + for (i=0; i Date: Thu, 31 Jul 2008 16:05:11 +0200 Subject: netapi: add skeleton for NetLocalGroup*Member calls. Guenther (This used to be commit 563fb06107d2d3279e08c5c801a940f03229131b) --- source3/lib/netapi/libnetapi.c | 199 ++++++++++++++++++++++++++++++++++++++++ source3/lib/netapi/libnetapi.h | 39 ++++++++ source3/lib/netapi/localgroup.c | 73 +++++++++++++++ 3 files changed, 311 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/libnetapi.c b/source3/lib/netapi/libnetapi.c index adc875d213..5fe48077a8 100644 --- a/source3/lib/netapi/libnetapi.c +++ b/source3/lib/netapi/libnetapi.c @@ -1480,6 +1480,205 @@ NET_API_STATUS NetLocalGroupEnum(const char * server_name /* [in] */, return r.out.result; } +/**************************************************************** + NetLocalGroupAddMembers +****************************************************************/ + +NET_API_STATUS NetLocalGroupAddMembers(const char * server_name /* [in] */, + const char * group_name /* [in] */, + uint32_t level /* [in] */, + uint8_t *buffer /* [in] [ref] */, + uint32_t total_entries /* [in] */) +{ + struct NetLocalGroupAddMembers r; + struct libnetapi_ctx *ctx = NULL; + NET_API_STATUS status; + WERROR werr; + + status = libnetapi_getctx(&ctx); + if (status != 0) { + return status; + } + + /* In parameters */ + r.in.server_name = server_name; + r.in.group_name = group_name; + r.in.level = level; + r.in.buffer = buffer; + r.in.total_entries = total_entries; + + /* Out parameters */ + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_IN_DEBUG(NetLocalGroupAddMembers, &r); + } + + if (LIBNETAPI_LOCAL_SERVER(server_name)) { + werr = NetLocalGroupAddMembers_l(ctx, &r); + } else { + werr = NetLocalGroupAddMembers_r(ctx, &r); + } + + r.out.result = W_ERROR_V(werr); + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_OUT_DEBUG(NetLocalGroupAddMembers, &r); + } + + return r.out.result; +} + +/**************************************************************** + NetLocalGroupDelMembers +****************************************************************/ + +NET_API_STATUS NetLocalGroupDelMembers(const char * server_name /* [in] */, + const char * group_name /* [in] */, + uint32_t level /* [in] */, + uint8_t *buffer /* [in] [ref] */, + uint32_t total_entries /* [in] */) +{ + struct NetLocalGroupDelMembers r; + struct libnetapi_ctx *ctx = NULL; + NET_API_STATUS status; + WERROR werr; + + status = libnetapi_getctx(&ctx); + if (status != 0) { + return status; + } + + /* In parameters */ + r.in.server_name = server_name; + r.in.group_name = group_name; + r.in.level = level; + r.in.buffer = buffer; + r.in.total_entries = total_entries; + + /* Out parameters */ + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_IN_DEBUG(NetLocalGroupDelMembers, &r); + } + + if (LIBNETAPI_LOCAL_SERVER(server_name)) { + werr = NetLocalGroupDelMembers_l(ctx, &r); + } else { + werr = NetLocalGroupDelMembers_r(ctx, &r); + } + + r.out.result = W_ERROR_V(werr); + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_OUT_DEBUG(NetLocalGroupDelMembers, &r); + } + + return r.out.result; +} + +/**************************************************************** + NetLocalGroupGetMembers +****************************************************************/ + +NET_API_STATUS NetLocalGroupGetMembers(const char * server_name /* [in] */, + const char * local_group_name /* [in] */, + uint32_t level /* [in] */, + uint8_t **buffer /* [out] [ref] */, + uint32_t prefmaxlen /* [in] */, + uint32_t *entries_read /* [out] [ref] */, + uint32_t *total_entries /* [out] [ref] */, + uint32_t *resume_handle /* [in,out] [ref] */) +{ + struct NetLocalGroupGetMembers r; + struct libnetapi_ctx *ctx = NULL; + NET_API_STATUS status; + WERROR werr; + + status = libnetapi_getctx(&ctx); + if (status != 0) { + return status; + } + + /* In parameters */ + r.in.server_name = server_name; + r.in.local_group_name = local_group_name; + r.in.level = level; + r.in.prefmaxlen = prefmaxlen; + r.in.resume_handle = resume_handle; + + /* Out parameters */ + r.out.buffer = buffer; + r.out.entries_read = entries_read; + r.out.total_entries = total_entries; + r.out.resume_handle = resume_handle; + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_IN_DEBUG(NetLocalGroupGetMembers, &r); + } + + if (LIBNETAPI_LOCAL_SERVER(server_name)) { + werr = NetLocalGroupGetMembers_l(ctx, &r); + } else { + werr = NetLocalGroupGetMembers_r(ctx, &r); + } + + r.out.result = W_ERROR_V(werr); + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_OUT_DEBUG(NetLocalGroupGetMembers, &r); + } + + return r.out.result; +} + +/**************************************************************** + NetLocalGroupSetMembers +****************************************************************/ + +NET_API_STATUS NetLocalGroupSetMembers(const char * server_name /* [in] */, + const char * group_name /* [in] */, + uint32_t level /* [in] */, + uint8_t *buffer /* [in] [ref] */, + uint32_t total_entries /* [in] */) +{ + struct NetLocalGroupSetMembers r; + struct libnetapi_ctx *ctx = NULL; + NET_API_STATUS status; + WERROR werr; + + status = libnetapi_getctx(&ctx); + if (status != 0) { + return status; + } + + /* In parameters */ + r.in.server_name = server_name; + r.in.group_name = group_name; + r.in.level = level; + r.in.buffer = buffer; + r.in.total_entries = total_entries; + + /* Out parameters */ + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_IN_DEBUG(NetLocalGroupSetMembers, &r); + } + + if (LIBNETAPI_LOCAL_SERVER(server_name)) { + werr = NetLocalGroupSetMembers_l(ctx, &r); + } else { + werr = NetLocalGroupSetMembers_r(ctx, &r); + } + + r.out.result = W_ERROR_V(werr); + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_OUT_DEBUG(NetLocalGroupSetMembers, &r); + } + + return r.out.result; +} + /**************************************************************** NetRemoteTOD ****************************************************************/ diff --git a/source3/lib/netapi/libnetapi.h b/source3/lib/netapi/libnetapi.h index 8e7a662d60..b0ff8e5baf 100644 --- a/source3/lib/netapi/libnetapi.h +++ b/source3/lib/netapi/libnetapi.h @@ -261,6 +261,45 @@ WERROR NetLocalGroupEnum_r(struct libnetapi_ctx *ctx, struct NetLocalGroupEnum *r); WERROR NetLocalGroupEnum_l(struct libnetapi_ctx *ctx, struct NetLocalGroupEnum *r); +NET_API_STATUS NetLocalGroupAddMembers(const char * server_name /* [in] */, + const char * group_name /* [in] */, + uint32_t level /* [in] */, + uint8_t *buffer /* [in] [ref] */, + uint32_t total_entries /* [in] */); +WERROR NetLocalGroupAddMembers_r(struct libnetapi_ctx *ctx, + struct NetLocalGroupAddMembers *r); +WERROR NetLocalGroupAddMembers_l(struct libnetapi_ctx *ctx, + struct NetLocalGroupAddMembers *r); +NET_API_STATUS NetLocalGroupDelMembers(const char * server_name /* [in] */, + const char * group_name /* [in] */, + uint32_t level /* [in] */, + uint8_t *buffer /* [in] [ref] */, + uint32_t total_entries /* [in] */); +WERROR NetLocalGroupDelMembers_r(struct libnetapi_ctx *ctx, + struct NetLocalGroupDelMembers *r); +WERROR NetLocalGroupDelMembers_l(struct libnetapi_ctx *ctx, + struct NetLocalGroupDelMembers *r); +NET_API_STATUS NetLocalGroupGetMembers(const char * server_name /* [in] */, + const char * local_group_name /* [in] */, + uint32_t level /* [in] */, + uint8_t **buffer /* [out] [ref] */, + uint32_t prefmaxlen /* [in] */, + uint32_t *entries_read /* [out] [ref] */, + uint32_t *total_entries /* [out] [ref] */, + uint32_t *resume_handle /* [in,out] [ref] */); +WERROR NetLocalGroupGetMembers_r(struct libnetapi_ctx *ctx, + struct NetLocalGroupGetMembers *r); +WERROR NetLocalGroupGetMembers_l(struct libnetapi_ctx *ctx, + struct NetLocalGroupGetMembers *r); +NET_API_STATUS NetLocalGroupSetMembers(const char * server_name /* [in] */, + const char * group_name /* [in] */, + uint32_t level /* [in] */, + uint8_t *buffer /* [in] [ref] */, + uint32_t total_entries /* [in] */); +WERROR NetLocalGroupSetMembers_r(struct libnetapi_ctx *ctx, + struct NetLocalGroupSetMembers *r); +WERROR NetLocalGroupSetMembers_l(struct libnetapi_ctx *ctx, + struct NetLocalGroupSetMembers *r); NET_API_STATUS NetRemoteTOD(const char * server_name /* [in] */, uint8_t **buffer /* [out] [ref] */); WERROR NetRemoteTOD_r(struct libnetapi_ctx *ctx, diff --git a/source3/lib/netapi/localgroup.c b/source3/lib/netapi/localgroup.c index c15a17efb1..840bc52fb7 100644 --- a/source3/lib/netapi/localgroup.c +++ b/source3/lib/netapi/localgroup.c @@ -956,3 +956,76 @@ WERROR NetLocalGroupEnum_l(struct libnetapi_ctx *ctx, { return WERR_NOT_SUPPORTED; } + +/**************************************************************** +****************************************************************/ + +WERROR NetLocalGroupAddMembers_r(struct libnetapi_ctx *ctx, + struct NetLocalGroupAddMembers *r) +{ + return WERR_NOT_SUPPORTED; +} + +/**************************************************************** +****************************************************************/ + +WERROR NetLocalGroupAddMembers_l(struct libnetapi_ctx *ctx, + struct NetLocalGroupAddMembers *r) +{ + return WERR_NOT_SUPPORTED; +} + +/**************************************************************** +****************************************************************/ + +WERROR NetLocalGroupDelMembers_r(struct libnetapi_ctx *ctx, + struct NetLocalGroupDelMembers *r) +{ + return WERR_NOT_SUPPORTED; +} + +/**************************************************************** +****************************************************************/ + +WERROR NetLocalGroupDelMembers_l(struct libnetapi_ctx *ctx, + struct NetLocalGroupDelMembers *r) +{ + return WERR_NOT_SUPPORTED; +} + +/**************************************************************** +****************************************************************/ + +WERROR NetLocalGroupGetMembers_r(struct libnetapi_ctx *ctx, + struct NetLocalGroupGetMembers *r) +{ + return WERR_NOT_SUPPORTED; +} + +/**************************************************************** +****************************************************************/ + +WERROR NetLocalGroupGetMembers_l(struct libnetapi_ctx *ctx, + struct NetLocalGroupGetMembers *r) +{ + return WERR_NOT_SUPPORTED; +} + +/**************************************************************** +****************************************************************/ + +WERROR NetLocalGroupSetMembers_r(struct libnetapi_ctx *ctx, + struct NetLocalGroupSetMembers *r) +{ + return WERR_NOT_SUPPORTED; +} + +/**************************************************************** +****************************************************************/ + +WERROR NetLocalGroupSetMembers_l(struct libnetapi_ctx *ctx, + struct NetLocalGroupSetMembers *r) +{ + return WERR_NOT_SUPPORTED; +} + -- cgit From 90a8f9d27741294e392cd207b2dfb9b47edae023 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 31 Jul 2008 16:24:58 +0200 Subject: netapi: add NetLocalGroup*Member calls to public headers. Guenther (This used to be commit d4a51bb01d33ad17db4e623085a89d258e91b57e) --- source3/lib/netapi/netapi.h | 57 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h index 9b6288d9e9..dbf293e25b 100644 --- a/source3/lib/netapi/netapi.h +++ b/source3/lib/netapi/netapi.h @@ -366,6 +366,39 @@ struct LOCALGROUP_INFO_1002 { const char * lgrpi1002_comment; }; +enum SID_NAME_USE { + SidTypeUser=1, + SidTypeGroup=2, + SidTypeDomain=3, + SidTypeAlias=4, + SidTypeWellKnownGroup=5, + SidTypeDeletedAccount=6, + SidTypeInvalid=7, + SidTypeUnknown=8, + SidTypeComputer=9, + SidTypeLabel=10 +}; + +struct LOCALGROUP_MEMBERS_INFO_0 { + struct domsid *lgrmi0_sid;/* [unique] */ +}; + +struct LOCALGROUP_MEMBERS_INFO_1 { + struct domsid *lgrmi1_sid;/* [unique] */ + enum SID_NAME_USE lgrmi1_sidusage; + const char * lgrmi1_name; +}; + +struct LOCALGROUP_MEMBERS_INFO_2 { + struct domsid *lgrmi2_sid;/* [unique] */ + enum SID_NAME_USE lgrmi2_sidusage; + const char * lgrmi2_domainandname; +}; + +struct LOCALGROUP_MEMBERS_INFO_3 { + const char * lgrmi3_domainandname; +}; + struct TIME_OF_DAY_INFO { uint32_t tod_elapsedt; uint32_t tod_msecs; @@ -1128,6 +1161,30 @@ NET_API_STATUS NetLocalGroupEnum(const char * server_name /* [in] */, uint32_t *total_entries /* [out] [ref] */, uint32_t *resume_handle /* [in,out] [ref] */); +NET_API_STATUS NetLocalGroupAddMembers(const char * server_name /* [in] */, + const char * group_name /* [in] */, + uint32_t level /* [in] */, + uint8_t *buffer /* [in] [ref] */, + uint32_t total_entries /* [in] */); +NET_API_STATUS NetLocalGroupDelMembers(const char * server_name /* [in] */, + const char * group_name /* [in] */, + uint32_t level /* [in] */, + uint8_t *buffer /* [in] [ref] */, + uint32_t total_entries /* [in] */); +NET_API_STATUS NetLocalGroupGetMembers(const char * server_name /* [in] */, + const char * local_group_name /* [in] */, + uint32_t level /* [in] */, + uint8_t **buffer /* [out] [ref] */, + uint32_t prefmaxlen /* [in] */, + uint32_t *entries_read /* [out] [ref] */, + uint32_t *total_entries /* [out] [ref] */, + uint32_t *resume_handle /* [in,out] [ref] */); +NET_API_STATUS NetLocalGroupSetMembers(const char * server_name /* [in] */, + const char * group_name /* [in] */, + uint32_t level /* [in] */, + uint8_t *buffer /* [in] [ref] */, + uint32_t total_entries /* [in] */); + /************************************************************//** * * NetRemoteTOD -- cgit From 14364acd085bf8c8eb962fdca100199c573b5333 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 1 Aug 2008 16:02:21 +0200 Subject: netapi: implement NetLocalGroupAddMembers_r(). Guenther (This used to be commit 53dc9a11810b93a1771304fbfbf4ae84f551612b) --- source3/lib/netapi/localgroup.c | 262 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 260 insertions(+), 2 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/localgroup.c b/source3/lib/netapi/localgroup.c index 840bc52fb7..aeaa96a84c 100644 --- a/source3/lib/netapi/localgroup.c +++ b/source3/lib/netapi/localgroup.c @@ -960,10 +960,268 @@ WERROR NetLocalGroupEnum_l(struct libnetapi_ctx *ctx, /**************************************************************** ****************************************************************/ +static NTSTATUS libnetapi_lsa_lookup_names3(TALLOC_CTX *mem_ctx, + struct rpc_pipe_client *lsa_pipe, + const char *name, + struct dom_sid *sid) +{ + NTSTATUS status; + struct policy_handle lsa_handle; + + struct lsa_RefDomainList *domains = NULL; + struct lsa_TransSidArray3 sids; + uint32_t count = 0; + + struct lsa_String names; + uint32_t num_names = 1; + + if (!sid || !name) { + return NT_STATUS_INVALID_PARAMETER; + } + + ZERO_STRUCT(sids); + + init_lsa_String(&names, name); + + status = rpccli_lsa_open_policy2(lsa_pipe, mem_ctx, + false, + STD_RIGHT_READ_CONTROL_ACCESS | + LSA_POLICY_VIEW_LOCAL_INFORMATION | + LSA_POLICY_LOOKUP_NAMES, + &lsa_handle); + NT_STATUS_NOT_OK_RETURN(status); + + status = rpccli_lsa_LookupNames3(lsa_pipe, mem_ctx, + &lsa_handle, + num_names, + &names, + &domains, + &sids, + LSA_LOOKUP_NAMES_ALL, /* sure ? */ + &count, + 0, 0); + NT_STATUS_NOT_OK_RETURN(status); + + if (count != 1 || sids.count != 1) { + return NT_STATUS_NONE_MAPPED; + } + + sid_copy(sid, sids.sids[0].sid); + + return NT_STATUS_OK; +} + +/**************************************************************** +****************************************************************/ + +static WERROR NetLocalGroupModifyMembers_r(struct libnetapi_ctx *ctx, + struct NetLocalGroupAddMembers *add) +{ + struct NetLocalGroupAddMembers *r = NULL; + + struct cli_state *cli = NULL; + struct rpc_pipe_client *pipe_cli = NULL; + struct rpc_pipe_client *lsa_pipe = NULL; + NTSTATUS status; + WERROR werr; + struct lsa_String lsa_account_name; + struct policy_handle connect_handle, domain_handle, builtin_handle, alias_handle; + struct dom_sid2 *domain_sid = NULL; + struct dom_sid *member_sids = NULL; + int i = 0; + + struct LOCALGROUP_MEMBERS_INFO_0 *info0 = NULL; + struct LOCALGROUP_MEMBERS_INFO_3 *info3 = NULL; + + struct dom_sid *add_sids = NULL; + size_t num_add_sids = 0; + + if (!add) { + return WERR_INVALID_PARAM; + } + + if (add) { + r = add; + } + + if (!r->in.group_name) { + return WERR_INVALID_PARAM; + } + + switch (r->in.level) { + case 0: + case 3: + break; + default: + return WERR_UNKNOWN_LEVEL; + } + + if (r->in.total_entries == 0 || !r->in.buffer) { + return WERR_INVALID_PARAM; + } + + ZERO_STRUCT(connect_handle); + ZERO_STRUCT(builtin_handle); + ZERO_STRUCT(domain_handle); + ZERO_STRUCT(alias_handle); + + member_sids = TALLOC_ZERO_ARRAY(ctx, struct dom_sid, + r->in.total_entries); + W_ERROR_HAVE_NO_MEMORY(member_sids); + + switch (r->in.level) { + case 0: + info0 = (struct LOCALGROUP_MEMBERS_INFO_0 *)r->in.buffer; + for (i=0; i < r->in.total_entries; i++) { + sid_copy(&member_sids[i], (struct dom_sid *)info0[i].lgrmi0_sid); + } + break; + case 3: + info3 = (struct LOCALGROUP_MEMBERS_INFO_3 *)r->in.buffer; + break; + default: + break; + } + + werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + if (r->in.level == 3) { + werr = libnetapi_open_pipe(ctx, cli, &ndr_table_lsarpc.syntax_id, + &lsa_pipe); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + for (i=0; i < r->in.total_entries; i++) { + status = libnetapi_lsa_lookup_names3(ctx, lsa_pipe, + info3[i].lgrmi3_domainandname, + &member_sids[i]); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + } + TALLOC_FREE(lsa_pipe); + } + + werr = libnetapi_open_pipe(ctx, cli, &ndr_table_samr.syntax_id, + &pipe_cli); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + werr = libnetapi_samr_open_builtin_domain(ctx, pipe_cli, + SAMR_ACCESS_OPEN_DOMAIN | + SAMR_ACCESS_ENUM_DOMAINS, + SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, + &connect_handle, + &builtin_handle); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + init_lsa_String(&lsa_account_name, r->in.group_name); + + werr = libnetapi_samr_lookup_and_open_alias(ctx, pipe_cli, + &builtin_handle, + r->in.group_name, + SAMR_ALIAS_ACCESS_ADD_MEMBER | + SAMR_ALIAS_ACCESS_REMOVE_MEMBER | + SAMR_ALIAS_ACCESS_GET_MEMBERS | + SAMR_ALIAS_ACCESS_LOOKUP_INFO, + &alias_handle); + + if (ctx->disable_policy_handle_cache) { + libnetapi_samr_close_builtin_handle(ctx, &builtin_handle); + } + + if (W_ERROR_IS_OK(werr)) { + goto modify_membership; + } + + werr = libnetapi_samr_open_domain(ctx, pipe_cli, + SAMR_ACCESS_ENUM_DOMAINS | + SAMR_ACCESS_OPEN_DOMAIN, + SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, + &connect_handle, + &domain_handle, + &domain_sid); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + werr = libnetapi_samr_lookup_and_open_alias(ctx, pipe_cli, + &domain_handle, + r->in.group_name, + SAMR_ALIAS_ACCESS_ADD_MEMBER | + SAMR_ALIAS_ACCESS_REMOVE_MEMBER | + SAMR_ALIAS_ACCESS_GET_MEMBERS | + SAMR_ALIAS_ACCESS_LOOKUP_INFO, + &alias_handle); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + if (ctx->disable_policy_handle_cache) { + libnetapi_samr_close_domain_handle(ctx, &domain_handle); + } + + modify_membership: + + if (add) { + for (i=0; i < r->in.total_entries; i++) { + status = add_sid_to_array_unique(ctx, &member_sids[i], + &add_sids, + &num_add_sids); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + } + } + + /* add list */ + + for (i=0; i < num_add_sids; i++) { + status = rpccli_samr_AddAliasMember(pipe_cli, ctx, + &alias_handle, + &add_sids[i]); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + } + + werr = WERR_OK; + + done: + if (!cli) { + return werr; + } + + if (is_valid_policy_hnd(&alias_handle)) { + rpccli_samr_Close(pipe_cli, ctx, &alias_handle); + } + + if (ctx->disable_policy_handle_cache) { + libnetapi_samr_close_domain_handle(ctx, &domain_handle); + libnetapi_samr_close_builtin_handle(ctx, &builtin_handle); + libnetapi_samr_close_connect_handle(ctx, &connect_handle); + } + + return werr; +} + +/**************************************************************** +****************************************************************/ + WERROR NetLocalGroupAddMembers_r(struct libnetapi_ctx *ctx, struct NetLocalGroupAddMembers *r) { - return WERR_NOT_SUPPORTED; + return NetLocalGroupModifyMembers_r(ctx, r); } /**************************************************************** @@ -972,7 +1230,7 @@ WERROR NetLocalGroupAddMembers_r(struct libnetapi_ctx *ctx, WERROR NetLocalGroupAddMembers_l(struct libnetapi_ctx *ctx, struct NetLocalGroupAddMembers *r) { - return WERR_NOT_SUPPORTED; + return NetLocalGroupAddMembers_r(ctx, r); } /**************************************************************** -- cgit From b65fcbc1f52a6a737d62241721bfe8a97dd79c62 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 11 Aug 2008 19:42:42 +0200 Subject: netapi: implement NetLocalGroupDelMembers_r(). Guenther (This used to be commit bd31d8f9ec9a24ca68e1d5441c0cafd98132060f) --- source3/lib/netapi/localgroup.c | 41 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 5 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/localgroup.c b/source3/lib/netapi/localgroup.c index aeaa96a84c..f9a0506e7c 100644 --- a/source3/lib/netapi/localgroup.c +++ b/source3/lib/netapi/localgroup.c @@ -1015,7 +1015,8 @@ static NTSTATUS libnetapi_lsa_lookup_names3(TALLOC_CTX *mem_ctx, ****************************************************************/ static WERROR NetLocalGroupModifyMembers_r(struct libnetapi_ctx *ctx, - struct NetLocalGroupAddMembers *add) + struct NetLocalGroupAddMembers *add, + struct NetLocalGroupDelMembers *del) { struct NetLocalGroupAddMembers *r = NULL; @@ -1034,9 +1035,11 @@ static WERROR NetLocalGroupModifyMembers_r(struct libnetapi_ctx *ctx, struct LOCALGROUP_MEMBERS_INFO_3 *info3 = NULL; struct dom_sid *add_sids = NULL; + struct dom_sid *del_sids = NULL; size_t num_add_sids = 0; + size_t num_del_sids = 0; - if (!add) { + if ((!add && !del) || (add && del)) { return WERR_INVALID_PARAM; } @@ -1044,6 +1047,10 @@ static WERROR NetLocalGroupModifyMembers_r(struct libnetapi_ctx *ctx, r = add; } + if (del) { + r = (struct NetLocalGroupAddMembers *)del; + } + if (!r->in.group_name) { return WERR_INVALID_PARAM; } @@ -1183,6 +1190,18 @@ static WERROR NetLocalGroupModifyMembers_r(struct libnetapi_ctx *ctx, } } + if (del) { + for (i=0; i < r->in.total_entries; i++) { + status = add_sid_to_array_unique(ctx, &member_sids[i], + &del_sids, + &num_del_sids); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + } + } + /* add list */ for (i=0; i < num_add_sids; i++) { @@ -1195,6 +1214,18 @@ static WERROR NetLocalGroupModifyMembers_r(struct libnetapi_ctx *ctx, } } + /* del list */ + + for (i=0; i < num_del_sids; i++) { + status = rpccli_samr_DeleteAliasMember(pipe_cli, ctx, + &alias_handle, + &del_sids[i]); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + } + werr = WERR_OK; done: @@ -1221,7 +1252,7 @@ static WERROR NetLocalGroupModifyMembers_r(struct libnetapi_ctx *ctx, WERROR NetLocalGroupAddMembers_r(struct libnetapi_ctx *ctx, struct NetLocalGroupAddMembers *r) { - return NetLocalGroupModifyMembers_r(ctx, r); + return NetLocalGroupModifyMembers_r(ctx, r, NULL); } /**************************************************************** @@ -1239,7 +1270,7 @@ WERROR NetLocalGroupAddMembers_l(struct libnetapi_ctx *ctx, WERROR NetLocalGroupDelMembers_r(struct libnetapi_ctx *ctx, struct NetLocalGroupDelMembers *r) { - return WERR_NOT_SUPPORTED; + return NetLocalGroupModifyMembers_r(ctx, NULL, r); } /**************************************************************** @@ -1248,7 +1279,7 @@ WERROR NetLocalGroupDelMembers_r(struct libnetapi_ctx *ctx, WERROR NetLocalGroupDelMembers_l(struct libnetapi_ctx *ctx, struct NetLocalGroupDelMembers *r) { - return WERR_NOT_SUPPORTED; + return NetLocalGroupDelMembers_r(ctx, r); } /**************************************************************** -- cgit From f947d416ff480176f64babdea87c3f251da05e53 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 11 Aug 2008 19:43:24 +0200 Subject: netapi: implement NetLocalGroupSetMembers_r(). Guenther (This used to be commit bb52ba58e47364d7c7ed38862a007e8e3d9dc104) --- source3/lib/netapi/localgroup.c | 76 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 69 insertions(+), 7 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/localgroup.c b/source3/lib/netapi/localgroup.c index f9a0506e7c..e863416438 100644 --- a/source3/lib/netapi/localgroup.c +++ b/source3/lib/netapi/localgroup.c @@ -1016,7 +1016,8 @@ static NTSTATUS libnetapi_lsa_lookup_names3(TALLOC_CTX *mem_ctx, static WERROR NetLocalGroupModifyMembers_r(struct libnetapi_ctx *ctx, struct NetLocalGroupAddMembers *add, - struct NetLocalGroupDelMembers *del) + struct NetLocalGroupDelMembers *del, + struct NetLocalGroupSetMembers *set) { struct NetLocalGroupAddMembers *r = NULL; @@ -1029,7 +1030,7 @@ static WERROR NetLocalGroupModifyMembers_r(struct libnetapi_ctx *ctx, struct policy_handle connect_handle, domain_handle, builtin_handle, alias_handle; struct dom_sid2 *domain_sid = NULL; struct dom_sid *member_sids = NULL; - int i = 0; + int i = 0, k = 0; struct LOCALGROUP_MEMBERS_INFO_0 *info0 = NULL; struct LOCALGROUP_MEMBERS_INFO_3 *info3 = NULL; @@ -1039,7 +1040,7 @@ static WERROR NetLocalGroupModifyMembers_r(struct libnetapi_ctx *ctx, size_t num_add_sids = 0; size_t num_del_sids = 0; - if ((!add && !del) || (add && del)) { + if ((!add && !del && !set) || (add && del && set)) { return WERR_INVALID_PARAM; } @@ -1051,6 +1052,10 @@ static WERROR NetLocalGroupModifyMembers_r(struct libnetapi_ctx *ctx, r = (struct NetLocalGroupAddMembers *)del; } + if (set) { + r = (struct NetLocalGroupAddMembers *)set; + } + if (!r->in.group_name) { return WERR_INVALID_PARAM; } @@ -1202,6 +1207,63 @@ static WERROR NetLocalGroupModifyMembers_r(struct libnetapi_ctx *ctx, } } + if (set) { + + struct lsa_SidArray current_sids; + + status = rpccli_samr_GetMembersInAlias(pipe_cli, ctx, + &alias_handle, + ¤t_sids); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + /* add list */ + + for (i=0; i < r->in.total_entries; i++) { + bool already_member = false; + for (k=0; k < current_sids.num_sids; k++) { + if (sid_equal(&member_sids[i], + current_sids.sids[k].sid)) { + already_member = true; + break; + } + } + if (!already_member) { + status = add_sid_to_array_unique(ctx, + &member_sids[i], + &add_sids, &num_add_sids); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + } + } + + /* del list */ + + for (k=0; k < current_sids.num_sids; k++) { + bool keep_member = false; + for (i=0; i < r->in.total_entries; i++) { + if (sid_equal(&member_sids[i], + current_sids.sids[k].sid)) { + keep_member = true; + break; + } + } + if (!keep_member) { + status = add_sid_to_array_unique(ctx, + current_sids.sids[k].sid, + &del_sids, &num_del_sids); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + } + } + } + /* add list */ for (i=0; i < num_add_sids; i++) { @@ -1252,7 +1314,7 @@ static WERROR NetLocalGroupModifyMembers_r(struct libnetapi_ctx *ctx, WERROR NetLocalGroupAddMembers_r(struct libnetapi_ctx *ctx, struct NetLocalGroupAddMembers *r) { - return NetLocalGroupModifyMembers_r(ctx, r, NULL); + return NetLocalGroupModifyMembers_r(ctx, r, NULL, NULL); } /**************************************************************** @@ -1270,7 +1332,7 @@ WERROR NetLocalGroupAddMembers_l(struct libnetapi_ctx *ctx, WERROR NetLocalGroupDelMembers_r(struct libnetapi_ctx *ctx, struct NetLocalGroupDelMembers *r) { - return NetLocalGroupModifyMembers_r(ctx, NULL, r); + return NetLocalGroupModifyMembers_r(ctx, NULL, r, NULL); } /**************************************************************** @@ -1306,7 +1368,7 @@ WERROR NetLocalGroupGetMembers_l(struct libnetapi_ctx *ctx, WERROR NetLocalGroupSetMembers_r(struct libnetapi_ctx *ctx, struct NetLocalGroupSetMembers *r) { - return WERR_NOT_SUPPORTED; + return NetLocalGroupModifyMembers_r(ctx, NULL, NULL, r); } /**************************************************************** @@ -1315,6 +1377,6 @@ WERROR NetLocalGroupSetMembers_r(struct libnetapi_ctx *ctx, WERROR NetLocalGroupSetMembers_l(struct libnetapi_ctx *ctx, struct NetLocalGroupSetMembers *r) { - return WERR_NOT_SUPPORTED; + return NetLocalGroupSetMembers_r(ctx, r); } -- cgit From 6f28bc691a9cf4a79352904cc91c77b17263d7e7 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 1 Aug 2008 16:03:00 +0200 Subject: netapi: add NetLocalGroupAddMembers example code. Guenther (This used to be commit 01c4640b1ca66c3285fd23d447d08db12cf83b42) --- source3/lib/netapi/examples/Makefile.in | 6 + .../examples/localgroup/localgroup_addmembers.c | 141 +++++++++++++++++++++ 2 files changed, 147 insertions(+) create mode 100644 source3/lib/netapi/examples/localgroup/localgroup_addmembers.c (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/Makefile.in b/source3/lib/netapi/examples/Makefile.in index 5e577ed330..d0a38745cf 100644 --- a/source3/lib/netapi/examples/Makefile.in +++ b/source3/lib/netapi/examples/Makefile.in @@ -44,6 +44,7 @@ PROGS = bin/getdc@EXEEXT@ \ bin/localgroup_getinfo@EXEEXT@ \ bin/localgroup_setinfo@EXEEXT@ \ bin/localgroup_enum@EXEEXT@ \ + bin/localgroup_addmembers@EXEEXT@ \ bin/remote_tod@EXEEXT@ all: $(PROGS) @@ -100,6 +101,7 @@ LOCALGROUPDEL_OBJ = localgroup/localgroup_del.o $(CMDLINE_OBJ) LOCALGROUPGETINFO_OBJ = localgroup/localgroup_getinfo.o $(CMDLINE_OBJ) LOCALGROUPSETINFO_OBJ = localgroup/localgroup_setinfo.o $(CMDLINE_OBJ) LOCALGROUPENUM_OBJ = localgroup/localgroup_enum.o $(CMDLINE_OBJ) +LOCALGROUPADDMEMBERS_OBJ = localgroup/localgroup_addmembers.o $(CMDLINE_OBJ) REMOTETOD_OBJ = server/remote_tod.o $(CMDLINE_OBJ) bin/getdc@EXEEXT@: $(BINARY_PREREQS) $(GETDC_OBJ) @@ -210,6 +212,10 @@ bin/localgroup_enum@EXEEXT@: $(BINARY_PREREQS) $(LOCALGROUPENUM_OBJ) @echo Linking $@ @$(CC) $(FLAGS) -o $@ $(LOCALGROUPENUM_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) +bin/localgroup_addmembers@EXEEXT@: $(BINARY_PREREQS) $(LOCALGROUPADDMEMBERS_OBJ) + @echo Linking $@ + @$(CC) $(FLAGS) -o $@ $(LOCALGROUPADDMEMBERS_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) + bin/remote_tod@EXEEXT@: $(BINARY_PREREQS) $(REMOTETOD_OBJ) @echo Linking $@ @$(CC) $(FLAGS) -o $@ $(REMOTETOD_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) diff --git a/source3/lib/netapi/examples/localgroup/localgroup_addmembers.c b/source3/lib/netapi/examples/localgroup/localgroup_addmembers.c new file mode 100644 index 0000000000..aa4a9b59b0 --- /dev/null +++ b/source3/lib/netapi/examples/localgroup/localgroup_addmembers.c @@ -0,0 +1,141 @@ +/* + * Unix SMB/CIFS implementation. + * NetLocalGroupAddMembers query + * Copyright (C) Guenther Deschner 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include +#include +#include +#include +#include + +#include + +#include "common.h" + +int main(int argc, const char **argv) +{ + NET_API_STATUS status; + struct libnetapi_ctx *ctx = NULL; + const char *hostname = NULL; + const char *groupname = NULL; + struct LOCALGROUP_MEMBERS_INFO_0 *g0; + struct LOCALGROUP_MEMBERS_INFO_3 *g3; + uint32_t total_entries = 0; + uint8_t *buffer = NULL; + uint32_t level = 3; + const char **names = NULL; + int i = 0; + + poptContext pc; + int opt; + + struct poptOption long_options[] = { + POPT_AUTOHELP + POPT_COMMON_LIBNETAPI_EXAMPLES + POPT_TABLEEND + }; + + status = libnetapi_init(&ctx); + if (status != 0) { + return status; + } + + pc = poptGetContext("localgroup_addmembers", argc, argv, long_options, 0); + + poptSetOtherOptionHelp(pc, "hostname groupname member1 member2 ..."); + while((opt = poptGetNextOpt(pc)) != -1) { + } + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + hostname = poptGetArg(pc); + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + groupname = poptGetArg(pc); + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + + names = poptGetArgs(pc); + for (i=0; names[i] != NULL; i++) { + total_entries++; + } + + switch (level) { + case 0: + status = NetApiBufferAllocate(sizeof(struct LOCALGROUP_MEMBERS_INFO_0) * total_entries, + (void **)&g0); + if (status) { + printf("NetApiBufferAllocate failed with: %s\n", + libnetapi_get_error_string(ctx, status)); + goto out; + } + + for (i=0; i Date: Fri, 1 Aug 2008 17:13:43 +0200 Subject: netapi: add NetLocalGroupDelMembers example code. Guenther (This used to be commit b2a413148e470e059c877f4e54955ab61559edee) --- source3/lib/netapi/examples/Makefile.in | 6 + .../examples/localgroup/localgroup_delmembers.c | 141 +++++++++++++++++++++ 2 files changed, 147 insertions(+) create mode 100644 source3/lib/netapi/examples/localgroup/localgroup_delmembers.c (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/Makefile.in b/source3/lib/netapi/examples/Makefile.in index d0a38745cf..5cf7a4d3c1 100644 --- a/source3/lib/netapi/examples/Makefile.in +++ b/source3/lib/netapi/examples/Makefile.in @@ -45,6 +45,7 @@ PROGS = bin/getdc@EXEEXT@ \ bin/localgroup_setinfo@EXEEXT@ \ bin/localgroup_enum@EXEEXT@ \ bin/localgroup_addmembers@EXEEXT@ \ + bin/localgroup_delmembers@EXEEXT@ \ bin/remote_tod@EXEEXT@ all: $(PROGS) @@ -102,6 +103,7 @@ LOCALGROUPGETINFO_OBJ = localgroup/localgroup_getinfo.o $(CMDLINE_OBJ) LOCALGROUPSETINFO_OBJ = localgroup/localgroup_setinfo.o $(CMDLINE_OBJ) LOCALGROUPENUM_OBJ = localgroup/localgroup_enum.o $(CMDLINE_OBJ) LOCALGROUPADDMEMBERS_OBJ = localgroup/localgroup_addmembers.o $(CMDLINE_OBJ) +LOCALGROUPDELMEMBERS_OBJ = localgroup/localgroup_delmembers.o $(CMDLINE_OBJ) REMOTETOD_OBJ = server/remote_tod.o $(CMDLINE_OBJ) bin/getdc@EXEEXT@: $(BINARY_PREREQS) $(GETDC_OBJ) @@ -216,6 +218,10 @@ bin/localgroup_addmembers@EXEEXT@: $(BINARY_PREREQS) $(LOCALGROUPADDMEMBERS_OBJ) @echo Linking $@ @$(CC) $(FLAGS) -o $@ $(LOCALGROUPADDMEMBERS_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) +bin/localgroup_delmembers@EXEEXT@: $(BINARY_PREREQS) $(LOCALGROUPDELMEMBERS_OBJ) + @echo Linking $@ + @$(CC) $(FLAGS) -o $@ $(LOCALGROUPDELMEMBERS_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) + bin/remote_tod@EXEEXT@: $(BINARY_PREREQS) $(REMOTETOD_OBJ) @echo Linking $@ @$(CC) $(FLAGS) -o $@ $(REMOTETOD_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) diff --git a/source3/lib/netapi/examples/localgroup/localgroup_delmembers.c b/source3/lib/netapi/examples/localgroup/localgroup_delmembers.c new file mode 100644 index 0000000000..7bd3ec0993 --- /dev/null +++ b/source3/lib/netapi/examples/localgroup/localgroup_delmembers.c @@ -0,0 +1,141 @@ +/* + * Unix SMB/CIFS implementation. + * NetLocalGroupDelMembers query + * Copyright (C) Guenther Deschner 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include +#include +#include +#include +#include + +#include + +#include "common.h" + +int main(int argc, const char **argv) +{ + NET_API_STATUS status; + struct libnetapi_ctx *ctx = NULL; + const char *hostname = NULL; + const char *groupname = NULL; + struct LOCALGROUP_MEMBERS_INFO_0 *g0; + struct LOCALGROUP_MEMBERS_INFO_3 *g3; + uint32_t total_entries = 0; + uint8_t *buffer = NULL; + uint32_t level = 3; + const char **names = NULL; + int i = 0; + + poptContext pc; + int opt; + + struct poptOption long_options[] = { + POPT_AUTOHELP + POPT_COMMON_LIBNETAPI_EXAMPLES + POPT_TABLEEND + }; + + status = libnetapi_init(&ctx); + if (status != 0) { + return status; + } + + pc = poptGetContext("localgroup_delmembers", argc, argv, long_options, 0); + + poptSetOtherOptionHelp(pc, "hostname groupname member1 member2 ..."); + while((opt = poptGetNextOpt(pc)) != -1) { + } + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + hostname = poptGetArg(pc); + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + groupname = poptGetArg(pc); + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + + names = poptGetArgs(pc); + for (i=0; names[i] != NULL; i++) { + total_entries++; + } + + switch (level) { + case 0: + status = NetApiBufferAllocate(sizeof(struct LOCALGROUP_MEMBERS_INFO_0) * total_entries, + (void **)&g0); + if (status) { + printf("NetApiBufferAllocate failed with: %s\n", + libnetapi_get_error_string(ctx, status)); + goto out; + } + + for (i=0; i Date: Fri, 1 Aug 2008 19:15:52 +0200 Subject: netapi: add NetLocalGroupSetMembers example code. Guenther (This used to be commit 4fea49ae83510225c51c580a2bea2c664851bb39) --- source3/lib/netapi/examples/Makefile.in | 6 + .../examples/localgroup/localgroup_setmembers.c | 141 +++++++++++++++++++++ 2 files changed, 147 insertions(+) create mode 100644 source3/lib/netapi/examples/localgroup/localgroup_setmembers.c (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/Makefile.in b/source3/lib/netapi/examples/Makefile.in index 5cf7a4d3c1..158df4ff00 100644 --- a/source3/lib/netapi/examples/Makefile.in +++ b/source3/lib/netapi/examples/Makefile.in @@ -46,6 +46,7 @@ PROGS = bin/getdc@EXEEXT@ \ bin/localgroup_enum@EXEEXT@ \ bin/localgroup_addmembers@EXEEXT@ \ bin/localgroup_delmembers@EXEEXT@ \ + bin/localgroup_setmembers@EXEEXT@ \ bin/remote_tod@EXEEXT@ all: $(PROGS) @@ -104,6 +105,7 @@ LOCALGROUPSETINFO_OBJ = localgroup/localgroup_setinfo.o $(CMDLINE_OBJ) LOCALGROUPENUM_OBJ = localgroup/localgroup_enum.o $(CMDLINE_OBJ) LOCALGROUPADDMEMBERS_OBJ = localgroup/localgroup_addmembers.o $(CMDLINE_OBJ) LOCALGROUPDELMEMBERS_OBJ = localgroup/localgroup_delmembers.o $(CMDLINE_OBJ) +LOCALGROUPSETMEMBERS_OBJ = localgroup/localgroup_setmembers.o $(CMDLINE_OBJ) REMOTETOD_OBJ = server/remote_tod.o $(CMDLINE_OBJ) bin/getdc@EXEEXT@: $(BINARY_PREREQS) $(GETDC_OBJ) @@ -222,6 +224,10 @@ bin/localgroup_delmembers@EXEEXT@: $(BINARY_PREREQS) $(LOCALGROUPDELMEMBERS_OBJ) @echo Linking $@ @$(CC) $(FLAGS) -o $@ $(LOCALGROUPDELMEMBERS_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) +bin/localgroup_setmembers@EXEEXT@: $(BINARY_PREREQS) $(LOCALGROUPSETMEMBERS_OBJ) + @echo Linking $@ + @$(CC) $(FLAGS) -o $@ $(LOCALGROUPSETMEMBERS_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) + bin/remote_tod@EXEEXT@: $(BINARY_PREREQS) $(REMOTETOD_OBJ) @echo Linking $@ @$(CC) $(FLAGS) -o $@ $(REMOTETOD_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) diff --git a/source3/lib/netapi/examples/localgroup/localgroup_setmembers.c b/source3/lib/netapi/examples/localgroup/localgroup_setmembers.c new file mode 100644 index 0000000000..acee5cd9c6 --- /dev/null +++ b/source3/lib/netapi/examples/localgroup/localgroup_setmembers.c @@ -0,0 +1,141 @@ +/* + * Unix SMB/CIFS implementation. + * NetLocalGroupSetMembers query + * Copyright (C) Guenther Deschner 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include +#include +#include +#include +#include + +#include + +#include "common.h" + +int main(int argc, const char **argv) +{ + NET_API_STATUS status; + struct libnetapi_ctx *ctx = NULL; + const char *hostname = NULL; + const char *groupname = NULL; + struct LOCALGROUP_MEMBERS_INFO_0 *g0; + struct LOCALGROUP_MEMBERS_INFO_3 *g3; + uint32_t total_entries = 0; + uint8_t *buffer = NULL; + uint32_t level = 3; + const char **names = NULL; + int i = 0; + + poptContext pc; + int opt; + + struct poptOption long_options[] = { + POPT_AUTOHELP + POPT_COMMON_LIBNETAPI_EXAMPLES + POPT_TABLEEND + }; + + status = libnetapi_init(&ctx); + if (status != 0) { + return status; + } + + pc = poptGetContext("localgroup_setmembers", argc, argv, long_options, 0); + + poptSetOtherOptionHelp(pc, "hostname groupname member1 member2 ..."); + while((opt = poptGetNextOpt(pc)) != -1) { + } + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + hostname = poptGetArg(pc); + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + groupname = poptGetArg(pc); + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + + names = poptGetArgs(pc); + for (i=0; names[i] != NULL; i++) { + total_entries++; + } + + switch (level) { + case 0: + status = NetApiBufferAllocate(sizeof(struct LOCALGROUP_MEMBERS_INFO_0) * total_entries, + (void **)&g0); + if (status) { + printf("NetApiBufferAllocate failed with: %s\n", + libnetapi_get_error_string(ctx, status)); + goto out; + } + + for (i=0; i Date: Tue, 12 Aug 2008 19:38:22 +0200 Subject: netapi: add c++ guard. Guenther (This used to be commit c9e38fef647520e4038f04bd163678bf4b30853d) --- source3/lib/netapi/netapi.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h index dbf293e25b..5f9cff97db 100644 --- a/source3/lib/netapi/netapi.h +++ b/source3/lib/netapi/netapi.h @@ -20,6 +20,10 @@ #ifndef __LIB_NETAPI_H__ #define __LIB_NETAPI_H__ +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + /**************************************************************** NET_API_STATUS ****************************************************************/ @@ -1200,5 +1204,8 @@ NET_API_STATUS NetLocalGroupSetMembers(const char * server_name /* [in] */, NET_API_STATUS NetRemoteTOD(const char * server_name /* [in] */, uint8_t **buf /* [out] [ref] */); +#ifdef __cplusplus +} +#endif /* __cplusplus */ -#endif +#endif /* __LIB_NETAPI_H__ */ -- cgit From 11db643962cec98299fbf6f79ef0b51cd2ee0e90 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 11 Aug 2008 20:39:14 +0200 Subject: netapi: let libnetapi_samr_lookup_and_open_alias return NTSTATUS. Guenther (cherry picked from commit dcf6d879a14a70ce5795eb8dcfbfe2fc5a8ad859) (This used to be commit 8ac6a2739be870f286d19dc6bf8f0054a559b43b) --- source3/lib/netapi/localgroup.c | 162 +++++++++++++++++++--------------------- 1 file changed, 77 insertions(+), 85 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/localgroup.c b/source3/lib/netapi/localgroup.c index e863416438..6fe5f1cd86 100644 --- a/source3/lib/netapi/localgroup.c +++ b/source3/lib/netapi/localgroup.c @@ -24,15 +24,14 @@ #include "lib/netapi/netapi_private.h" #include "lib/netapi/libnetapi.h" -static WERROR libnetapi_samr_lookup_and_open_alias(TALLOC_CTX *mem_ctx, - struct rpc_pipe_client *pipe_cli, - struct policy_handle *domain_handle, - const char *group_name, - uint32_t access_rights, - struct policy_handle *alias_handle) +static NTSTATUS libnetapi_samr_lookup_and_open_alias(TALLOC_CTX *mem_ctx, + struct rpc_pipe_client *pipe_cli, + struct policy_handle *domain_handle, + const char *group_name, + uint32_t access_rights, + struct policy_handle *alias_handle) { NTSTATUS status; - WERROR werr; struct lsa_String lsa_account_name; struct samr_Ids user_rids, name_types; @@ -46,8 +45,7 @@ static WERROR libnetapi_samr_lookup_and_open_alias(TALLOC_CTX *mem_ctx, &user_rids, &name_types); if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; + return status; } switch (name_types.ids[0]) { @@ -55,23 +53,14 @@ static WERROR libnetapi_samr_lookup_and_open_alias(TALLOC_CTX *mem_ctx, case SID_NAME_WKN_GRP: break; default: - return WERR_INVALID_DATATYPE; - } - - status = rpccli_samr_OpenAlias(pipe_cli, mem_ctx, - domain_handle, - access_rights, - user_rids.ids[0], - alias_handle); - if (NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; + return NT_STATUS_INVALID_SID; } - werr = WERR_OK; - - done: - return werr; + return rpccli_samr_OpenAlias(pipe_cli, mem_ctx, + domain_handle, + access_rights, + user_rids.ids[0], + alias_handle); } /**************************************************************** @@ -182,17 +171,16 @@ WERROR NetLocalGroupAdd_r(struct libnetapi_ctx *ctx, goto done; } - werr = libnetapi_samr_lookup_and_open_alias(ctx, pipe_cli, - &builtin_handle, - alias_name, - SAMR_ALIAS_ACCESS_LOOKUP_INFO, - &alias_handle); - + status = libnetapi_samr_lookup_and_open_alias(ctx, pipe_cli, + &builtin_handle, + alias_name, + SAMR_ALIAS_ACCESS_LOOKUP_INFO, + &alias_handle); if (ctx->disable_policy_handle_cache) { libnetapi_samr_close_builtin_handle(ctx, &builtin_handle); } - if (W_ERROR_IS_OK(werr)) { + if (NT_STATUS_IS_OK(status)) { werr = WERR_ALIAS_EXISTS; goto done; } @@ -312,17 +300,17 @@ WERROR NetLocalGroupDel_r(struct libnetapi_ctx *ctx, goto done; } - werr = libnetapi_samr_lookup_and_open_alias(ctx, pipe_cli, - &builtin_handle, - r->in.group_name, - SEC_STD_DELETE, - &alias_handle); + status = libnetapi_samr_lookup_and_open_alias(ctx, pipe_cli, + &builtin_handle, + r->in.group_name, + SEC_STD_DELETE, + &alias_handle); if (ctx->disable_policy_handle_cache) { libnetapi_samr_close_builtin_handle(ctx, &builtin_handle); } - if (W_ERROR_IS_OK(werr)) { + if (NT_STATUS_IS_OK(status)) { goto delete_alias; } @@ -338,17 +326,18 @@ WERROR NetLocalGroupDel_r(struct libnetapi_ctx *ctx, goto done; } - werr = libnetapi_samr_lookup_and_open_alias(ctx, pipe_cli, - &domain_handle, - r->in.group_name, - SEC_STD_DELETE, - &alias_handle); + status = libnetapi_samr_lookup_and_open_alias(ctx, pipe_cli, + &domain_handle, + r->in.group_name, + SEC_STD_DELETE, + &alias_handle); if (ctx->disable_policy_handle_cache) { libnetapi_samr_close_domain_handle(ctx, &domain_handle); } - if (!W_ERROR_IS_OK(werr)) { + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); goto done; } @@ -492,17 +481,17 @@ WERROR NetLocalGroupGetInfo_r(struct libnetapi_ctx *ctx, goto done; } - werr = libnetapi_samr_lookup_and_open_alias(ctx, pipe_cli, - &builtin_handle, - r->in.group_name, - SAMR_ALIAS_ACCESS_LOOKUP_INFO, - &alias_handle); + status = libnetapi_samr_lookup_and_open_alias(ctx, pipe_cli, + &builtin_handle, + r->in.group_name, + SAMR_ALIAS_ACCESS_LOOKUP_INFO, + &alias_handle); if (ctx->disable_policy_handle_cache) { libnetapi_samr_close_builtin_handle(ctx, &builtin_handle); } - if (W_ERROR_IS_OK(werr)) { + if (NT_STATUS_IS_OK(status)) { goto query_alias; } @@ -518,17 +507,18 @@ WERROR NetLocalGroupGetInfo_r(struct libnetapi_ctx *ctx, goto done; } - werr = libnetapi_samr_lookup_and_open_alias(ctx, pipe_cli, - &domain_handle, - r->in.group_name, - SAMR_ALIAS_ACCESS_LOOKUP_INFO, - &alias_handle); + status = libnetapi_samr_lookup_and_open_alias(ctx, pipe_cli, + &domain_handle, + r->in.group_name, + SAMR_ALIAS_ACCESS_LOOKUP_INFO, + &alias_handle); if (ctx->disable_policy_handle_cache) { libnetapi_samr_close_domain_handle(ctx, &domain_handle); } - if (!W_ERROR_IS_OK(werr)) { + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); goto done; } @@ -673,17 +663,17 @@ WERROR NetLocalGroupSetInfo_r(struct libnetapi_ctx *ctx, init_lsa_String(&lsa_account_name, r->in.group_name); - werr = libnetapi_samr_lookup_and_open_alias(ctx, pipe_cli, - &builtin_handle, - r->in.group_name, - SAMR_ALIAS_ACCESS_SET_INFO, - &alias_handle); + status = libnetapi_samr_lookup_and_open_alias(ctx, pipe_cli, + &builtin_handle, + r->in.group_name, + SAMR_ALIAS_ACCESS_SET_INFO, + &alias_handle); if (ctx->disable_policy_handle_cache) { libnetapi_samr_close_builtin_handle(ctx, &builtin_handle); } - if (W_ERROR_IS_OK(werr)) { + if (NT_STATUS_IS_OK(status)) { goto set_alias; } @@ -698,12 +688,13 @@ WERROR NetLocalGroupSetInfo_r(struct libnetapi_ctx *ctx, goto done; } - werr = libnetapi_samr_lookup_and_open_alias(ctx, pipe_cli, - &domain_handle, - r->in.group_name, - SAMR_ALIAS_ACCESS_SET_INFO, - &alias_handle); - if (!W_ERROR_IS_OK(werr)) { + status = libnetapi_samr_lookup_and_open_alias(ctx, pipe_cli, + &domain_handle, + r->in.group_name, + SAMR_ALIAS_ACCESS_SET_INFO, + &alias_handle); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); goto done; } @@ -1137,20 +1128,20 @@ static WERROR NetLocalGroupModifyMembers_r(struct libnetapi_ctx *ctx, init_lsa_String(&lsa_account_name, r->in.group_name); - werr = libnetapi_samr_lookup_and_open_alias(ctx, pipe_cli, - &builtin_handle, - r->in.group_name, - SAMR_ALIAS_ACCESS_ADD_MEMBER | - SAMR_ALIAS_ACCESS_REMOVE_MEMBER | - SAMR_ALIAS_ACCESS_GET_MEMBERS | - SAMR_ALIAS_ACCESS_LOOKUP_INFO, - &alias_handle); + status = libnetapi_samr_lookup_and_open_alias(ctx, pipe_cli, + &builtin_handle, + r->in.group_name, + SAMR_ALIAS_ACCESS_ADD_MEMBER | + SAMR_ALIAS_ACCESS_REMOVE_MEMBER | + SAMR_ALIAS_ACCESS_GET_MEMBERS | + SAMR_ALIAS_ACCESS_LOOKUP_INFO, + &alias_handle); if (ctx->disable_policy_handle_cache) { libnetapi_samr_close_builtin_handle(ctx, &builtin_handle); } - if (W_ERROR_IS_OK(werr)) { + if (NT_STATUS_IS_OK(status)) { goto modify_membership; } @@ -1165,15 +1156,16 @@ static WERROR NetLocalGroupModifyMembers_r(struct libnetapi_ctx *ctx, goto done; } - werr = libnetapi_samr_lookup_and_open_alias(ctx, pipe_cli, - &domain_handle, - r->in.group_name, - SAMR_ALIAS_ACCESS_ADD_MEMBER | - SAMR_ALIAS_ACCESS_REMOVE_MEMBER | - SAMR_ALIAS_ACCESS_GET_MEMBERS | - SAMR_ALIAS_ACCESS_LOOKUP_INFO, - &alias_handle); - if (!W_ERROR_IS_OK(werr)) { + status = libnetapi_samr_lookup_and_open_alias(ctx, pipe_cli, + &domain_handle, + r->in.group_name, + SAMR_ALIAS_ACCESS_ADD_MEMBER | + SAMR_ALIAS_ACCESS_REMOVE_MEMBER | + SAMR_ALIAS_ACCESS_GET_MEMBERS | + SAMR_ALIAS_ACCESS_LOOKUP_INFO, + &alias_handle); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); goto done; } -- cgit From a810cc865d40aff7dbe123ac5217d8b4b38c95e5 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 12 Aug 2008 12:49:19 +0200 Subject: netapi: add NetLocalGroupGetMembers example code. Guenther (cherry picked from commit bded298e022028d6237e25e1c785509bc983be9d) (This used to be commit 93b0907aa43e55d2d4093567212b0c9731917351) --- source3/lib/netapi/examples/Makefile.in | 6 + .../examples/localgroup/localgroup_getmembers.c | 165 +++++++++++++++++++++ 2 files changed, 171 insertions(+) create mode 100644 source3/lib/netapi/examples/localgroup/localgroup_getmembers.c (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/Makefile.in b/source3/lib/netapi/examples/Makefile.in index 158df4ff00..0b7553c389 100644 --- a/source3/lib/netapi/examples/Makefile.in +++ b/source3/lib/netapi/examples/Makefile.in @@ -47,6 +47,7 @@ PROGS = bin/getdc@EXEEXT@ \ bin/localgroup_addmembers@EXEEXT@ \ bin/localgroup_delmembers@EXEEXT@ \ bin/localgroup_setmembers@EXEEXT@ \ + bin/localgroup_getmembers@EXEEXT@ \ bin/remote_tod@EXEEXT@ all: $(PROGS) @@ -106,6 +107,7 @@ LOCALGROUPENUM_OBJ = localgroup/localgroup_enum.o $(CMDLINE_OBJ) LOCALGROUPADDMEMBERS_OBJ = localgroup/localgroup_addmembers.o $(CMDLINE_OBJ) LOCALGROUPDELMEMBERS_OBJ = localgroup/localgroup_delmembers.o $(CMDLINE_OBJ) LOCALGROUPSETMEMBERS_OBJ = localgroup/localgroup_setmembers.o $(CMDLINE_OBJ) +LOCALGROUPGETMEMBERS_OBJ = localgroup/localgroup_getmembers.o $(CMDLINE_OBJ) REMOTETOD_OBJ = server/remote_tod.o $(CMDLINE_OBJ) bin/getdc@EXEEXT@: $(BINARY_PREREQS) $(GETDC_OBJ) @@ -228,6 +230,10 @@ bin/localgroup_setmembers@EXEEXT@: $(BINARY_PREREQS) $(LOCALGROUPSETMEMBERS_OBJ) @echo Linking $@ @$(CC) $(FLAGS) -o $@ $(LOCALGROUPSETMEMBERS_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) +bin/localgroup_getmembers@EXEEXT@: $(BINARY_PREREQS) $(LOCALGROUPGETMEMBERS_OBJ) + @echo Linking $@ + @$(CC) $(FLAGS) -o $@ $(LOCALGROUPGETMEMBERS_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) + bin/remote_tod@EXEEXT@: $(BINARY_PREREQS) $(REMOTETOD_OBJ) @echo Linking $@ @$(CC) $(FLAGS) -o $@ $(REMOTETOD_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) diff --git a/source3/lib/netapi/examples/localgroup/localgroup_getmembers.c b/source3/lib/netapi/examples/localgroup/localgroup_getmembers.c new file mode 100644 index 0000000000..0589870d02 --- /dev/null +++ b/source3/lib/netapi/examples/localgroup/localgroup_getmembers.c @@ -0,0 +1,165 @@ +/* + * Unix SMB/CIFS implementation. + * NetLocalGroupGetMembers query + * Copyright (C) Guenther Deschner 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include +#include +#include +#include +#include + +#include + +#include "common.h" + +int main(int argc, const char **argv) +{ + NET_API_STATUS status; + struct libnetapi_ctx *ctx = NULL; + const char *hostname = NULL; + const char *groupname = NULL; + uint32_t level = 0; + uint8_t *buffer = NULL; + uint32_t entries_read = 0; + uint32_t total_entries = 0; + uint32_t resume_handle = 0; + char *sid_str = NULL; + int i; + + struct LOCALGROUP_MEMBERS_INFO_0 *info0 = NULL; + struct LOCALGROUP_MEMBERS_INFO_1 *info1 = NULL; + struct LOCALGROUP_MEMBERS_INFO_2 *info2 = NULL; + struct LOCALGROUP_MEMBERS_INFO_3 *info3 = NULL; + + poptContext pc; + int opt; + + struct poptOption long_options[] = { + POPT_AUTOHELP + POPT_COMMON_LIBNETAPI_EXAMPLES + POPT_TABLEEND + }; + + status = libnetapi_init(&ctx); + if (status != 0) { + return status; + } + + pc = poptGetContext("localgroup_getmembers", argc, argv, long_options, 0); + + poptSetOtherOptionHelp(pc, "hostname groupname level"); + while((opt = poptGetNextOpt(pc)) != -1) { + } + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + hostname = poptGetArg(pc); + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + groupname = poptGetArg(pc); + + if (poptPeekArg(pc)) { + level = atoi(poptGetArg(pc)); + } + + /* NetLocalGroupGetMembers */ + + do { + status = NetLocalGroupGetMembers(hostname, + groupname, + level, + &buffer, + (uint32_t)-1, + &entries_read, + &total_entries, + &resume_handle); + if (status == 0 || status == ERROR_MORE_DATA) { + printf("total entries: %d\n", total_entries); + switch (level) { + case 0: + info0 = (struct LOCALGROUP_MEMBERS_INFO_0 *)buffer; + break; + case 1: + info1 = (struct LOCALGROUP_MEMBERS_INFO_1 *)buffer; + break; + case 2: + info2 = (struct LOCALGROUP_MEMBERS_INFO_2 *)buffer; + break; + case 3: + info3 = (struct LOCALGROUP_MEMBERS_INFO_3 *)buffer; + break; + default: + break; + } + for (i=0; ilgrmi0_sid, + &sid_str)) { + printf("#%d member sid: %s\n", i, sid_str); + free(sid_str); + } + info0++; + break; + case 1: + if (ConvertSidToStringSid(info1->lgrmi1_sid, + &sid_str)) { + printf("#%d member sid: %s\n", i, sid_str); + free(sid_str); + } + printf("#%d sid type: %d\n", i, info1->lgrmi1_sidusage); + printf("#%d name: %s\n", i, info1->lgrmi1_name); + info1++; + break; + case 2: + if (ConvertSidToStringSid(info2->lgrmi2_sid, + &sid_str)) { + printf("#%d member sid: %s\n", i, sid_str); + free(sid_str); + } + printf("#%d sid type: %d\n", i, info2->lgrmi2_sidusage); + printf("#%d full name: %s\n", i, info2->lgrmi2_domainandname); + info2++; + break; + case 3: + printf("#%d full name: %s\n", i, info3->lgrmi3_domainandname); + info3++; + break; + default: + break; + } + } + NetApiBufferFree(buffer); + } + } while (status == ERROR_MORE_DATA); + + if (status != 0) { + printf("NetLocalGroupGetMembers failed with: %s\n", + libnetapi_get_error_string(ctx, status)); + } + + out: + libnetapi_free(ctx); + poptFreeContext(pc); + + return status; +} -- cgit From 87b9c9ade21a68d4428ff4aadd32f02f86e78a40 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 12 Aug 2008 15:25:06 +0200 Subject: netapi: make non-implemented local calls default to remote "localhost" calls. Guenther (cherry picked from commit aa70e588803e3767796dc958b139f4ee464d8626) (This used to be commit 9927ac6eec9fe1fecfedb97b61c4f93379fc8722) --- source3/lib/netapi/getdc.c | 4 ++-- source3/lib/netapi/group.c | 16 ++++++++-------- source3/lib/netapi/localgroup.c | 18 +++++++++--------- source3/lib/netapi/netapi_private.h | 7 +++++++ source3/lib/netapi/serverinfo.c | 2 +- source3/lib/netapi/user.c | 26 ++++++++------------------ 6 files changed, 35 insertions(+), 38 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/getdc.c b/source3/lib/netapi/getdc.c index 4636042431..82fa35d4a1 100644 --- a/source3/lib/netapi/getdc.c +++ b/source3/lib/netapi/getdc.c @@ -31,7 +31,7 @@ WERROR NetGetDCName_l(struct libnetapi_ctx *ctx, struct NetGetDCName *r) { - return WERR_NOT_SUPPORTED; + LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetGetDCName); } /******************************************************************** @@ -72,7 +72,7 @@ WERROR NetGetDCName_r(struct libnetapi_ctx *ctx, WERROR NetGetAnyDCName_l(struct libnetapi_ctx *ctx, struct NetGetAnyDCName *r) { - return WERR_NOT_SUPPORTED; + LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetGetAnyDCName); } /******************************************************************** diff --git a/source3/lib/netapi/group.c b/source3/lib/netapi/group.c index 30ff6af2f0..e057e6de02 100644 --- a/source3/lib/netapi/group.c +++ b/source3/lib/netapi/group.c @@ -220,7 +220,7 @@ WERROR NetGroupAdd_r(struct libnetapi_ctx *ctx, WERROR NetGroupAdd_l(struct libnetapi_ctx *ctx, struct NetGroupAdd *r) { - return NetGroupAdd_r(ctx, r); + LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetGroupAdd); } /**************************************************************** @@ -390,7 +390,7 @@ WERROR NetGroupDel_r(struct libnetapi_ctx *ctx, WERROR NetGroupDel_l(struct libnetapi_ctx *ctx, struct NetGroupDel *r) { - return NetGroupDel_r(ctx, r); + LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetGroupDel); } /**************************************************************** @@ -578,7 +578,7 @@ WERROR NetGroupSetInfo_r(struct libnetapi_ctx *ctx, WERROR NetGroupSetInfo_l(struct libnetapi_ctx *ctx, struct NetGroupSetInfo *r) { - return NetGroupSetInfo_r(ctx, r); + LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetGroupSetInfo); } /**************************************************************** @@ -766,7 +766,7 @@ WERROR NetGroupGetInfo_r(struct libnetapi_ctx *ctx, WERROR NetGroupGetInfo_l(struct libnetapi_ctx *ctx, struct NetGroupGetInfo *r) { - return NetGroupGetInfo_r(ctx, r); + LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetGroupGetInfo); } /**************************************************************** @@ -896,7 +896,7 @@ WERROR NetGroupAddUser_r(struct libnetapi_ctx *ctx, WERROR NetGroupAddUser_l(struct libnetapi_ctx *ctx, struct NetGroupAddUser *r) { - return NetGroupAddUser_r(ctx, r); + LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetGroupAddUser); } /**************************************************************** @@ -1025,7 +1025,7 @@ WERROR NetGroupDelUser_r(struct libnetapi_ctx *ctx, WERROR NetGroupDelUser_l(struct libnetapi_ctx *ctx, struct NetGroupDelUser *r) { - return NetGroupDelUser_r(ctx, r); + LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetGroupDelUser); } /**************************************************************** @@ -1304,7 +1304,7 @@ WERROR NetGroupEnum_r(struct libnetapi_ctx *ctx, WERROR NetGroupEnum_l(struct libnetapi_ctx *ctx, struct NetGroupEnum *r) { - return NetGroupEnum_r(ctx, r); + LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetGroupEnum); } /**************************************************************** @@ -1322,5 +1322,5 @@ WERROR NetGroupGetUsers_r(struct libnetapi_ctx *ctx, WERROR NetGroupGetUsers_l(struct libnetapi_ctx *ctx, struct NetGroupGetUsers *r) { - return WERR_NOT_SUPPORTED; + LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetGroupGetUsers); } diff --git a/source3/lib/netapi/localgroup.c b/source3/lib/netapi/localgroup.c index 6fe5f1cd86..811e7e8ab6 100644 --- a/source3/lib/netapi/localgroup.c +++ b/source3/lib/netapi/localgroup.c @@ -253,7 +253,7 @@ WERROR NetLocalGroupAdd_r(struct libnetapi_ctx *ctx, WERROR NetLocalGroupAdd_l(struct libnetapi_ctx *ctx, struct NetLocalGroupAdd *r) { - return NetLocalGroupAdd_r(ctx, r); + LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetLocalGroupAdd); } /**************************************************************** @@ -378,7 +378,7 @@ WERROR NetLocalGroupDel_r(struct libnetapi_ctx *ctx, WERROR NetLocalGroupDel_l(struct libnetapi_ctx *ctx, struct NetLocalGroupDel *r) { - return NetLocalGroupDel_r(ctx, r); + LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetLocalGroupDel); } /**************************************************************** @@ -562,7 +562,7 @@ WERROR NetLocalGroupGetInfo_r(struct libnetapi_ctx *ctx, WERROR NetLocalGroupGetInfo_l(struct libnetapi_ctx *ctx, struct NetLocalGroupGetInfo *r) { - return NetLocalGroupGetInfo_r(ctx, r); + LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetLocalGroupGetInfo); } /**************************************************************** @@ -745,7 +745,7 @@ WERROR NetLocalGroupSetInfo_r(struct libnetapi_ctx *ctx, WERROR NetLocalGroupSetInfo_l(struct libnetapi_ctx *ctx, struct NetLocalGroupSetInfo *r) { - return NetLocalGroupSetInfo_r(ctx, r); + LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetLocalGroupSetInfo); } /**************************************************************** @@ -945,7 +945,7 @@ WERROR NetLocalGroupEnum_r(struct libnetapi_ctx *ctx, WERROR NetLocalGroupEnum_l(struct libnetapi_ctx *ctx, struct NetLocalGroupEnum *r) { - return WERR_NOT_SUPPORTED; + LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetLocalGroupEnum); } /**************************************************************** @@ -1315,7 +1315,7 @@ WERROR NetLocalGroupAddMembers_r(struct libnetapi_ctx *ctx, WERROR NetLocalGroupAddMembers_l(struct libnetapi_ctx *ctx, struct NetLocalGroupAddMembers *r) { - return NetLocalGroupAddMembers_r(ctx, r); + LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetLocalGroupAddMembers); } /**************************************************************** @@ -1333,7 +1333,7 @@ WERROR NetLocalGroupDelMembers_r(struct libnetapi_ctx *ctx, WERROR NetLocalGroupDelMembers_l(struct libnetapi_ctx *ctx, struct NetLocalGroupDelMembers *r) { - return NetLocalGroupDelMembers_r(ctx, r); + LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetLocalGroupDelMembers); } /**************************************************************** @@ -1351,7 +1351,7 @@ WERROR NetLocalGroupGetMembers_r(struct libnetapi_ctx *ctx, WERROR NetLocalGroupGetMembers_l(struct libnetapi_ctx *ctx, struct NetLocalGroupGetMembers *r) { - return WERR_NOT_SUPPORTED; + LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetLocalGroupGetMembers); } /**************************************************************** @@ -1369,6 +1369,6 @@ WERROR NetLocalGroupSetMembers_r(struct libnetapi_ctx *ctx, WERROR NetLocalGroupSetMembers_l(struct libnetapi_ctx *ctx, struct NetLocalGroupSetMembers *r) { - return NetLocalGroupSetMembers_r(ctx, r); + LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetLocalGroupSetMembers); } diff --git a/source3/lib/netapi/netapi_private.h b/source3/lib/netapi/netapi_private.h index ef6e7cf2b7..5c60e994b1 100644 --- a/source3/lib/netapi/netapi_private.h +++ b/source3/lib/netapi/netapi_private.h @@ -20,6 +20,13 @@ #ifndef __LIB_NETAPI_PRIVATE_H__ #define __LIB_NETAPI_PRIVATE_H__ +#define LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, fn) \ + DEBUG(10,("redirecting call %s to localhost\n", #fn)); \ + if (!r->in.server_name) { \ + r->in.server_name = "localhost"; \ + } \ + return fn ## _r(ctx, r); + struct libnetapi_private_ctx { struct { const char *domain_name; diff --git a/source3/lib/netapi/serverinfo.c b/source3/lib/netapi/serverinfo.c index 622b8d425d..bd063332bf 100644 --- a/source3/lib/netapi/serverinfo.c +++ b/source3/lib/netapi/serverinfo.c @@ -252,6 +252,6 @@ WERROR NetRemoteTOD_r(struct libnetapi_ctx *ctx, WERROR NetRemoteTOD_l(struct libnetapi_ctx *ctx, struct NetRemoteTOD *r) { - return NetRemoteTOD_r(ctx, r); + LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetRemoteTOD); } diff --git a/source3/lib/netapi/user.c b/source3/lib/netapi/user.c index ff807997ae..c02dfb9dc9 100644 --- a/source3/lib/netapi/user.c +++ b/source3/lib/netapi/user.c @@ -361,12 +361,7 @@ WERROR NetUserAdd_r(struct libnetapi_ctx *ctx, WERROR NetUserAdd_l(struct libnetapi_ctx *ctx, struct NetUserAdd *r) { - /* for now just talk to local RPC server */ - if (!r->in.server_name) { - r->in.server_name = "localhost"; - } - - return NetUserAdd_r(ctx, r); + LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetUserAdd); } /**************************************************************** @@ -488,12 +483,7 @@ WERROR NetUserDel_r(struct libnetapi_ctx *ctx, WERROR NetUserDel_l(struct libnetapi_ctx *ctx, struct NetUserDel *r) { - /* for now just talk to local RPC server */ - if (!r->in.server_name) { - r->in.server_name = "localhost"; - } - - return NetUserDel_r(ctx, r); + LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetUserDel); } /**************************************************************** @@ -859,7 +849,7 @@ WERROR NetUserEnum_r(struct libnetapi_ctx *ctx, WERROR NetUserEnum_l(struct libnetapi_ctx *ctx, struct NetUserEnum *r) { - return WERR_NOT_SUPPORTED; + LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetUserEnum); } /**************************************************************** @@ -1123,7 +1113,7 @@ WERROR NetQueryDisplayInformation_r(struct libnetapi_ctx *ctx, WERROR NetQueryDisplayInformation_l(struct libnetapi_ctx *ctx, struct NetQueryDisplayInformation *r) { - return WERR_NOT_SUPPORTED; + LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetQueryDisplayInformation); } /**************************************************************** @@ -1265,7 +1255,7 @@ WERROR NetUserGetInfo_r(struct libnetapi_ctx *ctx, WERROR NetUserGetInfo_l(struct libnetapi_ctx *ctx, struct NetUserGetInfo *r) { - return WERR_NOT_SUPPORTED; + LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetUserGetInfo); } /**************************************************************** @@ -1405,7 +1395,7 @@ WERROR NetUserSetInfo_r(struct libnetapi_ctx *ctx, WERROR NetUserSetInfo_l(struct libnetapi_ctx *ctx, struct NetUserSetInfo *r) { - return WERR_NOT_SUPPORTED; + LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetUserSetInfo); } /**************************************************************** @@ -1793,7 +1783,7 @@ WERROR NetUserModalsGet_r(struct libnetapi_ctx *ctx, WERROR NetUserModalsGet_l(struct libnetapi_ctx *ctx, struct NetUserModalsGet *r) { - return NetUserModalsGet_r(ctx, r); + LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetUserModalsGet); } /**************************************************************** @@ -2275,5 +2265,5 @@ WERROR NetUserModalsSet_r(struct libnetapi_ctx *ctx, WERROR NetUserModalsSet_l(struct libnetapi_ctx *ctx, struct NetUserModalsSet *r) { - return NetUserModalsSet_r(ctx, r); + LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetUserModalsSet); } -- cgit From fcd10d26a407bef323cb8beda39a21aeb1e5b144 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 12 Aug 2008 17:59:23 +0200 Subject: netapi: make libnetapi_open_ipc_connection static. Guenther (cherry picked from commit 0259914f8ff04514a8395d8e1af61aadd50c5efb) (This used to be commit 7edc671cc1007ae216e7efdbcdb9cfa1e547dca5) --- source3/lib/netapi/cm.c | 20 +++++++--- source3/lib/netapi/getdc.c | 27 +++++--------- source3/lib/netapi/group.c | 63 +++++++++++--------------------- source3/lib/netapi/joindomain.c | 36 ++++++------------ source3/lib/netapi/localgroup.c | 58 +++++++++++------------------ source3/lib/netapi/netapi_private.h | 6 +-- source3/lib/netapi/serverinfo.c | 27 +++++--------- source3/lib/netapi/user.c | 73 +++++++++++++------------------------ 8 files changed, 114 insertions(+), 196 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/cm.c b/source3/lib/netapi/cm.c index 8ea31e54f9..a5c85bfe6b 100644 --- a/source3/lib/netapi/cm.c +++ b/source3/lib/netapi/cm.c @@ -25,9 +25,9 @@ /******************************************************************** ********************************************************************/ -WERROR libnetapi_open_ipc_connection(struct libnetapi_ctx *ctx, - const char *server_name, - struct cli_state **cli) +static WERROR libnetapi_open_ipc_connection(struct libnetapi_ctx *ctx, + const char *server_name, + struct cli_state **cli) { struct cli_state *cli_ipc = NULL; @@ -161,17 +161,25 @@ static NTSTATUS pipe_cm_open(TALLOC_CTX *ctx, ********************************************************************/ WERROR libnetapi_open_pipe(struct libnetapi_ctx *ctx, - struct cli_state *cli, + const char *server_name, const struct ndr_syntax_id *interface, + struct cli_state **pcli, struct rpc_pipe_client **presult) { struct rpc_pipe_client *result = NULL; NTSTATUS status; + WERROR werr; + struct cli_state *cli = NULL; - if (!cli || !presult) { + if (!presult) { return WERR_INVALID_PARAM; } + werr = libnetapi_open_ipc_connection(ctx, server_name, &cli); + if (!W_ERROR_IS_OK(werr)) { + return werr; + } + status = pipe_cm_open(ctx, cli, interface, &result); if (!NT_STATUS_IS_OK(status)) { libnetapi_set_error_string(ctx, "failed to open PIPE %s: %s", @@ -182,6 +190,8 @@ WERROR libnetapi_open_pipe(struct libnetapi_ctx *ctx, } *presult = result; + *pcli = cli; + return WERR_OK; } diff --git a/source3/lib/netapi/getdc.c b/source3/lib/netapi/getdc.c index 82fa35d4a1..07a6544af1 100644 --- a/source3/lib/netapi/getdc.c +++ b/source3/lib/netapi/getdc.c @@ -45,12 +45,9 @@ WERROR NetGetDCName_r(struct libnetapi_ctx *ctx, NTSTATUS status; WERROR werr; - werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - werr = libnetapi_open_pipe(ctx, cli, &ndr_table_netlogon.syntax_id, + werr = libnetapi_open_pipe(ctx, r->in.server_name, + &ndr_table_netlogon.syntax_id, + &cli, &pipe_cli); if (!W_ERROR_IS_OK(werr)) { goto done; @@ -86,12 +83,9 @@ WERROR NetGetAnyDCName_r(struct libnetapi_ctx *ctx, NTSTATUS status; WERROR werr; - werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - werr = libnetapi_open_pipe(ctx, cli, &ndr_table_netlogon.syntax_id, + werr = libnetapi_open_pipe(ctx, r->in.server_name, + &ndr_table_netlogon.syntax_id, + &cli, &pipe_cli); if (!W_ERROR_IS_OK(werr)) { goto done; @@ -146,12 +140,9 @@ WERROR DsGetDcName_r(struct libnetapi_ctx *ctx, struct cli_state *cli = NULL; struct rpc_pipe_client *pipe_cli = NULL; - werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - werr = libnetapi_open_pipe(ctx, cli, &ndr_table_netlogon.syntax_id, + werr = libnetapi_open_pipe(ctx, r->in.server_name, + &ndr_table_netlogon.syntax_id, + &cli, &pipe_cli); if (!W_ERROR_IS_OK(werr)) { goto done; diff --git a/source3/lib/netapi/group.c b/source3/lib/netapi/group.c index e057e6de02..f7c9366820 100644 --- a/source3/lib/netapi/group.c +++ b/source3/lib/netapi/group.c @@ -71,12 +71,9 @@ WERROR NetGroupAdd_r(struct libnetapi_ctx *ctx, goto done; } - werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - werr = libnetapi_open_pipe(ctx, cli, &ndr_table_samr.syntax_id, + werr = libnetapi_open_pipe(ctx, r->in.server_name, + &ndr_table_samr.syntax_id, + &cli, &pipe_cli); if (!W_ERROR_IS_OK(werr)) { goto done; @@ -251,12 +248,9 @@ WERROR NetGroupDel_r(struct libnetapi_ctx *ctx, return WERR_INVALID_PARAM; } - werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - werr = libnetapi_open_pipe(ctx, cli, &ndr_table_samr.syntax_id, + werr = libnetapi_open_pipe(ctx, r->in.server_name, + &ndr_table_samr.syntax_id, + &cli, &pipe_cli); if (!W_ERROR_IS_OK(werr)) { goto done; @@ -425,12 +419,9 @@ WERROR NetGroupSetInfo_r(struct libnetapi_ctx *ctx, return WERR_INVALID_PARAM; } - werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - werr = libnetapi_open_pipe(ctx, cli, &ndr_table_samr.syntax_id, + werr = libnetapi_open_pipe(ctx, r->in.server_name, + &ndr_table_samr.syntax_id, + &cli, &pipe_cli); if (!W_ERROR_IS_OK(werr)) { goto done; @@ -669,12 +660,9 @@ WERROR NetGroupGetInfo_r(struct libnetapi_ctx *ctx, return WERR_INVALID_PARAM; } - werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - werr = libnetapi_open_pipe(ctx, cli, &ndr_table_samr.syntax_id, + werr = libnetapi_open_pipe(ctx, r->in.server_name, + &ndr_table_samr.syntax_id, + &cli, &pipe_cli); if (!W_ERROR_IS_OK(werr)) { goto done; @@ -794,12 +782,9 @@ WERROR NetGroupAddUser_r(struct libnetapi_ctx *ctx, return WERR_INVALID_PARAM; } - werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - werr = libnetapi_open_pipe(ctx, cli, &ndr_table_samr.syntax_id, + werr = libnetapi_open_pipe(ctx, r->in.server_name, + &ndr_table_samr.syntax_id, + &cli, &pipe_cli); if (!W_ERROR_IS_OK(werr)) { goto done; @@ -924,12 +909,9 @@ WERROR NetGroupDelUser_r(struct libnetapi_ctx *ctx, return WERR_INVALID_PARAM; } - werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - werr = libnetapi_open_pipe(ctx, cli, &ndr_table_samr.syntax_id, + werr = libnetapi_open_pipe(ctx, r->in.server_name, + &ndr_table_samr.syntax_id, + &cli, &pipe_cli); if (!W_ERROR_IS_OK(werr)) { goto done; @@ -1211,12 +1193,9 @@ WERROR NetGroupEnum_r(struct libnetapi_ctx *ctx, return WERR_UNKNOWN_LEVEL; } - werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - werr = libnetapi_open_pipe(ctx, cli, &ndr_table_samr.syntax_id, + werr = libnetapi_open_pipe(ctx, r->in.server_name, + &ndr_table_samr.syntax_id, + &cli, &pipe_cli); if (!W_ERROR_IS_OK(werr)) { goto done; diff --git a/source3/lib/netapi/joindomain.c b/source3/lib/netapi/joindomain.c index 8d5202f07e..2a6fc80ca3 100644 --- a/source3/lib/netapi/joindomain.c +++ b/source3/lib/netapi/joindomain.c @@ -105,12 +105,9 @@ WERROR NetJoinDomain_r(struct libnetapi_ctx *ctx, WERROR werr; unsigned int old_timeout = 0; - werr = libnetapi_open_ipc_connection(ctx, r->in.server, &cli); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - werr = libnetapi_open_pipe(ctx, cli, &ndr_table_wkssvc.syntax_id, + werr = libnetapi_open_pipe(ctx, r->in.server, + &ndr_table_wkssvc.syntax_id, + &cli, &pipe_cli); if (!W_ERROR_IS_OK(werr)) { goto done; @@ -237,12 +234,9 @@ WERROR NetUnjoinDomain_r(struct libnetapi_ctx *ctx, WERROR werr; unsigned int old_timeout = 0; - werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - werr = libnetapi_open_pipe(ctx, cli, &ndr_table_wkssvc.syntax_id, + werr = libnetapi_open_pipe(ctx, r->in.server_name, + &ndr_table_wkssvc.syntax_id, + &cli, &pipe_cli); if (!W_ERROR_IS_OK(werr)) { goto done; @@ -290,12 +284,9 @@ WERROR NetGetJoinInformation_r(struct libnetapi_ctx *ctx, WERROR werr; const char *buffer = NULL; - werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - werr = libnetapi_open_pipe(ctx, cli, &ndr_table_wkssvc.syntax_id, + werr = libnetapi_open_pipe(ctx, r->in.server_name, + &ndr_table_wkssvc.syntax_id, + &cli, &pipe_cli); if (!W_ERROR_IS_OK(werr)) { goto done; @@ -425,12 +416,9 @@ WERROR NetGetJoinableOUs_r(struct libnetapi_ctx *ctx, NTSTATUS status; WERROR werr; - werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - werr = libnetapi_open_pipe(ctx, cli, &ndr_table_wkssvc.syntax_id, + werr = libnetapi_open_pipe(ctx, r->in.server_name, + &ndr_table_wkssvc.syntax_id, + &cli, &pipe_cli); if (!W_ERROR_IS_OK(werr)) { goto done; diff --git a/source3/lib/netapi/localgroup.c b/source3/lib/netapi/localgroup.c index 811e7e8ab6..25a3427bc1 100644 --- a/source3/lib/netapi/localgroup.c +++ b/source3/lib/netapi/localgroup.c @@ -150,12 +150,9 @@ WERROR NetLocalGroupAdd_r(struct libnetapi_ctx *ctx, ZERO_STRUCT(domain_handle); ZERO_STRUCT(alias_handle); - werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - werr = libnetapi_open_pipe(ctx, cli, &ndr_table_samr.syntax_id, + werr = libnetapi_open_pipe(ctx, r->in.server_name, + &ndr_table_samr.syntax_id, + &cli, &pipe_cli); if (!W_ERROR_IS_OK(werr)) { goto done; @@ -279,12 +276,9 @@ WERROR NetLocalGroupDel_r(struct libnetapi_ctx *ctx, ZERO_STRUCT(domain_handle); ZERO_STRUCT(alias_handle); - werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - werr = libnetapi_open_pipe(ctx, cli, &ndr_table_samr.syntax_id, + werr = libnetapi_open_pipe(ctx, r->in.server_name, + &ndr_table_samr.syntax_id, + &cli, &pipe_cli); if (!W_ERROR_IS_OK(werr)) { goto done; @@ -460,12 +454,9 @@ WERROR NetLocalGroupGetInfo_r(struct libnetapi_ctx *ctx, ZERO_STRUCT(domain_handle); ZERO_STRUCT(alias_handle); - werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - werr = libnetapi_open_pipe(ctx, cli, &ndr_table_samr.syntax_id, + werr = libnetapi_open_pipe(ctx, r->in.server_name, + &ndr_table_samr.syntax_id, + &cli, &pipe_cli); if (!W_ERROR_IS_OK(werr)) { goto done; @@ -640,12 +631,9 @@ WERROR NetLocalGroupSetInfo_r(struct libnetapi_ctx *ctx, ZERO_STRUCT(domain_handle); ZERO_STRUCT(alias_handle); - werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - werr = libnetapi_open_pipe(ctx, cli, &ndr_table_samr.syntax_id, + werr = libnetapi_open_pipe(ctx, r->in.server_name, + &ndr_table_samr.syntax_id, + &cli, &pipe_cli); if (!W_ERROR_IS_OK(werr)) { goto done; @@ -791,12 +779,9 @@ WERROR NetLocalGroupEnum_r(struct libnetapi_ctx *ctx, ZERO_STRUCT(domain_handle); ZERO_STRUCT(alias_handle); - werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - werr = libnetapi_open_pipe(ctx, cli, &ndr_table_samr.syntax_id, + werr = libnetapi_open_pipe(ctx, r->in.server_name, + &ndr_table_samr.syntax_id, + &cli, &pipe_cli); if (!W_ERROR_IS_OK(werr)) { goto done; @@ -1086,13 +1071,10 @@ static WERROR NetLocalGroupModifyMembers_r(struct libnetapi_ctx *ctx, break; } - werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - if (r->in.level == 3) { - werr = libnetapi_open_pipe(ctx, cli, &ndr_table_lsarpc.syntax_id, + werr = libnetapi_open_pipe(ctx, r->in.server_name, + &ndr_table_lsarpc.syntax_id, + &cli, &lsa_pipe); if (!W_ERROR_IS_OK(werr)) { goto done; @@ -1110,7 +1092,9 @@ static WERROR NetLocalGroupModifyMembers_r(struct libnetapi_ctx *ctx, TALLOC_FREE(lsa_pipe); } - werr = libnetapi_open_pipe(ctx, cli, &ndr_table_samr.syntax_id, + werr = libnetapi_open_pipe(ctx, r->in.server_name, + &ndr_table_samr.syntax_id, + &cli, &pipe_cli); if (!W_ERROR_IS_OK(werr)) { goto done; diff --git a/source3/lib/netapi/netapi_private.h b/source3/lib/netapi/netapi_private.h index 5c60e994b1..4d4c12ae85 100644 --- a/source3/lib/netapi/netapi_private.h +++ b/source3/lib/netapi/netapi_private.h @@ -50,13 +50,11 @@ NET_API_STATUS libnetapi_get_username(struct libnetapi_ctx *ctx, char **username NET_API_STATUS libnetapi_set_error_string(struct libnetapi_ctx *ctx, const char *format, ...); NET_API_STATUS libnetapi_get_debuglevel(struct libnetapi_ctx *ctx, char **debuglevel); -WERROR libnetapi_open_ipc_connection(struct libnetapi_ctx *ctx, - const char *server_name, - struct cli_state **cli); WERROR libnetapi_shutdown_cm(struct libnetapi_ctx *ctx); WERROR libnetapi_open_pipe(struct libnetapi_ctx *ctx, - struct cli_state *cli, + const char *server_name, const struct ndr_syntax_id *interface, + struct cli_state **pcli, struct rpc_pipe_client **presult); WERROR libnetapi_samr_open_domain(struct libnetapi_ctx *mem_ctx, struct rpc_pipe_client *pipe_cli, diff --git a/source3/lib/netapi/serverinfo.c b/source3/lib/netapi/serverinfo.c index bd063332bf..5f744bea26 100644 --- a/source3/lib/netapi/serverinfo.c +++ b/source3/lib/netapi/serverinfo.c @@ -70,12 +70,9 @@ WERROR NetServerGetInfo_r(struct libnetapi_ctx *ctx, WERROR werr; union srvsvc_NetSrvInfo info; - werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - werr = libnetapi_open_pipe(ctx, cli, &ndr_table_srvsvc.syntax_id, + werr = libnetapi_open_pipe(ctx, r->in.server_name, + &ndr_table_srvsvc.syntax_id, + &cli, &pipe_cli); if (!W_ERROR_IS_OK(werr)) { goto done; @@ -171,12 +168,9 @@ WERROR NetServerSetInfo_r(struct libnetapi_ctx *ctx, WERROR werr; union srvsvc_NetSrvInfo info; - werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - werr = libnetapi_open_pipe(ctx, cli, &ndr_table_srvsvc.syntax_id, + werr = libnetapi_open_pipe(ctx, r->in.server_name, + &ndr_table_srvsvc.syntax_id, + &cli, &pipe_cli); if (!W_ERROR_IS_OK(werr)) { goto done; @@ -218,12 +212,9 @@ WERROR NetRemoteTOD_r(struct libnetapi_ctx *ctx, WERROR werr; struct srvsvc_NetRemoteTODInfo *info = NULL; - werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - werr = libnetapi_open_pipe(ctx, cli, &ndr_table_srvsvc.syntax_id, + werr = libnetapi_open_pipe(ctx, r->in.server_name, + &ndr_table_srvsvc.syntax_id, + &cli, &pipe_cli); if (!W_ERROR_IS_OK(werr)) { goto done; diff --git a/source3/lib/netapi/user.c b/source3/lib/netapi/user.c index c02dfb9dc9..7b530f4308 100644 --- a/source3/lib/netapi/user.c +++ b/source3/lib/netapi/user.c @@ -214,12 +214,9 @@ WERROR NetUserAdd_r(struct libnetapi_ctx *ctx, goto done; } - werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - werr = libnetapi_open_pipe(ctx, cli, &ndr_table_samr.syntax_id, + werr = libnetapi_open_pipe(ctx, r->in.server_name, + &ndr_table_samr.syntax_id, + &cli, &pipe_cli); if (!W_ERROR_IS_OK(werr)) { goto done; @@ -385,13 +382,11 @@ WERROR NetUserDel_r(struct libnetapi_ctx *ctx, ZERO_STRUCT(domain_handle); ZERO_STRUCT(user_handle); - werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - werr = libnetapi_open_pipe(ctx, cli, &ndr_table_samr.syntax_id, + werr = libnetapi_open_pipe(ctx, r->in.server_name, + &ndr_table_samr.syntax_id, + &cli, &pipe_cli); + if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -751,12 +746,9 @@ WERROR NetUserEnum_r(struct libnetapi_ctx *ctx, return WERR_NOT_SUPPORTED; } - werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - werr = libnetapi_open_pipe(ctx, cli, &ndr_table_samr.syntax_id, + werr = libnetapi_open_pipe(ctx, r->in.server_name, + &ndr_table_samr.syntax_id, + &cli, &pipe_cli); if (!W_ERROR_IS_OK(werr)) { goto done; @@ -1044,12 +1036,9 @@ WERROR NetQueryDisplayInformation_r(struct libnetapi_ctx *ctx, return WERR_UNKNOWN_LEVEL; } - werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - werr = libnetapi_open_pipe(ctx, cli, &ndr_table_samr.syntax_id, + werr = libnetapi_open_pipe(ctx, r->in.server_name, + &ndr_table_samr.syntax_id, + &cli, &pipe_cli); if (!W_ERROR_IS_OK(werr)) { goto done; @@ -1172,12 +1161,9 @@ WERROR NetUserGetInfo_r(struct libnetapi_ctx *ctx, goto done; } - werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - werr = libnetapi_open_pipe(ctx, cli, &ndr_table_samr.syntax_id, + werr = libnetapi_open_pipe(ctx, r->in.server_name, + &ndr_table_samr.syntax_id, + &cli, &pipe_cli); if (!W_ERROR_IS_OK(werr)) { goto done; @@ -1295,12 +1281,9 @@ WERROR NetUserSetInfo_r(struct libnetapi_ctx *ctx, goto done; } - werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - werr = libnetapi_open_pipe(ctx, cli, &ndr_table_samr.syntax_id, + werr = libnetapi_open_pipe(ctx, r->in.server_name, + &ndr_table_samr.syntax_id, + &cli, &pipe_cli); if (!W_ERROR_IS_OK(werr)) { goto done; @@ -1726,12 +1709,9 @@ WERROR NetUserModalsGet_r(struct libnetapi_ctx *ctx, goto done; } - werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - werr = libnetapi_open_pipe(ctx, cli, &ndr_table_samr.syntax_id, + werr = libnetapi_open_pipe(ctx, r->in.server_name, + &ndr_table_samr.syntax_id, + &cli, &pipe_cli); if (!W_ERROR_IS_OK(werr)) { goto done; @@ -2213,12 +2193,9 @@ WERROR NetUserModalsSet_r(struct libnetapi_ctx *ctx, goto done; } - werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli); - if (!W_ERROR_IS_OK(werr)) { - goto done; - } - - werr = libnetapi_open_pipe(ctx, cli, &ndr_table_samr.syntax_id, + werr = libnetapi_open_pipe(ctx, r->in.server_name, + &ndr_table_samr.syntax_id, + &cli, &pipe_cli); if (!W_ERROR_IS_OK(werr)) { goto done; -- cgit From 214e6e7d72deb3a6c95bcd4cbaed0562c6b68110 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 12 Aug 2008 19:39:38 +0200 Subject: netapi: add doxygen documentation for NetLocalGroup{Add,Del,Set,Get}Members. Guenther (cherry picked from commit eee28804b7efc3089ce3528f13de6c930cf00adb) (This used to be commit b725852502d45b568c80eb3c323861b89928983d) --- source3/lib/netapi/netapi.h | 75 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h index 5f9cff97db..e3cec7dc58 100644 --- a/source3/lib/netapi/netapi.h +++ b/source3/lib/netapi/netapi.h @@ -1165,16 +1165,73 @@ NET_API_STATUS NetLocalGroupEnum(const char * server_name /* [in] */, uint32_t *total_entries /* [out] [ref] */, uint32_t *resume_handle /* [in,out] [ref] */); +/************************************************************//** + * + * NetLocalGroupAddMembers + * + * @brief Add Members to a Local Group + * + * @param[in] server_name The server name to connect to + * @param[in] group_name The name of the group that is going to modified + * @param[in] level The level defining the LOCALGROUP_MEMBERS_INFO_X structure + * @param[in] buffer The buffer containing a LOCALGROUP_MEMBERS_INFO_X structure + * @param[in] total_entries The number of LOCALGROUP_MEMBERS_INFO_X entries in + * the buffer + * @return NET_API_STATUS + * + * example localgroup/localgroup_addmembers.c + ***************************************************************/ + NET_API_STATUS NetLocalGroupAddMembers(const char * server_name /* [in] */, const char * group_name /* [in] */, uint32_t level /* [in] */, uint8_t *buffer /* [in] [ref] */, uint32_t total_entries /* [in] */); + +/************************************************************//** + * + * NetLocalGroupDelMembers + * + * @brief Delete Members from a Local Group + * + * @param[in] server_name The server name to connect to + * @param[in] group_name The name of the group that is going to modified + * @param[in] level The level defining the LOCALGROUP_MEMBERS_INFO_X structure + * @param[in] buffer The buffer containing a LOCALGROUP_MEMBERS_INFO_X structure + * @param[in] total_entries The number of LOCALGROUP_MEMBERS_INFO_X entries in + * the buffer + * @return NET_API_STATUS + * + * example localgroup/localgroup_delmembers.c + ***************************************************************/ + NET_API_STATUS NetLocalGroupDelMembers(const char * server_name /* [in] */, const char * group_name /* [in] */, uint32_t level /* [in] */, uint8_t *buffer /* [in] [ref] */, uint32_t total_entries /* [in] */); + +/************************************************************//** + * + * NetLocalGroupGetMembers + * + * @brief Enumerate Members in a local group + * + * @param[in] server_name The server name to connect to + * @param[in] local_group_name The localgroup that is going to be queried + * @param[in] level The level defining the LOCALGROUP_MEMBERS_INFO_X structure + * @param[out] buffer The buffer containing a LOCALGROUP_MEMBERS_INFO_X + * structure + * @param[in] prefmaxlen The requested maximal buffer size + * @param[out] entries_read The number of LOCALGROUP_MEMBERS_INFO_X entries in the buffer + * @param[out] total_entries The total number of LOCALGROUP_MEMBERS_INFO_X entries for that group + * @param[in,out] resume_handle A handle passed in and returned for resuming + * operations + * @return NET_API_STATUS + * + * example localgroup/localgroup_getmembers.c + ***************************************************************/ + NET_API_STATUS NetLocalGroupGetMembers(const char * server_name /* [in] */, const char * local_group_name /* [in] */, uint32_t level /* [in] */, @@ -1183,6 +1240,24 @@ NET_API_STATUS NetLocalGroupGetMembers(const char * server_name /* [in] */, uint32_t *entries_read /* [out] [ref] */, uint32_t *total_entries /* [out] [ref] */, uint32_t *resume_handle /* [in,out] [ref] */); + +/************************************************************//** + * + * NetLocalGroupSetMembers + * + * @brief Set Members in a Local Group + * + * @param[in] server_name The server name to connect to + * @param[in] group_name The name of the group that is going to modified + * @param[in] level The level defining the LOCALGROUP_MEMBERS_INFO_X structure + * @param[in] buffer The buffer containing a LOCALGROUP_MEMBERS_INFO_X structure + * @param[in] total_entries The number of LOCALGROUP_MEMBERS_INFO_X entries in + * the buffer + * @return NET_API_STATUS + * + * example localgroup/localgroup_setmembers.c + ***************************************************************/ + NET_API_STATUS NetLocalGroupSetMembers(const char * server_name /* [in] */, const char * group_name /* [in] */, uint32_t level /* [in] */, -- cgit From 2b89fc16ccdc486a94d9a77d2356a89e34dbf7d9 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 12 Aug 2008 19:47:37 +0200 Subject: netapi: add doxygen documentation for NetUserModalsGet and NetUserModalsSet. Guenther (cherry picked from commit 93210f04c3b1e4fe977a395531ddc0387a65dab5) (This used to be commit ab1b214ba0bebfebf0685f9c05fdcf6eb141adb9) --- source3/lib/netapi/netapi.h | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h index e3cec7dc58..270c76dca8 100644 --- a/source3/lib/netapi/netapi.h +++ b/source3/lib/netapi/netapi.h @@ -850,9 +850,39 @@ NET_API_STATUS NetUserSetInfo(const char * server_name /* [in] */, uint8_t *buffer /* [in] [ref] */, uint32_t *parm_err /* [out] [ref] */); +/************************************************************//** + * + * NetUserModalsGet + * + * @brief Get SAM domain and password information + * + * @param[in] server_name The server name to connect to + * @param[in] level The level defining which USER_MODALS_INFO_X buffer to query + * @param[out] buffer The returned USER_MODALS_INFO_X buffer + * @return NET_API_STATUS + * + * example user/user_modalsget.c + ***************************************************************/ + NET_API_STATUS NetUserModalsGet(const char * server_name /* [in] */, uint32_t level /* [in] */, uint8_t **buffer /* [out] [ref] */); + +/************************************************************//** + * + * NetUserModalsSet + * + * @brief Set SAM domain and password information + * + * @param[in] server_name The server name to connect to + * @param[in] level The level defining which USER_MODALS_INFO_X buffer to query + * @param[out] buffer The buffer conntaing a USER_MODALS_INFO_X structure + * @param[out] parm_err The returned parameter error number if any + * @return NET_API_STATUS + * + * example user/user_modalsset.c + ***************************************************************/ + NET_API_STATUS NetUserModalsSet(const char * server_name /* [in] */, uint32_t level /* [in] */, uint8_t *buffer /* [in] [ref] */, -- cgit From 06ad4dc625a91b0d94fce5f45349b68f093d7c9a Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 13 Aug 2008 13:59:08 +0200 Subject: netapi: add some remaining documentation fixes. Guenther (cherry picked from commit 4a4e90a3872d34791de43c3849c60e2f4e713d47) (This used to be commit c542307b7484df4adb9269f4bb99fa55d5dc48b8) --- source3/lib/netapi/netapi.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h index 270c76dca8..f7bf1880cc 100644 --- a/source3/lib/netapi/netapi.h +++ b/source3/lib/netapi/netapi.h @@ -511,7 +511,7 @@ NET_API_STATUS NetApiBufferFree(void *buffer); * @brief Convert a domain sid into a string * * @param[in] sid A pointer to a sid structure - * @param[in] sid_string A pointer that holds a pointer to a sid string. Caller + * @param[in,out] sid_string A pointer that holds a pointer to a sid string. Caller * needs to free with free(3) * @return bool ***************************************************************/ @@ -526,7 +526,7 @@ int ConvertSidToStringSid(const struct domsid *sid, * @brief Convert a string into a domain sid * * @param[in] sid_string A pointer to a sid string. - * @param[in] sid A pointer that holds a pointer to a sid structure. + * @param[in,out] sid A pointer that holds a pointer to a sid structure. * Caller needs to free with free(3) * @return bool ***************************************************************/ @@ -837,7 +837,7 @@ NET_API_STATUS NetUserGetInfo(const char * server_name /* [in] */, * @param[in] server_name The server name to connect to * @param[in] user_name The name of the user that is going to be modified * @param[in] level The level defining the requested USER_INFO_X structure - * @param[in] buf The buffer containing a USER_INFO_X structure + * @param[in] buffer The buffer containing a USER_INFO_X structure * @param[out] parm_err The returned parameter error number if any * @return NET_API_STATUS * -- cgit From 2e8b0006b181944eda8694d03d8cb36eb561341e Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 26 Aug 2008 21:12:23 +0200 Subject: netapi: add all USER_INFO structs to public header. Guenther (This used to be commit d19c06d7d055e4b1e8e47cc2df1a192a0a19eb14) --- source3/lib/netapi/netapi.h | 108 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h index f7bf1880cc..71873b7656 100644 --- a/source3/lib/netapi/netapi.h +++ b/source3/lib/netapi/netapi.h @@ -228,6 +228,37 @@ struct USER_INFO_20 { uint32_t usri20_user_id; }; +struct USER_INFO_21 { + uint8_t *usri21_password; +}; + +struct USER_INFO_22 { + const char * usri22_name; + uint8_t *usri22_password; + uint32_t usri22_password_age; + uint32_t usri22_priv; + const char * usri22_home_dir; + const char * usri22_comment; + uint32_t usri22_flags; + uint32_t usri22_script_path; + uint32_t usri22_auth_flags; + const char * usri22_full_name; + const char * usri22_usr_comment; + const char * usri22_parms; + const char * usri22_workstations; + uint32_t usri22_last_logon; + uint32_t usri22_last_logoff; + uint32_t usri22_acct_expires; + uint32_t usri22_max_storage; + uint32_t usri22_units_per_week; + uint8_t *usri22_logon_hours;/* [unique] */ + uint32_t usri22_bad_pw_count; + uint32_t usri22_num_logons; + const char * usri22_logon_server; + uint32_t usri22_country_code; + uint32_t usri22_code_page; +}; + struct USER_INFO_23 { const char * usri23_name; const char * usri23_full_name; @@ -236,10 +267,87 @@ struct USER_INFO_23 { struct domsid *usri23_user_sid;/* [unique] */ }; +struct USER_INFO_1003 { + const char * usri1003_password; +}; + +struct USER_INFO_1005 { + uint32_t usri1005_priv; +}; + +struct USER_INFO_1006 { + const char * usri1006_home_dir; +}; + struct USER_INFO_1007 { const char * usri1007_comment; }; +struct USER_INFO_1008 { + uint32_t usri1008_flags; +}; + +struct USER_INFO_1009 { + const char * usri1009_script_path; +}; + +struct USER_INFO_1010 { + uint32_t usri1010_auth_flags; +}; + +struct USER_INFO_1011 { + const char * usri1011_full_name; +}; + +struct USER_INFO_1012 { + const char * usri1012_usr_comment; +}; + +struct USER_INFO_1013 { + const char * usri1013_parms; +}; + +struct USER_INFO_1014 { + const char * usri1014_workstations; +}; + +struct USER_INFO_1017 { + uint32_t usri1017_acct_expires; +}; + +struct USER_INFO_1018 { + uint32_t usri1018_max_storage; +}; + +struct USER_INFO_1020 { + uint32_t usri1020_units_per_week; + uint8_t *usri1020_logon_hours;/* [unique] */ +}; + +struct USER_INFO_1023 { + const char * usri1023_logon_server; +}; + +struct USER_INFO_1024 { + uint32_t usri1024_country_code; +}; + +struct USER_INFO_1025 { + uint32_t usri1025_code_page; +}; + +struct USER_INFO_1051 { + uint32_t usri1051_primary_group_id; +}; + +struct USER_INFO_1052 { + const char * usri1052_profile; +}; + +struct USER_INFO_1053 { + const char * usri1053_home_dir_drive; +}; + struct USER_MODALS_INFO_0 { uint32_t usrmod0_min_passwd_len; uint32_t usrmod0_max_passwd_age; -- cgit From ab6fc34ebc20ff2d3eb60393b066feeb35230b9b Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 27 Aug 2008 00:30:51 +0200 Subject: netapi: add ENCRYPTED_PWLEN to public header. Guenther (This used to be commit 7010230c4af667b4197c9bd58685dc5a0b2b7c4f) --- source3/lib/netapi/netapi.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h index 71873b7656..4882ada893 100644 --- a/source3/lib/netapi/netapi.h +++ b/source3/lib/netapi/netapi.h @@ -33,6 +33,8 @@ typedef enum { #define ERROR_MORE_DATA ( 234L ) +#define ENCRYPTED_PWLEN ( 16 ) + /**************************************************************** ****************************************************************/ -- cgit From 220e01e5e04a11c3d11f3f9133ee9c3f4e9a79dd Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 27 Aug 2008 00:31:20 +0200 Subject: netapi: add more infolevels to NetUserSetInfo example. Guenther (This used to be commit 5ad217be7a12211a8340052f7f4481cf2f239f8d) --- source3/lib/netapi/examples/user/user_setinfo.c | 122 ++++++++++++++++++++++-- 1 file changed, 116 insertions(+), 6 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/user/user_setinfo.c b/source3/lib/netapi/examples/user/user_setinfo.c index ec464232e9..4f02ae7781 100644 --- a/source3/lib/netapi/examples/user/user_setinfo.c +++ b/source3/lib/netapi/examples/user/user_setinfo.c @@ -33,10 +33,34 @@ int main(int argc, const char **argv) struct libnetapi_ctx *ctx = NULL; const char *hostname = NULL; const char *username = NULL; - uint32_t level = 1007; + uint32_t level = 0; uint32_t parm_err = 0; - + uint8_t *buffer = NULL; + const char *val = NULL; + + struct USER_INFO_0 u0; + struct USER_INFO_1 u1; + struct USER_INFO_2 u2; + struct USER_INFO_3 u3; + struct USER_INFO_4 u4; + struct USER_INFO_21 u21; + struct USER_INFO_22 u22; + struct USER_INFO_1003 u1003; + struct USER_INFO_1005 u1005; + struct USER_INFO_1006 u1006; struct USER_INFO_1007 u1007; + struct USER_INFO_1008 u1008; + struct USER_INFO_1009 u1009; + struct USER_INFO_1010 u1010; + struct USER_INFO_1011 u1011; + struct USER_INFO_1012 u1012; + struct USER_INFO_1014 u1014; + struct USER_INFO_1017 u1017; + struct USER_INFO_1020 u1020; + struct USER_INFO_1024 u1024; + struct USER_INFO_1051 u1051; + struct USER_INFO_1052 u1052; + struct USER_INFO_1053 u1053; poptContext pc; int opt; @@ -70,18 +94,104 @@ int main(int argc, const char **argv) } username = poptGetArg(pc); - if (poptPeekArg(pc)) { - level = atoi(poptGetArg(pc)); + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + level = atoi(poptGetArg(pc)); + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; } + val = poptGetArg(pc); /* NetUserSetInfo */ - u1007.usri1007_comment = "NetApi test comment"; + switch (level) { + case 0: + u0.usri0_name = val; + buffer = (uint8_t *)&u0; + break; + case 1: + case 2: + case 3: + case 4: + break; + case 21: + break; + case 22: + break; + case 1003: + u1003.usri1003_password = val; + buffer = (uint8_t *)&u1003; + break; + case 1005: + u1005.usri1005_priv = atoi(val); + buffer = (uint8_t *)&u1005; + break; + case 1006: + u1006.usri1006_home_dir = val; + buffer = (uint8_t *)&u1006; + break; + case 1007: + u1007.usri1007_comment = val; + buffer = (uint8_t *)&u1007; + break; + case 1008: + u1008.usri1008_flags = atoi(val); + buffer = (uint8_t *)&u1008; + break; + case 1009: + u1009.usri1009_script_path = val; + buffer = (uint8_t *)&u1009; + break; + case 1010: + u1010.usri1010_auth_flags = atoi(val); + buffer = (uint8_t *)&u1010; + break; + case 1011: + u1011.usri1011_full_name = val; + buffer = (uint8_t *)&u1011; + break; + case 1012: + u1012.usri1012_usr_comment = val; + buffer = (uint8_t *)&u1012; + break; + case 1014: + u1014.usri1014_workstations = val; + buffer = (uint8_t *)&u1014; + break; + case 1017: + u1017.usri1017_acct_expires = atoi(val); + buffer = (uint8_t *)&u1017; + break; + case 1020: + break; + case 1024: + u1024.usri1024_country_code = atoi(val); + buffer = (uint8_t *)&u1024; + break; + case 1051: + u1051.usri1051_primary_group_id = atoi(val); + buffer = (uint8_t *)&u1051; + break; + case 1052: + u1052.usri1052_profile = val; + buffer = (uint8_t *)&u1052; + break; + case 1053: + u1053.usri1053_home_dir_drive = val; + buffer = (uint8_t *)&u1053; + break; + default: + break; + } status = NetUserSetInfo(hostname, username, level, - (uint8_t *)&u1007, + buffer, &parm_err); if (status != 0) { printf("NetUserSetInfo failed with: %s\n", -- cgit From 64d06eadb762948b2361f66f41c2995804060190 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 27 Aug 2008 00:32:08 +0200 Subject: netapi: make set_user_info_USER_INFO_X a separate function. Guenther (This used to be commit 529dd675bde3ac944ca69e4dbe2fc4beeeb9aab8) --- source3/lib/netapi/user.c | 106 ++++++++++++++++++++++++++++------------------ 1 file changed, 64 insertions(+), 42 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/user.c b/source3/lib/netapi/user.c index 7b530f4308..608c1a1d8d 100644 --- a/source3/lib/netapi/user.c +++ b/source3/lib/netapi/user.c @@ -178,6 +178,66 @@ static NTSTATUS construct_USER_INFO_X(uint32_t level, /**************************************************************** ****************************************************************/ +static NTSTATUS set_user_info_USER_INFO_X(TALLOC_CTX *ctx, + struct rpc_pipe_client *pipe_cli, + DATA_BLOB *session_key, + struct policy_handle *user_handle, + struct USER_INFO_X *uX) +{ + union samr_UserInfo user_info; + struct samr_UserInfo21 info21; + NTSTATUS status; + + if (!uX) { + return NT_STATUS_INVALID_PARAMETER; + } + + convert_USER_INFO_X_to_samr_user_info21(uX, &info21); + + ZERO_STRUCT(user_info); + + if (uX->usriX_password) { + + user_info.info25.info = info21; + + init_samr_CryptPasswordEx(uX->usriX_password, + session_key, + &user_info.info25.password); + + status = rpccli_samr_SetUserInfo2(pipe_cli, ctx, + user_handle, + 25, + &user_info); + + if (NT_STATUS_EQUAL(status, NT_STATUS(DCERPC_FAULT_INVALID_TAG))) { + + user_info.info23.info = info21; + + init_samr_CryptPassword(uX->usriX_password, + session_key, + &user_info.info23.password); + + status = rpccli_samr_SetUserInfo2(pipe_cli, ctx, + user_handle, + 23, + &user_info); + } + } else { + + user_info.info21 = info21; + + status = rpccli_samr_SetUserInfo(pipe_cli, ctx, + user_handle, + 21, + &user_info); + } + + return status; +} + +/**************************************************************** +****************************************************************/ + WERROR NetUserAdd_r(struct libnetapi_ctx *ctx, struct NetUserAdd *r) { @@ -188,7 +248,6 @@ WERROR NetUserAdd_r(struct libnetapi_ctx *ctx, POLICY_HND connect_handle, domain_handle, user_handle; struct lsa_String lsa_account_name; struct dom_sid2 *domain_sid = NULL; - struct samr_UserInfo21 info21; union samr_UserInfo *user_info = NULL; struct samr_PwInfo pw_info; uint32_t access_granted = 0; @@ -282,47 +341,10 @@ WERROR NetUserAdd_r(struct libnetapi_ctx *ctx, goto done; } - convert_USER_INFO_X_to_samr_user_info21(&uX, - &info21); - - ZERO_STRUCTP(user_info); - - if (uX.usriX_password) { - - user_info->info25.info = info21; - - init_samr_CryptPasswordEx(uX.usriX_password, - &cli->user_session_key, - &user_info->info25.password); - - status = rpccli_samr_SetUserInfo2(pipe_cli, ctx, - &user_handle, - 25, - user_info); - - if (NT_STATUS_EQUAL(status, NT_STATUS(DCERPC_FAULT_INVALID_TAG))) { - - user_info->info23.info = info21; - - init_samr_CryptPassword(uX.usriX_password, - &cli->user_session_key, - &user_info->info23.password); - - status = rpccli_samr_SetUserInfo2(pipe_cli, ctx, - &user_handle, - 23, - user_info); - } - } else { - - user_info->info21 = info21; - - status = rpccli_samr_SetUserInfo(pipe_cli, ctx, - &user_handle, - 21, - user_info); - - } + status = set_user_info_USER_INFO_X(ctx, pipe_cli, + &cli->user_session_key, + &user_handle, + &uX); if (!NT_STATUS_IS_OK(status)) { werr = ntstatus_to_werror(status); goto failed; -- cgit From 870944ca970f2b9484f0a36575b76f3eaeed66ee Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 27 Aug 2008 00:33:16 +0200 Subject: netapi: process level 1003 in construct_USER_INFO_X as well. Guenther (This used to be commit cf381b9f08cae32b62d7bd6f7dfe5210e732eeb2) --- source3/lib/netapi/user.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/user.c b/source3/lib/netapi/user.c index 608c1a1d8d..97eb9d8002 100644 --- a/source3/lib/netapi/user.c +++ b/source3/lib/netapi/user.c @@ -111,6 +111,7 @@ static NTSTATUS construct_USER_INFO_X(uint32_t level, struct USER_INFO_0 *u0 = NULL; struct USER_INFO_1 *u1 = NULL; struct USER_INFO_2 *u2 = NULL; + struct USER_INFO_1003 *u1003 = NULL; struct USER_INFO_1007 *u1007 = NULL; if (!buffer || !uX) { @@ -162,6 +163,10 @@ static NTSTATUS construct_USER_INFO_X(uint32_t level, uX->usriX_country_code = u2->usri2_country_code; uX->usriX_code_page = u2->usri2_code_page; break; + case 1003: + u1003 = (struct USER_INFO_1003 *)buffer; + uX->usriX_password = u1003->usri1003_password; + break; case 1007: u1007 = (struct USER_INFO_1007 *)buffer; uX->usriX_comment = u1007->usri1007_comment; -- cgit From a5fc8ee45736b39def94a2192a9b7899e60af205 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 27 Aug 2008 00:33:49 +0200 Subject: netapi: support level 1003 in NetUserSetInfo. Guenther (This used to be commit 863827eb2d5210350011055dda4319070bd1c520) --- source3/lib/netapi/user.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/user.c b/source3/lib/netapi/user.c index 97eb9d8002..045491c541 100644 --- a/source3/lib/netapi/user.c +++ b/source3/lib/netapi/user.c @@ -1286,7 +1286,7 @@ WERROR NetUserSetInfo_r(struct libnetapi_ctx *ctx, struct lsa_String lsa_account_name; struct dom_sid2 *domain_sid = NULL; struct samr_Ids user_rids, name_types; - union samr_UserInfo user_info; + uint32_t user_mask = 0; struct USER_INFO_X uX; @@ -1301,7 +1301,11 @@ WERROR NetUserSetInfo_r(struct libnetapi_ctx *ctx, switch (r->in.level) { case 0: + case 1003: + user_mask = SAMR_USER_ACCESS_SET_PASSWORD; + break; case 1007: + user_mask = SAMR_USER_ACCESS_SET_ATTRIBUTES; break; default: werr = WERR_NOT_SUPPORTED; @@ -1354,7 +1358,7 @@ WERROR NetUserSetInfo_r(struct libnetapi_ctx *ctx, status = rpccli_samr_OpenUser(pipe_cli, ctx, &domain_handle, - SAMR_USER_ACCESS_SET_ATTRIBUTES, + user_mask, user_rids.ids[0], &user_handle); if (!NT_STATUS_IS_OK(status)) { @@ -1368,12 +1372,10 @@ WERROR NetUserSetInfo_r(struct libnetapi_ctx *ctx, goto done; } - convert_USER_INFO_X_to_samr_user_info21(&uX, &user_info.info21); - - status = rpccli_samr_SetUserInfo(pipe_cli, ctx, - &user_handle, - 21, - &user_info); + status = set_user_info_USER_INFO_X(ctx, pipe_cli, + &cli->user_session_key, + &user_handle, + &uX); if (!NT_STATUS_IS_OK(status)) { werr = ntstatus_to_werror(status); goto done; -- cgit From 41fa94363fe1e22b4b7fc3360e9b130607b1dc12 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 27 Aug 2008 00:57:07 +0200 Subject: netapi: fix convert_USER_INFO_X_to_samr_user_info21. Guenther (This used to be commit 3f726952eb9a1fed0f4a990c82a2c47a5c0775be) --- source3/lib/netapi/user.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/user.c b/source3/lib/netapi/user.c index 045491c541..d70a790b81 100644 --- a/source3/lib/netapi/user.c +++ b/source3/lib/netapi/user.c @@ -41,7 +41,7 @@ static void convert_USER_INFO_X_to_samr_user_info21(struct USER_INFO_X *infoX, ZERO_STRUCT(zero_parameters); if (infoX->usriX_name) { - fields_present |= SAMR_FIELD_FULL_NAME; + fields_present |= SAMR_FIELD_ACCOUNT_NAME; } if (infoX->usriX_password) { fields_present |= SAMR_FIELD_PASSWORD; @@ -77,8 +77,8 @@ static void convert_USER_INFO_X_to_samr_user_info21(struct USER_INFO_X *infoX, 0, 0, password_age, - NULL, infoX->usriX_name, + NULL, infoX->usriX_home_dir, NULL, infoX->usriX_script_path, -- cgit From fac81ffb42245d274e5f44cacf9e1d5b245f7516 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 27 Aug 2008 01:04:21 +0200 Subject: netapi: support level 1011 in NetUserSetInfo. Guenther (This used to be commit b3680c0482ae05b32e9cf9fbddea57f0dd6e2bd3) --- source3/lib/netapi/user.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/user.c b/source3/lib/netapi/user.c index d70a790b81..6737012ed0 100644 --- a/source3/lib/netapi/user.c +++ b/source3/lib/netapi/user.c @@ -64,6 +64,9 @@ static void convert_USER_INFO_X_to_samr_user_info21(struct USER_INFO_X *infoX, if (infoX->usriX_password_age) { fields_present |= SAMR_FIELD_FORCE_PWD_CHANGE; } + if (infoX->usriX_full_name) { + fields_present |= SAMR_FIELD_FULL_NAME; + } acct_flags |= infoX->usriX_flags | ACB_NORMAL; @@ -78,7 +81,7 @@ static void convert_USER_INFO_X_to_samr_user_info21(struct USER_INFO_X *infoX, 0, password_age, infoX->usriX_name, - NULL, + infoX->usriX_full_name, infoX->usriX_home_dir, NULL, infoX->usriX_script_path, @@ -113,6 +116,7 @@ static NTSTATUS construct_USER_INFO_X(uint32_t level, struct USER_INFO_2 *u2 = NULL; struct USER_INFO_1003 *u1003 = NULL; struct USER_INFO_1007 *u1007 = NULL; + struct USER_INFO_1011 *u1011 = NULL; if (!buffer || !uX) { return NT_STATUS_INVALID_PARAMETER; @@ -171,6 +175,10 @@ static NTSTATUS construct_USER_INFO_X(uint32_t level, u1007 = (struct USER_INFO_1007 *)buffer; uX->usriX_comment = u1007->usri1007_comment; break; + case 1011: + u1011 = (struct USER_INFO_1011 *)buffer; + uX->usriX_full_name = u1011->usri1011_full_name; + break; case 3: case 4: default: @@ -1305,6 +1313,7 @@ WERROR NetUserSetInfo_r(struct libnetapi_ctx *ctx, user_mask = SAMR_USER_ACCESS_SET_PASSWORD; break; case 1007: + case 1011: user_mask = SAMR_USER_ACCESS_SET_ATTRIBUTES; break; default: -- cgit From bd450a7c3a0cd20a940ce631fdb2a7724c0cdd68 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 27 Aug 2008 01:15:21 +0200 Subject: netapi: support level 1009 in NetUserSetInfo. Guenther (This used to be commit 3a6c784284c8eb7e2b05afa6db16b27ee26ff352) --- source3/lib/netapi/user.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/user.c b/source3/lib/netapi/user.c index 6737012ed0..70bb353317 100644 --- a/source3/lib/netapi/user.c +++ b/source3/lib/netapi/user.c @@ -116,6 +116,7 @@ static NTSTATUS construct_USER_INFO_X(uint32_t level, struct USER_INFO_2 *u2 = NULL; struct USER_INFO_1003 *u1003 = NULL; struct USER_INFO_1007 *u1007 = NULL; + struct USER_INFO_1009 *u1009 = NULL; struct USER_INFO_1011 *u1011 = NULL; if (!buffer || !uX) { @@ -175,6 +176,10 @@ static NTSTATUS construct_USER_INFO_X(uint32_t level, u1007 = (struct USER_INFO_1007 *)buffer; uX->usriX_comment = u1007->usri1007_comment; break; + case 1009: + u1009 = (struct USER_INFO_1009 *)buffer; + uX->usriX_script_path = u1009->usri1009_script_path; + break; case 1011: u1011 = (struct USER_INFO_1011 *)buffer; uX->usriX_full_name = u1011->usri1011_full_name; @@ -1313,6 +1318,7 @@ WERROR NetUserSetInfo_r(struct libnetapi_ctx *ctx, user_mask = SAMR_USER_ACCESS_SET_PASSWORD; break; case 1007: + case 1009: case 1011: user_mask = SAMR_USER_ACCESS_SET_ATTRIBUTES; break; -- cgit From f1ce72a80bb48210c2fbdc62a93578a6b5c4b5b6 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 27 Aug 2008 01:36:06 +0200 Subject: netapi: fix acct_flags handling in convert_USER_INFO_X_to_samr_user_info21. Guenther (This used to be commit d3625b321f666bd506603b7c58ee89cd6b902d86) --- source3/lib/netapi/user.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/user.c b/source3/lib/netapi/user.c index 70bb353317..8fa0710dc1 100644 --- a/source3/lib/netapi/user.c +++ b/source3/lib/netapi/user.c @@ -30,16 +30,18 @@ static void convert_USER_INFO_X_to_samr_user_info21(struct USER_INFO_X *infoX, struct samr_UserInfo21 *info21) { - uint32_t fields_present = SAMR_FIELD_ACCT_FLAGS; + uint32_t fields_present = 0; struct samr_LogonHours zero_logon_hours; struct lsa_BinaryString zero_parameters; - uint32_t acct_flags = 0; NTTIME password_age; ZERO_STRUCTP(info21); ZERO_STRUCT(zero_logon_hours); ZERO_STRUCT(zero_parameters); + if (infoX->usriX_flags) { + fields_present |= SAMR_FIELD_ACCT_FLAGS; + } if (infoX->usriX_name) { fields_present |= SAMR_FIELD_ACCOUNT_NAME; } @@ -68,8 +70,6 @@ static void convert_USER_INFO_X_to_samr_user_info21(struct USER_INFO_X *infoX, fields_present |= SAMR_FIELD_FULL_NAME; } - acct_flags |= infoX->usriX_flags | ACB_NORMAL; - unix_to_nt_time_abs(&password_age, infoX->usriX_password_age); /* TODO: infoX->usriX_priv */ @@ -92,7 +92,7 @@ static void convert_USER_INFO_X_to_samr_user_info21(struct USER_INFO_X *infoX, &zero_parameters, 0, 0, - acct_flags, + infoX->usriX_flags, fields_present, zero_logon_hours, 0, @@ -359,6 +359,8 @@ WERROR NetUserAdd_r(struct libnetapi_ctx *ctx, goto done; } + uX.usriX_flags |= ACB_NORMAL; + status = set_user_info_USER_INFO_X(ctx, pipe_cli, &cli->user_session_key, &user_handle, -- cgit From 3029122f5e20671de5c440962c2a3aee3f661674 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 27 Aug 2008 01:36:49 +0200 Subject: netapi: support level 1012 in NetUserSetInfo. Guenther (This used to be commit db650e9b6ead70152b2640415477bb26d0b16097) --- source3/lib/netapi/user.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/user.c b/source3/lib/netapi/user.c index 8fa0710dc1..b7581957c4 100644 --- a/source3/lib/netapi/user.c +++ b/source3/lib/netapi/user.c @@ -69,6 +69,9 @@ static void convert_USER_INFO_X_to_samr_user_info21(struct USER_INFO_X *infoX, if (infoX->usriX_full_name) { fields_present |= SAMR_FIELD_FULL_NAME; } + if (infoX->usriX_usr_comment) { + fields_present |= SAMR_FIELD_COMMENT; + } unix_to_nt_time_abs(&password_age, infoX->usriX_password_age); @@ -88,7 +91,7 @@ static void convert_USER_INFO_X_to_samr_user_info21(struct USER_INFO_X *infoX, NULL, infoX->usriX_comment, NULL, - NULL, + infoX->usriX_usr_comment, &zero_parameters, 0, 0, @@ -118,6 +121,7 @@ static NTSTATUS construct_USER_INFO_X(uint32_t level, struct USER_INFO_1007 *u1007 = NULL; struct USER_INFO_1009 *u1009 = NULL; struct USER_INFO_1011 *u1011 = NULL; + struct USER_INFO_1012 *u1012 = NULL; if (!buffer || !uX) { return NT_STATUS_INVALID_PARAMETER; @@ -184,6 +188,10 @@ static NTSTATUS construct_USER_INFO_X(uint32_t level, u1011 = (struct USER_INFO_1011 *)buffer; uX->usriX_full_name = u1011->usri1011_full_name; break; + case 1012: + u1012 = (struct USER_INFO_1012 *)buffer; + uX->usriX_usr_comment = u1012->usri1012_usr_comment; + break; case 3: case 4: default: @@ -1324,6 +1332,9 @@ WERROR NetUserSetInfo_r(struct libnetapi_ctx *ctx, case 1011: user_mask = SAMR_USER_ACCESS_SET_ATTRIBUTES; break; + case 1012: + user_mask = SAMR_USER_ACCESS_SET_LOC_COM; + break; default: werr = WERR_NOT_SUPPORTED; goto done; -- cgit From daf162ce0cb6ee1d6bb859918ad2a90bf2a51f13 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 27 Aug 2008 01:40:46 +0200 Subject: netapi: support level 1006 in NetUserSetInfo. Guenther (This used to be commit 9c5ea4e8e8deb0a2be5f894fb5de96f0dea48120) --- source3/lib/netapi/user.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/user.c b/source3/lib/netapi/user.c index b7581957c4..35e4d7a9a9 100644 --- a/source3/lib/netapi/user.c +++ b/source3/lib/netapi/user.c @@ -118,6 +118,7 @@ static NTSTATUS construct_USER_INFO_X(uint32_t level, struct USER_INFO_1 *u1 = NULL; struct USER_INFO_2 *u2 = NULL; struct USER_INFO_1003 *u1003 = NULL; + struct USER_INFO_1006 *u1006 = NULL; struct USER_INFO_1007 *u1007 = NULL; struct USER_INFO_1009 *u1009 = NULL; struct USER_INFO_1011 *u1011 = NULL; @@ -176,6 +177,10 @@ static NTSTATUS construct_USER_INFO_X(uint32_t level, u1003 = (struct USER_INFO_1003 *)buffer; uX->usriX_password = u1003->usri1003_password; break; + case 1006: + u1006 = (struct USER_INFO_1006 *)buffer; + uX->usriX_home_dir = u1006->usri1006_home_dir; + break; case 1007: u1007 = (struct USER_INFO_1007 *)buffer; uX->usriX_comment = u1007->usri1007_comment; @@ -1327,6 +1332,7 @@ WERROR NetUserSetInfo_r(struct libnetapi_ctx *ctx, case 1003: user_mask = SAMR_USER_ACCESS_SET_PASSWORD; break; + case 1006: case 1007: case 1009: case 1011: -- cgit From 49db2e0ae18b9aac34faa00ef9f2a84461d13678 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 27 Aug 2008 01:47:33 +0200 Subject: netapi: support level 1052 in NetUserSetInfo. Guenther (This used to be commit ff8dede3b369d39ec5638eec8a73bd6397e3d94b) --- source3/lib/netapi/user.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/user.c b/source3/lib/netapi/user.c index 35e4d7a9a9..c68fe37344 100644 --- a/source3/lib/netapi/user.c +++ b/source3/lib/netapi/user.c @@ -72,6 +72,9 @@ static void convert_USER_INFO_X_to_samr_user_info21(struct USER_INFO_X *infoX, if (infoX->usriX_usr_comment) { fields_present |= SAMR_FIELD_COMMENT; } + if (infoX->usriX_profile) { + fields_present |= SAMR_FIELD_PROFILE_PATH; + } unix_to_nt_time_abs(&password_age, infoX->usriX_password_age); @@ -88,7 +91,7 @@ static void convert_USER_INFO_X_to_samr_user_info21(struct USER_INFO_X *infoX, infoX->usriX_home_dir, NULL, infoX->usriX_script_path, - NULL, + infoX->usriX_profile, infoX->usriX_comment, NULL, infoX->usriX_usr_comment, @@ -123,6 +126,7 @@ static NTSTATUS construct_USER_INFO_X(uint32_t level, struct USER_INFO_1009 *u1009 = NULL; struct USER_INFO_1011 *u1011 = NULL; struct USER_INFO_1012 *u1012 = NULL; + struct USER_INFO_1052 *u1052 = NULL; if (!buffer || !uX) { return NT_STATUS_INVALID_PARAMETER; @@ -197,6 +201,11 @@ static NTSTATUS construct_USER_INFO_X(uint32_t level, u1012 = (struct USER_INFO_1012 *)buffer; uX->usriX_usr_comment = u1012->usri1012_usr_comment; break; + case 1052: + u1052 = (struct USER_INFO_1052 *)buffer; + uX->usriX_profile = u1052->usri1052_profile; + break; + case 3: case 4: default: @@ -1336,6 +1345,7 @@ WERROR NetUserSetInfo_r(struct libnetapi_ctx *ctx, case 1007: case 1009: case 1011: + case 1052: user_mask = SAMR_USER_ACCESS_SET_ATTRIBUTES; break; case 1012: -- cgit From 3077047a17f2d852f3d6908cd1e48783df954448 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 27 Aug 2008 01:53:10 +0200 Subject: netapi: support level 1053 in NetUserSetInfo. Guenther (This used to be commit 039904f601755678fcbdef7d6bdc1c6da0082b83) --- source3/lib/netapi/user.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/user.c b/source3/lib/netapi/user.c index c68fe37344..5aff7f0d1e 100644 --- a/source3/lib/netapi/user.c +++ b/source3/lib/netapi/user.c @@ -75,6 +75,9 @@ static void convert_USER_INFO_X_to_samr_user_info21(struct USER_INFO_X *infoX, if (infoX->usriX_profile) { fields_present |= SAMR_FIELD_PROFILE_PATH; } + if (infoX->usriX_home_dir_drive) { + fields_present |= SAMR_FIELD_HOME_DRIVE; + } unix_to_nt_time_abs(&password_age, infoX->usriX_password_age); @@ -89,7 +92,7 @@ static void convert_USER_INFO_X_to_samr_user_info21(struct USER_INFO_X *infoX, infoX->usriX_name, infoX->usriX_full_name, infoX->usriX_home_dir, - NULL, + infoX->usriX_home_dir_drive, infoX->usriX_script_path, infoX->usriX_profile, infoX->usriX_comment, @@ -127,6 +130,7 @@ static NTSTATUS construct_USER_INFO_X(uint32_t level, struct USER_INFO_1011 *u1011 = NULL; struct USER_INFO_1012 *u1012 = NULL; struct USER_INFO_1052 *u1052 = NULL; + struct USER_INFO_1053 *u1053 = NULL; if (!buffer || !uX) { return NT_STATUS_INVALID_PARAMETER; @@ -205,7 +209,10 @@ static NTSTATUS construct_USER_INFO_X(uint32_t level, u1052 = (struct USER_INFO_1052 *)buffer; uX->usriX_profile = u1052->usri1052_profile; break; - + case 1053: + u1053 = (struct USER_INFO_1053 *)buffer; + uX->usriX_home_dir_drive = u1053->usri1053_home_dir_drive; + break; case 3: case 4: default: @@ -1346,6 +1353,7 @@ WERROR NetUserSetInfo_r(struct libnetapi_ctx *ctx, case 1009: case 1011: case 1052: + case 1053: user_mask = SAMR_USER_ACCESS_SET_ATTRIBUTES; break; case 1012: -- cgit From 4874a8b3b8ce755eca62eb28a4416703db866606 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 27 Aug 2008 02:02:30 +0200 Subject: netapi: support level 1051 in NetUserSetInfo. Guenther (This used to be commit 8da3b1cacb4ffa7ce8932dc0e9ceb78395d49b98) --- source3/lib/netapi/user.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/user.c b/source3/lib/netapi/user.c index 5aff7f0d1e..51c946bf6d 100644 --- a/source3/lib/netapi/user.c +++ b/source3/lib/netapi/user.c @@ -78,6 +78,9 @@ static void convert_USER_INFO_X_to_samr_user_info21(struct USER_INFO_X *infoX, if (infoX->usriX_home_dir_drive) { fields_present |= SAMR_FIELD_HOME_DRIVE; } + if (infoX->usriX_primary_group_id) { + fields_present |= SAMR_FIELD_PRIMARY_GID; + } unix_to_nt_time_abs(&password_age, infoX->usriX_password_age); @@ -100,7 +103,7 @@ static void convert_USER_INFO_X_to_samr_user_info21(struct USER_INFO_X *infoX, infoX->usriX_usr_comment, &zero_parameters, 0, - 0, + infoX->usriX_primary_group_id, infoX->usriX_flags, fields_present, zero_logon_hours, @@ -129,6 +132,7 @@ static NTSTATUS construct_USER_INFO_X(uint32_t level, struct USER_INFO_1009 *u1009 = NULL; struct USER_INFO_1011 *u1011 = NULL; struct USER_INFO_1012 *u1012 = NULL; + struct USER_INFO_1051 *u1051 = NULL; struct USER_INFO_1052 *u1052 = NULL; struct USER_INFO_1053 *u1053 = NULL; @@ -205,6 +209,10 @@ static NTSTATUS construct_USER_INFO_X(uint32_t level, u1012 = (struct USER_INFO_1012 *)buffer; uX->usriX_usr_comment = u1012->usri1012_usr_comment; break; + case 1051: + u1051 = (struct USER_INFO_1051 *)buffer; + uX->usriX_primary_group_id = u1051->usri1051_primary_group_id; + break; case 1052: u1052 = (struct USER_INFO_1052 *)buffer; uX->usriX_profile = u1052->usri1052_profile; @@ -1358,6 +1366,9 @@ WERROR NetUserSetInfo_r(struct libnetapi_ctx *ctx, break; case 1012: user_mask = SAMR_USER_ACCESS_SET_LOC_COM; + case 1051: + user_mask = SAMR_USER_ACCESS_SET_ATTRIBUTES | + SAMR_USER_ACCESS_GET_GROUPS; break; default: werr = WERR_NOT_SUPPORTED; -- cgit From 502036e730902d26e384dc12faa517d1758f2925 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 27 Aug 2008 02:11:54 +0200 Subject: netapi: support level 1024 in NetUserSetInfo. Guenther (This used to be commit 84bc7bf1adcde270ad20bba67345c0beed0b1d66) --- source3/lib/netapi/user.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/user.c b/source3/lib/netapi/user.c index 51c946bf6d..b67c5525d2 100644 --- a/source3/lib/netapi/user.c +++ b/source3/lib/netapi/user.c @@ -81,6 +81,9 @@ static void convert_USER_INFO_X_to_samr_user_info21(struct USER_INFO_X *infoX, if (infoX->usriX_primary_group_id) { fields_present |= SAMR_FIELD_PRIMARY_GID; } + if (infoX->usriX_country_code) { + fields_present |= SAMR_FIELD_COUNTRY_CODE; + } unix_to_nt_time_abs(&password_age, infoX->usriX_password_age); @@ -109,7 +112,7 @@ static void convert_USER_INFO_X_to_samr_user_info21(struct USER_INFO_X *infoX, zero_logon_hours, 0, 0, - 0, + infoX->usriX_country_code, 0, 0, 0, @@ -132,6 +135,7 @@ static NTSTATUS construct_USER_INFO_X(uint32_t level, struct USER_INFO_1009 *u1009 = NULL; struct USER_INFO_1011 *u1011 = NULL; struct USER_INFO_1012 *u1012 = NULL; + struct USER_INFO_1024 *u1024 = NULL; struct USER_INFO_1051 *u1051 = NULL; struct USER_INFO_1052 *u1052 = NULL; struct USER_INFO_1053 *u1053 = NULL; @@ -209,6 +213,10 @@ static NTSTATUS construct_USER_INFO_X(uint32_t level, u1012 = (struct USER_INFO_1012 *)buffer; uX->usriX_usr_comment = u1012->usri1012_usr_comment; break; + case 1024: + u1024 = (struct USER_INFO_1024 *)buffer; + uX->usriX_country_code = u1024->usri1024_country_code; + break; case 1051: u1051 = (struct USER_INFO_1051 *)buffer; uX->usriX_primary_group_id = u1051->usri1051_primary_group_id; @@ -1365,6 +1373,7 @@ WERROR NetUserSetInfo_r(struct libnetapi_ctx *ctx, user_mask = SAMR_USER_ACCESS_SET_ATTRIBUTES; break; case 1012: + case 1024: user_mask = SAMR_USER_ACCESS_SET_LOC_COM; case 1051: user_mask = SAMR_USER_ACCESS_SET_ATTRIBUTES | -- cgit From da843841be1aa796ca4d7b27e867cd0f49edc7c7 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 27 Aug 2008 02:18:30 +0200 Subject: netapi: support level 1014 in NetUserSetInfo. Guenther (This used to be commit 38178965a2f641978b666452f86fdcd258e8709b) --- source3/lib/netapi/user.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/user.c b/source3/lib/netapi/user.c index b67c5525d2..dba7542235 100644 --- a/source3/lib/netapi/user.c +++ b/source3/lib/netapi/user.c @@ -84,6 +84,9 @@ static void convert_USER_INFO_X_to_samr_user_info21(struct USER_INFO_X *infoX, if (infoX->usriX_country_code) { fields_present |= SAMR_FIELD_COUNTRY_CODE; } + if (infoX->usriX_workstations) { + fields_present |= SAMR_FIELD_WORKSTATIONS; + } unix_to_nt_time_abs(&password_age, infoX->usriX_password_age); @@ -102,7 +105,7 @@ static void convert_USER_INFO_X_to_samr_user_info21(struct USER_INFO_X *infoX, infoX->usriX_script_path, infoX->usriX_profile, infoX->usriX_comment, - NULL, + infoX->usriX_workstations, infoX->usriX_usr_comment, &zero_parameters, 0, @@ -135,6 +138,7 @@ static NTSTATUS construct_USER_INFO_X(uint32_t level, struct USER_INFO_1009 *u1009 = NULL; struct USER_INFO_1011 *u1011 = NULL; struct USER_INFO_1012 *u1012 = NULL; + struct USER_INFO_1014 *u1014 = NULL; struct USER_INFO_1024 *u1024 = NULL; struct USER_INFO_1051 *u1051 = NULL; struct USER_INFO_1052 *u1052 = NULL; @@ -213,6 +217,10 @@ static NTSTATUS construct_USER_INFO_X(uint32_t level, u1012 = (struct USER_INFO_1012 *)buffer; uX->usriX_usr_comment = u1012->usri1012_usr_comment; break; + case 1014: + u1014 = (struct USER_INFO_1014 *)buffer; + uX->usriX_workstations = u1014->usri1014_workstations; + break; case 1024: u1024 = (struct USER_INFO_1024 *)buffer; uX->usriX_country_code = u1024->usri1024_country_code; @@ -1368,6 +1376,7 @@ WERROR NetUserSetInfo_r(struct libnetapi_ctx *ctx, case 1007: case 1009: case 1011: + case 1014: case 1052: case 1053: user_mask = SAMR_USER_ACCESS_SET_ATTRIBUTES; -- cgit From 3967936a4b38252ee9821608da637bb309479201 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 27 Aug 2008 11:49:55 +0200 Subject: netapi: add skeleton for NetUserGetGroups. Guenther (This used to be commit a21ec57b2887012777f9580959a37cd23a412029) --- source3/lib/netapi/libnetapi.c | 52 ++++++++++++++++++++++++++++++++++++++++++ source3/lib/netapi/libnetapi.h | 11 +++++++++ source3/lib/netapi/user.c | 18 +++++++++++++++ 3 files changed, 81 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/libnetapi.c b/source3/lib/netapi/libnetapi.c index 5fe48077a8..4b87bbcdf4 100644 --- a/source3/lib/netapi/libnetapi.c +++ b/source3/lib/netapi/libnetapi.c @@ -725,6 +725,58 @@ NET_API_STATUS NetUserSetInfo(const char * server_name /* [in] */, return r.out.result; } +/**************************************************************** + NetUserGetGroups +****************************************************************/ + +NET_API_STATUS NetUserGetGroups(const char * server_name /* [in] */, + const char * user_name /* [in] */, + uint32_t level /* [in] */, + uint8_t **buffer /* [out] [ref] */, + uint32_t prefmaxlen /* [in] */, + uint32_t *entries_read /* [out] [ref] */, + uint32_t *total_entries /* [out] [ref] */) +{ + struct NetUserGetGroups r; + struct libnetapi_ctx *ctx = NULL; + NET_API_STATUS status; + WERROR werr; + + status = libnetapi_getctx(&ctx); + if (status != 0) { + return status; + } + + /* In parameters */ + r.in.server_name = server_name; + r.in.user_name = user_name; + r.in.level = level; + r.in.prefmaxlen = prefmaxlen; + + /* Out parameters */ + r.out.buffer = buffer; + r.out.entries_read = entries_read; + r.out.total_entries = total_entries; + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_IN_DEBUG(NetUserGetGroups, &r); + } + + if (LIBNETAPI_LOCAL_SERVER(server_name)) { + werr = NetUserGetGroups_l(ctx, &r); + } else { + werr = NetUserGetGroups_r(ctx, &r); + } + + r.out.result = W_ERROR_V(werr); + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_OUT_DEBUG(NetUserGetGroups, &r); + } + + return r.out.result; +} + /**************************************************************** NetUserModalsGet ****************************************************************/ diff --git a/source3/lib/netapi/libnetapi.h b/source3/lib/netapi/libnetapi.h index b0ff8e5baf..189083cc1f 100644 --- a/source3/lib/netapi/libnetapi.h +++ b/source3/lib/netapi/libnetapi.h @@ -125,6 +125,17 @@ WERROR NetUserSetInfo_r(struct libnetapi_ctx *ctx, struct NetUserSetInfo *r); WERROR NetUserSetInfo_l(struct libnetapi_ctx *ctx, struct NetUserSetInfo *r); +NET_API_STATUS NetUserGetGroups(const char * server_name /* [in] */, + const char * user_name /* [in] */, + uint32_t level /* [in] */, + uint8_t **buffer /* [out] [ref] */, + uint32_t prefmaxlen /* [in] */, + uint32_t *entries_read /* [out] [ref] */, + uint32_t *total_entries /* [out] [ref] */); +WERROR NetUserGetGroups_r(struct libnetapi_ctx *ctx, + struct NetUserGetGroups *r); +WERROR NetUserGetGroups_l(struct libnetapi_ctx *ctx, + struct NetUserGetGroups *r); NET_API_STATUS NetUserModalsGet(const char * server_name /* [in] */, uint32_t level /* [in] */, uint8_t **buffer /* [out] [ref] */); diff --git a/source3/lib/netapi/user.c b/source3/lib/netapi/user.c index dba7542235..78a95fd10b 100644 --- a/source3/lib/netapi/user.c +++ b/source3/lib/netapi/user.c @@ -2354,3 +2354,21 @@ WERROR NetUserModalsSet_l(struct libnetapi_ctx *ctx, { LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetUserModalsSet); } + +/**************************************************************** +****************************************************************/ + +WERROR NetUserGetGroups_r(struct libnetapi_ctx *ctx, + struct NetUserGetGroups *r) +{ + return WERR_NOT_SUPPORTED; +} + +/**************************************************************** +****************************************************************/ + +WERROR NetUserGetGroups_l(struct libnetapi_ctx *ctx, + struct NetUserGetGroups *r) +{ + LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetUserGetGroups); +} -- cgit From d304d17f2e21abdeb4adac15870026a6c3f86249 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 27 Aug 2008 11:55:57 +0200 Subject: netapi: fix NetUserSetInfo return code for currently unsupported levels. Guenther (This used to be commit 10bd55d68a91b76e82c3ba1d113729f97830a46a) --- source3/lib/netapi/user.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/user.c b/source3/lib/netapi/user.c index 78a95fd10b..25871563ce 100644 --- a/source3/lib/netapi/user.c +++ b/source3/lib/netapi/user.c @@ -1388,9 +1388,22 @@ WERROR NetUserSetInfo_r(struct libnetapi_ctx *ctx, user_mask = SAMR_USER_ACCESS_SET_ATTRIBUTES | SAMR_USER_ACCESS_GET_GROUPS; break; - default: + case 1: + case 2: + case 3: + case 4: + case 21: + case 22: + case 1005: + case 1008: + case 1010: + case 1017: + case 1020: werr = WERR_NOT_SUPPORTED; goto done; + default: + werr = WERR_UNKNOWN_LEVEL; + goto done; } werr = libnetapi_open_pipe(ctx, r->in.server_name, -- cgit From 29e8a0fa2a8ac8da624ebcf79f9d350ed1407c80 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 27 Aug 2008 13:13:57 +0200 Subject: netapi: add NetUserGetGroups to public headers. Guenther (This used to be commit 2f95b7d9b5ad513e43d7d41ce9fb87300ec357a8) --- source3/lib/netapi/netapi.h | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h index 4882ada893..9ba1d30f5c 100644 --- a/source3/lib/netapi/netapi.h +++ b/source3/lib/netapi/netapi.h @@ -998,6 +998,33 @@ NET_API_STATUS NetUserModalsSet(const char * server_name /* [in] */, uint8_t *buffer /* [in] [ref] */, uint32_t *parm_err /* [out] [ref] */); +/************************************************************//** + * + * NetUserGetGroups + * + * @brief Enumerate grouplist of a user on a server + * + * @param[in] server_name The server name to connect to + * @param[in] user_name The user name to query + * @param[in] level The enumeration level used for the query (Currently only + * level 0 is supported) + * @param[out] buffer The returned enumeration buffer + * @param[in] prefmaxlen The requested maximal buffer size + * @param[out] entries_read The number of returned entries + * @param[out] total_entries The number of total entries + * @return NET_API_STATUS + * + * example user/user_getgroups.c + ***************************************************************/ + +NET_API_STATUS NetUserGetGroups(const char * server_name /* [in] */, + const char * user_name /* [in] */, + uint32_t level /* [in] */, + uint8_t **buffer /* [out] [ref] */, + uint32_t prefmaxlen /* [in] */, + uint32_t *entries_read /* [out] [ref] */, + uint32_t *total_entries /* [out] [ref] */); + /************************************************************//** * * NetQueryDisplayInformation -- cgit From aeaa881c993e4875a8851b22412fee683f09de23 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 27 Aug 2008 13:14:24 +0200 Subject: netapi: add NetUserGetGroups example code. Guenther (This used to be commit 33e9baeb26a469445b6750c4bd2f00b4140f0554) --- source3/lib/netapi/examples/Makefile.in | 6 + source3/lib/netapi/examples/user/user_getgroups.c | 133 ++++++++++++++++++++++ 2 files changed, 139 insertions(+) create mode 100644 source3/lib/netapi/examples/user/user_getgroups.c (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/Makefile.in b/source3/lib/netapi/examples/Makefile.in index 0b7553c389..4595db552d 100644 --- a/source3/lib/netapi/examples/Makefile.in +++ b/source3/lib/netapi/examples/Makefile.in @@ -31,6 +31,7 @@ PROGS = bin/getdc@EXEEXT@ \ bin/user_setinfo@EXEEXT@ \ bin/user_modalsget@EXEEXT@ \ bin/user_modalsset@EXEEXT@ \ + bin/user_getgroups@EXEEXT@ \ bin/group_add@EXEEXT@ \ bin/group_del@EXEEXT@ \ bin/group_enum@EXEEXT@ \ @@ -91,6 +92,7 @@ USERGETINFO_OBJ = user/user_getinfo.o $(CMDLINE_OBJ) USERSETINFO_OBJ = user/user_setinfo.o $(CMDLINE_OBJ) USERMODALSGET_OBJ = user/user_modalsget.o $(CMDLINE_OBJ) USERMODALSSET_OBJ = user/user_modalsset.o $(CMDLINE_OBJ) +USERGETGROUPS_OBJ = user/user_getgroups.o $(CMDLINE_OBJ) GROUPADD_OBJ = group/group_add.o $(CMDLINE_OBJ) GROUPDEL_OBJ = group/group_del.o $(CMDLINE_OBJ) GROUPENUM_OBJ = group/group_enum.o $(CMDLINE_OBJ) @@ -166,6 +168,10 @@ bin/user_modalsset@EXEEXT@: $(BINARY_PREREQS) $(USERMODALSSET_OBJ) @echo Linking $@ @$(CC) $(FLAGS) -o $@ $(USERMODALSSET_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) +bin/user_getgroups@EXEEXT@: $(BINARY_PREREQS) $(USERGETGROUPS_OBJ) + @echo Linking $@ + @$(CC) $(FLAGS) -o $@ $(USERGETGROUPS_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) + bin/group_add@EXEEXT@: $(BINARY_PREREQS) $(GROUPADD_OBJ) @echo Linking $@ @$(CC) $(FLAGS) -o $@ $(GROUPADD_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) diff --git a/source3/lib/netapi/examples/user/user_getgroups.c b/source3/lib/netapi/examples/user/user_getgroups.c new file mode 100644 index 0000000000..939415e0eb --- /dev/null +++ b/source3/lib/netapi/examples/user/user_getgroups.c @@ -0,0 +1,133 @@ +/* + * Unix SMB/CIFS implementation. + * NetUserGetGroups query + * Copyright (C) Guenther Deschner 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include +#include +#include +#include +#include + +#include + +#include "common.h" + +int main(int argc, const char **argv) +{ + NET_API_STATUS status; + struct libnetapi_ctx *ctx = NULL; + const char *hostname = NULL; + const char *username = NULL; + uint32_t level = 0; + uint8_t *buffer = NULL; + uint32_t entries_read = 0; + uint32_t total_entries = 0; + int i; + + struct GROUP_USERS_INFO_0 *info0 = NULL; + struct GROUP_USERS_INFO_1 *info1 = NULL; + + poptContext pc; + int opt; + + struct poptOption long_options[] = { + POPT_AUTOHELP + POPT_COMMON_LIBNETAPI_EXAMPLES + POPT_TABLEEND + }; + + status = libnetapi_init(&ctx); + if (status != 0) { + return status; + } + + pc = poptGetContext("user_getgroups", argc, argv, long_options, 0); + + poptSetOtherOptionHelp(pc, "hostname username level"); + while((opt = poptGetNextOpt(pc)) != -1) { + } + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + hostname = poptGetArg(pc); + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + username = poptGetArg(pc); + + if (poptPeekArg(pc)) { + level = atoi(poptGetArg(pc)); + } + + /* NetUserGetGroups */ + + do { + status = NetUserGetGroups(hostname, + username, + level, + &buffer, + (uint32_t)-1, + &entries_read, + &total_entries); + if (status == 0 || status == ERROR_MORE_DATA) { + + switch (level) { + case 0: + info0 = (struct GROUP_USERS_INFO_0 *)buffer; + break; + case 1: + info1 = (struct GROUP_USERS_INFO_1 *)buffer; + break; + default: + break; + } + + for (i=0; igrui0_name); + info0++; + break; + case 1: + printf("#%d group: %s\n", i, info1->grui1_name); + printf("#%d attributes: %d\n", i, info1->grui1_attributes); + info1++; + break; + default: + break; + } + } + NetApiBufferFree(buffer); + } + } while (status == ERROR_MORE_DATA); + + if (status != 0) { + printf("NetUserGetGroups failed with: %s\n", + libnetapi_get_error_string(ctx, status)); + } + + out: + libnetapi_free(ctx); + poptFreeContext(pc); + + return status; +} -- cgit From 77285ee6024c7379766589f816a0f67c0e4ea4ec Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 27 Aug 2008 13:37:56 +0200 Subject: netapi: implement NetUserGetGroups_r. Guenther (This used to be commit 1ed8fefdae85e9b9f2794e502c8c1c41d9ba0615) --- source3/lib/netapi/user.c | 175 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 174 insertions(+), 1 deletion(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/user.c b/source3/lib/netapi/user.c index 25871563ce..6e13a54528 100644 --- a/source3/lib/netapi/user.c +++ b/source3/lib/netapi/user.c @@ -2371,10 +2371,183 @@ WERROR NetUserModalsSet_l(struct libnetapi_ctx *ctx, /**************************************************************** ****************************************************************/ +static NTSTATUS add_GROUP_USERS_INFO_X_buffer(TALLOC_CTX *mem_ctx, + uint32_t level, + const char *group_name, + uint32_t attributes, + uint8_t **buffer, + uint32_t *num_entries) +{ + struct GROUP_USERS_INFO_0 u0; + struct GROUP_USERS_INFO_1 u1; + + switch (level) { + case 0: + u0.grui0_name = talloc_strdup(mem_ctx, group_name); + NT_STATUS_HAVE_NO_MEMORY(u0.grui0_name); + + ADD_TO_ARRAY(mem_ctx, struct GROUP_USERS_INFO_0, u0, + (struct GROUP_USERS_INFO_0 **)buffer, num_entries); + break; + case 1: + u1.grui1_name = talloc_strdup(mem_ctx, group_name); + NT_STATUS_HAVE_NO_MEMORY(u1.grui1_name); + + u1.grui1_attributes = attributes; + + ADD_TO_ARRAY(mem_ctx, struct GROUP_USERS_INFO_1, u1, + (struct GROUP_USERS_INFO_1 **)buffer, num_entries); + break; + default: + return NT_STATUS_INVALID_INFO_CLASS; + } + + return NT_STATUS_OK; +} + +/**************************************************************** +****************************************************************/ + WERROR NetUserGetGroups_r(struct libnetapi_ctx *ctx, struct NetUserGetGroups *r) { - return WERR_NOT_SUPPORTED; + struct cli_state *cli = NULL; + struct rpc_pipe_client *pipe_cli = NULL; + struct policy_handle connect_handle, domain_handle, user_handle; + struct lsa_String lsa_account_name; + struct dom_sid2 *domain_sid = NULL; + struct samr_Ids user_rids, name_types; + struct samr_RidWithAttributeArray *rid_array = NULL; + struct lsa_Strings names; + struct samr_Ids types; + uint32_t *rids = NULL; + + int i; + uint32_t entries_read = 0; + + NTSTATUS status = NT_STATUS_OK; + WERROR werr; + + ZERO_STRUCT(connect_handle); + ZERO_STRUCT(domain_handle); + + if (!r->out.buffer) { + return WERR_INVALID_PARAM; + } + + *r->out.buffer = NULL; + *r->out.entries_read = 0; + + switch (r->in.level) { + case 0: + case 1: + break; + default: + return WERR_UNKNOWN_LEVEL; + } + + werr = libnetapi_open_pipe(ctx, r->in.server_name, + &ndr_table_samr.syntax_id, + &cli, + &pipe_cli); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + werr = libnetapi_samr_open_domain(ctx, pipe_cli, + SAMR_ACCESS_ENUM_DOMAINS | + SAMR_ACCESS_OPEN_DOMAIN, + SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, + &connect_handle, + &domain_handle, + &domain_sid); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + init_lsa_String(&lsa_account_name, r->in.user_name); + + status = rpccli_samr_LookupNames(pipe_cli, ctx, + &domain_handle, + 1, + &lsa_account_name, + &user_rids, + &name_types); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + status = rpccli_samr_OpenUser(pipe_cli, ctx, + &domain_handle, + SAMR_USER_ACCESS_GET_GROUPS, + user_rids.ids[0], + &user_handle); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + status = rpccli_samr_GetGroupsForUser(pipe_cli, ctx, + &user_handle, + &rid_array); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + rids = talloc_array(ctx, uint32_t, rid_array->count); + if (!rids) { + werr = WERR_NOMEM; + goto done; + } + + for (i=0; i < rid_array->count; i++) { + rids[i] = rid_array->rids[i].rid; + } + + status = rpccli_samr_LookupRids(pipe_cli, ctx, + &domain_handle, + rid_array->count, + rids, + &names, + &types); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + for (i=0; i < rid_array->count; i++) { + status = add_GROUP_USERS_INFO_X_buffer(ctx, + r->in.level, + names.names[i].string, + rid_array->rids[i].attributes, + r->out.buffer, + &entries_read); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + } + + if (r->out.entries_read) { + *r->out.entries_read = entries_read; + } + if (r->out.total_entries) { + *r->out.total_entries = entries_read; + } + + done: + if (!cli) { + return werr; + } + + if (ctx->disable_policy_handle_cache) { + libnetapi_samr_close_domain_handle(ctx, &domain_handle); + libnetapi_samr_close_connect_handle(ctx, &connect_handle); + } + + return werr; } /**************************************************************** -- cgit From 36de16b472a5377269cacb7f7e5227e8834d1788 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 27 Aug 2008 19:15:32 +0200 Subject: netapi: fix public header for USER_INFO_4. Guenther (This used to be commit f54b24c70afb28b6897ce258929ab2c97f255d86) --- source3/lib/netapi/netapi.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h index 9ba1d30f5c..1dc933a9d9 100644 --- a/source3/lib/netapi/netapi.h +++ b/source3/lib/netapi/netapi.h @@ -185,7 +185,7 @@ struct USER_INFO_4 { const char * usri4_logon_server; uint32_t usri4_country_code; uint32_t usri4_code_page; - struct dom_sid *usri4_user_sid;/* [unique] */ + struct domsid *usri4_user_sid;/* [unique] */ uint32_t usri4_primary_group_id; const char * usri4_profile; const char * usri4_home_dir_drive; -- cgit From 1aee2cedc1c60435406fca8f51f237f4eebd80df Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 27 Aug 2008 19:16:30 +0200 Subject: netapi: display all available levels in NetUserGetInfo example. Guenther (This used to be commit 814c9a4f663ea354291456407accbc3fe7edccf6) --- source3/lib/netapi/examples/user/user_getinfo.c | 149 ++++++++++++++++++++++++ 1 file changed, 149 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/user/user_getinfo.c b/source3/lib/netapi/examples/user/user_getinfo.c index 19234d0532..9e95260b5a 100644 --- a/source3/lib/netapi/examples/user/user_getinfo.c +++ b/source3/lib/netapi/examples/user/user_getinfo.c @@ -36,10 +36,15 @@ int main(int argc, const char **argv) uint8_t *buffer = NULL; uint32_t level = 0; char *sid_str = NULL; + int i; struct USER_INFO_0 *u0; struct USER_INFO_1 *u1; + struct USER_INFO_2 *u2; + struct USER_INFO_3 *u3; + struct USER_INFO_4 *u4; struct USER_INFO_10 *u10; + struct USER_INFO_11 *u11; struct USER_INFO_20 *u20; struct USER_INFO_23 *u23; @@ -107,6 +112,121 @@ int main(int argc, const char **argv) printf("flags: 0x%08x\n", u1->usri1_flags); printf("script: %s\n", u1->usri1_script_path); break; + case 2: + u2 = (struct USER_INFO_2 *)buffer; + printf("name: %s\n", u2->usri2_name); + printf("password: %s\n", u2->usri2_password); + printf("password_age: %d\n", u2->usri2_password_age); + printf("priv: %d\n", u2->usri2_priv); + printf("homedir: %s\n", u2->usri2_home_dir); + printf("comment: %s\n", u2->usri2_comment); + printf("flags: 0x%08x\n", u2->usri2_flags); + printf("script: %s\n", u2->usri2_script_path); + printf("auth flags: 0x%08x\n", u2->usri2_auth_flags); + printf("full name: %s\n", u2->usri2_full_name); + printf("user comment: %s\n", u2->usri2_usr_comment); + printf("user parameters: %s\n", u2->usri2_parms); + printf("workstations: %s\n", u2->usri2_workstations); + printf("last logon (seconds since jan. 1, 1970 GMT): %d\n", + u2->usri2_last_logon); + printf("last logoff (seconds since jan. 1, 1970 GMT): %d\n", + u2->usri2_last_logoff); + printf("account expires (seconds since jan. 1, 1970 GMT): %d\n", + u2->usri2_acct_expires); + printf("max storage: %d\n", u2->usri2_max_storage); + printf("units per week: %d\n", u2->usri2_units_per_week); + printf("logon hours:"); + for (i=0; i<21; i++) { + printf(" %x", (uint8_t)u2->usri2_logon_hours[i]); + } + printf("\n"); + printf("bad password count: %d\n", u2->usri2_bad_pw_count); + printf("logon count: %d\n", u2->usri2_num_logons); + printf("logon server: %s\n", u2->usri2_logon_server); + printf("country code: %d\n", u2->usri2_country_code); + printf("code page: %d\n", u2->usri2_code_page); + break; + case 3: + u3 = (struct USER_INFO_3 *)buffer; + printf("name: %s\n", u3->usri3_name); + printf("password_age: %d\n", u3->usri3_password_age); + printf("priv: %d\n", u3->usri3_priv); + printf("homedir: %s\n", u3->usri3_home_dir); + printf("comment: %s\n", u3->usri3_comment); + printf("flags: 0x%08x\n", u3->usri3_flags); + printf("script: %s\n", u3->usri3_script_path); + printf("auth flags: 0x%08x\n", u3->usri3_auth_flags); + printf("full name: %s\n", u3->usri3_full_name); + printf("user comment: %s\n", u3->usri3_usr_comment); + printf("user parameters: %s\n", u3->usri3_parms); + printf("workstations: %s\n", u3->usri3_workstations); + printf("last logon (seconds since jan. 1, 1970 GMT): %d\n", + u3->usri3_last_logon); + printf("last logoff (seconds since jan. 1, 1970 GMT): %d\n", + u3->usri3_last_logoff); + printf("account expires (seconds since jan. 1, 1970 GMT): %d\n", + u3->usri3_acct_expires); + printf("max storage: %d\n", u3->usri3_max_storage); + printf("units per week: %d\n", u3->usri3_units_per_week); + printf("logon hours:"); + for (i=0; i<21; i++) { + printf(" %x", (uint8_t)u3->usri3_logon_hours[i]); + } + printf("\n"); + printf("bad password count: %d\n", u3->usri3_bad_pw_count); + printf("logon count: %d\n", u3->usri3_num_logons); + printf("logon server: %s\n", u3->usri3_logon_server); + printf("country code: %d\n", u3->usri3_country_code); + printf("code page: %d\n", u3->usri3_code_page); + printf("user id: %d\n", u3->usri3_user_id); + printf("primary group id: %d\n", u3->usri3_primary_group_id); + printf("profile: %s\n", u3->usri3_profile); + printf("home dir drive: %s\n", u3->usri3_home_dir_drive); + printf("password expired: %d\n", u3->usri3_password_expired); + break; + case 4: + u4 = (struct USER_INFO_4 *)buffer; + printf("name: %s\n", u4->usri4_name); + printf("password: %s\n", u4->usri4_password); + printf("password_age: %d\n", u4->usri4_password_age); + printf("priv: %d\n", u4->usri4_priv); + printf("homedir: %s\n", u4->usri4_home_dir); + printf("comment: %s\n", u4->usri4_comment); + printf("flags: 0x%08x\n", u4->usri4_flags); + printf("script: %s\n", u4->usri4_script_path); + printf("auth flags: 0x%08x\n", u4->usri4_auth_flags); + printf("full name: %s\n", u4->usri4_full_name); + printf("user comment: %s\n", u4->usri4_usr_comment); + printf("user parameters: %s\n", u4->usri4_parms); + printf("workstations: %s\n", u4->usri4_workstations); + printf("last logon (seconds since jan. 1, 1970 GMT): %d\n", + u4->usri4_last_logon); + printf("last logoff (seconds since jan. 1, 1970 GMT): %d\n", + u4->usri4_last_logoff); + printf("account expires (seconds since jan. 1, 1970 GMT): %d\n", + u4->usri4_acct_expires); + printf("max storage: %d\n", u4->usri4_max_storage); + printf("units per week: %d\n", u4->usri4_units_per_week); + printf("logon hours:"); + for (i=0; i<21; i++) { + printf(" %x", (uint8_t)u4->usri4_logon_hours[i]); + } + printf("\n"); + printf("bad password count: %d\n", u4->usri4_bad_pw_count); + printf("logon count: %d\n", u4->usri4_num_logons); + printf("logon server: %s\n", u4->usri4_logon_server); + printf("country code: %d\n", u4->usri4_country_code); + printf("code page: %d\n", u4->usri4_code_page); + if (ConvertSidToStringSid(u4->usri4_user_sid, + &sid_str)) { + printf("user_sid: %s\n", sid_str); + free(sid_str); + } + printf("primary group id: %d\n", u4->usri4_primary_group_id); + printf("profile: %s\n", u4->usri4_profile); + printf("home dir drive: %s\n", u4->usri4_home_dir_drive); + printf("password expired: %d\n", u4->usri4_password_expired); + break; case 10: u10 = (struct USER_INFO_10 *)buffer; printf("name: %s\n", u10->usri10_name); @@ -114,6 +234,35 @@ int main(int argc, const char **argv) printf("usr_comment: %s\n", u10->usri10_usr_comment); printf("full_name: %s\n", u10->usri10_full_name); break; + case 11: + u11 = (struct USER_INFO_11 *)buffer; + printf("name: %s\n", u11->usri11_name); + printf("comment: %s\n", u11->usri11_comment); + printf("user comment: %s\n", u11->usri11_usr_comment); + printf("full name: %s\n", u11->usri11_full_name); + printf("priv: %d\n", u11->usri11_priv); + printf("auth flags: 0x%08x\n", u11->usri11_auth_flags); + printf("password_age: %d\n", u11->usri11_password_age); + printf("homedir: %s\n", u11->usri11_home_dir); + printf("user parameters: %s\n", u11->usri11_parms); + printf("last logon (seconds since jan. 1, 1970 GMT): %d\n", + u11->usri11_last_logon); + printf("last logoff (seconds since jan. 1, 1970 GMT): %d\n", + u11->usri11_last_logoff); + printf("bad password count: %d\n", u11->usri11_bad_pw_count); + printf("logon count: %d\n", u11->usri11_num_logons); + printf("logon server: %s\n", u11->usri11_logon_server); + printf("country code: %d\n", u11->usri11_country_code); + printf("workstations: %s\n", u11->usri11_workstations); + printf("max storage: %d\n", u11->usri11_max_storage); + printf("units per week: %d\n", u11->usri11_units_per_week); + printf("logon hours:"); + for (i=0; i<21; i++) { + printf(" %x", (uint8_t)u11->usri11_logon_hours[i]); + } + printf("\n"); + printf("code page: %d\n", u11->usri11_code_page); + break; case 20: u20 = (struct USER_INFO_20 *)buffer; printf("name: %s\n", u20->usri20_name); -- cgit From e96a99f3e2b33525cf87eff3d2a13118f21c5186 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 27 Aug 2008 19:25:07 +0200 Subject: netapi: add samr_acb_flags_to_netapi_flags for NetUserEnum and NetUserGetInfo. Guenther (This used to be commit 2f2c60bf91e1e2b3b24c4bb39ac598cb3c704158) --- source3/lib/netapi/user.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/user.c b/source3/lib/netapi/user.c index 6e13a54528..3c42f8b931 100644 --- a/source3/lib/netapi/user.c +++ b/source3/lib/netapi/user.c @@ -675,6 +675,18 @@ static NTSTATUS libnetapi_samr_lookup_user(TALLOC_CTX *mem_ctx, /**************************************************************** ****************************************************************/ +static uint32_t samr_acb_flags_to_netapi_flags(uint32_t acb) +{ + uint32_t fl = UF_SCRIPT; /* god knows why */ + + fl |= ads_acb2uf(acb); + + return fl; +} + +/**************************************************************** +****************************************************************/ + static NTSTATUS libnetapi_samr_lookup_user_map_USER_INFO(TALLOC_CTX *mem_ctx, struct rpc_pipe_client *pipe_cli, struct dom_sid *domain_sid, @@ -763,7 +775,8 @@ static NTSTATUS libnetapi_samr_lookup_user_map_USER_INFO(TALLOC_CTX *mem_ctx, info20.usri20_full_name = talloc_strdup(mem_ctx, info21->full_name.string); - info20.usri20_flags = info21->acct_flags; + info20.usri20_flags = + samr_acb_flags_to_netapi_flags(info21->acct_flags); info20.usri20_user_id = rid; ADD_TO_ARRAY(mem_ctx, struct USER_INFO_20, info20, @@ -780,7 +793,8 @@ static NTSTATUS libnetapi_samr_lookup_user_map_USER_INFO(TALLOC_CTX *mem_ctx, info23.usri23_full_name = talloc_strdup(mem_ctx, info21->full_name.string); - info23.usri23_flags = info21->acct_flags; + info23.usri23_flags = + samr_acb_flags_to_netapi_flags(info21->acct_flags); if (!sid_compose(&sid, domain_sid, rid)) { return NT_STATUS_NO_MEMORY; -- cgit From fea81f9056558a73608acbf5170ace0b7d4c1a8f Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 27 Aug 2008 19:26:37 +0200 Subject: netapi: always return correct account name in NetUserGetInfo/NetUserEnum. Guenther (This used to be commit 47768bfb01815f7b6bf687fe04ca7d19385aea59) --- source3/lib/netapi/user.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/user.c b/source3/lib/netapi/user.c index 3c42f8b931..887ab94002 100644 --- a/source3/lib/netapi/user.c +++ b/source3/lib/netapi/user.c @@ -748,7 +748,8 @@ static NTSTATUS libnetapi_samr_lookup_user_map_USER_INFO(TALLOC_CTX *mem_ctx, switch (level) { case 10: - info10.usri10_name = talloc_strdup(mem_ctx, user_name); + info10.usri10_name = talloc_strdup(mem_ctx, + info21->account_name.string); NT_STATUS_HAVE_NO_MEMORY(info10.usri10_name); info10.usri10_comment = talloc_strdup(mem_ctx, @@ -766,7 +767,8 @@ static NTSTATUS libnetapi_samr_lookup_user_map_USER_INFO(TALLOC_CTX *mem_ctx, break; case 20: - info20.usri20_name = talloc_strdup(mem_ctx, user_name); + info20.usri20_name = talloc_strdup(mem_ctx, + info21->account_name.string); NT_STATUS_HAVE_NO_MEMORY(info20.usri20_name); info20.usri20_comment = talloc_strdup(mem_ctx, @@ -784,7 +786,8 @@ static NTSTATUS libnetapi_samr_lookup_user_map_USER_INFO(TALLOC_CTX *mem_ctx, break; case 23: - info23.usri23_name = talloc_strdup(mem_ctx, user_name); + info23.usri23_name = talloc_strdup(mem_ctx, + info21->account_name.string); NT_STATUS_HAVE_NO_MEMORY(info23.usri23_name); info23.usri23_comment = talloc_strdup(mem_ctx, -- cgit From 0f928eb2cc0b7fe383cea28eb833d80f69545659 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 27 Aug 2008 19:28:34 +0200 Subject: netapi: give more correct error code in NetUserGetInfo. Guenther (This used to be commit c66651b6fb023e5b0952fd135589eb955f51fa12) --- source3/lib/netapi/user.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/user.c b/source3/lib/netapi/user.c index 887ab94002..47053f29af 100644 --- a/source3/lib/netapi/user.c +++ b/source3/lib/netapi/user.c @@ -1263,14 +1263,20 @@ WERROR NetUserGetInfo_r(struct libnetapi_ctx *ctx, switch (r->in.level) { case 0: - /* case 1: */ case 10: case 20: case 23: break; - default: + case 1: + case 2: + case 3: + case 4: + case 11: werr = WERR_NOT_SUPPORTED; goto done; + default: + werr = WERR_UNKNOWN_LEVEL; + goto done; } werr = libnetapi_open_pipe(ctx, r->in.server_name, -- cgit From 0faaff160813f8659ec16c708fb71c9e4a39fdf7 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 27 Aug 2008 22:38:32 +0200 Subject: netapi: add USER_PRIV_* constants to public header. Guenther (This used to be commit 2274e5d8a8236b15558507289a8a455c15ca2633) --- source3/lib/netapi/netapi.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h index 1dc933a9d9..51ea17ad7b 100644 --- a/source3/lib/netapi/netapi.h +++ b/source3/lib/netapi/netapi.h @@ -91,6 +91,10 @@ struct USER_INFO_0 { const char * usri0_name; }; +#define USER_PRIV_GUEST ( 0 ) +#define USER_PRIV_USER ( 1 ) +#define USER_PRIV_ADMIN ( 2 ) + struct USER_INFO_1 { const char * usri1_name; const char * usri1_password; -- cgit From 1283d081b2f9e15a1cefffa00f974039d96926de Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 27 Aug 2008 23:43:01 +0200 Subject: netapi: add AF_OP constants to public header. Guenther (This used to be commit a06e21782a4970840f5a8c65b633c9654443161d) --- source3/lib/netapi/netapi.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h index 51ea17ad7b..0c7c23b36f 100644 --- a/source3/lib/netapi/netapi.h +++ b/source3/lib/netapi/netapi.h @@ -106,6 +106,11 @@ struct USER_INFO_1 { const char * usri1_script_path; }; +#define AF_OP_PRINT ( 0x1 ) +#define AF_OP_COMM ( 0x2 ) +#define AF_OP_SERVER ( 0x4 ) +#define AF_OP_ACCOUNTS ( 0x8 ) + struct USER_INFO_2 { const char * usri2_name; const char * usri2_password; -- cgit From ff21cceecc66c0aa86557e99fbcbd825e3d9454c Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 28 Aug 2008 00:23:51 +0200 Subject: netapi: better point out what levels are unknown in NetUserEnum. Guenther (This used to be commit d85182aa54b936f8c85c6dcd10d5df613de4bb21) --- source3/lib/netapi/user.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/user.c b/source3/lib/netapi/user.c index 47053f29af..593434f999 100644 --- a/source3/lib/netapi/user.c +++ b/source3/lib/netapi/user.c @@ -854,8 +854,9 @@ WERROR NetUserEnum_r(struct libnetapi_ctx *ctx, case 2: case 3: case 11: - default: return WERR_NOT_SUPPORTED; + default: + return WERR_UNKNOWN_LEVEL; } werr = libnetapi_open_pipe(ctx, r->in.server_name, -- cgit From c750f8c40036f04ff0ae533aeb97d5948b31ed54 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 28 Aug 2008 00:56:25 +0200 Subject: netapi: add samr_rid_to_priv_level(). Guenther (This used to be commit 51afae499974f3ad73a1c9bdfbc41e3130966ebc) --- source3/lib/netapi/user.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/user.c b/source3/lib/netapi/user.c index 593434f999..7f259195a5 100644 --- a/source3/lib/netapi/user.c +++ b/source3/lib/netapi/user.c @@ -675,6 +675,21 @@ static NTSTATUS libnetapi_samr_lookup_user(TALLOC_CTX *mem_ctx, /**************************************************************** ****************************************************************/ +static uint32_t samr_rid_to_priv_level(uint32_t rid) +{ + switch (rid) { + case DOMAIN_RID_ADMINISTRATOR: + return USER_PRIV_ADMIN; + case DOMAIN_RID_GUEST: + return USER_PRIV_GUEST; + default: + return USER_PRIV_USER; + } +} + +/**************************************************************** +****************************************************************/ + static uint32_t samr_acb_flags_to_netapi_flags(uint32_t acb) { uint32_t fl = UF_SCRIPT; /* god knows why */ -- cgit From 0b484e684ab3181eedbb1bdc18dd750c712bb16e Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 28 Aug 2008 01:01:11 +0200 Subject: netapi: add NetShareAdd skeleton. Guenther (This used to be commit 6e22bcc1f5cba9bc37ecf193bbc7e031b69134f5) --- source3/lib/netapi/libnetapi.c | 46 ++++++++++++++++++++++++++++++++++++++++++ source3/lib/netapi/libnetapi.h | 8 ++++++++ source3/lib/netapi/share.c | 43 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 97 insertions(+) create mode 100644 source3/lib/netapi/share.c (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/libnetapi.c b/source3/lib/netapi/libnetapi.c index 4b87bbcdf4..b4f2bb6ac2 100644 --- a/source3/lib/netapi/libnetapi.c +++ b/source3/lib/netapi/libnetapi.c @@ -1773,3 +1773,49 @@ NET_API_STATUS NetRemoteTOD(const char * server_name /* [in] */, return r.out.result; } +/**************************************************************** + NetShareAdd +****************************************************************/ + +NET_API_STATUS NetShareAdd(const char * server_name /* [in] */, + uint32_t level /* [in] */, + uint8_t *buffer /* [in] [ref] */, + uint32_t *parm_err /* [out] [ref] */) +{ + struct NetShareAdd r; + struct libnetapi_ctx *ctx = NULL; + NET_API_STATUS status; + WERROR werr; + + status = libnetapi_getctx(&ctx); + if (status != 0) { + return status; + } + + /* In parameters */ + r.in.server_name = server_name; + r.in.level = level; + r.in.buffer = buffer; + + /* Out parameters */ + r.out.parm_err = parm_err; + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_IN_DEBUG(NetShareAdd, &r); + } + + if (LIBNETAPI_LOCAL_SERVER(server_name)) { + werr = NetShareAdd_l(ctx, &r); + } else { + werr = NetShareAdd_r(ctx, &r); + } + + r.out.result = W_ERROR_V(werr); + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_OUT_DEBUG(NetShareAdd, &r); + } + + return r.out.result; +} + diff --git a/source3/lib/netapi/libnetapi.h b/source3/lib/netapi/libnetapi.h index 189083cc1f..9a75b396fe 100644 --- a/source3/lib/netapi/libnetapi.h +++ b/source3/lib/netapi/libnetapi.h @@ -317,4 +317,12 @@ WERROR NetRemoteTOD_r(struct libnetapi_ctx *ctx, struct NetRemoteTOD *r); WERROR NetRemoteTOD_l(struct libnetapi_ctx *ctx, struct NetRemoteTOD *r); +NET_API_STATUS NetShareAdd(const char * server_name /* [in] */, + uint32_t level /* [in] */, + uint8_t *buffer /* [in] [ref] */, + uint32_t *parm_err /* [out] [ref] */); +WERROR NetShareAdd_r(struct libnetapi_ctx *ctx, + struct NetShareAdd *r); +WERROR NetShareAdd_l(struct libnetapi_ctx *ctx, + struct NetShareAdd *r); #endif /* __LIBNETAPI_LIBNETAPI__ */ diff --git a/source3/lib/netapi/share.c b/source3/lib/netapi/share.c new file mode 100644 index 0000000000..182330b0d6 --- /dev/null +++ b/source3/lib/netapi/share.c @@ -0,0 +1,43 @@ +/* + * Unix SMB/CIFS implementation. + * NetApi Share Support + * Copyright (C) Guenther Deschner 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include "includes.h" + +#include "librpc/gen_ndr/libnetapi.h" +#include "lib/netapi/netapi.h" +#include "lib/netapi/netapi_private.h" +#include "lib/netapi/libnetapi.h" + +/**************************************************************** +****************************************************************/ + +WERROR NetShareAdd_r(struct libnetapi_ctx *ctx, + struct NetShareAdd *r) +{ + return WERR_NOT_SUPPORTED; +} + +/**************************************************************** +****************************************************************/ + +WERROR NetShareAdd_l(struct libnetapi_ctx *ctx, + struct NetShareAdd *r) +{ + LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetShareAdd); +} -- cgit From f7b293353a06b1b44e67364ad5de5cc6d4d738dd Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 28 Aug 2008 01:06:12 +0200 Subject: netapi: add NetShareAdd to public header. Guenther (This used to be commit 5a036a431f4a8c686ddcd72df476acc6befddba0) --- source3/lib/netapi/netapi.h | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h index 0c7c23b36f..95d2316c9e 100644 --- a/source3/lib/netapi/netapi.h +++ b/source3/lib/netapi/netapi.h @@ -537,6 +537,17 @@ struct TIME_OF_DAY_INFO { uint32_t tod_weekday; }; +struct SHARE_INFO_2 { + const char * shi2_netname; + uint32_t shi2_type; + const char * shi2_remark; + uint32_t shi2_permissions; + uint32_t shi2_max_uses; + uint32_t shi2_current_uses; + const char * shi2_path; + const char * shi2_passwd; +}; + #endif /* _HEADER_libnetapi */ /**************************************************************** @@ -1455,6 +1466,27 @@ NET_API_STATUS NetLocalGroupSetMembers(const char * server_name /* [in] */, NET_API_STATUS NetRemoteTOD(const char * server_name /* [in] */, uint8_t **buf /* [out] [ref] */); + +/************************************************************//** + * + * NetShareAdd + * + * @brief Add Share + * + * @param[in] server_name The server name to connect to + * @param[in] level The level defining the requested SHARE_INFO_X structure + * @param[in] buf The buffer containing a SHARE_INFO_X structure + * @param[out] parm_err The returned parameter error number if any + * @return NET_API_STATUS + * + * example share/share_add.c + ***************************************************************/ + +NET_API_STATUS NetShareAdd(const char * server_name /* [in] */, + uint32_t level /* [in] */, + uint8_t *buffer /* [in] [ref] */, + uint32_t *parm_err /* [out] [ref] */); + #ifdef __cplusplus } #endif /* __cplusplus */ -- cgit From 0e37e225fd276b6126268f83842cc271f76653b5 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 28 Aug 2008 01:02:01 +0200 Subject: netapi: implement NetShareAdd_r. Guenther (This used to be commit d430d2fbd8746c8bcdb16e027d45a939c4976524) --- source3/lib/netapi/share.c | 92 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 91 insertions(+), 1 deletion(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/share.c b/source3/lib/netapi/share.c index 182330b0d6..3b99a8d291 100644 --- a/source3/lib/netapi/share.c +++ b/source3/lib/netapi/share.c @@ -27,10 +27,100 @@ /**************************************************************** ****************************************************************/ +static NTSTATUS map_SHARE_INFO_buffer_to_srvsvc_share_info(TALLOC_CTX *mem_ctx, + uint8_t *buffer, + uint32_t level, + union srvsvc_NetShareInfo *info) +{ + struct SHARE_INFO_2 *i2 = NULL; + struct srvsvc_NetShareInfo2 *s2 = NULL; + + if (!buffer) { + return NT_STATUS_INVALID_PARAMETER; + } + + switch (level) { + case 2: + i2 = (struct SHARE_INFO_2 *)buffer; + + s2 = TALLOC_P(mem_ctx, struct srvsvc_NetShareInfo2); + NT_STATUS_HAVE_NO_MEMORY(s2); + + s2->name = i2->shi2_netname; + s2->type = i2->shi2_type; + s2->comment = i2->shi2_remark; + s2->permissions = i2->shi2_permissions; + s2->max_users = i2->shi2_max_uses; + s2->current_users = i2->shi2_current_uses; + s2->path = i2->shi2_path; + s2->password = i2->shi2_passwd; + + info->info2 = s2; + + break; + default: + return NT_STATUS_INVALID_PARAMETER; + } + + return NT_STATUS_OK; +} + +/**************************************************************** +****************************************************************/ + WERROR NetShareAdd_r(struct libnetapi_ctx *ctx, struct NetShareAdd *r) { - return WERR_NOT_SUPPORTED; + WERROR werr; + NTSTATUS status; + struct cli_state *cli = NULL; + struct rpc_pipe_client *pipe_cli = NULL; + union srvsvc_NetShareInfo info; + + if (!r->in.buffer) { + return WERR_INVALID_PARAM; + } + + switch (r->in.level) { + case 2: + break; + default: + return WERR_UNKNOWN_LEVEL; + } + + werr = libnetapi_open_pipe(ctx, r->in.server_name, + &ndr_table_srvsvc.syntax_id, + &cli, + &pipe_cli); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + status = map_SHARE_INFO_buffer_to_srvsvc_share_info(ctx, + r->in.buffer, + r->in.level, + &info); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + status = rpccli_srvsvc_NetShareAdd(pipe_cli, ctx, + r->in.server_name, + r->in.level, + &info, + r->out.parm_err, + &werr); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + done: + if (!cli) { + return werr; + } + + return werr; } /**************************************************************** -- cgit From 3b88ef3e94c14f0d4f47e756a8b996f80876d1ce Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 28 Aug 2008 01:02:42 +0200 Subject: netapi: add NetShareAdd example code. Guenther (This used to be commit 4ec041e38a7dd2d89b182ab9e03ab85a060778d3) --- source3/lib/netapi/examples/Makefile.in | 8 +- source3/lib/netapi/examples/share/share_add.c | 110 ++++++++++++++++++++++++++ 2 files changed, 117 insertions(+), 1 deletion(-) create mode 100644 source3/lib/netapi/examples/share/share_add.c (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/Makefile.in b/source3/lib/netapi/examples/Makefile.in index 4595db552d..d48457a694 100644 --- a/source3/lib/netapi/examples/Makefile.in +++ b/source3/lib/netapi/examples/Makefile.in @@ -49,7 +49,8 @@ PROGS = bin/getdc@EXEEXT@ \ bin/localgroup_delmembers@EXEEXT@ \ bin/localgroup_setmembers@EXEEXT@ \ bin/localgroup_getmembers@EXEEXT@ \ - bin/remote_tod@EXEEXT@ + bin/remote_tod@EXEEXT@ \ + bin/share_add@EXEEXT@ all: $(PROGS) @@ -111,6 +112,7 @@ LOCALGROUPDELMEMBERS_OBJ = localgroup/localgroup_delmembers.o $(CMDLINE_OBJ) LOCALGROUPSETMEMBERS_OBJ = localgroup/localgroup_setmembers.o $(CMDLINE_OBJ) LOCALGROUPGETMEMBERS_OBJ = localgroup/localgroup_getmembers.o $(CMDLINE_OBJ) REMOTETOD_OBJ = server/remote_tod.o $(CMDLINE_OBJ) +SHAREADD_OBJ = share/share_add.o $(CMDLINE_OBJ) bin/getdc@EXEEXT@: $(BINARY_PREREQS) $(GETDC_OBJ) @echo Linking $@ @@ -244,6 +246,10 @@ bin/remote_tod@EXEEXT@: $(BINARY_PREREQS) $(REMOTETOD_OBJ) @echo Linking $@ @$(CC) $(FLAGS) -o $@ $(REMOTETOD_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) +bin/share_add@EXEEXT@: $(BINARY_PREREQS) $(SHAREADD_OBJ) + @echo Linking $@ + @$(CC) $(FLAGS) -o $@ $(SHAREADD_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) + clean: -rm -f $(PROGS) -rm -f core */*~ *~ \ diff --git a/source3/lib/netapi/examples/share/share_add.c b/source3/lib/netapi/examples/share/share_add.c new file mode 100644 index 0000000000..3d7948840d --- /dev/null +++ b/source3/lib/netapi/examples/share/share_add.c @@ -0,0 +1,110 @@ +/* + * Unix SMB/CIFS implementation. + * NetShareAdd query + * Copyright (C) Guenther Deschner 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include +#include +#include +#include +#include + +#include + +#include "common.h" + +int main(int argc, const char **argv) +{ + NET_API_STATUS status; + struct libnetapi_ctx *ctx = NULL; + const char *hostname = NULL; + const char *sharename = NULL; + const char *path = NULL; + uint32_t level = 0; + uint32_t parm_err = 0; + + struct SHARE_INFO_2 i2; + + poptContext pc; + int opt; + + struct poptOption long_options[] = { + POPT_AUTOHELP + POPT_COMMON_LIBNETAPI_EXAMPLES + POPT_TABLEEND + }; + + status = libnetapi_init(&ctx); + if (status != 0) { + return status; + } + + pc = poptGetContext("share_add", argc, argv, long_options, 0); + + poptSetOtherOptionHelp(pc, "hostname sharename path"); + while((opt = poptGetNextOpt(pc)) != -1) { + } + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + hostname = poptGetArg(pc); + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + sharename = poptGetArg(pc); + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + path = poptGetArg(pc); + + if (poptPeekArg(pc)) { + level = atoi(poptGetArg(pc)); + } + + /* NetShareAdd */ + + i2.shi2_netname = sharename; + i2.shi2_type = 0; + i2.shi2_remark = "Test share created via NetApi"; + i2.shi2_permissions = 0; + i2.shi2_max_uses = (uint32_t)-1; + i2.shi2_current_uses = 0; + i2.shi2_path = path; + i2.shi2_passwd = NULL; + + status = NetShareAdd(hostname, + 2, + (uint8_t *)&i2, + &parm_err); + if (status != 0) { + printf("NetShareAdd failed with: %s\n", + libnetapi_get_error_string(ctx, status)); + goto out; + } + + out: + libnetapi_free(ctx); + poptFreeContext(pc); + + return status; +} -- cgit From 8bab11088b337f6f02e221472e1d0381d531ccf1 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 28 Aug 2008 11:57:43 +0200 Subject: netapi: prepare libnetapi_samr_lookup_user to lookup priv levels. Guenther (This used to be commit f61bf5db5ff4a1d051999712dd76788d6a113545) --- source3/lib/netapi/user.c | 64 +++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 54 insertions(+), 10 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/user.c b/source3/lib/netapi/user.c index 7f259195a5..25fb085f44 100644 --- a/source3/lib/netapi/user.c +++ b/source3/lib/netapi/user.c @@ -584,10 +584,12 @@ static NTSTATUS libnetapi_samr_lookup_user(TALLOC_CTX *mem_ctx, struct policy_handle *domain_handle, struct policy_handle *builtin_handle, const char *user_name, + const struct dom_sid *domain_sid, uint32_t rid, uint32_t level, struct samr_UserInfo21 **info21, - struct sec_desc_buf **sec_desc) + struct sec_desc_buf **sec_desc, + uint32_t *auth_flag_p) { NTSTATUS status; @@ -643,7 +645,14 @@ static NTSTATUS libnetapi_samr_lookup_user(TALLOC_CTX *mem_ctx, goto done; } - if (level == 1) { + if (access_mask & SAMR_USER_ACCESS_GET_GROUPS) { + + struct lsa_SidArray sid_array; + struct samr_Ids alias_rids; + int i; + uint32_t auth_flag = 0; + struct dom_sid sid; + status = rpccli_samr_GetGroupsForUser(pipe_cli, mem_ctx, &user_handle, &rid_array); @@ -651,15 +660,48 @@ static NTSTATUS libnetapi_samr_lookup_user(TALLOC_CTX *mem_ctx, goto done; } -#if 0 - status = rpccli_samr_GetAliasMembership(pipe_cli, ctx, - &builtin_handle, - &sids, - &rids); + sid_array.num_sids = rid_array->count + 1; + sid_array.sids = talloc_array(mem_ctx, struct lsa_SidPtr, + sid_array.num_sids); + NT_STATUS_HAVE_NO_MEMORY(sid_array.sids); + + for (i=0; icount; i++) { + sid_compose(&sid, domain_sid, rid_array->rids[i].rid); + sid_array.sids[i].sid = sid_dup_talloc(mem_ctx, &sid); + NT_STATUS_HAVE_NO_MEMORY(sid_array.sids[i].sid); + } + + sid_compose(&sid, domain_sid, rid); + sid_array.sids[i].sid = sid_dup_talloc(mem_ctx, &sid); + NT_STATUS_HAVE_NO_MEMORY(sid_array.sids[i].sid); + + status = rpccli_samr_GetAliasMembership(pipe_cli, mem_ctx, + builtin_handle, + &sid_array, + &alias_rids); if (!NT_STATUS_IS_OK(status)) { goto done; } -#endif + + for (i=0; iinfo21; @@ -717,7 +759,7 @@ static NTSTATUS libnetapi_samr_lookup_user_map_USER_INFO(TALLOC_CTX *mem_ctx, struct samr_UserInfo21 *info21 = NULL; struct sec_desc_buf *sec_desc = NULL; - struct dom_sid sid; + uint32_t auth_flag = 0; struct USER_INFO_0 info0; struct USER_INFO_10 info10; @@ -752,10 +794,12 @@ static NTSTATUS libnetapi_samr_lookup_user_map_USER_INFO(TALLOC_CTX *mem_ctx, domain_handle, builtin_handle, user_name, + domain_sid, rid, level, &info21, - &sec_desc); + &sec_desc, + &auth_flag); if (!NT_STATUS_IS_OK(status)) { goto done; -- cgit From 29b96a63f13dba707c430638a8f0ca34b5993321 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 28 Aug 2008 12:00:07 +0200 Subject: netapi: add builtin handle to NetUserEnum. Guenther (This used to be commit f71b0808bec002f616fc451eddb7e19dd242a138) --- source3/lib/netapi/user.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/user.c b/source3/lib/netapi/user.c index 25fb085f44..4e31175ebc 100644 --- a/source3/lib/netapi/user.c +++ b/source3/lib/netapi/user.c @@ -884,7 +884,7 @@ WERROR NetUserEnum_r(struct libnetapi_ctx *ctx, struct rpc_pipe_client *pipe_cli = NULL; struct policy_handle connect_handle; struct dom_sid2 *domain_sid = NULL; - struct policy_handle domain_handle; + struct policy_handle domain_handle, builtin_handle; struct samr_SamArray *sam = NULL; uint32_t filter = ACB_NORMAL; int i; @@ -895,6 +895,7 @@ WERROR NetUserEnum_r(struct libnetapi_ctx *ctx, ZERO_STRUCT(connect_handle); ZERO_STRUCT(domain_handle); + ZERO_STRUCT(builtin_handle); if (!r->out.buffer) { return WERR_INVALID_PARAM; @@ -926,6 +927,17 @@ WERROR NetUserEnum_r(struct libnetapi_ctx *ctx, goto done; } + werr = libnetapi_samr_open_builtin_domain(ctx, pipe_cli, + SAMR_ACCESS_ENUM_DOMAINS | + SAMR_ACCESS_OPEN_DOMAIN, + SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT | + SAMR_DOMAIN_ACCESS_LOOKUP_ALIAS, + &connect_handle, + &builtin_handle); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + werr = libnetapi_samr_open_domain(ctx, pipe_cli, SAMR_ACCESS_ENUM_DOMAINS | SAMR_ACCESS_OPEN_DOMAIN, @@ -977,7 +989,7 @@ WERROR NetUserEnum_r(struct libnetapi_ctx *ctx, status = libnetapi_samr_lookup_user_map_USER_INFO(ctx, pipe_cli, domain_sid, &domain_handle, - NULL, /*&builtin_handle, */ + &builtin_handle, sam->entries[i].name.string, sam->entries[i].idx, r->in.level, @@ -1000,6 +1012,7 @@ WERROR NetUserEnum_r(struct libnetapi_ctx *ctx, if (ctx->disable_policy_handle_cache) { libnetapi_samr_close_domain_handle(ctx, &domain_handle); + libnetapi_samr_close_builtin_handle(ctx, &builtin_handle); libnetapi_samr_close_connect_handle(ctx, &connect_handle); } } -- cgit From ab627f40c092fa8b1254b590203f919c05ab13d7 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 28 Aug 2008 12:05:43 +0200 Subject: netapi: add info21_to_USER_INFO_10. Guenther (This used to be commit 3e0c5d4154a730fd9e4430d3e64f9c7bb654dc54) --- source3/lib/netapi/user.c | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/user.c b/source3/lib/netapi/user.c index 4e31175ebc..8ce97bedcc 100644 --- a/source3/lib/netapi/user.c +++ b/source3/lib/netapi/user.c @@ -744,6 +744,24 @@ static uint32_t samr_acb_flags_to_netapi_flags(uint32_t acb) /**************************************************************** ****************************************************************/ +static NTSTATUS info21_to_USER_INFO_10(TALLOC_CTX *mem_ctx, + const struct samr_UserInfo21 *i21, + struct USER_INFO_10 *i) +{ + ZERO_STRUCTP(i); + + i->usri10_name = talloc_strdup(mem_ctx, i21->account_name.string); + NT_STATUS_HAVE_NO_MEMORY(i->usri10_name); + i->usri10_comment = talloc_strdup(mem_ctx, i21->description.string); + i->usri10_full_name = talloc_strdup(mem_ctx, i21->full_name.string); + i->usri10_usr_comment = talloc_strdup(mem_ctx, i21->comment.string); + + return NT_STATUS_OK; +} + +/**************************************************************** +****************************************************************/ + static NTSTATUS libnetapi_samr_lookup_user_map_USER_INFO(TALLOC_CTX *mem_ctx, struct rpc_pipe_client *pipe_cli, struct dom_sid *domain_sid, @@ -807,18 +825,8 @@ static NTSTATUS libnetapi_samr_lookup_user_map_USER_INFO(TALLOC_CTX *mem_ctx, switch (level) { case 10: - info10.usri10_name = talloc_strdup(mem_ctx, - info21->account_name.string); - NT_STATUS_HAVE_NO_MEMORY(info10.usri10_name); - - info10.usri10_comment = talloc_strdup(mem_ctx, - info21->description.string); - - info10.usri10_full_name = talloc_strdup(mem_ctx, - info21->full_name.string); - - info10.usri10_usr_comment = talloc_strdup(mem_ctx, - info21->comment.string); + status = info21_to_USER_INFO_10(mem_ctx, info21, &info10); + NT_STATUS_NOT_OK_RETURN(status); ADD_TO_ARRAY(mem_ctx, struct USER_INFO_10, info10, (struct USER_INFO_10 **)buffer, num_entries); -- cgit From f14748ee45ad54751e732a9c384951dd755d7a2b Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 28 Aug 2008 12:07:25 +0200 Subject: netapi: add info21_to_USER_INFO_20. Guenther (This used to be commit 93a5844814714cf07341bc2962dfac5c3e51d788) --- source3/lib/netapi/user.c | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/user.c b/source3/lib/netapi/user.c index 8ce97bedcc..406d8fe6b5 100644 --- a/source3/lib/netapi/user.c +++ b/source3/lib/netapi/user.c @@ -762,6 +762,25 @@ static NTSTATUS info21_to_USER_INFO_10(TALLOC_CTX *mem_ctx, /**************************************************************** ****************************************************************/ +static NTSTATUS info21_to_USER_INFO_20(TALLOC_CTX *mem_ctx, + const struct samr_UserInfo21 *i21, + struct USER_INFO_20 *i) +{ + ZERO_STRUCTP(i); + + i->usri20_name = talloc_strdup(mem_ctx, i21->account_name.string); + NT_STATUS_HAVE_NO_MEMORY(i->usri20_name); + i->usri20_comment = talloc_strdup(mem_ctx, i21->description.string); + i->usri20_full_name = talloc_strdup(mem_ctx, i21->full_name.string); + i->usri20_flags = samr_acb_flags_to_netapi_flags(i21->acct_flags); + i->usri20_user_id = i21->rid; + + return NT_STATUS_OK; +} + +/**************************************************************** +****************************************************************/ + static NTSTATUS libnetapi_samr_lookup_user_map_USER_INFO(TALLOC_CTX *mem_ctx, struct rpc_pipe_client *pipe_cli, struct dom_sid *domain_sid, @@ -834,19 +853,8 @@ static NTSTATUS libnetapi_samr_lookup_user_map_USER_INFO(TALLOC_CTX *mem_ctx, break; case 20: - info20.usri20_name = talloc_strdup(mem_ctx, - info21->account_name.string); - NT_STATUS_HAVE_NO_MEMORY(info20.usri20_name); - - info20.usri20_comment = talloc_strdup(mem_ctx, - info21->description.string); - - info20.usri20_full_name = talloc_strdup(mem_ctx, - info21->full_name.string); - - info20.usri20_flags = - samr_acb_flags_to_netapi_flags(info21->acct_flags); - info20.usri20_user_id = rid; + status = info21_to_USER_INFO_20(mem_ctx, info21, &info20); + NT_STATUS_NOT_OK_RETURN(status); ADD_TO_ARRAY(mem_ctx, struct USER_INFO_20, info20, (struct USER_INFO_20 **)buffer, num_entries); -- cgit From 2bf066b549d7b45c62b5a93776b6f5a3cd31aefe Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 28 Aug 2008 12:08:31 +0200 Subject: netapi: add info21_to_USER_INFO_23. Guenther (This used to be commit 62871cb3829f5b9cd15211030fa409dbaf3b906f) --- source3/lib/netapi/user.c | 48 ++++++++++++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 19 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/user.c b/source3/lib/netapi/user.c index 406d8fe6b5..03fea433ea 100644 --- a/source3/lib/netapi/user.c +++ b/source3/lib/netapi/user.c @@ -781,6 +781,31 @@ static NTSTATUS info21_to_USER_INFO_20(TALLOC_CTX *mem_ctx, /**************************************************************** ****************************************************************/ +static NTSTATUS info21_to_USER_INFO_23(TALLOC_CTX *mem_ctx, + const struct samr_UserInfo21 *i21, + struct dom_sid *domain_sid, + struct USER_INFO_23 *i) +{ + struct dom_sid sid; + + ZERO_STRUCTP(i); + + i->usri23_name = talloc_strdup(mem_ctx, i21->account_name.string); + NT_STATUS_HAVE_NO_MEMORY(i->usri23_name); + i->usri23_comment = talloc_strdup(mem_ctx, i21->description.string); + i->usri23_full_name = talloc_strdup(mem_ctx, i21->full_name.string); + i->usri23_flags = samr_acb_flags_to_netapi_flags(i21->acct_flags); + if (!sid_compose(&sid, domain_sid, i21->rid)) { + return NT_STATUS_NO_MEMORY; + } + i->usri23_user_sid = (struct domsid *)sid_dup_talloc(mem_ctx, &sid); + + return NT_STATUS_OK; +} + +/**************************************************************** +****************************************************************/ + static NTSTATUS libnetapi_samr_lookup_user_map_USER_INFO(TALLOC_CTX *mem_ctx, struct rpc_pipe_client *pipe_cli, struct dom_sid *domain_sid, @@ -861,29 +886,14 @@ static NTSTATUS libnetapi_samr_lookup_user_map_USER_INFO(TALLOC_CTX *mem_ctx, break; case 23: - info23.usri23_name = talloc_strdup(mem_ctx, - info21->account_name.string); - NT_STATUS_HAVE_NO_MEMORY(info23.usri23_name); - - info23.usri23_comment = talloc_strdup(mem_ctx, - info21->description.string); - - info23.usri23_full_name = talloc_strdup(mem_ctx, - info21->full_name.string); - - info23.usri23_flags = - samr_acb_flags_to_netapi_flags(info21->acct_flags); - - if (!sid_compose(&sid, domain_sid, rid)) { - return NT_STATUS_NO_MEMORY; - } - - info23.usri23_user_sid = - (struct domsid *)sid_dup_talloc(mem_ctx, &sid); + status = info21_to_USER_INFO_23(mem_ctx, info21, domain_sid, &info23); + NT_STATUS_NOT_OK_RETURN(status); ADD_TO_ARRAY(mem_ctx, struct USER_INFO_23, info23, (struct USER_INFO_23 **)buffer, num_entries); break; + default: + return NT_STATUS_INVALID_LEVEL; } done: -- cgit From d405b5061e7a4d7815b03c505434614f7dfec172 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 28 Aug 2008 12:15:23 +0200 Subject: netapi: add info21_to_USER_INFO_1 and support level 1 NetUserEnum/GetInfo. Guenther (This used to be commit 391aaf16272aad09f8e2f1b1afb78a2535c0faaf) --- source3/lib/netapi/user.c | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/user.c b/source3/lib/netapi/user.c index 03fea433ea..77c74130b7 100644 --- a/source3/lib/netapi/user.c +++ b/source3/lib/netapi/user.c @@ -604,7 +604,11 @@ static NTSTATUS libnetapi_samr_lookup_user(TALLOC_CTX *mem_ctx, switch (level) { case 0: + break; case 1: + access_mask |= SAMR_USER_ACCESS_GET_LOGONINFO | + SAMR_USER_ACCESS_GET_GROUPS; + break; case 2: case 3: case 10: @@ -744,6 +748,27 @@ static uint32_t samr_acb_flags_to_netapi_flags(uint32_t acb) /**************************************************************** ****************************************************************/ +static NTSTATUS info21_to_USER_INFO_1(TALLOC_CTX *mem_ctx, + const struct samr_UserInfo21 *i21, + struct USER_INFO_1 *i) +{ + ZERO_STRUCTP(i); + i->usri1_name = talloc_strdup(mem_ctx, i21->account_name.string); + NT_STATUS_HAVE_NO_MEMORY(i->usri1_name); + i->usri1_password = NULL; + i->usri1_password_age = time(NULL) - nt_time_to_unix(i21->last_password_change); + i->usri1_priv = samr_rid_to_priv_level(i21->rid); + i->usri1_home_dir = talloc_strdup(mem_ctx, i21->home_directory.string); + i->usri1_comment = talloc_strdup(mem_ctx, i21->description.string); + i->usri1_flags = samr_acb_flags_to_netapi_flags(i21->acct_flags); + i->usri1_script_path = talloc_strdup(mem_ctx, i21->logon_script.string); + + return NT_STATUS_OK; +} + +/**************************************************************** +****************************************************************/ + static NTSTATUS info21_to_USER_INFO_10(TALLOC_CTX *mem_ctx, const struct samr_UserInfo21 *i21, struct USER_INFO_10 *i) @@ -824,6 +849,7 @@ static NTSTATUS libnetapi_samr_lookup_user_map_USER_INFO(TALLOC_CTX *mem_ctx, uint32_t auth_flag = 0; struct USER_INFO_0 info0; + struct USER_INFO_1 info1; struct USER_INFO_10 info10; struct USER_INFO_20 info20; struct USER_INFO_23 info23; @@ -868,6 +894,17 @@ static NTSTATUS libnetapi_samr_lookup_user_map_USER_INFO(TALLOC_CTX *mem_ctx, } switch (level) { + case 0: + /* already returned above */ + break; + case 1: + status = info21_to_USER_INFO_1(mem_ctx, info21, &info1); + NT_STATUS_NOT_OK_RETURN(status); + + ADD_TO_ARRAY(mem_ctx, struct USER_INFO_1, info1, + (struct USER_INFO_1 **)buffer, num_entries); + + break; case 10: status = info21_to_USER_INFO_10(mem_ctx, info21, &info10); NT_STATUS_NOT_OK_RETURN(status); @@ -932,11 +969,11 @@ WERROR NetUserEnum_r(struct libnetapi_ctx *ctx, switch (r->in.level) { case 0: + case 1: case 10: case 20: case 23: break; - case 1: case 2: case 3: case 11: @@ -1362,11 +1399,11 @@ WERROR NetUserGetInfo_r(struct libnetapi_ctx *ctx, switch (r->in.level) { case 0: + case 1: case 10: case 20: case 23: break; - case 1: case 2: case 3: case 4: -- cgit From 0018d14eedba213626200ef41cb29380bdbc7ef0 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 28 Aug 2008 12:18:01 +0200 Subject: netapi: add info21_to_USER_INFO_2 and support level 2 in NetUserEnum/GetInfo. Guenther (This used to be commit 1f1587423b7e01be552ae7cfc89f1334b32b124a) --- source3/lib/netapi/user.c | 52 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 2 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/user.c b/source3/lib/netapi/user.c index 77c74130b7..d7ebba1215 100644 --- a/source3/lib/netapi/user.c +++ b/source3/lib/netapi/user.c @@ -769,6 +769,45 @@ static NTSTATUS info21_to_USER_INFO_1(TALLOC_CTX *mem_ctx, /**************************************************************** ****************************************************************/ +static NTSTATUS info21_to_USER_INFO_2(TALLOC_CTX *mem_ctx, + const struct samr_UserInfo21 *i21, + uint32_t auth_flag, + struct USER_INFO_2 *i) +{ + ZERO_STRUCTP(i); + + i->usri2_name = talloc_strdup(mem_ctx, i21->account_name.string); + NT_STATUS_HAVE_NO_MEMORY(i->usri2_name); + i->usri2_password = NULL; + i->usri2_password_age = time(NULL) - nt_time_to_unix(i21->last_password_change); + i->usri2_priv = samr_rid_to_priv_level(i21->rid); + i->usri2_home_dir = talloc_strdup(mem_ctx, i21->home_directory.string); + i->usri2_comment = talloc_strdup(mem_ctx, i21->description.string); + i->usri2_flags = samr_acb_flags_to_netapi_flags(i21->acct_flags); + i->usri2_script_path = talloc_strdup(mem_ctx, i21->logon_script.string); + i->usri2_auth_flags = auth_flag; + i->usri2_full_name = talloc_strdup(mem_ctx, i21->full_name.string); + i->usri2_usr_comment = talloc_strdup(mem_ctx, i21->comment.string); + i->usri2_parms = talloc_strndup(mem_ctx, (const char *)i21->parameters.array, i21->parameters.size/2); + i->usri2_workstations = talloc_strdup(mem_ctx, i21->workstations.string); + i->usri2_last_logon = nt_time_to_unix(i21->last_logon); + i->usri2_last_logoff = nt_time_to_unix(i21->last_logoff); + i->usri2_acct_expires = nt_time_to_unix(i21->acct_expiry); + i->usri2_max_storage = USER_MAXSTORAGE_UNLIMITED; /* FIXME */ + i->usri2_units_per_week = i21->logon_hours.units_per_week; + i->usri2_logon_hours = (uint8_t *)talloc_memdup(mem_ctx, i21->logon_hours.bits, 21); + i->usri2_bad_pw_count = i21->bad_password_count; + i->usri2_num_logons = i21->logon_count; + i->usri2_logon_server = talloc_strdup(mem_ctx, "\\\\*"); + i->usri2_country_code = i21->country_code; + i->usri2_code_page = i21->code_page; + + return NT_STATUS_OK; +} + +/**************************************************************** +****************************************************************/ + static NTSTATUS info21_to_USER_INFO_10(TALLOC_CTX *mem_ctx, const struct samr_UserInfo21 *i21, struct USER_INFO_10 *i) @@ -850,6 +889,7 @@ static NTSTATUS libnetapi_samr_lookup_user_map_USER_INFO(TALLOC_CTX *mem_ctx, struct USER_INFO_0 info0; struct USER_INFO_1 info1; + struct USER_INFO_2 info2; struct USER_INFO_10 info10; struct USER_INFO_20 info20; struct USER_INFO_23 info23; @@ -904,6 +944,14 @@ static NTSTATUS libnetapi_samr_lookup_user_map_USER_INFO(TALLOC_CTX *mem_ctx, ADD_TO_ARRAY(mem_ctx, struct USER_INFO_1, info1, (struct USER_INFO_1 **)buffer, num_entries); + break; + case 2: + status = info21_to_USER_INFO_2(mem_ctx, info21, auth_flag, &info2); + NT_STATUS_NOT_OK_RETURN(status); + + ADD_TO_ARRAY(mem_ctx, struct USER_INFO_2, info2, + (struct USER_INFO_2 **)buffer, num_entries); + break; case 10: status = info21_to_USER_INFO_10(mem_ctx, info21, &info10); @@ -970,11 +1018,11 @@ WERROR NetUserEnum_r(struct libnetapi_ctx *ctx, switch (r->in.level) { case 0: case 1: + case 2: case 10: case 20: case 23: break; - case 2: case 3: case 11: return WERR_NOT_SUPPORTED; @@ -1400,11 +1448,11 @@ WERROR NetUserGetInfo_r(struct libnetapi_ctx *ctx, switch (r->in.level) { case 0: case 1: + case 2: case 10: case 20: case 23: break; - case 2: case 3: case 4: case 11: -- cgit From 4c659b9340efd466c1398fb0637fc51766b09100 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 28 Aug 2008 12:20:04 +0200 Subject: netapi: add info21_to_USER_INFO_3 and support level 3 in NetUserEnum/GetInfo. Guenther (This used to be commit 6b56b70a47823ab482f0c2a5fb55a759857b99f0) --- source3/lib/netapi/user.c | 56 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 54 insertions(+), 2 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/user.c b/source3/lib/netapi/user.c index d7ebba1215..acbd36c599 100644 --- a/source3/lib/netapi/user.c +++ b/source3/lib/netapi/user.c @@ -808,6 +808,49 @@ static NTSTATUS info21_to_USER_INFO_2(TALLOC_CTX *mem_ctx, /**************************************************************** ****************************************************************/ +static NTSTATUS info21_to_USER_INFO_3(TALLOC_CTX *mem_ctx, + const struct samr_UserInfo21 *i21, + uint32_t auth_flag, + struct USER_INFO_3 *i) +{ + ZERO_STRUCTP(i); + + i->usri3_name = talloc_strdup(mem_ctx, i21->account_name.string); + NT_STATUS_HAVE_NO_MEMORY(i->usri3_name); + i->usri3_password_age = time(NULL) - nt_time_to_unix(i21->last_password_change); + i->usri3_priv = samr_rid_to_priv_level(i21->rid); + i->usri3_home_dir = talloc_strdup(mem_ctx, i21->home_directory.string); + i->usri3_comment = talloc_strdup(mem_ctx, i21->description.string); + i->usri3_flags = samr_acb_flags_to_netapi_flags(i21->acct_flags); + i->usri3_script_path = talloc_strdup(mem_ctx, i21->logon_script.string); + i->usri3_auth_flags = auth_flag; + i->usri3_full_name = talloc_strdup(mem_ctx, i21->full_name.string); + i->usri3_usr_comment = talloc_strdup(mem_ctx, i21->comment.string); + i->usri3_parms = talloc_strndup(mem_ctx, (const char *)i21->parameters.array, i21->parameters.size/2); + i->usri3_workstations = talloc_strdup(mem_ctx, i21->workstations.string); + i->usri3_last_logon = nt_time_to_unix(i21->last_logon); + i->usri3_last_logoff = nt_time_to_unix(i21->last_logoff); + i->usri3_acct_expires = nt_time_to_unix(i21->acct_expiry); + i->usri3_max_storage = USER_MAXSTORAGE_UNLIMITED; /* FIXME */ + i->usri3_units_per_week = i21->logon_hours.units_per_week; + i->usri3_logon_hours = (uint8_t *)talloc_memdup(mem_ctx, i21->logon_hours.bits, 21); + i->usri3_bad_pw_count = i21->bad_password_count; + i->usri3_num_logons = i21->logon_count; + i->usri3_logon_server = talloc_strdup(mem_ctx, "\\\\*"); + i->usri3_country_code = i21->country_code; + i->usri3_code_page = i21->code_page; + i->usri3_user_id = i21->rid; + i->usri3_primary_group_id = i21->primary_gid; + i->usri3_profile = talloc_strdup(mem_ctx, i21->profile_path.string); + i->usri3_home_dir_drive = talloc_strdup(mem_ctx, i21->home_drive.string); + i->usri3_password_expired = i21->password_expired; + + return NT_STATUS_OK; +} + +/**************************************************************** +****************************************************************/ + static NTSTATUS info21_to_USER_INFO_10(TALLOC_CTX *mem_ctx, const struct samr_UserInfo21 *i21, struct USER_INFO_10 *i) @@ -890,6 +933,7 @@ static NTSTATUS libnetapi_samr_lookup_user_map_USER_INFO(TALLOC_CTX *mem_ctx, struct USER_INFO_0 info0; struct USER_INFO_1 info1; struct USER_INFO_2 info2; + struct USER_INFO_3 info3; struct USER_INFO_10 info10; struct USER_INFO_20 info20; struct USER_INFO_23 info23; @@ -952,6 +996,14 @@ static NTSTATUS libnetapi_samr_lookup_user_map_USER_INFO(TALLOC_CTX *mem_ctx, ADD_TO_ARRAY(mem_ctx, struct USER_INFO_2, info2, (struct USER_INFO_2 **)buffer, num_entries); + break; + case 3: + status = info21_to_USER_INFO_3(mem_ctx, info21, auth_flag, &info3); + NT_STATUS_NOT_OK_RETURN(status); + + ADD_TO_ARRAY(mem_ctx, struct USER_INFO_3, info3, + (struct USER_INFO_3 **)buffer, num_entries); + break; case 10: status = info21_to_USER_INFO_10(mem_ctx, info21, &info10); @@ -1019,11 +1071,11 @@ WERROR NetUserEnum_r(struct libnetapi_ctx *ctx, case 0: case 1: case 2: + case 3: case 10: case 20: case 23: break; - case 3: case 11: return WERR_NOT_SUPPORTED; default: @@ -1449,11 +1501,11 @@ WERROR NetUserGetInfo_r(struct libnetapi_ctx *ctx, case 0: case 1: case 2: + case 3: case 10: case 20: case 23: break; - case 3: case 4: case 11: werr = WERR_NOT_SUPPORTED; -- cgit From 038404a2b5268586f11927d9be7b3b411a008165 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 28 Aug 2008 12:21:13 +0200 Subject: netapi: add info21_to_USER_INFO_4 and support level 4 in NetUserEnum/GetInfo. Guenther (This used to be commit b3ccc9a447c380e2898606b8f392f8bec9f40dc9) --- source3/lib/netapi/user.c | 70 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 68 insertions(+), 2 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/user.c b/source3/lib/netapi/user.c index acbd36c599..1584a28be0 100644 --- a/source3/lib/netapi/user.c +++ b/source3/lib/netapi/user.c @@ -611,8 +611,13 @@ static NTSTATUS libnetapi_samr_lookup_user(TALLOC_CTX *mem_ctx, break; case 2: case 3: - case 10: + case 4: case 11: + access_mask |= SAMR_USER_ACCESS_GET_LOGONINFO | + SAMR_USER_ACCESS_GET_GROUPS | + SAMR_USER_ACCESS_GET_LOCALE; + break; + case 10: case 20: case 23: break; @@ -851,6 +856,56 @@ static NTSTATUS info21_to_USER_INFO_3(TALLOC_CTX *mem_ctx, /**************************************************************** ****************************************************************/ +static NTSTATUS info21_to_USER_INFO_4(TALLOC_CTX *mem_ctx, + const struct samr_UserInfo21 *i21, + uint32_t auth_flag, + struct dom_sid *domain_sid, + struct USER_INFO_4 *i) +{ + struct dom_sid sid; + + ZERO_STRUCTP(i); + + i->usri4_name = talloc_strdup(mem_ctx, i21->account_name.string); + NT_STATUS_HAVE_NO_MEMORY(i->usri4_name); + i->usri4_password_age = time(NULL) - nt_time_to_unix(i21->last_password_change); + i->usri4_password = NULL; + i->usri4_priv = samr_rid_to_priv_level(i21->rid); + i->usri4_home_dir = talloc_strdup(mem_ctx, i21->home_directory.string); + i->usri4_comment = talloc_strdup(mem_ctx, i21->description.string); + i->usri4_flags = samr_acb_flags_to_netapi_flags(i21->acct_flags); + i->usri4_script_path = talloc_strdup(mem_ctx, i21->logon_script.string); + i->usri4_auth_flags = auth_flag; + i->usri4_full_name = talloc_strdup(mem_ctx, i21->full_name.string); + i->usri4_usr_comment = talloc_strdup(mem_ctx, i21->comment.string); + i->usri4_parms = talloc_strndup(mem_ctx, (const char *)i21->parameters.array, i21->parameters.size/2); + i->usri4_workstations = talloc_strdup(mem_ctx, i21->workstations.string); + i->usri4_last_logon = nt_time_to_unix(i21->last_logon); + i->usri4_last_logoff = nt_time_to_unix(i21->last_logoff); + i->usri4_acct_expires = nt_time_to_unix(i21->acct_expiry); + i->usri4_max_storage = USER_MAXSTORAGE_UNLIMITED; /* FIXME */ + i->usri4_units_per_week = i21->logon_hours.units_per_week; + i->usri4_logon_hours = (uint8_t *)talloc_memdup(mem_ctx, i21->logon_hours.bits, 21); + i->usri4_bad_pw_count = i21->bad_password_count; + i->usri4_num_logons = i21->logon_count; + i->usri4_logon_server = talloc_strdup(mem_ctx, "\\\\*"); + i->usri4_country_code = i21->country_code; + i->usri4_code_page = i21->code_page; + if (!sid_compose(&sid, domain_sid, i21->rid)) { + return NT_STATUS_NO_MEMORY; + } + i->usri4_user_sid = (struct domsid *)sid_dup_talloc(mem_ctx, &sid); + i->usri4_primary_group_id = i21->primary_gid; + i->usri4_profile = talloc_strdup(mem_ctx, i21->profile_path.string); + i->usri4_home_dir_drive = talloc_strdup(mem_ctx, i21->home_drive.string); + i->usri4_password_expired = i21->password_expired; + + return NT_STATUS_OK; +} + +/**************************************************************** +****************************************************************/ + static NTSTATUS info21_to_USER_INFO_10(TALLOC_CTX *mem_ctx, const struct samr_UserInfo21 *i21, struct USER_INFO_10 *i) @@ -934,6 +989,7 @@ static NTSTATUS libnetapi_samr_lookup_user_map_USER_INFO(TALLOC_CTX *mem_ctx, struct USER_INFO_1 info1; struct USER_INFO_2 info2; struct USER_INFO_3 info3; + struct USER_INFO_4 info4; struct USER_INFO_10 info10; struct USER_INFO_20 info20; struct USER_INFO_23 info23; @@ -943,6 +999,7 @@ static NTSTATUS libnetapi_samr_lookup_user_map_USER_INFO(TALLOC_CTX *mem_ctx, case 1: case 2: case 3: + case 4: case 10: case 11: case 20: @@ -1004,6 +1061,14 @@ static NTSTATUS libnetapi_samr_lookup_user_map_USER_INFO(TALLOC_CTX *mem_ctx, ADD_TO_ARRAY(mem_ctx, struct USER_INFO_3, info3, (struct USER_INFO_3 **)buffer, num_entries); + break; + case 4: + status = info21_to_USER_INFO_4(mem_ctx, info21, auth_flag, domain_sid, &info4); + NT_STATUS_NOT_OK_RETURN(status); + + ADD_TO_ARRAY(mem_ctx, struct USER_INFO_4, info4, + (struct USER_INFO_4 **)buffer, num_entries); + break; case 10: status = info21_to_USER_INFO_10(mem_ctx, info21, &info10); @@ -1072,6 +1137,7 @@ WERROR NetUserEnum_r(struct libnetapi_ctx *ctx, case 1: case 2: case 3: + case 4: case 10: case 20: case 23: @@ -1502,11 +1568,11 @@ WERROR NetUserGetInfo_r(struct libnetapi_ctx *ctx, case 1: case 2: case 3: + case 4: case 10: case 20: case 23: break; - case 4: case 11: werr = WERR_NOT_SUPPORTED; goto done; -- cgit From 5dd07500635f399b117389238d226a521a224ef9 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 28 Aug 2008 12:22:19 +0200 Subject: netapi: add info21_to_USER_INFO_11 and support level 11 in NetUserEnum/GetInfo. Guenther (This used to be commit c022ec38521e7ff655fc12807fcfd0e4f056e18b) --- source3/lib/netapi/user.c | 50 ++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 45 insertions(+), 5 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/user.c b/source3/lib/netapi/user.c index 1584a28be0..ae8d2ecd89 100644 --- a/source3/lib/netapi/user.c +++ b/source3/lib/netapi/user.c @@ -924,6 +924,41 @@ static NTSTATUS info21_to_USER_INFO_10(TALLOC_CTX *mem_ctx, /**************************************************************** ****************************************************************/ +static NTSTATUS info21_to_USER_INFO_11(TALLOC_CTX *mem_ctx, + const struct samr_UserInfo21 *i21, + uint32_t auth_flag, + struct USER_INFO_11 *i) +{ + ZERO_STRUCTP(i); + + i->usri11_name = talloc_strdup(mem_ctx, i21->account_name.string); + NT_STATUS_HAVE_NO_MEMORY(i->usri11_name); + i->usri11_comment = talloc_strdup(mem_ctx, i21->description.string); + i->usri11_usr_comment = talloc_strdup(mem_ctx, i21->comment.string); + i->usri11_full_name = talloc_strdup(mem_ctx, i21->full_name.string); + i->usri11_priv = samr_rid_to_priv_level(i21->rid); + i->usri11_auth_flags = auth_flag; + i->usri11_password_age = time(NULL) - nt_time_to_unix(i21->last_password_change); + i->usri11_home_dir = talloc_strdup(mem_ctx, i21->home_directory.string); + i->usri11_parms = talloc_strndup(mem_ctx, (const char *)i21->parameters.array, i21->parameters.size/2); + i->usri11_last_logon = nt_time_to_unix(i21->last_logon); + i->usri11_last_logoff = nt_time_to_unix(i21->last_logoff); + i->usri11_bad_pw_count = i21->bad_password_count; + i->usri11_num_logons = i21->logon_count; + i->usri11_logon_server = talloc_strdup(mem_ctx, "\\\\*"); + i->usri11_country_code = i21->country_code; + i->usri11_workstations = talloc_strdup(mem_ctx, i21->workstations.string); + i->usri11_max_storage = USER_MAXSTORAGE_UNLIMITED; /* FIXME */ + i->usri11_units_per_week = i21->logon_hours.units_per_week; + i->usri11_logon_hours = (uint8_t *)talloc_memdup(mem_ctx, i21->logon_hours.bits, 21); + i->usri11_code_page = i21->code_page; + + return NT_STATUS_OK; +} + +/**************************************************************** +****************************************************************/ + static NTSTATUS info21_to_USER_INFO_20(TALLOC_CTX *mem_ctx, const struct samr_UserInfo21 *i21, struct USER_INFO_20 *i) @@ -991,6 +1026,7 @@ static NTSTATUS libnetapi_samr_lookup_user_map_USER_INFO(TALLOC_CTX *mem_ctx, struct USER_INFO_3 info3; struct USER_INFO_4 info4; struct USER_INFO_10 info10; + struct USER_INFO_11 info11; struct USER_INFO_20 info20; struct USER_INFO_23 info23; @@ -1078,7 +1114,14 @@ static NTSTATUS libnetapi_samr_lookup_user_map_USER_INFO(TALLOC_CTX *mem_ctx, (struct USER_INFO_10 **)buffer, num_entries); break; + case 11: + status = info21_to_USER_INFO_11(mem_ctx, info21, auth_flag, &info11); + NT_STATUS_NOT_OK_RETURN(status); + + ADD_TO_ARRAY(mem_ctx, struct USER_INFO_11, info11, + (struct USER_INFO_11 **)buffer, num_entries); + break; case 20: status = info21_to_USER_INFO_20(mem_ctx, info21, &info20); NT_STATUS_NOT_OK_RETURN(status); @@ -1139,11 +1182,10 @@ WERROR NetUserEnum_r(struct libnetapi_ctx *ctx, case 3: case 4: case 10: + case 11: case 20: case 23: break; - case 11: - return WERR_NOT_SUPPORTED; default: return WERR_UNKNOWN_LEVEL; } @@ -1570,12 +1612,10 @@ WERROR NetUserGetInfo_r(struct libnetapi_ctx *ctx, case 3: case 4: case 10: + case 11: case 20: case 23: break; - case 11: - werr = WERR_NOT_SUPPORTED; - goto done; default: werr = WERR_UNKNOWN_LEVEL; goto done; -- cgit From 57fe0182d3a17c1b61e969e8842b891c362c12f2 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 29 Aug 2008 12:46:38 +0200 Subject: netapi: add NetJoinFlags to public header. Guenther (This used to be commit 3babf758f49d6b08af8bd41c1dc8bd8de11a3893) --- source3/lib/netapi/netapi.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h index 95d2316c9e..05c702cb3f 100644 --- a/source3/lib/netapi/netapi.h +++ b/source3/lib/netapi/netapi.h @@ -75,6 +75,20 @@ struct DOMAIN_CONTROLLER_INFO { const char * client_site_name; }; +/* bitmap NetJoinFlags */ +#define NETSETUP_JOIN_DOMAIN ( 0x00000001 ) +#define NETSETUP_ACCT_CREATE ( 0x00000002 ) +#define NETSETUP_ACCT_DELETE ( 0x00000004 ) +#define NETSETUP_WIN9X_UPGRADE ( 0x00000010 ) +#define NETSETUP_DOMAIN_JOIN_IF_JOINED ( 0x00000020 ) +#define NETSETUP_JOIN_UNSECURE ( 0x00000040 ) +#define NETSETUP_MACHINE_PWD_PASSED ( 0x00000080 ) +#define NETSETUP_DEFER_SPN_SET ( 0x00000100 ) +#define NETSETUP_JOIN_DC_ACCOUNT ( 0x00000200 ) +#define NETSETUP_JOIN_WITH_NEW_NAME ( 0x00000400 ) +#define NETSETUP_INSTALL_INVOCATION ( 0x00040000 ) +#define NETSETUP_IGNORE_UNSUPPORTED_FLAGS ( 0x10000000 ) + #define FILTER_TEMP_DUPLICATE_ACCOUNT ( 0x0001 ) #define FILTER_NORMAL_ACCOUNT ( 0x0002 ) #define FILTER_INTERDOMAIN_TRUST_ACCOUNT ( 0x0008 ) -- cgit From e710a871776eee47642ef828fd04cb0a46e43d2a Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 29 Aug 2008 12:52:23 +0200 Subject: netapi: use NETSETUP join flags in examples. Guenther (This used to be commit 2f6f888d9cf89abf55767dc43a9e3d5de68bbcfb) --- .../lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c | 15 +++++---------- source3/lib/netapi/examples/netdomjoin/netdomjoin.c | 4 +++- 2 files changed, 8 insertions(+), 11 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c index 418b9c8b8e..970f8cf9f2 100644 --- a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c +++ b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c @@ -38,11 +38,6 @@ #define SAMBA_IMAGE_PATH "/usr/share/pixmaps/samba/logo.png" #define SAMBA_IMAGE_PATH_SMALL "/usr/share/pixmaps/samba/logo-small.png" -#define WKSSVC_JOIN_FLAGS_DOMAIN_JOIN_IF_JOINED ( 0x00000020 ) -#define WKSSVC_JOIN_FLAGS_ACCOUNT_DELETE ( 0x00000004 ) -#define WKSSVC_JOIN_FLAGS_ACCOUNT_CREATE ( 0x00000002 ) -#define WKSSVC_JOIN_FLAGS_JOIN_TYPE ( 0x00000001 ) - #define NetSetupWorkgroupName ( 2 ) #define NetSetupDomainName ( 3 ) @@ -631,9 +626,9 @@ static void callback_do_join(GtkWidget *widget, if (state->name_type_new == NetSetupDomainName) { domain_join = TRUE; join_creds_required = TRUE; - join_flags = WKSSVC_JOIN_FLAGS_JOIN_TYPE | - WKSSVC_JOIN_FLAGS_ACCOUNT_CREATE | - WKSSVC_JOIN_FLAGS_DOMAIN_JOIN_IF_JOINED; /* for testing */ + join_flags = NETSETUP_JOIN_DOMAIN | + NETSETUP_ACCT_CREATE | + NETSETUP_DOMAIN_JOIN_IF_JOINED; /* for testing */ } if ((state->name_type_initial == NetSetupDomainName) && @@ -641,8 +636,8 @@ static void callback_do_join(GtkWidget *widget, try_unjoin = TRUE; unjoin_creds_required = TRUE; join_creds_required = FALSE; - unjoin_flags = WKSSVC_JOIN_FLAGS_JOIN_TYPE | - WKSSVC_JOIN_FLAGS_ACCOUNT_DELETE; + unjoin_flags = NETSETUP_JOIN_DOMAIN | + NETSETUP_ACCT_DELETE; } if (try_unjoin) { diff --git a/source3/lib/netapi/examples/netdomjoin/netdomjoin.c b/source3/lib/netapi/examples/netdomjoin/netdomjoin.c index bd7c36382a..08ce71b938 100644 --- a/source3/lib/netapi/examples/netdomjoin/netdomjoin.c +++ b/source3/lib/netapi/examples/netdomjoin/netdomjoin.c @@ -39,7 +39,9 @@ int main(int argc, const char **argv) const char *account_ou = NULL; const char *account = NULL; const char *password = NULL; - uint32_t join_flags = 0x00000023; + uint32_t join_flags = NETSETUP_JOIN_DOMAIN | + NETSETUP_ACCT_CREATE | + NETSETUP_DOMAIN_JOIN_IF_JOINED; struct libnetapi_ctx *ctx = NULL; poptContext pc; -- cgit From af1db71c1446c854385de691781e5bb48ec65936 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 29 Aug 2008 12:59:56 +0200 Subject: netapi: fix some warnings in netdomjoin-gui. Guenther (This used to be commit e69eb09c1819eb4ea4bba7c3b3b0f8b6da789632) --- .../examples/netdomjoin-gui/netdomjoin-gui.c | 28 +++++++++++++++------- 1 file changed, 20 insertions(+), 8 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c index 970f8cf9f2..4e0488ed59 100644 --- a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c +++ b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c @@ -818,9 +818,13 @@ static void callback_enter_hostname_and_unlock(GtkWidget *widget, } state->hostname_changed = TRUE; if (state->name_type_initial == NetSetupDomainName) { - asprintf(&str, "%s.%s", entry_text, state->my_dnsdomain); + if (asprintf(&str, "%s.%s", entry_text, state->my_dnsdomain) == -1) { + return; + } } else { - asprintf(&str, "%s.", entry_text); + if (asprintf(&str, "%s.", entry_text) == -1) { + return; + } } gtk_label_set_text(GTK_LABEL(state->label_full_computer_name), str); free(str); @@ -1127,10 +1131,14 @@ static void callback_do_change(GtkWidget *widget, char *str = NULL; entry_text = gtk_entry_get_text(GTK_ENTRY(entry)); if (state->name_type_initial == NetSetupDomainName) { - asprintf(&str, "%s.%s", entry_text, - state->my_dnsdomain); + if (asprintf(&str, "%s.%s", entry_text, + state->my_dnsdomain) == -1) { + return; + } } else { - asprintf(&str, "%s.", entry_text); + if (asprintf(&str, "%s.", entry_text) == -1) { + return; + } } gtk_label_set_text(GTK_LABEL(state->label_full_computer_name), str); @@ -1431,10 +1439,14 @@ static int draw_main_window(struct join_state *state) /* Label */ char *str = NULL; if (state->name_type_initial == NetSetupDomainName) { - asprintf(&str, "%s.%s", state->my_hostname, - state->my_dnsdomain); + if (asprintf(&str, "%s.%s", state->my_hostname, + state->my_dnsdomain) == -1) { + return -1; + } } else { - asprintf(&str, "%s.", state->my_hostname); + if (asprintf(&str, "%s.", state->my_hostname) == -1) { + return -1; + } } label = gtk_label_new(str); -- cgit From c5a9348f1953f5801c219231a46c90c23a427b81 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 29 Aug 2008 13:31:55 +0200 Subject: netapi: fix NetGetJoinableOUs_l. It needs to try the dns domain name for the ads connection. Guenther (This used to be commit 918eae8221bb8c24084cad96556e4d8c3685e314) --- source3/lib/netapi/joindomain.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/joindomain.c b/source3/lib/netapi/joindomain.c index 2a6fc80ca3..17ea3923fe 100644 --- a/source3/lib/netapi/joindomain.c +++ b/source3/lib/netapi/joindomain.c @@ -364,7 +364,7 @@ WERROR NetGetJoinableOUs_l(struct libnetapi_ctx *ctx, dc = strip_hostname(info->dc_unc); - ads = ads_init(r->in.domain, r->in.domain, dc); + ads = ads_init(info->domain_name, info->domain_name, dc); if (!ads) { return WERR_GENERAL_FAILURE; } -- cgit From 7850c90d2d3c38a7b22e63d3d85e0bd31af1620d Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 4 Sep 2008 20:23:39 +0200 Subject: netapi: fix return code in NetShareAdd_r. Guenther (This used to be commit 69e6532e9d3fad9d1c55e33cf5f120ca8b4b8d51) --- source3/lib/netapi/share.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/share.c b/source3/lib/netapi/share.c index 3b99a8d291..9983471328 100644 --- a/source3/lib/netapi/share.c +++ b/source3/lib/netapi/share.c @@ -84,6 +84,9 @@ WERROR NetShareAdd_r(struct libnetapi_ctx *ctx, switch (r->in.level) { case 2: break; + case 502: + case 503: + return WERR_NOT_SUPPORTED; default: return WERR_UNKNOWN_LEVEL; } -- cgit From 6d310cb1d3b550295da386f8fa7a0036fb8e6ef2 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 29 Aug 2008 18:34:28 +0200 Subject: netapi: add NetShareDel skeleton. Guenther (This used to be commit 5b6e4740ea8b8fdfcbd766099a7c5044abbfddde) --- source3/lib/netapi/libnetapi.c | 44 ++++++++++++++++++++++++++++++++++++++++++ source3/lib/netapi/libnetapi.h | 7 +++++++ source3/lib/netapi/share.c | 19 ++++++++++++++++++ 3 files changed, 70 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/libnetapi.c b/source3/lib/netapi/libnetapi.c index b4f2bb6ac2..5ff7db0f7f 100644 --- a/source3/lib/netapi/libnetapi.c +++ b/source3/lib/netapi/libnetapi.c @@ -1819,3 +1819,47 @@ NET_API_STATUS NetShareAdd(const char * server_name /* [in] */, return r.out.result; } +/**************************************************************** + NetShareDel +****************************************************************/ + +NET_API_STATUS NetShareDel(const char * server_name /* [in] */, + const char * net_name /* [in] */, + uint32_t reserved /* [in] */) +{ + struct NetShareDel r; + struct libnetapi_ctx *ctx = NULL; + NET_API_STATUS status; + WERROR werr; + + status = libnetapi_getctx(&ctx); + if (status != 0) { + return status; + } + + /* In parameters */ + r.in.server_name = server_name; + r.in.net_name = net_name; + r.in.reserved = reserved; + + /* Out parameters */ + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_IN_DEBUG(NetShareDel, &r); + } + + if (LIBNETAPI_LOCAL_SERVER(server_name)) { + werr = NetShareDel_l(ctx, &r); + } else { + werr = NetShareDel_r(ctx, &r); + } + + r.out.result = W_ERROR_V(werr); + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_OUT_DEBUG(NetShareDel, &r); + } + + return r.out.result; +} + diff --git a/source3/lib/netapi/libnetapi.h b/source3/lib/netapi/libnetapi.h index 9a75b396fe..b20f465f63 100644 --- a/source3/lib/netapi/libnetapi.h +++ b/source3/lib/netapi/libnetapi.h @@ -325,4 +325,11 @@ WERROR NetShareAdd_r(struct libnetapi_ctx *ctx, struct NetShareAdd *r); WERROR NetShareAdd_l(struct libnetapi_ctx *ctx, struct NetShareAdd *r); +NET_API_STATUS NetShareDel(const char * server_name /* [in] */, + const char * net_name /* [in] */, + uint32_t reserved /* [in] */); +WERROR NetShareDel_r(struct libnetapi_ctx *ctx, + struct NetShareDel *r); +WERROR NetShareDel_l(struct libnetapi_ctx *ctx, + struct NetShareDel *r); #endif /* __LIBNETAPI_LIBNETAPI__ */ diff --git a/source3/lib/netapi/share.c b/source3/lib/netapi/share.c index 9983471328..1532b477e5 100644 --- a/source3/lib/netapi/share.c +++ b/source3/lib/netapi/share.c @@ -134,3 +134,22 @@ WERROR NetShareAdd_l(struct libnetapi_ctx *ctx, { LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetShareAdd); } + +/**************************************************************** +****************************************************************/ + +WERROR NetShareDel_r(struct libnetapi_ctx *ctx, + struct NetShareDel *r) +{ + return WERR_NOT_SUPPORTED; +} + +/**************************************************************** +****************************************************************/ + +WERROR NetShareDel_l(struct libnetapi_ctx *ctx, + struct NetShareDel *r) +{ + LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetShareDel); +} + -- cgit From e51de3e502fed7b932e43f115f7c1cdabfd576e3 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 29 Aug 2008 18:35:48 +0200 Subject: netapi: add NetShareDel to public header. Guenther (This used to be commit 3ac8f83fcd9f92fe944de8c094d6aa6bda9074dc) --- source3/lib/netapi/netapi.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h index 05c702cb3f..89665371a0 100644 --- a/source3/lib/netapi/netapi.h +++ b/source3/lib/netapi/netapi.h @@ -1501,6 +1501,24 @@ NET_API_STATUS NetShareAdd(const char * server_name /* [in] */, uint8_t *buffer /* [in] [ref] */, uint32_t *parm_err /* [out] [ref] */); +/************************************************************//** + * + * NetShareDel + * + * @brief Delete Share + * + * @param[in] server_name The server name to connect to + * @param[in] net_name The name of the share to delete + * @param[in] reserved + * @return NET_API_STATUS + * + * example share/share_del.c + ***************************************************************/ + +NET_API_STATUS NetShareDel(const char * server_name /* [in] */, + const char * net_name /* [in] */, + uint32_t reserved /* [in] */); + #ifdef __cplusplus } #endif /* __cplusplus */ -- cgit From 37704001bb36de3f2715d73cd2ddfaf27e4ee04e Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 29 Aug 2008 18:38:01 +0200 Subject: netapi: add NetShareDel example code. Guenther (This used to be commit 0962128a54980b4b699ef8f80583ed2e7e12fbb0) --- source3/lib/netapi/examples/Makefile.in | 8 ++- source3/lib/netapi/examples/share/share_del.c | 85 +++++++++++++++++++++++++++ 2 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 source3/lib/netapi/examples/share/share_del.c (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/Makefile.in b/source3/lib/netapi/examples/Makefile.in index d48457a694..74cbf322d8 100644 --- a/source3/lib/netapi/examples/Makefile.in +++ b/source3/lib/netapi/examples/Makefile.in @@ -50,7 +50,8 @@ PROGS = bin/getdc@EXEEXT@ \ bin/localgroup_setmembers@EXEEXT@ \ bin/localgroup_getmembers@EXEEXT@ \ bin/remote_tod@EXEEXT@ \ - bin/share_add@EXEEXT@ + bin/share_add@EXEEXT@ \ + bin/share_del@EXEEXT@ all: $(PROGS) @@ -113,6 +114,7 @@ LOCALGROUPSETMEMBERS_OBJ = localgroup/localgroup_setmembers.o $(CMDLINE_OBJ) LOCALGROUPGETMEMBERS_OBJ = localgroup/localgroup_getmembers.o $(CMDLINE_OBJ) REMOTETOD_OBJ = server/remote_tod.o $(CMDLINE_OBJ) SHAREADD_OBJ = share/share_add.o $(CMDLINE_OBJ) +SHAREDEL_OBJ = share/share_del.o $(CMDLINE_OBJ) bin/getdc@EXEEXT@: $(BINARY_PREREQS) $(GETDC_OBJ) @echo Linking $@ @@ -250,6 +252,10 @@ bin/share_add@EXEEXT@: $(BINARY_PREREQS) $(SHAREADD_OBJ) @echo Linking $@ @$(CC) $(FLAGS) -o $@ $(SHAREADD_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) +bin/share_del@EXEEXT@: $(BINARY_PREREQS) $(SHAREDEL_OBJ) + @echo Linking $@ + @$(CC) $(FLAGS) -o $@ $(SHAREDEL_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) + clean: -rm -f $(PROGS) -rm -f core */*~ *~ \ diff --git a/source3/lib/netapi/examples/share/share_del.c b/source3/lib/netapi/examples/share/share_del.c new file mode 100644 index 0000000000..20e3ce5a8b --- /dev/null +++ b/source3/lib/netapi/examples/share/share_del.c @@ -0,0 +1,85 @@ +/* + * Unix SMB/CIFS implementation. + * NetShareDel query + * Copyright (C) Guenther Deschner 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include +#include +#include +#include +#include + +#include + +#include "common.h" + +int main(int argc, const char **argv) +{ + NET_API_STATUS status; + struct libnetapi_ctx *ctx = NULL; + const char *hostname = NULL; + const char *sharename = NULL; + + poptContext pc; + int opt; + + struct poptOption long_options[] = { + POPT_AUTOHELP + POPT_COMMON_LIBNETAPI_EXAMPLES + POPT_TABLEEND + }; + + status = libnetapi_init(&ctx); + if (status != 0) { + return status; + } + + pc = poptGetContext("share_del", argc, argv, long_options, 0); + + poptSetOtherOptionHelp(pc, "hostname sharename"); + while((opt = poptGetNextOpt(pc)) != -1) { + } + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + hostname = poptGetArg(pc); + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + sharename = poptGetArg(pc); + + /* NetShareDel */ + + status = NetShareDel(hostname, + sharename, + 0); + if (status != 0) { + printf("NetShareDel failed with: %s\n", + libnetapi_get_error_string(ctx, status)); + goto out; + } + + out: + libnetapi_free(ctx); + poptFreeContext(pc); + + return status; +} -- cgit From 148dd3b820f754bd7f0394ace19dff983babcf2d Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 29 Aug 2008 18:49:35 +0200 Subject: netapi: implement NetShareDel_r. Guenther (This used to be commit 47bed6f112dbcc509ce6ac593c9920d98b658f9a) --- source3/lib/netapi/share.c | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/share.c b/source3/lib/netapi/share.c index 1532b477e5..2c796046df 100644 --- a/source3/lib/netapi/share.c +++ b/source3/lib/netapi/share.c @@ -141,7 +141,38 @@ WERROR NetShareAdd_l(struct libnetapi_ctx *ctx, WERROR NetShareDel_r(struct libnetapi_ctx *ctx, struct NetShareDel *r) { - return WERR_NOT_SUPPORTED; + WERROR werr; + NTSTATUS status; + struct cli_state *cli = NULL; + struct rpc_pipe_client *pipe_cli = NULL; + + if (!r->in.net_name) { + return WERR_INVALID_PARAM; + } + + werr = libnetapi_open_pipe(ctx, r->in.server_name, + &ndr_table_srvsvc.syntax_id, + &cli, + &pipe_cli); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + status = rpccli_srvsvc_NetShareDel(pipe_cli, ctx, + r->in.server_name, + r->in.net_name, + r->in.reserved, + &werr); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + done: + if (!cli) { + return werr; + } + + return werr; } /**************************************************************** -- cgit From d7b966714b2851c011845be50945796fddd3769f Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 4 Sep 2008 16:46:36 +0200 Subject: netapi: add new SHARE_INFO structs to public header. Guenther (This used to be commit 30b99eb7e18ba274299ef37e3883154b35d6f2dc) --- source3/lib/netapi/netapi.h | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h index 89665371a0..856791807a 100644 --- a/source3/lib/netapi/netapi.h +++ b/source3/lib/netapi/netapi.h @@ -551,6 +551,16 @@ struct TIME_OF_DAY_INFO { uint32_t tod_weekday; }; +struct SHARE_INFO_0 { + const char * shi0_netname; +}; + +struct SHARE_INFO_1 { + const char * shi1_netname; + uint32_t shi1_type; + const char * shi1_remark; +}; + struct SHARE_INFO_2 { const char * shi2_netname; uint32_t shi2_type; @@ -562,6 +572,25 @@ struct SHARE_INFO_2 { const char * shi2_passwd; }; +struct SHARE_INFO_501 { + const char * shi501_netname; + uint32_t shi501_type; + const char * shi501_remark; + uint32_t shi501_flags; +}; + +struct SHARE_INFO_1004 { + const char * shi1004_remark; +}; + +struct SHARE_INFO_1005 { + uint32_t shi1005_flags; +}; + +struct SHARE_INFO_1006 { + uint32_t shi1006_max_uses; +}; + #endif /* _HEADER_libnetapi */ /**************************************************************** -- cgit From 927a9f2cbe96d0044a7d56b6dd73de220dcbb246 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 29 Aug 2008 18:58:32 +0200 Subject: netapi: add NetShareEnum skeleton. Guenther (This used to be commit 0cc604ebc13125daf7e219c63a6ca8f21eda48c6) --- source3/lib/netapi/libnetapi.c | 53 ++++++++++++++++++++++++++++++++++++++++++ source3/lib/netapi/libnetapi.h | 11 +++++++++ source3/lib/netapi/share.c | 17 ++++++++++++++ 3 files changed, 81 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/libnetapi.c b/source3/lib/netapi/libnetapi.c index 5ff7db0f7f..3b203b4bcf 100644 --- a/source3/lib/netapi/libnetapi.c +++ b/source3/lib/netapi/libnetapi.c @@ -1863,3 +1863,56 @@ NET_API_STATUS NetShareDel(const char * server_name /* [in] */, return r.out.result; } +/**************************************************************** + NetShareEnum +****************************************************************/ + +NET_API_STATUS NetShareEnum(const char * server_name /* [in] */, + uint32_t level /* [in] */, + uint8_t **buffer /* [out] [ref] */, + uint32_t prefmaxlen /* [in] */, + uint32_t *entries_read /* [out] [ref] */, + uint32_t *total_entries /* [out] [ref] */, + uint32_t *resume_handle /* [in,out] [ref] */) +{ + struct NetShareEnum r; + struct libnetapi_ctx *ctx = NULL; + NET_API_STATUS status; + WERROR werr; + + status = libnetapi_getctx(&ctx); + if (status != 0) { + return status; + } + + /* In parameters */ + r.in.server_name = server_name; + r.in.level = level; + r.in.prefmaxlen = prefmaxlen; + r.in.resume_handle = resume_handle; + + /* Out parameters */ + r.out.buffer = buffer; + r.out.entries_read = entries_read; + r.out.total_entries = total_entries; + r.out.resume_handle = resume_handle; + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_IN_DEBUG(NetShareEnum, &r); + } + + if (LIBNETAPI_LOCAL_SERVER(server_name)) { + werr = NetShareEnum_l(ctx, &r); + } else { + werr = NetShareEnum_r(ctx, &r); + } + + r.out.result = W_ERROR_V(werr); + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_OUT_DEBUG(NetShareEnum, &r); + } + + return r.out.result; +} + diff --git a/source3/lib/netapi/libnetapi.h b/source3/lib/netapi/libnetapi.h index b20f465f63..d4d73e6439 100644 --- a/source3/lib/netapi/libnetapi.h +++ b/source3/lib/netapi/libnetapi.h @@ -332,4 +332,15 @@ WERROR NetShareDel_r(struct libnetapi_ctx *ctx, struct NetShareDel *r); WERROR NetShareDel_l(struct libnetapi_ctx *ctx, struct NetShareDel *r); +NET_API_STATUS NetShareEnum(const char * server_name /* [in] */, + uint32_t level /* [in] */, + uint8_t **buffer /* [out] [ref] */, + uint32_t prefmaxlen /* [in] */, + uint32_t *entries_read /* [out] [ref] */, + uint32_t *total_entries /* [out] [ref] */, + uint32_t *resume_handle /* [in,out] [ref] */); +WERROR NetShareEnum_r(struct libnetapi_ctx *ctx, + struct NetShareEnum *r); +WERROR NetShareEnum_l(struct libnetapi_ctx *ctx, + struct NetShareEnum *r); #endif /* __LIBNETAPI_LIBNETAPI__ */ diff --git a/source3/lib/netapi/share.c b/source3/lib/netapi/share.c index 2c796046df..d31743200f 100644 --- a/source3/lib/netapi/share.c +++ b/source3/lib/netapi/share.c @@ -184,3 +184,20 @@ WERROR NetShareDel_l(struct libnetapi_ctx *ctx, LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetShareDel); } +/**************************************************************** +****************************************************************/ + +WERROR NetShareEnum_r(struct libnetapi_ctx *ctx, + struct NetShareEnum *r) +{ + return WERR_NOT_SUPPORTED; +} + +/**************************************************************** +****************************************************************/ + +WERROR NetShareEnum_l(struct libnetapi_ctx *ctx, + struct NetShareEnum *r) +{ + LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetShareEnum); +} -- cgit From a1febe0513ed0228f344f85b2b96ad9efa483b4b Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 29 Aug 2008 19:00:38 +0200 Subject: netapi: add NetShareEnum to public headers. Guenther (This used to be commit c2e936743227f10c2ade61589fe15c1805c79773) --- source3/lib/netapi/netapi.h | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h index 856791807a..817d4029ec 100644 --- a/source3/lib/netapi/netapi.h +++ b/source3/lib/netapi/netapi.h @@ -1548,6 +1548,33 @@ NET_API_STATUS NetShareDel(const char * server_name /* [in] */, const char * net_name /* [in] */, uint32_t reserved /* [in] */); +/************************************************************//** + * + * NetShareEnum + * + * @brief Enumerate Shares + * + * @param[in] server_name The server name to connect to + * @param[in] level The level defining the SHARE_INFO_X structure + * @param[out] buffer The buffer containing a SHARE_INFO_X structure + * @param[in] prefmaxlen The requested maximal buffer size + * @param[out] entries_read The number of SHARE_INFO_X entries in the buffer + * @param[out] total_entries The total number of SHARE_INFO_X entries + * @param[in,out] resume_handle A handle passed in and returned for resuming + * operations + * @return NET_API_STATUS + * + * example share/share_enum.c + ***************************************************************/ + +NET_API_STATUS NetShareEnum(const char * server_name /* [in] */, + uint32_t level /* [in] */, + uint8_t **buffer /* [out] [ref] */, + uint32_t prefmaxlen /* [in] */, + uint32_t *entries_read /* [out] [ref] */, + uint32_t *total_entries /* [out] [ref] */, + uint32_t *resume_handle /* [in,out] [ref] */); + #ifdef __cplusplus } #endif /* __cplusplus */ -- cgit From 612e75dff6e13ac8b59d2cb083c5adb421539d9c Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 29 Aug 2008 19:06:43 +0200 Subject: netapi: add NetShareEnum example code. Guenther (This used to be commit 91830de4527db124889ada9845ab145762855bc2) --- source3/lib/netapi/examples/Makefile.in | 8 +- source3/lib/netapi/examples/share/share_enum.c | 142 +++++++++++++++++++++++++ 2 files changed, 149 insertions(+), 1 deletion(-) create mode 100644 source3/lib/netapi/examples/share/share_enum.c (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/Makefile.in b/source3/lib/netapi/examples/Makefile.in index 74cbf322d8..f4ac8af038 100644 --- a/source3/lib/netapi/examples/Makefile.in +++ b/source3/lib/netapi/examples/Makefile.in @@ -51,7 +51,8 @@ PROGS = bin/getdc@EXEEXT@ \ bin/localgroup_getmembers@EXEEXT@ \ bin/remote_tod@EXEEXT@ \ bin/share_add@EXEEXT@ \ - bin/share_del@EXEEXT@ + bin/share_del@EXEEXT@ \ + bin/share_enum@EXEEXT@ all: $(PROGS) @@ -115,6 +116,7 @@ LOCALGROUPGETMEMBERS_OBJ = localgroup/localgroup_getmembers.o $(CMDLINE_OBJ) REMOTETOD_OBJ = server/remote_tod.o $(CMDLINE_OBJ) SHAREADD_OBJ = share/share_add.o $(CMDLINE_OBJ) SHAREDEL_OBJ = share/share_del.o $(CMDLINE_OBJ) +SHAREENUM_OBJ = share/share_enum.o $(CMDLINE_OBJ) bin/getdc@EXEEXT@: $(BINARY_PREREQS) $(GETDC_OBJ) @echo Linking $@ @@ -256,6 +258,10 @@ bin/share_del@EXEEXT@: $(BINARY_PREREQS) $(SHAREDEL_OBJ) @echo Linking $@ @$(CC) $(FLAGS) -o $@ $(SHAREDEL_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) +bin/share_enum@EXEEXT@: $(BINARY_PREREQS) $(SHAREENUM_OBJ) + @echo Linking $@ + @$(CC) $(FLAGS) -o $@ $(SHAREENUM_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) + clean: -rm -f $(PROGS) -rm -f core */*~ *~ \ diff --git a/source3/lib/netapi/examples/share/share_enum.c b/source3/lib/netapi/examples/share/share_enum.c new file mode 100644 index 0000000000..b1f4043795 --- /dev/null +++ b/source3/lib/netapi/examples/share/share_enum.c @@ -0,0 +1,142 @@ +/* + * Unix SMB/CIFS implementation. + * NetShareEnum query + * Copyright (C) Guenther Deschner 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include +#include +#include +#include +#include + +#include + +#include "common.h" + +int main(int argc, const char **argv) +{ + NET_API_STATUS status; + struct libnetapi_ctx *ctx = NULL; + const char *hostname = NULL; + uint32_t level = 0; + uint8_t *buffer = NULL; + uint32_t entries_read = 0; + uint32_t total_entries = 0; + uint32_t resume_handle = 0; + int i; + + struct SHARE_INFO_0 *i0 = NULL; + struct SHARE_INFO_1 *i1 = NULL; + struct SHARE_INFO_2 *i2 = NULL; + + poptContext pc; + int opt; + + struct poptOption long_options[] = { + POPT_AUTOHELP + POPT_COMMON_LIBNETAPI_EXAMPLES + POPT_TABLEEND + }; + + status = libnetapi_init(&ctx); + if (status != 0) { + return status; + } + + pc = poptGetContext("share_enum", argc, argv, long_options, 0); + + poptSetOtherOptionHelp(pc, "hostname level"); + while((opt = poptGetNextOpt(pc)) != -1) { + } + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + hostname = poptGetArg(pc); + + if (poptPeekArg(pc)) { + level = atoi(poptGetArg(pc)); + } + + /* NetShareEnum */ + + do { + status = NetShareEnum(hostname, + level, + &buffer, + (uint32_t)-1, + &entries_read, + &total_entries, + &resume_handle); + if (status == 0 || status == ERROR_MORE_DATA) { + printf("total entries: %d\n", total_entries); + switch (level) { + case 0: + i0 = (struct SHARE_INFO_0 *)buffer; + break; + case 1: + i1 = (struct SHARE_INFO_1 *)buffer; + break; + case 2: + i2 = (struct SHARE_INFO_2 *)buffer; + break; + default: + break; + } + for (i=0; ishi0_netname); + i0++; + break; + case 1: + printf("#%d netname: %s\n", i, i1->shi1_netname); + printf("#%d type: %d\n", i, i1->shi1_type); + printf("#%d remark: %s\n", i, i1->shi1_remark); + i1++; + break; + case 2: + printf("#%d netname: %s\n", i, i2->shi2_netname); + printf("#%d type: %d\n", i, i2->shi2_type); + printf("#%d remark: %s\n", i, i2->shi2_remark); + printf("#%d permissions: %d\n", i, i2->shi2_permissions); + printf("#%d max users: %d\n", i, i2->shi2_max_uses); + printf("#%d current users: %d\n", i, i2->shi2_current_uses); + printf("#%d path: %s\n", i, i2->shi2_path); + printf("#%d password: %s\n", i, i2->shi2_passwd); + i2++; + break; + default: + break; + } + } + NetApiBufferFree(buffer); + } + } while (status == ERROR_MORE_DATA); + + if (status != 0) { + printf("NetShareEnum failed with: %s\n", + libnetapi_get_error_string(ctx, status)); + } + + out: + libnetapi_free(ctx); + poptFreeContext(pc); + + return status; +} -- cgit From 71196cf6adf5ccb610bbf878df45e99110cf8805 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 2 Sep 2008 13:17:28 +0200 Subject: netapi: fix NetGetJoinableOUs_r: do not tear down connection. Guenther (This used to be commit 14c2688f2d37105ad129d26d13930177fe5c585f) --- source3/lib/netapi/joindomain.c | 4 ---- 1 file changed, 4 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/joindomain.c b/source3/lib/netapi/joindomain.c index 17ea3923fe..c83b0e01ff 100644 --- a/source3/lib/netapi/joindomain.c +++ b/source3/lib/netapi/joindomain.c @@ -445,9 +445,5 @@ WERROR NetGetJoinableOUs_r(struct libnetapi_ctx *ctx, } done: - if (cli) { - cli_shutdown(cli); - } - return werr; } -- cgit From 240188b6ba50d00cb705c88ba3a8278f5db4bb5f Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 1 Sep 2008 18:36:50 +0200 Subject: netapi: add new SERVER_INFO structures to public header. Guenther (This used to be commit cff66738936f9f5cc4d2cd284cde2e1ac2972d33) --- source3/lib/netapi/netapi.h | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h index 817d4029ec..80c44f0ddb 100644 --- a/source3/lib/netapi/netapi.h +++ b/source3/lib/netapi/netapi.h @@ -97,6 +97,37 @@ struct DOMAIN_CONTROLLER_INFO { #define TIMEQ_FOREVER ( (uint32_t)-1L ) +struct SERVER_INFO_100 { + uint32_t sv100_platform_id; + const char * sv100_name; +}; + +struct SERVER_INFO_101 { + uint32_t sv101_platform_id; + const char * sv101_name; + uint32_t sv101_version_major; + uint32_t sv101_version_minor; + uint32_t sv101_type; + const char * sv101_comment; +}; + +struct SERVER_INFO_102 { + uint32_t sv102_platform_id; + const char * sv102_name; + uint32_t sv102_version_major; + uint32_t sv102_version_minor; + uint32_t sv102_type; + const char * sv102_comment; + uint32_t sv102_users; + uint32_t sv102_disc; + uint8_t sv102_hidden; + uint32_t sv102_announce; + uint32_t sv102_anndelta; + uint32_t sv102_licenses; + const char * sv102_userpath; +}; + + struct SERVER_INFO_1005 { const char * sv1005_comment; }; -- cgit From ee3fca8aea7eb9516bb232b8c243d7354a1a0d24 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 1 Sep 2008 17:45:42 +0200 Subject: netapi: add NetServerGetInfo example code. Guenther (This used to be commit b2d0df46038a88fa3f2ff82e155805c771916a42) --- source3/lib/netapi/examples/Makefile.in | 6 + .../lib/netapi/examples/server/server_getinfo.c | 128 +++++++++++++++++++++ 2 files changed, 134 insertions(+) create mode 100644 source3/lib/netapi/examples/server/server_getinfo.c (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/Makefile.in b/source3/lib/netapi/examples/Makefile.in index f4ac8af038..169736c64d 100644 --- a/source3/lib/netapi/examples/Makefile.in +++ b/source3/lib/netapi/examples/Makefile.in @@ -50,6 +50,7 @@ PROGS = bin/getdc@EXEEXT@ \ bin/localgroup_setmembers@EXEEXT@ \ bin/localgroup_getmembers@EXEEXT@ \ bin/remote_tod@EXEEXT@ \ + bin/server_getinfo@EXEEXT@ \ bin/share_add@EXEEXT@ \ bin/share_del@EXEEXT@ \ bin/share_enum@EXEEXT@ @@ -114,6 +115,7 @@ LOCALGROUPDELMEMBERS_OBJ = localgroup/localgroup_delmembers.o $(CMDLINE_OBJ) LOCALGROUPSETMEMBERS_OBJ = localgroup/localgroup_setmembers.o $(CMDLINE_OBJ) LOCALGROUPGETMEMBERS_OBJ = localgroup/localgroup_getmembers.o $(CMDLINE_OBJ) REMOTETOD_OBJ = server/remote_tod.o $(CMDLINE_OBJ) +SERVERGETINFO_OBJ = server/server_getinfo.o $(CMDLINE_OBJ) SHAREADD_OBJ = share/share_add.o $(CMDLINE_OBJ) SHAREDEL_OBJ = share/share_del.o $(CMDLINE_OBJ) SHAREENUM_OBJ = share/share_enum.o $(CMDLINE_OBJ) @@ -250,6 +252,10 @@ bin/remote_tod@EXEEXT@: $(BINARY_PREREQS) $(REMOTETOD_OBJ) @echo Linking $@ @$(CC) $(FLAGS) -o $@ $(REMOTETOD_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) +bin/server_getinfo@EXEEXT@: $(BINARY_PREREQS) $(SERVERGETINFO_OBJ) + @echo Linking $@ + @$(CC) $(FLAGS) -o $@ $(SERVERGETINFO_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) + bin/share_add@EXEEXT@: $(BINARY_PREREQS) $(SHAREADD_OBJ) @echo Linking $@ @$(CC) $(FLAGS) -o $@ $(SHAREADD_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) diff --git a/source3/lib/netapi/examples/server/server_getinfo.c b/source3/lib/netapi/examples/server/server_getinfo.c new file mode 100644 index 0000000000..afd2edd05d --- /dev/null +++ b/source3/lib/netapi/examples/server/server_getinfo.c @@ -0,0 +1,128 @@ +/* + * Unix SMB/CIFS implementation. + * NetServerGetInfo query + * Copyright (C) Guenther Deschner 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include +#include +#include +#include +#include + +#include + +#include "common.h" + +int main(int argc, const char **argv) +{ + NET_API_STATUS status; + struct libnetapi_ctx *ctx = NULL; + const char *hostname = NULL; + uint8_t *buffer = NULL; + uint32_t level = 100; + + struct SERVER_INFO_100 *i100; + struct SERVER_INFO_101 *i101; + struct SERVER_INFO_102 *i102; + struct SERVER_INFO_1005 *i1005; + + poptContext pc; + int opt; + + struct poptOption long_options[] = { + POPT_AUTOHELP + POPT_COMMON_LIBNETAPI_EXAMPLES + POPT_TABLEEND + }; + + status = libnetapi_init(&ctx); + if (status != 0) { + return status; + } + + pc = poptGetContext("server_getinfo", argc, argv, long_options, 0); + + poptSetOtherOptionHelp(pc, "hostname level"); + while((opt = poptGetNextOpt(pc)) != -1) { + } + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + hostname = poptGetArg(pc); + + if (poptPeekArg(pc)) { + level = atoi(poptGetArg(pc)); + } + + /* NetServerGetInfo */ + + status = NetServerGetInfo(hostname, + level, + &buffer); + if (status != 0) { + printf("NetServerGetInfo failed with: %s\n", + libnetapi_get_error_string(ctx, status)); + goto out; + } + + switch (level) { + case 100: + i100 = (struct SERVER_INFO_100 *)buffer; + printf("platform id: %d\n", i100->sv100_platform_id); + printf("name: %s\n", i100->sv100_name); + break; + case 101: + i101 = (struct SERVER_INFO_101 *)buffer; + printf("platform id: %d\n", i101->sv101_platform_id); + printf("name: %s\n", i101->sv101_name); + printf("version major: %d\n", i101->sv101_version_major); + printf("version minor: %d\n", i101->sv101_version_minor); + printf("type: 0x%08x\n", i101->sv101_type); + printf("comment: %s\n", i101->sv101_comment); + break; + case 102: + i102 = (struct SERVER_INFO_102 *)buffer; + printf("platform id: %d\n", i102->sv102_platform_id); + printf("name: %s\n", i102->sv102_name); + printf("version major: %d\n", i102->sv102_version_major); + printf("version minor: %d\n", i102->sv102_version_minor); + printf("type: 0x%08x\n", i102->sv102_type); + printf("comment: %s\n", i102->sv102_comment); + printf("users: %d\n", i102->sv102_users); + printf("disc: %d\n", i102->sv102_disc); + printf("hidden: %d\n", i102->sv102_hidden); + printf("announce: %d\n", i102->sv102_announce); + printf("anndelta: %d\n", i102->sv102_anndelta); + printf("licenses: %d\n", i102->sv102_licenses); + printf("userpath: %s\n", i102->sv102_userpath); + break; + case 1005: + i1005 = (struct SERVER_INFO_1005 *)buffer; + printf("comment: %s\n", i1005->sv1005_comment); + break; + default: + break; + } + + out: + libnetapi_free(ctx); + poptFreeContext(pc); + + return status; +} -- cgit From c59158b2258995833373b7c596b0a6e1d09dba4f Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 1 Sep 2008 18:37:54 +0200 Subject: netapi: add support for more infolevels in NetServerGetInfo_r. Guenther (This used to be commit 43aad72457f77ac209494cfca46048e0c4bfa6c7) --- source3/lib/netapi/serverinfo.c | 93 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 90 insertions(+), 3 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/serverinfo.c b/source3/lib/netapi/serverinfo.c index 5f744bea26..12a0808658 100644 --- a/source3/lib/netapi/serverinfo.c +++ b/source3/lib/netapi/serverinfo.c @@ -61,6 +61,78 @@ WERROR NetServerGetInfo_l(struct libnetapi_ctx *ctx, /**************************************************************** ****************************************************************/ +static NTSTATUS map_server_info_to_SERVER_INFO_buffer(TALLOC_CTX *mem_ctx, + uint32_t level, + union srvsvc_NetSrvInfo *i, + uint8_t **buffer) +{ + struct SERVER_INFO_100 i100; + struct SERVER_INFO_101 i101; + struct SERVER_INFO_102 i102; + struct SERVER_INFO_1005 i1005; + + uint32_t num_info = 0; + + switch (level) { + case 100: + i100.sv100_platform_id = i->info100->platform_id; + i100.sv100_name = talloc_strdup(mem_ctx, i->info100->server_name); + + ADD_TO_ARRAY(mem_ctx, struct SERVER_INFO_100, i100, + (struct SERVER_INFO_100 **)buffer, + &num_info); + break; + + case 101: + i101.sv101_platform_id = i->info101->platform_id; + i101.sv101_name = talloc_strdup(mem_ctx, i->info101->server_name); + i101.sv101_version_major = i->info101->version_major; + i101.sv101_version_minor = i->info101->version_minor; + i101.sv101_type = i->info101->server_type; + i101.sv101_comment = talloc_strdup(mem_ctx, i->info101->comment); + + ADD_TO_ARRAY(mem_ctx, struct SERVER_INFO_101, i101, + (struct SERVER_INFO_101 **)buffer, + &num_info); + break; + + case 102: + i102.sv102_platform_id = i->info102->platform_id; + i102.sv102_name = talloc_strdup(mem_ctx, i->info102->server_name); + i102.sv102_version_major = i->info102->version_major; + i102.sv102_version_minor = i->info102->version_minor; + i102.sv102_type = i->info102->server_type; + i102.sv102_comment = talloc_strdup(mem_ctx, i->info102->comment); + i102.sv102_users = i->info102->users; + i102.sv102_disc = i->info102->disc; + i102.sv102_hidden = i->info102->hidden; + i102.sv102_announce = i->info102->announce; + i102.sv102_anndelta = i->info102->anndelta; + i102.sv102_licenses = i->info102->licenses; + i102.sv102_userpath = talloc_strdup(mem_ctx, i->info102->userpath); + + ADD_TO_ARRAY(mem_ctx, struct SERVER_INFO_102, i102, + (struct SERVER_INFO_102 **)buffer, + &num_info); + break; + + case 1005: + i1005.sv1005_comment = talloc_strdup(mem_ctx, i->info1005->comment); + + ADD_TO_ARRAY(mem_ctx, struct SERVER_INFO_1005, i1005, + (struct SERVER_INFO_1005 **)buffer, + &num_info); + break; + default: + return NT_STATUS_NOT_SUPPORTED; + } + + return NT_STATUS_OK; +} + +/**************************************************************** +****************************************************************/ + WERROR NetServerGetInfo_r(struct libnetapi_ctx *ctx, struct NetServerGetInfo *r) { @@ -70,6 +142,20 @@ WERROR NetServerGetInfo_r(struct libnetapi_ctx *ctx, WERROR werr; union srvsvc_NetSrvInfo info; + if (!r->out.buffer) { + return WERR_INVALID_PARAM; + } + + switch (r->in.level) { + case 100: + case 101: + case 102: + case 1005: + break; + default: + return WERR_UNKNOWN_LEVEL; + } + werr = libnetapi_open_pipe(ctx, r->in.server_name, &ndr_table_srvsvc.syntax_id, &cli, @@ -88,9 +174,10 @@ WERROR NetServerGetInfo_r(struct libnetapi_ctx *ctx, goto done; } - *r->out.buffer = (uint8_t *)talloc_memdup(ctx, &info, sizeof(info)); - if (!*r->out.buffer) { - werr = WERR_NOMEM; + status = map_server_info_to_SERVER_INFO_buffer(ctx, r->in.level, &info, + r->out.buffer); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); goto done; } -- cgit From 78a80f18651fa08482427485e024c74120218925 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 1 Sep 2008 18:54:53 +0200 Subject: netapi: add support for local query of level 101 in NetServerGetInfo. Guenther (This used to be commit b7a2f27c1cae9abed2f821177fca425012222632) --- source3/lib/netapi/serverinfo.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/serverinfo.c b/source3/lib/netapi/serverinfo.c index 12a0808658..b2a134b0af 100644 --- a/source3/lib/netapi/serverinfo.c +++ b/source3/lib/netapi/serverinfo.c @@ -28,6 +28,29 @@ /**************************************************************** ****************************************************************/ +static WERROR NetServerGetInfo_l_101(struct libnetapi_ctx *ctx, + uint8_t **buffer) +{ + struct SERVER_INFO_101 i; + + i.sv101_platform_id = PLATFORM_ID_NT; + i.sv101_name = global_myname(); + i.sv101_version_major = lp_major_announce_version(); + i.sv101_version_minor = lp_minor_announce_version(); + i.sv101_type = lp_default_server_announce(); + i.sv101_comment = lp_serverstring(); + + *buffer = (uint8_t *)talloc_memdup(ctx, &i, sizeof(i)); + if (!*buffer) { + return WERR_NOMEM; + } + + return WERR_OK; +} + +/**************************************************************** +****************************************************************/ + static WERROR NetServerGetInfo_l_1005(struct libnetapi_ctx *ctx, uint8_t **buffer) { @@ -49,6 +72,8 @@ WERROR NetServerGetInfo_l(struct libnetapi_ctx *ctx, struct NetServerGetInfo *r) { switch (r->in.level) { + case 101: + return NetServerGetInfo_l_101(ctx, r->out.buffer); case 1005: return NetServerGetInfo_l_1005(ctx, r->out.buffer); default: -- cgit From cd8deeb6e06af53fe661c280569729f7ce77eea0 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 1 Sep 2008 18:59:59 +0200 Subject: netdomjoin-gui: add support to remotely join/unjoin workstations. Guenther (This used to be commit 1760c4ce79ae15f9a2ea92293d823afe3af9b3ee) --- .../examples/netdomjoin-gui/netdomjoin-gui.c | 98 +++++++++++++--------- 1 file changed, 60 insertions(+), 38 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c index 4e0488ed59..9afdb8b58c 100644 --- a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c +++ b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c @@ -80,6 +80,7 @@ typedef struct join_state { gboolean settings_changed; gboolean hostname_changed; uint32_t stored_num_ous; + char *target_hostname; } join_state; static void debug(const char *format, ...) @@ -180,7 +181,10 @@ static void callback_apply_description_change(GtkWidget *widget, info1005.sv1005_comment = state->comment_new; - status = NetServerSetInfo(NULL, 1005, (uint8_t *)&info1005, &parm_err); + status = NetServerSetInfo(state->target_hostname, + 1005, + (uint8_t *)&info1005, + &parm_err); if (status) { debug("NetServerSetInfo failed with: %s\n", libnetapi_errstr(status)); @@ -285,7 +289,9 @@ static void callback_do_reboot(GtkWidget *widget, const char *buffer; uint16_t type; - status = NetGetJoinInformation(NULL, &buffer, &type); + status = NetGetJoinInformation(state->target_hostname, + &buffer, + &type); if (status != 0) { g_print("failed to query status\n"); return; @@ -658,7 +664,7 @@ static void callback_do_join(GtkWidget *widget, } } - status = NetUnjoinDomain(NULL, + status = NetUnjoinDomain(state->target_hostname, state->account, state->password, unjoin_flags); @@ -748,7 +754,7 @@ static void callback_do_join(GtkWidget *widget, } debug("\n"); - status = NetJoinDomain(NULL, + status = NetJoinDomain(state->target_hostname, state->name_buffer_new, account_ou, state->account, @@ -1003,7 +1009,8 @@ static void callback_do_getous(GtkWidget *widget, return; } - status = NetGetJoinableOUs(NULL, domain, + status = NetGetJoinableOUs(state->target_hostname, + domain, state->account, state->password, &num_ous, &ous); @@ -1579,7 +1586,9 @@ static int init_join_state(struct join_state **state) } static int initialize_join_state(struct join_state *state, - const char *debug_level) + const char *debug_level, + const char *target_hostname, + const char *target_username) { struct libnetapi_ctx *ctx = NULL; NET_API_STATUS status = 0; @@ -1593,6 +1602,30 @@ static int initialize_join_state(struct join_state *state, libnetapi_set_debuglevel(ctx, debug_level); } + if (target_hostname) { + state->target_hostname = strdup(target_hostname); + if (!state->target_hostname) { + return -1; + } + } + + if (target_username) { + char *puser = strdup(target_username); + char *p = NULL; + + if ((p = strchr(puser,'%'))) { + size_t len; + *p = 0; + libnetapi_set_username(ctx, puser); + libnetapi_set_password(ctx, p+1); + len = strlen(p+1); + memset(strchr(target_username,'%')+1,'X',len); + } else { + libnetapi_set_username(ctx, puser); + } + free(puser); + } + { char my_hostname[HOST_NAME_MAX]; const char *p = NULL; @@ -1639,7 +1672,9 @@ static int initialize_join_state(struct join_state *state, { const char *buffer = NULL; uint16_t type = 0; - status = NetGetJoinInformation(NULL, &buffer, &type); + status = NetGetJoinInformation(state->target_hostname, + &buffer, + &type); if (status != 0) { printf("NetGetJoinInformation failed with: %s\n", libnetapi_get_error_string(state->ctx, status)); @@ -1655,42 +1690,23 @@ static int initialize_join_state(struct join_state *state, } { - struct SERVER_INFO_1005 *info1005 = NULL; - uint8_t *buffer = NULL; + struct SERVER_INFO_101 *info101 = NULL; - status = NetServerGetInfo(NULL, 1005, &buffer); + status = NetServerGetInfo(state->target_hostname, + 101, + (uint8_t **)&info101); if (status != 0) { printf("NetServerGetInfo failed with: %s\n", libnetapi_get_error_string(state->ctx, status)); - return status; - } - - info1005 = (struct SERVER_INFO_1005 *)buffer; - - state->comment = strdup(info1005->sv1005_comment); - if (!state->comment) { - return -1; - } - NetApiBufferFree(buffer); - } -#if 0 - { - struct srvsvc_NetSrvInfo100 *info100 = NULL; - uint8_t *buffer = NULL; - - status = NetServerGetInfo(NULL, 100, &buffer); - if (status) { - return status; - } - - info100 = (struct srvsvc_NetSrvInfo100 *)buffer; - - state->comment = strdup(info100->comment); - if (!state->comment) { - return -1; + /* return status; */ + } else { + state->comment = strdup(info101->sv101_comment); + if (!state->comment) { + return -1; + } } + NetApiBufferFree(info101); } -#endif state->ctx = ctx; @@ -1701,6 +1717,8 @@ int main(int argc, char **argv) { GOptionContext *context = NULL; static const char *debug_level = NULL; + static const char *target_hostname = NULL; + static const char *target_username = NULL; struct join_state *state = NULL; GError *error = NULL; int ret = 0; @@ -1708,6 +1726,8 @@ int main(int argc, char **argv) static GOptionEntry entries[] = { { "debug", 'd', 0, G_OPTION_ARG_STRING, &debug_level, "Debug level (for samba)", "N" }, { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, "Verbose output", 0 }, + { "target", 'S', 0, G_OPTION_ARG_STRING, &target_hostname, "Target hostname", 0 }, + { "username", 'U', 0, G_OPTION_ARG_STRING, &target_username, "Target hostname", 0 }, { NULL } }; @@ -1725,7 +1745,9 @@ int main(int argc, char **argv) return ret; } - ret = initialize_join_state(state, debug_level); + ret = initialize_join_state(state, debug_level, + target_hostname, + target_username); if (ret) { return ret; } -- cgit From 6dff24790fd6344665a98a5557d97f7afecbfea9 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 2 Sep 2008 16:14:14 +0200 Subject: netdomjoin-gui: test all NetServerGetInfo levels until we get comment. (This used to be commit 56d353b406ef77808b9cb968fcba387f301cf2de) --- .../examples/netdomjoin-gui/netdomjoin-gui.c | 65 ++++++++++++++++------ 1 file changed, 48 insertions(+), 17 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c index 9afdb8b58c..def56ae0b6 100644 --- a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c +++ b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c @@ -1585,6 +1585,51 @@ static int init_join_state(struct join_state **state) return 0; } +static NET_API_STATUS get_server_comment(struct join_state *state) +{ + struct SERVER_INFO_101 *info101 = NULL; + struct SERVER_INFO_1005 *info1005 = NULL; + NET_API_STATUS status; + + status = NetServerGetInfo(state->target_hostname, + 101, + (uint8_t **)&info101); + if (status == 0) { + state->comment = strdup(info101->sv101_comment); + if (!state->comment) { + return -1; + } + NetApiBufferFree(info101); + return NET_API_STATUS_SUCCESS; + } + + switch (status) { + case 124: /* WERR_UNKNOWN_LEVEL */ + case 50: /* WERR_NOT_SUPPORTED */ + break; + default: + goto failed; + } + + status = NetServerGetInfo(state->target_hostname, + 1005, + (uint8_t **)&info1005); + if (status == 0) { + state->comment = strdup(info1005->sv1005_comment); + if (!state->comment) { + return -1; + } + NetApiBufferFree(info1005); + return NET_API_STATUS_SUCCESS; + } + + failed: + printf("NetServerGetInfo failed with: %s\n", + libnetapi_get_error_string(state->ctx, status)); + + return status; +} + static int initialize_join_state(struct join_state *state, const char *debug_level, const char *target_hostname, @@ -1689,23 +1734,9 @@ static int initialize_join_state(struct join_state *state, NetApiBufferFree((void *)buffer); } - { - struct SERVER_INFO_101 *info101 = NULL; - - status = NetServerGetInfo(state->target_hostname, - 101, - (uint8_t **)&info101); - if (status != 0) { - printf("NetServerGetInfo failed with: %s\n", - libnetapi_get_error_string(state->ctx, status)); - /* return status; */ - } else { - state->comment = strdup(info101->sv101_comment); - if (!state->comment) { - return -1; - } - } - NetApiBufferFree(info101); + status = get_server_comment(state); + if (status != 0) { + return -1; } state->ctx = ctx; -- cgit From 78ed824dab95209ea9d48d4478e3a5de24060b7d Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 2 Sep 2008 00:36:31 +0200 Subject: netdomjoin-gui: add gtk set_transient flags. Guenther (This used to be commit c979b96eb4b0df94e9d736a9473d00c28a52ed07) --- .../lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c index def56ae0b6..45571e3f14 100644 --- a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c +++ b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c @@ -195,6 +195,7 @@ static void callback_apply_description_change(GtkWidget *widget, "Failed to change computer description: %s.", libnetapi_get_error_string(state->ctx, status)); gtk_window_set_modal(GTK_WINDOW(dialog), TRUE); + gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(state->window_main)); g_signal_connect_swapped(dialog, "response", G_CALLBACK(gtk_widget_destroy), @@ -266,6 +267,7 @@ static void callback_do_reboot(GtkWidget *widget, GTK_BUTTONS_OK, "You must restart this computer for the changes to take effect."); gtk_window_set_modal(GTK_WINDOW(dialog), TRUE); + gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(state->window_do_change)); #if 0 g_signal_connect_swapped(dialog, "response", G_CALLBACK(gtk_widget_destroy), @@ -467,6 +469,7 @@ static void callback_do_hostname_change(GtkWidget *widget, str); gtk_window_set_modal(GTK_WINDOW(dialog), TRUE); + gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(state->window_main)); g_signal_connect_swapped(dialog, "response", G_CALLBACK(gtk_widget_destroy), dialog); @@ -496,6 +499,7 @@ static void callback_creds_prompt(GtkWidget *widget, gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER); gtk_widget_set_size_request(GTK_WIDGET(window), 380, 280); gtk_window_set_icon_from_file(GTK_WINDOW(window), SAMBA_ICON_PATH, NULL); + gtk_window_set_transient_for(GTK_WINDOW(window), GTK_WINDOW(state->window_do_change)); g_signal_connect(G_OBJECT(window), "delete_event", G_CALLBACK(callback_do_close), window); @@ -718,6 +722,7 @@ static void callback_do_join(GtkWidget *widget, err_str); gtk_window_set_modal(GTK_WINDOW(dialog), TRUE); + gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(state->window_do_change)); g_signal_connect_swapped(dialog, "response", G_CALLBACK(gtk_widget_destroy), dialog); @@ -775,6 +780,7 @@ static void callback_do_join(GtkWidget *widget, err_str); gtk_window_set_modal(GTK_WINDOW(dialog), TRUE); + gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(state->window_do_change)); g_signal_connect_swapped(dialog, "response", G_CALLBACK(gtk_widget_destroy), dialog); @@ -797,6 +803,7 @@ static void callback_do_join(GtkWidget *widget, new_workgroup_type); gtk_window_set_modal(GTK_WINDOW(dialog), TRUE); + gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(state->window_do_change)); gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); @@ -988,6 +995,7 @@ static void callback_do_getous(GtkWidget *widget, err_str); gtk_window_set_modal(GTK_WINDOW(dialog), TRUE); + gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(state->window_do_change)); g_signal_connect_swapped(dialog, "response", G_CALLBACK(gtk_widget_destroy), dialog); @@ -1025,6 +1033,7 @@ static void callback_do_getous(GtkWidget *widget, "Failed to query joinable OUs: %s", libnetapi_get_error_string(state->ctx, status)); gtk_window_set_modal(GTK_WINDOW(dialog), TRUE); + gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(state->window_do_change)); gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); return; @@ -1090,6 +1099,7 @@ static void callback_do_change(GtkWidget *widget, gtk_window_set_resizable(GTK_WINDOW(window), FALSE); gtk_widget_set_size_request(GTK_WIDGET(window), 480, 650); gtk_window_set_icon_from_file(GTK_WINDOW(window), SAMBA_ICON_PATH, NULL); + gtk_window_set_transient_for(GTK_WINDOW(window), GTK_WINDOW(state->window_main)); g_signal_connect(G_OBJECT(window), "delete_event", G_CALLBACK(callback_do_close), window); @@ -1290,6 +1300,8 @@ static void callback_do_about(GtkWidget *widget, GError *error = NULL; GtkWidget *about; + struct join_state *state = (struct join_state *)data; + debug("callback_do_about called\n"); logo = gdk_pixbuf_new_from_file(SAMBA_IMAGE_PATH, @@ -1313,6 +1325,7 @@ static void callback_do_about(GtkWidget *widget, } gtk_about_dialog_set_comments(GTK_ABOUT_DIALOG(about), "Samba gtk domain join utility"); gtk_window_set_modal(GTK_WINDOW(about), TRUE); + gtk_window_set_transient_for(GTK_WINDOW(about), GTK_WINDOW(state->window_main)); g_signal_connect_swapped(about, "response", G_CALLBACK(gtk_widget_destroy), about); @@ -1553,7 +1566,7 @@ static int draw_main_window(struct join_state *state) gtk_container_add(GTK_CONTAINER(bbox2), button2); g_signal_connect(G_OBJECT(button2), "clicked", G_CALLBACK(callback_do_about), - window); + state); #if 0 button2 = gtk_button_new_from_stock(GTK_STOCK_HELP); gtk_container_add(GTK_CONTAINER(bbox2), button2); -- cgit From b0ab216cd53acf119aaba88a3d07f01810a5dfa9 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 2 Sep 2008 00:49:33 +0200 Subject: netdomjoin-gui: fix some small errors in callbacks. Guenther (This used to be commit 74031b0b4ac1301cff6ca551c3264c4137a43294) --- source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c index 45571e3f14..d5b60f1878 100644 --- a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c +++ b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c @@ -827,9 +827,11 @@ static void callback_enter_hostname_and_unlock(GtkWidget *widget, if (strcasecmp(state->my_hostname, entry_text) == 0) { state->hostname_changed = FALSE; gtk_widget_set_sensitive(GTK_WIDGET(state->button_ok), FALSE); - return; + /* return; */ + } else { + state->hostname_changed = TRUE; } - state->hostname_changed = TRUE; + if (state->name_type_initial == NetSetupDomainName) { if (asprintf(&str, "%s.%s", entry_text, state->my_dnsdomain) == -1) { return; @@ -852,7 +854,7 @@ static void callback_enter_computer_description_and_unlock(GtkWidget *widget, { const gchar *entry_text = NULL; struct join_state *state = (struct join_state *)data; - int string_unchanged = 0; + int string_unchanged = FALSE; entry_text = gtk_entry_get_text(GTK_ENTRY(widget)); debug("callback_enter_computer_description_and_unlock: %s\n", @@ -865,8 +867,8 @@ static void callback_enter_computer_description_and_unlock(GtkWidget *widget, return; } #endif - if (entry_text && strcasecmp(state->comment, entry_text) == 0) { - string_unchanged = 1; + if (entry_text && state->comment && strcasecmp(state->comment, entry_text) == 0) { + string_unchanged = TRUE; gtk_widget_set_sensitive(GTK_WIDGET(state->button_apply), FALSE); return; -- cgit From 685f7e3419b27cd0e274b7a768d9fa23b7de5f85 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 2 Sep 2008 01:06:25 +0200 Subject: netdomjoin-gui: always center new windows. Guenther (This used to be commit af25bd95d24de8e9fac8f86b18e03a09902b0b78) --- source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c index d5b60f1878..bf41ee430d 100644 --- a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c +++ b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c @@ -500,6 +500,7 @@ static void callback_creds_prompt(GtkWidget *widget, gtk_widget_set_size_request(GTK_WIDGET(window), 380, 280); gtk_window_set_icon_from_file(GTK_WINDOW(window), SAMBA_ICON_PATH, NULL); gtk_window_set_transient_for(GTK_WINDOW(window), GTK_WINDOW(state->window_do_change)); + gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER_ALWAYS); g_signal_connect(G_OBJECT(window), "delete_event", G_CALLBACK(callback_do_close), window); @@ -1102,6 +1103,7 @@ static void callback_do_change(GtkWidget *widget, gtk_widget_set_size_request(GTK_WIDGET(window), 480, 650); gtk_window_set_icon_from_file(GTK_WINDOW(window), SAMBA_ICON_PATH, NULL); gtk_window_set_transient_for(GTK_WINDOW(window), GTK_WINDOW(state->window_main)); + gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER_ALWAYS); g_signal_connect(G_OBJECT(window), "delete_event", G_CALLBACK(callback_do_close), window); @@ -1374,6 +1376,7 @@ static int draw_main_window(struct join_state *state) gtk_widget_set_size_request(GTK_WIDGET(window), 600, 600); gtk_window_set_resizable(GTK_WINDOW(window), FALSE); gtk_window_set_icon_from_file(GTK_WINDOW(window), SAMBA_ICON_PATH, NULL); + gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER_ALWAYS); g_signal_connect(G_OBJECT(window), "delete_event", G_CALLBACK(callback_delete_event), NULL); -- cgit From 231de7054a8f92990bc3b9da7dbddfa18cc44ff1 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 2 Sep 2008 02:02:20 +0200 Subject: netdomjoin-gui: fix some widget closing callbacks. Guenther (This used to be commit 8d541a3579637bb48c04ebb2b18844509c1f43e8) --- .../netapi/examples/netdomjoin-gui/netdomjoin-gui.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c index bf41ee430d..98994b69f8 100644 --- a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c +++ b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c @@ -104,14 +104,23 @@ static gboolean callback_delete_event(GtkWidget *widget, return FALSE; } -static void callback_do_close(GtkWidget *widget, - gpointer data) +static void callback_do_close_data(GtkWidget *widget, + gpointer data) { - debug("callback_do_close called\n"); + debug("callback_do_close_data called\n"); if (data) { gtk_widget_destroy(GTK_WIDGET(data)); - data = NULL; + } +} + +static void callback_do_close_widget(GtkWidget *widget, + gpointer data) +{ + debug("callback_do_close_widget called\n"); + + if (widget) { + gtk_widget_destroy(widget); } } @@ -503,7 +512,7 @@ static void callback_creds_prompt(GtkWidget *widget, gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER_ALWAYS); g_signal_connect(G_OBJECT(window), "delete_event", - G_CALLBACK(callback_do_close), window); + G_CALLBACK(callback_do_close_widget), NULL); state->window_creds_prompt = window; gtk_container_set_border_width(GTK_CONTAINER(window), 10); @@ -1106,7 +1115,7 @@ static void callback_do_change(GtkWidget *widget, gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER_ALWAYS); g_signal_connect(G_OBJECT(window), "delete_event", - G_CALLBACK(callback_do_close), window); + G_CALLBACK(callback_do_close_widget), NULL); gtk_container_set_border_width(GTK_CONTAINER(window), 10); -- cgit From c8334dc7089e9f615257fff7c1dbf5f9b4a4e1c6 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 2 Sep 2008 11:02:43 +0200 Subject: netapi: add skeleton for NetRenameMachineInDomain. Guenther (This used to be commit 03a7f7f33370d65493a81ccead2038ee3ab291d0) --- source3/lib/netapi/joindomain.c | 18 ++++++++++++++++ source3/lib/netapi/libnetapi.c | 48 +++++++++++++++++++++++++++++++++++++++++ source3/lib/netapi/libnetapi.h | 9 ++++++++ 3 files changed, 75 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/joindomain.c b/source3/lib/netapi/joindomain.c index c83b0e01ff..6bf1cad312 100644 --- a/source3/lib/netapi/joindomain.c +++ b/source3/lib/netapi/joindomain.c @@ -447,3 +447,21 @@ WERROR NetGetJoinableOUs_r(struct libnetapi_ctx *ctx, done: return werr; } + +/**************************************************************** +****************************************************************/ + +WERROR NetRenameMachineInDomain_r(struct libnetapi_ctx *ctx, + struct NetRenameMachineInDomain *r) +{ + return WERR_NOT_SUPPORTED; +} + +/**************************************************************** +****************************************************************/ + +WERROR NetRenameMachineInDomain_l(struct libnetapi_ctx *ctx, + struct NetRenameMachineInDomain *r) +{ + LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetRenameMachineInDomain); +} diff --git a/source3/lib/netapi/libnetapi.c b/source3/lib/netapi/libnetapi.c index 3b203b4bcf..3e42254c7e 100644 --- a/source3/lib/netapi/libnetapi.c +++ b/source3/lib/netapi/libnetapi.c @@ -214,6 +214,54 @@ NET_API_STATUS NetGetJoinableOUs(const char * server_name /* [in] [unique] */, return r.out.result; } +/**************************************************************** + NetRenameMachineInDomain +****************************************************************/ + +NET_API_STATUS NetRenameMachineInDomain(const char * server_name /* [in] */, + const char * new_machine_name /* [in] */, + const char * account /* [in] */, + const char * password /* [in] */, + uint32_t rename_options /* [in] */) +{ + struct NetRenameMachineInDomain r; + struct libnetapi_ctx *ctx = NULL; + NET_API_STATUS status; + WERROR werr; + + status = libnetapi_getctx(&ctx); + if (status != 0) { + return status; + } + + /* In parameters */ + r.in.server_name = server_name; + r.in.new_machine_name = new_machine_name; + r.in.account = account; + r.in.password = password; + r.in.rename_options = rename_options; + + /* Out parameters */ + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_IN_DEBUG(NetRenameMachineInDomain, &r); + } + + if (LIBNETAPI_LOCAL_SERVER(server_name)) { + werr = NetRenameMachineInDomain_l(ctx, &r); + } else { + werr = NetRenameMachineInDomain_r(ctx, &r); + } + + r.out.result = W_ERROR_V(werr); + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_OUT_DEBUG(NetRenameMachineInDomain, &r); + } + + return r.out.result; +} + /**************************************************************** NetServerGetInfo ****************************************************************/ diff --git a/source3/lib/netapi/libnetapi.h b/source3/lib/netapi/libnetapi.h index d4d73e6439..d2531a287f 100644 --- a/source3/lib/netapi/libnetapi.h +++ b/source3/lib/netapi/libnetapi.h @@ -35,6 +35,15 @@ WERROR NetGetJoinableOUs_r(struct libnetapi_ctx *ctx, struct NetGetJoinableOUs *r); WERROR NetGetJoinableOUs_l(struct libnetapi_ctx *ctx, struct NetGetJoinableOUs *r); +NET_API_STATUS NetRenameMachineInDomain(const char * server_name /* [in] */, + const char * new_machine_name /* [in] */, + const char * account /* [in] */, + const char * password /* [in] */, + uint32_t rename_options /* [in] */); +WERROR NetRenameMachineInDomain_r(struct libnetapi_ctx *ctx, + struct NetRenameMachineInDomain *r); +WERROR NetRenameMachineInDomain_l(struct libnetapi_ctx *ctx, + struct NetRenameMachineInDomain *r); NET_API_STATUS NetServerGetInfo(const char * server_name /* [in] [unique] */, uint32_t level /* [in] */, uint8_t **buffer /* [out] [ref] */); -- cgit From 10e8f90a65a95e3b2aeda467ec37b5c94288f2a6 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 2 Sep 2008 11:06:22 +0200 Subject: netapi: add NetRenameMachineInDomain to public header. Guenther (This used to be commit b66cee247fa7ef5293074b191b9cc2cbf4eef5f3) --- source3/lib/netapi/netapi.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h index 80c44f0ddb..ba509f8d8c 100644 --- a/source3/lib/netapi/netapi.h +++ b/source3/lib/netapi/netapi.h @@ -827,6 +827,29 @@ NET_API_STATUS NetGetJoinableOUs(const char * server_name /* [in] */, uint32_t *ou_count /* [out] [ref] */, const char * **ous /* [out] [ref] */); +/************************************************************//** + * + * NetRenameMachineInDomain + * + * @brief Rename a machine in a domain + * + * @param[in] server_name The server name to connect to + * @param[in] new_machine_name The new machine name + * @param[in] account The domain account used for the query + * @param[in] password The domain account's password used for the query + * @param[in] rename_options Options used for the rename operation + * @return NET_API_STATUS + * + * example join/rename_machine.c + * + ***************************************************************/ + +NET_API_STATUS NetRenameMachineInDomain(const char * server_name /* [in] */, + const char * new_machine_name /* [in] */, + const char * account /* [in] */, + const char * password /* [in] */, + uint32_t rename_options /* [in] */); + /************************************************************//** * * NetServerGetInfo -- cgit From 8cb544e2a1806b863bb5a1f49b6642b99435aa55 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 2 Sep 2008 13:17:57 +0200 Subject: netapi: implement NetRenameMachineInDomain_r. Guenther (This used to be commit 39a42380ca3fac92eb27bded90ab06f7760937b9) --- source3/lib/netapi/joindomain.c | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/joindomain.c b/source3/lib/netapi/joindomain.c index 6bf1cad312..d15e2e733c 100644 --- a/source3/lib/netapi/joindomain.c +++ b/source3/lib/netapi/joindomain.c @@ -454,7 +454,41 @@ WERROR NetGetJoinableOUs_r(struct libnetapi_ctx *ctx, WERROR NetRenameMachineInDomain_r(struct libnetapi_ctx *ctx, struct NetRenameMachineInDomain *r) { - return WERR_NOT_SUPPORTED; + struct cli_state *cli = NULL; + struct rpc_pipe_client *pipe_cli = NULL; + struct wkssvc_PasswordBuffer *encrypted_password = NULL; + NTSTATUS status; + WERROR werr; + + werr = libnetapi_open_pipe(ctx, r->in.server_name, + &ndr_table_wkssvc.syntax_id, + &cli, + &pipe_cli); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + if (r->in.password) { + encode_wkssvc_join_password_buffer(ctx, + r->in.password, + &cli->user_session_key, + &encrypted_password); + } + + status = rpccli_wkssvc_NetrRenameMachineInDomain2(pipe_cli, ctx, + r->in.server_name, + r->in.new_machine_name, + r->in.account, + encrypted_password, + r->in.rename_options, + &werr); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + done: + return werr; } /**************************************************************** -- cgit From e8f8ae407ffcb754a8bb288be242be01616bc73e Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 2 Sep 2008 13:18:32 +0200 Subject: netapi: add NetRenameMachineInDomain example code. Guenther (This used to be commit e28c332f32c4f7b1ac493f69f17254185d9cee96) --- source3/lib/netapi/examples/Makefile.in | 6 ++ source3/lib/netapi/examples/join/rename_machine.c | 86 +++++++++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 source3/lib/netapi/examples/join/rename_machine.c (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/Makefile.in b/source3/lib/netapi/examples/Makefile.in index 169736c64d..51fadb9a10 100644 --- a/source3/lib/netapi/examples/Makefile.in +++ b/source3/lib/netapi/examples/Makefile.in @@ -22,6 +22,7 @@ PROGS = bin/getdc@EXEEXT@ \ bin/netdomjoin@EXEEXT@ \ bin/netdomjoin-gui@EXEEXT@ \ bin/getjoinableous@EXEEXT@ \ + bin/rename_machine@EXEEXT@ \ bin/user_add@EXEEXT@ \ bin/user_del@EXEEXT@ \ bin/user_enum@EXEEXT@ \ @@ -87,6 +88,7 @@ DSGETDC_OBJ = dsgetdc/dsgetdc.o $(CMDLINE_OBJ) NETDOMJOIN_OBJ = netdomjoin/netdomjoin.o $(CMDLINE_OBJ) NETDOMJOIN_GUI_OBJ = netdomjoin-gui/netdomjoin-gui.o GETJOINABLEOUS_OBJ = getjoinableous/getjoinableous.o $(CMDLINE_OBJ) +RENAMEMACHINE_OBJ = join/rename_machine.o $(CMDLINE_OBJ) USERADD_OBJ = user/user_add.o $(CMDLINE_OBJ) USERDEL_OBJ = user/user_del.o $(CMDLINE_OBJ) USERENUM_OBJ = user/user_enum.o $(CMDLINE_OBJ) @@ -132,6 +134,10 @@ bin/getjoinableous@EXEEXT@: $(BINARY_PREREQS) $(GETJOINABLEOUS_OBJ) @echo Linking $@ @$(CC) $(FLAGS) -o $@ $(GETJOINABLEOUS_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) +bin/rename_machine@EXEEXT@: $(BINARY_PREREQS) $(RENAMEMACHINE_OBJ) + @echo Linking $@ + @$(CC) $(FLAGS) -o $@ $(RENAMEMACHINE_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) + bin/netdomjoin@EXEEXT@: $(BINARY_PREREQS) $(NETDOMJOIN_OBJ) @echo Linking $@ @$(CC) $(FLAGS) -o $@ $(NETDOMJOIN_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) diff --git a/source3/lib/netapi/examples/join/rename_machine.c b/source3/lib/netapi/examples/join/rename_machine.c new file mode 100644 index 0000000000..a21f9198d8 --- /dev/null +++ b/source3/lib/netapi/examples/join/rename_machine.c @@ -0,0 +1,86 @@ +/* + * Unix SMB/CIFS implementation. + * NetRenameMachineInDomain query + * Copyright (C) Guenther Deschner 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include +#include +#include +#include + +#include + +#include "common.h" + +int main(int argc, const char **argv) +{ + NET_API_STATUS status; + const char *host_name = NULL; + const char *new_machine_name = NULL; + uint32_t rename_opt = 0; + struct libnetapi_ctx *ctx = NULL; + + poptContext pc; + int opt; + + struct poptOption long_options[] = { + POPT_AUTOHELP + POPT_COMMON_LIBNETAPI_EXAMPLES + POPT_TABLEEND + }; + + status = libnetapi_init(&ctx); + if (status != 0) { + return status; + } + + pc = poptGetContext("rename_machine", argc, argv, long_options, 0); + + poptSetOtherOptionHelp(pc, "hostname newmachinename"); + while((opt = poptGetNextOpt(pc)) != -1) { + } + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + host_name = poptGetArg(pc); + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + new_machine_name = poptGetArg(pc); + + /* NetRenameMachineInDomain */ + + status = NetRenameMachineInDomain(host_name, + new_machine_name, + ctx->username, + ctx->password, + rename_opt); + if (status != 0) { + printf("failed with: %s\n", + libnetapi_get_error_string(ctx, status)); + } + + out: + libnetapi_free(ctx); + poptFreeContext(pc); + + return status; +} -- cgit From 51e962331c2a40037e65f6a2b12ba7c6d43cc68f Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 2 Sep 2008 13:24:51 +0200 Subject: netapi: move join related examples to one directory. Guenther (This used to be commit afdd14c26c27c9fa245165985a5d8e644855c4b5) --- source3/lib/netapi/examples/Makefile.in | 4 +- .../examples/getjoinableous/getjoinableous.c | 95 ------------------- source3/lib/netapi/examples/join/getjoinableous.c | 95 +++++++++++++++++++ source3/lib/netapi/examples/join/netdomjoin.c | 104 +++++++++++++++++++++ .../lib/netapi/examples/netdomjoin/netdomjoin.c | 104 --------------------- 5 files changed, 201 insertions(+), 201 deletions(-) delete mode 100644 source3/lib/netapi/examples/getjoinableous/getjoinableous.c create mode 100644 source3/lib/netapi/examples/join/getjoinableous.c create mode 100644 source3/lib/netapi/examples/join/netdomjoin.c delete mode 100644 source3/lib/netapi/examples/netdomjoin/netdomjoin.c (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/Makefile.in b/source3/lib/netapi/examples/Makefile.in index 51fadb9a10..ee72a95062 100644 --- a/source3/lib/netapi/examples/Makefile.in +++ b/source3/lib/netapi/examples/Makefile.in @@ -85,9 +85,9 @@ bin/.dummy: CMDLINE_OBJ = common.o GETDC_OBJ = getdc/getdc.o $(CMDLINE_OBJ) DSGETDC_OBJ = dsgetdc/dsgetdc.o $(CMDLINE_OBJ) -NETDOMJOIN_OBJ = netdomjoin/netdomjoin.o $(CMDLINE_OBJ) +NETDOMJOIN_OBJ = join/netdomjoin.o $(CMDLINE_OBJ) NETDOMJOIN_GUI_OBJ = netdomjoin-gui/netdomjoin-gui.o -GETJOINABLEOUS_OBJ = getjoinableous/getjoinableous.o $(CMDLINE_OBJ) +GETJOINABLEOUS_OBJ = join/getjoinableous.o $(CMDLINE_OBJ) RENAMEMACHINE_OBJ = join/rename_machine.o $(CMDLINE_OBJ) USERADD_OBJ = user/user_add.o $(CMDLINE_OBJ) USERDEL_OBJ = user/user_del.o $(CMDLINE_OBJ) diff --git a/source3/lib/netapi/examples/getjoinableous/getjoinableous.c b/source3/lib/netapi/examples/getjoinableous/getjoinableous.c deleted file mode 100644 index 732f73dd57..0000000000 --- a/source3/lib/netapi/examples/getjoinableous/getjoinableous.c +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Unix SMB/CIFS implementation. - * Join Support (cmdline + netapi) - * Copyright (C) Guenther Deschner 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 - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see . - */ - -#include -#include -#include -#include - -#include - -#include "common.h" - -int main(int argc, const char **argv) -{ - NET_API_STATUS status; - const char *host_name = NULL; - const char *domain_name = NULL; - const char **ous = NULL; - uint32_t num_ous = 0; - struct libnetapi_ctx *ctx = NULL; - int i; - - poptContext pc; - int opt; - - struct poptOption long_options[] = { - POPT_AUTOHELP - { "domain", 0, POPT_ARG_STRING, NULL, 'D', "Domain name", "DOMAIN" }, - POPT_COMMON_LIBNETAPI_EXAMPLES - POPT_TABLEEND - }; - - status = libnetapi_init(&ctx); - if (status != 0) { - return status; - } - - pc = poptGetContext("getjoinableous", argc, argv, long_options, 0); - - poptSetOtherOptionHelp(pc, "hostname domainname"); - while((opt = poptGetNextOpt(pc)) != -1) { - switch (opt) { - case 'D': - domain_name = poptGetOptArg(pc); - break; - } - } - - if (!poptPeekArg(pc)) { - poptPrintHelp(pc, stderr, 0); - goto out; - } - host_name = poptGetArg(pc); - - /* NetGetJoinableOUs */ - - status = NetGetJoinableOUs(host_name, - domain_name, - ctx->username, - ctx->password, - &num_ous, - &ous); - if (status != 0) { - printf("failed with: %s\n", - libnetapi_get_error_string(ctx, status)); - } else { - printf("Successfully queried joinable ous:\n"); - for (i=0; i. + */ + +#include +#include +#include +#include + +#include + +#include "common.h" + +int main(int argc, const char **argv) +{ + NET_API_STATUS status; + const char *host_name = NULL; + const char *domain_name = NULL; + const char **ous = NULL; + uint32_t num_ous = 0; + struct libnetapi_ctx *ctx = NULL; + int i; + + poptContext pc; + int opt; + + struct poptOption long_options[] = { + POPT_AUTOHELP + { "domain", 0, POPT_ARG_STRING, NULL, 'D', "Domain name", "DOMAIN" }, + POPT_COMMON_LIBNETAPI_EXAMPLES + POPT_TABLEEND + }; + + status = libnetapi_init(&ctx); + if (status != 0) { + return status; + } + + pc = poptGetContext("getjoinableous", argc, argv, long_options, 0); + + poptSetOtherOptionHelp(pc, "hostname domainname"); + while((opt = poptGetNextOpt(pc)) != -1) { + switch (opt) { + case 'D': + domain_name = poptGetOptArg(pc); + break; + } + } + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + host_name = poptGetArg(pc); + + /* NetGetJoinableOUs */ + + status = NetGetJoinableOUs(host_name, + domain_name, + ctx->username, + ctx->password, + &num_ous, + &ous); + if (status != 0) { + printf("failed with: %s\n", + libnetapi_get_error_string(ctx, status)); + } else { + printf("Successfully queried joinable ous:\n"); + for (i=0; i. + */ + +#include +#include +#include +#include +#include + +#include + +#include "common.h" + +enum { + OPT_OU = 1000 +}; + +int main(int argc, const char **argv) +{ + NET_API_STATUS status; + const char *host_name = NULL; + const char *domain_name = NULL; + const char *account_ou = NULL; + const char *account = NULL; + const char *password = NULL; + uint32_t join_flags = NETSETUP_JOIN_DOMAIN | + NETSETUP_ACCT_CREATE | + NETSETUP_DOMAIN_JOIN_IF_JOINED; + struct libnetapi_ctx *ctx = NULL; + + poptContext pc; + int opt; + + struct poptOption long_options[] = { + POPT_AUTOHELP + { "ou", 0, POPT_ARG_STRING, &account_ou, 'U', "Account ou", "ACCOUNT_OU" }, + { "domain", 0, POPT_ARG_STRING, &domain_name, 'U', "Domain name (required)", "DOMAIN" }, + { "userd", 0, POPT_ARG_STRING, &account, 'U', "Domain admin account", "USERNAME" }, + { "passwordd", 0, POPT_ARG_STRING, &password, 'U', "Domain admin password", "PASSWORD" }, + POPT_COMMON_LIBNETAPI_EXAMPLES + POPT_TABLEEND + }; + + + status = libnetapi_init(&ctx); + if (status != 0) { + return status; + } + + pc = poptGetContext("netdomjoin", argc, argv, long_options, 0); + + poptSetOtherOptionHelp(pc, "hostname"); + while((opt = poptGetNextOpt(pc)) != -1) { + } + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + host_name = poptGetArg(pc); + + if (!domain_name) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + + /* NetJoinDomain */ + + status = NetJoinDomain(host_name, + domain_name, + account_ou, + account, + password, + join_flags); + if (status != 0) { + const char *errstr = NULL; + errstr = libnetapi_get_error_string(ctx, status); + printf("Join failed with: %s\n", errstr); + } else { + printf("Successfully joined\n"); + } + + out: + libnetapi_free(ctx); + poptFreeContext(pc); + + return status; +} diff --git a/source3/lib/netapi/examples/netdomjoin/netdomjoin.c b/source3/lib/netapi/examples/netdomjoin/netdomjoin.c deleted file mode 100644 index 08ce71b938..0000000000 --- a/source3/lib/netapi/examples/netdomjoin/netdomjoin.c +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Unix SMB/CIFS implementation. - * Join Support (cmdline + netapi) - * 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 - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see . - */ - -#include -#include -#include -#include -#include - -#include - -#include "common.h" - -enum { - OPT_OU = 1000 -}; - -int main(int argc, const char **argv) -{ - NET_API_STATUS status; - const char *host_name = NULL; - const char *domain_name = NULL; - const char *account_ou = NULL; - const char *account = NULL; - const char *password = NULL; - uint32_t join_flags = NETSETUP_JOIN_DOMAIN | - NETSETUP_ACCT_CREATE | - NETSETUP_DOMAIN_JOIN_IF_JOINED; - struct libnetapi_ctx *ctx = NULL; - - poptContext pc; - int opt; - - struct poptOption long_options[] = { - POPT_AUTOHELP - { "ou", 0, POPT_ARG_STRING, &account_ou, 'U', "Account ou", "ACCOUNT_OU" }, - { "domain", 0, POPT_ARG_STRING, &domain_name, 'U', "Domain name (required)", "DOMAIN" }, - { "userd", 0, POPT_ARG_STRING, &account, 'U', "Domain admin account", "USERNAME" }, - { "passwordd", 0, POPT_ARG_STRING, &password, 'U', "Domain admin password", "PASSWORD" }, - POPT_COMMON_LIBNETAPI_EXAMPLES - POPT_TABLEEND - }; - - - status = libnetapi_init(&ctx); - if (status != 0) { - return status; - } - - pc = poptGetContext("netdomjoin", argc, argv, long_options, 0); - - poptSetOtherOptionHelp(pc, "hostname"); - while((opt = poptGetNextOpt(pc)) != -1) { - } - - if (!poptPeekArg(pc)) { - poptPrintHelp(pc, stderr, 0); - goto out; - } - host_name = poptGetArg(pc); - - if (!domain_name) { - poptPrintHelp(pc, stderr, 0); - goto out; - } - - /* NetJoinDomain */ - - status = NetJoinDomain(host_name, - domain_name, - account_ou, - account, - password, - join_flags); - if (status != 0) { - const char *errstr = NULL; - errstr = libnetapi_get_error_string(ctx, status); - printf("Join failed with: %s\n", errstr); - } else { - printf("Successfully joined\n"); - } - - out: - libnetapi_free(ctx); - poptFreeContext(pc); - - return status; -} -- cgit From 72718e08990107e087fca8b63418772b110bfbee Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 2 Sep 2008 14:34:58 +0200 Subject: netapi: add NETSETUP_JOIN_STATUS to public header. Guenther (This used to be commit 86de3242a478c9f669958414ee9e7720cddad9aa) --- source3/lib/netapi/netapi.h | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h index ba509f8d8c..8f1ec84fbc 100644 --- a/source3/lib/netapi/netapi.h +++ b/source3/lib/netapi/netapi.h @@ -97,6 +97,13 @@ struct DOMAIN_CONTROLLER_INFO { #define TIMEQ_FOREVER ( (uint32_t)-1L ) +enum NETSETUP_JOIN_STATUS { + NetSetupUnknownStatus=0, + NetSetupUnjoined=1, + NetSetupWorkgroupName=2, + NetSetupDomainName=3 +}; + struct SERVER_INFO_100 { uint32_t sv100_platform_id; const char * sv100_name; -- cgit From 150911f33e137d017e9f08f953bd96218401e04a Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 2 Sep 2008 14:35:58 +0200 Subject: netapi: remove NetSetup* flags from netdomjoin-gui. Guenther (This used to be commit 5851b4e40e5cc2b7ba973b274f9203aa6e6fb1d8) --- source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c index 98994b69f8..40a6e415eb 100644 --- a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c +++ b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c @@ -38,9 +38,6 @@ #define SAMBA_IMAGE_PATH "/usr/share/pixmaps/samba/logo.png" #define SAMBA_IMAGE_PATH_SMALL "/usr/share/pixmaps/samba/logo-small.png" -#define NetSetupWorkgroupName ( 2 ) -#define NetSetupDomainName ( 3 ) - #define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0) static gboolean verbose = FALSE; -- cgit From fda790bb5d9459d876b6cd4f2944ce434ebb7def Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 4 Sep 2008 15:53:54 +0200 Subject: netapi: add skeleton for NetShareGetInfo. Guenther (This used to be commit 237c6e0bca44e19ca89532e565b1345f9f329111) --- source3/lib/netapi/libnetapi.c | 46 ++++++++++++++++++++++++++++++++++++++++++ source3/lib/netapi/libnetapi.h | 8 ++++++++ source3/lib/netapi/share.c | 18 +++++++++++++++++ 3 files changed, 72 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/libnetapi.c b/source3/lib/netapi/libnetapi.c index 3e42254c7e..2ad63e37dd 100644 --- a/source3/lib/netapi/libnetapi.c +++ b/source3/lib/netapi/libnetapi.c @@ -1964,3 +1964,49 @@ NET_API_STATUS NetShareEnum(const char * server_name /* [in] */, return r.out.result; } +/**************************************************************** + NetShareGetInfo +****************************************************************/ + +NET_API_STATUS NetShareGetInfo(const char * server_name /* [in] */, + const char * net_name /* [in] */, + uint32_t level /* [in] */, + uint8_t **buffer /* [out] [ref] */) +{ + struct NetShareGetInfo r; + struct libnetapi_ctx *ctx = NULL; + NET_API_STATUS status; + WERROR werr; + + status = libnetapi_getctx(&ctx); + if (status != 0) { + return status; + } + + /* In parameters */ + r.in.server_name = server_name; + r.in.net_name = net_name; + r.in.level = level; + + /* Out parameters */ + r.out.buffer = buffer; + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_IN_DEBUG(NetShareGetInfo, &r); + } + + if (LIBNETAPI_LOCAL_SERVER(server_name)) { + werr = NetShareGetInfo_l(ctx, &r); + } else { + werr = NetShareGetInfo_r(ctx, &r); + } + + r.out.result = W_ERROR_V(werr); + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_OUT_DEBUG(NetShareGetInfo, &r); + } + + return r.out.result; +} + diff --git a/source3/lib/netapi/libnetapi.h b/source3/lib/netapi/libnetapi.h index d2531a287f..9c7aff82d2 100644 --- a/source3/lib/netapi/libnetapi.h +++ b/source3/lib/netapi/libnetapi.h @@ -352,4 +352,12 @@ WERROR NetShareEnum_r(struct libnetapi_ctx *ctx, struct NetShareEnum *r); WERROR NetShareEnum_l(struct libnetapi_ctx *ctx, struct NetShareEnum *r); +NET_API_STATUS NetShareGetInfo(const char * server_name /* [in] */, + const char * net_name /* [in] */, + uint32_t level /* [in] */, + uint8_t **buffer /* [out] [ref] */); +WERROR NetShareGetInfo_r(struct libnetapi_ctx *ctx, + struct NetShareGetInfo *r); +WERROR NetShareGetInfo_l(struct libnetapi_ctx *ctx, + struct NetShareGetInfo *r); #endif /* __LIBNETAPI_LIBNETAPI__ */ diff --git a/source3/lib/netapi/share.c b/source3/lib/netapi/share.c index d31743200f..20bfd78571 100644 --- a/source3/lib/netapi/share.c +++ b/source3/lib/netapi/share.c @@ -201,3 +201,21 @@ WERROR NetShareEnum_l(struct libnetapi_ctx *ctx, { LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetShareEnum); } + +/**************************************************************** +****************************************************************/ + +WERROR NetShareGetInfo_r(struct libnetapi_ctx *ctx, + struct NetShareGetInfo *r) +{ + return WERR_NOT_SUPPORTED; +} + +/**************************************************************** +****************************************************************/ + +WERROR NetShareGetInfo_l(struct libnetapi_ctx *ctx, + struct NetShareGetInfo *r) +{ + LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetShareGetInfo); +} -- cgit From 93cb6d26d168df88900a51d158f56208eb387c74 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 4 Sep 2008 15:59:58 +0200 Subject: netapi: add NetShareGetInfo to public header. Guenther (This used to be commit 5c63b181ec698a6134ce31326dab9e6bd232acf0) --- source3/lib/netapi/netapi.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h index 8f1ec84fbc..4432f767f8 100644 --- a/source3/lib/netapi/netapi.h +++ b/source3/lib/netapi/netapi.h @@ -1636,6 +1636,26 @@ NET_API_STATUS NetShareEnum(const char * server_name /* [in] */, uint32_t *total_entries /* [out] [ref] */, uint32_t *resume_handle /* [in,out] [ref] */); +/************************************************************//** + * + * NetShareGetInfo + * + * @brief Get Share Info + * + * @param[in] server_name The server name to connect to + * @param[in] net_name The name of the share to query + * @param[in] level The level defining the SHARE_INFO_X structure + * @param[out] buffer The buffer containing a SHARE_INFO_X structure + * @return NET_API_STATUS + * + * example share/share_getinfo.c + ***************************************************************/ + +NET_API_STATUS NetShareGetInfo(const char * server_name /* [in] */, + const char * net_name /* [in] */, + uint32_t level /* [in] */, + uint8_t **buffer /* [out] [ref] */); + #ifdef __cplusplus } #endif /* __cplusplus */ -- cgit From 15a3ec1467582b671bb64ed6927e846e4b27558f Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 4 Sep 2008 16:18:32 +0200 Subject: netapi: add NetShareGetInfo example code. Guenther (This used to be commit 0166c8f04be1168fe83d7bf3730d3011ffd8c6f6) --- source3/lib/netapi/examples/Makefile.in | 8 +- source3/lib/netapi/examples/share/share_getinfo.c | 152 ++++++++++++++++++++++ 2 files changed, 159 insertions(+), 1 deletion(-) create mode 100644 source3/lib/netapi/examples/share/share_getinfo.c (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/Makefile.in b/source3/lib/netapi/examples/Makefile.in index ee72a95062..0613951eec 100644 --- a/source3/lib/netapi/examples/Makefile.in +++ b/source3/lib/netapi/examples/Makefile.in @@ -54,7 +54,8 @@ PROGS = bin/getdc@EXEEXT@ \ bin/server_getinfo@EXEEXT@ \ bin/share_add@EXEEXT@ \ bin/share_del@EXEEXT@ \ - bin/share_enum@EXEEXT@ + bin/share_enum@EXEEXT@ \ + bin/share_getinfo@EXEEXT@ all: $(PROGS) @@ -121,6 +122,7 @@ SERVERGETINFO_OBJ = server/server_getinfo.o $(CMDLINE_OBJ) SHAREADD_OBJ = share/share_add.o $(CMDLINE_OBJ) SHAREDEL_OBJ = share/share_del.o $(CMDLINE_OBJ) SHAREENUM_OBJ = share/share_enum.o $(CMDLINE_OBJ) +SHAREGETINFO_OBJ = share/share_getinfo.o $(CMDLINE_OBJ) bin/getdc@EXEEXT@: $(BINARY_PREREQS) $(GETDC_OBJ) @echo Linking $@ @@ -274,6 +276,10 @@ bin/share_enum@EXEEXT@: $(BINARY_PREREQS) $(SHAREENUM_OBJ) @echo Linking $@ @$(CC) $(FLAGS) -o $@ $(SHAREENUM_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) +bin/share_getinfo@EXEEXT@: $(BINARY_PREREQS) $(SHAREGETINFO_OBJ) + @echo Linking $@ + @$(CC) $(FLAGS) -o $@ $(SHAREGETINFO_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) + clean: -rm -f $(PROGS) -rm -f core */*~ *~ \ diff --git a/source3/lib/netapi/examples/share/share_getinfo.c b/source3/lib/netapi/examples/share/share_getinfo.c new file mode 100644 index 0000000000..5b3bbc38b6 --- /dev/null +++ b/source3/lib/netapi/examples/share/share_getinfo.c @@ -0,0 +1,152 @@ +/* + * Unix SMB/CIFS implementation. + * NetShareGetInfo query + * Copyright (C) Guenther Deschner 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include +#include +#include +#include +#include + +#include + +#include "common.h" + +int main(int argc, const char **argv) +{ + NET_API_STATUS status; + struct libnetapi_ctx *ctx = NULL; + const char *hostname = NULL; + const char *sharename = NULL; + uint32_t level = 2; + uint8_t *buffer = NULL; + + struct SHARE_INFO_0 *i0 = NULL; + struct SHARE_INFO_1 *i1 = NULL; + struct SHARE_INFO_2 *i2 = NULL; + struct SHARE_INFO_501 *i501 = NULL; + struct SHARE_INFO_1005 *i1005 = NULL; + + poptContext pc; + int opt; + + struct poptOption long_options[] = { + POPT_AUTOHELP + POPT_COMMON_LIBNETAPI_EXAMPLES + POPT_TABLEEND + }; + + status = libnetapi_init(&ctx); + if (status != 0) { + return status; + } + + pc = poptGetContext("share_getinfo", argc, argv, long_options, 0); + + poptSetOtherOptionHelp(pc, "hostname sharename level"); + while((opt = poptGetNextOpt(pc)) != -1) { + } + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + hostname = poptGetArg(pc); + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + sharename = poptGetArg(pc); + + if (poptPeekArg(pc)) { + level = atoi(poptGetArg(pc)); + } + + /* NetShareGetInfo */ + + status = NetShareGetInfo(hostname, + sharename, + level, + &buffer); + if (status != 0) { + printf("NetShareGetInfo failed with: %s\n", + libnetapi_get_error_string(ctx, status)); + goto out; + } + + switch (level) { + case 0: + i0 = (struct SHARE_INFO_0 *)buffer; + break; + case 1: + i1 = (struct SHARE_INFO_1 *)buffer; + break; + case 2: + i2 = (struct SHARE_INFO_2 *)buffer; + break; + case 501: + i501 = (struct SHARE_INFO_501 *)buffer; + break; + case 1005: + i1005 = (struct SHARE_INFO_1005 *)buffer; + break; + + default: + break; + } + + switch (level) { + case 0: + printf("netname: %s\n", i0->shi0_netname); + break; + case 1: + printf("netname: %s\n", i1->shi1_netname); + printf("type: %d\n", i1->shi1_type); + printf("remark: %s\n", i1->shi1_remark); + break; + case 2: + printf("netname: %s\n", i2->shi2_netname); + printf("type: %d\n", i2->shi2_type); + printf("remark: %s\n", i2->shi2_remark); + printf("permissions: %d\n", i2->shi2_permissions); + printf("max users: %d\n", i2->shi2_max_uses); + printf("current users: %d\n", i2->shi2_current_uses); + printf("path: %s\n", i2->shi2_path); + printf("password: %s\n", i2->shi2_passwd); + break; + case 501: + printf("netname: %s\n", i501->shi501_netname); + printf("type: %d\n", i501->shi501_type); + printf("remark: %s\n", i501->shi501_remark); + printf("flags: %d\n", i501->shi501_flags); + break; + case 1005: + printf("flags: %s\n", i1005->shi1005_flags); + break; + default: + break; + } + NetApiBufferFree(buffer); + + out: + libnetapi_free(ctx); + poptFreeContext(pc); + + return status; +} -- cgit From cdb31ef2f913e3504466121dde171bc6fff35c37 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 4 Sep 2008 16:31:18 +0200 Subject: netapi: implement NetShareGetInfo_r. Guenther (This used to be commit 029cf4a2a9d95b9c7de6eb75118a92474c0ae9c1) --- source3/lib/netapi/share.c | 155 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 154 insertions(+), 1 deletion(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/share.c b/source3/lib/netapi/share.c index 20bfd78571..d0bcb3885f 100644 --- a/source3/lib/netapi/share.c +++ b/source3/lib/netapi/share.c @@ -27,6 +27,101 @@ /**************************************************************** ****************************************************************/ +static NTSTATUS map_srvsvc_share_info_to_SHARE_INFO_buffer(TALLOC_CTX *mem_ctx, + uint32_t level, + union srvsvc_NetShareInfo *info, + uint8_t **buffer, + uint32_t *num_shares) +{ + struct SHARE_INFO_0 i0; + struct SHARE_INFO_1 i1; + struct SHARE_INFO_2 i2; + struct SHARE_INFO_501 i501; + struct SHARE_INFO_1005 i1005; + + struct srvsvc_NetShareInfo0 *s0; + struct srvsvc_NetShareInfo1 *s1; + struct srvsvc_NetShareInfo2 *s2; + struct srvsvc_NetShareInfo501 *s501; + struct srvsvc_NetShareInfo1005 *s1005; + + if (!buffer) { + return NT_STATUS_INVALID_PARAMETER; + } + + switch (level) { + case 0: + s0 = info->info0; + + i0.shi0_netname = talloc_strdup(mem_ctx, s0->name); + + ADD_TO_ARRAY(mem_ctx, struct SHARE_INFO_0, i0, + (struct SHARE_INFO_0 **)buffer, + num_shares); + break; + + case 1: + s1 = info->info1; + + i1.shi1_netname = talloc_strdup(mem_ctx, s1->name); + i1.shi1_type = s1->type; + i1.shi1_remark = talloc_strdup(mem_ctx, s1->comment); + + ADD_TO_ARRAY(mem_ctx, struct SHARE_INFO_1, i1, + (struct SHARE_INFO_1 **)buffer, + num_shares); + break; + + case 2: + s2 = info->info2; + + i2.shi2_netname = talloc_strdup(mem_ctx, s2->name); + i2.shi2_type = s2->type; + i2.shi2_remark = talloc_strdup(mem_ctx, s2->comment); + i2.shi2_permissions = s2->permissions; + i2.shi2_max_uses = s2->max_users; + i2.shi2_current_uses = s2->current_users; + i2.shi2_path = talloc_strdup(mem_ctx, s2->path); + i2.shi2_passwd = talloc_strdup(mem_ctx, s2->password); + + ADD_TO_ARRAY(mem_ctx, struct SHARE_INFO_2, i2, + (struct SHARE_INFO_2 **)buffer, + num_shares); + break; + + case 501: + s501 = info->info501; + + i501.shi501_netname = talloc_strdup(mem_ctx, s501->name); + i501.shi501_type = s501->type; + i501.shi501_remark = talloc_strdup(mem_ctx, s501->comment); + i501.shi501_flags = s501->csc_policy; + + ADD_TO_ARRAY(mem_ctx, struct SHARE_INFO_501, i501, + (struct SHARE_INFO_501 **)buffer, + num_shares); + break; + + case 1005: + s1005 = info->info1005; + + i1005.shi1005_flags = s1005->dfs_flags; + + ADD_TO_ARRAY(mem_ctx, struct SHARE_INFO_1005, i1005, + (struct SHARE_INFO_1005 **)buffer, + num_shares); + break; + + default: + return NT_STATUS_INVALID_PARAMETER; + } + + return NT_STATUS_OK; +} + +/**************************************************************** +****************************************************************/ + static NTSTATUS map_SHARE_INFO_buffer_to_srvsvc_share_info(TALLOC_CTX *mem_ctx, uint8_t *buffer, uint32_t level, @@ -208,7 +303,65 @@ WERROR NetShareEnum_l(struct libnetapi_ctx *ctx, WERROR NetShareGetInfo_r(struct libnetapi_ctx *ctx, struct NetShareGetInfo *r) { - return WERR_NOT_SUPPORTED; + WERROR werr; + NTSTATUS status; + struct cli_state *cli = NULL; + struct rpc_pipe_client *pipe_cli = NULL; + union srvsvc_NetShareInfo info; + uint32_t num_entries = 0; + + if (!r->in.net_name) { + return WERR_INVALID_PARAM; + } + + switch (r->in.level) { + case 0: + case 1: + case 2: + case 501: + case 1005: + break; + case 502: + case 503: + return WERR_NOT_SUPPORTED; + default: + return WERR_UNKNOWN_LEVEL; + } + + werr = libnetapi_open_pipe(ctx, r->in.server_name, + &ndr_table_srvsvc.syntax_id, + &cli, + &pipe_cli); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + status = rpccli_srvsvc_NetShareGetInfo(pipe_cli, ctx, + r->in.server_name, + r->in.net_name, + r->in.level, + &info, + &werr); + + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + status = map_srvsvc_share_info_to_SHARE_INFO_buffer(ctx, + r->in.level, + &info, + r->out.buffer, + &num_entries); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + } + + done: + if (!cli) { + return werr; + } + + return werr; } /**************************************************************** -- cgit From c38546ad9d6d97b9f92a548cec4f9e61ba7d2cc1 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 4 Sep 2008 19:29:47 +0200 Subject: netapi: implement NetShareEnum_r. Guenther (This used to be commit 3fbfbaea004f792a577f21275e6e4218f581d698) --- source3/lib/netapi/share.c | 91 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 90 insertions(+), 1 deletion(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/share.c b/source3/lib/netapi/share.c index d0bcb3885f..1b3cd4abc8 100644 --- a/source3/lib/netapi/share.c +++ b/source3/lib/netapi/share.c @@ -285,7 +285,96 @@ WERROR NetShareDel_l(struct libnetapi_ctx *ctx, WERROR NetShareEnum_r(struct libnetapi_ctx *ctx, struct NetShareEnum *r) { - return WERR_NOT_SUPPORTED; + WERROR werr; + NTSTATUS status; + struct cli_state *cli = NULL; + struct rpc_pipe_client *pipe_cli = NULL; + struct srvsvc_NetShareInfoCtr info_ctr; + struct srvsvc_NetShareCtr0 ctr0; + struct srvsvc_NetShareCtr1 ctr1; + struct srvsvc_NetShareCtr2 ctr2; + uint32_t i; + + if (!r->out.buffer) { + return WERR_INVALID_PARAM; + } + + switch (r->in.level) { + case 0: + case 1: + case 2: + break; + case 502: + case 503: + return WERR_NOT_SUPPORTED; + default: + return WERR_UNKNOWN_LEVEL; + } + + ZERO_STRUCT(info_ctr); + + werr = libnetapi_open_pipe(ctx, r->in.server_name, + &ndr_table_srvsvc.syntax_id, + &cli, + &pipe_cli); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + info_ctr.level = r->in.level; + switch (r->in.level) { + case 0: + info_ctr.ctr.ctr0 = &ctr0; + break; + case 1: + info_ctr.ctr.ctr1 = &ctr1; + break; + case 2: + info_ctr.ctr.ctr2 = &ctr2; + break; + } + + status = rpccli_srvsvc_NetShareEnum(pipe_cli, ctx, + r->in.server_name, + &info_ctr, + r->in.prefmaxlen, + r->out.total_entries, + r->out.resume_handle, + &werr); + if (NT_STATUS_IS_ERR(status)) { + goto done; + } + + for (i=0; i < info_ctr.ctr.ctr1->count; i++) { + union srvsvc_NetShareInfo _i; + switch (r->in.level) { + case 0: + _i.info0 = &info_ctr.ctr.ctr0->array[i]; + break; + case 1: + _i.info1 = &info_ctr.ctr.ctr1->array[i]; + break; + case 2: + _i.info2 = &info_ctr.ctr.ctr2->array[i]; + break; + } + + status = map_srvsvc_share_info_to_SHARE_INFO_buffer(ctx, + r->in.level, + &_i, + r->out.buffer, + r->out.entries_read); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + } + } + + done: + if (!cli) { + return werr; + } + + return werr; } /**************************************************************** -- cgit From 582a48d89ce5e9650e6a5b293c06b2294cac0841 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 4 Sep 2008 20:03:14 +0200 Subject: netapi: add skeleton for NetShareSetInfo. Guenther (This used to be commit 4d7947e54959c6a445e8b0f7a8313fe232c1fb8f) --- source3/lib/netapi/libnetapi.c | 48 ++++++++++++++++++++++++++++++++++++++++++ source3/lib/netapi/libnetapi.h | 9 ++++++++ source3/lib/netapi/share.c | 18 ++++++++++++++++ 3 files changed, 75 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/libnetapi.c b/source3/lib/netapi/libnetapi.c index 2ad63e37dd..1f3f2d9bdb 100644 --- a/source3/lib/netapi/libnetapi.c +++ b/source3/lib/netapi/libnetapi.c @@ -2010,3 +2010,51 @@ NET_API_STATUS NetShareGetInfo(const char * server_name /* [in] */, return r.out.result; } +/**************************************************************** + NetShareSetInfo +****************************************************************/ + +NET_API_STATUS NetShareSetInfo(const char * server_name /* [in] */, + const char * net_name /* [in] */, + uint32_t level /* [in] */, + uint8_t *buffer /* [in] [ref] */, + uint32_t *parm_err /* [out] [ref] */) +{ + struct NetShareSetInfo r; + struct libnetapi_ctx *ctx = NULL; + NET_API_STATUS status; + WERROR werr; + + status = libnetapi_getctx(&ctx); + if (status != 0) { + return status; + } + + /* In parameters */ + r.in.server_name = server_name; + r.in.net_name = net_name; + r.in.level = level; + r.in.buffer = buffer; + + /* Out parameters */ + r.out.parm_err = parm_err; + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_IN_DEBUG(NetShareSetInfo, &r); + } + + if (LIBNETAPI_LOCAL_SERVER(server_name)) { + werr = NetShareSetInfo_l(ctx, &r); + } else { + werr = NetShareSetInfo_r(ctx, &r); + } + + r.out.result = W_ERROR_V(werr); + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_OUT_DEBUG(NetShareSetInfo, &r); + } + + return r.out.result; +} + diff --git a/source3/lib/netapi/libnetapi.h b/source3/lib/netapi/libnetapi.h index 9c7aff82d2..00ad4de479 100644 --- a/source3/lib/netapi/libnetapi.h +++ b/source3/lib/netapi/libnetapi.h @@ -360,4 +360,13 @@ WERROR NetShareGetInfo_r(struct libnetapi_ctx *ctx, struct NetShareGetInfo *r); WERROR NetShareGetInfo_l(struct libnetapi_ctx *ctx, struct NetShareGetInfo *r); +NET_API_STATUS NetShareSetInfo(const char * server_name /* [in] */, + const char * net_name /* [in] */, + uint32_t level /* [in] */, + uint8_t *buffer /* [in] [ref] */, + uint32_t *parm_err /* [out] [ref] */); +WERROR NetShareSetInfo_r(struct libnetapi_ctx *ctx, + struct NetShareSetInfo *r); +WERROR NetShareSetInfo_l(struct libnetapi_ctx *ctx, + struct NetShareSetInfo *r); #endif /* __LIBNETAPI_LIBNETAPI__ */ diff --git a/source3/lib/netapi/share.c b/source3/lib/netapi/share.c index 1b3cd4abc8..36f8133f7d 100644 --- a/source3/lib/netapi/share.c +++ b/source3/lib/netapi/share.c @@ -461,3 +461,21 @@ WERROR NetShareGetInfo_l(struct libnetapi_ctx *ctx, { LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetShareGetInfo); } + +/**************************************************************** +****************************************************************/ + +WERROR NetShareSetInfo_r(struct libnetapi_ctx *ctx, + struct NetShareSetInfo *r) +{ + return WERR_NOT_SUPPORTED; +} + +/**************************************************************** +****************************************************************/ + +WERROR NetShareSetInfo_l(struct libnetapi_ctx *ctx, + struct NetShareSetInfo *r) +{ + LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetShareSetInfo); +} -- cgit From 09e96f2a98019beb8e0982ba86dd25336eed22be Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 4 Sep 2008 20:04:35 +0200 Subject: netapi: add NetShareSetInfo to public header. Guenther (This used to be commit 2066ebc5e3e782b9443aee3e5beb1a99d69096ec) --- source3/lib/netapi/netapi.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h index 4432f767f8..e9670bb16e 100644 --- a/source3/lib/netapi/netapi.h +++ b/source3/lib/netapi/netapi.h @@ -1656,6 +1656,28 @@ NET_API_STATUS NetShareGetInfo(const char * server_name /* [in] */, uint32_t level /* [in] */, uint8_t **buffer /* [out] [ref] */); +/************************************************************//** + * + * NetShareSetInfo + * + * @brief Set Share Info + * + * @param[in] server_name The server name to connect to + * @param[in] net_name The name of the share to query + * @param[in] level The level defining the SHARE_INFO_X structure + * @param[in] buffer The buffer containing a SHARE_INFO_X structure + * @param[out] parm_err The returned parameter error number if any + * @return NET_API_STATUS + * + * example share/share_setinfo.c + ***************************************************************/ + +NET_API_STATUS NetShareSetInfo(const char * server_name /* [in] */, + const char * net_name /* [in] */, + uint32_t level /* [in] */, + uint8_t *buffer /* [in] [ref] */, + uint32_t *parm_err /* [out] [ref] */); + #ifdef __cplusplus } #endif /* __cplusplus */ -- cgit From 86df00a38813f96780e4b7a8bbc7cfc02572b13e Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 4 Sep 2008 20:12:56 +0200 Subject: netapi: add NetShareSetInfo example code. Guenther (This used to be commit a7050c999ff0a13724afbbbb2628cb47daec5b35) --- source3/lib/netapi/examples/Makefile.in | 8 +- source3/lib/netapi/examples/share/share_setinfo.c | 105 ++++++++++++++++++++++ 2 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 source3/lib/netapi/examples/share/share_setinfo.c (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/Makefile.in b/source3/lib/netapi/examples/Makefile.in index 0613951eec..0fca4c704b 100644 --- a/source3/lib/netapi/examples/Makefile.in +++ b/source3/lib/netapi/examples/Makefile.in @@ -55,7 +55,8 @@ PROGS = bin/getdc@EXEEXT@ \ bin/share_add@EXEEXT@ \ bin/share_del@EXEEXT@ \ bin/share_enum@EXEEXT@ \ - bin/share_getinfo@EXEEXT@ + bin/share_getinfo@EXEEXT@ \ + bin/share_setinfo@EXEEXT@ all: $(PROGS) @@ -123,6 +124,7 @@ SHAREADD_OBJ = share/share_add.o $(CMDLINE_OBJ) SHAREDEL_OBJ = share/share_del.o $(CMDLINE_OBJ) SHAREENUM_OBJ = share/share_enum.o $(CMDLINE_OBJ) SHAREGETINFO_OBJ = share/share_getinfo.o $(CMDLINE_OBJ) +SHARESETINFO_OBJ = share/share_setinfo.o $(CMDLINE_OBJ) bin/getdc@EXEEXT@: $(BINARY_PREREQS) $(GETDC_OBJ) @echo Linking $@ @@ -280,6 +282,10 @@ bin/share_getinfo@EXEEXT@: $(BINARY_PREREQS) $(SHAREGETINFO_OBJ) @echo Linking $@ @$(CC) $(FLAGS) -o $@ $(SHAREGETINFO_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) +bin/share_setinfo@EXEEXT@: $(BINARY_PREREQS) $(SHARESETINFO_OBJ) + @echo Linking $@ + @$(CC) $(FLAGS) -o $@ $(SHARESETINFO_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) + clean: -rm -f $(PROGS) -rm -f core */*~ *~ \ diff --git a/source3/lib/netapi/examples/share/share_setinfo.c b/source3/lib/netapi/examples/share/share_setinfo.c new file mode 100644 index 0000000000..f4748f4122 --- /dev/null +++ b/source3/lib/netapi/examples/share/share_setinfo.c @@ -0,0 +1,105 @@ +/* + * Unix SMB/CIFS implementation. + * NetShareSetInfo query + * Copyright (C) Guenther Deschner 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include +#include +#include +#include +#include + +#include + +#include "common.h" + +int main(int argc, const char **argv) +{ + NET_API_STATUS status; + struct libnetapi_ctx *ctx = NULL; + const char *hostname = NULL; + const char *sharename = NULL; + const char *comment = "NetApi generated Share comment"; + uint32_t level = 1004; + uint8_t *buffer = NULL; + uint32_t parm_err = 0; + + struct SHARE_INFO_1004 i1004; + + poptContext pc; + int opt; + + struct poptOption long_options[] = { + POPT_AUTOHELP + POPT_COMMON_LIBNETAPI_EXAMPLES + POPT_TABLEEND + }; + + status = libnetapi_init(&ctx); + if (status != 0) { + return status; + } + + pc = poptGetContext("share_setinfo", argc, argv, long_options, 0); + + poptSetOtherOptionHelp(pc, "hostname sharename comment"); + while((opt = poptGetNextOpt(pc)) != -1) { + } + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + hostname = poptGetArg(pc); + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + sharename = poptGetArg(pc); + + if (poptPeekArg(pc)) { + comment = poptGetArg(pc); + } + + /* NetShareSetInfo */ + switch (level) { + case 1004: + i1004.shi1004_remark = comment; + buffer = (uint8_t *)&i1004; + break; + default: + break; + } + + status = NetShareSetInfo(hostname, + sharename, + level, + buffer, + &parm_err); + if (status != 0) { + printf("NetShareSetInfo failed with: %s\n", + libnetapi_get_error_string(ctx, status)); + goto out; + } + + out: + libnetapi_free(ctx); + poptFreeContext(pc); + + return status; +} -- cgit From 136ddc8f049a248b635d82ff395d774c5d78769d Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 4 Sep 2008 20:24:02 +0200 Subject: netapi: add support for level 1004 in map_SHARE_INFO_buffer_to_srvsvc_share_info. Guenther (This used to be commit f21a934e1e100cb1496a6c854684ff110ba6d1cc) --- source3/lib/netapi/share.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/share.c b/source3/lib/netapi/share.c index 36f8133f7d..414900a11d 100644 --- a/source3/lib/netapi/share.c +++ b/source3/lib/netapi/share.c @@ -128,7 +128,9 @@ static NTSTATUS map_SHARE_INFO_buffer_to_srvsvc_share_info(TALLOC_CTX *mem_ctx, union srvsvc_NetShareInfo *info) { struct SHARE_INFO_2 *i2 = NULL; + struct SHARE_INFO_1004 *i1004 = NULL; struct srvsvc_NetShareInfo2 *s2 = NULL; + struct srvsvc_NetShareInfo1004 *s1004 = NULL; if (!buffer) { return NT_STATUS_INVALID_PARAMETER; @@ -152,6 +154,17 @@ static NTSTATUS map_SHARE_INFO_buffer_to_srvsvc_share_info(TALLOC_CTX *mem_ctx, info->info2 = s2; + break; + case 1004: + i1004 = (struct SHARE_INFO_1004 *)buffer; + + s1004 = TALLOC_P(mem_ctx, struct srvsvc_NetShareInfo1004); + NT_STATUS_HAVE_NO_MEMORY(s1004); + + s1004->comment = i1004->shi1004_remark; + + info->info1004 = s1004; + break; default: return NT_STATUS_INVALID_PARAMETER; -- cgit From 05449814e98b50a0f2615be5c476b48db1036f22 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 4 Sep 2008 20:24:23 +0200 Subject: netapi: implement NetShareSetInfo_r. Guenther (This used to be commit ebcd45ed3ff79ce3b90872aa87a737ba6ee3401f) --- source3/lib/netapi/share.c | 60 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/share.c b/source3/lib/netapi/share.c index 414900a11d..c6af548225 100644 --- a/source3/lib/netapi/share.c +++ b/source3/lib/netapi/share.c @@ -481,7 +481,65 @@ WERROR NetShareGetInfo_l(struct libnetapi_ctx *ctx, WERROR NetShareSetInfo_r(struct libnetapi_ctx *ctx, struct NetShareSetInfo *r) { - return WERR_NOT_SUPPORTED; + WERROR werr; + NTSTATUS status; + struct cli_state *cli = NULL; + struct rpc_pipe_client *pipe_cli = NULL; + union srvsvc_NetShareInfo info; + + if (!r->in.buffer) { + return WERR_INVALID_PARAM; + } + + switch (r->in.level) { + case 2: + case 1004: + break; + case 1: + case 502: + case 503: + case 1005: + case 1006: + case 1501: + return WERR_NOT_SUPPORTED; + default: + return WERR_UNKNOWN_LEVEL; + } + + werr = libnetapi_open_pipe(ctx, r->in.server_name, + &ndr_table_srvsvc.syntax_id, + &cli, + &pipe_cli); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + status = map_SHARE_INFO_buffer_to_srvsvc_share_info(ctx, + r->in.buffer, + r->in.level, + &info); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + status = rpccli_srvsvc_NetShareSetInfo(pipe_cli, ctx, + r->in.server_name, + r->in.net_name, + r->in.level, + &info, + r->out.parm_err, + &werr); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + done: + if (!cli) { + return werr; + } + + return werr; } /**************************************************************** -- cgit From 9194109e6c05a482ba63d97a11cd2b286ac3bfbe Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 5 Sep 2008 14:01:17 +0200 Subject: netapi: fix NetShareGetInfo example output. Guenther (This used to be commit 00ecf8205c4cd4a4c150b204811d448d0ac53c0d) --- source3/lib/netapi/examples/share/share_getinfo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/share/share_getinfo.c b/source3/lib/netapi/examples/share/share_getinfo.c index 5b3bbc38b6..479da5cc4a 100644 --- a/source3/lib/netapi/examples/share/share_getinfo.c +++ b/source3/lib/netapi/examples/share/share_getinfo.c @@ -137,7 +137,7 @@ int main(int argc, const char **argv) printf("flags: %d\n", i501->shi501_flags); break; case 1005: - printf("flags: %s\n", i1005->shi1005_flags); + printf("flags: %d\n", i1005->shi1005_flags); break; default: break; -- cgit From a828a644d0054117cffca02c29b33bdeb1296982 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 5 Sep 2008 23:21:58 +0200 Subject: netapi: re-arrange a little NetLocalGroupSetMembers example code. Guenther (This used to be commit 84a25e69947c077623165fe4535cddd48aba0a3e) --- .../lib/netapi/examples/localgroup/localgroup_setmembers.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/localgroup/localgroup_setmembers.c b/source3/lib/netapi/examples/localgroup/localgroup_setmembers.c index acee5cd9c6..c35f2bbb81 100644 --- a/source3/lib/netapi/examples/localgroup/localgroup_setmembers.c +++ b/source3/lib/netapi/examples/localgroup/localgroup_setmembers.c @@ -40,6 +40,7 @@ int main(int argc, const char **argv) uint32_t level = 3; const char **names = NULL; int i = 0; + size_t buf_size = 0; poptContext pc; int opt; @@ -85,8 +86,9 @@ int main(int argc, const char **argv) switch (level) { case 0: - status = NetApiBufferAllocate(sizeof(struct LOCALGROUP_MEMBERS_INFO_0) * total_entries, - (void **)&g0); + buf_size = sizeof(struct LOCALGROUP_MEMBERS_INFO_0) * total_entries; + + status = NetApiBufferAllocate(buf_size, (void **)&g0); if (status) { printf("NetApiBufferAllocate failed with: %s\n", libnetapi_get_error_string(ctx, status)); @@ -103,8 +105,9 @@ int main(int argc, const char **argv) buffer = (uint8_t *)g0; break; case 3: - status = NetApiBufferAllocate(sizeof(struct LOCALGROUP_MEMBERS_INFO_3) * total_entries, - (void **)&g3); + buf_size = sizeof(struct LOCALGROUP_MEMBERS_INFO_3) * total_entries; + + status = NetApiBufferAllocate(buf_size, (void **)&g3); if (status) { printf("NetApiBufferAllocate failed with: %s\n", libnetapi_get_error_string(ctx, status)); @@ -133,6 +136,8 @@ int main(int argc, const char **argv) libnetapi_get_error_string(ctx, status)); } + NetApiBufferFree(buffer); + out: libnetapi_free(ctx); poptFreeContext(pc); -- cgit From c01d0c0bdf6f5733e344b166875f27ba5a9c863c Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 5 Sep 2008 15:13:13 +0200 Subject: netapi: add NetShare testsuite. Guenther (This used to be commit 07cf13e43d03803a5f039fa6df3c9a35c701d43a) --- source3/lib/netapi/tests/Makefile.in | 2 +- source3/lib/netapi/tests/common.h | 2 + source3/lib/netapi/tests/netapitest.c | 5 + source3/lib/netapi/tests/netshare.c | 232 ++++++++++++++++++++++++++++++++++ 4 files changed, 240 insertions(+), 1 deletion(-) create mode 100644 source3/lib/netapi/tests/netshare.c (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/tests/Makefile.in b/source3/lib/netapi/tests/Makefile.in index f13281ee8c..d3f0663908 100644 --- a/source3/lib/netapi/tests/Makefile.in +++ b/source3/lib/netapi/tests/Makefile.in @@ -44,7 +44,7 @@ bin/.dummy: CMDLINE_OBJ = common.o NETAPIBUFFER_OBJ = netapibuffer.o -NETAPITEST_OBJ = netapitest.o netlocalgroup.o netuser.o netgroup.o netdisplay.o $(CMDLINE_OBJ) +NETAPITEST_OBJ = netapitest.o netlocalgroup.o netuser.o netgroup.o netdisplay.o netshare.o $(CMDLINE_OBJ) bin/netapitest@EXEEXT@: $(BINARY_PREREQS) $(NETAPITEST_OBJ) @echo Linking $@ diff --git a/source3/lib/netapi/tests/common.h b/source3/lib/netapi/tests/common.h index ed073c0038..5a320321ba 100644 --- a/source3/lib/netapi/tests/common.h +++ b/source3/lib/netapi/tests/common.h @@ -39,6 +39,8 @@ NET_API_STATUS netapitest_group(struct libnetapi_ctx *ctx, const char *hostname); NET_API_STATUS netapitest_display(struct libnetapi_ctx *ctx, const char *hostname); +NET_API_STATUS netapitest_share(struct libnetapi_ctx *ctx, + const char *hostname); #ifndef ARRAY_SIZE #define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0])) diff --git a/source3/lib/netapi/tests/netapitest.c b/source3/lib/netapi/tests/netapitest.c index de81f5efe8..87144020f5 100644 --- a/source3/lib/netapi/tests/netapitest.c +++ b/source3/lib/netapi/tests/netapitest.c @@ -79,6 +79,11 @@ int main(int argc, const char **argv) goto out; } + status = netapitest_share(ctx, hostname); + if (status) { + goto out; + } + out: if (status != 0) { printf("testsuite failed with: %s\n", diff --git a/source3/lib/netapi/tests/netshare.c b/source3/lib/netapi/tests/netshare.c new file mode 100644 index 0000000000..9446c307b3 --- /dev/null +++ b/source3/lib/netapi/tests/netshare.c @@ -0,0 +1,232 @@ +/* + * Unix SMB/CIFS implementation. + * NetShare testsuite + * Copyright (C) Guenther Deschner 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include +#include +#include +#include +#include + +#include + +#include "common.h" + +static NET_API_STATUS test_netshareenum(const char *hostname, + uint32_t level, + const char *sharename) +{ + NET_API_STATUS status; + uint32_t entries_read = 0; + uint32_t total_entries = 0; + uint32_t resume_handle = 0; + int found_share = 0; + const char *current_name; + uint8_t *buffer = NULL; + int i; + + struct SHARE_INFO_0 *i0; + struct SHARE_INFO_1 *i1; + struct SHARE_INFO_2 *i2; + + printf("testing NetShareEnum level %d\n", level); + + do { + status = NetShareEnum(hostname, + level, + &buffer, + (uint32_t)-1, + &entries_read, + &total_entries, + &resume_handle); + if (status == 0 || status == ERROR_MORE_DATA) { + switch (level) { + case 0: + i0 = (struct SHARE_INFO_0 *)buffer; + break; + case 1: + i1 = (struct SHARE_INFO_1 *)buffer; + break; + case 2: + i2 = (struct SHARE_INFO_2 *)buffer; + break; + default: + return -1; + } + + for (i=0; ishi0_netname; + break; + case 1: + current_name = i1->shi1_netname; + break; + case 2: + current_name = i2->shi2_netname; + break; + default: + break; + } + + if (strcasecmp(current_name, sharename) == 0) { + found_share = 1; + } + + switch (level) { + case 0: + i0++; + break; + case 1: + i1++; + break; + case 2: + i2++; + break; + } + } + NetApiBufferFree(buffer); + } + } while (status == ERROR_MORE_DATA); + + if (status) { + return status; + } + + if (!found_share) { + printf("failed to get share\n"); + return -1; + } + + return 0; +} + +NET_API_STATUS netapitest_share(struct libnetapi_ctx *ctx, + const char *hostname) +{ + NET_API_STATUS status = 0; + const char *sharename, *comment; + uint8_t *buffer = NULL; + struct SHARE_INFO_2 i2; + struct SHARE_INFO_1004 i1004; + struct SHARE_INFO_501 *i501 = NULL; + uint32_t parm_err = 0; + uint32_t levels[] = { 0, 1, 2, 501, 1005 }; + uint32_t enum_levels[] = { 0, 1, 2 }; + int i; + + printf("NetShare tests\n"); + + sharename = "torture_test_share"; + + /* cleanup */ + NetShareDel(hostname, sharename, 0); + + /* add a share */ + + printf("testing NetShareAdd\n"); + + ZERO_STRUCT(i2); + + i2.shi2_netname = sharename; + i2.shi2_path = "c:\\"; + + status = NetShareAdd(hostname, 2, (uint8_t *)&i2, &parm_err); + if (status) { + NETAPI_STATUS(ctx, status, "NetShareAdd"); + goto out; + }; + + /* test enum */ + + for (i=0; ishi501_remark, comment) != 0) { + NETAPI_STATUS(ctx, status, "NetShareGetInfo"); + goto out; + } + + /* delete */ + + printf("testing NetShareDel\n"); + + status = NetShareDel(hostname, sharename, 0); + if (status) { + NETAPI_STATUS(ctx, status, "NetShareDel"); + goto out; + }; + + /* should not exist anymore */ + + status = NetShareGetInfo(hostname, sharename, 0, &buffer); + if (status == 0) { + NETAPI_STATUS(ctx, status, "NetShareGetInfo"); + goto out; + }; + + status = 0; + + printf("NetShare tests succeeded\n"); + out: + if (status != 0) { + printf("NetShare testsuite failed with: %s\n", + libnetapi_get_error_string(ctx, status)); + } + + return status; +} -- cgit From 7089c800c19802c9ca7aaa6feceb8311af019020 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 5 Sep 2008 17:06:24 +0200 Subject: netapi: expand NetUser testsuite a little. Guenther (This used to be commit fc1b04df78fc0fb5bc59fa0120c0e29bbb3978a1) --- source3/lib/netapi/tests/netuser.c | 148 ++++++++++++++++++++++++++++++++++++- 1 file changed, 146 insertions(+), 2 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/tests/netuser.c b/source3/lib/netapi/tests/netuser.c index c50e384951..f1622e45c4 100644 --- a/source3/lib/netapi/tests/netuser.c +++ b/source3/lib/netapi/tests/netuser.c @@ -41,7 +41,12 @@ static NET_API_STATUS test_netuserenum(const char *hostname, int i; struct USER_INFO_0 *info0; + struct USER_INFO_1 *info1; + struct USER_INFO_2 *info2; + struct USER_INFO_3 *info3; + struct USER_INFO_4 *info4; struct USER_INFO_10 *info10; + struct USER_INFO_11 *info11; struct USER_INFO_20 *info20; struct USER_INFO_23 *info23; @@ -61,9 +66,24 @@ static NET_API_STATUS test_netuserenum(const char *hostname, case 0: info0 = (struct USER_INFO_0 *)buffer; break; + case 1: + info1 = (struct USER_INFO_1 *)buffer; + break; + case 2: + info2 = (struct USER_INFO_2 *)buffer; + break; + case 3: + info3 = (struct USER_INFO_3 *)buffer; + break; + case 4: + info4 = (struct USER_INFO_4 *)buffer; + break; case 10: info10 = (struct USER_INFO_10 *)buffer; break; + case 11: + info11 = (struct USER_INFO_11 *)buffer; + break; case 20: info20 = (struct USER_INFO_20 *)buffer; break; @@ -80,9 +100,24 @@ static NET_API_STATUS test_netuserenum(const char *hostname, case 0: current_name = info0->usri0_name; break; + case 1: + current_name = info1->usri1_name; + break; + case 2: + current_name = info2->usri2_name; + break; + case 3: + current_name = info3->usri3_name; + break; + case 4: + current_name = info4->usri4_name; + break; case 10: current_name = info10->usri10_name; break; + case 11: + current_name = info11->usri11_name; + break; case 20: current_name = info20->usri20_name; break; @@ -101,9 +136,24 @@ static NET_API_STATUS test_netuserenum(const char *hostname, case 0: info0++; break; + case 1: + info1++; + break; + case 2: + info2++; + break; + case 3: + info3++; + break; + case 4: + info4++; + break; case 10: info10++; break; + case 11: + info11++; + break; case 20: info20++; break; @@ -202,14 +252,97 @@ static NET_API_STATUS test_netusermodals(struct libnetapi_ctx *ctx, return 0; } +static NET_API_STATUS test_netusergetgroups(const char *hostname, + uint32_t level, + const char *username, + const char *groupname) +{ + NET_API_STATUS status; + uint32_t entries_read = 0; + uint32_t total_entries = 0; + const char *current_name; + int found_group = 0; + uint8_t *buffer = NULL; + int i; + + struct GROUP_USERS_INFO_0 *i0; + struct GROUP_USERS_INFO_1 *i1; + + printf("testing NetUserGetGroups level %d\n", level); + + do { + status = NetUserGetGroups(hostname, + username, + level, + &buffer, + 120, //(uint32_t)-1, + &entries_read, + &total_entries); + if (status == 0 || status == ERROR_MORE_DATA) { + switch (level) { + case 0: + i0 = (struct GROUP_USERS_INFO_0 *)buffer; + break; + case 1: + i1 = (struct GROUP_USERS_INFO_1 *)buffer; + break; + default: + return -1; + } + + for (i=0; igrui0_name; + break; + case 1: + current_name = i1->grui1_name; + break; + default: + return -1; + } + + if (groupname && strcasecmp(current_name, groupname) == 0) { + found_group = 1; + } + + switch (level) { + case 0: + i0++; + break; + case 1: + i1++; + break; + default: + break; + } + } + NetApiBufferFree(buffer); + } + } while (status == ERROR_MORE_DATA); + + if (status) { + return status; + } + + if (groupname && !found_group) { + printf("failed to get membership\n"); + return -1; + } + + return 0; +} + NET_API_STATUS netapitest_user(struct libnetapi_ctx *ctx, const char *hostname) { NET_API_STATUS status = 0; const char *username, *username2; uint8_t *buffer = NULL; - uint32_t levels[] = { 0, 10, 20, 23 }; - uint32_t enum_levels[] = { 0, 10, 20, 23 }; + uint32_t levels[] = { 0, 1, 2, 3, 4, 10, 11, 20, 23 }; + uint32_t enum_levels[] = { 0, 1, 2, 3, 4, 10, 11, 20, 23 }; + uint32_t getgr_levels[] = { 0, 1 }; int i; struct USER_INFO_1007 u1007; @@ -256,6 +389,17 @@ NET_API_STATUS netapitest_user(struct libnetapi_ctx *ctx, } } + /* testing getgroups */ + + for (i=0; i Date: Tue, 9 Sep 2008 19:36:51 +0200 Subject: netapi: fix doxygen warning. Guenther (This used to be commit e0312728a5ac5abd64622600f47967861a4e0183) --- source3/lib/netapi/netapi.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h index e9670bb16e..234caf4b93 100644 --- a/source3/lib/netapi/netapi.h +++ b/source3/lib/netapi/netapi.h @@ -1579,7 +1579,7 @@ NET_API_STATUS NetRemoteTOD(const char * server_name /* [in] */, * * @param[in] server_name The server name to connect to * @param[in] level The level defining the requested SHARE_INFO_X structure - * @param[in] buf The buffer containing a SHARE_INFO_X structure + * @param[in] buffer The buffer containing a SHARE_INFO_X structure * @param[out] parm_err The returned parameter error number if any * @return NET_API_STATUS * -- cgit From d323e48abea064a51399a6bcca63742cd32e81cd Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 10 Sep 2008 13:26:54 +0200 Subject: netapi: fix NetShareEnum_r which in fact enumerates all shares. Guenther (This used to be commit 0637ad872e5d30f71b6ea1ec2d243ec8e8836c31) --- source3/lib/netapi/share.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/share.c b/source3/lib/netapi/share.c index c6af548225..2752895387 100644 --- a/source3/lib/netapi/share.c +++ b/source3/lib/netapi/share.c @@ -347,13 +347,13 @@ WERROR NetShareEnum_r(struct libnetapi_ctx *ctx, break; } - status = rpccli_srvsvc_NetShareEnum(pipe_cli, ctx, - r->in.server_name, - &info_ctr, - r->in.prefmaxlen, - r->out.total_entries, - r->out.resume_handle, - &werr); + status = rpccli_srvsvc_NetShareEnumAll(pipe_cli, ctx, + r->in.server_name, + &info_ctr, + r->in.prefmaxlen, + r->out.total_entries, + r->out.resume_handle, + &werr); if (NT_STATUS_IS_ERR(status)) { goto done; } -- cgit From 07585d9fb7bf8b7b8b22538f39208965c91a508a Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 10 Sep 2008 10:13:55 +0200 Subject: netapi: fix NetShareGetInfo_r. Guenther (This used to be commit b42408f54ea61ad47f5a33085ab1532c67ceee83) --- source3/lib/netapi/share.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/share.c b/source3/lib/netapi/share.c index 2752895387..8b9124b513 100644 --- a/source3/lib/netapi/share.c +++ b/source3/lib/netapi/share.c @@ -412,7 +412,7 @@ WERROR NetShareGetInfo_r(struct libnetapi_ctx *ctx, union srvsvc_NetShareInfo info; uint32_t num_entries = 0; - if (!r->in.net_name) { + if (!r->in.net_name || !r->out.buffer) { return WERR_INVALID_PARAM; } -- cgit From 93eb9860c6e26bf53bb103e758c935987dba27c8 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 10 Sep 2008 10:13:41 +0200 Subject: netapi: fix NetShareEnum_r. Guenther (This used to be commit 7e8903b53beba3ad1bb8617ed435249257724be3) --- source3/lib/netapi/share.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/share.c b/source3/lib/netapi/share.c index 8b9124b513..1d0e1810f1 100644 --- a/source3/lib/netapi/share.c +++ b/source3/lib/netapi/share.c @@ -337,12 +337,15 @@ WERROR NetShareEnum_r(struct libnetapi_ctx *ctx, info_ctr.level = r->in.level; switch (r->in.level) { case 0: + ZERO_STRUCT(ctr0); info_ctr.ctr.ctr0 = &ctr0; - break; + break; case 1: + ZERO_STRUCT(ctr1); info_ctr.ctr.ctr1 = &ctr1; break; case 2: + ZERO_STRUCT(ctr2); info_ctr.ctr.ctr2 = &ctr2; break; } -- cgit From 35c96827b4b1a453919184b554ba8b66bf0d3b42 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 8 Sep 2008 16:42:10 +0200 Subject: netapi: make add_GROUP_USERS_INFO_X_buffer non-static. Guenther (This used to be commit 87fc15d9b52bbb15550015cb106062d24c5674ba) --- source3/lib/netapi/netapi_private.h | 7 +++++++ source3/lib/netapi/user.c | 12 ++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi_private.h b/source3/lib/netapi/netapi_private.h index 4d4c12ae85..e6a2eb8e99 100644 --- a/source3/lib/netapi/netapi_private.h +++ b/source3/lib/netapi/netapi_private.h @@ -77,4 +77,11 @@ void libnetapi_samr_close_connect_handle(struct libnetapi_ctx *ctx, struct policy_handle *handle); void libnetapi_samr_free(struct libnetapi_ctx *ctx); +NTSTATUS add_GROUP_USERS_INFO_X_buffer(TALLOC_CTX *mem_ctx, + uint32_t level, + const char *group_name, + uint32_t attributes, + uint8_t **buffer, + uint32_t *num_entries); + #endif diff --git a/source3/lib/netapi/user.c b/source3/lib/netapi/user.c index ae8d2ecd89..4fe0aa04ab 100644 --- a/source3/lib/netapi/user.c +++ b/source3/lib/netapi/user.c @@ -2736,12 +2736,12 @@ WERROR NetUserModalsSet_l(struct libnetapi_ctx *ctx, /**************************************************************** ****************************************************************/ -static NTSTATUS add_GROUP_USERS_INFO_X_buffer(TALLOC_CTX *mem_ctx, - uint32_t level, - const char *group_name, - uint32_t attributes, - uint8_t **buffer, - uint32_t *num_entries) +NTSTATUS add_GROUP_USERS_INFO_X_buffer(TALLOC_CTX *mem_ctx, + uint32_t level, + const char *group_name, + uint32_t attributes, + uint8_t **buffer, + uint32_t *num_entries) { struct GROUP_USERS_INFO_0 u0; struct GROUP_USERS_INFO_1 u1; -- cgit From cbcebf0f08395737b4d8fa8b7d1bcdc4384467d9 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 5 Sep 2008 16:51:55 +0200 Subject: netapi: add skeleton for NetUserSetGroups. Guenther (This used to be commit 165be948fab1c64526421b44b08de700849bba25) --- source3/lib/netapi/libnetapi.c | 48 ++++++++++++++++++++++++++++++++++++++++++ source3/lib/netapi/libnetapi.h | 9 ++++++++ source3/lib/netapi/user.c | 19 +++++++++++++++++ 3 files changed, 76 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/libnetapi.c b/source3/lib/netapi/libnetapi.c index 1f3f2d9bdb..e8c69ae837 100644 --- a/source3/lib/netapi/libnetapi.c +++ b/source3/lib/netapi/libnetapi.c @@ -825,6 +825,54 @@ NET_API_STATUS NetUserGetGroups(const char * server_name /* [in] */, return r.out.result; } +/**************************************************************** + NetUserSetGroups +****************************************************************/ + +NET_API_STATUS NetUserSetGroups(const char * server_name /* [in] */, + const char * user_name /* [in] */, + uint32_t level /* [in] */, + uint8_t *buffer /* [in] [ref] */, + uint32_t num_entries /* [in] */) +{ + struct NetUserSetGroups r; + struct libnetapi_ctx *ctx = NULL; + NET_API_STATUS status; + WERROR werr; + + status = libnetapi_getctx(&ctx); + if (status != 0) { + return status; + } + + /* In parameters */ + r.in.server_name = server_name; + r.in.user_name = user_name; + r.in.level = level; + r.in.buffer = buffer; + r.in.num_entries = num_entries; + + /* Out parameters */ + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_IN_DEBUG(NetUserSetGroups, &r); + } + + if (LIBNETAPI_LOCAL_SERVER(server_name)) { + werr = NetUserSetGroups_l(ctx, &r); + } else { + werr = NetUserSetGroups_r(ctx, &r); + } + + r.out.result = W_ERROR_V(werr); + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_OUT_DEBUG(NetUserSetGroups, &r); + } + + return r.out.result; +} + /**************************************************************** NetUserModalsGet ****************************************************************/ diff --git a/source3/lib/netapi/libnetapi.h b/source3/lib/netapi/libnetapi.h index 00ad4de479..eecbf8e4d5 100644 --- a/source3/lib/netapi/libnetapi.h +++ b/source3/lib/netapi/libnetapi.h @@ -145,6 +145,15 @@ WERROR NetUserGetGroups_r(struct libnetapi_ctx *ctx, struct NetUserGetGroups *r); WERROR NetUserGetGroups_l(struct libnetapi_ctx *ctx, struct NetUserGetGroups *r); +NET_API_STATUS NetUserSetGroups(const char * server_name /* [in] */, + const char * user_name /* [in] */, + uint32_t level /* [in] */, + uint8_t *buffer /* [in] [ref] */, + uint32_t num_entries /* [in] */); +WERROR NetUserSetGroups_r(struct libnetapi_ctx *ctx, + struct NetUserSetGroups *r); +WERROR NetUserSetGroups_l(struct libnetapi_ctx *ctx, + struct NetUserSetGroups *r); NET_API_STATUS NetUserModalsGet(const char * server_name /* [in] */, uint32_t level /* [in] */, uint8_t **buffer /* [out] [ref] */); diff --git a/source3/lib/netapi/user.c b/source3/lib/netapi/user.c index 4fe0aa04ab..bf3397b4eb 100644 --- a/source3/lib/netapi/user.c +++ b/source3/lib/netapi/user.c @@ -2923,3 +2923,22 @@ WERROR NetUserGetGroups_l(struct libnetapi_ctx *ctx, { LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetUserGetGroups); } + +/**************************************************************** +****************************************************************/ + + +WERROR NetUserSetGroups_r(struct libnetapi_ctx *ctx, + struct NetUserSetGroups *r) +{ + return WERR_NOT_SUPPORTED; +} + +/**************************************************************** +****************************************************************/ + +WERROR NetUserSetGroups_l(struct libnetapi_ctx *ctx, + struct NetUserSetGroups *r) +{ + LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetUserSetGroups); +} -- cgit From fce223602e33232c021ddfa7b4326ab1c464b4b4 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 8 Sep 2008 10:26:11 +0200 Subject: netapi: add NetUserSetGroups to public header. Guenther (This used to be commit 3e96cd229c1536a7e16441f600c379ceb651b2b3) --- source3/lib/netapi/netapi.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h index 234caf4b93..b1b8e8f3fc 100644 --- a/source3/lib/netapi/netapi.h +++ b/source3/lib/netapi/netapi.h @@ -1149,6 +1149,28 @@ NET_API_STATUS NetUserGetGroups(const char * server_name /* [in] */, uint32_t *entries_read /* [out] [ref] */, uint32_t *total_entries /* [out] [ref] */); +/************************************************************//** + * + * NetUserSetGroups + * + * @brief Set grouplist of a user on a server + * + * @param[in] server_name The server name to connect to + * @param[in] user_name The user name to query + * @param[in] level The level defining the GROUP_USERS_INFO_X structures in the buffer + * @param[in] buffer The buffer containing GROUP_USERS_INFO_X structures + * @param[in] num_entries The number of X structures in the buffer + * @return NET_API_STATUS + * + * example user/user_setgroups.c + ***************************************************************/ + +NET_API_STATUS NetUserSetGroups(const char * server_name /* [in] */, + const char * user_name /* [in] */, + uint32_t level /* [in] */, + uint8_t *buffer /* [in] [ref] */, + uint32_t num_entries /* [in] */); + /************************************************************//** * * NetQueryDisplayInformation -- cgit From 2fb0f6c995b5532f8b37f1cb344fbb3efb9ea710 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 5 Sep 2008 17:01:23 +0200 Subject: netapi: add example code for NetUserSetGroups. Guenther (This used to be commit 1355939b4c9c2883f9542ef4189cac7418104b68) --- source3/lib/netapi/examples/Makefile.in | 6 + source3/lib/netapi/examples/user/user_setgroups.c | 144 ++++++++++++++++++++++ 2 files changed, 150 insertions(+) create mode 100644 source3/lib/netapi/examples/user/user_setgroups.c (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/Makefile.in b/source3/lib/netapi/examples/Makefile.in index 0fca4c704b..c7b279c0f5 100644 --- a/source3/lib/netapi/examples/Makefile.in +++ b/source3/lib/netapi/examples/Makefile.in @@ -33,6 +33,7 @@ PROGS = bin/getdc@EXEEXT@ \ bin/user_modalsget@EXEEXT@ \ bin/user_modalsset@EXEEXT@ \ bin/user_getgroups@EXEEXT@ \ + bin/user_setgroups@EXEEXT@ \ bin/group_add@EXEEXT@ \ bin/group_del@EXEEXT@ \ bin/group_enum@EXEEXT@ \ @@ -101,6 +102,7 @@ USERSETINFO_OBJ = user/user_setinfo.o $(CMDLINE_OBJ) USERMODALSGET_OBJ = user/user_modalsget.o $(CMDLINE_OBJ) USERMODALSSET_OBJ = user/user_modalsset.o $(CMDLINE_OBJ) USERGETGROUPS_OBJ = user/user_getgroups.o $(CMDLINE_OBJ) +USERSETGROUPS_OBJ = user/user_setgroups.o $(CMDLINE_OBJ) GROUPADD_OBJ = group/group_add.o $(CMDLINE_OBJ) GROUPDEL_OBJ = group/group_del.o $(CMDLINE_OBJ) GROUPENUM_OBJ = group/group_enum.o $(CMDLINE_OBJ) @@ -190,6 +192,10 @@ bin/user_getgroups@EXEEXT@: $(BINARY_PREREQS) $(USERGETGROUPS_OBJ) @echo Linking $@ @$(CC) $(FLAGS) -o $@ $(USERGETGROUPS_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) +bin/user_setgroups@EXEEXT@: $(BINARY_PREREQS) $(USERSETGROUPS_OBJ) + @echo Linking $@ + @$(CC) $(FLAGS) -o $@ $(USERSETGROUPS_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) + bin/group_add@EXEEXT@: $(BINARY_PREREQS) $(GROUPADD_OBJ) @echo Linking $@ @$(CC) $(FLAGS) -o $@ $(GROUPADD_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) diff --git a/source3/lib/netapi/examples/user/user_setgroups.c b/source3/lib/netapi/examples/user/user_setgroups.c new file mode 100644 index 0000000000..de3ff22ec8 --- /dev/null +++ b/source3/lib/netapi/examples/user/user_setgroups.c @@ -0,0 +1,144 @@ +/* + * Unix SMB/CIFS implementation. + * NetUserSetGroups query + * Copyright (C) Guenther Deschner 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include +#include +#include +#include +#include + +#include + +#include "common.h" + +int main(int argc, const char **argv) +{ + NET_API_STATUS status; + struct libnetapi_ctx *ctx = NULL; + const char *hostname = NULL; + const char *username = NULL; + uint32_t level = 0; + uint8_t *buffer = NULL; + uint32_t num_entries = 0; + const char **names = NULL; + int i = 0; + size_t buf_size = 0; + + struct GROUP_USERS_INFO_0 *g0 = NULL; + struct GROUP_USERS_INFO_1 *g1 = NULL; + + poptContext pc; + int opt; + + struct poptOption long_options[] = { + POPT_AUTOHELP + POPT_COMMON_LIBNETAPI_EXAMPLES + POPT_TABLEEND + }; + + status = libnetapi_init(&ctx); + if (status != 0) { + return status; + } + + pc = poptGetContext("user_setgroups", argc, argv, long_options, 0); + + poptSetOtherOptionHelp(pc, "hostname username group1 group2 ..."); + while((opt = poptGetNextOpt(pc)) != -1) { + } + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + hostname = poptGetArg(pc); + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + username = poptGetArg(pc); + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + + names = poptGetArgs(pc); + for (i=0; names[i] != NULL; i++) { + num_entries++; + } + + switch (level) { + case 0: + buf_size = sizeof(struct GROUP_USERS_INFO_0) * num_entries; + + status = NetApiBufferAllocate(buf_size, (void **)&g0); + if (status) { + printf("NetApiBufferAllocate failed with: %s\n", + libnetapi_get_error_string(ctx, status)); + goto out; + } + + for (i=0; i Date: Mon, 8 Sep 2008 19:10:00 +0200 Subject: netapi: implement NetUserSetGroups_r. Guenther (This used to be commit 2ddee7577de1d6d2b7a39b949ed6a925da2e9db8) --- source3/lib/netapi/user.c | 244 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 242 insertions(+), 2 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/user.c b/source3/lib/netapi/user.c index bf3397b4eb..4fbc27f364 100644 --- a/source3/lib/netapi/user.c +++ b/source3/lib/netapi/user.c @@ -2927,11 +2927,251 @@ WERROR NetUserGetGroups_l(struct libnetapi_ctx *ctx, /**************************************************************** ****************************************************************/ - WERROR NetUserSetGroups_r(struct libnetapi_ctx *ctx, struct NetUserSetGroups *r) { - return WERR_NOT_SUPPORTED; + struct cli_state *cli = NULL; + struct rpc_pipe_client *pipe_cli = NULL; + struct policy_handle connect_handle, domain_handle, user_handle, group_handle; + struct lsa_String lsa_account_name; + struct dom_sid2 *domain_sid = NULL; + struct samr_Ids user_rids, name_types; + struct samr_Ids group_rids; + struct samr_RidWithAttributeArray *rid_array = NULL; + + uint32_t *add_rids = NULL; + uint32_t *del_rids = NULL; + size_t num_add_rids = 0; + size_t num_del_rids = 0; + + uint32_t *member_rids = NULL; + size_t num_member_rids = 0; + + struct GROUP_USERS_INFO_0 *i0 = NULL; + struct GROUP_USERS_INFO_1 *i1 = NULL; + + int i, k; + + NTSTATUS status = NT_STATUS_OK; + WERROR werr; + + ZERO_STRUCT(connect_handle); + ZERO_STRUCT(domain_handle); + + if (!r->in.buffer) { + return WERR_INVALID_PARAM; + } + + switch (r->in.level) { + case 0: + case 1: + break; + default: + return WERR_UNKNOWN_LEVEL; + } + + werr = libnetapi_open_pipe(ctx, r->in.server_name, + &ndr_table_samr.syntax_id, + &cli, + &pipe_cli); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + werr = libnetapi_samr_open_domain(ctx, pipe_cli, + SAMR_ACCESS_ENUM_DOMAINS | + SAMR_ACCESS_OPEN_DOMAIN, + SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, + &connect_handle, + &domain_handle, + &domain_sid); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + init_lsa_String(&lsa_account_name, r->in.user_name); + + status = rpccli_samr_LookupNames(pipe_cli, ctx, + &domain_handle, + 1, + &lsa_account_name, + &user_rids, + &name_types); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + status = rpccli_samr_OpenUser(pipe_cli, ctx, + &domain_handle, + SAMR_USER_ACCESS_GET_GROUPS, + user_rids.ids[0], + &user_handle); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + switch (r->in.level) { + case 0: + i0 = (struct GROUP_USERS_INFO_0 *)r->in.buffer; + break; + case 1: + i1 = (struct GROUP_USERS_INFO_1 *)r->in.buffer; + break; + } + + for (i=0; i < r->in.num_entries; i++) { + + switch (r->in.level) { + case 0: + init_lsa_String(&lsa_account_name, i0->grui0_name); + i0++; + break; + case 1: + init_lsa_String(&lsa_account_name, i1->grui1_name); + i1++; + break; + } + + status = rpccli_samr_LookupNames(pipe_cli, ctx, + &domain_handle, + 1, + &lsa_account_name, + &group_rids, + &name_types); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + if (!add_rid_to_array_unique(ctx, + group_rids.ids[0], + &member_rids, + &num_member_rids)) { + werr = WERR_GENERAL_FAILURE; + goto done; + } + } + + status = rpccli_samr_GetGroupsForUser(pipe_cli, ctx, + &user_handle, + &rid_array); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + /* add list */ + + for (i=0; i < r->in.num_entries; i++) { + bool already_member = false; + for (k=0; k < rid_array->count; k++) { + if (member_rids[i] == rid_array->rids[k].rid) { + already_member = true; + break; + } + } + if (!already_member) { + if (!add_rid_to_array_unique(ctx, + member_rids[i], + &add_rids, &num_add_rids)) { + werr = WERR_GENERAL_FAILURE; + goto done; + } + } + } + + /* del list */ + + for (k=0; k < rid_array->count; k++) { + bool keep_member = false; + for (i=0; i < r->in.num_entries; i++) { + if (member_rids[i] == rid_array->rids[k].rid) { + keep_member = true; + break; + } + } + if (!keep_member) { + if (!add_rid_to_array_unique(ctx, + rid_array->rids[k].rid, + &del_rids, &num_del_rids)) { + werr = WERR_GENERAL_FAILURE; + goto done; + } + } + } + + /* add list */ + + for (i=0; i < num_add_rids; i++) { + status = rpccli_samr_OpenGroup(pipe_cli, ctx, + &domain_handle, + SAMR_GROUP_ACCESS_ADD_MEMBER, + add_rids[i], + &group_handle); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + status = rpccli_samr_AddGroupMember(pipe_cli, ctx, + &group_handle, + user_rids.ids[0], + 7 /* ? */); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + if (is_valid_policy_hnd(&group_handle)) { + rpccli_samr_Close(pipe_cli, ctx, &group_handle); + } + } + + /* del list */ + + for (i=0; i < num_del_rids; i++) { + status = rpccli_samr_OpenGroup(pipe_cli, ctx, + &domain_handle, + SAMR_GROUP_ACCESS_REMOVE_MEMBER, + del_rids[i], + &group_handle); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + status = rpccli_samr_DeleteGroupMember(pipe_cli, ctx, + &group_handle, + user_rids.ids[0]); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + if (is_valid_policy_hnd(&group_handle)) { + rpccli_samr_Close(pipe_cli, ctx, &group_handle); + } + } + + werr = WERR_OK; + + done: + if (!cli) { + return werr; + } + + if (is_valid_policy_hnd(&group_handle)) { + rpccli_samr_Close(pipe_cli, ctx, &group_handle); + } + + if (ctx->disable_policy_handle_cache) { + libnetapi_samr_close_domain_handle(ctx, &domain_handle); + libnetapi_samr_close_connect_handle(ctx, &connect_handle); + } + + return werr; } /**************************************************************** -- cgit From ffdfe3e8b48bd74199f089176782ae3117106b71 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 8 Sep 2008 10:21:17 +0200 Subject: netapi: add skeleton for NetGroupSetUsers. Guenther (This used to be commit 4d92d000a1676d2da45e8113ade60250c6c7eebe) --- source3/lib/netapi/group.c | 18 ++++++++++++++++ source3/lib/netapi/libnetapi.c | 48 ++++++++++++++++++++++++++++++++++++++++++ source3/lib/netapi/libnetapi.h | 9 ++++++++ 3 files changed, 75 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/group.c b/source3/lib/netapi/group.c index f7c9366820..44c4a74df1 100644 --- a/source3/lib/netapi/group.c +++ b/source3/lib/netapi/group.c @@ -1303,3 +1303,21 @@ WERROR NetGroupGetUsers_l(struct libnetapi_ctx *ctx, { LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetGroupGetUsers); } + +/**************************************************************** +****************************************************************/ + +WERROR NetGroupSetUsers_r(struct libnetapi_ctx *ctx, + struct NetGroupSetUsers *r) +{ + return WERR_NOT_SUPPORTED; +} + +/**************************************************************** +****************************************************************/ + +WERROR NetGroupSetUsers_l(struct libnetapi_ctx *ctx, + struct NetGroupSetUsers *r) +{ + LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetGroupSetUsers); +} diff --git a/source3/lib/netapi/libnetapi.c b/source3/lib/netapi/libnetapi.c index e8c69ae837..4f3a5bdcb0 100644 --- a/source3/lib/netapi/libnetapi.c +++ b/source3/lib/netapi/libnetapi.c @@ -1393,6 +1393,54 @@ NET_API_STATUS NetGroupGetUsers(const char * server_name /* [in] */, return r.out.result; } +/**************************************************************** + NetGroupSetUsers +****************************************************************/ + +NET_API_STATUS NetGroupSetUsers(const char * server_name /* [in] */, + const char * group_name /* [in] */, + uint32_t level /* [in] */, + uint8_t *buffer /* [in] [ref] */, + uint32_t num_entries /* [in] */) +{ + struct NetGroupSetUsers r; + struct libnetapi_ctx *ctx = NULL; + NET_API_STATUS status; + WERROR werr; + + status = libnetapi_getctx(&ctx); + if (status != 0) { + return status; + } + + /* In parameters */ + r.in.server_name = server_name; + r.in.group_name = group_name; + r.in.level = level; + r.in.buffer = buffer; + r.in.num_entries = num_entries; + + /* Out parameters */ + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_IN_DEBUG(NetGroupSetUsers, &r); + } + + if (LIBNETAPI_LOCAL_SERVER(server_name)) { + werr = NetGroupSetUsers_l(ctx, &r); + } else { + werr = NetGroupSetUsers_r(ctx, &r); + } + + r.out.result = W_ERROR_V(werr); + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_OUT_DEBUG(NetGroupSetUsers, &r); + } + + return r.out.result; +} + /**************************************************************** NetLocalGroupAdd ****************************************************************/ diff --git a/source3/lib/netapi/libnetapi.h b/source3/lib/netapi/libnetapi.h index eecbf8e4d5..c622116a93 100644 --- a/source3/lib/netapi/libnetapi.h +++ b/source3/lib/netapi/libnetapi.h @@ -248,6 +248,15 @@ WERROR NetGroupGetUsers_r(struct libnetapi_ctx *ctx, struct NetGroupGetUsers *r); WERROR NetGroupGetUsers_l(struct libnetapi_ctx *ctx, struct NetGroupGetUsers *r); +NET_API_STATUS NetGroupSetUsers(const char * server_name /* [in] */, + const char * group_name /* [in] */, + uint32_t level /* [in] */, + uint8_t *buffer /* [in] [ref] */, + uint32_t num_entries /* [in] */); +WERROR NetGroupSetUsers_r(struct libnetapi_ctx *ctx, + struct NetGroupSetUsers *r); +WERROR NetGroupSetUsers_l(struct libnetapi_ctx *ctx, + struct NetGroupSetUsers *r); NET_API_STATUS NetLocalGroupAdd(const char * server_name /* [in] */, uint32_t level /* [in] */, uint8_t *buffer /* [in] [ref] */, -- cgit From b6d861a9c0af1250a60e3e568bed860af40c7918 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 8 Sep 2008 10:23:07 +0200 Subject: netapi: add NetGroupSetUsers to public header. Guenther (This used to be commit 72a0b27aecc9113445dd03bdcd549ac50dd988aa) --- source3/lib/netapi/netapi.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h index b1b8e8f3fc..c82dc9af5a 100644 --- a/source3/lib/netapi/netapi.h +++ b/source3/lib/netapi/netapi.h @@ -1370,6 +1370,28 @@ NET_API_STATUS NetGroupGetUsers(const char * server_name /* [in] */, uint32_t *total_entries /* [out] [ref] */, uint32_t *resume_handle /* [in,out] [ref] */); +/************************************************************//** + * + * NetGroupSetUsers + * + * @brief Set Users for a group on a server + * + * @param[in] server_name The server name to connect to + * @param[in] group_name The group name to enumerate users for + * @param[in] level The enumeration level used for the query + * @param[in] buffer The buffer containing a X structure + * @param[in] num_entries The number of X entries in the buffer + * @return NET_API_STATUS + * + * example group/group_setusers.c + ***************************************************************/ + +NET_API_STATUS NetGroupSetUsers(const char * server_name /* [in] */, + const char * group_name /* [in] */, + uint32_t level /* [in] */, + uint8_t *buffer /* [in] [ref] */, + uint32_t num_entries /* [in] */); + /************************************************************//** * * NetLocalGroupAdd -- cgit From dcdca803fced39e88d27b5ce657d1ec7e5a1346a Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 5 Sep 2008 17:05:49 +0200 Subject: netapi: add example code for NetGroupSetUsers. Guenther (This used to be commit dc7994195c9e34d85db8c9406edaa704027ab47f) --- source3/lib/netapi/examples/Makefile.in | 6 + source3/lib/netapi/examples/group/group_setusers.c | 142 +++++++++++++++++++++ 2 files changed, 148 insertions(+) create mode 100644 source3/lib/netapi/examples/group/group_setusers.c (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/Makefile.in b/source3/lib/netapi/examples/Makefile.in index c7b279c0f5..6efe022fb4 100644 --- a/source3/lib/netapi/examples/Makefile.in +++ b/source3/lib/netapi/examples/Makefile.in @@ -42,6 +42,7 @@ PROGS = bin/getdc@EXEEXT@ \ bin/group_adduser@EXEEXT@ \ bin/group_deluser@EXEEXT@ \ bin/group_getusers@EXEEXT@ \ + bin/group_setusers@EXEEXT@ \ bin/localgroup_add@EXEEXT@ \ bin/localgroup_del@EXEEXT@ \ bin/localgroup_getinfo@EXEEXT@ \ @@ -111,6 +112,7 @@ GROUPGETINFO_OBJ = group/group_getinfo.o $(CMDLINE_OBJ) GROUPADDUSER_OBJ = group/group_adduser.o $(CMDLINE_OBJ) GROUPDELUSER_OBJ = group/group_deluser.o $(CMDLINE_OBJ) GROUPGETUSERS_OBJ = group/group_getusers.o $(CMDLINE_OBJ) +GROUPSETUSERS_OBJ = group/group_setusers.o $(CMDLINE_OBJ) LOCALGROUPADD_OBJ = localgroup/localgroup_add.o $(CMDLINE_OBJ) LOCALGROUPDEL_OBJ = localgroup/localgroup_del.o $(CMDLINE_OBJ) LOCALGROUPGETINFO_OBJ = localgroup/localgroup_getinfo.o $(CMDLINE_OBJ) @@ -228,6 +230,10 @@ bin/group_getusers@EXEEXT@: $(BINARY_PREREQS) $(GROUPGETUSERS_OBJ) @echo Linking $@ @$(CC) $(FLAGS) -o $@ $(GROUPGETUSERS_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) +bin/group_setusers@EXEEXT@: $(BINARY_PREREQS) $(GROUPSETUSERS_OBJ) + @echo Linking $@ + @$(CC) $(FLAGS) -o $@ $(GROUPSETUSERS_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) + bin/localgroup_add@EXEEXT@: $(BINARY_PREREQS) $(LOCALGROUPADD_OBJ) @echo Linking $@ @$(CC) $(FLAGS) -o $@ $(LOCALGROUPADD_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) diff --git a/source3/lib/netapi/examples/group/group_setusers.c b/source3/lib/netapi/examples/group/group_setusers.c new file mode 100644 index 0000000000..70cf10514c --- /dev/null +++ b/source3/lib/netapi/examples/group/group_setusers.c @@ -0,0 +1,142 @@ +/* + * Unix SMB/CIFS implementation. + * NetGroupSetUsers query + * Copyright (C) Guenther Deschner 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include +#include +#include +#include +#include + +#include + +#include "common.h" + +int main(int argc, const char **argv) +{ + NET_API_STATUS status; + struct libnetapi_ctx *ctx = NULL; + const char *hostname = NULL; + const char *groupname = NULL; + uint32_t level = 0; + uint8_t *buffer = NULL; + uint32_t num_entries = 0; + const char **names = NULL; + int i = 0; + size_t buf_size = 0; + + struct GROUP_USERS_INFO_0 *g0 = NULL; + struct GROUP_USERS_INFO_1 *g1 = NULL; + + poptContext pc; + int opt; + + struct poptOption long_options[] = { + POPT_AUTOHELP + POPT_COMMON_LIBNETAPI_EXAMPLES + POPT_TABLEEND + }; + + status = libnetapi_init(&ctx); + if (status != 0) { + return status; + } + + pc = poptGetContext("group_setusers", argc, argv, long_options, 0); + + poptSetOtherOptionHelp(pc, "hostname groupname level"); + while((opt = poptGetNextOpt(pc)) != -1) { + } + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + hostname = poptGetArg(pc); + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + groupname = poptGetArg(pc); + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + + names = poptGetArgs(pc); + for (i=0; names[i] != NULL; i++) { + num_entries++; + } + + switch (level) { + case 0: + buf_size = sizeof(struct GROUP_USERS_INFO_0) * num_entries; + + status = NetApiBufferAllocate(buf_size, (void **)&g0); + if (status) { + printf("NetApiBufferAllocate failed with: %s\n", + libnetapi_get_error_string(ctx, status)); + goto out; + } + + for (i=0; i Date: Tue, 9 Sep 2008 13:17:22 +0200 Subject: netapi: implement NetGroupSetUsers_r. Guenther (This used to be commit 0ba0ffdb3023cd0bb6aa5c479309c871ff15ed0c) --- source3/lib/netapi/group.c | 228 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 227 insertions(+), 1 deletion(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/group.c b/source3/lib/netapi/group.c index 44c4a74df1..02500983ea 100644 --- a/source3/lib/netapi/group.c +++ b/source3/lib/netapi/group.c @@ -1310,7 +1310,233 @@ WERROR NetGroupGetUsers_l(struct libnetapi_ctx *ctx, WERROR NetGroupSetUsers_r(struct libnetapi_ctx *ctx, struct NetGroupSetUsers *r) { - return WERR_NOT_SUPPORTED; + struct cli_state *cli = NULL; + struct rpc_pipe_client *pipe_cli = NULL; + struct policy_handle connect_handle, domain_handle, group_handle; + struct lsa_String lsa_account_name; + struct dom_sid2 *domain_sid = NULL; + union samr_GroupInfo *group_info = NULL; + struct samr_Ids user_rids, name_types; + struct samr_Ids group_rids, group_types; + struct samr_RidTypeArray *rid_array = NULL; + + uint32_t *add_rids = NULL; + uint32_t *del_rids = NULL; + size_t num_add_rids = 0; + size_t num_del_rids = 0; + + uint32_t *member_rids = NULL; + size_t num_member_rids = 0; + + struct GROUP_USERS_INFO_0 *i0 = NULL; + struct GROUP_USERS_INFO_1 *i1 = NULL; + + int i, k; + + NTSTATUS status = NT_STATUS_OK; + WERROR werr; + + ZERO_STRUCT(connect_handle); + ZERO_STRUCT(domain_handle); + + if (!r->in.buffer) { + return WERR_INVALID_PARAM; + } + + switch (r->in.level) { + case 0: + case 1: + break; + default: + return WERR_UNKNOWN_LEVEL; + } + + werr = libnetapi_open_pipe(ctx, r->in.server_name, + &ndr_table_samr.syntax_id, + &cli, + &pipe_cli); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + werr = libnetapi_samr_open_domain(ctx, pipe_cli, + SAMR_ACCESS_ENUM_DOMAINS | + SAMR_ACCESS_OPEN_DOMAIN, + SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, + &connect_handle, + &domain_handle, + &domain_sid); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + init_lsa_String(&lsa_account_name, r->in.group_name); + + status = rpccli_samr_LookupNames(pipe_cli, ctx, + &domain_handle, + 1, + &lsa_account_name, + &group_rids, + &group_types); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + status = rpccli_samr_OpenGroup(pipe_cli, ctx, + &domain_handle, + SAMR_GROUP_ACCESS_GET_MEMBERS | + SAMR_GROUP_ACCESS_ADD_MEMBER | + SAMR_GROUP_ACCESS_REMOVE_MEMBER | + SAMR_GROUP_ACCESS_LOOKUP_INFO, + group_rids.ids[0], + &group_handle); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + status = rpccli_samr_QueryGroupInfo(pipe_cli, ctx, + &group_handle, + GROUPINFOATTRIBUTES, + &group_info); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + switch (r->in.level) { + case 0: + i0 = (struct GROUP_USERS_INFO_0 *)r->in.buffer; + break; + case 1: + i1 = (struct GROUP_USERS_INFO_1 *)r->in.buffer; + break; + } + + for (i=0; i < r->in.num_entries; i++) { + + switch (r->in.level) { + case 0: + init_lsa_String(&lsa_account_name, i0->grui0_name); + i0++; + break; + case 1: + init_lsa_String(&lsa_account_name, i1->grui1_name); + i1++; + break; + } + + status = rpccli_samr_LookupNames(pipe_cli, ctx, + &domain_handle, + 1, + &lsa_account_name, + &user_rids, + &name_types); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + if (!add_rid_to_array_unique(ctx, + user_rids.ids[0], + &member_rids, + &num_member_rids)) { + werr = WERR_GENERAL_FAILURE; + goto done; + } + } + + status = rpccli_samr_QueryGroupMember(pipe_cli, ctx, + &group_handle, + &rid_array); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + /* add list */ + + for (i=0; i < r->in.num_entries; i++) { + bool already_member = false; + for (k=0; k < rid_array->count; k++) { + if (member_rids[i] == rid_array->rids[k]) { + already_member = true; + break; + } + } + if (!already_member) { + if (!add_rid_to_array_unique(ctx, + member_rids[i], + &add_rids, &num_add_rids)) { + werr = WERR_GENERAL_FAILURE; + goto done; + } + } + } + + /* del list */ + + for (k=0; k < rid_array->count; k++) { + bool keep_member = false; + for (i=0; i < r->in.num_entries; i++) { + if (member_rids[i] == rid_array->rids[k]) { + keep_member = true; + break; + } + } + if (!keep_member) { + if (!add_rid_to_array_unique(ctx, + rid_array->rids[k], + &del_rids, &num_del_rids)) { + werr = WERR_GENERAL_FAILURE; + goto done; + } + } + } + + /* add list */ + + for (i=0; i < num_add_rids; i++) { + status = rpccli_samr_AddGroupMember(pipe_cli, ctx, + &group_handle, + add_rids[i], + 7 /* ? */); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + } + + /* del list */ + + for (i=0; i < num_del_rids; i++) { + status = rpccli_samr_DeleteGroupMember(pipe_cli, ctx, + &group_handle, + del_rids[i]); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + } + + werr = WERR_OK; + + done: + if (!cli) { + return werr; + } + + if (is_valid_policy_hnd(&group_handle)) { + rpccli_samr_Close(pipe_cli, ctx, &group_handle); + } + + if (ctx->disable_policy_handle_cache) { + libnetapi_samr_close_domain_handle(ctx, &domain_handle); + libnetapi_samr_close_connect_handle(ctx, &connect_handle); + } + + return werr; } /**************************************************************** -- cgit From de1ec0f40ce8dbf9eb8a7f4f54a909a27a923245 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 8 Sep 2008 16:42:38 +0200 Subject: netapi: implement NetGroupGetUsers_r. Guenther (This used to be commit 7b77dacde5f667d36868a2a8474cf719d9cce331) --- source3/lib/netapi/group.c | 137 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 136 insertions(+), 1 deletion(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/group.c b/source3/lib/netapi/group.c index 02500983ea..2e0c4dc48e 100644 --- a/source3/lib/netapi/group.c +++ b/source3/lib/netapi/group.c @@ -1292,7 +1292,142 @@ WERROR NetGroupEnum_l(struct libnetapi_ctx *ctx, WERROR NetGroupGetUsers_r(struct libnetapi_ctx *ctx, struct NetGroupGetUsers *r) { - return WERR_NOT_SUPPORTED; + /* FIXME: this call needs to cope with large replies */ + + struct cli_state *cli = NULL; + struct rpc_pipe_client *pipe_cli = NULL; + struct policy_handle connect_handle, domain_handle, group_handle; + struct lsa_String lsa_account_name; + struct dom_sid2 *domain_sid = NULL; + struct samr_Ids group_rids, name_types; + struct samr_RidTypeArray *rid_array = NULL; + struct lsa_Strings names; + struct samr_Ids member_types; + + int i; + uint32_t entries_read = 0; + + NTSTATUS status = NT_STATUS_OK; + WERROR werr; + + ZERO_STRUCT(connect_handle); + ZERO_STRUCT(domain_handle); + + if (!r->out.buffer) { + return WERR_INVALID_PARAM; + } + + *r->out.buffer = NULL; + *r->out.entries_read = 0; + + switch (r->in.level) { + case 0: + case 1: + break; + default: + return WERR_UNKNOWN_LEVEL; + } + + + werr = libnetapi_open_pipe(ctx, r->in.server_name, + &ndr_table_samr.syntax_id, + &cli, + &pipe_cli); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + werr = libnetapi_samr_open_domain(ctx, pipe_cli, + SAMR_ACCESS_ENUM_DOMAINS | + SAMR_ACCESS_OPEN_DOMAIN, + SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, + &connect_handle, + &domain_handle, + &domain_sid); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + init_lsa_String(&lsa_account_name, r->in.group_name); + + status = rpccli_samr_LookupNames(pipe_cli, ctx, + &domain_handle, + 1, + &lsa_account_name, + &group_rids, + &name_types); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + status = rpccli_samr_OpenGroup(pipe_cli, ctx, + &domain_handle, + SAMR_GROUP_ACCESS_GET_MEMBERS, + group_rids.ids[0], + &group_handle); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + status = rpccli_samr_QueryGroupMember(pipe_cli, ctx, + &group_handle, + &rid_array); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + status = rpccli_samr_LookupRids(pipe_cli, ctx, + &domain_handle, + rid_array->count, + rid_array->rids, + &names, + &member_types); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + for (i=0; i < names.count; i++) { + status = add_GROUP_USERS_INFO_X_buffer(ctx, + r->in.level, + names.names[i].string, + member_types.ids[i], + r->out.buffer, + &entries_read); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + } + + if (r->out.entries_read) { + *r->out.entries_read = entries_read; + } + + if (r->out.total_entries) { + *r->out.total_entries = entries_read; + } + + werr = WERR_OK; + + done: + if (!cli) { + return werr; + } + + if (is_valid_policy_hnd(&group_handle)) { + rpccli_samr_Close(pipe_cli, ctx, &group_handle); + } + + if (ctx->disable_policy_handle_cache) { + libnetapi_samr_close_domain_handle(ctx, &domain_handle); + libnetapi_samr_close_connect_handle(ctx, &connect_handle); + } + + return werr; } /**************************************************************** -- cgit From a5bf77be8658106542995e879833cff2857d5f0d Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 8 Sep 2008 16:43:06 +0200 Subject: netapi: fix group_getusers example. Guenther (This used to be commit a977e18a669a220fd3f98161ced5bebd642e628b) --- source3/lib/netapi/examples/group/group_getusers.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/group/group_getusers.c b/source3/lib/netapi/examples/group/group_getusers.c index 55d0717aa5..72e79ec3a2 100644 --- a/source3/lib/netapi/examples/group/group_getusers.c +++ b/source3/lib/netapi/examples/group/group_getusers.c @@ -105,11 +105,11 @@ int main(int argc, const char **argv) for (i=0; igrui0_name); + printf("#%d member: %s\n", i, info0->grui0_name); info0++; break; case 1: - printf("#%d group: %s\n", i, info1->grui1_name); + printf("#%d member: %s\n", i, info1->grui1_name); printf("#%d attributes: %d\n", i, info1->grui1_attributes); info1++; break; -- cgit From 40e9ddd6e422f2fa6d0ffa43dc4c78bef5489b7a Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 9 Sep 2008 13:42:27 +0200 Subject: netapi: add NetUserGetLocalGroups skeleton. Guenther (This used to be commit b31209e4495de31140c57338a891569b3436d91e) --- source3/lib/netapi/libnetapi.c | 54 ++++++++++++++++++++++++++++++++++++++++++ source3/lib/netapi/libnetapi.h | 12 ++++++++++ source3/lib/netapi/user.c | 18 ++++++++++++++ 3 files changed, 84 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/libnetapi.c b/source3/lib/netapi/libnetapi.c index 4f3a5bdcb0..639cbf9e65 100644 --- a/source3/lib/netapi/libnetapi.c +++ b/source3/lib/netapi/libnetapi.c @@ -873,6 +873,60 @@ NET_API_STATUS NetUserSetGroups(const char * server_name /* [in] */, return r.out.result; } +/**************************************************************** + NetUserGetLocalGroups +****************************************************************/ + +NET_API_STATUS NetUserGetLocalGroups(const char * server_name /* [in] */, + const char * user_name /* [in] */, + uint32_t level /* [in] */, + uint32_t flags /* [in] */, + uint8_t **buffer /* [out] [ref] */, + uint32_t prefmaxlen /* [in] */, + uint32_t *entries_read /* [out] [ref] */, + uint32_t *total_entries /* [out] [ref] */) +{ + struct NetUserGetLocalGroups r; + struct libnetapi_ctx *ctx = NULL; + NET_API_STATUS status; + WERROR werr; + + status = libnetapi_getctx(&ctx); + if (status != 0) { + return status; + } + + /* In parameters */ + r.in.server_name = server_name; + r.in.user_name = user_name; + r.in.level = level; + r.in.flags = flags; + r.in.prefmaxlen = prefmaxlen; + + /* Out parameters */ + r.out.buffer = buffer; + r.out.entries_read = entries_read; + r.out.total_entries = total_entries; + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_IN_DEBUG(NetUserGetLocalGroups, &r); + } + + if (LIBNETAPI_LOCAL_SERVER(server_name)) { + werr = NetUserGetLocalGroups_l(ctx, &r); + } else { + werr = NetUserGetLocalGroups_r(ctx, &r); + } + + r.out.result = W_ERROR_V(werr); + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_OUT_DEBUG(NetUserGetLocalGroups, &r); + } + + return r.out.result; +} + /**************************************************************** NetUserModalsGet ****************************************************************/ diff --git a/source3/lib/netapi/libnetapi.h b/source3/lib/netapi/libnetapi.h index c622116a93..766d6fb705 100644 --- a/source3/lib/netapi/libnetapi.h +++ b/source3/lib/netapi/libnetapi.h @@ -154,6 +154,18 @@ WERROR NetUserSetGroups_r(struct libnetapi_ctx *ctx, struct NetUserSetGroups *r); WERROR NetUserSetGroups_l(struct libnetapi_ctx *ctx, struct NetUserSetGroups *r); +NET_API_STATUS NetUserGetLocalGroups(const char * server_name /* [in] */, + const char * user_name /* [in] */, + uint32_t level /* [in] */, + uint32_t flags /* [in] */, + uint8_t **buffer /* [out] [ref] */, + uint32_t prefmaxlen /* [in] */, + uint32_t *entries_read /* [out] [ref] */, + uint32_t *total_entries /* [out] [ref] */); +WERROR NetUserGetLocalGroups_r(struct libnetapi_ctx *ctx, + struct NetUserGetLocalGroups *r); +WERROR NetUserGetLocalGroups_l(struct libnetapi_ctx *ctx, + struct NetUserGetLocalGroups *r); NET_API_STATUS NetUserModalsGet(const char * server_name /* [in] */, uint32_t level /* [in] */, uint8_t **buffer /* [out] [ref] */); diff --git a/source3/lib/netapi/user.c b/source3/lib/netapi/user.c index 4fbc27f364..80c7c53b37 100644 --- a/source3/lib/netapi/user.c +++ b/source3/lib/netapi/user.c @@ -3182,3 +3182,21 @@ WERROR NetUserSetGroups_l(struct libnetapi_ctx *ctx, { LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetUserSetGroups); } + +/**************************************************************** +****************************************************************/ + +WERROR NetUserGetLocalGroups_r(struct libnetapi_ctx *ctx, + struct NetUserGetLocalGroups *r) +{ + return WERR_NOT_SUPPORTED; +} + +/**************************************************************** +****************************************************************/ + +WERROR NetUserGetLocalGroups_l(struct libnetapi_ctx *ctx, + struct NetUserGetLocalGroups *r) +{ + LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetUserGetLocalGroups); +} -- cgit From f87901f7e402a067daec2caaad4e3070c0caedc3 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 9 Sep 2008 13:44:09 +0200 Subject: netapi: add NetUserGetLocalGroups to public header. Guenther (This used to be commit 299f76f4ce9d6f617431149e2502c27faa4431aa) --- source3/lib/netapi/netapi.h | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h index c82dc9af5a..6e4edab6c6 100644 --- a/source3/lib/netapi/netapi.h +++ b/source3/lib/netapi/netapi.h @@ -574,6 +574,10 @@ struct LOCALGROUP_MEMBERS_INFO_3 { const char * lgrmi3_domainandname; }; +struct LOCALGROUP_USERS_INFO_0 { + const char * lgrui0_name; +}; + struct TIME_OF_DAY_INFO { uint32_t tod_elapsedt; uint32_t tod_msecs; @@ -1171,6 +1175,34 @@ NET_API_STATUS NetUserSetGroups(const char * server_name /* [in] */, uint8_t *buffer /* [in] [ref] */, uint32_t num_entries /* [in] */); +/************************************************************//** + * + * NetUserGetLocalGroups + * + * @brief Enumerate local grouplist of a user on a server + * + * @param[in] server_name The server name to connect to + * @param[in] user_name The user name to query + * @param[in] level The enumeration level used for the query + * @param[in] flags The flags used for the query + * @param[out] buffer The returned enumeration buffer + * @param[in] prefmaxlen The requested maximal buffer size + * @param[out] entries_read The number of returned entries + * @param[out] total_entries The number of total entries + * @return NET_API_STATUS + * + * example user/user_getlocalgroups.c + ***************************************************************/ + +NET_API_STATUS NetUserGetLocalGroups(const char * server_name /* [in] */, + const char * user_name /* [in] */, + uint32_t level /* [in] */, + uint32_t flags /* [in] */, + uint8_t **buffer /* [out] [ref] */, + uint32_t prefmaxlen /* [in] */, + uint32_t *entries_read /* [out] [ref] */, + uint32_t *total_entries /* [out] [ref] */); + /************************************************************//** * * NetQueryDisplayInformation -- cgit From 434ff0ddc8c2e93f033477ba664ab4fd574ddd7b Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 9 Sep 2008 14:48:06 +0200 Subject: netapi: add NetUserGetLocalGroups example code. Guenther (This used to be commit 7d05936ff455b40449fe2e5280f15c81ccc7f4d0) --- source3/lib/netapi/examples/Makefile.in | 6 + .../lib/netapi/examples/user/user_getlocalgroups.c | 122 +++++++++++++++++++++ 2 files changed, 128 insertions(+) create mode 100644 source3/lib/netapi/examples/user/user_getlocalgroups.c (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/Makefile.in b/source3/lib/netapi/examples/Makefile.in index 6efe022fb4..3eea96ab00 100644 --- a/source3/lib/netapi/examples/Makefile.in +++ b/source3/lib/netapi/examples/Makefile.in @@ -34,6 +34,7 @@ PROGS = bin/getdc@EXEEXT@ \ bin/user_modalsset@EXEEXT@ \ bin/user_getgroups@EXEEXT@ \ bin/user_setgroups@EXEEXT@ \ + bin/user_getlocalgroups@EXEEXT@ \ bin/group_add@EXEEXT@ \ bin/group_del@EXEEXT@ \ bin/group_enum@EXEEXT@ \ @@ -104,6 +105,7 @@ USERMODALSGET_OBJ = user/user_modalsget.o $(CMDLINE_OBJ) USERMODALSSET_OBJ = user/user_modalsset.o $(CMDLINE_OBJ) USERGETGROUPS_OBJ = user/user_getgroups.o $(CMDLINE_OBJ) USERSETGROUPS_OBJ = user/user_setgroups.o $(CMDLINE_OBJ) +USERGETLOCALGROUPS_OBJ = user/user_getlocalgroups.o $(CMDLINE_OBJ) GROUPADD_OBJ = group/group_add.o $(CMDLINE_OBJ) GROUPDEL_OBJ = group/group_del.o $(CMDLINE_OBJ) GROUPENUM_OBJ = group/group_enum.o $(CMDLINE_OBJ) @@ -198,6 +200,10 @@ bin/user_setgroups@EXEEXT@: $(BINARY_PREREQS) $(USERSETGROUPS_OBJ) @echo Linking $@ @$(CC) $(FLAGS) -o $@ $(USERSETGROUPS_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) +bin/user_getlocalgroups@EXEEXT@: $(BINARY_PREREQS) $(USERGETLOCALGROUPS_OBJ) + @echo Linking $@ + @$(CC) $(FLAGS) -o $@ $(USERGETLOCALGROUPS_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) + bin/group_add@EXEEXT@: $(BINARY_PREREQS) $(GROUPADD_OBJ) @echo Linking $@ @$(CC) $(FLAGS) -o $@ $(GROUPADD_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) diff --git a/source3/lib/netapi/examples/user/user_getlocalgroups.c b/source3/lib/netapi/examples/user/user_getlocalgroups.c new file mode 100644 index 0000000000..133104d7c1 --- /dev/null +++ b/source3/lib/netapi/examples/user/user_getlocalgroups.c @@ -0,0 +1,122 @@ +/* + * Unix SMB/CIFS implementation. + * NetUserGetLocalGroups query + * Copyright (C) Guenther Deschner 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include +#include +#include +#include +#include + +#include + +#include "common.h" + +int main(int argc, const char **argv) +{ + NET_API_STATUS status; + struct libnetapi_ctx *ctx = NULL; + const char *hostname = NULL; + const char *username = NULL; + uint32_t level = 0; + uint8_t *buffer = NULL; + uint32_t entries_read = 0; + uint32_t total_entries = 0; + uint32_t flags = 0; + int i; + + struct LOCALGROUP_USERS_INFO_0 *info0 = NULL; + + poptContext pc; + int opt; + + struct poptOption long_options[] = { + POPT_AUTOHELP + POPT_COMMON_LIBNETAPI_EXAMPLES + POPT_TABLEEND + }; + + status = libnetapi_init(&ctx); + if (status != 0) { + return status; + } + + pc = poptGetContext("user_getlocalgroups", argc, argv, long_options, 0); + + poptSetOtherOptionHelp(pc, "hostname username"); + while((opt = poptGetNextOpt(pc)) != -1) { + } + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + hostname = poptGetArg(pc); + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + username = poptGetArg(pc); + + /* NetUserGetLocalGroups */ + + do { + status = NetUserGetLocalGroups(hostname, + username, + level, + flags, + &buffer, + (uint32_t)-1, + &entries_read, + &total_entries); + if (status == 0 || status == ERROR_MORE_DATA) { + + switch (level) { + case 0: + info0 = (struct LOCALGROUP_USERS_INFO_0 *)buffer; + break; + default: + break; + } + + for (i=0; ilgrui0_name); + info0++; + break; + default: + break; + } + } + NetApiBufferFree(buffer); + } + } while (status == ERROR_MORE_DATA); + + if (status != 0) { + printf("NetUserGetLocalGroups failed with: %s\n", + libnetapi_get_error_string(ctx, status)); + } + + out: + libnetapi_free(ctx); + poptFreeContext(pc); + + return status; +} -- cgit From 2474026c003d216cc29805c8b56836b49fe7b2fb Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 9 Sep 2008 18:44:40 +0200 Subject: netapi: implement NetUserGetLocalGroups_r. Guenther (This used to be commit 969bc7ce3d3f266bf07784a980ea35ab458e6eae) --- source3/lib/netapi/user.c | 238 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 238 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/user.c b/source3/lib/netapi/user.c index 80c7c53b37..62df2f9da5 100644 --- a/source3/lib/netapi/user.c +++ b/source3/lib/netapi/user.c @@ -3186,9 +3186,247 @@ WERROR NetUserSetGroups_l(struct libnetapi_ctx *ctx, /**************************************************************** ****************************************************************/ +static NTSTATUS add_LOCALGROUP_USERS_INFO_X_buffer(TALLOC_CTX *mem_ctx, + uint32_t level, + const char *group_name, + uint8_t **buffer, + uint32_t *num_entries) +{ + struct LOCALGROUP_USERS_INFO_0 u0; + + switch (level) { + case 0: + u0.lgrui0_name = talloc_strdup(mem_ctx, group_name); + NT_STATUS_HAVE_NO_MEMORY(u0.lgrui0_name); + + ADD_TO_ARRAY(mem_ctx, struct LOCALGROUP_USERS_INFO_0, u0, + (struct LOCALGROUP_USERS_INFO_0 **)buffer, num_entries); + break; + default: + return NT_STATUS_INVALID_INFO_CLASS; + } + + return NT_STATUS_OK; +} + +/**************************************************************** +****************************************************************/ + WERROR NetUserGetLocalGroups_r(struct libnetapi_ctx *ctx, struct NetUserGetLocalGroups *r) { + struct cli_state *cli = NULL; + struct rpc_pipe_client *pipe_cli = NULL; + struct policy_handle connect_handle, domain_handle, user_handle, + builtin_handle; + struct lsa_String lsa_account_name; + struct dom_sid2 *domain_sid = NULL; + struct samr_Ids user_rids, name_types; + struct samr_RidWithAttributeArray *rid_array = NULL; + struct lsa_Strings names; + struct samr_Ids types; + uint32_t *rids = NULL; + size_t num_rids = 0; + struct dom_sid user_sid; + struct lsa_SidArray sid_array; + struct samr_Ids domain_rids; + struct samr_Ids builtin_rids; + + int i; + uint32_t entries_read = 0; + + NTSTATUS status = NT_STATUS_OK; + WERROR werr; + + ZERO_STRUCT(connect_handle); + ZERO_STRUCT(domain_handle); + + if (!r->out.buffer) { + return WERR_INVALID_PARAM; + } + + *r->out.buffer = NULL; + *r->out.entries_read = 0; + + switch (r->in.level) { + case 0: + case 1: + break; + default: + return WERR_UNKNOWN_LEVEL; + } + + werr = libnetapi_open_pipe(ctx, r->in.server_name, + &ndr_table_samr.syntax_id, + &cli, + &pipe_cli); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + werr = libnetapi_samr_open_domain(ctx, pipe_cli, + SAMR_ACCESS_ENUM_DOMAINS | + SAMR_ACCESS_OPEN_DOMAIN, + SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT | + SAMR_DOMAIN_ACCESS_LOOKUP_ALIAS, + &connect_handle, + &domain_handle, + &domain_sid); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + werr = libnetapi_samr_open_builtin_domain(ctx, pipe_cli, + SAMR_ACCESS_ENUM_DOMAINS | + SAMR_ACCESS_OPEN_DOMAIN, + SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT | + SAMR_DOMAIN_ACCESS_LOOKUP_ALIAS, + &connect_handle, + &builtin_handle); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + init_lsa_String(&lsa_account_name, r->in.user_name); + + status = rpccli_samr_LookupNames(pipe_cli, ctx, + &domain_handle, + 1, + &lsa_account_name, + &user_rids, + &name_types); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + status = rpccli_samr_OpenUser(pipe_cli, ctx, + &domain_handle, + SAMR_USER_ACCESS_GET_GROUPS, + user_rids.ids[0], + &user_handle); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + status = rpccli_samr_GetGroupsForUser(pipe_cli, ctx, + &user_handle, + &rid_array); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + if (!sid_compose(&user_sid, domain_sid, user_rids.ids[0])) { + werr = WERR_NOMEM; + goto done; + } + + sid_array.num_sids = rid_array->count + 1; + sid_array.sids = TALLOC_ARRAY(ctx, struct lsa_SidPtr, sid_array.num_sids); + if (!sid_array.sids) { + werr = WERR_NOMEM; + goto done; + } + + sid_array.sids[0].sid = sid_dup_talloc(ctx, &user_sid); + if (!sid_array.sids[0].sid) { + werr = WERR_NOMEM; + goto done; + } + + for (i=0; i < rid_array->count; i++) { + struct dom_sid sid; + + if (!sid_compose(&sid, domain_sid, rid_array->rids[i].rid)) { + werr = WERR_NOMEM; + goto done; + } + + sid_array.sids[i+1].sid = sid_dup_talloc(ctx, &sid); + if (!sid_array.sids[i+1].sid) { + werr = WERR_NOMEM; + goto done; + } + } + + status = rpccli_samr_GetAliasMembership(pipe_cli, ctx, + &domain_handle, + &sid_array, + &domain_rids); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + for (i=0; i < domain_rids.count; i++) { + if (!add_rid_to_array_unique(ctx, domain_rids.ids[i], + &rids, &num_rids)) { + werr = WERR_NOMEM; + goto done; + } + } + + status = rpccli_samr_GetAliasMembership(pipe_cli, ctx, + &builtin_handle, + &sid_array, + &builtin_rids); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + for (i=0; i < builtin_rids.count; i++) { + if (!add_rid_to_array_unique(ctx, builtin_rids.ids[i], + &rids, &num_rids)) { + werr = WERR_NOMEM; + goto done; + } + } + + status = rpccli_samr_LookupRids(pipe_cli, ctx, + &builtin_handle, + num_rids, + rids, + &names, + &types); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + + for (i=0; i < names.count; i++) { + status = add_LOCALGROUP_USERS_INFO_X_buffer(ctx, + r->in.level, + names.names[i].string, + r->out.buffer, + &entries_read); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + } + + if (r->out.entries_read) { + *r->out.entries_read = entries_read; + } + if (r->out.total_entries) { + *r->out.total_entries = entries_read; + } + + done: + if (!cli) { + return werr; + } + + if (ctx->disable_policy_handle_cache) { + libnetapi_samr_close_domain_handle(ctx, &domain_handle); + libnetapi_samr_close_connect_handle(ctx, &connect_handle); + } + + return werr; + return WERR_NOT_SUPPORTED; } -- cgit From 1aff85342792e8ce4713285be85124d975ace271 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 9 Sep 2008 19:21:48 +0200 Subject: netapi: add NetFileClose skeleton. Guenther (This used to be commit 4a006ae644bd85b670aab835dc7d90dadaec3503) --- source3/lib/netapi/file.c | 43 ++++++++++++++++++++++++++++++++++++++++++ source3/lib/netapi/libnetapi.c | 42 +++++++++++++++++++++++++++++++++++++++++ source3/lib/netapi/libnetapi.h | 6 ++++++ 3 files changed, 91 insertions(+) create mode 100644 source3/lib/netapi/file.c (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/file.c b/source3/lib/netapi/file.c new file mode 100644 index 0000000000..aa80e8d56a --- /dev/null +++ b/source3/lib/netapi/file.c @@ -0,0 +1,43 @@ +/* + * Unix SMB/CIFS implementation. + * NetApi File Support + * Copyright (C) Guenther Deschner 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include "includes.h" + +#include "librpc/gen_ndr/libnetapi.h" +#include "lib/netapi/netapi.h" +#include "lib/netapi/netapi_private.h" +#include "lib/netapi/libnetapi.h" + +/**************************************************************** +****************************************************************/ + +WERROR NetFileClose_r(struct libnetapi_ctx *ctx, + struct NetFileClose *r) +{ + return WERR_NOT_SUPPORTED; +} + +/**************************************************************** +****************************************************************/ + +WERROR NetFileClose_l(struct libnetapi_ctx *ctx, + struct NetFileClose *r) +{ + LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetFileClose); +} diff --git a/source3/lib/netapi/libnetapi.c b/source3/lib/netapi/libnetapi.c index 639cbf9e65..d83dc28c43 100644 --- a/source3/lib/netapi/libnetapi.c +++ b/source3/lib/netapi/libnetapi.c @@ -2208,3 +2208,45 @@ NET_API_STATUS NetShareSetInfo(const char * server_name /* [in] */, return r.out.result; } +/**************************************************************** + NetFileClose +****************************************************************/ + +NET_API_STATUS NetFileClose(const char * server_name /* [in] */, + uint32_t fileid /* [in] */) +{ + struct NetFileClose r; + struct libnetapi_ctx *ctx = NULL; + NET_API_STATUS status; + WERROR werr; + + status = libnetapi_getctx(&ctx); + if (status != 0) { + return status; + } + + /* In parameters */ + r.in.server_name = server_name; + r.in.fileid = fileid; + + /* Out parameters */ + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_IN_DEBUG(NetFileClose, &r); + } + + if (LIBNETAPI_LOCAL_SERVER(server_name)) { + werr = NetFileClose_l(ctx, &r); + } else { + werr = NetFileClose_r(ctx, &r); + } + + r.out.result = W_ERROR_V(werr); + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_OUT_DEBUG(NetFileClose, &r); + } + + return r.out.result; +} + diff --git a/source3/lib/netapi/libnetapi.h b/source3/lib/netapi/libnetapi.h index 766d6fb705..8648563665 100644 --- a/source3/lib/netapi/libnetapi.h +++ b/source3/lib/netapi/libnetapi.h @@ -399,4 +399,10 @@ WERROR NetShareSetInfo_r(struct libnetapi_ctx *ctx, struct NetShareSetInfo *r); WERROR NetShareSetInfo_l(struct libnetapi_ctx *ctx, struct NetShareSetInfo *r); +NET_API_STATUS NetFileClose(const char * server_name /* [in] */, + uint32_t fileid /* [in] */); +WERROR NetFileClose_r(struct libnetapi_ctx *ctx, + struct NetFileClose *r); +WERROR NetFileClose_l(struct libnetapi_ctx *ctx, + struct NetFileClose *r); #endif /* __LIBNETAPI_LIBNETAPI__ */ -- cgit From bbd2eeb0f6f553600c8a5edc215aa544f9eab5a9 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 9 Sep 2008 19:37:39 +0200 Subject: netapi: add NetFileClose to public header. Guenther (This used to be commit 502bbf00faa500765d1a9dedc1cede271c89b7d1) --- source3/lib/netapi/netapi.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h index 6e4edab6c6..a95ea50a86 100644 --- a/source3/lib/netapi/netapi.h +++ b/source3/lib/netapi/netapi.h @@ -1754,6 +1754,22 @@ NET_API_STATUS NetShareSetInfo(const char * server_name /* [in] */, uint8_t *buffer /* [in] [ref] */, uint32_t *parm_err /* [out] [ref] */); +/************************************************************//** + * + * NetFileClose + * + * @brief Close a file + * + * @param[in] server_name The server name to connect to + * @param[in] fileid The fileid of the file that is going to be closed + * @return NET_API_STATUS + * + * example file/file_close.c + ***************************************************************/ + +NET_API_STATUS NetFileClose(const char * server_name /* [in] */, + uint32_t fileid /* [in] */); + #ifdef __cplusplus } #endif /* __cplusplus */ -- cgit From 120e7ba1f43783e451ab752ac4d4aee11a50d777 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 9 Sep 2008 19:37:17 +0200 Subject: netapi: add NetFileClose example code. Guenther (This used to be commit 9d6e3655346b6d1e08fd180ced9bd60ee1bc2f8f) --- source3/lib/netapi/examples/Makefile.in | 8 ++- source3/lib/netapi/examples/file/file_close.c | 83 +++++++++++++++++++++++++++ 2 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 source3/lib/netapi/examples/file/file_close.c (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/Makefile.in b/source3/lib/netapi/examples/Makefile.in index 3eea96ab00..e11bdf5001 100644 --- a/source3/lib/netapi/examples/Makefile.in +++ b/source3/lib/netapi/examples/Makefile.in @@ -59,7 +59,8 @@ PROGS = bin/getdc@EXEEXT@ \ bin/share_del@EXEEXT@ \ bin/share_enum@EXEEXT@ \ bin/share_getinfo@EXEEXT@ \ - bin/share_setinfo@EXEEXT@ + bin/share_setinfo@EXEEXT@ \ + bin/file_close@EXEEXT@ all: $(PROGS) @@ -131,6 +132,7 @@ SHAREDEL_OBJ = share/share_del.o $(CMDLINE_OBJ) SHAREENUM_OBJ = share/share_enum.o $(CMDLINE_OBJ) SHAREGETINFO_OBJ = share/share_getinfo.o $(CMDLINE_OBJ) SHARESETINFO_OBJ = share/share_setinfo.o $(CMDLINE_OBJ) +FILECLOSE_OBJ = file/file_close.o $(CMDLINE_OBJ) bin/getdc@EXEEXT@: $(BINARY_PREREQS) $(GETDC_OBJ) @echo Linking $@ @@ -304,6 +306,10 @@ bin/share_setinfo@EXEEXT@: $(BINARY_PREREQS) $(SHARESETINFO_OBJ) @echo Linking $@ @$(CC) $(FLAGS) -o $@ $(SHARESETINFO_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) +bin/file_close@EXEEXT@: $(BINARY_PREREQS) $(FILECLOSE_OBJ) + @echo Linking $@ + @$(CC) $(FLAGS) -o $@ $(FILECLOSE_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) + clean: -rm -f $(PROGS) -rm -f core */*~ *~ \ diff --git a/source3/lib/netapi/examples/file/file_close.c b/source3/lib/netapi/examples/file/file_close.c new file mode 100644 index 0000000000..759173a0ec --- /dev/null +++ b/source3/lib/netapi/examples/file/file_close.c @@ -0,0 +1,83 @@ +/* + * Unix SMB/CIFS implementation. + * NetFileClose query + * Copyright (C) Guenther Deschner 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include +#include +#include +#include +#include + +#include + +#include "common.h" + +int main(int argc, const char **argv) +{ + NET_API_STATUS status; + struct libnetapi_ctx *ctx = NULL; + const char *hostname = NULL; + uint32_t fileid = 0; + + poptContext pc; + int opt; + + struct poptOption long_options[] = { + POPT_AUTOHELP + POPT_COMMON_LIBNETAPI_EXAMPLES + POPT_TABLEEND + }; + + status = libnetapi_init(&ctx); + if (status != 0) { + return status; + } + + pc = poptGetContext("file_close", argc, argv, long_options, 0); + + poptSetOtherOptionHelp(pc, "hostname fileid"); + while((opt = poptGetNextOpt(pc)) != -1) { + } + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + hostname = poptGetArg(pc); + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + fileid = atoi(poptGetArg(pc)); + + /* NetFileClose */ + + status = NetFileClose(hostname, fileid); + if (status != 0) { + printf("NetFileClose failed with: %s\n", + libnetapi_get_error_string(ctx, status)); + goto out; + } + + out: + libnetapi_free(ctx); + poptFreeContext(pc); + + return status; +} -- cgit From cb1e34745b180f93a58d29a566ac11b4253ff806 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 9 Sep 2008 19:31:03 +0200 Subject: netapi: implement NetFileClose_r. Guenther (This used to be commit 0cbbdf21ed0c9270c00a7fd08f42f6546b9ac9b8) --- source3/lib/netapi/file.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/file.c b/source3/lib/netapi/file.c index aa80e8d56a..c0edb8e062 100644 --- a/source3/lib/netapi/file.c +++ b/source3/lib/netapi/file.c @@ -30,7 +30,33 @@ WERROR NetFileClose_r(struct libnetapi_ctx *ctx, struct NetFileClose *r) { - return WERR_NOT_SUPPORTED; + WERROR werr; + NTSTATUS status; + struct cli_state *cli = NULL; + struct rpc_pipe_client *pipe_cli = NULL; + + werr = libnetapi_open_pipe(ctx, r->in.server_name, + &ndr_table_srvsvc.syntax_id, + &cli, + &pipe_cli); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + status = rpccli_srvsvc_NetFileClose(pipe_cli, ctx, + r->in.server_name, + r->in.fileid, + &werr); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + done: + if (!cli) { + return werr; + } + + return werr; } /**************************************************************** -- cgit From f2381acf5a69df049dd897d40f9eb7490b33fd00 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 9 Sep 2008 19:43:02 +0200 Subject: netapi: add NetFileGetInfo skeleton. Guenther (This used to be commit 6c61c2e35e60a7b1398533311dab5eee38eb3b09) --- source3/lib/netapi/file.c | 18 +++++++++++++++++ source3/lib/netapi/libnetapi.c | 46 ++++++++++++++++++++++++++++++++++++++++++ source3/lib/netapi/libnetapi.h | 8 ++++++++ 3 files changed, 72 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/file.c b/source3/lib/netapi/file.c index c0edb8e062..021e4c2938 100644 --- a/source3/lib/netapi/file.c +++ b/source3/lib/netapi/file.c @@ -67,3 +67,21 @@ WERROR NetFileClose_l(struct libnetapi_ctx *ctx, { LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetFileClose); } + +/**************************************************************** +****************************************************************/ + +WERROR NetFileGetInfo_r(struct libnetapi_ctx *ctx, + struct NetFileGetInfo *r) +{ + return WERR_NOT_SUPPORTED; +} + +/**************************************************************** +****************************************************************/ + +WERROR NetFileGetInfo_l(struct libnetapi_ctx *ctx, + struct NetFileGetInfo *r) +{ + LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetFileGetInfo); +} diff --git a/source3/lib/netapi/libnetapi.c b/source3/lib/netapi/libnetapi.c index d83dc28c43..48c019cdf9 100644 --- a/source3/lib/netapi/libnetapi.c +++ b/source3/lib/netapi/libnetapi.c @@ -2250,3 +2250,49 @@ NET_API_STATUS NetFileClose(const char * server_name /* [in] */, return r.out.result; } +/**************************************************************** + NetFileGetInfo +****************************************************************/ + +NET_API_STATUS NetFileGetInfo(const char * server_name /* [in] */, + uint32_t fileid /* [in] */, + uint32_t level /* [in] */, + uint8_t **buffer /* [out] [ref] */) +{ + struct NetFileGetInfo r; + struct libnetapi_ctx *ctx = NULL; + NET_API_STATUS status; + WERROR werr; + + status = libnetapi_getctx(&ctx); + if (status != 0) { + return status; + } + + /* In parameters */ + r.in.server_name = server_name; + r.in.fileid = fileid; + r.in.level = level; + + /* Out parameters */ + r.out.buffer = buffer; + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_IN_DEBUG(NetFileGetInfo, &r); + } + + if (LIBNETAPI_LOCAL_SERVER(server_name)) { + werr = NetFileGetInfo_l(ctx, &r); + } else { + werr = NetFileGetInfo_r(ctx, &r); + } + + r.out.result = W_ERROR_V(werr); + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_OUT_DEBUG(NetFileGetInfo, &r); + } + + return r.out.result; +} + diff --git a/source3/lib/netapi/libnetapi.h b/source3/lib/netapi/libnetapi.h index 8648563665..0d2cd3107e 100644 --- a/source3/lib/netapi/libnetapi.h +++ b/source3/lib/netapi/libnetapi.h @@ -405,4 +405,12 @@ WERROR NetFileClose_r(struct libnetapi_ctx *ctx, struct NetFileClose *r); WERROR NetFileClose_l(struct libnetapi_ctx *ctx, struct NetFileClose *r); +NET_API_STATUS NetFileGetInfo(const char * server_name /* [in] */, + uint32_t fileid /* [in] */, + uint32_t level /* [in] */, + uint8_t **buffer /* [out] [ref] */); +WERROR NetFileGetInfo_r(struct libnetapi_ctx *ctx, + struct NetFileGetInfo *r); +WERROR NetFileGetInfo_l(struct libnetapi_ctx *ctx, + struct NetFileGetInfo *r); #endif /* __LIBNETAPI_LIBNETAPI__ */ -- cgit From 93ae66e01ec9e674e2fcac2a4f8a4c48cb35c673 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 9 Sep 2008 21:55:45 +0200 Subject: netapi: implement NetFileGetInfo_r. Guenther (This used to be commit de84049bc14d5c2061cdb701fd81a7fed1546eed) --- source3/lib/netapi/file.c | 94 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 93 insertions(+), 1 deletion(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/file.c b/source3/lib/netapi/file.c index 021e4c2938..8d40fdb046 100644 --- a/source3/lib/netapi/file.c +++ b/source3/lib/netapi/file.c @@ -71,10 +71,102 @@ WERROR NetFileClose_l(struct libnetapi_ctx *ctx, /**************************************************************** ****************************************************************/ +static NTSTATUS map_srvsvc_FileInfo_to_FILE_INFO_buffer(TALLOC_CTX *mem_ctx, + uint32_t level, + union srvsvc_NetFileInfo *info, + uint8_t **buffer, + uint32_t *num_entries) +{ + struct FILE_INFO_2 i2; + struct FILE_INFO_3 i3; + + switch (level) { + case 2: + i2.fi2_id = info->info2->fid; + + ADD_TO_ARRAY(mem_ctx, struct FILE_INFO_2, i2, + (struct FILE_INFO_2 **)buffer, + num_entries); + break; + case 3: + i3.fi3_id = info->info3->fid; + i3.fi3_permissions = info->info3->permissions; + i3.fi3_num_locks = info->info3->num_locks; + i3.fi3_pathname = talloc_strdup(mem_ctx, info->info3->path); + i3.fi3_username = talloc_strdup(mem_ctx, info->info3->user); + + NT_STATUS_HAVE_NO_MEMORY(i3.fi3_pathname); + NT_STATUS_HAVE_NO_MEMORY(i3.fi3_username); + + ADD_TO_ARRAY(mem_ctx, struct FILE_INFO_3, i3, + (struct FILE_INFO_3 **)buffer, + num_entries); + break; + default: + return NT_STATUS_INVALID_INFO_CLASS; + } + + return NT_STATUS_OK; +} + +/**************************************************************** +****************************************************************/ + WERROR NetFileGetInfo_r(struct libnetapi_ctx *ctx, struct NetFileGetInfo *r) { - return WERR_NOT_SUPPORTED; + WERROR werr; + NTSTATUS status; + struct cli_state *cli = NULL; + struct rpc_pipe_client *pipe_cli = NULL; + union srvsvc_NetFileInfo info; + uint32_t num_entries = 0; + + if (!r->out.buffer) { + return WERR_INVALID_PARAM; + } + + switch (r->in.level) { + case 2: + case 3: + break; + default: + return WERR_UNKNOWN_LEVEL; + } + + werr = libnetapi_open_pipe(ctx, r->in.server_name, + &ndr_table_srvsvc.syntax_id, + &cli, + &pipe_cli); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + status = rpccli_srvsvc_NetFileGetInfo(pipe_cli, ctx, + r->in.server_name, + r->in.fileid, + r->in.level, + &info, + &werr); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + status = map_srvsvc_FileInfo_to_FILE_INFO_buffer(ctx, + r->in.level, + &info, + r->out.buffer, + &num_entries); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + done: + if (!cli) { + return werr; + } + + return werr; } /**************************************************************** -- cgit From 8ab0d696c5be9602c239eeb00f5c976fe28ebc87 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 9 Sep 2008 21:56:04 +0200 Subject: netapi: add NetFileGetInfo to public header. Guenther (This used to be commit 5dd017b33f7d4154966aa3633d3ef3c8b482ca62) --- source3/lib/netapi/netapi.h | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h index a95ea50a86..f29ba225ff 100644 --- a/source3/lib/netapi/netapi.h +++ b/source3/lib/netapi/netapi.h @@ -633,6 +633,18 @@ struct SHARE_INFO_1006 { uint32_t shi1006_max_uses; }; +struct FILE_INFO_2 { + uint32_t fi2_id; +}; + +struct FILE_INFO_3 { + uint32_t fi3_id; + uint32_t fi3_permissions; + uint32_t fi3_num_locks; + const char * fi3_pathname; + const char * fi3_username; +}; + #endif /* _HEADER_libnetapi */ /**************************************************************** @@ -1770,6 +1782,26 @@ NET_API_STATUS NetShareSetInfo(const char * server_name /* [in] */, NET_API_STATUS NetFileClose(const char * server_name /* [in] */, uint32_t fileid /* [in] */); +/************************************************************//** + * + * NetFileGetInfo + * + * @brief Close a file + * + * @param[in] server_name The server name to connect to + * @param[in] fileid The fileid of the file that is going to be closed + * @param[in] level The level of the FILE_INFO_X buffer + * @param[out] buffer The buffer containing a FILE_INFO_X structure + * @return NET_API_STATUS + * + * example file/file_getinfo.c + ***************************************************************/ + +NET_API_STATUS NetFileGetInfo(const char * server_name /* [in] */, + uint32_t fileid /* [in] */, + uint32_t level /* [in] */, + uint8_t **buffer /* [out] [ref] */); + #ifdef __cplusplus } #endif /* __cplusplus */ -- cgit From 939d969490857d7315744184ddfcbcb684988f8f Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 9 Sep 2008 21:56:29 +0200 Subject: netapi: add NetFileGetInfo example code. Guenther (This used to be commit 66158036423f8e875921b7ba36f048033c3e98a6) --- source3/lib/netapi/examples/Makefile.in | 8 +- source3/lib/netapi/examples/file/file_getinfo.c | 112 ++++++++++++++++++++++++ 2 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 source3/lib/netapi/examples/file/file_getinfo.c (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/Makefile.in b/source3/lib/netapi/examples/Makefile.in index e11bdf5001..2e787572d8 100644 --- a/source3/lib/netapi/examples/Makefile.in +++ b/source3/lib/netapi/examples/Makefile.in @@ -60,7 +60,8 @@ PROGS = bin/getdc@EXEEXT@ \ bin/share_enum@EXEEXT@ \ bin/share_getinfo@EXEEXT@ \ bin/share_setinfo@EXEEXT@ \ - bin/file_close@EXEEXT@ + bin/file_close@EXEEXT@ \ + bin/file_getinfo@EXEEXT@ all: $(PROGS) @@ -133,6 +134,7 @@ SHAREENUM_OBJ = share/share_enum.o $(CMDLINE_OBJ) SHAREGETINFO_OBJ = share/share_getinfo.o $(CMDLINE_OBJ) SHARESETINFO_OBJ = share/share_setinfo.o $(CMDLINE_OBJ) FILECLOSE_OBJ = file/file_close.o $(CMDLINE_OBJ) +FILEGETINFO_OBJ = file/file_getinfo.o $(CMDLINE_OBJ) bin/getdc@EXEEXT@: $(BINARY_PREREQS) $(GETDC_OBJ) @echo Linking $@ @@ -310,6 +312,10 @@ bin/file_close@EXEEXT@: $(BINARY_PREREQS) $(FILECLOSE_OBJ) @echo Linking $@ @$(CC) $(FLAGS) -o $@ $(FILECLOSE_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) +bin/file_getinfo@EXEEXT@: $(BINARY_PREREQS) $(FILEGETINFO_OBJ) + @echo Linking $@ + @$(CC) $(FLAGS) -o $@ $(FILEGETINFO_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) + clean: -rm -f $(PROGS) -rm -f core */*~ *~ \ diff --git a/source3/lib/netapi/examples/file/file_getinfo.c b/source3/lib/netapi/examples/file/file_getinfo.c new file mode 100644 index 0000000000..9ad8305bc5 --- /dev/null +++ b/source3/lib/netapi/examples/file/file_getinfo.c @@ -0,0 +1,112 @@ +/* + * Unix SMB/CIFS implementation. + * NetFileGetInfo query + * Copyright (C) Guenther Deschner 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include +#include +#include +#include +#include + +#include + +#include "common.h" + +int main(int argc, const char **argv) +{ + NET_API_STATUS status; + struct libnetapi_ctx *ctx = NULL; + const char *hostname = NULL; + uint32_t fileid = 0; + uint32_t level = 3; + uint8_t *buffer = NULL; + + struct FILE_INFO_2 *i2 = NULL; + struct FILE_INFO_3 *i3 = NULL; + + poptContext pc; + int opt; + + struct poptOption long_options[] = { + POPT_AUTOHELP + POPT_COMMON_LIBNETAPI_EXAMPLES + POPT_TABLEEND + }; + + status = libnetapi_init(&ctx); + if (status != 0) { + return status; + } + + pc = poptGetContext("file_getinfo", argc, argv, long_options, 0); + + poptSetOtherOptionHelp(pc, "hostname fileid"); + while((opt = poptGetNextOpt(pc)) != -1) { + } + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + hostname = poptGetArg(pc); + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + fileid = atoi(poptGetArg(pc)); + + if (poptPeekArg(pc)) { + level = atoi(poptGetArg(pc)); + } + + /* NetFileGetInfo */ + + status = NetFileGetInfo(hostname, + fileid, + level, + &buffer); + if (status != 0) { + printf("NetFileGetInfo failed with: %s\n", + libnetapi_get_error_string(ctx, status)); + goto out; + } + + switch (level) { + case 2: + i2 = (struct FILE_INFO_2 *)buffer; + printf("file_id: %d\n", i2->fi2_id); + break; + case 3: + i3 = (struct FILE_INFO_3 *)buffer; + printf("file_id: %d\n", i3->fi3_id); + printf("permissions: %d\n", i3->fi3_permissions); + printf("num_locks: %d\n", i3->fi3_num_locks); + printf("pathname: %s\n", i3->fi3_pathname); + printf("username: %s\n", i3->fi3_username); + break; + default: + break; + } + + out: + libnetapi_free(ctx); + poptFreeContext(pc); + + return status; +} -- cgit From 13f28b574784aaa409b719d7da9a454760dbdc18 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 9 Sep 2008 22:01:32 +0200 Subject: netapi: add NetFileEnum skeleton. Guenther (This used to be commit 8113249fe3be2968257bd6a4a12153104d91132e) --- source3/lib/netapi/file.c | 18 +++++++++++++ source3/lib/netapi/libnetapi.c | 57 ++++++++++++++++++++++++++++++++++++++++++ source3/lib/netapi/libnetapi.h | 13 ++++++++++ 3 files changed, 88 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/file.c b/source3/lib/netapi/file.c index 8d40fdb046..d7c0558eec 100644 --- a/source3/lib/netapi/file.c +++ b/source3/lib/netapi/file.c @@ -177,3 +177,21 @@ WERROR NetFileGetInfo_l(struct libnetapi_ctx *ctx, { LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetFileGetInfo); } + +/**************************************************************** +****************************************************************/ + +WERROR NetFileEnum_r(struct libnetapi_ctx *ctx, + struct NetFileEnum *r) +{ + return WERR_NOT_SUPPORTED; +} + +/**************************************************************** +****************************************************************/ + +WERROR NetFileEnum_l(struct libnetapi_ctx *ctx, + struct NetFileEnum *r) +{ + LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetFileEnum); +} diff --git a/source3/lib/netapi/libnetapi.c b/source3/lib/netapi/libnetapi.c index 48c019cdf9..043190a1f9 100644 --- a/source3/lib/netapi/libnetapi.c +++ b/source3/lib/netapi/libnetapi.c @@ -2296,3 +2296,60 @@ NET_API_STATUS NetFileGetInfo(const char * server_name /* [in] */, return r.out.result; } +/**************************************************************** + NetFileEnum +****************************************************************/ + +NET_API_STATUS NetFileEnum(const char * server_name /* [in] */, + const char * base_path /* [in] */, + const char * user_name /* [in] */, + uint32_t level /* [in] */, + uint8_t **buffer /* [out] [ref] */, + uint32_t prefmaxlen /* [in] */, + uint32_t *entries_read /* [out] [ref] */, + uint32_t *total_entries /* [out] [ref] */, + uint32_t *resume_handle /* [in,out] [ref] */) +{ + struct NetFileEnum r; + struct libnetapi_ctx *ctx = NULL; + NET_API_STATUS status; + WERROR werr; + + status = libnetapi_getctx(&ctx); + if (status != 0) { + return status; + } + + /* In parameters */ + r.in.server_name = server_name; + r.in.base_path = base_path; + r.in.user_name = user_name; + r.in.level = level; + r.in.prefmaxlen = prefmaxlen; + r.in.resume_handle = resume_handle; + + /* Out parameters */ + r.out.buffer = buffer; + r.out.entries_read = entries_read; + r.out.total_entries = total_entries; + r.out.resume_handle = resume_handle; + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_IN_DEBUG(NetFileEnum, &r); + } + + if (LIBNETAPI_LOCAL_SERVER(server_name)) { + werr = NetFileEnum_l(ctx, &r); + } else { + werr = NetFileEnum_r(ctx, &r); + } + + r.out.result = W_ERROR_V(werr); + + if (DEBUGLEVEL >= 10) { + NDR_PRINT_OUT_DEBUG(NetFileEnum, &r); + } + + return r.out.result; +} + diff --git a/source3/lib/netapi/libnetapi.h b/source3/lib/netapi/libnetapi.h index 0d2cd3107e..1b84b75f94 100644 --- a/source3/lib/netapi/libnetapi.h +++ b/source3/lib/netapi/libnetapi.h @@ -413,4 +413,17 @@ WERROR NetFileGetInfo_r(struct libnetapi_ctx *ctx, struct NetFileGetInfo *r); WERROR NetFileGetInfo_l(struct libnetapi_ctx *ctx, struct NetFileGetInfo *r); +NET_API_STATUS NetFileEnum(const char * server_name /* [in] */, + const char * base_path /* [in] */, + const char * user_name /* [in] */, + uint32_t level /* [in] */, + uint8_t **buffer /* [out] [ref] */, + uint32_t prefmaxlen /* [in] */, + uint32_t *entries_read /* [out] [ref] */, + uint32_t *total_entries /* [out] [ref] */, + uint32_t *resume_handle /* [in,out] [ref] */); +WERROR NetFileEnum_r(struct libnetapi_ctx *ctx, + struct NetFileEnum *r); +WERROR NetFileEnum_l(struct libnetapi_ctx *ctx, + struct NetFileEnum *r); #endif /* __LIBNETAPI_LIBNETAPI__ */ -- cgit From 6b3308648cc828d3e713b330c95bdc63eac4fd53 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 9 Sep 2008 22:16:07 +0200 Subject: netapi: add NetFileEnum to public header. Guenther (This used to be commit 50ce2a3d1a520bd1508110872e871c2c67e0f606) --- source3/lib/netapi/netapi.h | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h index f29ba225ff..9687461920 100644 --- a/source3/lib/netapi/netapi.h +++ b/source3/lib/netapi/netapi.h @@ -1802,6 +1802,37 @@ NET_API_STATUS NetFileGetInfo(const char * server_name /* [in] */, uint32_t level /* [in] */, uint8_t **buffer /* [out] [ref] */); +/************************************************************//** + * + * NetFileEnum + * + * @brief Enumerate Files + * + * @param[in] server_name The server name to connect to + * @param[in] base_path The + * @param[in] user_name The + * @param[in] level The level defining the FILE_INFO_X structure + * @param[out] buffer The buffer containing a FILE_INFO_X structure + * @param[in] prefmaxlen The requested maximal buffer size + * @param[out] entries_read The number of FILE_INFO_X entries in the buffer + * @param[out] total_entries The total number of FILE_INFO_X entries + * @param[in,out] resume_handle A handle passed in and returned for resuming + * operations + * @return NET_API_STATUS + * + * example file/file_enum.c + ***************************************************************/ + +NET_API_STATUS NetFileEnum(const char * server_name /* [in] */, + const char * base_path /* [in] */, + const char * user_name /* [in] */, + uint32_t level /* [in] */, + uint8_t **buffer /* [out] [ref] */, + uint32_t prefmaxlen /* [in] */, + uint32_t *entries_read /* [out] [ref] */, + uint32_t *total_entries /* [out] [ref] */, + uint32_t *resume_handle /* [in,out] [ref] */); + #ifdef __cplusplus } #endif /* __cplusplus */ -- cgit From d556635bcc755d72d36104b85235bfecfbcf7108 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 9 Sep 2008 22:17:00 +0200 Subject: netapi: add NetFileEnum example code. Guenther (This used to be commit 32ee2dadab5b2579d53d0ecb106f0e64063da3f7) --- source3/lib/netapi/examples/Makefile.in | 8 +- source3/lib/netapi/examples/file/file_enum.c | 146 +++++++++++++++++++++++++++ 2 files changed, 153 insertions(+), 1 deletion(-) create mode 100644 source3/lib/netapi/examples/file/file_enum.c (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/examples/Makefile.in b/source3/lib/netapi/examples/Makefile.in index 2e787572d8..b1c1e59be7 100644 --- a/source3/lib/netapi/examples/Makefile.in +++ b/source3/lib/netapi/examples/Makefile.in @@ -61,7 +61,8 @@ PROGS = bin/getdc@EXEEXT@ \ bin/share_getinfo@EXEEXT@ \ bin/share_setinfo@EXEEXT@ \ bin/file_close@EXEEXT@ \ - bin/file_getinfo@EXEEXT@ + bin/file_getinfo@EXEEXT@ \ + bin/file_enum@EXEEXT@ all: $(PROGS) @@ -135,6 +136,7 @@ SHAREGETINFO_OBJ = share/share_getinfo.o $(CMDLINE_OBJ) SHARESETINFO_OBJ = share/share_setinfo.o $(CMDLINE_OBJ) FILECLOSE_OBJ = file/file_close.o $(CMDLINE_OBJ) FILEGETINFO_OBJ = file/file_getinfo.o $(CMDLINE_OBJ) +FILEENUM_OBJ = file/file_enum.o $(CMDLINE_OBJ) bin/getdc@EXEEXT@: $(BINARY_PREREQS) $(GETDC_OBJ) @echo Linking $@ @@ -316,6 +318,10 @@ bin/file_getinfo@EXEEXT@: $(BINARY_PREREQS) $(FILEGETINFO_OBJ) @echo Linking $@ @$(CC) $(FLAGS) -o $@ $(FILEGETINFO_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) +bin/file_enum@EXEEXT@: $(BINARY_PREREQS) $(FILEENUM_OBJ) + @echo Linking $@ + @$(CC) $(FLAGS) -o $@ $(FILEENUM_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS) + clean: -rm -f $(PROGS) -rm -f core */*~ *~ \ diff --git a/source3/lib/netapi/examples/file/file_enum.c b/source3/lib/netapi/examples/file/file_enum.c new file mode 100644 index 0000000000..5fbb285194 --- /dev/null +++ b/source3/lib/netapi/examples/file/file_enum.c @@ -0,0 +1,146 @@ +/* + * Unix SMB/CIFS implementation. + * NetFileEnum query + * Copyright (C) Guenther Deschner 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include +#include +#include +#include +#include + +#include + +#include "common.h" + +int main(int argc, const char **argv) +{ + NET_API_STATUS status; + struct libnetapi_ctx *ctx = NULL; + const char *hostname = NULL; + const char *basepath = NULL; + const char *username = NULL; + uint32_t level = 3; + uint8_t *buffer = NULL; + uint32_t entries_read = 0; + uint32_t total_entries = 0; + uint32_t resume_handle = 0; + int i; + + struct FILE_INFO_2 *i2 = NULL; + struct FILE_INFO_3 *i3 = NULL; + + poptContext pc; + int opt; + + struct poptOption long_options[] = { + POPT_AUTOHELP + POPT_COMMON_LIBNETAPI_EXAMPLES + POPT_TABLEEND + }; + + status = libnetapi_init(&ctx); + if (status != 0) { + return status; + } + + pc = poptGetContext("file_enum", argc, argv, long_options, 0); + + poptSetOtherOptionHelp(pc, "hostname basepath username level"); + while((opt = poptGetNextOpt(pc)) != -1) { + } + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + hostname = poptGetArg(pc); + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + basepath = poptGetArg(pc); + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + username = poptGetArg(pc); + + if (poptPeekArg(pc)) { + level = atoi(poptGetArg(pc)); + } + + /* NetFileEnum */ + + do { + + status = NetFileEnum(hostname, + basepath, + username, + level, + &buffer, + (uint32_t)-1, + &entries_read, + &total_entries, + &resume_handle); + if (status == 0 || status == ERROR_MORE_DATA) { + printf("total entries: %d\n", total_entries); + switch (level) { + case 2: + i2 = (struct FILE_INFO_2 *)buffer; + break; + case 3: + i3 = (struct FILE_INFO_3 *)buffer; + break; + default: + break; + } + for (i=0; ifi2_id); + i2++; + break; + case 3: + printf("file_id: %d\n", i3->fi3_id); + printf("permissions: %d\n", i3->fi3_permissions); + printf("num_locks: %d\n", i3->fi3_num_locks); + printf("pathname: %s\n", i3->fi3_pathname); + printf("username: %s\n", i3->fi3_username); + i3++; + break; + default: + break; + } + } + NetApiBufferFree(buffer); + } + } while (status == ERROR_MORE_DATA); + + if (status != 0) { + printf("NetFileEnum failed with: %s\n", + libnetapi_get_error_string(ctx, status)); + goto out; + } + out: + libnetapi_free(ctx); + poptFreeContext(pc); + + return status; +} -- cgit From 898a69ea0c9000e8ecb91902e4d4662a4decf741 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 10 Sep 2008 10:03:48 +0200 Subject: netapi: implement NetFileEnum_r. Guenther (This used to be commit fd66b72fd017013c83d36f5219192716eb17cacb) --- source3/lib/netapi/file.c | 94 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 93 insertions(+), 1 deletion(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/file.c b/source3/lib/netapi/file.c index d7c0558eec..036af32f38 100644 --- a/source3/lib/netapi/file.c +++ b/source3/lib/netapi/file.c @@ -184,7 +184,99 @@ WERROR NetFileGetInfo_l(struct libnetapi_ctx *ctx, WERROR NetFileEnum_r(struct libnetapi_ctx *ctx, struct NetFileEnum *r) { - return WERR_NOT_SUPPORTED; + WERROR werr; + NTSTATUS status; + struct cli_state *cli = NULL; + struct rpc_pipe_client *pipe_cli = NULL; + struct srvsvc_NetFileInfoCtr info_ctr; + struct srvsvc_NetFileCtr2 ctr2; + struct srvsvc_NetFileCtr3 ctr3; + uint32_t num_entries = 0; + uint32_t i; + + if (!r->out.buffer) { + return WERR_INVALID_PARAM; + } + + switch (r->in.level) { + case 2: + case 3: + break; + default: + return WERR_UNKNOWN_LEVEL; + } + + werr = libnetapi_open_pipe(ctx, r->in.server_name, + &ndr_table_srvsvc.syntax_id, + &cli, + &pipe_cli); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + ZERO_STRUCT(info_ctr); + + info_ctr.level = r->in.level; + switch (r->in.level) { + case 2: + ZERO_STRUCT(ctr2); + info_ctr.ctr.ctr2 = &ctr2; + break; + case 3: + ZERO_STRUCT(ctr3); + info_ctr.ctr.ctr3 = &ctr3; + break; + } + + status = rpccli_srvsvc_NetFileEnum(pipe_cli, ctx, + r->in.server_name, + r->in.base_path, + r->in.user_name, + &info_ctr, + r->in.prefmaxlen, + r->out.total_entries, + r->out.resume_handle, + &werr); + if (NT_STATUS_IS_ERR(status)) { + goto done; + } + + for (i=0; i < info_ctr.ctr.ctr2->count; i++) { + union srvsvc_NetFileInfo _i; + switch (r->in.level) { + case 2: + _i.info2 = &info_ctr.ctr.ctr2->array[i]; + break; + case 3: + _i.info3 = &info_ctr.ctr.ctr3->array[i]; + break; + } + + status = map_srvsvc_FileInfo_to_FILE_INFO_buffer(ctx, + r->in.level, + &_i, + r->out.buffer, + &num_entries); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; + } + } + + if (r->out.entries_read) { + *r->out.entries_read = num_entries; + } + + if (r->out.total_entries) { + *r->out.total_entries = num_entries; + } + + done: + if (!cli) { + return werr; + } + + return werr; } /**************************************************************** -- cgit From 00ba381e09988a2b8b531e5e42dfd5a31f822a90 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 12 Sep 2008 11:13:20 +0200 Subject: netapi: fix NetGroupSetUsers. Guenther (This used to be commit 735bc2e425ce629745495190cd1c721ccb583d24) --- source3/lib/netapi/group.c | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/group.c b/source3/lib/netapi/group.c index 2e0c4dc48e..e2a4913824 100644 --- a/source3/lib/netapi/group.c +++ b/source3/lib/netapi/group.c @@ -1454,6 +1454,7 @@ WERROR NetGroupSetUsers_r(struct libnetapi_ctx *ctx, struct samr_Ids user_rids, name_types; struct samr_Ids group_rids, group_types; struct samr_RidTypeArray *rid_array = NULL; + struct lsa_String *lsa_names = NULL; uint32_t *add_rids = NULL; uint32_t *del_rids = NULL; @@ -1549,39 +1550,40 @@ WERROR NetGroupSetUsers_r(struct libnetapi_ctx *ctx, break; } + lsa_names = talloc_array(ctx, struct lsa_String, r->in.num_entries); + if (!lsa_names) { + werr = WERR_NOMEM; + goto done; + } + for (i=0; i < r->in.num_entries; i++) { switch (r->in.level) { case 0: - init_lsa_String(&lsa_account_name, i0->grui0_name); + init_lsa_String(&lsa_names[i], i0->grui0_name); i0++; break; case 1: - init_lsa_String(&lsa_account_name, i1->grui1_name); + init_lsa_String(&lsa_names[i], i1->grui1_name); i1++; break; } + } - status = rpccli_samr_LookupNames(pipe_cli, ctx, - &domain_handle, - 1, - &lsa_account_name, - &user_rids, - &name_types); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - if (!add_rid_to_array_unique(ctx, - user_rids.ids[0], - &member_rids, - &num_member_rids)) { - werr = WERR_GENERAL_FAILURE; - goto done; - } + status = rpccli_samr_LookupNames(pipe_cli, ctx, + &domain_handle, + r->in.num_entries, + lsa_names, + &user_rids, + &name_types); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; } + member_rids = user_rids.ids; + num_member_rids = user_rids.count; + status = rpccli_samr_QueryGroupMember(pipe_cli, ctx, &group_handle, &rid_array); -- cgit From 47dbe6f7aef5cf3b7f2c0da90533fa2da2790cec Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 12 Sep 2008 11:28:03 +0200 Subject: netapi: fix NetUserSetGroups. Guenther (This used to be commit e8b27b69f33fb33c670026b3a24ed95a2f0099fe) --- source3/lib/netapi/user.c | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/user.c b/source3/lib/netapi/user.c index 62df2f9da5..986c32ad93 100644 --- a/source3/lib/netapi/user.c +++ b/source3/lib/netapi/user.c @@ -2938,6 +2938,7 @@ WERROR NetUserSetGroups_r(struct libnetapi_ctx *ctx, struct samr_Ids user_rids, name_types; struct samr_Ids group_rids; struct samr_RidWithAttributeArray *rid_array = NULL; + struct lsa_String *lsa_names = NULL; uint32_t *add_rids = NULL; uint32_t *del_rids = NULL; @@ -3021,39 +3022,40 @@ WERROR NetUserSetGroups_r(struct libnetapi_ctx *ctx, break; } + lsa_names = talloc_array(ctx, struct lsa_String, r->in.num_entries); + if (!lsa_names) { + werr = WERR_NOMEM; + goto done; + } + for (i=0; i < r->in.num_entries; i++) { switch (r->in.level) { case 0: - init_lsa_String(&lsa_account_name, i0->grui0_name); + init_lsa_String(&lsa_names[i], i0->grui0_name); i0++; break; case 1: - init_lsa_String(&lsa_account_name, i1->grui1_name); + init_lsa_String(&lsa_names[i], i1->grui1_name); i1++; break; } + } - status = rpccli_samr_LookupNames(pipe_cli, ctx, - &domain_handle, - 1, - &lsa_account_name, - &group_rids, - &name_types); - if (!NT_STATUS_IS_OK(status)) { - werr = ntstatus_to_werror(status); - goto done; - } - - if (!add_rid_to_array_unique(ctx, - group_rids.ids[0], - &member_rids, - &num_member_rids)) { - werr = WERR_GENERAL_FAILURE; - goto done; - } + status = rpccli_samr_LookupNames(pipe_cli, ctx, + &domain_handle, + r->in.num_entries, + lsa_names, + &group_rids, + &name_types); + if (!NT_STATUS_IS_OK(status)) { + werr = ntstatus_to_werror(status); + goto done; } + member_rids = group_rids.ids; + num_member_rids = group_rids.count; + status = rpccli_samr_GetGroupsForUser(pipe_cli, ctx, &user_handle, &rid_array); -- cgit From f792f87094c4eda453d54b6b4f1d70d88412f451 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 12 Sep 2008 11:28:42 +0200 Subject: netapi: fix NetGroupGetUsers (only enumerates users). Guenther (This used to be commit a94318be4656a668be0295988ed0743105d830c9) --- source3/lib/netapi/group.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/group.c b/source3/lib/netapi/group.c index e2a4913824..c3fccb4840 100644 --- a/source3/lib/netapi/group.c +++ b/source3/lib/netapi/group.c @@ -1391,10 +1391,15 @@ WERROR NetGroupGetUsers_r(struct libnetapi_ctx *ctx, } for (i=0; i < names.count; i++) { + + if (member_types.ids[i] != SID_NAME_USER) { + continue; + } + status = add_GROUP_USERS_INFO_X_buffer(ctx, r->in.level, names.names[i].string, - member_types.ids[i], + 7, r->out.buffer, &entries_read); if (!NT_STATUS_IS_OK(status)) { -- cgit From cf3d089afa55c3b3b21b2c48aa9941d1d2f3c043 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 12 Sep 2008 11:47:39 +0200 Subject: netapi: fix NetUserGetLocalGroups. Guenther (This used to be commit 5d91c9184c27def47f20fc089cc127d780387ed8) --- source3/lib/netapi/user.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/user.c b/source3/lib/netapi/user.c index 986c32ad93..7d0c47f331 100644 --- a/source3/lib/netapi/user.c +++ b/source3/lib/netapi/user.c @@ -3428,8 +3428,6 @@ WERROR NetUserGetLocalGroups_r(struct libnetapi_ctx *ctx, } return werr; - - return WERR_NOT_SUPPORTED; } /**************************************************************** -- cgit