VFS chroot

David Collier-Brown davec-b at rogers.com
Fri Nov 16 10:07:46 MST 2012


On 11/16/2012 10:38 AM, René Klomp wrote:
> Op 16-11-2012 16:15, David Collier-Brown schreef:
>> On 11/16/2012 09:48 AM, René Klomp wrote:
>>> Hi all,
>>>
>>> I am developing a VFS module that modifies certain files in a specific
>>> way that can be different each time that file is opened
>>> To do this I want to use an external script that takes a file as input
>>> and then changes it and writes those changes to a temporary file. The
>>> temporary file then has to be served to the client.
>>>
>>> How could I best do this?
>>> I tried the following:
>>> static int my_vfs_open(vfs_handle_struct *handle, struct smb_filename
>>> *smb_fname,
>>>              files_struct *fsp, int flags, mode_t mode)
>>> {
>>>     if(strcmp(smb_fname->base_name,"test.txt")==0){
>>>         return open("test2.txt", flags, mode);
>>>     }
>>>     return SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
>>> }
>>>
>>> This works, but it is not possible to open a file outside the current
>>> share directory... So I wont be able to let a script write a file to
>>> another directory so that it wont be visible in the share.
>>> Another thing I thought about was piping the output of the external
>>> script to the user. That would probably be more efficient? Is that
>>> possible? If yes, how?
>> This sounds a little bit like software copy-on-write, so you perhaps
>> could do something like
>>      if(strcmp(smb_fname->base_name,"test.txt")==0){
>>          return open("./.invisible_copy_dir/test.txt", flags, mode);
>>
>> That's what you're doing, though, not what you *want* to be doing (:-))
>>
>> What's the thing you want?  In effect, "why?"
>>
>> --dave
> 
> I shall be more precise.
> What I want to do for example i change a certain value in a file with
> another value and then serve the file to the client. So for example
> include his/her login name or the current time somewhere in the file.
> After the file has been downloaded from the share the temp file can be
> removed again. Thats why I also thought about piping the output of my
> external script.
> My knowledge of samba's internals are still limited. This is the first
> time I develop on it.
> 
> Regards,
> Rene
> 

You will need to figure out when the user is finished editing their copy
and clean up: samba will treat opening the file with an editor the same
way as opening it with a copy program, and won't know which is an edit
versus a download.

--dave

-- 
David Collier-Brown,         | Always do right. This will gratify
System Programmer and Author | some people and astonish the rest
davecb at spamcop.net           |                      -- Mark Twain
(416) 223-8968


More information about the samba-technical mailing list