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

« back to all changes in this revision

Viewing changes to nss/services.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
   service.c - NSS lookup functions for services 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,tmp2int32,tmp3int32;
39
39
  size_t bufptr=0;
 
40
  memset(result,0,sizeof(struct servent));
40
41
  READ_BUF_STRING(fp,result->s_name);
41
42
  READ_BUF_STRINGLIST(fp,result->s_aliases);
42
43
  /* store port number in network byte order */
98
99
#ifdef NSS_FLAVOUR_SOLARIS
99
100
 
100
101
#ifdef HAVE_STRUCT_NSS_XBYY_ARGS_RETURNLEN
101
 
 
102
 
static nss_status_t read_servstring(TFILE *fp,nss_XbyY_args_t *args)
 
102
static char *servent2str(struct servent *result,char *buffer,size_t buflen)
103
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++)
 
104
  int res,i;
 
105
  res=snprintf(buffer,buflen,"%s %d/%s",result->s_name,result->s_port,result->s_proto);
 
106
  if ((res<0)||(res>=buflen))
 
107
    return NULL;
 
108
  if (result->s_aliases)
 
109
    for (i=0;result->s_aliases[i];i++)
121
110
    {
122
 
      strcat(buffer," ");
123
 
      strcat(buffer,result.s_aliases[i]);
 
111
      strlcat(buffer," ",buflen);
 
112
      strlcat(buffer,result->s_aliases[i],buflen);
124
113
    }
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 */
 
114
  if (strlen(buffer)>=buflen-1)
 
115
    return NULL;
 
116
  return buffer;
 
117
}
 
118
#endif /* HAVE_STRUCT_NSS_XBYY_ARGS_RETURNLEN */
 
119
 
 
120
static nss_status_t read_result(TFILE *fp,nss_XbyY_args_t *args)
 
121
{
 
122
  READ_RESULT(servent,&args->erange);
 
123
}
148
124
 
149
125
static nss_status_t services_getservbyname(nss_backend_t UNUSED(*be),void *args)
150
126
{
151
127
  NSS_BYGEN(NSLCD_ACTION_SERVICE_BYNAME,
152
128
            WRITE_STRING(fp,NSS_ARGS(args)->key.serv.serv.name);
153
129
            WRITE_STRING(fp,NSS_ARGS(args)->key.serv.proto),
154
 
            READ_RESULT(fp));
 
130
            read_result(fp,args));
155
131
}
156
132
 
157
133
static nss_status_t services_getservbyport(nss_backend_t UNUSED(*be),void *args)
159
135
  NSS_BYGEN(NSLCD_ACTION_SERVICE_BYNUMBER,
160
136
            WRITE_INT32(fp,ntohs(NSS_ARGS(args)->key.serv.serv.port));
161
137
            WRITE_STRING(fp,NSS_ARGS(args)->key.serv.proto),
162
 
            READ_RESULT(fp));
 
138
            read_result(fp,args));
163
139
}
164
140
 
165
141
static nss_status_t services_setservent(nss_backend_t *be,void UNUSED(*args))
170
146
static nss_status_t services_getservent(nss_backend_t *be,void *args)
171
147
{
172
148
  NSS_GETENT(LDAP_BE(be)->fp,NSLCD_ACTION_SERVICE_ALL,
173
 
             READ_RESULT(LDAP_BE(be)->fp));
 
149
             read_result(LDAP_BE(be)->fp,args));
174
150
}
175
151
 
176
152
static nss_status_t services_endservent(nss_backend_t *be,void UNUSED(*args))