summaryrefslogtreecommitdiff
path: root/source4/utils/net
diff options
context:
space:
mode:
Diffstat (limited to 'source4/utils/net')
-rw-r--r--source4/utils/net/config.mk26
-rw-r--r--source4/utils/net/net.c217
-rw-r--r--source4/utils/net/net.h39
-rw-r--r--source4/utils/net/net_join.c170
-rw-r--r--source4/utils/net/net_password.c171
-rw-r--r--source4/utils/net/net_time.c78
-rw-r--r--source4/utils/net/net_user.c125
-rw-r--r--source4/utils/net/net_vampire.c181
8 files changed, 1007 insertions, 0 deletions
diff --git a/source4/utils/net/config.mk b/source4/utils/net/config.mk
new file mode 100644
index 0000000000..93b51e1e28
--- /dev/null
+++ b/source4/utils/net/config.mk
@@ -0,0 +1,26 @@
+# $(utilssrcdir)/net subsystem
+
+#################################
+# Start BINARY net
+[BINARY::net]
+INSTALLDIR = BINDIR
+PRIVATE_DEPENDENCIES = \
+ LIBSAMBA-HOSTCONFIG \
+ LIBSAMBA-UTIL \
+ LIBSAMBA-NET \
+ LIBPOPT \
+ POPT_SAMBA \
+ POPT_CREDENTIALS
+# End BINARY net
+#################################
+
+net_OBJ_FILES = $(addprefix $(utilssrcdir)/net/, \
+ net.o \
+ net_password.o \
+ net_time.o \
+ net_join.o \
+ net_vampire.o \
+ net_user.o)
+
+
+$(eval $(call proto_header_template,$(utilssrcdir)/net/net_proto.h,$(net_OBJ_FILES:.o=.c)))
diff --git a/source4/utils/net/net.c b/source4/utils/net/net.c
new file mode 100644
index 0000000000..1c834fe4f0
--- /dev/null
+++ b/source4/utils/net/net.c
@@ -0,0 +1,217 @@
+/*
+ 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)
+
+ 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 "includes.h"
+#include "utils/net/net.h"
+#include "lib/cmdline/popt_common.h"
+#include "lib/ldb/include/ldb.h"
+#include "librpc/rpc/dcerpc.h"
+#include "param/param.h"
+#include "lib/events/events.h"
+#include "auth/credentials/credentials.h"
+
+/*
+ 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;
+
+ 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);
+ }
+ }
+
+ d_printf("No usage information for command: %s\n", argv[0]);
+
+ return 1;
+}
+
+
+/* main function table */
+static const struct net_functable net_functable[] = {
+ {"password", "change password\n", net_password, net_password_usage},
+ {"time", "get remote server's time\n", net_time, net_time_usage},
+ {"join", "join a domain\n", net_join, net_join_usage},
+ {"samdump", "dump the sam of a domain\n", net_samdump, net_samdump_usage},
+ {"vampire", "join and syncronise an AD domain onto the local server\n", net_vampire, net_vampire_usage},
+ {"samsync", "synchronise into the local ldb the sam of an NT4 domain\n", net_samsync_ldb, net_samsync_ldb_usage},
+ {"user", "manage user accounts\n", net_user, net_user_usage},
+ {NULL, NULL, NULL, NULL}
+};
+
+int net_help(struct net_context *ctx, const struct net_functable *ftable)
+{
+ int i = 0;
+ const char *name = ftable[i].name;
+ const char *desc = ftable[i].desc;
+
+ d_printf("Available commands:\n");
+ while (name && desc) {
+ d_printf("\t%s\t\t%s", name, desc);
+ name = ftable[++i].name;
+ desc = ftable[i].desc;
+ }
+
+ return 0;
+}
+
+static int net_usage(struct net_context *ctx, int argc, const char **argv)
+{
+ d_printf("Usage:\n");
+ d_printf("net <command> [options]\n");
+ return 0;
+}
+
+/****************************************************************************
+ main program
+****************************************************************************/
+static int binary_net(int argc, const char **argv)
+{
+ int opt,i;
+ int rc;
+ int argc_new;
+ const char **argv_new;
+ struct event_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);
+
+ 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);
+ }
+
+ dcerpc_init();
+
+ ev = s4_event_context_init(NULL);
+ if (!ev) {
+ d_printf("Failed to create an event context\n");
+ exit(1);
+ }
+ 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/utils/net/net.h b/source4/utils/net/net.h
new file mode 100644
index 0000000000..309bee277c
--- /dev/null
+++ b/source4/utils/net/net.h
@@ -0,0 +1,39 @@
+/*
+ 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 _UTIL_NET_H
+#define _UTIL_NET_H
+
+struct net_context {
+ struct cli_credentials *credentials;
+ struct loadparm_context *lp_ctx;
+ struct event_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 "utils/net/net_proto.h"
+
+#endif /* _UTIL_NET_H */
diff --git a/source4/utils/net/net_join.c b/source4/utils/net/net_join.c
new file mode 100644
index 0000000000..ad63340089
--- /dev/null
+++ b/source4/utils/net/net_join.c
@@ -0,0 +1,170 @@
+/*
+ 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 "utils/net/net.h"
+#include "libnet/libnet.h"
+#include "libcli/security/security.h"
+#include "param/param.h"
+#include "lib/events/events.h"
+
+int net_join(struct net_context *ctx, int argc, const char **argv)
+{
+ NTSTATUS status;
+ struct libnet_context *libnetctx;
+ struct libnet_Join *r;
+ char *tmp;
+ const char *domain_name;
+ enum netr_SchannelType secure_channel_type = SEC_CHAN_WKSTA;
+
+ switch (argc) {
+ case 0: /* no args -> fail */
+ return net_join_usage(ctx, argc, argv);
+ case 1: /* only DOMAIN */
+ tmp = talloc_strdup(ctx, argv[0]);
+ break;
+ case 2: /* DOMAIN and role */
+ tmp = talloc_strdup(ctx, argv[0]);
+ if (strcasecmp(argv[1], "BDC") == 0) {
+ secure_channel_type = SEC_CHAN_BDC;
+ } else if (strcasecmp(argv[1], "MEMBER") == 0) {
+ secure_channel_type = SEC_CHAN_WKSTA;
+ } else {
+ d_fprintf(stderr, "net_join: Invalid 2nd argument (%s) must be MEMBER or BDC\n", argv[1]);
+ return net_join_usage(ctx, argc, argv);
+ }
+ break;
+ default: /* too many args -> fail */
+ return net_join_usage(ctx, argc, argv);
+ }
+
+ domain_name = tmp;
+
+ libnetctx = libnet_context_init(ctx->event_ctx, ctx->lp_ctx);
+ if (!libnetctx) {
+ return -1;
+ }
+ libnetctx->cred = ctx->credentials;
+ r = talloc(ctx, struct libnet_Join);
+ if (!r) {
+ return -1;
+ }
+ /* prepare parameters for the join */
+ r->in.netbios_name = lp_netbios_name(ctx->lp_ctx);
+ r->in.domain_name = domain_name;
+ r->in.join_type = secure_channel_type;
+ r->in.level = LIBNET_JOIN_AUTOMATIC;
+ r->out.error_string = NULL;
+
+ /* do the domain join */
+ status = libnet_Join(libnetctx, r, r);
+
+ if (!NT_STATUS_IS_OK(status)) {
+ d_fprintf(stderr, "Joining domain failed: %s\n",
+ r->out.error_string ? r->out.error_string : nt_errstr(status));
+ talloc_free(r);
+ talloc_free(libnetctx);
+ return -1;
+ }
+ d_printf("Joined domain %s (%s)\n", r->out.domain_name, dom_sid_string(ctx, r->out.domain_sid));
+
+ talloc_free(libnetctx);
+ return 0;
+}
+
+int net_join_usage(struct net_context *ctx, int argc, const char **argv)
+{
+ d_printf("net join <domain> [BDC | MEMBER] [options]\n");
+ return 0;
+}
+
+int net_join_help(struct net_context *ctx, int argc, const char **argv)
+{
+ d_printf("Joins domain as either member or backup domain controller.\n");
+ return 0;
+}
+
+int net_vampire(struct net_context *ctx, int argc, const char **argv)
+{
+ NTSTATUS status;
+ struct libnet_context *libnetctx;
+ struct libnet_Vampire *r;
+ char *tmp, *targetdir = NULL;
+ const char *domain_name;
+
+ switch (argc) {
+ case 0: /* no args -> fail */
+ return net_vampire_usage(ctx, argc, argv);
+ case 1: /* only DOMAIN */
+ tmp = talloc_strdup(ctx, argv[0]);
+ break;
+ case 2: /* domain and target dir */
+ tmp = talloc_strdup(ctx, argv[0]);
+ targetdir = talloc_strdup(ctx, argv[1]);
+ break;
+ default: /* too many args -> fail */
+ return net_vampire_usage(ctx, argc, argv);
+ }
+
+ domain_name = tmp;
+
+ libnetctx = libnet_context_init(NULL, ctx->lp_ctx);
+ if (!libnetctx) {
+ return -1;
+ }
+ libnetctx->cred = ctx->credentials;
+ r = talloc(ctx, struct libnet_Vampire);
+ if (!r) {
+ return -1;
+ }
+ /* prepare parameters for the vampire */
+ r->in.netbios_name = lp_netbios_name(ctx->lp_ctx);
+ r->in.domain_name = domain_name;
+ r->in.targetdir = targetdir;
+ r->out.error_string = NULL;
+
+ /* do the domain vampire */
+ status = libnet_Vampire(libnetctx, r, r);
+
+ if (!NT_STATUS_IS_OK(status)) {
+ d_fprintf(stderr, "Vampire of domain failed: %s\n",
+ r->out.error_string ? r->out.error_string : nt_errstr(status));
+ talloc_free(r);
+ talloc_free(libnetctx);
+ return -1;
+ }
+ d_printf("Vampired domain %s (%s)\n", r->out.domain_name, dom_sid_string(ctx, r->out.domain_sid));
+
+ talloc_free(libnetctx);
+ return 0;
+}
+
+int net_vampire_usage(struct net_context *ctx, int argc, const char **argv)
+{
+ d_printf("net vampire <domain> [options]\n");
+ return 0;
+}
+
+int net_vampire_help(struct net_context *ctx, int argc, const char **argv)
+{
+ d_printf("Vampires domain as either member or backup domain controller.\n");
+ return 0;
+}
diff --git a/source4/utils/net/net_password.c b/source4/utils/net/net_password.c
new file mode 100644
index 0000000000..55f7c3c31d
--- /dev/null
+++ b/source4/utils/net/net_password.c
@@ -0,0 +1,171 @@
+/*
+ Samba Unix/Linux SMB client library
+ Distributed SMB/CIFS Server Management Utility
+
+ Copyright (C) 2004 Stefan Metzmacher (metze@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 "utils/net/net.h"
+#include "libnet/libnet.h"
+#include "system/filesys.h"
+#include "lib/events/events.h"
+#include "auth/credentials/credentials.h"
+
+/*
+ * Code for Changing and setting a password
+ */
+
+static int net_password_change_usage(struct net_context *ctx, int argc, const char **argv)
+{
+ d_printf("net_password_change_usage: TODO\n");
+ return 0;
+}
+
+
+static int net_password_change(struct net_context *ctx, int argc, const char **argv)
+{
+ NTSTATUS status;
+ struct libnet_context *libnetctx;
+ union libnet_ChangePassword r;
+ char *password_prompt = NULL;
+ const char *new_password;
+
+ if (argc > 0 && argv[0]) {
+ new_password = argv[0];
+ } else {
+ password_prompt = talloc_asprintf(ctx, "Enter new password for account [%s\\%s]:",
+ cli_credentials_get_domain(ctx->credentials),
+ cli_credentials_get_username(ctx->credentials));
+ new_password = getpass(password_prompt);
+ }
+
+ libnetctx = libnet_context_init(ctx->event_ctx, ctx->lp_ctx);
+ if (!libnetctx) {
+ return -1;
+ }
+ libnetctx->cred = ctx->credentials;
+
+ /* prepare password change */
+ r.generic.level = LIBNET_CHANGE_PASSWORD_GENERIC;
+ r.generic.in.account_name = cli_credentials_get_username(ctx->credentials);
+ r.generic.in.domain_name = cli_credentials_get_domain(ctx->credentials);
+ r.generic.in.oldpassword = cli_credentials_get_password(ctx->credentials);
+ r.generic.in.newpassword = new_password;
+
+ /* do password change */
+ status = libnet_ChangePassword(libnetctx, ctx, &r);
+ if (!NT_STATUS_IS_OK(status)) {
+ DEBUG(0,("net_password_change: %s\n",r.generic.out.error_string));
+ return -1;
+ }
+
+ talloc_free(libnetctx);
+
+ return 0;
+}
+
+
+static int net_password_set_usage(struct net_context *ctx, int argc, const char **argv)
+{
+ d_printf("net_password_set_usage: TODO\n");
+ return 0;
+}
+
+
+static int net_password_set(struct net_context *ctx, int argc, const char **argv)
+{
+ NTSTATUS status;
+ struct libnet_context *libnetctx;
+ union libnet_SetPassword r;
+ char *password_prompt = NULL;
+ char *p;
+ char *tmp;
+ const char *account_name;
+ const char *domain_name;
+ const char *new_password = NULL;
+
+ switch (argc) {
+ case 0: /* no args -> fail */
+ return net_password_set_usage(ctx, argc, argv);
+ case 1: /* only DOM\\user; prompt for password */
+ tmp = talloc_strdup(ctx, argv[0]);
+ break;
+ case 2: /* DOM\\USER and password */
+ tmp = talloc_strdup(ctx, argv[0]);
+ new_password = argv[1];
+ break;
+ default: /* too mayn args -> fail */
+ DEBUG(0,("net_password_set: too many args [%d]\n",argc));
+ return net_password_usage(ctx, argc, argv);
+ }
+
+ if ((p = strchr_m(tmp,'\\'))) {
+ *p = 0;
+ domain_name = tmp;
+ account_name = talloc_strdup(ctx, p+1);
+ } else {
+ account_name = tmp;
+ domain_name = cli_credentials_get_domain(ctx->credentials);
+ }
+
+ if (!new_password) {
+ password_prompt = talloc_asprintf(ctx, "Enter new password for account [%s\\%s]:",
+ domain_name, account_name);
+ new_password = getpass(password_prompt);
+ }
+
+ libnetctx = libnet_context_init(ctx->event_ctx, ctx->lp_ctx);
+ if (!libnetctx) {
+ return -1;
+ }
+ libnetctx->cred = ctx->credentials;
+
+ /* prepare password change */
+ r.generic.level = LIBNET_SET_PASSWORD_GENERIC;
+ r.generic.in.account_name = account_name;
+ r.generic.in.domain_name = domain_name;
+ r.generic.in.newpassword = new_password;
+
+ /* do password change */
+ status = libnet_SetPassword(libnetctx, ctx, &r);
+ if (!NT_STATUS_IS_OK(status)) {
+ DEBUG(0,("net_password_set: %s\n",r.generic.out.error_string));
+ return -1;
+ }
+
+ talloc_free(libnetctx);
+
+ return 0;
+}
+
+
+static const struct net_functable net_password_functable[] = {
+ {"change", "change password (old password required)\n", net_password_change, net_password_change_usage },
+ {"set", "set password\n", net_password_set, net_password_set_usage },
+ {NULL, NULL}
+};
+
+int net_password(struct net_context *ctx, int argc, const char **argv)
+{
+ return net_run_function(ctx, argc, argv, net_password_functable, net_password_usage);
+}
+
+int net_password_usage(struct net_context *ctx, int argc, const char **argv)
+{
+ d_printf("net password <command> [options]\n");
+ return 0;
+}
diff --git a/source4/utils/net/net_time.c b/source4/utils/net/net_time.c
new file mode 100644
index 0000000000..92e6e77481
--- /dev/null
+++ b/source4/utils/net/net_time.c
@@ -0,0 +1,78 @@
+/*
+ Samba Unix/Linux SMB client library
+ Distributed SMB/CIFS Server Management Utility
+
+ Copyright (C) 2004 Stefan Metzmacher (metze@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 "libnet/libnet.h"
+#include "utils/net/net.h"
+#include "system/time.h"
+#include "lib/events/events.h"
+
+/*
+ * Code for getting the remote time
+ */
+
+int net_time(struct net_context *ctx, int argc, const char **argv)
+{
+ NTSTATUS status;
+ struct libnet_context *libnetctx;
+ union libnet_RemoteTOD r;
+ const char *server_name;
+ struct tm *tm;
+ char timestr[64];
+
+ if (argc > 0 && argv[0]) {
+ server_name = argv[0];
+ } else {
+ return net_time_usage(ctx, argc, argv);
+ }
+
+ libnetctx = libnet_context_init(ctx->event_ctx, ctx->lp_ctx);
+ if (!libnetctx) {
+ return -1;
+ }
+ libnetctx->cred = ctx->credentials;
+
+ /* prepare to get the time */
+ r.generic.level = LIBNET_REMOTE_TOD_GENERIC;
+ r.generic.in.server_name = server_name;
+
+ /* get the time */
+ status = libnet_RemoteTOD(libnetctx, ctx, &r);
+ if (!NT_STATUS_IS_OK(status)) {
+ DEBUG(0,("net_time: %s\n",r.generic.out.error_string));
+ return -1;
+ }
+
+ ZERO_STRUCT(timestr);
+ tm = localtime(&r.generic.out.time);
+ strftime(timestr, sizeof(timestr)-1, "%c %Z",tm);
+
+ printf("%s\n",timestr);
+
+ talloc_free(libnetctx);
+
+ return 0;
+}
+
+int net_time_usage(struct net_context *ctx, int argc, const char **argv)
+{
+ d_printf("net time <server> [options]\n");
+ return 0;
+}
diff --git a/source4/utils/net/net_user.c b/source4/utils/net/net_user.c
new file mode 100644
index 0000000000..c4b8ecb0c2
--- /dev/null
+++ b/source4/utils/net/net_user.c
@@ -0,0 +1,125 @@
+/*
+ Samba Unix/Linux SMB client library
+ Distributed SMB/CIFS Server Management Utility
+
+ Copyright (C) Rafal Szczesniak <mimir@samba.org> 2005
+
+ 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 "utils/net/net.h"
+#include "libnet/libnet.h"
+#include "lib/events/events.h"
+#include "auth/credentials/credentials.h"
+
+static int net_user_add(struct net_context *ctx, int argc, const char **argv)
+{
+ NTSTATUS status;
+ struct libnet_context *lnet_ctx;
+ struct libnet_CreateUser r;
+ char *user_name;
+
+ /* command line argument preparation */
+ switch (argc) {
+ case 0:
+ return net_user_usage(ctx, argc, argv);
+ break;
+ case 1:
+ user_name = talloc_strdup(ctx, argv[0]);
+ break;
+ default:
+ return net_user_usage(ctx, argc, argv);
+ }
+
+ /* libnet context init and its params */
+ lnet_ctx = libnet_context_init(ctx->event_ctx, ctx->lp_ctx);
+ if (!lnet_ctx) return -1;
+
+ lnet_ctx->cred = ctx->credentials;
+
+ /* calling CreateUser function */
+ r.in.user_name = user_name;
+ r.in.domain_name = cli_credentials_get_domain(lnet_ctx->cred);
+
+ status = libnet_CreateUser(lnet_ctx, ctx, &r);
+ if (!NT_STATUS_IS_OK(status)) {
+ DEBUG(0, ("Failed to add user account: %s\n",
+ r.out.error_string));
+ return -1;
+ }
+
+ talloc_free(lnet_ctx);
+ return 0;
+}
+
+static int net_user_delete(struct net_context *ctx, int argc, const char **argv)
+{
+ NTSTATUS status;
+ struct libnet_context *lnet_ctx;
+ struct libnet_DeleteUser r;
+ char *user_name;
+
+ /* command line argument preparation */
+ switch (argc) {
+ case 0:
+ return net_user_usage(ctx, argc, argv);
+ break;
+ case 1:
+ user_name = talloc_strdup(ctx, argv[0]);
+ break;
+ default:
+ return net_user_usage(ctx, argc, argv);
+ }
+
+ /* libnet context init and its params */
+ lnet_ctx = libnet_context_init(ctx->event_ctx, ctx->lp_ctx);
+ if (!lnet_ctx) return -1;
+
+ lnet_ctx->cred = ctx->credentials;
+
+ /* calling DeleteUser function */
+ r.in.user_name = user_name;
+ r.in.domain_name = cli_credentials_get_domain(lnet_ctx->cred);
+
+ status = libnet_DeleteUser(lnet_ctx, ctx, &r);
+ if (!NT_STATUS_IS_OK(status)) {
+ DEBUG(0, ("Failed to delete user account: %s\n",
+ r.out.error_string));
+ return -1;
+ }
+
+ talloc_free(lnet_ctx);
+ return 0;
+}
+
+
+static const struct net_functable net_user_functable[] = {
+ { "add", "create new user account\n", net_user_add, net_user_usage },
+ { "delete", "delete an existing user account\n", net_user_delete, net_user_usage },
+ { NULL, NULL }
+};
+
+
+int net_user(struct net_context *ctx, int argc, const char **argv)
+{
+ return net_run_function(ctx, argc, argv, net_user_functable, net_user_usage);
+}
+
+
+int net_user_usage(struct net_context *ctx, int argc, const char **argv)
+{
+ d_printf("net user <command> [options]\n");
+ return 0;
+}
diff --git a/source4/utils/net/net_vampire.c b/source4/utils/net/net_vampire.c
new file mode 100644
index 0000000000..14f6a07e4b
--- /dev/null
+++ b/source4/utils/net/net_vampire.c
@@ -0,0 +1,181 @@
+/*
+ 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 "utils/net/net.h"
+#include "libnet/libnet.h"
+#include "librpc/gen_ndr/samr.h"
+#include "auth/auth.h"
+#include "param/param.h"
+#include "lib/events/events.h"
+
+static int net_samdump_keytab_usage(struct net_context *ctx, int argc, const char **argv)
+{
+ d_printf("net samdump keytab <keytab>\n");
+ return 0;
+}
+
+static int net_samdump_keytab_help(struct net_context *ctx, int argc, const char **argv)
+{
+ d_printf("Dumps kerberos keys of a domain into a keytab.\n");
+ return 0;
+}
+
+static int net_samdump_keytab(struct net_context *ctx, int argc, const char **argv)
+{
+ NTSTATUS status;
+ struct libnet_context *libnetctx;
+ struct libnet_SamDump_keytab r;
+
+ switch (argc) {
+ case 0:
+ return net_samdump_keytab_usage(ctx, argc, argv);
+ break;
+ case 1:
+ r.in.keytab_name = argv[0];
+ break;
+ }
+
+ 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_keytab(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;
+}
+
+/* main function table */
+static const struct net_functable net_samdump_functable[] = {
+ {"keytab", "dump keys into a keytab\n", net_samdump_keytab, net_samdump_keytab_usage},
+ {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("net samdump\n");
+ d_printf("net samdump keytab <keytab>\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(libnetctx, 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("net 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;
+}