示例#1
0
static int net_registry_enumerate(struct net_context *c, int argc,
				  const char **argv)
{
	WERROR werr;
	struct registry_key *key = NULL;
	TALLOC_CTX *ctx = talloc_stackframe();
	char *subkey_name;
	NTTIME modtime;
	uint32_t count;
	char *valname = NULL;
	struct registry_value *valvalue = NULL;
	int ret = -1;

	if (argc != 1 || c->display_usage) {
		d_printf("Usage:    net registry enumerate <path>\n");
		d_printf("Example:  net registry enumerate "
			 "'HKLM\\Software\\Samba'\n");
		goto done;
	}

	werr = open_key(ctx, argv[0], REG_KEY_READ, &key);
	if (!W_ERROR_IS_OK(werr)) {
		d_fprintf(stderr, "open_key failed: %s\n", win_errstr(werr));
		goto done;
	}

	for (count = 0;
	     werr = reg_enumkey(ctx, key, count, &subkey_name, &modtime),
	     W_ERROR_IS_OK(werr);
	     count++)
	{
		print_registry_key(subkey_name, &modtime);
	}
	if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS, werr)) {
		goto done;
	}

	for (count = 0;
	     werr = reg_enumvalue(ctx, key, count, &valname, &valvalue),
	     W_ERROR_IS_OK(werr);
	     count++)
	{
		print_registry_value_with_name(valname, valvalue);
	}
	if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS, werr)) {
		goto done;
	}

	ret = 0;
done:
	TALLOC_FREE(ctx);
	return ret;
}
示例#2
0
文件: patchfile.c 项目: gojdic/samba
static WERROR reg_diff_apply_set_value(void *_ctx, const char *path,
				       const char *value_name,
				       uint32_t value_type, DATA_BLOB value)
{
	struct registry_context *ctx = (struct registry_context *)_ctx;
	struct registry_key *tmp;
	WERROR error;

	/* Open key */
	error = reg_open_key_abs(ctx, ctx, path, &tmp);

	if (W_ERROR_EQUAL(error, WERR_BADFILE)) {
		DEBUG(0, ("Error opening key '%s'\n", path));
		return error;
	}

	/* Set value */
	error = reg_val_set(tmp, value_name,
				 value_type, value);
	if (!W_ERROR_IS_OK(error)) {
		DEBUG(0, ("Error setting value '%s'\n", value_name));
		return error;
	}

	return WERR_OK;
}
/**
 * delete all values from a key
 */
static sbcErr smbconf_reg_delete_values(struct registry_key *key)
{
	WERROR werr;
	sbcErr err;
	char *valname;
	struct registry_value *valvalue;
	uint32_t count;
	TALLOC_CTX *mem_ctx = talloc_stackframe();

	for (count = 0;
	     werr = reg_enumvalue(mem_ctx, key, count, &valname, &valvalue),
	     W_ERROR_IS_OK(werr);
	     count++)
	{
		werr = reg_deletevalue(key, valname);
		if (!W_ERROR_IS_OK(werr)) {
			err = SBC_ERR_ACCESS_DENIED;
			goto done;
		}
	}
	if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS, werr)) {
		DEBUG(1, ("smbconf_reg_delete_values: "
			  "Error enumerating values of %s: %s\n",
			  key->key->name,
			  win_errstr(werr)));
		err = SBC_ERR_ACCESS_DENIED;
		goto done;
	}

	err = SBC_ERR_OK;

done:
	talloc_free(mem_ctx);
	return err;
}
示例#4
0
WERROR rpccli_spoolss_enumprinterkey(struct rpc_pipe_client *cli,
				     TALLOC_CTX *mem_ctx,
				     struct policy_handle *handle,
				     const char *key_name,
				     const char ***key_buffer,
				     uint32_t offered)
{
	NTSTATUS status;
	WERROR werror;
	uint32_t needed;

	status = rpccli_spoolss_EnumPrinterKey(cli, mem_ctx,
					       handle,
					       key_name,
					       key_buffer,
					       offered,
					       &needed,
					       &werror);

	if (W_ERROR_EQUAL(werror, WERR_MORE_DATA)) {
		offered = needed;

		status = rpccli_spoolss_EnumPrinterKey(cli, mem_ctx,
						       handle,
						       key_name,
						       key_buffer,
						       offered,
						       &needed,
						       &werror);
	}

	return werror;
}
示例#5
0
static WERROR cmd_ls(struct regshell_context *ctx, int argc, char **argv)
{
	unsigned int i;
	WERROR error;
	uint32_t valuetype;
	DATA_BLOB valuedata;
	const char *name = NULL;

	for (i = 0; W_ERROR_IS_OK(error = reg_key_get_subkey_by_index(ctx,
								      ctx->current,
								      i,
								      &name,
								      NULL,
								      NULL)); i++) {
		printf("K %s\n", name);
	}

	if (!W_ERROR_EQUAL(error, WERR_NO_MORE_ITEMS)) {
		fprintf(stderr, "Error occurred while browsing through keys: %s\n",
			win_errstr(error));
		return error;
	}

	for (i = 0; W_ERROR_IS_OK(error = reg_key_get_value_by_index(ctx,
		ctx->current, i, &name, &valuetype, &valuedata)); i++)
		printf("V \"%s\" %s %s\n", name, str_regtype(valuetype),
			   reg_val_data_string(ctx, valuetype, valuedata));

	return WERR_OK;
}
示例#6
0
/*
 * this function is called from within a ldb transaction from the schema_fsmo module
 */
