diff options
Diffstat (limited to 'source3/utils')
-rw-r--r-- | source3/utils/net_ads.c | 16 | ||||
-rw-r--r-- | source3/utils/net_ads_gpo.c | 6 | ||||
-rw-r--r-- | source3/utils/net_eventlog.c | 54 | ||||
-rw-r--r-- | source3/utils/net_rpc_service.c | 204 | ||||
-rw-r--r-- | source3/utils/ntlm_auth.c | 6 | ||||
-rw-r--r-- | source3/utils/pdbedit.c | 7 |
6 files changed, 218 insertions, 75 deletions
diff --git a/source3/utils/net_ads.c b/source3/utils/net_ads.c index 2a66619438..8e927becbe 100644 --- a/source3/utils/net_ads.c +++ b/source3/utils/net_ads.c @@ -503,9 +503,9 @@ static int ads_user_add(struct net_context *c, int argc, const char **argv) ads_msgfree(ads, res); status=ads_find_user_acct(ads, &res, argv[0]); if (ADS_ERR_OK(status)) { - userdn = ads_get_dn(ads, res); + userdn = ads_get_dn(ads, talloc_tos(), res); ads_del_dn(ads, userdn); - ads_memfree(ads, userdn); + TALLOC_FREE(userdn); } done: @@ -598,10 +598,10 @@ static int ads_user_delete(struct net_context *c, int argc, const char **argv) ads_destroy(&ads); return -1; } - userdn = ads_get_dn(ads, res); + userdn = ads_get_dn(ads, talloc_tos(), res); ads_msgfree(ads, res); rc = ads_del_dn(ads, userdn); - ads_memfree(ads, userdn); + TALLOC_FREE(userdn); if (ADS_ERR_OK(rc)) { d_printf("User %s deleted\n", argv[0]); ads_destroy(&ads); @@ -757,10 +757,10 @@ static int ads_group_delete(struct net_context *c, int argc, const char **argv) ads_destroy(&ads); return -1; } - groupdn = ads_get_dn(ads, res); + groupdn = ads_get_dn(ads, talloc_tos(), res); ads_msgfree(ads, res); rc = ads_del_dn(ads, groupdn); - ads_memfree(ads, groupdn); + TALLOC_FREE(groupdn); if (ADS_ERR_OK(rc)) { d_printf("Group %s deleted\n", argv[0]); ads_destroy(&ads); @@ -1740,10 +1740,10 @@ static int net_ads_printer_remove(struct net_context *c, int argc, const char ** return -1; } - prt_dn = ads_get_dn(ads, res); + prt_dn = ads_get_dn(ads, talloc_tos(), res); ads_msgfree(ads, res); rc = ads_del_dn(ads, prt_dn); - ads_memfree(ads, prt_dn); + TALLOC_FREE(prt_dn); if (!ADS_ERR_OK(rc)) { d_fprintf(stderr, "ads_del_dn: %s\n", ads_errstr(rc)); diff --git a/source3/utils/net_ads_gpo.c b/source3/utils/net_ads_gpo.c index 181cba221d..910c78d05a 100644 --- a/source3/utils/net_ads_gpo.c +++ b/source3/utils/net_ads_gpo.c @@ -257,7 +257,7 @@ static int net_ads_gpo_list_all(struct net_context *c, int argc, const char **ar msg; msg = ads_next_entry(ads, msg)) { - if ((dn = ads_get_dn(ads, msg)) == NULL) { + if ((dn = ads_get_dn(ads, mem_ctx, msg)) == NULL) { goto out; } @@ -266,18 +266,16 @@ static int net_ads_gpo_list_all(struct net_context *c, int argc, const char **ar if (!ADS_ERR_OK(status)) { d_printf("ads_parse_gpo failed: %s\n", ads_errstr(status)); - ads_memfree(ads, dn); goto out; } dump_gpo(ads, mem_ctx, &gpo, 0); - ads_memfree(ads, dn); } out: ads_msgfree(ads, res); - talloc_destroy(mem_ctx); + TALLOC_FREE(mem_ctx); ads_destroy(&ads); return 0; diff --git a/source3/utils/net_eventlog.c b/source3/utils/net_eventlog.c index 197a7cd330..b86be6d48b 100644 --- a/source3/utils/net_eventlog.c +++ b/source3/utils/net_eventlog.c @@ -182,13 +182,9 @@ static int net_eventlog_export(struct net_context *c, int argc, 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"); @@ -201,54 +197,8 @@ static int net_eventlog_export(struct net_context *c, int argc, 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)); + status = evlog_convert_tdb_to_evt(ctx, etdb, &blob, &num_records); + if (!NT_STATUS_IS_OK(status)) { goto done; } diff --git a/source3/utils/net_rpc_service.c b/source3/utils/net_rpc_service.c index bcb1a00dab..57a721e55b 100644 --- a/source3/utils/net_rpc_service.c +++ b/source3/utils/net_rpc_service.c @@ -631,6 +631,161 @@ done: /******************************************************************** ********************************************************************/ +static NTSTATUS rpc_service_delete_internal(struct net_context *c, + const DOM_SID *domain_sid, + const char *domain_name, + struct cli_state *cli, + struct rpc_pipe_client *pipe_hnd, + TALLOC_CTX *mem_ctx, + int argc, + const char **argv) +{ + struct policy_handle hSCM, hService; + WERROR result = WERR_GENERAL_FAILURE; + NTSTATUS status; + + if (argc != 1 ) { + d_printf("Usage: net rpc service delete <service>\n"); + return NT_STATUS_OK; + } + + /* Open the Service Control Manager */ + status = rpccli_svcctl_OpenSCManagerW(pipe_hnd, mem_ctx, + pipe_hnd->srv_name_slash, + NULL, + SC_RIGHT_MGR_ENUMERATE_SERVICE, + &hSCM, + &result); + if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result)) { + d_fprintf(stderr, "Failed to open Service Control Manager. [%s]\n", + win_errstr(result)); + return werror_to_ntstatus(result); + } + + /* Open the Service */ + + status = rpccli_svcctl_OpenServiceW(pipe_hnd, mem_ctx, + &hSCM, + argv[0], + SERVICE_ALL_ACCESS, + &hService, + &result); + + if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result) ) { + d_fprintf(stderr, "Failed to open service. [%s]\n", + win_errstr(result)); + goto done; + } + + /* Delete the Service */ + + status = rpccli_svcctl_DeleteService(pipe_hnd, mem_ctx, + &hService, + &result); + + if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result) ) { + d_fprintf(stderr, "Delete service request failed. [%s]\n", + win_errstr(result)); + goto done; + } + + d_printf("Successfully deleted Service: %s\n", argv[0]); + + done: + if (is_valid_policy_hnd(&hService)) { + rpccli_svcctl_CloseServiceHandle(pipe_hnd, mem_ctx, &hService, NULL); + } + if (is_valid_policy_hnd(&hSCM)) { + rpccli_svcctl_CloseServiceHandle(pipe_hnd, mem_ctx, &hSCM, NULL); + } + + return werror_to_ntstatus(result); +} + +/******************************************************************** +********************************************************************/ + +static NTSTATUS rpc_service_create_internal(struct net_context *c, + const DOM_SID *domain_sid, + const char *domain_name, + struct cli_state *cli, + struct rpc_pipe_client *pipe_hnd, + TALLOC_CTX *mem_ctx, + int argc, + const char **argv) +{ + struct policy_handle hSCM, hService; + WERROR result = WERR_GENERAL_FAILURE; + NTSTATUS status; + const char *ServiceName; + const char *DisplayName; + const char *binary_path; + + if (argc != 3) { + d_printf("Usage: net rpc service create <service> <displayname> <binarypath>\n"); + return NT_STATUS_OK; + } + + /* Open the Service Control Manager */ + status = rpccli_svcctl_OpenSCManagerW(pipe_hnd, mem_ctx, + pipe_hnd->srv_name_slash, + NULL, + SC_RIGHT_MGR_CREATE_SERVICE, + &hSCM, + &result); + if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result)) { + d_fprintf(stderr, "Failed to open Service Control Manager. [%s]\n", + win_errstr(result)); + return werror_to_ntstatus(result); + } + + /* Create the service */ + + ServiceName = argv[0]; + DisplayName = argv[1]; + binary_path = argv[2]; + + status = rpccli_svcctl_CreateServiceW(pipe_hnd, mem_ctx, + &hSCM, + ServiceName, + DisplayName, + SERVICE_ALL_ACCESS, + SERVICE_TYPE_WIN32_OWN_PROCESS, + SVCCTL_DEMAND_START, + SVCCTL_SVC_ERROR_NORMAL, + binary_path, + NULL, /* LoadOrderGroupKey */ + NULL, /* TagId */ + NULL, /* dependencies */ + 0, /* dependencies_size */ + NULL, /* service_start_name */ + NULL, /* password */ + 0, /* password_size */ + &hService, + &result); + + if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result) ) { + d_fprintf(stderr, "Create service request failed. [%s]\n", + win_errstr(result)); + goto done; + } + + d_printf("Successfully created Service: %s\n", argv[0]); + + done: + if (is_valid_policy_hnd(&hService)) { + rpccli_svcctl_CloseServiceHandle(pipe_hnd, mem_ctx, &hService, NULL); + } + if (is_valid_policy_hnd(&hSCM)) { + rpccli_svcctl_CloseServiceHandle(pipe_hnd, mem_ctx, &hSCM, NULL); + } + + return werror_to_ntstatus(result); +} + +/******************************************************************** +********************************************************************/ + static int rpc_service_list(struct net_context *c, int argc, const char **argv ) { if (c->display_usage) { @@ -727,6 +882,38 @@ static int rpc_service_status(struct net_context *c, int argc, const char **argv /******************************************************************** ********************************************************************/ +static int rpc_service_delete(struct net_context *c, int argc, const char **argv) +{ + if (c->display_usage) { + d_printf("Usage:\n" + "net rpc service delete <service>\n" + " Delete a Win32 service\n"); + return 0; + } + + return run_rpc_command(c, NULL, &ndr_table_svcctl.syntax_id, 0, + rpc_service_delete_internal, argc, argv); +} + +/******************************************************************** +********************************************************************/ + +static int rpc_service_create(struct net_context *c, int argc, const char **argv) +{ + if (c->display_usage) { + d_printf("Usage:\n" + "net rpc service create <service>\n" + " Create a Win32 service\n"); + return 0; + } + + return run_rpc_command(c, NULL, &ndr_table_svcctl.syntax_id, 0, + rpc_service_create_internal, argc, argv); +} + +/******************************************************************** +********************************************************************/ + int net_rpc_service(struct net_context *c, int argc, const char **argv) { struct functable func[] = { @@ -778,6 +965,23 @@ int net_rpc_service(struct net_context *c, int argc, const char **argv) "net rpc service status\n" " View current status of a service" }, + { + "delete", + rpc_service_delete, + NET_TRANSPORT_RPC, + "Delete a service", + "net rpc service delete\n" + " Deletes a service" + }, + { + "create", + rpc_service_create, + NET_TRANSPORT_RPC, + "Create a service", + "net rpc service create\n" + " Creates a service" + }, + {NULL, NULL, 0, NULL, NULL} }; diff --git a/source3/utils/ntlm_auth.c b/source3/utils/ntlm_auth.c index 9bc0c60b7b..7899bd0d07 100644 --- a/source3/utils/ntlm_auth.c +++ b/source3/utils/ntlm_auth.c @@ -1251,8 +1251,6 @@ static void manage_gss_spnego_request(struct ntlm_auth_state *state, &principal, &pac_data, &ap_rep, &session_key, True); - talloc_destroy(mem_ctx); - /* Now in "principal" we have the name we are authenticated as. */ @@ -1274,9 +1272,9 @@ static void manage_gss_spnego_request(struct ntlm_auth_state *state, user = SMB_STRDUP(principal); data_blob_free(&ap_rep); - - SAFE_FREE(principal); } + + TALLOC_FREE(mem_ctx); } #endif diff --git a/source3/utils/pdbedit.c b/source3/utils/pdbedit.c index a5bc0c9bd4..328b2cb1f4 100644 --- a/source3/utils/pdbedit.c +++ b/source3/utils/pdbedit.c @@ -847,13 +847,6 @@ int main (int argc, char **argv) POPT_TABLEEND }; - /* we shouldn't have silly checks like this */ - if (getuid() != 0) { - d_fprintf(stderr, "You must be root to use pdbedit\n"); - TALLOC_FREE(frame); - return -1; - } - bin = bout = bdef = NULL; load_case_tables(); |