2 * Samba Unix/Linux SMB client library
3 * Distributed SMB/CIFS Server Management Utility
4 * Local win32 eventlog interface
6 * Copyright (C) Guenther Deschner 2009
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "utils/net.h"
24 #include "lib/eventlog/eventlog.h"
25 #include "lib/util/util_file.h"
28 * Dump an *evt win32 eventlog file
30 * @param argc Standard main() style argc.
31 * @param argv Standard main() style argv. Initial components are already
34 * @return A shell status integer (0 for success).
37 static int net_eventlog_dump(struct net_context
*c
, int argc
,
41 TALLOC_CTX
*ctx
= talloc_stackframe();
42 enum ndr_err_code ndr_err
;
44 struct EVENTLOG_EVT_FILE evt
;
47 if (argc
< 1 || c
->display_usage
) {
48 d_fprintf(stderr
, "%s\nnet eventlog dump <file.evt>\n",
53 blob
.data
= (uint8_t *)file_load(argv
[0], &blob
.length
, 0, ctx
);
55 d_fprintf(stderr
, _("failed to load evt file: %s\n"), argv
[0]);
59 ndr_err
= ndr_pull_struct_blob(&blob
, ctx
, &evt
,
60 (ndr_pull_flags_fn_t
)ndr_pull_EVENTLOG_EVT_FILE
);
61 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
62 d_fprintf(stderr
, _("evt pull failed: %s\n"),
67 s
= NDR_PRINT_STRUCT_STRING(ctx
, EVENTLOG_EVT_FILE
, &evt
);
79 * Import an *evt win32 eventlog file to internal tdb representation
81 * @param argc Standard main() style argc.
82 * @param argv Standard main() style argv. Initial components are already
85 * @return A shell status integer (0 for success).
88 static int net_eventlog_import(struct net_context
*c
, int argc
,
92 TALLOC_CTX
*ctx
= talloc_stackframe();
94 enum ndr_err_code ndr_err
;
96 uint32_t num_records
= 0;
98 ELOG_TDB
*etdb
= NULL
;
100 struct EVENTLOGHEADER evt_header
;
101 struct EVENTLOG_EVT_FILE evt
;
103 if (argc
< 2 || c
->display_usage
) {
105 "%s\nnet eventlog import <file> <eventlog>\n",
110 blob
.data
= (uint8_t *)file_load(argv
[0], &blob
.length
, 0, ctx
);
112 d_fprintf(stderr
, _("failed to load evt file: %s\n"), argv
[0]);
116 /* dump_data(0, blob.data, blob.length); */
117 ndr_err
= ndr_pull_struct_blob(&blob
, ctx
, &evt_header
,
118 (ndr_pull_flags_fn_t
)ndr_pull_EVENTLOGHEADER
);
119 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
120 d_fprintf(stderr
, _("evt header pull failed: %s\n"),
121 ndr_errstr(ndr_err
));
125 if (evt_header
.Flags
& ELF_LOGFILE_HEADER_WRAP
) {
126 d_fprintf(stderr
, _("input file is wrapped, cannot proceed\n"));
130 ndr_err
= ndr_pull_struct_blob(&blob
, ctx
, &evt
,
131 (ndr_pull_flags_fn_t
)ndr_pull_EVENTLOG_EVT_FILE
);
132 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
133 d_fprintf(stderr
, _("evt pull failed: %s\n"),
134 ndr_errstr(ndr_err
));
138 /* NDR_PRINT_DEBUG(EVENTLOG_EVT_FILE, &evt); */
140 etdb
= elog_open_tdb(argv
[1], false, false);
142 d_fprintf(stderr
, _("can't open the eventlog TDB (%s)\n"),
147 num_records
= evt
.hdr
.CurrentRecordNumber
- evt
.hdr
.OldestRecordNumber
;
149 for (i
=0; i
<num_records
; i
++) {
150 uint32_t record_number
;
151 struct eventlog_Record_tdb e
;
153 status
= evlog_evt_entry_to_tdb_entry(ctx
, &evt
.records
[i
], &e
);
154 if (!NT_STATUS_IS_OK(status
)) {
158 status
= evlog_push_record_tdb(ctx
, ELOG_TDB_CTX(etdb
),
160 if (!NT_STATUS_IS_OK(status
)) {
162 _("can't write to the eventlog: %s\n"),
168 printf(_("wrote %d entries to tdb\n"), i
);
173 elog_close_tdb(etdb
, false);
180 * Export internal eventlog tdb representation to an *evt win32 eventlog file
182 * @param argc Standard main() style argc.
183 * @param argv Standard main() style argv. Initial components are already
186 * @return A shell status integer (0 for success).
189 static int net_eventlog_export(struct net_context
*c
, int argc
,
194 TALLOC_CTX
*ctx
= talloc_stackframe();
196 uint32_t num_records
= 0;
197 ELOG_TDB
*etdb
= NULL
;
199 if (argc
< 2 || c
->display_usage
) {
201 "%s\nnet eventlog export <file> <eventlog>\n",
206 etdb
= elog_open_tdb(argv
[1], false, true);
208 d_fprintf(stderr
, _("can't open the eventlog TDB (%s)\n"),
213 status
= evlog_convert_tdb_to_evt(ctx
, etdb
, &blob
, &num_records
);
214 if (!NT_STATUS_IS_OK(status
)) {
218 if (!file_save(argv
[0], blob
.data
, blob
.length
)) {
219 d_fprintf(stderr
, _("failed to save evt file: %s\n"), argv
[0]);
226 elog_close_tdb(etdb
, false);
233 * 'net rpc eventlog' entrypoint.
234 * @param argc Standard main() style argc.
235 * @param argv Standard main() style argv. Initial components are already
239 int net_eventlog(struct net_context
*c
, int argc
, const char **argv
)
243 struct functable func
[] = {
249 N_("net eventlog dump\n"
250 " Dump win32 *.evt eventlog file")
256 N_("Import eventlog"),
257 N_("net eventlog import\n"
258 " Import win32 *.evt eventlog file")
264 N_("Export eventlog"),
265 N_("net eventlog export\n"
266 " Export win32 *.evt eventlog file")
270 { NULL
, NULL
, 0, NULL
, NULL
}
273 ret
= net_run_function(c
, argc
, argv
, "net eventlog", func
);