2
nslcd-prot.c - common functions for NSLCD lookups
4
Copyright (C) 2006 West Consulting
5
Copyright (C) 2006, 2007, 2008, 2009, 2010, 2012 Arthur de Jong
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.
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.
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
27
#endif /* HAVE_STDINT_H */
30
#include <sys/socket.h>
32
#include <sys/types.h>
38
#include "nslcd-prot.h"
39
#include "compat/socket.h"
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
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. */
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()
58
struct sockaddr_un addr;
59
struct timeval readtimeout,writetimeout;
62
if ( (sock=socket(PF_UNIX,SOCK_STREAM,0))<0 )
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)
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)
88
/* return the stream */