Re: permission upgrade during O_TRUNC

2003-02-03 Thread jra
On Wed, Jan 08, 2003 at 11:01:13AM +0100, Steve Hardy wrote:
> not entirely true again
> 
> the error in the current code is
> 
> S -> SR = SR
> H -> HR = HR
> 
> which should be
> 
> S -> SR = S
> H -> HR = H
> 
> that's all. Still simplifies the code.

Ok, I finally got to test this and built a torture tester
for this case. The reality is more complex, but you can see
how it works by looking at the code I just committed to
all branches.

Thanks a *lot* for your help on this !

Jeremy.



RE: permission upgrade during O_TRUNC

2003-01-08 Thread Steve Hardy
not entirely true again

the error in the current code is

S -> SR = SR
H -> HR = HR

which should be

S -> SR = S
H -> HR = H

that's all. Still simplifies the code.

Index: open.c
===
RCS file: /cvsroot/samba/source/smbd/open.c,v
retrieving revision 1.128
diff -u -r1.128 open.c
--- open.c  8 Jan 2003 02:09:14 -   1.128
+++ open.c  8 Jan 2003 09:51:50 -
@@ -717,20 +717,19 @@
 * the file attributes need to be changed.
 */

-   *returned_mode = (mode_t)0;
+   if(old_dos_mode == (mode_t)0 && new_dos_mode != (mode_t)0)
+   *returned_mode = new_dos_mode;
+   else
+   *returned_mode = (mode_t)0;

/* If we're mapping SYSTEM and HIDDEN ensure they match. */
if (lp_map_system(SNUM(conn))) {
if ((old_dos_mode & FILE_ATTRIBUTE_SYSTEM) && !(new_dos_mode &
FILE_ATTRIBUTE_SYSTEM))
return False;
-   if  (!(old_dos_mode & FILE_ATTRIBUTE_SYSTEM) && (new_dos_mode &
FILE_ATTRIBUTE_SYSTEM))
-   *returned_mode = new_mode;
}
if (lp_map_hidden(SNUM(conn))) {
if ((old_dos_mode & FILE_ATTRIBUTE_HIDDEN) && !(new_dos_mode &
FILE_ATTRIBUTE_HIDDEN))
return False;
-   if (!(old_dos_mode & FILE_ATTRIBUTE_HIDDEN) && (new_dos_mode &
FILE_ATTRIBUTE_HIDDEN))
-   *returned_mode = new_mode;
}
return True;
 }

