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