WERROR dsdb_create_prefix_mapping(struct ldb_context *ldb, struct dsdb_schema *schema, const char *full_oid)
{
	WERROR status;
	uint32_t attid;
	TALLOC_CTX *mem_ctx;
	struct dsdb_schema_prefixmap *pfm;

	mem_ctx = talloc_new(ldb);
	W_ERROR_HAVE_NO_MEMORY(mem_ctx);

	/* Read prefixes from disk*/
	status = dsdb_read_prefixes_from_ldb(ldb, mem_ctx, &pfm);
	if (!W_ERROR_IS_OK(status)) {
		DEBUG(0,("dsdb_create_prefix_mapping: dsdb_read_prefixes_from_ldb: %s\n",
			win_errstr(status)));
		talloc_free(mem_ctx);
		return status;
	}

	/* Check if there is a prefix for the oid in the prefixes array*/
	status = dsdb_schema_pfm_find_oid(pfm, full_oid, NULL);
	if (W_ERROR_IS_OK(status)) {
		/* prefix found*/
		talloc_free(mem_ctx);
		return status;
	} else if (!W_ERROR_EQUAL(status, WERR_NOT_FOUND)) {
		/* error */
		DEBUG(0,("dsdb_create_prefix_mapping: dsdb_find_prefix_for_oid: %s\n",
			win_errstr(status)));
		talloc_free(mem_ctx);
		return status;
	}

	/* Create the new mapping for the prefix of full_oid */
	status = dsdb_schema_pfm_make_attid(pfm, full_oid, &attid);
	if (!W_ERROR_IS_OK(status)) {
		DEBUG(0,("dsdb_create_prefix_mapping: dsdb_schema_pfm_make_attid: %s\n",
			win_errstr(status)));
		talloc_free(mem_ctx);
		return status;
	}

	talloc_unlink(schema, schema->prefixmap);
	schema->prefixmap = talloc_steal(schema, pfm);

	/* Update prefixMap in ldb*/
	status = dsdb_write_prefixes_from_schema_to_ldb(mem_ctx, ldb, schema);
	if (!W_ERROR_IS_OK(status)) {
		DEBUG(0,("dsdb_create_prefix_mapping: dsdb_write_prefixes_to_ldb: %s\n",
			win_errstr(status)));
		talloc_free(mem_ctx);
		return status;
	}

	DEBUG(2,(__location__ " Added prefixMap %s - now have %u prefixes\n",
		 full_oid, schema->prefixmap->length));

	talloc_free(mem_ctx);
	return status;
}
示例#7
0
文件: dfs.c 项目: AllardJ/Tomato
static bool test_GetInfoLevel(struct dcerpc_pipe *p,
			      TALLOC_CTX *mem_ctx,
			      uint16_t level,
			      const char *root)
{
	NTSTATUS status;
	struct dfs_GetInfo r;
	union dfs_Info info;

	printf("Testing GetInfo level %u on '%s'\n", level, root);

	r.in.dfs_entry_path = talloc_strdup(mem_ctx, root);
	r.in.servername = NULL;
	r.in.sharename = NULL;
	r.in.level = level;
	r.out.info = &info;

	status = dcerpc_dfs_GetInfo(p, mem_ctx, &r);
	if (!NT_STATUS_IS_OK(status)) {
		printf("GetInfo failed - %s\n", nt_errstr(status));
		return false;
	} else if (!W_ERROR_IS_OK(r.out.result) &&
		   !W_ERROR_EQUAL(WERR_NO_MORE_ITEMS, r.out.result)) {
		printf("dfs_GetInfo failed - %s\n", win_errstr(r.out.result));
		return false;
	}

	return true;
}
示例#8
0
文件: samba.c 项目: 0x24bin/winexe-1
static WERROR mount_samba_hive(struct registry_context *ctx,
			       struct tevent_context *event_ctx,
			       struct loadparm_context *lp_ctx,
			       struct auth_session_info *auth_info,
			       struct cli_credentials *creds,
			       const char *name,
			       uint32_t hive_id)
{
	WERROR error;
	struct hive_key *hive;
	const char *location;

	location = talloc_asprintf(ctx, "%s/%s.ldb",
				   lp_private_dir(lp_ctx),
				   name);

	error = reg_open_hive(ctx, location, auth_info, creds, event_ctx, lp_ctx, &hive);

	if (W_ERROR_EQUAL(error, WERR_BADFILE))
		error = reg_open_ldb_file(ctx, location, auth_info,
					  creds, event_ctx, lp_ctx, &hive);

	if (!W_ERROR_IS_OK(error))
		return error;

	return reg_mount_hive(ctx, hive, hive_id, NULL);
}
示例#9
0
WERROR rpccli_spoolss_enumjobs(struct rpc_pipe_client *cli,
			       TALLOC_CTX *mem_ctx,
			       struct policy_handle *handle,
			       uint32_t firstjob,
			       uint32_t numjobs,
			       uint32_t level,
			       uint32_t offered,
			       uint32_t *count,
			       union spoolss_JobInfo **info)
{
	NTSTATUS status;
	WERROR werror;
	uint32_t needed;
	DATA_BLOB buffer;
	struct dcerpc_binding_handle *b = cli->binding_handle;

	if (offered > 0) {
		buffer = data_blob_talloc_zero(mem_ctx, offered);
		W_ERROR_HAVE_NO_MEMORY(buffer.data);
	}

	status = dcerpc_spoolss_EnumJobs(b, mem_ctx,
					 handle,
					 firstjob,
					 numjobs,
					 level,
					 (offered > 0) ? &buffer : NULL,
					 offered,
					 count,
					 info,
					 &needed,
					 &werror);
	if (!NT_STATUS_IS_OK(status)) {
		return ntstatus_to_werror(status);
	}

