summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source4/utils/net/config.mk3
-rw-r--r--source4/utils/net/net.c84
-rw-r--r--source4/utils/net/net.h8
-rw-r--r--source4/utils/net/net_password.c100
4 files changed, 172 insertions, 23 deletions
diff --git a/source4/utils/net/config.mk b/source4/utils/net/config.mk
index 8593aaec65..ce90906fe6 100644
--- a/source4/utils/net/config.mk
+++ b/source4/utils/net/config.mk
@@ -4,7 +4,8 @@
# Start BINARY net
[BINARY::net]
OBJ_FILES = \
- utils/net/net.o
+ utils/net/net.o \
+ utils/net/net_password.o
REQUIRED_SUBSYSTEMS = \
CONFIG \
LIBCMDLINE \
diff --git a/source4/utils/net/net.c b/source4/utils/net/net.c
index a636e4cdaa..f1bb4cef4c 100644
--- a/source4/utils/net/net.c
+++ b/source4/utils/net/net.c
@@ -50,64 +50,99 @@
int net_run_function(struct net_context *ctx,
int argc, const char **argv,
const struct net_functable *functable,
- int (*help_fn)(struct net_context *ctx, int argc, const char **argv))
+ int (*usage_fn)(struct net_context *ctx, int argc, const char **argv))
{
int i;
-
+
if (argc < 1) {
d_printf("Usage: \n");
- return help_fn(ctx, argc, argv);
+ return usage_fn(ctx, argc, argv);
}
+
for (i=0; functable[i].name; i++) {
if (StrCaseCmp(argv[0], functable[i].name) == 0)
return functable[i].fn(ctx, argc-1, argv+1);
}
+
d_printf("No command: %s\n", argv[0]);
- return help_fn(ctx, argc, argv);
+ return usage_fn(ctx, argc, argv);
}
/*
- run a help function from a function table. If not found then fail
+ 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;
+
+ if (argc < 1) {
+ d_printf("net_run_usage: TODO (argc < 1)\n");
+ return 1;
+ }
+
+ for (i=0; functable[i].name; i++) {
+ if (StrCaseCmp(argv[0], functable[i].name) == 0)
+ if (functable[i].usage) {
+ return functable[i].usage(ctx, argc-1, argv+1);
+ }
+ }
+
+ d_printf("No usage for command: %s\n", argv[0]);
+
+ return 1;
+}
+
+/*
+ run a usage function from a function table. If not found then fail
*/
int net_run_help(struct net_context *ctx,
int argc, const char **argv,
const struct net_functable *functable)
{
int i;
-
+
if (argc < 1) {
d_printf("net_run_help: TODO (argc < 1)\n");
return 1;
}
+
for (i=0; functable[i].name; i++) {
if (StrCaseCmp(argv[0], functable[i].name) == 0)
if (functable[i].help) {
return functable[i].help(ctx, argc-1, argv+1);
}
}
+
d_printf("No help for command: %s\n", argv[0]);
+
return 1;
}
-static int net_help_msg(struct net_context *ctx, int argc, const char **argv)
+static int net_help(struct net_context *ctx, int argc, const char **argv)
{
- d_printf("Help: TODO\n");
- return 0;
+ d_printf("net_help: TODO\n");
+ return 0;
}
-static int net_help(struct net_context *ctx, int argc, const char **argv);
+static int net_help_usage(struct net_context *ctx, int argc, const char **argv)
+{
+ d_printf("net_help_usage: TODO\n");
+ return 0;
+}
/* main function table */
-static const struct net_functable net_functable[] = {
-/* {"password", net_password, net_password_help},*/
+static const struct net_functable const net_functable[] = {
+ {"password", net_password, net_password_usage, net_password_help},
- {"help", net_help_msg, net_help_msg},
+ {"help", net_help, net_help_usage, net_help},
{NULL, NULL}
};
-static int net_help(struct net_context *ctx, int argc, const char **argv)
+static int net_usage(struct net_context *ctx, int argc, const char **argv)
{
- return net_run_help(ctx, argc, argv, net_functable);
+ return net_run_usage(ctx, argc, argv, net_functable);
}
/****************************************************************************
@@ -119,7 +154,8 @@ static int binary_net(int argc, const char **argv)
int rc;
int argc_new;
const char **argv_new;
- struct net_context ctx;
+ TALLOC_CTX *mem_ctx;
+ struct net_context *ctx;
poptContext pc;
setup_logging("net", DEBUG_STDOUT);
@@ -128,12 +164,16 @@ static int binary_net(int argc, const char **argv)
setbuffer(stdout, NULL, 0);
#endif
- ctx.mem_ctx = talloc_init("net_context");
- if (!ctx.mem_ctx) {
+ mem_ctx = talloc_init("net_context");
+ ctx = talloc_p(mem_ctx, struct net_context);
+ if (!ctx) {
d_printf("talloc_init(net_context) failed\n");
exit(1);
}
+ ZERO_STRUCTP(ctx);
+ ctx->mem_ctx = mem_ctx;
+
struct poptOption long_options[] = {
{"help", 'h', POPT_ARG_NONE, 0, 'h'},
{NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_version},
@@ -146,13 +186,13 @@ static int binary_net(int argc, const char **argv)
while((opt = poptGetNextOpt(pc)) != -1) {
switch (opt) {
case 'h':
- net_help(&ctx, argc, argv);
+ net_help(ctx, argc, argv);
exit(0);
break;
default:
d_printf("Invalid option %s: %s\n",
poptBadOption(pc, 0), poptStrerror(opt));
- net_help(&ctx, argc, argv);
+ net_help(ctx, argc, argv);
exit(1);
}
}
@@ -175,11 +215,13 @@ static int binary_net(int argc, const char **argv)
return 1;
}
- rc = net_run_function(&ctx, argc_new-1, argv_new+1, net_functable, net_help_msg);
+ 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_destroy(mem_ctx);
return rc;
}
diff --git a/source4/utils/net/net.h b/source4/utils/net/net.h
index f1ed93fbfb..ba8294c144 100644
--- a/source4/utils/net/net.h
+++ b/source4/utils/net/net.h
@@ -24,12 +24,18 @@
struct net_context {
TALLOC_CTX *mem_ctx;
+ struct {
+ const char *account_name;
+ const char *domain_name;
+ const char *password;
+ } user;
};
struct net_functable {
const char *name;
int (*fn)(struct net_context *ctx, int argc, const char **argv);
- int (*help)(struct net_context *ctx, int argc, const char **argv);
+ int (*usage)(struct net_context *ctx, int argc, const char **argv);
+ int (*help)(struct net_context *ctx, int argc, const char **argv);
};
#endif /* _UTIL_NET_H */
diff --git a/source4/utils/net/net_password.c b/source4/utils/net/net_password.c
new file mode 100644
index 0000000000..90f26924a6
--- /dev/null
+++ b/source4/utils/net/net_password.c
@@ -0,0 +1,100 @@
+/*
+ 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 2 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, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#include "includes.h"
+
+/*
+ * Code for Changing and setting a password
+ */
+
+
+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->mem_ctx, "Enter new password for %s:", ctx->user.account_name);
+ new_password = getpass(password_prompt);
+ }
+
+ libnetctx = libnet_context_init();
+ if (!libnetctx) {
+ return -1;
+ }
+
+ /* prepare password change */
+ r.generic.level = LIBNET_CHANGE_PASSWORD_GENERIC;
+ r.generic.in.account_name = ctx->user.account_name;
+ r.generic.in.domain_name = ctx->user.domain_name;
+ r.generic.in.oldpassword = ctx->user.password;
+ r.generic.in.newpassword = new_password;
+
+ /* do password change */
+ status = libnet_ChangePassword(libnetctx, ctx->mem_ctx, &r);
+ if (!NT_STATUS_IS_OK(status)) {
+ DEBUG(0,("net_password_change: %s\n",r.generic.out.error_string));
+ return -1;
+ }
+
+ libnet_context_destroy(&libnetctx);
+
+ return 0;
+}
+
+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_help(struct net_context *ctx, int argc, const char **argv)
+{
+ d_printf("net_password_change_help: TODO\n");
+ return 0;
+}
+
+static const struct net_functable const net_password_functable[] = {
+ {"change", net_password_change, net_password_change_usage, net_password_change_help},
+ {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_usage: TODO\n");
+ return 0;
+}
+
+int net_password_help(struct net_context *ctx, int argc, const char **argv)
+{
+ d_printf("net_password_help: TODO\n");
+ return 0;
+}