From c88bc35f1c88d9fbbba6706a4abaad24a1868c98 Mon Sep 17 00:00:00 2001 From: Peter Palfrader Date: Wed, 18 Oct 2006 11:33:32 +0000 Subject: Add hosting ldap git-svn-id: svn+ssh://asteria.noreply.org/svn/weaselutils/trunk@190 bc3d92e2-beff-0310-a7cd-cc87d7ac0ede --- bin/ldap2uucp | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100755 bin/ldap2uucp (limited to 'bin/ldap2uucp') 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 +# +# 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(< + +# 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(< +system + time any + called-login + protocol it + + +# 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(< +# +no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty,command="/usr/sbin/uucico -D -l" + +# end autogenerated stuff +EOF +) +templ.param({ 'systems' => systems }) +File.open("/var/spool/uucp/.ssh/authorized_keys", "w").write( templ.output ); -- cgit v1.2.3