diff options
Diffstat (limited to 'source3/utils')
-rw-r--r-- | source3/utils/eventlogadm.c | 81 | ||||
-rw-r--r-- | source3/utils/net.c | 8 | ||||
-rw-r--r-- | source3/utils/net_ads.c | 8 | ||||
-rw-r--r-- | source3/utils/net_eventlog.c | 313 | ||||
-rw-r--r-- | source3/utils/net_proto.h | 3 | ||||
-rw-r--r-- | source3/utils/net_rpc.c | 18 | ||||
-rw-r--r-- | source3/utils/net_rpc_join.c | 7 | ||||
-rw-r--r-- | source3/utils/smbcacls.c | 10 |
8 files changed, 416 insertions, 32 deletions
diff --git a/source3/utils/eventlogadm.c b/source3/utils/eventlogadm.c index 5fed4d1a39..d134ea8fea 100644 --- a/source3/utils/eventlogadm.c +++ b/source3/utils/eventlogadm.c @@ -5,6 +5,7 @@ * * * Copyright (C) Brian Moran 2005. + * 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 @@ -37,6 +38,7 @@ static void usage( char *s ) printf( "\nUsage: %s [OPTION]\n\n", s ); printf( " -o write <Eventlog Name> \t\t\t\t\tWrites records to eventlog from STDIN\n" ); printf( " -o addsource <EventlogName> <sourcename> <msgfileDLLname> \tAdds the specified source & DLL eventlog registry entry\n" ); + printf( " -o dump <Eventlog Name> <starting_record>\t\t\t\t\tDump stored eventlog entries on STDOUT\n" ); printf( "\nMiscellaneous options:\n" ); printf( " -d\t\t\t\t\t\t\t\tturn debug on\n" ); printf( " -h\t\t\t\t\t\t\t\tdisplay help\n\n" ); @@ -83,12 +85,14 @@ static int DoWriteCommand( int argc, char **argv, bool debugflag, char *exename FILE *f1; char *argfname; ELOG_TDB *etdb; + NTSTATUS status; /* fixed constants are bad bad bad */ char linein[1024]; bool is_eor; - Eventlog_entry ee; - int rcnum; + struct eventlog_Record_tdb ee; + uint32_t record_number; + TALLOC_CTX *mem_ctx = talloc_tos(); f1 = stdin; if ( !f1 ) { @@ -103,7 +107,7 @@ static int DoWriteCommand( int argc, char **argv, bool debugflag, char *exename argfname = argv[0]; - if ( !( etdb = elog_open_tdb( argfname, False ) ) ) { + if ( !( etdb = elog_open_tdb( argfname, False, False ) ) ) { printf( "can't open the eventlog TDB (%s)\n", argfname ); return -1; } @@ -122,26 +126,29 @@ static int DoWriteCommand( int argc, char **argv, bool debugflag, char *exename is_eor = False; - parse_logentry( ( char * ) &linein, &ee, &is_eor ); + parse_logentry( mem_ctx, ( char * ) &linein, &ee, &is_eor ); /* should we do something with the return code? */ if ( is_eor ) { - fixup_eventlog_entry( &ee ); + fixup_eventlog_record_tdb( &ee ); if ( opt_debug ) - printf( "record number [%d], tg [%d] , tw [%d]\n", ee.record.record_number, ee.record.time_generated, ee.record.time_written ); + printf( "record number [%d], tg [%d] , tw [%d]\n", + ee.record_number, (int)ee.time_generated, (int)ee.time_written ); - if ( ee.record.time_generated != 0 ) { + if ( ee.time_generated != 0 ) { /* printf("Writing to the event log\n"); */ - rcnum = write_eventlog_tdb( ELOG_TDB_CTX(etdb), &ee ); - if ( !rcnum ) { - printf( "Can't write to the event log\n" ); + status = evlog_push_record_tdb( mem_ctx, ELOG_TDB_CTX(etdb), + &ee, &record_number ); + if ( !NT_STATUS_IS_OK(status) ) { + printf( "Can't write to the event log: %s\n", + nt_errstr(status) ); } else { if ( opt_debug ) printf( "Wrote record %d\n", - rcnum ); + record_number ); } } else { if ( opt_debug ) @@ -156,6 +163,54 @@ static int DoWriteCommand( int argc, char **argv, bool debugflag, char *exename return 0; } +static int DoDumpCommand(int argc, char **argv, bool debugflag, char *exename) +{ + ELOG_TDB *etdb; + TALLOC_CTX *mem_ctx = talloc_tos(); + const char *tdb_filename; + uint32_t count = 1; + + if (argc > 2) { + return -1; + } + + tdb_filename = argv[0]; + + if (argc > 1) { + count = atoi(argv[1]); + } + + etdb = elog_open_tdb(argv[0], false, true); + if (!etdb) { + printf("can't open the eventlog TDB (%s)\n", argv[0]); + return -1; + } + + while (1) { + + struct eventlog_Record_tdb *r; + char *s; + + r = evlog_pull_record_tdb(mem_ctx, etdb->tdb, count); + if (!r) { + break; + } + + printf("displaying record: %d\n", count); + + s = NDR_PRINT_STRUCT_STRING(mem_ctx, eventlog_Record_tdb, r); + if (s) { + printf("%s\n", s); + talloc_free(s); + } + count++; + } + + elog_close_tdb(etdb, false); + + return 0; +} + /* would be nice to use the popT stuff here, however doing so forces us to drag in a lot of other infrastructure */ int main( int argc, char *argv[] ) @@ -221,6 +276,10 @@ int main( int argc, char *argv[] ) rc = DoWriteCommand( argc, argv, opt_debug, exename ); break; } + if ( !StrCaseCmp( opname, "dump" ) ) { + rc = DoDumpCommand( argc, argv, opt_debug, exename ); + break; + } printf( "unknown command [%s]\n", opname ); usage( exename ); exit( 1 ); diff --git a/source3/utils/net.c b/source3/utils/net.c index c9525ab2eb..d483198a9e 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_ads.c b/source3/utils/net_ads.c index 766f3216f0..86fb9f6782 100644 --- a/source3/utils/net_ads.c +++ b/source3/utils/net_ads.c @@ -1920,7 +1920,7 @@ int net_ads_changetrustpw(struct net_context *c, int argc, const char **argv) d_printf("Password change for principal %s succeeded.\n", host_principal); - if (lp_use_kerberos_keytab()) { + if (USE_SYSTEM_KEYTAB) { d_printf("Attempting to update system keytab with new password.\n"); if (ads_keytab_create_default(ads)) { d_printf("Failed to update system keytab.\n"); @@ -2241,9 +2241,9 @@ int net_ads_keytab(struct net_context *c, int argc, const char **argv) {NULL, NULL, 0, NULL, NULL} }; - if (!lp_use_kerberos_keytab()) { - d_printf("\nWarning: \"use kerberos keytab\" must be set to \"true\" in order to \ -use keytab functions.\n"); + if (!USE_KERBEROS_KEYTAB) { + d_printf("\nWarning: \"kerberos method\" must be set to a " + "keytab method to use keytab functions.\n"); } return net_run_function(c, argc, argv, "net ads keytab", func); diff --git a/source3/utils/net_eventlog.c b/source3/utils/net_eventlog.c new file mode 100644 index 0000000000..197a7cd330 --- /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 a65fbbb6eb..75ac032db9 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 */ diff --git a/source3/utils/net_rpc.c b/source3/utils/net_rpc.c index 0f59f02746..c54d479413 100644 --- a/source3/utils/net_rpc.c +++ b/source3/utils/net_rpc.c @@ -181,8 +181,7 @@ int run_rpc_command(struct net_context *c, } if (!NT_STATUS_IS_OK(nt_status)) { DEBUG(0, ("Could not initialise pipe %s. Error was %s\n", - cli_get_pipe_name_from_iface( - debug_ctx(), interface), + get_pipe_name_from_iface(interface), nt_errstr(nt_status) )); cli_shutdown(cli); return -1; @@ -797,7 +796,7 @@ static int rpc_user_info(struct net_context *c, int argc, const char **argv) status = NetUserGetGroups(c->opt_host, argv[0], 0, - (uint8_t **)&u0, + (uint8_t **)(void *)&u0, (uint32_t)-1, &entries_read, &total_entries); @@ -1394,7 +1393,7 @@ static NTSTATUS rpc_group_delete_internals(struct net_context *c, struct samr_RidTypeArray *rids = NULL; /* char **names; */ int i; - /* DOM_GID *user_gids; */ + /* struct samr_RidWithAttribute *user_gids; */ struct samr_Ids group_rids, name_types; struct lsa_String lsa_acct_name; @@ -2997,7 +2996,7 @@ static int rpc_share_list(struct net_context *c, int argc, const char **argv) status = NetShareEnum(c->opt_host, level, - (uint8_t **)&i1, + (uint8_t **)(void *)&i1, (uint32_t)-1, &entries_read, &total_entries, @@ -3022,7 +3021,7 @@ static int rpc_share_list(struct net_context *c, int argc, const char **argv) static bool check_share_availability(struct cli_state *cli, const char *netname) { - if (!cli_send_tconX(cli, netname, "A:", "", 0)) { + if (!NT_STATUS_IS_OK(cli_tcon_andx(cli, netname, "A:", "", 0))) { d_printf("skipping [%s]: not a file share.\n", netname); return false; } @@ -4281,7 +4280,7 @@ static void show_userlist(struct rpc_pipe_client *pipe_hnd, cnum = cli->cnum; - if (!cli_send_tconX(cli, netname, "A:", "", 0)) { + if (!NT_STATUS_IS_OK(cli_tcon_andx(cli, netname, "A:", "", 0))) { return; } @@ -4378,7 +4377,6 @@ static NTSTATUS rpc_share_allowedusers_internals(struct net_context *c, { int ret; bool r; - ENUM_HND hnd; uint32 i; FILE *f; @@ -4411,8 +4409,6 @@ static NTSTATUS rpc_share_allowedusers_internals(struct net_context *c, for (i=0; i<num_tokens; i++) collect_alias_memberships(&tokens[i].token); - init_enum_hnd(&hnd, 0); - share_list.num_shares = 0; share_list.shares = NULL; @@ -4776,7 +4772,7 @@ static int rpc_file_user(struct net_context *c, int argc, const char **argv) NULL, username, 3, - (uint8_t **)&i3, + (uint8_t **)(void *)&i3, preferred_len, &entries_read, &total_entries, diff --git a/source3/utils/net_rpc_join.c b/source3/utils/net_rpc_join.c index 5651676693..0c363d373e 100644 --- a/source3/utils/net_rpc_join.c +++ b/source3/utils/net_rpc_join.c @@ -243,14 +243,17 @@ int net_rpc_join_newstyle(struct net_context *c, int argc, const char **argv) CHECK_RPC_ERR(rpccli_samr_Connect2(pipe_hnd, mem_ctx, pipe_hnd->desthost, - SEC_RIGHTS_MAXIMUM_ALLOWED, + SAMR_ACCESS_ENUM_DOMAINS + | SAMR_ACCESS_OPEN_DOMAIN, &sam_pol), "could not connect to SAM database"); CHECK_RPC_ERR(rpccli_samr_OpenDomain(pipe_hnd, mem_ctx, &sam_pol, - SEC_RIGHTS_MAXIMUM_ALLOWED, + SAMR_DOMAIN_ACCESS_LOOKUP_INFO_1 + | SAMR_DOMAIN_ACCESS_CREATE_USER + | SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, domain_sid, &domain_pol), "could not open domain"); diff --git a/source3/utils/smbcacls.c b/source3/utils/smbcacls.c index f07b5011c8..c12778f8c7 100644 --- a/source3/utils/smbcacls.c +++ b/source3/utils/smbcacls.c @@ -76,8 +76,9 @@ static NTSTATUS cli_lsa_lookup_sid(struct cli_state *cli, char **domains; char **names; - if (!cli_send_tconX(cli, "IPC$", "?????", "", 0)) { - return cli_nt_error(cli); + status = cli_tcon_andx(cli, "IPC$", "?????", "", 0); + if (!NT_STATUS_IS_OK(status)) { + return status; } status = cli_rpc_pipe_open_noauth(cli, &ndr_table_lsarpc.syntax_id, @@ -124,8 +125,9 @@ static NTSTATUS cli_lsa_lookup_name(struct cli_state *cli, DOM_SID *sids; enum lsa_SidType *types; - if (!cli_send_tconX(cli, "IPC$", "?????", "", 0)) { - return cli_nt_error(cli); + status = cli_tcon_andx(cli, "IPC$", "?????", "", 0); + if (!NT_STATUS_IS_OK(status)) { + return status; } status = cli_rpc_pipe_open_noauth(cli, &ndr_table_lsarpc.syntax_id, |