net.exe: Parses options for NET USE

Tim Schwartz tim at sanityinternet.com
Tue Jul 24 09:05:19 CDT 2007


-------------- next part --------------
diff --git a/programs/net/En.rc b/programs/net/En.rc
index f3d8f4f..4b64a17 100644
--- a/programs/net/En.rc
+++ b/programs/net/En.rc
@@ -37,4 +37,5 @@ STRINGTABLE
     STRING_STOP_SVC_SUCCESS, "The %s service was stopped successfully.\n"
     STRING_STOP_SVC_FAIL, "The %s service failed to stop.\n"
     STRING_HELP_USAGE, "The syntax of this command is:\n\nNET HELP command\n    -or-\nNET command /HELP\n\n   Commands available are:\n   NET HELP    NET START     NET STOP\n"
+    STRING_INVALID_NETUSE_PARM, "\"%s\" is an invalid parameter for NET USE\n"
 }
diff --git a/programs/net/net.c b/programs/net/net.c
index 73e1763..fcfc862 100644
--- a/programs/net/net.c
+++ b/programs/net/net.c
@@ -21,8 +21,10 @@
 #include <windows.h>
 #include "resources.h"
 
+#define MAXLEN 256
 #define NET_START 0001
 #define NET_STOP  0002
+#define NET_USE_ADD  0003
 
 int output_string(int msg, ...)
 {
@@ -36,6 +38,11 @@ int output_string(int msg, ...)
     return 0;
 }
 
+static BOOL net_use(int operation, char *device_name, char *remote_name, char *domain_name, char *user_name, char *user_password)
+{
+    return FALSE;
+}
+
 static BOOL StopService(SC_HANDLE SCManager, SC_HANDLE serviceHandle)
 {
     LPENUM_SERVICE_STATUS dependencies = NULL;
@@ -159,5 +166,53 @@ int main(int argc, char *argv[])
         return 0;
     }
 
+    if(!strcasecmp(argv[1], "use"))
+    {
+        argv+=2;
+        /* First non-switch parameter is device name, second is share name, third (if it exists) is password */
+        while(argc > 2)
+        {
+            argc--;
+            if (*argv[0] != '/')
+            {
+                if(!device_name[0]) strncpy(device_name, *argv, strlen(*argv));
+                else if(!remote_name[0]) strncpy(remote_name, *argv, strlen(*argv));
+                else if(!user_password[0]) strncpy(user_password, *argv, strlen(*argv));
+                else 
+                {
+                    output_string(STRING_INVALID_NETUSE_PARM, *argv);
+                    return 1;
+                }
+            } else
+            {
+                if(strstr(_strlwr(*argv), "/user:"))
+                {
+                    buffer = strstr(*argv, ":");
+                    buffer++;
+                    /* Check to see if /user is given in user at domain.com or domain.com\user format */
+                    while((buffer[0] != '@') && (buffer[0] != '\\') && (buffer[0] != '\0'))
+                    {
+                        temp[counter] = buffer[0];
+                        buffer++; counter++;
+                    }
+                    if(buffer[0] == '@')
+                    {
+                         strncpy(user_name, temp, strlen(temp));
+                         buffer++;
+                         strncpy(domain_name, buffer, strlen(buffer));
+                    }
+                    if(buffer[0] == '\\')
+                    {
+                         strncpy(domain_name, temp, strlen(temp));
+                         buffer++;
+                         strncpy(user_name, buffer, strlen(buffer));
+                    }
+                }
+            }
+            argv++;
+        }
+        if(!net_use(NET_USE_ADD, device_name, remote_name, domain_name, user_name, user_password)) return 1;
+    }
+
     return 0;
 }
diff --git a/programs/net/resources.h b/programs/net/resources.h
index 4c1c167..533580a 100644
--- a/programs/net/resources.h
+++ b/programs/net/resources.h
@@ -30,3 +30,4 @@
 #define STRING_STOP_SVC_SUCCESS   112
 #define STRING_STOP_SVC_FAIL      113
 #define STRING_HELP_USAGE         114
+#define STRING_INVALID_NETUSE_PARM 115


More information about the wine-patches mailing list