~ubuntu-branches/ubuntu/saucy/nss-pam-ldapd/saucy

« back to all changes in this revision

Viewing changes to nss/shadow.c

  • Committer: Package Import Robot
  • Author(s): Arthur de Jong
  • Date: 2013-05-05 20:00:00 UTC
  • mfrom: (16.1.6) (14.1.6 experimental)
  • Revision ID: package-import@ubuntu.com-20130505200000-nhg39y204kr141mz
Tags: 0.8.13-1
* New upstream release
  - include an extra sanity check to ensure not too many file
    descriptors are open
  - fix handling of gid configuration option if it listed before the uid
    option
  - return NSS_STATUS_TRYAGAIN on zero-length (but not-NULL) buffer (thanks
    Jakub Hrozek)
  - provide an _nss_ldap_version symbol in the NSS module to help debug
    problems with a newer nslcd
  - retry updating the lastChange attribute with the normal nslcd LDAP
    connection if the update with the user's connection failed
  - avoid processing passwd_byuid requests for uids below nss_min_uid
  - fix a few minor or very unlikely to occur memory leaks
  - miscellaneous minor changes, fixes and compatibility improvements
* drop 01-fix-set-usec-instead-of-sec.patch which is part of 0.8.13
* remove compatibility code that converted nss-ldapd.conf to nslcd.conf
  for upgrading from pre-0.7 versions of nss-ldapd (thanks Dominik George)
* remove code for fixing permissions when upgrading from a pre-0.6.7.1
  version
* updated Turkish debconf translation by Atila KOÇ (closes: #701067)
* drop Richard A Nelson from uploaders
* add build dependency on autotools-dev to ensure config.sub and
  config.guess are automatically updated during build

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, 2010 Arthur de Jong
 
5
   Copyright (C) 2006, 2007, 2008, 2010, 2012 Arthur de Jong
6
6
   Copyright (C) 2010 Symas Corporation
7
7
 
8
8
   This library is free software; you can redistribute it and/or
37
37
{
38
38
  int32_t tmpint32;
39
39
  size_t bufptr=0;
 
40
  memset(result,0,sizeof(struct spwd));
40
41
  READ_BUF_STRING(fp,result->sp_namp);
41
42
  READ_BUF_STRING(fp,result->sp_pwdp);
42
43
  READ_INT32(fp,result->sp_lstchg);
90
91
#ifdef NSS_FLAVOUR_SOLARIS
91
92
 
92
93
#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 */
 
94
static char *spwd2str(struct spwd *result,char *buffer,size_t buflen)
 
95
{
 
96
  /* snprintf writes a terminating \0 on Solaris */
 
97
  snprintf(buffer,buflen,"%s:%s:",result->sp_namp,result->sp_pwdp);
 
98
  if (result->sp_lstchg>=0)
 
99
    snprintf(buffer,buflen-strlen(buffer)-1,"%d",result->sp_lstchg);
 
100
  strlcat(buffer,":",buflen);
 
101
  if (result->sp_min>=0)
 
102
    snprintf(buffer,buflen-strlen(buffer)-1,"%d",result->sp_min);
 
103
  strlcat(buffer,":",buflen);
 
104
  if (result->sp_max>=0)
 
105
    snprintf(buffer,buflen-strlen(buffer)-1,"%d",result->sp_max);
 
106
  strlcat(buffer,":",buflen);
 
107
  if (result->sp_warn>=0)
 
108
    snprintf(buffer,buflen-strlen(buffer)-1,"%d",result->sp_warn);
 
109
  strlcat(buffer,":",buflen);
 
110
  if (result->sp_inact>=0)
 
111
    snprintf(buffer,buflen-strlen(buffer)-1,"%d",result->sp_inact);
 
112
  strlcat(buffer,":",buflen);
 
113
  if (result->sp_expire>=0)
 
114
    snprintf(buffer,buflen-strlen(buffer)-1,"%d",result->sp_expire);
 
115
  strlcat(buffer,":",buflen);
 
116
  if (result->sp_flag>0)
 
117
    snprintf(buffer,buflen-strlen(buffer)-1,"%x",result->sp_flag);
 
118
  if (strlen(buffer)>=buflen-1)
 
119
    return NULL;
 
120
  return buffer;
 
121
}
 
122
#endif /* HAVE_STRUCT_NSS_XBYY_ARGS_RETURNLEN */
 
123
 
 
124
static nss_status_t read_result(TFILE *fp,nss_XbyY_args_t *args)
 
125
{
 
126
  READ_RESULT(spwd,&args->erange);
 
127
}
169
128
 
170
129
static nss_status_t shadow_getspnam(nss_backend_t UNUSED(*be),void *args)
171
130
{
172
131
  NSS_BYNAME(NSLCD_ACTION_SHADOW_BYNAME,
173
132
             NSS_ARGS(args)->key.name,
174
 
             READ_RESULT(fp));
 
133
             read_result(fp,args));
175
134
}
176
135
 
177
136
static nss_status_t shadow_setspent(nss_backend_t *be,void UNUSED(*args))
182
141
static nss_status_t shadow_getspent(nss_backend_t *be,void *args)
183
142
{
184
143
  NSS_GETENT(LDAP_BE(be)->fp,NSLCD_ACTION_SHADOW_ALL,
185
 
             READ_RESULT(LDAP_BE(be)->fp));
 
144
             read_result(LDAP_BE(be)->fp,args));
186
145
}
187
146
 
188
147
static nss_status_t shadow_endspent(nss_backend_t *be,void UNUSED(*args))