ruby-ldap 0.9.11 → 0.9.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. data/ChangeLog +18 -0
  2. data/FAQ +5 -9
  3. data/NOTES +29 -0
  4. data/README +22 -18
  5. data/TODO +10 -0
  6. data/clientauth.c +605 -0
  7. data/conn.c +24 -1
  8. data/entry.c +9 -9
  9. data/extconf.rb +70 -29
  10. data/ldap.c +67 -0
  11. data/lib/ldap/control.rb +3 -3
  12. data/lib/ldap/ldif.rb +264 -269
  13. data/lib/ldap/schema.rb +39 -33
  14. data/mod.c +7 -3
  15. data/rbldap.h +8 -6
  16. data/test/cookbooks/apt/metadata.rb +13 -0
  17. data/test/cookbooks/apt/providers/repository.rb +73 -0
  18. data/test/cookbooks/apt/recipes/cacher-client.rb +44 -0
  19. data/test/cookbooks/apt/recipes/cacher.rb +45 -0
  20. data/test/cookbooks/apt/recipes/default.rb +50 -0
  21. data/test/cookbooks/apt/resources/repository.rb +30 -0
  22. data/test/cookbooks/nginx/attributes/default.rb +35 -0
  23. data/test/cookbooks/nginx/definitions/nginx_site.rb +35 -0
  24. data/test/cookbooks/nginx/metadata.rb +86 -0
  25. data/test/cookbooks/nginx/recipes/default.rb +56 -0
  26. data/test/cookbooks/nginx/recipes/source.rb +143 -0
  27. data/test/cookbooks/openldap/attributes/default.rb +61 -0
  28. data/test/cookbooks/openldap/metadata.rb +99 -0
  29. data/test/cookbooks/openldap/recipes/auth.rb +70 -0
  30. data/test/cookbooks/openldap/recipes/client.rb +28 -0
  31. data/test/cookbooks/openldap/recipes/default.rb +18 -0
  32. data/test/cookbooks/openldap/recipes/server.rb +110 -0
  33. data/test/cookbooks/postgresql/attributes/default.rb +68 -0
  34. data/test/cookbooks/postgresql/metadata.rb +15 -0
  35. data/test/cookbooks/postgresql/recipes/client.rb +27 -0
  36. data/test/cookbooks/postgresql/recipes/default.rb +20 -0
  37. data/test/cookbooks/postgresql/recipes/server.rb +36 -0
  38. data/test/cookbooks/postgresql/recipes/server_debian.rb +51 -0
  39. data/test/cookbooks/postgresql/recipes/server_redhat.rb +84 -0
  40. data/test/cookbooks/sqlite/metadata.rb +11 -0
  41. data/test/cookbooks/sqlite/recipes/default.rb +26 -0
  42. data/test/cookbooks/vagrant_main/recipes/default.rb +12 -0
  43. data/test/moz_cert.rb +105 -0
  44. data/test/setup.rb +2 -2
  45. data/win/wldap32.def +257 -0
  46. metadata +78 -55
data/lib/ldap/schema.rb CHANGED
@@ -15,9 +15,9 @@ module LDAP
15
15
 
16
16
  def initialize(entry)
17
17
  if( entry )
18
- entry.each{|key,vals|
19
- self[key] = vals
20
- }
18
+ entry.each do |key, vals|
19
+ self[key] = vals
20
+ end
21
21
  end
22
22
  end
23
23
 
@@ -32,14 +32,15 @@ module LDAP
32
32
  # +at+. +at+ may be the string *MUST*, *MAY* or *SUP*.
33
33
  #
34
34
  def attr(oc,at)
35
- self['objectClasses'].each{|s|
36
- if( s =~ /NAME\s+'#{oc}'/ )
37
- case s
38
- when /#{at}\s+\(([\w\d_\-\s\$]+)\)/i then return $1.split("$").collect{|attr| attr.strip}
39
- when /#{at}\s+([\w\d_\-]+)/i then return $1.split("$").collect{|attr| attr.strip}
40
- end
41
- end
42
- }
35
+ self['objectClasses'].each do |s|
36
+ if( s =~ /NAME\s+'#{oc}'/ )
37
+ case s
38
+ when /#{at}\s+\(([\w\d_\-\s\$]+)\)/i then return $1.split("$").collect{|attr| attr.strip}
39
+ when /#{at}\s+([\w\d_\-]+)/i then return $1.split("$").collect{|attr| attr.strip}
40
+ end
41
+ end
42
+ end
43
+
43
44
  return nil
