summaryrefslogtreecommitdiff
path: root/bin/ldap2uucp
blob: 5dbf8f5e8fc7ec616dee93cfe9dfbd80368beb43 (plain)
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/ruby

#
# Copyright (c) 2004 Peter Palfrader <peter@palfrader.org>
#
# All rights reserved.
#

require "ldap"
require "getoptlong"
require "myldap"
require "yaml"
require "html/template"

config = YAML::load( File.open( '/etc/noreply/config' ) )

ldap = MyLDAP.new(config, "ldap2uucp")

systems = []

begin
	ldap.conn.search(config['basedn'], LDAP::LDAP_SCOPE_SUBTREE, 
		'(&(objectclass=tnUUCPSystem)'+
		  '(tnHost='+config['thishost']+'))') {|e|

		systemname = e.vals("tnUUCPSysName").pop;
		sshkey = e.vals("tnSSHKey").pop; # FIXME: only first used
		password = e.vals("tnUUCPPassword").pop

		systems.push( {
			'system' => systemname,
			'password' => password,
			'sshkey' => sshkey } )
	}
rescue LDAP::ResultError => msg
	$stderr.print(msg)
	exit 1;
end


spool = "/var/spool/uucp"
existingdirs = Dir.entries( spool ).delete_if { |e| ((e =~ /^\./) != nil) || !File.stat( spool + '/' + e ).directory?}
systems.each{ |s| existingdirs.delete( s['system'] ) };
STDERR.puts "The following orphaned nodes have dirs in the uucp spool: " + existingdirs.join(", ") unless (existingdirs.empty?)

#
# /etc/uucp/passwd
#
templ = HTML::Template.new
templ.set_html(<<EOF
# begin autogenerated stuff
<!begin:systems><!var:system>			<!var:password>
<!end:systems>
# end autogenerated stuff
EOF
)
templ.param({ 'systems' => systems })
File.open("/etc/uucp/passwd", "w").write( templ.output );


#
# /etc/uucp/sys
#
templ = HTML::Template.new
templ.set_html(<<EOF
# begin autogenerated stuff
protocol gvG
protocol-parameter G packet-size 1024
# protocol-parameter G window 7
protocol-parameter G short-packets

<!begin:systems>
system <!var:system>
	time any
	called-login <!var:system>
	protocol it

<!end:systems>
# end autogenerated stuff
EOF
)
templ.param({ 'systems' => systems })
File.open("/etc/uucp/sys", "w").write( templ.output );

#
# ~uucp/.ssh/authorized_keys
#
templ = HTML::Template.new
templ.set_html(<<EOF
# begin autogenerated stuff
<!begin:systems>
# <!var:system>
no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty,command="/usr/sbin/uucico -D -l" <!var:sshkey>
<!end:systems>
# end autogenerated stuff
EOF
)
templ.param({ 'systems' => systems })
File.open("/var/spool/uucp/.ssh/authorized_keys", "w").write( templ.output );