OSDN Git Service

* mount.cc (mount_info::from_fstab): Read user fstab files from
authorcorinna <corinna>
Tue, 8 Apr 2008 16:12:24 +0000 (16:12 +0000)
committercorinna <corinna>
Tue, 8 Apr 2008 16:12:24 +0000 (16:12 +0000)
/etc/fstab.d/$USER to avoid user write access to /etc.
* postinstall: Use variables for filenames.  Create /etc/fstab.d dir
with 01777 permissions.

winsup/cygwin/ChangeLog
winsup/cygwin/mount.cc
winsup/cygwin/postinstall

index 14d6360..5070c72 100644 (file)
@@ -1,5 +1,12 @@
 2008-04-08  Corinna Vinschen  <corinna@vinschen.de>
 
+       * mount.cc (mount_info::from_fstab): Read user fstab files from
+       /etc/fstab.d/$USER to avoid user write access to /etc.
+       * postinstall: Use variables for filenames.  Create /etc/fstab.d dir
+       with 01777 permissions.
+
+2008-04-08  Corinna Vinschen  <corinna@vinschen.de>
+
        * postinstall: Disable adding registry mounts to /etc/fstab for now.
 
 2008-04-07  Christopher Faylor  <me+cygwin@cgf.cx>
index ba6f42b..83d45d5 100644 (file)
@@ -914,7 +914,7 @@ mount_info::from_fstab (bool user)
 
   PWCHAR u = wcpcpy (w, L"\\etc\\fstab");
   if (user)
-    sys_mbstowcs (wcpcpy (u, L"."), NT_MAX_PATH - (u - path),
+    sys_mbstowcs (wcpcpy (u, L".d\\"), NT_MAX_PATH - (u - path),
                  cygheap->user.name ());
   debug_printf ("Try to read mounts from %W", path);
   HANDLE h = CreateFileW (path, GENERIC_READ, FILE_SHARE_READ, &sec_none_nih,
index 68ae132..829bb5f 100755 (executable)
 #
 export PATH="/bin:$PATH"
 
+SYSCONFDIR=/etc
+FSTAB="${SYSCONFDIR}/fstab"
+FSTABDIR="${SYSCONFDIR}/fstab.d"
+
 DEVDIR=/dev
 
 print_flags ()
@@ -22,21 +26,21 @@ print_flags ()
 }
 
 # Create fstab file if it doesn't exist.
-if [ -e "/etc/fstab" -a ! -f "/etc/fstab" ]
+if [ -e "${FSTAB}" -a ! -f "${FSTAB}" ]
 then
   # Try to move
-  mv -f "/etc/fstab" "/etc/fstab.orig"
-  if [ -e "/etc/fstab" -a ! -f "/etc/fstab" ]
+  mv -f "${FSTAB}" "${FSTAB}.orig"
+  if [ -e "${FSTAB}" -a ! -f "${FSTAB}" ]
   then
     echo
-    echo "/etc/fstab is existant but not a file."
+    echo "${FSTAB} is existant but not a file."
     echo "Since this file is specifying the mount points, this might"
     echo "result in unexpected trouble.  Please fix that manually."
     echo
   fi
 fi
 
-if [ ! -e "/etc/fstab" ]
+if [ ! -e "${FSTAB}" ]
 then
   # Set IFS to just a LF
   _OLD_IFS="$IFS"
@@ -52,7 +56,7 @@ then
       break
     fi
   done
-  cat > /etc/fstab << EOF
+  cat > ${FSTAB} << EOF
 # The  file fstab contains descriptive information about the various file
 # systems.  fstab is only read by programs, and not written;  it  is  the
 # duty  of  the system administrator to properly create and maintain this
@@ -144,12 +148,12 @@ EOF
   #    echo -n "${nat} ${psx} some_fs "
   #    print_flags $flags
   #    echo " 0 0"
-  #  fi >> /etc/fstab
+  #  fi >> ${FSTAB}
   #done
   #[ -z "$usr_bin" ] &&
-    echo "${CYGROOT//\\//}/bin /usr/bin ${FS_TYPE} binary 0 0" >> /etc/fstab
+    echo "${CYGROOT//\\//}/bin /usr/bin ${FS_TYPE} binary 0 0" >> ${FSTAB}
   #[ -z "$usr_lib" ] &&
-    echo "${CYGROOT//\\//}/lib /usr/lib ${FS_TYPE} binary 0 0" >> /etc/fstab
+    echo "${CYGROOT//\\//}/lib /usr/lib ${FS_TYPE} binary 0 0" >> ${FSTAB}
 
   #cygd=""
   #prefix=$(regtool -q get "$key\cygdrive prefix")
@@ -162,16 +166,47 @@ EOF
   #  echo -n "none ${psx} cygdrive "
   #  print_flags $flags
   #  echo ",user 0 0"
-  #fi >> /etc/fstab
+  #fi >> ${FSTAB}
 
   #if [ -z "$cygd" ]
   #then
-    echo "# This is default anyway:" >> /etc/fstab
-    echo "# none /cygdrive cygdrive binary,user 0 0" >> /etc/fstab
+    echo "# This is default anyway:" >> ${FSTAB}
+    echo "# none /cygdrive cygdrive binary,user 0 0" >> ${FSTAB}
   #fi
   IFS="$_OLD_IFS"
 fi
 
+# Check for ${FSTABDIR} directory
+
+if [ -e "${FSTABDIR}" -a ! -d "${FSTABDIR}" ]
+then 
+  # No mercy.  Try to remove.
+  rm -f "${FSTABDIR}"
+  if [ -e "${FSTABDIR}" -a ! -d "${FSTABDIR}" ]
+  then 
+    echo
+    echo "${FSTABDIR} is existant but not a directory."
+    echo "Please fix that manually."
+    echo
+    exit 1
+  fi
+fi
+
+# Create it if necessary
+
+if [ ! -e "${FSTABDIR}" ]
+then
+  mkdir -m 1777 "${FSTABDIR}"
+  if [ ! -e "${FSTABDIR}" ]
+  then
+    echo
+    echo "Creating ${FSTABDIR} directory failed."
+    echo "Please fix that manually."
+    echo
+    exit 1
+  fi
+fi
+
 # Check for ${DEVDIR} directory
 
 if [ -e "${DEVDIR}" -a ! -d "${DEVDIR}" ]