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

« back to all changes in this revision

Viewing changes to tests/test_nslcd_group.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:
1
 
/*
2
 
   test_nslcd_group.c - simple tests of developed lookup code
3
 
 
4
 
   Copyright (C) 2008 Arthur de Jong
5
 
 
6
 
   This library is free software; you can redistribute it and/or
7
 
   modify it under the terms of the GNU Lesser General Public
8
 
   License as published by the Free Software Foundation; either
9
 
   version 2.1 of the License, or (at your option) any later version.
10
 
 
11
 
   This library is distributed in the hope that it will be useful,
12
 
   but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
 
   Lesser General Public License for more details.
15
 
 
16
 
   You should have received a copy of the GNU Lesser General Public
17
 
   License along with this library; if not, write to the Free Software
18
 
   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19
 
   02110-1301 USA
20
 
*/
21
 
 
22
 
#include "config.h"
23
 
 
24
 
#include <sys/types.h>
25
 
#include <sys/stat.h>
26
 
#include <fcntl.h>
27
 
#include <errno.h>
28
 
#include <assert.h>
29
 
 
30
 
#include "common/tio.h"
31
 
#include "nslcd/myldap.h"
32
 
 
33
 
/* include group code because we want to test static methods */
34
 
#include "nslcd/group.c"
35
 
 
36
 
static void test_isvalidgroupname(void)
37
 
{
38
 
  assert(isvalidgroupname("foo"));
39
 
  assert(!isvalidgroupname("foo^"));
40
 
  assert(!isvalidgroupname("-foo"));
41
 
  assert(isvalidgroupname("foo-bar"));
42
 
}
43
 
 
44
 
static void test_group_all(MYLDAP_SESSION *session,TFILE *fp)
45
 
{
46
 
  MYLDAP_SEARCH *search;
47
 
  MYLDAP_ENTRY *entry;
48
 
  int rc;
49
 
  /* build the list of attributes */
50
 
  group_init();
51
 
  /* do the LDAP search */
52
 
  search=myldap_search(session,group_base,group_scope,group_filter,group_attrs);
53
 
  assert(search!=NULL);
54
 
  /* go over results */
55
 
  while ((entry=myldap_get_entry(search,&rc))!=NULL)
56
 
  {
57
 
    if (write_group(fp,entry,NULL,NULL,1,session))
58
 
      return;
59
 
  }
60
 
}
61
 
 
62
 
static void test_group_byname(MYLDAP_SESSION *session,TFILE *fp,const char *name)
63
 
{
64
 
  MYLDAP_SEARCH *search;
65
 
  MYLDAP_ENTRY *entry;
66
 
  int rc;
67
 
  char filter[1024];
68
 
  /* build the list of attributes */
69
 
  group_init();
70
 
  /* build the filter */
71
 
  mkfilter_group_byname(name,filter,sizeof(filter));
72
 
  /* do the LDAP search */
73
 
  search=myldap_search(session,group_base,group_scope,filter,group_attrs);
74
 
  assert(search!=NULL);
75
 
  /* go over results */
76
 
  while ((entry=myldap_get_entry(search,&rc))!=NULL)
77
 
  {
78
 
    if (write_group(fp,entry,NULL,NULL,1,session))
79
 
      return;
80
 
  }
81
 
}
82
 
 
83
 
static void initconfig(void)
84
 
{
85
 
  char *srcdir;
86
 
  char fname[100];
87
 
  /* build the name of the file to read */
88
 
  srcdir=getenv("srcdir");
89
 
  if (srcdir==NULL)
90
 
    strcpy(fname,"nslcd-test.conf");
91
 
  else
92
 
    snprintf(fname,sizeof(fname),"%s/nslcd-test.conf",srcdir);
93
 
  fname[sizeof(fname)-1]='\0';
94
 
  /* load config file */
95
 
  cfg_init(fname);
96
 
  /* partially initialize logging */
97
 
  log_setdefaultloglevel(LOG_DEBUG);
98
 
}
99
 
 
100
 
static TFILE *opendummyfile(void)
101
 
{
102
 
  int fd;
103
 
  struct timeval timeout;
104
 
  /* set the timeout */
105
 
  timeout.tv_sec=2;
106
 
  timeout.tv_usec=0;
107
 
  /* open the file for writing the result data */
108
 
  fd=open("/dev/null",O_RDWR,0);
109
 
  assert(fd>=0);
110
 
  return tio_fdopen(fd,&timeout,&timeout,1024,2*1024,1024,2*1024);
111
 
}
112
 
 
113
 
/* the main program... */
114
 
int main(int UNUSED(argc),char UNUSED(*argv[]))
115
 
{
116
 
  MYLDAP_SESSION *session;
117
 
  TFILE *fp;
118
 
  /* initialize configuration */
119
 
  initconfig();
120
 
  /* initialize session */
121
 
  session=myldap_create_session();
122
 
  assert(session!=NULL);
123
 
  /* get a stream */
124
 
  fp=opendummyfile();
125
 
  assert(fp!=NULL);
126
 
  /* perform tests */
127
 
  test_isvalidgroupname();
128
 
  test_group_byname(session,fp,"testgroup");
129
 
  test_group_byname(session,fp,"testgroup2");
130
 
  test_group_all(session,fp);
131
 
  /* close session */
132
 
  myldap_session_close(session);
133
 
  tio_close(fp);
134
 
  return 0;
135
 
}