summaryrefslogtreecommitdiff
path: root/bin/ldap2uucp
diff options
context:
space:
mode:
authorPeter Palfrader <peter@palfrader.org>2006-10-18 11:33:32 +0000
committerweasel <weasel@bc3d92e2-beff-0310-a7cd-cc87d7ac0ede>2006-10-18 11:33:32 +0000
commitc88bc35f1c88d9fbbba6706a4abaad24a1868c98 (patch)
tree487c31421b2f92e6e76bcf946500187b6b014e91 /bin/ldap2uucp
Add hosting ldap
git-svn-id: svn+ssh://asteria.noreply.org/svn/weaselutils/trunk@190 bc3d92e2-beff-0310-a7cd-cc87d7ac0ede
Diffstat (limited to 'bin/ldap2uucp')
-rwxr-xr-xbin/ldap2uucp99
1 files changed, 99 insertions, 0 deletions
diff --git a/bin/ldap2uucp b/bin/ldap2uucp
new file mode 100755
index 0000000..5dbf8f5
--- /dev/null
+++ b/bin/ldap2uucp
@@ -0,0 +1,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 );