44
45
  end
45
46
 
@@ -62,6 +63,7 @@ module LDAP
62
63
  def sup(oc)
63
64
  attr(oc, "SUP")
64
65
  end
66
+
65
67
  end
66
68
 
67
69
  class Conn
@@ -76,23 +78,24 @@ module LDAP
76
78
  #
77
79
  # +sec+ and +usec+ can be used to specify a time-out for the search in
78
80
  # seconds and microseconds, respectively.
79
- #
81
+ #
80
82
  def schema(base = nil, attrs = nil, sec = 0, usec = 0)
81
83
  attrs ||= [
82
- 'objectClasses',
83
- 'attributeTypes',
84
- 'matchingRules',
85
- 'matchingRuleUse',
86
- 'dITStructureRules',
87
- 'dITContentRules',
88
- 'nameForms',
89
- 'ldapSyntaxes',
84
+ 'objectClasses',
85
+ 'attributeTypes',
86
+ 'matchingRules',
87
+ 'matchingRuleUse',
88
+ 'dITStructureRules',
89
+ 'dITContentRules',
90
+ 'nameForms',
91
+ 'ldapSyntaxes',
90
92
  ]
91
93
  base ||= root_dse(['subschemaSubentry'], sec, usec)[0]['subschemaSubentry'][0]
92
94
  base ||= 'cn=schema'
93
- ent = search2(base, LDAP_SCOPE_BASE, '(objectClass=subschema)',
94
- attrs, false, sec, usec)
95
- return Schema.new(ent[0])
95
+ entries = search2(base, LDAP_SCOPE_BASE, '(objectClass=subschema)',
96
+ attrs, false, sec, usec)
97
+
98
+ return Schema.new(entries[0])
96
99
  end
97
100
 
98
101
  # Fetch the root DSE (DSA-specific Entry) for the connection. DSA stands
@@ -110,20 +113,23 @@ module LDAP
110
113
  #
111
114
  def root_dse(attrs = nil, sec = 0, usec = 0)
112
115
  attrs ||= [
113
- 'subschemaSubentry',
114
- 'namingContexts',
115
- 'monitorContext',
116
- 'altServer',
117
- 'supportedControl',
118
- 'supportedExtension',
119
- 'supportedFeatures',
120
- 'supportedSASLMechanisms',
121
- 'supportedLDAPVersion',
116
+ 'subschemaSubentry',
117
+ 'namingContexts',
118
+ 'monitorContext',
119
+ 'altServer',
120
+ 'supportedControl',
121
+ 'supportedExtension',
122
+ 'supportedFeatures',
123
+ 'supportedSASLMechanisms',
124
+ 'supportedLDAPVersion',
122
125
  ]
123
126
 
124
127
  entries = search2('', LDAP_SCOPE_BASE, '(objectClass=*)',
125
- attrs, false, sec, usec)
128
+ attrs, false, sec, usec)
129
+
126
130
  return entries
127
131
  end
132
+
128
133
  end
134
+
129
135
  end
data/mod.c CHANGED
@@ -18,6 +18,7 @@ rb_ldap_mod_free (RB_LDAPMOD_DATA * data)
18
18
  char **svals;
19
19
  int i;
20
20
 
21
+ xfree(data->mod->mod_type);
21
22
  if (data->mod->mod_op & LDAP_MOD_BVALUES)
22
23
  {
23
24
  bvals = data->mod->mod_vals.modv_bvals;
@@ -38,6 +39,7 @@ rb_ldap_mod_free (RB_LDAPMOD_DATA * data)
38
39
  }
39
40
  xfree (data->mod);
40
41
  }
42
+ xfree (data);
41
43
  }
42
44
 
43
45
  static LDAPMod *
@@ -52,7 +54,8 @@ rb_ldap_new_mod (int mod_op, char *mod_type, char **modv_strvals)
52
54
 
53
55
  mod = ALLOC_N (LDAPMod, 1);
54
56
  mod->mod_op = mod_op;
