summaryrefslogtreecommitdiff
path: root/bin/ldap.add.ftp
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/ldap.add.ftp
Add hosting ldap
git-svn-id: svn+ssh://asteria.noreply.org/svn/weaselutils/trunk@190 bc3d92e2-beff-0310-a7cd-cc87d7ac0ede
Diffstat (limited to 'bin/ldap.add.ftp')
-rwxr-xr-xbin/ldap.add.ftp76
1 files changed, 76 insertions, 0 deletions
diff --git a/bin/ldap.add.ftp b/bin/ldap.add.ftp
new file mode 100755
index 0000000..93fb138
--- /dev/null
+++ b/bin/ldap.add.ftp
@@ -0,0 +1,76 @@
+#!/usr/bin/ruby
+
+#
+# Copyright (c) 2004 Peter Palfrader <peter@palfrader.org>
+#
+# All rights reserved.
+#
+
+require "ldap"
+require "getoptlong"
+require "myldap"
+require "yaml"
+require 'optparse'
+
+config = YAML::load( File.open( '/etc/noreply/config' ) )
+
+@password = [File.new("/dev/urandom").read(config['module']['ftp']['pwlen'])].pack("m").chomp.delete('=')
+@sshkeys = []
+@hosts = []
+
+def show_help(parser, code=0, io=STDOUT)
+ io.puts parser
+ exit(code)
+end
+ARGV.options do |opts|
+ opts.on_tail("-h", "--help", "Display this help screen") { show_help(opts) }
+ opts.on("-c", "--client=CLIENT" , String, "Client Identifier") { |@clientname| }
+ opts.on("-b", "--basedir=DIRECTORY", String, "Account basedirectory") { |@basedir| }
+ opts.on("-a", "--accountname=NAME" , String, "Account (base)name") { |@accountname| }
+ opts.on("-p", "--password=PASSWORD", String, "Password") { |@password| }
+ opts.on("-s", "--ssh-key=SSH-KEY" , String, "ssh public key") { |val| @sshkeys.push(val) }
+ opts.on("-H", "--host=HOST" , String, "active host") { |val| @hosts.push(val) }
+ opts.on("-D", "--description=BLA" , String, "description") { |@description| }
+ opts.parse!
+end
+
+show_help(ARGV.options, 1, STDERR) if ARGV.length > 0
+show_help(ARGV.options, 1, STDERR) unless @clientname
+show_help(ARGV.options, 1, STDERR) unless @basedir
+show_help(ARGV.options, 1, STDERR) unless @accountname
+@hosts.push(config['defaulthost']) unless @hosts.length > 0
+
+ldap = MyLDAP.new(config)
+client = ldap.verify_client(@clientname)
+
+@accountname = @clientname+'.'+@accountname
+@pamHomedirectory = config['module']['ftp']['chrootBaseDir']+'/'+@accountname
+@realDatadirectory = (@basedir =~ /^\// ? '' : client['homeDirectory'][0]) + '/' + @basedir
+
+@pamHomedirectory.gsub!('//', '/') while @pamHomedirectory.index('//') # scponly gives special meaning to //
+@realDatadirectory.gsub!('//', '/') while @realDatadirectory.index('//') # scponly gives special meaning to //
+
+data = {
+ 'objectclass' => ['top', 'tnFTPuser', 'posixAccount'],
+ 'cn' => [ @accountname ],
+ 'uid' => [ @accountname ],
+ 'uidNumber' => client['uidNumber'],
+ 'gidNumber' => client['gidNumber'],
+ 'homeDirectory' => [ @pamHomedirectory ],
+ 'tnFTPDataDirectory' => [ @realDatadirectory ],
+ 'userPassword' => [ @password ],
+ 'tnHost' => @hosts,
+ 'loginShell' => [ config['module']['ftp']['loginShell'] ]
+
+}
+data['tnSSHKey'] = [@sshkeys] if @sshkeys.length > 0
+data['description'] = [@description] if @description
+
+
+dn = "cn=%s,ou=ftp,o=%s,ou=hosting,%s"%[@accountname, @clientname, config['basedn']]
+
+puts dn
+puts data.to_yaml
+puts
+
+ldap.add(dn, data)