ruby-ldap 0.9.18 → 0.9.19

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
- ---
2
- SHA1:
3
- metadata.gz: b6924c44fe913f0e2f2886a6d867e315a4c4d1d2
4
- data.tar.gz: 78eb5ced76910731afc0ef06aed0f47440f5e943
5
- SHA512:
6
- metadata.gz: e8550110a3097ed2c36dc787dfe392de3c6b7bec9de5887729cff903ca390e82d34a3dd403098684d61f0db056ce637837a968ae1507f91467e705221daa3858
7
- data.tar.gz: 3bff7856fbeec9d8b091d94571b9b396f110dfcfa8ed931fd26ef6e24d3db2ff4daa3bc43591b9221e0fbce3bdc582ee67dfab52b5baa0d8375b250b9a43d835
1
+ ---
2
+ SHA512:
3
+ metadata.gz: fbdef63d5618e4f8a8500c7afff630ba9622436f23ef7b5a7e16717d44aaf175f6932e90ca95afc8c5a5e2ff4e1a028a8e1e8ca4909260a9f563d8e33b42dc1e
4
+ data.tar.gz: 337ea5de70b3d724077e34700510f7c18f6bf574bdfa099c73507368a6883164ff25eecfa43cdc67c8340ad04229d1c2ec8fe1ea48ac7a7a0e60e9f0a300881a
5
+ SHA1:
6
+ metadata.gz: d7de5be007d5104fd3cfd75aeaee5170c5f8c5b4
7
+ data.tar.gz: e0fcbbcfce4ec9a65a213550e6c7228eafd27b2b
data/ChangeLog CHANGED
@@ -1,3 +1,8 @@
1
+ Mon Jun 20 14:30:52 UTC 2016 Alexey Chebotar <alexey.chebotar@gmail.com>
2
+ * Version 0.9.19
3
+ * Fixed parsing of LDIF with CR LF line separators (GH-38).
4
+ Thanks to doppelreim.
5
+
1
6
  Fri Mar 4 11:17:21 UTC 2016 Alexey Chebotar <alexey.chebotar@gmail.com>
2
7
  * Version 0.9.18
3
8
  * backout issue32 to compile for ruby-1.8.x.
data/NOTES CHANGED
@@ -1,3 +1,9 @@
1
+ 0.9.19
2
+ -----
3
+ * Fixed parsing of LDIF with CR LF line separators (GH-38).
4
+ Thanks to doppelreim.
5
+
6
+
1
7
  0.9.18
2
8
  -----
3
9
  * backout issue32 to compile for ruby-1.8.x.
data/TODO CHANGED
@@ -3,9 +3,6 @@
3
3
  To-do list
4
4
  ----------
5
5
 
6
- - Running tests:
7
- ./test/test.sh /Users/bearded/.rvm/rubies/ruby-1.8.7-head/bin/ruby openldap2 /usr/libexec/slapd /etc/openldap/schema/
8
-
9
6
  - Support for more LDAPv3 controls and extensions.
10
7
 
11
8
  - DSML support.
