~ubuntu-branches/debian/squeeze/netatalk/squeeze

« back to all changes in this revision

Viewing changes to contrib/patches/patch.mangled_trash_with_ip

  • Committer: Bazaar Package Importer
  • Author(s): Bhavani Shankar
  • Date: 2009-02-02 19:59:05 UTC
  • mfrom: (8.2.1 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090202195905-732t6wxk8jzsb91r
Tags: 2.0.4~beta2-4.1ubuntu1
* Merge from Debian unstable. Remaining Ubuntu changes: LP: #318665
  - Changed dependency from libdb-dev to libdb4.6-dev to correct
    FTBFS due to an issue caused by mismatches on installed binaries
    and development headers (db4.7 is installed under a different soname
    which breaks a check in netatalk) (LP: #262991)
  - debian/control:
    + Replace libltdl3-dev with libltdl7-dev.
    + Recommend db4.6-util instead of db4.2-util as we build netatalk with
      db4.6.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
Workaround for Network Trash and system without byte locking (broken nfs/afs)
2
 
mangle OS9 "Network Trash Folder/Trash Can #2" name to
3
 
"Network Trash Folder/Trash Can #2.<client ip>.<tcp port>"
4
 
So multiple clients can share the same volume and have a working trash.
5
 
 
6
 
Index: etc/afpd/directory.c
7
 
===================================================================
8
 
RCS file: /cvsroot/netatalk/netatalk/etc/afpd/directory.c,v
9
 
retrieving revision 1.71.2.4.2.12
10
 
diff -u -r1.71.2.4.2.12 directory.c
11
 
--- etc/afpd/directory.c        11 Mar 2004 16:16:40 -0000      1.71.2.4.2.12
12
 
+++ etc/afpd/directory.c        21 Apr 2004 12:42:03 -0000
13
 
@@ -554,6 +554,7 @@
14
 
  * attempt to extend the current dir. tree to include path
15
 
  * as a side-effect, movecwd to that point and return the new dir
16
 
  */
17
 
+
18
 
 static struct dir *
19
 
             extenddir( vol, dir, path )
20
 
 struct vol     *vol;
21
 
@@ -563,7 +564,25 @@
22
 
     char *save_m_name;
23
 
 
24
 
     if ( path->u_name == NULL) {
25
 
-        path->u_name = mtoupath(vol, path->m_name, dir->d_did, (path->m_type==3) );
26
 
+#ifdef DISABLE_LOCKING
27
 
+        int l = strlen(TRASH_PREFIX);
28
 
+        /* XXX replace mac name with unix name */
29
 
+       if (vol->v_trash_id && vol->v_trash_id  == dir->d_did && vol->v_ip &&
30
 
+              !strncmp(TRASH_PREFIX , path->m_name, l ) )
31
 
+       {
32
 
+           static char temp[MAXPATHLEN + 1];
33
 
+           char *u;
34
 
+
35
 
+           strcpy(temp, path->m_name);
36
 
+           u = temp +l;
37
 
+           strcat(temp, ".");
38
 
+           strcat(temp, vol->v_ip);
39
 
+           path->u_name = temp;
40
 
+       
41
 
+       }
42
 
+        else 
43
 
+#endif
44
 
+            path->u_name = mtoupath(vol, path->m_name, dir->d_did, (path->m_type==3) );
45
 
     }
46
 
     path->dir = NULL;
47
 
 
48
 
Index: etc/afpd/enumerate.c
49
 
===================================================================
50
 
RCS file: /cvsroot/netatalk/netatalk/etc/afpd/enumerate.c,v
51
 
retrieving revision 1.39.2.2.2.4
52
 
diff -u -r1.39.2.2.2.4 enumerate.c
53
 
--- etc/afpd/enumerate.c        11 Mar 2004 02:01:59 -0000      1.39.2.2.2.4
54
 
+++ etc/afpd/enumerate.c        21 Apr 2004 12:42:04 -0000
55
 
@@ -54,9 +54,39 @@
56
 
     if (id == 0) {
57
 
         return NULL;
58
 
     }
59
 
+    
60
 
+#ifdef DISABLE_LOCKING
61
 
+    if (!path->m_name) {
62
 
+        int l = strlen(TRASH_PREFIX);
63
 
+        /* XXX */
64
 
+       if (vol->v_trash_id && vol->v_trash_id  == dir->d_did && vol->v_ip &&
65
 
+              !strncmp(TRASH_PREFIX , upath, l ) )
66
 
+       {
67
 
+           static char temp[MAXPATHLEN + 1];
68
 
+           char *u;
69
 
+
70
 
+           strcpy(temp, upath);
71
 
+           u = temp +l;
72
 
+           
73
 
+           while (*u >= '0' && *u <= '9') {
74
 
+               u++;
75
 
+           }
76
 
+           if (*u == '.') {
77
 
+               *u = '\0';
78
 
+           }
79
 
+           path->m_name = temp; 
80
 
+       }
81
 
+           
82
 
+        else if(!(path->m_name = utompath(vol, upath, id , utf8_encoding()))) {
83
 
+           return NULL;
84
 
+        }
85
 
+    }
86
 
+#else 
87
 
     if (!path->m_name && !(path->m_name = utompath(vol, upath, id , utf8_encoding()))) {
88
 
-        return NULL;
89
 
+       return NULL;
90
 
     }
91
 
+#endif
92
 
+    
93
 
     name  = path->m_name;    
94
 
     if ((cdir = dirnew(name, upath)) == NULL) {
95
 
         LOG(log_error, logtype_afpd, "adddir: malloc: %s", strerror(errno) );
96
 
@@ -185,6 +215,32 @@
97
 
     return name;
98
 
 }
99
 
 
100
 
+#ifdef DISABLE_LOCKING
101
 
+/* ----------------------------- */
102
 
+int check_trash(const struct vol *vol, char *name)
103
 
+{
104
 
+int l = strlen(TRASH_PREFIX);
105
 
+char *u;
106
 
+
107
 
+    if (strncmp(TRASH_PREFIX , name, l)) 
108
 
+        return 0;
109
 
+    /* */
110
 
+    u = name +l;
111
 
+    while (*u >= '0' && *u <= '9') {
112
 
+        u++;
113
 
+    }
114
 
+
115
 
+    if (u == name +l)
116
 
+        return 0;
117
 
+
118
 
+    if (*u == '.' && !strcmp(vol->v_ip, u +1)) {
119
 
+        return 0;
120
 
+    }
121
 
+    /* hide this one */
122
 
+    return 1;
123
 
+}
124
 
+#endif
125
 
+
126
 
 /* ----------------------------- */
127
 
 int 
128
 
 for_each_dirent(const struct vol *vol, char *name, dir_loop fn, void *data)
129
 
@@ -193,15 +249,28 @@
130
 
     struct dirent      *de;
131
 
     char            *m_name;
132
 
     int             ret;
133
 
+#ifdef DISABLE_LOCKING
134
 
+    int             mangle_trash = 0;
135
 
+#endif
136
 
     
137
 
     if (NULL == ( dp = opendir( name)) ) {
138
 
         return -1;
139
 
     }
140
 
+
141
 
+#ifdef DISABLE_LOCKING
142
 
+    if (vol->v_trash_id && vol->v_trash_id == curdir->d_did && !strcmp(name, ".")) {
143
 
+        mangle_trash = 1;
144
 
+    }
145
 
+#endif    
146
 
     ret = 0;
147
 
     for ( de = readdir( dp ); de != NULL; de = readdir( dp )) {
148
 
         if (!(m_name = check_dirent(vol, de->d_name)))
149
 
             continue;
150
 
 
151
 
+#ifdef DISABLE_LOCKING
152
 
+        if (mangle_trash && check_trash(vol, de->d_name))
153
 
+            continue;
154
 
+#endif
155
 
         ret++;
156
 
         if (fn && fn(de,m_name, data) < 0) {
157
 
            closedir(dp);
158
 
Index: etc/afpd/volume.c
159
 
===================================================================
160
 
RCS file: /cvsroot/netatalk/netatalk/etc/afpd/volume.c,v
161
 
retrieving revision 1.51.2.7.2.28
162
 
diff -u -r1.51.2.7.2.28 volume.c
163
 
--- etc/afpd/volume.c   6 Apr 2004 23:29:37 -0000       1.51.2.7.2.28
164
 
+++ etc/afpd/volume.c   21 Apr 2004 12:42:05 -0000
165
 
@@ -73,7 +73,11 @@
166
 
 
167
 
 static struct vol *Volumes = NULL;
168
 
 static u_int16_t       lastvid = 0;
169
 
-static char            *Trash = "\02\024Network Trash Folder";
170
 
+
171
 
+/* type, len, name */
172
 
+static char            *Trash2 = "\02\024Network Trash Folder";
173
 
+/* type, hint (4 bytes), len (2bytes), name */
174
 
+static char            *Trash3 = "\03\0\0\0\0\0\024Network Trash Folder";
175
 
 
176
 
 static struct extmap   *Extmap = NULL, *Defextmap = NULL;
177
 
 static int              Extmap_cnt;
178
 
@@ -1038,6 +1042,10 @@
179
 
     free(vol->v_forceuid);
180
 
     free(vol->v_forcegid);
181
 
 #endif /* FORCE_UIDGID */
182
 
+
183
 
+#ifdef DISABLE_LOCKING
184
 
+    free(vol->v_ip);
185
 
+#endif    
186
 
 }
187
 
 
188
 
 /* ------------------------------- */
189
 
@@ -1730,9 +1738,31 @@
190
 
                goto openvol_err;
191
 
            }
192
 
        }
193
 
-       else {
194
 
-            p = Trash;
195
 
-            cname( volume, volume->v_dir, &p );
196
 
+#ifndef DISABLE_LOCKING        
197
 
+       else 
198
 
+#endif 
199
 
+        {
200
 
+            struct path *s_path;
201
 
+
202
 
+            /* use the right name format */
203
 
+            p = (afp_version>= 30)?Trash3:Trash2;
204
 
+            s_path = cname( volume, volume->v_dir, &p );
205
 
+#ifdef DISABLE_LOCKING
206
 
+            if (s_path && *s_path->m_name == '\0' ) {
207
 
+                /* XXXX should do the same with ASP, could use volxlate but there's ':' in $p */
208
 
+                if (obj->proto == AFPPROTO_DSI) {
209
 
+                    DSI *dsi = obj->handle;
210
 
+                
211
 
+                    /* cname moved into dest folder */
212
 
+                    volume->v_trash_id = curdir->d_did;
213
 
+                    volume->v_ip = malloc(MAXPATHLEN +1);
214
 
+                    if (volume->v_ip) {
215
 
+                        sprintf(volume->v_ip, "%s.%u", inet_ntoa(dsi->client.sin_addr),
216
 
+                              ntohs(dsi->client.sin_port));
217
 
+                    }
218
 
+                }
219
 
+            }
220
 
+#endif
221
 
         }
222
 
         return( AFP_OK );
223
 
     }
224
 
Index: etc/afpd/volume.h
225
 
===================================================================
226
 
RCS file: /cvsroot/netatalk/netatalk/etc/afpd/volume.h,v
227
 
retrieving revision 1.19.2.5.2.6
228
 
diff -u -r1.19.2.5.2.6 volume.h
229
 
--- etc/afpd/volume.h   11 Mar 2004 02:02:04 -0000      1.19.2.5.2.6
230
 
+++ etc/afpd/volume.h   21 Apr 2004 12:42:05 -0000
231
 
@@ -81,6 +81,12 @@
232
 
     /* adouble indirection */
233
 
     int                 (*validupath)(const struct vol *, const char *);
234
 
     char                *(*ad_path)(const char *, int);
235
 
+
236
 
+#ifdef DISABLE_LOCKING
237
 
+    /* for OS 9 trash when there's no working byte locking (afs, nfs) */
238
 
+    cnid_t             v_trash_id;
239
 
+    char               *v_ip;
240
 
+#endif    
241
 
 };
242
 
 
243
 
 #ifdef NO_LARGE_VOL_SUPPORT
244
 
@@ -167,6 +173,8 @@
245
 
 #define VOLPBIT_BSIZE   11        /* block size */
246
 
 
247
 
 
248
 
+#define TRASH_PREFIX "Trash Can #"
249
 
+
250
 
 #define vol_noadouble(vol) (((vol)->v_flags & AFPVOL_NOADOUBLE) ? \
251
 
                            ADFLAGS_NOADOUBLE : 0)
252
 
 #ifdef AFP3x