wmi-1.3.16 from opsview.com
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
# utils/net subsystem
|
||||
|
||||
#################################
|
||||
# Start BINARY net
|
||||
[BINARY::net]
|
||||
INSTALLDIR = BINDIR
|
||||
PRIVATE_PROTO_HEADER = net_proto.h
|
||||
OBJ_FILES = \
|
||||
net.o \
|
||||
net_password.o \
|
||||
net_time.o \
|
||||
net_join.o \
|
||||
net_vampire.o \
|
||||
net_user.o
|
||||
PRIVATE_DEPENDENCIES = \
|
||||
LIBSAMBA-CONFIG \
|
||||
LIBSAMBA-UTIL \
|
||||
LIBSAMBA-NET \
|
||||
LIBPOPT \
|
||||
POPT_SAMBA \
|
||||
POPT_CREDENTIALS
|
||||
# End BINARY net
|
||||
#################################
|
||||
@@ -0,0 +1,211 @@
|
||||
/*
|
||||
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 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.
|
||||
*/
|
||||
|
||||
/*****************************************************/
|
||||
/* */
|
||||
/* 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"
|
||||
|
||||
/*
|
||||
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},
|
||||
{"samsync", "synchronise into the local ldb the sam of a 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;
|
||||
TALLOC_CTX *mem_ctx;
|
||||
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();
|
||||
|
||||
ldb_global_init();
|
||||
|
||||
mem_ctx = talloc_init("net_context");
|
||||
ctx = talloc(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;
|
||||
ctx->credentials = cmdline_credentials;
|
||||
|
||||
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(mem_ctx);
|
||||
return rc;
|
||||
}
|
||||
|
||||
int main(int argc, const char **argv)
|
||||
{
|
||||
return binary_net(argc, argv);
|
||||
}
|
||||
@@ -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 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.
|
||||
*/
|
||||
|
||||
#ifndef _UTIL_NET_H
|
||||
#define _UTIL_NET_H
|
||||
|
||||
struct net_context {
|
||||
TALLOC_CTX *mem_ctx;
|
||||
struct cli_credentials *credentials;
|
||||
};
|
||||
|
||||
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 */
|
||||
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
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 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"
|
||||
#include "utils/net/net.h"
|
||||
#include "libnet/libnet.h"
|
||||
#include "libcli/security/security.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->mem_ctx, argv[0]);
|
||||
break;
|
||||
case 2: /* DOMAIN and role */
|
||||
tmp = talloc_strdup(ctx->mem_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(NULL);
|
||||
if (!libnetctx) {
|
||||
return -1;
|
||||
}
|
||||
libnetctx->cred = ctx->credentials;
|
||||
r = talloc(ctx->mem_ctx, struct libnet_Join);
|
||||
if (!r) {
|
||||
return -1;
|
||||
}
|
||||
/* prepare parameters for the join */
|
||||
r->in.netbios_name = lp_netbios_name();
|
||||
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->mem_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;
|
||||
}
|
||||
@@ -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 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"
|
||||
#include "utils/net/net.h"
|
||||
#include "libnet/libnet.h"
|
||||
#include "system/filesys.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->mem_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(NULL);
|
||||
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->mem_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->mem_ctx, argv[0]);
|
||||
break;
|
||||
case 2: /* DOM\\USER and password */
|
||||
tmp = talloc_strdup(ctx->mem_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->mem_ctx, p+1);
|
||||
} else {
|
||||
account_name = tmp;
|
||||
domain_name = cli_credentials_get_domain(ctx->credentials);
|
||||
}
|
||||
|
||||
if (!new_password) {
|
||||
password_prompt = talloc_asprintf(ctx->mem_ctx, "Enter new password for account [%s\\%s]:",
|
||||
domain_name, account_name);
|
||||
new_password = getpass(password_prompt);
|
||||
}
|
||||
|
||||
libnetctx = libnet_context_init(NULL);
|
||||
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->mem_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;
|
||||
}
|
||||
@@ -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 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"
|
||||
#include "libnet/libnet.h"
|
||||
#include "utils/net/net.h"
|
||||
#include "system/time.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(NULL);
|
||||
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->mem_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;
|
||||
}
|
||||
@@ -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 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"
|
||||
#include "utils/net/net.h"
|
||||
#include "libnet/libnet.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->mem_ctx, argv[0]);
|
||||
break;
|
||||
default:
|
||||
return net_user_usage(ctx, argc, argv);
|
||||
}
|
||||
|
||||
/* libnet context init and its params */
|
||||
lnet_ctx = libnet_context_init(NULL);
|
||||
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->mem_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->mem_ctx, argv[0]);
|
||||
break;
|
||||
default:
|
||||
return net_user_usage(ctx, argc, argv);
|
||||
}
|
||||
|
||||
/* libnet context init and its params */
|
||||
lnet_ctx = libnet_context_init(NULL);
|
||||
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->mem_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;
|
||||
}
|
||||
@@ -0,0 +1,180 @@
|
||||
/*
|
||||
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 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"
|
||||
#include "utils/net/net.h"
|
||||
#include "libnet/libnet.h"
|
||||
#include "librpc/gen_ndr/samr.h"
|
||||
#include "auth/auth.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(NULL);
|
||||
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->mem_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(NULL);
|
||||
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->mem_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(NULL);
|
||||
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);
|
||||
|
||||
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_ldb\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;
|
||||
}
|
||||
Reference in New Issue
Block a user