Olf fashioned 'anonynous' FTP 'incoming' directory

Dirk-Willem van Gulik dirk-willem.van.gulik at bbc.co.uk
Wed Jan 5 12:53:41 MST 2011


Was looking for FTP style incoming directory functionality in CIFS (windows or unix).

I.e. where you have a dir "incoming" with x--x--x--  - in which you can put stuff; And you can even get it out if you know the exact name. But directory listings are dis-allowed. I.e. like:

	$ mkdir -p foo/bar
  	$ echo Hi > foo/bar/test
  	$ chmod a-rw foo
  	$ ls foo
	ls: foo: Permission denied 
 	$ cat foo/bar/test
	Hi
	$ ls -la foo/bar
	total 6 
	drwxr-xr-x 2 dirkx dirkx 512 Jan 5 20:51 . 
	d--x--x--x 3 dirkx dirkx 512 Jan 5 20:51 .. 
	-rw-r--r-- 1 dirkx dirkx   3 Jan 5 20:51 test 
	$ ls foo 
	ls: foo: Permission denied 
	$

And found that I could not really do this cleanly/neatly with veto/hidden or permissions - as OpenDir is called from filename.c/dir.c for every path element - rather than evaluating it 'unix style'.

Is that correct ? Or is there a clean/rock-solid way (in the light of caching) which works ?

So I ended up hacking below into the 'opendir' -- as a special case. Which works well... but am guessing that this is not the right approach.

Any advice ?

Dw.



static SMB_STRUCT_DIR *vfswrap_opendir(vfs_handle_struct *handle,  const char *fname, const char *mask, uint32 attr)
{
	SMB_STRUCT_DIR *result;

	START_PROFILE(syscall_opendir);
	result = sys_opendir(fname);
#ifDEF FTP_HIDDENDIR
	if (!result) {
		/* Rather than return an error right away - make an exception for a FTP incoming style (no R, no R but X on all)
		 * and if that is indeed the leaf - show an empty dir - but allow pass through.
		 */
                struct stat dirstat;
                if ((stat(fname, &dirstat) != 0) || ((dirstat.st_mode & (S_IRWXU|S_IRWXG|S_IRWXO)) != (S_IXUSR|S_IXGRP|S_IXOTH))) {
                        return NULL;
                }
		result = sys_opendir(FTP_HIDDENDIR);
		DEBUG(3,("Cont. with a empty dir struct - as we detected a rwXrwXrwX 'hidden' dir.\n"));
        }
#endif
	END_PROFILE(syscall_opendir);
	return result;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4817 bytes
Desc: not available
URL: <http://lists.samba.org/pipermail/samba-technical/attachments/20110105/285df691/attachment.bin>


More information about the samba-technical mailing list