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"
27 * Dump an *evt win32 eventlog file
29 * @param argc Standard main() style argc.
30 * @param argv Standard main() style argv. Initial components are already
33 * @return A shell status integer (0 for success).
36 static int net_eventlog_dump(struct net_context
*c
, int argc
,
40 TALLOC_CTX
*ctx
= talloc_stackframe();
41 enum ndr_err_code ndr_err
;
43 struct EVENTLOG_EVT_FILE evt
;
46 if (argc
< 1 || c
->display_usage
) {
47 d_fprintf(stderr
, "%s\nnet eventlog dump <file.evt>\n",
52 blob
.data
= (uint8_t *)file_load(argv
[0], &blob
.length
, 0, ctx
);
54 d_fprintf(stderr
, _("failed to load evt file: %s\n"), argv
[0]);
58 ndr_err
= ndr_pull_struct_blob(&blob
, ctx
, &evt
,
59 (ndr_pull_flags_fn_t
)ndr_pull_EVENTLOG_EVT_FILE
);
60 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
61 d_fprintf(stderr
, _("evt pull failed: %s\n"),
66 s
= NDR_PRINT_STRUCT_STRING(ctx
, EVENTLOG_EVT_FILE
, &evt
);
78 * Import an *evt win32 eventlog file to internal tdb representation
80 * @param argc Standard main() style argc.
81 * @param argv Standard main() style argv. Initial components are already
84 * @return A shell status integer (0 for success).
87 static int net_eventlog_import(struct net_context
*c
, int argc
,
91 TALLOC_CTX
*ctx
= talloc_stackframe();
93 enum ndr_err_code ndr_err
;
95 uint32_t num_records
= 0;
97 ELOG_TDB
*etdb
= NULL
;
99 struct EVENTLOGHEADER evt_header
;
100 struct EVENTLOG_EVT_FILE evt
;
102 if (argc
< 2 || c
->display_usage
) {
104 "%s\nnet eventlog import <file> <eventlog>\n",
109 blob
.data
= (uint8_t *)file_load(argv
[0], &blob
.length
, 0, ctx
);
111 d_fprintf(stderr
, _("failed to load evt file: %s\n"), argv
[0]);
115 /* dump_data(0, blob.data, blob.length); */
116 ndr_err
= ndr_pull_struct_blob(&blob
, ctx
, &evt_header
,
117 (ndr_pull_flags_fn_t
)ndr_pull_EVENTLOGHEADER
);
118 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
119 d_fprintf(stderr
, _("evt header pull failed: %s\n"),
120 ndr_errstr(ndr_err
));
124 if (evt_header
.Flags
& ELF_LOGFILE_HEADER_WRAP
) {
125 d_fprintf(stderr
, _("input file is wrapped, cannot proceed\n"));
129 ndr_err
= ndr_pull_struct_blob(&blob
, ctx
, &evt
,
130 (ndr_pull_flags_fn_t
)ndr_pull_EVENTLOG_EVT_FILE
);
131 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
132 d_fprintf(stderr
, _("evt pull failed: %s\n"),
133 ndr_errstr(ndr_err
));
137 /* NDR_PRINT_DEBUG(EVENTLOG_EVT_FILE, &evt); */
139 etdb
= elog_open_tdb(argv
[1], false, false);
141 d_fprintf(stderr
, _("can't open the eventlog TDB (%s)\n"),
146 num_records
= evt
.hdr
.CurrentRecordNumber
- evt
.hdr
.OldestRecordNumber
;
148 for (i
=0; i
<num_records
; i
++) {
149 uint32_t record_number
;
150 struct eventlog_Record_tdb e
;
152 status
= evlog_evt_entry_to_tdb_entry(ctx
, &evt
.records
[i
], &e
);
153 if (!NT_STATUS_IS_OK(status
)) {
157 status
= evlog_push_record_tdb(ctx
, ELOG_TDB_CTX(etdb
),
159 if (!NT_STATUS_IS_OK(status
)) {
161 _("can't write to the eventlog: %s\n"),
167 printf(_("wrote %d entries to tdb\n"), i
);
172 elog_close_tdb(etdb
, false);
179 * Export internal eventlog tdb representation to an *evt win32 eventlog file
181 * @param argc Standard main() style argc.
182 * @param argv Standard main() style argv. Initial components are already
185 * @return A shell status integer (0 for success).
188 static int net_eventlog_export(struct net_context
*c
, int argc
,
193 TALLOC_CTX
*ctx
= talloc_stackframe();
195 uint32_t num_records
= 0;
196 ELOG_TDB
*etdb
= NULL
;
198 if (argc
< 2 || c
->display_usage
) {
200 "%s\nnet eventlog export <file> <eventlog>\n",
205 etdb
= elog_open_tdb(argv
[1], false, true);
207 d_fprintf(stderr
, _("can't open the eventlog TDB (%s)\n"),
212 status
= evlog_convert_tdb_to_evt(ctx
, etdb
, &blob
, &num_records
);
213 if (!NT_STATUS_IS_OK(status
)) {
217 if (!file_save(argv
[0], blob
.data
, blob
.length
)) {
218 d_fprintf(stderr
, _("failed to save evt file: %s\n"), argv
[0]);
225 elog_close_tdb(etdb
, false);
232 * 'net rpc eventlog' entrypoint.
233 * @param argc Standard main() style argc.
234 * @param argv Standard main() style argv. Initial components are already
238 int net_eventlog(struct net_context
*c
, int argc
, const char **argv
)
242 struct functable func
[] = {
248 N_("net eventlog dump\n"
249 " Dump win32 *.evt eventlog file")
255 N_("Import eventlog"),
256 N_("net eventlog import\n"
257 " Import win32 *.evt eventlog file")
263 N_("Export eventlog"),
264 N_("net eventlog export\n"
265 " Export win32 *.evt eventlog file")
269 { NULL
, NULL
, 0, NULL
, NULL
}
272 ret
= net_run_function(c
, argc
, argv
, "net eventlog", func
);