	if (W_ERROR_EQUAL(werror, WERR_INSUFFICIENT_BUFFER)) {
		offered = needed;
		buffer = data_blob_talloc_zero(mem_ctx, needed);
		W_ERROR_HAVE_NO_MEMORY(buffer.data);

		status = dcerpc_spoolss_EnumJobs(b, mem_ctx,
						 handle,
						 firstjob,
						 numjobs,
						 level,
						 (offered > 0) ? &buffer : NULL,
						 offered,
						 count,
						 info,
						 &needed,
						 &werror);
	}
	if (!NT_STATUS_IS_OK(status)) {
		return ntstatus_to_werror(status);
	}

	return werror;
}
示例#10
0
static bool test_SetServiceObjectSecurity(struct torture_context *tctx,
					  struct dcerpc_pipe *p)
{
	struct svcctl_QueryServiceObjectSecurity q;
	struct svcctl_SetServiceObjectSecurity r;
	struct policy_handle h, s;
	struct dcerpc_binding_handle *b = p->binding_handle;

	uint8_t *buffer;
	uint32_t needed;

	if (!test_OpenSCManager(b, tctx, &h))
		return false;

	if (!test_OpenService(b, tctx, &h, TORTURE_DEFAULT_SERVICE, &s))
		return false;

	q.in.handle = &s;
	q.in.security_flags = SECINFO_DACL;
	q.in.offered = 0;
	q.out.buffer = NULL;
	q.out.needed = &needed;

	torture_assert_ntstatus_ok(tctx,
		dcerpc_svcctl_QueryServiceObjectSecurity_r(b, tctx, &q),
		"QueryServiceObjectSecurity failed!");

	if (W_ERROR_EQUAL(q.out.result, WERR_INSUFFICIENT_BUFFER)) {
		q.in.offered = needed;
		buffer = talloc_array(tctx, uint8_t, needed);
		q.out.buffer = buffer;
		torture_assert_ntstatus_ok(tctx,
			dcerpc_svcctl_QueryServiceObjectSecurity_r(b, tctx, &q),
			"QueryServiceObjectSecurity failed!");
	}

	torture_assert_werr_ok(tctx, q.out.result,
		"QueryServiceObjectSecurity failed!");

	r.in.handle = &s;
	r.in.security_flags = SECINFO_DACL;
	r.in.buffer = q.out.buffer;
	r.in.offered = *q.out.needed;

	torture_assert_ntstatus_ok(tctx,
		dcerpc_svcctl_SetServiceObjectSecurity_r(b, tctx, &r),
		"SetServiceObjectSecurity failed!");
	torture_assert_werr_ok(tctx, r.out.result,
		"SetServiceObjectSecurity failed!");

	if (!test_CloseServiceHandle(b, tctx, &s))
		return false;

	if (!test_CloseServiceHandle(b, tctx, &h))
		return false;

	return true;
}
示例#11
0
WERROR rpccli_spoolss_getprinterdriver2(struct rpc_pipe_client *cli,
					TALLOC_CTX *mem_ctx,
					struct policy_handle *handle,
					const char *architecture,
					uint32_t level,
					uint32_t offered,
					uint32_t client_major_version,
					uint32_t client_minor_version,
					union spoolss_DriverInfo *info,
					uint32_t *server_major_version,
					uint32_t *server_minor_version)
{
	NTSTATUS status;
	WERROR werror;
	uint32_t needed;
	DATA_BLOB buffer;

	if (offered > 0) {
		buffer = data_blob_talloc_zero(mem_ctx, offered);
		W_ERROR_HAVE_NO_MEMORY(buffer.data);
	}

	status = rpccli_spoolss_GetPrinterDriver2(cli, mem_ctx,
						  handle,
						  architecture,
						  level,
						  (offered > 0) ? &buffer : NULL,
						  offered,
						  client_major_version,
						  client_minor_version,
						  info,
						  &needed,
						  server_major_version,
						  server_minor_version,
						  &werror);
	if (W_ERROR_EQUAL(werror, WERR_INSUFFICIENT_BUFFER)) {
		offered = needed;
		buffer = data_blob_talloc_zero(mem_ctx, needed);
		W_ERROR_HAVE_NO_MEMORY(buffer.data);

		status = rpccli_spoolss_GetPrinterDriver2(cli, mem_ctx,
							  handle,
							  architecture,
							  level,
							  &buffer,
							  offered,
							  client_major_version,
							  client_minor_version,
							  info,
							  &needed,
							  server_major_version,
							  server_minor_version,
							  &werror);
	}

	return werror;
}
示例#12
0
文件: ntsvcs.c 项目: AIdrifter/samba
static bool test_PNP_GetDeviceList(struct torture_context *tctx,
				   struct dcerpc_pipe *p)
{
	struct dcerpc_binding_handle *b = p->binding_handle;
	struct PNP_GetDeviceList r;
	uint16_t *buffer = NULL;
	uint32_t length = 0;

	buffer = talloc_array(tctx, uint16_t, 0);

	r.in.filter = NULL;
	r.in.flags = CM_GETIDLIST_FILTER_SERVICE;
	r.in.length = &length;
	r.out.length = &length;
	r.out.buffer = buffer;

	torture_assert_ntstatus_ok(tctx,
		dcerpc_PNP_GetDeviceList_r(b, tctx, &r),
		"PNP_GetDeviceList failed");
	torture_assert_werr_equal(tctx, r.out.result, WERR_CM_INVALID_POINTER,
		"PNP_GetDeviceList failed");

	r.in.filter = "Spooler";

	torture_assert_ntstatus_ok(tctx,
		dcerpc_PNP_GetDeviceList_r(b, tctx, &r),
		"PNP_GetDeviceList failed");

