-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgenwinhost.pl
More file actions
executable file
·69 lines (58 loc) · 1.36 KB
/
genwinhost.pl
File metadata and controls
executable file
·69 lines (58 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/perl -w
#
# $Id: genwinhost.pl,v 1.2 2001/07/16 20:11:54 steve Exp $
use strict;
if (@ARGV!=2 and @ARGV!=3)
{
print STDERR
"Usage: genwinhost.pl <hostname> <domain> [ <administrator password> ]\n";
exit 1;
}
my ($host,$domain,$pass)=@ARGV;
if (@ARGV==2)
{
if (!-t)
{
print STDERR "No password supplied, and we have no tty!\n";
exit 1;
}
print STDERR "Password: ";
system "stty -echo";
$pass=<STDIN>;
system "stty echo";
print STDERR "\n";
chomp $pass;
}
my @fs;
$ENV{'USER'}="administrator%$pass";
open(SMBCLIENT, "smbclient -L //'$host' -W '$domain' -N |")
or die "smbclient failed: $!\n";
while (<SMBCLIENT>)
{
my @foo=split;
if (@foo>3 and $foo[0]=~/^([A-Z])\$$/ and $foo[1] eq "Disk")
{
push(@fs, $1);
}
}
close(SMBCLIENT);
if (!@fs)
{
print STDERR "No administrative shares found!\n";
exit 1;
}
print "# filesystem\tcommand\n";
for my $fs (@fs)
{
print <<END;
$fs trap "umount /mnt/HOST/PATH" EXIT ; \\
mkdir -p /mnt/HOST/PATH \\
2>/dev/null ; \\ # This can fail.
mount -t smbfs '//HOST/PATH\$' \\
/mnt/HOST/PATH \\ # This can't.
-o username=administrator,password=$pass,workgroup=$domain,ro && \\
rsync -aW /mnt/HOST/PATH/. . --numeric-ids --partial --timeout=600 \\
--exclude /RECYCLER/ --exclude /pagefile.sys \\
EXTRAFLAGS
END
}