one more try: [PATCH] extended RPC-WINREG test [Re: svn commit: samba r23578]

Michael Adam ma at sernet.de
Tue Jul 10 21:39:02 GMT 2007


r23821

On Sat, Jul 07, 2007 at 10:38:16PM +0200, Michael Adam wrote:
> Hi, since nobody answered for two weeks, I'd like to ask once
> more if anyone would like to have a look at my extended winreg
> test (patch attached below). If not, I'd simply check it in
> in a couple of days.
> 
> :-)
> 
> Cheers, Michael
> 
> ----- Forwarded message from Michael Adam <ma at sernet.de> -----
> 
> Date: Fri, 22 Jun 2007 00:28:42 +0200
> From: Michael Adam <ma at sernet.de>
> To: samba-technical at lists.samba.org
> Subject: [PATCH] extended RPC-WINREG test [Re: svn commit: samba r23578]
> 
> Hi, 
> 
> I have changed samba3 behaviour of reg_deletekey to behave like
> windows in that ACCESS_DENIED is returned when trying to delete
> a key that has subkeys. 
> 
> I have also extended s4:torture/rpc/winreg.c to test to check
> for this behaviour. Attached find the patch for review.
> 
> Furthermore I found the following problems with the winreg test:
> 
> * it runs ok agains w2k3, but "smbtorture test" keys don't
>   get deleted at the end.
> * it fails against w2k (panic)
> * it fails to create keys for s3, has lots of NT_STATUS_NET_WRITE_FAULT
>   and eventually ends with "ERROR IN TEST WINREG! - Unknown error/failure"
> 
> I did not debug this much further due to lack of time mostly.
> 
> (I called "smbtorture -Uuser%pass ncacn_np:ip-address RPC-WINREG")
> 
> Cheers, Michael
> 
> On Do, Jun 21, 2007 at 10:18:42 +0000, obnox at samba.org wrote:
> > Author: obnox
> > Date: 2007-06-21 22:18:42 +0000 (Thu, 21 Jun 2007)
> > New Revision: 23578
> > 
> > WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=23578
> > 
> > Log:
> > When calling DeleteKey for a key that has subkey(s), Windows
> > returns WERR_ACCESS_DENIED. This adapts reg_deletekey to behave 
> > the same way. 
> > 
> > Michael
> > 
> > 
> > Modified:
> >    branches/SAMBA_3_0/source/registry/reg_api.c
> >    branches/SAMBA_3_0_26/source/registry/reg_api.c
> > 
> > 
> > Changeset:
> > Modified: branches/SAMBA_3_0/source/registry/reg_api.c
> > ===================================================================
> > --- branches/SAMBA_3_0/source/registry/reg_api.c	2007-06-21 22:10:41 UTC (rev 23577)
> > +++ branches/SAMBA_3_0/source/registry/reg_api.c	2007-06-21 22:18:42 UTC (rev 23578)
> > @@ -386,6 +386,7 @@
> >  	TALLOC_CTX *mem_ctx;
> >  	char *name, *end;
> >  	int num_subkeys;
> > +	struct registry_key *tmp_key;
> >  
> >  	if (!(mem_ctx = talloc_init("reg_createkey"))) return WERR_NOMEM;
> >  
> > @@ -394,18 +395,30 @@
> >  		goto error;
> >  	}
> >  
> > +	/* check if the key has subkeys */
> > +	err = reg_openkey(mem_ctx, parent, name, REG_KEY_READ, &tmp_key);
> > +	if (!W_ERROR_IS_OK(err)) {
> > +		goto error;
> > +	}
> > +	if (!W_ERROR_IS_OK(err = fill_subkey_cache(tmp_key))) {
> > +		goto error;
> > +	}
> > +	if (tmp_key->subkeys->num_subkeys > 0) {
> > +		err = WERR_ACCESS_DENIED;
> > +		goto error;
> > +	}
> > +
> > +	/* no subkeys - proceed with delete */
> >  	if ((end = strrchr(name, '\\')) != NULL) {
> > -		struct registry_key *tmp;
> > -
> >  		*end = '\0';
> >  
> >  		err = reg_openkey(mem_ctx, parent, name,
> > -				  SEC_RIGHTS_CREATE_SUBKEY, &tmp);
> > +				  SEC_RIGHTS_CREATE_SUBKEY, &tmp_key);
> >  		if (!W_ERROR_IS_OK(err)) {
> >  			goto error;
> >  		}
> >  
> > -		parent = tmp;
> > +		parent = tmp_key;
> >  		name = end+1;
> >  	}
> >  
> > 
> > Modified: branches/SAMBA_3_0_26/source/registry/reg_api.c
> > ===================================================================
> > --- branches/SAMBA_3_0_26/source/registry/reg_api.c	2007-06-21 22:10:41 UTC (rev 23577)
> > +++ branches/SAMBA_3_0_26/source/registry/reg_api.c	2007-06-21 22:18:42 UTC (rev 23578)
> > @@ -386,6 +386,7 @@
> >  	TALLOC_CTX *mem_ctx;
> >  	char *name, *end;
> >  	int num_subkeys;
> > +	struct registry_key *tmp_key;
> >  
> >  	if (!(mem_ctx = talloc_init("reg_createkey"))) return WERR_NOMEM;
> >  
> > @@ -394,18 +395,30 @@
> >  		goto error;
> >  	}
> >  
> > +	/* check if the key has subkeys */
> > +	err = reg_openkey(mem_ctx, parent, name, REG_KEY_READ, &tmp_key);
> > +	if (!W_ERROR_IS_OK(err)) {
> > +		goto error;
> > +	}
> > +	if (!W_ERROR_IS_OK(err = fill_subkey_cache(tmp_key))) {
> > +		goto error;
> > +	}
> > +	if (tmp_key->subkeys->num_subkeys > 0) {
> > +		err = WERR_ACCESS_DENIED;
> > +		goto error;
> > +	}
> > +
> > +	/* no subkeys - proceed with delete */
> >  	if ((end = strrchr(name, '\\')) != NULL) {
> > -		struct registry_key *tmp;
> > -
> >  		*end = '\0';
> >  
> >  		err = reg_openkey(mem_ctx, parent, name,
> > -				  SEC_RIGHTS_CREATE_SUBKEY, &tmp);
> > +				  SEC_RIGHTS_CREATE_SUBKEY, &tmp_key);
> >  		if (!W_ERROR_IS_OK(err)) {
> >  			goto error;
> >  		}
> >  
> > -		parent = tmp;
> > +		parent = tmp_key;
> >  		name = end+1;
> >  	}
> >  
> > 
> 
> -- 
> 
> i.A. Michael Adam
> 
> -- 
> Michael Adam <ma at sernet.de>
> SerNet GmbH, Bahnhofsallee 1b, 37081 Göttingen
> phone: +49-551-370000-0, fax: +49-551-370000-9
> AG Göttingen, HRB 2816, GF: Dr. Johannes Loxen
> http://www.SerNet.DE, mailto: Info @ SerNet.DE
> 
> Index: torture/rpc/winreg.c
> ===================================================================
> --- torture/rpc/winreg.c	(revision 23561)
> +++ torture/rpc/winreg.c	(working copy)
> @@ -30,6 +30,8 @@
>  #define TEST_KEY_BASE "smbtorture test"
>  #define TEST_KEY1 TEST_KEY_BASE "\\spottyfoot"
>  #define TEST_KEY2 TEST_KEY_BASE "\\with a SD (#1)"
> +#define TEST_KEY3 TEST_KEY_BASE "\\with a subkey"
> +#define TEST_SUBKEY TEST_KEY3 "\\subkey"
>  
>  static void init_initshutdown_String(TALLOC_CTX *mem_ctx, struct initshutdown_String *name, const char *s)
>  {
> @@ -369,6 +371,35 @@
>  	return true;
>  }
>  
> +/* DeleteKey on a key with subkey(s) should
> + * return WERR_ACCESS_DENIED. */
> +static bool test_DeleteKeyWithSubkey(struct dcerpc_pipe *p, 
> +				     TALLOC_CTX* mem_ctx,
> +				     struct policy_handle *handle, const char *key)
> +{
> +	NTSTATUS status;
> +	struct winreg_DeleteKey r;
> +
> +	printf("\ntesting DeleteKeyWithSubkey\n");
> +
> +	r.in.handle = handle;
> +	init_winreg_String(&r.in.key, key);
> +
> +	status = dcerpc_winreg_DeleteKey(p, mem_ctx, &r);
> +
> +	if (!NT_STATUS_IS_OK(status)) {
> +		printf("DeleteKeyWithSubkey failed  - %s\n", nt_errstr(status));
> +		return false;
> +	}
> +
> +	if (!W_ERROR_EQUAL(r.out.result, WERR_ACCESS_DENIED)) {
> +		printf("DeleteKeyWithSubkey failed - %s\n", win_errstr(r.out.result));
> +		return false;
> +	}
> +
> +	return true;
> +}
> +
>  static bool test_QueryInfoKey(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
>  			      struct policy_handle *handle, char *class)
>  {
> @@ -710,6 +741,7 @@
>  {
>  	struct policy_handle handle, newhandle;
>  	bool ret = true, created = false, created2 = false, deleted = false;
> +	bool created3 = false, created_subkey = false;
>  	struct winreg_OpenHKLM r;
>  	NTSTATUS status;
>  
> @@ -726,6 +758,8 @@
>  
>  	test_Cleanup(p, mem_ctx, &handle, TEST_KEY1);
>  	test_Cleanup(p, mem_ctx, &handle, TEST_KEY2);
> +	test_Cleanup(p, mem_ctx, &handle, TEST_SUBKEY);
> +	test_Cleanup(p, mem_ctx, &handle, TEST_KEY3);
>  	test_Cleanup(p, mem_ctx, &handle, TEST_KEY_BASE);
>  
>  	if (!test_CreateKey(p, mem_ctx, &handle, TEST_KEY1, NULL)) {
> @@ -787,6 +821,38 @@
>  		ret = false;
>  	}
>  
> +	if (created && test_CreateKey(p, mem_ctx, &handle, TEST_KEY3, NULL)) {
> +		created3 = true;
> +	}
> +
> +	if (created3 && 
> +	    test_CreateKey(p, mem_ctx, &handle, TEST_SUBKEY, NULL)) 
> +	{
> +		created_subkey = true;
> +	}
> +
> +	if (created_subkey && 
> +	    !test_DeleteKeyWithSubkey(p, mem_ctx, &handle, TEST_KEY3)) 
> +	{
> +		printf("DeleteKeyWithSubkey failed "
> +		       "(DeleteKey didn't return ACCESS_DENIED)\n");
> +		ret = false;
> +	}
> +
> +	if (created_subkey && 
> +	    !test_DeleteKey(p, mem_ctx, &handle, TEST_SUBKEY))
> +	{
> +		printf("DeleteKey failed\n");
> +		ret = false;
> +	}
> +
> +	if (created3 &&
> +	    !test_DeleteKey(p, mem_ctx, &handle, TEST_KEY3))
> +	{
> +		printf("DeleteKey failed\n");
> +		ret = false;
> +	}
> +
>  	/* The HKCR hive has a very large fanout */
>  
>  	if (open_fn == (void *)dcerpc_winreg_OpenHKCR) {
> 
> 
> ----- End forwarded message -----
> 
> -- 
> 
> i.A. Michael Adam
> 
> -- 
> Michael Adam <ma at sernet.de>
> SerNet GmbH, Bahnhofsallee 1b, 37081 Göttingen
> phone: +49-551-370000-0, fax: +49-551-370000-9
> AG Göttingen, HRB 2816, GF: Dr. Johannes Loxen
> http://www.SerNet.DE, mailto: Info @ SerNet.DE

-- 

i.A. Michael Adam

-- 
Michael Adam <ma at sernet.de>
SerNet GmbH, Bahnhofsallee 1b, 37081 Göttingen
phone: +49-551-370000-0, fax: +49-551-370000-9
AG Göttingen, HRB 2816, GF: Dr. Johannes Loxen
http://www.SerNet.DE, mailto: Info @ SerNet.DE


More information about the samba-technical mailing list