Removed unneeded libbind files (were never compiled, anyway).

Moved some headers around and cleaned them up.

Fixed threading code in libbind.so. Don't know why I hadn't noticed this before. Now it is reliable, but uses an even uglier hack.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@15585 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Waldemar Kornewald 2005-12-19 13:26:54 +00:00
parent 39cc80346c
commit f7a223fa1b
49 changed files with 145 additions and 7578 deletions

View File

@ -1,132 +0,0 @@
/*
* ++Copyright++ 1983, 1993
* -
* Copyright (c) 1983, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* -
* Portions Copyright (c) 1993 by Digital Equipment Corporation.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies, and that
* the name of Digital Equipment Corporation not be used in advertising or
* publicity pertaining to distribution of the document or software without
* specific, written prior permission.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
* WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
* CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
* SOFTWARE.
* -
* --Copyright--
*/
/*
* @(#)inet.h 8.1 (Berkeley) 6/2/93
* $Id$
*/
#ifndef _INET_H_
#define _INET_H_
/* External definitions for functions in inet(3) */
#include <sys/param.h>
#if (!defined(BSD)) || (BSD < 199306)
# include <sys/bitypes.h>
#else
# include <sys/types.h>
#endif
#include <sys/cdefs.h>
#define inet_addr __inet_addr
#define inet_aton __inet_aton
#define inet_lnaof __inet_lnaof
#define inet_makeaddr __inet_makeaddr
#define inet_neta __inet_neta
#define inet_netof __inet_netof
#define inet_network __inet_network
#define inet_net_ntop __inet_net_ntop
#define inet_net_pton __inet_net_pton
#define inet_cidr_ntop __inet_cidr_ntop
#define inet_cidr_pton __inet_cidr_pton
#define inet_ntoa __inet_ntoa
#define inet_pton __inet_pton
#define inet_ntop __inet_ntop
#define inet_nsap_addr __inet_nsap_addr
#define inet_nsap_ntoa __inet_nsap_ntoa
#ifdef __cplusplus
extern "C" {
#endif
__BEGIN_DECLS
unsigned long inet_addr __P((const char *));
int inet_aton __P((const char *, struct in_addr *));
unsigned long inet_lnaof __P((struct in_addr));
struct in_addr inet_makeaddr __P((u_long , u_long));
char * inet_neta __P((u_long, char *, size_t));
unsigned long inet_netof __P((struct in_addr));
unsigned long inet_network __P((const char *));
char *inet_net_ntop __P((int, const void *, int, char *, size_t));
int inet_net_pton __P((int, const char *, void *, size_t));
char *inet_cidr_ntop __P((int, const void *, int, char *, size_t));
int inet_cidr_pton __P((int, const char *, void *, int *));
/*const*/ char *inet_ntoa __P((struct in_addr));
int inet_pton __P((int, const char *, void *));
const char *inet_ntop __P((int, const void *, char *, size_t));
u_int inet_nsap_addr __P((const char *, u_char *, int));
char *inet_nsap_ntoa __P((int, const u_char *, char *));
__END_DECLS
#ifdef __cplusplus
}
#endif
#if defined(__hpux) && defined(_XOPEN_SOURCE_EXTENDED)
/*
* Macros for number representation conversion.
*
* netinet/in.h is another location for these macros
*/
#ifndef ntohl
#define ntohl(x) (x)
#define ntohs(x) (x)
#define htonl(x) (x)
#define htons(x) (x)
#endif
#endif
#endif /* !_INET_H_ */

View File

@ -1,552 +0,0 @@
/*
* ++Copyright++ 1980, 1983, 1988, 1993
* -
* Copyright (c) 1980, 1983, 1988, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* -
* Portions Copyright (c) 1993 by Digital Equipment Corporation.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies, and that
* the name of Digital Equipment Corporation not be used in advertising or
* publicity pertaining to distribution of the document or software without
* specific, written prior permission.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
* WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
* CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
* SOFTWARE.
* -
* Portions Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by WIDE Project and
* its contributors.
* 4. Neither the name of the project nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* -
* --Copyright--
*/
/*
* @(#)netdb.h 8.1 (Berkeley) 6/2/93
* $Id$
*/
#ifndef _NETDB_H_
#define _NETDB_H_
#include <sys/param.h>
#include <sys/types.h>
#if (!defined(BSD)) || (BSD < 199306)
# include <sys/bitypes.h>
#endif
#include <sys/cdefs.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <stdio.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifndef _PATH_HEQUIV
#define _PATH_HEQUIV "/etc/hosts.equiv"
#endif
#ifndef _PATH_HOSTS
#define _PATH_HOSTS "/etc/hosts"
#endif
#ifndef _PATH_NETWORKS
#define _PATH_NETWORKS "/etc/networks"
#endif
#ifndef _PATH_PROTOCOLS
#define _PATH_PROTOCOLS "/etc/protocols"
#endif
#ifndef _PATH_SERVICES
#define _PATH_SERVICES "/etc/services"
#endif
#if (__GLIBC__ > 2 || __GLIBC__ == 2 && __GLIBC_MINOR__ >= 3)
#define __h_errno __h_errno_location
#endif
__BEGIN_DECLS
extern int * __h_errno __P((void));
__END_DECLS
#define h_errno (*__h_errno())
/*
* Structures returned by network data base library. All addresses are
* supplied in host order, and returned in network order (suitable for
* use in system calls).
*/
struct hostent {
char *h_name; /* official name of host */
char **h_aliases; /* alias list */
int h_addrtype; /* host address type */
int h_length; /* length of address */
char **h_addr_list; /* list of addresses from name server */
#define h_addr h_addr_list[0] /* address, for backward compatiblity */
};
/*
* Assumption here is that a network number
* fits in an unsigned long -- probably a poor one.
*/
struct netent {
char *n_name; /* official name of net */
char **n_aliases; /* alias list */
int n_addrtype; /* net address type */
unsigned long n_net; /* network # */
};
struct servent {
char *s_name; /* official service name */
char **s_aliases; /* alias list */
int s_port; /* port # */
char *s_proto; /* protocol to use */
};
struct protoent {
char *p_name; /* official protocol name */
char **p_aliases; /* alias list */
int p_proto; /* protocol # */
};
struct addrinfo {
int ai_flags; /* AI_PASSIVE, AI_CANONNAME */
int ai_family; /* PF_xxx */
int ai_socktype; /* SOCK_xxx */
int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */
#if defined(sun) && defined(_SOCKLEN_T)
#ifdef __sparc9
int _ai_pad;
#endif
socklen_t ai_addrlen;
#else
size_t ai_addrlen; /* length of ai_addr */
#endif
#ifdef __linux
struct sockaddr *ai_addr; /* binary address */
char *ai_canonname; /* canonical name for hostname */
#else
char *ai_canonname; /* canonical name for hostname */
struct sockaddr *ai_addr; /* binary address */
#endif
struct addrinfo *ai_next; /* next structure in linked list */
};
/*
* Error return codes from gethostbyname() and gethostbyaddr()
* (left in extern int h_errno).
*/
#define NETDB_INTERNAL -1 /* see errno */
#define NETDB_SUCCESS 0 /* no problem */
#define HOST_NOT_FOUND 1 /* Authoritative Answer Host not found */
#define TRY_AGAIN 2 /* Non-Authoritive Host not found, or SERVERFAIL */
#define NO_RECOVERY 3 /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */
#define NO_DATA 4 /* Valid name, no data record of requested type */
#define NO_ADDRESS NO_DATA /* no address, look for MX record */
/*
* Error return codes from getaddrinfo()
*/
#define EAI_ADDRFAMILY 1 /* address family for hostname not supported */
#define EAI_AGAIN 2 /* temporary failure in name resolution */
#define EAI_BADFLAGS 3 /* invalid value for ai_flags */
#define EAI_FAIL 4 /* non-recoverable failure in name resolution */
#define EAI_FAMILY 5 /* ai_family not supported */
#define EAI_MEMORY 6 /* memory allocation failure */
#define EAI_NODATA 7 /* no address associated with hostname */
#define EAI_NONAME 8 /* hostname nor servname provided, or not known */
#define EAI_SERVICE 9 /* servname not supported for ai_socktype */
#define EAI_SOCKTYPE 10 /* ai_socktype not supported */
#define EAI_SYSTEM 11 /* system error returned in errno */
#define EAI_BADHINTS 12
#define EAI_PROTOCOL 13
#define EAI_MAX 14
/*
* Flag values for getaddrinfo()
*/
#define AI_PASSIVE 0x00000001
#define AI_CANONNAME 0x00000002
#define AI_NUMERICHOST 0x00000004
#define AI_MASK 0x00000007
/*
* Flag values for getipnodebyname()
*/
#define AI_V4MAPPED 0x00000008
#define AI_ALL 0x00000010
#define AI_ADDRCONFIG 0x00000020
#define AI_DEFAULT (AI_V4MAPPED|AI_ADDRCONFIG)
/*
* Constants for getnameinfo()
*/
#define NI_MAXHOST 1025
#define NI_MAXSERV 32
/*
* Flag values for getnameinfo()
*/
#define NI_NOFQDN 0x00000001
#define NI_NUMERICHOST 0x00000002
#define NI_NAMEREQD 0x00000004
#define NI_NUMERICSERV 0x00000008
#define NI_DGRAM 0x00000010
#define NI_WITHSCOPEID 0x00000020
#define NI_NUMERICSCOPE 0x00000040
/*
* Scope delimit character
*/
#define SCOPE_DELIMITER '%'
#if defined (__hpux) || defined(__osf__) || defined(_AIX)
#define _MAXALIASES 35
#define _MAXLINELEN 1024
#define _MAXADDRS 35
#define _HOSTBUFSIZE (BUFSIZ + 1)
struct hostent_data {
struct in_addr host_addr;
char *h_addr_ptrs[_MAXADDRS + 1];
char hostaddr[_MAXADDRS];
char hostbuf[_HOSTBUFSIZE];
char *host_aliases[_MAXALIASES];
char *host_addrs[2];
FILE *hostf;
#ifdef __osf__
int svc_gethostflag;
int svc_gethostbind;
#endif
#ifdef __hpux
short _nsw_src;
short _flags;
char *current;
int currentlen;
#endif
};
struct netent_data {
FILE *net_fp;
#ifdef __osf__
char line[_MAXLINELEN];
#endif
#ifdef __hpux
char line[_MAXLINELEN+1];
#endif
char *net_aliases[_MAXALIASES];
#ifdef __osf__
int _net_stayopen;
int svc_getnetflag;
#endif
#ifdef __hpux
short _nsw_src;
short _flags;
char *current;
int currentlen;
#endif
};
struct protoent_data {
FILE *proto_fp;
#ifdef __osf__
char line[1024];
#endif
#ifdef __hpux
char line[_MAXLINELEN+1];
#endif
char *proto_aliases[_MAXALIASES];
#ifdef __osf__
int _proto_stayopen;
int svc_getprotoflag;
#endif
#ifdef __hpux
short _nsw_src;
short _flags;
char *current;
int currentlen;
#endif
};
struct servent_data {
FILE *serv_fp;
#ifdef __osf__
char line[_MAXLINELEN];
#endif
#ifdef __hpux
char line[_MAXLINELEN+1];
#endif
char *serv_aliases[_MAXALIASES];
#ifdef __osf__
int _serv_stayopen;
int svc_getservflag;
#endif
#ifdef __hpux
short _nsw_src;
short _flags;
char *current;
int currentlen;
#endif
};
#endif
__BEGIN_DECLS
void endhostent __P((void));
void endnetent __P((void));
void endprotoent __P((void));
void endservent __P((void));
void freehostent __P((struct hostent *));
struct hostent *gethostbyaddr __P((const char *, int, int));
struct hostent *gethostbyname __P((const char *));
struct hostent *gethostbyname2 __P((const char *, int));
struct hostent *gethostent __P((void));
struct hostent *getipnodebyaddr __P((const void *, size_t, int, int *));
struct hostent *getipnodebyname __P((const char *, int, int, int *));
struct netent *getnetbyaddr __P((unsigned long, int));
struct netent *getnetbyname __P((const char *));
struct netent *getnetent __P((void));
struct protoent *getprotobyname __P((const char *));
struct protoent *getprotobynumber __P((int));
struct protoent *getprotoent __P((void));
struct servent *getservbyname __P((const char *, const char *));
struct servent *getservbyport __P((int, const char *));
struct servent *getservent __P((void));
void herror __P((const char *));
const char *hstrerror __P((int));
void sethostent __P((int));
/* void sethostfile __P((const char *)); */
void setnetent __P((int));
void setprotoent __P((int));
void setservent __P((int));
int getaddrinfo __P((const char *, const char *,
const struct addrinfo *, struct addrinfo **));
int getnameinfo __P((const struct sockaddr *, size_t, char *,
size_t, char *, size_t, int));
void freeaddrinfo __P((struct addrinfo *));
const char *gai_strerror __P((int));
struct hostent *getipnodebyname __P((const char *, int, int, int *));
struct hostent *getipnodebyaddr __P((const void *, size_t, int, int *));
void freehostent __P((struct hostent *));
#ifdef __GLIBC__
int getnetgrent __P((/* const */ char **, /* const */ char **,
/* const */ char **));
void setnetgrent __P((const char *));
void endnetgrent __P((void));
int innetgr __P((const char *, const char *, const char *,
const char *));
#endif
#if defined(__hpux) || defined(__osf__) || defined(_AIX)
int gethostbyaddr_r __P((const char *, int, int, struct hostent *,
struct hostent_data *));
int gethostbyname_r __P((const char *, struct hostent *,
struct hostent_data *));
int gethostent_r __P((struct hostent *, struct hostent_data *));
#if defined(_AIX)
void sethostent_r __P((int, struct hostent_data *));
#else
int sethostent_r __P((int, struct hostent_data *));
#endif
#if defined(__hpux)
int endhostent_r __P((struct hostent_data *));
#else
void endhostent_r __P((struct hostent_data *));
#endif
#if defined(__hpux) || defined(__osf__)
int getnetbyaddr_r __P((int, int,
struct netent *, struct netent_data *));
#else
int getnetbyaddr_r __P((long, int,
struct netent *, struct netent_data *));
#endif
int getnetbyname_r __P((const char *,
struct netent *, struct netent_data *));
int getnetent_r __P((struct netent *, struct netent_data *));
int setnetent_r __P((int, struct netent_data *));
#ifdef __hpux
int endnetent_r __P((struct netent_data *buffer));
#else
void endnetent_r __P((struct netent_data *buffer));
#endif
int getprotobyname_r __P((const char *,
struct protoent *, struct protoent_data *));
int getprotobynumber_r __P((int,
struct protoent *, struct protoent_data *));
int getprotoent_r __P((struct protoent *, struct protoent_data *));
int setprotoent_r __P((int, struct protoent_data *));
#ifdef __hpux
int endprotoent_r __P((struct protoent_data *));
#else
void endprotoent_r __P((struct protoent_data *));
#endif
int getservbyname_r __P((const char *, const char *,
struct servent *, struct servent_data *));
int getservbyport_r __P((int, const char *,
struct servent *, struct servent_data *));
int getservent_r __P((struct servent *, struct servent_data *));
int setservent_r __P((int, struct servent_data *));
#ifdef __hpux
int endservent_r __P((struct servent_data *));
#else
void endservent_r __P((struct servent_data *));
#endif
#else
/* defined(sun) || defined(bsdi) */
#ifdef __GLIBC__
int gethostbyaddr_r __P((const char *, int, int, struct hostent *,
char *, size_t, struct hostent **, int *));
int gethostbyname_r __P((const char *, struct hostent *,
char *, size_t, struct hostent **, int *));
int gethostent_r __P((struct hostent *, char *, size_t,
struct hostent **, int *));
#else
struct hostent *gethostbyaddr_r __P((const char *, int, int, struct hostent *,
char *, int, int *));
struct hostent *gethostbyname_r __P((const char *, struct hostent *,
char *, int, int *));
struct hostent *gethostent_r __P((struct hostent *, char *, int, int *));
#endif
void sethostent_r __P((int));
void endhostent_r __P((void));
#ifdef __GLIBC__
int getnetbyname_r __P((const char *, struct netent *,
char *, size_t, struct netent **, int*));
int getnetbyaddr_r __P((unsigned long int, int, struct netent *,
char *, size_t, struct netent **, int*));
int getnetent_r __P((struct netent *, char *, size_t, struct netent **, int*));
#else
struct netent *getnetbyname_r __P((const char *, struct netent *,
char *, int));
struct netent *getnetbyaddr_r __P((long, int, struct netent *,
char *, int));
struct netent *getnetent_r __P((struct netent *, char *, int));
#endif
void setnetent_r __P((int));
void endnetent_r __P((void));
#ifdef __GLIBC__
int getprotobyname_r __P((const char *, struct protoent *, char *,
size_t, struct protoent **));
int getprotobynumber_r __P((int, struct protoent *, char *, size_t,
struct protoent **));
int getprotoent_r __P((struct protoent *, char *, size_t, struct protoent **));
#else
struct protoent *getprotobyname_r __P((const char *,
struct protoent *, char *, int));
struct protoent *getprotobynumber_r __P((int,
struct protoent *, char *, int));
struct protoent *getprotoent_r __P((struct protoent *, char *, int));
#endif
void setprotoent_r __P((int));
void endprotoent_r __P((void));
#ifdef __GLIBC__
int getservbyname_r __P((const char *name, const char *,
struct servent *, char *, size_t, struct servent **));
int getservbyport_r __P((int port, const char *,
struct servent *, char *, size_t, struct servent **));
int getservent_r __P((struct servent *, char *, size_t, struct servent **));
#else
struct servent *getservbyname_r __P((const char *name, const char *,
struct servent *, char *, int));
struct servent *getservbyport_r __P((int port, const char *,
struct servent *, char *, int));
struct servent *getservent_r __P((struct servent *, char *, int));
#endif
void setservent_r __P((int));
void endservent_r __P((void));
#ifdef __GLIBC__
int getnetgrent_r __P((char **, char **, char **, char *, size_t));
#endif
#ifdef _AIX
int setnetgrent_r __P((char *, void **));
#endif
#endif
#ifdef __cplusplus
}
#endif
__END_DECLS
/* This is nec'y to make this include file properly replace the sun version. */
#ifdef sun
#ifdef __GNU_LIBRARY__
#include <rpc/netdb.h>
#else
struct rpcent {
char *r_name; /* name of server for this rpc program */
char **r_aliases; /* alias list */
int r_number; /* rpc program number */
};
struct rpcent *getrpcbyname(), *getrpcbynumber(), *getrpcent();
#endif /* __GNU_LIBRARY__ */
#endif /* sun */
#endif /* !_NETDB_H_ */

View File