	if (W_ERROR_EQUAL(r.out.result, WERR_CM_BUFFER_SMALL)) {
		struct PNP_GetDeviceListSize s;

		s.in.devicename = "Spooler";
		s.in.flags = CM_GETIDLIST_FILTER_SERVICE;
		s.out.size = &length;

		torture_assert_ntstatus_ok(tctx,
			dcerpc_PNP_GetDeviceListSize_r(b, tctx, &s),
			"PNP_GetDeviceListSize failed");
		torture_assert_werr_ok(tctx, s.out.result,
			"PNP_GetDeviceListSize failed");
	}

	buffer = talloc_array(tctx, uint16_t, length);

	r.in.length = &length;
	r.out.length = &length;
	r.out.buffer = buffer;

	torture_assert_ntstatus_ok(tctx,
		dcerpc_PNP_GetDeviceList_r(b, tctx, &r),
		"PNP_GetDeviceList failed");

	torture_assert_werr_ok(tctx, r.out.result,
		"PNP_GetDeviceList failed");

	return true;
}
示例#13
0
NTSTATUS printing_tdb_migrate_form(TALLOC_CTX *mem_ctx,
				   struct rpc_pipe_client *winreg_pipe,
				   const char *key_name,
				   unsigned char *data,
				   size_t length)
{
	struct dcerpc_binding_handle *b = winreg_pipe->binding_handle;
	enum ndr_err_code ndr_err;
	struct ntprinting_form r;
	struct spoolss_AddFormInfo1 f1;
	DATA_BLOB blob;
	WERROR result;

	blob = data_blob_const(data, length);

	ZERO_STRUCT(r);

	ndr_err = ndr_pull_struct_blob(&blob, mem_ctx, &r,
		   (ndr_pull_flags_fn_t)ndr_pull_ntprinting_form);
	if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
		DEBUG(2, ("Form pull failed: %s\n",
			  ndr_errstr(ndr_err)));
		return NT_STATUS_NO_MEMORY;
	}

	/* Don't migrate builtin forms */
	if (r.flag == SPOOLSS_FORM_BUILTIN) {
		return NT_STATUS_OK;
	}

	DEBUG(2, ("Migrating Form: %s\n", key_name));

	f1.form_name = key_name;
	f1.flags = r.flag;

	f1.size.width = r.width;
	f1.size.height = r.length;

	f1.area.top = r.top;
	f1.area.right = r.right;
	f1.area.bottom = r.bottom;
	f1.area.left = r.left;

	result = winreg_printer_addform1(mem_ctx,
					 b,
					 &f1);
	if (W_ERROR_EQUAL(result, WERR_FILE_EXISTS)) {
		/* Don't migrate form if it already exists. */
		result = WERR_OK;
	}
	if (!W_ERROR_IS_OK(result)) {
		return werror_to_ntstatus(result);
	}

	return NT_STATUS_OK;
}
示例#14
0
WERROR rpccli_spoolss_enumprinterdrivers(struct rpc_pipe_client *cli,
					 TALLOC_CTX *mem_ctx,
					 const char *server,
					 const char *environment,
					 uint32_t level,
					 uint32_t offered,
					 uint32_t *count,
					 union spoolss_DriverInfo **info)
{
	NTSTATUS status;
	WERROR werror;
	uint32_t needed;
	DATA_BLOB buffer;
	struct dcerpc_binding_handle *b = cli->binding_handle;

	if (offered > 0) {
		buffer = data_blob_talloc_zero(mem_ctx, offered);
		W_ERROR_HAVE_NO_MEMORY(buffer.data);
	}

	status = dcerpc_spoolss_EnumPrinterDrivers(b, mem_ctx,
						   server,
						   environment,
						   level,
						   (offered > 0) ? &buffer : NULL,
						   offered,
						   count,
						   info,
						   &needed,
						   &werror);
	if (!NT_STATUS_IS_OK(status)) {
		return ntstatus_to_werror(status);
	}

	if (W_ERROR_EQUAL(werror, WERR_INSUFFICIENT_BUFFER)) {
		offered = needed;
		buffer = data_blob_talloc_zero(mem_ctx, needed);
		W_ERROR_HAVE_NO_MEMORY(buffer.data);

		status = dcerpc_spoolss_EnumPrinterDrivers(b, mem_ctx,
						   server,
						   environment,
						   level,
						   (offered > 0) ? &buffer : NULL,
						   offered,
						   count,
						   info,
						   &needed,
						   &werror);
	}
	if (!NT_STATUS_IS_OK(status)) {
		return ntstatus_to_werror(status);
	}

	return werror;
}
示例#15
0
文件: patchfile.c 项目: gojdic/samba
/**
 * Generate diff between two registry contexts
 */
