svn commit: samba r16074 - in branches/SOC/bnh: . windows_setup
brad at samba.org
brad at samba.org
Wed Jun 7 04:26:39 GMT 2006
Author: brad
Date: 2006-06-07 04:26:11 +0000 (Wed, 07 Jun 2006)
New Revision: 16074
WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=16074
Log:
WINDOWS_SETUP_README is a process to easily setup a windows host for remote access to an interactive SSH shell.
windows_setup.zip contains the necessary scripts and the SSH server windows executable.
win_setup.wsf is the main script which performs the installation and configuration. It requires /username:<username> and /password:<password> parameters, and accepts an optional parameter /basedir:<basedir>.
win_setup.wsf is intended to perform the installation without user interaction on a wide variety of windows platforms.
The script currently has the limitation that it will only work on a host within a domain, as it adds the user to the Domain Admins group. Eventually, it will instead add the user to the local Administrators group when necessary.
Added:
branches/SOC/bnh/WINDOWS_SETUP_README
branches/SOC/bnh/windows_setup.zip
branches/SOC/bnh/windows_setup/
branches/SOC/bnh/windows_setup/win_setup.wsf
Changeset:
Added: branches/SOC/bnh/WINDOWS_SETUP_README
===================================================================
--- branches/SOC/bnh/WINDOWS_SETUP_README 2006-06-07 04:23:42 UTC (rev 16073)
+++ branches/SOC/bnh/WINDOWS_SETUP_README 2006-06-07 04:26:11 UTC (rev 16074)
@@ -0,0 +1,17 @@
+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.
+
+Copy windows_setup.zip into a directory (C:\smbtmp 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.)
+
+Once this script finishes, <username> should be able to SSH into the windows
+host.
Added: branches/SOC/bnh/windows_setup/win_setup.wsf
===================================================================
--- branches/SOC/bnh/windows_setup/win_setup.wsf 2006-06-07 04:23:42 UTC (rev 16073)
+++ branches/SOC/bnh/windows_setup/win_setup.wsf 2006-06-07 04:26:11 UTC (rev 16074)
@@ -0,0 +1,176 @@
+<package>
+<job id=win_setup>
+<script language="VBScript" src="..\include\common.vbs">
+
+const USAGE_STATEMENT = "Usage: cscript win_setup.wsf /username:<username> /password:<password> /basedir:<directory path>"
+const DEFAULT_BASEDIR = "C:\smbtorture_root"
+
+execute include("..\include\fs_common.vbs")
+
+function setup_base_dir(pathname)
+
+ on error resume next
+
+ error_code = RTN_OK
+
+ ' If basedir exists, remove it.
+ set fileSystemObject = createObject("scripting.fileSystemObject")
+ if fileSystemObject.folderExists(pathname) then
+ stdout.writeline "Directory " & pathname & " exists."
+ error_code = delete_directory(pathname)
+ if error_code <> 0 then
+ ' There was an unexpected error.
+ setup_base_dir = error_code
+ exit function
+ end if
+ end if
+
+ ' Create basedir.
+ error_code = create_directory(pathname)
+ setup_base_dir = error_code
+
+end function
+
+' Run the installer for the ssh server silently, installing into basedir.
+function setup_sshd
+
+ on error resume next
+
+ set shell = wscript.createObject("wscript.shell")
+ install_cmd = "Copssh_1.3.10_Installer.exe "_
+ & "/S"
+
+ error_code = shell.run(install_cmd, NEW_WINDOW_MINIMIZED, True)
+ if error_code <> 0 then
+ stdout.writeline "Unhandled error calling " & install_cmd _
+ & ". Returned " & error_code & "."
+ else
+ stdout.writeline "SSH service installed and running."
+ end if
+ setup_sshd = error_code
+
+end function
+
+' If username exists, remove it.
+' Create user. Add to Domain Admins 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 Domain Admins group.
+ ' If we aren't on a dc, we should add the user to the local admins
+ ' group as well.
+ netgroup_cmd = "net group ""Domain Admins"" " & 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" _
+ & " ""Domain Admins""."
+ setup_user = RTN_OK
+
+end function
+
+' Activate username for SSH logins.
+function setup_sshd_user(username, password)
+
+ on error resume next
+
+ activate_cmd = "C:\progra~1\copssh\bin\bash.exe --login " _
+ & "activate-user-auto.sh " & username
+ set shell = createObject("wscript.shell")
+ error_code = shell.run(activate_cmd, NEW_WINDOW_MINIMIZED, True)
+ if error_code <> 0 then
+ stdout.writeline activate_command & " returned " & error_code
+ else
+ stdout.writeline username & " activated for SSH logins."
+ end if
+
+ setup_sshd_user = error_code
+
+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
+
+
+basedir = DEFAULT_BASEDIR
+
+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")
+if provided_options.exists("basedir") then
+ basedir = provided_options.item("basedir")
+end if
+
+' Install ssh server in basedir/sshd.
+error_code = setup_base_dir(basedir)
+check_error error_code, "setup_base_dir"
+
+
+error_code = setup_sshd
+check_error error_code, "setup_sshd"
+
+' Create local admin user with a known password.
+error_code = setup_user(username, password)
+check_error error_code, "setup_user"
+
+' Allow user to use ssh.
+error_code = setup_sshd_user(username, password)
+check_error error_code, "setup_sshd_user"
+
+</script>
+</job>
+</package>
\ No newline at end of file
Added: branches/SOC/bnh/windows_setup.zip
===================================================================
(Binary files differ)
Property changes on: branches/SOC/bnh/windows_setup.zip
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
More information about the samba-cvs
mailing list