* conf/autofs/autofs_solaris_v1.c: convert relative targets to
authorIon Badulescu <ib42@cs.columbia.edu>
Thu, 28 Aug 2003 03:10:34 +0000 (03:10 +0000)
committerIon Badulescu <ib42@cs.columbia.edu>
Thu, 28 Aug 2003 03:10:34 +0000 (03:10 +0000)
absolute paths when using lofs mounts

* conf/autofs/autofs_solaris_v2_v3.c: ditto

* conf/autofs/autofs_linux.c: ditto

ChangeLog
conf/autofs/autofs_linux.c
conf/autofs/autofs_solaris_v1.c
conf/autofs/autofs_solaris_v2_v3.c

index 61f8a2fc2fa30a58b5f89c30980b425e9279ea55..cecc2d532c3a38a8cbce2b5c7a515d86046c3836 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2003-08-27  Ion Badulescu  <ionut@moisil.badula.org>
+
+       * conf/autofs/autofs_solaris_v1.c: convert relative targets to
+       absolute paths when using lofs mounts
+
+       * conf/autofs/autofs_solaris_v2_v3.c: ditto
+
+       * conf/autofs/autofs_linux.c: ditto
+
 2003-08-27  Ion Badulescu  <ionut@buggy.badula.org>
 
        * README.autofs: added a paragraph about the resource consumption
index eaa106ec739820eacb57fb0832e60edc38453f49..ba40dccaeb7a2e48ce3e3305de3eda61a9912009 100644 (file)
@@ -38,7 +38,7 @@
  * SUCH DAMAGE.
  *
  *
- * $Id: autofs_linux.c,v 1.39 2003/08/27 04:39:37 ib42 Exp $
+ * $Id: autofs_linux.c,v 1.40 2003/08/28 03:10:34 ib42 Exp $
  *
  */
 
