]> git.eshelyaron.com Git - emacs.git/commitdiff
(logon_network_drive): New function.
authorJason Rumney <jasonr@gnu.org>
Sat, 26 Jan 2008 01:08:53 +0000 (01:08 +0000)
committerJason Rumney <jasonr@gnu.org>
Sat, 26 Jan 2008 01:08:53 +0000 (01:08 +0000)
(stat): Use it.

src/ChangeLog
src/w32.c

index dddf5447469e5fcc1e28b093cdbacad110d4c4f2..469bc6321823947adea3866a42c95ad22d4fb9c1 100644 (file)
@@ -1,3 +1,8 @@
+2008-01-26  Jason Rumney  <jasonr@gnu.org>
+
+       * w32.c (logon_network_drive): New function.
+       (stat): Use it.
+
 2008-01-26  Chong Yidong  <cyd@stupidchicken.com>
 
        * xdisp.c (pos_visible_p): Handle the case where charpos falls on
index 5a8289789dac06b92fec22fd33e2d0ace9d1940b..f1be902707ef923b9081818d946527a4f043f3d6 100644 (file)
--- a/src/w32.c
+++ b/src/w32.c
@@ -1938,6 +1938,36 @@ unc_volume_file_attributes (const char *path)
   return attrs;
 }
 
+/* Ensure a network connection is authenticated.  */
+static void
+logon_network_drive (const char *path)
+{
+  NETRESOURCE resource;
+  char share[MAX_PATH];
+  int i, n_slashes;
+
+  /* Only logon to networked drives.  */
+  if (!IS_DIRECTORY_SEP (path[0]) || !IS_DIRECTORY_SEP (path[1]))
+    return;
+  n_slashes = 2;
+  strncpy (share, path, MAX_PATH);
+  /* Truncate to just server and share name.  */
+  for (i = 2; i < MAX_PATH; i++)
+    {
+      if (IS_DIRECTORY_SEP (share[i]) && ++n_slashes > 3)
+        {
+          share[i] = '\0';
+          break;
+        }
+    }
+
+  resource.dwType = RESOURCETYPE_DISK;
+  resource.lpLocalName = NULL;
+  resource.lpRemoteName = share;
+  resource.lpProvider = NULL;
+
+  WNetAddConnection2 (&resource, NULL, NULL, CONNECT_INTERACTIVE);
+}
 
 /* Shadow some MSVC runtime functions to map requests for long filenames
    to reasonable short names if necessary.  This was originally added to
@@ -2495,6 +2525,9 @@ stat (const char * path, struct stat * buf)
        }
       else
        {
+          if (IS_DIRECTORY_SEP (name[0]) && IS_DIRECTORY_SEP (name[1]))
+            logon_network_drive (name);
+
          fh = FindFirstFile (name, &wfd);
          if (fh == INVALID_HANDLE_VALUE)
            {