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

« back to all changes in this revision

Viewing changes to nss/shadow.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
   shadow.c - NSS lookup functions for shadow 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_spwd(
 
33
/* read a single shadow entry from the stream */
 
34
static nss_status_t read_spwd(
33
35
        TFILE *fp,struct spwd *result,
34
36
        char *buffer,size_t buflen,int *errnop)
35
37
{
47
49
  return NSS_STATUS_SUCCESS;
48
50
}
49
51
 
50
 
enum nss_status _nss_ldap_getspnam_r(const char *name,struct spwd *result,char *buffer,size_t buflen,int *errnop)
 
52
#ifdef NSS_FLAVOUR_GLIBC
 
53
 
 
54
/* get a shadow entry by name */
 
55
nss_status_t _nss_ldap_getspnam_r(
 
56
        const char *name,struct spwd *result,
 
57
        char *buffer,size_t buflen,int *errnop)
51
58
{
52
59
  NSS_BYNAME(NSLCD_ACTION_SHADOW_BYNAME,
53
60
             name,
57
64
/* thread-local file pointer to an ongoing request */
58
65
static __thread TFILE *spentfp;
59
66
 
60
 
enum nss_status _nss_ldap_setspent(int UNUSED(stayopen))
 
67
/* start listing all shadow users */
 
68
nss_status_t _nss_ldap_setspent(int UNUSED(stayopen))
61
69
{
62
70
  NSS_SETENT(spentfp);
63
71
}
64
72
 
65
 
enum nss_status _nss_ldap_getspent_r(struct spwd *result,char *buffer,size_t buflen,int *errnop)
 
73
/* return a single shadow entry read from the stream */
 
74
nss_status_t _nss_ldap_getspent_r(
 
75
        struct spwd *result,
 
76
        char *buffer,size_t buflen,int *errnop)
66
77
{
67
78
  NSS_GETENT(spentfp,NSLCD_ACTION_SHADOW_ALL,
68
79
             read_spwd(spentfp,result,buffer,buflen,errnop));
69
80
}
70
81
 
71
 
enum nss_status _nss_ldap_endspent(void)
 
82
/* close the stream opened by setspent() above */
 
83
nss_status_t _nss_ldap_endspent(void)
72
84
{
73
85
  NSS_ENDENT(spentfp);
74
86
}
 
87
 
 
88
#endif /* NSS_FLAVOUR_GLIBC */
 
89
 
 
90
#ifdef NSS_FLAVOUR_SOLARIS
 
91
 
 
92
#ifdef HAVE_STRUCT_NSS_XBYY_ARGS_RETURNLEN
 
93
 
 
94
static nss_status_t read_spwdstring(TFILE *fp,nss_XbyY_args_t *args)
 
95
{
 
96
  struct spwd result;
 
97
  nss_status_t retv;
 
98
  char *buffer;
 
99
  char field_buf[128];
 
100
  size_t buflen;
 
101
  /* read the spwd */
 
102
  retv=read_spwd(fp,&result,NSS_ARGS(args)->buf.buffer,args->buf.buflen,&errno);
 
103
  if (retv!=NSS_STATUS_SUCCESS)
 
104
    return retv;
 
105
  /* allocate a temporary buffer */
 
106
  buflen=args->buf.buflen;
 
107
  buffer=(char *)malloc(buflen);
 
108
  /* build the formatted string */
 
109
  /* FIXME: implement proper buffer size checking */
 
110
  sprintf(buffer,"%s:%s:",result.sp_namp,result.sp_pwdp);
 
111
  if (result.sp_lstchg >= 0)
 
112
    sprintf(field_buf,"%d:",result.sp_lstchg);
 
113
  else
 
114
    sprintf(field_buf,":");
 
115
  strcat(buffer,field_buf);
 
116
  if (result.sp_min >= 0)
 
117
    sprintf(field_buf,"%d:",result.sp_min);
 
118
  else
 
119
    sprintf(field_buf,":");
 
120
  strcat(buffer,field_buf);
 
121
  if (result.sp_max >= 0)
 
122
    sprintf(field_buf,"%d:",result.sp_max);
 
123
  else
 
124
    sprintf(field_buf,":");
 
125
  strcat(buffer,field_buf);
 
126
  if (result.sp_warn >= 0)
 
127
    sprintf(field_buf,"%d:",result.sp_warn);
 
128
  else
 
129
    sprintf(field_buf,":");
 
130
  strcat(buffer,field_buf);
 
131
  if (result.sp_inact >= 0)
 
132
    sprintf(field_buf,"%d:",result.sp_inact);
 
133
  else
 
134
    sprintf(field_buf,":");
 
135
  strcat(buffer,field_buf);
 
136
  if (result.sp_expire >= 0)
 
137
    sprintf(field_buf,"%d:",result.sp_expire);
 
138
  else
 
139
    sprintf(field_buf,":");
 
140
  strcat(buffer,field_buf);
 
141
  if (result.sp_flag >= 0)
 
142
    sprintf(field_buf,"%x",result.sp_flag);
 
143
  else
 
144
    sprintf(field_buf,":");
 
145
  strcat(buffer,field_buf);
 
146
  /* copy the result back to the result buffer and free the temporary one */
 
147
  strcpy(NSS_ARGS(args)->buf.buffer,buffer);
 
148
  free(buffer);
 
149
  NSS_ARGS(args)->returnval=NSS_ARGS(args)->buf.buffer;
 
150
  NSS_ARGS(args)->returnlen=strlen(NSS_ARGS(args)->buf.buffer);
 
151
  return NSS_STATUS_SUCCESS;
 
152
}
 
153
 
 
154
#define READ_RESULT(fp) \
 
155
  NSS_ARGS(args)->buf.result? \
 
156
    read_spwd(fp,(struct spwd *)NSS_ARGS(args)->buf.result,NSS_ARGS(args)->buf.buffer,NSS_ARGS(args)->buf.buflen,&errno): \
 
157
    read_spwdstring(fp,args); \
 
158
  if ((NSS_ARGS(args)->buf.result)&&(retv==NSS_STATUS_SUCCESS)) \
 
159
    NSS_ARGS(args)->returnval=NSS_ARGS(args)->buf.result;
 
160
 
 
161
#else /* not HAVE_STRUCT_NSS_XBYY_ARGS_RETURNLEN */
 
162
 
 
163
#define READ_RESULT(fp) \
 
164
  read_spwd(fp,(struct spwd *)NSS_ARGS(args)->buf.result,NSS_ARGS(args)->buf.buffer,NSS_ARGS(args)->buf.buflen,&errno); \
 
165
  if (retv==NSS_STATUS_SUCCESS) \
 
166
    NSS_ARGS(args)->returnval=NSS_ARGS(args)->buf.result;
 
167
 
 
168
#endif /* not HAVE_STRUCT_NSS_XBYY_ARGS_RETURNLEN */
 
169
 
 
170
static nss_status_t shadow_getspnam(nss_backend_t UNUSED(*be),void *args)
 
171
{
 
172
  NSS_BYNAME(NSLCD_ACTION_SHADOW_BYNAME,
 
173
             NSS_ARGS(args)->key.name,
 
174
             READ_RESULT(fp));
 
175
}
 
176
 
 
177
static nss_status_t shadow_setspent(nss_backend_t *be,void UNUSED(*args))
 
178
{
 
179
  NSS_SETENT(LDAP_BE(be)->fp);
 
180
}
 
181
 
 
182
static nss_status_t shadow_getspent(nss_backend_t *be,void *args)
 
183
{
 
184
  NSS_GETENT(LDAP_BE(be)->fp,NSLCD_ACTION_SHADOW_ALL,
 
185
             READ_RESULT(LDAP_BE(be)->fp));
 
186
}
 
187
 
 
188
static nss_status_t shadow_endspent(nss_backend_t *be,void UNUSED(*args))
 
189
{
 
190
  NSS_ENDENT(LDAP_BE(be)->fp);
 
191
}
 
192
 
 
193
static nss_backend_op_t shadow_ops[]={
 
194
  nss_ldap_destructor,
 
195
  shadow_endspent,
 
196
  shadow_setspent,
 
197
  shadow_getspent,
 
198
  shadow_getspnam
 
199
};
 
200
 
 
201
nss_backend_t *_nss_ldap_shadow_constr(const char UNUSED(*db_name),
 
202
                  const char UNUSED(*src_name),const char UNUSED(*cfg_args))
 
203
{
 
204
  return nss_ldap_constructor(shadow_ops,sizeof(shadow_ops));
 
205
}
 
206
 
 
207
#endif /* NSS_FLAVOUR_SOLARIS */