@@ -539,7 +539,7 @@ autofs_bind_umount(char *mountpoint)
 int
 autofs_mount_fs(am_node *mp, mntfs *mf)
 {
-  char *target;
+  char *target, *target2 = NULL;
   int err = 0;
 
   if (mf->mf_flags & MFF_ON_AUTOFS) {
@@ -583,6 +583,11 @@ autofs_mount_fs(am_node *mp, mntfs *mf)
     if (mf->mf_ops == &amfs_host_ops)
       goto use_symlink;
 
+    if (target[0] != '/')
+      target2 = str3cat(NULL, mp->am_parent->am_path, "/", target);
+    else
+      target2 = strdup(target);
+
     /*
      * We need to stat() the destination, because the bind mount does not
      * follow symlinks and/or allow for non-existent destinations.
@@ -601,26 +606,26 @@ autofs_mount_fs(am_node *mp, mntfs *mf)
     if (!foreground) {
       pid_t pgrp = getpgrp();
       setpgrp();
-      err = stat(target, &buf);
-      if (setpgid(0, pgrp)) {
+      err = stat(target2, &buf);
+      if ((err = setpgid(0, pgrp))) {
        plog(XLOG_ERROR, "autofs: cannot restore pgrp: %s", strerror(errno));
        plog(XLOG_ERROR, "autofs: aborting the mount");
-       return errno;
+       goto out;
       }
       if (err)
        goto use_symlink;
     }
-    if ((err = lstat(target, &buf)))
+    if ((err = lstat(target2, &buf)))
       goto use_symlink;
     if (S_ISLNK(buf.st_mode))
       goto use_symlink;
 
-    plog(XLOG_INFO, "autofs: bind-mounting %s -> %s", mp->am_path, target);
+    plog(XLOG_INFO, "autofs: bind-mounting %s -> %s", mp->am_path, target2);
     mkdir(mp->am_path, 0555);
-    err = mount_lofs(mp->am_path, target, mf->mf_mopts, 1);
+    err = mount_lofs(mp->am_path, target2, mf->mf_mopts, 1);
     if (err) {
       rmdir(mp->am_path);
-      plog(XLOG_INFO, "autofs: bind-mounting %s -> %s failed", mp->am_path, target);
+      plog(XLOG_INFO, "autofs: bind-mounting %s -> %s failed", mp->am_path, target2);
       goto use_symlink;
     }
     goto out;
@@ -631,6 +636,9 @@ autofs_mount_fs(am_node *mp, mntfs *mf)
   err = symlink(target, mp->am_path);
 
  out:
+  if (target2)
+    free(target2);
+
   if (err)
     return errno;
   return 0;
index 9eccf05b33a06ec79c404d73da6afabbb4e1bfdb..2c07a2a79a6defafcc465ce1f34dfd4a403f2b13 100644 (file)
@@ -38,7 +38,7 @@
  * SUCH DAMAGE.
  *
  *
- * $Id: autofs_solaris_v1.c,v 1.19 2003/08/22 05:16:11 ib42 Exp $
+ * $Id: autofs_solaris_v1.c,v 1.20 2003/08/28 03:10:34 ib42 Exp $
  *
  */
 
@@ -477,15 +477,13 @@ int
 autofs_mount_fs(am_node *mp, mntfs *mf)
 {
   int err = 0;
-  char *target;
+  char *target, *target2 = NULL;
   char *space_hack = autofs_strdup_space_hack(mp->am_path);
   struct stat buf;
 
   if (mf->mf_flags & MFF_ON_AUTOFS) {
-    if ((err = mkdir(space_hack, 0555))) {
-      err = errno;
+    if ((err = mkdir(space_hack, 0555)))
       goto out;
-    }
   }
 
   /*
@@ -498,6 +496,7 @@ autofs_mount_fs(am_node *mp, mntfs *mf)
   if (err) {
     if (mf->mf_flags & MFF_ON_AUTOFS)
       rmdir(space_hack);
+    errno = err;
     goto out;
   }
 
@@ -514,7 +513,12 @@ autofs_mount_fs(am_node *mp, mntfs *mf)
   else
     target = mf->mf_mount;
 
-  plog(XLOG_INFO, "autofs: converting from link to lofs (%s -> %s)", mp->am_path, target);
+  if (target[0] != '/')
+    target2 = str3cat(NULL, mp->am_parent->am_path, "/", target);
+  else
+    target2 = strdup(target);
+
+  plog(XLOG_INFO, "autofs: converting from link to lofs (%s -> %s)", mp->am_path, target2);
   /*
    * we need to stat() the destination, because the bind mount does not
    * follow symlinks and/or allow for non-existent destinations.
@@ -527,26 +531,28 @@ autofs_mount_fs(am_node *mp, mntfs *mf)
    * cause the recursive mount anyway if called from the parent amd.
    */
   if (!foreground) {
-    if (stat(target, &buf)) {
-      err = errno;
+    if ((err = stat(target2, &buf))) {
       goto out;
-    }
   }
-  if (lstat(target, &buf)) {
-    err = errno;
+  if ((err = lstat(target2, &buf)))
     goto out;
-  }
 
-  if (mkdir(space_hack, 0555)) {
-    err = errno;
+  if ((err = mkdir(space_hack, 0555)))
     goto out;
-  }
 
-  err = mount_lofs(mp->am_path, target, mf->mf_mopts, 1);
+  if ((err = mount_lofs(mp->am_path, target2, mf->mf_mopts, 1))) {
+    errno = err;
+    goto out;
+  }
 
  out:
   free(space_hack);
-  return err;
+  if (target2)
+    free(target2);
+
+  if (err)
+    return errno;
+  return 0;
 }
 
 
index 3118b1d42fcae569cf1a2355dc00c1c6638c34e3..27b97d52c598bcc5a89bd40010977eeb12f33430 100644 (file)
@@ -38,7 +38,7 @@
  * SUCH DAMAGE.
  *
  *
- * $Id: autofs_solaris_v2_v3.c,v 1.34 2003/08/05 04:27:46 ib42 Exp $
+ * $Id: autofs_solaris_v2_v3.c,v 1.35 2003/08/28 03:10:35 ib42 Exp $
  *
  */
 
@@ -1052,7 +1052,7 @@ int
 autofs_mount_fs(am_node *mp, mntfs *mf)
 {
   int err = 0;
-  char *target;
+  char *target, *target2 = NULL;
   struct stat buf;
 
   /*
@@ -1067,7 +1067,7 @@ autofs_mount_fs(am_node *mp, mntfs *mf)
     return err;
 
   if (!(gopt.flags & CFM_AUTOFS_USE_LOFS))
-    /* Symlinks are requested in autofs_mount_succeeded */
+    /* Symlinks will be requested in autofs_mount_succeeded */
     return 0;
 
   if (mp->am_link)
@@ -1075,7 +1075,12 @@ autofs_mount_fs(am_node *mp, mntfs *mf)
   else
     target = mf->mf_mount;
 
-  plog(XLOG_INFO, "autofs: converting from link to lofs (%s -> %s)", mp->am_path, target);
+  if (target[0] != '/')
+    target2 = str3cat(NULL, mp->am_parent->am_path, "/", target);
+  else
+    target2 = strdup(target);
+
+  plog(XLOG_INFO, "autofs: converting from link to lofs (%s -> %s)", mp->am_path, target2);
 
   /*
    * we need to stat() the destination, because the bind mount does not
@@ -1093,18 +1098,23 @@ autofs_mount_fs(am_node *mp, mntfs *mf)
    * cause the recursive mount anyway if called from the parent amd.
    */
   if (!foreground) {
-    err = stat(target, &buf);
-    if (err)
-      return errno;
+    if ((err = stat(target2, &buf)))
+      goto out;
   }
-  if ((err = lstat(target, &buf)))
-    return errno;
+  if ((err = lstat(target2, &buf)))
+    goto out;
 
-  if ((err = mkdirs(mp->am_path, 0555)))
-    return errno;
+  if ((err = mount_lofs(mp->am_path, target2, mf->mf_mopts, 1))) {
+    errno = err;
+    goto out;
+  }
 
-  if ((err = mount_lofs(mp->am_path, target, mf->mf_mopts, 1)))
-    return err;
+ out:
+  if (target2)
+    free(target2);
+
+  if (err)
+    return errno;
   return 0;
 }