diff options
Diffstat (limited to 'nss/common.c')
-rw-r--r-- | nss/common.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/nss/common.c b/nss/common.c index a1fc34f..ab8fb40 100644 --- a/nss/common.c +++ b/nss/common.c @@ -22,6 +22,14 @@ #include "config.h" +#include <stdint.h> +#include <unistd.h> +#include <stdio.h> +#include <sys/socket.h> +#include <sys/un.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <errno.h> #include <nss.h> #include "nslcd.h" @@ -39,3 +47,32 @@ enum nss_status nslcd2nss(int code) default: return NSS_STATUS_UNAVAIL; } } + +/* returns a socket to the server or NULL on error (see errno), + socket should be closed with fclose() */ +FILE *nslcd_client_open() +{ + int sock; + struct sockaddr_un addr; + FILE *fp; + /* create a socket */ + if ( (sock=socket(PF_UNIX,SOCK_STREAM,0))<0 ) + return NULL; + /* create socket address structure */ + addr.sun_family=AF_UNIX; + strcpy(addr.sun_path,NSLCD_SOCKET); + /* connect to the socket */ + if (connect(sock,(struct sockaddr *)&addr,sizeof(struct sockaddr_un))<0) + { + close(sock); + return NULL; + } + /* create a stream object */ + if ((fp=fdopen(sock,"w+"))==NULL) + { + close(sock); + return NULL; + } + /* return the stream */ + return fp; +} |