_PUBLIC_ WERROR reg_generate_diff(struct registry_context *ctx1,
				  struct registry_context *ctx2,
				  const struct reg_diff_callbacks *callbacks,
				  void *callback_data)
{
	int i;
	WERROR error;

	for (i = 0; reg_predefined_keys[i].name; i++) {
		struct registry_key *r1 = NULL, *r2 = NULL;

		error = reg_get_predefined_key(ctx1,
			reg_predefined_keys[i].handle, &r1);
		if (!W_ERROR_IS_OK(error) &&
		    !W_ERROR_EQUAL(error, WERR_BADFILE)) {
			DEBUG(0, ("Unable to open hive %s for backend 1\n",
				reg_predefined_keys[i].name));
			continue;
		}

		error = reg_get_predefined_key(ctx2,
			reg_predefined_keys[i].handle, &r2);
		if (!W_ERROR_IS_OK(error) &&
		    !W_ERROR_EQUAL(error, WERR_BADFILE)) {
			DEBUG(0, ("Unable to open hive %s for backend 2\n",
				reg_predefined_keys[i].name));
			continue;
		}

		error = reg_generate_diff_key(r1, r2,
			reg_predefined_keys[i].name, callbacks,
			callback_data);
		if (!W_ERROR_IS_OK(error)) {
			DEBUG(0, ("Unable to determine diff: %s\n",
				win_errstr(error)));
			return error;
		}
	}
	if (callbacks->done != NULL) {
		callbacks->done(callback_data);
	}
	return WERR_OK;
}
示例#16
0
static bool test_EnumPrinters_findone(struct torture_context *tctx,
                                      struct dcerpc_pipe *p,
                                      const char **printername)
{
    struct spoolss_EnumPrinters r;
    uint32_t count;
    union spoolss_PrinterInfo *info;
    uint32_t needed;
    int i;
    struct dcerpc_binding_handle *b = p->binding_handle;

    *printername = NULL;

    r.in.flags = PRINTER_ENUM_LOCAL;
    r.in.server = NULL;
    r.in.level = 1;
    r.in.buffer = NULL;
    r.in.offered = 0;
    r.out.count = &count;
    r.out.info = &info;
    r.out.needed = &needed;

    torture_assert_ntstatus_ok(tctx,
                               dcerpc_spoolss_EnumPrinters_r(b, tctx, &r),
                               "failed to enum printers");

    if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
        DATA_BLOB blob = data_blob_talloc_zero(tctx, needed);
        r.in.buffer = &blob;
        r.in.offered = needed;

        torture_assert_ntstatus_ok(tctx,
                                   dcerpc_spoolss_EnumPrinters_r(b, tctx, &r),
                                   "failed to enum printers");
    }

    torture_assert_werr_ok(tctx, r.out.result,
                           "failed to enum printers");

    for (i=0; i < count; i++) {

        if (count > 1 && strequal(info[i].info1.name, "Microsoft XPS Document Writer")) {
            continue;
        }

        torture_comment(tctx, "testing printer: %s\n",
                        info[i].info1.name);

        *printername = talloc_strdup(tctx, info[i].info1.name);

        break;
    }

    return true;
}
示例#17
0
WERROR rpccli_spoolss_getprinterdata(struct rpc_pipe_client *cli,
				     TALLOC_CTX *mem_ctx,
				     struct policy_handle *handle,
				     const char *value_name,
				     uint32_t offered,
				     enum winreg_Type *type,
				     uint32_t *needed_p,
				     uint8_t **data_p)
{
	NTSTATUS status;
	WERROR werror;
	uint32_t needed;
	uint8_t *data;
	struct dcerpc_binding_handle *b = cli->binding_handle;

	data = talloc_zero_array(mem_ctx, uint8_t, offered);
	W_ERROR_HAVE_NO_MEMORY(data);

	status = dcerpc_spoolss_GetPrinterData(b, mem_ctx,
					       handle,
					       value_name,
					       type,
					       data,
					       offered,
					       &needed,
					       &werror);
	if (!NT_STATUS_IS_OK(status)) {
		return ntstatus_to_werror(status);
	}

	if (W_ERROR_EQUAL(werror, WERR_MORE_DATA)) {
		offered = needed;
		data = talloc_zero_array(mem_ctx, uint8_t, offered);
		W_ERROR_HAVE_NO_MEMORY(data);

		status = dcerpc_spoolss_GetPrinterData(b, mem_ctx,
						       handle,
						       value_name,
						       type,
						       data,
						       offered,
						       &needed,
						       &werror);
	}
	if (!NT_STATUS_IS_OK(status)) {
		return ntstatus_to_werror(status);
	}

	*data_p = data;
	*needed_p = needed;

	return werror;
}
示例#18
0
static int net_registry_deletekey_internal(struct net_context *c, int argc,
					   const char **argv,
					   bool recursive)
{
	WERROR werr;
	char *subkeyname;
	struct registry_key *hivekey = NULL;
	TALLOC_CTX *ctx = talloc_stackframe();
	int ret = -1;

	if (argc != 1 || c->display_usage) {
		d_printf("%s\n%s",
			 _("Usage:"),
			 _("net registry deletekey <path>\n"));
		d_printf("%s\n%s",
			 _("Example:"),
			 _("net registry deletekey "
			   "'HKLM\\Software\\Samba\\smbconf.127.0.0.1'\n"));
		goto done;
	}
	if (strlen(argv[0]) == 0) {
		d_fprintf(stderr, _("error: zero length key name given\n"));
		goto done;
	}

	werr = open_hive(ctx, argv[0], REG_KEY_WRITE, &hivekey, &subkeyname);
	if (!W_ERROR_IS_OK(werr)) {
		d_fprintf(stderr, "open_hive %s: %s\n", _("failed"),
			  win_errstr(werr));
		goto done;
	}

	if (recursive) {
		werr = reg_deletekey_recursive(hivekey, subkeyname);
	} else {
		werr = reg_deletekey(hivekey, subkeyname);
	}
	if (!W_ERROR_IS_OK(werr) &&
	    !(c->opt_force && W_ERROR_EQUAL(werr, WERR_BADFILE)))
	{
		d_fprintf(stderr, "reg_deletekey %s: %s\n", _("failed"),
			  win_errstr(werr));
		goto done;
	}

	ret = 0;

done:
	TALLOC_FREE(ctx);
	return ret;
}
示例#19
0
文件: patchfile.c 项目: gojdic/samba
/**
 * The reg_diff_apply functions
 */
