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

« back to all changes in this revision

Viewing changes to nss/networks.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
   networks.c - NSS lookup functions for networks database
3
3
 
4
4
   Copyright (C) 2006 West Consulting
5
 
   Copyright (C) 2006, 2007, 2008 Arthur de Jong
 
5
   Copyright (C) 2006, 2007, 2008, 2010, 2011 Arthur de Jong
 
6
   Copyright (C) 2010 Symas Corporation
6
7
 
7
8
   This library is free software; you can redistribute it and/or
8
9
   modify it under the terms of the GNU Lesser General Public
24
25
 
25
26
#include <string.h>
26
27
#include <errno.h>
 
28
#include <sys/socket.h>
 
29
#include <netinet/in.h>
 
30
#include <arpa/inet.h>
27
31
 
28
32
#include "prototypes.h"
29
33
#include "common.h"
30
34
#include "compat/attrs.h"
31
35
 
32
 
/* Redifine some ERROR_OUT macros as we also want to set h_errnop. */
 
36
/* Redefine some ERROR_OUT macros as we also want to set h_errnop. */
33
37
 
34
38
#undef ERROR_OUT_OPENERROR
35
39
#define ERROR_OUT_OPENERROR \
59
63
 
60
64
/* read a single network entry from the stream, ignoring entries
61
65
   that are not AF_INET (IPv4), result is stored in result */
62
 
