From 4561721cc3b4e45d953e0cdb7cca422fe0fa3b0d Mon Sep 17 00:00:00 2001 From: =?utf8?q?G=C3=BCnther=20Deschner?= Date: Mon, 12 Jan 2009 16:16:24 +0100 Subject: [PATCH] s3-rpcclient: some cleanup for eventlog client. Guenther --- source3/rpcclient/cmd_eventlog.c | 35 ++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/source3/rpcclient/cmd_eventlog.c b/source3/rpcclient/cmd_eventlog.c index a6254dab52d0..2dcb72a04f86 100644 --- a/source3/rpcclient/cmd_eventlog.c +++ b/source3/rpcclient/cmd_eventlog.c @@ -66,11 +66,15 @@ static NTSTATUS cmd_eventlog_readlog(struct rpc_pipe_client *cli, uint32_t sent_size = 0; uint32_t real_size = 0; - if (argc != 2) { - printf("Usage: %s logname\n", argv[0]); + if (argc < 2 || argc > 4) { + printf("Usage: %s logname [offset]\n", argv[0]); return NT_STATUS_OK; } + if (argc >= 3) { + offset = atoi(argv[2]); + } + status = get_eventlog_handle(cli, mem_ctx, argv[1], &handle); if (!NT_STATUS_IS_OK(status)) { return status; @@ -85,14 +89,17 @@ static NTSTATUS cmd_eventlog_readlog(struct rpc_pipe_client *cli, data, &sent_size, &real_size); - if (NT_STATUS_EQUAL(status, NT_STATUS_BUFFER_TOO_SMALL)) { + if (NT_STATUS_EQUAL(status, NT_STATUS_BUFFER_TOO_SMALL) && + real_size > 0 ) { number_of_bytes = real_size; data = talloc_array(mem_ctx, uint8_t, real_size); continue; } + number_of_bytes = 0; + if (!NT_STATUS_IS_OK(status)) { - return status; + goto done; } { @@ -106,7 +113,8 @@ static NTSTATUS cmd_eventlog_readlog(struct rpc_pipe_client *cli, &rec, (ndr_pull_flags_fn_t)ndr_pull_eventlog_Record); if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) { - return ndr_map_error2ntstatus(ndr_err); + status = ndr_map_error2ntstatus(ndr_err); + goto done; } NDR_PRINT_DEBUG(eventlog_Record, &rec); @@ -115,6 +123,9 @@ static NTSTATUS cmd_eventlog_readlog(struct rpc_pipe_client *cli, offset++; } + done: + rpccli_eventlog_CloseEventLog(cli, mem_ctx, &handle); + return status; } @@ -141,12 +152,15 @@ static NTSTATUS cmd_eventlog_numrecords(struct rpc_pipe_client *cli, &handle, &number); if (!NT_STATUS_IS_OK(status)) { - return status; + goto done; } printf("number of records: %d\n", number); - return NT_STATUS_OK; + done: + rpccli_eventlog_CloseEventLog(cli, mem_ctx, &handle); + + return status; } static NTSTATUS cmd_eventlog_oldestrecord(struct rpc_pipe_client *cli, @@ -172,12 +186,15 @@ static NTSTATUS cmd_eventlog_oldestrecord(struct rpc_pipe_client *cli, &handle, &oldest_entry); if (!NT_STATUS_IS_OK(status)) { - return status; + goto done; } printf("oldest entry: %d\n", oldest_entry); - return NT_STATUS_OK; + done: + rpccli_eventlog_CloseEventLog(cli, mem_ctx, &handle); + + return status; } struct cmd_set eventlog_commands[] = { -- 2.34.1