> -Oorspronkelijk bericht-
> Van: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED]]Namens Steve Hardy
> Verzonden: Wednesday, January 08, 2003 10:42 AM
> Aan: [EMAIL PROTECTED]
> CC: [EMAIL PROTECTED]
> Onderwerp: RE: permission upgrade during O_TRUNC
>
>
> Yeah I thought about implementing it the way it's in CVS now
> but didn't dare
> touch your code :P, although I just found another instance of
> attributes
> changing the whole story goes for READONLY as well ...
>
> hmm let me make a table
>
> - H -> H
> - S -> S
> - R -> R
> - RH -> RH
> - SH -> SH
> H * -> H
> S * -> S
> R * -> R
>
> So it seems you can only upgrade the attributes if NONE of
> the original
> attributes were set, and if so, you take all of the new attributes.
> Currently the code always takes the new attributes if you're upgrading
> system or hidden so you'd get
>
> S H -> H
> H S -> S
> and worse:
> S HR -> HR
> H SR -> SR
>
> It probably doesn't make much of a difference but hey, you
> never know :)
> Makes the code easier too 'cause you get
>
> if(old_dos_mode == 0 && new_dos_mode != 0)
>   *returned_mode = new_dos_mode
>
> Which is even easier (yay!). Sorry for the part
> misinformation in previous
> posts :)
>
> grtz,
>   Steve
>
> > -Oorspronkelijk bericht-
> > Van: [EMAIL PROTECTED]
> > [mailto:[EMAIL PROTECTED]]Namens
> [EMAIL PROTECTED]
> > Verzonden: Wednesday, January 08, 2003 3:10 AM
> > Aan: [EMAIL PROTECTED]
> > CC: [EMAIL PROTECTED]
> > Onderwerp: Re: permission upgrade during O_TRUNC
> >
> >
> > On Tue, Jan 07, 2003 at 10:53:41AM +0100,
> [EMAIL PROTECTED] wrote:
> > > Hey there, I posted a quick fix for a problem I found with
> > all samba's up
> > > to 2.2.7a on the general samba list, which describes the following
> > > problem:
> > >
> > > In Windows, if you create a file with NORMAL attributes and
> > ALWAYS_CREATE,
> > > close the file and then re-create it with, say, HIDDEN and
> > ALWAYS_CREATE,
> > > the file *should* be upgraded to HIDDEN. The other way around, ie.
> > > starting with HIDDEN and re-creating with NORMAL should
> > keep the file as
> > > HIDDEN. Currently, samba always keep the original
> > attributes. This causes
> > > windows to incorrectly store hidden and system files from
> > in a roaming
> > > profile which gets you that stupid popping-up Desktop.ini
> > in new profiles
> > > after the second login (because the files are not hidden on
> > the profile
> > > directory). Why windows opens the files as non-hidden first
> > is unknown to
> > > me :) Anyways, here is a patch that fixes it. I have tried
> > my best to make
> > > it as clean as possible but as I know little of samba
> > internals it may be
> > > wrong ...
> > >
> > > This works for me, and stops Desktop.ini appearing all over
> > the place. I
> > > haven't found any problems with it yet.
> >
> > Thanks for this - I didn't apply exactly this patch but it
> inspired me
> > to write something I believe is correct. I applied it to
> HEAD and 3.0,
> > and will back-port to 2.2.x.
> >
> > Thanks once again !
> >
> > Jeremy.
> >
> > PS. Andrew Bartlett - we now pass the torture test OPEN #9 when map
> > hidden and map system are set :-).
>




RE: permission upgrade during O_TRUNC

2003-01-08 Thread Steve Hardy
Yeah I thought about implementing it the way it's in CVS now but didn't dare
touch your code :P, although I just found another instance of attributes
changing the whole story goes for READONLY as well ...

hmm let me make a table

- H -> H
- S -> S
- R -> R
- RH -> RH
- SH -> SH
H * -> H
S * -> S
R * -> R

So it seems you can only upgrade the attributes if NONE of the original
attributes were set, and if so, you take all of the new attributes.
Currently the code always takes the new attributes if you're upgrading
system or hidden so you'd get

S H -> H
H S -> S
and worse:
S HR -> HR
H SR -> SR

It probably doesn't make much of a difference but hey, you never know :)
Makes the code easier too 'cause you get

if(old_dos_mode == 0 && new_dos_mode != 0)
*returned_mode = new_dos_mode

Which is even easier (yay!). Sorry for the part misinformation in previous
posts :)

grtz,
Steve

> -Oorspronkelijk bericht-
> Van: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED]]Namens [EMAIL PROTECTED]
> Verzonden: Wednesday, January 08, 2003 3:10 AM
> Aan: [EMAIL PROTECTED]
> CC: [EMAIL PROTECTED]
> Onderwerp: Re: permission upgrade during O_TRUNC
>
>
> On Tue, Jan 07, 2003 at 10:53:41AM +0100, [EMAIL PROTECTED] wrote:
> > Hey there, I posted a quick fix for a problem I found with
> all samba's up
> > to 2.2.7a on the general samba list, which describes the following
> > problem:
> >
> > In Windows, if you create a file with NORMAL attributes and
> ALWAYS_CREATE,
> > close the file and then re-create it with, say, HIDDEN and
> ALWAYS_CREATE,
> > the file *should* be upgraded to HIDDEN. The other way around, ie.
> > starting with HIDDEN and re-creating with NORMAL should
> keep the file as
> > HIDDEN. Currently, samba always keep the original
> attributes. This causes
> > windows to incorrectly store hidden and system files from
> in a roaming
> > profile which gets you that stupid popping-up Desktop.ini
> in new profiles
> > after the second login (because the files are not hidden on
> the profile
> > directory). Why windows opens the files as non-hidden first
> is unknown to
> > me :) Anyways, here is a patch that fixes it. I have tried
> my best to make
> > it as clean as possible but as I know little of samba
> internals it may be
> > wrong ...
> >
> > This works for me, and stops Desktop.ini appearing all over
> the place. I
> > haven't found any problems with it yet.
>
> Thanks for this - I didn't apply exactly this patch but it inspired me
> to write something I believe is correct. I applied it to HEAD and 3.0,
> and will back-port to 2.2.x.
>
> Thanks once again !
>
> Jeremy.
>
> PS. Andrew Bartlett - we now pass the torture test OPEN #9 when map
> hidden and map system are set :-).




