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

« back to all changes in this revision

Viewing changes to nss/services.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
   service.c - NSS lookup functions for services 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 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
29
30
#include "common.h"
30
31
#include "compat/attrs.h"
31
32
 
32
 
static enum nss_status read_servent(
 
33
/* read a single services result entry from the stream */
 
34
static nss_status_t read_servent(
33
35
        TFILE *fp,struct servent *result,
34
36
        char *buffer,size_t buflen,int *errnop)
35
37
{
45
47
  return NSS_STATUS_SUCCESS;
46
48
}
47
49
 
48
 
enum nss_status _nss_ldap_getservbyname_r(const char *name,const char *protocol,struct servent *result,char *buffer,size_t buflen,int *errnop)
 
50
#ifdef NSS_FLAVOUR_GLIBC
 
51
 
 
52
/* get a service entry by name and protocol */
 
53
nss_status_t _nss_ldap_getservbyname_r(
 
54
        const char *name,const char *protocol,struct servent *result,
 
55
        char *buffer,size_t buflen,int *errnop)
49
56
{
50
57
  NSS_BYGEN(NSLCD_ACTION_SERVICE_BYNAME,
51
58
            WRITE_STRING(fp,name);WRITE_STRING(fp,protocol),
52
59
            read_servent(fp,result,buffer,buflen,errnop));
53
 
 
54
60
}
55
61
 
56
 
enum nss_status _nss_ldap_getservbyport_r(int port,const char *protocol,struct servent *result,char *buffer,size_t buflen,int *errnop)
 
62
/* get a service entry by port and protocol */
 
63
nss_status_t _nss_ldap_getservbyport_r(
 
64
        int port,const char *protocol,struct servent *result,
 
65
        char *buffer,size_t buflen,int *errnop)
57
66
{
58
67
  NSS_BYGEN(NSLCD_ACTION_SERVICE_BYNUMBER,
59
68
            WRITE_INT32(fp,ntohs(port));WRITE_STRING(fp,protocol),
61
70
}
62
71
 
63
72
/* thread-local file pointer to an ongoing request */
64
 
static __thread TFILE *protoentfp;
65
 
 
66
 
enum nss_status _nss_ldap_setservent(int UNUSED(stayopen))
67
 
{
68
 
  NSS_SETENT(protoentfp);
69
 
}
70
 
 
71
 
enum nss_status _nss_ldap_getservent_r(struct servent *result,char *buffer,size_t buflen,int *errnop)
72
 
{
73
 
  NSS_GETENT(protoentfp,NSLCD_ACTION_SERVICE_ALL,
74
 
             read_servent(protoentfp,result,buffer,buflen,errnop));
75
 
}
76
 
 
77
 
enum nss_status _nss_ldap_endservent(void)
78
 
{
79
 
  NSS_ENDENT(protoentfp);
80
 
}
 
73
static __thread TFILE *serventfp;
 
74
 
 
75
/* open request to get all services */
 
76
nss_status_t _nss_ldap_setservent(int UNUSED(stayopen))
 
77
{
 
78
  NSS_SETENT(serventfp);
 
79
}
 
80
 
 
81
/* read a single returned service definition */
 
82
nss_status_t _nss_ldap_getservent_r(
 
83
        struct servent *result,
 
84
        char *buffer,size_t buflen,int *errnop)
 
85
{
 
86
  NSS_GETENT(serventfp,NSLCD_ACTION_SERVICE_ALL,
 
87
             read_servent(serventfp,result,buffer,buflen,errnop));
 
88
}
 
89
 
 
90
/* close the stream opened by setservent() above */
 
91
nss_status_t _nss_ldap_endservent(void)
 
92
{
 
93
  NSS_ENDENT(serventfp);
 
94
}
 
95
 
 
96
#endif /* NSS_FLAVOUR_GLIBC */
 
97
 
 
98
#ifdef NSS_FLAVOUR_SOLARIS
 
99
 
 
100
#ifdef HAVE_STRUCT_NSS_XBYY_ARGS_RETURNLEN
 
101
 
 
102
static nss_status_t read_servstring(TFILE *fp,nss_XbyY_args_t *args)
 
103
{
 
104
  struct servent result;
 
105
  nss_status_t retv;
 
106
  char *buffer;
 
107
  size_t buflen;
 
108
  int i;
 
109
  /* read the servent */
 
110
  retv=read_servent(fp,&result,NSS_ARGS(args)->buf.buffer,args->buf.buflen,&errno);
 
111
  if (retv!=NSS_STATUS_SUCCESS)
 
112
    return retv;
 
113
  /* allocate a temporary buffer */
 
114
  buflen=args->buf.buflen;
 
115
  buffer=(char *)malloc(buflen);
 
116
  /* build the formatted string */
 
117
  /* FIXME: implement proper buffer size checking */
 
118
  sprintf(buffer,"%s %d/%s",result.s_name,result.s_port,result.s_proto);
 
119
  if (result.s_aliases)
 
120
    for (i=0;result.s_aliases[i];i++)
 
121
    {
 
122
      strcat(buffer," ");
 
123
      strcat(buffer,result.s_aliases[i]);
 
124
    }
 
125
  /* copy the result back to the result buffer and free the temporary one */
 
126
  strcpy(NSS_ARGS(args)->buf.buffer,buffer);
 
127
  free(buffer);
 
128
  NSS_ARGS(args)->returnval=NSS_ARGS(args)->buf.buffer;
 
129
  NSS_ARGS(args)->returnlen=strlen(NSS_ARGS(args)->buf.buffer);
 
130
  return NSS_STATUS_SUCCESS;
 
131
}
 
132
 
 
133
#define READ_RESULT(fp) \
 
134
  NSS_ARGS(args)->buf.result? \
 
135
    read_servent(fp,(struct servent *)NSS_ARGS(args)->buf.result,NSS_ARGS(args)->buf.buffer,NSS_ARGS(args)->buf.buflen,&errno): \
 
136
    read_servstring(fp,args); \
 
137
  if ((NSS_ARGS(args)->buf.result)&&(retv==NSS_STATUS_SUCCESS)) \
 
138
    NSS_ARGS(args)->returnval=NSS_ARGS(args)->buf.result;
 
139
 
 
140
#else /* not HAVE_STRUCT_NSS_XBYY_ARGS_RETURNLEN */
 
141
 
 
142
#define READ_RESULT(fp) \
 
143
  read_servent(fp,(struct servent *)NSS_ARGS(args)->buf.result,NSS_ARGS(args)->buf.buffer,NSS_ARGS(args)->buf.buflen,&errno); \
 
144
  if (retv==NSS_STATUS_SUCCESS) \
 
145
    NSS_ARGS(args)->returnval=NSS_ARGS(args)->buf.result;
 
146
 
 
147
#endif /* not HAVE_STRUCT_NSS_XBYY_ARGS_RETURNLEN */
 
148
 
 
149
static nss_status_t services_getservbyname(nss_backend_t UNUSED(*be),void *args)
 
150
{
 
151
  NSS_BYGEN(NSLCD_ACTION_SERVICE_BYNAME,
 
152
            WRITE_STRING(fp,NSS_ARGS(args)->key.serv.serv.name);
 
153
            WRITE_STRING(fp,NSS_ARGS(args)->key.serv.proto),
 
154
            READ_RESULT(fp));
 
155
}
 
156
 
 
157
static nss_status_t services_getservbyport(nss_backend_t UNUSED(*be),void *args)
 
158
{
 
159
  NSS_BYGEN(NSLCD_ACTION_SERVICE_BYNUMBER,
 
160
            WRITE_INT32(fp,ntohs(NSS_ARGS(args)->key.serv.serv.port));
 
161
            WRITE_STRING(fp,NSS_ARGS(args)->key.serv.proto),
 
162
            READ_RESULT(fp));
 
163
}
 
164
 
 
165
static nss_status_t services_setservent(nss_backend_t *be,void UNUSED(*args))
 
166
{
 
167
  NSS_SETENT(LDAP_BE(be)->fp);
 
168
}
 
169
 
 
170
static nss_status_t services_getservent(nss_backend_t *be,void *args)
 
171
{
 
172
  NSS_GETENT(LDAP_BE(be)->fp,NSLCD_ACTION_SERVICE_ALL,
 
173
             READ_RESULT(LDAP_BE(be)->fp));
 
174
}
 
175
 
 
176
static nss_status_t services_endservent(nss_backend_t *be,void UNUSED(*args))
 
177
{
 
178
  NSS_ENDENT(LDAP_BE(be)->fp);
 
179
}
 
180
 
 
181
static nss_backend_op_t services_ops[]={
 
182
  nss_ldap_destructor,
 
183
  services_endservent,
 
184
  services_setservent,
 
185
  services_getservent,
 
186
  services_getservbyname,
 
187
  services_getservbyport
 
188
};
 
189
 
 
190
nss_backend_t *_nss_ldap_services_constr(const char UNUSED(*db_name),
 
191
                  const char UNUSED(*src_name),const char UNUSED(*cfg_args))
 
192
{
 
193
  return nss_ldap_constructor(services_ops,sizeof(services_ops));
 
194
}
 
195
 
 
196
#endif /* NSS_FLAVOUR_SOLARIS */