diff options
author | Arthur de Jong <arthur@arthurdejong.org> | 2006-10-30 16:37:07 +0100 |
---|---|---|
committer | Arthur de Jong <arthur@arthurdejong.org> | 2006-10-30 16:37:07 +0100 |
commit | d2b5fc4db1a7353e9b0c3ab87d99d60c6521d32d (patch) | |
tree | 5cb08148139fdb7c9619dd6d186ac66dc0047d97 /server | |
parent | 81018fb9efe3b9a55fdaa628270e0963ae276748 (diff) |
implement simple password lookup with nslcd_getpwnam() function
git-svn-id: http://arthurdejong.org/svn/nss-pam-ldapd/libnss_ldapd@29 ef36b2f9-881f-0410-afb5-c4e39611909c
Diffstat (limited to 'server')
-rw-r--r-- | server/Makefile.am | 25 | ||||
-rw-r--r-- | server/common.c | 39 | ||||
-rw-r--r-- | server/common.h | 33 | ||||
-rw-r--r-- | server/passwd.c | 63 |
4 files changed, 148 insertions, 12 deletions
diff --git a/server/Makefile.am b/server/Makefile.am new file mode 100644 index 0000000..53cf81e --- /dev/null +++ b/server/Makefile.am @@ -0,0 +1,25 @@ +# Makefile.am - use automake to generate Makefile.in +# +# Copyright (C) 2006 West consulting +# Copyright (C) 2006 Arthur de Jong +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Library General Public +# License as published by the Free Software Foundation; either +# version 2 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Library General Public License for more details. +# +# You should have received a copy of the GNU Library General Public +# License along with this library; if not, write to the Free +# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +# MA 02110-1301 USA + +noinst_LIBRARIES = libserver.a + +libserver_a_SOURCES = common.c common.h \ + aliases.c automount.c ethers.c group.c hosts.c netgroup.c \ + networks.c passwd.c protocols.c rpc.c services.c shadow.c diff --git a/server/common.c b/server/common.c new file mode 100644 index 0000000..34b67d5 --- /dev/null +++ b/server/common.c @@ -0,0 +1,39 @@ +/* + common.c - common server code routines + + Copyright (C) 2006 West Consulting + Copyright (C) 2006 Arthur de Jong + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, + MA 02110-1301 USA +*/ + +#include "nslcd.h" +#include "common.h" + +/* translates a nslcd return code (as defined in nslcd.h) to + a nss code (as defined in nss.h) */ +/* FIXME: this is a temporary hack, get rid of it */ +int nss2nslcd(enum nss_status code) +{ + switch (code) + { + case NSS_STATUS_UNAVAIL: return NSLCD_RS_UNAVAIL; + case NSS_STATUS_NOTFOUND: return NSLCD_RS_NOTFOUND; + case NSS_STATUS_SUCCESS: return NSLCD_RS_SUCCESS; +/* case NSS_STATUS_TRYAGAIN: return NSLCD_RS_SMALLBUF; */ + default: return NSLCD_RS_UNAVAIL; + } +} diff --git a/server/common.h b/server/common.h new file mode 100644 index 0000000..9d21b11 --- /dev/null +++ b/server/common.h @@ -0,0 +1,33 @@ +/* + common.h - common server code routines + + Copyright (C) 2006 West Consulting + Copyright (C) 2006 Arthur de Jong + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, + MA 02110-1301 USA +*/ + +#ifndef _SERVER_COMMON_H +#define _SERVER_COMMON_H 1 + +#include <nss.h> + +/* translates a nss code (as defined in nss.h) to a + nslcd return code (as defined in nslcd.h) */ +/* FIXME: this is a temporary hack, get rid of it */ +int nss2nslcd(enum nss_status code); + +#endif /* not _SERVER_COMMON_H */ diff --git a/server/passwd.c b/server/passwd.c index 11155a9..48a83cc 100644 --- a/server/passwd.c +++ b/server/passwd.c @@ -1,22 +1,24 @@ /* + passwd.c - password entry lookup routines + Copyright (C) 1997-2005 Luke Howard - This file is part of the nss_ldap library. - Contributed by Luke Howard, <lukeh@padl.com>, 1997. + Copyright (C) 2006 West Consulting + Copyright (C) 2006 Arthur de Jong - The nss_ldap library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. - The nss_ldap library is distributed in the hope that it will be useful, + This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public - License along with the nss_ldap library; see the file COPYING.LIB. If not, - write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. + License along with this library; if not, write to the Free + Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, + MA 02110-1301 USA */ #include "config.h" @@ -41,6 +43,8 @@ #include "ldap-nss.h" #include "util.h" +#include "nslcd-server.h" +#include "common.h" static struct ent_context *pw_context = NULL; @@ -60,8 +64,7 @@ static inline enum nss_status _nss_ldap_assign_emptystring( return NSS_STATUS_SUCCESS; } -/* FIXME: make this non-static for now for testing purposes */ -enum nss_status _nss_ldap_parse_pw (LDAPMessage * e, +static enum nss_status _nss_ldap_parse_pw (LDAPMessage * e, struct ldap_state * pvt, void *result, char *buffer, size_t buflen) { @@ -171,6 +174,20 @@ enum nss_status _nss_ldap_parse_pw (LDAPMessage * e, return NSS_STATUS_SUCCESS; } +#define PASSWD_NAME result.pw_name +#define PASSWD_PASSWD result.pw_passwd +#define PASSWD_UID result.pw_uid +#define PASSWD_GID result.pw_gid +#define PASSWD_GECOS result.pw_gecos +#define PASSWD_DIR result.pw_dir +#define PASSWD_SHELL result.pw_shell + +#define LDF_STRING(field) \ + WRITE_STRING(fp,field) + +#define LDF_TYPE(field,type) \ + WRITE(fp,&(field),sizeof(type)) + enum nss_status _nss_ldap_getpwnam_r(const char *name, struct passwd *result, char *buffer,size_t buflen,int *errnop) @@ -179,6 +196,28 @@ enum nss_status _nss_ldap_getpwnam_r(const char *name, LM_PASSWD, _nss_ldap_parse_pw, LDAP_NSS_BUFLEN_DEFAULT); } +/* the caller should take care of opening and closing the stream */ +int nslcd_getpwnam(FILE *fp,const char *name) +{ + int32_t tmpint32; + /* these are here for now until we rewrite the LDAP code */ + struct passwd result; + char buffer[1024]; + int errnop; + int retv; + /* do the LDAP request */ + retv=nss2nslcd(_nss_ldap_getpwnam_r(name,&result,buffer,1024,&errnop)); + /* write the response header */ + WRITE_INT32(fp,NSLCD_VERSION); + WRITE_INT32(fp,NSLCD_RT_GETPWBYNAME); + WRITE_INT32(fp,retv); + /* write the record */ + LDF_PASSWD; + fflush(fp); + /* we're done */ + return 0; +} + enum nss_status _nss_ldap_getpwuid_r(uid_t uid, struct passwd *result, char *buffer,size_t buflen,int *errnop) |