Commits

Michael Granger committed aa49654

Adding a --no-tls flag to the treequel shell

Comments (0)

Files changed (1)

 	def self.start_session( obj )
 		unless @__initialized
 			args = ARGV
-			ARGV.replace( ARGV.dup )
+			ARGV.replace( [] )
 			IRB.setup( nil )
 			ARGV.replace( args )
 			@__initialized = true
 	### Run the shell.
 	def self::run( args )
 		Treequel.logger.formatter = Treequel::ColorLogFormatter.new( Treequel.logger )
-		bind_as, uri = self.parse_options( args )
+		bind_as, plaintext, uri = self.parse_options( args )
+
+		connect_type = plaintext ? :plain : :tls
 
 		directory = if uri
-			Treequel.directory( uri )
+			Treequel.directory( uri, :connect_type => connect_type )
 		else
 			Treequel.directory_from_config
 		end
 			collect {|name,lvl| name.to_s }.
 			join(', ')
 		bind_as = nil
+		plaintext = false
 
 		oparser = OptionParser.new( "Usage: #{progname} [OPTIONS] [LDAPURL]" ) do |oparser|
 			oparser.separator ' '
 				bind_as = dn
 			end
 
+			oparser.on( '--no-tls', FalseClass, "Use a plaintext (unencrypted) connection.",
+			 	"If you don't specify a connection URL, this option is ignored." ) do
+				plaintext = true
+			end
+
 			oparser.on( '--loglevel=LEVEL', '-l LEVEL', Treequel::LOG_LEVELS.keys,
 				"Set the logging level. Should be one of:", loglevels ) do |lvl|
 				Treequel.logger.level = Treequel::LOG_LEVELS[ lvl ] or
 
 		remaining_args = oparser.parse( argv )
 
-		return bind_as, *remaining_args
+		return bind_as, plaintext, *remaining_args
 	end
 
 
 	protected
 	#########
 
-	### Fetch a Treequel::Directory object for the directory at the given +uri+, or
-	### quit with an error if unable to do so.
-	def get_ldap_directory( uri, options )
-		if uri.port == LDAP::LDAP_PORT
-			if options.try_tls
-				return Treequel.directory( uri, :connect_type => :tls )
-			else
-				return Treequel.directory( uri, :connect_type => :plain )
-			end
-		else
-			return Treequel.directory( uri, :connect_type => :ssl )
-		end
-	end
-
-
 	### Set up Readline completion
 	def setup_completion
 		Readline.completion_proc = self.method( :completion_callback ).to_proc