ldap-shell-utils 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,35 @@
1
+ = LDAP Shell utils
2
+
3
+ A little wrapper over ldapsearch command a piece for working with shell wrappers
4
+
5
+
6
+ == Installation
7
+
8
+ gem install ldap-shell-utils
9
+
10
+
11
+ == Examples
12
+
13
+ * lsu --config myldapconfigfile.yml --filter uid=testuser --attributes mailAlternateAddress
14
+ * lsu --config myldapconfigfile.yml --filter '(&(ojectClass=VirtualMailAccount)(uid=testuser)(mailAlternateAddress=*@example.com))'
15
+
16
+ * How to write a simple shell wrapper that can be work with base64 dn for example
17
+
18
+ #
19
+ # Find the Distinguished Name for an UID
20
+ #
21
+ __ldap_find_by_uid() {
22
+
23
+ [ -s ${LDAP_CONFIG} ] && [ -n "${1}" ] && lsu --config ${LDAP_CONFIG} --filter uid=${1} dn
24
+ }
25
+
26
+
27
+ == To Do
28
+
29
+ * Testing all this stuff
30
+ * Improve flexibility... for example changing the ldap base with a simple command line option
31
+
32
+
33
+ == License
34
+
35
+ Copyright © 2007-2010 Javier Juarez, released under the MIT license.
data/bin/lsu ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift( File.join( File.dirname( __FILE__ ), %w[.. lib] ) )
4
+
5
+ require 'loader'
6
+
7
+ LdapShellUtils::CliApplication.run(
8
+ Choice.choices[:config],
9
+ Choice.choices[:filter],
10
+ Choice.choices[:attributes]
11
+ )
@@ -0,0 +1,25 @@
1
+ require 'rubygems'
2
+ require 'config_context'
3
+
4
+
5
+ module LdapShellUtils
6
+ module CliApplication
7
+ extend self
8
+
9
+ def run( config, filter, attributes )
10
+
11
+ ConfigContext.load( File.expand_path( config ) )
12
+ results = LdapConnection.new( ConfigContext.url, ConfigContext.all ).search( filter, attributes )
13
+
14
+ if( results )
15
+ results.each do |entry|
16
+
17
+ puts "dn: #{entry.dn}"
18
+ entry.each { |a,v| puts " - #{a}: #{v.length == 1 ? v[0]:v.inspect}" unless a == :dn }
19
+ end
20
+ end
21
+ rescue Exception => e
22
+ $stderr.puts( e.message )
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,42 @@
1
+ require 'rubygems'
2
+ require 'uri'
3
+ require 'net/ldap'
4
+
5
+
6
+ module LdapShellUtils
7
+ class LdapConnection
8
+
9
+ attr_reader :connection
10
+
11
+ def initialize( url, config )
12
+
13
+ @uri = URI.parse( url )
14
+ @configuration = {
15
+ :host => @uri.host,
16
+ :port => @uri.port,
17
+ :base => config[:base],
18
+ :auth => {
19
+ :method => :simple,
20
+ :username => config[:username],
21
+ :password => config[:password]
22
+ }
23
+ }
24
+
25
+ @configuration[:encryption] = { :method => :simple_tls } if( @uri.scheme.to_sym == :ldaps )
26
+ @connection = Net::LDAP.new( @configuration )
27
+
28
+ self
29
+ rescue Exception => e
30
+ raise ArgumentError.new( e.message )
31
+ end
32
+
33
+ def search( filter, attributes=[] )
34
+
35
+ @connection.search( :filter=>Net::LDAP::Filter.from_rfc2254( filter ), :attributes=>attributes, :result=>false )
36
+ end
37
+
38
+ def to_s
39
+ "#{@configuration.uri}"
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,38 @@
1
+ require 'rubygems'
2
+ require 'choice'
3
+
4
+
5
+ Choice.options do
6
+
7
+ header ''
8
+ header ' options:'
9
+
10
+ option :config, :required=>true do
11
+ short '-c'
12
+ long '--config'
13
+ desc 'The Yaml config file'
14
+ end
15
+
16
+ option :filter, :required=>true do
17
+ short '-f'
18
+ long '--filter'
19
+ desc 'The LDAP query'
20
+ end
21
+
22
+ option :attributes, :required=>false do
23
+ short '-a'
24
+ long '--attributes *ATTRIBUTES'
25
+ desc 'The attributes list'
26
+ end
27
+
28
+ separator ''
29
+ separator ' help:'
30
+
31
+ option :help do
32
+ short '-h'
33
+ long '--help'
34
+ desc 'Show this help screen'
35
+ end
36
+
37
+ separator ''
38
+ end
@@ -0,0 +1,5 @@
1
+ begin
2
+ Dir.glob( File.join( File.dirname( __FILE__ ), "**", "*.rb" ) ).each { |library| require library }
3
+ rescue LoadError => e
4
+ $sdterr.puts( e.message )
5
+ end
@@ -0,0 +1,10 @@
1
+ module Version
2
+ INFO = {
3
+ :major =>0,
4
+ :minor =>0,
5
+ :patch =>1
6
+ }
7
+
8
+ NAME = 'ldap-shell-utils'
9
+ VERSION = [ INFO[:major], INFO[:minor], INFO[:patch] ].join( '.' )
10
+ end
metadata ADDED
@@ -0,0 +1,216 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ldap-shell-utils
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Javier Juarez
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-05-07 00:00:00 +02:00
19
+ default_executable: lsu
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ type: :runtime
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ name: choice
33
+ version_requirements: *id001
34
+ prerelease: false
35
+ - !ruby/object:Gem::Dependency
36
+ type: :runtime
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ hash: 3
43
+ segments:
44
+ - 0
45
+ version: "0"
46
+ name: net-ldap
47
+ version_requirements: *id002
48
+ prerelease: false
49
+ - !ruby/object:Gem::Dependency
50
+ type: :runtime
51
+ requirement: &id003 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ hash: 3
57
+ segments:
58
+ - 0
59
+ version: "0"
60
+ name: config_context
61
+ version_requirements: *id003
62
+ prerelease: false
63
+ - !ruby/object:Gem::Dependency
64
+ type: :development
65
+ requirement: &id004 !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ~>
69
+ - !ruby/object:Gem::Version
70
+ hash: 23
71
+ segments:
72
+ - 1
73
+ - 0
74
+ - 0
75
+ version: 1.0.0
76
+ name: bundler
77
+ version_requirements: *id004
78
+ prerelease: false
79
+ - !ruby/object:Gem::Dependency
80
+ type: :development
81
+ requirement: &id005 !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ hash: 3
87
+ segments:
88
+ - 0
89
+ version: "0"
90
+ name: shoulda
91
+ version_requirements: *id005
92
+ prerelease: false
93
+ - !ruby/object:Gem::Dependency
94
+ type: :development
95
+ requirement: &id006 !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ~>
99
+ - !ruby/object:Gem::Version
100
+ hash: 1
101
+ segments:
102
+ - 1
103
+ - 5
104
+ - 1
105
+ version: 1.5.1
106
+ name: jeweler
107
+ version_requirements: *id006
108
+ prerelease: false
109
+ - !ruby/object:Gem::Dependency
110
+ type: :development
111
+ requirement: &id007 !ruby/object:Gem::Requirement
112
+ none: false
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ hash: 3
117
+ segments:
118
+ - 0
119
+ version: "0"
120
+ name: rcov
121
+ version_requirements: *id007
122
+ prerelease: false
123
+ - !ruby/object:Gem::Dependency
124
+ type: :runtime
125
+ requirement: &id008 !ruby/object:Gem::Requirement
126
+ none: false
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ hash: 3
131
+ segments:
132
+ - 0
133
+ version: "0"
134
+ name: net-ldap
135
+ version_requirements: *id008
136
+ prerelease: false
137
+ - !ruby/object:Gem::Dependency
138
+ type: :runtime
139
+ requirement: &id009 !ruby/object:Gem::Requirement
140
+ none: false
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ hash: 3
145
+ segments:
146
+ - 0
147
+ version: "0"
148
+ name: choice
149
+ version_requirements: *id009
150
+ prerelease: false
151
+ - !ruby/object:Gem::Dependency
152
+ type: :runtime
153
+ requirement: &id010 !ruby/object:Gem::Requirement
154
+ none: false
155
+ requirements:
156
+ - - ">="
157
+ - !ruby/object:Gem::Version
158
+ hash: 3
159
+ segments:
160
+ - 0
161
+ version: "0"
162
+ name: config_context
163
+ version_requirements: *id010
164
+ prerelease: false
165
+ description: This is a simple wrapper over ldapsearch util avoiding base64 dn and others gotchas
166
+ email: javier.juarez@gmail.com
167
+ executables:
168
+ - lsu
169
+ extensions: []
170
+
171
+ extra_rdoc_files:
172
+ - README.rdoc
173
+ files:
174
+ - lib/ldap-shell-utils/cli_application.rb
175
+ - lib/ldap-shell-utils/ldap_connection.rb
176
+ - lib/ldap-shell-utils/options_parser.rb
177
+ - lib/loader.rb
178
+ - lib/version.rb
179
+ - README.rdoc
180
+ - bin/lsu
181
+ has_rdoc: true
182
+ homepage: http://github.com/jjuarez/ldap-shell-utils
183
+ licenses:
184
+ - MIT License
185
+ post_install_message:
186
+ rdoc_options: []
187
+
188
+ require_paths:
189
+ - lib
190
+ required_ruby_version: !ruby/object:Gem::Requirement
191
+ none: false
192
+ requirements:
193
+ - - ">="
194
+ - !ruby/object:Gem::Version
195
+ hash: 3
196
+ segments:
197
+ - 0
198
+ version: "0"
199
+ required_rubygems_version: !ruby/object:Gem::Requirement
200
+ none: false
201
+ requirements:
202
+ - - ">="
203
+ - !ruby/object:Gem::Version
204
+ hash: 3
205
+ segments:
206
+ - 0
207
+ version: "0"
208
+ requirements: []
209
+
210
+ rubyforge_project: http://github.com/jjuarez/ldap-shell-utils
211
+ rubygems_version: 1.6.2
212
+ signing_key:
213
+ specification_version: 3
214
+ summary: A minimal ldapsearch wrapper
215
+ test_files: []
216
+