Re: permission upgrade during O_TRUNC

2003-01-07 Thread Andrew Bartlett
On Wed, 2003-01-08 at 13:10, [EMAIL PROTECTED] wrote:
> On Tue, Jan 07, 2003 at 10:53:41AM +0100, [EMAIL PROTECTED] wrote:
> > Hey there, I posted a quick fix for a problem I found with all samba's up
> > to 2.2.7a on the general samba list, which describes the following
> > problem:
> > 
> > In Windows, if you create a file with NORMAL attributes and ALWAYS_CREATE,
> > close the file and then re-create it with, say, HIDDEN and ALWAYS_CREATE,
> > the file *should* be upgraded to HIDDEN. The other way around, ie.
> > starting with HIDDEN and re-creating with NORMAL should keep the file as
> > HIDDEN. Currently, samba always keep the original attributes. This causes
> > windows to incorrectly store hidden and system files from in a roaming
> > profile which gets you that stupid popping-up Desktop.ini in new profiles
> > after the second login (because the files are not hidden on the profile
> > directory). Why windows opens the files as non-hidden first is unknown to
> > me :) Anyways, here is a patch that fixes it. I have tried my best to make
> > it as clean as possible but as I know little of samba internals it may be
> > wrong ...
> > 
> > This works for me, and stops Desktop.ini appearing all over the place. I
> > haven't found any problems with it yet.
> 
> Thanks for this - I didn't apply exactly this patch but it inspired me
> to write something I believe is correct. I applied it to HEAD and 3.0,
> and will back-port to 2.2.x.
> 
> Thanks once again !
> 
> Jeremy.
> 
> PS. Andrew Bartlett - we now pass the torture test OPEN #9 when map
> hidden and map system are set :-).

Thanks - it's good to get the build farm going green again. 

Andrew Bartlett

-- 
Andrew Bartlett [EMAIL PROTECTED]
Manager, Authentication Subsystems, Samba Team  [EMAIL PROTECTED]
Student Network Administrator, Hawker College   [EMAIL PROTECTED]
http://samba.org http://build.samba.org http://hawkerc.net



signature.asc
Description: This is a digitally signed message part


Re: permission upgrade during O_TRUNC

2003-01-07 Thread jra
On Tue, Jan 07, 2003 at 10:53:41AM +0100, [EMAIL PROTECTED] wrote:
> Hey there, I posted a quick fix for a problem I found with all samba's up
> to 2.2.7a on the general samba list, which describes the following
> problem:
> 
> In Windows, if you create a file with NORMAL attributes and ALWAYS_CREATE,
> close the file and then re-create it with, say, HIDDEN and ALWAYS_CREATE,
> the file *should* be upgraded to HIDDEN. The other way around, ie.
> starting with HIDDEN and re-creating with NORMAL should keep the file as
> HIDDEN. Currently, samba always keep the original attributes. This causes
> windows to incorrectly store hidden and system files from in a roaming
> profile which gets you that stupid popping-up Desktop.ini in new profiles
> after the second login (because the files are not hidden on the profile
> directory). Why windows opens the files as non-hidden first is unknown to
> me :) Anyways, here is a patch that fixes it. I have tried my best to make
> it as clean as possible but as I know little of samba internals it may be
> wrong ...
> 
> This works for me, and stops Desktop.ini appearing all over the place. I
> haven't found any problems with it yet.