static WERROR reg_diff_apply_add_key(void *_ctx, const char *key_name)
{
	struct registry_context *ctx = (struct registry_context *)_ctx;
	struct registry_key *tmp;
	char *buf, *buf_ptr;
	WERROR error;

	/* Recursively create the path */
	buf = talloc_strdup(ctx, key_name);
	buf_ptr = buf;

	while (*buf_ptr++ != '\0' ) {
		if (*buf_ptr == '\\') {
			*buf_ptr = '\0';
			error = reg_key_add_abs(ctx, ctx, buf, 0, NULL, &tmp);

			if (!W_ERROR_EQUAL(error, WERR_ALREADY_EXISTS) &&
				    !W_ERROR_IS_OK(error)) {
				DEBUG(0, ("Error adding new key '%s': %s\n",
					key_name, win_errstr(error)));
				return error;
			}
			*buf_ptr++ = '\\';
		}
	}

	/* Add the key */
	error = reg_key_add_abs(ctx, ctx, key_name, 0, NULL, &tmp);

	if (!W_ERROR_EQUAL(error, WERR_ALREADY_EXISTS) &&
		    !W_ERROR_IS_OK(error)) {
		DEBUG(0, ("Error adding new key '%s': %s\n",
			key_name, win_errstr(error)));
		return error;
	}
	return WERR_OK;
}
示例#20
0
WERROR rpccli_spoolss_enumprinters(struct rpc_pipe_client *cli,
				   TALLOC_CTX *mem_ctx,
				   uint32_t flags,
				   const char *server,
				   uint32_t level,
				   uint32_t offered,
				   uint32_t *count,
				   union spoolss_PrinterInfo **info)
{
	NTSTATUS status;
	WERROR werror;
	uint32_t needed;
	DATA_BLOB buffer;

	if (offered > 0) {
		buffer = data_blob_talloc_zero(mem_ctx, offered);
		W_ERROR_HAVE_NO_MEMORY(buffer.data);
	}

	status = rpccli_spoolss_EnumPrinters(cli, mem_ctx,
					     flags,
					     server,
					     level,
					     (offered > 0) ? &buffer : NULL,
					     offered,
					     count,
					     info,
					     &needed,
					     &werror);

	if (W_ERROR_EQUAL(werror, WERR_INSUFFICIENT_BUFFER)) {
		offered = needed;
		buffer = data_blob_talloc_zero(mem_ctx, needed);
		W_ERROR_HAVE_NO_MEMORY(buffer.data);

		status = rpccli_spoolss_EnumPrinters(cli, mem_ctx,
						     flags,
						     server,
						     level,
						     (offered > 0) ? &buffer : NULL,
						     offered,
						     count,
						     info,
						     &needed,
						     &werror);
	}

	return werror;
}
示例#21
0
static BOOL test_EnumServicesStatus(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct policy_handle *h)
{
	struct svcctl_EnumServicesStatusW r;
	int i;
	NTSTATUS status;
	uint32_t resume_handle = 0;
	struct ENUM_SERVICE_STATUS *service = NULL; 

	r.in.handle = h;
	r.in.type = SERVICE_TYPE_WIN32;
	r.in.state = SERVICE_STATE_ALL;
	r.in.buf_size = 0;
	r.in.resume_handle = &resume_handle;
	r.out.service = NULL;
	r.out.resume_handle = &resume_handle;
	r.out.services_returned = 0;
	r.out.bytes_needed = 0;

	status = dcerpc_svcctl_EnumServicesStatusW(p, mem_ctx, &r);

	if (!NT_STATUS_IS_OK(status)) {
		printf("ËnumServicesStatus failed!\n");
		return False;
	}

	if (W_ERROR_EQUAL(r.out.result, WERR_MORE_DATA)) {
		r.in.buf_size = r.out.bytes_needed;
		r.out.service = talloc_size(mem_ctx, r.out.bytes_needed);
		
		status = dcerpc_svcctl_EnumServicesStatusW(p, mem_ctx, &r);

		if (!NT_STATUS_IS_OK(status)) {
			printf("ËnumServicesStatus failed!\n");
			return False;
		}

		if (!W_ERROR_IS_OK(r.out.result)) {
			printf("EnumServicesStatus failed\n");
			return False;
		}
		service = (struct ENUM_SERVICE_STATUS *)r.out.service;
	}

	for(i = 0; i < r.out.services_returned; i++) {
		printf("Type: %d, State: %d\n", service[i].status.type, service[i].status.state);
	}
		
	return True;
}
示例#22
0
文件: dfs.c 项目: AllardJ/Tomato
static bool test_EnumLevel(struct dcerpc_pipe *p,
			   TALLOC_CTX *mem_ctx,
			   uint16_t level)
{
	NTSTATUS status;
	struct dfs_Enum r;
	uint32_t total=0;
	struct dfs_EnumStruct e;
	struct dfs_Info1 s;
	struct dfs_EnumArray1 e1;
	bool ret = true;

	r.in.level = level;
	r.in.bufsize = (uint32_t)-1;
	r.in.total = &total;
	r.in.info = &e;

	e.level = r.in.level;
	e.e.info1 = &e1;
	e.e.info1->count = 0;
	e.e.info1->s = &s;
	s.path = NULL;

	printf("Testing Enum level %u\n", level);

	status = dcerpc_dfs_Enum(p, mem_ctx, &r);
	if (!NT_STATUS_IS_OK(status)) {
		printf("Enum failed - %s\n", nt_errstr(status));
		return false;
	} else if (!W_ERROR_IS_OK(r.out.result) &&
		   !W_ERROR_EQUAL(WERR_NO_MORE_ITEMS, r.out.result)) {
		printf("dfs_Enum failed - %s\n", win_errstr(r.out.result));
		return false;
	}

	if (level == 1 && r.out.total) {
		int i;
		for (i=0;i<*r.out.total;i++) {
			const char *root = r.out.info->e.info1->s[i].path;
			if (!test_GetInfo(p, mem_ctx, root)) {
				ret = false;
			}
		}

	}

	return ret;
}
示例#23
0
static bool test_QueryServiceStatusEx(struct torture_context *tctx, struct dcerpc_pipe *p)
{
	struct svcctl_QueryServiceStatusEx r;
	struct policy_handle h, s;
	NTSTATUS status;
	struct dcerpc_binding_handle *b = p->binding_handle;

	uint32_t info_level = SVC_STATUS_PROCESS_INFO;
	uint8_t *buffer;
	uint32_t offered = 0;
	uint32_t needed = 0;

	if (!test_OpenSCManager(b, tctx, &h))
		return false;

	if (!test_OpenService(b, tctx, &h, TORTURE_DEFAULT_SERVICE, &s))
		return false;

	buffer = talloc(tctx, uint8_t);

	r.in.handle = &s;
	r.in.info_level = info_level;
	r.in.offered = offered;
	r.out.buffer = buffer;
	r.out.needed = &needed;

	status = dcerpc_svcctl_QueryServiceStatusEx_r(b, tctx, &r);
	torture_assert_ntstatus_ok(tctx, status, "QueryServiceStatusEx failed!");

	if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
		r.in.offered = needed;
		buffer = talloc_array(tctx, uint8_t, needed);
		r.out.buffer = buffer;

		status = dcerpc_svcctl_QueryServiceStatusEx_r(b, tctx, &r);
		torture_assert_ntstatus_ok(tctx, status, "QueryServiceStatusEx failed!");
		torture_assert_werr_ok(tctx, r.out.result, "QueryServiceStatusEx failed!");
	}

	if (!test_CloseServiceHandle(b, tctx, &s))
		return false;

	if (!test_CloseServiceHandle(b, tctx, &h))
		return false;

	return true;
}
示例#24
0
WERROR rpccli_spoolss_getjob(struct rpc_pipe_client *cli,
			     TALLOC_CTX *mem_ctx,
			     struct policy_handle *handle,
			     uint32_t job_id,
			     uint32_t level,
			     uint32_t offered,
			     union spoolss_JobInfo *info)
{
	NTSTATUS status;
	WERROR werror;
	uint32_t needed;
	DATA_BLOB buffer;

