~ubuntu-branches/ubuntu/utopic/nss-pam-ldapd/utopic-proposed

« back to all changes in this revision

Viewing changes to .pc/01-use-poll-instead-of-select.patch/common/nslcd-prot.c

  • Committer: Package Import Robot
  • Author(s): Arthur de Jong
  • Date: 2012-10-14 23:00:00 UTC
  • Revision ID: package-import@ubuntu.com-20121014230000-tn63bv35wlebv45a
Tags: 0.8.10-3
* fix a problem in sed logic for commenting out disabled options
  (closes: #689296)
* support "EXTERNAL" SASL mechanism in debconf configuration (LP: #1063923)
  (the debconf template has been postponed to avoid having to update all
  translations for a relatively minor change)
* 01-use-poll-instead-of-select.patch: use poll() instead of select()
  for checking file descriptor activity to also correctly work if more
  than FD_SETSIZE files are already open (closes: #690319)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
   nslcd-prot.c - common functions for NSLCD lookups
 
3
 
 
4
   Copyright (C) 2006 West Consulting
 
5
   Copyright (C) 2006, 2007, 2008, 2009, 2010, 2012 Arthur de Jong
 
6
 
 
7
   This library is free software; you can redistribute it and/or
 
8
   modify it under the terms of the GNU Lesser General Public
 
9
   License as published by the Free Software Foundation; either
 
10
   version 2.1 of the License, or (at your option) any later version.
 
11
 
 
12
   This library is distributed in the hope that it will be useful,
 
13
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
15
   Lesser General Public License for more details.
 
16
 
 
17
   You should have received a copy of the GNU Lesser General Public
 
18
   License along with this library; if not, write to the Free Software
 
19
   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 
20
   02110-1301 USA
 
21
*/
 
22
 
 
23
#include "config.h"
 
24
 
 
25
#ifdef HAVE_STDINT_H
 
26
#include <stdint.h>
 
27
#endif /* HAVE_STDINT_H */
 
28
#include <unistd.h>
 
29
#include <stdio.h>
 
30
#include <sys/socket.h>
 
31
#include <sys/un.h>
 
32
#include <sys/types.h>
 
33
#include <sys/stat.h>
 
34
#include <errno.h>
 
35
#include <string.h>
 
36
 
 
37
#include "nslcd.h"
 
38
#include "nslcd-prot.h"
 
39
#include "compat/socket.h"
 
40
 
 
41
/* buffer sizes for I/O */
 
42
#define READBUFFER_MINSIZE 1024
 
43
#define READBUFFER_MAXSIZE 2*1024*1024
 
44
#define WRITEBUFFER_MINSIZE 32
 
45
#define WRITEBUFFER_MAXSIZE 32
 
46
 
 
47
/* Note that the READBUFFER_MAXSIZE should be large enough to hold any single
 
48
   result entity as defined in nslcd.h because the get*ent() functions expect
 
49
   to be able to tio_reset() the stream to re-read the current entity.
 
50
   Since group entities can grow arbitrarily large, this setting limits the
 
51
   number of users that can be put in a group. */
 
52
 
 
53
/* returns a socket to the server or NULL on error (see errno),
 
54
   socket should be closed with fclose() */
 
55
TFILE *nslcd_client_open()
 
56
{
 
57
  int sock;
 
58
  struct sockaddr_un addr;
 
59
  struct timeval readtimeout,writetimeout;
 
60
  TFILE *fp;
 
61
  /* create a socket */
 
62
  if ( (sock=socket(PF_UNIX,SOCK_STREAM,0))<0 )
 
63
    return NULL;
 
64
  /* create socket address structure */
 
65
  memset(&addr,0,sizeof(struct sockaddr_un));
 
66
  addr.sun_family=AF_UNIX;
 
67
  strncpy(addr.sun_path,NSLCD_SOCKET,sizeof(addr.sun_path));
 
68
  addr.sun_path[sizeof(addr.sun_path)-1]='\0';
 
69
  /* connect to the socket */
 
70
  if (connect(sock,(struct sockaddr *)&addr,SUN_LEN(&addr))<0)
 
71
  {
 
72
    (void)close(sock);
 
73
    return NULL;
 
74
  }
 
75
  /* set the timeouts */
 
76
  readtimeout.tv_sec=60; /* looking up stuff may take some time */
 
77
  readtimeout.tv_usec=0;
 
78
  writetimeout.tv_sec=10; /* nslcd could be loaded with requests */
 
79
  writetimeout.tv_usec=0;
 
80
  /* create a stream object */
 
81
  if ((fp=tio_fdopen(sock,&readtimeout,&writetimeout,
 
82
                     READBUFFER_MINSIZE,READBUFFER_MAXSIZE,
 
83
                     WRITEBUFFER_MINSIZE,WRITEBUFFER_MAXSIZE))==NULL)
 
84
  {
 
85
    (void)close(sock);
 
86
    return NULL;
 
87
  }
 
88
  /* return the stream */
 
89
  return fp;
 
90
}