changeset 87985:f7a641e1f03d

(logon_network_drive): New function. (stat): Use it.
author Jason Rumney <jasonr@gnu.org>
date Sat, 26 Jan 2008 01:07:49 +0000
parents 5ca564f6a9e6
children a84696688907
files src/w32.c
diffstat 1 files changed, 33 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/w32.c	Sat Jan 26 01:00:44 2008 +0000
+++ b/src/w32.c	Sat Jan 26 01:07:49 2008 +0000
@@ -1938,6 +1938,36 @@
   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 @@
 	}
       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)
 	    {