Imported Upstream version 2.7
[ossec-hids.git] / src / agentlessd / scripts / su.exp
1 #!/usr/bin/env expect
2
3 # @(#) $Id: ./src/agentlessd/scripts/su.exp, 2011/09/08 dcid Exp $
4
5 # Agentless monitoring
6 #
7 # Copyright (C) 2009 Trend Micro Inc.
8 # All rights reserved.
9
10 # This program is a free software; you can redistribute it
11 # and/or modify it under the terms of the GNU General Public
12 # License (version 2) as published by the FSF - Free Software
13 # Foundation.
14
15
16 # If su was chosen
17 set timeout 10
18 if {[string compare $use_su "su;"] == 0} {
19
20     # Run su command
21     send "\rsu\r"
22
23     expect {
24         "Password:" {
25             send "$addpass\r"
26         }
27         timeout {
28             send_user "\nERROR: Unable to run su.\n"
29             exit 1;
30         }
31     }
32
33
34     expect {
35         "Permission denied" {
36             send_user "\nERROR: Incorrect su password to host: $hostname .\n"
37             exit 1;
38         }
39         "Password:" {
40             send_user "\nERROR: Incorrect su password to host: $hostname .\n"
41             exit 1;
42         }
43         "Sorry" {
44             send_user "\nERROR: Incorrect su password to remote host: $hostname .\n"
45             exit 1;
46         }
47         eof {
48             send_user "\nERROR: EOF while running su on host: $hostname .\n"
49             exit 1;
50         }
51         timeout {
52             send_user "\nERROR: Timeout while running on host: $hostname .\n"
53             exit 1;
54         }
55         "*#" {
56             send_user "\nINFO: su accepted.\n"
57         }
58     }
59 }