	if (offered > 0) {
		buffer = data_blob_talloc_zero(mem_ctx, offered);
		W_ERROR_HAVE_NO_MEMORY(buffer.data);
	}

	status = rpccli_spoolss_GetJob(cli, mem_ctx,
				       handle,
				       job_id,
				       level,
				       (offered > 0) ? &buffer : NULL,
				       offered,
				       info,
				       &needed,
				       &werror);

	if (W_ERROR_EQUAL(werror, WERR_INSUFFICIENT_BUFFER)) {
		offered = needed;
		buffer = data_blob_talloc_zero(mem_ctx, needed);
		W_ERROR_HAVE_NO_MEMORY(buffer.data);

		status = rpccli_spoolss_GetJob(cli, mem_ctx,
					       handle,
					       job_id,
					       level,
					       &buffer,
					       offered,
					       info,
					       &needed,
					       &werror);
	}

	return werror;
}
示例#25
0
WERROR rpccli_spoolss_enumprinterkey(struct rpc_pipe_client *cli,
				     TALLOC_CTX *mem_ctx,
				     struct policy_handle *handle,
				     const char *key_name,
				     const char ***key_buffer,
				     uint32_t offered)
{
	NTSTATUS status;
	WERROR werror;
	uint32_t needed;
	union spoolss_KeyNames _key_buffer;
	uint32_t _ndr_size;
	struct dcerpc_binding_handle *b = cli->binding_handle;

	status = dcerpc_spoolss_EnumPrinterKey(b, mem_ctx,
					       handle,
					       key_name,
					       &_ndr_size,
					       &_key_buffer,
					       offered,
					       &needed,
					       &werror);
	if (!NT_STATUS_IS_OK(status)) {
		return ntstatus_to_werror(status);
	}

	if (W_ERROR_EQUAL(werror, WERR_MORE_DATA)) {
		offered = needed;
		status = dcerpc_spoolss_EnumPrinterKey(b, mem_ctx,
						       handle,
						       key_name,
						       &_ndr_size,
						       &_key_buffer,
						       offered,
						       &needed,
						       &werror);
	}
	if (!NT_STATUS_IS_OK(status)) {
		return ntstatus_to_werror(status);
	}

	*key_buffer = _key_buffer.string_array;

	return werror;
}
示例#26
0
WERROR rpccli_spoolss_enumprinterdataex(struct rpc_pipe_client *cli,
					TALLOC_CTX *mem_ctx,
					struct policy_handle *handle,
					const char *key_name,
					uint32_t offered,
					uint32_t *count,
					struct spoolss_PrinterEnumValues **info)
{
	NTSTATUS status;
	WERROR werror;
	uint32_t needed;
	struct dcerpc_binding_handle *b = cli->binding_handle;

	status = dcerpc_spoolss_EnumPrinterDataEx(b, mem_ctx,
						  handle,
						  key_name,
						  offered,
						  count,
						  info,
						  &needed,
						  &werror);
	if (!NT_STATUS_IS_OK(status)) {
		return ntstatus_to_werror(status);
	}

	if (W_ERROR_EQUAL(werror, WERR_MORE_DATA)) {
		offered = needed;

		status = dcerpc_spoolss_EnumPrinterDataEx(b, mem_ctx,
							  handle,
							  key_name,
							  offered,
							  count,
							  info,
							  &needed,
							  &werror);
	}
	if (!NT_STATUS_IS_OK(status)) {
		return ntstatus_to_werror(status);
	}

	return werror;
}
示例#27
0
static bool test_QueryServiceConfigW(struct torture_context *tctx,
				     struct dcerpc_pipe *p)
{
	struct svcctl_QueryServiceConfigW r;
	struct QUERY_SERVICE_CONFIG query;
	struct policy_handle h, s;
	NTSTATUS status;
	struct dcerpc_binding_handle *b = p->binding_handle;