@ -1,503 +0,0 @@
/*
* Copyright (c) 1983, 1987, 1989
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/*
* Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
* Portions Copyright (c) 1996-1999 by Internet Software Consortium.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/*
* @(#)resolv.h 8.1 (Berkeley) 6/2/93
* $Id$
*/
#ifndef _RESOLV_H_
#define _RESOLV_H_
#include <sys/param.h>
#if (!defined(BSD)) || (BSD < 199306)
# include <sys/bitypes.h>
#else
# include <sys/types.h>
#endif
#include <sys/cdefs.h>
#include <sys/socket.h>
#include <stdio.h>
#include <arpa/nameser.h>
#ifdef __cplusplus
extern "C" {
#endif
/*
* Revision information. This is the release date in YYYYMMDD format.
* It can change every day so the right thing to do with it is use it
* in preprocessor commands such as "#if (__RES > 19931104)". Do not
* compare for equality; rather, use it to determine whether your resolver
* is new enough to contain a certain feature.
*/
#define __RES 20030124
/*
* This used to be defined in res_query.c, now it's in herror.c.
* [XXX no it's not. It's in irs/irs_data.c]
* It was
* never extern'd by any *.h file before it was placed here. For thread
* aware programs, the last h_errno value set is stored in res->h_errno.
*
* XXX: There doesn't seem to be a good reason for exposing RES_SET_H_ERRNO
* (and __h_errno_set) to the public via <resolv.h>.
* XXX: __h_errno_set is really part of IRS, not part of the resolver.
* If somebody wants to build and use a resolver that doesn't use IRS,
* what do they do? Perhaps something like
* #ifdef WANT_IRS
* # define RES_SET_H_ERRNO(r,x) __h_errno_set(r,x)
* #else
* # define RES_SET_H_ERRNO(r,x) (h_errno = (r)->res_h_errno = (x))
* #endif
*/
#define RES_SET_H_ERRNO(r,x) __h_errno_set(r,x)
struct __res_state; /* forward */
__BEGIN_DECLS
void __h_errno_set(struct __res_state *res, int err);
__END_DECLS
/*
* Resolver configuration file.
* Normally not present, but may contain the address of the
* initial name server(s) to query and the domain search list.
*/
#ifndef _PATH_RESCONF
#define _PATH_RESCONF "/etc/resolv.conf"
#endif
typedef enum { res_goahead, res_nextns, res_modified, res_done, res_error }
res_sendhookact;
#ifndef __PMT
#if defined(__STDC__) || defined(__cplusplus)
#define __PMT(args) args
#else
#define __PMT(args) ()
#endif
#endif
typedef res_sendhookact (*res_send_qhook)__PMT((struct sockaddr * const *,
const u_char **, int *,
u_char *, int, int *));
typedef res_sendhookact (*res_send_rhook)__PMT((const struct sockaddr *,
const u_char *, int, u_char *,
int, int *));
struct res_sym {
int number; /* Identifying number, like T_MX */
const char * name; /* Its symbolic name, like "MX" */
const char * humanname; /* Its fun name, like "mail exchanger" */
};
/*
* Global defines and variables for resolver stub.
*/
#define MAXNS 3 /* max # name servers we'll track */
#define MAXDFLSRCH 3 /* # default domain levels to try */
#define MAXDNSRCH 6 /* max # domains in search path */
#define LOCALDOMAINPARTS 2 /* min levels in name that is "local" */
#define RES_TIMEOUT 5 /* min. seconds between retries */
#define MAXRESOLVSORT 10 /* number of net to sort on */
#define RES_MAXNDOTS 15 /* should reflect bit field size */
#define RES_MAXRETRANS 30 /* only for resolv.conf/RES_OPTIONS */
#define RES_MAXRETRY 5 /* only for resolv.conf/RES_OPTIONS */
#define RES_DFLRETRY 2 /* Default #/tries. */
#define RES_MAXTIME 65535 /* Infinity, in milliseconds. */
struct __res_state_ext;
struct __res_state {
int retrans; /* retransmission time interval */
int retry; /* number of times to retransmit */
#ifdef sun
u_int options; /* option flags - see below. */
#else
u_long options; /* option flags - see below. */
#endif
int nscount; /* number of name servers */
struct sockaddr_in
nsaddr_list[MAXNS]; /* address of name server */
#define nsaddr nsaddr_list[0] /* for backward compatibility */
u_short id; /* current message id */
char *dnsrch[MAXDNSRCH+1]; /* components of domain to search */
char defdname[256]; /* default domain (deprecated) */
#ifdef sun
u_int pfcode; /* RES_PRF_ flags - see below. */
#else
u_long pfcode; /* RES_PRF_ flags - see below. */
#endif
unsigned ndots:4; /* threshold for initial abs. query */
unsigned nsort:4; /* number of elements in sort_list[] */
char unused[3];
struct {
struct in_addr addr;
u_int32_t mask;
} sort_list[MAXRESOLVSORT];
res_send_qhook qhook; /* query hook */
res_send_rhook rhook; /* response hook */
int res_h_errno; /* last one set for this context */
int _vcsock; /* PRIVATE: for res_send VC i/o */
u_int _flags; /* PRIVATE: see below */
u_int _pad; /* make _u 64 bit aligned */
union {
/* On an 32-bit arch this means 512b total. */
char pad[72 - 4*sizeof (int) - 2*sizeof (void *)];
struct {
u_int16_t nscount;
u_int16_t nstimes[MAXNS]; /* ms. */
int nssocks[MAXNS];
struct __res_state_ext *ext; /* extention for IPv6 */
} _ext;
} _u;
};
typedef struct __res_state *res_state;
union res_sockaddr_union {
struct sockaddr_in sin;
#ifdef IN6ADDR_ANY_INIT
struct sockaddr_in6 sin6;
#endif
#ifdef ISC_ALIGN64
int64_t __align64; /* 64bit alignment */
#else
int32_t __align32; /* 32bit alignment */
#endif
char __space[128]; /* max size */
};
/*
* Resolver flags (used to be discrete per-module statics ints).
*/
#define RES_F_VC 0x00000001 /* socket is TCP */
#define RES_F_CONN 0x00000002 /* socket is connected */
#define RES_F_EDNS0ERR 0x00000004 /* EDNS0 caused errors */
#define RES_F__UNUSED 0x00000008 /* (unused) */
#define RES_F_LASTMASK 0x000000F0 /* ordinal server of last res_nsend */
#define RES_F_LASTSHIFT 4 /* bit position of LASTMASK "flag" */
#define RES_GETLAST(res) (((res)._flags & RES_F_LASTMASK) >> RES_F_LASTSHIFT)
/* res_findzonecut2() options */
#define RES_EXHAUSTIVE 0x00000001 /* always do all queries */
#define RES_IPV4ONLY 0x00000002 /* IPv4 only */
#define RES_IPV6ONLY 0x00000004 /* IPv6 only */
/*
* Resolver options (keep these in synch with res_debug.c, please)
*/
#define RES_INIT 0x00000001 /* address initialized */
#define RES_DEBUG 0x00000002 /* print debug messages */
#define RES_AAONLY 0x00000004 /* authoritative answers only (!IMPL)*/
#define RES_USEVC 0x00000008 /* use virtual circuit */
#define RES_PRIMARY 0x00000010 /* query primary server only (!IMPL) */
#define RES_IGNTC 0x00000020 /* ignore trucation errors */
#define RES_RECURSE 0x00000040 /* recursion desired */
#define RES_DEFNAMES 0x00000080 /* use default domain name */
#define RES_STAYOPEN 0x00000100 /* Keep TCP socket open */
#define RES_DNSRCH 0x00000200 /* search up local domain tree */
#define RES_INSECURE1 0x00000400 /* type 1 security disabled */
#define RES_INSECURE2 0x00000800 /* type 2 security disabled */
#define RES_NOALIASES 0x00001000 /* shuts off HOSTALIASES feature */
#define RES_USE_INET6 0x00002000 /* use/map IPv6 in gethostbyname() */
#define RES_ROTATE 0x00004000 /* rotate ns list after each query */
#define RES_NOCHECKNAME 0x00008000 /* do not check names for sanity. */
#define RES_KEEPTSIG 0x00010000 /* do not strip TSIG records */
#define RES_BLAST 0x00020000 /* blast all recursive servers */
#define RES_NOTLDQUERY 0x00100000 /* don't unqualified name as a tld */
#define RES_USE_DNSSEC 0x00200000 /* use DNSSEC using OK bit in OPT */
/* #define RES_DEBUG2 0x00400000 */ /* nslookup internal */
/* KAME extensions: use higher bit to avoid conflict with ISC use */
#define RES_USE_DNAME 0x10000000 /* use DNAME */
#define RES_USE_EDNS0 0x40000000 /* use EDNS0 if configured */
#define RES_NO_NIBBLE2 0x80000000 /* disable alternate nibble lookup */
#define RES_DEFAULT (RES_RECURSE | RES_DEFNAMES | \
RES_DNSRCH | RES_NO_NIBBLE2)
/*
* Resolver "pfcode" values. Used by dig.
*/
#define RES_PRF_STATS 0x00000001
#define RES_PRF_UPDATE 0x00000002
#define RES_PRF_CLASS 0x00000004
#define RES_PRF_CMD 0x00000008
#define RES_PRF_QUES 0x00000010
#define RES_PRF_ANS 0x00000020
#define RES_PRF_AUTH 0x00000040
#define RES_PRF_ADD 0x00000080
#define RES_PRF_HEAD1 0x00000100
#define RES_PRF_HEAD2 0x00000200
#define RES_PRF_TTLID 0x00000400
#define RES_PRF_HEADX 0x00000800
#define RES_PRF_QUERY 0x00001000
#define RES_PRF_REPLY 0x00002000
#define RES_PRF_INIT 0x00004000
#define RES_PRF_TRUNC 0x00008000
/* 0x00010000 */
/* Things involving an internal (static) resolver context. */
__BEGIN_DECLS
extern struct __res_state *__res_state(void);
__END_DECLS
#define _res (*__res_state())
#ifndef __BIND_NOSTATIC
#define fp_nquery __fp_nquery
#define fp_query __fp_query
#define hostalias __hostalias
#define p_query __p_query
#define res_close __res_close
#define res_init __res_init
#define res_isourserver __res_isourserver
#define res_mkquery __res_mkquery
#define res_query __res_query
#define res_querydomain __res_querydomain
#define res_search __res_search
#define res_send __res_send
#define res_sendsigned __res_sendsigned
__BEGIN_DECLS
void fp_nquery __P((const u_char *, int, FILE *));
void fp_query __P((const u_char *, FILE *));
const char * hostalias __P((const char *));
void p_query __P((const u_char *));
void res_close __P((void));
int res_init __P((void));
int res_isourserver __P((const struct sockaddr_in *));
int res_mkquery __P((int, const char *, int, int, const u_char *,
int, const u_char *, u_char *, int));
int res_query __P((const char *, int, int, u_char *, int));
int res_querydomain __P((const char *, const char *, int, int,
u_char *, int));
int res_search __P((const char *, int, int, u_char *, int));
int res_send __P((const u_char *, int, u_char *, int));
int res_sendsigned __P((const u_char *, int, ns_tsig_key *,
u_char *, int));
__END_DECLS
#endif
#if !defined(SHARED_LIBBIND) || defined(LIB)
/*
* If libbind is a shared object (well, DLL anyway)
* these externs break the linker when resolv.h is
* included by a lib client (like named)
* Make them go away if a client is including this
*
*/
extern const struct res_sym __p_key_syms[];
extern const struct res_sym __p_cert_syms[];
extern const struct res_sym __p_class_syms[];
extern const struct res_sym __p_type_syms[];
extern const struct res_sym __p_rcode_syms[];
#endif /* SHARED_LIBBIND */
#define b64_ntop __b64_ntop
#define b64_pton __b64_pton
#define dn_comp __dn_comp
#define dn_count_labels __dn_count_labels
#define dn_expand __dn_expand
#define dn_skipname __dn_skipname
#define fp_resstat __fp_resstat
#define loc_aton __loc_aton
#define loc_ntoa __loc_ntoa
#define p_cdname __p_cdname
#define p_cdnname __p_cdnname
#define p_class __p_class
#define p_fqname __p_fqname
#define p_fqnname __p_fqnname
#define p_option __p_option
#define p_secstodate __p_secstodate
#define p_section __p_section
#define p_time __p_time
#define p_type __p_type
#define p_rcode __p_rcode
#define p_sockun __p_sockun
#define putlong __putlong
#define putshort __putshort
#define res_dnok __res_dnok
#define res_findzonecut __res_findzonecut
#define res_findzonecut2 __res_findzonecut2
#define res_hnok __res_hnok
#define res_hostalias __res_hostalias
#define res_mailok __res_mailok
#define res_nameinquery __res_nameinquery
#define res_nclose __res_nclose
#define res_ninit __res_ninit
#define res_nmkquery __res_nmkquery
#define res_pquery __res_pquery
#define res_nquery __res_nquery
#define res_nquerydomain __res_nquerydomain
#define res_nsearch __res_nsearch
#define res_nsend __res_nsend
#define res_nsendsigned __res_nsendsigned
#define res_nisourserver __res_nisourserver
#define res_ownok __res_ownok
#define res_queriesmatch __res_queriesmatch
#define res_randomid __res_randomid
#define sym_ntop __sym_ntop
#define sym_ntos __sym_ntos
#define sym_ston __sym_ston
#define res_nopt __res_nopt
#define res_ndestroy __res_ndestroy
#define res_nametoclass __res_nametoclass
#define res_nametotype __res_nametotype
#define res_setservers __res_setservers
#define res_getservers __res_getservers
#define res_buildprotolist __res_buildprotolist
#define res_destroyprotolist __res_destroyprotolist
#define res_destroyservicelist __res_destroyservicelist
#define res_get_nibblesuffix __res_get_nibblesuffix
#define res_get_nibblesuffix2 __res_get_nibblesuffix2
#define res_ourserver_p __res_ourserver_p
#define res_protocolname __res_protocolname
#define res_protocolnumber __res_protocolnumber
#define res_send_setqhook __res_send_setqhook
#define res_send_setrhook __res_send_setrhook
#define res_servicename __res_servicename
#define res_servicenumber __res_servicenumber
__BEGIN_DECLS
int res_hnok __P((const char *));
int res_ownok __P((const char *));
int res_mailok __P((const char *));
int res_dnok __P((const char *));
int sym_ston __P((const struct res_sym *, const char *, int *));
const char * sym_ntos __P((const struct res_sym *, int, int *));
const char * sym_ntop __P((const struct res_sym *, int, int *));
int b64_ntop __P((u_char const *, size_t, char *, size_t));
int b64_pton __P((char const *, u_char *, size_t));
int loc_aton __P((const char *, u_char *));
const char * loc_ntoa __P((const u_char *, char *));
int dn_skipname __P((const u_char *, const u_char *));
void putlong __P((u_int32_t, u_char *));
void putshort __P((u_int16_t, u_char *));
#ifndef __ultrix__
u_int16_t _getshort __P((const u_char *));
u_int32_t _getlong __P((const u_char *));
#endif
const char * p_class __P((int));
const char * p_time __P((u_int32_t));
const char * p_type __P((int));
const char * p_rcode __P((int));
const char * p_sockun __P((union res_sockaddr_union, char *, size_t));
const u_char * p_cdnname __P((const u_char *, const u_char *, int, FILE *));
const u_char * p_cdname __P((const u_char *, const u_char *, FILE *));
const u_char * p_fqnname __P((const u_char *, const u_char *,
int, char *, int));
const u_char * p_fqname __P((const u_char *, const u_char *, FILE *));
const char * p_option __P((u_long));
char * p_secstodate __P((u_long));
int dn_count_labels __P((const char *));
int dn_comp __P((const char *, u_char *, int,
u_char **, u_char **));
int dn_expand __P((const u_char *, const u_char *, const u_char *,
char *, int));
u_int res_randomid __P((void));
int res_nameinquery __P((const char *, int, int, const u_char *,
const u_char *));
int res_queriesmatch __P((const u_char *, const u_char *,
const u_char *, const u_char *));
const char * p_section __P((int, int));
/* Things involving a resolver context. */
int res_ninit __P((res_state));
int res_nisourserver __P((const res_state,
const struct sockaddr_in *));
void fp_resstat __P((const res_state, FILE *));
void res_pquery __P((const res_state, const u_char *, int, FILE *));
const char * res_hostalias __P((const res_state, const char *,
char *, size_t));
int res_nquery __P((res_state, const char *, int, int,
u_char *, int));
int res_nsearch __P((res_state, const char *, int, int, u_char *,
int));
int res_nquerydomain __P((res_state, const char *, const char *,
int, int, u_char *, int));
int res_nmkquery __P((res_state, int, const char *, int, int,
const u_char *, int, const u_char *,
u_char *, int));
int res_nsend __P((res_state, const u_char *, int, u_char *, int));
int res_nsendsigned __P((res_state, const u_char *, int,
ns_tsig_key *, u_char *, int));
int res_findzonecut __P((res_state, const char *, ns_class, int,
char *, size_t, struct in_addr *, int));
int res_findzonecut2 __P((res_state, const char *, ns_class, int,
char *, size_t,
union res_sockaddr_union *, int));
void res_nclose __P((res_state));
int res_nopt __P((res_state, int, u_char *, int, int));
void res_send_setqhook __P((res_send_qhook));
void res_send_setrhook __P((res_send_rhook));
int __res_vinit __P((res_state, int));
void res_destroyservicelist __P((void));
const char * res_servicename __P((u_int16_t, const char *));
const char * res_protocolname __P((int));
void res_destroyprotolist __P((void));
void res_buildprotolist __P((void));
const char * res_get_nibblesuffix __P((res_state));
const char * res_get_nibblesuffix2 __P((res_state));
void res_ndestroy __P((res_state));
u_int16_t res_nametoclass __P((const char *, int *));
u_int16_t res_nametotype __P((const char *, int *));
void res_setservers __P((res_state,
const union res_sockaddr_union *, int));
int res_getservers __P((res_state,
union res_sockaddr_union *, int));
__END_DECLS
#ifdef __cplusplus
}
#endif
#endif /* !_RESOLV_H_ */

View File

