Suppress a reglookup warning
[snf-image] / snf-image-helper / tasks / 40DisableRemoteDesktopConnections.in
1 #! /bin/bash
2
3 # Copyright (C) 2011 GRNET S.A. 
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 # General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 # 02110-1301, USA.
19
20 ### BEGIN TASK INFO
21 # Provides:             DisableRemoteDesktopConnections
22 # RunBefore:            EnforcePersonality
23 # RunAfter:             MountImage
24 # Short-Description:    Temporary Disable Remote Desktop Connections
25 ### END TASK INFO
26
27 #
28 # This task will change the value of `fDenyTSConnection' registry key located
29 # in `HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\' to
30 # "true". This will disable RDP connections. The key will change back to
31 # "false" during the specialize pass of the Windows setup.
32 #
33
34 set -e
35 . "@commondir@/common.sh"
36
37 trap task_cleanup EXIT
38 report_task_start
39
40 # Check if the task should be prevented from running.
41 check_if_excluded
42
43 if [ ! -d "$SNF_IMAGE_TARGET" ]; then
44     log_error "Target directory \`$SNF_IMAGE_TARGET' is missing"
45 fi
46
47 if [ "$SNF_IMAGE_PROPERTY_OSFAMILY" != "windows" ]; then
48     exit 0
49 fi
50
51 # Supress a specific reglookup warning messages. In Windows 2012, although the
52 # command works correct, it polluts the output with hundreds of warning
53 # messages about not being able to interprete registry key values.
54 RGLKP_WRNG="^WARN: While quoting value for '.\+', warning returned: Data could not be interpreted, quoting raw buffer."
55 hive="$SNF_IMAGE_TARGET/Windows/System32/config/SYSTEM"
56 current=$($REGLOOKUP "$hive" 2> >(grep -v "$RGLKP_WRNG" >&2) | grep ^/Select/Current | cut -d, -f3)
57
58 # Change the key value.
59 # For a stupid reason chntpw returns 2!
60 chntpw -e "$hive" <<EOF || { test $? -eq 2 && chntpw_ret="success"; }
61 cd ControlSet${current: -3}\Control\Terminal Server
62 ed fDenyTSConnections
63 1
64 q
65 y
66 EOF
67
68 if [ x"$chntpw_ret" != "xsuccess" ]; then
69     log_error "$CHNTPW failed"
70 fi
71
72 exit 0
73
74 # vim: set sta sts=4 shiftwidth=4 sw=4 et ai :