Thanks for this - I didn't apply exactly this patch but it inspired me
to write something I believe is correct. I applied it to HEAD and 3.0,
and will back-port to 2.2.x.

Thanks once again !

Jeremy.

PS. Andrew Bartlett - we now pass the torture test OPEN #9 when map
hidden and map system are set :-).



permission upgrade during O_TRUNC

2003-01-07 Thread steve
Hey there, I posted a quick fix for a problem I found with all samba's up
to 2.2.7a on the general samba list, which describes the following
problem:

In Windows, if you create a file with NORMAL attributes and ALWAYS_CREATE,
close the file and then re-create it with, say, HIDDEN and ALWAYS_CREATE,
the file *should* be upgraded to HIDDEN. The other way around, ie.
starting with HIDDEN and re-creating with NORMAL should keep the file as
HIDDEN. Currently, samba always keep the original attributes. This causes
windows to incorrectly store hidden and system files from in a roaming
profile which gets you that stupid popping-up Desktop.ini in new profiles
after the second login (because the files are not hidden on the profile
directory). Why windows opens the files as non-hidden first is unknown to
me :) Anyways, here is a patch that fixes it. I have tried my best to make
it as clean as possible but as I know little of samba internals it may be
wrong ...

This works for me, and stops Desktop.ini appearing all over the place. I
haven't found any problems with it yet.

--- samba-2.2.7a/source/smbd/open.c Tue Dec 10 15:58:17 2002
+++ samba-2.2.7a-truncfix/source/smbd/open.cTue Jan  7 11:49:13 2003
@@ -685,6 +685,43 @@
return num_share_modes;
 }
 
+int open_upgrade_attributes(connection_struct *conn, char *path, mode_t 
+existing_mode, mode_t new_mode)
+{
+   uint32 old_dos_mode, new_dos_mode;
+   SMB_STRUCT_STAT sbuf;
+   files_struct *fsp;
+   int ret;
+
+   ZERO_STRUCT(sbuf);
+
+   sbuf.st_mode = existing_mode;
+   old_dos_mode = dos_mode(conn, path, &sbuf);
+
+   sbuf.st_mode = new_mode ;
+   new_dos_mode = old_dos_mode | (dos_mode(conn, path, &sbuf) & 
+(FILE_ATTRIBUTE_SYSTEM|FILE_ATTRIBUTE_HIDDEN));
+   
+   if(new_dos_mode != old_dos_mode) {
+   DEBUG(5,("upgrading attributes for file %s from %d to %d during 
+truncate\n",path,old_dos_mode, new_dos_mode));
+   
+   if (vfs_stat(conn,path,&sbuf))
+   return -1;
+
+   fsp = open_file_fchmod(conn,path,&sbuf);
+   if (!fsp)
+   return -1;
+   become_root();
+   ret = conn->vfs_ops.fchmod(fsp, fsp->fd, unix_mode(conn, new_dos_mode, 
+path));
+   unbecome_root();
+   close_file_fchmod(fsp);
+   
+   return ret;
+   }
+   
+   return 0;
+}  
+
+   
+
 static BOOL open_match_attributes(connection_struct *conn, char *path, mode_t 
existing_mode, mode_t new_mode)
 {
uint32 old_dos_mode, new_dos_mode;
@@ -829,6 +866,10 @@
errno = EACCES;
return NULL;
}
+   /* Upgrade attributes if the truncate specified more attributes
+* than the old file
+*/
+   open_upgrade_attributes(conn,fname, psbuf->st_mode, mode);
}
 
if (GET_FILE_OPEN_DISPOSITION(ofun) == FILE_EXISTS_FAIL)