@ -61,13 +61,16 @@
#ifndef _INET_H_
#define _INET_H_
#include <sys/types.h>
#include <netinet/in.h>
/* External definitions for functions in inet(3) */
/* R5 libnet.so does not have "__" prefix. */
#ifndef BUILDING_R5_LIBNET
#include <sys/param.h>
#include <sys/bitypes.h>
#include <sys/cdefs.h>
#ifdef __cplusplus
extern "C" {
#endif
#define inet_addr __inet_addr
#define inet_aton __inet_aton
#define inet_lnaof __inet_lnaof
@ -84,32 +87,28 @@
#define inet_ntop __inet_ntop
#define inet_nsap_addr __inet_nsap_addr
#define inet_nsap_ntoa __inet_nsap_ntoa
#endif
#ifdef __cplusplus
extern "C" {
#endif
unsigned long inet_addr(const char *);
int inet_aton(const char *, struct in_addr *);
unsigned long inet_lnaof(struct in_addr);
struct in_addr inet_makeaddr(u_long , u_long);
char * inet_neta(u_long, char *, size_t);
unsigned long inet_netof(struct in_addr);
unsigned long inet_network(const char *);
char *inet_net_ntop(int, const void *, int, char *, size_t);
int inet_net_pton(int, const char *, void *, size_t);
char *inet_cidr_ntop(int, const void *, int, char *, size_t);
int inet_cidr_pton(int, const char *, void *, int *);
/*const*/ char *inet_ntoa(struct in_addr);
int inet_pton(int, const char *, void *);
const char *inet_ntop(int, const void *, char *, size_t);
u_int inet_nsap_addr(const char *, u_char *, int);
char *inet_nsap_ntoa(int, const u_char *, char *);
__BEGIN_DECLS
unsigned long inet_addr __P((const char *));
int inet_aton __P((const char *, struct in_addr *));
unsigned long inet_lnaof __P((struct in_addr));
struct in_addr inet_makeaddr __P((u_long , u_long));
char * inet_neta __P((u_long, char *, size_t));
unsigned long inet_netof __P((struct in_addr));
unsigned long inet_network __P((const char *));
char *inet_net_ntop __P((int, const void *, int, char *, size_t));
int inet_net_pton __P((int, const char *, void *, size_t));
char *inet_cidr_ntop __P((int, const void *, int, char *, size_t));
int inet_cidr_pton __P((int, const char *, void *, int *));
/*const*/ char *inet_ntoa __P((struct in_addr));
int inet_pton __P((int, const char *, void *));
const char *inet_ntop __P((int, const void *, char *, size_t));
u_int inet_nsap_addr __P((const char *, u_char *, int));
char *inet_nsap_ntoa __P((int, const u_char *, char *));
__END_DECLS
#ifdef __cplusplus
}
#endif
#endif /* !_INET_H_ */

View File

@ -58,13 +58,13 @@
#define BIND_4_COMPAT
#include <sys/param.h>
#if (!defined(BSD)) || (BSD < 199306)
# include <sys/bitypes.h>
#else
# include <sys/types.h>
#endif
#include <sys/bitypes.h>
#include <sys/cdefs.h>
#ifdef __cplusplus
extern "C" {
#endif
/*
* Revision information. This is the release date in YYYYMMDD format.
* It can change every day so the right thing to do with it is use it
@ -569,6 +569,10 @@ int ns_makecanon __P((const char *, char *, size_t));
int ns_samename __P((const char *, const char *));
__END_DECLS
#ifdef __cplusplus
}
#endif
#ifdef BIND_4_COMPAT
#include <arpa/nameser_compat.h>
#endif

View File

@ -40,39 +40,7 @@
#define __BIND 19950621 /* (DEAD) interface version stamp. */
#ifndef BYTE_ORDER
#if (BSD >= 199103)
# include <machine/endian.h>
#else
#if defined(__linux) || defined(__HAIKU__) || defined(__BEOS__)
# include <endian.h>
#else
#define LITTLE_ENDIAN 1234 /* least-significant byte first (vax, pc) */
#define BIG_ENDIAN 4321 /* most-significant byte first (IBM, net) */
#define PDP_ENDIAN 3412 /* LSB first in word, MSW first in long (pdp)*/
#if defined(vax) || defined(ns32000) || defined(sun386) || defined(i386) || \
defined(MIPSEL) || defined(_MIPSEL) || defined(BIT_ZERO_ON_RIGHT) || \
defined(__alpha__) || defined(__alpha) || \
(defined(__Lynx__) && defined(__x86__))
#define BYTE_ORDER LITTLE_ENDIAN
#endif
#if defined(sel) || defined(pyr) || defined(mc68000) || defined(sparc) || \
defined(is68k) || defined(tahoe) || defined(ibm032) || defined(ibm370) || \
defined(MIPSEB) || defined(_MIPSEB) || defined(_IBMR2) || defined(DGUX) ||\
defined(apollo) || defined(__convex__) || defined(_CRAY) || \
defined(__hppa) || defined(__hp9000) || \
defined(__hp9000s300) || defined(__hp9000s700) || \
defined(__hp3000s900) || defined(__hpux) || defined(MPE) || \
defined (BIT_ZERO_ON_LEFT) || defined(m68k) || defined(__sparc) || \
(defined(__Lynx__) && \
(defined(__68k__) || defined(__sparc__) || defined(__powerpc__)))
#define BYTE_ORDER BIG_ENDIAN
#endif
#endif /* __linux */
#endif /* BSD */
#endif /* BYTE_ORDER */
#include <endian.h>
#if !defined(BYTE_ORDER) || \
(BYTE_ORDER != BIG_ENDIAN && BYTE_ORDER != LITTLE_ENDIAN && \

View File

@ -1,7 +1,3 @@
/*
Modified for [Open]BeOS
*/
/*
* ++Copyright++ 1980, 1983, 1988, 1993
* -
@ -92,35 +88,21 @@
* @(#)netdb.h 8.1 (Berkeley) 6/2/93
* $Id$
*/
/* Modified for OpenBeOS
*/
#ifndef _NETDB_H_
#define _NETDB_H_
#include <sys/types.h>
#include <netinet/in.h>
#include <stdio.h>
/*
#include <sys/param.h>
#include <sys/types.h>
#if (!defined(BSD)) || (BSD < 199306)
# include <sys/bitypes.h>
#endif
#include <sys/bitypes.h>
#include <sys/cdefs.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <stdio.h>
*/
#ifdef __cplusplus
extern "C" {
#endif
#ifndef _PATH_HEQUIV
#define _PATH_HEQUIV "/etc/hosts.equiv"
#endif
@ -137,7 +119,9 @@ extern "C" {
#define _PATH_SERVICES "/etc/services"
#endif
extern int * __h_errno (void);
__BEGIN_DECLS
extern int * __h_errno __P((void));
__END_DECLS
#define h_errno (*__h_errno())
/*
@ -259,98 +243,7 @@ struct addrinfo {
#define SCOPE_DELIMITER '%'
#if defined (__hpux) || defined(__osf__) || defined(_AIX)
#define _MAXALIASES 35
#define _MAXLINELEN 1024
#define _MAXADDRS 35
#define _HOSTBUFSIZE (BUFSIZ + 1)
struct hostent_data {
struct in_addr host_addr;
char *h_addr_ptrs[_MAXADDRS + 1];
char hostaddr[_MAXADDRS];
char hostbuf[_HOSTBUFSIZE];
char *host_aliases[_MAXALIASES];
char *host_addrs[2];
FILE *hostf;
#ifdef __osf__
int svc_gethostflag;
int svc_gethostbind;
#endif
#ifdef __hpux
short _nsw_src;
short _flags;
char *current;
int currentlen;
#endif
};
struct netent_data {
FILE *net_fp;
#ifdef __osf__
char line[_MAXLINELEN];
#endif
#ifdef __hpux
char line[_MAXLINELEN+1];
#endif
char *net_aliases[_MAXALIASES];
#ifdef __osf__
int _net_stayopen;
int svc_getnetflag;
#endif
#ifdef __hpux
short _nsw_src;
short _flags;
char *current;
int currentlen;
#endif
};
struct protoent_data {
FILE *proto_fp;
#ifdef __osf__
char line[1024];
#endif
#ifdef __hpux
char line[_MAXLINELEN+1];
#endif
char *proto_aliases[_MAXALIASES];
#ifdef __osf__
int _proto_stayopen;
int svc_getprotoflag;
#endif
#ifdef __hpux
short _nsw_src;
short _flags;
char *current;
int currentlen;
#endif
};
struct servent_data {
FILE *serv_fp;
#ifdef __osf__
char line[_MAXLINELEN];
#endif
#ifdef __hpux
char line[_MAXLINELEN+1];
#endif
char *serv_aliases[_MAXALIASES];
#ifdef __osf__
int _serv_stayopen;
int svc_getservflag;
#endif
#ifdef __hpux
short _nsw_src;
short _flags;
char *current;
int currentlen;
#endif
};
#endif
#define __P(a) a
__BEGIN_DECLS
void endhostent __P((void));
void endnetent __P((void));
void endprotoent __P((void));
@ -388,7 +281,6 @@ struct hostent *getipnodebyname __P((const char *, int, int, int *));
struct hostent *getipnodebyaddr __P((const void *, size_t, int, int *));
void freehostent __P((struct hostent *));
struct hostent *gethostbyaddr_r __P((const char *, int, int, struct hostent *,
char *, int, int *));
struct hostent *gethostbyname_r __P((const char *, struct hostent *,
@ -420,12 +312,7 @@ struct servent *getservbyport_r __P((int port, const char *,
struct servent *getservent_r __P((struct servent *, char *, int));
void setservent_r __P((int));
void endservent_r __P((void));
/* BeOS specific, because of lack of UNIX passwd functions */
int getusername(char *username, unsigned userlen);
int getpassword(char *password, unsigned passlen);
__END_DECLS
#ifdef __cplusplus
}

View File

@ -32,20 +32,20 @@
*/
/*
* Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
* Portions Copyright (c) 1996-1999 by Internet Software Consortium.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
* SOFTWARE.
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/*
@ -57,16 +57,16 @@
#define _RESOLV_H_
#include <sys/param.h>
#if (!defined(BSD)) || (BSD < 199306)
# include <sys/bitypes.h>
#else
# include <sys/types.h>
#endif
#include <sys/bitypes.h>
#include <sys/cdefs.h>
#include <sys/socket.h>
#include <stdio.h>
#include <arpa/nameser.h>
#ifdef __cplusplus
extern "C" {
#endif
/*
* Revision information. This is the release date in YYYYMMDD format.
* It can change every day so the right thing to do with it is use it
@ -115,13 +115,21 @@ __END_DECLS
typedef enum { res_goahead, res_nextns, res_modified, res_done, res_error }
res_sendhookact;
typedef res_sendhookact (*res_send_qhook)__P((struct sockaddr * const *,
const u_char **, int *,
u_char *, int, int *));
#ifndef __PMT
#if defined(__STDC__) || defined(__cplusplus)
#define __PMT(args) args
#else
#define __PMT(args) ()
#endif
#endif
typedef res_sendhookact (*res_send_rhook)__P((const struct sockaddr *,
const u_char *, int, u_char *,
int, int *));
typedef res_sendhookact (*res_send_qhook)__PMT((struct sockaddr * const *,
const u_char **, int *,
u_char *, int, int *));
typedef res_sendhookact (*res_send_rhook)__PMT((const struct sockaddr *,
const u_char *, int, u_char *,
int, int *));
struct res_sym {
int number; /* Identifying number, like T_MX */
@ -150,11 +158,7 @@ struct __res_state_ext;
struct __res_state {
int retrans; /* retransmission time interval */
int retry; /* number of times to retransmit */
#ifdef sun
u_int options; /* option flags - see below. */
#else
u_long options; /* option flags - see below. */
#endif
int nscount; /* number of name servers */
struct sockaddr_in
nsaddr_list[MAXNS]; /* address of name server */
@ -162,11 +166,7 @@ struct __res_state {
u_short id; /* current message id */
char *dnsrch[MAXDNSRCH+1]; /* components of domain to search */
char defdname[256]; /* default domain (deprecated) */
#ifdef sun
u_int pfcode; /* RES_PRF_ flags - see below. */
#else
u_long pfcode; /* RES_PRF_ flags - see below. */
#endif
unsigned ndots:4; /* threshold for initial abs. query */
unsigned nsort:4; /* number of elements in sort_list[] */
char unused[3];
@ -246,12 +246,14 @@ union res_sockaddr_union {
#define RES_BLAST 0x00020000 /* blast all recursive servers */
#define RES_NOTLDQUERY 0x00100000 /* don't unqualified name as a tld */
#define RES_USE_DNSSEC 0x00200000 /* use DNSSEC using OK bit in OPT */
/* #define RES_DEBUG2 0x00400000 */ /* nslookup internal */
/* KAME extensions: use higher bit to avoid conflict with ISC use */
#define RES_USE_DNAME 0x10000000 /* use DNAME */
#define RES_USE_EDNS0 0x40000000 /* use EDNS0 if configured */
#define RES_NO_NIBBLE2 0x80000000 /* disable alternate nibble lookup */
#define RES_DEFAULT (RES_RECURSE | RES_DEFNAMES | RES_DNSRCH)
#define RES_DEFAULT (RES_RECURSE | RES_DEFNAMES | \
RES_DNSRCH | RES_NO_NIBBLE2)
/*
* Resolver "pfcode" values. Used by dig.
@ -315,7 +317,6 @@ int res_sendsigned __P((const u_char *, int, ns_tsig_key *,
__END_DECLS
#endif
#if !defined(SHARED_LIBBIND) || defined(LIB)
/*
* If libbind is a shared object (well, DLL anyway)
* these externs break the linker when resolv.h is
@ -328,7 +329,6 @@ extern const struct res_sym __p_cert_syms[];
extern const struct res_sym __p_class_syms[];
extern const struct res_sym __p_type_syms[];
extern const struct res_sym __p_rcode_syms[];
#endif /* SHARED_LIBBIND */
#define b64_ntop __b64_ntop
#define b64_pton __b64_pton
@ -409,10 +409,6 @@ const char * loc_ntoa __P((const u_char *, char *));
int dn_skipname __P((const u_char *, const u_char *));
void putlong __P((u_int32_t, u_char *));
void putshort __P((u_int16_t, u_char *));
#ifndef __ultrix__
u_int16_t _getshort __P((const u_char *));
u_int32_t _getlong __P((const u_char *));
#endif
const char * p_class __P((int));
const char * p_time __P((u_int32_t));
const char * p_type __P((int));
@ -482,4 +478,8 @@ int res_getservers __P((res_state,
union res_sockaddr_union *, int));
__END_DECLS
#ifdef __cplusplus
}
#endif
#endif /* !_RESOLV_H_ */

View File

@ -10,6 +10,29 @@ Added folders and files:
All BIND headers were moved to legacy/network (public) and private/net (private) in the system-wide headers folder.
Removed files:
irs/
dns_gr.c
dns_pw.c
gen_gr.c
gen_pw.c
getgrent.c
getgrent_r.c
getpwent.c
getpwent_r.c
irp_gr.c
irp_pw.c
lcl_gr.c
lcl_pw.c
nis_gr.c
nis_ho.c
nis_ng.c
nis_nw.c
nis_pr.c
nis_pw.c
nis_sv.c
Porting issues:
BIND wants to include sys/un.h and utmp.h. We do not have these, so I put empty headers into the private headers folder.
@ -21,6 +44,6 @@ Added sources for compatibility:
Changes made to the sources and headers:
nameser_compat.h: added check for __HAIKU__ and __BEOS__ to not redefine endianness
arpa/inet.h, netdb.h, resolv.h: added check for __cplusplus, removed check for _REENTRANT (we are always reentrant)
arpa/inet.h, netdb.h, resolv.h, nameser.h, nameser_compat.h: added check for __cplusplus, removed check for _REENTRANT (we are always reentrant), removed all checks for other operating systems
irs/gai_strerror.c, irs/irs_data.c: Changed the initialization of the mutex lock and switched to BeOS-native TLS in gai_strerror() and net_data_init().
irs/gai_strerror.c, irs/irs_data.c: Switched to BeOS-native TLS in gai_strerror() and net_data_init() using a very ugly hack (see src/TLSInit.cpp). We need full mutex support!

View File

@ -20,7 +20,6 @@ if $(TARGET_PLATFORM) != haiku {
}
# our libroot contains functions that are missing in BeOS (e.g.: strlcat)
SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src system libroot posix pthread ] ;
SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src system libroot posix string ] ;
# private sources for this port
@ -73,24 +72,18 @@ MergeObject <compatlibbind>inet.o :
MergeObject <compatlibbind>irs.o :
dns.c
dns_gr.c
dns_ho.c
dns_nw.c
dns_pr.c
dns_pw.c
dns_sv.c
gai_strerror.c
gen.c
gen_gr.c
gen_ho.c
gen_ng.c
gen_nw.c
gen_pr.c
gen_pw.c
gen_sv.c
getaddrinfo.c
getgrent.c
getgrent_r.c
gethostent.c
gethostent_r.c
getnameinfo.c
@ -100,37 +93,24 @@ MergeObject <compatlibbind>irs.o :
getnetgrent_r.c
getprotoent.c
getprotoent_r.c
getpwent.c
getpwent_r.c
getservent.c
getservent_r.c
hesiod.c
irp.c
irp_gr.c
irp_ho.c
irp_ng.c
irp_nw.c
irp_pr.c
irp_pw.c
irp_sv.c
irpmarshall.c
irs_data.c
lcl.c
lcl_gr.c
lcl_ho.c
lcl_ng.c
lcl_nw.c
lcl_pr.c
lcl_pw.c
lcl_sv.c
nis.c
nis_gr.c
nis_ho.c
nis_ng.c
nis_nw.c
nis_pr.c
nis_pw.c
nis_sv.c
nul_ng.c
util.c
;
@ -185,9 +165,7 @@ MergeObject <compatlibbind>resolv.o :
SharedLibrary libbind.so :
# functions from our libroot
# ToDo: these can be removed for the Haiku build
pthread_mutex.c
pthread_mutexattr.c
# TODO: these can be removed for the Haiku build
strlcat.c
# private functions
@ -195,9 +173,11 @@ SharedLibrary libbind.so :
ethers.c
gettimeofday.c
linkaddr.c
pthread_emu.c
res_resultcodes.c
strsep.c
# UGLY HACK
TLSInit.cpp
;
LinkAgainst libbind.so :

View File

@ -1,6 +1,10 @@
#ifndef PTHREAD_EMU_H
#define PTHREAD_EMU_H
#ifdef __cplusplus
extern "C" {
#endif
#include <TLS.h>
#include <pthread.h>
#include <OS.h>
@ -16,4 +20,8 @@ extern int pthread_setspecific(pthread_key_t key, void *value);
extern void *pthread_getspecific(pthread_key_t key);
#ifdef __cplusplus
}
#endif
#endif /* PTHREAD_EMU_H */

View File

@ -1,293 +0,0 @@
/*
* Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
* Copyright (c) 1996-1999 by Internet Software Consortium.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#if defined(LIBC_SCCS) && !defined(lint)
static const char rcsid[] = "$Id$";
#endif
/*
* dns_gr.c --- this file contains the functions for accessing
* group information from Hesiod.
*/
#include "port_before.h"
#ifndef WANT_IRS_GR
static int __bind_irs_gr_unneeded;
#else
#include <sys/param.h>
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/nameser.h>
#include <resolv.h>
#include <isc/memcluster.h>
#include <irs.h>
#include "port_after.h"
#include "irs_p.h"
#include "hesiod.h"
#include "dns_p.h"
/* Types. */
struct pvt {
/*
* This is our private accessor data. It has a shared hesiod context.
*/
struct dns_p * dns;
/*
* Need space to store the entries read from the group file.
* The members list also needs space per member, and the
* strings making up the user names must be allocated
* somewhere. Rather than doing lots of small allocations,
* we keep one buffer and resize it as needed.
*/
struct group group;
size_t nmemb; /* Malloc'd max index of gr_mem[]. */
char * membuf;
size_t membufsize;
};
/* Forward. */
static struct group * gr_next(struct irs_gr *);
static struct group * gr_byname(struct irs_gr *, const char *);
static struct group * gr_bygid(struct irs_gr *, gid_t);
static void gr_rewind(struct irs_gr *);
static void gr_close(struct irs_gr *);
static int gr_list(struct irs_gr *, const char *,
gid_t, gid_t *, int *);
static void gr_minimize(struct irs_gr *);
static struct __res_state * gr_res_get(struct irs_gr *);
static void gr_res_set(struct irs_gr *,
struct __res_state *,
void (*)(void *));
static struct group * get_hes_group(struct irs_gr *this,
const char *name,
const char *type);
/* Public. */
struct irs_gr *
irs_dns_gr(struct irs_acc *this) {
struct dns_p *dns = (struct dns_p *)this->private;
struct irs_gr *gr;
struct pvt *pvt;
if (!dns || !dns->hes_ctx) {
errno = ENODEV;
return (NULL);
}
if (!(pvt = memget(sizeof *pvt))) {
errno = ENOMEM;
return (NULL);
}
memset(pvt, 0, sizeof *pvt);
pvt->dns = dns;
if (!(gr = memget(sizeof *gr))) {
memput(pvt, sizeof *pvt);
errno = ENOMEM;
return (NULL);
}
memset(gr, 0x5e, sizeof *gr);
gr->private = pvt;
gr->next = gr_next;
gr->byname = gr_byname;
gr->bygid = gr_bygid;
gr->rewind = gr_rewind;
gr->close = gr_close;
gr->list = gr_list;
gr->minimize = gr_minimize;
gr->res_get = gr_res_get;
gr->res_set = gr_res_set;
return (gr);
}
/* methods */
static void
gr_close(struct irs_gr *this) {
struct pvt *pvt = (struct pvt *)this->private;
if (pvt->group.gr_mem)
free(pvt->group.gr_mem);
if (pvt->membuf)
free(pvt->membuf);
memput(pvt, sizeof *pvt);
memput(this, sizeof *this);
}
static struct group *
gr_next(struct irs_gr *this) {
UNUSED(this);
return (NULL);
}
static struct group *
gr_byname(struct irs_gr *this, const char *name) {
return (get_hes_group(this, name, "group"));
}
static struct group *
gr_bygid(struct irs_gr *this, gid_t gid) {
char name[32];
sprintf(name, "%ld", (long)gid);
return (get_hes_group(this, name, "gid"));
}
static void
gr_rewind(struct irs_gr *this) {
UNUSED(this);
/* NOOP */
}
static int
gr_list(struct irs_gr *this, const char *name,
gid_t basegid, gid_t *groups, int *ngroups)
{
UNUSED(this);
UNUSED(name);
UNUSED(basegid);
UNUSED(groups);
*ngroups = 0;
/* There's some way to do this in Hesiod. */
return (-1);
}
static void
gr_minimize(struct irs_gr *this) {
UNUSED(this);
/* NOOP */
}
/* Private. */
static struct group *
get_hes_group(struct irs_gr *this, const char *name, const char *type) {
struct pvt *pvt = (struct pvt *)this->private;
char **hes_list, *cp, **new;
size_t num_members = 0;
u_long t;
hes_list = hesiod_resolve(pvt->dns->hes_ctx, name, type);
if (!hes_list)
return (NULL);
/*
* Copy the returned hesiod string into storage space.
*/
if (pvt->membuf)
free(pvt->membuf);
pvt->membuf = strdup(*hes_list);
hesiod_free_list(pvt->dns->hes_ctx, hes_list);
cp = pvt->membuf;
pvt->group.gr_name = cp;
if (!(cp = strchr(cp, ':')))
goto cleanup;
*cp++ = '\0';
pvt->group.gr_passwd = cp;
if (!(cp = strchr(cp, ':')))
goto cleanup;
*cp++ = '\0';
errno = 0;
t = strtoul(cp, NULL, 10);
if (errno == ERANGE)
goto cleanup;
pvt->group.gr_gid = (gid_t) t;
if (!(cp = strchr(cp, ':')))
goto cleanup;
cp++;
/*
* Parse the members out.
*/
while (*cp) {
if (num_members+1 >= pvt->nmemb || pvt->group.gr_mem == NULL) {
pvt->nmemb += 10;
new = realloc(pvt->group.gr_mem,
pvt->nmemb * sizeof(char *));
if (new == NULL)
goto cleanup;
pvt->group.gr_mem = new;
}
pvt->group.gr_mem[num_members++] = cp;
if (!(cp = strchr(cp, ',')))
break;
*cp++ = '\0';
}
if (!pvt->group.gr_mem) {
pvt->group.gr_mem = malloc(sizeof(char*));
if (!pvt->group.gr_mem)
goto cleanup;
}
pvt->group.gr_mem[num_members] = NULL;
return (&pvt->group);
cleanup:
if (pvt->group.gr_mem) {
free(pvt->group.gr_mem);
pvt->group.gr_mem = NULL;
}
if (pvt->membuf) {
free(pvt->membuf);
pvt->membuf = NULL;
}
return (NULL);
}
static struct __res_state *
gr_res_get(struct irs_gr *this) {
struct pvt *pvt = (struct pvt *)this->private;
struct dns_p *dns = pvt->dns;
return (__hesiod_res_get(dns->hes_ctx));
}
static void
gr_res_set(struct irs_gr *this, struct __res_state * res,
void (*free_res)(void *)) {
struct pvt *pvt = (struct pvt *)this->private;
struct dns_p *dns = pvt->dns;
__hesiod_res_set(dns->hes_ctx, res, free_res);
}
#endif /* WANT_IRS_GR */

View File

@ -1,231 +0,0 @@
/*
* Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
* Copyright (c) 1996,1999 by Internet Software Consortium.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#if defined(LIBC_SCCS) && !defined(lint)
static const char rcsid[] = "$Id$";
#endif
#include "port_before.h"
#ifndef WANT_IRS_PW
static int __bind_irs_pw_unneeded;
#else
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/nameser.h>
#include <resolv.h>
#include <isc/memcluster.h>
#include <irs.h>
#include "port_after.h"
#include "irs_p.h"
#include "hesiod.h"
#include "dns_p.h"
/* Types. */
struct pvt {
struct dns_p * dns;
struct passwd passwd;
char * pwbuf;
};
/* Forward. */
static void pw_close(struct irs_pw *);
static struct passwd * pw_byname(struct irs_pw *, const char *);
static struct passwd * pw_byuid(struct irs_pw *, uid_t);
static struct passwd * pw_next(struct irs_pw *);
static void pw_rewind(struct irs_pw *);
static void pw_minimize(struct irs_pw *);
static struct __res_state * pw_res_get(struct irs_pw *);
static void pw_res_set(struct irs_pw *,
struct __res_state *,
void (*)(void *));
static struct passwd * getpwcommon(struct irs_pw *, const char *,
const char *);
/* Public. */
struct irs_pw *
irs_dns_pw(struct irs_acc *this) {
struct dns_p *dns = (struct dns_p *)this->private;
struct irs_pw *pw;
struct pvt *pvt;
if (!dns || !dns->hes_ctx) {
errno = ENODEV;
return (NULL);
}
if (!(pvt = memget(sizeof *pvt))) {
errno = ENOMEM;
return (NULL);
}
memset(pvt, 0, sizeof *pvt);
pvt->dns = dns;
if (!(pw = memget(sizeof *pw))) {
memput(pvt, sizeof *pvt);
errno = ENOMEM;
return (NULL);
}
memset(pw, 0x5e, sizeof *pw);
pw->private = pvt;
pw->close = pw_close;
pw->byname = pw_byname;
pw->byuid = pw_byuid;
pw->next = pw_next;
pw->rewind = pw_rewind;
pw->minimize = pw_minimize;
pw->res_get = pw_res_get;
pw->res_set = pw_res_set;
return (pw);
}
/* Methods. */
static void
pw_close(struct irs_pw *this) {
struct pvt *pvt = (struct pvt *)this->private;
if (pvt->pwbuf)
free(pvt->pwbuf);
memput(pvt, sizeof *pvt);
memput(this, sizeof *this);
}
static struct passwd *
pw_byname(struct irs_pw *this, const char *nam) {
return (getpwcommon(this, nam, "passwd"));
}
static struct passwd *
pw_byuid(struct irs_pw *this, uid_t uid) {
char uidstr[16];
sprintf(uidstr, "%lu", (u_long)uid);
return (getpwcommon(this, uidstr, "uid"));
}
static struct passwd *
pw_next(struct irs_pw *this) {
UNUSED(this);
errno = ENODEV;
return (NULL);
}
static void
pw_rewind(struct irs_pw *this) {
UNUSED(this);
/* NOOP */
}
static void
pw_minimize(struct irs_pw *this) {
UNUSED(this);
/* NOOP */
}
static struct __res_state *
pw_res_get(struct irs_pw *this) {
struct pvt *pvt = (struct pvt *)this->private;
struct dns_p *dns = pvt->dns;
return (__hesiod_res_get(dns->hes_ctx));
}
static void
pw_res_set(struct irs_pw *this, struct __res_state * res,
void (*free_res)(void *)) {
struct pvt *pvt = (struct pvt *)this->private;
struct dns_p *dns = pvt->dns;
__hesiod_res_set(dns->hes_ctx, res, free_res);
}
/* Private. */
static struct passwd *
getpwcommon(struct irs_pw *this, const char *arg, const char *type) {
struct pvt *pvt = (struct pvt *)this->private;
char **hes_list, *cp;
if (!(hes_list = hesiod_resolve(pvt->dns->hes_ctx, arg, type)))
return (NULL);
if (!*hes_list) {
hesiod_free_list(pvt->dns->hes_ctx, hes_list);
errno = ENOENT;
return (NULL);
}
memset(&pvt->passwd, 0, sizeof pvt->passwd);
if (pvt->pwbuf)
free(pvt->pwbuf);
pvt->pwbuf = strdup(*hes_list);
hesiod_free_list(pvt->dns->hes_ctx, hes_list);
cp = pvt->pwbuf;
pvt->passwd.pw_name = cp;
if (!(cp = strchr(cp, ':')))
goto cleanup;
*cp++ = '\0';
pvt->passwd.pw_passwd = cp;
if (!(cp = strchr(cp, ':')))
goto cleanup;
*cp++ = '\0';
pvt->passwd.pw_uid = atoi(cp);
if (!(cp = strchr(cp, ':')))
goto cleanup;
*cp++ = '\0';
pvt->passwd.pw_gid = atoi(cp);
if (!(cp = strchr(cp, ':')))
goto cleanup;
*cp++ = '\0';
pvt->passwd.pw_gecos = cp;
if (!(cp = strchr(cp, ':')))
goto cleanup;
*cp++ = '\0';
pvt->passwd.pw_dir = cp;
if (!(cp = strchr(cp, ':')))
goto cleanup;
*cp++ = '\0';
pvt->passwd.pw_shell = cp;
return (&pvt->passwd);
cleanup:
free(pvt->pwbuf);
pvt->pwbuf = NULL;
return (NULL);
}
#endif /* WANT_IRS_PW */

View File

@ -47,6 +47,10 @@ static const int gai_nerr = (sizeof(gai_errlist)/sizeof(*gai_errlist));
#define EAI_BUFSIZE 128
#ifdef DO_PTHREADS
pthread_key_t gGaiStrerrorKey;
#endif
const char *
gai_strerror(int ecode) {
#ifndef DO_PTHREADS
@ -55,33 +59,20 @@ gai_strerror(int ecode) {
#ifndef LIBBIND_MUTEX_INITIALIZER
#define LIBBIND_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
#endif
static pthread_mutex_t lock;
static pthread_key_t key;
static int once = 0;
char *buf;
#endif
if (ecode >= 0 && ecode < (gai_nerr - 1))
return (gai_errlist[ecode]);
#ifdef DO_PTHREADS
if (!once) {
/* XXX: Haiku has non-constant mutex initializer! Must init here. */
lock = LIBBIND_MUTEX_INITIALIZER;
pthread_mutex_lock(&lock);
if (!once++)
key = tls_allocate();
pthread_mutex_unlock(&lock);
}
buf = tls_get(key);
buf = tls_get(gGaiStrerrorKey);
if (buf == NULL) {
buf = malloc(EAI_BUFSIZE);
if (buf == NULL)
return ("unknown error");
on_exit_thread(free, buf);
tls_set(key, buf);
tls_set(gGaiStrerrorKey, buf);
}
#endif
/*

View File

@ -1,492 +0,0 @@
/*
* Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
* Copyright (c) 1996-1999 by Internet Software Consortium.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#if !defined(LINT) && !defined(CODECENTER)
static const char rcsid[] = "$Id$";
#endif
/* Imports */
#include "port_before.h"
#ifndef WANT_IRS_GR
static int __bind_irs_gr_unneeded;
#else
#include <sys/types.h>
#include <isc/assertions.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <netinet/in.h>
#include <arpa/nameser.h>
#include <resolv.h>
#include <isc/memcluster.h>
#include <irs.h>
#include "port_after.h"
#include "irs_p.h"
#include "gen_p.h"
/* Definitions */
struct pvt {
struct irs_rule * rules;
struct irs_rule * rule;
struct irs_gr * gr;
/*
* Need space to store the entries read from the group file.
* The members list also needs space per member, and the
* strings making up the user names must be allocated
* somewhere. Rather than doing lots of small allocations,
* we keep one buffer and resize it as needed.
*/
struct group group;
size_t nmemb; /* Malloc'd max index of gr_mem[]. */
char * membuf;
size_t membufsize;
struct __res_state * res;
void (*free_res)(void *);
};
/* Forward */
static void gr_close(struct irs_gr *);
static struct group * gr_next(struct irs_gr *);
static struct group * gr_byname(struct irs_gr *, const char *);
static struct group * gr_bygid(struct irs_gr *, gid_t);
static void gr_rewind(struct irs_gr *);
static int gr_list(struct irs_gr *, const char *,
gid_t, gid_t *, int *);
static void gr_minimize(struct irs_gr *);
static struct __res_state * gr_res_get(struct irs_gr *);
static void gr_res_set(struct irs_gr *,
struct __res_state *,
void (*)(void *));
static int grmerge(struct irs_gr *gr, const struct group *src,
int preserve);
static int countvec(char **vec);
static int isnew(char **old, char *new);
static int countnew(char **old, char **new);
static size_t sizenew(char **old, char **new);
static int newgid(int, gid_t *, gid_t);
/* Macros */
#define FREE_IF(x) do { if ((x) != NULL) { free(x); (x) = NULL; } } while (0)
/* Public */
struct irs_gr *
irs_gen_gr(struct irs_acc *this) {
struct gen_p *accpvt = (struct gen_p *)this->private;
struct irs_gr *gr;
struct pvt *pvt;
if (!(gr = memget(sizeof *gr))) {
errno = ENOMEM;
return (NULL);
}
memset(gr, 0x5e, sizeof *gr);
if (!(pvt = memget(sizeof *pvt))) {
memput(gr, sizeof *gr);
errno = ENOMEM;
return (NULL);
}
memset(pvt, 0, sizeof *pvt);
pvt->rules = accpvt->map_rules[irs_gr];
pvt->rule = pvt->rules;
gr->private = pvt;
gr->close = gr_close;
gr->next = gr_next;
gr->byname = gr_byname;
gr->bygid = gr_bygid;
gr->rewind = gr_rewind;
gr->list = gr_list;
gr->minimize = gr_minimize;
gr->res_get = gr_res_get;
gr->res_set = gr_res_set;
return (gr);
}
/* Methods. */
static void
gr_close(struct irs_gr *this) {
struct pvt *pvt = (struct pvt *)this->private;
memput(pvt, sizeof *pvt);
memput(this, sizeof *this);
}
static struct group *
gr_next(struct irs_gr *this) {
struct pvt *pvt = (struct pvt *)this->private;
struct group *rval;
struct irs_gr *gr;
while (pvt->rule) {
gr = pvt->rule->inst->gr;
rval = (*gr->next)(gr);
if (rval)
return (rval);
if (!(pvt->rule->flags & IRS_CONTINUE))
break;
pvt->rule = pvt->rule->next;
if (pvt->rule) {
gr = pvt->rule->inst->gr;
(*gr->rewind)(gr);
}
}
return (NULL);
}
static struct group *
gr_byname(struct irs_gr *this, const char *name) {
struct pvt *pvt = (struct pvt *)this->private;
struct irs_rule *rule;
struct group *tval;
struct irs_gr *gr;
int dirty;
dirty = 0;
for (rule = pvt->rules; rule; rule = rule->next) {
gr = rule->inst->gr;
tval = (*gr->byname)(gr, name);
if (tval) {
if (!grmerge(this, tval, dirty++))
return (NULL);
if (!(rule->flags & IRS_MERGE))
break;
} else {
if (!(rule->flags & IRS_CONTINUE))
break;
}
}
if (dirty)
return (&pvt->group);
return (NULL);
}
static struct group *
gr_bygid(struct irs_gr *this, gid_t gid) {
struct pvt *pvt = (struct pvt *)this->private;
struct irs_rule *rule;
struct group *tval;
struct irs_gr *gr;
int dirty;
dirty = 0;
for (rule = pvt->rules; rule; rule = rule->next) {
gr = rule->inst->gr;
tval = (*gr->bygid)(gr, gid);
if (tval) {
if (!grmerge(this, tval, dirty++))
return (NULL);
if (!(rule->flags & IRS_MERGE))
break;
} else {
if (!(rule->flags & IRS_CONTINUE))
break;
}
}
if (dirty)
return (&pvt->group);
return (NULL);
}
static void
gr_rewind(struct irs_gr *this) {
struct pvt *pvt = (struct pvt *)this->private;
struct irs_gr *gr;
pvt->rule = pvt->rules;
if (pvt->rule) {
gr = pvt->rule->inst->gr;
(*gr->rewind)(gr);
}
}
static int
gr_list(struct irs_gr *this, const char *name,
gid_t basegid, gid_t *groups, int *ngroups)
{
struct pvt *pvt = (struct pvt *)this->private;
struct irs_rule *rule;
struct irs_gr *gr;
int t_ngroups, maxgroups;
gid_t *t_groups;
int n, t, rval = 0;
maxgroups = *ngroups;
*ngroups = 0;
t_groups = (gid_t *)malloc(maxgroups * sizeof(gid_t));
if (!t_groups) {
errno = ENOMEM;
return (-1);
}
for (rule = pvt->rules; rule; rule = rule->next) {
t_ngroups = maxgroups;
gr = rule->inst->gr;
t = (*gr->list)(gr, name, basegid, t_groups, &t_ngroups);
for (n = 0; n < t_ngroups; n++) {
if (newgid(*ngroups, groups, t_groups[n])) {
if (*ngroups == maxgroups) {
rval = -1;
goto done;
}
groups[(*ngroups)++] = t_groups[n];
}
}
if (t == 0) {
if (!(rule->flags & IRS_MERGE))
break;
} else {
if (!(rule->flags & IRS_CONTINUE))
break;
}
}
done:
free(t_groups);
return (rval);
}
static void
gr_minimize(struct irs_gr *this) {
struct pvt *pvt = (struct pvt *)this->private;
struct irs_rule *rule;
for (rule = pvt->rules; rule != NULL; rule = rule->next) {
struct irs_gr *gr = rule->inst->gr;
(*gr->minimize)(gr);
}
}
static struct __res_state *
gr_res_get(struct irs_gr *this) {
struct pvt *pvt = (struct pvt *)this->private;
if (!pvt->res) {
struct __res_state *res;
res = (struct __res_state *)malloc(sizeof *res);
if (!res) {
errno = ENOMEM;
return (NULL);
}
memset(res, 0, sizeof *res);
gr_res_set(this, res, free);
}
return (pvt->res);
}
static void
gr_res_set(struct irs_gr *this, struct __res_state *res,
void (*free_res)(void *)) {
struct pvt *pvt = (struct pvt *)this->private;
struct irs_rule *rule;
if (pvt->res && pvt->free_res) {
res_nclose(pvt->res);
(*pvt->free_res)(pvt->res);
}
pvt->res = res;
pvt->free_res = free_res;
for (rule = pvt->rules; rule != NULL; rule = rule->next) {
struct irs_gr *gr = rule->inst->gr;
if (gr->res_set)
(*gr->res_set)(gr, pvt->res, NULL);
}
}
/* Private. */
static int
grmerge(struct irs_gr *this, const struct group *src, int preserve) {
struct pvt *pvt = (struct pvt *)this->private;
char *cp, **m, **p, *oldmembuf, *ep;
int n, ndst, nnew;
size_t used;
if (!preserve) {
pvt->group.gr_gid = src->gr_gid;
if (pvt->nmemb < 1) {
m = malloc(sizeof *m);
if (m == NULL) {
/* No harm done, no work done. */
return (0);
}
pvt->group.gr_mem = m;
pvt->nmemb = 1;
}
pvt->group.gr_mem[0] = NULL;
}
ndst = countvec(pvt->group.gr_mem);
nnew = countnew(pvt->group.gr_mem, src->gr_mem);
/*
* Make sure destination member array is large enough.
* p points to new portion.
*/
n = ndst + nnew + 1;
if ((size_t)n > pvt->nmemb) {
m = realloc(pvt->group.gr_mem, n * sizeof *m);
if (m == NULL) {
/* No harm done, no work done. */
return (0);
}
pvt->group.gr_mem = m;
pvt->nmemb = n;
}
p = pvt->group.gr_mem + ndst;
/*
* Enlarge destination membuf; cp points at new portion.
*/
n = sizenew(pvt->group.gr_mem, src->gr_mem);
INSIST((nnew == 0) == (n == 0));
if (!preserve) {
n += strlen(src->gr_name) + 1;
n += strlen(src->gr_passwd) + 1;
}
if (n == 0) {
/* No work to do. */
return (1);
}
used = preserve ? pvt->membufsize : 0;
cp = malloc(used + n);
if (cp == NULL) {
/* No harm done, no work done. */
return (0);
}
ep = cp + used + n;
if (used != 0)
memcpy(cp, pvt->membuf, used);
oldmembuf = pvt->membuf;
pvt->membuf = cp;
pvt->membufsize = used + n;
cp += used;
/*
* Adjust group.gr_mem.
*/
if (pvt->membuf != oldmembuf)
for (m = pvt->group.gr_mem; *m; m++)
*m = pvt->membuf + (*m - oldmembuf);
/*
* Add new elements.
*/
for (m = src->gr_mem; *m; m++)
if (isnew(pvt->group.gr_mem, *m)) {
*p++ = cp;
*p = NULL;
n = strlen(*m) + 1;
if (n > ep - cp) {
FREE_IF(oldmembuf);
return (0);
}
strcpy(cp, *m); /* (checked) */
cp += n;
}
if (preserve) {
pvt->group.gr_name = pvt->membuf +
(pvt->group.gr_name - oldmembuf);
pvt->group.gr_passwd = pvt->membuf +
(pvt->group.gr_passwd - oldmembuf);
} else {
pvt->group.gr_name = cp;
n = strlen(src->gr_name) + 1;
if (n > ep - cp) {
FREE_IF(oldmembuf);
return (0);
}
strcpy(cp, src->gr_name); /* (checked) */
cp += n;
pvt->group.gr_passwd = cp;
n = strlen(src->gr_passwd) + 1;
if (n > ep - cp) {
FREE_IF(oldmembuf);
return (0);
}
strcpy(cp, src->gr_passwd); /* (checked) */
cp += n;
}
FREE_IF(oldmembuf);
INSIST(cp >= pvt->membuf && cp <= &pvt->membuf[pvt->membufsize]);
return (1);
}
static int
countvec(char **vec) {
int n = 0;
while (*vec++)
n++;
return (n);
}
static int
isnew(char **old, char *new) {
for (; *old; old++)
if (strcmp(*old, new) == 0)
return (0);
return (1);
}
static int
countnew(char **old, char **new) {
int n = 0;
for (; *new; new++)
n += isnew(old, *new);
return (n);
}
static size_t
sizenew(char **old, char **new) {
size_t n = 0;
for (; *new; new++)
if (isnew(old, *new))
n += strlen(*new) + 1;
return (n);
}
static int
newgid(int ngroups, gid_t *groups, gid_t group) {
ngroups--, groups++;
for (; ngroups-- > 0; groups++)
if (*groups == group)
return (0);
return (1);
}
#endif /* WANT_IRS_GR */

View File

@ -1,233 +0,0 @@
/*
* Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
* Copyright (c) 1996,1999 by Internet Software Consortium.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#if !defined(LINT) && !defined(CODECENTER)
static const char rcsid[] = "$Id$";
#endif
/* Imports */
#include "port_before.h"
#ifndef WANT_IRS_PW
static int __bind_irs_pw_unneeded;
#else
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/nameser.h>
#include <resolv.h>
#include <errno.h>
#include <pwd.h>
#include <stdlib.h>
#include <string.h>
#include <isc/memcluster.h>
#include <irs.h>
#include "port_after.h"
#include "irs_p.h"
#include "gen_p.h"
/* Types */
struct pvt {
struct irs_rule * rules;
struct irs_rule * rule;
struct __res_state * res;
void (*free_res)(void *);
};
/* Forward */
static void pw_close(struct irs_pw *);
static struct passwd * pw_next(struct irs_pw *);
static struct passwd * pw_byname(struct irs_pw *, const char *);
static struct passwd * pw_byuid(struct irs_pw *, uid_t);
static void pw_rewind(struct irs_pw *);
static void pw_minimize(struct irs_pw *);
static struct __res_state * pw_res_get(struct irs_pw *);
static void pw_res_set(struct irs_pw *,
struct __res_state *,
void (*)(void *));
/* Public */
struct irs_pw *
irs_gen_pw(struct irs_acc *this) {
struct gen_p *accpvt = (struct gen_p *)this->private;
struct irs_pw *pw;
struct pvt *pvt;
if (!(pw = memget(sizeof *pw))) {
errno = ENOMEM;
return (NULL);
}
memset(pw, 0x5e, sizeof *pw);
if (!(pvt = memget(sizeof *pvt))) {
memput(pw, sizeof *pvt);
errno = ENOMEM;
return (NULL);
}
memset(pvt, 0, sizeof *pvt);
pvt->rules = accpvt->map_rules[irs_pw];
pvt->rule = pvt->rules;
pw->private = pvt;
pw->close = pw_close;
pw->next = pw_next;
pw->byname = pw_byname;
pw->byuid = pw_byuid;
pw->rewind = pw_rewind;
pw->minimize = pw_minimize;
pw->res_get = pw_res_get;
pw->res_set = pw_res_set;
return (pw);
}
/* Methods */
static void
pw_close(struct irs_pw *this) {
struct pvt *pvt = (struct pvt *)this->private;
memput(pvt, sizeof *pvt);
memput(this, sizeof *this);
}
static struct passwd *
pw_next(struct irs_pw *this) {
struct pvt *pvt = (struct pvt *)this->private;
struct passwd *rval;
struct irs_pw *pw;
while (pvt->rule) {
pw = pvt->rule->inst->pw;
rval = (*pw->next)(pw);
if (rval)
return (rval);
if (!(pvt->rule->flags & IRS_CONTINUE))
break;
pvt->rule = pvt->rule->next;
if (pvt->rule) {
pw = pvt->rule->inst->pw;
(*pw->rewind)(pw);
}
}
return (NULL);
}
static void
pw_rewind(struct irs_pw *this) {
struct pvt *pvt = (struct pvt *)this->private;
struct irs_pw *pw;
pvt->rule = pvt->rules;
if (pvt->rule) {
pw = pvt->rule->inst->pw;
(*pw->rewind)(pw);
}
}
static struct passwd *
pw_byname(struct irs_pw *this, const char *name) {
struct pvt *pvt = (struct pvt *)this->private;
struct irs_rule *rule;
struct passwd *rval;
struct irs_pw *pw;
rval = NULL;
for (rule = pvt->rules; rule; rule = rule->next) {
pw = rule->inst->pw;
rval = (*pw->byname)(pw, name);
if (rval || !(rule->flags & IRS_CONTINUE))
break;
}
return (rval);
}
static struct passwd *
pw_byuid(struct irs_pw *this, uid_t uid) {
struct pvt *pvt = (struct pvt *)this->private;
struct irs_rule *rule;
struct passwd *rval;
struct irs_pw *pw;
rval = NULL;
for (rule = pvt->rules; rule; rule = rule->next) {
pw = rule->inst->pw;
rval = (*pw->byuid)(pw, uid);
if (rval || !(rule->flags & IRS_CONTINUE))
break;
}
return (rval);
}
static void
pw_minimize(struct irs_pw *this) {
struct pvt *pvt = (struct pvt *)this->private;
struct irs_rule *rule;
for (rule = pvt->rules; rule != NULL; rule = rule->next) {
struct irs_pw *pw = rule->inst->pw;
(*pw->minimize)(pw);
}
}
static struct __res_state *
pw_res_get(struct irs_pw *this) {
struct pvt *pvt = (struct pvt *)this->private;
if (!pvt->res) {
struct __res_state *res;
res = (struct __res_state *)malloc(sizeof *res);
if (!res) {
errno = ENOMEM;
return (NULL);
}
memset(res, 0, sizeof *res);
pw_res_set(this, res, free);
}
return (pvt->res);
}
static void
pw_res_set(struct irs_pw *this, struct __res_state *res,
void (*free_res)(void *)) {
struct pvt *pvt = (struct pvt *)this->private;
struct irs_rule *rule;
if (pvt->res && pvt->free_res) {
res_nclose(pvt->res);
(*pvt->free_res)(pvt->res);
}
pvt->res = res;
pvt->free_res = free_res;
for (rule = pvt->rules; rule != NULL; rule = rule->next) {
struct irs_pw *pw = rule->inst->pw;
if (pw->res_set)
(*pw->res_set)(pw, pvt->res, NULL);
}
}
#endif /* WANT_IRS_PW */

View File

@ -1,223 +0,0 @@
/*
* Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
* Copyright (c) 1996-1999 by Internet Software Consortium.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#if !defined(LINT) && !defined(CODECENTER)
static const char rcsid[] = "$Id$";
#endif
/* Imports */
#include "port_before.h"
#if !defined(WANT_IRS_GR) || defined(__BIND_NOSTATIC)
static int __bind_irs_gr_unneeded;
#else
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/nameser.h>
#include <errno.h>
#include <grp.h>
#include <resolv.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <irs.h>
#include "port_after.h"
#include "irs_data.h"
/* Forward */
static struct net_data *init(void);
void endgrent(void);
/* Public */
struct group *
getgrent() {
struct net_data *net_data = init();
return (getgrent_p(net_data));
}
struct group *
getgrnam(const char *name) {
struct net_data *net_data = init();
return (getgrnam_p(name, net_data));
}
struct group *
getgrgid(gid_t gid) {
struct net_data *net_data = init();
return (getgrgid_p(gid, net_data));
}
int
setgroupent(int stayopen) {
struct net_data *net_data = init();
return (setgroupent_p(stayopen, net_data));
}
#ifdef SETGRENT_VOID
void
setgrent(void) {
struct net_data *net_data = init();
setgrent_p(net_data);
}
#else
int
setgrent(void) {
struct net_data *net_data = init();
return (setgrent_p(net_data));
}
#endif /* SETGRENT_VOID */
void
endgrent() {
struct net_data *net_data = init();
endgrent_p(net_data);
}
int
getgrouplist(GETGROUPLIST_ARGS) {
struct net_data *net_data = init();
return (getgrouplist_p(name, basegid, groups, ngroups, net_data));
}
/* Shared private. */
struct group *
getgrent_p(struct net_data *net_data) {
struct irs_gr *gr;
if (!net_data || !(gr = net_data->gr))
return (NULL);
net_data->gr_last = (*gr->next)(gr);
return (net_data->gr_last);
}
struct group *
getgrnam_p(const char *name, struct net_data *net_data) {
struct irs_gr *gr;
if (!net_data || !(gr = net_data->gr))
return (NULL);
if (net_data->gr_stayopen && net_data->gr_last &&
!strcmp(net_data->gr_last->gr_name, name))
return (net_data->gr_last);
net_data->gr_last = (*gr->byname)(gr, name);
if (!net_data->gr_stayopen)
endgrent();
return (net_data->gr_last);
}
struct group *
getgrgid_p(gid_t gid, struct net_data *net_data) {
struct irs_gr *gr;
if (!net_data || !(gr = net_data->gr))
return (NULL);
if (net_data->gr_stayopen && net_data->gr_last &&
(gid_t)net_data->gr_last->gr_gid == gid)
return (net_data->gr_last);
net_data->gr_last = (*gr->bygid)(gr, gid);
if (!net_data->gr_stayopen)
endgrent();
return (net_data->gr_last);
}
int
setgroupent_p(int stayopen, struct net_data *net_data) {
struct irs_gr *gr;
if (!net_data || !(gr = net_data->gr))
return (0);
(*gr->rewind)(gr);
net_data->gr_stayopen = (stayopen != 0);
if (stayopen == 0)
net_data_minimize(net_data);
return (1);
}
#ifdef SETGRENT_VOID
void
setgrent_p(struct net_data *net_data) {
(void)setgroupent_p(0, net_data);
}
#else
int
setgrent_p(struct net_data *net_data) {
return (setgroupent_p(0, net_data));
}
#endif /* SETGRENT_VOID */
void
endgrent_p(struct net_data *net_data) {
struct irs_gr *gr;
if ((net_data != NULL) && ((gr = net_data->gr) != NULL))
(*gr->minimize)(gr);
}
int
getgrouplist_p(const char *name, gid_t basegid, gid_t *groups, int *ngroups,
struct net_data *net_data) {
struct irs_gr *gr;
if (!net_data || !(gr = net_data->gr)) {
*ngroups = 0;
return (-1);
}
return ((*gr->list)(gr, name, basegid, groups, ngroups));
}
/* Private */
static struct net_data *
init() {
struct net_data *net_data;
if (!(net_data = net_data_init(NULL)))
goto error;
if (!net_data->gr) {
net_data->gr = (*net_data->irs->gr_map)(net_data->irs);
if (!net_data->gr || !net_data->res) {
error:
errno = EIO;
return (NULL);
}
(*net_data->gr->res_set)(net_data->gr, net_data->res,
NULL);
}
return (net_data);
}
#endif /* WANT_IRS_GR */

View File

@ -1,229 +0,0 @@
/*
* Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
* Copyright (c) 1998-1999 by Internet Software Consortium.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#if defined(LIBC_SCCS) && !defined(lint)
static const char rcsid[] = "$Id$";
#endif /* LIBC_SCCS and not lint */
#include <port_before.h>
#if !defined(_REENTRANT) || !defined(DO_PTHREADS) || !defined(WANT_IRS_PW)
static int getgrent_r_not_required = 0;
#else
#include <errno.h>
#include <string.h>
#include <stdio.h>
#include <sys/types.h>
#if (defined(POSIX_GETGRNAM_R) || defined(POSIX_GETGRGID_R)) && \
defined(_POSIX_PTHREAD_SEMANTICS)
/* turn off solaris remapping in <grp.h> */
#define _UNIX95
#undef _POSIX_PTHREAD_SEMANTICS
#include <grp.h>
#define _POSIX_PTHREAD_SEMANTICS 1
#else
#include <grp.h>
#endif
#include <sys/param.h>
#include <port_after.h>
#ifdef GROUP_R_RETURN
static int
copy_group(struct group *, struct group *, char *buf, int buflen);
/* POSIX 1003.1c */
#ifdef POSIX_GETGRNAM_R
int
__posix_getgrnam_r(const char *name, struct group *gptr,
char *buf, int buflen, struct group **result) {
#else
int
getgrnam_r(const char *name, struct group *gptr,
char *buf, size_t buflen, struct group **result) {
#endif
struct group *ge = getgrnam(name);
int res;
if (ge == NULL) {
*result = NULL;
return (0);
}
res = copy_group(ge, gptr, buf, buflen);
*result = res ? NULL : gptr;
return (res);
}
#ifdef POSIX_GETGRNAM_R
struct group *
getgrnam_r(const char *name, struct group *gptr,
char *buf, int buflen) {
struct group *ge = getgrnam(name);
int res;
if (ge == NULL)
return (NULL);
res = copy_group(ge, gptr, buf, buflen);
return (res ? NULL : gptr);
}
#endif /* POSIX_GETGRNAM_R */
/* POSIX 1003.1c */
#ifdef POSIX_GETGRGID_R
int
__posix_getgrgid_r(gid_t gid, struct group *gptr,
char *buf, int buflen, struct group **result) {
#else /* POSIX_GETGRGID_R */
int
getgrgid_r(gid_t gid, struct group *gptr,
char *buf, size_t buflen, struct group **result) {
#endif /* POSIX_GETGRGID_R */
struct group *ge = getgrgid(gid);
int res;
if (ge == NULL) {
*result = NULL;
return (0);
}
res = copy_group(ge, gptr, buf, buflen);
*result = res ? NULL : gptr;
return (res);
}
#ifdef POSIX_GETGRGID_R
struct group *
getgrgid_r(gid_t gid, struct group *gptr,
char *buf, int buflen) {
struct group *ge = getgrgid(gid);
int res;
if (ge == NULL)
return (NULL);
res = copy_group(ge, gptr, buf, buflen);
return (res ? NULL : gptr);
}
#endif
/*
* These assume a single context is in operation per thread.
* If this is not the case we will need to call irs directly
* rather than through the base functions.
*/
GROUP_R_RETURN
getgrent_r(struct group *gptr, GROUP_R_ARGS) {
struct group *ge = getgrent();
int res;
if (ge == NULL) {
return (GROUP_R_BAD);
}
res = copy_group(ge, gptr, buf, buflen);
return (res ? GROUP_R_BAD : GROUP_R_OK);
}
GROUP_R_SET_RETURN
setgrent_r(GROUP_R_ENT_ARGS) {
setgrent();
#ifdef GROUP_R_SET_RESULT
return (GROUP_R_SET_RESULT);
#endif
}
GROUP_R_END_RETURN
endgrent_r(GROUP_R_ENT_ARGS) {
endgrent();
GROUP_R_END_RESULT(GROUP_R_OK);
}
#if 0
/* XXX irs does not have a fgetgrent() */
GROUP_R_RETURN
fgetgrent_r(FILE *f, struct group *gptr, GROUP_R_ARGS) {
struct group *ge = fgetgrent(f);
int res;
if (ge == NULL)
return (GROUP_R_BAD);
res = copy_group(ge, gptr, buf, buflen);
return (res ? GROUP_R_BAD : GROUP_R_OK);
}
#endif
/* Private */
static int
copy_group(struct group *ge, struct group *gptr, char *buf, int buflen) {
char *cp;
int i, n;
int numptr, len;
/* Find out the amount of space required to store the answer. */
numptr = 1; /* NULL ptr */
len = (char *)ALIGN(buf) - buf;
for (i = 0; ge->gr_mem[i]; i++, numptr++) {
len += strlen(ge->gr_mem[i]) + 1;
}
len += strlen(ge->gr_name) + 1;
len += strlen(ge->gr_passwd) + 1;
len += numptr * sizeof(char*);
if (len > buflen) {
errno = ERANGE;
return (ERANGE);
}
/* copy group id */
gptr->gr_gid = ge->gr_gid;
cp = (char *)ALIGN(buf) + numptr * sizeof(char *);
/* copy official name */
n = strlen(ge->gr_name) + 1;
strcpy(cp, ge->gr_name);
gptr->gr_name = cp;
cp += n;
/* copy member list */
gptr->gr_mem = (char **)ALIGN(buf);
for (i = 0 ; ge->gr_mem[i]; i++) {
n = strlen(ge->gr_mem[i]) + 1;
strcpy(cp, ge->gr_mem[i]);
gptr->gr_mem[i] = cp;
cp += n;
}
gptr->gr_mem[i] = NULL;
/* copy password */
n = strlen(ge->gr_passwd) + 1;
strcpy(cp, ge->gr_passwd);
gptr->gr_passwd = cp;
cp += n;
return (0);
}
#else /* GROUP_R_RETURN */
static int getgrent_r_unknown_system = 0;
#endif /* GROUP_R_RETURN */
#endif /* !def(_REENTRANT) || !def(DO_PTHREADS) || !def(WANT_IRS_PW) */

View File

@ -1,200 +0,0 @@
/*
* Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
* Copyright (c) 1996,1999 by Internet Software Consortium.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#if !defined(LINT) && !defined(CODECENTER)
static const char rcsid[] = "$Id$";
#endif
/* Imports */
#include "port_before.h"
#if !defined(WANT_IRS_PW) || defined(__BIND_NOSTATIC)
static int __bind_irs_pw_unneeded;
#else
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/nameser.h>
#include <errno.h>
#include <pwd.h>
#include <resolv.h>
#include <stdio.h>
#include <string.h>
#include <irs.h>
#include "port_after.h"
#include "irs_data.h"
/* Forward */
static struct net_data * init(void);
/* Public */
struct passwd *
getpwent(void) {
struct net_data *net_data = init();
return (getpwent_p(net_data));
}
struct passwd *
getpwnam(const char *name) {
struct net_data *net_data = init();
return (getpwnam_p(name, net_data));
}
struct passwd *
getpwuid(uid_t uid) {
struct net_data *net_data = init();
return (getpwuid_p(uid, net_data));
}
int
setpassent(int stayopen) {
struct net_data *net_data = init();
return (setpassent_p(stayopen, net_data));
}
#ifdef SETPWENT_VOID
void
setpwent() {
struct net_data *net_data = init();
setpwent_p(net_data);
}
#else
int
setpwent() {
struct net_data *net_data = init();
return (setpwent_p(net_data));
}
#endif
void
endpwent() {
struct net_data *net_data = init();
endpwent_p(net_data);
}
/* Shared private. */
struct passwd *
getpwent_p(struct net_data *net_data) {
struct irs_pw *pw;
if (!net_data || !(pw = net_data->pw))
return (NULL);
net_data->pw_last = (*pw->next)(pw);
return (net_data->pw_last);
}
struct passwd *
getpwnam_p(const char *name, struct net_data *net_data) {
struct irs_pw *pw;
if (!net_data || !(pw = net_data->pw))
return (NULL);
if (net_data->pw_stayopen && net_data->pw_last &&
!strcmp(net_data->pw_last->pw_name, name))
return (net_data->pw_last);
net_data->pw_last = (*pw->byname)(pw, name);
if (!net_data->pw_stayopen)
endpwent();
return (net_data->pw_last);
}
struct passwd *
getpwuid_p(uid_t uid, struct net_data *net_data) {
struct irs_pw *pw;
if (!net_data || !(pw = net_data->pw))
return (NULL);
if (net_data->pw_stayopen && net_data->pw_last &&
net_data->pw_last->pw_uid == uid)
return (net_data->pw_last);
net_data->pw_last = (*pw->byuid)(pw, uid);
if (!net_data->pw_stayopen)
endpwent();
return (net_data->pw_last);
}
int
setpassent_p(int stayopen, struct net_data *net_data) {
struct irs_pw *pw;
if (!net_data || !(pw = net_data->pw))
return (0);
(*pw->rewind)(pw);
net_data->pw_stayopen = (stayopen != 0);
if (stayopen == 0)
net_data_minimize(net_data);
return (1);
}
#ifdef SETPWENT_VOID
void
setpwent_p(struct net_data *net_data) {
(void) setpassent_p(0, net_data);
}
#else
int
setpwent_p(struct net_data *net_data) {
return (setpassent_p(0, net_data));
}
#endif
void
endpwent_p(struct net_data *net_data) {
struct irs_pw *pw;
if ((net_data != NULL) && ((pw = net_data->pw) != NULL))
(*pw->minimize)(pw);
}
/* Private */
static struct net_data *
init() {
struct net_data *net_data;
if (!(net_data = net_data_init(NULL)))
goto error;
if (!net_data->pw) {
net_data->pw = (*net_data->irs->pw_map)(net_data->irs);
if (!net_data->pw || !net_data->res) {
error:
errno = EIO;
return (NULL);
}
(*net_data->pw->res_set)(net_data->pw, net_data->res, NULL);
}
return (net_data);
}
#endif /* WANT_IRS_PW */

View File

@ -1,275 +0,0 @@
/*
* Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
* Copyright (c) 1998-1999 by Internet Software Consortium.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#if defined(LIBC_SCCS) && !defined(lint)
static const char rcsid[] = "$Id$";
#endif /* LIBC_SCCS and not lint */
#include <port_before.h>
#if !defined(_REENTRANT) || !defined(DO_PTHREADS) || !defined(WANT_IRS_PW)
static int getpwent_r_not_required = 0;
#else
#include <errno.h>
#include <string.h>
#include <stdio.h>
#include <sys/types.h>
#if (defined(POSIX_GETPWNAM_R) || defined(POSIX_GETPWUID_R))
#if defined(_POSIX_PTHREAD_SEMANTICS)
/* turn off solaris remapping in <grp.h> */
#undef _POSIX_PTHREAD_SEMANTICS
#include <pwd.h>
#define _POSIX_PTHREAD_SEMANTICS 1
#else
#define _UNIX95 1
#include <pwd.h>
#endif
#else
#include <pwd.h>
#endif
#include <port_after.h>
#ifdef PASS_R_RETURN
static int
copy_passwd(struct passwd *, struct passwd *, char *buf, int buflen);
/* POSIX 1003.1c */
#ifdef POSIX_GETPWNAM_R
int
__posix_getpwnam_r(const char *login, struct passwd *pwptr,
char *buf, size_t buflen, struct passwd **result) {
#else
int
getpwnam_r(const char *login, struct passwd *pwptr,
char *buf, size_t buflen, struct passwd **result) {
#endif
struct passwd *pw = getpwnam(login);
int res;
if (pw == NULL) {
*result = NULL;
return (0);
}
res = copy_passwd(pw, pwptr, buf, buflen);
*result = res ? NULL : pwptr;
return (res);
}
#ifdef POSIX_GETPWNAM_R
struct passwd *
getpwnam_r(const char *login, struct passwd *pwptr, char *buf, int buflen) {
struct passwd *pw = getpwnam(login);
int res;
if (pw == NULL)
return (NULL);
res = copy_passwd(pw, pwptr, buf, buflen);
return (res ? NULL : pwptr);
}
#endif
/* POSIX 1003.1c */
#ifdef POSIX_GETPWUID_R
int
__posix_getpwuid_r(uid_t uid, struct passwd *pwptr,
char *buf, int buflen, struct passwd **result) {
#else
int
getpwuid_r(uid_t uid, struct passwd *pwptr,
char *buf, size_t buflen, struct passwd **result) {
#endif
struct passwd *pw = getpwuid(uid);
int res;
if (pw == NULL) {
*result = NULL;
return (0);
}
res = copy_passwd(pw, pwptr, buf, buflen);
*result = res ? NULL : pwptr;
return (res);
}
#ifdef POSIX_GETPWUID_R
struct passwd *
getpwuid_r(uid_t uid, struct passwd *pwptr, char *buf, int buflen) {
struct passwd *pw = getpwuid(uid);
int res;
if (pw == NULL)
return (NULL);
res = copy_passwd(pw, pwptr, buf, buflen);
return (res ? NULL : pwptr);
}
#endif
/*
* These assume a single context is in operation per thread.
* If this is not the case we will need to call irs directly
* rather than through the base functions.
*/
PASS_R_RETURN
getpwent_r(struct passwd *pwptr, PASS_R_ARGS) {
struct passwd *pw = getpwent();
int res = 0;
if (pw == NULL)
return (PASS_R_BAD);
res = copy_passwd(pw, pwptr, buf, buflen);
return (res ? PASS_R_BAD : PASS_R_OK);
}
PASS_R_SET_RETURN
#ifdef PASS_R_ENT_ARGS
setpassent_r(int stayopen, PASS_R_ENT_ARGS)
#else
setpassent_r(int stayopen)
#endif
{
setpassent(stayopen);
#ifdef PASS_R_SET_RESULT
return (PASS_R_SET_RESULT);
#endif
}
PASS_R_SET_RETURN
#ifdef PASS_R_ENT_ARGS
setpwent_r(PASS_R_ENT_ARGS)
#else
setpwent_r(void)
#endif
{
setpwent();
#ifdef PASS_R_SET_RESULT
return (PASS_R_SET_RESULT);
#endif
}
PASS_R_END_RETURN
#ifdef PASS_R_ENT_ARGS
endpwent_r(PASS_R_ENT_ARGS)
#else
endpwent_r(void)
#endif
{
endpwent();
PASS_R_END_RESULT(PASS_R_OK);
}
#ifdef HAS_FGETPWENT
PASS_R_RETURN
fgetpwent_r(FILE *f, struct passwd *pwptr, PASS_R_COPY_ARGS) {
struct passwd *pw = fgetpwent(f);
int res = 0;
if (pw == NULL)
return (PASS_R_BAD);
res = copy_passwd(pw, pwptr, PASS_R_COPY);
return (res ? PASS_R_BAD : PASS_R_OK );
}
#endif
/* Private */
static int
copy_passwd(struct passwd *pw, struct passwd *pwptr, char *buf, int buflen) {
char *cp;
int n;
int len;
/* Find out the amount of space required to store the answer. */
len = strlen(pw->pw_name) + 1;
len += strlen(pw->pw_passwd) + 1;
#ifdef HAVE_PW_CLASS
len += strlen(pw->pw_class) + 1;
#endif
len += strlen(pw->pw_gecos) + 1;
len += strlen(pw->pw_dir) + 1;
len += strlen(pw->pw_shell) + 1;
if (len > buflen) {
errno = ERANGE;
return (ERANGE);
}
/* copy fixed atomic values*/
pwptr->pw_uid = pw->pw_uid;
pwptr->pw_gid = pw->pw_gid;
#ifdef HAVE_PW_CHANGE
pwptr->pw_change = pw->pw_change;
#endif
#ifdef HAVE_PW_EXPIRE
pwptr->pw_expire = pw->pw_expire;
#endif
cp = buf;
/* copy official name */
n = strlen(pw->pw_name) + 1;
strcpy(cp, pw->pw_name);
pwptr->pw_name = cp;
cp += n;
/* copy password */
n = strlen(pw->pw_passwd) + 1;
strcpy(cp, pw->pw_passwd);
pwptr->pw_passwd = cp;
cp += n;
#ifdef HAVE_PW_CLASS
/* copy class */
n = strlen(pw->pw_class) + 1;
strcpy(cp, pw->pw_class);
pwptr->pw_class = cp;
cp += n;
#endif
/* copy gecos */
n = strlen(pw->pw_gecos) + 1;
strcpy(cp, pw->pw_gecos);
pwptr->pw_gecos = cp;
cp += n;
/* copy directory */
n = strlen(pw->pw_dir) + 1;
strcpy(cp, pw->pw_dir);
pwptr->pw_dir = cp;
cp += n;
/* copy login shell */
n = strlen(pw->pw_shell) + 1;
strcpy(cp, pw->pw_shell);
pwptr->pw_shell = cp;
cp += n;
return (0);
}
#else /* PASS_R_RETURN */
static int getpwent_r_unknown_system = 0;
#endif /* PASS_R_RETURN */
#endif /* !def(_REENTRANT) || !def(DO_PTHREADS) || !def(WANT_IRS_PW) */

View File

@ -1,408 +0,0 @@
/*
* Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
* Portions Copyright(c) 1996, 1998 by Internet Software Consortium.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#if defined(LIBC_SCCS) && !defined(lint)
static const char rcsid[] = "$Id$";
#endif /* LIBC_SCCS and not lint */
/* extern */
#include "port_before.h"
#ifndef WANT_IRS_PW
static int __bind_irs_gr_unneeded;
#else
#include <syslog.h>
#include <sys/param.h>
#include <sys/types.h>
#include <errno.h>
#include <fcntl.h>
#include <grp.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <syslog.h>
#include <irs.h>
#include <irp.h>
#include <isc/memcluster.h>
#include <isc/irpmarshall.h>
#include "irs_p.h"
#include "lcl_p.h"
#include "irp_p.h"
#include "port_after.h"
/* Types. */
/*
* Module for the getnetgrent(3) family to use when connected to a
* remote irp daemon.
*
* See irpd.c for justification of caching done here.
*
*/
struct pvt {
struct irp_p *girpdata; /* global IRP data */
int warned;
struct group group;
};
/* Forward. */
static void gr_close(struct irs_gr *);
static struct group * gr_next(struct irs_gr *);
static struct group * gr_byname(struct irs_gr *, const char *);
static struct group * gr_bygid(struct irs_gr *, gid_t);
static void gr_rewind(struct irs_gr *);
static void gr_minimize(struct irs_gr *);
/* Private */
static void free_group(struct group *gr);
/* Public. */
/*
* struct irs_gr * irs_irp_gr(struct irs_acc *this)
*
* Notes:
*
* Initialize the group sub-module.
*
* Notes:
*
* Module data.
*
*/
struct irs_gr *
irs_irp_gr(struct irs_acc *this) {
struct irs_gr *gr;
struct pvt *pvt;
if (!(gr = memget(sizeof *gr))) {
errno = ENOMEM;
return (NULL);
}
memset(gr, 0x0, sizeof *gr);
if (!(pvt = memget(sizeof *pvt))) {
memput(gr, sizeof *gr);
errno = ENOMEM;
return (NULL);
}
memset(pvt, 0x0, sizeof *pvt);
pvt->girpdata = this->private;
gr->private = pvt;
gr->close = gr_close;
gr->next = gr_next;
gr->byname = gr_byname;
gr->bygid = gr_bygid;
gr->rewind = gr_rewind;
gr->list = make_group_list;
gr->minimize = gr_minimize;
return (gr);
}
/* Methods. */
/*
* void gr_close(struct irs_gr *this)
*
* Notes:
*
* Close the sub-module.
*
*/
static void
gr_close(struct irs_gr *this) {
struct pvt *pvt = (struct pvt *)this->private;
gr_minimize(this);
memput(pvt, sizeof *pvt);
memput(this, sizeof *this);
}
/*
* struct group * gr_next(struct irs_gr *this)
*
* Notes:
*
* Gets the next group out of the cached data and returns it.
*
*/
static struct group *
gr_next(struct irs_gr *this) {
struct pvt *pvt = (struct pvt *)this->private;
struct group *gr = &pvt->group;
char *body;
size_t bodylen;
int code;
char text[256];
if (irs_irp_connection_setup(pvt->girpdata, &pvt->warned) != 0) {
return (NULL);
}
if (irs_irp_send_command(pvt->girpdata, "getgrent") != 0) {
return (NULL);
}
if (irs_irp_get_full_response(pvt->girpdata, &code,
text, sizeof text,
&body, &bodylen) != 0) {
if (irp_log_errors) {
syslog(LOG_WARNING, "getgrent failed: %s", text);
}
return (NULL);
}
if (code == IRPD_GETGROUP_OK) {
free_group(gr);
if (irp_unmarshall_gr(gr, body) != 0) {
gr = NULL;
}
} else {
gr = NULL;
}
if (body != NULL) {
memput(body, bodylen);
}
return (gr);
}
/*
* struct group * gr_byname(struct irs_gr *this, const char *name)
*
* Notes:
*
* Gets a group by name from irpd and returns it.
*
*/
static struct group *
gr_byname(struct irs_gr *this, const char *name) {
struct pvt *pvt = (struct pvt *)this->private;
struct group *gr = &pvt->group;
char *body;
size_t bodylen;
int code;
char text[256];
if (gr->gr_name != NULL && strcmp(name, gr->gr_name) == 0) {
return (gr);
}
if (irs_irp_connection_setup(pvt->girpdata, &pvt->warned) != 0) {
return (NULL);
}
if (irs_irp_send_command(pvt->girpdata, "getgrnam %s", name) != 0)
return (NULL);
if (irs_irp_get_full_response(pvt->girpdata, &code,
text, sizeof text,
&body, &bodylen) != 0) {
return (NULL);
}
if (code == IRPD_GETGROUP_OK) {
free_group(gr);
if (irp_unmarshall_gr(gr, body) != 0) {
gr = NULL;
}
} else {
gr = NULL;
}
if (body != NULL) {
memput(body, bodylen);
}
return (gr);
}
/*
* struct group * gr_bygid(struct irs_gr *this, gid_t gid)
*
* Notes:
*
* Gets a group by gid from irpd and returns it.
*
*/
static struct group *
gr_bygid(struct irs_gr *this, gid_t gid) {
struct pvt *pvt = (struct pvt *)this->private;
struct group *gr = &pvt->group;
char *body;
size_t bodylen;
int code;
char text[256];
if (gr->gr_name != NULL && (gid_t)gr->gr_gid == gid) {
return (gr);
}
if (irs_irp_connection_setup(pvt->girpdata, &pvt->warned) != 0) {
return (NULL);
}
if (irs_irp_send_command(pvt->girpdata, "getgrgid %d", gid) != 0)
return (NULL);
if (irs_irp_get_full_response(pvt->girpdata, &code,
text, sizeof text,
&body, &bodylen) != 0) {
return (NULL);
}
if (code == IRPD_GETGROUP_OK) {
free_group(gr);
if (irp_unmarshall_gr(gr, body) != 0) {
gr = NULL;
}
} else {
gr = NULL;
}
if (body != NULL) {
memput(body, bodylen);
}
return (gr);
}
/*
* void gr_rewind(struct irs_gr *this)
*
*/
static void
gr_rewind(struct irs_gr *this) {
struct pvt *pvt = (struct pvt *)this->private;
char text[256];
int code;
if (irs_irp_connection_setup(pvt->girpdata, &pvt->warned) != 0) {
return;
}
if (irs_irp_send_command(pvt->girpdata, "setgrent") != 0) {
return;
}
code = irs_irp_read_response(pvt->girpdata, text, sizeof text);
if (code != IRPD_GETGROUP_SETOK) {
if (irp_log_errors) {
syslog(LOG_WARNING, "setgrent failed: %s", text);
}
}
return;
}
/*
* void gr_minimize(struct irs_gr *this)
*
* Notes:
*
* Frees up cached data and disconnects(if necessary) from the remote.
*
*/
static void
gr_minimize(struct irs_gr *this) {
struct pvt *pvt = (struct pvt *)this->private;
free_group(&pvt->group);
irs_irp_disconnect(pvt->girpdata);
}
/* Private. */
/*
* static void free_group(struct group *gr);
*
* Deallocate all the memory irp_unmarshall_gr allocated.
*
*/
static void
free_group(struct group *gr) {
char **p;
if (gr == NULL)
return;
if (gr->gr_name != NULL)
free(gr->gr_name);
if (gr->gr_passwd != NULL)
free(gr->gr_passwd);
for (p = gr->gr_mem ; p != NULL && *p != NULL ; p++)
free(*p);
if (gr->gr_mem)
free(gr->gr_mem);
if (p != NULL)
free(p);
}
#endif /* WANT_IRS_GR */

View File

@ -1,358 +0,0 @@
/*
* Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
* Portions Copyright (c) 1996 by Internet Software Consortium.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#if defined(LIBC_SCCS) && !defined(lint)
static const char rcsid[] = "$Id$";
#endif /* LIBC_SCCS and not lint */
/* Extern */
#include "port_before.h"
#ifndef WANT_IRS_PW
static int __bind_irs_pw_unneeded;
#else
#include <syslog.h>
#include <sys/param.h>
#include <db.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <pwd.h>
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
#include <utmp.h>
#include <unistd.h>
#include <irs.h>
#include <irp.h>
#include <isc/memcluster.h>
#include <isc/irpmarshall.h>
#include "port_after.h"
#include "irs_p.h"
#include "irp_p.h"
/* Types */
struct pvt {
struct irp_p *girpdata; /* global IRP data */
int warned;
struct passwd passwd; /* password structure */
};
/* Forward */
static void pw_close(struct irs_pw *);
static struct passwd * pw_next(struct irs_pw *);
static struct passwd * pw_byname(struct irs_pw *, const char *);
static struct passwd * pw_byuid(struct irs_pw *, uid_t);
static void pw_rewind(struct irs_pw *);
static void pw_minimize(struct irs_pw *);
static void free_passwd(struct passwd *pw);
/* Public */
struct irs_pw *
irs_irp_pw(struct irs_acc *this) {
struct irs_pw *pw;
struct pvt *pvt;
if (!(pw = memget(sizeof *pw))) {
errno = ENOMEM;
return (NULL);
}
memset(pw, 0, sizeof *pw);
if (!(pvt = memget(sizeof *pvt))) {
memput(pw, sizeof *pw);
errno = ENOMEM;
return (NULL);
}
memset(pvt, 0, sizeof *pvt);
pvt->girpdata = this->private;
pw->private = pvt;
pw->close = pw_close;
pw->next = pw_next;
pw->byname = pw_byname;
pw->byuid = pw_byuid;
pw->rewind = pw_rewind;
pw->minimize = pw_minimize;
return (pw);
}
/* Methods */
/*
* void pw_close(struct irs_pw *this)
*
*/
static void
pw_close(struct irs_pw *this) {
struct pvt *pvt = (struct pvt *)this->private;
pw_minimize(this);
free_passwd(&pvt->passwd);
memput(pvt, sizeof *pvt);
memput(this, sizeof *this);
}
/*
* struct passwd * pw_next(struct irs_pw *this)
*
*/
static struct passwd *
pw_next(struct irs_pw *this) {
struct pvt *pvt = (struct pvt *)this->private;
struct passwd *pw = &pvt->passwd;
char *body;
size_t bodylen;
int code;
char text[256];
if (irs_irp_connection_setup(pvt->girpdata, &pvt->warned) != 0) {
return (NULL);
}
if (irs_irp_send_command(pvt->girpdata, "getpwent") != 0) {
return (NULL);
}
if (irs_irp_get_full_response(pvt->girpdata, &code,
text, sizeof text,
&body, &bodylen) != 0) {
return (NULL);
}
if (code == IRPD_GETUSER_OK) {
free_passwd(pw);
if (irp_unmarshall_pw(pw, body) != 0) {
pw = NULL;
}
} else {
pw = NULL;
}
if (body != NULL) {
memput(body, bodylen);
}
return (pw);
}
/*
* struct passwd * pw_byname(struct irs_pw *this, const char *name)
*
*/
static struct passwd *
pw_byname(struct irs_pw *this, const char *name) {
struct pvt *pvt = (struct pvt *)this->private;
struct passwd *pw = &pvt->passwd;
char *body = NULL;
char text[256];
size_t bodylen;
int code;
if (pw->pw_name != NULL && strcmp(name, pw->pw_name) == 0) {
return (pw);
}
if (irs_irp_connection_setup(pvt->girpdata, &pvt->warned) != 0) {
return (NULL);
}
if (irs_irp_send_command(pvt->girpdata, "getpwnam %s", name) != 0) {
return (NULL);
}
if (irs_irp_get_full_response(pvt->girpdata, &code,
text, sizeof text,
&body, &bodylen) != 0) {
return (NULL);
}
if (code == IRPD_GETUSER_OK) {
free_passwd(pw);
if (irp_unmarshall_pw(pw, body) != 0) {
pw = NULL;
}
} else {
pw = NULL;
}
if (body != NULL) {
memput(body, bodylen);
}
return (pw);
}
/*
* struct passwd * pw_byuid(struct irs_pw *this, uid_t uid)
*
*/
static struct passwd *
pw_byuid(struct irs_pw *this, uid_t uid) {
struct pvt *pvt = (struct pvt *)this->private;
char *body;
char text[256];
size_t bodylen;
int code;
struct passwd *pw = &pvt->passwd;
if (pw->pw_name != NULL && pw->pw_uid == uid) {
return (pw);
}
if (irs_irp_connection_setup(pvt->girpdata, &pvt->warned) != 0) {
return (NULL);
}
if (irs_irp_send_command(pvt->girpdata, "getpwuid %d", uid) != 0) {
return (NULL);
}
if (irs_irp_get_full_response(pvt->girpdata, &code,
text, sizeof text,
&body, &bodylen) != 0) {
return (NULL);
}
if (code == IRPD_GETUSER_OK) {
free_passwd(pw);
if (irp_unmarshall_pw(pw, body) != 0) {
pw = NULL;
}
} else {
pw = NULL;
}
if (body != NULL) {
memput(body, bodylen);
}
return (pw);
}
/*
* void pw_rewind(struct irs_pw *this)
*
*/
static void
pw_rewind(struct irs_pw *this) {
struct pvt *pvt = (struct pvt *)this->private;
char text[256];
int code;
if (irs_irp_connection_setup(pvt->girpdata, &pvt->warned) != 0) {
return;
}
if (irs_irp_send_command(pvt->girpdata, "setpwent") != 0) {
return;
}
code = irs_irp_read_response(pvt->girpdata, text, sizeof text);
if (code != IRPD_GETUSER_SETOK) {
if (irp_log_errors) {
syslog(LOG_WARNING, "setpwent failed: %s", text);
}
}
return;
}
/*
* void pw_minimize(struct irs_pw *this)
*
*/
static void
pw_minimize(struct irs_pw *this) {
struct pvt *pvt = (struct pvt *)this->private;
irs_irp_disconnect(pvt->girpdata);
}
/* Private. */
/*
* static void free_passwd(struct passwd *pw);
*
* Deallocate all the memory irp_unmarshall_pw allocated.
*
*/
static void
free_passwd(struct passwd *pw) {
if (pw == NULL)
return;
if (pw->pw_name != NULL)
free(pw->pw_name);
if (pw->pw_passwd != NULL)
free(pw->pw_passwd);
#ifdef HAVE_PW_CLASS
if (pw->pw_class != NULL)
free(pw->pw_class);
#endif
if (pw->pw_gecos != NULL)
free(pw->pw_gecos);
if (pw->pw_dir != NULL)
free(pw->pw_dir);
if (pw->pw_shell != NULL)
free(pw->pw_shell);
}
#endif /* WANT_IRS_PW */

View File

@ -52,8 +52,7 @@ extern int h_errno;
extern struct __res_state _res;
#ifdef DO_PTHREADS
static pthread_key_t key;
static int once = 0;
pthread_key_t gIRSInitKey;
#else
static struct net_data *net_data;
#endif
@ -124,31 +123,21 @@ net_data_init(const char *conf_file) {
#ifndef LIBBIND_MUTEX_INITIALIZER
#define LIBBIND_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
#endif
static pthread_mutex_t keylock;
struct net_data *net_data;
if (!once) {
/* XXX: Haiku has non-constant mutex initializer! Must init here. */
keylock = LIBBIND_MUTEX_INITIALIZER;
pthread_mutex_lock(&keylock);
if (!once++)
key = tls_allocate();
pthread_mutex_unlock(&keylock);
}
net_data = tls_get(key);
net_data = tls_get(gIRSInitKey);
#endif
if (net_data == NULL) {
net_data = net_data_create(conf_file);
if (net_data == NULL)
return (NULL);
#ifdef DO_PTHREADS
on_exit_thread(net_data_destroy, net_data);
tls_set(key, net_data);
tls_set(gIRSInitKey, net_data);
#endif
}
return (net_data);
}

View File

@ -1,354 +0,0 @@
/*
* Copyright (c) 1989, 1993, 1995
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/*
* Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
* Portions Copyright (c) 1996-1999 by Internet Software Consortium.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#if defined(LIBC_SCCS) && !defined(lint)
static const char rcsid[] = "$Id$";
/* from getgrent.c 8.2 (Berkeley) 3/21/94"; */
/* from BSDI Id: getgrent.c,v 2.8 1996/05/28 18:15:14 bostic Exp $ */
#endif /* LIBC_SCCS and not lint */
/* extern */
#include "port_before.h"
#ifndef WANT_IRS_PW
static int __bind_irs_gr_unneeded;
#else
#include <sys/param.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/nameser.h>
#include <resolv.h>
#include <errno.h>
#include <fcntl.h>
#include <grp.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <irs.h>
#include <isc/memcluster.h>
#include "irs_p.h"
#include "lcl_p.h"
#include "irp_p.h"
#include "port_after.h"
/* Types. */
struct pvt {
FILE * fp;
/*
* Need space to store the entries read from the group file.
* The members list also needs space per member, and the
* strings making up the user names must be allocated
* somewhere. Rather than doing lots of small allocations,
* we keep one buffer and resize it as needed.
*/
struct group group;
size_t nmemb; /* Malloc'd max index of gr_mem[]. */
char * membuf;
size_t membufsize;
};
/* Forward. */
static void gr_close(struct irs_gr *);
static struct group * gr_next(struct irs_gr *);
static struct group * gr_byname(struct irs_gr *, const char *);
static struct group * gr_bygid(struct irs_gr *, gid_t);
static void gr_rewind(struct irs_gr *);
static void gr_minimize(struct irs_gr *);
static int grstart(struct pvt *);
static char * grnext(struct pvt *);
static struct group * grscan(struct irs_gr *, int, gid_t, const char *);
/* Portability. */
#ifndef SEEK_SET
# define SEEK_SET 0
#endif
/* Public. */
struct irs_gr *
irs_lcl_gr(struct irs_acc *this) {
struct irs_gr *gr;
struct pvt *pvt;
UNUSED(this);
if (!(gr = memget(sizeof *gr))) {
errno = ENOMEM;
return (NULL);
}
memset(gr, 0x5e, sizeof *gr);
if (!(pvt = memget(sizeof *pvt))) {
memput(gr, sizeof *gr);
errno = ENOMEM;
return (NULL);
}
memset(pvt, 0, sizeof *pvt);
gr->private = pvt;
gr->close = gr_close;
gr->next = gr_next;
gr->byname = gr_byname;
gr->bygid = gr_bygid;
gr->rewind = gr_rewind;
gr->list = make_group_list;
gr->minimize = gr_minimize;
gr->res_get = NULL;
gr->res_set = NULL;
return (gr);
}
/* Methods. */
static void
gr_close(struct irs_gr *this) {
struct pvt *pvt = (struct pvt *)this->private;
if (pvt->fp)
(void)fclose(pvt->fp);
if (pvt->group.gr_mem)
free(pvt->group.gr_mem);
if (pvt->membuf)
free(pvt->membuf);
memput(pvt, sizeof *pvt);
memput(this, sizeof *this);
}
static struct group *
gr_next(struct irs_gr *this) {
struct pvt *pvt = (struct pvt *)this->private;
if (!pvt->fp && !grstart(pvt))
return (NULL);
return (grscan(this, 0, 0, NULL));
}
static struct group *
gr_byname(struct irs_gr *this, const char *name) {
if (!grstart((struct pvt *)this->private))
return (NULL);
return (grscan(this, 1, 0, name));
}
static struct group *
gr_bygid(struct irs_gr *this, gid_t gid) {
if (!grstart((struct pvt *)this->private))
return (NULL);
return (grscan(this, 1, gid, NULL));
}
static void
gr_rewind(struct irs_gr *this) {
(void) grstart((struct pvt *)this->private);
}
static void
gr_minimize(struct irs_gr *this) {
struct pvt *pvt = (struct pvt *)this->private;
if (pvt->fp != NULL) {
(void)fclose(pvt->fp);
pvt->fp = NULL;
}
}
/* Private. */
static int
grstart(struct pvt *pvt) {
if (pvt->fp) {
if (fseek(pvt->fp, 0L, SEEK_SET) == 0)
return (1);
(void)fclose(pvt->fp);
}
if (!(pvt->fp = fopen(_PATH_GROUP, "r")))
return (0);
if (fcntl(fileno(pvt->fp), F_SETFD, 1) < 0) {
fclose(pvt->fp);
return (0);
}
return (1);
}
#define INITIAL_NMEMB 30 /* about 120 bytes */
#define INITIAL_BUFSIZ (INITIAL_NMEMB * 8) /* about 240 bytes */
static char *
grnext(struct pvt *pvt) {
char *w, *e;
int ch;
/* Make sure we have a buffer. */
if (pvt->membuf == NULL) {
pvt->membuf = malloc(INITIAL_BUFSIZ);
if (pvt->membuf == NULL) {
enomem:
errno = ENOMEM;
return (NULL);
}
pvt->membufsize = INITIAL_BUFSIZ;
}
/* Read until EOF or EOL. */
w = pvt->membuf;
e = pvt->membuf + pvt->membufsize;
while ((ch = fgetc(pvt->fp)) != EOF && ch != '\n') {
/* Make sure we have room for this character and a \0. */
if (w + 1 == e) {
size_t o = w - pvt->membuf;
size_t n = pvt->membufsize * 2;
char *t = realloc(pvt->membuf, n);
if (t == NULL)
goto enomem;
pvt->membuf = t;
pvt->membufsize = n;
w = pvt->membuf + o;
e = pvt->membuf + pvt->membufsize;
}
/* Store it. */
*w++ = (char)ch;
}
/* Hitting EOF on the first character really does mean EOF. */
if (w == pvt->membuf && ch == EOF) {
errno = ENOENT;
return (NULL);
}
/* Last line of /etc/group need not end with \n; we don't care. */
*w = '\0';
return (pvt->membuf);
}
static struct group *
grscan(struct irs_gr *this, int search, gid_t gid, const char *name) {
struct pvt *pvt = (struct pvt *)this->private;
size_t n;
char *bp, **m, *p;
/* Read lines until we find one that matches our search criteria. */
for (;;) {
if ((bp = grnext(pvt)) == NULL)
return (NULL);
/* Optimize the usual case of searching for a name. */
pvt->group.gr_name = strsep(&bp, ":");
if (search && name != NULL &&
strcmp(pvt->group.gr_name, name) != 0)
continue;
if (bp == NULL || *bp == '\0')
goto corrupt;
/* Skip past the password field. */
pvt->group.gr_passwd = strsep(&bp, ":");
if (bp == NULL || *bp == '\0')
goto corrupt;
/* Checking for a gid. */
if ((p = strsep(&bp, ":")) == NULL)
continue;
/*
* Unlike the tests above, the test below is supposed to be
* testing 'p' and not 'bp', in case you think it's a typo.
*/
if (p == NULL || *p == '\0') {
corrupt:
/* warning: corrupted %s file!", _PATH_GROUP */
continue;
}
pvt->group.gr_gid = atoi(p);
if (search && name == NULL && (gid_t)pvt->group.gr_gid != gid)
continue;
/* We want this record. */
break;
}
/*
* Count commas to find out how many members there might be.
* Note that commas separate, so if there is one comma there
* can be two members (group:*:id:user1,user2). Add another
* to account for the NULL terminator. As above, allocate
* largest of INITIAL_NMEMB, or 2*n.
*/
n = 1;
if (bp != NULL)
for (n = 2, p = bp; (p = strpbrk(p, ", ")) != NULL; ++n)
p += strspn(p, ", ");
if (n > pvt->nmemb || pvt->group.gr_mem == NULL) {
if ((n *= 2) < INITIAL_NMEMB)
n = INITIAL_NMEMB;
if ((m = realloc(pvt->group.gr_mem, n * sizeof *m)) == NULL)
return (NULL);
pvt->group.gr_mem = m;
pvt->nmemb = n;
}
/* Set the name pointers. */
for (m = pvt->group.gr_mem; (p = strsep(&bp, ", ")) != NULL;)
if (p[0] != '\0')
*m++ = p;
*m = NULL;
return (&pvt->group);
}
#endif /* WANT_IRS_GR */

View File

@ -1,308 +0,0 @@
/*
* Copyright (c) 1989, 1993, 1995
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/*
* Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
* Portions Copyright (c) 1996,1999 by Internet Software Consortium.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#if defined(LIBC_SCCS) && !defined(lint)
static const char rcsid[] = "$Id$";
#endif /* LIBC_SCCS and not lint */
/* Extern */
#include "port_before.h"
#ifndef WANT_IRS_PW
static int __bind_irs_pw_unneeded;
#else
#include <sys/param.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/nameser.h>
#include <resolv.h>
#include <db.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <pwd.h>
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
#include <utmp.h>
#include <unistd.h>
#include <isc/memcluster.h>
#include <irs.h>
#include "port_after.h"
#include "irs_p.h"
#include "lcl_p.h"
/*
* The lookup techniques and data extraction code here must be kept
* in sync with that in `pwd_mkdb'.
*/
/* Types */
struct pvt {
struct passwd passwd; /* password structure */
DB *pw_db; /* password database */
int pw_keynum; /* key counter */
int warned;
u_int max;
char * line;
};
/* Forward */
static void pw_close(struct irs_pw *);
static struct passwd * pw_next(struct irs_pw *);
static struct passwd * pw_byname(struct irs_pw *, const char *);
static struct passwd * pw_byuid(struct irs_pw *, uid_t);
static void pw_rewind(struct irs_pw *);
static void pw_minimize(struct irs_pw *);
static int initdb(struct pvt *);
static int hashpw(struct irs_pw *, DBT *);
/* Public */
struct irs_pw *
irs_lcl_pw(struct irs_acc *this) {
struct irs_pw *pw;
struct pvt *pvt;
UNUSED(this);
if (!(pw = memget(sizeof *pw))) {
errno = ENOMEM;
return (NULL);
}
memset(pw, 0x5e, sizeof *pw);
if (!(pvt = memget(sizeof *pvt))) {
free(pw);
errno = ENOMEM;
return (NULL);
}
memset(pvt, 0, sizeof *pvt);
pw->private = pvt;
pw->close = pw_close;
pw->next = pw_next;
pw->byname = pw_byname;
pw->byuid = pw_byuid;
pw->rewind = pw_rewind;
pw->minimize = pw_minimize;
pw->res_get = NULL;
pw->res_set = NULL;
return (pw);
}
/* Methods */
static void
pw_close(struct irs_pw *this) {
struct pvt *pvt = (struct pvt *)this->private;
if (pvt->pw_db) {
(void)(pvt->pw_db->close)(pvt->pw_db);
pvt->pw_db = NULL;
}
if (pvt->line)
memput(pvt->line, pvt->max);
memput(pvt, sizeof *pvt);
memput(this, sizeof *this);
}
static struct passwd *
pw_next(struct irs_pw *this) {
struct pvt *pvt = (struct pvt *)this->private;
DBT key;
char bf[sizeof(pvt->pw_keynum) + 1];
if (!initdb(pvt))
return (NULL);
++pvt->pw_keynum;
bf[0] = _PW_KEYBYNUM;
memcpy(bf + 1, (char *)&pvt->pw_keynum, sizeof(pvt->pw_keynum));
key.data = (u_char *)bf;
key.size = sizeof(pvt->pw_keynum) + 1;
return (hashpw(this, &key) ? &pvt->passwd : NULL);
}
static struct passwd *
pw_byname(struct irs_pw *this, const char *name) {
struct pvt *pvt = (struct pvt *)this->private;
DBT key;
int len, rval;
char bf[UT_NAMESIZE + 1];
if (!initdb(pvt))
return (NULL);
bf[0] = _PW_KEYBYNAME;
len = strlen(name);
memcpy(bf + 1, name, MIN(len, UT_NAMESIZE));
key.data = (u_char *)bf;
key.size = len + 1;
rval = hashpw(this, &key);
return (rval ? &pvt->passwd : NULL);
}
static struct passwd *
pw_byuid(struct irs_pw *this, uid_t uid) {
struct pvt *pvt = (struct pvt *)this->private;
DBT key;
int keyuid, rval;
char bf[sizeof(keyuid) + 1];
if (!initdb(pvt))
return (NULL);
bf[0] = _PW_KEYBYUID;
keyuid = uid;
memcpy(bf + 1, &keyuid, sizeof(keyuid));
key.data = (u_char *)bf;
key.size = sizeof(keyuid) + 1;
rval = hashpw(this, &key);
return (rval ? &pvt->passwd : NULL);
}
static void
pw_rewind(struct irs_pw *this) {
struct pvt *pvt = (struct pvt *)this->private;
pvt->pw_keynum = 0;
}
static void
pw_minimize(struct irs_pw *this) {
struct pvt *pvt = (struct pvt *)this->private;
if (pvt->pw_db != NULL) {
(void) (*pvt->pw_db->close)(pvt->pw_db);
pvt->pw_db = NULL;
}
}
/* Private. */
static int
initdb(struct pvt *pvt) {
const char *p;
if (pvt->pw_db) {
if (lseek((*pvt->pw_db->fd)(pvt->pw_db), 0L, SEEK_CUR) >= 0L)
return (1);
else
(void) (*pvt->pw_db->close)(pvt->pw_db);
}
pvt->pw_db = dbopen((p = _PATH_SMP_DB), O_RDONLY, 0, DB_HASH, NULL);
if (!pvt->pw_db)
pvt->pw_db = dbopen((p =_PATH_MP_DB), O_RDONLY,
0, DB_HASH, NULL);
if (pvt->pw_db)
return (1);
if (!pvt->warned) {
syslog(LOG_ERR, "%s: %m", p);
pvt->warned++;
}
return (0);
}
static int
hashpw(struct irs_pw *this, DBT *key) {
struct pvt *pvt = (struct pvt *)this->private;
char *p, *t, *l;
DBT data;
if ((pvt->pw_db->get)(pvt->pw_db, key, &data, 0))
return (0);
p = (char *)data.data;
if (data.size > pvt->max) {
size_t newlen = pvt->max + 1024;
char *p = memget(newlen);
if (p == NULL) {
return (0);
}
if (pvt->line != NULL) {
memcpy(p, pvt->line, pvt->max);
memput(pvt->line, pvt->max);
}
pvt->max = newlen;
pvt->line = p;
}
/* THIS CODE MUST MATCH THAT IN pwd_mkdb. */
t = pvt->line;
l = pvt->line + pvt->max;
#define EXPAND(e) if ((e = t) == NULL) return (0); else \
do if (t >= l) return (0); while ((*t++ = *p++) != '\0')
#define SCALAR(v) if (t + sizeof v >= l) return (0); else \
(memmove(&(v), p, sizeof v), p += sizeof v)
EXPAND(pvt->passwd.pw_name);
EXPAND(pvt->passwd.pw_passwd);
SCALAR(pvt->passwd.pw_uid);
SCALAR(pvt->passwd.pw_gid);
SCALAR(pvt->passwd.pw_change);
EXPAND(pvt->passwd.pw_class);
EXPAND(pvt->passwd.pw_gecos);
EXPAND(pvt->passwd.pw_dir);
EXPAND(pvt->passwd.pw_shell);
SCALAR(pvt->passwd.pw_expire);
return (1);
}
#endif /* WANT_IRS_PW */

View File

@ -1,353 +0,0 @@
/*
* Copyright (c) 1989, 1993, 1995
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/*
* Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
* Portions Copyright (c) 1996-1999 by Internet Software Consortium.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#if defined(LIBC_SCCS) && !defined(lint)
static const char rcsid[] = "$Id$";
/* from getgrent.c 8.2 (Berkeley) 3/21/94"; */
/* from BSDI Id: getgrent.c,v 2.8 1996/05/28 18:15:14 bostic Exp $ */
#endif /* LIBC_SCCS and not lint */
/* Imports */
#include "port_before.h"
#if !defined(WANT_IRS_GR) || !defined(WANT_IRS_NIS)
static int __bind_irs_gr_unneeded;
#else
#include <sys/param.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/nameser.h>
#include <resolv.h>
#include <isc/memcluster.h>
#include <rpc/rpc.h>
#include <rpc/xdr.h>
#include <rpcsvc/yp_prot.h>
#include <rpcsvc/ypclnt.h>
#include <errno.h>
#include <grp.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <isc/memcluster.h>
#include <irs.h>
#include "port_after.h"
#include "irs_p.h"
#include "nis_p.h"
/* Definitions */
struct pvt {
int needrewind;
char * nis_domain;
char * curkey_data;
int curkey_len;
char * curval_data;
int curval_len;
/*
* Need space to store the entries read from the group file.
* The members list also needs space per member, and the
* strings making up the user names must be allocated
* somewhere. Rather than doing lots of small allocations,
* we keep one buffer and resize it as needed.
*/
struct group group;
size_t nmemb; /* Malloc'd max index of gr_mem[]. */
char * membuf;
size_t membufsize;
};
enum do_what { do_none = 0x0, do_key = 0x1, do_val = 0x2, do_all = 0x3 };
static /*const*/ char group_bygid[] = "group.bygid";
static /*const*/ char group_byname[] = "group.byname";
/* Forward */
static void gr_close(struct irs_gr *);
static struct group * gr_next(struct irs_gr *);
static struct group * gr_byname(struct irs_gr *, const char *);
static struct group * gr_bygid(struct irs_gr *, gid_t);
static void gr_rewind(struct irs_gr *);
static void gr_minimize(struct irs_gr *);
static struct group * makegroupent(struct irs_gr *);
static void nisfree(struct pvt *, enum do_what);
/* Public */
struct irs_gr *
irs_nis_gr(struct irs_acc *this) {
struct irs_gr *gr;
struct pvt *pvt;
if (!(gr = memget(sizeof *gr))) {
errno = ENOMEM;
return (NULL);
}
memset(gr, 0x5e, sizeof *gr);
if (!(pvt = memget(sizeof *pvt))) {
memput(gr, sizeof *gr);
errno = ENOMEM;
return (NULL);
}
memset(pvt, 0, sizeof *pvt);
pvt->needrewind = 1;
pvt->nis_domain = ((struct nis_p *)this->private)->domain;
gr->private = pvt;
gr->close = gr_close;
gr->next = gr_next;
gr->byname = gr_byname;
gr->bygid = gr_bygid;
gr->rewind = gr_rewind;
gr->list = make_group_list;
gr->minimize = gr_minimize;
gr->res_get = NULL;
gr->res_set = NULL;
return (gr);
}
/* Methods */
static void
gr_close(struct irs_gr *this) {
struct pvt *pvt = (struct pvt *)this->private;
if (pvt->group.gr_mem)
free(pvt->group.gr_mem);
if (pvt->membuf)
free(pvt->membuf);
memput(pvt, sizeof *pvt);
memput(this, sizeof *this);
}
static struct group *
gr_next(struct irs_gr *this) {
struct pvt *pvt = (struct pvt *)this->private;
struct group *rval;
int r;
do {
if (pvt->needrewind) {
nisfree(pvt, do_all);
r = yp_first(pvt->nis_domain, group_byname,
&pvt->curkey_data, &pvt->curkey_len,
&pvt->curval_data, &pvt->curval_len);
pvt->needrewind = 0;
} else {
char *newkey_data;
int newkey_len;
nisfree(pvt, do_val);
r = yp_next(pvt->nis_domain, group_byname,
pvt->curkey_data, pvt->curkey_len,
&newkey_data, &newkey_len,
&pvt->curval_data, &pvt->curval_len);
nisfree(pvt, do_key);
pvt->curkey_data = newkey_data;
pvt->curkey_len = newkey_len;
}
if (r != 0) {
errno = ENOENT;
return (NULL);
}
rval = makegroupent(this);
} while (rval == NULL);
return (rval);
}
static struct group *
gr_byname(struct irs_gr *this, const char *name) {
struct pvt *pvt = (struct pvt *)this->private;
int r;
nisfree(pvt, do_val);
r = yp_match(pvt->nis_domain, group_byname, name, strlen(name),
&pvt->curval_data, &pvt->curval_len);
if (r != 0) {
errno = ENOENT;
return (NULL);
}
return (makegroupent(this));
}
static struct group *
gr_bygid(struct irs_gr *this, gid_t gid) {
struct pvt *pvt = (struct pvt *)this->private;
char tmp[sizeof "4294967295"];
int r;
nisfree(pvt, do_val);
(void) sprintf(tmp, "%u", (unsigned int)gid);
r = yp_match(pvt->nis_domain, group_bygid, tmp, strlen(tmp),
&pvt->curval_data, &pvt->curval_len);
if (r != 0) {
errno = ENOENT;
return (NULL);
}
return (makegroupent(this));
}
static void
gr_rewind(struct irs_gr *this) {
struct pvt *pvt = (struct pvt *)this->private;
pvt->needrewind = 1;
}
static void
gr_minimize(struct irs_gr *this) {
UNUSED(this);
/* NOOP */
}
/* Private */
static struct group *
makegroupent(struct irs_gr *this) {
struct pvt *pvt = (struct pvt *)this->private;
unsigned int num_members = 0;
char *cp, **new;
u_long t;
if (pvt->group.gr_mem) {
free(pvt->group.gr_mem);
pvt->group.gr_mem = NULL;
pvt->nmemb = 0;
}
if (pvt->membuf)
free(pvt->membuf);
pvt->membuf = pvt->curval_data;
pvt->curval_data = NULL;
cp = pvt->membuf;
pvt->group.gr_name = cp;
if (!(cp = strchr(cp, ':')))
goto cleanup;
*cp++ = '\0';
pvt->group.gr_passwd = cp;
if (!(cp = strchr(cp, ':')))
goto cleanup;
*cp++ = '\0';
errno = 0;
t = strtoul(cp, NULL, 10);
if (errno == ERANGE)
goto cleanup;
pvt->group.gr_gid = (gid_t) t;
if (!(cp = strchr(cp, ':')))
goto cleanup;
cp++;
if (*cp && cp[strlen(cp)-1] == '\n')
cp[strlen(cp)-1] = '\0';
/*
* Parse the members out.
*/
while (*cp) {
if (num_members+1 >= pvt->nmemb || pvt->group.gr_mem == NULL) {
pvt->nmemb += 10;
new = realloc(pvt->group.gr_mem,
pvt->nmemb * sizeof(char *));
if (new == NULL)
goto cleanup;
pvt->group.gr_mem = new;
}
pvt->group.gr_mem[num_members++] = cp;
if (!(cp = strchr(cp, ',')))
break;
*cp++ = '\0';
}
if (pvt->group.gr_mem == NULL) {
pvt->group.gr_mem = malloc(sizeof(char*));
if (!pvt->group.gr_mem)
goto cleanup;
pvt->nmemb = 1;
}
pvt->group.gr_mem[num_members] = NULL;
return (&pvt->group);
cleanup:
if (pvt->group.gr_mem) {
free(pvt->group.gr_mem);
pvt->group.gr_mem = NULL;
pvt->nmemb = 0;
}
if (pvt->membuf) {
free(pvt->membuf);
pvt->membuf = NULL;
}
return (NULL);
}
static void
nisfree(struct pvt *pvt, enum do_what do_what) {
if ((do_what & do_key) && pvt->curkey_data) {
free(pvt->curkey_data);
pvt->curkey_data = NULL;
}
if ((do_what & do_val) && pvt->curval_data) {
free(pvt->curval_data);
pvt->curval_data = NULL;
}
}
#endif /* WANT_IRS_GR && WANT_IRS_NIS */

View File

@ -1,533 +0,0 @@
/*
* Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
* Copyright (c) 1996,1999 by Internet Software Consortium.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#if defined(LIBC_SCCS) && !defined(lint)
static const char rcsid[] = "$Id$";
#endif /* LIBC_SCCS and not lint */
/* Imports */
#include "port_before.h"
#ifndef WANT_IRS_NIS
static int __bind_irs_nis_unneeded;
#else
#include <sys/types.h>
#include <sys/param.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <arpa/nameser.h>
#ifdef T_NULL
#undef T_NULL /* Silence re-definition warning of T_NULL. */
#endif
#include <rpc/rpc.h>
#include <rpc/xdr.h>
#include <rpcsvc/yp_prot.h>
#include <rpcsvc/ypclnt.h>
#include <ctype.h>
#include <errno.h>
#include <stdlib.h>
#include <netdb.h>
#include <resolv.h>
#include <stdio.h>
#include <string.h>
#include <isc/memcluster.h>
#include <irs.h>
#include "port_after.h"
#include "irs_p.h"
#include "nis_p.h"
/* Definitions */
#define MAXALIASES 35
#define MAXADDRS 35
#if PACKETSZ > 1024
#define MAXPACKET PACKETSZ
#else
#define MAXPACKET 1024
#endif
struct pvt {
int needrewind;
char * nis_domain;
char * curkey_data;
int curkey_len;
char * curval_data;
int curval_len;
struct hostent host;
char * h_addr_ptrs[MAXADDRS + 1];
char * host_aliases[MAXALIASES + 1];
char hostbuf[8*1024];
u_char host_addr[16]; /* IPv4 or IPv6 */
struct __res_state *res;
void (*free_res)(void *);
};
enum do_what { do_none = 0x0, do_key = 0x1, do_val = 0x2, do_all = 0x3 };
static const u_char mapped[] = { 0,0, 0,0, 0,0, 0,0, 0,0, 0xff,0xff };
static const u_char tunnelled[] = { 0,0, 0,0, 0,0, 0,0, 0,0, 0,0 };
static /*const*/ char hosts_byname[] = "hosts.byname";
static /*const*/ char hosts_byaddr[] = "hosts.byaddr";
static /*const*/ char ipnode_byname[] = "ipnode.byname";
static /*const*/ char ipnode_byaddr[] = "ipnode.byaddr";
static /*const*/ char yp_multi[] = "YP_MULTI_";
/* Forwards */
static void ho_close(struct irs_ho *this);
static struct hostent * ho_byname(struct irs_ho *this, const char *name);
static struct hostent * ho_byname2(struct irs_ho *this, const char *name,
int af);
static struct hostent * ho_byaddr(struct irs_ho *this, const void *addr,
int len, int af);
static struct hostent * ho_next(struct irs_ho *this);
static void ho_rewind(struct irs_ho *this);
static void ho_minimize(struct irs_ho *this);
static struct __res_state * ho_res_get(struct irs_ho *this);
static void ho_res_set(struct irs_ho *this,
struct __res_state *res,
void (*free_res)(void *));
static struct addrinfo * ho_addrinfo(struct irs_ho *this, const char *name,
const struct addrinfo *pai);
static struct hostent * makehostent(struct irs_ho *this);
static void nisfree(struct pvt *, enum do_what);
static int init(struct irs_ho *this);
/* Public */
struct irs_ho *
irs_nis_ho(struct irs_acc *this) {
struct irs_ho *ho;
struct pvt *pvt;
if (!(pvt = memget(sizeof *pvt))) {
errno = ENOMEM;
return (NULL);
}
memset(pvt, 0, sizeof *pvt);
if (!(ho = memget(sizeof *ho))) {
memput(pvt, sizeof *pvt);
errno = ENOMEM;
return (NULL);
}
memset(ho, 0x5e, sizeof *ho);
pvt->needrewind = 1;
pvt->nis_domain = ((struct nis_p *)this->private)->domain;
ho->private = pvt;
ho->close = ho_close;
ho->byname = ho_byname;
ho->byname2 = ho_byname2;
ho->byaddr = ho_byaddr;
ho->next = ho_next;
ho->rewind = ho_rewind;
ho->minimize = ho_minimize;
ho->res_set = ho_res_set;
ho->res_get = ho_res_get;
ho->addrinfo = ho_addrinfo;
return (ho);
}
/* Methods */
static void
ho_close(struct irs_ho *this) {
struct pvt *pvt = (struct pvt *)this->private;
ho_minimize(this);
nisfree(pvt, do_all);
if (pvt->res && pvt->free_res)
(*pvt->free_res)(pvt->res);
memput(pvt, sizeof *pvt);
memput(this, sizeof *this);
}
static struct hostent *
ho_byname(struct irs_ho *this, const char *name) {
struct pvt *pvt = (struct pvt *)this->private;
struct hostent *hp;
if (init(this) == -1)
return (NULL);
if (pvt->res->options & RES_USE_INET6) {
hp = ho_byname2(this, name, AF_INET6);
if (hp)
return (hp);
}
return (ho_byname2(this, name, AF_INET));
}
static struct hostent *
ho_byname2(struct irs_ho *this, const char *name, int af) {
struct pvt *pvt = (struct pvt *)this->private;
int r;
char *tmp;
UNUSED(af);
if (init(this) == -1)
return (NULL);
nisfree(pvt, do_val);
strcpy(pvt->hostbuf, yp_multi);
strncat(pvt->hostbuf, name, sizeof(pvt->hostbuf) - sizeof(yp_multi));
pvt->hostbuf[sizeof(pvt->hostbuf) - 1] = '\0';
for (r = sizeof(yp_multi) - 1; pvt->hostbuf[r] != '\0'; r++)
if (isupper((unsigned char)pvt->hostbuf[r]))
tolower(pvt->hostbuf[r]);
tmp = pvt->hostbuf;
r = yp_match(pvt->nis_domain, ipnode_byname, tmp,
strlen(tmp), &pvt->curval_data, &pvt->curval_len);
if (r != 0) {
tmp = pvt->hostbuf + sizeof(yp_multi) - 1;
r = yp_match(pvt->nis_domain, ipnode_byname, tmp,
strlen(tmp), &pvt->curval_data, &pvt->curval_len);
}
if (r != 0) {
tmp = pvt->hostbuf;
r = yp_match(pvt->nis_domain, hosts_byname, tmp,
strlen(tmp), &pvt->curval_data, &pvt->curval_len);
}
if (r != 0) {
tmp = pvt->hostbuf + sizeof(yp_multi) - 1;
r = yp_match(pvt->nis_domain, hosts_byname, tmp,
strlen(tmp), &pvt->curval_data, &pvt->curval_len);
}
if (r != 0) {
RES_SET_H_ERRNO(pvt->res, HOST_NOT_FOUND);
return (NULL);
}
return (makehostent(this));
}
static struct hostent *
ho_byaddr(struct irs_ho *this, const void *addr, int len, int af) {
struct pvt *pvt = (struct pvt *)this->private;
char tmp[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"];
const u_char *uaddr = addr;
int r;
if (init(this) == -1)
return (NULL);
if (af == AF_INET6 && len == IN6ADDRSZ &&
(!memcmp(uaddr, mapped, sizeof mapped) ||
!memcmp(uaddr, tunnelled, sizeof tunnelled))) {
/* Unmap. */
addr = (const u_char *)addr + sizeof mapped;
uaddr += sizeof mapped;
af = AF_INET;
len = INADDRSZ;
}
if (inet_ntop(af, uaddr, tmp, sizeof tmp) == NULL) {
RES_SET_H_ERRNO(pvt->res, NETDB_INTERNAL);
return (NULL);
}
nisfree(pvt, do_val);
r = yp_match(pvt->nis_domain, ipnode_byaddr, tmp, strlen(tmp),
&pvt->curval_data, &pvt->curval_len);
if (r != 0)
r = yp_match(pvt->nis_domain, hosts_byaddr, tmp, strlen(tmp),
&pvt->curval_data, &pvt->curval_len);
if (r != 0) {
RES_SET_H_ERRNO(pvt->res, HOST_NOT_FOUND);
return (NULL);
}
return (makehostent(this));
}
static struct hostent *
ho_next(struct irs_ho *this) {
struct pvt *pvt = (struct pvt *)this->private;
struct hostent *rval;
int r;
if (init(this) == -1)
return (NULL);
do {
if (pvt->needrewind) {
nisfree(pvt, do_all);
r = yp_first(pvt->nis_domain, hosts_byaddr,
&pvt->curkey_data, &pvt->curkey_len,
&pvt->curval_data, &pvt->curval_len);
pvt->needrewind = 0;
} else {
char *newkey_data;
int newkey_len;
nisfree(pvt, do_val);
r = yp_next(pvt->nis_domain, hosts_byaddr,
pvt->curkey_data, pvt->curkey_len,
&newkey_data, &newkey_len,
&pvt->curval_data, &pvt->curval_len);
nisfree(pvt, do_key);
pvt->curkey_data = newkey_data;
pvt->curkey_len = newkey_len;
}
if (r != 0) {
RES_SET_H_ERRNO(pvt->res, HOST_NOT_FOUND);
return (NULL);
}
rval = makehostent(this);
} while (rval == NULL);
return (rval);
}
static void
ho_rewind(struct irs_ho *this) {
struct pvt *pvt = (struct pvt *)this->private;
pvt->needrewind = 1;
}
static void
ho_minimize(struct irs_ho *this) {
struct pvt *pvt = (struct pvt *)this->private;
if (pvt->res)
res_nclose(pvt->res);
}
static struct __res_state *
ho_res_get(struct irs_ho *this) {
struct pvt *pvt = (struct pvt *)this->private;
if (!pvt->res) {
struct __res_state *res;
res = (struct __res_state *)malloc(sizeof *res);
if (!res) {
errno = ENOMEM;
return (NULL);
}
memset(res, 0, sizeof *res);
ho_res_set(this, res, free);
}
return (pvt->res);
}
static void
ho_res_set(struct irs_ho *this, struct __res_state *res,
void (*free_res)(void *)) {
struct pvt *pvt = (struct pvt *)this->private;
if (pvt->res && pvt->free_res) {
res_nclose(pvt->res);
(*pvt->free_res)(pvt->res);
}
pvt->res = res;
pvt->free_res = free_res;
}
struct nis_res_target {
struct nis_res_target *next;
int family;
};
/* XXX */
extern struct addrinfo *hostent2addrinfo __P((struct hostent *,
const struct addrinfo *pai));
static struct addrinfo *
ho_addrinfo(struct irs_ho *this, const char *name, const struct addrinfo *pai)
{
struct pvt *pvt = (struct pvt *)this->private;
struct hostent *hp;
struct nis_res_target q, q2, *p;
struct addrinfo sentinel, *cur;
memset(&q, 0, sizeof(q2));
memset(&q2, 0, sizeof(q2));
memset(&sentinel, 0, sizeof(sentinel));
cur = &sentinel;
switch(pai->ai_family) {
case AF_UNSPEC: /* INET6 then INET4 */
q.family = AF_INET6;
q.next = &q2;
q2.family = AF_INET;
break;
case AF_INET6:
q.family = AF_INET6;
break;
case AF_INET:
q.family = AF_INET;
break;
default:
RES_SET_H_ERRNO(pvt->res, NO_RECOVERY); /* ??? */
return(NULL);
}
for (p = &q; p; p = p->next) {
struct addrinfo *ai;
hp = (*this->byname2)(this, name, p->family);
if (hp == NULL) {
/* byname2 should've set an appropriate error */
continue;
}
if ((hp->h_name == NULL) || (hp->h_name[0] == 0) ||
(hp->h_addr_list[0] == NULL)) {
RES_SET_H_ERRNO(pvt->res, NO_RECOVERY);
continue;
}
ai = hostent2addrinfo(hp, pai);
if (ai) {
cur->ai_next = ai;
while (cur && cur->ai_next)
cur = cur->ai_next;
}
}
if (sentinel.ai_next == NULL)
RES_SET_H_ERRNO(pvt->res, HOST_NOT_FOUND);
return(sentinel.ai_next);
}
/* Private */
/*
ipnodes:
::1 localhost
127.0.0.1 localhost
1.2.3.4 FOO bar
1.2.6.4 FOO bar
1.2.6.5 host
ipnodes.byname:
YP_MULTI_localhost ::1,127.0.0.1 localhost
YP_MULTI_foo 1.2.3.4,1.2.6.4 FOO bar
YP_MULTI_bar 1.2.3.4,1.2.6.4 FOO bar
host 1.2.6.5 host
hosts.byname:
localhost 127.0.0.1 localhost
host 1.2.6.5 host
YP_MULTI_foo 1.2.3.4,1.2.6.4 FOO bar
YP_MULTI_bar 1.2.3.4,1.2.6.4 FOO bar
*/
static struct hostent *
makehostent(struct irs_ho *this) {
struct pvt *pvt = (struct pvt *)this->private;
static const char spaces[] = " \t";
char *cp, **q, *p, *comma, *ap;
int af = 0, len = 0;
int multi = 0;
int addr = 0;
p = pvt->curval_data;
if ((cp = strpbrk(p, "#\n")) != NULL)
*cp = '\0';
if (!(cp = strpbrk(p, spaces)))
return (NULL);
*cp++ = '\0';
ap = pvt->hostbuf;
do {
if ((comma = strchr(p, ',')) != NULL) {
*comma++ = '\0';
multi = 1;
}
if ((ap + IN6ADDRSZ) > (pvt->hostbuf + sizeof(pvt->hostbuf)))
break;
if ((pvt->res->options & RES_USE_INET6) &&
inet_pton(AF_INET6, p, ap) > 0) {
af = AF_INET6;
len = IN6ADDRSZ;
} else if (inet_pton(AF_INET, p, pvt->host_addr) > 0) {
if (pvt->res->options & RES_USE_INET6) {
map_v4v6_address((char*)pvt->host_addr, ap);
af = AF_INET6;
len = IN6ADDRSZ;
} else {
af = AF_INET;
len = INADDRSZ;
}
} else {
if (!multi)
return (NULL);
continue;
}
if (addr < MAXADDRS) {
pvt->h_addr_ptrs[addr++] = ap;
pvt->h_addr_ptrs[addr] = NULL;
ap += len;
}
} while ((p = comma) != NULL);
if (ap == pvt->hostbuf)
return (NULL);
pvt->host.h_addr_list = pvt->h_addr_ptrs;
pvt->host.h_length = len;
pvt->host.h_addrtype = af;
cp += strspn(cp, spaces);
pvt->host.h_name = cp;
q = pvt->host.h_aliases = pvt->host_aliases;
if ((cp = strpbrk(cp, spaces)) != NULL)
*cp++ = '\0';
while (cp && *cp) {
if (*cp == ' ' || *cp == '\t') {
cp++;
continue;
}
if (q < &pvt->host_aliases[MAXALIASES])
*q++ = cp;
if ((cp = strpbrk(cp, spaces)) != NULL)
*cp++ = '\0';
}
*q = NULL;
RES_SET_H_ERRNO(pvt->res, NETDB_SUCCESS);
return (&pvt->host);
}
static void
nisfree(struct pvt *pvt, enum do_what do_what) {
if ((do_what & do_key) && pvt->curkey_data) {
free(pvt->curkey_data);
pvt->curkey_data = NULL;
}
if ((do_what & do_val) && pvt->curval_data) {
free(pvt->curval_data);
pvt->curval_data = NULL;
}
}
static int
init(struct irs_ho *this) {
struct pvt *pvt = (struct pvt *)this->private;
if (!pvt->res && !ho_res_get(this))
return (-1);
if (((pvt->res->options & RES_INIT) == 0) &&
res_ninit(pvt->res) == -1)
return (-1);
return (0);
}
#endif /*WANT_IRS_NIS*/

View File

@ -1,302 +0,0 @@
/*
* Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
* Copyright (c) 1996,1999 by Internet Software Consortium.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#if defined(LIBC_SCCS) && !defined(lint)
static const char rcsid[] = "$Id$";
#endif
/* Imports */
#include "port_before.h"
#ifndef WANT_IRS_NIS
static int __bind_irs_nis_unneeded;
#else
#include <sys/types.h>
#include <netinet/in.h>
#include <rpc/rpc.h>
#include <rpc/xdr.h>
#include <rpcsvc/yp_prot.h>
#include <rpcsvc/ypclnt.h>
#include <isc/assertions.h>
#include <ctype.h>
#include <errno.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <netinet/in.h>
#ifdef T_NULL
#undef T_NULL /* Silence re-definition warning of T_NULL. */
#endif
#include <arpa/nameser.h>
#include <resolv.h>
#include <isc/memcluster.h>
#include <irs.h>
#include "port_after.h"
#include "irs_p.h"
#include "nis_p.h"
/* Definitions */
struct tmpgrp {
const char * name;
const char * host;
const char * user;
const char * domain;
struct tmpgrp * next;
};
struct pvt {
char * nis_domain;
struct tmpgrp * tmp;
struct tmpgrp * cur;
char * tmpgroup;
};
enum do_what { do_none = 0x0, do_key = 0x1, do_val = 0x2, do_all = 0x3 };
static /*const*/ char netgroup_map[] = "netgroup";
/* Forward */
static void ng_close(struct irs_ng *);
static int ng_next(struct irs_ng *, const char **,
const char **, const char **);
static int ng_test(struct irs_ng *,
const char *, const char *,
const char *, const char *);
static void ng_rewind(struct irs_ng *, const char *);
static void ng_minimize(struct irs_ng *);
static void add_group_to_list(struct pvt *, const char *, int);
static void add_tuple_to_list(struct pvt *, const char *, char *);
static void tmpfree(struct pvt *);
/* Public */
struct irs_ng *
irs_nis_ng(struct irs_acc *this) {
struct irs_ng *ng;
struct pvt *pvt;
if (!(ng = memget(sizeof *ng))) {
errno = ENOMEM;
return (NULL);
}
memset(ng, 0x5e, sizeof *ng);
if (!(pvt = memget(sizeof *pvt))) {
memput(ng, sizeof *ng);
errno = ENOMEM;
return (NULL);
}
memset(pvt, 0, sizeof *pvt);
pvt->nis_domain = ((struct nis_p *)this->private)->domain;
ng->private = pvt;
ng->close = ng_close;
ng->next = ng_next;
ng->test = ng_test;
ng->rewind = ng_rewind;
ng->minimize = ng_minimize;
return (ng);
}
/* Methods */
static void
ng_close(struct irs_ng *this) {
struct pvt *pvt = (struct pvt *)this->private;
tmpfree(pvt);
memput(pvt, sizeof *pvt);
memput(this, sizeof *this);
}
static int
ng_next(struct irs_ng *this, const char **host, const char **user, const char **domain) {
struct pvt *pvt = (struct pvt *)this->private;
if (!pvt->cur)
return (0);
*host = pvt->cur->host;
*user = pvt->cur->user;
*domain = pvt->cur->domain;
pvt->cur = pvt->cur->next;
return (1);
}
static int
ng_test(struct irs_ng *this, const char *name,
const char *host, const char *user, const char *domain)
{
struct pvt *pvt = (struct pvt *)this->private;
struct tmpgrp *cur;
tmpfree(pvt);
add_group_to_list(pvt, name, strlen(name));
for (cur = pvt->tmp; cur; cur = cur->next) {
if ((!host || !cur->host || !strcmp(host, cur->host)) &&
(!user || !cur->user || !strcmp(user, cur->user)) &&
(!domain || !cur->domain || !strcmp(domain, cur->domain)))
break;
}
tmpfree(pvt);
return ((cur == NULL) ? 0 : 1);
}
static void
ng_rewind(struct irs_ng *this, const char *name) {
struct pvt *pvt = (struct pvt *)this->private;
/* Either hand back or free the existing list. */
if (pvt->tmpgroup) {
if (pvt->tmp && !strcmp(pvt->tmpgroup, name))
goto reset;
tmpfree(pvt);
}
pvt->tmpgroup = strdup(name);
add_group_to_list(pvt, name, strlen(name));
reset:
pvt->cur = pvt->tmp;
}
static void
ng_minimize(struct irs_ng *this) {
UNUSED(this);
/* NOOP */
}
/* Private */
static void
add_group_to_list(struct pvt *pvt, const char *name, int len) {
char *vdata, *cp, *np;
struct tmpgrp *tmp;
int vlen, r;
char *nametmp;
/* Don't add the same group to the list more than once. */
for (tmp = pvt->tmp; tmp; tmp = tmp->next)
if (!strcmp(tmp->name, name))
return;
DE_CONST(name, nametmp);
r = yp_match(pvt->nis_domain, netgroup_map, nametmp, len,
&vdata, &vlen);
if (r == 0) {
cp = vdata;
if (*cp && cp[strlen(cp)-1] == '\n')
cp[strlen(cp)-1] = '\0';
for ( ; cp; cp = np) {
np = strchr(cp, ' ');
if (np)
*np++ = '\0';
if (*cp == '(')
add_tuple_to_list(pvt, name, cp);
else
add_group_to_list(pvt, cp, strlen(cp));
}
free(vdata);
}
}
static void
add_tuple_to_list(struct pvt *pvt, const char *name, char *cp) {
struct tmpgrp *tmp;
char *tp, *np;
INSIST(*cp++ == '(');
tmp = malloc(sizeof *tmp + strlen(name) + sizeof '\0' +
strlen(cp) - sizeof ')');
if (!tmp)
return;
memset(tmp, 0, sizeof *tmp);
tp = ((char *)tmp) + sizeof *tmp;
/* Name */
strcpy(tp, name);
tmp->name = tp;
tp += strlen(tp) + 1;
/* Host */
if (!(np = strchr(cp, ',')))
goto cleanup;
*np++ = '\0';
strcpy(tp, cp);
tmp->host = tp;
tp += strlen(tp) + 1;
cp = np;
/* User */
if (!(np = strchr(cp, ',')))
goto cleanup;
*np++ = '\0';
strcpy(tp, cp);
tmp->user = tp;
tp += strlen(tp) + 1;
cp = np;
/* Domain */
if (!(np = strchr(cp, ')')))
goto cleanup;
*np++ = '\0';
strcpy(tp, cp);
tmp->domain = tp;
/*
* Empty string in file means wildcard, but
* NULL string in return value means wildcard.
*/
if (!*tmp->host)
tmp->host = NULL;
if (!*tmp->user)
tmp->user = NULL;
if (!*tmp->domain)
tmp->domain = NULL;
/* Add to list (LIFO). */
tmp->next = pvt->tmp;
pvt->tmp = tmp;
return;
cleanup:
free(tmp);
}
static void
tmpfree(struct pvt *pvt) {
struct tmpgrp *cur, *next;
if (pvt->tmpgroup) {
free(pvt->tmpgroup);
pvt->tmpgroup = NULL;
}
for (cur = pvt->tmp; cur; cur = next) {
next = cur->next;
free(cur);
}
pvt->tmp = NULL;
}
#endif /*WANT_IRS_NIS*/

View File

@ -1,383 +0,0 @@
/*
* Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
* Copyright (c) 1996,1999 by Internet Software Consortium.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#if defined(LIBC_SCCS) && !defined(lint)
static const char rcsid[] = "$Id$";
#endif /* LIBC_SCCS and not lint */
/* Imports */
#include "port_before.h"
#ifndef WANT_IRS_NIS
static int __bind_irs_nis_unneeded;
#else
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <arpa/nameser.h>
#ifdef T_NULL
#undef T_NULL /* Silence re-definition warning of T_NULL. */
#endif
#include <rpc/rpc.h>
#include <rpc/xdr.h>
#include <rpcsvc/yp_prot.h>
#include <rpcsvc/ypclnt.h>
#include <errno.h>
#include <resolv.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <isc/memcluster.h>
#include <irs.h>
#include "port_after.h"
#include "irs_p.h"
#include "nis_p.h"
/* Definitions */
#define MAXALIASES 35
#define MAXADDRSIZE 4
struct pvt {
int needrewind;
char * nis_domain;
char * curkey_data;
int curkey_len;
char * curval_data;
int curval_len;
struct nwent nwent;
char * nwbuf;
char * aliases[MAXALIASES + 1];
u_char addr[MAXADDRSIZE];
struct __res_state * res;
void (*free_res)(void *);
};
enum do_what { do_none = 0x0, do_key = 0x1, do_val = 0x2, do_all = 0x3 };
static /*const*/ char networks_byname[] = "networks.byname";
static /*const*/ char networks_byaddr[] = "networks.byaddr";
/* Forward */
static void nw_close(struct irs_nw *);
static struct nwent * nw_byname(struct irs_nw *, const char *, int);
static struct nwent * nw_byaddr(struct irs_nw *, void *, int, int);
static struct nwent * nw_next(struct irs_nw *);
static void nw_rewind(struct irs_nw *);
static void nw_minimize(struct irs_nw *);
static struct __res_state * nw_res_get(struct irs_nw *this);
static void nw_res_set(struct irs_nw *this,
struct __res_state *res,
void (*free_res)(void *));
static struct nwent * makenwent(struct irs_nw *this);
static void nisfree(struct pvt *, enum do_what);
static int init(struct irs_nw *this);
/* Public */
struct irs_nw *
irs_nis_nw(struct irs_acc *this) {
struct irs_nw *nw;
struct pvt *pvt;
if (!(pvt = memget(sizeof *pvt))) {
errno = ENOMEM;
return (NULL);
}
memset(pvt, 0, sizeof *pvt);
if (!(nw = memget(sizeof *nw))) {
memput(pvt, sizeof *pvt);
errno = ENOMEM;
return (NULL);
}
memset(nw, 0x5e, sizeof *nw);
pvt->needrewind = 1;
pvt->nis_domain = ((struct nis_p *)this->private)->domain;
nw->private = pvt;
nw->close = nw_close;
nw->byname = nw_byname;
nw->byaddr = nw_byaddr;
nw->next = nw_next;
nw->rewind = nw_rewind;
nw->minimize = nw_minimize;
nw->res_get = nw_res_get;
nw->res_set = nw_res_set;
return (nw);
}
/* Methods */
static void
nw_close(struct irs_nw *this) {
struct pvt *pvt = (struct pvt *)this->private;
nw_minimize(this);
if (pvt->res && pvt->free_res)
(*pvt->free_res)(pvt->res);
if (pvt->nwbuf)
free(pvt->nwbuf);
memput(pvt, sizeof *pvt);
memput(this, sizeof *this);
}
static struct nwent *
nw_byaddr(struct irs_nw *this, void *net, int length, int af) {
struct pvt *pvt = (struct pvt *)this->private;
char tmp[sizeof "255.255.255.255/32"], *t;
int r;
if (init(this) == -1)
return (NULL);
if (af != AF_INET) {
RES_SET_H_ERRNO(pvt->res, NETDB_INTERNAL);
errno = EAFNOSUPPORT;
return (NULL);
}
nisfree(pvt, do_val);
/* Try it with /CIDR first. */
if (inet_net_ntop(AF_INET, net, length, tmp, sizeof tmp) == NULL) {
RES_SET_H_ERRNO(pvt->res, NETDB_INTERNAL);
return (NULL);
}
r = yp_match(pvt->nis_domain, networks_byaddr, tmp, strlen(tmp),
&pvt->curval_data, &pvt->curval_len);
if (r != 0) {
/* Give it a shot without the /CIDR. */
if ((t = strchr(tmp, '/')) != NULL) {
*t = '\0';
r = yp_match(pvt->nis_domain, networks_byaddr,
tmp, strlen(tmp),
&pvt->curval_data, &pvt->curval_len);
}
if (r != 0) {
RES_SET_H_ERRNO(pvt->res, HOST_NOT_FOUND);
return (NULL);
}
}
return (makenwent(this));
}
static struct nwent *
nw_byname(struct irs_nw *this, const char *name, int af) {
struct pvt *pvt = (struct pvt *)this->private;
int r;
char *tmp;
if (init(this) == -1)
return (NULL);
if (af != AF_INET) {
RES_SET_H_ERRNO(pvt->res, NETDB_INTERNAL);
errno = EAFNOSUPPORT;
return (NULL);
}
nisfree(pvt, do_val);
DE_CONST(name, tmp);
r = yp_match(pvt->nis_domain, networks_byname, tmp,
strlen(tmp), &pvt->curval_data, &pvt->curval_len);
if (r != 0) {
RES_SET_H_ERRNO(pvt->res, HOST_NOT_FOUND);
return (NULL);
}
return (makenwent(this));
}
static void
nw_rewind(struct irs_nw *this) {
struct pvt *pvt = (struct pvt *)this->private;
pvt->needrewind = 1;
}
static struct nwent *
nw_next(struct irs_nw *this) {
struct pvt *pvt = (struct pvt *)this->private;
struct nwent *rval;
int r;
if (init(this) == -1)
return (NULL);
do {
if (pvt->needrewind) {
nisfree(pvt, do_all);
r = yp_first(pvt->nis_domain, networks_byaddr,
&pvt->curkey_data, &pvt->curkey_len,
&pvt->curval_data, &pvt->curval_len);
pvt->needrewind = 0;
} else {
char *newkey_data;
int newkey_len;
nisfree(pvt, do_val);
r = yp_next(pvt->nis_domain, networks_byaddr,
pvt->curkey_data, pvt->curkey_len,
&newkey_data, &newkey_len,
&pvt->curval_data, &pvt->curval_len);
nisfree(pvt, do_key);
pvt->curkey_data = newkey_data;
pvt->curkey_len = newkey_len;
}
if (r != 0) {
RES_SET_H_ERRNO(pvt->res, HOST_NOT_FOUND);
return (NULL);
}
rval = makenwent(this);
} while (rval == NULL);
return (rval);
}
static void
nw_minimize(struct irs_nw *this) {
struct pvt *pvt = (struct pvt *)this->private;
if (pvt->res)
res_nclose(pvt->res);
}
static struct __res_state *
nw_res_get(struct irs_nw *this) {
struct pvt *pvt = (struct pvt *)this->private;
if (!pvt->res) {
struct __res_state *res;
res = (struct __res_state *)malloc(sizeof *res);
if (!res) {
errno = ENOMEM;
return (NULL);
}
memset(res, 0, sizeof *res);
nw_res_set(this, res, free);
}
return (pvt->res);
}
static void
nw_res_set(struct irs_nw *this, struct __res_state *res,
void (*free_res)(void *)) {
struct pvt *pvt = (struct pvt *)this->private;
if (pvt->res && pvt->free_res) {
res_nclose(pvt->res);
(*pvt->free_res)(pvt->res);
}
pvt->res = res;
pvt->free_res = free_res;
}
/* Private */
static struct nwent *
makenwent(struct irs_nw *this) {
struct pvt *pvt = (struct pvt *)this->private;
static const char spaces[] = " \t";
char *t, *cp, **ap;
if (pvt->nwbuf)
free(pvt->nwbuf);
pvt->nwbuf = pvt->curval_data;
pvt->curval_data = NULL;
if ((cp = strpbrk(pvt->nwbuf, "#\n")) != NULL)
*cp = '\0';
cp = pvt->nwbuf;
/* Name */
pvt->nwent.n_name = cp;
cp += strcspn(cp, spaces);
if (!*cp)
goto cleanup;
*cp++ = '\0';
cp += strspn(cp, spaces);
/* Network */
pvt->nwent.n_addrtype = AF_INET;
t = cp + strcspn(cp, spaces);
if (*t)
*t++ = '\0';
pvt->nwent.n_length = inet_net_pton(AF_INET, cp,
pvt->addr, sizeof pvt->addr);
if (pvt->nwent.n_length < 0)
goto cleanup;
pvt->nwent.n_addr = pvt->addr;
cp = t;
/* Aliases */
ap = pvt->nwent.n_aliases = pvt->aliases;
while (*cp) {
if (ap >= &pvt->aliases[MAXALIASES])
break;
*ap++ = cp;
cp += strcspn(cp, spaces);
if (!*cp)
break;
*cp++ = '\0';
cp += strspn(cp, spaces);
}
*ap = NULL;
return (&pvt->nwent);
cleanup:
if (pvt->nwbuf) {
free(pvt->nwbuf);
pvt->nwbuf = NULL;
}
return (NULL);
}
static void
nisfree(struct pvt *pvt, enum do_what do_what) {
if ((do_what & do_key) && pvt->curkey_data) {
free(pvt->curkey_data);
pvt->curkey_data = NULL;
}
if ((do_what & do_val) && pvt->curval_data) {
free(pvt->curval_data);
pvt->curval_data = NULL;
}
}
static int
init(struct irs_nw *this) {
struct pvt *pvt = (struct pvt *)this->private;
if (!pvt->res && !nw_res_get(this))
return (-1);
if (((pvt->res->options & RES_INIT) == 0) &&
res_ninit(pvt->res) == -1)
return (-1);
return (0);
}
#endif /*WANT_IRS_NIS*/

View File

@ -1,300 +0,0 @@
/*
* Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
* Copyright (c) 1996,1999 by Internet Software Consortium.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#if defined(LIBC_SCCS) && !defined(lint)
static const char rcsid[] = "$Id$";
#endif
/* Imports */
#include "port_before.h"
#ifndef WANT_IRS_NIS
static int __bind_irs_nis_unneeded;
#else
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/nameser.h>
#include <resolv.h>
#ifdef T_NULL
#undef T_NULL /* Silence re-definition warning of T_NULL. */
#endif
#include <rpc/rpc.h>
#include <rpc/xdr.h>
#include <rpcsvc/yp_prot.h>
#include <rpcsvc/ypclnt.h>
#include <stdio.h>
#include <string.h>
#include <netdb.h>
#include <ctype.h>
#include <stdlib.h>
#include <errno.h>
#include <isc/memcluster.h>
#include <irs.h>
#include "port_after.h"
#include "irs_p.h"
#include "nis_p.h"
/* Definitions */
struct pvt {
int needrewind;
char * nis_domain;
char * curkey_data;
int curkey_len;
char * curval_data;
int curval_len;
struct protoent proto;
char * prbuf;
};
enum do_what { do_none = 0x0, do_key = 0x1, do_val = 0x2, do_all = 0x3 };
static /*const*/ char protocols_byname[] = "protocols.byname";
static /*const*/ char protocols_bynumber[] = "protocols.bynumber";
/* Forward */
static void pr_close(struct irs_pr *);
static struct protoent * pr_byname(struct irs_pr *, const char *);
static struct protoent * pr_bynumber(struct irs_pr *, int);
static struct protoent * pr_next(struct irs_pr *);
static void pr_rewind(struct irs_pr *);
static void pr_minimize(struct irs_pr *);
static struct protoent * makeprotoent(struct irs_pr *this);
static void nisfree(struct pvt *, enum do_what);
/* Public */
struct irs_pr *
irs_nis_pr(struct irs_acc *this) {
struct irs_pr *pr;
struct pvt *pvt;
if (!(pr = memget(sizeof *pr))) {
errno = ENOMEM;
return (NULL);
}
memset(pr, 0x5e, sizeof *pr);
if (!(pvt = memget(sizeof *pvt))) {
memput(pr, sizeof *pr);
errno = ENOMEM;
return (NULL);
}
memset(pvt, 0, sizeof *pvt);
pvt->needrewind = 1;
pvt->nis_domain = ((struct nis_p *)this->private)->domain;
pr->private = pvt;
pr->byname = pr_byname;
pr->bynumber = pr_bynumber;
pr->next = pr_next;
pr->rewind = pr_rewind;
pr->close = pr_close;
pr->minimize = pr_minimize;
pr->res_get = NULL;
pr->res_set = NULL;
return (pr);
}
/* Methods. */
static void
pr_close(struct irs_pr *this) {
struct pvt *pvt = (struct pvt *)this->private;
nisfree(pvt, do_all);
if (pvt->proto.p_aliases)
free(pvt->proto.p_aliases);
if (pvt->prbuf)
free(pvt->prbuf);
memput(pvt, sizeof *pvt);
memput(this, sizeof *this);
}
static struct protoent *
pr_byname(struct irs_pr *this, const char *name) {
struct pvt *pvt = (struct pvt *)this->private;
int r;
char *tmp;
nisfree(pvt, do_val);
DE_CONST(name, tmp);
r = yp_match(pvt->nis_domain, protocols_byname, tmp,
strlen(tmp), &pvt->curval_data, &pvt->curval_len);
if (r != 0) {
errno = ENOENT;
return (NULL);
}
return (makeprotoent(this));
}
static struct protoent *
pr_bynumber(struct irs_pr *this, int num) {
struct pvt *pvt = (struct pvt *)this->private;
char tmp[sizeof "-4294967295"];
int r;
nisfree(pvt, do_val);
(void) sprintf(tmp, "%d", num);
r = yp_match(pvt->nis_domain, protocols_bynumber, tmp, strlen(tmp),
&pvt->curval_data, &pvt->curval_len);
if (r != 0) {
errno = ENOENT;
return (NULL);
}
return (makeprotoent(this));
}
static struct protoent *
pr_next(struct irs_pr *this) {
struct pvt *pvt = (struct pvt *)this->private;
struct protoent *rval;
int r;
do {
if (pvt->needrewind) {
nisfree(pvt, do_all);
r = yp_first(pvt->nis_domain, protocols_bynumber,
&pvt->curkey_data, &pvt->curkey_len,
&pvt->curval_data, &pvt->curval_len);
pvt->needrewind = 0;
} else {
char *newkey_data;
int newkey_len;
nisfree(pvt, do_val);
r = yp_next(pvt->nis_domain, protocols_bynumber,
pvt->curkey_data, pvt->curkey_len,
&newkey_data, &newkey_len,
&pvt->curval_data, &pvt->curval_len);
nisfree(pvt, do_key);
pvt->curkey_data = newkey_data;
pvt->curkey_len = newkey_len;
}
if (r != 0) {
errno = ENOENT;
return (NULL);
}
rval = makeprotoent(this);
} while (rval == NULL);
return (rval);
}
static void
pr_rewind(struct irs_pr *this) {
struct pvt *pvt = (struct pvt *)this->private;
pvt->needrewind = 1;
}
static void
pr_minimize(struct irs_pr *this) {
UNUSED(this);
/* NOOP */
}
/* Private */
static struct protoent *
makeprotoent(struct irs_pr *this) {
struct pvt *pvt = (struct pvt *)this->private;
char *p, **t;
int n, m;
if (pvt->prbuf)
free(pvt->prbuf);
pvt->prbuf = pvt->curval_data;
pvt->curval_data = NULL;
for (p = pvt->prbuf; *p && *p != '#';)
p++;
while (p > pvt->prbuf && isspace((unsigned char)(p[-1])))
p--;
*p = '\0';
p = pvt->prbuf;
n = m = 0;
pvt->proto.p_name = p;
while (*p && !isspace((unsigned char)*p))
p++;
if (!*p)
return (NULL);
*p++ = '\0';
while (*p && isspace((unsigned char)*p))
p++;
pvt->proto.p_proto = atoi(p);
while (*p && !isspace((unsigned char)*p))
p++;
*p++ = '\0';
while (*p) {
if ((n + 1) >= m || !pvt->proto.p_aliases) {
m += 10;
t = realloc(pvt->proto.p_aliases,
m * sizeof(char *));
if (!t) {
errno = ENOMEM;
goto cleanup;
}
pvt->proto.p_aliases = t;
}
pvt->proto.p_aliases[n++] = p;
while (*p && !isspace((unsigned char)*p))
p++;
if (*p)
*p++ = '\0';
}
if (!pvt->proto.p_aliases)
pvt->proto.p_aliases = malloc(sizeof(char *));
if (!pvt->proto.p_aliases)
goto cleanup;
pvt->proto.p_aliases[n] = NULL;
return (&pvt->proto);
cleanup:
if (pvt->proto.p_aliases) {
free(pvt->proto.p_aliases);
pvt->proto.p_aliases = NULL;
}
if (pvt->prbuf) {
free(pvt->prbuf);
pvt->prbuf = NULL;
}
return (NULL);
}
static void
nisfree(struct pvt *pvt, enum do_what do_what) {
if ((do_what & do_key) && pvt->curkey_data) {
free(pvt->curkey_data);
pvt->curkey_data = NULL;
}
if ((do_what & do_val) && pvt->curval_data) {
free(pvt->curval_data);
pvt->curval_data = NULL;
}
}
#endif /*WANT_IRS_NIS*/

View File

@ -1,287 +0,0 @@
/*
* Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
* Copyright (c) 1996,1999 by Internet Software Consortium.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#if defined(LIBC_SCCS) && !defined(lint)
static const char rcsid[] = "$Id$";
#endif /* LIBC_SCCS and not lint */
/* Imports */
#include "port_before.h"
#if !defined(WANT_IRS_PW) || !defined(WANT_IRS_NIS)
static int __bind_irs_pw_unneeded;
#else
#include <sys/param.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/nameser.h>
#include <resolv.h>
#include <isc/memcluster.h>
#include <rpc/rpc.h>
#include <rpc/xdr.h>
#include <rpcsvc/yp_prot.h>
#include <rpcsvc/ypclnt.h>
#include <errno.h>
#include <fcntl.h>
#include <pwd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <isc/memcluster.h>
#include <irs.h>
#include "port_after.h"
#include "irs_p.h"
#include "nis_p.h"
/* Definitions */
struct pvt {
int needrewind;
char * nis_domain;
char * curkey_data;
int curkey_len;
char * curval_data;
int curval_len;
struct passwd passwd;
char * pwbuf;
};
enum do_what { do_none = 0x0, do_key = 0x1, do_val = 0x2, do_all = 0x3 };
static /*const*/ char passwd_byname[] = "passwd.byname";
static /*const*/ char passwd_byuid[] = "passwd.byuid";
/* Forward */
static void pw_close(struct irs_pw *);
static struct passwd * pw_next(struct irs_pw *);
static struct passwd * pw_byname(struct irs_pw *, const char *);
static struct passwd * pw_byuid(struct irs_pw *, uid_t);
static void pw_rewind(struct irs_pw *);
static void pw_minimize(struct irs_pw *);
static struct passwd * makepasswdent(struct irs_pw *);
static void nisfree(struct pvt *, enum do_what);
/* Public */
struct irs_pw *
irs_nis_pw(struct irs_acc *this) {
struct irs_pw *pw;
struct pvt *pvt;
if (!(pw = memget(sizeof *pw))) {
errno = ENOMEM;
return (NULL);
}
memset(pw, 0x5e, sizeof *pw);
if (!(pvt = memget(sizeof *pvt))) {
memput(pw, sizeof *pw);
errno = ENOMEM;
return (NULL);
}
memset(pvt, 0, sizeof *pvt);
pvt->needrewind = 1;
pvt->nis_domain = ((struct nis_p *)this->private)->domain;
pw->private = pvt;
pw->close = pw_close;
pw->next = pw_next;
pw->byname = pw_byname;
pw->byuid = pw_byuid;
pw->rewind = pw_rewind;
pw->minimize = pw_minimize;
pw->res_get = NULL;
pw->res_set = NULL;
return (pw);
}
/* Methods */
static void
pw_close(struct irs_pw *this) {
struct pvt *pvt = (struct pvt *)this->private;
if (pvt->pwbuf)
free(pvt->pwbuf);
nisfree(pvt, do_all);
memput(pvt, sizeof *pvt);
memput(this, sizeof *this);
}
static struct passwd *
pw_next(struct irs_pw *this) {
struct pvt *pvt = (struct pvt *)this->private;
struct passwd *rval;
int r;
do {
if (pvt->needrewind) {
nisfree(pvt, do_all);
r = yp_first(pvt->nis_domain, passwd_byname,
&pvt->curkey_data, &pvt->curkey_len,
&pvt->curval_data, &pvt->curval_len);
pvt->needrewind = 0;
} else {
char *newkey_data;
int newkey_len;
nisfree(pvt, do_val);
r = yp_next(pvt->nis_domain, passwd_byname,
pvt->curkey_data, pvt->curkey_len,
&newkey_data, &newkey_len,
&pvt->curval_data, &pvt->curval_len);
nisfree(pvt, do_key);
pvt->curkey_data = newkey_data;
pvt->curkey_len = newkey_len;
}
if (r != 0) {
errno = ENOENT;
return (NULL);
}
rval = makepasswdent(this);
} while (rval == NULL);
return (rval);
}
static struct passwd *
pw_byname(struct irs_pw *this, const char *name) {
struct pvt *pvt = (struct pvt *)this->private;
int r;
char *tmp;
nisfree(pvt, do_val);
DE_CONST(name, tmp);
r = yp_match(pvt->nis_domain, passwd_byname, tmp, strlen(tmp),
&pvt->curval_data, &pvt->curval_len);
if (r != 0) {
errno = ENOENT;
return (NULL);
}
return (makepasswdent(this));
}
static struct passwd *
pw_byuid(struct irs_pw *this, uid_t uid) {
struct pvt *pvt = (struct pvt *)this->private;
char tmp[sizeof "4294967295"];
int r;
nisfree(pvt, do_val);
(void) sprintf(tmp, "%u", (unsigned int)uid);
r = yp_match(pvt->nis_domain, passwd_byuid, tmp, strlen(tmp),
&pvt->curval_data, &pvt->curval_len);
if (r != 0) {
errno = ENOENT;
return (NULL);
}
return (makepasswdent(this));
}
static void
pw_rewind(struct irs_pw *this) {
struct pvt *pvt = (struct pvt *)this->private;
pvt->needrewind = 1;
}
static void
pw_minimize(struct irs_pw *this) {
UNUSED(this);
/* NOOP */
}
/* Private */
static struct passwd *
makepasswdent(struct irs_pw *this) {
struct pvt *pvt = (struct pvt *)this->private;
char *cp;
memset(&pvt->passwd, 0, sizeof pvt->passwd);
if (pvt->pwbuf)
free(pvt->pwbuf);
pvt->pwbuf = pvt->curval_data;
pvt->curval_data = NULL;
cp = pvt->pwbuf;
pvt->passwd.pw_name = cp;
if (!(cp = strchr(cp, ':')))
goto cleanup;
#ifdef HAS_PW_CLASS
pvt->passwd.pw_class = cp; /* Needs to point at a \0. */
#endif
*cp++ = '\0';
pvt->passwd.pw_passwd = cp;
if (!(cp = strchr(cp, ':')))
goto cleanup;
*cp++ = '\0';
pvt->passwd.pw_uid = atoi(cp);
if (!(cp = strchr(cp, ':')))
goto cleanup;
*cp++ = '\0';
pvt->passwd.pw_gid = atoi(cp);
if (!(cp = strchr(cp, ':')))
goto cleanup;
*cp++ = '\0';
pvt->passwd.pw_gecos = cp;
if (!(cp = strchr(cp, ':')))
goto cleanup;
*cp++ = '\0';
pvt->passwd.pw_dir = cp;
if (!(cp = strchr(cp, ':')))
goto cleanup;
*cp++ = '\0';
pvt->passwd.pw_shell = cp;
if ((cp = strchr(cp, '\n')) != NULL)
*cp = '\0';
return (&pvt->passwd);
cleanup:
free(pvt->pwbuf);
pvt->pwbuf = NULL;
return (NULL);
}
static void
nisfree(struct pvt *pvt, enum do_what do_what) {
if ((do_what & do_key) && pvt->curkey_data) {
free(pvt->curkey_data);
pvt->curkey_data = NULL;
}
if ((do_what & do_val) && pvt->curval_data) {
free(pvt->curval_data);
pvt->curval_data = NULL;
}
}
#endif /* WANT_IRS_PW && WANT_IRS_NIS */

View File

@ -1,308 +0,0 @@
/*
* Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
* Copyright (c) 1996,1999 by Internet Software Consortium.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#if defined(LIBC_SCCS) && !defined(lint)
static const char rcsid[] = "$Id$";
#endif /* LIBC_SCCS and not lint */
/* Imports */
#include "port_before.h"
#ifndef WANT_IRS_NIS
static int __bind_irs_nis_unneeded;
#else
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/nameser.h>
#include <resolv.h>
#include <sys/socket.h>
#ifdef T_NULL
#undef T_NULL /* Silence re-definition warning of T_NULL. */
#endif
#include <rpc/rpc.h>
#include <rpc/xdr.h>
#include <rpcsvc/yp_prot.h>
#include <rpcsvc/ypclnt.h>
#include <ctype.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <isc/memcluster.h>
#include <irs.h>
#include "port_after.h"
#include "irs_p.h"
#include "nis_p.h"
/* Definitions */
struct pvt {
int needrewind;
char * nis_domain;
char * curkey_data;
int curkey_len;
char * curval_data;
int curval_len;
char line[BUFSIZ+1];
struct servent serv;
char * svbuf;
};
enum do_what { do_none = 0x0, do_key = 0x1, do_val = 0x2, do_all = 0x3 };
static /*const*/ char services_byname[] = "services.byname";
/* Forward */
static void sv_close(struct irs_sv*);
static struct servent * sv_next(struct irs_sv *);
static struct servent * sv_byname(struct irs_sv *, const char *,
const char *);
static struct servent * sv_byport(struct irs_sv *, int, const char *);
static void sv_rewind(struct irs_sv *);
static void sv_minimize(struct irs_sv *);
static struct servent * makeservent(struct irs_sv *this);
static void nisfree(struct pvt *, enum do_what);
/* Public */
struct irs_sv *
irs_nis_sv(struct irs_acc *this) {
struct irs_sv *sv;
struct pvt *pvt;
if (!(sv = memget(sizeof *sv))) {
errno = ENOMEM;
return (NULL);
}
memset(sv, 0x5e, sizeof *sv);
if (!(pvt = memget(sizeof *pvt))) {
memput(sv, sizeof *sv);
errno = ENOMEM;
return (NULL);
}
memset(pvt, 0, sizeof *pvt);
pvt->needrewind = 1;
pvt->nis_domain = ((struct nis_p *)this->private)->domain;
sv->private = pvt;
sv->close = sv_close;
sv->next = sv_next;
sv->byname = sv_byname;
sv->byport = sv_byport;
sv->rewind = sv_rewind;
sv->minimize = sv_minimize;
sv->res_get = NULL;
sv->res_set = NULL;
return (sv);
}
/* Methods */
static void
sv_close(struct irs_sv *this) {
struct pvt *pvt = (struct pvt *)this->private;
nisfree(pvt, do_all);
if (pvt->serv.s_aliases)
free(pvt->serv.s_aliases);
if (pvt->svbuf)
free(pvt->svbuf);
memput(pvt, sizeof *pvt);
memput(this, sizeof *this);
}
static struct servent *
sv_byname(struct irs_sv *this, const char *name, const char *proto) {
struct servent *serv;
char **sap;
sv_rewind(this);
while ((serv = sv_next(this)) != NULL) {
if (proto != NULL && strcmp(proto, serv->s_proto))
continue;
if (!strcmp(name, serv->s_name))
break;
for (sap = serv->s_aliases; sap && *sap; sap++)
if (!strcmp(name, *sap))
break;
}
return (serv);
}
static struct servent *
sv_byport(struct irs_sv *this, int port, const char *proto) {
struct servent *serv;
sv_rewind(this);
while ((serv = sv_next(this)) != NULL) {
if (proto != NULL && strcmp(proto, serv->s_proto))
continue;
if (serv->s_port == port)
break;
}
return (serv);
}
static void
sv_rewind(struct irs_sv *this) {
struct pvt *pvt = (struct pvt *)this->private;
pvt->needrewind = 1;
}
static struct servent *
sv_next(struct irs_sv *this) {
struct pvt *pvt = (struct pvt *)this->private;
struct servent *rval;
int r;
do {
if (pvt->needrewind) {
nisfree(pvt, do_all);
r = yp_first(pvt->nis_domain, services_byname,
&pvt->curkey_data, &pvt->curkey_len,
&pvt->curval_data, &pvt->curval_len);
pvt->needrewind = 0;
} else {
char *newkey_data;
int newkey_len;
nisfree(pvt, do_val);
r = yp_next(pvt->nis_domain, services_byname,
pvt->curkey_data, pvt->curkey_len,
&newkey_data, &newkey_len,
&pvt->curval_data, &pvt->curval_len);
nisfree(pvt, do_key);
pvt->curkey_data = newkey_data;
pvt->curkey_len = newkey_len;
}
if (r != 0) {
errno = ENOENT;
return (NULL);
}
rval = makeservent(this);
} while (rval == NULL);
return (rval);
}
static void
sv_minimize(struct irs_sv *this) {
UNUSED(this);
/* NOOP */
}
/* Private */
static struct servent *
makeservent(struct irs_sv *this) {
struct pvt *pvt = (struct pvt *)this->private;
static const char spaces[] = " \t";
char *p, **t;
int n, m;
if (pvt->svbuf)
free(pvt->svbuf);
pvt->svbuf = pvt->curval_data;
pvt->curval_data = NULL;
if (pvt->serv.s_aliases) {
free(pvt->serv.s_aliases);
pvt->serv.s_aliases = NULL;
}
if ((p = strpbrk(pvt->svbuf, "#\n")))
*p = '\0';
p = pvt->svbuf;
pvt->serv.s_name = p;
p += strcspn(p, spaces);
if (!*p)
goto cleanup;
*p++ = '\0';
p += strspn(p, spaces);
pvt->serv.s_port = htons((u_short) atoi(p));
pvt->serv.s_proto = NULL;
while (*p && !isspace((unsigned char)*p))
if (*p++ == '/')
pvt->serv.s_proto = p;
if (!pvt->serv.s_proto)
goto cleanup;
if (*p) {
*p++ = '\0';
p += strspn(p, spaces);
}
n = m = 0;
while (*p) {
if ((n + 1) >= m || !pvt->serv.s_aliases) {
m += 10;
t = realloc(pvt->serv.s_aliases, m * sizeof(char *));
if (!t) {
errno = ENOMEM;
goto cleanup;
}
pvt->serv.s_aliases = t;
}
pvt->serv.s_aliases[n++] = p;
p += strcspn(p, spaces);
if (!*p)
break;
*p++ = '\0';
p += strspn(p, spaces);
}
if (!pvt->serv.s_aliases)
pvt->serv.s_aliases = malloc(sizeof(char *));
if (!pvt->serv.s_aliases)
goto cleanup;
pvt->serv.s_aliases[n] = NULL;
return (&pvt->serv);
cleanup:
if (pvt->serv.s_aliases) {
free(pvt->serv.s_aliases);
pvt->serv.s_aliases = NULL;
}
if (pvt->svbuf) {
free(pvt->svbuf);
pvt->svbuf = NULL;
}
return (NULL);
}
static void
nisfree(struct pvt *pvt, enum do_what do_what) {
if ((do_what & do_key) && pvt->curkey_data) {
free(pvt->curkey_data);
pvt->curkey_data = NULL;
}
if ((do_what & do_val) && pvt->curval_data) {
free(pvt->curval_data);
pvt->curval_data = NULL;
}
}
#endif /*WANT_IRS_NIS*/

View File

@ -0,0 +1,19 @@
#include <pthread_emu.h>
// XXX: this is an ugly hack because we don't support mutexes
extern pthread_key_t gIRSInitKey;
extern pthread_key_t gGaiStrerrorKey;
class TLSInit {
public:
TLSInit();
};
TLSInit::TLSInit()
{
gIRSInitKey = tls_allocate();
gGaiStrerrorKey = tls_allocate();
}
static TLSInit __tlsinit_hack;

View File

@ -1,44 +0,0 @@
#include <pthread_emu.h>
pthread_mutex_t
pthread_mutex_static_initializer(void)
{
return _pthread_mutex_static_initializer();
}
/*
Does not work because the destructor function must be called for _every_ thread.
Solution: maybe run a thread in the background that watches for dying threads
and calls the key's destructor function.
Does tls_allocate() set the key's value to NULL?
int
pthread_key_create(pthread_key_t *key, void (*destructor)(void *))
{
if(!key)
return B_ERROR;
*key = tls_allocate();
if(destructor)
return on_exit_thread(destructor, tls_address(*key));
return B_OK;
}
int
pthread_setspecific(pthread_key_t key, void *value)
{
tls_set(key, value);
return B_OK;
}
void*
pthread_getspecific(pthread_key_t key)
{
return tls_get(key);
}
*/