Arla 0.8 and .@sys

Assar Westerlund assar at sics.se
Thu Jul 23 04:41:27 CEST 1998


David Morrison <dave at bnl.gov> writes:
> Here's a patch to inter.c to do a more complete job of replacing all
> occurrences of `@sys' in filenames with sysname.

Thanks for sending the patch.  I fixed this based on your patch but it
turned out a little bit different.  I append my patch at the end of
this mail.

> properly - if I `cd' into a directory named `. at sys' I end up right
> back where I started!

I'm not able to get this error with the current code.  Could you try
it and see if you still get the same problem?

Index: arlad/inter.c
===================================================================
RCS file: /usr/local/cvsroot/arla/arlad/inter.c,v
retrieving revision 1.51
diff -u -w -u -w -r1.51 inter.c
--- inter.c	1998/07/22 07:03:37	1.51
+++ inter.c	1998/07/23 02:39:51
@@ -438,6 +438,47 @@
 }
 
 /*
+ * Expand `src' into `dest' (of size `dst_sz'), expanding `str' to
+ * `replacement' Return number of characters written to `dest'
+ * (excluding terminating zero) or `dst_sz' if there's not enough
+ * room.
+ */
+
+static int
+expand_sys (char *dest, size_t dst_sz, const char *src,
+	    const char *str, const char *rep)
+{
+    char *destp = dst;
+    const char *srcp = src;
+    char *s;
+    int n = 0;
+    int len;
+    size_t str_len = strlen(str);
+    size_t rep_len = strlen(rep);
+    size_t src_len = strlen(src);
+    
+    while ((s = strstr (srcp, str)) != NULL) {
+	len = s - srcp;
+
+	if (dst_sz <= n + len + rep_len)
+	    return dst_sz;
+
+	memcpy (destp, srcp, len);
+	memcpy (destp + len, rep, rep_len);
+	n += len + rep_len;
+	destp += len + rep_len;
+	srcp = s + str_len;
+    }
+    len = src_len - (srcp - src);
+    if (dst_sz <= n + len)
+	return dst_sz;
+    memcpy (destp, srcp, len);
+    n += len;
+    destp[len] = '\0';
+    return n;
+}
+
+/*
  * Find this entry in the directory. If the entry happens to point to
  * a mount point, then we follow that and return the root directory of
  * the volume. Hopefully this is the only place where we need to think
@@ -450,11 +491,19 @@
 	   VenusFid *res,
 	   CredCacheEntry** ce)
 {
+     char tmp_name[MAXPATHLEN];
      Result ret;
      int error;
 
-     if (strcmp(name, "@sys") == 0)
-	 name = arlasysname;
+     if (strstr (name, "@sys") != NULL) {
+	 if (expand_sys (tmp_name, sizeof(tmp_name), name,
+			 "@sys", arlasysname) >= sizeof(tmp_name)) {
+	     ret.res   = -1;
+	     ret.error = ENAMETOOLONG;
+	     return ret;
+	 }
+	 name = tmp_name;
+     }
 
      error = adir_lookup (dir_fid, name, res, *ce);
      if (error) {





More information about the Arla-drinkers mailing list