[SCM] Samba Shared Repository - branch master updated -
release-4-0-0alpha6-460-g0126dba
Günther Deschner
gd at samba.org
Wed Feb 4 18:03:11 GMT 2009
The branch, master has been updated
via 0126dba7efb6d8fea2565f21cffa1e85569da81e (commit)
via c0cf20a49e34eec76422e79d463eb780c5c53e96 (commit)
via 21d23bf7e893aa8afc128af419135f4d37b080f9 (commit)
from 65200328eea3ab2179796ecf88a7ef276f8e2c9c (commit)
http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master
- Log -----------------------------------------------------------------
commit 0126dba7efb6d8fea2565f21cffa1e85569da81e
Author: Günther Deschner <gd at samba.org>
Date: Thu Jan 29 15:33:20 2009 +0100
s3-net: add "net eventlog export".
This allows to export our tdb eventlog representation into a native
win32 *.evt eventlog file.
Guenther
commit c0cf20a49e34eec76422e79d463eb780c5c53e96
Author: Günther Deschner <gd at samba.org>
Date: Mon Jan 26 16:41:46 2009 +0100
s3-net: add "net eventlog import".
This allows to import a native (non-wrapped) win32 *.evt eventlog file
into our tdb eventlog representation.
Guenther
commit 21d23bf7e893aa8afc128af419135f4d37b080f9
Author: Günther Deschner <gd at samba.org>
Date: Fri Jan 23 15:00:17 2009 +0100
s3-net: add "net eventlog dump".
This allows to dump a native (non-wrapped) win32 *.evt eventlog file.
Guenther
-----------------------------------------------------------------------
Summary of changes:
source3/Makefile.in | 11 +-
source3/utils/net.c | 8 +
source3/utils/net_eventlog.c | 313 ++++++++++++++++++++++++++++++++++++++++++
source3/utils/net_proto.h | 3 +
4 files changed, 331 insertions(+), 4 deletions(-)
create mode 100644 source3/utils/net_eventlog.c
Changeset truncated at 500 lines:
diff --git a/source3/Makefile.in b/source3/Makefile.in
index 992df5e..c4a6317 100644
--- a/source3/Makefile.in
+++ b/source3/Makefile.in
@@ -530,6 +530,7 @@ REG_FULL_OBJ = $(REG_SMBCONF_OBJ) \
registry/reg_perfcount.o \
registry/reg_util_legacy.o
+LIB_EVENTLOG_OBJ = rpc_server/srv_eventlog_lib.o
RPC_LSA_OBJ = rpc_server/srv_lsa_nt.o ../librpc/gen_ndr/srv_lsa.o
@@ -566,7 +567,7 @@ RPC_DFS_OBJ = ../librpc/gen_ndr/srv_dfs.o rpc_server/srv_dfs_nt.o
RPC_SPOOLSS_OBJ = rpc_server/srv_spoolss.o rpc_server/srv_spoolss_nt.o
RPC_EVENTLOG_OBJ = rpc_server/srv_eventlog.o rpc_server/srv_eventlog_nt.o \
- rpc_server/srv_eventlog_lib.o ../librpc/gen_ndr/srv_eventlog.o
+ $(LIB_EVENTLOG_OBJ) ../librpc/gen_ndr/srv_eventlog.o
RPC_PIPE_OBJ = rpc_server/srv_pipe_hnd.o \
rpc_server/srv_pipe.o rpc_server/srv_lsa_hnd.o
@@ -896,7 +897,8 @@ NET_OBJ1 = utils/net.o utils/net_ads.o utils/net_help.o \
$(PASSWD_UTIL_OBJ) utils/net_dns.o utils/net_ads_gpo.o \
utils/net_conf.o utils/net_join.o utils/net_user.o \
utils/net_group.o utils/net_file.o utils/net_registry.o \
- auth/token_util.o utils/net_dom.o utils/net_share.o utils/net_lua.o
+ auth/token_util.o utils/net_dom.o utils/net_share.o utils/net_lua.o \
+ utils/net_eventlog.o
# these are not processed by make proto
NET_OBJ2 = utils/net_registry_util.o utils/net_help_common.o
@@ -914,7 +916,8 @@ NET_OBJ = $(NET_OBJ1) \
$(REG_SMBCONF_OBJ) @LIBNETAPI_STATIC@ $(LIBNET_OBJ) \
$(LIBSMBCONF_OBJ) \
@LIBWBCLIENT_STATIC@ \
- $(PRIVILEGES_BASIC_OBJ) @LIBLUA_STATIC@
+ $(PRIVILEGES_BASIC_OBJ) @LIBLUA_STATIC@ \
+ $(LIB_EVENTLOG_OBJ)
CUPS_OBJ = client/smbspool.o $(PARAM_OBJ) $(LIBSMB_OBJ) \
$(LIB_NONSMBD_OBJ) $(KRBCLIENT_OBJ) $(POPT_LIB_OBJ) \
@@ -983,7 +986,7 @@ EVTLOGADM_OBJ0 = utils/eventlogadm.o
EVTLOGADM_OBJ = $(EVTLOGADM_OBJ0) $(PARAM_OBJ) $(LIB_NONSMBD_OBJ) \
$(LIBSAMBA_OBJ) \
- registry/reg_eventlog.o rpc_server/srv_eventlog_lib.o \
+ registry/reg_eventlog.o $(LIB_EVENTLOG_OBJ) \
../librpc/gen_ndr/ndr_eventlog.o \
../librpc/gen_ndr/ndr_lsa.o
diff --git a/source3/utils/net.c b/source3/utils/net.c
index c9525ab..d483198 100644
--- a/source3/utils/net.c
+++ b/source3/utils/net.c
@@ -589,6 +589,14 @@ static struct functable net_func[] = {
" Use 'net help lua' to get more information about 'net "
"lua' commands."
},
+ { "eventlog",
+ net_eventlog,
+ NET_TRANSPORT_LOCAL,
+ "Dump Win32 *.evt eventlog files",
+ " Use 'net help eventlog' to get more information about 'net "
+ "eventlog' commands."
+ },
+
#ifdef WITH_FAKE_KASERVER
{ "afs",
net_afs,
diff --git a/source3/utils/net_eventlog.c b/source3/utils/net_eventlog.c
new file mode 100644
index 0000000..197a7cd
--- /dev/null
+++ b/source3/utils/net_eventlog.c
@@ -0,0 +1,313 @@
+/*
+ * Samba Unix/Linux SMB client library
+ * Distributed SMB/CIFS Server Management Utility
+ * Local win32 eventlog interface
+ *
+ * Copyright (C) Guenther Deschner 2009
+ *
+ * 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.h"
+
+/**
+ * Dump an *evt win32 eventlog file
+ *
+ * @param argc Standard main() style argc.
+ * @param argv Standard main() style argv. Initial components are already
+ * stripped.
+ *
+ * @return A shell status integer (0 for success).
+ **/
+
+static int net_eventlog_dump(struct net_context *c, int argc,
+ const char **argv)
+{
+ int ret = -1;
+ TALLOC_CTX *ctx = talloc_stackframe();
+ enum ndr_err_code ndr_err;
+ DATA_BLOB blob;
+ struct EVENTLOG_EVT_FILE evt;
+ char *s;
+
+ if (argc < 1 || c->display_usage) {
+ d_fprintf(stderr, "usage: net eventlog dump <file.evt>\n");
+ goto done;
+ }
+
+ blob.data = (uint8_t *)file_load(argv[0], &blob.length, 0, ctx);
+ if (!blob.data) {
+ d_fprintf(stderr, "failed to load evt file: %s\n", argv[0]);
+ goto done;
+ }
+
+ ndr_err = ndr_pull_struct_blob(&blob, ctx, NULL, &evt,
+ (ndr_pull_flags_fn_t)ndr_pull_EVENTLOG_EVT_FILE);
+ if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
+ d_fprintf(stderr, "evt pull failed: %s\n", ndr_errstr(ndr_err));
+ goto done;
+ }
+
+ s = NDR_PRINT_STRUCT_STRING(ctx, EVENTLOG_EVT_FILE, &evt);
+ if (s) {
+ printf("%s\n", s);
+ }
+
+ ret = 0;
+ done:
+ TALLOC_FREE(ctx);
+ return ret;
+}
+
+/**
+ * Import an *evt win32 eventlog file to internal tdb representation
+ *
+ * @param argc Standard main() style argc.
+ * @param argv Standard main() style argv. Initial components are already
+ * stripped.
+ *
+ * @return A shell status integer (0 for success).
+ **/
+
+static int net_eventlog_import(struct net_context *c, int argc,
+ const char **argv)
+{
+ int ret = -1;
+ TALLOC_CTX *ctx = talloc_stackframe();
+ NTSTATUS status;
+ enum ndr_err_code ndr_err;
+ DATA_BLOB blob;
+ uint32_t num_records = 0;
+ uint32_t i;
+ ELOG_TDB *etdb = NULL;
+
+ struct EVENTLOGHEADER evt_header;
+ struct EVENTLOG_EVT_FILE evt;
+
+ if (argc < 2 || c->display_usage) {
+ d_fprintf(stderr, "usage: net eventlog import <file> <eventlog>\n");
+ goto done;
+ }
+
+ blob.data = (uint8_t *)file_load(argv[0], &blob.length, 0, ctx);
+ if (!blob.data) {
+ d_fprintf(stderr, "failed to load evt file: %s\n", argv[0]);
+ goto done;
+ }
+
+ /* dump_data(0, blob.data, blob.length); */
+ ndr_err = ndr_pull_struct_blob(&blob, ctx, NULL, &evt_header,
+ (ndr_pull_flags_fn_t)ndr_pull_EVENTLOGHEADER);
+ if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
+ d_fprintf(stderr, "evt header pull failed: %s\n", ndr_errstr(ndr_err));
+ goto done;
+ }
+
+ if (evt_header.Flags & ELF_LOGFILE_HEADER_WRAP) {
+ d_fprintf(stderr, "input file is wrapped, cannot proceed\n");
+ goto done;
+ }
+
+ ndr_err = ndr_pull_struct_blob(&blob, ctx, NULL, &evt,
+ (ndr_pull_flags_fn_t)ndr_pull_EVENTLOG_EVT_FILE);
+ if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
+ d_fprintf(stderr, "evt pull failed: %s\n", ndr_errstr(ndr_err));
+ goto done;
+ }
+
+ /* NDR_PRINT_DEBUG(EVENTLOG_EVT_FILE, &evt); */
+
+ etdb = elog_open_tdb(argv[1], false, false);
+ if (!etdb) {
+ d_fprintf(stderr, "can't open the eventlog TDB (%s)\n", argv[1]);
+ goto done;
+ }
+
+ num_records = evt.hdr.CurrentRecordNumber - evt.hdr.OldestRecordNumber;
+
+ for (i=0; i<num_records; i++) {
+ uint32_t record_number;
+ struct eventlog_Record_tdb e;
+
+ status = evlog_evt_entry_to_tdb_entry(ctx, &evt.records[i], &e);
+ if (!NT_STATUS_IS_OK(status)) {
+ goto done;
+ }
+
+ status = evlog_push_record_tdb(ctx, ELOG_TDB_CTX(etdb),
+ &e, &record_number);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_fprintf(stderr, "can't write to the eventlog: %s\n",
+ nt_errstr(status));
+ goto done;
+ }
+ }
+
+ printf("wrote %d entries to tdb\n", i);
+
+ ret = 0;
+ done:
+
+ elog_close_tdb(etdb, false);
+
+ TALLOC_FREE(ctx);
+ return ret;
+}
+
+/**
+ * Export internal eventlog tdb representation to an *evt win32 eventlog file
+ *
+ * @param argc Standard main() style argc.
+ * @param argv Standard main() style argv. Initial components are already
+ * stripped.
+ *
+ * @return A shell status integer (0 for success).
+ **/
+
+static int net_eventlog_export(struct net_context *c, int argc,
+ const char **argv)
+{
+ int ret = -1;
+ NTSTATUS status;
+ TALLOC_CTX *ctx = talloc_stackframe();
+ enum ndr_err_code ndr_err;
+ DATA_BLOB blob;
+ uint32_t num_records = 0;
+ struct EVENTLOG_EVT_FILE evt;
+ ELOG_TDB *etdb = NULL;
+ uint32_t count = 1;
+ size_t endoffset = 0;
+
+ if (argc < 2 || c->display_usage) {
+ d_fprintf(stderr, "usage: net eventlog export <file> <eventlog>\n");
+ goto done;
+ }
+
+ etdb = elog_open_tdb(argv[1], false, true);
+ if (!etdb) {
+ d_fprintf(stderr, "can't open the eventlog TDB (%s)\n", argv[1]);
+ goto done;
+ }
+
+ ZERO_STRUCT(evt);
+
+ while (1) {
+
+ struct eventlog_Record_tdb *r;
+ struct EVENTLOGRECORD e;
+
+ r = evlog_pull_record_tdb(ctx, etdb->tdb, count);
+ if (!r) {
+ break;
+ }
+
+ status = evlog_tdb_entry_to_evt_entry(ctx, r, &e);
+ if (!NT_STATUS_IS_OK(status)) {
+ goto done;
+ }
+
+ endoffset += ndr_size_EVENTLOGRECORD(&e, NULL, 0);
+
+ ADD_TO_ARRAY(ctx, struct EVENTLOGRECORD, e, &evt.records, &num_records);
+ count++;
+ }
+
+ evt.hdr.StartOffset = 0x30;
+ evt.hdr.EndOffset = evt.hdr.StartOffset + endoffset;
+ evt.hdr.CurrentRecordNumber = count;
+ evt.hdr.OldestRecordNumber = 1;
+ evt.hdr.MaxSize = tdb_fetch_int32(etdb->tdb, EVT_MAXSIZE);
+ evt.hdr.Flags = 0;
+ evt.hdr.Retention = tdb_fetch_int32(etdb->tdb, EVT_RETENTION);
+
+ if (DEBUGLEVEL >= 10) {
+ NDR_PRINT_DEBUG(EVENTLOGHEADER, &evt.hdr);
+ }
+
+ evt.eof.BeginRecord = 0x30;
+ evt.eof.EndRecord = evt.hdr.StartOffset + endoffset;
+ evt.eof.CurrentRecordNumber = evt.hdr.CurrentRecordNumber;
+ evt.eof.OldestRecordNumber = evt.hdr.OldestRecordNumber;
+
+ if (DEBUGLEVEL >= 10) {
+ NDR_PRINT_DEBUG(EVENTLOGEOF, &evt.eof);
+ }
+
+ ndr_err = ndr_push_struct_blob(&blob, ctx, NULL, &evt,
+ (ndr_push_flags_fn_t)ndr_push_EVENTLOG_EVT_FILE);
+ if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
+ d_fprintf(stderr, "evt push failed: %s\n", ndr_errstr(ndr_err));
+ goto done;
+ }
+
+ if (!file_save(argv[0], blob.data, blob.length)) {
+ d_fprintf(stderr, "failed to save evt file: %s\n", argv[0]);
+ goto done;
+ }
+
+ ret = 0;
+ done:
+
+ elog_close_tdb(etdb, false);
+
+ TALLOC_FREE(ctx);
+ return ret;
+}
+
+/**
+ * 'net rpc eventlog' entrypoint.
+ * @param argc Standard main() style argc.
+ * @param argv Standard main() style argv. Initial components are already
+ * stripped.
+ **/
+
+int net_eventlog(struct net_context *c, int argc, const char **argv)
+{
+ int ret = -1;
+
+ struct functable func[] = {
+ {
+ "dump",
+ net_eventlog_dump,
+ NET_TRANSPORT_LOCAL,
+ "Dump eventlog",
+ "net eventlog dump\n"
+ " Dump win32 *.evt eventlog file"
+ },
+ {
+ "import",
+ net_eventlog_import,
+ NET_TRANSPORT_LOCAL,
+ "Import eventlog",
+ "net eventlog import\n"
+ " Import win32 *.evt eventlog file"
+ },
+ {
+ "export",
+ net_eventlog_export,
+ NET_TRANSPORT_LOCAL,
+ "Export eventlog",
+ "net eventlog export\n"
+ " Export win32 *.evt eventlog file"
+ },
+
+
+ { NULL, NULL, 0, NULL, NULL }
+ };
+
+ ret = net_run_function(c, argc, argv, "net eventlog", func);
+
+ return ret;
+}
diff --git a/source3/utils/net_proto.h b/source3/utils/net_proto.h
index a65fbbb..75ac032 100644
--- a/source3/utils/net_proto.h
+++ b/source3/utils/net_proto.h
@@ -427,6 +427,9 @@ int net_usershare(struct net_context *c, int argc, const char **argv);
int net_lua(struct net_context *c, int argc, const char **argv);
+/* The following definitions come from utils/net_eventlog.c */
+
+int net_eventlog(struct net_context *c, int argc, const char **argv);
/* The following definitions come from utils/net_util.c */
--
Samba Shared Repository
More information about the samba-cvs
mailing list