data/extconf.rb CHANGED
@@ -235,7 +235,6 @@ for l in [$libcrypto, $libssl, $libnsl, $libpthread, $libresolv,
235
235
  end
236
236
 
237
237
  have_func("ldap_init", 'ldap.h')
238
- have_func('rb_hash_dup')
239
238
  have_func("ldap_set_option")
240
239
  have_func("ldap_get_option")
241
240
  have_func("ldap_start_tls_s") if $use_openldap2
@@ -261,12 +260,12 @@ $defs << "-DRUBY_VERSION_CODE=#{RUBY_VERSION.gsub(/\D/, '')}"
261
260
  create_makefile("ldap")
262
261
 
263
262
 
264
- $slapd = ldap_with_config("slapd") || File.join("/usr","libexec","slapd")
263
+ $slapd = ldap_with_config("slapd") || File.join($ldap_dir,"libexec","slapd")
265
264
  $schema_dir = ldap_with_config("schema-dir")
266
265
  if( !$schema_dir )
267
- $schema_dir = File.join("/etc","openldap","schema")
266
+ $schema_dir = File.join($ldap_dir,"etc","openldap","schema")
268
267
  if( !File.exist?($schema_dir) )
269
- $schema_dir = File.join("/etc","openldap")
268
+ $schema_dir = File.join($ldap_dir,"etc","openldap")
270
269
  end
271
270
  end
272
271
 
@@ -185,28 +185,27 @@ module LDAP
185
185
  mod_type = nil
186
186
 
187
187
  lines.each do |line|
188
+ _line = line.chomp
188
189
  # Skip (continued) comments.
189
- if line =~ /^#/ || ( comment && line[0..0] == ' ' )
190
+ if _line =~ /^#/ || ( comment && _line[0..0] == ' ' )
190
191
  comment = true
191
192
  next
192
193
  end
193
194
 
194
195
  # Skip blank lines.
195
- next if line =~ /^$/
196
+ next if _line =~ /^$/
196
197
 
197
198
  # Reset mod type if this entry has more than one mod to make.
198
199
  # A '-' continuation is only valid if we've already had a
199
200
  # 'changetype: modify' line.
200
- if line =~ /^-$/ && change_type == LDAP_MOD_REPLACE
201
+ if _line =~ /^-$/ && change_type == LDAP_MOD_REPLACE
201
202
  next
202
203
  end
203
204
 
204
- line.chomp!
205
-
206
205
  # N.B. Attributes and values can be separated by one or two colons,
207
206
  # or one colon and a '<'. Either of these is then followed by zero
208
207
  # or one spaces.
209
- if md = line.match( /^[^ ].*?((:[:<]?) ?)/ )
208
+ if md = _line.match( /^[^ ].*?((:[:<]?) ?)/ )
210
209
 
211
210
  # If previous value was Base64-encoded and is not continued,
212
211
  # we need to decode it now.
@@ -222,7 +221,7 @@ module LDAP
222
221
  end
223
222
 
224
223
  # Found a attr/value line.
225
- attr, val = line.split( md[1], 2 )
224
+ attr, val = _line.split( md[1], 2 )
226
225
  attr.downcase!
227
226
 
228
227
  # Attribute must be ldap-oid / (ALPHA *(attr-type-chars))
@@ -331,21 +330,21 @@ module LDAP
331
330
  # continuation line must be indented. If a comment makes it this
332
331
  # far, that's also an error.
333
332
  #
334
- if sep == ':' && line[0..0] != ' ' || comment
335
- raise LDIFError, "Improperly continued line: #{line}"
333
+ if sep == ':' && _line[0..0] != ' ' || comment
334
+ raise LDIFError, "Improperly continued line: #{_line}"
336
335
  end
337
336
 
338
337
  # OK; this is a valid continuation line.
339
338
 
340
339
  # Append line except for initial space.
341
- line[0] = '' if line[0..0] == ' '
340
+ _line[0] = '' if _line[0..0] == ' '
342
341
 
343
342
  if change_type == LDAP_MOD_REPLACE
344
343
  # Append to last value of current mod type.
345
- mods[mod_type][attr][-1] << line
344
+ mods[mod_type][attr][-1] << _line
346
345
  else
347
346
  # Append to last value.
348
- hash[attr][-1] << line
347
+ hash[attr][-1] << _line
349
348
  end
350
349
  end
351
350
 
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 18
31
- #define RB_LDAP_VERSION "0.9.18"
30
+ #define RB_LDAP_PATCH_VERSION 19
31
+ #define RB_LDAP_VERSION "0.9.19"
32
32
 
33
33
  #define LDAP_GET_OPT_MAX_BUFFER_SIZE (1024) /* >= sizeof(LDAPAPIInfo) */
34
34
 
@@ -1,8 +1,9 @@
1
1
  # -*- ruby -*-
2
2
  # This file is a part of test scripts of LDAP extension module.
3
3
 
4
- require './ldap'
5
- require './test/conf'
4
+ $test = File.dirname($0)
5
+ require "#{$test}/conf"
6
+ require "./ldap"
6
7
 
7
8
  conn = LDAP::Conn.new($HOST, $PORT)
8
9
  conn.bind('cn=root, dc=localhost, dc=localdomain','secret'){
@@ -1,8 +1,9 @@
1
1
  # -*- ruby -*-
2
2
  # This file is a part of test scripts of LDAP extension module.
3
3
 
4
- require './ldap'
5
- require './test/conf'
4
+ $test = File.dirname($0)
5
+ require "#{$test}/conf"
6
+ require "./ldap"
6
7
 
7
8
  conn = LDAP::Conn.new($HOST, $PORT)
8
9
  conn.bind('cn=root, dc=localhost, dc=localdomain','secret'){
@@ -1,8 +1,9 @@
1
1
  # -*- ruby -*-
2
2
  # This file is a part of test scripts of LDAP extension module.
3
3
 
4
- require './ldap'
5
- require './test/conf'
4
+ $test = File.dirname($0)
5
+ require "#{$test}/conf"
6
+ require "./ldap"
6
7
 
7
8
  $KCODE = "UTF8"
8
9
 
@@ -1,13 +1,15 @@
1
1
  # -*- ruby -*-
2
2
  # This file is a part of test scripts of LDAP extension module.
3
3
 
4
- require './ldap'
5
- require './test/conf'
4
+ $test = File.dirname($0)
5
+ require "#{$test}/conf"
6
+ require "./ldap"
6
7
 
7
8
  LDAP::Conn.new($HOST, $PORT).bind{|conn|
8
9
  conn.perror("bind")
9
10
  begin
10
- conn.compare("cn=Takaaki Tateishi, dc=localhost, dc=localdomain", "cn", "Takaaki Tateishi")
11
+ conn.compare("cn=Takaaki Tateishi, dc=localhost, dc=localdomain",
12
+ "cn", "Takaaki Tateishi")
11
13
  rescue LDAP::ResultError
12
14
  exit(0)
13
15
  end
@@ -1,5 +1,7 @@
1
1
  # -*- ruby -*-
2
2
 
3
+ require './ldap'
4
+
3
5
  $HOST = 'localhost'
4
6
  begin
5
7
  $PORT = ARGV[0].to_i || LDAP::LDAP_PORT
@@ -0,0 +1,256 @@
1
+ /* ldif-filter -- clean up LDIF testdata from stdin */
2
+ /* $OpenLDAP$ */
3
+ /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4
+ *
5
+ * Copyright 2009-2016 The OpenLDAP Foundation.
6
+ * All rights reserved.
7
+ *
8
+ * Redistribution and use in source and binary forms, with or without
9
+ * modification, are permitted only as authorized by the OpenLDAP
10
+ * Public License.
11
+ *
12
+ * A copy of this license is available in file LICENSE in the
13
+ * top-level directory of the distribution or, alternatively, at
14
+ * <http://www.OpenLDAP.org/license.html>.
15
+ */
16
+
17
+ #include "portable.h"
18
+
19
+ #include <stdio.h>
20
+ #include <ac/ctype.h>
21
+ #include <ac/stdlib.h>
22
+ #include <ac/string.h>
23
+ #include <ac/unistd.h>
24
+ #ifdef _WIN32
25
+ #include <fcntl.h>
26
+ #endif
27
+
28
+ #define DEFAULT_SPECS "ndb=a,null=n"
29
+
30
+ typedef struct { char *val; size_t len, alloc; } String;
31
+ typedef struct { String *val; size_t len, alloc; } Strings;
32
+
33
+ /* Flags and corresponding program options */
34
+ enum { SORT_ATTRS = 1, SORT_ENTRIES = 2, NO_OUTPUT = 4, DUMMY_FLAG = 8 };
35
+ static const char spec_options[] = "aen"; /* option index = log2(enum flag) */
36
+
37
+ static const char *progname = "ldif-filter";
38
+ static const String null_string = { NULL, 0, 0 };
39
+
40
+ static void
41
+ usage( void )
42
+ {
43
+ fprintf( stderr, "\
44
+ Usage: %s [-b backend] [-s spec[,spec]...]\n\
45
+ Filter standard input by first <spec> matching '[<backend>]=[a][e][n]':\n\
46
+ - Remove LDIF comments.\n\
47
+ - 'a': Sort attributes in entries.\n\
48
+ - 'e': Sort any entries separated by just one empty line.\n\
49
+ - 'n': Output nothing.\n\
50
+ <backend> defaults to the $BACKEND environment variable.\n\
51
+ Use specs '%s' if no spec on the command line applies.\n",
52
+ progname, DEFAULT_SPECS );
53
+ exit( EXIT_FAILURE );
54
+ }
55
+
56
+ /* Return flags from "backend=flags" in spec; nonzero if backend found */
57
+ static unsigned
58
+ get_flags( const char *backend, const char *spec )
59
+ {
60
+ size_t len = strlen( backend );
61
+ unsigned flags = DUMMY_FLAG;
62
+ const char *end, *tmp;
63
+
64
+ for ( ;; spec = end + ( *end != '\0' )) {
65
+ if ( !*spec )
66
+ return 0;
67
+ end = spec + strcspn( spec, "," );
68
+ if ( !(tmp = memchr( spec, '=', end-spec )))
69
+ break;
70
+ if ( tmp-spec == len && !memcmp( spec, backend, len )) {
71
+ spec = tmp+1;
72
+ break;
73
+ }
74
+ }
75
+
76
+ for ( ; spec < end; spec++ ) {
77
+ if ( (tmp = strchr( spec_options, *spec )) == NULL ) {
78
+ usage();
79
+ }
80
+ flags |= 1U << (tmp - spec_options);
81
+ }
82
+ return flags;
83
+ }
84
+
85
+ #define APPEND(s /* String or Strings */, data, count, isString) do { \
86
+ size_t slen = (s)->len, salloc = (s)->alloc, sz = sizeof *(s)->val; \
87
+ if ( salloc <= slen + (count) ) { \
88
+ (s)->alloc = salloc += salloc + ((count)|7) + 1; \
89
+ (s)->val = xrealloc( (s)->val, sz * salloc ); \
90
+ } \
91
+ memcpy( (s)->val + slen, data, sz * ((count) + !!(isString)) ); \
92
+ (s)->len = slen + (count); \
93
+ } while (0)
94
+
95
+ static void *
96
+ xrealloc( void *ptr, size_t len )
97
+ {
98
+ if ( (ptr = realloc( ptr, len )) == NULL ) {
99
+ perror( progname );
100
+ exit( EXIT_FAILURE );
101
+ }
102
+ return ptr;
103
+ }
104
+
105
+ static int
106
+ cmp( const void *s, const void *t )
107
+ {
108
+ return strcmp( ((const String *) s)->val, ((const String *) t)->val );
109
+ }
110
+
111
+ static void
112
+ sort_strings( Strings *ss, size_t offset )
113
+ {
114
+ qsort( ss->val + offset, ss->len - offset, sizeof(*ss->val), cmp );
115
+ }
116
+
117
+ /* Build entry ss[n] from attrs ss[n...], and free the attrs */
118
+ static void
119
+ build_entry( Strings *ss, size_t n, unsigned flags, size_t new_len )
120
+ {
121
+ String *vals = ss->val, *e = &vals[n];
122
+ size_t end = ss->len;
123
+ char *ptr;
124
+
125
+ if ( flags & SORT_ATTRS ) {
126
+ sort_strings( ss, n + 1 );
127
+ }
128
+ e->val = xrealloc( e->val, e->alloc = new_len + 1 );
129
+ ptr = e->val + e->len;
130
+ e->len = new_len;
131
+ ss->len = ++n;
132
+ for ( ; n < end; free( vals[n++].val )) {
133
+ ptr = strcpy( ptr, vals[n].val ) + vals[n].len;
134
+ }
135
+ assert( ptr == e->val + new_len );
136
+ }
137
+
138
+ /* Flush entries to stdout and free them */
139
+ static void
140
+ flush_entries( Strings *ss, const char *sep, unsigned flags )
141
+ {
142
+ size_t i, end = ss->len;
143
+ const char *prefix = "";
144
+
145
+ if ( flags & SORT_ENTRIES ) {
146
+ sort_strings( ss, 0 );
147
+ }
148
+ for ( i = 0; i < end; i++, prefix = sep ) {
149
+ if ( printf( "%s%s", prefix, ss->val[i].val ) < 0 ) {
150
+ perror( progname );
151
+ exit( EXIT_FAILURE );
152
+ }
153
+ free( ss->val[i].val );
154
+ }
155
+ ss->len = 0;
156
+ }
157
+
158
+ static void
159
+ filter_stdin( unsigned flags )
160
+ {
161
+ char line[256];
162
+ Strings ss = { NULL, 0, 0 }; /* entries + attrs of partial entry */
163
+ size_t entries = 0, attrs_totlen = 0, line_len;
164
+ const char *entry_sep = "\n", *sep = "";
165
+ int comment = 0, eof = 0, eol, prev_eol = 1; /* flags */
166
+ String *s;
167
+
168
+ /* LDIF = Entries ss[..entries-1] + sep + attrs ss[entries..] + line */
169
+ for ( ; !eof || ss.len || *sep; prev_eol = eol ) {
170
+ if ( eof || (eof = !fgets( line, sizeof(line), stdin ))) {
171
+ strcpy( line, prev_eol ? "" : *sep ? sep : "\n" );
172
+ }
173
+ line_len = strlen( line );
174
+ eol = (line_len == 0 || line[line_len - 1] == '\n');
175
+
176
+ if ( *line == ' ' ) { /* continuation line? */
177
+ prev_eol = 0;
178
+ } else if ( prev_eol ) { /* start of logical line? */
179
+ comment = (*line == '#');
180
+ }
181
+ if ( comment || (flags & NO_OUTPUT) ) {
182
+ continue;
183
+ }
184
+
185
+ /* Collect attrs for partial entry in ss[entries...] */
186
+ if ( !prev_eol && attrs_totlen != 0 ) {
187
+ goto grow_attr;
188
+ } else if ( line_len > (*line == '\r' ? 2 : 1) ) {
189
+ APPEND( &ss, &null_string, 1, 0 ); /* new attr */
190
+ grow_attr:
191
+ s = &ss.val[ss.len - 1];
192
+ APPEND( s, line, line_len, 1 ); /* strcat to attr */
193
+ attrs_totlen += line_len;
194
+ continue;
195
+ }
196
+
197
+ /* Empty line - consume sep+attrs or entries+sep */
198
+ if ( attrs_totlen != 0 ) {
199
+ entry_sep = sep;
200
+ if ( entries == 0 )
201
+ fputs( sep, stdout );
202
+ build_entry( &ss, entries++, flags, attrs_totlen );
203
+ attrs_totlen = 0;
204
+ } else {
205
+ flush_entries( &ss, entry_sep, flags );
206
+ fputs( sep, stdout );
207
+ entries = 0;
208
+ }
209
+ sep = "\r\n" + 2 - line_len; /* sep = copy(line) */
210
+ }
211
+
212
+ free( ss.val );
213
+ }
214
+
215
+ int
216
+ main( int argc, char **argv )
217
+ {
218
+ const char *backend = getenv( "BACKEND" ), *specs = "", *tmp;
219
+ unsigned flags;
220
+ int i;
221
+
222
+ if ( argc > 0 ) {
223
+ progname = (tmp = strrchr( argv[0], '/' )) ? tmp+1 : argv[0];
224
+ }
225
+
226
+ while ( (i = getopt( argc, argv, "b:s:" )) != EOF ) {
227
+ switch ( i ) {
228
+ case 'b':
229
+ backend = optarg;
230
+ break;
231
+ case 's':
232
+ specs = optarg;
233
+ break;
234
+ default:
235
+ usage();
236
+ }
237
+ }
238
+ if ( optind < argc ) {
239
+ usage();
240
+ }
241
+ if ( backend == NULL ) {
242
+ backend = "";
243
+ }
244
+
245
+ #ifdef _WIN32
246
+ _setmode(1, _O_BINARY); /* don't convert \n to \r\n on stdout */
247
+ #endif
248
+ flags = get_flags( backend, specs );
249
+ filter_stdin( flags ? flags : get_flags( backend, DEFAULT_SPECS ));
250
+ if ( fclose( stdout ) == EOF ) {
251
+ perror( progname );
252
+ return EXIT_FAILURE;
253
+ }
254
+
255
+ return EXIT_SUCCESS;
256
+ }