svn commit: samba r16180 - in branches/SOC/bnh/vbscript: .
brad at samba.org
brad at samba.org
Tue Jun 13 03:09:59 GMT 2006
Author: brad
Date: 2006-06-13 03:09:56 +0000 (Tue, 13 Jun 2006)
New Revision: 16180
WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=16180
Log:
Updated windows host configuration readme file to reflect the new changes in win_setup.wsf.
win_setup.wsf is a vbscript that:
* Creates a local workstation administrator account.
* If /hostname:<hostname> is passed in at the command line, change the system hostname.
* If /workgroup:<workgroup> is passed in, change the system workgroup.
* Enable and start the telnet service.
win_setup.wsf requires that common.vbs be in the same directory.
Added:
branches/SOC/bnh/vbscript/win_setup.wsf
Removed:
branches/SOC/bnh/vbscript/windows_setup.zip
branches/SOC/bnh/vbscript/windows_setup/
Modified:
branches/SOC/bnh/vbscript/WINDOWS_SETUP_README
Changeset:
Modified: branches/SOC/bnh/vbscript/WINDOWS_SETUP_README
===================================================================
--- branches/SOC/bnh/vbscript/WINDOWS_SETUP_README 2006-06-13 02:55:02 UTC (rev 16179)
+++ branches/SOC/bnh/vbscript/WINDOWS_SETUP_README 2006-06-13 03:09:56 UTC (rev 16180)
@@ -1,17 +1,15 @@
-To setup a windows host for testing, i've created a script to create a base
-working directory, install the COP SSH server (http://itefix.no/copssh),
-create an adminstrative user account, and give that user access to the SSH
-server.
+To setup a windows host for testing, i've created a script to create an
+adminstrative user account, and enable and start the telnet service.
+Optionally, the hostname and workgroup name can also be set.
-Copy windows_setup.zip into a directory (C:\smbtmp in this example), and follow
-these steps:
+Copy win_setup.wsf and common.vbs into a directory (Z:\smbtest in this example),
+ and follow these steps:
-C:\smbtmp>unzip windows_setup.zip
-C:\smbtmp>cd windows_setup
-C:\smbtmp\windows_setup>cscript win_setup.wsf /username:<username> /password:<password>
-(<username> will be created, assigned the password <password>, and added to
-the Domain Admins group. By passing optional /basedir:<basedir> parameter,
-<basedir> will be created, otherwise C:\smbtorture_root will be created.)
+Z:\smbtest>cscript win_setup.wsf /username:<username> /password:<password>
+(<username> will be created, assigned the password <password>, and added to
+the local Administrators group. By passing the optional /hostname:<hostname>
+or /workgroup:<workgroup> parameters, the script will set the system hostname
+or workgroup, respectively.)
-Once this script finishes, <username> should be able to SSH into the windows
+Once this script finishes, <username> should be able to telnet into the windows
host.
Added: branches/SOC/bnh/vbscript/win_setup.wsf
===================================================================
--- branches/SOC/bnh/vbscript/win_setup.wsf 2006-06-13 02:55:02 UTC (rev 16179)
+++ branches/SOC/bnh/vbscript/win_setup.wsf 2006-06-13 03:09:56 UTC (rev 16180)
@@ -0,0 +1,239 @@
+<package>
+<job id=win_setup>
+<script language="VBScript" src="common.vbs">
+
+const USAGE_STATEMENT = "Usage: cscript win_setup.wsf /username:<username> /password:<password> /hostname:<hostname> /workgroup:<workgroup>"
+const DEFAULT_BASEDIR = "C:\smbtorture_root"
+
+' Use WMI to set the local system's hostname.
+function setup_hostname(adminuser, adminpass, hostname)
+
+ on error resume next
+
+ dim network, old_hostname, wmi_service, local_machine
+
+ ' Get current hostname.
+ set network = createObject("wscript.network")
+ old_hostname = network.computerName
+
+ ' Get the WMI object for this host.
+ set local_machine = getObject("winmgmts:{impersonationLevel=" _
+ & "impersonate}\\" & old_hostname _
+ & "\root\cimv2:Win32_ComputerSystem.Name='" _
+ & old_hostname & "'")
+ if err.number <> 0 then
+ stdout.writeline "Error setting up local_machine in " _
+ & "function setup_hostname: " & err.description
+ setup_hostname = err.number
+ exit function
+ end if
+
+ ' Rename the host.
+ error_code = local_machine.rename(hostname, adminpass, adminuser)
+ if error_code <> 0 then
+ setup_hostname = error_code
+ stdout.writeline "Error renaming host to " & hostname _
+ & ". Returned " & error_code & "."
+ exit function
+ end if
+
+ stdout.writeline "Local machine renamed to " & hostname & "."
+ setup_hostname = RTN_OK
+
+end function
+
+' Use WMI to set the local system's workgroup.
+function setup_workgroup(adminuser, adminpass, workgroup)
+
+ on error resume next
+
+ dim network, hostname, wmi_service, local_machine
+
+ ' Get hostname.
+ set network = createObject("wscript.network")
+ hostname = network.computerName
+
+ set local_machine = getObject("winmgmts:{impersonationLevel=" _
+ & "impersonate}!\\" & hostname _
+ & "\root\cimv2:Win32_ComputerSystem.Name='" _
+ & hostname & "'")
+ if err.number <> 0 then
+ stdout.writeline "Error setting up local_machine in " _
+ & "function setup_workgroup: " & err.description
+ setup_workgroup = err.number
+ exit function
+ end if
+
+ ' Set the workgroup name.
+ error_code = local_machine.joinDomainOrWorkgroup(workgroup, adminpass, adminuser)
+ if error_code <> 0 then
+ setup_workgroup = error_code
+ stdout.writeline "Error joining workgroup " & workgroup _
+ & ". Returned " & error_code & "."
+ exit_function
+ end if
+
+ stdout.writeline "Workgroup set to " & workgroup & "."
+ setup_workgroup = RTN_OK
+
+end function
+
+' Use WMI to start the disabled telnet service.
+function start_telnet_service
+
+ on error resume next
+
+ dim network, hostname, wmi_service, telnet_service
+
+ ' Get hostname.
+ set network = createObject("wscript.network")
+ hostname = network.computerName
+
+ set telnet_service = getObject("winmgmts:{impersonationLevel=" _
+ & "impersonate}\\" & hostname _
+ & "\root\cimv2:Win32_Service='TlntSvr'")
+ if err.number <> 0 then
+ stdout.writeline "Error setting up telnet_service in " _
+ & "function start_telnet_service: " & err.description
+ start_telnet_service = err.number
+ exit function
+ end if
+
+ ' Set the telnet service start mode to Manual.
+ set method = telnet_service.methods_("ChangeStartMode")
+ set inParam = method.inParameters.spawnInstance_()
+ inParam.startMode = "Manual"
+
+ set error_obj = telnet_service.execMethod_("ChangeStartMode", inParam)
+ if error_obj.returnValue <> 0 then
+ stdout.writeline "Error changing the telnet service " _
+ & "start mode: " & error_obj.returnValue
+ start_telnet_service = error_obj.returnValue
+ exit function
+ end if
+ stdout.writeline "Telnet service enabled - Manual start mode."
+
+ ' net start telnet
+ set shell = wscript.createObject("wscript.shell")
+ netstart_cmd = "net start telnet"
+
+ error_code = shell.run(netstart_cmd, NEW_WINDOW_MINIMIZED, _
+ True)
+ if error_code <> 0 then
+ if error_code = 2 then
+ stdout.writeline "Telnet service was already started."
+ else
+ stdout.writeline "Error calling " & netstart_cmd _
+ & ". Returned " & error_code & "."
+ start_telnet_service = error_code
+ exit function
+ end if
+ else
+ stdout.writeline "Telnet service started."
+ end if
+ start_telnet_service = RTN_OK
+
+end function
+
+' If username exists, remove it.
+' Create user. Add to local Administrators group.
+function setup_user(username, password)
+
+ on error resume next
+
+ set shell = wscript.createObject("wscript.shell")
+ netuser_cmd = "net user " & username
+ error_code = shell.run(netuser_cmd, NEW_WINDOW_MINIMIZED, True)
+
+ if error_code = 0 then
+ ' Try to delete the user before adding.
+ stdout.writeline "User " & username & " exists."
+ netuserdel_cmd = "net user " & username & " /DELETE"
+ error_code = shell.run(netuserdel_cmd, NEW_WINDOW_MINIMIZED, _
+ True)
+ if error_code <> 0 then
+ stdout.writeline "Error calling " & netuserdel_cmd _
+ & ". Returned " & error_code & "."
+ setup_user = error_code
+ exit function
+ end if
+ stdout.writeline "User " & username & " removed."
+ end if
+
+ netuseradd_cmd = "net user " & username & " " & password & " /ADD"
+ error_code = shell.run(netuseradd_cmd, NEW_WINDOW_MINIMIZED, True)
+ if error_code <> 0 then
+ stdout.writeline "Error calling " & netuseradd_cmd _
+ & ". Returned " & error_code & "."
+ setup_user = error_code
+ exit function
+ end if
+
+ stdout.writeline "User " & username & " added."
+
+ ' Add user to local Administrators group.
+ netgroup_cmd = "net localgroup ""Administrators"" " & username & " /ADD"
+ error_code = shell.run(netgroup_cmd, NEW_WINDOW_MINIMIZED, True)
+ if error_code <> 0 then
+ stdout.writeline "Error calling " & netgroup_cmd _
+ & ". Returned " & error_code & "."
+ setup_user = error_code
+ exit function
+ end if
+
+ stdout.writeline "User " & username & " added to group" _
+ & " ""Administrators""."
+ setup_user = RTN_OK
+
+end function
+
+function check_error(error_code, function_name)
+ if error_code <> RTN_OK then
+ stdout.writeline "Fatal error. Function " & function_name _
+ & " returned " & error_code & "."
+ wscript.quit(error_code)
+ end if
+
+end function
+
+dim required_options, provided_options
+
+required_options = array("username", "password")
+set provided_options = wscript.arguments.named
+
+set setup_options = new setup_object
+setup_options.check_options provided_options, required_options
+
+if setup_options.error_code = RTN_ERR then
+ setup_options.list_missing_options
+ stdout.writeline USAGE_STATEMENT
+ wscript.quit(setup_options.error_code)
+end if
+
+username = provided_options.item("username")
+password = provided_options.item("password")
+
+' Create local admin user with a known password.
+error_code = setup_user(username, password)
+check_error error_code, "setup_user"
+
+if provided_options.exists("hostname") then
+ hostname = provided_options.item("hostname")
+ error_code = setup_hostname(username, password, hostname)
+ check_error error_code, "setup_hostname"
+end if
+
+if provided_options.exists("workgroup") then
+ workgroup = provided_options.item("workgroup")
+ error_code = setup_workgroup(username, password, workgroup)
+ check_error error_code, "setup_workgroup"
+end if
+
+
+' Enable and start the telnet service.
+error_code = start_telnet_service
+check_error error_code, "start_telnet_service"
+
+</script>
+</job>
+</package>
Deleted: branches/SOC/bnh/vbscript/windows_setup.zip
===================================================================
(Binary files differ)
More information about the samba-cvs
mailing list