diff options
Diffstat (limited to 'source4')
-rw-r--r-- | source4/samba_tool/gpo.c | 609 | ||||
-rw-r--r-- | source4/samba_tool/samba_tool.c | 385 | ||||
-rw-r--r-- | source4/samba_tool/samba_tool.h | 39 | ||||
-rw-r--r-- | source4/samba_tool/vampire.c | 130 | ||||
-rw-r--r-- | source4/samba_tool/wscript_build | 9 |
5 files changed, 0 insertions, 1172 deletions
diff --git a/source4/samba_tool/gpo.c b/source4/samba_tool/gpo.c deleted file mode 100644 index 10c231c85a..0000000000 --- a/source4/samba_tool/gpo.c +++ /dev/null @@ -1,609 +0,0 @@ -/* - Samba Unix/Linux SMB client library - net ads commands for Group Policy - - Copyright (C) 2005-2008 Guenther Deschner - Copyright (C) 2009 Wilco Baan Hofman - - Based on Guenther's work in net_ads_gpo.h (samba 3) - - 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 <http://www.gnu.org/licenses/>. -*/ - -#include "includes.h" -#include "samba_tool/samba_tool.h" -#include <ldb.h> -#include "auth/auth.h" -#include "param/param.h" -#include "libcli/security/sddl.h" -#include "dsdb/samdb/samdb.h" -#include "dsdb/common/util.h" -#include "lib/policy/policy.h" - -static int net_gpo_list_all_usage(struct net_context *ctx, int argc, const char **argv) -{ - d_printf("Syntax: samba-tool gpo listall [options]\n"); - d_printf("For a list of available options, please type samba-tool gpo listall --help\n"); - return 0; -} - -static int net_gpo_list_all(struct net_context *ctx, int argc, const char **argv) -{ - struct gp_context *gp_ctx; - struct gp_object **gpo; - const char **gpo_flags; - unsigned int i, j; - NTSTATUS rv; - - rv = gp_init(ctx, ctx->lp_ctx, ctx->credentials, ctx->event_ctx, &gp_ctx); - if (!NT_STATUS_IS_OK(rv)) { - DEBUG(0, ("Failed to connect to DC's LDAP: %s\n", get_friendly_nt_error_msg(rv))); - return 1; - } - - rv = gp_list_all_gpos(gp_ctx, &gpo); - if (!NT_STATUS_IS_OK(rv)) { - DEBUG(0, ("Failed to list all GPO's: %s\n", get_friendly_nt_error_msg(rv))); - talloc_free(gp_ctx); - return 1; - } - - for (i = 0; gpo[i] != NULL; i++) { - gp_get_gpo_flags(gp_ctx, gpo[i]->flags, &gpo_flags); - - d_printf("GPO : %s\n", gpo[i]->name); - d_printf("display name : %s\n", gpo[i]->display_name); - d_printf("path : %s\n", gpo[i]->file_sys_path); - d_printf("dn : %s\n", gpo[i]->dn); - d_printf("version : %d\n", gpo[i]->version); - if (gpo_flags[0] == NULL) { - d_printf("flags : NONE\n"); - } else { - d_printf("flags : %s\n", gpo_flags[0]); - for (j = 1; gpo_flags[j] != NULL; j++) { - d_printf(" %s\n", gpo_flags[i]); - } - } - d_printf("\n"); - talloc_free(gpo_flags); - } - talloc_free(gp_ctx); - - return 0; -} - -static int net_gpo_get_gpo_usage(struct net_context *ctx, int argc, const char **argv) -{ - d_printf("Syntax: samba-tool gpo show <dn> [options]\n"); - d_printf("For a list of available options, please type samba-tool gpo show --help\n"); - return 0; -} - -static int net_gpo_get_gpo(struct net_context *ctx, int argc, const char **argv) -{ - struct gp_context *gp_ctx; - struct gp_object *gpo; - const char **gpo_flags; - char *sddl; - int i; - NTSTATUS rv; - - if (argc != 1) { - return net_gpo_get_gpo_usage(ctx, argc, argv); - } - - - rv = gp_init(ctx, ctx->lp_ctx, ctx->credentials, ctx->event_ctx, &gp_ctx); - if (!NT_STATUS_IS_OK(rv)) { - DEBUG(0, ("Failed to connect to DC's LDAP: %s\n", get_friendly_nt_error_msg(rv))); - return 1; - } - - rv = gp_get_gpo_info(gp_ctx, argv[0], &gpo); - if (!NT_STATUS_IS_OK(rv)) { - DEBUG(0, ("Failed to get GPO: %s\n", get_friendly_nt_error_msg(rv))); - talloc_free(gp_ctx); - return 1; - } - - gp_get_gpo_flags(gp_ctx, gpo->flags, &gpo_flags); - - d_printf("GPO : %s\n", gpo->name); - d_printf("display name : %s\n", gpo->display_name); - d_printf("path : %s\n", gpo->file_sys_path); - d_printf("dn : %s\n", gpo->dn); - d_printf("version : %d\n", gpo->version); - if (gpo_flags[0] == NULL) { - d_printf("flags : NONE\n"); - } else { - d_printf("flags : %s\n", gpo_flags[0]); - for (i = 1; gpo_flags[i] != NULL; i++) { - d_printf(" %s\n", gpo_flags[i]); - } - } - sddl = sddl_encode(gp_ctx, gpo->security_descriptor, samdb_domain_sid(gp_ctx->ldb_ctx)); - if (sddl != NULL) { - d_printf("ACL : %s\n", sddl); - } - - d_printf("\n"); - - talloc_free(gp_ctx); - return 0; -} - -static int net_gpo_link_get_usage(struct net_context *ctx, int argc, const char **argv) -{ - d_printf("Syntax: samba-tool gpo getlink <dn> [options]\n"); - d_printf("For a list of available options, please type samba-tool gpo getlink --help\n"); - return 0; -} - -static int net_gpo_link_get(struct net_context *ctx, int argc, const char **argv) -{ - struct gp_context *gp_ctx; - struct gp_link **links; - NTSTATUS rv; - unsigned int i,j; - const char **options; - - if (argc != 1) { - return net_gpo_link_get_usage(ctx, argc, argv); - } - - rv = gp_init(ctx, ctx->lp_ctx, ctx->credentials, ctx->event_ctx, &gp_ctx); - if (!NT_STATUS_IS_OK(rv)) { - DEBUG(0, ("Failed to connect to DC's LDAP: %s\n", get_friendly_nt_error_msg(rv))); - return 1; - } - - rv = gp_get_gplinks(gp_ctx, argv[0], &links); - if (!NT_STATUS_IS_OK(rv)) { - DEBUG(0, ("Failed to get gplinks: %s\n", get_friendly_nt_error_msg(rv))); - talloc_free(gp_ctx); - return 1; - } - - for (i = 0; links[i] != NULL; i++) { - gp_get_gplink_options(gp_ctx, links[i]->options, &options); - - d_printf("GPO DN : %s\n", links[i]->dn); - if (options[0] == NULL) { - d_printf("Options : NONE\n"); - } else { - d_printf("Options : %s\n", options[0]); - for (j = 1; options[j] != NULL; j++) { - d_printf(" : %s\n", options[j]); - } - } - d_printf("\n"); - - talloc_free(options); - } - - talloc_free(gp_ctx); - - return 0; -} - -static int net_gpo_list_usage(struct net_context *ctx, int argc, const char **argv) -{ - d_printf("Syntax: samba-tool gpo list <username> [options]\n"); - d_printf("For a list of available options, please type samba-tool gpo list --help\n"); - return 0; -} - -static int net_gpo_list(struct net_context *ctx, int argc, const char **argv) -{ - struct gp_context *gp_ctx; - struct ldb_result *result; - struct auth_user_info_dc *user_info_dc; - struct auth_session_info *session_info; - DATA_BLOB dummy = { NULL, 0 }; - const char **gpos; - NTSTATUS status; - int rv; - unsigned int i; - - if (argc != 1) { - return net_gpo_list_usage(ctx, argc, argv); - } - - status = gp_init(ctx, ctx->lp_ctx, ctx->credentials, ctx->event_ctx, &gp_ctx); - if (!NT_STATUS_IS_OK(status)) { - DEBUG(0, ("Failed to connect to DC's LDAP: %s\n", get_friendly_nt_error_msg(status))); - return 1; - } - - /* Find the user in the directory. We need extended DN's for group expansion - * in authsam_make_user_info_dc */ - rv = dsdb_search(gp_ctx->ldb_ctx, - gp_ctx, - &result, - ldb_get_default_basedn(gp_ctx->ldb_ctx), - LDB_SCOPE_SUBTREE, - NULL, - DSDB_SEARCH_SHOW_EXTENDED_DN, - "(&(objectClass=user)(sAMAccountName=%s))", argv[0]); - if (rv != LDB_SUCCESS) { - DEBUG(0, ("LDB search failed: %s\n%s\n", ldb_strerror(rv),ldb_errstring(gp_ctx->ldb_ctx))); - talloc_free(gp_ctx); - return 1; - } - - /* We expect exactly one record */ - if (result->count != 1) { - DEBUG(0, ("Could not find SAM account with name %s\n", argv[0])); - talloc_free(gp_ctx); - return 1; - } - - /* We need the server info, as this will contain the groups of this - * user, needed for a token */ - status = authsam_make_user_info_dc(gp_ctx, - gp_ctx->ldb_ctx, - lpcfg_netbios_name(gp_ctx->lp_ctx), - lpcfg_sam_name(gp_ctx->lp_ctx), - ldb_get_default_basedn(gp_ctx->ldb_ctx), - result->msgs[0], - dummy, - dummy, - &user_info_dc); - if (!NT_STATUS_IS_OK(status)) { - DEBUG(0, ("Failed to make server information: %s\n", get_friendly_nt_error_msg(status))); - talloc_free(gp_ctx); - return 1; - } - - /* The session info will contain the security token for this user */ - status = auth_generate_session_info(gp_ctx, gp_ctx->lp_ctx, gp_ctx->ldb_ctx, user_info_dc, 0, &session_info); - if (!NT_STATUS_IS_OK(status)) { - DEBUG(0, ("Failed to generate session information: %s\n", get_friendly_nt_error_msg(status))); - talloc_free(gp_ctx); - return 1; - } - - status = gp_list_gpos(gp_ctx, session_info->security_token, &gpos); - if (!NT_STATUS_IS_OK(status)) { - DEBUG(0, ("Failed to list gpos for user %s: %s\n", argv[0], - get_friendly_nt_error_msg(status))); - talloc_free(gp_ctx); - return 1; - } - - d_printf("GPO's for user %s:\n", argv[0]); - for (i = 0; gpos[i] != NULL; i++) { - d_printf("\t%s\n", gpos[i]); - } - - talloc_free(gp_ctx); - return 0; -} - -static int net_gpo_link_set_usage(struct net_context *ctx, int argc, const char **argv) -{ - d_printf("Syntax: samba-tool gpo setlink <container> <gpo> ['disable'] ['enforce'] [options]\n"); - d_printf("For a list of available options, please type samba-tool gpo setlink --help\n"); - return 0; -} - -static int net_gpo_link_set(struct net_context *ctx, int argc, const char **argv) -{ - struct gp_link *gplink = talloc_zero(ctx, struct gp_link); - struct gp_context *gp_ctx; - unsigned int i; - NTSTATUS status; - - if (argc < 2) { - return net_gpo_link_set_usage(ctx, argc, argv); - } - - if (argc >= 3) { - for (i = 2; i < argc; i++) { - if (strcmp(argv[i], "disable") == 0) { - gplink->options |= GPLINK_OPT_DISABLE; - } - if (strcmp(argv[i], "enforce") == 0) { - gplink->options |= GPLINK_OPT_ENFORCE; - } - } - } - gplink->dn = argv[1]; - - status = gp_init(ctx, ctx->lp_ctx, ctx->credentials, ctx->event_ctx, &gp_ctx); - if (!NT_STATUS_IS_OK(status)) { - DEBUG(0, ("Failed to connect to DC's LDAP: %s\n", get_friendly_nt_error_msg(status))); - return 1; - } - - status = gp_set_gplink(gp_ctx, argv[0], gplink); - if (!NT_STATUS_IS_OK(status)) { - DEBUG(0, ("Failed to set GPO link on container: %s\n", get_friendly_nt_error_msg(status))); - return 1; - } - d_printf("Set link on container.\nCurrent Group Policy links:\n"); - - /* Display current links */ - net_gpo_link_get(ctx, 1, argv); - - talloc_free(gp_ctx); - return 0; -} - -static int net_gpo_link_del_usage(struct net_context *ctx, int argc, const char **argv) -{ - d_printf("Syntax: samba-tool gpo dellink <container> <gpo> [options]\n"); - d_printf("For a list of available options, please type samba-tool gpo dellink --help\n"); - return 0; -} - -static int net_gpo_link_del(struct net_context *ctx, int argc, const char **argv) -{ - struct gp_context *gp_ctx; - NTSTATUS status; - - if (argc != 2) { - return net_gpo_link_del_usage(ctx, argc, argv); - } - - status = gp_init(ctx, ctx->lp_ctx, ctx->credentials, ctx->event_ctx, &gp_ctx); - if (!NT_STATUS_IS_OK(status)) { - DEBUG(0, ("Failed to connect to DC's LDAP: %s\n", get_friendly_nt_error_msg(status))); - return 1; - } - - status = gp_del_gplink(gp_ctx, argv[0], argv[1]); - if (!NT_STATUS_IS_OK(status)) { - DEBUG(0, ("Failed to delete gplink: %s\n", get_friendly_nt_error_msg(status))); - talloc_free(gp_ctx); - return 1; - } - d_printf("Deleted gplink.\nCurrent Group Policy links:\n\n"); - - /* Display current links */ - net_gpo_link_get(ctx, 1, argv); - - talloc_free(gp_ctx); - return 0; -} - -static int net_gpo_inheritance_get_usage(struct net_context *ctx, int argc, const char **argv) -{ - d_printf("Syntax: samba-tool gpo getinheritance <container> [options]\n"); - d_printf("For a list of available options, please type samba-tool gpo getinheritance --help\n"); - return 0; -} - -static int net_gpo_inheritance_get(struct net_context *ctx, int argc, const char **argv) -{ - struct gp_context *gp_ctx; - enum gpo_inheritance inheritance; - NTSTATUS status; - - if (argc != 1) { - return net_gpo_inheritance_get_usage(ctx, argc, argv); - } - - status = gp_init(ctx, ctx->lp_ctx, ctx->credentials, ctx->event_ctx, &gp_ctx); - if (!NT_STATUS_IS_OK(status)) { - DEBUG(0, ("Failed to connect to DC's LDAP: %s\n", get_friendly_nt_error_msg(status))); - return 1; - } - - status = gp_get_inheritance(gp_ctx, argv[0], &inheritance); - if (!NT_STATUS_IS_OK(status)) { - DEBUG(0, ("Failed to set GPO link on container: %s\n", get_friendly_nt_error_msg(status))); - talloc_free(gp_ctx); - return 1; - } - - if (inheritance == GPO_BLOCK_INHERITANCE) { - d_printf("container has GPO_BLOCK_INHERITANCE\n"); - } else { - d_printf("container has GPO_INHERIT\n"); - } - - talloc_free(gp_ctx); - return 0; -} - -static int net_gpo_inheritance_set_usage(struct net_context *ctx, int argc, const char **argv) -{ - d_printf("Syntax: samba-tool gpo setinheritance <container> <\"block\"|\"inherit\"> [options]\n"); - d_printf("For a list of available options, please type samba-tool gpo setinheritance --help\n"); - return 0; -} - -static int net_gpo_inheritance_set(struct net_context *ctx, int argc, const char **argv) -{ - struct gp_context *gp_ctx; - enum gpo_inheritance inheritance; - NTSTATUS status; - - if (argc != 2) { - return net_gpo_inheritance_set_usage(ctx, argc, argv); - } - - if (strcmp(argv[1], "inherit") == 0) { - inheritance = GPO_INHERIT; - } else if (strcmp(argv[1], "block") == 0) { - inheritance = GPO_BLOCK_INHERITANCE; - } else { - return net_gpo_inheritance_set_usage(ctx, argc, argv); - } - - status = gp_init(ctx, ctx->lp_ctx, ctx->credentials, ctx->event_ctx, &gp_ctx); - if (!NT_STATUS_IS_OK(status)) { - DEBUG(0, ("Failed to connect to DC's LDAP: %s\n", get_friendly_nt_error_msg(status))); - return 1; - } - - status = gp_set_inheritance(gp_ctx, argv[0], inheritance); - if (!NT_STATUS_IS_OK(status)) { - DEBUG(0, ("Failed to set GPO link on container: %s\n", get_friendly_nt_error_msg(status))); - talloc_free(gp_ctx); - return 1; - } - - /* Display current links */ - net_gpo_inheritance_get(ctx, 1, argv); - - return 0; -} - -static int net_gpo_fetch_usage(struct net_context *ctx, int argc, const char **argv) -{ - d_printf("Syntax: samba-tool gpo fetch <container> [options]\n"); - d_printf("For a list of available options, please type samba-tool gpo fetch --help\n"); - return 0; -} - -static int net_gpo_fetch(struct net_context *ctx, int argc, const char **argv) -{ - struct gp_context *gp_ctx; - struct gp_object *gpo; - const char *path; - NTSTATUS rv; - - if (argc != 1) { - return net_gpo_fetch_usage(ctx, argc, argv); - } - - rv = gp_init(ctx, ctx->lp_ctx, ctx->credentials, ctx->event_ctx, &gp_ctx); - if (!NT_STATUS_IS_OK(rv)) { - DEBUG(0, ("Failed to connect to DC's LDAP: %s\n", get_friendly_nt_error_msg(rv))); - return 1; - } - - rv = gp_get_gpo_info(gp_ctx, argv[0], &gpo); - if (!NT_STATUS_IS_OK(rv)) { - DEBUG(0, ("Failed to get GPO: %s\n", get_friendly_nt_error_msg(rv))); - talloc_free(gp_ctx); - return 1; - } - - rv = gp_fetch_gpt(gp_ctx, gpo, &path); - if (!NT_STATUS_IS_OK(rv)) { - DEBUG(0, ("Failed to fetch GPO: %s\n", get_friendly_nt_error_msg(rv))); - talloc_free(gp_ctx); - return 1; - } - d_printf("%s\n", path); - - return 0; -} -static int net_gpo_create_usage(struct net_context *ctx, int argc, const char **argv) -{ - d_printf("Syntax: samba-tool gpo create <displayname> [options]\n"); - d_printf("For a list of available options, please type samba-tool gpo create --help\n"); - return 0; -} - -static int net_gpo_create(struct net_context *ctx, int argc, const char **argv) -{ - struct gp_context *gp_ctx; - struct gp_object *gpo; - NTSTATUS rv; - - if (argc != 1) { - return net_gpo_create_usage(ctx, argc, argv); - } - - rv = gp_init(ctx, ctx->lp_ctx, ctx->credentials, ctx->event_ctx, &gp_ctx); - if (!NT_STATUS_IS_OK(rv)) { - DEBUG(0, ("Failed to connect to DC's LDAP: %s\n", get_friendly_nt_error_msg(rv))); - return 1; - } - - rv = gp_create_gpo(gp_ctx, argv[0], &gpo); - if (!NT_STATUS_IS_OK(rv)) { - DEBUG(0, ("Failed to create GPO: %s\n", get_friendly_nt_error_msg(rv))); - talloc_free(gp_ctx); - return 1; - } - - - return 0; -} - -static int net_gpo_set_acl_usage(struct net_context *ctx, int argc, const char **argv) -{ - d_printf("Syntax: samba-tool gpo setacl <dn> <sddl> [options]\n"); - d_printf("For a list of available options, please type samba-tool gpo setacl --help\n"); - return 0; -} - -static int net_gpo_set_acl(struct net_context *ctx, int argc, const char **argv) -{ - struct gp_context *gp_ctx; - struct security_descriptor *sd; - NTSTATUS rv; - - if (argc != 2) { - return net_gpo_set_acl_usage(ctx, argc, argv); - } - - rv = gp_init(ctx, ctx->lp_ctx, ctx->credentials, ctx->event_ctx, &gp_ctx); - if (!NT_STATUS_IS_OK(rv)) { - DEBUG(0, ("Failed to connect to DC's LDAP: %s\n", get_friendly_nt_error_msg(rv))); - return 1; - } - - /* Convert sddl to security descriptor */ - sd = sddl_decode(gp_ctx, argv[1], samdb_domain_sid(gp_ctx->ldb_ctx)); - if (sd == NULL) { - DEBUG(0, ("Invalid SDDL\n")); - talloc_free(gp_ctx); - return 1; - } - - rv = gp_set_acl(gp_ctx, argv[0], sd); - if (!NT_STATUS_IS_OK(rv)) { - DEBUG(0, ("Failed to set ACL on GPO: %s\n", get_friendly_nt_error_msg(rv))); - talloc_free(gp_ctx); - return 1; - } - - talloc_free(gp_ctx); - return 0; -} - - - -static const struct net_functable net_gpo_functable[] = { - { "listall", "List all GPO's on a DC\n", net_gpo_list_all, net_gpo_list_all_usage }, - { "list", "List all active GPO's for a machine/user\n", net_gpo_list, net_gpo_list_usage }, - { "show", "Show information for a GPO\n", net_gpo_get_gpo, net_gpo_get_gpo_usage }, - { "getlink", "List gPLink of container\n", net_gpo_link_get, net_gpo_link_get_usage }, - { "setlink", "Link a GPO to a container\n", net_gpo_link_set, net_gpo_link_set_usage }, - { "dellink", "Delete GPO link from a container\n", net_gpo_link_del, net_gpo_link_del_usage }, - { "getinheritance", "Get inheritance flag from a container\n", net_gpo_inheritance_get, net_gpo_inheritance_get_usage }, - { "setinheritance", "Set inheritance flag on a container\n", net_gpo_inheritance_set, net_gpo_inheritance_set_usage }, - { "fetch", "Download a GPO\n", net_gpo_fetch, net_gpo_fetch_usage }, - { "create", "Create a GPO\n", net_gpo_create, net_gpo_create_usage }, - { "setacl", "Set ACL on a GPO\n", net_gpo_set_acl, net_gpo_set_acl_usage }, - { NULL, NULL } -}; - -int net_gpo_usage(struct net_context *ctx, int argc, const char **argv) -{ - d_printf("Syntax: samba-tool gpo <command> [options]\n"); - d_printf("For available commands, please type samba-tool gpo help\n"); - return 0; -} - -int net_gpo(struct net_context *ctx, int argc, const char **argv) -{ - return net_run_function(ctx, argc, argv, net_gpo_functable, net_gpo_usage); -} diff --git a/source4/samba_tool/samba_tool.c b/source4/samba_tool/samba_tool.c deleted file mode 100644 index 07c9f396dc..0000000000 --- a/source4/samba_tool/samba_tool.c +++ /dev/null @@ -1,385 +0,0 @@ -/* - Samba Unix/Linux SMB client library - Distributed SMB/CIFS Server Management Utility - Copyright (C) 2001 Steve French (sfrench@us.ibm.com) - Copyright (C) 2001 Jim McDonough (jmcd@us.ibm.com) - Copyright (C) 2001 Andrew Tridgell (tridge@samba.org) - Copyright (C) 2001 Andrew Bartlett (abartlet@samba.org) - Copyright (C) 2004 Stefan Metzmacher (metze@samba.org) - Copyright (C) 2009 Jelmer Vernooij (jelmer@samba.org) - Copyright (C) 2011 Giampaolo Lauria (lauria2@yahoo.com) - - Largely rewritten by metze in August 2004 - - Originally written by Steve and Jim. Largely rewritten by tridge in - November 2001. - - Reworked again by abartlet in December 2001 - - 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 <http://www.gnu.org/licenses/>. -*/ - -/*****************************************************/ -/* */ -/* Distributed SMB/CIFS Server Management Utility */ -/* */ -/* The intent was to make the syntax similar */ -/* to the NET utility (first developed in DOS */ -/* with additional interesting & useful functions */ -/* added in later SMB server network operating */ -/* systems). */ -/* */ -/*****************************************************/ - -#include <Python.h> -#include "includes.h" -#include "samba_tool/samba_tool.h" -#include "lib/cmdline/popt_common.h" -#include <ldb.h> -#include "librpc/rpc/dcerpc.h" -#include "param/param.h" -#include "lib/events/events.h" -#include "auth/credentials/credentials.h" -#include "scripting/python/modules.h" - -/* There's no Py_ssize_t in 2.4, apparently */ -#if PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION < 5 -typedef int Py_ssize_t; -#endif - -static PyObject *py_tuple_from_argv(int argc, const char *argv[]) -{ - PyObject *l; - Py_ssize_t i; - - l = PyTuple_New(argc); - if (l == NULL) { - return NULL; - } - - for (i = 0; i < argc; i++) { - PyTuple_SetItem(l, i, PyString_FromString(argv[i])); - } - - return l; -} - -static int py_call_with_string_args(PyObject *self, const char *method, int argc, const char *argv[]) -{ - PyObject *ret, *args, *py_method; - - args = py_tuple_from_argv(argc, argv); - if (args == NULL) { - PyErr_Print(); - return 1; - } - - py_method = PyObject_GetAttrString(self, method); - if (py_method == NULL) { - PyErr_Print(); - return 1; - } - - ret = PyObject_CallObject(py_method, args); - - Py_DECREF(args); - - if (ret == NULL) { - PyErr_Print(); - return 1; - } - - if (ret == Py_None) { - return 0; - } else if (PyInt_Check(ret)) { - return PyInt_AsLong(ret); - } else { - fprintf(stderr, "Function return value type unexpected.\n"); - return -1; - } -} - -static PyObject *py_commands(void) -{ - PyObject *netcmd_module, *py_cmds; - netcmd_module = PyImport_ImportModule("samba.netcmd"); - if (netcmd_module == NULL) { - PyErr_Print(); - return NULL; - } - - py_cmds = PyObject_GetAttrString(netcmd_module, "commands"); - if (py_cmds == NULL) { - PyErr_Print(); - return NULL; - } - - if (!PyDict_Check(py_cmds)) { - d_printf("Python net commands is not a dictionary\n"); - return NULL; - } - - return py_cmds; -} - -/* - run a function from a function table. If not found then - call the specified usage function -*/ -int net_run_function(struct net_context *ctx, - int argc, const char **argv, - const struct net_functable *functable, - int (*usage_fn)(struct net_context *ctx, int argc, const char **argv)) -{ - int i; - - if (argc == 0) { - return usage_fn(ctx, argc, argv); - - } else if (argc == 1 && strequal(argv[0], "help")) { - return net_help(ctx, functable); - } - - for (i=0; functable[i].name; i++) { - if (strcasecmp_m(argv[0], functable[i].name) == 0) - return functable[i].fn(ctx, argc-1, argv+1); - } - - d_printf("No command: '%s'\n", argv[0]); - return usage_fn(ctx, argc, argv); -} - -/* - run a usage function from a function table. If not found then fail -*/ -int net_run_usage(struct net_context *ctx, - int argc, const char **argv, - const struct net_functable *functable) -{ - int i; - PyObject *py_cmds, *py_cmd; - - for (i=0; functable[i].name; i++) { - if (strcasecmp_m(argv[0], functable[i].name) == 0) - if (functable[i].usage) { - return functable[i].usage(ctx, argc-1, argv+1); - } - } - - py_cmds = py_commands(); - if (py_cmds == NULL) { - return 1; - } - - py_cmd = PyDict_GetItemString(py_cmds, argv[0]); - if (py_cmd != NULL) { - return py_call_with_string_args(py_cmd, "usage", argc-1, - argv+1); - } - - d_printf("No usage information for command: %s\n", argv[0]); - - return 1; -} - - -/* main function table */ -static const struct net_functable net_functable[] = { - {"samdump", "dump the sam of a domain\n", net_samdump, net_samdump_usage}, - {"samsync", "synchronise into the local ldb the sam of an NT4 domain\n", net_samsync_ldb, net_samsync_ldb_usage}, - {"gpo", "Administer group policies\n", net_gpo, net_gpo_usage}, - {NULL, NULL, NULL, NULL} -}; - -static int net_help_builtin(const struct net_functable *ftable) -{ - int i = 0; - const char *name = ftable[i].name; - const char *desc = ftable[i].desc; - - while (name && desc) { - if (strlen(name) > 7) { - d_printf("\t%s\t%s", name, desc); - } else { - d_printf("\t%s\t\t%s", name, desc); - } - name = ftable[++i].name; - desc = ftable[i].desc; - } - return 0; -} - -static int net_help_python(void) -{ - PyObject *py_cmds; - PyObject *key, *value; - Py_ssize_t pos = 0; - - py_cmds = py_commands(); - if (py_cmds == NULL) { - return 1; - } - - while (PyDict_Next(py_cmds, &pos, &key, &value)) { - char *name, *desc; - PyObject *py_desc; - if (!PyString_Check(key)) { - d_printf("Command name not a string\n"); - return 1; - } - name = PyString_AsString(key); - py_desc = PyObject_GetAttrString(value, "description"); - if (py_desc == NULL) { - PyErr_Print(); - return 1; - } - if (!PyString_Check(py_desc)) { - d_printf("Command description for %s not a string\n", - name); - return 1; - } - desc = PyString_AsString(py_desc); - if (strlen(name) > 7) { - d_printf("\t%s\t%s\n", name, desc); - } else { - d_printf("\t%s\t\t%s\n", name, desc); - } - } - return 0; -} - -int net_help(struct net_context *ctx, const struct net_functable *ftable) -{ - d_printf("Available commands:\n"); - net_help_builtin(ftable); - /* net_help_python(); */ - return 0; -} - -static int net_usage(struct net_context *ctx, int argc, const char **argv) -{ - d_printf("Usage:\n"); - d_printf("samba-tool <command> [options]\n"); - net_help(ctx, net_functable); - return -1; -} - -/**************************************************************************** - main program -****************************************************************************/ -static int binary_net(int argc, const char **argv) -{ - int opt,i; - int rc; - int argc_new; - PyObject *py_cmds, *py_cmd; - const char **argv_new; - struct tevent_context *ev; - struct net_context *ctx = NULL; - poptContext pc; - struct poptOption long_options[] = { - POPT_AUTOHELP - POPT_COMMON_SAMBA - POPT_COMMON_CONNECTION - POPT_COMMON_CREDENTIALS - POPT_COMMON_VERSION - { NULL } - }; - - setlinebuf(stdout); - - dcerpc_init(); - - ev = s4_event_context_init(NULL); - if (!ev) { - d_printf("Failed to create an event context\n"); - exit(1); - } - Py_Initialize(); - PySys_SetArgv(argc, discard_const_p(char *, argv)); - py_update_path(); /* Put the Samba path at the start of sys.path */ - - py_cmds = py_commands(); - if (py_cmds == NULL) { - return 1; - } - - for (i=1; i<argc; i++) { - if (argv[i][0] != '-') { - py_cmd = PyDict_GetItemString(py_cmds, argv[i]); - if (py_cmd != NULL) { - rc = py_call_with_string_args(py_cmd, "_run", - argc-1, argv+1); - talloc_free(ev); - return rc; - } - } - } - - pc = poptGetContext("net", argc, (const char **) argv, long_options, - POPT_CONTEXT_KEEP_FIRST); - - while((opt = poptGetNextOpt(pc)) != -1) { - switch (opt) { - default: - d_printf("Invalid option %s: %s\n", - poptBadOption(pc, 0), poptStrerror(opt)); - net_usage(ctx, argc, argv); - exit(1); - } - } - - argv_new = (const char **)poptGetArgs(pc); - - argc_new = argc; - for (i=0; i<argc; i++) { - if (argv_new[i] == NULL) { - argc_new = i; - break; - } - } - - if (argc_new < 2) { - return net_usage(ctx, argc, argv); - } - - - ctx = talloc(ev, struct net_context); - if (!ctx) { - d_printf("Failed to talloc a net_context\n"); - exit(1); - } - - ZERO_STRUCTP(ctx); - ctx->lp_ctx = cmdline_lp_ctx; - ctx->credentials = cmdline_credentials; - ctx->event_ctx = ev; - - - - rc = net_run_function(ctx, argc_new-1, argv_new+1, net_functable, - net_usage); - - if (rc != 0) { - DEBUG(0,("return code = %d\n", rc)); - } - - talloc_free(ev); - return rc; -} - - int main(int argc, const char **argv) -{ - return binary_net(argc, argv); -} diff --git a/source4/samba_tool/samba_tool.h b/source4/samba_tool/samba_tool.h deleted file mode 100644 index c8492e613b..0000000000 --- a/source4/samba_tool/samba_tool.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - Samba Unix/Linux SMB client library - Distributed SMB/CIFS Server Management Utility - - Copyright (C) Stefan Metzmacher 2004 - - 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 <http://www.gnu.org/licenses/>. -*/ - -#ifndef _SAMBA_TOOL_H -#define _SAMBA_TOOL_H - -struct net_context { - struct cli_credentials *credentials; - struct loadparm_context *lp_ctx; - struct tevent_context *event_ctx; -}; - -struct net_functable { - const char *name; - const char *desc; - int (*fn)(struct net_context *ctx, int argc, const char **argv); - int (*usage)(struct net_context *ctx, int argc, const char **argv); -}; - -#include "samba_tool/proto.h" - -#endif /* _SAMBA_TOOL_H */ diff --git a/source4/samba_tool/vampire.c b/source4/samba_tool/vampire.c deleted file mode 100644 index 7f16c82668..0000000000 --- a/source4/samba_tool/vampire.c +++ /dev/null @@ -1,130 +0,0 @@ -/* - Samba Unix/Linux SMB client library - Distributed SMB/CIFS Server Management Utility - - Copyright (C) 2004 Stefan Metzmacher <metze@samba.org> - Copyright (C) 2005 Andrew Bartlett <abartlet@samba.org> - - 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 <http://www.gnu.org/licenses/>. -*/ - -#include "includes.h" -#include "samba_tool/samba_tool.h" -#include "libnet/libnet.h" -#include "librpc/gen_ndr/samr.h" -#include "auth/auth.h" -#include "libcli/security/security.h" -#include "param/param.h" -#include "lib/events/events.h" - -/* main function table */ -static const struct net_functable net_samdump_functable[] = { - {NULL, NULL, NULL, NULL} -}; - -int net_samdump(struct net_context *ctx, int argc, const char **argv) -{ - NTSTATUS status; - struct libnet_context *libnetctx; - struct libnet_SamDump r; - int rc; - - switch (argc) { - case 0: - break; - case 1: - default: - rc = net_run_function(ctx, argc, argv, net_samdump_functable, - net_samdump_usage); - return rc; - } - - libnetctx = libnet_context_init(ctx->event_ctx, ctx->lp_ctx); - if (!libnetctx) { - return -1; - } - libnetctx->cred = ctx->credentials; - - r.out.error_string = NULL; - r.in.machine_account = NULL; - r.in.binding_string = NULL; - - status = libnet_SamDump(libnetctx, ctx, &r); - if (!NT_STATUS_IS_OK(status)) { - DEBUG(0,("libnet_SamDump returned %s: %s\n", - nt_errstr(status), - r.out.error_string)); - return -1; - } - - talloc_free(libnetctx); - - return 0; -} - -int net_samdump_usage(struct net_context *ctx, int argc, const char **argv) -{ - d_printf("samba-tool samdump\n"); - return 0; -} - -int net_samdump_help(struct net_context *ctx, int argc, const char **argv) -{ - d_printf("Dumps the sam of the domain we are joined to.\n"); - return 0; -} - -int net_samsync_ldb(struct net_context *ctx, int argc, const char **argv) -{ - NTSTATUS status; - struct libnet_context *libnetctx; - struct libnet_samsync_ldb r; - - libnetctx = libnet_context_init(ctx->event_ctx, ctx->lp_ctx); - if (!libnetctx) { - return -1; - } - libnetctx->cred = ctx->credentials; - - r.out.error_string = NULL; - r.in.machine_account = NULL; - r.in.binding_string = NULL; - - /* Needed to override the ACLs on ldb */ - r.in.session_info = system_session(ctx->lp_ctx); - - status = libnet_samsync_ldb(libnetctx, libnetctx, &r); - if (!NT_STATUS_IS_OK(status)) { - DEBUG(0,("libnet_samsync_ldb returned %s: %s\n", - nt_errstr(status), - r.out.error_string)); - return -1; - } - - talloc_free(libnetctx); - - return 0; -} - -int net_samsync_ldb_usage(struct net_context *ctx, int argc, const char **argv) -{ - d_printf("samba-tool samsync\n"); - return 0; -} - -int net_samsync_ldb_help(struct net_context *ctx, int argc, const char **argv) -{ - d_printf("Synchronise into the local ldb the SAM of a domain.\n"); - return 0; -} diff --git a/source4/samba_tool/wscript_build b/source4/samba_tool/wscript_build deleted file mode 100644 index 4092b53de3..0000000000 --- a/source4/samba_tool/wscript_build +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/env python - -bld.SAMBA_BINARY('samba-tool-c', - source='samba_tool.c vampire.c gpo.c', - autoproto='proto.h', - deps='samba-hostconfig samba-util samba-net popt POPT_SAMBA POPT_CREDENTIALS samba-policy auth4', - pyembed=True, - install=False - ) |