From 6ffd9f0708c4ff382defb760b8c65cea01879c32 Mon Sep 17 00:00:00 2001 From: Arthur de Jong Date: Sat, 11 Nov 2006 15:16:12 +0000 Subject: fix naming and copyright headers git-svn-id: http://arthurdejong.org/svn/nss-pam-ldapd/libnss_ldapd@85 ef36b2f9-881f-0410-afb5-c4e39611909c --- server/Makefile.am | 4 +- server/alias.c | 143 ++++++++++++++++++++++ server/aliases.c | 141 ---------------------- server/automount.c | 26 ++-- server/common.c | 1 + server/common.h | 1 + server/ether.c | 144 ++++++++++++++++++++++ server/ethers.c | 142 ---------------------- server/group.c | 2 + server/host.c | 330 +++++++++++++++++++++++++++++++++++++++++++++++++++ server/hosts.c | 328 -------------------------------------------------- server/ldap-nss.c | 22 ++-- server/ldap-nss.h | 26 ++-- server/ldap-parse.h | 27 +++-- server/ldap-schema.c | 26 ++-- server/ldap-schema.h | 26 ++-- server/netgroup.c | 37 +++--- server/network.c | 202 +++++++++++++++++++++++++++++++ server/networks.c | 200 ------------------------------- server/passwd.c | 2 + server/protocol.c | 120 +++++++++++++++++++ server/protocols.c | 118 ------------------ server/rpc.c | 26 ++-- server/service.c | 227 +++++++++++++++++++++++++++++++++++ server/services.c | 225 ----------------------------------- server/shadow.c | 26 ++-- server/util.c | 26 ++-- server/util.h | 26 ++-- 28 files changed, 1330 insertions(+), 1294 deletions(-) create mode 100644 server/alias.c delete mode 100644 server/aliases.c create mode 100644 server/ether.c delete mode 100644 server/ethers.c create mode 100644 server/host.c delete mode 100644 server/hosts.c create mode 100644 server/network.c delete mode 100644 server/networks.c create mode 100644 server/protocol.c delete mode 100644 server/protocols.c create mode 100644 server/service.c delete mode 100644 server/services.c diff --git a/server/Makefile.am b/server/Makefile.am index 72d004a..eba28d1 100644 --- a/server/Makefile.am +++ b/server/Makefile.am @@ -21,8 +21,8 @@ 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 \ + alias.c automount.c ether.c group.c host.c netgroup.c \ + network.c passwd.c protocol.c rpc.c service.c shadow.c \ dnsconfig.c dnsconfig.h ldap-nss.c ldap-nss.h ldap-parse.h \ ldap-schema.c ldap-schema.h pagectrl.c pagectrl.h \ resolve.c resolve.h util.c util.h diff --git a/server/alias.c b/server/alias.c new file mode 100644 index 0000000..d1fc842 --- /dev/null +++ b/server/alias.c @@ -0,0 +1,143 @@ +/* + alias.c - alias entry lookup routines + This file was part of the nss-ldap library (as ldap-alias.c) + which has been forked into the nss-ldapd library. + + Copyright (C) 1997-2005 Luke Howard + 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 "config.h" + +#include +#include +#include +#include +#include +#include +#include +#if defined(HAVE_THREAD_H) +#include +#elif defined(HAVE_PTHREAD_H) +#include +#endif + +#include "ldap-nss.h" +#include "util.h" +#include "nslcd-server.h" +#include "common.h" +#include "log.h" + +static enum nss_status _nss_ldap_parse_alias( + LDAPMessage *e,struct ldap_state *pvt,void *result, + char *buffer,size_t buflen) +{ + + struct aliasent *alias=(struct aliasent *)result; + enum nss_status stat; + + stat=_nss_ldap_getrdnvalue(e,ATM(LM_ALIASES,cn),&alias->alias_name,&buffer,&buflen); + if (stat != NSS_STATUS_SUCCESS) + return stat; + + stat=_nss_ldap_assign_attrvals(e,AT(rfc822MailMember),NULL,&alias->alias_members,&buffer,&buflen,&alias->alias_members_len); + + return stat; +} + +static int write_alias(LDAPMessage *e,struct ldap_state *pvt,FILE *fp) +{ + int stat; + log_log(LOG_DEBUG,"write_alias: _nss_ldap_write_rndvalue"); + if ((stat=_nss_ldap_write_rndvalue(fp,e,ATM(LM_ALIASES,cn)))!=NSLCD_RESULT_SUCCESS) + return stat; + log_log(LOG_DEBUG,"write_alias: _nss_ldap_write_attrvals"); + if ((stat=_nss_ldap_write_attrvals(fp,e,AT(rfc822MailMember)))!=NSLCD_RESULT_SUCCESS) + return stat; + return NSLCD_RESULT_SUCCESS; +} + + +/* macros for expanding the LDF_ALIAS macro */ +#define LDF_STRING(field) WRITE_STRING(fp,field) +#define LDF_STRINGLIST(field) WRITE_STRINGLIST_NUM(fp,field,result.alias_members_len) +#define ALIAS_NAME result.alias_name +#define ALIAS_RCPTS result.alias_members + +int nslcd_alias_byname(FILE *fp) +{ + int32_t tmpint32; + char *name; + struct ldap_args a; + /* read request parameters */ + READ_STRING_ALLOC(fp,name); + /* log call */ + log_log(LOG_DEBUG,"nslcd_alias_byname(%s)",name); + /* write the response header */ + WRITE_INT32(fp,NSLCD_VERSION); + WRITE_INT32(fp,NSLCD_ACTION_ALIAS_BYNAME); + /* do the LDAP request */ + LA_INIT(a); + LA_STRING(a)=name; + LA_TYPE(a)=LA_TYPE_STRING; + _nss_ldap_searchbyname(&a,_nss_ldap_filt_getaliasbyname,LM_ALIASES,fp,write_alias); + /* no more need for this */ + free(name); + WRITE_FLUSH(fp); + log_log(LOG_DEBUG,"nslcd_alias_byname DONE"); + /* we're done */ + return 0; +} + +int nslcd_alias_all(FILE *fp) +{ + int32_t tmpint32,tmp2int32; + static struct ent_context *alias_context; + /* these are here for now until we rewrite the LDAP code */ + struct aliasent result; + char buffer[1024]; + int errnop; + int retv; + /* log call */ + log_log(LOG_DEBUG,"nslcd_alias_all"); + /* write the response header */ + WRITE_INT32(fp,NSLCD_VERSION); + WRITE_INT32(fp,NSLCD_ACTION_ALIAS_ALL); + /* initialize context */ + if (_nss_ldap_ent_context_init(&alias_context)==NULL) + return -1; + /* loop over all results */ + while ((retv=nss2nslcd(_nss_ldap_getent(&alias_context,&result,buffer,1024,&errnop,_nss_ldap_filt_getaliasent,LM_ALIASES,_nss_ldap_parse_alias)))==NSLCD_RESULT_SUCCESS) + { + /* write the result code */ + WRITE_INT32(fp,retv); + /* write the alias entry */ + LDF_ALIAS; + fflush(fp); + } + /* write the final result code */ + WRITE_INT32(fp,retv); + /* FIXME: if a previous call returns what happens to the context? */ + _nss_ldap_enter(); + _nss_ldap_ent_context_release(alias_context); + _nss_ldap_leave(); + log_log(LOG_DEBUG,"nslcd_alias_all DONE"); + /* we're done */ + return 0; +} diff --git a/server/aliases.c b/server/aliases.c deleted file mode 100644 index d7031fd..0000000 --- a/server/aliases.c +++ /dev/null @@ -1,141 +0,0 @@ -/* - aliases.c - alias entry lookup routines - - Copyright (C) 1997-2005 Luke Howard - 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 "config.h" - -#include -#include -#include -#include -#include -#include -#include -#if defined(HAVE_THREAD_H) -#include -#elif defined(HAVE_PTHREAD_H) -#include -#endif - -#include "ldap-nss.h" -#include "util.h" -#include "nslcd-server.h" -#include "common.h" -#include "log.h" - -static enum nss_status _nss_ldap_parse_alias( - LDAPMessage *e,struct ldap_state *pvt,void *result, - char *buffer,size_t buflen) -{ - - struct aliasent *alias=(struct aliasent *)result; - enum nss_status stat; - - stat=_nss_ldap_getrdnvalue(e,ATM(LM_ALIASES,cn),&alias->alias_name,&buffer,&buflen); - if (stat != NSS_STATUS_SUCCESS) - return stat; - - stat=_nss_ldap_assign_attrvals(e,AT(rfc822MailMember),NULL,&alias->alias_members,&buffer,&buflen,&alias->alias_members_len); - - return stat; -} - -static int write_alias(LDAPMessage *e,struct ldap_state *pvt,FILE *fp) -{ - int stat; - log_log(LOG_DEBUG,"write_alias: _nss_ldap_write_rndvalue"); - if ((stat=_nss_ldap_write_rndvalue(fp,e,ATM(LM_ALIASES,cn)))!=NSLCD_RESULT_SUCCESS) - return stat; - log_log(LOG_DEBUG,"write_alias: _nss_ldap_write_attrvals"); - if ((stat=_nss_ldap_write_attrvals(fp,e,AT(rfc822MailMember)))!=NSLCD_RESULT_SUCCESS) - return stat; - return NSLCD_RESULT_SUCCESS; -} - - -/* macros for expanding the LDF_ALIAS macro */ -#define LDF_STRING(field) WRITE_STRING(fp,field) -#define LDF_STRINGLIST(field) WRITE_STRINGLIST_NUM(fp,field,result.alias_members_len) -#define ALIAS_NAME result.alias_name -#define ALIAS_RCPTS result.alias_members - -int nslcd_alias_byname(FILE *fp) -{ - int32_t tmpint32; - char *name; - struct ldap_args a; - /* read request parameters */ - READ_STRING_ALLOC(fp,name); - /* log call */ - log_log(LOG_DEBUG,"nslcd_alias_byname(%s)",name); - /* write the response header */ - WRITE_INT32(fp,NSLCD_VERSION); - WRITE_INT32(fp,NSLCD_ACTION_ALIAS_BYNAME); - /* do the LDAP request */ - LA_INIT(a); - LA_STRING(a)=name; - LA_TYPE(a)=LA_TYPE_STRING; - _nss_ldap_searchbyname(&a,_nss_ldap_filt_getaliasbyname,LM_ALIASES,fp,write_alias); - /* no more need for this */ - free(name); - WRITE_FLUSH(fp); - log_log(LOG_DEBUG,"nslcd_alias_byname DONE"); - /* we're done */ - return 0; -} - -int nslcd_alias_all(FILE *fp) -{ - int32_t tmpint32,tmp2int32; - static struct ent_context *alias_context; - /* these are here for now until we rewrite the LDAP code */ - struct aliasent result; - char buffer[1024]; - int errnop; - int retv; - /* log call */ - log_log(LOG_DEBUG,"nslcd_alias_all"); - /* write the response header */ - WRITE_INT32(fp,NSLCD_VERSION); - WRITE_INT32(fp,NSLCD_ACTION_ALIAS_ALL); - /* initialize context */ - if (_nss_ldap_ent_context_init(&alias_context)==NULL) - return -1; - /* loop over all results */ - while ((retv=nss2nslcd(_nss_ldap_getent(&alias_context,&result,buffer,1024,&errnop,_nss_ldap_filt_getaliasent,LM_ALIASES,_nss_ldap_parse_alias)))==NSLCD_RESULT_SUCCESS) - { - /* write the result code */ - WRITE_INT32(fp,retv); - /* write the alias entry */ - LDF_ALIAS; - fflush(fp); - } - /* write the final result code */ - WRITE_INT32(fp,retv); - /* FIXME: if a previous call returns what happens to the context? */ - _nss_ldap_enter(); - _nss_ldap_ent_context_release(alias_context); - _nss_ldap_leave(); - log_log(LOG_DEBUG,"nslcd_alias_all DONE"); - /* we're done */ - return 0; -} diff --git a/server/automount.c b/server/automount.c index 1b7b4cb..e81ce59 100644 --- a/server/automount.c +++ b/server/automount.c @@ -1,24 +1,26 @@ /* + automount.c - automounter maps lookup routines + This file was part of the nss-ldap library (as ldap-automount.c) + which has been forked into the nss-ldapd library. + Copyright (C) 2005 Luke Howard - This file is part of the nss_ldap library. - Contributed by Luke Howard, , 2005. + 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. - - $Id$ + 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" diff --git a/server/common.c b/server/common.c index 9ada651..f4be471 100644 --- a/server/common.c +++ b/server/common.c @@ -1,5 +1,6 @@ /* common.c - common server code routines + This file is part of the nss-ldapd library. Copyright (C) 2006 West Consulting Copyright (C) 2006 Arthur de Jong diff --git a/server/common.h b/server/common.h index 65d5f49..69b1732 100644 --- a/server/common.h +++ b/server/common.h @@ -1,5 +1,6 @@ /* common.h - common server code routines + This file is part of the nss-ldapd library. Copyright (C) 2006 West Consulting Copyright (C) 2006 Arthur de Jong diff --git a/server/ether.c b/server/ether.c new file mode 100644 index 0000000..cf96437 --- /dev/null +++ b/server/ether.c @@ -0,0 +1,144 @@ +/* + ether.c - ethernet address entry lookup routines + This file was part of the nss-ldap library (as ldap-ethers.c) + which has been forked into the nss-ldapd library. + + Copyright (C) 1997-2005 Luke Howard + 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 "config.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef HAVE_LBER_H +#include +#endif +#ifdef HAVE_LDAP_H +#include +#endif +#if defined(HAVE_THREAD_H) +#include +#elif defined(HAVE_PTHREAD_H) +#include +#endif +#ifdef HAVE_NET_ROUTE_H +#include +#endif +#ifdef HAVE_NETINET_IF_ETHER_H +#include +#endif +#ifdef HAVE_NETINET_ETHER_H +#include +#endif + +#include "ldap-nss.h" +#include "util.h" + +/* for HP-UX */ +#ifndef NSS_BUFLEN_ETHERS +#define NSS_BUFLEN_ETHERS 1024 +#endif /* NSS_BUFLEN_ETHERS */ + +#ifndef HAVE_STRUCT_ETHER_ADDR +struct ether_addr { + u_char ether_addr_octet[6]; +}; +#endif + +struct ether +{ + char *e_name; + struct ether_addr e_addr; +}; + +static struct ent_context *ether_context = NULL; + +static enum nss_status +_nss_ldap_parse_ether (LDAPMessage * e, + struct ldap_state * pvt, + void *result, char *buffer, size_t buflen) +{ + struct ether *ether = (struct ether *) result; + char *saddr; + enum nss_status stat; + struct ether_addr *addr; + + stat = _nss_ldap_assign_attrval (e, ATM (LM_ETHERS, cn), + ðer->e_name, &buffer, &buflen); + if (stat != NSS_STATUS_SUCCESS) + return stat; + + stat = _nss_ldap_assign_attrval (e, AT (macAddress), &saddr, + &buffer, &buflen); + + if (stat != NSS_STATUS_SUCCESS || ((addr = ether_aton (saddr)) == NULL)) + return NSS_STATUS_NOTFOUND; + + memcpy (ðer->e_addr, addr, sizeof (*addr)); + + return NSS_STATUS_SUCCESS; +} + +enum nss_status +_nss_ldap_gethostton_r (const char *name, struct ether * result, + char *buffer, size_t buflen, int *errnop) +{ + LOOKUP_NAME (name, result, buffer, buflen, errnop, + _nss_ldap_filt_gethostton, LM_ETHERS, _nss_ldap_parse_ether, + LDAP_NSS_BUFLEN_DEFAULT); +} + +enum nss_status +_nss_ldap_getntohost_r (struct ether_addr * addr, struct ether * result, + char *buffer, size_t buflen, int *errnop) +{ +/* The correct ether_ntoa call would have a struct ether instead of whatever + result->e_addr is */ + + LOOKUP_NAME (ether_ntoa ((struct ether_addr *) (&result->e_addr)), result, + buffer, buflen, errnop, _nss_ldap_filt_getntohost, LM_ETHERS, + _nss_ldap_parse_ether, LDAP_NSS_BUFLEN_DEFAULT); +} + +enum nss_status _nss_ldap_setetherent (void) +{ + LOOKUP_SETENT (ether_context); +} + +enum nss_status _nss_ldap_endetherent (void) +{ + LOOKUP_ENDENT (ether_context); +} + +enum nss_status +_nss_ldap_getetherent_r (struct ether * result, char *buffer, size_t buflen, + int *errnop) +{ + LOOKUP_GETENT (ether_context, result, buffer, buflen, errnop, + _nss_ldap_filt_getetherent, LM_ETHERS, + _nss_ldap_parse_ether, LDAP_NSS_BUFLEN_DEFAULT); +} diff --git a/server/ethers.c b/server/ethers.c deleted file mode 100644 index a6dafe9..0000000 --- a/server/ethers.c +++ /dev/null @@ -1,142 +0,0 @@ -/* - Copyright (C) 1997-2005 Luke Howard - This file is part of the nss_ldap library. - Contributed by Luke Howard, , 1997. - - 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. - - The nss_ldap 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. - - $Id$ -*/ - -#include "config.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#ifdef HAVE_LBER_H -#include -#endif -#ifdef HAVE_LDAP_H -#include -#endif -#if defined(HAVE_THREAD_H) -#include -#elif defined(HAVE_PTHREAD_H) -#include -#endif -#ifdef HAVE_NET_ROUTE_H -#include -#endif -#ifdef HAVE_NETINET_IF_ETHER_H -#include -#endif -#ifdef HAVE_NETINET_ETHER_H -#include -#endif - -#include "ldap-nss.h" -#include "util.h" - -/* for HP-UX */ -#ifndef NSS_BUFLEN_ETHERS -#define NSS_BUFLEN_ETHERS 1024 -#endif /* NSS_BUFLEN_ETHERS */ - -#ifndef HAVE_STRUCT_ETHER_ADDR -struct ether_addr { - u_char ether_addr_octet[6]; -}; -#endif - -struct ether -{ - char *e_name; - struct ether_addr e_addr; -}; - -static struct ent_context *ether_context = NULL; - -static enum nss_status -_nss_ldap_parse_ether (LDAPMessage * e, - struct ldap_state * pvt, - void *result, char *buffer, size_t buflen) -{ - struct ether *ether = (struct ether *) result; - char *saddr; - enum nss_status stat; - struct ether_addr *addr; - - stat = _nss_ldap_assign_attrval (e, ATM (LM_ETHERS, cn), - ðer->e_name, &buffer, &buflen); - if (stat != NSS_STATUS_SUCCESS) - return stat; - - stat = _nss_ldap_assign_attrval (e, AT (macAddress), &saddr, - &buffer, &buflen); - - if (stat != NSS_STATUS_SUCCESS || ((addr = ether_aton (saddr)) == NULL)) - return NSS_STATUS_NOTFOUND; - - memcpy (ðer->e_addr, addr, sizeof (*addr)); - - return NSS_STATUS_SUCCESS; -} - -enum nss_status -_nss_ldap_gethostton_r (const char *name, struct ether * result, - char *buffer, size_t buflen, int *errnop) -{ - LOOKUP_NAME (name, result, buffer, buflen, errnop, - _nss_ldap_filt_gethostton, LM_ETHERS, _nss_ldap_parse_ether, - LDAP_NSS_BUFLEN_DEFAULT); -} - -enum nss_status -_nss_ldap_getntohost_r (struct ether_addr * addr, struct ether * result, - char *buffer, size_t buflen, int *errnop) -{ -/* The correct ether_ntoa call would have a struct ether instead of whatever - result->e_addr is */ - - LOOKUP_NAME (ether_ntoa ((struct ether_addr *) (&result->e_addr)), result, - buffer, buflen, errnop, _nss_ldap_filt_getntohost, LM_ETHERS, - _nss_ldap_parse_ether, LDAP_NSS_BUFLEN_DEFAULT); -} - -enum nss_status _nss_ldap_setetherent (void) -{ - LOOKUP_SETENT (ether_context); -} - -enum nss_status _nss_ldap_endetherent (void) -{ - LOOKUP_ENDENT (ether_context); -} - -enum nss_status -_nss_ldap_getetherent_r (struct ether * result, char *buffer, size_t buflen, - int *errnop) -{ - LOOKUP_GETENT (ether_context, result, buffer, buflen, errnop, - _nss_ldap_filt_getetherent, LM_ETHERS, - _nss_ldap_parse_ether, LDAP_NSS_BUFLEN_DEFAULT); -} diff --git a/server/group.c b/server/group.c index 38a1c78..13139ce 100644 --- a/server/group.c +++ b/server/group.c @@ -1,5 +1,7 @@ /* group.c - group entry lookup routines + This file was part of the nss-ldap library (as ldap-grp.c) which + has been forked into the nss-ldapd library. Copyright (C) 1997-2006 Luke Howard Copyright (C) 2006 West Consulting diff --git a/server/host.c b/server/host.c new file mode 100644 index 0000000..fbd2f62 --- /dev/null +++ b/server/host.c @@ -0,0 +1,330 @@ +/* + host.c - host name lookup routines + This file was part of the nss-ldap library (as ldap-hosts.c) + which has been forked into the nss-ldapd library. + + Copyright (C) 1997-2005 Luke Howard + 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 "config.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef HAVE_LBER_H +#include +#endif +#ifdef HAVE_LDAP_H +#include +#endif +#if defined(HAVE_THREAD_H) +#include +#elif defined(HAVE_PTHREAD_H) +#include +#endif +#ifdef INET6 +#include +#endif + +#include "ldap-nss.h" +#include "util.h" + +#ifndef MAXALIASES +#define MAXALIASES 35 +#endif + +static struct ent_context *hosts_context = NULL; + +static enum nss_status +_nss_ldap_parse_host (LDAPMessage * e, + struct ldap_state * pvt, + void *result, char *buffer, size_t buflen, + int af) +{ + /* this code needs reviewing. XXX */ + struct hostent *host = (struct hostent *) result; + enum nss_status stat; +#ifdef INET6 + char addressbuf[sizeof ("ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255") * + MAXALIASES]; +#else + char addressbuf[sizeof ("255.255.255.255") * MAXALIASES]; +#endif + char *p_addressbuf = addressbuf; + char **addresses = NULL; + size_t addresslen = sizeof (addressbuf); + size_t addresscount = 0; + char **host_addresses = NULL; + int i; + + *addressbuf = *buffer = '\0'; + + stat = _nss_ldap_assign_attrval (e, ATM (LM_HOSTS, cn), &host->h_name, + &buffer, &buflen); + if (stat != NSS_STATUS_SUCCESS) + return stat; + + stat = + _nss_ldap_assign_attrvals (e, ATM (LM_HOSTS, cn), host->h_name, + &host->h_aliases, &buffer, &buflen, NULL); + if (stat != NSS_STATUS_SUCCESS) + return stat; + + stat = + _nss_ldap_assign_attrvals (e, AT (ipHostNumber), NULL, &addresses, + &p_addressbuf, &addresslen, &addresscount); + if (stat != NSS_STATUS_SUCCESS) + return stat; + if (addresscount == 0) + return NSS_STATUS_NOTFOUND; + +#ifdef INET6 + if (af == AF_INET6) + { + if (bytesleft (buffer, buflen, char *) < + (size_t) ((addresscount + 1) * IN6ADDRSZ)) + return NSS_STATUS_TRYAGAIN; + } + else + { + if (bytesleft (buffer, buflen, char *) < + (size_t) ((addresscount + 1) * INADDRSZ)) + return NSS_STATUS_TRYAGAIN; + } +#else + if (bytesleft (buffer, buflen, char *) < + (size_t) ((addresscount + 1) * INADDRSZ)) + return NSS_STATUS_TRYAGAIN; +#endif + + align (buffer, buflen, char *); + host_addresses = (char **) buffer; + host->h_addr_list = host_addresses; + host_addresses[addresscount] = NULL; + + buffer += (addresscount + 1) * sizeof (char *); + buflen -= (addresscount + 1) * sizeof (char *); +#ifdef INET6 + host->h_addrtype = 0; + host->h_length = 0; +#else + host->h_addrtype = AF_INET; + host->h_length = INADDRSZ; +#endif + + for (i = 0; i < (int) addresscount; i++) + { +#ifdef INET6 + char *addr = addresses[i]; + char entdata[16]; + /* from glibc NIS parser. Thanks, Uli. */ + + if (af == AF_INET && inet_pton (AF_INET, addr, entdata) > 0) + { + if (_res.options & RES_USE_INET6) + { + map_v4v6_address ((char *) entdata, + (char *) entdata); + host->h_addrtype = AF_INET6; + host->h_length = IN6ADDRSZ; + } + else + { + host->h_addrtype = AF_INET; + host->h_length = INADDRSZ; + } + } + else if (af == AF_INET6 + && inet_pton (AF_INET6, addr, entdata) > 0) + { + host->h_addrtype = AF_INET6; + host->h_length = IN6ADDRSZ; + } + else + /* Illegal address: ignore line. */ + continue; + +#else + unsigned long haddr; + haddr = inet_addr (addresses[i]); +#endif + + if (buflen < (size_t) host->h_length) + return NSS_STATUS_TRYAGAIN; + +#ifdef INET6 + memcpy (buffer, entdata, host->h_length); + *host_addresses = buffer; + buffer += host->h_length; + buflen -= host->h_length; +#else + memcpy (buffer, &haddr, INADDRSZ); + *host_addresses = buffer; + buffer += INADDRSZ; + buflen -= INADDRSZ; +#endif + + host_addresses++; + *host_addresses = NULL; + } + +#ifdef INET6 + /* if host->h_addrtype is not changed, this entry does not + have the right IP address. */ + if (host->h_addrtype == 0) + return NSS_STATUS_NOTFOUND; +#endif + + return NSS_STATUS_SUCCESS; +} + +static enum nss_status +_nss_ldap_parse_hostv4 (LDAPMessage * e, + struct ldap_state * pvt, + void *result, char *buffer, size_t buflen) +{ + return _nss_ldap_parse_host (e, pvt, result, buffer, buflen, + AF_INET); +} + +#ifdef INET6 +static enum nss_status +_nss_ldap_parse_hostv6 (LDAPMessage * e, + struct ldap_state * pvt, + void *result, char *buffer, size_t buflen) +{ + return _nss_ldap_parse_host (e, pvt, result, buffer, buflen, + AF_INET6); +} +#endif + +enum nss_status _nss_ldap_gethostbyname2_r (const char *name, int af, struct hostent * result, + char *buffer, size_t buflen, int *errnop, + int *h_errnop) +{ + enum nss_status status; + struct ldap_args a; + + LA_INIT (a); + LA_STRING (a) = name; + LA_TYPE (a) = LA_TYPE_STRING; + + status = _nss_ldap_getbyname (&a, + result, + buffer, + buflen, + errnop, + _nss_ldap_filt_gethostbyname, + LM_HOSTS, +#ifdef INET6 + (af == AF_INET6) ? + _nss_ldap_parse_hostv6 : +#endif + _nss_ldap_parse_hostv4); + + MAP_H_ERRNO (status, *h_errnop); + + return status; +} + +enum nss_status _nss_ldap_gethostbyname_r (const char *name, struct hostent * result, + char *buffer, size_t buflen, int *errnop, + int *h_errnop) +{ + return _nss_ldap_gethostbyname2_r (name, +#ifdef INET6 + (_res.options & RES_USE_INET6) ? + AF_INET6 : +#endif + AF_INET, result, buffer, buflen, + errnop, h_errnop); +} + +enum nss_status _nss_ldap_gethostbyaddr_r (struct in_addr * addr, int len, int type, + struct hostent * result, char *buffer, + size_t buflen, int *errnop, int *h_errnop) +{ + enum nss_status status; + struct ldap_args a; + + /* if querying by IPv6 address, make sure the address is "normalized" -- + * it should contain no leading zeros and all components of the address. + * still we can't fit an IPv6 address in an int, so who cares for now. + */ + + LA_INIT (a); + LA_STRING (a) = inet_ntoa (*addr); + LA_TYPE (a) = LA_TYPE_STRING; + + status = _nss_ldap_getbyname (&a, + result, + buffer, + buflen, + errnop, + _nss_ldap_filt_gethostbyaddr, + LM_HOSTS, +#ifdef INET6 + (type == AF_INET6) ? + _nss_ldap_parse_hostv6 : +#endif + _nss_ldap_parse_hostv4); + + MAP_H_ERRNO (status, *h_errnop); + + return status; +} + +enum nss_status _nss_ldap_sethostent (void) +{ + LOOKUP_SETENT (hosts_context); +} + +enum nss_status _nss_ldap_endhostent (void) +{ + LOOKUP_ENDENT (hosts_context); +} + +enum nss_status _nss_ldap_gethostent_r (struct hostent * result, char *buffer, size_t buflen, + int *errnop, int *h_errnop) +{ + enum nss_status status; + + status = _nss_ldap_getent (&hosts_context, + result, + buffer, + buflen, + errnop, + _nss_ldap_filt_gethostent, LM_HOSTS, +#ifdef INET6 + (_res.options & RES_USE_INET6) ? + _nss_ldap_parse_hostv6 : +#endif + _nss_ldap_parse_hostv4); + + MAP_H_ERRNO (status, *h_errnop); + + return status; +} diff --git a/server/hosts.c b/server/hosts.c deleted file mode 100644 index 935c857..0000000 --- a/server/hosts.c +++ /dev/null @@ -1,328 +0,0 @@ -/* - Copyright (C) 1997-2005 Luke Howard - This file is part of the nss_ldap library. - Contributed by Luke Howard, , 1997. - - 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. - - The nss_ldap 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. - - $Id$ -*/ - -#include "config.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#ifdef HAVE_LBER_H -#include -#endif -#ifdef HAVE_LDAP_H -#include -#endif -#if defined(HAVE_THREAD_H) -#include -#elif defined(HAVE_PTHREAD_H) -#include -#endif -#ifdef INET6 -#include -#endif - -#include "ldap-nss.h" -#include "util.h" - -#ifndef MAXALIASES -#define MAXALIASES 35 -#endif - -static struct ent_context *hosts_context = NULL; - -static enum nss_status -_nss_ldap_parse_host (LDAPMessage * e, - struct ldap_state * pvt, - void *result, char *buffer, size_t buflen, - int af) -{ - /* this code needs reviewing. XXX */ - struct hostent *host = (struct hostent *) result; - enum nss_status stat; -#ifdef INET6 - char addressbuf[sizeof ("ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255") * - MAXALIASES]; -#else - char addressbuf[sizeof ("255.255.255.255") * MAXALIASES]; -#endif - char *p_addressbuf = addressbuf; - char **addresses = NULL; - size_t addresslen = sizeof (addressbuf); - size_t addresscount = 0; - char **host_addresses = NULL; - int i; - - *addressbuf = *buffer = '\0'; - - stat = _nss_ldap_assign_attrval (e, ATM (LM_HOSTS, cn), &host->h_name, - &buffer, &buflen); - if (stat != NSS_STATUS_SUCCESS) - return stat; - - stat = - _nss_ldap_assign_attrvals (e, ATM (LM_HOSTS, cn), host->h_name, - &host->h_aliases, &buffer, &buflen, NULL); - if (stat != NSS_STATUS_SUCCESS) - return stat; - - stat = - _nss_ldap_assign_attrvals (e, AT (ipHostNumber), NULL, &addresses, - &p_addressbuf, &addresslen, &addresscount); - if (stat != NSS_STATUS_SUCCESS) - return stat; - if (addresscount == 0) - return NSS_STATUS_NOTFOUND; - -#ifdef INET6 - if (af == AF_INET6) - { - if (bytesleft (buffer, buflen, char *) < - (size_t) ((addresscount + 1) * IN6ADDRSZ)) - return NSS_STATUS_TRYAGAIN; - } - else - { - if (bytesleft (buffer, buflen, char *) < - (size_t) ((addresscount + 1) * INADDRSZ)) - return NSS_STATUS_TRYAGAIN; - } -#else - if (bytesleft (buffer, buflen, char *) < - (size_t) ((addresscount + 1) * INADDRSZ)) - return NSS_STATUS_TRYAGAIN; -#endif - - align (buffer, buflen, char *); - host_addresses = (char **) buffer; - host->h_addr_list = host_addresses; - host_addresses[addresscount] = NULL; - - buffer += (addresscount + 1) * sizeof (char *); - buflen -= (addresscount + 1) * sizeof (char *); -#ifdef INET6 - host->h_addrtype = 0; - host->h_length = 0; -#else - host->h_addrtype = AF_INET; - host->h_length = INADDRSZ; -#endif - - for (i = 0; i < (int) addresscount; i++) - { -#ifdef INET6 - char *addr = addresses[i]; - char entdata[16]; - /* from glibc NIS parser. Thanks, Uli. */ - - if (af == AF_INET && inet_pton (AF_INET, addr, entdata) > 0) - { - if (_res.options & RES_USE_INET6) - { - map_v4v6_address ((char *) entdata, - (char *) entdata); - host->h_addrtype = AF_INET6; - host->h_length = IN6ADDRSZ; - } - else - { - host->h_addrtype = AF_INET; - host->h_length = INADDRSZ; - } - } - else if (af == AF_INET6 - && inet_pton (AF_INET6, addr, entdata) > 0) - { - host->h_addrtype = AF_INET6; - host->h_length = IN6ADDRSZ; - } - else - /* Illegal address: ignore line. */ - continue; - -#else - unsigned long haddr; - haddr = inet_addr (addresses[i]); -#endif - - if (buflen < (size_t) host->h_length) - return NSS_STATUS_TRYAGAIN; - -#ifdef INET6 - memcpy (buffer, entdata, host->h_length); - *host_addresses = buffer; - buffer += host->h_length; - buflen -= host->h_length; -#else - memcpy (buffer, &haddr, INADDRSZ); - *host_addresses = buffer; - buffer += INADDRSZ; - buflen -= INADDRSZ; -#endif - - host_addresses++; - *host_addresses = NULL; - } - -#ifdef INET6 - /* if host->h_addrtype is not changed, this entry does not - have the right IP address. */ - if (host->h_addrtype == 0) - return NSS_STATUS_NOTFOUND; -#endif - - return NSS_STATUS_SUCCESS; -} - -static enum nss_status -_nss_ldap_parse_hostv4 (LDAPMessage * e, - struct ldap_state * pvt, - void *result, char *buffer, size_t buflen) -{ - return _nss_ldap_parse_host (e, pvt, result, buffer, buflen, - AF_INET); -} - -#ifdef INET6 -static enum nss_status -_nss_ldap_parse_hostv6 (LDAPMessage * e, - struct ldap_state * pvt, - void *result, char *buffer, size_t buflen) -{ - return _nss_ldap_parse_host (e, pvt, result, buffer, buflen, - AF_INET6); -} -#endif - -enum nss_status _nss_ldap_gethostbyname2_r (const char *name, int af, struct hostent * result, - char *buffer, size_t buflen, int *errnop, - int *h_errnop) -{ - enum nss_status status; - struct ldap_args a; - - LA_INIT (a); - LA_STRING (a) = name; - LA_TYPE (a) = LA_TYPE_STRING; - - status = _nss_ldap_getbyname (&a, - result, - buffer, - buflen, - errnop, - _nss_ldap_filt_gethostbyname, - LM_HOSTS, -#ifdef INET6 - (af == AF_INET6) ? - _nss_ldap_parse_hostv6 : -#endif - _nss_ldap_parse_hostv4); - - MAP_H_ERRNO (status, *h_errnop); - - return status; -} - -enum nss_status _nss_ldap_gethostbyname_r (const char *name, struct hostent * result, - char *buffer, size_t buflen, int *errnop, - int *h_errnop) -{ - return _nss_ldap_gethostbyname2_r (name, -#ifdef INET6 - (_res.options & RES_USE_INET6) ? - AF_INET6 : -#endif - AF_INET, result, buffer, buflen, - errnop, h_errnop); -} - -enum nss_status _nss_ldap_gethostbyaddr_r (struct in_addr * addr, int len, int type, - struct hostent * result, char *buffer, - size_t buflen, int *errnop, int *h_errnop) -{ - enum nss_status status; - struct ldap_args a; - - /* if querying by IPv6 address, make sure the address is "normalized" -- - * it should contain no leading zeros and all components of the address. - * still we can't fit an IPv6 address in an int, so who cares for now. - */ - - LA_INIT (a); - LA_STRING (a) = inet_ntoa (*addr); - LA_TYPE (a) = LA_TYPE_STRING; - - status = _nss_ldap_getbyname (&a, - result, - buffer, - buflen, - errnop, - _nss_ldap_filt_gethostbyaddr, - LM_HOSTS, -#ifdef INET6 - (type == AF_INET6) ? - _nss_ldap_parse_hostv6 : -#endif - _nss_ldap_parse_hostv4); - - MAP_H_ERRNO (status, *h_errnop); - - return status; -} - -enum nss_status _nss_ldap_sethostent (void) -{ - LOOKUP_SETENT (hosts_context); -} - -enum nss_status _nss_ldap_endhostent (void) -{ - LOOKUP_ENDENT (hosts_context); -} - -enum nss_status _nss_ldap_gethostent_r (struct hostent * result, char *buffer, size_t buflen, - int *errnop, int *h_errnop) -{ - enum nss_status status; - - status = _nss_ldap_getent (&hosts_context, - result, - buffer, - buflen, - errnop, - _nss_ldap_filt_gethostent, LM_HOSTS, -#ifdef INET6 - (_res.options & RES_USE_INET6) ? - _nss_ldap_parse_hostv6 : -#endif - _nss_ldap_parse_hostv4); - - MAP_H_ERRNO (status, *h_errnop); - - return status; -} diff --git a/server/ldap-nss.c b/server/ldap-nss.c index 73b5a29..ee0538d 100644 --- a/server/ldap-nss.c +++ b/server/ldap-nss.c @@ -1,26 +1,26 @@ /* ldap-nss.c - main file for NSS interface - This file is part of the nss_ldap library. + This file was part of the nss-ldap library which has been + forked into the nss-ldapd library. Copyright (C) 1997-2006 Luke Howard + 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. - - $Id$ + 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" diff --git a/server/ldap-nss.h b/server/ldap-nss.h index 02963a1..723e573 100644 --- a/server/ldap-nss.h +++ b/server/ldap-nss.h @@ -1,24 +1,26 @@ /* + ldap-nss.c - main file for NSS interface + This file was part of the nss-ldap library which has been + forked into the nss-ldapd library. + Copyright (C) 1997-2005 Luke Howard - This file is part of the nss_ldap library. - Contributed by Luke Howard, , 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. - - $Id$ + 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 _LDAP_NSS_LDAP_LDAP_NSS_H diff --git a/server/ldap-parse.h b/server/ldap-parse.h index c1e1f1f..4fa94aa 100644 --- a/server/ldap-parse.h +++ b/server/ldap-parse.h @@ -1,27 +1,28 @@ /* + ldap-parse.h - helper macros for lookup functions + This file was part of the nss-ldap library which has been + forked into the nss-ldapd library. + Copyright (C) 1997-2005 Luke Howard - This file is part of the nss_ldap library. - Contributed by Luke Howard, , 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. - - $Id$ + 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 _LDAP_NSS_LDAP_LDAP_PARSE_H #define _LDAP_NSS_LDAP_LDAP_PARSE_H diff --git a/server/ldap-schema.c b/server/ldap-schema.c index a0354eb..3956dc6 100644 --- a/server/ldap-schema.c +++ b/server/ldap-schema.c @@ -1,24 +1,26 @@ /* + ldap-schema.c - LDAP schema information functions and definitions + This file was part of the nss-ldap library which has been + forked into the nss-ldapd library. + Copyright (C) 1997-2005 Luke Howard - This file is part of the nss_ldap library. - Contributed by Luke Howard, , 2000. + 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. - - $Id$ + 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" diff --git a/server/ldap-schema.h b/server/ldap-schema.h index b7cfd14..6044f1e 100644 --- a/server/ldap-schema.h +++ b/server/ldap-schema.h @@ -1,24 +1,26 @@ /* + ldap-schema.h - LDAP schema information functions and definitions + This file was part of the nss-ldap library which has been + forked into the nss-ldapd library. + Copyright (C) 1997-2005 Luke Howard - This file is part of the nss_ldap library. - Contributed by Luke Howard, , 1999. + 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. - - $Id$ + 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 _LDAP_NSS_LDAP_LDAP_SCHEMA_H diff --git a/server/netgroup.c b/server/netgroup.c index b5b93cb..5d5e5a1 100644 --- a/server/netgroup.c +++ b/server/netgroup.c @@ -1,25 +1,26 @@ /* - Copyright (C) 2002-2005 Luke Howard - This file is part of the nss_ldap library. - Linux support contributed by Larry Lile, , 2002. - Solaris support contributed by Luke Howard, , 2004. + netgroup.c - netgroup lookup routines + This file was part of the nss-ldap library (as ldap-netgrp.c) + which has been forked into the nss-ldapd library. - 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. + Copyright (C) 1997-2005 Luke Howard + Copyright (C) 2006 West Consulting + Copyright (C) 2006 Arthur de Jong - The nss_ldap library is distributed in the hope that it will be useful, + 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 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. - - $Id$ + 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" @@ -50,10 +51,10 @@ static struct ent_context *_ngbe = NULL; /* - * I pulled the following macro (EXPAND), functions (strip_whitespace and - * _nss_netgroup_parseline) and structures (name_list and __netgrent) from - * glibc-2.2.x. _nss_netgroup_parseline became _nss_ldap_parse_netgr after - * some modification. + * I (Luke Howard) pulled the following macro (EXPAND), functions + * (strip_whitespace and _nss_netgroup_parseline) and structures + * (name_list and __netgrent) from glibc-2.2.x. _nss_netgroup_parseline + * became _nss_ldap_parse_netgr after some modification. * * The rest of the code is modeled on various other _nss_ldap functions. */ diff --git a/server/network.c b/server/network.c new file mode 100644 index 0000000..507eaee --- /dev/null +++ b/server/network.c @@ -0,0 +1,202 @@ +/* + network.c - network address entry lookup routines + This file was part of the nss-ldap library (as ldap-network.c) + which has been forked into the nss-ldapd library. + + Copyright (C) 1997-2005 Luke Howard + 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 +*/ + +/* parts based on nss_nis */ + +#include "config.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef HAVE_LBER_H +#include +#endif +#ifdef HAVE_LDAP_H +#include +#endif +#if defined(HAVE_THREAD_H) +#include +#elif defined(HAVE_PTHREAD_H) +#include +#endif + +#include "ldap-nss.h" +#include "util.h" + +#if defined(HAVE_USERSEC_H) +#define MAXALIASES 35 +#define MAXADDRSIZE 4 +#endif /* HAVE_USERSEC_H */ + +static struct ent_context *net_context = NULL; + +static enum nss_status +_nss_ldap_parse_net (LDAPMessage * e, + struct ldap_state * pvt, + void *result, char *buffer, size_t buflen) +{ + + char *tmp; + struct netent *network = (struct netent *) result; + enum nss_status stat; + + /* IPv6 support ? XXX */ + network->n_addrtype = AF_INET; + + stat = _nss_ldap_assign_attrval (e, ATM (LM_NETWORKS, cn), &network->n_name, + &buffer, &buflen); + if (stat != NSS_STATUS_SUCCESS) + return stat; + + stat = + _nss_ldap_assign_attrval (e, AT (ipNetworkNumber), &tmp, &buffer, + &buflen); + if (stat != NSS_STATUS_SUCCESS) + return stat; + + network->n_net = inet_network (tmp); + + stat = + _nss_ldap_assign_attrvals (e, ATM (LM_NETWORKS, cn), network->n_name, + &network->n_aliases, &buffer, &buflen, NULL); + if (stat != NSS_STATUS_SUCCESS) + return stat; + + return NSS_STATUS_SUCCESS; +} + +enum nss_status _nss_ldap_getnetbyname_r(const char *name,struct netent *result, + char *buffer,size_t buflen,int *errnop, + int *herrnop) +{ + enum nss_status status; + struct ldap_args a; + + LA_INIT (a); + LA_STRING (a) = name; + LA_TYPE (a) = LA_TYPE_STRING; + + status = _nss_ldap_getbyname (&a, + result, + buffer, + buflen, + errnop, + _nss_ldap_filt_getnetbyname, + LM_NETWORKS, _nss_ldap_parse_net); + + MAP_H_ERRNO (status, *herrnop); + + return status; +} + +enum nss_status _nss_ldap_getnetbyaddr_r(unsigned long addr,int type, + struct netent *result,char *buffer,size_t buflen, + int *errnop,int *herrnop) +{ + struct in_addr in; + char buf[256]; + int blen; + struct ldap_args a; + enum nss_status retval = NSS_STATUS_NOTFOUND; + + LA_INIT (a); + LA_TYPE (a) = LA_TYPE_STRING; + + in = inet_makeaddr (addr, 0); + strcpy (buf, inet_ntoa (in)); + blen = strlen (buf); + LA_STRING (a) = buf; + + while (1) + { + retval = _nss_ldap_getbyname (&a, result, buffer, buflen, errnop, + _nss_ldap_filt_getnetbyaddr, + LM_NETWORKS, _nss_ldap_parse_net); + + if (retval != NSS_STATUS_SUCCESS) + { + if (retval == NSS_STATUS_NOTFOUND) + { + if (buf[blen - 2] == '.' && buf[blen - 1] == '\0') + { + buf[blen - 2] = '\0'; + blen -= 2; + continue; + } + else + { + MAP_H_ERRNO (retval, *herrnop); + return NSS_STATUS_NOTFOUND; + } + } + else + { + MAP_H_ERRNO (retval, *herrnop); + return retval; + } + } + else + { + /* retval == NSS_STATUS_SUCCESS */ + break; + } + } + + MAP_H_ERRNO (NSS_STATUS_SUCCESS, *herrnop); + + return retval; +} + +enum nss_status _nss_ldap_setnetent(void) +{ + LOOKUP_SETENT (net_context); +} + +enum nss_status _nss_ldap_getnetent_r(struct netent *result,char *buffer,size_t buflen, + int *errnop,int *herrnop) +{ + enum nss_status status; + status = _nss_ldap_getent (&net_context, + result, + buffer, + buflen, + errnop, + _nss_ldap_filt_getnetent, + LM_NETWORKS, _nss_ldap_parse_net); + + MAP_H_ERRNO (status, *herrnop); + return status; +} + +enum nss_status _nss_ldap_endnetent(void) +{ + LOOKUP_ENDENT (net_context); +} diff --git a/server/networks.c b/server/networks.c deleted file mode 100644 index 959c531..0000000 --- a/server/networks.c +++ /dev/null @@ -1,200 +0,0 @@ -/* - Copyright (C) 1997-2005 Luke Howard - This file is part of the nss_ldap library. - Contributed by Luke Howard, , 1997. - - 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. - - The nss_ldap 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. - - $Id$ -*/ - -/* parts based on nss_nis */ - -#include "config.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#ifdef HAVE_LBER_H -#include -#endif -#ifdef HAVE_LDAP_H -#include -#endif -#if defined(HAVE_THREAD_H) -#include -#elif defined(HAVE_PTHREAD_H) -#include -#endif - -#include "ldap-nss.h" -#include "util.h" - -#if defined(HAVE_USERSEC_H) -#define MAXALIASES 35 -#define MAXADDRSIZE 4 -#endif /* HAVE_USERSEC_H */ - -static struct ent_context *net_context = NULL; - -static enum nss_status -_nss_ldap_parse_net (LDAPMessage * e, - struct ldap_state * pvt, - void *result, char *buffer, size_t buflen) -{ - - char *tmp; - struct netent *network = (struct netent *) result; - enum nss_status stat; - - /* IPv6 support ? XXX */ - network->n_addrtype = AF_INET; - - stat = _nss_ldap_assign_attrval (e, ATM (LM_NETWORKS, cn), &network->n_name, - &buffer, &buflen); - if (stat != NSS_STATUS_SUCCESS) - return stat; - - stat = - _nss_ldap_assign_attrval (e, AT (ipNetworkNumber), &tmp, &buffer, - &buflen); - if (stat != NSS_STATUS_SUCCESS) - return stat; - - network->n_net = inet_network (tmp); - - stat = - _nss_ldap_assign_attrvals (e, ATM (LM_NETWORKS, cn), network->n_name, - &network->n_aliases, &buffer, &buflen, NULL); - if (stat != NSS_STATUS_SUCCESS) - return stat; - - return NSS_STATUS_SUCCESS; -} - -enum nss_status _nss_ldap_getnetbyname_r(const char *name,struct netent *result, - char *buffer,size_t buflen,int *errnop, - int *herrnop) -{ - enum nss_status status; - struct ldap_args a; - - LA_INIT (a); - LA_STRING (a) = name; - LA_TYPE (a) = LA_TYPE_STRING; - - status = _nss_ldap_getbyname (&a, - result, - buffer, - buflen, - errnop, - _nss_ldap_filt_getnetbyname, - LM_NETWORKS, _nss_ldap_parse_net); - - MAP_H_ERRNO (status, *herrnop); - - return status; -} - -enum nss_status _nss_ldap_getnetbyaddr_r(unsigned long addr,int type, - struct netent *result,char *buffer,size_t buflen, - int *errnop,int *herrnop) -{ - struct in_addr in; - char buf[256]; - int blen; - struct ldap_args a; - enum nss_status retval = NSS_STATUS_NOTFOUND; - - LA_INIT (a); - LA_TYPE (a) = LA_TYPE_STRING; - - in = inet_makeaddr (addr, 0); - strcpy (buf, inet_ntoa (in)); - blen = strlen (buf); - LA_STRING (a) = buf; - - while (1) - { - retval = _nss_ldap_getbyname (&a, result, buffer, buflen, errnop, - _nss_ldap_filt_getnetbyaddr, - LM_NETWORKS, _nss_ldap_parse_net); - - if (retval != NSS_STATUS_SUCCESS) - { - if (retval == NSS_STATUS_NOTFOUND) - { - if (buf[blen - 2] == '.' && buf[blen - 1] == '\0') - { - buf[blen - 2] = '\0'; - blen -= 2; - continue; - } - else - { - MAP_H_ERRNO (retval, *herrnop); - return NSS_STATUS_NOTFOUND; - } - } - else - { - MAP_H_ERRNO (retval, *herrnop); - return retval; - } - } - else - { - /* retval == NSS_STATUS_SUCCESS */ - break; - } - } - - MAP_H_ERRNO (NSS_STATUS_SUCCESS, *herrnop); - - return retval; -} - -enum nss_status _nss_ldap_setnetent(void) -{ - LOOKUP_SETENT (net_context); -} - -enum nss_status _nss_ldap_getnetent_r(struct netent *result,char *buffer,size_t buflen, - int *errnop,int *herrnop) -{ - enum nss_status status; - status = _nss_ldap_getent (&net_context, - result, - buffer, - buflen, - errnop, - _nss_ldap_filt_getnetent, - LM_NETWORKS, _nss_ldap_parse_net); - - MAP_H_ERRNO (status, *herrnop); - return status; -} - -enum nss_status _nss_ldap_endnetent(void) -{ - LOOKUP_ENDENT (net_context); -} diff --git a/server/passwd.c b/server/passwd.c index 8b50dc3..da17a3a 100644 --- a/server/passwd.c +++ b/server/passwd.c @@ -1,5 +1,7 @@ /* passwd.c - password entry lookup routines + This file was part of the nss-ldap library (as ldap-pwd.c) + which has been forked into the nss-ldapd library. Copyright (C) 1997-2005 Luke Howard Copyright (C) 2006 West Consulting diff --git a/server/protocol.c b/server/protocol.c new file mode 100644 index 0000000..2300535 --- /dev/null +++ b/server/protocol.c @@ -0,0 +1,120 @@ +/* + protocol.c - network address entry lookup routines + This file was part of the nss-ldap library (as ldap-proto.c) + which has been forked into the nss-ldapd library. + + Copyright (C) 1997-2005 Luke Howard + 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 +*/ + +/* + Determine the canonical name of the RPC with _nss_ldap_getrdnvalue(), + and assign any values of "cn" which do NOT match this canonical name + as aliases. + */ + +#include "config.h" + +#include +#include +#include +#include +#include +#ifdef HAVE_LBER_H +#include +#endif +#ifdef HAVE_LDAP_H +#include +#endif +#if defined(HAVE_THREAD_H) +#include +#elif defined(HAVE_PTHREAD_H) +#include +#endif + +#include "ldap-nss.h" +#include "util.h" + +static struct ent_context *proto_context = NULL; + +static enum nss_status _nss_ldap_parse_proto (LDAPMessage *e, + struct ldap_state *pvt, + void *result, char *buffer, size_t buflen) +{ + + struct protoent *proto = (struct protoent *) result; + char *number; + enum nss_status stat; + + stat = + _nss_ldap_getrdnvalue (e, ATM (LM_PROTOCOLS, cn), &proto->p_name, + &buffer, &buflen); + if (stat != NSS_STATUS_SUCCESS) + return stat; + + stat = + _nss_ldap_assign_attrval (e, AT (ipProtocolNumber), &number, &buffer, + &buflen); + if (stat != NSS_STATUS_SUCCESS) + return stat; + + proto->p_proto = atoi (number); + + stat = + _nss_ldap_assign_attrvals (e, ATM (LM_PROTOCOLS, cn), proto->p_name, + &proto->p_aliases, &buffer, &buflen, NULL); + if (stat != NSS_STATUS_SUCCESS) + return stat; + + return NSS_STATUS_SUCCESS; +} + +enum nss_status _nss_ldap_getprotobyname_r(const char *name,struct protoent *result, + char *buffer,size_t buflen,int *errnop) +{ + LOOKUP_NAME (name, result, buffer, buflen, errnop, + _nss_ldap_filt_getprotobyname, LM_PROTOCOLS, + _nss_ldap_parse_proto, LDAP_NSS_BUFLEN_DEFAULT); +} + +enum nss_status _nss_ldap_getprotobynumber_r(int number,struct protoent *result, + char *buffer,size_t buflen,int *errnop) +{ + LOOKUP_NUMBER (number, result, buffer, buflen, errnop, + _nss_ldap_filt_getprotobynumber, LM_PROTOCOLS, + _nss_ldap_parse_proto, LDAP_NSS_BUFLEN_DEFAULT); +} + +enum nss_status _nss_ldap_setprotoent(void) +{ + LOOKUP_SETENT (proto_context); +} + +enum nss_status _nss_ldap_getprotoent_r(struct protoent *result,char *buffer,size_t buflen, + int *errnop) +{ + LOOKUP_GETENT (proto_context, result, buffer, buflen, errnop, + _nss_ldap_filt_getprotoent, LM_PROTOCOLS, + _nss_ldap_parse_proto, LDAP_NSS_BUFLEN_DEFAULT); +} + +enum nss_status _nss_ldap_endprotoent(void) +{ + LOOKUP_ENDENT (proto_context); +} diff --git a/server/protocols.c b/server/protocols.c deleted file mode 100644 index d601c40..0000000 --- a/server/protocols.c +++ /dev/null @@ -1,118 +0,0 @@ -/* - Copyright (C) 1997-2005 Luke Howard - This file is part of the nss_ldap library. - Contributed by Luke Howard, , 1997. - - 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. - - The nss_ldap 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. - - $Id$ -*/ - -/* - Determine the canonical name of the RPC with _nss_ldap_getrdnvalue(), - and assign any values of "cn" which do NOT match this canonical name - as aliases. - */ - -#include "config.h" - -#include -#include -#include -#include -#include -#ifdef HAVE_LBER_H -#include -#endif -#ifdef HAVE_LDAP_H -#include -#endif -#if defined(HAVE_THREAD_H) -#include -#elif defined(HAVE_PTHREAD_H) -#include -#endif - -#include "ldap-nss.h" -#include "util.h" - -static struct ent_context *proto_context = NULL; - -static enum nss_status _nss_ldap_parse_proto (LDAPMessage *e, - struct ldap_state *pvt, - void *result, char *buffer, size_t buflen) -{ - - struct protoent *proto = (struct protoent *) result; - char *number; - enum nss_status stat; - - stat = - _nss_ldap_getrdnvalue (e, ATM (LM_PROTOCOLS, cn), &proto->p_name, - &buffer, &buflen); - if (stat != NSS_STATUS_SUCCESS) - return stat; - - stat = - _nss_ldap_assign_attrval (e, AT (ipProtocolNumber), &number, &buffer, - &buflen); - if (stat != NSS_STATUS_SUCCESS) - return stat; - - proto->p_proto = atoi (number); - - stat = - _nss_ldap_assign_attrvals (e, ATM (LM_PROTOCOLS, cn), proto->p_name, - &proto->p_aliases, &buffer, &buflen, NULL); - if (stat != NSS_STATUS_SUCCESS) - return stat; - - return NSS_STATUS_SUCCESS; -} - -enum nss_status _nss_ldap_getprotobyname_r(const char *name,struct protoent *result, - char *buffer,size_t buflen,int *errnop) -{ - LOOKUP_NAME (name, result, buffer, buflen, errnop, - _nss_ldap_filt_getprotobyname, LM_PROTOCOLS, - _nss_ldap_parse_proto, LDAP_NSS_BUFLEN_DEFAULT); -} - -enum nss_status _nss_ldap_getprotobynumber_r(int number,struct protoent *result, - char *buffer,size_t buflen,int *errnop) -{ - LOOKUP_NUMBER (number, result, buffer, buflen, errnop, - _nss_ldap_filt_getprotobynumber, LM_PROTOCOLS, - _nss_ldap_parse_proto, LDAP_NSS_BUFLEN_DEFAULT); -} - -enum nss_status _nss_ldap_setprotoent(void) -{ - LOOKUP_SETENT (proto_context); -} - -enum nss_status _nss_ldap_getprotoent_r(struct protoent *result,char *buffer,size_t buflen, - int *errnop) -{ - LOOKUP_GETENT (proto_context, result, buffer, buflen, errnop, - _nss_ldap_filt_getprotoent, LM_PROTOCOLS, - _nss_ldap_parse_proto, LDAP_NSS_BUFLEN_DEFAULT); -} - -enum nss_status _nss_ldap_endprotoent(void) -{ - LOOKUP_ENDENT (proto_context); -} diff --git a/server/rpc.c b/server/rpc.c index 3a12026..2f33f1c 100644 --- a/server/rpc.c +++ b/server/rpc.c @@ -1,24 +1,26 @@ /* + rpc.c - rpc name lookup routines + This file was part of the nss-ldap library (as ldap-rpc.c) which + has been forked into the nss-ldapd library. + Copyright (C) 1997-2005 Luke Howard - This file is part of the nss_ldap library. - Contributed by Luke Howard, , 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. - - $Id$ + License along with this library; if not, write to the Free + Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, + MA 02110-1301 USA */ /* diff --git a/server/service.c b/server/service.c new file mode 100644 index 0000000..8e3d49f --- /dev/null +++ b/server/service.c @@ -0,0 +1,227 @@ +/* + service.c - service entry lookup routines + This file was part of the nss-ldap library (as ldap-service.c) + which has been forked into the nss-ldapd library. + + Copyright (C) 1997-2005 Luke Howard + 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 +*/ + +/* + Determine the canonical name of the RPC with _nss_ldap_getrdnvalue(), + and assign any values of "cn" which do NOT match this canonical name + as aliases. + */ + +#include "config.h" + +#include +#include +#include +#include +#include +#include +#ifdef HAVE_SYS_BYTEORDER_H +#include +#endif +#ifdef HAVE_LBER_H +#include +#endif +#ifdef HAVE_LDAP_H +#include +#endif +#if defined(HAVE_THREAD_H) +#include +#elif defined(HAVE_PTHREAD_H) +#include +#endif + +#include "ldap-nss.h" +#include "util.h" + +static struct ent_context *serv_context = NULL; + +static enum nss_status _nss_ldap_parse_serv (LDAPMessage *e, + struct ldap_state *state, + void *result,char *buffer,size_t buflen) +{ + struct servent *service = (struct servent *)result; + char *port; + enum nss_status stat = NSS_STATUS_SUCCESS; + + /* this is complicated and ugly, because some git (me) specified that service + * entries should expand to two entities (or more) if they have multi-valued + * ipServiceProtocol fields. + */ + + if (state->ls_type == LS_TYPE_KEY) + { + if (state->ls_info.ls_key == NULL) + { + /* non-deterministic behaviour is ok */ + stat = + _nss_ldap_assign_attrval (e, AT (ipServiceProtocol), + &service->s_proto, &buffer, &buflen); + if (stat != NSS_STATUS_SUCCESS) + { + return stat; + } + } + else + { + register int len; + len = strlen (state->ls_info.ls_key); + if (buflen < (size_t) (len + 1)) + { + return NSS_STATUS_TRYAGAIN; + } + strncpy (buffer, state->ls_info.ls_key, len); + buffer[len] = '\0'; + service->s_proto = buffer; + buffer += len + 1; + buflen -= len + 1; + } + } + else + { + char **vals = _nss_ldap_get_values (e, AT (ipServiceProtocol)); + int len; + if (vals == NULL) + { + state->ls_info.ls_index = -1; + return NSS_STATUS_NOTFOUND; + } + + switch (state->ls_info.ls_index) + { + case 0: + /* last time. decrementing ls_index to -1 AND returning !NSS_STATUS_SUCCESS + will force this entry to be discarded. + */ + stat = NSS_STATUS_NOTFOUND; + break; + case -1: + /* first time */ + state->ls_info.ls_index = ldap_count_values (vals); + /* fall off to default ... */ + default: + len = strlen (vals[state->ls_info.ls_index - 1]); + if (buflen < (size_t) (len + 1)) + { + return NSS_STATUS_TRYAGAIN; + } + strncpy (buffer, vals[state->ls_info.ls_index - 1], len); + buffer[len] = '\0'; + service->s_proto = buffer; + buffer += len + 1; + buflen -= len + 1; + stat = NSS_STATUS_SUCCESS; + } + + ldap_value_free (vals); + state->ls_info.ls_index--; + } + + if (stat != NSS_STATUS_SUCCESS) + { + return stat; + } + + stat = + _nss_ldap_getrdnvalue (e, ATM (LM_SERVICES, cn), &service->s_name, + &buffer, &buflen); + if (stat != NSS_STATUS_SUCCESS) + { + return stat; + } + + stat = + _nss_ldap_assign_attrvals (e, ATM (LM_SERVICES, cn), service->s_name, + &service->s_aliases, &buffer, &buflen, NULL); + if (stat != NSS_STATUS_SUCCESS) + { + return stat; + } + + stat = + _nss_ldap_assign_attrval (e, AT (ipServicePort), &port, &buffer, + &buflen); + if (stat != NSS_STATUS_SUCCESS) + { + return stat; + } + + service->s_port = htons (atoi (port)); + + return NSS_STATUS_SUCCESS; +} + +enum nss_status _nss_ldap_getservbyname_r(const char *name, + const char *proto, + struct servent *result, + char *buffer,size_t buflen,int *errnop) +{ + struct ldap_args a; + + LA_INIT (a); + LA_STRING (a) = name; + LA_TYPE (a) = (proto == NULL) ? LA_TYPE_STRING : LA_TYPE_STRING_AND_STRING; + LA_STRING2 (a) = proto; + + return _nss_ldap_getbyname (&a, result, buffer, buflen, errnop, + ((proto == NULL) ? _nss_ldap_filt_getservbyname + : _nss_ldap_filt_getservbynameproto), + LM_SERVICES, _nss_ldap_parse_serv); +} + +enum nss_status _nss_ldap_getservbyport_r(int port, + const char *proto, + struct servent *result, + char *buffer,size_t buflen,int *errnop) +{ + struct ldap_args a; + + LA_INIT (a); + LA_NUMBER (a) = htons (port); + LA_TYPE (a) = (proto == NULL) ? LA_TYPE_NUMBER : LA_TYPE_NUMBER_AND_STRING; + LA_STRING2 (a) = proto; + return _nss_ldap_getbyname (&a, result, buffer, buflen, errnop, + (proto == + NULL) ? _nss_ldap_filt_getservbyport : + _nss_ldap_filt_getservbyportproto, + LM_SERVICES, _nss_ldap_parse_serv); +} + +enum nss_status _nss_ldap_setservent(void) +{ + LOOKUP_SETENT(serv_context); +} + +enum nss_status _nss_ldap_getservent_r(struct servent *result,char *buffer,size_t buflen, + int *errnop) +{ + LOOKUP_GETENT(serv_context, result, buffer, buflen, errnop, + _nss_ldap_filt_getservent, LM_SERVICES, + _nss_ldap_parse_serv, LDAP_NSS_BUFLEN_DEFAULT); +} + +enum nss_status _nss_ldap_endservent(void) +{ + LOOKUP_ENDENT(serv_context); +} diff --git a/server/services.c b/server/services.c deleted file mode 100644 index ffe9b62..0000000 --- a/server/services.c +++ /dev/null @@ -1,225 +0,0 @@ -/* - Copyright (C) 1997-2005 Luke Howard - This file is part of the nss_ldap library. - Contributed by Luke Howard, , 1997. - - 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. - - The nss_ldap 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. - - $Id$ -*/ - -/* - Determine the canonical name of the RPC with _nss_ldap_getrdnvalue(), - and assign any values of "cn" which do NOT match this canonical name - as aliases. - */ - -#include "config.h" - -#include -#include -#include -#include -#include -#include -#ifdef HAVE_SYS_BYTEORDER_H -#include -#endif -#ifdef HAVE_LBER_H -#include -#endif -#ifdef HAVE_LDAP_H -#include -#endif -#if defined(HAVE_THREAD_H) -#include -#elif defined(HAVE_PTHREAD_H) -#include -#endif - -#include "ldap-nss.h" -#include "util.h" - -static struct ent_context *serv_context = NULL; - -static enum nss_status _nss_ldap_parse_serv (LDAPMessage *e, - struct ldap_state *state, - void *result,char *buffer,size_t buflen) -{ - struct servent *service = (struct servent *)result; - char *port; - enum nss_status stat = NSS_STATUS_SUCCESS; - - /* this is complicated and ugly, because some git (me) specified that service - * entries should expand to two entities (or more) if they have multi-valued - * ipServiceProtocol fields. - */ - - if (state->ls_type == LS_TYPE_KEY) - { - if (state->ls_info.ls_key == NULL) - { - /* non-deterministic behaviour is ok */ - stat = - _nss_ldap_assign_attrval (e, AT (ipServiceProtocol), - &service->s_proto, &buffer, &buflen); - if (stat != NSS_STATUS_SUCCESS) - { - return stat; - } - } - else - { - register int len; - len = strlen (state->ls_info.ls_key); - if (buflen < (size_t) (len + 1)) - { - return NSS_STATUS_TRYAGAIN; - } - strncpy (buffer, state->ls_info.ls_key, len); - buffer[len] = '\0'; - service->s_proto = buffer; - buffer += len + 1; - buflen -= len + 1; - } - } - else - { - char **vals = _nss_ldap_get_values (e, AT (ipServiceProtocol)); - int len; - if (vals == NULL) - { - state->ls_info.ls_index = -1; - return NSS_STATUS_NOTFOUND; - } - - switch (state->ls_info.ls_index) - { - case 0: - /* last time. decrementing ls_index to -1 AND returning !NSS_STATUS_SUCCESS - will force this entry to be discarded. - */ - stat = NSS_STATUS_NOTFOUND; - break; - case -1: - /* first time */ - state->ls_info.ls_index = ldap_count_values (vals); - /* fall off to default ... */ - default: - len = strlen (vals[state->ls_info.ls_index - 1]); - if (buflen < (size_t) (len + 1)) - { - return NSS_STATUS_TRYAGAIN; - } - strncpy (buffer, vals[state->ls_info.ls_index - 1], len); - buffer[len] = '\0'; - service->s_proto = buffer; - buffer += len + 1; - buflen -= len + 1; - stat = NSS_STATUS_SUCCESS; - } - - ldap_value_free (vals); - state->ls_info.ls_index--; - } - - if (stat != NSS_STATUS_SUCCESS) - { - return stat; - } - - stat = - _nss_ldap_getrdnvalue (e, ATM (LM_SERVICES, cn), &service->s_name, - &buffer, &buflen); - if (stat != NSS_STATUS_SUCCESS) - { - return stat; - } - - stat = - _nss_ldap_assign_attrvals (e, ATM (LM_SERVICES, cn), service->s_name, - &service->s_aliases, &buffer, &buflen, NULL); - if (stat != NSS_STATUS_SUCCESS) - { - return stat; - } - - stat = - _nss_ldap_assign_attrval (e, AT (ipServicePort), &port, &buffer, - &buflen); - if (stat != NSS_STATUS_SUCCESS) - { - return stat; - } - - service->s_port = htons (atoi (port)); - - return NSS_STATUS_SUCCESS; -} - -enum nss_status _nss_ldap_getservbyname_r(const char *name, - const char *proto, - struct servent *result, - char *buffer,size_t buflen,int *errnop) -{ - struct ldap_args a; - - LA_INIT (a); - LA_STRING (a) = name; - LA_TYPE (a) = (proto == NULL) ? LA_TYPE_STRING : LA_TYPE_STRING_AND_STRING; - LA_STRING2 (a) = proto; - - return _nss_ldap_getbyname (&a, result, buffer, buflen, errnop, - ((proto == NULL) ? _nss_ldap_filt_getservbyname - : _nss_ldap_filt_getservbynameproto), - LM_SERVICES, _nss_ldap_parse_serv); -} - -enum nss_status _nss_ldap_getservbyport_r(int port, - const char *proto, - struct servent *result, - char *buffer,size_t buflen,int *errnop) -{ - struct ldap_args a; - - LA_INIT (a); - LA_NUMBER (a) = htons (port); - LA_TYPE (a) = (proto == NULL) ? LA_TYPE_NUMBER : LA_TYPE_NUMBER_AND_STRING; - LA_STRING2 (a) = proto; - return _nss_ldap_getbyname (&a, result, buffer, buflen, errnop, - (proto == - NULL) ? _nss_ldap_filt_getservbyport : - _nss_ldap_filt_getservbyportproto, - LM_SERVICES, _nss_ldap_parse_serv); -} - -enum nss_status _nss_ldap_setservent(void) -{ - LOOKUP_SETENT(serv_context); -} - -enum nss_status _nss_ldap_getservent_r(struct servent *result,char *buffer,size_t buflen, - int *errnop) -{ - LOOKUP_GETENT(serv_context, result, buffer, buflen, errnop, - _nss_ldap_filt_getservent, LM_SERVICES, - _nss_ldap_parse_serv, LDAP_NSS_BUFLEN_DEFAULT); -} - -enum nss_status _nss_ldap_endservent(void) -{ - LOOKUP_ENDENT(serv_context); -} diff --git a/server/shadow.c b/server/shadow.c index 5319ade..7a2e407 100644 --- a/server/shadow.c +++ b/server/shadow.c @@ -1,24 +1,26 @@ /* + shadow.c - service entry lookup routines + This file was part of the nss-ldap library (as ldap-spwd.c) which + has been forked into the nss-ldapd library. + Copyright (C) 1997-2005 Luke Howard - This file is part of the nss_ldap library. - Contributed by Luke Howard, , 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. - - $Id$ + 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" diff --git a/server/util.c b/server/util.c index e2888f6..6372c1f 100644 --- a/server/util.c +++ b/server/util.c @@ -1,24 +1,26 @@ /* + util.c - LDAP utility functions + This file was part of the nss-ldap library which has been + forked into the nss-ldapd library. + Copyright (C) 1997-2005 Luke Howard - This file is part of the nss_ldap library. - Contributed by Luke Howard, , 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. - - $Id$ + 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" diff --git a/server/util.h b/server/util.h index 1a90b52..77c6487 100644 --- a/server/util.h +++ b/server/util.h @@ -1,24 +1,26 @@ /* + util.h - LDAP utility functions + This file was part of the nss-ldap library which has been + forked into the nss-ldapd library. + Copyright (C) 1997-2005 Luke Howard - This file is part of the nss_ldap library. - Contributed by Luke Howard, , 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. - - $Id$ + 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 _LDAP_NSS_LDAP_UTIL_H -- cgit v1.2.3-54-g00ecf