Samba network recycle bin
Eelco Vriezekolk
eelco at nexus.com.na
Thu Nov 1 13:10:08 GMT 2001
This is the patch I use. No warranties other than that it seems to
work fine for me. Hope that the line-wrapping doesn't mess this up.
diff -Nabur samba-2.2.2-orig/source/include/proto.h samba-2.2.2/source/include/proto.h
--- samba-2.2.2-orig/source/include/proto.h Sat Oct 13 23:09:22 2001
+++ samba-2.2.2/source/include/proto.h Tue Oct 23 12:49:37 2001
@@ -1909,6 +1909,7 @@
char *lp_hide_files(int );
char *lp_veto_oplocks(int );
char *lp_driverlocation(int );
+char *lp_recyclebin(int );
BOOL lp_msdfs_root(int );
BOOL lp_autoloaded(int );
BOOL lp_preexec_close(int );
diff -Nabur samba-2.2.2-orig/source/param/loadparm.c samba-2.2.2/source/param/loadparm.c
--- samba-2.2.2-orig/source/param/loadparm.c Sat Oct 13 23:09:31 2001
+++ samba-2.2.2/source/param/loadparm.c Tue Oct 23 12:49:37 2001
@@ -332,6 +332,7 @@
char *printer_admin;
char *volume;
char *fstype;
+
char *recycle_bin;
char *szVfsObjectFile;
char *szVfsOptions;
int iMinPrintSpace;
@@ -447,6 +448,7 @@
NULL,
/* printer admin */
NULL,
/* volume */
NULL,
/* fstype */
+
NULL, /* recycle_bin */
NULL,
/* vfs object */
NULL,
/* vfs options */
0,
/* iMinPrintSpace */
@@ -1034,6 +1036,7 @@
{"panic action", P_STRING, P_GLOBAL, &Globals.szPanicAction, NULL, NULL, 0},
{"hide local users", P_BOOL, P_GLOBAL, &Globals.bHideLocalUsers, NULL,
NULL, 0},
+
{"recycle bin", P_STRING, P_LOCAL, &sDefault.recycle_bin, NULL, NULL, FLAG_SHARE},
{"VFS options", P_SEP, P_SEPARATOR},
@@ -1660,6 +1663,7 @@
FN_LOCAL_STRING(lp_hide_files, szHideFiles)
FN_LOCAL_STRING(lp_veto_oplocks, szVetoOplockFiles)
FN_LOCAL_STRING(lp_driverlocation, szPrinterDriverLocation)
+FN_LOCAL_STRING(lp_recyclebin,recycle_bin)
FN_LOCAL_BOOL(lp_msdfs_root, bMSDfsRoot)
FN_LOCAL_BOOL(lp_autoloaded, autoloaded)
FN_LOCAL_BOOL(lp_preexec_close, bPreexecClose)
diff -Nabur samba-2.2.2-orig/source/smbd/reply.c samba-2.2.2/source/smbd/reply.c
--- samba-2.2.2-orig/source/smbd/reply.c Sat Oct 13 23:09:41 2001
+++ samba-2.2.2/source/smbd/reply.c Tue Oct 23 12:49:37 2001
@@ -1960,6 +1960,63 @@
return(True);
}
+/********************************************************************
+check if file should be recycled
+*********************************************************************/
+static int recycle(connection_struct *conn, char *fname, char *recycle_bin)
+{
+ char *base, *ext;
+ pstring bin;
+ int i=1, len, addlen;
+
+ SMB_BIG_UINT dfree,dsize,bsize;
+
+ if(!recycle_bin || !*recycle_bin) {
+ DEBUG(3, ("recycle bin: share parameter not set, purging %s...\n", fname));
+ return vfs_unlink(conn,fname);
+ }
+
+ if(get_file_size(fname) == 0) {
+ DEBUG(3, ("recycle bin: file %s is empty, purging...\n", fname));
+ return vfs_unlink(conn,fname);
+ }
+
+ base = strrchr(fname, '/') + 1;
+ if(base == (char*)1) base = fname;
+
+ ext = strrchr(base, '.');
+
+ pstrcpy(bin, recycle_bin);
+ pstrcat(bin, "/");
+ pstrcat(bin, base);
+
+ if(strcmp(fname,bin) == 0) {
+ DEBUG(3, ("recycle bin: file %s exists, purging...\n", fname));
+ return vfs_unlink(conn,fname);
+ }
+
+ if(!directory_exist(recycle_bin,NULL)) {
+ vfs_mkdir(conn,recycle_bin,unix_mode(conn,aDIR,recycle_bin));
+ }
+
+ len = strlen(bin);
+ addlen = sizeof(pstring)-len-1;
+ while(vfs_file_exist(conn,bin, NULL)) {
+ slprintf(bin+len, addlen, " (Copy #%d)", i++);
+ pstrcat(bin, ext);
+ }
+
+ DEBUG(3, ("recycle bin: moving source=%s to dest=%s\n", fname, bin));
+ sys_disk_free(".",True,&bsize,&dfree,&dsize);
+ if((unsigned int)dfree > 0) {
+ DEBUG(3, ("recycle bin: move successful\n"));
+ return rename(fname, bin);
+ } else {
+ DEBUG(3, ("recycle bin: move failed, purging...\n"));
+ return vfs_unlink(conn,fname);
+ }
+}
+
/****************************************************************************
The guts of the unlink command, split out so it may be called by the NT SMB
code.
@@ -1971,6 +2028,7 @@
pstring directory;
pstring mask;
char *p;
+ char *recycle_bin = lp_recyclebin(SNUM(conn));
int count=0;
int error = ERRnoaccess;
BOOL has_wild;
@@ -2010,7 +2068,7 @@
if (!has_wild) {
pstrcat(directory,"/");
pstrcat(directory,mask);
- if (can_delete(directory,conn,dirtype) && !vfs_unlink(conn,directory))
+ if (can_delete(directory,conn,dirtype) && !recycle(conn, directory, recycle_bin))
count++;
if (!count)
exists = vfs_file_exist(conn,directory,&sbuf);
@@ -2043,7 +2101,7 @@
error = ERRnoaccess;
slprintf(fname,sizeof(fname)-1, "%s/%s",directory,dname);
if (!can_delete(fname,conn,dirtype)) continue;
-
if (!vfs_unlink(conn,fname)) count++;
+
if (!recycle(conn, fname, recycle_bin)) count++;
DEBUG(3,("unlink_internals: succesful unlink [%s]\n",fname));
}
CloseDir(dirptr);
--
Nexus Consultants cc, Eelco Vriezekolk <eelco at nexus.com.na>
Phone: +264 61 252345 AOL IM: "vriezekolk"
Fax: +264 61 250392
Mobile: +264 81 2495182
More information about the samba
mailing list