diff options
author | Arthur de Jong <arthur@arthurdejong.org> | 2006-11-27 09:59:19 +0000 |
---|---|---|
committer | Arthur de Jong <arthur@arthurdejong.org> | 2006-11-27 09:59:19 +0000 |
commit | d22651f5099312abb620bba25af9bc8bc3a520a1 (patch) | |
tree | e3167edd02b709dd2edf16012f906814d59c4744 /nss/common.c | |
parent | e23505ff456b72aa8c1fe3e7105f22c8f9331c91 (diff) |
get rid of nslcd-client.{c,h} and move it to nss/common.{c,h}, this ensures that all code that is needed for the nss part is in the nss directory
git-svn-id: http://arthurdejong.org/svn/nss-pam-ldapd/libnss_ldapd@127 ef36b2f9-881f-0410-afb5-c4e39611909c
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; +} |