~ubuntu-branches/ubuntu/precise/nss-pam-ldapd/precise-security

« back to all changes in this revision

Viewing changes to tests/test_tio.c

  • Committer: Package Import Robot
  • Author(s): Arthur de Jong
  • Date: 2011-09-04 21:00:00 UTC
  • mfrom: (14.1.4 experimental)
  • Revision ID: package-import@ubuntu.com-20110904210000-pe3u91iga88vtr16
Tags: 0.8.4
* Upload to unstable
* switch to using the member attribute by default instead of
  uniqueMember (backwards incompatible change)
* only return "x" as a password hash when the object has the shadowAccount
  objectClass and nsswitch.conf is configured to do shadow lookups using
  LDAP (this avoids some problems with pam_unix)
* fix problem with partial attribute name matches in DN (thanks Timothy
  White)
* fix a problem with objectSid mappings with recent versions of OpenLDAP
  (patch by Wesley Mason)
* set the socket timeout in a connection callback to avoid timeout
  issues during the SSL handshake (patch by Stefan Völkel)
* check for unknown variables in pam_authz_search
* only check password expiration when authenticating, only check account
  expiration when doing authorisation
* make buffer sizes consistent and grow all buffers holding string
  representations of numbers to be able to hold 64-bit numbers
* update AX_PTHREAD from autoconf-archive
* support querying DNS SRV records from a different domain than the current
  one (based on a patch by James M. Leddy)