55
- mod->mod_type = mod_type;
57
+ mod->mod_type = ALLOC_N(char,strlen(mod_type) + 1);
58
+ strcpy(mod->mod_type, mod_type);
56
59
  mod->mod_vals.modv_strvals = modv_strvals;
57
60
 
58
61
  return mod;
@@ -83,7 +86,8 @@ rb_ldap_new_mod2 (int mod_op, char *mod_type, struct berval **modv_bvals)
83
86
 
84
87
  mod = ALLOC_N (LDAPMod, 1);
85
88
  mod->mod_op = mod_op;
86
- mod->mod_type = mod_type;
89
+ mod->mod_type = ALLOC_N(char,strlen(mod_type) + 1);
90
+ strcpy(mod->mod_type, mod_type);
87
91
  mod->mod_vals.modv_bvals = modv_bvals;
88
92
 
89
93
  return mod;
@@ -148,7 +152,7 @@ rb_ldap_mod_initialize (int argc, VALUE argv[], VALUE self)
148
152
  return Qnil;
149
153
 
150
154
  mod_op = NUM2INT (op);
151
- mod_type = StringValueCStr (type);
155
+ mod_type = RSTRING_PTR(type);
152
156
  Check_Type (vals, T_ARRAY);
153
157
 
154
158
  if (mod_op & LDAP_MOD_BVALUES)
data/rbldap.h CHANGED
@@ -27,8 +27,8 @@
27
27
 
28
28
  #define RB_LDAP_MAJOR_VERSION 0
29
29
  #define RB_LDAP_MINOR_VERSION 9
30
- #define RB_LDAP_PATCH_VERSION 11
31
- #define RB_LDAP_VERSION "0.9.11"
30
+ #define RB_LDAP_PATCH_VERSION 12
31
+ #define RB_LDAP_VERSION "0.9.12"
32
32
 
33
33
  #define LDAP_GET_OPT_MAX_BUFFER_SIZE (1024) /* >= sizeof(LDAPAPIInfo) */
34
34
 
@@ -140,13 +140,13 @@ VALUE rb_ldap_mod_vals (VALUE);
140
140
  };
141
141
 
142
142
  #define Check_LDAP_Result(err) { \
143
- if( err != LDAP_SUCCESS && err != LDAP_SIZELIMIT_EXCEEDED ){ \
143
+ if( (err) != LDAP_SUCCESS && (err) != LDAP_SIZELIMIT_EXCEEDED ){ \
144
144
  rb_raise(rb_eLDAP_ResultError, ldap_err2string(err)); \
145
145
  } \
146
146
  }
147
147
 
148
148
  #define Check_LDAP_OPT_Result(err) { \
149
- if( err != LDAP_OPT_SUCCESS ){ \
149
+ if( (err) != LDAP_OPT_SUCCESS ){ \
150
150
  rb_raise(rb_eLDAP_ResultError, ldap_err2string(err)); \
151
151
  } \
152
152
  }
@@ -162,16 +162,18 @@ VALUE rb_ldap_mod_vals (VALUE);
162
162
  RB_LDAPENTRY_DATA *ptr; \
163
163
  Data_Get_Struct(obj, struct rb_ldapmsg_data, ptr); \
164
164
  if( ! ptr->msg ){ \
165
+ VALUE value = rb_inspect(obj); \
165
166
  rb_raise(rb_eLDAP_InvalidEntryError, "%s is not a valid entry", \
166
- STR2CSTR(rb_inspect(obj))); \
167
+ StringValuePtr(value)); \
167
168
  }; \
168
169
  }
169
170
 
170
171
  #define GET_LDAPENTRY_DATA(obj,ptr) { \
171
172
  Data_Get_Struct(obj, struct rb_ldapentry_data, ptr); \
172
173
  if( ! ptr->msg ){ \
174
+ VALUE value = rb_inspect(obj); \
173
175
  rb_raise(rb_eLDAP_InvalidEntryError, "%s is not a valid entry", \
174
- STR2CSTR(rb_inspect(obj))); \
176
+ StringValuePtr(value)); \
175
177
  }; \
176
178
  }
177
179
 