	uint32_t offered = 0;
	uint32_t needed = 0;

	if (!test_OpenSCManager(b, tctx, &h))
		return false;

	if (!test_OpenService(b, tctx, &h, TORTURE_DEFAULT_SERVICE, &s))
		return false;

	r.in.handle = &s;
	r.in.offered = offered;
	r.out.query = &query;
	r.out.needed = &needed;

	status = dcerpc_svcctl_QueryServiceConfigW_r(b, tctx, &r);
	torture_assert_ntstatus_ok(tctx, status, "QueryServiceConfigW failed!");

	if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
		r.in.offered = needed;
		status = dcerpc_svcctl_QueryServiceConfigW_r(b, tctx, &r);
		torture_assert_ntstatus_ok(tctx, status, "QueryServiceConfigW failed!");
	}

	torture_assert_werr_ok(tctx, r.out.result, "QueryServiceConfigW failed!");

	if (!test_CloseServiceHandle(b, tctx, &s))
		return false;

	if (!test_CloseServiceHandle(b, tctx, &h))
		return false;

	return true;
}
示例#28
0
static int net_registry_getvaluesraw(struct net_context *c, int argc,
				     const char **argv)
{
	WERROR werr;
	int ret = -1;
	struct registry_key *key = NULL;
	TALLOC_CTX *ctx = talloc_stackframe();
	uint32_t idx;

	if (argc != 1 || c->display_usage) {
		d_fprintf(stderr, "usage: net rpc registry getvaluesraw "
			  "<key>\n");
		goto done;
	}

	werr = open_key(ctx, argv[0], REG_KEY_READ, &key);
	if (!W_ERROR_IS_OK(werr)) {
		d_fprintf(stderr, "open_key failed: %s\n", win_errstr(werr));
		goto done;
	}

	idx = 0;
	while (true) {
		struct registry_value *val;

		werr = reg_enumvalue(talloc_tos(), key, idx, NULL, &val);

		if (W_ERROR_EQUAL(werr, WERR_NO_MORE_ITEMS)) {
			ret = 0;
			break;
		}
		if (!W_ERROR_IS_OK(werr)) {
			break;
		}
		print_registry_value(val, true);
		TALLOC_FREE(val);
		idx += 1;
	}
done:
	TALLOC_FREE(ctx);
	return ret;
}
示例#29
0
static bool test_GetPrinter(struct torture_context *tctx,
				struct dcerpc_binding_handle *b,
				struct policy_handle *handle,
				struct test_spoolss_win_context *ctx,
				uint32_t level,
				uint32_t initial_blob_size)
{
	NTSTATUS status;
	struct spoolss_GetPrinter gp;
	DATA_BLOB blob = data_blob_talloc_zero(ctx, initial_blob_size);
	uint32_t needed;

	torture_comment(tctx, "Test GetPrinter level %d\n", level);

	gp.in.handle = handle;
	gp.in.level = level;
	gp.in.buffer = (initial_blob_size == 0)?NULL:&blob;
	gp.in.offered = initial_blob_size;
	gp.out.needed = &needed;

	status = dcerpc_spoolss_GetPrinter_r(b, tctx, &gp);
	torture_assert_ntstatus_ok(tctx, status, "GetPrinter failed");

	if (W_ERROR_EQUAL(gp.out.result, WERR_INSUFFICIENT_BUFFER)) {
		blob = data_blob_talloc_zero(ctx, needed);
		gp.in.buffer = &blob;
		gp.in.offered = needed;
		status = dcerpc_spoolss_GetPrinter_r(b, tctx, &gp);
		torture_assert_ntstatus_ok(tctx, status, "GetPrinter failed");
	}

	torture_assert_werr_ok(tctx, gp.out.result, "GetPrinter failed");

	ctx->current_info = gp.out.info;

	if (level == 2 && gp.out.info) {
		ctx->printer_has_driver = gp.out.info->info2.drivername &&
					  strlen(gp.out.info->info2.drivername);
	}

	return true;
}
示例#30
0
static bool test_EnumPrinters(struct torture_context *tctx,
				struct dcerpc_pipe *p,
				struct test_spoolss_win_context *ctx,
				uint32_t initial_blob_size)
{
	NTSTATUS status;
	struct spoolss_EnumPrinters ep;
	DATA_BLOB blob = data_blob_talloc_zero(ctx, initial_blob_size);
	uint32_t needed;
	uint32_t count;
	union spoolss_PrinterInfo *info;
	struct dcerpc_binding_handle *b = p->binding_handle;

	ep.in.flags = PRINTER_ENUM_NAME;
	ep.in.server = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
	ep.in.level = 2;
	ep.in.buffer = &blob;
	ep.in.offered = initial_blob_size;
	ep.out.needed = &needed;
	ep.out.count = &count;
	ep.out.info = &info;

	status = dcerpc_spoolss_EnumPrinters_r(b, ctx, &ep);
	torture_assert_ntstatus_ok(tctx, status, "EnumPrinters failed.");

	if (W_ERROR_EQUAL(ep.out.result, WERR_INSUFFICIENT_BUFFER)) {
		blob = data_blob_talloc_zero(ctx, needed);
		ep.in.buffer = &blob;
		ep.in.offered = needed;
		status = dcerpc_spoolss_EnumPrinters_r(b, ctx, &ep);
		torture_assert_ntstatus_ok(tctx, status,"EnumPrinters failed.");
	}

	torture_assert_werr_ok(tctx, ep.out.result, "EnumPrinters failed.");

	ctx->printer_count = count;
	ctx->printer_info = info;

	torture_comment(tctx, "Found %d printer(s).\n", ctx->printer_count);

	return true;
}