* fix a problem with uninitialised memory while parsing the tls_ciphers
  option (closes: #638872) (but doesn't work yet due to #640384)
* implement bounds checking of numeric values read from LDAP (patch by
  Jakub Hrozek)
* correctly support large uid and gid values from LDAP (patch by Jakub
  Hrozek)
* improvements to the configure script (patch by Jakub Hrozek)
* switch to dh for debian/rules and bump debhelper compatibility to 8
* build Debian packages with multiarch support
* ship shlibs (but still no symbol files) for libnss-ldapd since that was
  the easiest way to support multiarch
* fix output in init script when restarting nslcd (closes: #637132)
* correctly handle leading and trailing spaces in preseeded debconf uri
  option (patch by Andreas B. Mundt) (closes: #637863)
* support spaces around database names in /etc/nsswitch.conf while
  configuring package (closes: #640185)
* updated Russian debconf translation by Yuri Kozlov (closes: #637751)
* updated French debconf translation by Christian Perrier (closes: #637756)
* added Slovak debconf translation by Slavko (closes: #637759)
* updated Danish debconf translation by Joe Hansen (closes :#637763)
* updated Brazilian Portuguese debconf translation by Denis Doria
* updated Portuguese debconf translation by Américo Monteiro
* updated Japanese debconf translation by Kenshi Muto (closes: #638195)
* updated Czech debconf translation by Miroslav Kure (closes: #639026)
* updated German debconf translation by Chris Leick (closes: #639107)
* updated Spanish debconf translation by Francisco Javier Cuadrado
  (closes: #639236)
* updated Dutch debconf translation by Arthur de Jong with help from Paul
  Gevers and Jeroen Schot

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
   test_tio.c - simple test for the tio module
3
3
   This file is part of the nss-pam-ldapd library.
4
4
 
5
 
   Copyright (C) 2007, 2008 Arthur de Jong
 
5
   Copyright (C) 2007, 2008, 2011 Arthur de Jong
6
6
 
7
7
   This library is free software; you can redistribute it and/or
8
8
   modify it under the terms of the GNU Lesser General Public
33
33
#endif /* HAVE_STDINT_H */
34
34
#include <stdlib.h>
35
35
#include <errno.h>
 
36
#include <unistd.h>
 
37
#include <fcntl.h>
 
38
 
 
39
#include "common.h"
36
40
 
37
41
#include "common/tio.h"
38
42
 
39
 
#ifndef __ASSERT_FUNCTION
40
 
#define __ASSERT_FUNCTION ""
41
 
#endif /* not __ASSERT_FUNCTION */
42
 
 
43
 
#define assertok(expr) \
44
 
  ((expr) \
45
 
   ? (void) (0) \
46
 
   : __assertok_fail(__STRING(expr),__FILE__,__LINE__,__ASSERT_FUNCTION))
47
 
 
48
 
static void __assertok_fail(const char *expr,const char *file,
49
 
                          int line,const char *function)
50
 
{
51
 
  char msg[120];
52
 
  snprintf(msg,sizeof(msg),"%s (errno=\"%s\")",expr,strerror(errno));
53
 
  __assert_fail(msg,file,line,function);
54
 
}
55
 
 
56
43
/* structure for passing arguments to helper (is a thread) */
57
44
struct helper_args {
58
45
  int fd;
187
174
  /* set up the socket pair */
188
175
  assertok(socketpair(AF_UNIX,SOCK_STREAM,0,sp)==0);
189
176
  /* log */
190
 
  printf("test_tio: writing %d blocks of %d bytes (%d total)\n",wbl,wbs,wbl*wbs);
191
 
  printf("test_tio: reading %d blocks of %d bytes (%d total)\n",rbl,rbs,rbl*rbs);
 
177
  printf("test_tio: writing %d blocks of %d bytes (%d total)\n",(int)wbl,(int)wbs,(int)(wbl*wbs));
 
178
  printf("test_tio: reading %d blocks of %d bytes (%d total)\n",(int)rbl,(int)rbs,(int)(rbl*rbs));
192
179
  /* start the writer thread */
193
180
  wargs.fd=sp[0];
194
181
  wargs.blocksize=wbs;
288
275
  assertok(pthread_join(wthread,NULL)==0);
289
276
}
290
277
 
 
278
/* this test starts a reader and writer and does not write for a while */
 
279
static void test_timeout_reader(void)
 
280
{
 
281
  int sp[2];
 
282
  TFILE *rfp;
 
283
  FILE *wfp;
 
284
  struct timeval timeout;
 
285
  uint8_t buf[20];
 
286
  time_t start,end;
 
287
  /* set up the socket pair */
 
288
  assertok(socketpair(AF_UNIX,SOCK_STREAM,0,sp)==0);
 
289
  /* open the writer */
 
290
  assertok((wfp=fdopen(sp[0],"wb"))!=NULL);
 
291
  /* open the reader */
 
292
  timeout.tv_sec=1;
 
293
  timeout.tv_usec=100000;
 
294
  assertok((rfp=tio_fdopen(sp[1],&timeout,&timeout,2*1024,4*1024,2*1024,4*1024))!=NULL);
 
295
  /* perform a read */
 
296
  start=time(NULL);
 
297
  assertok(tio_read(rfp,buf,sizeof(buf))!=0);
 
298
  end=time(NULL);
 
299
  assert(end>start);
 
300
  /* close the files */
 
301
  assertok(tio_close(rfp)==0);
 
302
  assertok(fclose(wfp)==0);
 
303
}
 
304
 
 
305
/* this test starts a writer and an idle reader */
 
306
static void test_timeout_writer(void)
 
307
{
 
308
  int sp[2];
 
309
  FILE *rfp;
 
310
  TFILE *wfp;
 
311
  int i;
 
312
  struct timeval timeout;
 
313
  uint8_t buf[20];
 
314
  time_t start,end;
 
315
  /* set up the socket pair */
 
316
  assertok(socketpair(AF_UNIX,SOCK_STREAM,0,sp)==0);
 
317
  /* open the reader */
 
318
  assertok((rfp=fdopen(sp[0],"rb"))!=NULL);
 
319
  /* open the writer */
 
320
  timeout.tv_sec=1;
 
321
  timeout.tv_usec=100000;
 
322
  assertok((wfp=tio_fdopen(sp[1],&timeout,&timeout,2*1024,4*1024,2*20,4*20+1))!=NULL);
 
323
  /* perform a few write (these should be OK because they fill the buffer) */
 
324
  assertok(tio_write(wfp,buf,sizeof(buf))==0);
 
325
  assertok(tio_write(wfp,buf,sizeof(buf))==0);
 
326
  assertok(tio_write(wfp,buf,sizeof(buf))==0);
 
327
  assertok(tio_write(wfp,buf,sizeof(buf))==0);
 
328
  /* one of these should fail but it depends on OS buffers */
 
329
  start=time(NULL);
 
330
  for (i=0;(i<10000)&&(tio_write(wfp,buf,sizeof(buf))==0);i++);
 
331
  assert(i<10000);
 
332
  end=time(NULL);
 
333
  assert(end>start);
 
334
  /* close the files */
 
335
  assertok(tio_close(wfp)!=0); /* fails because of bufferred data */
 
336
  assertok(fclose(rfp)==0);
 
337
}
 
338
 
291
339
/* the main program... */
292
340
int main(int UNUSED(argc),char UNUSED(*argv[]))
293
341
{
303
351
/*  test_blocks(10,9,10,10); */
304
352
  /* set tio_mark() and tio_reset() functions */
305
353
  test_reset();
 
354
  /* test timeout functionality */
 
355
  test_timeout_reader();
 
356
  test_timeout_writer();
306
357
  return 0;
307
358
}