@@ -0,0 +1,13 @@
1
+ maintainer "Opscode, Inc."
2
+ maintainer_email "cookbooks@opscode.com"
3
+ license "Apache 2.0"
4
+ description "Configures apt and apt services and an LWRP for managing apt repositories"
5
+ long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
6
+ version "1.2.0"
7
+ recipe "apt", "Runs apt-get update during compile phase and sets up preseed directories"
8
+ recipe "apt::cacher", "Set up an APT cache"
9
+ recipe "apt::cacher-client", "Client for the apt::cacher server"
10
+
11
+ %w{ ubuntu debian }.each do |os|
12
+ supports os
13
+ end
@@ -0,0 +1,73 @@
1
+ #
2
+ # Cookbook Name:: apt
3
+ # Provider:: repository
4
+ #
5
+ # Copyright 2010-2011, Opscode, Inc.
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+ #
19
+
20
+ action :add do
21
+ unless ::File.exists?("/etc/apt/sources.list.d/#{new_resource.repo_name}-source.list")
22
+ Chef::Log.info "Adding #{new_resource.repo_name} repository to /etc/apt/sources.list.d/#{new_resource.repo_name}-source.list"
23
+ # add key
24
+ if new_resource.keyserver && new_resource.key
25
+ execute "install-key #{new_resource.key}" do
26
+ command "apt-key adv --keyserver #{new_resource.keyserver} --recv #{new_resource.key}"
27
+ action :nothing
28
+ end.run_action(:run)
29
+ elsif new_resource.key && (new_resource.key =~ /http/)
30
+ key_name = new_resource.key.split(/\//).last
31
+ remote_file "#{Chef::Config[:file_cache_path]}/#{key_name}" do
32
+ source new_resource.key
33
+ mode "0644"
34
+ action :nothing
35
+ end.run_action(:create_if_missing)
36
+ execute "install-key #{key_name}" do
37
+ command "apt-key add #{Chef::Config[:file_cache_path]}/#{key_name}"
38
+ action :nothing
39
+ end.run_action(:run)
40
+ end
41
+ # build our listing
42
+ repository = "deb"
43
+ repository = "deb-src" if new_resource.deb_src
44
+ repository = "# Created by the Chef apt_repository LWRP\n" + repository
45
+ repository += " #{new_resource.uri}"
46
+ repository += " #{new_resource.distribution}"
47
+ new_resource.components.each {|component| repository += " #{component}"}
48
+ # write out the file, replace it if it already exists
49
+ file "/etc/apt/sources.list.d/#{new_resource.repo_name}-source.list" do
50
+ owner "root"
51
+ group "root"
52
+ mode 0644
53
+ content repository + "\n"
54
+ action :nothing
55
+ end.run_action(:create)
56
+ execute "update package index" do
57
+ command "apt-get update"
58
+ ignore_failure true
59
+ action :nothing
60
+ end.run_action(:run)
61
+ new_resource.updated_by_last_action(true)
62
+ end
63
+ end
64
+
65
+ action :remove do
66
+ if ::File.exists?("/etc/apt/sources.list.d/#{new_resource.repo_name}-source.list")
67
+ Chef::Log.info "Removing #{new_resource.repo_name} repository from /etc/apt/sources.list.d/"
68
+ file "/etc/apt/sources.list.d/#{new_resource.repo_name}-source.list" do
69
+ action :delete
70
+ end
71
+ new_resource.updated_by_last_action(true)
72
+ end
73
+ end
@@ -0,0 +1,44 @@
1
+ #
2
+ # Cookbook Name:: apt
3
+ # Recipe:: cacher-client
4
+ #
5
+ # Copyright 2011, Opscode, Inc.
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+ #
19
+
20
+ #remove Acquire::http::Proxy lines from /etc/apt/apt.conf since we use 01proxy
21
+ #these are leftover from preseed installs
22
+ execute "Remove proxy from /etc/apt/apt.conf" do
23
+ command "sed --in-place '/^Acquire::http::Proxy/d' /etc/apt/apt.conf"
24
+ only_if "grep Acquire::http::Proxy /etc/apt/apt.conf"
25
+ end
26
+
27
+ servers = search(:node, 'recipes:apt\:\:cacher') || []
28
+ if servers.length > 0
29
+ Chef::Log.info("apt-cacher server found on #{servers[0]}.")
30
+ proxy = "Acquire::http::Proxy \"http://#{servers[0].ipaddress}:3142\";\n"
31
+ file "/etc/apt/apt.conf.d/01proxy" do
32
+ owner "root"
33
+ group "root"
34
+ mode "0644"
35
+ content proxy
36
+ action :create
37
+ end
38
+ else
39
+ Chef::Log.info("No apt-cacher server found.")
40
+ file "/etc/apt/apt.conf.d/01proxy" do
41
+ action :delete
42
+ only_if {File.exists?("/etc/apt/apt.conf.d/01proxy")}
43
+ end
44
+ end
@@ -0,0 +1,45 @@
1
+ #
2
+ # Cookbook Name:: apt
3
+ # Recipe:: cacher
4
+ #
5
+ # Copyright 2008-2011, Opscode, Inc.
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+ #
19
+ package "apt-cacher" do
20
+ action :install
21
+ end
22
+
23
+ service "apt-cacher" do
24
+ supports :restart => true, :status => false
25
+ action [ :enable, :start ]
26
+ end
27
+
28
+ cookbook_file "/etc/apt-cacher/apt-cacher.conf" do
29
+ source "apt-cacher.conf"
30
+ owner "root"
31
+ group "root"
32
+ mode 0644
33
+ notifies :restart, resources(:service => "apt-cacher")
34
+ end
35
+
36
+ cookbook_file "/etc/default/apt-cacher" do
37
+ source "apt-cacher"
38
+ owner "root"
39
+ group "root"
40
+ mode 0644
41
+ notifies :restart, resources(:service => "apt-cacher")
42
+ end
43
+
44
+ #this will help seed the proxy
45
+ include_recipe "apt::cacher-client"
@@ -0,0 +1,50 @@
1
+ #
2
+ # Cookbook Name:: apt
3
+ # Recipe:: default
4
+ #
5
+ # Copyright 2008-2011, Opscode, Inc.
6
+ # Copyright 2009, Bryan McLellan <btm@loftninjas.org>
7
+ #
8
+ # Licensed under the Apache License, Version 2.0 (the "License");
9
+ # you may not use this file except in compliance with the License.
10
+ # You may obtain a copy of the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS,
16
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ # See the License for the specific language governing permissions and
18
+ # limitations under the License.
19
+ #
20
+
21
+ # Run apt-get update to create the stamp file
22
+ execute "apt-get-update" do
23
+ command "apt-get update"
24
+ ignore_failure true
25
+ not_if do ::File.exists?('/var/lib/apt/periodic/update-success-stamp') end
26
+ action :nothing
27
+ end
28
+
29
+ # provides /var/lib/apt/periodic/update-success-stamp on apt-get update
30
+ package "update-notifier-common" do
31
+ notifies :run, resources(:execute => "apt-get-update"), :immediately
32
+ end
33
+
34
+ execute "apt-get-update-periodic" do
35
+ command "apt-get update"
36
+ ignore_failure true
37
+ only_if do
38
+ File.exists?('/var/lib/apt/periodic/update-success-stamp') &&
39
+ File.mtime('/var/lib/apt/periodic/update-success-stamp') < Time.now - 86400
40
+ end
41
+ end
42
+
43
+ %w{/var/cache/local /var/cache/local/preseeding}.each do |dirname|
44
+ directory dirname do
45
+ owner "root"
46
+ group "root"
47
+ mode 0644
48
+ action :create
49
+ end
50
+ end
@@ -0,0 +1,30 @@
1
+ #
2
+ # Cookbook Name:: apt
3
+ # Resource:: repository
4
+ #
5
+ # Copyright 2010-2011, Opscode, Inc.
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+ #
19
+
20
+ actions :add, :remove
21
+
22
+ #name of the repo, used for source.list filename
23
+ attribute :repo_name, :kind_of => String, :name_attribute => true
24
+ attribute :uri, :kind_of => String
25
+ attribute :distribution, :kind_of => String
26
+ attribute :components, :kind_of => Array, :default => []
27
+ #whether or not to add the repository as a source repo as well
28
+ attribute :deb_src, :default => false
29
+ attribute :keyserver, :kind_of => String, :default => nil
30
+ attribute :key, :kind_of => String, :default => nil