static enum nss_status read_netent(
 
66
static nss_status_t read_netent(
63
67
        TFILE *fp,struct netent *result,
64
68
        char *buffer,size_t buflen,int *errnop,int *h_errnop)
65
69
{
66
70
  int32_t tmpint32,tmp2int32,tmp3int32;
67
 
  int32_t numaddr,i;
 
71
  int32_t numaddr;
68
72
  int readaf;
69
73
  size_t bufptr=0;
70
 
  enum nss_status retv=NSS_STATUS_NOTFOUND;
 
74
  nss_status_t retv=NSS_STATUS_NOTFOUND;
71
75
  /* read the network entry */
72
76
  READ_BUF_STRING(fp,result->n_name);
73
77
  READ_BUF_STRINGLIST(fp,result->n_aliases);
75
79
  /* read number of addresses to follow */
76
80
  READ_TYPE(fp,numaddr,int32_t);
77
81
  /* go through the address list and filter on af */
78
 
  i=0;
79
82
  while (--numaddr>=0)
80
83
  {
81
84
    /* read address family and size */
82
85
    READ_INT32(fp,readaf);
83
 
    READ_INT32(fp,tmp2int32);
 
86
    READ_INT32(fp,tmp2int32); /* address length */
84
87
    if ((readaf==AF_INET)&&(tmp2int32==4))
85
88
    {
86
89
      /* read address and translate to host byte order */
99
102
  return retv;
100
103
}
101
104
 
102
 
enum nss_status _nss_ldap_getnetbyname_r(const char *name,struct netent *result,char *buffer,size_t buflen,int *errnop,int *h_errnop)
103
 
{
104
 
  NSS_BYNAME(NSLCD_ACTION_NETWORK_BYNAME,
105
 
             name,
106
 
             read_netent(fp,result,buffer,buflen,errnop,h_errnop));
107
 
}
108
 
 
109
105
/* write an address value */
110
106
/* version 2.10 of glibc changed the address from network to host order
111
107
   (changelog entry 2009-07-01) */
114
110
  WRITE_INT32(fp,4); \
115
111
  WRITE_INT32(fp,htonl(addr));
116
112
 
 
113
#ifdef NSS_FLAVOUR_GLIBC
 
114
 
 
115
/* get a network entry by name */
 
116
nss_status_t _nss_ldap_getnetbyname_r(
 
117
        const char *name,struct netent *result,
 
118
        char *buffer,size_t buflen,int *errnop,int *h_errnop)
 
119
{
 
120
  NSS_BYNAME(NSLCD_ACTION_NETWORK_BYNAME,
 
121
             name,
 
122
             read_netent(fp,result,buffer,buflen,errnop,h_errnop));
 
123
}
 
124
 
117
125
/* Note: the af parameter is ignored and is assumed to be AF_INET */
118
126
/* TODO: implement handling of af parameter */
119
 
enum nss_status _nss_ldap_getnetbyaddr_r(uint32_t addr,int UNUSED(af),struct netent *result,char *buffer,size_t buflen,int *errnop,int *h_errnop)
 
127
nss_status_t _nss_ldap_getnetbyaddr_r(
 
128
        uint32_t addr,int UNUSED(af),struct netent *result,
 
129
        char *buffer,size_t buflen,int *errnop,int *h_errnop)
120
130
{
121
131
  NSS_BYGEN(NSLCD_ACTION_NETWORK_BYADDR,
122
132
            WRITE_ADDRESS(fp,addr),
126
136
/* thread-local file pointer to an ongoing request */
127
137
static __thread TFILE *netentfp;
128
138
 
129
 
enum nss_status _nss_ldap_setnetent(int UNUSED(stayopen))
 
139
/* start a request to read all networks */
 
140
nss_status_t _nss_ldap_setnetent(int UNUSED(stayopen))
130
141
{
131
142
  NSS_SETENT(netentfp);
132
143
}
133
144
 
134
 
enum nss_status _nss_ldap_getnetent_r(struct netent *result,char *buffer,size_t buflen,int *errnop,int *h_errnop)
 
145
/* get a single network entry from the stream */
 
146
nss_status_t _nss_ldap_getnetent_r(
 
147
        struct netent *result,
 
148
        char *buffer,size_t buflen,int *errnop,int *h_errnop)
135
149
{
136
150
  NSS_GETENT(netentfp,NSLCD_ACTION_NETWORK_ALL,
137
151
             read_netent(netentfp,result,buffer,buflen,errnop,h_errnop));
138
152
}
139
153
 
140
 
enum nss_status _nss_ldap_endnetent(void)
 
154
/* close the stream opened by setnetent() above */
 
155
nss_status_t _nss_ldap_endnetent(void)
141
156
{
142
157
  NSS_ENDENT(netentfp);
143
158
}
 
159
 
 
160
#endif /* NSS_FLAVOUR_GLIBC */
 
161
 
 
162
#ifdef NSS_FLAVOUR_SOLARIS
 
163
 
 
164
#ifdef HAVE_STRUCT_NSS_XBYY_ARGS_RETURNLEN
 
165
 
 
166
static nss_status_t read_netentstring(TFILE *fp,nss_XbyY_args_t *args)
 
167
{
 
168
  struct netent result;
 
169
  nss_status_t retv;
 
170
  char *buffer;
 
171
  size_t buflen;
 
172
  int i;
 
173
  struct in_addr priv_in_addr;
 
174
  /* read the netent */
 
175
  retv=read_netent(fp,&result,NSS_ARGS(args)->buf.buffer,args->buf.buflen,&errno,&(NSS_ARGS(args)->h_errno));
 
176
  if (retv!=NSS_STATUS_SUCCESS)
 
177
    return retv;
 
178
  /* allocate a temporary buffer */
 
179
  buflen=args->buf.buflen;
 
180
  buffer=(char *)malloc(buflen);
 
181
  /* build the formatted string */
 
182
  /* FIXME: implement proper buffer size checking */
 
183
  priv_in_addr.s_addr = result.n_net;
 
184
  sprintf(buffer,"%s %s",result.n_name,inet_ntoa(priv_in_addr)); /* ipNetworkNumber */
 
185
  if (result.n_aliases)
 
186
    for (i=0;result.n_aliases[i];i++)
 
187
    {
 
188
      strcat(buffer," ");
 
189
      strcat(buffer,result.n_aliases[i]);
 
190
    }
 
191
  /* copy the result back to the result buffer and free the temporary one */
 
192
  strcpy(NSS_ARGS(args)->buf.buffer,buffer);
 
193
  free(buffer);
 
194
  NSS_ARGS(args)->returnval=NSS_ARGS(args)->buf.buffer;
 
195
  NSS_ARGS(args)->returnlen=strlen(NSS_ARGS(args)->buf.buffer);
 
196
  return NSS_STATUS_SUCCESS;
 
197
}
 
198
 
 
199
#define READ_RESULT(fp) \
 
200
  NSS_ARGS(args)->buf.result? \
 
201
    read_netent(fp,(struct netent *)NSS_ARGS(args)->buf.result,NSS_ARGS(args)->buf.buffer,NSS_ARGS(args)->buf.buflen,&errno,&(NSS_ARGS(args)->h_errno)): \
 
202
    read_netentstring(fp,args); \
 
203
  if ((NSS_ARGS(args)->buf.result)&&(retv==NSS_STATUS_SUCCESS)) \
 
204
    NSS_ARGS(args)->returnval=NSS_ARGS(args)->buf.result;
 
205
 
 
206
#else /* not HAVE_STRUCT_NSS_XBYY_ARGS_RETURNLEN */
 
207
 
 
208
#define READ_RESULT(fp) \
 
209
  read_netent(fp,(struct netent *)NSS_ARGS(args)->buf.result,NSS_ARGS(args)->buf.buffer,NSS_ARGS(args)->buf.buflen,&errno,&(NSS_ARGS(args)->h_errno)); \
 
210
  if (retv==NSS_STATUS_SUCCESS) \
 
211
    NSS_ARGS(args)->returnval=NSS_ARGS(args)->buf.result;
 
212
 
 
213
#endif /* not HAVE_STRUCT_NSS_XBYY_ARGS_RETURNLEN */
 
214
 
 
215
/* more of a dirty hack */
 
216
#define h_errnop (&(NSS_ARGS(args)->h_errno))
 
217
 
 
218
static nss_status_t networks_getnetbyname(nss_backend_t UNUSED(*be),void *args)
 
219
{
 
220
  NSS_BYNAME(NSLCD_ACTION_NETWORK_BYNAME,
 
221
             NSS_ARGS(args)->key.name,
 
222
             READ_RESULT(fp));
 
223
}
 
224
 
 
225
static nss_status_t networks_getnetbyaddr(nss_backend_t UNUSED(*be),void *args)
 
226
{
 
227
  NSS_BYGEN(NSLCD_ACTION_NETWORK_BYADDR,
 
228
            WRITE_ADDRESS(fp,NSS_ARGS(args)->key.netaddr.net),
 
229
            READ_RESULT(fp));
 
230
}
 
231
 
 
232
static nss_status_t networks_setnetent(nss_backend_t *be,void UNUSED(*args))
 
233
{
 
234
  NSS_SETENT(LDAP_BE(be)->fp);
 
235
}
 
236
 
 
237
static nss_status_t networks_getnetent(nss_backend_t *be,void *args)
 
238
{
 
239
  NSS_GETENT(LDAP_BE(be)->fp,NSLCD_ACTION_NETWORK_ALL,
 
240
             READ_RESULT(LDAP_BE(be)->fp));
 
241
}
 
242
 
 
243
static nss_status_t networks_endnetent(nss_backend_t *be,void UNUSED(*args))
 
244
{
 
245
  NSS_ENDENT(LDAP_BE(be)->fp);
 
246
}
 
247
 
 
248
static nss_backend_op_t networks_ops[]={
 
249
  nss_ldap_destructor,
 
250
  networks_endnetent,
 
251
  networks_setnetent,
 
252
  networks_getnetent,
 
253
  networks_getnetbyname,
 
254
  networks_getnetbyaddr
 
255
};
 
256
 
 
257
nss_backend_t *_nss_ldap_networks_constr(const char UNUSED(*db_name),
 
258
                  const char UNUSED(*src_name),const char UNUSED(*cfg_args))
 
259
{
 
260
  return nss_ldap_constructor(networks_ops,sizeof(networks_ops));
 
261
}
 
262
 
 
263
#endif /* NSS_FLAVOUR_SOLARIS */